Rev 11803 | Rev 11811 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
8299 | schaersvoo | 1 | /*27/7/2013 version 0.01 |
7614 | schaersvoo | 2 | "Inspired" by FLY program: http://martin.gleeson.com/fly |
3 | ********************************************************************************* |
||
4 | * J.M. Evers 7/2013 * |
||
5 | * This is all just amateur scriblings... So no copyrights. * |
||
6 | * This source code file, and compiled objects derived from it, * |
||
7 | * can be used and distributed without restriction, including for commercial use * |
||
8 | * No warrenty whatsoever * |
||
9 | ********************************************************************************* |
||
10 | */ |
||
7848 | bpr | 11 | #include "canvasdraw.h" |
7614 | schaersvoo | 12 | |
13 | /****************************************************************************** |
||
14 | ** Internal Functions |
||
15 | ******************************************************************************/ |
||
16 | void add_to_buffer(char *tmp); /* add tmp_buffer to the buffer */ |
||
17 | void sync_input(FILE *infile);/* proceed with inputfile */ |
||
11021 | schaersvoo | 18 | void add_javascript_function(int js_function[], int canvas_root_id); |
7614 | schaersvoo | 19 | void reset();/* reset some global variables like "use_filled" , "use_dashed" */ |
20 | int get_token(FILE *infile); /* read next char until EOL*/ |
||
8225 | bpr | 21 | /* |
7614 | schaersvoo | 22 | int x2px(double x); |
23 | int y2px(double y); |
||
8225 | bpr | 24 | */ |
7614 | schaersvoo | 25 | double px2x(int x); |
26 | double px2y(int y); |
||
7906 | schaersvoo | 27 | double get_real(FILE *infile,int last); /* read a value; calculation and symbols allowed */ |
7614 | schaersvoo | 28 | char *str_replace ( const char *word, const char *sub_word, const char *rep_word ); |
29 | char *get_color(FILE *infile,int last); /* read hex-color or colorname -> hex */ |
||
7906 | schaersvoo | 30 | char *get_string(FILE *infile,int last); /* get the string at the end of a command */ |
7614 | schaersvoo | 31 | char *get_string_argument(FILE *infile,int last); /* the same, but with "comma" as separator */ |
32 | char *convert_hex2rgb(char *hexcolor); |
||
8257 | schaersvoo | 33 | void add_read_canvas(int canvas_root_id,int reply_format,int reply_precision); |
7614 | schaersvoo | 34 | void make_js_include(int canvas_root_id); |
35 | void check_string_length(int length);/* checks if the length of string argument of command is correct */ |
||
8224 | bpr | 36 | FILE *js_include_file; |
7614 | schaersvoo | 37 | FILE *get_file(int *line_number, char **filename); |
38 | FILE *infile; /* will be stdin */ |
||
39 | /****************************************************************************** |
||
40 | ** global |
||
41 | ******************************************************************************/ |
||
42 | int finished = FALSE;/* main variable for signalling the end of the fly-script ; if finished = 1 ; write to stdout or canvasz */ |
||
43 | int line_number = 1;/* used in canvas_error() ; keep track of line number in canvasdraw/fly - script */ |
||
44 | /* set some variables to avoid trouble (NaN) in case of syntax and other usage errors */ |
||
45 | int xsize = 320; |
||
46 | int ysize = 320; |
||
47 | double xmin = 0.0; |
||
48 | double xmax = 320.0; |
||
49 | double ymin = 0.0; |
||
50 | double ymax = 320.0; |
||
51 | double tmax = 2; |
||
52 | double tmin = -2; |
||
53 | /* flag to indicate parsing of line status */ |
||
8224 | bpr | 54 | int done = FALSE; |
7614 | schaersvoo | 55 | int type; /* eg command number */ |
56 | int onclick = 0;/* 0 = noninteractive ; 1 = onclick ; 2 = draggable*/ |
||
8097 | schaersvoo | 57 | int slider = 0;/* slider=1 : x-values ; slider=2 : y-values;slider=3 angle values */ |
7785 | schaersvoo | 58 | int use_affine = FALSE; |
7614 | schaersvoo | 59 | int use_rotate = FALSE; |
60 | int use_filled = FALSE; |
||
61 | int use_dashed = FALSE; /* dashing not natively supported in firefox , for now... */ |
||
8097 | schaersvoo | 62 | |
7614 | schaersvoo | 63 | char buffer[MAX_BUFFER];/* contains js-functions with arguments ... all other basic code is directly printed into js-include file */ |
9329 | schaersvoo | 64 | char *getfile_cmd = ""; |
7614 | schaersvoo | 65 | /****************************************************************************** |
66 | ** Main Program |
||
67 | ******************************************************************************/ |
||
68 | int main(int argc, char *argv[]){ |
||
69 | /* need unique id for every call to canvasdraw : rand(); is too slow...will result in many identical id's */ |
||
70 | struct timeval tv;struct timezone tz;gettimeofday(&tv, &tz);unsigned int canvas_root_id = (unsigned int) tv.tv_usec; |
||
71 | infile = stdin;/* read flyscript via stdin */ |
||
72 | int i,c; |
||
73 | double double_data[MAX_INT+1]; |
||
74 | int int_data[MAX_INT+1]; |
||
75 | for(i=0;i<MAX_INT;i++){int_data[i]=0;double_data[i]=0;} |
||
76 | int use_parametric = FALSE;/* will be reset after parametric plotting */ |
||
11802 | schaersvoo | 77 | int use_offset = FALSE;/* use_offset only for text shape objects... 0=none;1=xcentered;2=xyoffset*/ |
7614 | schaersvoo | 78 | int use_axis = FALSE; |
79 | int use_axis_numbering = FALSE; |
||
7797 | schaersvoo | 80 | int use_pan_and_zoom = FALSE; |
7956 | schaersvoo | 81 | int use_safe_eval = FALSE; /* if true, add just once : js function to evaluate userinput values for plotting etc */ |
7858 | schaersvoo | 82 | int use_js_math = FALSE; /* if true add js-function to convert math_function --> javascript math_function */ |
83 | int use_js_plot = FALSE; /* if true , let js-engine plot the curve */ |
||
11006 | schaersvoo | 84 | int jsplot_cnt = 0; /* keepint track on the curve identity */ |
8448 | schaersvoo | 85 | int print_drag_params_only_once = FALSE;/* avoid multiple useless identical lines about javascript precision and use_dragdrop */ |
7614 | schaersvoo | 86 | int line_width = 1; |
87 | int decimals = 2; |
||
8365 | schaersvoo | 88 | int precision = 100; /* 10 = 1;100=2;1000=3 decimal display for mouse coordinates or grid coordinate.May be redefined before every object */ |
89 | int use_userdraw = FALSE; /* flag to indicate user interaction */ |
||
7614 | schaersvoo | 90 | int drag_type = -1;/* 0,1,2 : xy,x,y */ |
9329 | schaersvoo | 91 | int use_tooltip = -1; /* 1= tooltip 2= popup window*/ |
7614 | schaersvoo | 92 | char *tooltip_text = "Click here"; |
93 | char *temp = ""; /* */ |
||
94 | char *bgcolor = "";/* used for background of canvas_div ; default is tranparent */ |
||
95 | char *stroke_color = "255,0,0"; |
||
96 | char *fill_color = "0,255,0"; |
||
97 | char *font_family = "12px Ariel"; /* commands xaxistext,yaxistext,legend,text/textup/string/stringup may us this */ |
||
98 | char *font_color = "#00000"; |
||
99 | char *draw_type = "points"; |
||
100 | char *fly_font = "normal"; |
||
8815 | schaersvoo | 101 | char *input_style = "font-family:Ariel;text-align:center;color:blue;font-size:12px;background-color:orange;"; |
7614 | schaersvoo | 102 | char *flytext = ""; |
7785 | schaersvoo | 103 | char *affine_matrix = "[1,0,0,1,0,0]"; |
8297 | schaersvoo | 104 | char *function_label = "f(x)="; |
11006 | schaersvoo | 105 | int canvas_type = DRAG_CANVAS; /* to use a specific canvas for filling etc */ |
7614 | schaersvoo | 106 | int pixelsize = 1; |
107 | int reply_format = 0; |
||
108 | int input_cnt = 0; |
||
109 | int ext_img_cnt = 0; |
||
8071 | schaersvoo | 110 | int slider_cnt = 0; |
11763 | schaersvoo | 111 | int fill_cnt = 0; |
10953 | bpr | 112 | int font_size = 12;/* this may lead to problems when using something like "fontfamily Italic 24px Ariel" the "font_size" value is not substituted into fontfamily !! */ |
8388 | schaersvoo | 113 | int fly_font_size = 12; /*fly_font_size is relative to this... */ |
8365 | schaersvoo | 114 | int dashtype[2] = { 4 , 4 }; /* just line_px and space_px : may have more arguments...if needed in future*/ |
7614 | schaersvoo | 115 | int js_function[MAX_JS_FUNCTIONS]; /* javascript functions include objects on demand basis : only once per object type */ |
116 | for(i=0;i<MAX_JS_FUNCTIONS;i++){js_function[i]=0;} |
||
8365 | schaersvoo | 117 | int arrow_head = 8; /* size in px needed for arrow based userdraw: "userdraw arrow,color" */ |
7833 | schaersvoo | 118 | int crosshair_size = 5; /* size in px*/ |
8365 | schaersvoo | 119 | int plot_steps = 250;/* the js-arrays with x_data_points and y_data_points will have size 250 each: use with care !!! use jscurve when precise plots are required */ |
120 | int found_size_command = 0; /* 1 = found size ; 2 = found xrange; 3 = found yrange :just to flag an error message */ |
||
8448 | schaersvoo | 121 | int click_cnt = 0; /*counter to identify the "onclick" ojects ; 0 is first object set onclick: reply[click_cnt]=1 when clicked ; otherwise reply[click_cnt]=0 ; click_cnt is only increased when another object is set again */ |
7614 | schaersvoo | 122 | int clock_cnt = 0; /* counts the amount of clocks used -> unique object clock%d */ |
123 | int linegraph_cnt = 0; /* identifier for command 'linegraph' ; multiple line graphs may be plotted in a single plot*/ |
||
7989 | schaersvoo | 124 | int barchart_cnt = 0; /* identifier for command 'barchart' ; multiple charts may be plotted in a single plot*/ |
9433 | schaersvoo | 125 | int boxplot_cnt = 0; |
7956 | schaersvoo | 126 | int legend_cnt = -1; /* to allow multiple legends to be used, for multiple piecharts etc */ |
8074 | schaersvoo | 127 | int reply_precision = 100; /* used for precision of student answers / drawings */ |
7614 | schaersvoo | 128 | double angle = 0.0; |
10953 | bpr | 129 | char *rotation_center = "null"; |
8365 | schaersvoo | 130 | int clickfillmarge = 20; /* in pixels : if the 'remove click' is within this marge, the filling is removed */ |
131 | int animation_type = 9; /* REMOVED == object type curve in drag library */ |
||
7823 | schaersvoo | 132 | int use_input_xy = 0; /* 1= input fields 2= textarea 3=calc y value*/ |
10953 | bpr | 133 | int use_slider_display = 0; /* in case of a slider, should we display its value ?*/ |
8365 | schaersvoo | 134 | size_t string_length = 0; /* measure the size of the user input fly-string */ |
135 | double stroke_opacity = 0.8; /* use some opacity as default */ |
||
136 | double fill_opacity = 0.8;/* use some opacity as default */ |
||
7614 | schaersvoo | 137 | char *URL = "http://localhost/images"; |
9213 | schaersvoo | 138 | char *slider_function_x = "x"; |
139 | char *slider_function_y = "y"; |
||
7614 | schaersvoo | 140 | memset(buffer,'\0',MAX_BUFFER); |
141 | void *tmp_buffer = ""; |
||
8224 | bpr | 142 | |
7614 | schaersvoo | 143 | /* default writing a unzipped js-include file into wims getfile directory */ |
144 | char *w_wims_session = getenv("w_wims_session"); |
||
8224 | bpr | 145 | if( w_wims_session == NULL || *w_wims_session == 0 ){ |
7614 | schaersvoo | 146 | canvas_error("Hmmm, your wims environment does not exist...\nCanvasdraw should be used within wims."); |
147 | } |
||
148 | int L0=strlen(w_wims_session) + 21; |
||
149 | char *getfile_dir = my_newmem(L0); /* create memory to fit string precisely */ |
||
150 | snprintf(getfile_dir,L0, "../sessions/%s/getfile",w_wims_session);/* string will fit precisely */ |
||
151 | mode_t process_mask = umask(0); /* check if file exists */ |
||
152 | int result = mkdir(getfile_dir, S_IRWXU | S_IRWXG | S_IRWXO); |
||
153 | if( result == 0 || errno == EEXIST ){ |
||
154 | umask(process_mask); /* be sure to set correct permission */ |
||
8224 | bpr | 155 | char *w_session = getenv("w_session"); |
7614 | schaersvoo | 156 | int L1 = (int) (strlen(w_session)) + find_number_of_digits(canvas_root_id) + 48; |
9329 | schaersvoo | 157 | getfile_cmd = my_newmem(L1); /* create memory to fit string precisely */ |
8224 | bpr | 158 | snprintf(getfile_cmd,L1,"wims.cgi?session=%s&cmd=getfile&special_parm=%d.js",w_session,canvas_root_id);/* extension ".gz" is MANDATORY for webserver */ |
7614 | schaersvoo | 159 | /* write the include tag to html page:<script type="text/javascript" src="wims.cgi?session=%s&cmd=getfile&special_parm=11223344_js"></script> */ |
160 | /* now write file into getfile dir*/ |
||
161 | char *w_wims_home = getenv("w_wims_home"); /* "/home/users/wims" : we need absolute path for location */ |
||
162 | int L2 = (int) (strlen(w_wims_home)) + (int) (strlen(w_wims_session)) + find_number_of_digits(canvas_root_id) + 23; |
||
163 | char *location = my_newmem(L2); /* create memory to fit string precisely */ |
||
164 | snprintf(location,L2,"%s/sessions/%s/getfile/%d.js",w_wims_home,w_wims_session,canvas_root_id);/*absolute path */ |
||
165 | js_include_file = fopen(location,"w");/* open the file location for writing */ |
||
166 | /* check on opening...if nogood : mount readonly? disk full? permissions not set correctly? */ |
||
167 | if(js_include_file == NULL){ canvas_error("SHOULD NOT HAPPEN : could not write to javascript include file...check your system logfiles !" );} |
||
168 | |||
169 | /* ----------------------------------------------------- */ |
||
170 | /* while more lines to process */ |
||
171 | |||
172 | while(!finished){ |
||
9329 | schaersvoo | 173 | if(line_number>1 && found_size_command == 0 && use_tooltip != 2 ){canvas_error("command \"size xsize,ysize\" needs to come first ! ");} |
7614 | schaersvoo | 174 | type = get_token(infile); |
175 | done = FALSE; |
||
176 | /* |
||
9385 | schaersvoo | 177 | @ canvasdraw |
178 | @ will try use the same syntax as flydraw or svgdraw to paint a html5 bitmap image<br />by generating a tailor-made javascript include file: providing only the js-functionality needed to perform the job.<br />thus ensuring a minimal strain on the client browser <br />(unlike some popular 'canvas-do-it-all' libraries, who have proven to be not suitable for low-end computers found in schools...) |
||
9386 | schaersvoo | 179 | @ general syntax <ul><li>The transparency of all objects can be controlled by command <a href="#opacity">'opacity [0-255],[0,255]'</a></il><li>line width of any object can be controlled by command <a href="#linewidth">'linewidth int'</a></li><li>any may be dashed by using keyword <a href="#dashed">'dashed'</a> before the object command.<br />the dashing type can be controled by command <a href="#dashtype">'dashtype int,int'</a></li><li>a fillable object can be set fillable by starting the object command with an 'f'<br />(like frect,fcircle,ftriangle...)<br />or by using the keyword <a href="#filled">'filled'</a> before the object command.<br />The fill colour of 'non_userdraw' objects will be the stroke colour...(flydraw harmonization 19/10/2013)</li><li>all draggable objects may have a <a href="#slider">slider</a> for translation / rotation; several objects may be translated / rotated by a single slider</li> <li> a draggable object can be set draggable by a preceding command <a href="#drag">'drag x/y/xy'</a><br />The translation can be read by javascript:read_dragdrop();The replyformat is : object_number : x-orig : y-orig : x-drag : y-drag<br />The x-orig/y-orig will be returned in maximum precision (javascript float)...<br />the x-drag/y-drag will be returned in defined 'precision' number of decimals<br />Multiple objects may be set draggable / clickable (no limit)<br /> not all flydraw objects may be dragged / clicked<br />Only draggable / clickable objects will be scaled on <a href="#zoom">zoom</a> and will be translated in case of panning</li><li> a 'onclick object' can be set 'clickable' by the preceding keyword <a href="#onclick">'onclick'</a><br />not all flydraw objects can be set clickable</li><li><b>remarks using a ';' as command separator</b><br />commands with only numeric or colour arguments may be using a ';' as command separator (instead of a new line)<br />commands with a string argument may not use a ';' as command separator !<br />these exceptions are not really straight forward... so keep this in mind.</li><li>almost every <a href="#userdraw">"userdraw object,color"</a> or <a href="#multidraw">"multidraw"</a> command 'family' may be combined with keywords <a href="#snaptogrid">"snaptogrid | xsnaptogrid | ysnaptogrid | snaptofunction</a> or command "snaptopoints x1,y1,x2,y2,..." </li><li>every draggable | onclick object may be combined with keywords <a href="#snaptogrid">snaptogrid | xsnaptogrid | ysnaptogrid | snaptofunction</a> or command "snaptopoints x1,y1,x2,y2,..." </li><li>almost every command for a single object has a multiple objects counterpart:<br /><ul>general syntaxrule:<li><em>single_object</em> x1,y1,...,color</li><li><em>multi_object</em> color,x1,y1,...</li></ul><li>All inputfields or textareas generated, can be styled individually using command <a href="#inputstyle">'inputstyle some_css'</a><br/>the fontsize used for labeling these elements can be controlled by command <a href="fontsize">'fontsize int'</a> <br />command 'fontfamily' is <b>not</b> active for these elements </li></ul> |
10953 | bpr | 180 | @ If needed multiple interactive scripts may be used in a single webpage.<br />A function 'read_canvas()' and / or 'read_dragdrop()' can read all interactive userdata from these images.<br />The global array 'canvas_scripts' will contain all unique random "canvas_root_id" of the included scripts.<br />The included local javascript "read" functions "read_canvas%d()" and "read_dragdrop%d()" will have this "%d = canvas_root_id"<br />e.g. canvas_scripts[0] will be the random id of the first script in the page and will thus provide a function<br />fun = eval("read_canvas"+canvas_scripts[0]) to read user based drawings / inputfield in this first image.<br />The read_dragdrop is analogue.<br />If the default reply formatting is not suitable, use command <a href='#replyformat'>'replyformat'</a> to format the replies for an individual canvas script,<br />To read all user interactions from all included canvas scripts , use something like:<br /><em>function read_all_canvas_images(){<br /> var script_len = canvas_scripts.length;<br /> var draw_reply = "";<br /> var found_result = false;<br /> for(var p = 0 ; p < script_len ; p++){<br /> var fun = eval("read_canvas"+canvas_scripts[p]);<br /> if( typeof fun === 'function'){<br /> var result = fun();<br /> if( result && result.length != 0){<br /> if(script_len == 1 ){ return result;};<br /> found_result = true;<br /> draw_reply = draw_reply + result + "\\n";<br /> };<br /> };<br /> };<br /> if( found_result ){return draw_reply;}else{return null;};<br />};</em> |
11006 | schaersvoo | 181 | @ you can check the javascript reply format in the wims tool <a href="http://localhost/wims/wims.cgi?lang=en&module=tool/directexec">direct exec</a> |
10962 | schaersvoo | 182 | @ for usage within OEF (without anstype "draw"), something like this (a popup function plotter) will work:<br /><small>\\text{popup_grapher=wims(exec canvasdraw <br />popup<br />size 400,400<br />xrange -10,10<br />yrange -10,10<br />axis<br />axisnumbering<br />opacity 100,100<br />grid 2,2,grey,2,2,6,black<br />snaptogrid<br />linewidth 2<br />jsplot red,5*sin(1/x)<br />strokecolor green<br />functionlabel f(x)=<br />userinput function<br />mouse blue,22<br />)<br />}<br />\\statement{<br />\\popup_grapher<br />}</small> |
9427 | schaersvoo | 183 | @ be aware that older browsers will probably not work correctly<br />no effort has been undertaken to add glue code for older browsers !! <br />in any case it's not wise to use older browsers...not just for canvasdraw |
10827 | schaersvoo | 184 | @ if you find flaws, errors or other incompatibilities -not those mentioned in this document- send <a href='mailto:jm.evers-at-schaersvoorde.nl'>me</a> an email with screenshots and the generated javascript include file. |
11002 | schaersvoo | 185 | @ there is limited support for touch devices : touchstart,touchmove and touchend in commands <a href="#userdraw">userdraw primitives </a>, <a href="#protractor">protractor</a> and <a href="#ruler">ruler</a><br />only single finger gestures are supported (for now)<br />for more accurate user-interaction with canvasdraw on touch devices: use the command family <a href="userinput_xy">userinput</a> |
7614 | schaersvoo | 186 | */ |
187 | switch(type){ |
||
188 | case END: |
||
189 | finished = 1; |
||
190 | done = TRUE; |
||
191 | break; |
||
192 | case 0: |
||
193 | sync_input(infile); |
||
194 | break; |
||
195 | case COMMENT: |
||
196 | sync_input(infile); |
||
197 | break; |
||
11806 | schaersvoo | 198 | case AFFINE: |
7614 | schaersvoo | 199 | /* |
11806 | schaersvoo | 200 | @ affine a,b,c,d,tx,ty |
201 | @ defines a transformation matrix for subsequent objects |
||
202 | @ images drawn by setting skew params a & d will be very different from Flydraw's "affine a,b,c,d,e,tx,ty" !! |
||
203 | @ use keyword 'killaffine' to end the transformation |
||
204 | @ note 1: only 'draggable' / 'noclick' objects can be transformed. |
||
205 | @ note 2: do not use 'onclick' or 'drag xy' with tranformation objects : the mouse coordinates do not get transformed (yet) |
||
206 | @ note 3: no matrix operations on the transformation matrix implemented (yet) |
||
207 | @ a : Scales the drawings horizontally |
||
208 | @ b : Skews the drawings horizontally |
||
209 | @ c : Skews the drawings vertically |
||
210 | @ d : Scales the drawings vertically |
||
211 | @ tx: Moves the drawings horizontally in xrange coordinate system |
||
212 | @ ty: Moves the drawings vertically in yrange coordinate system |
||
213 | @ the data precision may be set by preceding command "precision int" |
||
7614 | schaersvoo | 214 | */ |
11806 | schaersvoo | 215 | for(i = 0 ; i<6;i++){ |
7614 | schaersvoo | 216 | switch(i){ |
11806 | schaersvoo | 217 | case 0: double_data[0] = get_real(infile,0);break; |
218 | case 1: double_data[1] = get_real(infile,0);break; |
||
219 | case 2: double_data[2] = get_real(infile,0);break; |
||
220 | case 3: double_data[3] = get_real(infile,0);break; |
||
221 | case 4: double_data[4] = get_real(infile,0);break; |
||
222 | case 5: double_data[5] = get_real(infile,1); |
||
223 | use_affine = TRUE; |
||
224 | decimals = find_number_of_digits(precision); |
||
225 | string_length = snprintf(NULL,0, "[%.*f,%.*f,%.*f,%.*f,%.*f,%.*f] ",decimals,double_data[0],decimals,double_data[1],decimals,double_data[2],decimals,double_data[3],decimals,double_data[4]*xsize/(xmax - xmin),decimals,-1*double_data[5]*ysize/(ymax - ymin)); |
||
226 | check_string_length(string_length);affine_matrix = my_newmem(string_length+1); |
||
227 | snprintf(affine_matrix,string_length,"[%.*f,%.*f,%.*f,%.*f,%.*f,%.*f] ",decimals,double_data[0],decimals,double_data[1],decimals,double_data[2],decimals,double_data[3],decimals,double_data[4]*xsize/(xmax - xmin),decimals,-1*double_data[5]*ysize/(ymax - ymin)); |
||
228 | break; |
||
7614 | schaersvoo | 229 | default: break; |
230 | } |
||
231 | } |
||
11806 | schaersvoo | 232 | break; |
8386 | schaersvoo | 233 | |
11806 | schaersvoo | 234 | case ANGLE: |
7614 | schaersvoo | 235 | /* |
11806 | schaersvoo | 236 | @ angle xc,yc,width,start_angle,end_angle,color |
237 | @ width is in x-range |
||
238 | @ will zoom in/out |
||
239 | @ if size is controlled by command <a href='#slider'>'slider'</a> use radians to set limits of slider. |
||
7614 | schaersvoo | 240 | */ |
11806 | schaersvoo | 241 | for(i=0;i<7;i++){ |
7614 | schaersvoo | 242 | switch(i){ |
11806 | schaersvoo | 243 | case 0:double_data[0] = get_real(infile,0);break; /* x-values */ |
244 | case 1:double_data[1] = get_real(infile,0);break; /* y-values */ |
||
245 | case 2:double_data[2] = get_real(infile,0);break; /* width in pixels ! */ |
||
246 | case 3:double_data[3] = get_real(infile,0);break; /* start angle in degrees */ |
||
247 | case 4:double_data[4] = get_real(infile,0);break; /* end angle in degrees */ |
||
248 | case 5:stroke_color = get_color(infile,1);/* name or hex color */ |
||
249 | decimals = find_number_of_digits(precision); |
||
250 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,17,[%.*f,%.*f],[%.*f,%.*f],[%.*f,%.*f],[%.*f,%.*f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[0],decimals,double_data[1],decimals,double_data[1],decimals,double_data[2],decimals,double_data[2],decimals,double_data[3],decimals,double_data[4],line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset); |
||
251 | reset(); |
||
252 | break; |
||
7614 | schaersvoo | 253 | } |
254 | } |
||
255 | break; |
||
8386 | schaersvoo | 256 | |
11806 | schaersvoo | 257 | case ANIMATE: |
7614 | schaersvoo | 258 | /* |
11806 | schaersvoo | 259 | @ animate type |
260 | @ REMOVED : this should be done with a slider |
||
261 | @ type may be "point" (nothing else , yet...) |
||
262 | @ the point is a filled rectangle ; adjust colour with command 'fillcolor colorname/hexnumber' |
||
263 | @ will animate a point on the next plot/curve command |
||
264 | @ the curve will not be draw |
||
265 | @ moves repeatedly from xmin to xmax |
||
7614 | schaersvoo | 266 | */ |
11806 | schaersvoo | 267 | if( strstr(get_string(infile,1),"point") != 0 ){animation_type = 15;}else{canvas_error("the only animation type (for now) is \"point\"...");} |
7614 | schaersvoo | 268 | break; |
8386 | schaersvoo | 269 | |
270 | |||
11806 | schaersvoo | 271 | case ARC: |
7614 | schaersvoo | 272 | /* |
11806 | schaersvoo | 273 | @ arc xc,yc,width,height,start_angle,end_angle,color |
274 | @ can <b>not</b> be set "onclick" or "drag xy" |
||
275 | @ <b>attention</b>: width in height in x/y-range |
||
276 | @ will not zoom in or zoom out (because radius is given in pixels an not in x/y-system !). Panning will work |
||
277 | @ use command <a href='#angle'>'angle'</a> for scalable angle |
||
7614 | schaersvoo | 278 | */ |
11806 | schaersvoo | 279 | for(i=0;i<7;i++){ |
280 | switch(i){ |
||
281 | case 0:double_data[0] = get_real(infile,0);break; /* x-values */ |
||
282 | case 1:double_data[1] = get_real(infile,0);break; /* y-values */ |
||
283 | case 2:double_data[2] = get_real(infile,0);break; /* width x-range no pixels ! */ |
||
284 | case 3:double_data[3] = get_real(infile,0);break; /* height y-range no pixels ! */ |
||
285 | case 4:double_data[4] = get_real(infile,0);break; /* start angle in degrees */ |
||
286 | case 5:double_data[5] = get_real(infile,0);break; /* end angle in degrees */ |
||
287 | case 6:stroke_color = get_color(infile,1);/* name or hex color */ |
||
288 | /* in Shape library: |
||
289 | x[0] = x[1] = xc = double_data[0] |
||
290 | y[0] = y[1] = yc = double_data[1] |
||
291 | w[0] = width = double_data[2] |
||
292 | w[1] = height = double_data[3] |
||
293 | h[0] = start_angle = double_data[4] |
||
294 | h[1] = end_angle = double_data[5] |
||
295 | */ |
||
296 | decimals = find_number_of_digits(precision); |
||
297 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,12,[%.*f,%.*f],[%.*f,%.*f],[%.*f,%.*f],[%.*f,%.*f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[0],decimals,double_data[1],decimals,double_data[1],decimals,double_data[2],decimals,double_data[3],decimals,double_data[4],decimals,double_data[5],line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset); |
||
298 | reset(); |
||
299 | break; |
||
300 | } |
||
301 | } |
||
7614 | schaersvoo | 302 | break; |
11806 | schaersvoo | 303 | case ARROW: |
7614 | schaersvoo | 304 | /* |
11806 | schaersvoo | 305 | @ arrow x1,y1,x2,y2,h,color |
306 | @ alternative : vector |
||
307 | @ draw a single headed arrow / vector from (x1:y1) to (x2:y2)<br />with arrowhead size h in px and in color 'color' |
||
308 | @ use command 'linewidth int' to adjust thickness of the arrow |
||
9406 | schaersvoo | 309 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
7614 | schaersvoo | 310 | */ |
11806 | schaersvoo | 311 | for(i=0;i<6;i++){ |
7614 | schaersvoo | 312 | switch(i){ |
313 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
314 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
11806 | schaersvoo | 315 | case 2: double_data[2] = get_real(infile,0);break; /* x */ |
316 | case 3: double_data[3] = get_real(infile,0);break; /* y */ |
||
317 | case 4: arrow_head = (int) get_real(infile,0);break;/* h */ |
||
318 | case 5: stroke_color = get_color(infile,1);/* name or hex color */ |
||
7614 | schaersvoo | 319 | decimals = find_number_of_digits(precision); |
11806 | schaersvoo | 320 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,8,[%.*f,%.*f],[%.*f,%.*f],[%d,%d],[%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,double_data[1],decimals,double_data[3],arrow_head,arrow_head,arrow_head,arrow_head,line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset); |
321 | if(onclick > 0){click_cnt++;} |
||
322 | /* click_cnt++;*/ |
||
323 | reset(); |
||
324 | break; |
||
325 | } |
||
326 | } |
||
327 | break; |
||
8386 | schaersvoo | 328 | |
11806 | schaersvoo | 329 | case ARROWS: |
7614 | schaersvoo | 330 | /* |
11806 | schaersvoo | 331 | @ arrows color,head (px),x1,y1,x2,y2...x_n,y_n |
332 | @ alternative : vectors |
||
333 | @ draw single headed arrows / vectors from (x1:y1) to (x2:y2) ... (x3:y3) to (x4:y4) etc ... in color 'color' |
||
334 | @ use command 'linewidth int' to adjust thickness of the arrow |
||
335 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually |
||
7614 | schaersvoo | 336 | */ |
337 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
338 | fill_color = stroke_color; |
||
11806 | schaersvoo | 339 | arrow_head = (int) get_real(infile,0);/* h */ |
7614 | schaersvoo | 340 | i=0; |
341 | while( ! done ){ /* get next item until EOL*/ |
||
342 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
343 | if(i%2 == 0 ){ |
||
344 | double_data[i] = get_real(infile,0); /* x */ |
||
345 | } |
||
346 | else |
||
347 | { |
||
348 | double_data[i] = get_real(infile,1); /* y */ |
||
349 | } |
||
350 | i++; |
||
351 | } |
||
352 | decimals = find_number_of_digits(precision); |
||
11806 | schaersvoo | 353 | for(c = 0 ; c < i-1 ; c = c+4){ |
354 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,8,[%.*f,%.*f],[%.*f,%.*f],[%d,%d],[%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+2],decimals,double_data[c+1],decimals,double_data[c+3],arrow_head,arrow_head,arrow_head,arrow_head,line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset); |
||
355 | if(onclick > 0){click_cnt++;} |
||
8379 | schaersvoo | 356 | /* click_cnt++; */ |
7614 | schaersvoo | 357 | } |
358 | reset(); |
||
359 | break; |
||
8386 | schaersvoo | 360 | |
11806 | schaersvoo | 361 | case ARROW2: |
7614 | schaersvoo | 362 | /* |
11806 | schaersvoo | 363 | @ arrow2 x1,y1,x2,y2,h,color |
364 | @ draw a double headed arrow/vector from (x1:y1) to (x2:y2)<br />with arrowhead size h in px and in color 'color' |
||
365 | @ use command 'arrowhead int' to adjust the arrow head size |
||
366 | @ use command 'linewidth int' to adjust thickness of the arrow |
||
9406 | schaersvoo | 367 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
7614 | schaersvoo | 368 | */ |
11806 | schaersvoo | 369 | for(i=0;i<6;i++){ |
7614 | schaersvoo | 370 | switch(i){ |
371 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
372 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
11806 | schaersvoo | 373 | case 2: double_data[2] = get_real(infile,0);break; /* x */ |
374 | case 3: double_data[3] = get_real(infile,0);break; /* y */ |
||
375 | case 4: arrow_head = (int) get_real(infile,0);break;/* h */ |
||
376 | case 5: stroke_color = get_color(infile,1);/* name or hex color */ |
||
377 | decimals = find_number_of_digits(precision); |
||
378 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,10,[%.*f,%.*f],[%.*f,%.*f],[%d,%d],[%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,double_data[1],decimals,double_data[3],arrow_head,arrow_head,arrow_head,arrow_head,line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset); |
||
379 | if(onclick > 0){click_cnt++;} |
||
380 | /* click_cnt++;*/ |
||
381 | reset(); |
||
382 | break; |
||
383 | } |
||
384 | } |
||
385 | break; |
||
8386 | schaersvoo | 386 | |
11806 | schaersvoo | 387 | case ARROWS2: |
7614 | schaersvoo | 388 | /* |
11806 | schaersvoo | 389 | @ arrows2 color,head (px),x1,y1,x2,y2...x_n,y_n |
390 | @ draw double headed arrows / vectors from (x1:y1) to (x2:y2) ... (x3:y3) to (x4:y4) etc ... in color 'color' |
||
391 | @ use command 'linewidth int' to adjust thickness of the arrows |
||
392 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually |
||
7614 | schaersvoo | 393 | */ |
394 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
395 | fill_color = stroke_color; |
||
11806 | schaersvoo | 396 | arrow_head = (int) get_real(infile,0);/* h */ |
7614 | schaersvoo | 397 | i=0; |
398 | while( ! done ){ /* get next item until EOL*/ |
||
399 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
400 | if(i%2 == 0 ){ |
||
401 | double_data[i] = get_real(infile,0); /* x */ |
||
402 | } |
||
403 | else |
||
404 | { |
||
405 | double_data[i] = get_real(infile,1); /* y */ |
||
406 | } |
||
407 | i++; |
||
408 | } |
||
8224 | bpr | 409 | decimals = find_number_of_digits(precision); |
11806 | schaersvoo | 410 | for(c = 0 ; c < i-1 ; c = c+4){ |
411 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,10,[%.*f,%.*f],[%.*f,%.*f],[%d,%d],[%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+2],decimals,double_data[c+1],decimals,double_data[c+3],arrow_head,arrow_head,arrow_head,arrow_head,line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset); |
||
412 | if(onclick > 0){click_cnt++;} |
||
8379 | schaersvoo | 413 | /* click_cnt++; */ |
11806 | schaersvoo | 414 | |
7614 | schaersvoo | 415 | } |
416 | reset(); |
||
417 | break; |
||
11806 | schaersvoo | 418 | case ARROWHEAD: |
9427 | schaersvoo | 419 | /* |
11806 | schaersvoo | 420 | @ arrowhead int |
421 | @ default 8 (pixels) |
||
9427 | schaersvoo | 422 | */ |
11806 | schaersvoo | 423 | arrow_head = (int) (get_real(infile,1)); |
424 | break; |
||
425 | |||
426 | case AUDIO: |
||
427 | /* |
||
428 | @ audio x,y,w,h,loop,visible,audiofile location |
||
429 | @ x,y : left top corner of audio element (in xrange / yrange) |
||
430 | @ w,y : width and height in pixels |
||
431 | @ loop : 0 or 1 ( 1 = loop audio fragment) |
||
432 | @ visible : 0 or 1 (1 = show controls) |
||
433 | @ audio format may be in *.mp3 or *.ogg |
||
434 | @ If you are using *.mp3 : be aware that FireFox will not (never) play this ! (Pattented format) |
||
435 | @ if you are using *.ogg : be aware that Microsoft based systems not support it natively |
||
436 | @ To avoid problems supply both types (mp3 and ogg) of audiofiles.<br />the program will use both as source tag |
||
437 | @ example: upload both audio1.ogg and audio1.mp3 to http://server/files/<br />audio 0,0,http://server/files/audio1.mp3<br />svdraw will copy html-tag audio1.mp3 to audio1.ogg<br /> and the browser will play the compatible file (audio1.ogg or audio1.mp3)<br /> |
||
438 | */ |
||
439 | if( js_function[DRAW_AUDIO] != 1 ){ js_function[DRAW_AUDIO] = 1;} |
||
440 | for(i=0;i<7;i++){ |
||
441 | switch(i){ |
||
442 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */ |
||
443 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system -> pixel */ |
||
444 | case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */ |
||
445 | case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */ |
||
446 | case 4: int_data[4] = (int) (get_real(infile,0)); if(int_data[4] != TRUE){int_data[4] = FALSE;} break; /* loop boolean */ |
||
447 | case 5: int_data[5] = (int) (get_real(infile,0)); if(int_data[5] != TRUE){int_data[5] = FALSE;} break; /* visible boolean */ |
||
448 | case 6: |
||
449 | temp = get_string(infile,1); |
||
450 | if( strstr(temp,".mp3") != 0 ){ temp = str_replace(temp,".mp3","");} |
||
451 | if( strstr(temp,".ogg") != 0 ){ temp = str_replace(temp,".ogg","");} |
||
452 | string_length = snprintf(NULL,0, "draw_audio(%d,%d,%d,%d,%d,%d,%d,\"%s.ogg\",\"%s.mp3\");\n",canvas_root_id,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],temp,temp); |
||
453 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
454 | snprintf(tmp_buffer,string_length,"draw_audio(%d,%d,%d,%d,%d,%d,%d,\"%s.ogg\",\"%s.mp3\");\n",canvas_root_id,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],temp,temp); |
||
455 | add_to_buffer(tmp_buffer); |
||
456 | break; |
||
457 | default:break; |
||
9427 | schaersvoo | 458 | } |
11806 | schaersvoo | 459 | } |
460 | reset(); |
||
461 | break; |
||
462 | |||
463 | |||
464 | case AXIS_NUMBERING: |
||
465 | /* |
||
466 | @ axisnumbering |
||
467 | @ keyword (no arguments required) |
||
468 | @ for special numbering of x-axis or y-axis see grid related commands <a href="#axis">axis</a> <a href="#xaxis">xaxis</a> , <a href="#xaxisup">xaxisup</a>, <a href="#noxaxis">noxaxis</a> ,<a href="#yaxis">yaxis</a> , <a href="#yaxisup">yaxisup</a>, <a href="#noyaxis">noyaxis</a> |
||
469 | @ to be used before command grid (see <a href="#grid">command grid</a>) |
||
470 | */ |
||
471 | use_axis_numbering = 1; |
||
472 | break; |
||
473 | case AXIS: |
||
474 | /* |
||
475 | @ axis |
||
476 | @ keyword (no arguments required) |
||
477 | @ to be used before command grid (see <a href="#grid">command grid</a>) |
||
478 | |||
479 | */ |
||
480 | use_axis = TRUE; |
||
481 | break; |
||
482 | |||
483 | case BARCHART: |
||
484 | /* |
||
485 | @ barchart x_1:y_1:color_1:x_2:y_2:color_2:...x_n:y_n:color_n |
||
486 | @ may <b>only</b> to be used together with command <a href='#grid'>'grid'</a> |
||
487 | @ can be used together with freestyle x-axis/y-axis texts : see commands <a href='#xaxis'>'xaxis'</a>,<a href='#xaxisup'>'xaxisup'</a> and <a href='#yaxis'>'yaxis'</a> |
||
488 | @ use command <a href='#legend'>'legend'</a> to provide an optional legend in right-top-corner |
||
489 | @ multiple barchart command may be used in a single script |
||
490 | @ also see command <a href='#piechart'>'piechart'</a> |
||
491 | @ note: your arguments are not checked by canvasdraw : use your javascript console in case of trouble... |
||
492 | */ |
||
493 | temp = get_string(infile,1); |
||
494 | if( strstr( temp,":" ) != 0 ){ temp = str_replace(temp,":","\",\""); } |
||
495 | fprintf(js_include_file,"var barchart_%d = [\"%s\"];",barchart_cnt,temp); |
||
496 | barchart_cnt++; |
||
497 | reset(); |
||
498 | break; |
||
499 | |||
500 | case BEZIER: |
||
501 | /* |
||
502 | @ bezier color,x_start,y_start,x_first,y_first,x_second,y_second,x_end,y_end |
||
503 | @ draw a bezier curve between points, starting from (x_start:y_start) |
||
504 | @ can <b>not</b> be dragged or set onclick |
||
505 | */ |
||
506 | if( js_function[DRAW_BEZIER] != 1 ){ js_function[DRAW_BEZIER] = 1;} |
||
507 | decimals = find_number_of_digits(precision); |
||
508 | for(i = 0 ; i < 9; i++){ |
||
509 | switch(i){ |
||
510 | case 0: stroke_color = get_color(infile,0);break; |
||
511 | case 1: double_data[0] = get_real(infile,0);break;/* start x */ |
||
512 | case 2: double_data[1] = get_real(infile,0);break;/* start y */ |
||
513 | case 3: double_data[2] = get_real(infile,0);break;/*The x-coordinate of the first Bézier control point */ |
||
514 | case 4: double_data[3] = get_real(infile,0);break;/*The y-coordinate of the first Bézier control point */ |
||
515 | case 5: double_data[4] = get_real(infile,0);break;/*The x-coordinate of the second Bézier control point */ |
||
516 | case 6: double_data[5] = get_real(infile,0);break;/*The y-coordinate of the second Bézier control point */ |
||
517 | case 7: double_data[6] = get_real(infile,0);break;/*The x-coordinate of the Bézier end point */ |
||
518 | case 8: double_data[7] = get_real(infile,1);/*The y-coordinate of the Bézier end point */ |
||
519 | string_length = snprintf(NULL,0,"draw_bezier(%d,%d,[%f,%f,%f,%f,%f,%f,%f,%f],\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.2f,%d,%s);",STATIC_CANVAS,line_width,double_data[0],double_data[1],double_data[2],double_data[3],double_data[4],double_data[5],double_data[6],double_data[7],fill_color,fill_opacity,stroke_color,stroke_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,use_affine,affine_matrix); |
||
520 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
521 | snprintf(tmp_buffer,string_length,"draw_bezier(%d,%d,[%f,%f,%f,%f,%f,%f,%f,%f],\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.2f,%d,%s);",STATIC_CANVAS,line_width,double_data[0],double_data[1],double_data[2],double_data[3],double_data[4],double_data[5],double_data[6],double_data[7],fill_color,fill_opacity,stroke_color,stroke_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,use_affine,affine_matrix); |
||
522 | add_to_buffer(tmp_buffer); |
||
523 | break; |
||
524 | default: break; |
||
9427 | schaersvoo | 525 | } |
526 | } |
||
527 | reset(); |
||
528 | break; |
||
11806 | schaersvoo | 529 | |
530 | |||
531 | case BGCOLOR: |
||
9427 | schaersvoo | 532 | /* |
11806 | schaersvoo | 533 | @ bgcolor colorname or #hex |
534 | @ use this color as background of the "div" containing the canvas(es) |
||
9427 | schaersvoo | 535 | */ |
11806 | schaersvoo | 536 | /* [255,255,255]*/ |
537 | bgcolor = get_string(infile,1); |
||
538 | if(strstr(bgcolor,"#") == NULL){ /* convert colorname -> #ff00ff */ |
||
539 | int found = 0; |
||
540 | for( i = 0; i < NUMBER_OF_COLORNAMES ; i++ ){ |
||
541 | if( strcmp( colors[i].name , bgcolor ) == 0 ){ |
||
542 | bgcolor = colors[i].hex; |
||
543 | found = 1; |
||
544 | break; |
||
545 | } |
||
9427 | schaersvoo | 546 | } |
11806 | schaersvoo | 547 | if(found == 0){canvas_error("your bgcolor is not in my rgb.txt data list : use hexcolor...something like #a0ffc4");} |
548 | } |
||
549 | fprintf(js_include_file,"<!-- set background color of canvas div -->\ncanvas_div.style.backgroundColor = \"%s\";canvas_div.style.opacity = %f;\n",bgcolor,fill_opacity); |
||
550 | break; |
||
551 | |||
552 | case BGIMAGE: |
||
553 | /* |
||
554 | @ bgimage image_location |
||
555 | @ use an image as background .<br />technical: we use the background of 'canvas_div' |
||
556 | @ the background image will be resized to match "width = xsize" and "height = ysize" |
||
557 | */ |
||
558 | URL = get_string(infile,1); |
||
559 | fprintf(js_include_file,"<!-- set background image to canvas div -->\ncanvas_div.style.backgroundImage = \"url(%s)\";canvas_div.style.backgroundSize = \"%dpx %dpx\";\n",URL,xsize,ysize); |
||
560 | break; |
||
561 | |||
562 | case BLINK: |
||
563 | /* |
||
564 | @ blink time(seconds) |
||
565 | @ NOT IMPLEMETED -YET |
||
566 | */ |
||
567 | break; |
||
568 | |||
569 | case BOXPLOT: |
||
570 | /* |
||
571 | @ boxplot x_or_y,box-height_or_box-width,position,min,Q1,median,Q3,max |
||
572 | @ example:<br />xrange 0,300<br />yrange 0,10<br />boxplot x,4,8,120,160,170,220,245<br />meaning: create a boxplot in x-direction, with height 4 (in yrange) and centered around line y=8 |
||
573 | @ example:<br />xrange 0,10<br />yrange 0,300<br />boxplot y,4,8,120,160,170,220,245<br />meaning: create a boxplot in y-direction, with width 4 (in xrange) and centered around line x=8 |
||
574 | @ use command <a href='filled'>'filled'</a> to fill the box<br /><b>note:</b> the strokecolor is used for filling Q1, the fillcolor is used for filling Q3 |
||
575 | @ use command <a href='#opacity'>'opacity'</a> to adjust fill_opacity of stroke and fill colours |
||
576 | @ use command <a href='#legend'>'legend'</a> to automatically create a legend <br />unicode allowed in legend<br />use command 'fontfamily' to set the font of the legend. |
||
577 | @ there is no limit to the number of boxplots used. |
||
578 | @ can <b>not</b> be set draggable (<a href='#onclick'>'onclick'</a> is not ready ,yet) |
||
579 | @ use keyword <a href="#userboxplot">'userboxplot'</a> before command boxplot, if a pupil must draw a boxplot (using his own min,Q1,median,Q3,max data) |
||
580 | @ use keyword <a href="#userboxplotdata">'userboxplotdata'</a> before command boxplot, if a pupil must generate the data by some means. |
||
581 | @ use command <a href="#boxplotdata">'boxplotdata'</a> when the boxplot should be drawn from wims-generated raw statistical date |
||
582 | */ |
||
583 | if( js_function[DRAW_BOXPLOT] != 1 ){ js_function[DRAW_BOXPLOT] = 1;} |
||
584 | for(i=0;i<8;i++){ |
||
585 | switch(i){ |
||
586 | case 0: temp = get_string_argument(infile,0); |
||
587 | if( strstr(temp,"x") != 0){int_data[0] = 1;}else{int_data[0] = 0;} break; /* x or y */ |
||
588 | case 1: double_data[0] = get_real(infile,0);break;/* height | width */ |
||
589 | case 2: |
||
590 | if( js_function[DRAW_JSBOXPLOT] == 0 ){ |
||
591 | double_data[1] = get_real(infile,0); |
||
592 | fprintf(js_include_file,"var boxplot_source = 0;\n");/* we use given min,Q1,median,Q3,max */ |
||
593 | } |
||
594 | else |
||
595 | { |
||
596 | double_data[1] = get_real(infile,1); |
||
597 | double_data[2] = 1; |
||
598 | double_data[3] = 1; |
||
599 | double_data[4] = 1; |
||
600 | double_data[5] = 1; |
||
601 | double_data[6] = 1; |
||
602 | double_data[7] = 1; |
||
603 | i=8; |
||
604 | } |
||
605 | break;/* center value x or y */ |
||
606 | case 3: double_data[2] = get_real(infile,0); break;/* min */ |
||
607 | case 4: double_data[3] = get_real(infile,0); break;/* Q1 */ |
||
608 | case 5: double_data[4] = get_real(infile,0); break;/* median */ |
||
609 | case 6: double_data[5] = get_real(infile,0); break;/* Q3 */ |
||
610 | case 7: double_data[6] = get_real(infile,1); break;/* max */ |
||
611 | default:break; |
||
9427 | schaersvoo | 612 | } |
613 | } |
||
614 | decimals = find_number_of_digits(precision); |
||
11806 | schaersvoo | 615 | /*function draw_boxplot(canvas_type,xy,hw,cxy,data,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype0,dashtype1)*/ |
616 | string_length = snprintf(NULL,0, "draw_boxplot(%d,%d,%.*f,%.*f,[%.*f,%.*f,%.*f,%.*f,%.*f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d);\n",BOXPLOT_CANVAS+boxplot_cnt,int_data[0],decimals,double_data[0],decimals,double_data[1],decimals,double_data[2],decimals,double_data[3],decimals,double_data[4],decimals,double_data[5],decimals,double_data[6],line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1]); |
||
617 | check_string_length(string_length); |
||
618 | tmp_buffer = my_newmem(string_length+1); |
||
619 | snprintf(tmp_buffer,string_length, "draw_boxplot(%d,%d,%.*f,%.*f,[%.*f,%.*f,%.*f,%.*f,%.*f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d);\n",BOXPLOT_CANVAS+boxplot_cnt,int_data[0],decimals,double_data[0],decimals,double_data[1],decimals,double_data[2],decimals,double_data[3],decimals,double_data[4],decimals,double_data[5],decimals,double_data[6],line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1]); |
||
620 | add_to_buffer(tmp_buffer); |
||
621 | boxplot_cnt++; |
||
622 | reset(); |
||
623 | break; |
||
624 | case BOXPLOTDATA: |
||
625 | /* |
||
626 | @ boxplotdata some_data |
||
627 | @ 'some_data' are a list of numbers separated by a comma "," (items) |
||
628 | @ only be used before command 'boxplot': the command <a href="#boxplot">'boxplot'</a> will provide the boxplot drawing of the data. |
||
629 | @ xrange 0,100<br />yrange 0,10<br />boxplotdata 11,22,13,15,23,43,12,12,14,2,45,32,44,13,21,24,13,19,35,21,24,23<br />boxplot x,4,5 |
||
630 | @ note: wims will not check your data input | format. use js-error console to debug any problems. |
||
631 | @ a javascript function 'statistics()' will parse the data and calculate the values [min,Q1,median,Q3,max] and hand them to the boxplot draw function. |
||
632 | */ |
||
633 | if( js_function[DRAW_JSBOXPLOT] != 1 ){ js_function[DRAW_JSBOXPLOT] = 1;} |
||
634 | if( js_function[DRAW_BOXPLOT] != 1 ){ js_function[DRAW_BOXPLOT] = 1;} |
||
635 | fprintf(js_include_file,"var boxplot_source = 1;var jsboxplot_data = [%s];\n",get_string(infile,1)); |
||
636 | |||
637 | break; |
||
638 | |||
639 | case CANVASTYPE: |
||
640 | canvas_type = (int) (get_real(infile,1)); |
||
641 | /* |
||
642 | @ canvastype TYPE |
||
643 | @ for now only usefull before commands filltoborder / floodfill / clickfill etc operations<br />Only the images of this TYPE will be scanned and filled |
||
644 | @ default value of TYPE is DRAG_CANVAS e.g. 5 (all clickable / draggable object are in this canvas) |
||
645 | @ use another TYPE, if you know what you are doing... |
||
646 | @ other possible canvasses (transparent PNG pictures xsize x ysize on top of each other)<ul><li> EXTERNAL_IMAGE_CANVAS 0</li><li> BG_CANVAS 1</li><li> STATIC_CANVAS 2</li><li> MOUSE_CANVAS 3</li><li> GRID_CANVAS 4</li><li> DRAG_CANVAS 5</li><li> DRAW_CANVAS 6</li><li> TEXT_CANVAS 7</li><li> CLOCK_CANVAS 8</li><li> ANIMATE_CANVAS 9</li><li> TRACE_CANVAS 10</li><li>BOXPLOT_CANVAS 11</li><li> JSPLOT_CANVAS 100 , will increase with every call</li><li> FILL_CANVAS 200 , will increase with every call </li><li> USERDRAW_JSPLOT 300 , will increase with every call </li><li>CLICKFILL_CANVAS 400 , will increase with every call/click</li><li>BOXPLOT_CANVAS 500 , will increase with every call</li></ul> |
||
647 | */ |
||
648 | break; |
||
649 | |||
650 | case CENTERSTRING: |
||
651 | /* |
||
652 | @ centerstring color,y-value,the text string |
||
653 | @ title color,y-value,the text string |
||
654 | @ draw a string centered on the canvas at y = y-value |
||
655 | @ can not be set "onclick" or "drag xy" (...) |
||
656 | @ unicode supported: centerstring red,5,\\u2232 |
||
657 | @ use a command like 'fontfamily italic 24px Ariel' <br />to set fonts on browser that support font change |
||
658 | */ |
||
659 | if( js_function[DRAW_CENTERSTRING] != 1 ){ js_function[DRAW_CENTERSTRING] = 1;} |
||
660 | for(i=0;i<3;i++){ |
||
661 | switch(i){ |
||
662 | case 0: stroke_color = get_color(infile,0);break;/* name or hex color */ |
||
663 | case 1: double_data[0] = get_real(infile,0);break; /* y in xrange*/ |
||
664 | case 2: temp = get_string_argument(infile,1); |
||
665 | /* draw_text = function(canvas_type,y,font_family,stroke_color,stroke_opacity,text) */ |
||
666 | decimals = find_number_of_digits(precision); |
||
667 | string_length = snprintf(NULL,0, |
||
668 | "draw_centerstring(%d,%.*f,\"%s\",\"%s\",%.2f,\"%s\");\n",canvas_root_id,decimals,double_data[0],font_family,stroke_color,stroke_opacity,temp); |
||
669 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
670 | snprintf(tmp_buffer,string_length,"draw_centerstring(%d,%.*f,\"%s\",\"%s\",%.2f,\"%s\");\n",canvas_root_id,decimals,double_data[0],font_family,stroke_color,stroke_opacity,temp); |
||
671 | add_to_buffer(tmp_buffer); |
||
672 | break; |
||
673 | default:break; |
||
674 | } |
||
9427 | schaersvoo | 675 | } |
676 | break; |
||
8386 | schaersvoo | 677 | |
11806 | schaersvoo | 678 | |
8386 | schaersvoo | 679 | case CIRCLE: |
8299 | schaersvoo | 680 | /* |
8386 | schaersvoo | 681 | @ circle xc,yc,width (2*r in pixels),color |
9383 | schaersvoo | 682 | @ use command 'fcircle xc,yc,d,color' |
683 | @ alternative: disk for a filled circle |
||
8386 | schaersvoo | 684 | @ use command 'fillcolor color' to set the fillcolor |
9406 | schaersvoo | 685 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
8386 | schaersvoo | 686 | @ will shrink / expand on zoom out / zoom in |
8299 | schaersvoo | 687 | */ |
8386 | schaersvoo | 688 | for(i=0;i<4;i++){ |
689 | switch(i){ |
||
690 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
691 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
692 | case 2: double_data[2] = px2x((get_real(infile,0))/2) - px2x(0);break; /* for zoom in/out : radius in 'dx' xrange*/ |
||
693 | case 3: stroke_color = get_color(infile,1);/* name or hex color */ |
||
694 | decimals = find_number_of_digits(precision); |
||
11802 | schaersvoo | 695 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,13,[%.*f],[%.*f],[%.3f],[%.3f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[1],double_data[2],double_data[2],line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset); |
8386 | schaersvoo | 696 | if(onclick > 0){click_cnt++;} |
697 | /* click_cnt++;*/ |
||
698 | reset(); |
||
699 | break; |
||
700 | default : break; |
||
701 | } |
||
702 | } |
||
703 | break; |
||
704 | |||
705 | case CIRCLES: |
||
706 | /* |
||
707 | @ circles color,xc1,yc1,r1,xc2,yc2,r2...xc_n,yc_n,r_n |
||
9383 | schaersvoo | 708 | @ <b>attention</b> r = radius in x-range (!) |
709 | @ use keyword 'filled' or command 'fcircles' to produce solid circles |
||
710 | @ alternative : disks for filled circles |
||
8386 | schaersvoo | 711 | @ use command 'fillcolor color' to set the fillcolor |
9406 | schaersvoo | 712 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> (individually) |
8386 | schaersvoo | 713 | @ will shrink / expand on zoom out / zoom in |
714 | */ |
||
8299 | schaersvoo | 715 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
716 | fill_color = stroke_color; |
||
8386 | schaersvoo | 717 | i=1; |
8299 | schaersvoo | 718 | while( ! done ){ /* get next item until EOL*/ |
719 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
8386 | schaersvoo | 720 | switch (i%3){ |
721 | case 1:double_data[i-1] = get_real(infile,0);break; /* x */ |
||
722 | case 2:double_data[i-1] = get_real(infile,0);break; /* y */ |
||
723 | case 0:double_data[i-1] = get_real(infile,1);break; /* r */ |
||
8299 | schaersvoo | 724 | } |
725 | i++; |
||
726 | } |
||
727 | decimals = find_number_of_digits(precision); |
||
8386 | schaersvoo | 728 | for(c = 0 ; c < i-1 ; c = c+3){ |
11802 | schaersvoo | 729 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,13,[%.*f],[%.*f],[%.3f],[%.3f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+1],double_data[c+2],double_data[c+2],line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset); |
8379 | schaersvoo | 730 | if(onclick > 0){click_cnt++;} |
8386 | schaersvoo | 731 | /* click_cnt++; */ |
8299 | schaersvoo | 732 | } |
733 | reset(); |
||
734 | break; |
||
11806 | schaersvoo | 735 | case CLEARBUTTON: |
736 | /* |
||
737 | @ clearbutton value |
||
738 | @ alternative : delete |
||
739 | @ alternative : erase |
||
740 | @ adds a button to clear the <a href="#userdraw">userdraw</a> canvas with text 'value' |
||
741 | @ <b>attention</b> command 'clearbutton' is incompatible with <a href="multidraw">multidraw</a> based drawings<br/>(in 'multidraw' there is always a remove_object_button for every drawprimitive) |
||
742 | @ normally <a href="#userdraw">userdraw</a> primitives have the option to use middle/right mouse button on<br /> a point of the object to remove this specific object...this clear button will remove all drawings |
||
743 | @ uses the tooltip placeholder div element: may not be used with command 'intooltip' |
||
744 | @ use command <a href="#inputstyle">'inputstyle'</a> to style the button... |
||
745 | @ the clearbutton will have id="canvas_scripts[%d]" ; starting with %d=0 for the first script<br />to change the style of all "clearbutton" of all included canvasdraw scripts, use something like<br /><em>if(document.getElementById("clearbutton"+canvas_scripts[0])){<br /> var p = 0;<br /> while(document.getElementById("clearbutton"+canvas_scripts[p])){<br /> document.getElementById("clearbutton"+canvas_scripts[p]).className="some_class_name";<br /> <!−− or document.getElementById("clearbutton"+canvas_scripts[p]).setAttribute("style","some_style"); −−><br /> p++;<br /> };<br />};<br /> |
||
746 | */ |
||
747 | if(reply_format == 29){/* eg multidraw is selected */ |
||
748 | canvas_error("command clearbutton incompatible with multidraw...only suitable for userdraw"); |
||
749 | } |
||
750 | add_clear_button(js_include_file,canvas_root_id,input_style,get_string(infile,1)); |
||
751 | break; |
||
8386 | schaersvoo | 752 | |
11806 | schaersvoo | 753 | case CLOCK: |
7614 | schaersvoo | 754 | /* |
11806 | schaersvoo | 755 | @ clock x,y,r(px),H,M,S,type hourglass,interactive [ ,H_color,M_color,S_color,background_color,foreground_color ] |
756 | @ use command 'opacity stroke-opacity,fill-opacity' to adjust foreground (stroke) and background (fill) transparency |
||
757 | @ type hourglass:<br />type = 0 : only segments<br />type = 1 : only numbers<br />type = 2 : numbers and segments |
||
758 | @ colors are optional: if not defined, default values will be used<br />default colours: clock 0,0,60,4,35,45,1,2<br />custom colours: clock 0,0,60,4,35,45,1,2,,,,yellow,red<br />custom colours: clock 0,0,60,4,35,45,1,2,white,green,blue,black,yellow |
||
759 | @ if you don't want a seconds hand (or minutes...), just make it invisible by using the background color of the hourglass... |
||
760 | @ interactive <ul><li>0 : not interactive, just clock(s)</li><li>1 : function read_canvas() will read all active clocks in H:M:S format<br />The active clock(s) can be adjusted by pupils</li><li>2 : function read_canvas() will return the clicked clock <br />(like multiplechoice; first clock in script in nr. 0 )</li><li>3: no prefab buttons...create your own buttons (or other means) to make the clock(s) adjustable by javascript function set_clock(num,type,diff)<br />wherein: num = clock id (starts with 0) ; type = 1 (hours) ; type = 2 (minutes) ; type = 3 (seconds) <br />and diff = the increment of 'type' (positive or negative) </li></ul> |
||
761 | @ canvasdraw will not check validity of colornames...the javascript console is your best friend |
||
762 | @ no combinations with other reply_types allowed, for now |
||
763 | @ if interactive is set to '1', 6 buttons per clock will be displayed for adjusting a clock (H+ M+ S+ H- M- S-)<br /> set_clock(clock_id,type,incr) <br />first clock has clock_id=0 ; type : H=1,M=2,S=3 ; incr : increment integer |
||
764 | @ note: if you need multiple -interactive- clocks on a webpage, use multiple 'clock' commands in a single script !<br />and <i>not multiple canvas scripts</i> in a single page |
||
765 | @ note: clocks will not zoom or pan, when using command <a href='#zoom'>'zoom'</a> |
||
7614 | schaersvoo | 766 | */ |
11806 | schaersvoo | 767 | if( js_function[DRAW_CLOCK] != 1 ){ js_function[DRAW_CLOCK] = 1;} |
768 | |||
769 | /* var clock = function(xc,yc,radius,H,M,S,h_color,m_color,s_color,bg_color,fg_color) */ |
||
770 | for(i=0;i<9;i++){ |
||
771 | switch(i){ |
||
772 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* xc */ |
||
773 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* yc */ |
||
774 | case 2: int_data[2] = get_real(infile,0);break;/* radius in px */ |
||
775 | case 3: int_data[3] = get_real(infile,0);break;/* hours */ |
||
776 | case 4: int_data[4] = get_real(infile,0);break;/* minutes */ |
||
777 | case 5: int_data[5] = get_real(infile,0);break;/* seconds */ |
||
778 | case 6: int_data[6] = get_real(infile,0);if(int_data[6] < 0 || int_data[6] > 2){canvas_error("hourglass can be 0,1 or 2");}break;/* type hourglass */ |
||
779 | case 7: int_data[7] = (int)(get_real(infile,1));/* interactive 0,1,2*/ |
||
780 | switch(int_data[7]){ |
||
781 | case 0:break; |
||
782 | case 1:if(clock_cnt == 0){ |
||
783 | if( reply_format == 0 ){ |
||
784 | reply_format = 18; /* user sets clock */ |
||
785 | /* string_length = snprintf(NULL,0,"set_clock = function(num,type,diff){var name = eval(\"clocks\"+num);switch(type){case 1:name.H = parseInt(name.H+diff);break;case 2:name.M = parseInt(name.M+diff);break;case 3:name.S = parseInt(name.S+diff);break;default: break;};name = clock(name.xc,name.yc,name.radius,name.H,name.M,name.S,name.type,name.interaction,name.H_color,name.M_color,name.S_color,name.bg_color,name.fg_color);};\n"); |
||
786 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
787 | snprintf(tmp_buffer,string_length,"set_clock = function(num,type,diff){var name = eval(\"clocks\"+num);switch(type){case 1:name.H = parseInt(name.H+diff);break;case 2:name.M = parseInt(name.M+diff);break;case 3:name.S = parseInt(name.S+diff);break;default: break;};name = clock(name.xc,name.yc,name.radius,name.H,name.M,name.S,name.type,name.interaction,name.H_color,name.M_color,name.S_color,name.bg_color,name.fg_color);};\n"); |
||
788 | add_to_buffer(tmp_buffer); |
||
789 | */ |
||
790 | fprintf(js_include_file,"set_clock = function(num,type,diff){if(wims_status == \"done\"){return;};var name = eval(\"clocks\"+num);switch(type){case 1:name.H = parseInt(name.H+diff);break;case 2:name.M = parseInt(name.M+diff);break;case 3:name.S = parseInt(name.S+diff);break;default: break;};name = new clock(name.xc,name.yc,name.radius,name.H,name.M,name.S,name.type,name.interaction,name.H_color,name.M_color,name.S_color,name.bg_color,name.fg_color);};\n"); |
||
791 | } |
||
792 | else |
||
793 | { |
||
794 | canvas_error("interactive clock may not be used together with other reply_types..."); |
||
795 | } |
||
796 | } |
||
797 | fprintf(stdout,"<p style=\"text-align:center\"><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,1,1)\" value=\"H+\" /><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,2,1)\" value=\"M+\" /><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,3,1)\" value=\"S+\" /><br /><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,1,-1)\" value=\"H−\" /><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−\" /></p>",input_style,clock_cnt,input_style,clock_cnt,input_style,clock_cnt,input_style,clock_cnt,input_style,clock_cnt,input_style,clock_cnt); |
||
798 | break; |
||
799 | case 3:if(clock_cnt == 0){ |
||
800 | if( reply_format == 0 ){ |
||
801 | reply_format = 18; /* user sets clock */ |
||
802 | fprintf(js_include_file,"set_clock = function(num,type,diff){if(wims_status == \"done\"){return;};var name = eval(\"clocks\"+num);switch(type){case 1:name.H = parseInt(name.H+diff);break;case 2:name.M = parseInt(name.M+diff);break;case 3:name.S = parseInt(name.S+diff);break;default: break;};name = new clock(name.xc,name.yc,name.radius,name.H,name.M,name.S,name.type,1,name.H_color,name.M_color,name.S_color,name.bg_color,name.fg_color);};\n"); |
||
803 | } |
||
804 | else |
||
805 | { |
||
806 | canvas_error("interactive clock may not be used together with other reply_types..."); |
||
807 | } |
||
808 | } |
||
809 | /* |
||
810 | fprintf(stdout,"<p style=\"text-align:center\"><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,1,1)\" value=\"H+\" /><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,2,1)\" value=\"M+\" /><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,3,1)\" value=\"S+\" /><br /><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,1,-1)\" value=\"H−\" /><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−\" /></p>",input_style,clock_cnt,input_style,clock_cnt,input_style,clock_cnt,input_style,clock_cnt,input_style,clock_cnt,input_style,clock_cnt); |
||
811 | */ |
||
812 | break; |
||
813 | case 2:if( reply_format == 0 ){ |
||
814 | reply_format = 19; /* "onclick */ |
||
815 | fprintf(js_include_file,"\n<!-- begin onclick handler for clocks -->\nvar reply = new Array();canvas_div.addEventListener( 'mousedown', user_click,false);\n\nfunction user_click(evt){if(evt.which == 1){var canvas_rect = clock_canvas.getBoundingClientRect();var x = evt.clientX - canvas_rect.left;var y = evt.clientY - canvas_rect.top;var p = 0;var name;var t = true;while(t){try{name = eval('clocks'+p);if( x < name.xc + name.radius && x > name.xc - name.radius ){if( y < name.yc + name.radius && y > name.yc - name.radius ){reply[0] = p;name = new clock(name.xc,name.yc,name.radius,name.H,name.M,name.S,name.type,name.interaction,name.H_color,name.M_color,name.S_color,\"lightblue\",name.fg_color);};}else{clock_ctx.clearRect(name.xc-name.radius,name.yc-name.radius,name.xc+name.radius,name.yc+name.radius);name = new clock(name.xc,name.yc,name.radius,name.H,name.M,name.S,name.type,name.interaction,name.H_color,name.M_color,name.S_color,name.bg_color,name.fg_color);};p++;}catch(e){t=false;};};};};\n"); |
||
816 | } |
||
817 | else |
||
818 | { |
||
819 | if( reply_format != 19){ |
||
820 | canvas_error("clickable clock(s) may not be used together with other reply_types..."); |
||
821 | } |
||
822 | } |
||
823 | break; |
||
824 | default: canvas_error("interactive must be set 0,1 or 2");break; |
||
825 | } |
||
826 | break; |
||
827 | case 8: |
||
828 | if(clock_cnt == 0 ){ /* set opacity's just once .... it should be a argument to clock() , for now it's OK */ |
||
829 | fprintf(js_include_file,"var clock_bg_opacity = %.2f;var clock_fg_opacity = %.2f;",fill_opacity,stroke_opacity); |
||
830 | } |
||
831 | temp = get_string(infile,3);/* optional colors, like: ,,red,,blue*/ |
||
832 | if( strstr( temp,",") != 0 ){ temp = str_replace(temp,",","\",\""); } |
||
833 | else{ |
||
834 | /* h_color,m_color,s_color,bg_color,fg_color */ |
||
835 | temp = ",black\",\"black\",\"red\",\"white\",\"black";} |
||
836 | string_length = snprintf(NULL,0,"clocks%d = new clock(%d,%d,%d,%d,%d,%d,%d,%d,\"%s\");\n",clock_cnt,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],temp); |
||
837 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
838 | snprintf(tmp_buffer,string_length,"clocks%d = new clock(%d,%d,%d,%d,%d,%d,%d,%d,\"%s\");\n",clock_cnt,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],temp); |
||
839 | add_to_buffer(tmp_buffer); |
||
840 | fprintf(js_include_file,"var clocks%d;",clock_cnt); |
||
841 | clock_cnt++; |
||
842 | break; |
||
843 | default:break; |
||
844 | } |
||
845 | } |
||
846 | break; |
||
847 | |||
848 | |||
849 | case COLORPALETTE: |
||
850 | /* |
||
851 | @ colorpalette color_name_1,color_name_2,...,color_name_8 |
||
852 | @ opacity will be the same for all colors and is set by command <a href="#opacity">opacity [0-255],[0-255]</a> |
||
853 | @ can be used with command <a href='#userdraw'>'userdraw clickfill,color'</a> when more than one fillcolor is wanted.<br />in that case use for example <a href='#replyformat'>replyformat 10</a> ... reply=x1:y1:color1,x2:y2:color2...<br />the pupil can choose from the given colors by clicking small coloured buttons.<br /> the click coordinates and corresponding fillcolor will be stored in read_canvas()...when using the appropriate replyformat.<br />the first color of the palette is color=0 |
||
854 | @ make sure to include the 'remove button' by using command <a href='#clearbutton'>clearbutton some_text</a> |
||
855 | */ |
||
856 | if( use_tooltip == 1 ){canvas_error("command 'colorpalette' is incompatible with command 'intooltip tip_text'");} |
||
857 | fprintf(js_include_file,"var multifillcolors = [];var palettecolors = ["); |
||
858 | while( ! done ){ |
||
859 | temp = get_color(infile,1); |
||
860 | fprintf(js_include_file,"\"%s\",",temp); |
||
861 | } |
||
862 | fprintf(js_include_file,"];");/* add black to avoid trouble with dangling comma... */ |
||
863 | add_color_palette(js_include_file,canvas_root_id,input_style); |
||
864 | break; |
||
865 | |||
866 | case COPY: |
||
867 | /* |
||
868 | @ copy x,y,x1,y1,x2,y2,[filename URL] |
||
869 | @ The image may be "bitmap" or "SVG" |
||
870 | @ Insert the region from (x1,y1) to (x2,y2) (in pixels) of [filename] to (x,y) in x/y-range |
||
871 | @ If x1=y1=x2=y2=-1, the whole [filename URL] is copied. |
||
872 | @ [filename] is the URL of the image |
||
873 | @ URL is normal URL of network reachable image file location<br />(eg special url for 'classexo' not -yet- implemented) |
||
874 | @ if command <a href="#drag">'drag x/y/xy'</a> is set before command 'copy', the images will be draggable<br />javascript function read_canvas(); will return the x/y coordinate data in xrange/yrange of all -including non draggable- images<br />the command drag is only valid for the next image<br />draggable / non-draggable images may be mixed<br />may be used together with preceding keywords 'snaptogrid','xsnaptogrid','ysnaptogrid' or 'snaptopoints x1,y1,x2,y2...' |
||
875 | @ if keyword <a href="#onclick">'onclick'</a> is set before command 'copy' the image(s) is clickable (marked with a green rectangle around the image)<br />use 'read_dragdrop' to get the number of the clicked image(s)<br />use command 'clearbutton some_text' to reset the reply/click array.<br />example: 4 images; student clicked on image 2 and 3 : reply = 0,1,1,0<br />after clicking the clear button: reply = 0,0,0,0<br />May be mixed with commands 'drag x|y|xy' (use javascript read_canvas to get the new coordinates |
||
876 | @ 'onclick' for external images may be mixed with canvas generated stuff (like lines,curves etc) |
||
877 | @ you may draw / userdraw / drag other stuff on top of an "imported" image |
||
878 | */ |
||
879 | for(i = 0 ; i<7;i++){ |
||
7614 | schaersvoo | 880 | switch(i){ |
11806 | schaersvoo | 881 | case 0: int_data[0]=x2px(get_real(infile,0));break; /* x left top corner in x/y range */ |
882 | case 1: int_data[1]=y2px(get_real(infile,0));break; /* y left top corner in x/y range */ |
||
883 | case 2: int_data[2]=(int)(get_real(infile,0));break;/* x1 in px of external image */ |
||
884 | case 3: int_data[3]=(int)(get_real(infile,0));break;/* y1 in px of external image */ |
||
885 | case 4: int_data[4]=(int)(get_real(infile,0));break;/* x2 --> width */ |
||
886 | case 5: int_data[5]=(int)(get_real(infile,0)) ;break;/* y2 --> height */ |
||
887 | case 6: URL = get_string(infile,1); |
||
888 | int_data[6] = int_data[4] - int_data[2];/* swidth & width (if not scaling )*/ |
||
889 | int_data[7] = int_data[5] - int_data[3];/* sheight & height (if not scaling )*/ |
||
890 | if( js_function[DRAW_EXTERNAL_IMAGE] != 1 ){ js_function[DRAW_EXTERNAL_IMAGE] = 1;} |
||
891 | int_data[9] = click_cnt; |
||
892 | if( drag_type > -1 ){/* e.g. we are dragging images x/y/xy */ |
||
893 | if( reply_format == 0 ){ reply_format = 20; } |
||
894 | int_data[8] = 2;/* drag & drop */ |
||
895 | } |
||
896 | else |
||
897 | { |
||
898 | if( onclick == 1 ){ |
||
899 | reply_format = 20; |
||
900 | int_data[8] = 1; /* onclick will be reset using 'void reset()'*/ |
||
901 | click_cnt++; /* will also be used in dragstuff ! */ |
||
902 | } |
||
903 | else |
||
904 | { |
||
905 | int_data[8] = 0; /* just static image */ |
||
906 | } |
||
907 | } |
||
908 | /* |
||
909 | function draw_external_image(URL,sx,sy,swidth,sheight,x0,y0,width,height,ext_img_cnt,resizable,draggable,click_cnt) |
||
910 | */ |
||
911 | string_length = snprintf(NULL,0, "draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,0,%d,%d);\n",URL,int_data[2],int_data[3],int_data[6],int_data[7],int_data[0],int_data[1],int_data[6],int_data[7],ext_img_cnt,int_data[8],int_data[9]); |
||
912 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
913 | snprintf(tmp_buffer,string_length,"draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,0,%d,%d);\n",URL,int_data[2],int_data[3],int_data[6],int_data[7],int_data[0],int_data[1],int_data[6],int_data[7],ext_img_cnt,int_data[8],int_data[9]); |
||
914 | drag_type = -1; /* reset the drag_type indicator */ |
||
915 | ext_img_cnt++; |
||
916 | onclick=0; |
||
917 | add_to_buffer(tmp_buffer); |
||
918 | break; |
||
7614 | schaersvoo | 919 | default: break; |
920 | } |
||
921 | } |
||
922 | break; |
||
11806 | schaersvoo | 923 | /* |
924 | HTML5 specs: |
||
925 | context.drawImage(img,sx,sy,swidth,sheight,x,y,width,height); |
||
926 | img Specifies the image, canvas, or video element to use |
||
927 | sx The x coordinate where to start clipping : x1 = int_data[0] |
||
928 | sy The y coordinate where to start clipping : x2 = int_data[1] |
||
929 | swidth The width of the clipped image : int_data[2] - int_data[0] |
||
930 | sheight The height of the clipped image : int_data[3] - int_data[1] |
||
931 | x The x coordinate where to place the image on the canvas : dx1 = int_data[4] |
||
932 | y The y coordinate where to place the image on the canvas : dy1 = int_data[5] |
||
933 | width The width of the image to use (stretch or reduce the image) : dx2 - dx1 = int_data[6] |
||
934 | height The height of the image to use (stretch or reduce the image) : dy2 - dy1 = int_data[7] |
||
935 | */ |
||
936 | case COPYRESIZED: |
||
937 | /* |
||
938 | @ copyresized x1,y2,x2,y2,dx1,dy1,dx2,dy2,image_file_url |
||
939 | @ The image may be any "bitmap" or "SVG" |
||
940 | @ Insert the region from (x1,y1) to (x2,y2) (in pixels) of [ filename], <br />possibly resized,<br />to the region of (dx1,dy1) to (dx2,dy2) in x/y-range |
||
941 | @ (dx1:dy1) must be left top corner; (dx2 :dy2) must be right bottom corner of inserted image |
||
942 | @ If x1=y1=x2=y2=-1, the whole [filename / URL ] is copied and resized. |
||
943 | @ URL is normal URL of network reachable image file location<br />(as seen from public_html-root or network reachable 'http://some_server/my_images/test.gif'<br />(eg no special wims paths are searched !!) |
||
944 | @ if command <a href="#drag">'drag x/y/xy'</a> is set before command 'copy', the images will be draggable<br />javascript function read_canvas(); will return the x/y coordinate data in xrange/yrange of all -including non draggable- images<br />the command drag is only valid for the next image<br />draggable / non-draggable images may be mixed<br />may be used together with preceding keywords 'snaptogrid','xsnaptogrid','ysnaptogrid' or 'snaptopoints x1,y1,x2,y2...' |
||
945 | @ if keyword <a href="#onclick">'onclick'</a> is set before command 'copy' the image(s) is clickable (marked with a green rectangle around the image)<br />use 'read_dragdrop' to get the number of the clicked image(s)<br />use command 'clearbutton some_text' to reset the reply/click array.<br />example: 4 images; student clicked on image 2 and 3 : reply = 0,1,1,0<br />after clicking the clear button: reply = 0,0,0,0<br />May be mixed with commands 'drag x|y|xy' (use javascript read_canvas to get the new coordinates |
||
946 | @ 'onclick' for external images may be mixed with canvas generated stuff (like lines,curves etc) |
||
947 | @ you may draw / userdraw / drag stuff on top of an "imported" image |
||
948 | */ |
||
949 | for(i = 0 ; i<9;i++){ |
||
950 | switch(i){ |
||
951 | case 0: int_data[0] = (int)(get_real(infile,0));break; /* x1 */ |
||
952 | case 1: int_data[1] = (int)(get_real(infile,0));break; /* y1 */ |
||
953 | case 2: int_data[2] = (int)(get_real(infile,0));break;/* x2 */ |
||
954 | case 3: int_data[3] = (int)(get_real(infile,0));break;/* y2 */ |
||
955 | case 4: int_data[4] = x2px(get_real(infile,0));break;/* dx1 */ |
||
956 | case 5: int_data[5] = y2px(get_real(infile,0));break;/* dy1 */ |
||
957 | case 6: int_data[6] = x2px(get_real(infile,0));break;/* dx2 */ |
||
958 | case 7: int_data[7] = y2px(get_real(infile,0));break;/* dy2 */ |
||
959 | case 8: URL = get_string(infile,1); |
||
960 | /* flag error when wrong diagonal: copyresized -1,-1,-1,-1,0,0,7,7,testfig.gif */ |
||
961 | if( int_data[7] < int_data[5] || int_data[6] < int_data[4]){ |
||
962 | canvas_error("in copyresized , use:<br />left top corner (dx1:dy1) and right bottom corner (dx2:dy2) ! "); |
||
963 | } |
||
964 | int_data[2] = abs(int_data[2] - int_data[0]);/* swidth */ |
||
965 | int_data[3] = abs(int_data[3] - int_data[1]);/* sheight */ |
||
966 | int_data[6] = abs(int_data[6] - int_data[4]);/* width */ |
||
967 | int_data[7] = abs(int_data[7] - int_data[5]);/* height */ |
||
968 | if( js_function[DRAW_EXTERNAL_IMAGE] != 1 ){ js_function[DRAW_EXTERNAL_IMAGE] = 1;} |
||
969 | int_data[9] = click_cnt; |
||
970 | if( drag_type > -1 ){/* e.g. we are dragging images x/y/xy */ |
||
971 | if( reply_format == 0 ){ reply_format = 20; } |
||
972 | int_data[8] = 2;/* drag & drop */ |
||
973 | } |
||
974 | else |
||
975 | { |
||
976 | if( onclick == 1 ){ |
||
977 | reply_format = 20; |
||
978 | int_data[8] = 1; /* onclick will be reset using 'void reset()'*/ |
||
979 | click_cnt++; /* will also be used in dragstuff ! */ |
||
980 | } |
||
981 | else |
||
982 | { |
||
983 | int_data[8] = 0; /* just static image */ |
||
984 | } |
||
985 | } |
||
986 | /* |
||
987 | (URL,sx,sy,swidth,sheight,x0,y0,width,height,idx,resizable,draggable,click_cnt) |
||
988 | URL,[2],[3],[6], [7], [4],[5],[6],[7],ext_img_cnt,1, [8], [9] |
||
989 | */ |
||
990 | string_length = snprintf(NULL,0, "draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,1,%d,%d);\n",URL,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],ext_img_cnt,int_data[8],int_data[9]); |
||
991 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
992 | snprintf(tmp_buffer,string_length,"draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,1,%d,%d);\n",URL,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],ext_img_cnt,int_data[8],int_data[9]); |
||
993 | drag_type = -1; /* reset the drag_type indicator */ |
||
994 | ext_img_cnt++; |
||
995 | onclick=0; |
||
996 | add_to_buffer(tmp_buffer); |
||
997 | break; |
||
998 | default: break; |
||
999 | } |
||
1000 | } |
||
1001 | break; |
||
8386 | schaersvoo | 1002 | |
11806 | schaersvoo | 1003 | |
1004 | case CROSSHAIR: |
||
8386 | schaersvoo | 1005 | /* |
11806 | schaersvoo | 1006 | @ crosshair x,y,color |
1007 | @ draw a single crosshair point at (x;y) in color 'color' |
||
1008 | @ use command 'crosshairsize int' and / or 'linewidth int' to adust |
||
1009 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
||
1010 | */ |
||
1011 | for(i=0;i<3;i++){ |
||
1012 | switch(i){ |
||
1013 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
1014 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
1015 | case 2: stroke_color = get_color(infile,1);/* name or hex color */ |
||
1016 | decimals = find_number_of_digits(precision); |
||
1017 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,7,[%.*f],[%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[1],crosshair_size,crosshair_size,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,0,0,0,use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset); |
||
1018 | if(onclick > 0){click_cnt++;} |
||
1019 | /* click_cnt++ */ |
||
1020 | reset(); |
||
1021 | break; |
||
1022 | default:break; |
||
1023 | } |
||
1024 | } |
||
1025 | break; |
||
1026 | |||
1027 | case CROSSHAIRS: |
||
1028 | /* |
||
1029 | @ crosshairs color,x1,y1,x2,y2,...,x_n,y_n |
||
1030 | @ draw multiple crosshair points at given coordinates in color 'color' |
||
1031 | @ use command 'crosshairsize int' and / or 'linewidth int' to adust |
||
9406 | schaersvoo | 1032 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!) |
8386 | schaersvoo | 1033 | */ |
1034 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
1035 | fill_color = stroke_color; |
||
1036 | i=0; |
||
1037 | while( ! done ){ /* get next item until EOL*/ |
||
1038 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
1039 | if(i%2 == 0 ){ |
||
1040 | double_data[i] = get_real(infile,0); /* x */ |
||
1041 | } |
||
1042 | else |
||
1043 | { |
||
1044 | double_data[i] = get_real(infile,1); /* y */ |
||
1045 | } |
||
1046 | i++; |
||
1047 | } |
||
1048 | decimals = find_number_of_digits(precision); |
||
11806 | schaersvoo | 1049 | for(c=0 ; c < i-1 ; c = c+2){ |
1050 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,7,[%.*f],[%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+1],crosshair_size,crosshair_size,line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,1,0,0,0,use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset); |
||
8386 | schaersvoo | 1051 | if(onclick > 0){click_cnt++;} |
11806 | schaersvoo | 1052 | /* click_cnt++; */ |
8386 | schaersvoo | 1053 | } |
1054 | reset(); |
||
1055 | break; |
||
1056 | |||
11806 | schaersvoo | 1057 | case CROSSHAIRSIZE: |
7614 | schaersvoo | 1058 | /* |
11806 | schaersvoo | 1059 | @ crosshairsize int |
1060 | @ default 8 (px) |
||
7614 | schaersvoo | 1061 | */ |
11806 | schaersvoo | 1062 | crosshair_size = (int) (get_real(infile,1)); |
1063 | break; |
||
1064 | |||
1065 | case CURSOR: |
||
1066 | /* |
||
1067 | @ cursor 'some CSS cursor_style' |
||
1068 | @ alternative : pointer |
||
1069 | @ style can be any valid CSS property value, like crosshair,grabbing,move etc |
||
1070 | @ wims will not check the validity of your cursor declaration |
||
1071 | */ |
||
1072 | fprintf(js_include_file,"canvas_div%d.style.cursor = \"%s\";",canvas_root_id,get_string(infile,1)); |
||
1073 | break; |
||
1074 | |||
1075 | case CURVE: |
||
1076 | /* |
||
1077 | @ curve color,formula(x) |
||
1078 | @ alernative : plot color,formula(x) |
||
1079 | @ use command <a href="#trange">trange</a> in parametric functions before command curve / plot (trange -pi,pi)<br />curve color,formula1(t),formula2(t) |
||
1080 | @ use command <a href="#precision">"precision" </a>to ncrease the number of digits of the plotted points |
||
1081 | @ use command <a href="#plotsteps">"plotsteps"</a> to increase / decrease the amount of plotted points (default 150) |
||
1082 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
||
1083 | @ if you need a plot beyond xrange / yrange, use <a href="#jsplot">"jsplot"'</a><br />(command "curve" will only calculate points within the xrange) |
||
1084 | */ |
||
1085 | if( use_parametric == TRUE ){ /* parametric color,fun1(t),fun2(t)*/ |
||
1086 | use_parametric = FALSE; |
||
1087 | stroke_color = get_color(infile,0); |
||
1088 | char *fun1 = get_string_argument(infile,0); |
||
1089 | char *fun2 = get_string_argument(infile,1); |
||
1090 | if( strlen(fun1) == 0 || strlen(fun2) == 0 ){canvas_error("parametric functions are NOT OK !");} |
||
1091 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,%s,[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d));\n",click_cnt,onclick,drag_type,animation_type,eval_parametric(xsize,ysize,fun1,fun2,xmin,xmax,ymin,ymax,tmin,tmax,plot_steps,precision),2*line_width,2*line_width,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset); |
||
1092 | } |
||
1093 | else |
||
1094 | { |
||
1095 | stroke_color = get_color(infile,0); |
||
1096 | char *fun1 = get_string_argument(infile,1); |
||
1097 | if( strlen(fun1) == 0 ){canvas_error("function is NOT OK !");} |
||
1098 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,%s,[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d));\n",click_cnt,onclick,drag_type,animation_type,eval(xsize,ysize,fun1,xmin,xmax,ymin,ymax,plot_steps,precision),line_width,line_width,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset); |
||
1099 | } |
||
1100 | if(onclick > 0){click_cnt++;} |
||
1101 | /* click_cnt++; */ |
||
1102 | reset(); |
||
1103 | break; |
||
1104 | |||
1105 | case DASHED: |
||
1106 | /* |
||
1107 | @ dashed |
||
1108 | @ keyword (no arguments required) |
||
1109 | @ next object will be drawn with a dashed line |
||
1110 | @ change dashing scheme by using command <a href="#dashtype">dashtype</a> |
||
1111 | */ |
||
1112 | use_dashed = TRUE; |
||
1113 | break; |
||
1114 | |||
1115 | case DASHTYPE: |
||
1116 | /* |
||
1117 | @ dashtype line_width_px,space_width_px |
||
1118 | @ every indiviual object may have its own dashtype, if needed... |
||
1119 | @ When keyword <a href='#dashed'>dashed</a> is set, the objects will be drawn with this dashtype |
||
1120 | @ default value "dashtype 2,2" e.g. 2px line and 2px space |
||
1121 | @ html5 canvas specification supports more arguments (dashing schemes) ... but not all modern browsers are yet capable |
||
1122 | */ |
||
1123 | for(i=0;i<2;i++){ |
||
1124 | switch(i){ |
||
1125 | case 0 : dashtype[0] = (int) line_width*( get_real(infile,0)) ; break; |
||
1126 | case 1 : dashtype[1] = (int) line_width*( get_real(infile,1)) ; break; |
||
1127 | } |
||
1128 | } |
||
1129 | break; |
||
1130 | |||
1131 | case DIAMONDFILL: |
||
1132 | /* |
||
1133 | @ diamondfill x0,y0,dx,dy,color |
||
1134 | @ x0,y0 in xrange / yrange |
||
1135 | @ distances dx,dy in pixels |
||
1136 | @ ATTENTION: NOT TO BE USED AS ALTERNATIVE FOR FLYDRAW COMMAND |
||
1137 | */ |
||
1138 | if( js_function[DRAW_DIAMONDFILL] != 1 ){ js_function[DRAW_DIAMONDFILL] = 1;} |
||
7614 | schaersvoo | 1139 | for(i=0;i<5;i++){ |
1140 | switch(i){ |
||
11806 | schaersvoo | 1141 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */ |
1142 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y */ |
||
1143 | case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */ |
||
1144 | case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/ |
||
1145 | case 4: stroke_color = get_color(infile,1); |
||
1146 | /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */ |
||
1147 | string_length = snprintf(NULL,0, "draw_diamondfill(%d,%d,%d,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],int_data[2],int_data[3],line_width,stroke_color,stroke_opacity,xsize,ysize); |
||
1148 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
1149 | snprintf(tmp_buffer,string_length,"draw_diamondfill(%d,%d,%d,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],int_data[2],int_data[3],line_width,stroke_color,stroke_opacity,xsize,ysize); |
||
1150 | add_to_buffer(tmp_buffer); |
||
1151 | break; |
||
1152 | default:break; |
||
1153 | } |
||
1154 | } |
||
1155 | reset(); |
||
1156 | break; |
||
8224 | bpr | 1157 | |
11806 | schaersvoo | 1158 | case DOTFILL: |
1159 | /* |
||
1160 | @ dotfill x0,y0,dx,dy,color |
||
1161 | @ x0,y0 in xrange / yrange |
||
1162 | @ distances dx,dy in pixels |
||
1163 | @ radius of dots is linewidth |
||
1164 | */ |
||
1165 | if( js_function[DRAW_DOTFILL] != 1 ){ js_function[DRAW_DOTFILL] = 1;} |
||
1166 | for(i=0;i<5;i++){ |
||
1167 | switch(i){ |
||
1168 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */ |
||
1169 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y */ |
||
1170 | case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */ |
||
1171 | case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/ |
||
1172 | case 4: stroke_color = get_color(infile,1); |
||
1173 | /* draw_dotfill(ctx,x0,y0,dx,dy,radius,color,opacity,xsize,ysize) */ |
||
1174 | string_length = snprintf(NULL,0, "draw_dotfill(%d,%d,%d,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],int_data[2],int_data[3],line_width,stroke_color,stroke_opacity,xsize,ysize); |
||
1175 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
1176 | snprintf(tmp_buffer,string_length,"draw_dotfill(%d,%d,%d,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],int_data[2],int_data[3],line_width,stroke_color,stroke_opacity,xsize,ysize); |
||
1177 | add_to_buffer(tmp_buffer); |
||
7614 | schaersvoo | 1178 | break; |
11806 | schaersvoo | 1179 | default:break; |
7614 | schaersvoo | 1180 | } |
1181 | } |
||
11806 | schaersvoo | 1182 | reset(); |
1183 | break; |
||
1184 | |||
1185 | case DRAG: |
||
1186 | /* |
||
1187 | @ drag [x][y][xy] |
||
1188 | @ the next object will be draggable in x / y / xy direction |
||
1189 | @ the displacement can be read by 'javascript:read_dragdrop();' |
||
1190 | @ 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' ! |
||
1191 | @ 'onclick' and 'drag x|y|xy' may be combined (for different objects: a single object can either be onclick or drag , not both ) |
||
1192 | @ '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) |
||
1193 | @ <b>attention</b>: static objects and 'onclick/drag' objects of the same type (like point,circle,etc) with the same coordinates (e.g. objects that overlap) will give problems in the 'recognition algorithm')<br />in this example<br /><em>linewidth 4<br />point 0,0,red<br />drag xy<br />point 0,0,blue<br /></em>the blue point will not be recognised as draggable !<br /><em>linewidth 4<br />drag xy<br />point 0,0,red<br />drag xy<br />point 0,0,blue<br /></em>both points will be recognised |
||
1194 | @ the answer is : drag_or_onclick_object_number : Xorg : Yorg : Xnew : Ynew<br />wherein object_number is the sequence number of the draggable & 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) |
||
1195 | @ use keyword 'snaptogrid' , 'xsnaptogrid' , 'ysnaptogrid' or command 'snaptopoints x1,y1,x2,y2,...' to switch from free to discrete movement |
||
1196 | @ 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. |
||
1197 | @ note: in case an object is dragged , zooming or panning will cause the coordinates to be reset to the original position :( <br />e.g. dragging / panning will get lost. (array with 'drag data' is erased)<br />This is a design flaw and not a feature !! |
||
1198 | */ |
||
1199 | temp = get_string(infile,1); |
||
1200 | if(strstr(temp,"xy") != NULL ){ |
||
1201 | drag_type = 0; |
||
1202 | } |
||
1203 | else |
||
1204 | { |
||
1205 | if(strstr(temp,"x") != NULL ){ |
||
1206 | drag_type = 1; |
||
1207 | } |
||
1208 | else |
||
1209 | { |
||
1210 | drag_type = 2; |
||
1211 | } |
||
1212 | } |
||
1213 | /* assuming all drag&drop coordinates the same precision: so set only once */ |
||
1214 | if( print_drag_params_only_once == FALSE ){ |
||
1215 | fprintf(js_include_file,"dragdrop_precision = %d;use_dragdrop_reply = true;\n",precision); |
||
1216 | print_drag_params_only_once = TRUE; |
||
1217 | } |
||
1218 | onclick = 2; |
||
1219 | /* if(use_userdraw == TRUE ){canvas_error("\"drag & drop\" may not be combined with \"userdraw\" or \"pan and zoom\" \n");} */ |
||
7614 | schaersvoo | 1220 | break; |
8386 | schaersvoo | 1221 | |
11806 | schaersvoo | 1222 | case ELLIPSE: |
8351 | schaersvoo | 1223 | /* |
11806 | schaersvoo | 1224 | @ ellipse xc,yc,radius_x,radius_y,color |
1225 | @ a ellipse with center xc/yc in x/y-range |
||
1226 | @ radius_x and radius_y are in pixels |
||
9406 | schaersvoo | 1227 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
11806 | schaersvoo | 1228 | @ will shrink / expand on zoom out / zoom in |
8351 | schaersvoo | 1229 | */ |
11806 | schaersvoo | 1230 | for(i=0;i<5;i++){ |
1231 | switch(i){ |
||
1232 | case 0:double_data[0] = get_real(infile,0);break; /* x-values */ |
||
1233 | case 1:double_data[1] = get_real(infile,0);break; /* y-values */ |
||
1234 | case 2:double_data[2] = get_real(infile,0);break; /* rx -> px */ |
||
1235 | case 3:double_data[3] = get_real(infile,0);break; /* ry -> px */ |
||
1236 | case 4:stroke_color = get_color(infile,1);/* name or hex color */ |
||
1237 | decimals = find_number_of_digits(precision); |
||
1238 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,3,[%.*f],[%.*f],[%.*f],[%.*f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[1],decimals,double_data[2],decimals,double_data[3],line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset); |
||
1239 | if(onclick > 0){click_cnt++;} |
||
1240 | /* click_cnt++; */ |
||
1241 | reset(); |
||
1242 | break; |
||
1243 | } |
||
1244 | } |
||
1245 | break; |
||
1246 | case FILLALL: |
||
1247 | /* |
||
1248 | @ fillall color,x1,y1,x2,y2...x_n,y_n |
||
1249 | @ fill all region containing points (x1:y1),(x2:y2)...(x_n:y_n) with color 'color' |
||
1250 | @ any other colors (objects) in the <a href="#canvastype>canvastype</a> will act as border to the bucket fill |
||
1251 | @ use this command after all boundary objects are declared. |
||
1252 | @ Use command 'userdraw clickfill,color' for user click driven flood fill. |
||
1253 | @ use command <a href="#canvastype">canvastype </a> to fill another canvas (default should be fine: DRAG_CANVAS = 5) |
||
1254 | @ note: the fill-family of commands are very (client) cpu intensive operations!<br />filling is done pixel by pixel<br/>e.g. image size of 400x400 uses 160000 pixels : each pixel contains 4 data (R,G,B,Opacity) = 640000 data.<br />on every data a few operations / comparisons are done...<br />So have pity on your students CPU.. |
||
1255 | */ |
||
1256 | decimals = find_number_of_digits(precision); |
||
1257 | fill_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
8351 | schaersvoo | 1258 | i=0; |
11806 | schaersvoo | 1259 | if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */ |
1260 | js_function[DRAW_FILLTOBORDER] = 1; |
||
1261 | add_js_filltoborder(js_include_file,canvas_root_id,canvas_type); |
||
1262 | } |
||
8351 | schaersvoo | 1263 | while( ! done ){ /* get next item until EOL*/ |
1264 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
1265 | if(i%2 == 0 ){ |
||
1266 | double_data[i] = get_real(infile,0); /* x */ |
||
1267 | } |
||
1268 | else |
||
1269 | { |
||
1270 | double_data[i] = get_real(infile,1); /* y */ |
||
11806 | schaersvoo | 1271 | string_length = snprintf(NULL,0, "setTimeout(function(){filltoborder(%.*f,%.*f,[%s,%d],[%s,%d],%d);},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); |
1272 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
1273 | snprintf(tmp_buffer,string_length,"setTimeout(function(){filltoborder(%.*f,%.*f,[%s,%d],[%s,%d],%d);},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); |
||
1274 | add_to_buffer(tmp_buffer); |
||
1275 | fill_cnt++; |
||
8351 | schaersvoo | 1276 | } |
1277 | i++; |
||
1278 | } |
||
11806 | schaersvoo | 1279 | break; |
1280 | |||
1281 | case FILLED: |
||
1282 | /* |
||
1283 | @ filled |
||
1284 | @ keyword (no arguments required) |
||
1285 | @ the next 'fillable' object (only) will be filled |
||
1286 | @ use command "fillcolor color" to set fillcolor |
||
1287 | @ use command "opacity 0-255,0-255" to set stroke and fill-opacity |
||
1288 | @ use command "fill x,y,color" or "floodfill x,y,color" to fill the space around (x;y) with color <br />pixel operation implemented in javascript: use with care ! |
||
1289 | */ |
||
1290 | use_filled = TRUE; |
||
1291 | break; |
||
1292 | |||
1293 | case FILLCOLOR: |
||
1294 | /* |
||
1295 | @ fillcolor colorname or #hex |
||
1296 | @ set the color for a filled object : mainly used for command 'userdraw obj,stroke_color' |
||
1297 | @ all fillable massive objects will have a fillcolor == strokecolor (just to be compatible with flydraw...) |
||
1298 | */ |
||
1299 | fill_color = get_color(infile,1); |
||
1300 | break; |
||
1301 | |||
1302 | case FILLTOBORDER: |
||
1303 | /* |
||
1304 | @ filltoborder x,y,bordercolor,color |
||
1305 | @ fill the region of point (x:y) with color 'color' |
||
1306 | @ any other color will not act as border to the bucket fill |
||
1307 | @ use this command after all boundary objects are declared. |
||
1308 | @ use command <a href="#canvastype">canvastype </a> to fill another canvas (default should be fine: DRAG_CANVAS = 5) |
||
1309 | @ note: filltoborder is a very (client) cpu intensive operation!<br />filling is done pixel by pixel<br/>e.g. image size of 400x400 uses 160000 pixels : each pixel contains 4 data (R,G,B,Opacity) = 640000 data.<br />on every data a few operations / comparisons are done...<br />So have pity on your students CPU.. |
||
1310 | @ maybe used together with command <a href="#userdraw">userdraw clickfill,color</a> |
||
1311 | */ |
||
1312 | for(i=0 ;i < 4 ; i++){ |
||
1313 | switch(i){ |
||
1314 | case 0:double_data[0] = get_real(infile,0);break; |
||
1315 | case 1:double_data[1] = get_real(infile,0);break; |
||
1316 | case 2:bgcolor = get_color(infile,0);break; |
||
1317 | case 3:fill_color = get_color(infile,1); |
||
1318 | if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */ |
||
1319 | js_function[DRAW_FILLTOBORDER] = 1; |
||
1320 | add_js_filltoborder(js_include_file,canvas_root_id,canvas_type); |
||
1321 | } |
||
1322 | decimals = find_number_of_digits(precision); |
||
1323 | /* we need to set a timeout: the canvas is not yet draw in memory? when floodfill is called directly... */ |
||
1324 | string_length = snprintf(NULL,0, "setTimeout(function(){filltoborder(%.*f,%.*f,[%s,%d],[%s,%d],%d);},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); |
||
1325 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
1326 | snprintf(tmp_buffer,string_length,"setTimeout(function(){filltoborder(%.*f,%.*f,[%s,%d],[%s,%d],%d);},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); |
||
1327 | add_to_buffer(tmp_buffer); |
||
1328 | fill_cnt++; |
||
1329 | break; |
||
1330 | default:break; |
||
8351 | schaersvoo | 1331 | } |
11806 | schaersvoo | 1332 | } |
1333 | reset(); |
||
1334 | break; |
||
1335 | case FLOODFILL: |
||
1336 | /* |
||
1337 | @ floodfill x,y,color |
||
1338 | @ alternative : fill x,y,color |
||
1339 | @ fill the region of point (x:y) with color 'color' |
||
1340 | @ any other color or size of picture (borders of picture) will act as border to the bucket fill |
||
1341 | @ use this command after all boundary objects are declared. |
||
1342 | @ Use command 'userdraw clickfill,color' for user click driven flood fill. |
||
1343 | @ use command <a href="#canvastype">canvastype </a> to fill another canvas (default should be fine: DRAG_CANVAS = 5) |
||
1344 | @ note: floodfill is a very (client) cpu intensive operation!<br />filling is done pixel by pixel<br/>e.g. image size of 400x400 uses 160000 pixels : each pixel contains 4 data (R,G,B,Opacity) = 640000 data.<br />on every data a few operations / comparisons are done...<br />So have pity on your students CPU.. |
||
1345 | */ |
||
1346 | for(i=0 ;i < 4 ; i++){ |
||
1347 | switch(i){ |
||
1348 | case 0:double_data[0] = get_real(infile,0);break; |
||
1349 | case 1:double_data[1] = get_real(infile,0);break; |
||
1350 | case 2:fill_color = get_color(infile,1); |
||
1351 | if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */ |
||
1352 | js_function[DRAW_FILLTOBORDER] = 1; |
||
1353 | add_js_filltoborder(js_include_file,canvas_root_id,canvas_type); |
||
1354 | } |
||
1355 | decimals = find_number_of_digits(precision); |
||
1356 | /* we need to set a timeout: the canvas is not yet draw in memory? when floodfill is called directly... */ |
||
1357 | string_length = snprintf(NULL,0, "setTimeout(function(){filltoborder(%.*f,%.*f,[%s,%d],[%s,%d],%d);},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); |
||
1358 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
1359 | snprintf(tmp_buffer,string_length,"setTimeout(function(){filltoborder(%.*f,%.*f,[%s,%d],[%s,%d],%d);},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); |
||
1360 | add_to_buffer(tmp_buffer); |
||
1361 | fill_cnt++; |
||
1362 | break; |
||
1363 | default:break; |
||
1364 | } |
||
1365 | } |
||
1366 | reset(); |
||
1367 | break; |
||
1368 | |||
1369 | case FONTCOLOR: |
||
1370 | /* |
||
1371 | @ fontcolor color |
||
1372 | @ color: hexcolor or colorname |
||
1373 | @ default: black |
||
1374 | @ example usage: x/y-axis text |
||
1375 | */ |
||
1376 | font_color = get_color(infile,1); |
||
1377 | break; |
||
1378 | |||
1379 | case FONTFAMILY: |
||
1380 | /* |
||
1381 | @ fontfamily font_description |
||
1382 | @ set the font family; for browsers that support it |
||
1383 | @ font_description: Ariel ,Courier, Helvetica etc |
||
1384 | @ in case commands<br /> 'string color,x,y,the string'<br /> 'stringup color,x,y,rotation,the string'<br />fontfamily can be something like:<br />italic 34px Ariel |
||
1385 | @ use correct syntax : 'font style' 'font size'px 'fontfamily' |
||
1386 | */ |
||
1387 | font_family = get_string(infile,1); |
||
1388 | break; |
||
1389 | |||
1390 | case FONTSIZE: |
||
1391 | /* |
||
1392 | @ fontsize font_size |
||
1393 | @ default value 12 |
||
1394 | @ note:for some macro's (like grid | legend | xaxistext | xlabel etc) sometimes command <a href="#fontfamily">"fontfamily"</a> can be used for some specific font-setting<br />this is however not always very straight forward...so just try and see what happens |
||
1395 | */ |
||
1396 | font_size = (int) (get_real(infile,1)); |
||
1397 | break; |
||
1398 | |||
1399 | case FUNCTION_LABEL: |
||
1400 | /* |
||
1401 | @ functionlabel 'some string' |
||
1402 | @ default value "f(x)=" |
||
1403 | @ no mathml allowed (just ascii string) |
||
1404 | @ use command 'fontsize int' to adjust the size |
||
1405 | @ use command 'strokecolor colorname' to adjust the labels (individually, if needed) |
||
1406 | @ if needed, use before every command 'userinput function | inputfield | textarea' |
||
1407 | */ |
||
1408 | function_label = get_string_argument(infile,1); |
||
1409 | break; |
||
1410 | |||
1411 | case GRID:/* xmajor,ymajor,gridcolor [,xminor,yminor,tick length (px) ,axis/tickscolor]*/ |
||
1412 | /* |
||
1413 | @ grid step_x,step_y,gridcolor |
||
1414 | @ if keywords <a href="#axis">"axis"</a> or <a href="#axisnumbering">"axisnumbering"</a> are set, use :<br />grid step_x,step_y,major_color,minor_x,minor_y,tics height in px,axis_color<br />minor x step = step_x / minor_x |
||
1415 | @ in that case, use command <a href="#fontcolor">"fontcolor"</a>, <a href="#fontsize">"fontsize"</a> and / or <a href="#fontfamily">"fontfamily"</a> to adjust font <br />defaults: black,12,Ariel |
||
1416 | @ if xmin > 0 and/or ymin > 0 and zooming / panning is not activ: <br /> be aware that the x/y-axis numbering and x/y major/minor tic marks will not be visual <br /> as they are placed under the x-axis and left to the y-axis (in Quadrant II and IV) |
||
1417 | @ can <b>not</b> be set <a href="#onclick">"onclick"</a> or <a href="#drag">"drag xy"</a> |
||
1418 | @ use commands <a href="#xlabel">'xlabel some_string'</a> and/or <a href="#ylabel">'ylabel some_string'</a> to label axis;<br />use command "fontsize" to adjust size:the font family is non-configurable 'italic your_fontsize px Ariel' ! |
||
1419 | @ see commands (see <a href="#xaxis">"xaxis" or xaxistext"</a>, <a href="#yaxis">"yaxis" or "yaxistext"</a> to set tailormade values on axis (the used font is set by <a href="fontfamily">command fontfamily</a>; default '12px Ariel') |
||
1420 | @ see command <a href="#legend">"legend"</a>to set a legend for the graph ;<br />use command <a href="#fontsize">"fontsize"</a> to adjust size (the font family is non-configurable 'bold your_fontsize px Ariel') |
||
1421 | */ |
||
1422 | if( js_function[DRAW_YLOGSCALE] == 1 ){canvas_error("only one grid type is allowed...");} |
||
1423 | if( js_function[DRAW_GRID] != 1 ){ js_function[DRAW_GRID] = 1;} |
||
1424 | for(i=0;i<4;i++){ |
||
1425 | switch(i){ |
||
1426 | case 0:double_data[0] = get_real(infile,0);break;/* xmajor */ |
||
1427 | case 1:double_data[1] = get_real(infile,0);break;/* ymajor */ |
||
1428 | case 2: |
||
1429 | if( use_axis == TRUE ){ |
||
1430 | stroke_color = get_color(infile,0); |
||
1431 | done = FALSE; |
||
1432 | int_data[0] = (int) (get_real(infile,0));/* xminor */ |
||
1433 | int_data[1] = (int) (get_real(infile,0));/* yminor */ |
||
1434 | int_data[2] = (int) (get_real(infile,0));/* tic_length */ |
||
1435 | fill_color = get_color(infile,1); /* used as axis_color*/ |
||
8351 | schaersvoo | 1436 | } |
1437 | else |
||
1438 | { |
||
11806 | schaersvoo | 1439 | int_data[0] = 1; |
1440 | int_data[1] = 1; |
||
1441 | stroke_color = get_color(infile,1); |
||
1442 | fill_color = stroke_color; |
||
8351 | schaersvoo | 1443 | } |
11806 | schaersvoo | 1444 | 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 !");} |
1445 | /* set snap_x snap_y values in pixels */ |
||
1446 | fprintf(js_include_file,"snap_x = %f;snap_y = %f;",double_data[0] / int_data[0],double_data[1] / int_data[1]); |
||
1447 | string_length = snprintf(NULL,0, ";draw_grid%d(%d,%d,%.2f,%.*f,%.*f,%d,%d,%d,%d,\"%s\",\"%s\",%d,\"%s\",%d,%d,%d,%.2f,%d,%s,%d,%d,%d,\"%s\",%.2f);\n ",canvas_root_id,GRID_CANVAS,precision,stroke_opacity,decimals,double_data[0],decimals,double_data[1],int_data[0],int_data[1],int_data[2],line_width,stroke_color,fill_color,font_size,font_family,use_axis,use_axis_numbering,use_rotate,angle,use_affine,affine_matrix,use_dashed,dashtype[0],dashtype[1],font_color,fill_opacity); |
||
1448 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
1449 | 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); |
||
1450 | add_to_buffer(tmp_buffer); |
||
1451 | break; |
||
8351 | schaersvoo | 1452 | } |
1453 | } |
||
1454 | reset(); |
||
1455 | break; |
||
11806 | schaersvoo | 1456 | case GRIDFILL: |
1457 | /* |
||
1458 | @ gridfill x0,y0,dx,dy,color |
||
1459 | @ x0,y0 in xrange / yrange |
||
1460 | @ distances dx,dy in pixels |
||
1461 | @ a draggable object may <a href="#snaptogrid">snap_to_grid</a> (using keywords snaptogrid,xsnaprogrid, ysnaptogrid or snaptopoints) |
||
1462 | @ userdraw object may snap_to_grid |
||
1463 | */ |
||
1464 | if( js_function[DRAW_GRIDFILL] != 1 ){ js_function[DRAW_GRIDFILL] = 1;} |
||
1465 | for(i=0;i<5;i++){ |
||
1466 | switch(i){ |
||
1467 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */ |
||
1468 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y */ |
||
1469 | case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */ |
||
1470 | case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/ |
||
1471 | case 4: stroke_color = get_color(infile,1); |
||
1472 | string_length = snprintf(NULL,0, "draw_gridfill(%d,%d,%d,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],int_data[2],int_data[3],line_width,stroke_color,stroke_opacity,xsize,ysize); |
||
1473 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
1474 | snprintf(tmp_buffer,string_length,"draw_gridfill(%d,%d,%d,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],int_data[2],int_data[3],line_width,stroke_color,stroke_opacity,xsize,ysize); |
||
1475 | add_to_buffer(tmp_buffer); |
||
1476 | break; |
||
1477 | default:break; |
||
1478 | } |
||
1479 | } |
||
1480 | reset(); |
||
1481 | break; |
||
8386 | schaersvoo | 1482 | |
8244 | schaersvoo | 1483 | case HALFLINE: |
1484 | /* |
||
1485 | @ demiline x1,y1,x2,y2,color |
||
1486 | @ alternative : halfline |
||
1487 | @ draws a halfline starting in (x1:y1) and through (x2:y2) in color 'color' (colorname or hex) |
||
9406 | schaersvoo | 1488 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
8244 | schaersvoo | 1489 | */ |
1490 | for(i=0;i<5;i++){ |
||
1491 | switch(i){ |
||
1492 | case 0: double_data[0]= get_real(infile,0);break; /* x-values */ |
||
1493 | case 1: double_data[1]= get_real(infile,0);break; /* y-values */ |
||
1494 | case 2: double_data[10]= get_real(infile,0);break; /* x-values */ |
||
1495 | case 3: double_data[11]= get_real(infile,0);break; /* y-values */ |
||
1496 | case 4: stroke_color=get_color(infile,1);/* name or hex color */ |
||
1497 | if(double_data[0] == double_data[10]){ /* vertical halfline */ |
||
1498 | if(double_data[1] < double_data[11]){ |
||
1499 | double_data[3] = ymax + 1000; |
||
1500 | } |
||
1501 | else |
||
1502 | { |
||
1503 | double_data[3] = ymin - 1000; |
||
1504 | } |
||
10953 | bpr | 1505 | double_data[2] = double_data[0]; |
8244 | schaersvoo | 1506 | } |
1507 | else |
||
1508 | { /* horizontal halfline*/ |
||
1509 | if( double_data[1] == double_data[11] ){ |
||
1510 | if( double_data[0] < double_data[10] ){ |
||
1511 | double_data[2] = xmax + 1000; /* halfline to the right */ |
||
1512 | } |
||
1513 | else |
||
1514 | { |
||
1515 | double_data[2] = xmin - 1000; /* halfline to the left */ |
||
1516 | } |
||
1517 | double_data[3] = double_data[1]; |
||
1518 | } |
||
1519 | else |
||
1520 | { |
||
1521 | /* any other halfline */ |
||
1522 | /* slope */ |
||
1523 | double_data[12] = (double_data[11] - double_data[1])/(double_data[10] - double_data[0]); |
||
1524 | /* const */ |
||
1525 | double_data[13] = double_data[1] - double_data[12]*double_data[0]; |
||
1526 | if( double_data[0] < double_data[10] ){ |
||
1527 | double_data[2] = double_data[2] + 1000; |
||
1528 | } |
||
1529 | else |
||
1530 | { |
||
1531 | double_data[2] = double_data[2] - 1000; |
||
1532 | } |
||
1533 | double_data[3] = double_data[12]*double_data[2] + double_data[13]; |
||
1534 | } |
||
10953 | bpr | 1535 | } |
8244 | schaersvoo | 1536 | decimals = find_number_of_digits(precision); |
11802 | schaersvoo | 1537 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,18,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,double_data[1],decimals,double_data[3],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset); |
8379 | schaersvoo | 1538 | if(onclick > 0){click_cnt++;} |
1539 | /* click_cnt++; */ |
||
1540 | reset(); |
||
8244 | schaersvoo | 1541 | break; |
1542 | } |
||
1543 | } |
||
1544 | break; |
||
8386 | schaersvoo | 1545 | |
8365 | schaersvoo | 1546 | case HALFLINES: |
1547 | /* |
||
1548 | @ demilines color,x1,y1,x2,y2,.... |
||
1549 | @ alternative : halflines |
||
1550 | @ draws halflines starting in (x1:y1) and through (x2:y2) in color 'color' (colorname or hex) etc etc |
||
9406 | schaersvoo | 1551 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> indiviually |
8365 | schaersvoo | 1552 | */ |
1553 | stroke_color=get_color(infile,0); |
||
1554 | fill_color = stroke_color; |
||
1555 | i=0; |
||
1556 | while( ! done ){ /* get next item until EOL*/ |
||
1557 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
1558 | if(i%2 == 0 ){ |
||
1559 | double_data[i] = get_real(infile,0); /* x */ |
||
1560 | } |
||
1561 | else |
||
1562 | { |
||
1563 | double_data[i] = get_real(infile,1); /* y */ |
||
1564 | } |
||
1565 | i++; |
||
1566 | } |
||
1567 | decimals = find_number_of_digits(precision); |
||
1568 | for(c = 0 ; c < i-1 ; c = c+4){ |
||
1569 | if( double_data[c] == double_data[c+2] ){ /* vertical line*/ |
||
1570 | if(double_data[c+1] < double_data[c+3]){ /* upright halfline */ |
||
1571 | double_data[c+3] = ymax + 1000; |
||
1572 | } |
||
1573 | else |
||
1574 | { |
||
1575 | double_data[c+3] = ymin - 1000;/* descending halfline */ |
||
1576 | } |
||
1577 | } |
||
1578 | else |
||
1579 | { |
||
1580 | if( double_data[c+1] == double_data[c+3] ){ /* horizontal line */ |
||
1581 | if(double_data[c] < double_data[c+2] ){ /* halfline to the right */ |
||
1582 | double_data[c+2] = xmax+100; |
||
1583 | } |
||
1584 | else |
||
1585 | { |
||
1586 | double_data[c+2] = xmin-1000; /* halfline to the right */ |
||
1587 | } |
||
1588 | } |
||
1589 | else |
||
1590 | { |
||
1591 | /* m */ |
||
1592 | double m = (double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]); |
||
1593 | /* q */ |
||
1594 | double q = double_data[c+1] - ((double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]))*double_data[c]; |
||
1595 | if(double_data[c] < double_data[c+2]){ /* to the right */ |
||
1596 | double_data[c+2] = xmax+1000; /* 1000 is needed for dragging...otherwise it's just segment */ |
||
1597 | double_data[c+3] = (m)*(double_data[c+2])+(q); |
||
1598 | } |
||
1599 | else |
||
1600 | { /* to the left */ |
||
1601 | double_data[c+2] = xmin - 1000; |
||
1602 | double_data[c+3] = (m)*(double_data[c+2])+(q); |
||
1603 | } |
||
1604 | } |
||
1605 | } |
||
11802 | schaersvoo | 1606 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,18,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+2],decimals,double_data[c+1],decimals,double_data[c+3],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset); |
8379 | schaersvoo | 1607 | if(onclick > 0){click_cnt++;} |
1608 | /* click_cnt++; */ |
||
8365 | schaersvoo | 1609 | } |
1610 | reset(); |
||
1611 | break; |
||
11806 | schaersvoo | 1612 | case HATCHFILL: |
1613 | /* |
||
1614 | @ hatchfill x0,y0,dx,dy,color |
||
1615 | @ x0,y0 in xrange / yrange |
||
1616 | @ distances dx,dy in pixels |
||
1617 | */ |
||
1618 | if( js_function[DRAW_HATCHFILL] != 1 ){ js_function[DRAW_HATCHFILL] = 1;} |
||
1619 | for(i=0;i<5;i++){ |
||
1620 | switch(i){ |
||
1621 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */ |
||
1622 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y */ |
||
1623 | case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */ |
||
1624 | case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/ |
||
1625 | case 4: stroke_color = get_color(infile,1); |
||
1626 | /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */ |
||
1627 | string_length = snprintf(NULL,0, "draw_hatchfill(%d,%d,%d,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],int_data[2],int_data[3],line_width,stroke_color,stroke_opacity,xsize,ysize); |
||
1628 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
1629 | snprintf(tmp_buffer,string_length,"draw_hatchfill(%d,%d,%d,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],int_data[2],int_data[3],line_width,stroke_color,stroke_opacity,xsize,ysize); |
||
1630 | add_to_buffer(tmp_buffer); |
||
1631 | break; |
||
1632 | default:break; |
||
1633 | } |
||
1634 | } |
||
1635 | reset(); |
||
1636 | break; |
||
8386 | schaersvoo | 1637 | |
8224 | bpr | 1638 | case HLINE: |
7614 | schaersvoo | 1639 | /* |
1640 | @ hline x,y,color |
||
9383 | schaersvoo | 1641 | @ alternative : horizontalline |
7614 | schaersvoo | 1642 | @ draw a horizontal line through point (x:y) in color 'color' |
9373 | schaersvoo | 1643 | @ or use command <a href='#curve'>'curve color,formula'</a> to draw the line <br />(uses more points to draw the line; is however better draggable) |
9406 | schaersvoo | 1644 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
7614 | schaersvoo | 1645 | */ |
1646 | for(i=0;i<3;i++) { |
||
1647 | switch(i){ |
||
1648 | case 0: double_data[0] = get_real(infile,0);break; /* x-values */ |
||
1649 | case 1: double_data[1] = get_real(infile,0);break; /* y-values */ |
||
1650 | case 2: stroke_color = get_color(infile,1);/* name or hex color */ |
||
1651 | double_data[3] = double_data[1]; |
||
1652 | decimals = find_number_of_digits(precision); |
||
11802 | schaersvoo | 1653 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d));\n",click_cnt,onclick,drag_type,decimals,100*xmin,decimals,100*xmax,decimals,double_data[1],decimals,double_data[3],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset); |
8379 | schaersvoo | 1654 | if(onclick > 0){click_cnt++;} |
1655 | /* click_cnt++; */ |
||
1656 | reset(); |
||
7614 | schaersvoo | 1657 | break; |
1658 | } |
||
1659 | } |
||
1660 | break; |
||
8366 | schaersvoo | 1661 | |
1662 | case HLINES: |
||
1663 | /* |
||
1664 | @ hlines color,x1,y1,x2,y2,... |
||
9383 | schaersvoo | 1665 | @ alternative : horizontallines |
8366 | schaersvoo | 1666 | @ draw horizontal lines through points (x1:y1)...(xn:yn) in color 'color' |
9406 | schaersvoo | 1667 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually |
8366 | schaersvoo | 1668 | */ |
1669 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
1670 | fill_color = stroke_color; |
||
1671 | i=0; |
||
1672 | while( ! done ){ /* get next item until EOL*/ |
||
1673 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
1674 | if(i%2 == 0 ){ |
||
1675 | double_data[i] = get_real(infile,0); /* x */ |
||
1676 | } |
||
1677 | else |
||
1678 | { |
||
1679 | double_data[i] = get_real(infile,1); /* y */ |
||
1680 | } |
||
1681 | i++; |
||
1682 | } |
||
1683 | decimals = find_number_of_digits(precision); |
||
1684 | for(c = 0 ; c < i-1 ; c = c+2){ |
||
11802 | schaersvoo | 1685 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d));\n",click_cnt,onclick,drag_type,decimals,xmin,decimals,xmax,decimals,double_data[c+1],decimals,double_data[c+1],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset); |
8379 | schaersvoo | 1686 | if(onclick > 0){click_cnt++;} |
1687 | /* click_cnt++; */ |
||
8366 | schaersvoo | 1688 | } |
1689 | reset(); |
||
1690 | break; |
||
11806 | schaersvoo | 1691 | case HTTP: |
7614 | schaersvoo | 1692 | /* |
11806 | schaersvoo | 1693 | @ http x1,y1,x2,y2,http://some_adress.com |
1694 | @ an active html-page will be displayed in an "iframe" rectangle left top (x1:y1) , right bottom (x2:y2) |
||
1695 | @ do not use interactivity (or mouse) if the mouse needs to be active in the iframe |
||
1696 | @ can <b>not</b> be 'set onclick' or 'drag xy' |
||
7614 | schaersvoo | 1697 | */ |
11806 | schaersvoo | 1698 | if( js_function[DRAW_HTTP] != 1 ){ js_function[DRAW_HTTP] = 1;} |
1699 | for(i=0;i<5;i++){ |
||
7614 | schaersvoo | 1700 | switch(i){ |
11806 | schaersvoo | 1701 | case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */ |
1702 | case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system -> pixel height */ |
||
1703 | case 2: int_data[2]=x2px(get_real(infile,0)) - int_data[0];break; /* width in x/y-range coord system -> pixel width */ |
||
1704 | case 3: int_data[3]=y2px(get_real(infile,0)) - int_data[1];break; /* height in x/y-range coord system -> pixel height */ |
||
1705 | case 4: decimals = find_number_of_digits(precision); |
||
1706 | temp = get_string(infile,1); |
||
1707 | if(strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'");} |
||
1708 | string_length = snprintf(NULL,0,"draw_http(%d,%d,%d,%d,%d,\"%s\");\n",canvas_root_id,int_data[0],int_data[1],int_data[2],int_data[3],temp); |
||
1709 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+2); |
||
1710 | 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); |
||
1711 | add_to_buffer(tmp_buffer); |
||
7614 | schaersvoo | 1712 | break; |
1713 | } |
||
1714 | } |
||
11806 | schaersvoo | 1715 | reset(); |
7614 | schaersvoo | 1716 | break; |
11806 | schaersvoo | 1717 | case HTML: |
8366 | schaersvoo | 1718 | /* |
11806 | schaersvoo | 1719 | @ html x1,y1,x2,y2,html_string |
1720 | @ all tags are allowed<br /> html-code using inputfields could be read using your own javascript-code. Do not use id's like 'canvas_input0' etc. |
||
1721 | @ can be set onclick <br />(however dragging not supported) |
||
8366 | schaersvoo | 1722 | */ |
11806 | schaersvoo | 1723 | if( js_function[DRAW_XML] != 1 ){ js_function[DRAW_XML] = 1;} |
1724 | for(i=0;i<5;i++){ |
||
1725 | switch(i){ |
||
1726 | case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */ |
||
1727 | case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system -> pixel height */ |
||
1728 | case 2: int_data[2]=x2px(get_real(infile,0));break;/* no more width needed : overflow */ |
||
1729 | case 3: int_data[3]=y2px(get_real(infile,0));break;/* no more height needed : overflow */ |
||
1730 | case 4: decimals = find_number_of_digits(precision); |
||
1731 | temp = get_string(infile,1); |
||
1732 | if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'"); } |
||
1733 | string_length = snprintf(NULL,0,"draw_xml(%d,%d,%d,\"%s\",%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f);\n",canvas_root_id,int_data[0],int_data[1],temp,drag_type,onclick,click_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity); |
||
1734 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
1735 | snprintf(tmp_buffer,string_length,"draw_xml(%d,%d,%d,\"%s\",%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f);\n",canvas_root_id,int_data[0],int_data[1],temp,drag_type,onclick,click_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity); |
||
1736 | add_to_buffer(tmp_buffer); |
||
1737 | if(onclick == 1 || onclick == 2 ){click_cnt++;} |
||
1738 | break; |
||
1739 | default:break; |
||
8366 | schaersvoo | 1740 | } |
1741 | } |
||
1742 | reset(); |
||
1743 | break; |
||
8386 | schaersvoo | 1744 | |
11806 | schaersvoo | 1745 | case IMAGEFILL: |
7614 | schaersvoo | 1746 | /* |
11806 | schaersvoo | 1747 | @ imagefill dx,dy,image_url |
1748 | @ The next suitable <b>filled object</b> will be filled with "image_url" tiled |
||
1749 | @ After pattern filling ,the fill-color should be reset ! |
||
1750 | @ wims getins / image from class directory : imagefill 80,80,my_image.gif |
||
1751 | @ normal url : imagefill 80,80,$module_dir/gifs/my_image.gif |
||
1752 | @ normal url : imagefill 80,80,http://adres/a/b/c/my_image.jpg |
||
1753 | @ if dx,dy is larger than the image, the whole image will be background to the next object. |
||
7614 | schaersvoo | 1754 | */ |
11806 | schaersvoo | 1755 | if( js_function[DRAW_IMAGEFILL] != 1 ){ js_function[DRAW_IMAGEFILL] = 1;} |
1756 | for(i=0 ;i < 3 ; i++){ |
||
7614 | schaersvoo | 1757 | switch(i){ |
11806 | schaersvoo | 1758 | case 0:int_data[0] = (int) (get_real(infile,0));break; |
1759 | case 1:int_data[1] = (int) (get_real(infile,0));break; |
||
1760 | case 2: URL = get_string_argument(infile,1); |
||
1761 | string_length = snprintf(NULL,0, "draw_imagefill(%d,%d,%d,\"%s\",%d,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],URL,xsize,ysize); |
||
1762 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
1763 | snprintf(tmp_buffer,string_length,"draw_imagefill(%d,%d,%d,\"%s\",%d,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],URL,xsize,ysize); |
||
1764 | add_to_buffer(tmp_buffer); |
||
1765 | break; |
||
7614 | schaersvoo | 1766 | } |
1767 | } |
||
11806 | schaersvoo | 1768 | reset(); |
1769 | break; |
||
1770 | |||
1771 | case INPUTSTYLE: |
||
1772 | /* |
||
1773 | @ inputstyle style_description |
||
1774 | @ may be used before any 'style-able' html object.(like inputfields or buttons)<br />or any html objects that are generated by some canvasdraw commands |
||
1775 | @ example: inputstyle color:blue;font-weight:bold;font-style:italic;font-size:16pt |
||
1776 | */ |
||
1777 | input_style = get_string(infile,1); |
||
7614 | schaersvoo | 1778 | break; |
11806 | schaersvoo | 1779 | case INPUT: |
1780 | /* |
||
1781 | @ input x,y,size,editable,value |
||
1782 | @ to set inputfield "readonly", use editable = 0 |
||
1783 | @ only active inputfields (editable = 1) will be read with read_canvas(); |
||
1784 | @ if "$status=done" (e.g. in answer.phtml) the inputfield will be cleared and set readonly<br />override this by keyword <a href="#status">'status'</a> |
||
1785 | @ may be further controlled by <a href="#inputstyle">"inputstyle"</a> (inputcss is not yet implemented...) |
||
1786 | @ if mathml inputfields are present and / or some userdraw is performed, these data will <b>not</b> be send as well (javascript:read_canvas();) |
||
1787 | @ 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) |
||
1788 | */ |
||
1789 | if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;} |
||
1790 | for(i = 0 ; i<5;i++){ |
||
1791 | switch(i){ |
||
1792 | case 0: int_data[0]=x2px(get_real(infile,0));break;/* x in px */ |
||
1793 | case 1: int_data[1]=y2px(get_real(infile,0));break;/* y in px */ |
||
1794 | case 2: int_data[2]=abs( (int)(get_real(infile,0)));break; /* size */ |
||
1795 | case 3: if( get_real(infile,1) >0){int_data[3] = 1;}else{int_data[3] = 0;};break; /* readonly */ |
||
1796 | case 4: |
||
1797 | temp = get_string_argument(infile,1); |
||
1798 | string_length = snprintf(NULL,0, "draw_inputs(%d,%d,%d,%d,%d,%d,\"%s\",\"%s\",%d);\n",canvas_root_id,input_cnt,int_data[0],int_data[1],int_data[2],int_data[3],input_style,temp,use_offset); |
||
1799 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
1800 | 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); |
||
1801 | add_to_buffer(tmp_buffer); |
||
1802 | input_cnt++;break; |
||
1803 | default: break; |
||
1804 | } |
||
1805 | } |
||
1806 | if(reply_format == 0 ){reply_format = 15;} |
||
1807 | reset(); |
||
1808 | break; |
||
8386 | schaersvoo | 1809 | |
11806 | schaersvoo | 1810 | case INTOOLTIP: |
1811 | /* |
||
1812 | @ intooltip link_text |
||
1813 | @ link_text is a single line (span-element) |
||
1814 | @ link_text may also be an image URL 'http://some_server/images/my_image.png' or '$module_dir/gifs/my_image.jpg' |
||
1815 | @ link_text may contain HTML markup |
||
1816 | @ the canvas will be displayed in a tooltip on 'link_text' |
||
1817 | @ the canvas is default transparent: use command <a href="#bgcolor">'bgcolor color'</a> to adjust background-color<br />the link text will also be shown with this 'bgcolor'. |
||
1818 | @ many 'userinput stuff' will use the tooltip_placeholder_div element...only one is defined in the wims-page<br />and are therefor these commands are mutually exclusive.<br />keep this in mind... |
||
1819 | */ |
||
1820 | if(use_input_xy != FALSE ){canvas_error("intooltip can not be combined with userinput_xy or other commands using the tooltip-div...see documentation");} |
||
1821 | if( use_tooltip == 1 ){ canvas_error("command 'intooltip' cannot be combined with command 'popup'...");} |
||
1822 | tooltip_text = get_string(infile,1); |
||
1823 | if(strstr(tooltip_text,"\"") != 0 ){ tooltip_text = str_replace(tooltip_text,"\"","'"); } |
||
1824 | use_tooltip = 1; |
||
1825 | break; |
||
1826 | |||
1827 | case JSCURVE: |
||
7614 | schaersvoo | 1828 | /* |
11806 | schaersvoo | 1829 | @ jscurve color,formula(x) |
1830 | @ alternative : jsplot color,formula(x) |
||
1831 | @ your function will be plotted by the javascript engine of the client browser. |
||
1832 | @ use only basic math in your curve:<br /> sqrt,^,asin,acos,atan,log,pi,abs,sin,cos,tan,e |
||
1833 | @ use parenthesis and rawmath : use 2*x instead of 2x ; use 2^(sin(x))...etc etc<br />use error console to debug any errors... |
||
1834 | @ <b>attention</b> : last "precision" command in the canvasdraw script determines the calculation precision of the javascript curve plot ! |
||
1835 | @ no validity check is done by wims. |
||
1836 | @ 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 |
||
1837 | @ 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 |
||
1838 | @ use command 'trace_jscurve formula(x)` for tracing |
||
1839 | @ use command 'jsmath formula(x)` for calculating and displaying indiviual points on the curve |
||
1840 | @ can <b>not</b> be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> (yet) |
||
1841 | @ commands plotjump / plotstep are not active for 'jscurve' |
||
1842 | @ every command jscurve will produce a new canvas (canvastype 111,112,113...) for this one curve. |
||
1843 | @ plotting multiple js-curves on the same canvas <br/>(for example if you want to use 'userdraw clickfill,color' on <a href="#canvastype">canvastype</a> number 111 ,use :<br/> jscurve red,fun1(x),fun2(x)...fun_n(x)<br /> you want to specify individual colors | opacity | linewidth for these multiple js-curves.<br />use commands like: <a href="#multistrokecolors">multistrokecolors</a>,<a href="#multilinewidth">multilinewidth</a>, <a href="#multidash">multidash</a><br />, <a href="multistrokeopacity">multistroke</a><br />the <b>color</b> given for the command "jscurve <b>color</b>,formulas(x)" will not be used in that case...<br />but the color argument must still be given in any case (otherwise syntax error...) |
||
1844 | */ |
||
1845 | stroke_color = get_color(infile,0); |
||
1846 | if( use_js_math == FALSE){/* add this stuff only once...*/ |
||
1847 | add_to_js_math(js_include_file); |
||
1848 | use_js_math = TRUE; |
||
1849 | } |
||
1850 | if( use_js_plot == FALSE){ |
||
1851 | use_js_plot = TRUE; |
||
1852 | add_jsplot(js_include_file,canvas_root_id); /* this plots the function on JSPLOT_CANVAS */ |
||
1853 | } |
||
1854 | temp = get_string(infile,1); |
||
1855 | temp = str_replace(temp,",","\",\""); |
||
1856 | string_length = snprintf(NULL,0, "jsplot(%d,[\"%s\"],[%d],[\"%s\"],[%.2f],[%d],%d,%d); ",JSPLOT_CANVAS+jsplot_cnt,temp,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]); |
||
1857 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
1858 | snprintf(tmp_buffer,string_length,"jsplot(%d,[\"%s\"],[%d],[\"%s\"],[%.2f],[%d],%d,%d); ",JSPLOT_CANVAS+jsplot_cnt,temp,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]); |
||
1859 | add_to_buffer(tmp_buffer); |
||
1860 | jsplot_cnt++; |
||
1861 | /* we need to create multiple canvasses, so we may zoom and pan ?? */ |
||
1862 | break; |
||
1863 | |||
1864 | case JSMATH: |
||
1865 | /* |
||
1866 | @ jsmath some_math_function |
||
1867 | @ will calculate an y-value from a userinput x-value and draws a crosshair on these coordinates. |
||
1868 | @ default labels 'x' and 'y'<br />the commands 'xlabel some_x_axis_name' and 'ylabel some_y_axis_name' will set the label for the input fields |
||
1869 | @ use command 'inputstyle some_css' for styling the display fields. Use command 'fontsize int' to size the labels 'x' and 'y' |
||
1870 | @ example: jsmath sin(x^2) |
||
1871 | @ 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... |
||
1872 | @ be aware that the formula's of the plotted function(s) can be found in the page javascript source |
||
1873 | */ |
||
1874 | if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;} |
||
1875 | if( use_js_math == FALSE){ |
||
1876 | add_to_js_math(js_include_file); |
||
1877 | use_js_math = TRUE; |
||
1878 | } |
||
1879 | add_calc_y(js_include_file,canvas_root_id,get_string(infile,1),font_size,input_style); |
||
1880 | break; |
||
1881 | case KILLAFFINE: |
||
1882 | /* |
||
1883 | @ killaffine |
||
1884 | @ keyword : resets the transformation matrix to 1,0,0,1,0,0 |
||
1885 | */ |
||
1886 | use_affine = FALSE; |
||
1887 | snprintf(affine_matrix,14,"[1,0,0,1,0,0]"); |
||
1888 | break; |
||
1889 | |||
1890 | case KILLROTATE: |
||
1891 | /* |
||
1892 | @ killrotate will reset the command <a href="#rotationcenter">rotationcenter xc,yc</a> |
||
1893 | @ a following rotate command will have the first object point as rotation center |
||
1894 | @ if not set, the rotation center will remain unchanged |
||
1895 | */ |
||
1896 | rotation_center= my_newmem(6); |
||
1897 | snprintf(rotation_center,5,"null"); |
||
1898 | break; |
||
1899 | |||
1900 | case KILLSLIDER: |
||
1901 | /* |
||
1902 | @ killslider |
||
1903 | @ keyword (no arguments required) |
||
1904 | @ ends grouping of object under a previously defined slider |
||
1905 | */ |
||
1906 | slider = 0; |
||
1907 | break; |
||
1908 | |||
1909 | case KILLTRANSLATION: |
||
1910 | /* |
||
1911 | @ killtranslation |
||
1912 | @ alternative : killtranslate |
||
1913 | @ resets the translation matrix to 1,0,0,1,0,0 |
||
1914 | */ |
||
1915 | use_affine = FALSE; |
||
1916 | snprintf(affine_matrix,14,"[1,0,0,1,0,0]"); |
||
1917 | break; |
||
1918 | |||
1919 | case LINE: |
||
1920 | /* |
||
1921 | @ line x1,y1,x2,y2,color |
||
1922 | @ draw a line through points (x1:y1)--(x2:y2) in color 'color' |
||
1923 | @ or use command 'curve color,formula' to draw the line <br />(uses more points to draw the line; is however better draggable) |
||
9406 | schaersvoo | 1924 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
7614 | schaersvoo | 1925 | */ |
8386 | schaersvoo | 1926 | for(i=0;i<5;i++){ |
7614 | schaersvoo | 1927 | switch(i){ |
11806 | schaersvoo | 1928 | case 0: double_data[10]= get_real(infile,0);break; /* x-values */ |
1929 | case 1: double_data[11]= get_real(infile,0);break; /* y-values */ |
||
1930 | case 2: double_data[12]= get_real(infile,0);break; /* x-values */ |
||
1931 | case 3: double_data[13]= get_real(infile,0);break; /* y-values */ |
||
1932 | case 4: stroke_color=get_color(infile,1);/* name or hex color */ |
||
1933 | if( double_data[10] == double_data[12] ){ /* vertical line*/ |
||
1934 | double_data[1] = xmin; |
||
1935 | double_data[3] = ymax; |
||
1936 | double_data[0] = double_data[10]; |
||
1937 | double_data[2] = double_data[10]; |
||
1938 | } |
||
1939 | else |
||
1940 | { |
||
1941 | if( double_data[11] == double_data[13] ){ /* horizontal line */ |
||
1942 | double_data[1] = double_data[11]; |
||
1943 | double_data[3] = double_data[11]; |
||
1944 | double_data[0] = ymin; |
||
1945 | double_data[2] = xmax; |
||
1946 | } |
||
1947 | else |
||
1948 | { |
||
1949 | /* m */ |
||
1950 | double_data[5] = (double_data[13] - double_data[11]) /(double_data[12] - double_data[10]); |
||
1951 | /* q */ |
||
1952 | double_data[6] = double_data[11] - ((double_data[13] - double_data[11]) /(double_data[12] - double_data[10]))*double_data[10]; |
||
1953 | |||
1954 | /*xmin,m*xmin+q,xmax,m*xmax+q*/ |
||
1955 | |||
1956 | double_data[1] = (double_data[5])*(xmin)+(double_data[6]); |
||
1957 | double_data[3] = (double_data[5])*(xmax)+(double_data[6]); |
||
1958 | double_data[0] = xmin; |
||
1959 | double_data[2] = xmax; |
||
1960 | } |
||
1961 | } |
||
1962 | decimals = find_number_of_digits(precision); |
||
1963 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,double_data[1],decimals,double_data[3],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset); |
||
1964 | if(onclick > 0){click_cnt++;} |
||
1965 | /* click_cnt++;*/ |
||
1966 | reset(); |
||
1967 | break; |
||
7614 | schaersvoo | 1968 | } |
1969 | } |
||
1970 | break; |
||
8386 | schaersvoo | 1971 | |
11806 | schaersvoo | 1972 | case LINES: |
8370 | schaersvoo | 1973 | /* |
11806 | schaersvoo | 1974 | @ lines color,x1,y1,x2,y2...x_n-1,y_n-1,x_n,y_n |
1975 | @ draw multiple lines through points (x1:y1)--(x2:y2) ...(x_n-1:y_n-1)--(x_n:y_n) in color 'color' |
||
1976 | @ 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) |
||
1977 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
||
1978 | @ <b>attention</b>: the flydraw command "lines" is equivalent to canvasdraw command <a href="#polyline">"polyline"</a> |
||
8370 | schaersvoo | 1979 | */ |
1980 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
1981 | fill_color = stroke_color; |
||
1982 | i=0; |
||
1983 | while( ! done ){ /* get next item until EOL*/ |
||
1984 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
1985 | if(i%2 == 0 ){ |
||
1986 | double_data[i] = get_real(infile,0); /* x */ |
||
1987 | } |
||
1988 | else |
||
1989 | { |
||
1990 | double_data[i] = get_real(infile,1); /* y */ |
||
1991 | } |
||
1992 | i++; |
||
1993 | } |
||
1994 | decimals = find_number_of_digits(precision); |
||
1995 | for(c = 0 ; c < i-1 ; c = c+4){ |
||
11806 | schaersvoo | 1996 | if( double_data[c] == double_data[c+2] ){ /* vertical line*/ |
1997 | double_data[c+1] = xmin; |
||
1998 | double_data[c+3] = ymax; |
||
1999 | double_data[c+2] = double_data[c]; |
||
2000 | } |
||
2001 | else |
||
2002 | { |
||
2003 | if( double_data[c+1] == double_data[c+3] ){ /* horizontal line */ |
||
2004 | double_data[c+3] = double_data[c+1]; |
||
2005 | double_data[c] = ymin; |
||
2006 | double_data[c+2] = xmax; |
||
2007 | } |
||
2008 | else |
||
2009 | { |
||
2010 | /* m */ |
||
2011 | double m = (double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]); |
||
2012 | /* q */ |
||
2013 | double q = double_data[c+1] - ((double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]))*double_data[c]; |
||
2014 | /*xmin,m*xmin+q,xmax,m*xmax+q*/ |
||
2015 | double_data[c+1] = (m)*(xmin)+(q); |
||
2016 | double_data[c+3] = (m)*(xmax)+(q); |
||
2017 | double_data[c] = xmin; |
||
2018 | double_data[c+2] = xmax; |
||
2019 | } |
||
2020 | } |
||
2021 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+2],decimals,double_data[c+1],decimals,double_data[c+3],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset); |
||
8379 | schaersvoo | 2022 | if(onclick > 0){click_cnt++;} |
2023 | /* click_cnt++; */ |
||
8370 | schaersvoo | 2024 | } |
2025 | reset(); |
||
2026 | break; |
||
8386 | schaersvoo | 2027 | |
11806 | schaersvoo | 2028 | |
2029 | case LINEWIDTH: |
||
7614 | schaersvoo | 2030 | /* |
11806 | schaersvoo | 2031 | @ linewidth int |
2032 | @ default 1 |
||
7614 | schaersvoo | 2033 | */ |
11806 | schaersvoo | 2034 | line_width = (int) (get_real(infile,1)); |
2035 | break; |
||
2036 | |||
2037 | case LATTICE: |
||
2038 | /* |
||
2039 | @ lattice x0,y0,xv1,yv1,xv2,yv2,n1,n2,color |
||
2040 | @ can <b>not</b> be set "onclick" or "drag xy" |
||
2041 | */ |
||
2042 | if( js_function[DRAW_LATTICE] != 1 ){ js_function[DRAW_LATTICE] = 1;} |
||
2043 | for( i = 0; i<9; i++){ |
||
7614 | schaersvoo | 2044 | switch(i){ |
11806 | schaersvoo | 2045 | case 0: int_data[0] = x2px(get_real(infile,0));break; /* x0-values -> x-pixels*/ |
2046 | case 1: int_data[1] = y2px(get_real(infile,0));break; /* y0-values -> y-pixels*/ |
||
2047 | case 2: int_data[2] = (int) (get_real(infile,0));break; /* x1-values -> x-pixels*/ |
||
2048 | case 3: int_data[3] = (int) -1*(get_real(infile,0));break; /* y1-values -> y-pixels*/ |
||
2049 | case 4: int_data[4] = (int) (get_real(infile,0));break; /* x2-values -> x-pixels*/ |
||
2050 | case 5: int_data[5] = (int) -1*(get_real(infile,0));break; /* y2-values -> y-pixels*/ |
||
2051 | case 6: int_data[6] = (int) (get_real(infile,0));break; /* n1-values */ |
||
2052 | case 7: int_data[7] = (int) (get_real(infile,0));break; /* n2-values */ |
||
2053 | case 8: stroke_color=get_color(infile,1); |
||
7614 | schaersvoo | 2054 | decimals = find_number_of_digits(precision); |
11806 | schaersvoo | 2055 | string_length = snprintf(NULL,0,"draw_lattice(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%.2f,%d,%s);",STATIC_CANVAS,line_width,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],fill_color,fill_opacity,stroke_color,stroke_opacity,use_rotate,angle,use_affine,affine_matrix); |
2056 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
2057 | snprintf(tmp_buffer,string_length,"draw_lattice(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%.2f,%d,%s);",STATIC_CANVAS,line_width,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],fill_color,fill_opacity,stroke_color,stroke_opacity,use_rotate,angle,use_affine,affine_matrix); |
||
2058 | add_to_buffer(tmp_buffer);break; |
||
2059 | default:break; |
||
7614 | schaersvoo | 2060 | } |
2061 | } |
||
11806 | schaersvoo | 2062 | reset(); |
7614 | schaersvoo | 2063 | break; |
8363 | schaersvoo | 2064 | |
11806 | schaersvoo | 2065 | case LEVELCURVE: |
8363 | schaersvoo | 2066 | /* |
11806 | schaersvoo | 2067 | @ levelcurve color,expression in x/y,l1,l2,... |
2068 | @ draws very primitive level curves for expression, with levels l1,l2,l3,...,l_n |
||
2069 | @ the quality is <b>not to be compared</b> with the Flydraw levelcurve. <br />(choose flydraw if you want quality...) |
||
2070 | @ 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 |
||
2071 | @ note : the arrays for holding the javascript data are limited in size |
||
2072 | @ note : reduce image size if javascript data arrays get overloaded<br />(command 'plotsteps int' will not control the data size of the plot...) |
||
8363 | schaersvoo | 2073 | */ |
11806 | schaersvoo | 2074 | fill_color = get_color(infile,0); |
2075 | char *fun1 = get_string_argument(infile,0); |
||
2076 | if( strlen(fun1) == 0 ){canvas_error("function is NOT OK !");} |
||
2077 | i = 0; |
||
2078 | done = FALSE; |
||
2079 | while( !done ){ |
||
2080 | double_data[i] = get_real(infile,1); |
||
2081 | i++; |
||
2082 | } |
||
2083 | for(c = 0 ; c < i; c++){ |
||
2084 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,16,%s,[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d));\n",click_cnt,onclick,drag_type,eval_levelcurve(xsize,ysize,fun1,xmin,xmax,ymin,ymax,plot_steps,precision,double_data[c]),line_width,line_width,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset); |
||
2085 | if(onclick > 0){click_cnt++;} |
||
2086 | /* click_cnt++; */ |
||
2087 | } |
||
2088 | reset(); |
||
2089 | break; |
||
8386 | schaersvoo | 2090 | |
11806 | schaersvoo | 2091 | case LEGEND: |
2092 | /* |
||
2093 | @ legend string1:string2:string3....string_n |
||
2094 | @ will be used to create a legend for a graph |
||
2095 | @ also see command <a href='#piechart'>'piechart'</a> |
||
2096 | @ will use the same colors per default as used in the graphs : use command <a href='#legendcolors'>'legendcolors'</a> to override the default |
||
2097 | @ use command <a href="#fontsize">fontsize</a> to adjust. (command "fontfamily" is not active for command "legend") |
||
2098 | */ |
||
2099 | temp = get_string(infile,1); |
||
2100 | if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); } |
||
2101 | legend_cnt++; /* attention :starts with -1 : it will be used in piechart etc */ |
||
2102 | fprintf(js_include_file,"var legend%d = [\"%s\"];",legend_cnt,temp); |
||
2103 | break; |
||
2104 | |||
2105 | case LEGENDCOLORS: |
||
2106 | /* |
||
2107 | @ legendcolors color1:color2:color3:...:color_n |
||
2108 | @ 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 |
||
2109 | @ make sure the number of colours match the number of legend items |
||
2110 | @ command 'legend' in case of 'piechart' and 'barchart' will use these colours per default (no need to specify 'legendcolors' |
||
2111 | */ |
||
2112 | if(legend_cnt == -1){canvas_error("use command \"legend\" before command \"legendcolors\" ! ");} |
||
2113 | temp = get_string(infile,1); |
||
2114 | if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); } |
||
2115 | fprintf(js_include_file,"var legendcolors%d = [\"%s\"];",legend_cnt,temp); |
||
2116 | break; |
||
2117 | |||
2118 | case LINEGRAPH: /* scheme: var linegraph_0 = [ 'stroke_color','line_width','use_dashed' ,'dashtype0','dashtype1','x1','y1',...,'x_n','y_n'];*/ |
||
2119 | /* |
||
2120 | @ linegraph x1:y1:x2:y2...x_n:y_n |
||
2121 | @ will plot your data in a graph |
||
2122 | @ may <b>only</b> to be used together with command <a href='#grid'>'grid'</a> |
||
2123 | @ 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> |
||
2124 | @ use command <a href='#legend'>'legend'</a> to provide an optional legend in right-top-corner |
||
2125 | @ also see command <a href='#piechart'>'piechart'</a> |
||
2126 | @ multiple linegraphs may be used in a single plot |
||
2127 | @ note: your arguments are not checked by canvasdraw : use your javascript console in case of trouble... |
||
2128 | @ <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> |
||
2129 | */ |
||
2130 | temp = get_string(infile,1); |
||
2131 | if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); } |
||
2132 | 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); |
||
2133 | linegraph_cnt++; |
||
2134 | reset(); |
||
2135 | break; |
||
2136 | |||
2137 | case MATHML: |
||
2138 | /* |
||
2139 | @ mathml x1,y1,x2,y2,mathml_string |
||
2140 | @ 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. |
||
2141 | @ in case of drag(xy|x|y) | onclick the div rectangle left to corner will be the drag-anchor of the mathml object |
||
2142 | @ can be set onclick <br />javascript:read_dragdrop(); will return click numbers of mathml-objects<br />if 4 click_able object are drawn, the reply could be 1,0,1,0 ... meaning clicked on the first and third object |
||
2143 | @ can be set draggable<br /> the javascript:read_dragdrop() will return all coordinates <br />in same order as the canvas script: unmoved object will have their original coordinates... |
||
2144 | @ 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 |
||
2145 | @ 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 |
||
2146 | @ userdraw may be combined with 'mathml' ; the read_canvas() will contain the drawing. |
||
2147 | @ draggable or onclick 'external images' from command <a href='#copyresized'>copy or copyresized</a> can be combined with drag and/or onclick mathml |
||
2148 | @ other drag objects (circles/rects etc) are supported , but read_dragdrop() will probably be difficult to interpret... |
||
2149 | @ 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();" |
||
2150 | @ 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.... |
||
2151 | */ |
||
2152 | if( js_function[DRAW_XML] != 1 ){ js_function[DRAW_XML] = 1;} |
||
2153 | for(i=0;i<5;i++){ |
||
2154 | switch(i){ |
||
2155 | case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */ |
||
2156 | case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system -> pixel height */ |
||
2157 | case 2: int_data[2]=x2px(get_real(infile,0));break;/* no more width needed : overflow */ |
||
2158 | case 3: int_data[3]=y2px(get_real(infile,0));break;/* no more height needed : overflow */ |
||
2159 | case 4: decimals = find_number_of_digits(precision); |
||
2160 | temp = get_string(infile,1); |
||
2161 | if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'"); } |
||
2162 | string_length = snprintf(NULL,0,"draw_xml(%d,%d,%d,\"%s\",%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f);\n",canvas_root_id,int_data[0],int_data[1],temp,drag_type,onclick,click_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity); |
||
2163 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
2164 | snprintf(tmp_buffer,string_length,"draw_xml(%d,%d,%d,\"%s\",%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f);\n",canvas_root_id,int_data[0],int_data[1],temp,drag_type,onclick,click_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity); |
||
2165 | add_to_buffer(tmp_buffer); |
||
2166 | if(onclick == 1 || onclick == 2 ){click_cnt++;} |
||
2167 | /* |
||
2168 | in case inputs are present , trigger adding the read_mathml() |
||
2169 | if no other reply_format is defined |
||
2170 | note: all other reply types will include a reading of elements with id='mathml'+p) |
||
2171 | */ |
||
2172 | if(strstr(temp,"mathml0") != NULL){ |
||
2173 | if(reply_format == 0 ){reply_format = 16;} /* no other reply type is defined */ |
||
2174 | } |
||
2175 | break; |
||
2176 | default:break; |
||
2177 | } |
||
2178 | } |
||
2179 | reset(); |
||
2180 | break; |
||
2181 | |||
2182 | case MOUSE: |
||
2183 | /* |
||
2184 | @ mouse color,fontsize |
||
2185 | @ will display the cursor (x:y) coordinates in 'color' and 'font size'<br /> using default fontfamily Ariel |
||
2186 | @ note: use command 'mouse' at the end of your script code (the same is true for command 'zoom') |
||
2187 | |||
2188 | */ |
||
2189 | stroke_color = get_color(infile,0); |
||
2190 | font_size = (int) (get_real(infile,1)); |
||
2191 | tmp_buffer = my_newmem(26); |
||
2192 | snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer); |
||
2193 | add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,2); |
||
2194 | break; |
||
2195 | |||
2196 | |||
2197 | case MOUSE_DEGREE: |
||
2198 | /* |
||
2199 | @ mouse_degree color,fontsize |
||
2200 | @ 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 |
||
2201 | @ The angle is positive in QI and QIII and the angle value is negative in QII and QIV |
||
2202 | @ note: use command 'mouse' at the end of your script code (the same is true for command 'zoom') |
||
2203 | |||
2204 | */ |
||
2205 | stroke_color = get_color(infile,0); |
||
2206 | font_size = (int) (get_real(infile,1)); |
||
2207 | tmp_buffer = my_newmem(26); |
||
2208 | snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer); |
||
2209 | add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,3); |
||
2210 | js_function[JS_FIND_ANGLE] = 1; |
||
2211 | break; |
||
2212 | case MOUSE_DISPLAY: |
||
2213 | /* |
||
2214 | @ display TYPE,color,fontsize |
||
2215 | @ TYPE may be x | y | xy | degree | radian | radius |
||
2216 | @ will display the mouse cursor coordinates as x-only,y-only,(x:y),<br />the radius of a circle (this only in case 'userdraw circle(s),color')<br />or the angle in degrees or radians for commands "userdraw arc,color" or protractor , ruler (if set dynamic) |
||
2217 | @ use commands 'xunit' and / or 'yunit' to add the units to the mouse values.<br />The "degree | radian" will always have the appropriate symbol) |
||
2218 | @ just like commands 'mouse','mousex','mousey','mouse_degree'...only other name) |
||
2219 | */ |
||
2220 | temp = get_string_argument(infile,0); |
||
2221 | if( strstr(temp,"xy") != NULL ){ |
||
2222 | int_data[0] = 2; |
||
2223 | }else{ |
||
2224 | if( strstr(temp,"y") != NULL ){ |
||
2225 | int_data[0] = 1; |
||
2226 | }else{ |
||
2227 | if( strstr(temp,"x") != NULL ){ |
||
2228 | int_data[0] = 0; |
||
2229 | }else{ |
||
2230 | if(strstr(temp,"degree") != NULL){ |
||
2231 | int_data[0] = 3; |
||
2232 | js_function[JS_FIND_ANGLE] = 1; |
||
2233 | }else{ |
||
2234 | if(strstr(temp,"radian") != NULL){ |
||
2235 | int_data[0] = 4; |
||
2236 | js_function[JS_FIND_ANGLE] = 1; |
||
2237 | }else{ |
||
2238 | if(strstr(temp,"radius") != NULL){ |
||
2239 | int_data[0] = 5; |
||
2240 | }else{ |
||
2241 | int_data[0] = 2; |
||
2242 | } |
||
2243 | } |
||
2244 | } |
||
2245 | } |
||
2246 | } |
||
2247 | } |
||
2248 | stroke_color = get_color(infile,0); |
||
2249 | font_size = (int) (get_real(infile,1)); |
||
2250 | tmp_buffer = my_newmem(26); |
||
2251 | snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer); |
||
2252 | add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,int_data[0]); |
||
2253 | break; |
||
2254 | |||
2255 | case MOUSE_PRECISION: |
||
2256 | /* |
||
2257 | @ precision int |
||
2258 | @ 1 = no decimals ; 10 = 1 decimal ; 100 = 2 decimals etc |
||
2259 | @ may be used / changed before every object |
||
2260 | @ In case of user interaction (like 'userdraw' or 'multidraw') this value will be used to determine the amount of decimals in the reply / answer |
||
2261 | */ |
||
2262 | precision = (int) (get_real(infile,1)); |
||
2263 | if(precision < 1 ){precision = 1;}; |
||
2264 | break; |
||
2265 | |||
2266 | case MOUSEX: |
||
2267 | /* |
||
2268 | @ mousex color,fontsize |
||
2269 | @ will display the cursor x-coordinate in 'color' and 'font size'<br /> using the fontfamily Ariel |
||
2270 | @ note: use command 'mouse' at the end of your script code (the same is true for command 'zoom') |
||
2271 | |||
2272 | */ |
||
2273 | stroke_color = get_color(infile,0); |
||
2274 | font_size = (int) (get_real(infile,1)); |
||
2275 | tmp_buffer = my_newmem(26); |
||
2276 | snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer); |
||
2277 | add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,0); |
||
2278 | break; |
||
2279 | case MOUSEY: |
||
2280 | /* |
||
2281 | @ mousey color,fontsize |
||
2282 | @ will display the cursor y-coordinate in 'color' and 'font size'<br /> using default fontfamily Ariel |
||
2283 | @ note: use command 'mouse' at the end of your script code (the same is true for command 'zoom') |
||
2284 | |||
2285 | */ |
||
2286 | stroke_color = get_color(infile,0); |
||
2287 | font_size = (int) (get_real(infile,1)); |
||
2288 | tmp_buffer = my_newmem(26); |
||
2289 | snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer); |
||
2290 | add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,1); |
||
2291 | break; |
||
2292 | |||
2293 | case MULTIDASH: |
||
2294 | /* |
||
2295 | @ multidash 0,1,1 |
||
2296 | @ meaning draw objects no. 2 (circle) and 3 (segments), in the list of command like <em>'multifill points,circle,segments'</em>, are dashed |
||
2297 | @ use before command <a href='#multidraw'>'multidraw'</a> |
||
2298 | @ if not set all objects will be set 'not dashed'...<br />unless a generic keyword <em>'dashed'</em> was given before command <em>'multidraw'</em> |
||
2299 | @ the dash-type is not -yet- adjustable <br />(e.g. command <em>dashtype line_px,space_px</em> will give no control over multidraw objects) |
||
2300 | @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives... |
||
2301 | @ always use the same sequence as is used for 'multidraw' |
||
2302 | */ |
||
2303 | if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
||
2304 | temp = get_string(infile,1); |
||
2305 | temp = str_replace(temp,",","\",\""); |
||
2306 | fprintf(js_include_file,"var multidash = [\"%s\"];",temp); |
||
2307 | reset();/* if command 'dashed' was given...reset to not-dashed */ |
||
2308 | break; |
||
2309 | |||
2310 | case MULTIDRAW: |
||
2311 | /* |
||
2312 | @ multidraw obj_type_1,obj_type_2...obj_type_11 |
||
2313 | @ for simple single object user drawings you could also use command <a href="#userdraw">'userdraw'</a> |
||
2314 | @ implemented obj_types:<ul><li>point | points </li><li>circle | circles </li><li>line | lines </li><li>segment | segments </li><li>arrow | arrows <br />use command 'arrowhead int' for size (default value 8 pixels)</li><li>rect | rects </li><li>closedpoly<br /><b>only one</b> closedpolygon may be drawn.The number of 'corner points' is not preset (e.g. not limited,freestyle)<br />the polygone is closed when clicking on the first point again..(+/- 10px) </li><li>triangle | triangles</li><li>parallelogram | parallelograms</li><li>poly[3-9] | polys[3-9] draw 3...9 point polygone(s): polys3 is of course triangles </li></ul> |
||
2315 | @ 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 |
||
2316 | @ 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... |
||
2317 | @ note: mouselisteners are only active if "$status != done " (eg only drawing in an active/non-finished exercise) <br /> to overrule use command/keyword "status" (no arguments required) |
||
2318 | @ buttons for changing the obj_type (and incase of 'multiuserinput' , some inputfields and buttons) <br />will be present in the reserved div 'tooltip_div' and can be styled using command 'inputstyle some_css' |
||
2319 | @ the button label will be default the 'object primitive name' (like 'point', 'circles').<br />If you want a different label (e.g. an other language) ,use command 'multilabel'<br />for example in dutch: <br /><em>multilabel cirkel,lijnstuk,punten,STOP<br />multidraw circle,segment,points</em><br />(see command <a href='#multilabel'>'multilabel'</a> for more details) |
||
2320 | @ multidraw is incompatible with command 'tooltip' (the reserved div_area is used for the multidraw control buttons) |
||
2321 | @ all 'multidraw' drawings will scale on zooming.<br />this in contrast to the command <a href="#userdraw">'userdraw'</a>. |
||
2322 | @ wims will <b>not</b> check the amount or validity of your command arguments ! <br />( use javascript console to debug any typo's ) |
||
2323 | @ a local function read_canvas%d will read all userbased drawings.<br />The output is always a 11 lines string with fixed sequence.<br/>line 1 = points_x+";"+points_y+"\\n"<br/>line 2 = circles_x+";"+circlespoint_y+";"+multi_radius+"\\n"<br/>line 3 = segments_x+";"+segments_y+"\\n"<br/>line 4 = arrows_x+";"+arrows_y+"\\n"<br/>line 5 = lines_x+";"+lines_y+"\\n"<br/>line 6 = triangles_x+";"+triangles_y+"\\n"<br/>line 7 = polys[3-9]_x+";"+polys[3-9]_y+"\\n"<br/>line 8 = rects_x +";"+rects_y+"\\n"<br />line 9 = closedpoly_x+";"+closedpoly_y+"\\n"<br/>line 10 = parallelogram_x+";"+parallelogram_y"\\n"<br/>line 11 = text_x+";"+text_y+";"+text"\\n"<br/>The x/y-data are in x/y-coordinate system and display precision may be set by a previous command 'precision 0 | 10 | 100 | 1000...'<br />In case of circles the radius is -for the time being- rounded to pixels<br /><b>use the wims "direct exec" tool to see the format of the reply</b> |
||
2324 | @ 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 /> !for s=1 to $pts <br /> !increase idx <br /> X = !item $idx of $x_rep <br /> Y = !item $idx of $y_rep <br /> # do some checking <br /> !next s <br />!next p <br /> |
||
2325 | @ <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. |
||
2326 | @ <em>technical: all 10 'draw primitives' + 'text' will have their own -transparent- PNG bitmap canvas. <br />So for example there can be a points_canvas entirely separated from a line_canvas.<br />This to avoid the need for a complete redraw when something is drawn to the canvas...(eg only the object_type_canvas is redrawn)<br />This in contrast to many very slow do-it-all HTML5 canvas javascript libraries.<br />The mouselisteners are attached to the canvas-div element.</em> |
||
2327 | */ |
||
2328 | // if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
||
2329 | if( use_userdraw == TRUE ){canvas_error("Only one userdraw primitive may be used in command 'userdraw' use command 'multidraw' for this...");} |
||
2330 | use_userdraw = TRUE; |
||
2331 | /* LET OP max 6 DRAW PRIMITIVES + TEXT */ |
||
2332 | temp = get_string(infile,1); |
||
2333 | temp = str_replace(temp,",","\",\""); |
||
2334 | /* if these are not set, set the default values for the 6 (!!!) draw_primitives + draw_text */ |
||
2335 | fprintf(js_include_file,"\ |
||
2336 | if( typeof(multistrokecolors) === 'undefined' && multistrokecolors == null ){ var multistrokecolors = ['%s','%s','%s','%s','%s','%s','%s','%s','%s'];};\ |
||
2337 | if( typeof(multifillcolors) === 'undefined' && multifillcolors == null ){ var multifillcolors = ['%s','%s','%s','%s','%s','%s','%s','%s','%s'];};\ |
||
2338 | if( typeof(multistrokeopacity) === 'undefined' && multistrokeopacity == null ){ var multistrokeopacity = ['%.2f','%.2f','%.2f','%.2f','%.2f','%.2f','%2.f','%2.f','%2.f'];};\ |
||
2339 | if( typeof(multifillopacity) === 'undefined' && multifillopacity == null ){ var multifillopacity = ['%.2f','%.2f','%.2f','%.2f','%.2f','%.2f','%2.f','%2.f','%2.f'];};\ |
||
2340 | if( typeof(multilinewidth) === 'undefined' && multilinewidth == null ){ var multilinewidth = ['%d','%d','%d','%d','%d','%d','%d','%d','%d'];};\ |
||
2341 | if( typeof(multifill) === 'undefined' && multifill == null ){ var multifill = ['%d','%d','%d','%d','%d','%d','%d','%d','%d'];};\ |
||
2342 | if( typeof(multidash) === 'undefined' && multidash == null ){ var multidash = ['%d','%d','%d','%d','%d','%d','%d','%d','%d'];};\ |
||
2343 | if( typeof(multilabel) === 'undefined' && multilabel == null ){ var multilabel = [\"%s\",\"stop drawing\"];};\ |
||
2344 | if( typeof(multiuserinput) === 'undefined' && multiuserinput == null ){ var multiuserinput= ['0','0','0','0','0','0','0','0'];};\ |
||
2345 | if( typeof(multisnaptogrid) == 'undefined' && multisnaptogrid == null){var multisnaptogrid;if( x_use_snap_to_grid == 1 && y_use_snap_to_grid == 1){ multisnaptogrid = [1,1,1,1,1,1,1];}else{if( x_use_snap_to_grid == 1 ){ multisnaptogrid = [2,2,2,2,2,2,2];}else{if( y_use_snap_to_grid == 1 ){ multisnaptogrid = [3,3,3,3,3,3,3];}else{ multisnaptogrid = [0,0,0,0,0,0,0];};};};};\ |
||
2346 | var arrow_head = %d;var multifont_color = '%s';var multifont_family = '%s';", |
||
2347 | stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color, |
||
2348 | fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color, |
||
2349 | stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity, |
||
2350 | fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity, |
||
2351 | line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width, |
||
2352 | use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled, |
||
2353 | use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed, |
||
2354 | temp,arrow_head,font_color,font_family); |
||
2355 | |||
2356 | if(strstr(temp,"text") != NULL){ |
||
2357 | if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */ |
||
2358 | } |
||
2359 | |||
2360 | /* the canvasses range from 1000 ... 1008 */ |
||
2361 | add_js_multidraw(js_include_file,canvas_root_id,temp,input_style); |
||
2362 | reply_precision = precision; |
||
2363 | if( reply_format == 0){reply_format = 29;} |
||
2364 | reset();/* if command 'filled' / 'dashed' was given...reset all */ |
||
2365 | break; |
||
2366 | case MULTILABEL: |
||
2367 | /* |
||
2368 | @ multilabel button_label_1,button_label_2,...,button_label_8,'stop drawing text' |
||
2369 | @ use before command <a href='#multidraw'>'multidraw'</a> |
||
2370 | @ 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'...) |
||
2371 | @ the 'stop drawing' button text <b>must</b> be the last item on the 'multilabel' -list <br />for example:<br /><em>multilabel punten,lijnen,Stop met Tekenen<br />multidraw points,lines</em> |
||
2372 | @ all buttons can be 'styled' by using commant 'inputstyle'<br /><b>note:</b><em>If you want to add some CSS style to the buttons...<br />the id's of the 'draw buttons' are their english command argument<br />(e.g. id="canvasdraw_points" for the draw points button).<br />the id of the 'stop drawing' button is "canvasdraw_stop_drawing".<br />the id of the "OK" button is"canvasdraw_ok_button"</em> |
||
2373 | @ wims will not check the amount or validity of your input |
||
2374 | @ always use the same sequence as is used for 'multidraw' |
||
2375 | */ |
||
2376 | if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
||
2377 | temp = get_string(infile,1); |
||
2378 | temp = str_replace(temp,",","\",\""); |
||
2379 | fprintf(js_include_file,"var multilabel = [\"%s\"];",temp); |
||
2380 | break; |
||
2381 | case MULTILINEWIDTH: |
||
2382 | /* |
||
2383 | @ multilinewidth linewidth_1,linewidth_2,...,linewidth_8 |
||
2384 | @ use before command <a href='#multidraw'>'multidraw'</a> |
||
2385 | @ if not set all line width will be set by a previous command <em>'linewidth int'</em> |
||
2386 | @ use these up to 7 different line widths for the draw primitives used by command <em>'multidraw obj_type_1,obj_type_2...obj_type_7</em> |
||
2387 | @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives... |
||
2388 | @ always use the same sequence as is used for 'multidraw' |
||
2389 | */ |
||
2390 | if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
||
2391 | temp = get_string(infile,1); |
||
2392 | temp = str_replace(temp,",","\",\""); |
||
2393 | fprintf(js_include_file,"var multilinewidth = [\"%s\"];",temp); |
||
2394 | break; |
||
2395 | case MULTIFILL: |
||
2396 | /* |
||
2397 | @ multifill 0,0,1,0,1,0,0 |
||
2398 | @ meaning draw objects no. 3 and 5, in the list of command 'multifill', are filled<br />(if the object is fillable...and not a line,segment,arrow or point...) |
||
2399 | @ use before command <a href='#multidraw'>'multidraw'</a> |
||
2400 | @ if not set all objects -except point|points- will be set 'not filled'...<br />unless a command 'filled' was given before command 'multifill' |
||
2401 | @ only suitable for draw_primitives like 'circle | circles' , 'triangle | triangles' and 'polygon' |
||
2402 | @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives... |
||
2403 | @ always use the same sequence as is used for 'multidraw' |
||
2404 | */ |
||
2405 | if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
||
2406 | temp = get_string(infile,1); |
||
2407 | temp = str_replace(temp,",","\",\""); |
||
2408 | fprintf(js_include_file,"var multifill = [\"%s\"];",temp); |
||
2409 | break; |
||
2410 | |||
2411 | case MULTIFILLCOLORS: |
||
2412 | /* |
||
2413 | @ multifillcolors color_name_1,color_name_2,...,color_name_8 |
||
2414 | @ use before command <a href='#multidraw'>'multidraw'</a> |
||
2415 | @ if not set all fillcolors (for circle | triangle | poly[3-9] | closedpoly ) will be 'stroke_color' , 'fill_opacity' |
||
2416 | @ use these up to 6 colors for the draw primitives used by command 'multidraw obj_type_1,obj_type_2...obj_type_n |
||
2417 | @ wims will <b>not</b> check if the number of colours matches the amount of draw primitives... |
||
2418 | @ always use the same sequence as is used for 'multidraw' |
||
2419 | @ 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> |
||
2420 | */ |
||
2421 | if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
||
2422 | fprintf(js_include_file,"var multifillcolors = ["); |
||
2423 | while( ! done ){ |
||
2424 | temp = get_color(infile,1); |
||
2425 | fprintf(js_include_file,"\"%s\",",temp); |
||
2426 | } |
||
2427 | fprintf(js_include_file,"\"0,0,0\"];");/* add black to avoid trouble with dangling comma... */ |
||
2428 | break; |
||
2429 | |||
2430 | case MULTIFILLOPACITY: |
||
2431 | /* |
||
2432 | @ multifillopacity fill_opacity_1,fill_opacity_2,...,fill_opacity_8 |
||
2433 | @ float values 0 - 1 or integer values 0 - 255 |
||
2434 | @ use before command <a href='#multidraw'>'multidraw'</a> |
||
2435 | @ if not set all fill opacity_ will be set by previous command <em>'opacity int,int'</em> and keyword <em>'filled'</em> |
||
2436 | @ use these up to 7 different stroke opacities for the draw primitives used by command <em>'multidraw obj_type_1,obj_type_2...obj_type_y</em> |
||
2437 | @ wims will not check the amount or validity of your input |
||
2438 | @ always use the same sequence as is used for 'multidraw' |
||
2439 | */ |
||
2440 | if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
||
2441 | temp = get_string(infile,1); |
||
2442 | temp = str_replace(temp,",","\",\""); |
||
2443 | fprintf(js_include_file,"var multifillopacity = [\"%s\"];",temp); |
||
2444 | break; |
||
2445 | case MULTISNAPTOGRID: |
||
2446 | /* |
||
2447 | @ multisnaptogrid 0,1,1 |
||
2448 | @ meaning draw objects no. 2 (circle) and 3 (segments), in the list of command like <em>'multifill points,circle,segments'</em>, will snap to the xy-grid (default 1 in x/y-coordinate system: see command <a href='#snaptogrid'>'snaptogrid'</a>) |
||
2449 | @ only the x-values snap_to_grid: <em>multisnaptogrid 0,2,2</em> |
||
2450 | @ only the y-values snap_to_grid: <em>multisnaptogrid 0,3,3</em> |
||
2451 | @ mixing allowed: <em>multisnaptogrid 1,2,3,0</em> e.g. the first object will snap to the xy-grid, the second draw object will snap to the x-values, the third object will snap to the y-valeus of the grid, the last object may be placed anywhere on the canvas |
||
2452 | @ use before command <a href='#multidraw'>'multidraw'</a> |
||
2453 | @ if not set all objects will be set 'no snap'...<br />unless a generic command 'snaptogrid' was given before command 'multidraw' |
||
2454 | @ commands <a href='#xsnaptogrid'>'xsnaptogrid'</a>, <a href='#ysnaptogrid'>'ysnaptogrid'</a>, <a href='#snaptofunction'>'snaptofunction'</a> and <a href='#snaptopoints'>'snaptopoints</a> x1,y1,x2,y2...' are <b>not</b> supported at this time |
||
2455 | @ always use the same sequence as is used for 'multidraw' |
||
2456 | @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives... |
||
2457 | */ |
||
2458 | if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
||
2459 | temp = get_string(infile,1); |
||
2460 | temp = str_replace(temp,",","\",\""); |
||
2461 | fprintf(js_include_file,"var multisnaptogrid = [\"%s\"];",temp); |
||
2462 | reset();/* if command 'dashed' was given...reset to not-dashed */ |
||
2463 | break; |
||
2464 | case MULTISTROKECOLORS: |
||
2465 | /* |
||
2466 | @ multistrokecolors color_name_1,color_name_2,...,color_name_8 |
||
2467 | @ use before command <a href='#multidraw'>'multidraw'</a> |
||
2468 | @ if not set all colors will be 'stroke_color' , 'stroke_opacity' |
||
2469 | @ use these up to 6 colors for the draw primitives used by command <em>'multidraw obj_type_1,obj_type_2...obj_type_7</em> |
||
2470 | @ wims will <b>not</b> check if the number of colours matches the amount of draw primitives... |
||
2471 | @ always use the same sequence as is used for 'multidraw' |
||
2472 | */ |
||
2473 | if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
||
2474 | fprintf(js_include_file,"var multistrokecolors = ["); |
||
2475 | while( ! done ){ |
||
2476 | temp = get_color(infile,1); |
||
2477 | fprintf(js_include_file,"\"%s\",",temp); |
||
2478 | } |
||
2479 | fprintf(js_include_file,"\"0,0,0\"];");/* add black to avoid trouble with dangling comma... */ |
||
2480 | break; |
||
2481 | case MULTISTROKEOPACITY: |
||
2482 | /* |
||
2483 | @ multistrokeopacity stroke_opacity_1,stroke_opacity_2,...,stroke_opacity_7 |
||
2484 | @ float values 0 - 1 or integer values 0 - 255 |
||
2485 | @ use before command <a href='#multidraw'>'multidraw'</a> |
||
2486 | @ if not set all stroke opacity_ will be set by previous command <em>'opacity int,int'</em> |
||
2487 | @ use these up to 7 different stroke opacities for the draw primitives used by command <em>'multidraw obj_type_1,obj_type_2...obj_type_7</em> |
||
2488 | @ wims will not check the amount or validity of your input |
||
2489 | @ always use the same sequence as is used for 'multidraw' |
||
2490 | */ |
||
2491 | if( use_tooltip == 1){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
||
2492 | temp = get_string(infile,1); |
||
2493 | temp = str_replace(temp,",","\",\""); |
||
2494 | fprintf(js_include_file,"var multistrokeopacity = [\"%s\"];",temp); |
||
2495 | break; |
||
2496 | |||
2497 | case MULTIUSERINPUT: |
||
2498 | /* |
||
2499 | @ multiuserinput 0,1,1,0 |
||
2500 | @ meaning, when the command 'multidraw' is used <br />multidraw circles,points,lines,triangles<br />objects 'points' and 'lines' may additionally be 'drawn' by direct input (inputfields)<br/>all other objects must be drawn with a mouse |
||
2501 | @ in case of circle | circles a third inputfield for Radius (R) is added.<br />the radius must be in the x/y coordinate system (x-range) and <b>not</b> in pixels...students don't think in pixels.<br />note: R-values will not snap-to-grid |
||
2502 | @ 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... |
||
2503 | @ in case of a triangle | poly3, three inputfields are provided. |
||
2504 | @ in case of 'text' and multiuserinput=1 , 3 inputfields will be shown : x,y,text |
||
2505 | @ in case of 'text' and multiuserinput=0 , 1 inputfield will be shown : text ... a mouse click will place the text on the canvas. |
||
2506 | @ may be styled using command <a href="#inputstyle">"inputstyle"</a> |
||
2507 | @ an additional button 'stop drawing' may be used to combine userbased drawings with 'drag&drop' or 'onclick' elements |
||
2508 | @ when exercise if finished (status=done) the buttons will not be shown.<br />To override this default behaviour use command / keyword 'status' |
||
2509 | @ use before command <a href='#multidraw'>'multidraw'</a> |
||
2510 | @ always use the same sequence as is used for 'multidraw' |
||
2511 | */ |
||
2512 | /* simple rawmath and input check */ |
||
2513 | if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */ |
||
2514 | temp = get_string(infile,1); |
||
2515 | temp = str_replace(temp,",","\",\""); |
||
2516 | fprintf(js_include_file,"var multiuserinput = [\"%s\"];",temp); |
||
2517 | break; |
||
2518 | |||
2519 | case NOXAXIS: |
||
2520 | /* |
||
2521 | @ noaxis |
||
2522 | @ keyword |
||
2523 | @ if set, the automatic x-axis numbering will be ignored |
||
2524 | @ use command <a href="#axis">axis</a> to have a visual x/y-axis lines (see command <a href="grid">grid</a> |
||
2525 | @ to be used before command grid (see <a href="#grid">command grid</a>) |
||
2526 | */ |
||
2527 | fprintf(js_include_file,"x_strings = [0,\" \"];\n"); |
||
2528 | use_axis_numbering = 1; |
||
2529 | break; |
||
2530 | case NOYAXIS: |
||
2531 | /* |
||
2532 | @ noayis |
||
2533 | @ keyword |
||
2534 | @ if set, the automatic y-axis numbering will be ignored |
||
2535 | @ use command <a href="#axis">axis</a> to have a visual x/y-axis lines (see command <a href="grid">grid</a> |
||
2536 | @ to be used before command grid (see <a href="#grid">command grid</a>) |
||
2537 | */ |
||
2538 | fprintf(js_include_file,"y_strings = [0,\" \"];\n"); |
||
2539 | use_axis_numbering = 1; |
||
2540 | break; |
||
2541 | case OPACITY: |
||
2542 | /* |
||
2543 | @ opacity 0-255,0-255 |
||
2544 | @ opacity 0.0 - 1.0,0.0 - 1.0 |
||
2545 | @ alternative : transparent |
||
2546 | @ first item is stroke opacity, second is fill opacity |
||
2547 | */ |
||
2548 | for(i = 0 ; i<2;i++){ |
||
2549 | switch(i){ |
||
2550 | case 0: double_data[0]= get_real(infile,0);break; |
||
2551 | case 1: double_data[1]= get_real(infile,1);break; |
||
2552 | default: break; |
||
2553 | } |
||
2554 | } |
||
2555 | if( double_data[0] > 255 || double_data[1] > 255 ){ canvas_error("opacity [0 - 255] , [0 - 255] ");}/* typo or non-RGB ? */ |
||
2556 | if( double_data[0] > 1 ){ stroke_opacity = (double) (0.0039215*double_data[0]); }else{ stroke_opacity = double_data[0];} /* 0.0 - 1.0 */ |
||
2557 | if( double_data[0] > 1 ){ fill_opacity = (double) (0.0039215*double_data[1]); }else{ fill_opacity = double_data[0];} /* 0.0 - 1.0 */ |
||
2558 | break; |
||
2559 | |||
2560 | case ONCLICK: |
||
2561 | /* |
||
2562 | @ onclick |
||
2563 | @ keyword (no arguments required) |
||
2564 | @ if the next object is clicked, its 'object onclick_or_drag sequence number' in fly script is returned <br /> by javascript:read_canvas(); |
||
2565 | @ onclick seqeuence numbering starts at '0'.<br />e.g. if there are 6 objects set onclick, the first onclick object will have id-number '0', the last id-number '5' |
||
2566 | @ line based objects will show an increase in line width<br />font based objects will show the text in 'bold' when clicked. |
||
2567 | @ the click zone (accuracy) is determined by 2× the line width of the object |
||
2568 | @ onclick and <a href="#drag">drag x|y|xy</a> may be combined in a single flyscript <br />(although a single object can <b>not</b> be onclick and draggable at the same time...) |
||
2569 | @ note: not all objects may be set onclick |
||
2570 | */ |
||
2571 | fprintf(js_include_file,"use_dragdrop_reply = true;"); |
||
2572 | onclick = 1; |
||
2573 | |||
2574 | break; |
||
2575 | |||
2576 | case PARALLEL: |
||
2577 | /* |
||
2578 | @ parallel x1,y1,x2,y2,dx,dy,n,[colorname or #hexcolor] |
||
2579 | @ can <b>not</b> be set "onclick" or "drag xy" |
||
2580 | */ |
||
2581 | for( i = 0;i < 8; i++ ){ |
||
2582 | switch(i){ |
||
2583 | case 0: double_data[0] = get_real(infile,0);break; /* x1-values -> x-pixels*/ |
||
2584 | case 1: double_data[1] = get_real(infile,0);break; /* y1-values -> y-pixels*/ |
||
2585 | case 2: double_data[2] = get_real(infile,0);break; /* x2-values -> x-pixels*/ |
||
2586 | case 3: double_data[3] = get_real(infile,0);break; /* y2-values -> y-pixels*/ |
||
2587 | case 4: double_data[4] = xmin + get_real(infile,0);break; /* xv -> x-pixels */ |
||
2588 | case 5: double_data[5] = ymax + get_real(infile,0);break; /* yv -> y-pixels */ |
||
2589 | case 6: int_data[0] = (int) (get_real(infile,0));break; /* n */ |
||
2590 | case 7: stroke_color=get_color(infile,1);/* name or hex color */ |
||
2591 | decimals = find_number_of_digits(precision); |
||
2592 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,11,[%.*f,%.*f,%.*f],[%.*f,%.*f,%.*f],[%d,%d,%d],[%d,%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,double_data[4],decimals,double_data[1],decimals,double_data[3],decimals,double_data[5],int_data[0],int_data[0],int_data[0],int_data[0],int_data[0],int_data[0],line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset); |
||
2593 | if(onclick > 0){click_cnt++;} |
||
2594 | /* click_cnt++*/; |
||
2595 | reset(); |
||
2596 | break; |
||
2597 | default: break; |
||
2598 | } |
||
2599 | } |
||
2600 | break; |
||
2601 | |||
2602 | |||
2603 | case PLOTSTEPS: |
||
2604 | /* |
||
2605 | @ plotsteps a_number |
||
2606 | @ default 150 |
||
2607 | @ only used for commands <a href="#curve">"curve / plot"</a> and <a href="#levelcurve">"levelcurve"</a> |
||
2608 | @ use with care ! |
||
2609 | */ |
||
2610 | plot_steps = (int) (get_real(infile,1)); |
||
2611 | break; |
||
2612 | |||
2613 | case POINT: |
||
2614 | /* |
||
2615 | @ point x,y,color |
||
2616 | @ draw a single point at (x;y) in color 'color' |
||
2617 | @ use command 'linewidth int' to adust size |
||
2618 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
||
2619 | @ will not resize on zooming <br />(command 'circle x,y,r,color' will resize on zooming) |
||
2620 | @ attention: in case of command <a href="#rotate">'rotate angle'</a> a point has rotation center (0:0) in x/y-range |
||
2621 | */ |
||
2622 | for(i=0;i<3;i++){ |
||
2623 | switch(i){ |
||
2624 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
2625 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
2626 | case 2: stroke_color = get_color(infile,1);/* name or hex color */ |
||
2627 | decimals = find_number_of_digits(precision); |
||
2628 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,2,[%.*f],[%.*f],[%.2f],[%d],%.2f,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[1],1.5*line_width,line_width,1.5*line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,1,0,0,0,use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset); |
||
2629 | /* click_cnt++; */ |
||
2630 | if(onclick > 0){click_cnt++;} |
||
2631 | break; |
||
2632 | default: break; |
||
2633 | } |
||
2634 | } |
||
2635 | reset(); |
||
2636 | break; |
||
2637 | |||
2638 | case POINTS: |
||
2639 | /* |
||
2640 | @ points color,x1,y1,x2,y2,...,x_n,y_n |
||
2641 | @ draw multiple points at given coordinates in color 'color' |
||
2642 | @ use command 'linewidth int' to adust size |
||
2643 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!) |
||
2644 | @ attention: in case of command <a href="#rotate">'rotate angle'</a> the points have rotation center (0:0) in x/y-range |
||
2645 | */ |
||
8363 | schaersvoo | 2646 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
2647 | fill_color = stroke_color; |
||
2648 | i=0; |
||
2649 | while( ! done ){ /* get next item until EOL*/ |
||
2650 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
2651 | if(i%2 == 0 ){ |
||
2652 | double_data[i] = get_real(infile,0); /* x */ |
||
2653 | } |
||
2654 | else |
||
2655 | { |
||
2656 | double_data[i] = get_real(infile,1); /* y */ |
||
2657 | } |
||
2658 | i++; |
||
2659 | } |
||
2660 | decimals = find_number_of_digits(precision); |
||
11806 | schaersvoo | 2661 | for(c = 0 ; c < i-1 ; c = c+2){ |
2662 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,2,[%.*f],[%.*f],[%.2f],[%d],%.2f,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+1],1.5*line_width,line_width,1.5*line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,1,0,0,0,use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset); |
||
8379 | schaersvoo | 2663 | /* click_cnt++; */ |
11806 | schaersvoo | 2664 | if(onclick > 0){click_cnt++;} |
8363 | schaersvoo | 2665 | } |
2666 | reset(); |
||
2667 | break; |
||
11806 | schaersvoo | 2668 | |
2669 | case POLY: |
||
2670 | /* |
||
2671 | @ poly color,x1,y1,x2,y2...x_n,y_n |
||
2672 | @ polygon color,x1,y1,x2,y2...x_n,y_n |
||
2673 | @ draw closed polygon |
||
2674 | @ use command 'fpoly' to fill it or use keyword <a href='#filled'>'filled'</a> |
||
2675 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
||
2676 | */ |
||
2677 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
2678 | i=0; |
||
2679 | c=0; |
||
2680 | while( ! done ){ /* get next item until EOL*/ |
||
2681 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
2682 | for( c = 0 ; c < 2; c++){ |
||
2683 | if(c == 0 ){ |
||
2684 | double_data[i] = get_real(infile,0); |
||
2685 | i++; |
||
2686 | } |
||
2687 | else |
||
2688 | { |
||
2689 | double_data[i] = get_real(infile,1); |
||
2690 | i++; |
||
2691 | } |
||
2692 | } |
||
2693 | } |
||
2694 | /* draw path : closed & optional filled */ |
||
2695 | decimals = find_number_of_digits(precision); |
||
2696 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,5,%s,[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d));\n",click_cnt,onclick,drag_type,double_xy2js_array(double_data,i,decimals),line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset); |
||
2697 | if(onclick > 0){click_cnt++;} |
||
2698 | /* click_cnt++; */ |
||
2699 | reset(); |
||
2700 | break; |
||
2701 | |||
7614 | schaersvoo | 2702 | case POLYLINE: |
2703 | /* |
||
2704 | @ polyline color,x1,y1,x2,y2...x_n,y_n |
||
10975 | schaersvoo | 2705 | @ brokenline color,x1,y1,x2,y2...x_n,y_n |
2706 | @ path color,x1,y1,x2,y2...x_n,y_n |
||
2707 | @ remark: there is <b>no</b> command polylines | brokenlines | paths ... just use multiple commands "polyline ,x1,y1,x2,y2...x_n,y_n" |
||
2708 | @ remark: there are commands "userdraw path(s),color" and "userdraw polyline,color"... these are two entirely different things !<br />the path(s) userdraw commands may be used for freehand drawing(s)<br />the polyline userdraw command is analogue to this polyline|brokenline command |
||
2709 | @ 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) |
||
2710 | @ use command <a href='#segments'>'segments'</a> for a series of segments.<br />these may be clicked/dragged individually |
||
9406 | schaersvoo | 2711 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
7614 | schaersvoo | 2712 | */ |
2713 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
2714 | i=0; |
||
2715 | c=0; |
||
2716 | while( ! done ){ /* get next item until EOL*/ |
||
2717 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
2718 | for( c = 0 ; c < 2; c++){ |
||
2719 | if(c == 0 ){ |
||
2720 | double_data[i] = get_real(infile,0); |
||
2721 | i++; |
||
2722 | } |
||
2723 | else |
||
2724 | { |
||
2725 | double_data[i] = get_real(infile,1); |
||
2726 | i++; |
||
2727 | } |
||
2728 | } |
||
2729 | } |
||
2730 | /* draw path : not closed & not filled */ |
||
2731 | decimals = find_number_of_digits(precision); |
||
11802 | schaersvoo | 2732 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,4,%s,[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d));\n",click_cnt,onclick,drag_type,double_xy2js_array(double_data,i,decimals),line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset); |
8379 | schaersvoo | 2733 | if(onclick > 0){click_cnt++;} |
2734 | /* click_cnt++;*/ |
||
2735 | reset(); |
||
7614 | schaersvoo | 2736 | break; |
11806 | schaersvoo | 2737 | |
2738 | case POPUP: |
||
2739 | /* |
||
2740 | @ popup |
||
2741 | @ keyword (no arguments) |
||
2742 | @ if fly-script starts with keyword 'popup', the canvas image will be exclusively in a popup window (xsize px × ysize px) |
||
2743 | @ if keyword 'popup' is used after command 'size xsize,ysize' the canvas will also be displayed in a popup window with size 'xsize × ysize' |
||
2744 | @ the popup window will be embedded into the page as a 'normal' image , when 'status=done' ; override with keyword <a href="#status"> 'nostatus'</a> |
||
2745 | @ to access the read_canvas and read_dragdrop functions in a popup window, use:<br /><em><br /> function read_all(){<br /> if( typeof popup !== 'undefined' ){<br /> var fun1 = popup['read_dragdrop'+canvas_scripts[0]];<br /> var fun2 = popup['read_canvas'+canvas_scripts[0]];<br /> popup.close();<br /> return "dragdrop="+fun1()+"\\ncanvas="+fun2();<br /> };<br /></em> |
||
2746 | @ to set a canvasdraw produced <a href="#clock">clock</a> or multiple clocks...use something like:<br /><em>popup.set_clock(clock_id,type,diff);</em><br />as js-function for a button (or something else) in your document page.<br />wherein <b>clock_id</b> starts with 0 for the first clock<br /><b>type</b> is 1 for Hours,2 for Minutes and 3 for Seconds<br /><b>diff</b> is the increment (positive or negative) per click |
||
2747 | */ |
||
2748 | use_tooltip = 2; |
||
2749 | break; |
||
2750 | |||
2751 | case PROTRACTOR: |
||
7614 | schaersvoo | 2752 | /* |
11806 | schaersvoo | 2753 | @ protractor x,y,x_width,type,mode,use_a_scale |
2754 | @ x,y are the initial location |
||
2755 | @ x_width : give the width in x-coordinate system (e.g. not in pixels !) |
||
2756 | @ type = 1 : a triangle range 0 - 180<br />type = 2 : a circle shape 0 - 360 |
||
2757 | @ mode : use -1 to set the protractor interactive (mouse movement of protractor)<br />use mode = '0° - 360°' to set the protractor with a static angle of some value |
||
2758 | @ 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> |
||
2759 | @ use_scale = 1 : the protractor will have some scale values printed; use_scale=0 to disable |
||
2760 | @ the rotating direction of the mouse around the protractor determines the clockwise/ counter clockwise rotation of the protractor... |
||
2761 | @ commands <em>stroke_color | fill_color | linewidth | opacity | font_family</em> will determine the looks of the protractor. |
||
2762 | @ default replyformat: reply[0] = x;reply[1] = y;reply[2] = angle_in_radians<br />use command 'precision' to set the reply precision. |
||
2763 | @ if combined with a ruler, use replyformat = 32 |
||
2764 | @ command <em>snap_to_grid</em> may be used to assist the pupil at placing the protractor |
||
2765 | @ when using command 'zoom' , pay <b>attention</b> to the size and symmetry of your canvas<br />...to avoid a partial image, locate the start position near the center of the visual canvas<br /><em>technical:<br /> the actual 'protractor' is just a static generated image in a new canvas-memory<br />This image is only generated once, and a copy of its bitmap is translated & rotated onto the visible canvas.<br />That is the reason for the 'high-speed dragging and rotating'.<br />I've limited its size to xsize × ysize e.g. the same size as the visual canvas... </em> |
||
2766 | @ only one protractor allowed (for the time being) |
||
2767 | @ usage: first left click on the protractor will activate dragging;<br />a second left click will activate rotating (just move mouse around)<br />a third click will freeze this position and the x/y-coordinate and angle in radians will be stored in reply(3)<br />a next click will restart this sequence... |
||
7614 | schaersvoo | 2768 | */ |
11806 | schaersvoo | 2769 | for( i = 0;i < 6; i++ ){ |
2770 | switch(i){ |
||
2771 | case 0: double_data[0] = get_real(infile,0);break; /* x-center */ |
||
2772 | case 1: double_data[1] = get_real(infile,0);break; /* y-center */ |
||
2773 | case 2: double_data[2] = get_real(infile,0);break; /* x-width */ |
||
2774 | case 3: int_data[0] = (int)(get_real(infile,0));break; /* type: 1==triangle 2 == circle */ |
||
2775 | case 4: int_data[1] = (int)(get_real(infile,0));break; /* passive mode == 0; active mode == -1 */ |
||
2776 | case 5: int_data[2] = (int)(get_real(infile,1)); /* use scale */ |
||
2777 | decimals = find_number_of_digits(precision); |
||
2778 | if( int_data[2] < 0 ){ |
||
2779 | if( js_function[JS_FIND_ANGLE] != 1 ){ /* add je function for calculating angle */ |
||
2780 | js_function[JS_FIND_ANGLE] = 1; |
||
2781 | } |
||
2782 | } |
||
2783 | 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]); |
||
2784 | |||
2785 | string_length = snprintf(NULL,0,";protractor%d(); ",canvas_root_id); |
||
2786 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
2787 | snprintf(tmp_buffer,string_length,";protractor%d(); ",canvas_root_id); |
||
2788 | add_to_buffer(tmp_buffer); |
||
2789 | reply_precision = precision; |
||
2790 | /* no reply from protractor if non-interactive */ |
||
2791 | if( reply_format == 0 && int_data[1] == -1 ){reply_format = 30;} |
||
2792 | break; |
||
2793 | default: break; |
||
2794 | } |
||
2795 | } |
||
2796 | break; |
||
2797 | |||
2798 | case PIXELS: |
||
2799 | /* |
||
2800 | @ pixels color,x1,y1,x2,y2,x3,y3... |
||
2801 | @ draw rectangular "points" with diameter 1 pixel |
||
2802 | @ pixels can <b>not</b> be dragged or clicked |
||
2803 | @ "pixelsize = 1" may be changed by command "pixelsize int" |
||
2804 | */ |
||
2805 | if( js_function[DRAW_PIXELS] != 1 ){ js_function[DRAW_PIXELS] = 1;} |
||
2806 | stroke_color=get_color(infile,0); |
||
7614 | schaersvoo | 2807 | i=0; |
2808 | c=0; |
||
2809 | while( ! done ){ /* get next item until EOL*/ |
||
2810 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
2811 | for( c = 0 ; c < 2; c++){ |
||
2812 | if(c == 0 ){ |
||
2813 | double_data[i] = get_real(infile,0); |
||
2814 | i++; |
||
2815 | } |
||
2816 | else |
||
2817 | { |
||
2818 | double_data[i] = get_real(infile,1); |
||
2819 | i++; |
||
2820 | } |
||
2821 | } |
||
2822 | } |
||
11806 | schaersvoo | 2823 | decimals = find_number_of_digits(precision); |
2824 | /* *double_xy2js_array(double xy[],int len,int decimals) */ |
||
2825 | string_length = snprintf(NULL,0, "draw_setpixel(%s,\"%s\",%.2f,%d);\n",double_xy2js_array(double_data,i,decimals),stroke_color,stroke_opacity,pixelsize); |
||
2826 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
2827 | snprintf(tmp_buffer,string_length,"draw_setpixel(%s,\"%s\",%.2f,%d);\n",double_xy2js_array(double_data,i,decimals),stroke_color,stroke_opacity,pixelsize); |
||
2828 | add_to_buffer(tmp_buffer); |
||
2829 | reset(); |
||
7614 | schaersvoo | 2830 | break; |
11806 | schaersvoo | 2831 | |
2832 | case PIXELSIZE: |
||
7614 | schaersvoo | 2833 | /* |
11806 | schaersvoo | 2834 | @ pixelsize int |
2835 | @ in case you want to deviate from default pixelsize = 1(...) |
||
7614 | schaersvoo | 2836 | */ |
11806 | schaersvoo | 2837 | pixelsize = (int) get_real(infile,1); |
2838 | break; |
||
8105 | schaersvoo | 2839 | |
11806 | schaersvoo | 2840 | case PIECHART: |
7614 | schaersvoo | 2841 | /* |
11806 | schaersvoo | 2842 | @ piechart xc,yc,radius,'data+colorlist' |
2843 | @ (xc : yc) center of circle diagram in xrange/yrange |
||
2844 | @ radius in pixels |
||
2845 | @ 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 |
||
2846 | @ example data+colorlist : 132:red:23565:green:323:black:234324:orange:23434:yellow:2543:white |
||
2847 | @ the number of colors must match the number of data. |
||
2848 | @ use command "<a href='#opacity'>'opacity'</a> to adjust fill_opacity of colours |
||
2849 | @ use command <a href='#legend'>'legend'</a> to automatically create a legend <br />using the same colours as pie segments<br />unicode allowed in legend<br />expect javascript trouble if the amount of 'pie-slices', 'pie-colours' 'pie-legend-titles' do not match<br />a javascript console is your best friend...<br />use command 'fontfamily' to set the font of the legend. |
||
7614 | schaersvoo | 2850 | */ |
11806 | schaersvoo | 2851 | if( js_function[DRAW_PIECHART] != 1 ){ js_function[DRAW_PIECHART] = 1;} |
7614 | schaersvoo | 2852 | for(i=0;i<5;i++){ |
2853 | switch(i){ |
||
11806 | schaersvoo | 2854 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */ |
2855 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y */ |
||
2856 | case 2: int_data[2] = (int)(get_real(infile,1));break;/* radius*/ |
||
2857 | case 3: temp = get_string(infile,1); |
||
2858 | if( strstr( temp, ":" ) != 0 ){ temp = str_replace(temp,":","\",\"");} |
||
2859 | string_length = snprintf(NULL,0,"draw_piechart(%d,%d,%d,%d,[\"%s\"],%.2f,%d,\"%s\");\n",PIECHART,int_data[0],int_data[1],int_data[2],temp,fill_opacity,legend_cnt,font_family); |
||
2860 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
2861 | snprintf(tmp_buffer,string_length,"draw_piechart(%d,%d,%d,%d,[\"%s\"],%.2f,%d,\"%s\");\n",PIECHART,int_data[0],int_data[1],int_data[2],temp,fill_opacity,legend_cnt,font_family); |
||
2862 | add_to_buffer(tmp_buffer); |
||
2863 | break; |
||
2864 | default:break; |
||
7614 | schaersvoo | 2865 | } |
2866 | } |
||
11806 | schaersvoo | 2867 | reset(); |
7614 | schaersvoo | 2868 | break; |
8304 | schaersvoo | 2869 | |
7614 | schaersvoo | 2870 | case RAYS: |
2871 | /* |
||
2872 | @ rays color,xc,yc,x1,y1,x2,y2,x3,y3...x_n,y_n |
||
2873 | @ draw rays in color 'color' and center (xc:yc) |
||
7786 | schaersvoo | 2874 | @ may be set draggable or onclick (every individual ray) |
7614 | schaersvoo | 2875 | */ |
2876 | stroke_color=get_color(infile,0); |
||
7786 | schaersvoo | 2877 | fill_color = stroke_color; |
2878 | double_data[0] = get_real(infile,0);/* xc */ |
||
2879 | double_data[1] = get_real(infile,0);/* yc */ |
||
2880 | i=2; |
||
2881 | while( ! done ){ /* get next item until EOL*/ |
||
2882 | if(i > MAX_INT - 1){canvas_error("in command rays to many points / rays in argument: repeat command multiple times to fit");} |
||
2883 | if(i%2 == 0 ){ |
||
2884 | double_data[i] = get_real(infile,0); /* x */ |
||
7614 | schaersvoo | 2885 | } |
7786 | schaersvoo | 2886 | else |
2887 | { |
||
2888 | double_data[i] = get_real(infile,1); /* y */ |
||
7614 | schaersvoo | 2889 | } |
7786 | schaersvoo | 2890 | fprintf(js_include_file,"/* double_data[%d] = %f */\n",i,double_data[i]); |
2891 | i++; |
||
7614 | schaersvoo | 2892 | } |
8224 | bpr | 2893 | |
2894 | if( i%2 != 0 ){canvas_error("in command rays: unpaired x or y value");} |
||
2895 | decimals = find_number_of_digits(precision); |
||
7786 | schaersvoo | 2896 | for(c=2; c<i;c = c+2){ |
11802 | schaersvoo | 2897 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[c],decimals,double_data[1],decimals,double_data[c+1],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset); |
8379 | schaersvoo | 2898 | /* click_cnt++; */ |
2899 | if(onclick > 0){click_cnt++;} |
||
7614 | schaersvoo | 2900 | } |
2901 | reset(); |
||
2902 | break; |
||
8304 | schaersvoo | 2903 | |
11806 | schaersvoo | 2904 | case RECT: |
8386 | schaersvoo | 2905 | /* |
11806 | schaersvoo | 2906 | @ rect x1,y1,x2,y2,color |
2907 | @ use command 'frect x1,y1,x2,y2,color' for a filled rectangle |
||
2908 | @ use command/keyword <a href='#filled'>'filled'</a> before command 'rect x1,y1,x2,y2,color' |
||
9406 | schaersvoo | 2909 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
8386 | schaersvoo | 2910 | */ |
11806 | schaersvoo | 2911 | for(i=0;i<5;i++){ |
2912 | switch(i){ |
||
2913 | case 0:double_data[0] = get_real(infile,0);break; /* x-values */ |
||
2914 | case 1:double_data[1] = get_real(infile,0);break; /* y-values */ |
||
2915 | case 2:double_data[2] = get_real(infile,0);break; /* x-values */ |
||
2916 | case 3:double_data[3] = get_real(infile,0);break; /* y-values */ |
||
2917 | case 4:stroke_color = get_color(infile,1);/* name or hex color */ |
||
8386 | schaersvoo | 2918 | decimals = find_number_of_digits(precision); |
11806 | schaersvoo | 2919 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,1,[%.*f,%.*f,%.*f,%.*f],[%.*f,%.*f,%.*f,%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,double_data[2],decimals,double_data[0],decimals,double_data[1],decimals,double_data[1],decimals,double_data[3],decimals,double_data[3],line_width,line_width,line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset); |
2920 | if(onclick > 0){click_cnt++;} |
||
2921 | /* click_cnt++; */ |
||
8386 | schaersvoo | 2922 | reset(); |
2923 | break; |
||
11806 | schaersvoo | 2924 | } |
2925 | } |
||
2926 | break; |
||
8386 | schaersvoo | 2927 | |
11806 | schaersvoo | 2928 | case RECTS: |
8304 | schaersvoo | 2929 | /* |
11806 | schaersvoo | 2930 | @ rects color,x1,y1,x2,y2,..... |
2931 | @ use command 'frect color,x1,y1,x2,y2,.....' for a filled rectangle |
||
2932 | @ use command/keyword <a href='#filled'>'filled'</a> before command 'rects color,x1,y1,x2,y2,....' |
||
2933 | @ use command 'fillcolor color' before 'frects' to set the fill colour. |
||
9406 | schaersvoo | 2934 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually |
8304 | schaersvoo | 2935 | */ |
2936 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
2937 | fill_color = stroke_color; |
||
2938 | i=0; |
||
2939 | while( ! done ){ /* get next item until EOL*/ |
||
2940 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
2941 | if(i%2 == 0 ){ |
||
2942 | double_data[i] = get_real(infile,0); /* x */ |
||
2943 | } |
||
2944 | else |
||
2945 | { |
||
2946 | double_data[i] = get_real(infile,1); /* y */ |
||
2947 | } |
||
2948 | i++; |
||
2949 | } |
||
2950 | decimals = find_number_of_digits(precision); |
||
2951 | for(c = 0 ; c < i-1 ; c = c+4){ |
||
11806 | schaersvoo | 2952 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,1,[%.*f,%.*f,%.*f,%.*f],[%.*f,%.*f,%.*f,%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+2],decimals,double_data[c+2],decimals,double_data[c],decimals,double_data[c+1],decimals,double_data[c+1],decimals,double_data[c+3],decimals,double_data[c+3],line_width,line_width,line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset); |
2953 | if(onclick > 0){click_cnt++;} |
||
8379 | schaersvoo | 2954 | /* click_cnt++; */ |
8304 | schaersvoo | 2955 | } |
2956 | reset(); |
||
2957 | break; |
||
8386 | schaersvoo | 2958 | |
11806 | schaersvoo | 2959 | case REPLYFORMAT: |
7614 | schaersvoo | 2960 | /* |
11806 | schaersvoo | 2961 | @ replyformat number |
2962 | @ use number=-1 to deactivate the js-functions read_canvas() and read_dragdrop() |
||
2963 | @ default values should be fine ! |
||
2964 | @ use command 'precision [0,1,10,100,1000,10000...]' before command 'replyformat' to set the desired number of decimals in the student reply / drawing |
||
2965 | @ the last value for 'precision int' will be used to calculate the reply coordinates, if needed (read_canvas();) |
||
2966 | @ choose<ul><li>1 = x1,x2,x3,x4....x_n<br />y1,y2,y3,y4....y_n<br /><br />x/y in pixels</li><li>2 = x1,x2,x3,x4....x_n<br /> y1,y2,y3,y4....y_n<br /> x/y in xrange / yrange coordinate system<br /></li><li>3 = x1,x2,x3,x4....x_n<br /> y1,y2,y3,y4....y_n<br /> r1,r2,r3,r4....r_n<br /> x/y in pixels <br /> r in pixels</li><li>4 = x1,x2,x3,x4....x_n<br /> y1,y2,y3,y4....y_n<br /> r1,r2,r3,r4....r_n<br /> x/y in xrange / yrange coordinate system<br /> r in pixels</li><li>5 = Ax1,Ax2,Ax3,Ax4....Ax_n<br /> Ay1,Ay2,Ay3,Ay4....Ay_n<br /> Bx1,Bx2,Bx3,Bx4....Bx_n<br /> By1,By2,By3,By4....By_n<br /> Cx1,Cx2,Cx3,Cx4....Cx_n<br /> Cy1,Cy2,Cy3,Cy4....Cy_n<br /> ....<br /> Zx1,Zx2,Zx3,Zx4....Zx_n<br /> Zy1,Zy2,Zy3,Zy4....Zy_n<br /> x/y in pixels<br /></li><li>6 = Ax1,Ax2,Ax3,Ax4....Ax_n<br /> Ay1,Ay2,Ay3,Ay4....Ay_n<br /> Bx1,Bx2,Bx3,Bx4....Bx_n<br /> By1,By2,By3,By4....By_n<br /> Cx1,Cx2,Cx3,Cx4....Cx_n<br /> Cy1,Cy2,Cy3,Cy4....Cy_n<br /> ....<br /> Zx1,Zx2,Zx3,Zx4....Zx_n<br /> Zy1,Zy2,Zy3,Zy4....Zy_n<br /> x/y in xrange / yrange coordinate system<br /></li><li>7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n<br /> x/y in pixels</li><li>8 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n<br /> x/y in xrange / yrange coordinate system</li><li>9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n<br /> x/y in pixels</li><li>10 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n<br /> x/y in xrange / yrange coordinate system</li><li>11 = Ax1,Ay1,Ax2,Ay2<br /> Bx1,By1,Bx2,By2<br /> Cx1,Cy1,Cx2,Cy2<br /> Dx1,Dy1,Dx2,Dy2<br /> ......<br /> Zx1,Zy1,Zx2,Zy2<br /> x/y in xrange / yrange coordinate system</li><li>12 = Ax1,Ay1,Ax2,Ay2<br /> Bx1,By1,Bx2,By2<br />Cx1,Cy1,Cx2,Cy2<br /> Dx1,Dy1,Dx2,Dy2<br /> ......<br /> Zx1,Zy1,Zx2,Zy2<br /> x/y in pixels</li><li>13 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2,Cx1:Cy1:Cx2:Cy2,Dx1:Dy1:Dx2:Dy2, ... ,Zx1:Zy1:Zx2:Zy2<br /> x/y in xrange / yrange coordinate system</li><li>14 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2....Zx1:Zy1:Zx2:Zy2<br /> x/y in pixels</li><li>15 = reply from inputfields,textareas<br /> reply1,reply2,reply3,...,reply_n</li><li>16 = mathml input fields </li><li>17 = read "userdraw text,color" only (x1,y1,text1 \\n x2,y2,text2...\\n...x_n,y_n,text_n <br /> x/y-values are in xrang/yrange</li><li>18 = read_canvas() will read all interactive clocks in H1:M1:S1,H2:M2:S2...Hn:Mn:Sn</li><li>19 = read_canvas() will return the object number of marked / clicked object (clock)<br />analogue to (shape library) onclick command </li><li>20 = read_canvas() will reply "object_number:x:y" of external images : object_number of the first draggable external image in the fly-script starts with 0 <br />e.g. expect something like 0:-5:4,1:6:2,2:-2:-5 <br /> the first image position is (-5:4) , the second image position is (6:2) and the third image position is (-2:-5) <li>21 = (x1:y1) (x2:y2) ... (x_n:y_n)<br />verbatim coordinate return</li><li>22 = returns an array .... reply[0]=x1 reply[1]=y1 reply[2]=x2 reply[3]=y2 ... reply[n-1]=x_n reply[n]=y_n<br /> x/y in xrange / yrange coordinate system</li><li>23 : can only be used for drawtype 'polyline'<br />a typical click sequence in drawtype polyline is x1,y1,x2,y2,x2,y2,x3,y3,x3,y3.....,x(n-1),y(n-1),x(n-1),y(n-1),xn,yn --replyformat 23--> x1,y1,x2,y2,x3,y3,.....x(n-1),y(n-1),xn,yn multiple occurences will be filtered out.The reply will be in x-y-range (xreply \\n yreply)</li><li>24 = read all inputfield values: even those set 'readonly'</li><li>25 = angle1,angle2...angle_n : will return the radius (one or many) of the user drawn circle segment in degrees </li><li>26 = rad1,rad2...rad_n : will return the radius (one or many) of the user drawn circle segment in radians </li><li>27 = return (only) userdraw inputfields x1,y1,text1 \\n x2,y2,text2...\\n...x_n,y_n,text_n</li><li>28 = x1,y1,r1,x2,y2,r2...x_n,y_n,r_n <br />x / y / r in xrange / yrange coordinate system: may be used to reinput into command 'circles color,x1,y1,r1,x2,y2,r2...x_n,y_n,r_n'<br /> will not return anything else (e.g. no inputfields , text etc)</li></ul> |
||
2967 | |||
2968 | */ |
||
2969 | reply_format = (int) get_real(infile,1); |
||
2970 | reply_precision = precision; |
||
2971 | break; |
||
2972 | |||
2973 | case ROUNDRECT: |
||
2974 | /* |
||
2975 | @ roundrect x1,y1,x2,y2,radius in px,color |
||
2976 | @ use command 'froundrect x1,y1,x2,y2,radius,color' for a filled rectangle |
||
2977 | @ use command/keyword <a href='#filled'>'filled'</a> before command 'roundrect x1,y1,x2,y2,radius,color' |
||
2978 | @ fillcolor will be identical to 'color' |
||
9406 | schaersvoo | 2979 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
7614 | schaersvoo | 2980 | */ |
11806 | schaersvoo | 2981 | for(i=0;i<6;i++){ |
2982 | switch(i){ |
||
2983 | case 0:double_data[0] = get_real(infile,0);break; /* x-values */ |
||
2984 | case 1:double_data[1] = get_real(infile,0);break; /* y-values */ |
||
2985 | case 2:double_data[2] = get_real(infile,0);break; /* x-values */ |
||
2986 | case 3:double_data[3] = get_real(infile,0);break; /* y-values */ |
||
2987 | case 4:int_data[0] = (int) (get_real(infile,0));break; /* radius value in pixels */ |
||
2988 | case 5:stroke_color = get_color(infile,1);/* name or hex color */ |
||
2989 | /* ensure no inverted roundrect is produced... */ |
||
2990 | 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];} |
||
2991 | 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 | 2992 | decimals = find_number_of_digits(precision); |
11806 | schaersvoo | 2993 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,6,[%.*f,%.*f],[%.*f,%.*f],[%d,%d],[%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,double_data[1],decimals,double_data[3],int_data[0],int_data[0],int_data[0],int_data[0],line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset); |
8379 | schaersvoo | 2994 | if(onclick > 0){click_cnt++;} |
2995 | /* click_cnt++;*/ |
||
2996 | reset(); |
||
11806 | schaersvoo | 2997 | break; |
2998 | } |
||
2999 | } |
||
3000 | break; |
||
8386 | schaersvoo | 3001 | |
11806 | schaersvoo | 3002 | case ROUNDRECTS: |
8347 | schaersvoo | 3003 | /* |
11806 | schaersvoo | 3004 | @ roundrects color,radius in px,x1,y1,x2,y2,x3,y3,x4,y4,.... |
3005 | @ for filled roundrects use command/keyword <a href='#filled'>'filled'</a> before command |
||
9406 | schaersvoo | 3006 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually |
8347 | schaersvoo | 3007 | */ |
11806 | schaersvoo | 3008 | |
8347 | schaersvoo | 3009 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
11806 | schaersvoo | 3010 | int_data[0] = (int) (get_real(infile,0)); /* radius value in pixels */ |
8347 | schaersvoo | 3011 | fill_color = stroke_color; |
3012 | i=0; |
||
3013 | while( ! done ){ /* get next item until EOL*/ |
||
3014 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
3015 | if(i%2 == 0 ){ |
||
3016 | double_data[i] = get_real(infile,0); /* x */ |
||
3017 | } |
||
3018 | else |
||
3019 | { |
||
3020 | double_data[i] = get_real(infile,1); /* y */ |
||
3021 | } |
||
3022 | i++; |
||
3023 | } |
||
3024 | decimals = find_number_of_digits(precision); |
||
3025 | for(c = 0 ; c < i-1 ; c = c+4){ |
||
11806 | schaersvoo | 3026 | /* ensure no inverted roundrect is produced... */ |
3027 | 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];} |
||
3028 | 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];} |
||
3029 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,6,[%.*f,%.*f],[%.*f,%.*f],[%d,%d],[%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+2],decimals,double_data[c+1],decimals,double_data[c+3],int_data[0],int_data[0],int_data[0],int_data[0],line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset); |
||
3030 | if(onclick > 0){click_cnt++;} |
||
8379 | schaersvoo | 3031 | /* click_cnt++; */ |
8347 | schaersvoo | 3032 | } |
3033 | reset(); |
||
3034 | break; |
||
8386 | schaersvoo | 3035 | |
11806 | schaersvoo | 3036 | case RULER: |
7614 | schaersvoo | 3037 | /* |
11806 | schaersvoo | 3038 | @ ruler x,y,x-width ,y-height,mode |
3039 | @ x,y are the initial location |
||
3040 | @ x-width , y-height are the ruler dimensions width & height in xy-coordinate system |
||
3041 | @ the ruler scale is by definition the x-scale, set by command 'xrange'<br />for example: a ruler x-width of 6 will have a scale ranging from 0 to 6 |
||
3042 | @ mode : use -1 to set the ruler interactive (eg mouse movement of ruler; drag & rotate)<br />use mode = '0° - 360°' to set the ruler with a static angle of some value |
||
3043 | @ if combined with a protractor, use replyformat = 32 |
||
3044 | @ only one ruler allowed (for the time being) |
||
3045 | @ when using command 'zoom' , pay <b>attention</b> to the size and symmetry of your canvas<br />...to avoid a partial image, locate the start position near the center of the visual canvas<br /><em>technical:<br /> the actual 'ruler' is just a static generated image in a new canvas-memory<br />This image is only generated once, and a copy of its bitmap is translated & rotated onto the visible canvas.<br />That is the reason for the 'high-speed dragging and rotating'.<br />I've limited its size to xsize × ysize e.g. the same size as the visual canvas... </em> |
||
3046 | @ usage: first left click on the ruler will activate dragging;<br />a second left click will activate rotating (just move mouse around)<br />a third click will freeze this position and the x/y-coordinate and angle in radians will be stored in reply(3)<br />a next click will restart this sequence... |
||
7614 | schaersvoo | 3047 | */ |
11806 | schaersvoo | 3048 | for( i = 0;i < 5; i++ ){ |
7614 | schaersvoo | 3049 | switch(i){ |
11806 | schaersvoo | 3050 | case 0: double_data[0] = get_real(infile,0);break; /* x-center */ |
3051 | case 1: double_data[1] = get_real(infile,0);break; /* y-center */ |
||
3052 | case 2: double_data[2] = get_real(infile,0);break; /* x-width */ |
||
3053 | case 3: double_data[3] = get_real(infile,0);break; /* y-width */ |
||
3054 | case 4: int_data[0] = (int)(get_real(infile,1)); /* passive mode */ |
||
3055 | decimals = find_number_of_digits(precision); |
||
3056 | if( int_data[0] < 0 ){ |
||
3057 | if( js_function[JS_FIND_ANGLE] != 1 ){ js_function[JS_FIND_ANGLE] = 1; } |
||
3058 | } |
||
3059 | 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]); |
||
3060 | string_length = snprintf(NULL,0,";ruler%d(); ",canvas_root_id); |
||
3061 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
3062 | snprintf(tmp_buffer,string_length,";ruler%d(); ",canvas_root_id); |
||
3063 | add_to_buffer(tmp_buffer); |
||
3064 | reply_precision = precision; |
||
3065 | /* no reply from ruler if non-interactive */ |
||
3066 | if( reply_format == 0 && int_data[0] == -1 ){reply_format = 31;} |
||
7614 | schaersvoo | 3067 | break; |
3068 | default: break; |
||
3069 | } |
||
3070 | } |
||
3071 | break; |
||
8386 | schaersvoo | 3072 | |
11806 | schaersvoo | 3073 | case RESETOFFSET: |
7614 | schaersvoo | 3074 | /* |
11806 | schaersvoo | 3075 | @ resetoffset |
3076 | @ keyword ; use to restore text placement on the canvas to the real (x;y) coordinates of the left bottom corner of the text |
||
3077 | @ 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 | 3078 | */ |
11806 | schaersvoo | 3079 | use_offset = 0; |
3080 | break; |
||
3081 | |||
3082 | case ROTATE: |
||
3083 | /* |
||
3084 | @ rotate rotation_angle |
||
3085 | @ angle in degrees |
||
3086 | @ (only) the next object will be rotated is given angle |
||
3087 | @ positive values rotate counter clockwise |
||
3088 | @ attention: all objects will be rotated around their first point...<br /><em>rotate 45</em><br /> <em>triangle 1,1,5,1,3,4,red</em><br />will rotate 45 degrees around point (1:1) |
||
3089 | @ 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> |
||
3090 | @ 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 |
||
3091 | */ |
||
3092 | use_rotate = TRUE; |
||
3093 | angle = -1*(get_real(infile,1));/* -1 : to be compatible with Flydraw... */ |
||
7614 | schaersvoo | 3094 | break; |
11806 | schaersvoo | 3095 | case ROTATION_CENTER: |
9306 | schaersvoo | 3096 | /* |
11806 | schaersvoo | 3097 | @ rotationcenter x_center,y_center |
3098 | @ define an rotation center in your x/y-coordinate system |
||
3099 | @ wims will not check the validity of your input; use javascript console to debug any erors |
||
3100 | @ if not defined a rotation will be around the first point of an object |
||
3101 | @ to be used before command <a href="#rotate">rotate</a> |
||
3102 | @ all other commands will use this rotation center, unless a <a href="#killrotation">killrotation</a> is given |
||
9306 | schaersvoo | 3103 | */ |
11806 | schaersvoo | 3104 | temp = get_string(infile,1); |
3105 | string_length = snprintf(NULL,0,"[ %s ]",temp); |
||
3106 | check_string_length(string_length); |
||
3107 | rotation_center = my_newmem(string_length+1); |
||
3108 | snprintf(rotation_center,string_length,"[%s]",temp); |
||
9306 | schaersvoo | 3109 | break; |
11806 | schaersvoo | 3110 | |
3111 | case SIZE: |
||
3112 | /* |
||
3113 | @ size width,height |
||
3114 | @ set canvas size in pixels |
||
3115 | @ mandatory first command (can only be preceded by keyword <a href="#popup">'popup'</a>) |
||
3116 | @ 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 |
||
3117 | */ |
||
3118 | found_size_command = 1; |
||
3119 | /* using fabs : however "xsize == int" : so "xsize = abs( (int) get_real(infile,0))" would be the idea... */ |
||
3120 | xsize = (int)(fabs(round(get_real(infile,0)))); /* just to be sure that sizes > 0 */ |
||
3121 | ysize = (int)(fabs(round(get_real(infile,1)))); |
||
3122 | /* sometimes we want xrange / yrange to be in pixels...without telling x/y-range */ |
||
3123 | xmin = 0;xmax = xsize; |
||
3124 | ymin = 0;ymax = ysize; |
||
3125 | |||
3126 | /* |
||
3127 | The sequence in which stuff is finally printed is important !! |
||
3128 | */ |
||
3129 | fprintf(stdout,"\n\ |
||
3130 | <script type=\"text/javascript\">\n\ |
||
3131 | /*<![CDATA[*/\n\ |
||
3132 | if( typeof(wims_status) === 'undefined' ){ var wims_status = \"$status\";};\ |
||
3133 | if( typeof(use_dragdrop_reply) === 'undefined' ){ var use_dragdrop_reply = false;};\ |
||
3134 | if( typeof(canvas_scripts) === 'undefined' ){ var canvas_scripts = new Array();};\ |
||
3135 | canvas_scripts.push(\"%d\");\n/*]]>*/\n</script>\n\ |
||
3136 | ",canvas_root_id); |
||
3137 | |||
3138 | /* style=\"display:block;position:relative;margin-left:auto;margin-right:auto;margin-bottom:4px;\" */ |
||
3139 | if( use_tooltip != 2){ |
||
3140 | fprintf(stdout,"<!-- canvasdraw div -->\n\ |
||
3141 | <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\ |
||
3142 | <!-- tooltip and input placeholder -->\n\ |
||
3143 | <div id=\"tooltip_placeholder_div%d\" style=\"text-align:center\"><span id=\"tooltip_placeholder%d\" style=\"display:none;\"></span></div>\ |
||
3144 | <!-- include actual object code via include file -->\n\ |
||
3145 | <script id=\"canvas_script%d\" type=\"text/javascript\" src=\"%s\"></script>\n",canvas_root_id,xsize,ysize,canvas_root_id,canvas_root_id,canvas_root_id,getfile_cmd); |
||
3146 | } |
||
3147 | else |
||
3148 | { |
||
3149 | /* |
||
3150 | set canvas_div invisible and do not include placeholder in main html page : |
||
3151 | the js-include will also be in a popup window...to be shown when wims $status = done |
||
3152 | */ |
||
3153 | fprintf(stdout,"<!-- canvasdraw div invisible -->\n\ |
||
3154 | <div tabindex=\"0\" id=\"canvas_div%d\" style=\"display:none;position:relative;width:%dpx;height:%dpx;margin-left:auto;margin-right:auto;\" ></div>\n\ |
||
3155 | <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>\ |
||
3156 | <!-- include actual object code via include file -->\n\ |
||
3157 | <script id=\"canvas_script%d\" type=\"text/javascript\" src=\"%s\"></script>\n",canvas_root_id,xsize,ysize,canvas_root_id,canvas_root_id,canvas_root_id,getfile_cmd); |
||
3158 | } |
||
3159 | |||
3160 | /* these must be global...it's all really very poor javascript :( */ |
||
3161 | fprintf(js_include_file,"\n<!-- begin generated javascript include for canvasdraw -->\n\ |
||
3162 | \"use strict\";\n\ |
||
3163 | <!-- these variables and functions must be global -->\n\ |
||
3164 | var read_dragdrop%d;\ |
||
3165 | var read_canvas%d;\ |
||
3166 | var set_clock;\ |
||
3167 | var clear_draw_area%d;\ |
||
3168 | var update_draw_area%d;\ |
||
3169 | var draw_boxplot;\ |
||
3170 | var redraw_all%d;\ |
||
3171 | var userdraw_primitive;\n\ |
||
3172 | var wims_canvas_function%d = function(){\n<!-- common used stuff -->\n\ |
||
3173 | var userdraw_x = [];var userdraw_y = [];var userdraw_radius = [];\n\ |
||
3174 | var xsize = %d;\ |
||
3175 | var ysize = %d;\ |
||
3176 | var precision = 100;\ |
||
3177 | var canvas_div = document.getElementById(\"canvas_div%d\");\ |
||
3178 | 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;};\ |
||
3179 | 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;};\ |
||
3180 | 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);};};\ |
||
3181 | 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);};};\ |
||
3182 | 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);};};\ |
||
3183 | 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);};};\ |
||
3184 | function scale_x_radius(rx){return rx*xsize/(xmax - xmin);};\ |
||
3185 | function scale_y_radius(ry){return ry*ysize/(ymax - ymin);};\ |
||
3186 | function distance(x1,y1,x2,y2){return Math.sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) );};\ |
||
3187 | 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) ));};\ |
||
3188 | 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;};\ |
||
3189 | function slide(obj,dx,dy){for(var p = 0 ; p < obj.x.length; p++){obj.x[p] = x2px(obj.xorg[p] + dx);obj.y[p] = y2px(obj.yorg[p] + dy);};return obj;};\ |
||
3190 | var isTouch = (('ontouchstart' in window) || (navigator.msMaxTouchPoints > 0));\ |
||
3191 | var x_use_snap_to_grid = 0;var y_use_snap_to_grid = 0;var snap_x = 1;var snap_y = 1;\ |
||
3192 | var use_snap_to_points = 0;\ |
||
3193 | function snap_to_x(x){return x2px(snap_x*(Math.round((px2x(x))/snap_x)));};\ |
||
3194 | function snap_to_y(y){return y2px(snap_y*(Math.round((px2y(y))/snap_y)));};\n\ |
||
3195 | var xlogbase = 10;\ |
||
3196 | var ylogbase = 10;\ |
||
3197 | var use_xlogscale = 0;\ |
||
3198 | var use_ylogscale = 0;\ |
||
3199 | var x_strings = null;var x_strings_up = null;\ |
||
3200 | var y_strings = null;\ |
||
3201 | var use_pan_and_zoom = 0;\ |
||
3202 | var use_jsmath = 0;\ |
||
3203 | var xstart = 0;\ |
||
3204 | var ystart = 0;\ |
||
3205 | var unit_x=\" \";\ |
||
3206 | var unit_y=\" \";\ |
||
3207 | var external_canvas = create_canvas%d(%d,xsize,ysize);\n",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,xsize,ysize,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,EXTERNAL_IMAGE_CANVAS); |
||
3208 | /* default add the drag code : nearly always used ...*/ |
||
3209 | add_drag_code(js_include_file,DRAG_CANVAS,canvas_root_id); |
||
3210 | |||
3211 | break; |
||
3212 | |||
3213 | |||
3214 | case SEGMENT: |
||
7614 | schaersvoo | 3215 | /* |
11806 | schaersvoo | 3216 | @ segment x1,y1,x2,y2,color |
3217 | @ alternative : seg |
||
3218 | @ draw a line segment between points (x1:y1)--(x2:y2) in color 'color' |
||
3219 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
||
7614 | schaersvoo | 3220 | */ |
11806 | schaersvoo | 3221 | for(i=0;i<5;i++) { |
7614 | schaersvoo | 3222 | switch(i){ |
11806 | schaersvoo | 3223 | case 0: double_data[0]= get_real(infile,0);break; /* x1-values */ |
3224 | case 1: double_data[1]= get_real(infile,0);break; /* y1-values */ |
||
3225 | case 2: double_data[2]= get_real(infile,0);break; /* x2-values */ |
||
3226 | case 3: double_data[3]= get_real(infile,0);break; /* y2-values */ |
||
3227 | case 4: stroke_color=get_color(infile,1);/* name or hex color */ |
||
3228 | decimals = find_number_of_digits(precision); |
||
3229 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,double_data[1],decimals,double_data[3],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset); |
||
3230 | if(onclick > 0){click_cnt++;} |
||
3231 | /* click_cnt++; */ |
||
3232 | reset(); |
||
3233 | break; |
||
3234 | default: break; |
||
7614 | schaersvoo | 3235 | } |
3236 | } |
||
3237 | break; |
||
10953 | bpr | 3238 | |
11806 | schaersvoo | 3239 | case SEGMENTS: |
9213 | schaersvoo | 3240 | /* |
11806 | schaersvoo | 3241 | @ segments color,x1,y1,x2,y2,...,x_n,y_n |
3242 | @ alternative : segs |
||
3243 | @ draw multiple segments between points (x1:y1)--(x2:y2).....and... (x_n-1:y_n-1)--(x_n:y_n) in color 'color' |
||
3244 | @ use command 'linewidth int' to adust size |
||
3245 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!) |
||
9213 | schaersvoo | 3246 | */ |
11806 | schaersvoo | 3247 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
3248 | fill_color = stroke_color; |
||
3249 | i=0; |
||
3250 | while( ! done ){ /* get next item until EOL*/ |
||
3251 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
3252 | if(i%2 == 0 ){ |
||
3253 | double_data[i] = get_real(infile,0); /* x */ |
||
3254 | } |
||
3255 | else |
||
3256 | { |
||
3257 | double_data[i] = get_real(infile,1); /* y */ |
||
3258 | } |
||
3259 | i++; |
||
3260 | } |
||
3261 | decimals = find_number_of_digits(precision); |
||
3262 | for(c = 0 ; c < i-1 ; c = c+4){ |
||
3263 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+2],decimals,double_data[c+1],decimals,double_data[c+3],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset); |
||
3264 | if(onclick > 0){click_cnt++;} |
||
3265 | /* click_cnt++;*/ |
||
3266 | } |
||
3267 | reset(); |
||
9213 | schaersvoo | 3268 | break; |
11806 | schaersvoo | 3269 | |
3270 | case SETLIMITS: |
||
9213 | schaersvoo | 3271 | /* |
11806 | schaersvoo | 3272 | @ setlimits |
3273 | @ keyword : if set, it will produce 4 inputfields for 'xmin,xmax,ymin,ymax' and an 'ok' button |
||
3274 | @ may be used for inputfield based zooming / panning |
||
3275 | @ may be styled using command <a href="#inputstyle">inputstyle</a> |
||
3276 | @ use commands <a href="#xlabel">xlabel / ylabel</a> to change text from xmin to 'xlabel' etc |
||
3277 | @ note:the input value will not be checked on validity |
||
9213 | schaersvoo | 3278 | */ |
11806 | schaersvoo | 3279 | if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */ |
3280 | add_setlimits(js_include_file,canvas_root_id,font_size,input_style); |
||
3281 | /* add_setlimits provides 'fprintf(js_include_file,"use_pan_and_zoom = 1;");' */ |
||
3282 | use_pan_and_zoom = TRUE; |
||
3283 | done = TRUE; |
||
9213 | schaersvoo | 3284 | break; |
11806 | schaersvoo | 3285 | |
3286 | case SETPIXEL: |
||
9213 | schaersvoo | 3287 | /* |
11806 | schaersvoo | 3288 | @ setpixel x,y,color |
3289 | @ A rectangular "point" with diameter 1 pixel centered at (x:y) in xrange / yrange |
||
3290 | @ pixels can <b>not</b> be dragged or clicked |
||
3291 | @ "pixelsize = 1" may be changed by command "pixelsize int" |
||
9213 | schaersvoo | 3292 | */ |
11806 | schaersvoo | 3293 | if( js_function[DRAW_PIXELS] != 1 ){ js_function[DRAW_PIXELS] = 1;} |
3294 | for(i=0;i<3;i++){ |
||
3295 | switch(i){ |
||
3296 | case 0: double_data[0] = get_real(infile,0); break; /* x */ |
||
3297 | case 1: double_data[1] = get_real(infile,0); break; /* y */ |
||
3298 | case 2: stroke_color = get_color(infile,1); |
||
3299 | string_length = snprintf(NULL,0,"draw_setpixel([%f],[%f],\"%s\",%.2f,%d);\n",double_data[0],double_data[1],stroke_color,stroke_opacity,pixelsize); |
||
3300 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
3301 | snprintf(tmp_buffer,string_length,"draw_setpixel([%f],[%f],\"%s\",%.2f,%d);\n",double_data[0],double_data[1],stroke_color,stroke_opacity,pixelsize); |
||
3302 | add_to_buffer(tmp_buffer); |
||
3303 | break; |
||
3304 | default:break; |
||
3305 | } |
||
3306 | } |
||
3307 | reset(); |
||
3308 | break; |
||
3309 | |||
3310 | |||
3311 | case SLIDER: |
||
9213 | schaersvoo | 3312 | /* |
11806 | schaersvoo | 3313 | @ slider start_value,end_value,width px,height px,<em>type</em>,label |
3314 | @ <em>type</em> may be : xy,x,y,angle |
||
3315 | @ 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 |
||
3316 | @ if a unit (or something like that...) for x/y-value display is needed, use commands 'xunit' and / or 'yunit' |
||
3317 | @ if the translation should be performed using a function, use for type: xy function,x function,y function<br />use commands sliderfunction_x and/or sliderfunction_y before the slider command to define the functions<br />example:<br />sliderfunction_x x^2<br />sliderfunction_y y^2<br />slider -5,5,100,100,xy function,Some_Text<br />...some stuff to slide<br />killslider<br />sliderfunction_x x^2-2<br />slider -15,15,100,10,x function,Some_Other_Text<br />...more stuff to slide<br />killslider<br />... etc |
||
3318 | @ use command 'slider' before draggable/clickable objects. |
||
3319 | @ drag and drop may be combined with rotation slider<br />for example an arrow rotated by a slider may be placed anywhere (drag&drop)<em>size 300,300<br />xrange -5,5<br />yrange -5,5<br />grid 1,1,grey<br />linewidth 3<br />drag xy<br />fillcolor orange<br />strokecolor blue<br />slider 0,2*pi,250,30,angle degrees,Rotate arrow<br />arrow 2,2,5,5,8,red</em> |
||
3320 | @ no slider for a math function, these can be traced using command 'trace_jscurve some_function_in_x' |
||
3321 | @ 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' |
||
3322 | @ amount of sliders is not limited. |
||
3323 | @ javascript:read_dragdrop(); will return an array with 'object_number:slider_value' |
||
3324 | @ type=xy: will produce a 2D 'slider' [rectangle width x heigh px] in your web page |
||
3325 | @ every draggable object may have its own slider (no limit in amount of sliders) |
||
3326 | @ label: some slider text |
||
3327 | @ use fillcolor for slider ball |
||
3328 | @ use strokecolor for slider bar |
||
3329 | @ use fontfamily / fontcolor to set used fonts |
||
3330 | @ use opacity (only fill opacity will be used) to set transparency |
||
3331 | @ the slider canvas will be added to the 'tooltip div' : so incompatible with command tooltip ; setlimits etc |
||
9213 | schaersvoo | 3332 | */ |
11806 | schaersvoo | 3333 | slider_cnt++;/* slider starts at 1 */ |
3334 | for(i=0; i<6 ; i++){ |
||
3335 | switch(i){ |
||
3336 | case 0: double_data[0] = get_real(infile,0);break; /* start value */ |
||
3337 | case 1: double_data[1] = get_real(infile,0);break; /* end value */ |
||
3338 | case 2: int_data[0] = (int)(get_real(infile,0));break; /* width */ |
||
3339 | case 3: int_data[1] = (int)(get_real(infile,0));break; /* height */ |
||
3340 | case 4: temp = get_string_argument(infile,0); /* type : xy,x,y,angle */ |
||
3341 | if(strstr(temp,"xy")!= 0){ |
||
3342 | slider = 4; |
||
3343 | } |
||
3344 | else |
||
3345 | { |
||
3346 | if(strstr(temp,"x") != 0){ |
||
3347 | slider = 1; |
||
3348 | } |
||
3349 | else |
||
3350 | { |
||
3351 | if(strstr(temp,"y") != 0){ |
||
3352 | slider = 2; |
||
3353 | } |
||
3354 | else |
||
3355 | { |
||
3356 | if(strstr(temp,"angle") != 0){ /* angle diplay radian */ |
||
3357 | slider = 3; |
||
3358 | } |
||
3359 | else |
||
3360 | { |
||
3361 | canvas_error("slider can be of type: xy,x,y,angle,fun_x:fun_y"); |
||
3362 | } |
||
3363 | } |
||
3364 | } |
||
3365 | } |
||
3366 | if(strstr(temp,"display")!=0){ |
||
3367 | if( slider == 4 ){ /* show x:y */ |
||
3368 | use_slider_display = 1; /* show x xy values in canvas window */ |
||
3369 | } |
||
3370 | else |
||
3371 | { |
||
3372 | if( slider == 1 ){ /* show only x -values */ |
||
3373 | use_slider_display = 10; |
||
3374 | } |
||
3375 | else |
||
3376 | { |
||
3377 | use_slider_display = 11; /* show only y -values*/ |
||
3378 | } |
||
3379 | } |
||
3380 | } |
||
3381 | else |
||
3382 | { |
||
3383 | if(strstr(temp,"degree")!= 0){ |
||
3384 | use_slider_display = 2; /* show angle values in canvas window */ |
||
3385 | } |
||
3386 | else |
||
3387 | { |
||
3388 | if(strstr(temp,"radian")!=0){ |
||
3389 | use_slider_display = 3; /* show radian values in canvas window */ |
||
3390 | } |
||
3391 | } |
||
3392 | } |
||
3393 | if(use_slider_display != 0 && slider_cnt == 1){ /*add just once the display js-code */ |
||
3394 | add_slider_display(js_include_file,canvas_root_id,precision,font_size,font_color,stroke_opacity); |
||
3395 | } |
||
3396 | if(strstr(temp,"fun")!= 0){ |
||
3397 | if( use_js_math == FALSE){/* add this stuff only once...*/ |
||
3398 | add_to_js_math(js_include_file); use_js_math = TRUE; |
||
3399 | } |
||
3400 | fprintf(js_include_file,"var slider_function%d = {x:to_js_math('%s'),y:to_js_math('%s')};",slider_cnt,slider_function_x,slider_function_y); |
||
3401 | slider_function_x = "x";slider_function_y = "y";/* reset the functions for next slider...*/ |
||
3402 | } |
||
3403 | else |
||
3404 | { |
||
3405 | fprintf(js_include_file,"var slider_function%d = {x:'x',y:'y'};",slider_cnt); |
||
3406 | /* we must define these, otherwise 'use stict' will cause an error */ |
||
3407 | } |
||
3408 | break; |
||
3409 | case 5: /* some string used for slider description */ |
||
3410 | if(slider == 4){ |
||
3411 | add_xyslider(js_include_file,canvas_root_id,double_data[0],double_data[1],int_data[0],int_data[1],slider,get_string_argument(infile,1),slider_cnt,stroke_color,fill_color,line_width,fill_opacity,font_family,font_color,use_slider_display); |
||
3412 | } |
||
3413 | else |
||
3414 | { |
||
3415 | add_slider(js_include_file,canvas_root_id,double_data[0],double_data[1],int_data[0],int_data[1],slider,get_string_argument(infile,1),slider_cnt,stroke_color,fill_color,line_width,fill_opacity,font_family,font_color,use_slider_display); |
||
3416 | } |
||
3417 | break; |
||
3418 | } |
||
3419 | } |
||
9213 | schaersvoo | 3420 | break; |
11806 | schaersvoo | 3421 | case SLIDER_X: |
9213 | schaersvoo | 3422 | /* |
11806 | schaersvoo | 3423 | @ sliderfunction_x some_function_in_x |
3424 | @ default value "x" |
||
3425 | @ the x-value of the slider object(s) will be calculated with this function. |
||
3426 | @ default is the x-slider value itself |
||
3427 | @ only used by command 'slider' |
||
3428 | @ define before a slider command ! |
||
9213 | schaersvoo | 3429 | */ |
11806 | schaersvoo | 3430 | slider_function_x = get_string(infile,1); |
3431 | break; |
||
3432 | case SLIDER_Y: |
||
3433 | slider_function_y = get_string(infile,1); |
||
3434 | /* |
||
3435 | @ sliderfunction_y some_function_in_y |
||
3436 | @ default value "y" |
||
3437 | @ the y-value of the slider object(s) will be calculated with this function. |
||
3438 | @ only used by command 'slider' |
||
3439 | @ define before a slider command ! |
||
3440 | */ |
||
3441 | break; |
||
3442 | case SGRAPH: |
||
3443 | /* |
||
3444 | @ sgraph xstart,ystart,xmajor,ymajor,xminor,yminor,majorgrid_color,minorgrid_color |
||
3445 | @ primitive implementation of a 'broken scale' graph... |
||
3446 | @ 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 /> |
||
3447 | @ example:<br />size 400,400<br />xrange 0,10000<br />yrange 0,100<br />sgraph 9000,50,100,10,4,4,grey,blue<br />userinput_xy<br />linewidth 2<br />userdraw segments,red |
||
3448 | */ |
||
3449 | if( js_function[DRAW_SGRAPH] != 1 ){ js_function[DRAW_SGRAPH] = 1;} |
||
3450 | for(i = 0 ; i < 8 ;i++){ |
||
3451 | switch(i){ |
||
3452 | case 0:double_data[0] = get_real(infile,0);break; |
||
3453 | case 1:double_data[1] = get_real(infile,0);break; |
||
3454 | case 2:double_data[2] = get_real(infile,0);break; |
||
3455 | case 3:double_data[3] = get_real(infile,0);break; |
||
3456 | case 4:int_data[0] = (int)(get_real(infile,0));break; |
||
3457 | case 5:int_data[1] = (int)(get_real(infile,0));break; |
||
3458 | case 6:stroke_color = get_color(infile,0);break; |
||
3459 | case 7:font_color = get_color(infile,1); |
||
3460 | string_length = snprintf(NULL,0,"xstart = %f;\nystart = %f;\ndraw_sgraph(%d,%d,%f,%f,%d,%d,\"%s\",\"%s\",\"%s\",%f,%d);\n",double_data[0],double_data[1],GRID_CANVAS,precision,double_data[2],double_data[3],int_data[0],int_data[1],stroke_color,font_color,font_family,stroke_opacity,font_size); |
||
3461 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
3462 | 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); |
||
3463 | add_to_buffer(tmp_buffer); |
||
3464 | break; |
||
3465 | default:break; |
||
3466 | } |
||
3467 | } |
||
3468 | /* sgraph(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily,opacity)*/ |
||
9213 | schaersvoo | 3469 | break; |
11806 | schaersvoo | 3470 | |
3471 | case SNAPTOFUNCTION: |
||
9213 | schaersvoo | 3472 | /* |
11806 | schaersvoo | 3473 | @ snaptofunction some_function_in_x,some_funtion_in_y |
3474 | @ alternative : snaptofun some_function_in_x,some_funtion_in_y |
||
3475 | @ the next object will snap to the calculated values |
||
3476 | @ if you want only modification of y-values,just use: snaptofunction x,5*sin(1/y) |
||
3477 | @ if you want only modification of x-values,just use: snaptofunction 5*sin(1/x),y |
||
3478 | @ for now only one instance of 'snaptofunction' is allowed |
||
3479 | @ use rawmath on your functions: no validity checking is done by wims ! |
||
3480 | @ example:<br />....<br />snaptofunction 5*(cos(x),4*sin(y)<br />linewidth 3<br />userdraw points,blue<br />....<br /> |
||
3481 | @ example : switching x and y coordinates?<br />snaptofunction y,x |
||
9213 | schaersvoo | 3482 | */ |
11806 | schaersvoo | 3483 | temp = get_string_argument(infile,0); |
3484 | fprintf(js_include_file,"\nuse_snap_to_points = 2;"); |
||
3485 | if( use_js_math == FALSE){/* add this stuff only once...*/ |
||
3486 | add_to_js_math(js_include_file); use_js_math = TRUE; |
||
3487 | } |
||
3488 | 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)); |
||
3489 | break; |
||
3490 | case SNAPTOPOINTS: |
||
3491 | /* |
||
3492 | @ snaptopoints x1,y1,x2,y2,x3,y3.... |
||
3493 | @ a userdraw object will snap to these points. |
||
3494 | @ the array size (e.g. the number of points) of command 'snaptopoints' is limited by constant MAX_INT (canvasdraw.h) |
||
3495 | @ a draggable object (use command "drag x|y|xy") will snap to the clossed of these points when dragged (mouseup) |
||
3496 | @ other options: use keyword "snaptogrid", "xsnaptogrid" or "ysnaptogrid" |
||
3497 | */ |
||
3498 | i = 0; |
||
3499 | while( ! done ){ /* get next item until EOL*/ |
||
3500 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
3501 | if(i%2 == 0 ){ |
||
3502 | double_data[i] = get_real(infile,0); /* x */ |
||
3503 | } |
||
3504 | else |
||
3505 | { |
||
3506 | double_data[i] = get_real(infile,1); /* y */ |
||
3507 | } |
||
3508 | i++; |
||
3509 | } |
||
3510 | decimals = find_number_of_digits(precision); |
||
3511 | fprintf(js_include_file,"\nuse_snap_to_points = 1;\nfunction find_min_diff(x,y,X,Y){var diff = 100000000;var chk;var idx = 0;for(var p = 0 ; p < %d ; p++){chk = distance(x,y,X[p],Y[p]);if( chk < diff ){ diff = chk; idx = p;};};return idx;};\nfunction snap_to_points(x,y){x = px2x(x); y = px2y(y);var points = [%s];var xpoints = points[0];var ypoints = points[1];var idx = find_min_diff(x,y,xpoints,ypoints);x = xpoints[idx];y = ypoints[idx];return [x2px(x),y2px(y)];};\n",(int) (0.5*i),double_xy2js_array(double_data,i,decimals)); |
||
3512 | break; |
||
3513 | |||
3514 | case SNAPTOGRID: |
||
3515 | /* |
||
3516 | @ snaptogrid |
||
3517 | @ keyword (no arguments required) |
||
3518 | @ a draggable object (use command "drag x|y|xy") will snap to the given grid when dragged (mouseup) |
||
3519 | @ in case of userdraw the drawn points will snap to xmajor / ymajor grid |
||
3520 | @ if no grid is defined ,points will snap to every integer xrange/yrange value. (eg snap_x=1,snap_y=1) |
||
3521 | @ if you do not want a visible grid, but you only want a 'snaptogrid' with some value...define this grid with opacity 0. |
||
3522 | @ if xminor / yminor is defined,(use keyword 'axis' to activate the minor steps) the drawing will snap to xminor and yminor<br />use only even dividers in x/y-minor...for example<br />snaptogrid<br />axis<br />grid 2,1,grey,4,4,7,red<br /> will snap on x=0, x=0.5, x=1, x=1.5 ....<br /> will snap on y=0, y=0.25 y=0.5 y=0.75 ...<br /> |
||
3523 | */ |
||
3524 | fprintf(js_include_file,"\nx_use_snap_to_grid = 1;y_use_snap_to_grid = 1;"); |
||
3525 | break; |
||
3526 | |||
3527 | case SQUARE: |
||
3528 | /* |
||
3529 | @ square x,y,side (px) ,color |
||
3530 | @ draw a square with left top corner (x:y) with side 'side' in color 'color' |
||
3531 | @ use command 'fsquare x,y,side,color' for a filled square |
||
3532 | @ use command/keyword <a href='#filled'>'filled'</a> before command 'square x,y,side,color' |
||
3533 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
||
3534 | */ |
||
3535 | for(i=0;i<5;i++){ |
||
3536 | switch(i){ |
||
3537 | case 0:double_data[0] = get_real(infile,0);break; /* x1-values */ |
||
3538 | case 1:double_data[1] = get_real(infile,0);break; /* y1-values */ |
||
3539 | case 2:double_data[2] = (int) (get_real(infile,0));break; /* width in px */ |
||
3540 | case 3: |
||
3541 | stroke_color = get_color(infile,1);/* name or hex color */ |
||
3542 | decimals = find_number_of_digits(precision); |
||
3543 | double_data[3] = double_data[0] + (xmax - xmin)*double_data[2]/xsize; |
||
3544 | double_data[4] = double_data[1] + -1*(ymax - ymin)*double_data[2]/ysize; |
||
3545 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,1,[%.*f,%.*f,%.*f,%.*f],[%.*f,%.*f,%.*f,%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[3],decimals,double_data[3],decimals,double_data[0],decimals,double_data[1],decimals,double_data[1],decimals,double_data[4],decimals,double_data[4],line_width,line_width,line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset); |
||
3546 | if(onclick > 0){click_cnt++;} |
||
3547 | /* click_cnt++; */ |
||
3548 | reset(); |
||
3549 | break; |
||
3550 | } |
||
3551 | } |
||
9213 | schaersvoo | 3552 | break; |
11806 | schaersvoo | 3553 | |
3554 | case STATUS: |
||
9213 | schaersvoo | 3555 | /* |
11806 | schaersvoo | 3556 | @ status |
3557 | @ keyword |
||
3558 | @ alernative : nostatus |
||
3559 | @ used to override the effects of "status=done" in wims (answer.phtml) |
||
3560 | @ affects 'readonly' in inputfields / textarea's in canvasimage and all userdraw based commands |
||
3561 | @ e.g.: if keyword 'status' is set, the pupil will be able to modify the canvas when the 'wims $status variable' is set to 'done' |
||
9213 | schaersvoo | 3562 | */ |
11806 | schaersvoo | 3563 | |
3564 | fprintf(js_include_file,"\nwims_status=\"waiting\";\n"); |
||
9213 | schaersvoo | 3565 | break; |
11806 | schaersvoo | 3566 | |
3567 | case STRING: |
||
9213 | schaersvoo | 3568 | /* |
11806 | schaersvoo | 3569 | @ string color,x,y,the text string |
3570 | @ may be set "onclick" or "drag xy" |
||
3571 | @ unicode supported: string red,0,0,\\u2232 |
||
3572 | @ use a command like 'fontfamily italic 24px Ariel' <br />to set fonts on browser that support font change |
||
9213 | schaersvoo | 3573 | */ |
11806 | schaersvoo | 3574 | for(i=0;i<5;i++){ |
3575 | switch(i){ |
||
3576 | case 0: stroke_color = get_color(infile,0);break;/* name or hex color */ |
||
3577 | case 1: double_data[0] = get_real(infile,0);break; /* x in xrange*/ |
||
3578 | case 2: double_data[1] = get_real(infile,0);break; /* y in yrange*/ |
||
3579 | case 3: decimals = find_number_of_digits(precision); |
||
3580 | temp = get_string_argument(infile,1); |
||
3581 | decimals = find_number_of_digits(precision); |
||
3582 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,14,[%.*f],[%.*f],[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[1],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,0,0,0,use_rotate,angle,temp,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset); |
||
3583 | if(onclick > 0){click_cnt++;} |
||
3584 | /* click_cnt++;*/ |
||
3585 | reset(); |
||
3586 | break; |
||
3587 | default:break; |
||
3588 | } |
||
9213 | schaersvoo | 3589 | } |
3590 | break; |
||
11806 | schaersvoo | 3591 | |
3592 | case STRINGUP: |
||
9213 | schaersvoo | 3593 | /* |
11806 | schaersvoo | 3594 | @ stringup color,x,y,rotation_degrees,the text string |
3595 | @ can <b>not</b> be set "onclick" or "drag xy" (because of translaton matrix...mouse incompatible) |
||
3596 | @ unicode supported: stringup red,0,0,45,\\u2232 |
||
3597 | @ use a command like 'fontfamily bold 34px Courier' <br />to set fonts on browser that support font change |
||
3598 | |||
9213 | schaersvoo | 3599 | */ |
11806 | schaersvoo | 3600 | if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;} /* can not be added to shape library : rotate / mouse issues */ |
3601 | for(i=0;i<6;i++){ |
||
3602 | switch(i){ |
||
3603 | case 0: font_color = get_color(infile,0);break;/* name or hex color */ |
||
3604 | case 1: int_data[0] = x2px(get_real(infile,0));break; /* x */ |
||
3605 | case 2: int_data[1] = y2px(get_real(infile,0));break; /* y */ |
||
3606 | case 3: double_data[0] = get_real(infile,0);break;/* rotation */ |
||
3607 | case 4: decimals = find_number_of_digits(precision); |
||
3608 | temp = get_string_argument(infile,1); |
||
3609 | string_length = snprintf(NULL,0,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,%.2f,\"%s\",%d,%.2f,%d,%s);\n",STATIC_CANVAS,int_data[0],int_data[1],font_size,font_family,font_color,stroke_opacity,double_data[0],temp,use_rotate,angle,use_affine,affine_matrix); |
||
3610 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
3611 | snprintf(tmp_buffer,string_length,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,%.2f,\"%s\",%d,%.2f,%d,%s);\n",STATIC_CANVAS,int_data[0],int_data[1],font_size,font_family,font_color,stroke_opacity,double_data[0],temp,use_rotate,angle,use_affine,affine_matrix); |
||
3612 | add_to_buffer(tmp_buffer); |
||
3613 | break; |
||
3614 | default:break; |
||
3615 | } |
||
9213 | schaersvoo | 3616 | } |
11806 | schaersvoo | 3617 | reset(); |
9213 | schaersvoo | 3618 | break; |
11767 | schaersvoo | 3619 | |
11806 | schaersvoo | 3620 | case STYLE: |
11767 | schaersvoo | 3621 | /* |
11806 | schaersvoo | 3622 | @ highlight color,opacity,linewidth |
3623 | @ NOT IMPLEMENTED |
||
3624 | @ use command "onclick" : when the object receives a userclick it will increase its linewidth |
||
11767 | schaersvoo | 3625 | */ |
3626 | break; |
||
11806 | schaersvoo | 3627 | |
3628 | |||
3629 | case STROKECOLOR: |
||
9213 | schaersvoo | 3630 | /* |
11806 | schaersvoo | 3631 | @ strokecolor colorname or #hex |
3632 | @ to be used for commands that do not supply a color argument (like command 'linegraph') |
||
9213 | schaersvoo | 3633 | */ |
11806 | schaersvoo | 3634 | stroke_color = get_color(infile,1); |
9213 | schaersvoo | 3635 | break; |
11806 | schaersvoo | 3636 | |
3637 | case FLY_TEXT: |
||
9213 | schaersvoo | 3638 | /* |
11806 | schaersvoo | 3639 | @ text fontcolor,x,y,font,text_string |
3640 | @ font may be described by keywords : giant,huge,normal,small,tiny |
||
3641 | @ use command 'fontsize' to increase base fontsize for these keywords |
||
3642 | @ may be set "onclick" or "drag xy" |
||
3643 | @ backwards compatible with flydraw |
||
3644 | @ unicode supported: text red,0,0,huge,\\u2232 |
||
3645 | @ use command 'string' combined with 'fontfamily' for a more fine grained control over html5 canvas text element |
||
3646 | @ Avoid mixing old flydraw commands 'text' 'textup' with new canvasdraw commands 'string' stringup'<br />If the fontfamily was set completely like "fontfamily italic 24px Ariel".<br />In that case reset 'fontfamily' to something lke 'fontfamily Ariel' before the old flydraw commands. |
||
9213 | schaersvoo | 3647 | */ |
11806 | schaersvoo | 3648 | for(i = 0; i < 5 ;i++){ |
3649 | switch(i){ |
||
3650 | case 0: stroke_color = get_color(infile,0);break;/* font_color == stroke_color name or hex color */ |
||
3651 | case 1: double_data[0] = get_real(infile,0);break; /* x */ |
||
3652 | case 2: double_data[1] = get_real(infile,0);break; /* y */ |
||
3653 | case 3: fly_font = get_string_argument(infile,0); |
||
3654 | if(strcmp(fly_font,"giant") == 0){ |
||
3655 | fly_font_size = (int)(font_size + 24); |
||
3656 | } |
||
3657 | else |
||
3658 | { |
||
3659 | if(strcmp(fly_font,"huge") == 0){ |
||
3660 | fly_font_size = (int)(font_size + 14); |
||
3661 | } |
||
3662 | else |
||
3663 | { |
||
3664 | if(strcmp(fly_font,"large") == 0){ |
||
3665 | fly_font_size = (int)(font_size + 6); |
||
3666 | } |
||
3667 | else |
||
3668 | { |
||
3669 | if(strcmp(fly_font,"small") == 0){ |
||
3670 | fly_font_size = (int)(font_size - 4); |
||
3671 | if(fly_font_size<0){fly_font_size = 8;} |
||
3672 | } |
||
3673 | } |
||
3674 | } |
||
3675 | } |
||
3676 | break; |
||
3677 | case 4: |
||
3678 | temp = get_string_argument(infile,1); |
||
3679 | decimals = find_number_of_digits(precision); |
||
3680 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,14,[%.*f],[%.*f],[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[1],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,0,0,0,use_rotate,angle,temp,fly_font_size,"null",use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset); |
||
3681 | if(onclick > 0){click_cnt++;} |
||
3682 | /* click_cnt++;*/ |
||
3683 | reset(); |
||
3684 | break; |
||
3685 | default:break; |
||
3686 | } |
||
10953 | bpr | 3687 | } |
9213 | schaersvoo | 3688 | break; |
11806 | schaersvoo | 3689 | case TEXTAREA: |
9289 | schaersvoo | 3690 | /* |
11806 | schaersvoo | 3691 | @ textarea x,y,cols,rows,readonly,value |
3692 | @ may be further controlled by <a href="#inputstyle">"inputstyle"</a> |
||
3693 | @ if "$status=done" (e.g. in answer.phtml) the inputfield will be cleared and set readonly<br />override this by keyword <a href="#status">'status'.</a> |
||
3694 | @ if mathml inputfields are present and / or some userdraw is performed, these data will <b>not</b> be send as well (javascript:read_canvas();) |
||
3695 | @ keyword 'xoffset | centered' is not active for commande 'textarea' |
||
9289 | schaersvoo | 3696 | */ |
11806 | schaersvoo | 3697 | if( js_function[DRAW_TEXTAREAS] != 1 ){ js_function[DRAW_TEXTAREAS] = 1;} |
3698 | for(i = 0 ; i<6;i++){ |
||
9289 | schaersvoo | 3699 | switch(i){ |
11806 | schaersvoo | 3700 | case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in px */ |
3701 | case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in px */ |
||
3702 | case 2: int_data[2]=abs( (int)(get_real(infile,0)));break;/* cols */ |
||
3703 | case 3: int_data[3]=abs( (int)(get_real(infile,0)));break;/* rows */ |
||
3704 | case 4: if( get_real(infile,1) >0){int_data[4] = 1;}else{int_data[3] = 0;};break; /* readonly */ |
||
3705 | case 5: temp = get_string_argument(infile,1); |
||
3706 | string_length = snprintf(NULL,0, "draw_textareas(%d,%d,%d,%d,%d,%d,%d,\"%s\",\"%s\");\n",canvas_root_id,input_cnt,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],input_style,temp); |
||
3707 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
3708 | 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); |
||
3709 | add_to_buffer(tmp_buffer); |
||
3710 | input_cnt++;break; |
||
9289 | schaersvoo | 3711 | default: break; |
3712 | } |
||
3713 | } |
||
11806 | schaersvoo | 3714 | if(reply_format == 0 ){reply_format = 15;} |
3715 | reset(); |
||
9289 | schaersvoo | 3716 | break; |
11806 | schaersvoo | 3717 | |
3718 | case FLY_TEXTUP: |
||
9289 | schaersvoo | 3719 | /* |
11806 | schaersvoo | 3720 | @ textup fontcolor,x,y,font,text_string |
3721 | @ can <b>not</b> be set "onclick" or "drag xy" (because of translaton matrix...mouse incompatible) |
||
3722 | @ font may be described by keywords : giant,huge,normal,small,tiny |
||
3723 | @ use command 'fontsize' to increase base fontsize for the keywords |
||
3724 | @ backwards compatible with flydraw |
||
3725 | @ unicode supported: textup red,0,0,huge,\\u2232 |
||
3726 | @ use command 'stringup' and 'fontfamily' for a more fine grained control over html5 canvas text element |
||
3727 | @ Avoid mixing old flydraw commands 'text' 'textup' with new canvasdraw commands 'string' stringup'<br />If the fontfamily was set completely like "fontfamily italic 24px Ariel".<br />In that case reset 'fontfamily' to something lke 'fontfamily Ariel' before the old flydraw commands. |
||
9289 | schaersvoo | 3728 | */ |
11806 | schaersvoo | 3729 | if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;} |
3730 | for(i = 0; i<5 ;i++){ |
||
9289 | schaersvoo | 3731 | switch(i){ |
11806 | schaersvoo | 3732 | case 0: font_color = get_color(infile,0);break;/* name or hex color */ |
3733 | case 1: int_data[0] = x2px(get_real(infile,0));break; /* x */ |
||
3734 | case 2: int_data[1] = y2px(get_real(infile,0));break; /* y */ |
||
3735 | case 3: fly_font = get_string_argument(infile,0); |
||
3736 | if(strcmp(fly_font,"giant") == 0){ |
||
3737 | fly_font_size = (int)(font_size + 24); |
||
3738 | } |
||
3739 | else |
||
3740 | { |
||
3741 | if(strcmp(fly_font,"huge") == 0){ |
||
3742 | fly_font_size = (int)(font_size + 14); |
||
3743 | } |
||
3744 | else |
||
3745 | { |
||
3746 | if(strcmp(fly_font,"large") == 0){ |
||
3747 | fly_font_size = (int)(font_size + 6); |
||
3748 | } |
||
3749 | else |
||
3750 | { |
||
3751 | if(strcmp(fly_font,"small") == 0){ |
||
3752 | fly_font_size = (int)(font_size - 4); |
||
3753 | if(fly_font_size<0){fly_font_size = 8;} |
||
3754 | } |
||
3755 | } |
||
3756 | } |
||
3757 | } |
||
3758 | break; |
||
3759 | case 4: |
||
9289 | schaersvoo | 3760 | decimals = find_number_of_digits(precision); |
11806 | schaersvoo | 3761 | temp = get_string_argument(infile,1); |
3762 | string_length = snprintf(NULL,0,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,90,\"%s\",%d,%.2f,%d,%s);\n",STATIC_CANVAS,int_data[0],int_data[1],fly_font_size,"null",font_color,stroke_opacity,temp,use_rotate,angle,use_affine,affine_matrix); |
||
9289 | schaersvoo | 3763 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
11806 | schaersvoo | 3764 | snprintf(tmp_buffer,string_length,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,90,\"%s\",%d,%.2f,%d,%s);\n",STATIC_CANVAS,int_data[0],int_data[1],fly_font_size,"null",font_color,stroke_opacity,temp,use_rotate,angle,use_affine,affine_matrix); |
9289 | schaersvoo | 3765 | add_to_buffer(tmp_buffer); |
3766 | break; |
||
11806 | schaersvoo | 3767 | default:break; |
3768 | } |
||
3769 | } |
||
3770 | reset(); |
||
3771 | break; |
||
3772 | |||
3773 | |||
3774 | case TRACE_JSCURVE: |
||
3775 | /* |
||
3776 | @ trace_jscurve some_math_function |
||
3777 | @ will use a crosshair to trace the jsmath curve |
||
3778 | @ two inputfields will display the current x/y-values (numerical evaluation by javascript) |
||
3779 | @ default labels 'x' and 'y'<br />use commands 'xlabel some_x_axis_name' and 'ylabel some_y_axis_name' to customize the labels for the input fields |
||
3780 | @ use commands fontsize and inputstyle to format the fonts for labels and inputfields. |
||
3781 | @ use commands linewidth,strokecolor,crosshairsize to adjust the corsshair. |
||
3782 | @ 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... |
||
3783 | @ be aware that the formula's of the plotted function(s) can be found in the page javascript source |
||
3784 | */ |
||
3785 | if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;} |
||
3786 | if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;} |
||
3787 | if( use_js_math == FALSE){ |
||
3788 | add_to_js_math(js_include_file); |
||
3789 | use_js_math = TRUE; |
||
3790 | } |
||
3791 | 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); |
||
3792 | break; |
||
3793 | |||
3794 | |||
3795 | case TRANGE: |
||
3796 | /* |
||
3797 | @ trange tmin,tmax |
||
3798 | @ alternative : ranget |
||
3799 | @ default -2,2 |
||
3800 | */ |
||
3801 | use_parametric = TRUE; |
||
3802 | for(i = 0 ; i<2; i++){ |
||
3803 | switch(i){ |
||
3804 | case 0: tmin = get_real(infile,0);break; |
||
3805 | case 1: tmax = get_real(infile,1);break; |
||
9289 | schaersvoo | 3806 | default: break; |
3807 | } |
||
3808 | } |
||
11806 | schaersvoo | 3809 | if(tmin >= tmax ){canvas_error(" trange is not OK : tmin < tmax!\n");} |
9289 | schaersvoo | 3810 | break; |
11806 | schaersvoo | 3811 | case TRANSLATION: |
3812 | /* |
||
3813 | @ translation tx,ty |
||
3814 | @ alternative : translate |
||
3815 | @ will translate the next objects tx in xrange and ty in yrange |
||
3816 | @ use command 'killtranstation' to end the command |
||
3817 | */ |
||
3818 | for(i = 0 ; i<2;i++){ |
||
3819 | switch(i){ |
||
3820 | case 0: double_data[0] = get_real(infile,0);break; |
||
3821 | case 1: double_data[1] = get_real(infile,1); |
||
3822 | use_affine = TRUE; |
||
3823 | decimals = find_number_of_digits(precision); |
||
3824 | string_length = snprintf(NULL,0, "[1,0,0,1,%.*f,%.*f] ",decimals,double_data[0]*xsize/(xmax - xmin),decimals,-1*double_data[1]*ysize/(ymax - ymin)); |
||
3825 | check_string_length(string_length);affine_matrix = my_newmem(string_length+1); |
||
3826 | 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)); |
||
3827 | break; |
||
3828 | default: break; |
||
3829 | } |
||
3830 | } |
||
3831 | break; |
||
3832 | |||
3833 | case TRIANGLE: |
||
3834 | /* |
||
3835 | @ triangle x1,y1,x2,y2,x3,y3,color |
||
3836 | @ use ftriangle or keyword <a href='#filled'>'filled'</a> for a solid triangle |
||
3837 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
||
3838 | */ |
||
3839 | for(i=0;i<7;i++){ |
||
3840 | switch(i){ |
||
3841 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
3842 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
3843 | case 2: double_data[2] = get_real(infile,0);break; /* x */ |
||
3844 | case 3: double_data[3] = get_real(infile,0);break; /* y */ |
||
3845 | case 4: double_data[4] = get_real(infile,0);break; /* x */ |
||
3846 | case 5: double_data[5] = get_real(infile,0);break; /* y */ |
||
3847 | case 6: stroke_color = get_color(infile,1);/* name or hex color */ |
||
3848 | decimals = find_number_of_digits(precision); |
||
3849 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,5,%s,[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d));\n",click_cnt,onclick,drag_type,double_xy2js_array(double_data,6,decimals),line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset); |
||
3850 | if(onclick > 0){click_cnt++;} |
||
3851 | /* click_cnt++;*/ |
||
3852 | reset(); |
||
3853 | break; |
||
3854 | default: break; |
||
3855 | } |
||
3856 | } |
||
3857 | break; |
||
3858 | case TRIANGLES: |
||
3859 | /* |
||
3860 | @ triangles color,x1,y1,x2,y2,x3,y3,... |
||
3861 | @ use ftriangles or keyword <a href='#filled'>'filled'</a> for solid triangles |
||
3862 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!) |
||
3863 | */ |
||
3864 | stroke_color = get_color(infile,0);/* name or hex color */ |
||
3865 | i = 0; |
||
3866 | decimals = find_number_of_digits(precision); |
||
3867 | while( ! done ){ |
||
3868 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
3869 | double_data[0] = get_real(infile,0); /* x1 */ |
||
3870 | double_data[1] = get_real(infile,0); /* y1 */ |
||
3871 | double_data[2] = get_real(infile,0); /* x2 */ |
||
3872 | double_data[3] = get_real(infile,0); /* y2 */ |
||
3873 | double_data[4] = get_real(infile,0); /* x3 */ |
||
3874 | double_data[5] = get_real(infile,1); /* y3 */ |
||
3875 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,5,%s,[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d));\n",click_cnt,onclick,drag_type,double_xy2js_array(double_data,6,decimals),line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset); |
||
3876 | if(onclick > 0){click_cnt++;} |
||
3877 | i = i + 6; |
||
3878 | } |
||
3879 | reset(); |
||
3880 | break; |
||
3881 | case USERBOXPLOT: |
||
3882 | /* |
||
3883 | @ userboxplot |
||
3884 | @ keyword, no arguments |
||
3885 | @ use before command <a href="#boxplot">'boxplot x_or_y,box-height_or_box-width,x_or_y-position'</a> |
||
3886 | @ if set, the student will have to calculate "min,Q1,median,Q3,max" and feed these data into the 'draw_boxplot' function |
||
3887 | @ for example:<br />put the canvas-script into a html element with id='boxplot'and set style='display:none'<br />define a variable called 'student_boxplot' and fill it with the 5 student-data (from inputfields or something)<br />var student_boxplot = new Array(5)<br />function show_boxplot(){<br />student_boxplot[0] = min;<br />student_boxplot[1] = Q1;<br />student_boxplot[2] = median;<br />student_boxplot[3] = Q3;<br />student_boxplot[4] = max;<br />document.getElementById('boxplot').style.display = "block";<br />draw_boxplot(12345,1,2.00,5.00,[0,0,0,0,0],4,"0,0,255",0.78,"255,165,0",0.60,1,0,1,1);<br />};<br />In the canvas-script the function draw_boxplot has the following arguments:<br />draw_boxplot=function(canvas_type,xy,hw,cxy,data,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype0,dashtype1) |
||
3888 | */ |
||
3889 | if( js_function[DRAW_BOXPLOT] != 1 ){ js_function[DRAW_BOXPLOT] = 1;} |
||
3890 | fprintf(js_include_file,"var boxplot_source = 3;\n"); |
||
3891 | js_function[DRAW_JSBOXPLOT] = 2; |
||
3892 | break; |
||
3893 | |||
3894 | case USERBOXPLOTDATA: |
||
3895 | /* |
||
3896 | @ userboxplotdata |
||
3897 | @ keyword, no arguments |
||
3898 | @ use before command <a href="#boxplot">'boxplot x_or_y,box-height_or_box-width,x_or_y-position'</a> |
||
3899 | @ if set, the student will have to generate some statistical data. These data should be put in a named array "student_boxplot_data" |
||
3900 | @ "min,Q1,median,Q3,max" are calculated by a js-function and the 'draw_boxplot' function will draw a boxplot. |
||
3901 | @ see command <a href="#userboxplot">'userboxplot'</a> for calling 'draw_boxplot()' |
||
3902 | */ |
||
3903 | if( js_function[DRAW_BOXPLOT] != 1 ){ js_function[DRAW_BOXPLOT] = 1;} |
||
3904 | fprintf(js_include_file,"var boxplot_source = 2;\n"); |
||
3905 | js_function[DRAW_JSBOXPLOT] = 1; |
||
3906 | |||
3907 | break; |
||
3908 | |||
7614 | schaersvoo | 3909 | case USERDRAW: |
3910 | /* |
||
3911 | @ userdraw object_type,color |
||
9213 | schaersvoo | 3912 | @ only a single object_type is allowed. |
9385 | schaersvoo | 3913 | @ for multiple object user drawings use command <a href="#multidraw">'multidraw'</a> |
11764 | schaersvoo | 3914 | @ implemented object_type: <ul><li>point</li><li>points</li><li>crosshair</li><li>crosshairs</li><li>line</li><li>lines</li><li>vline</li><li>vlines</li><li>hline</li><li>hlines</li><li>demiline</li><li>demilines</li><li>segment</li><li>segments</li><li>polyline | brokenline </li><li>circle</li><li>circles</li><li>arrow</li><li>arrow2 (double arrow)</li><li>arrows</li><li>arrows2 (double arrows)</li><li>triangle</li><li>polygon</li><li>poly[3-9] (e.g poly3 ... poly7...poly9 </li><li>rect</li><li>roundrect</li><li>rects</li><li>roundrects</li><li>freehandline | path</li><li>freehandlines | paths</li><li>clickfill : fill the clicked area with a color<br />the click may be set <a href="#snaptogrid">'snaptogrid'</a><br />may be used together with command <a href="#floodfill">'floodfill'</a><br />multiple areas may be selected <br /><b>always</b> use together with command <a href="clearbutton">'clearbutton some_text'</a> for removal of all click_colored areas<br />the function read_cancas() will return the click coordinates in the sequence of the user clicks<br />use command <a href="#canvastype">'canvastype'</a> to fill another canvas (default should be fine: DRAG_CANVAS = 5)<br />command <a href='#multifillcolors'>multifillcolors color1,color2...color_n</a> can also be used when more than one fillcolor is wanted.<br />in that case use for example <a href='#replyformat'>replyformat 10</a> ... reply=x1:y1:color1,x2:y2:color2...<br />the colors will restart at the first color, when there are more fill-clicks than multi-fill-colors</li><li>text</li><li>arc</li><li>arcs</li><li>input<br/>place a single inputfield on 'canvas'<br />use commands 'inputstyle' for css styling: use command 'linewidth' for adjusting the input field size (default 1)</li><li>inputs<br/>place multiple inputfield : placing inputfields on top of each other is not possible</li></ul> |
11088 | schaersvoo | 3915 | @ note: mouselisteners are only active if "$status != done " (eg only drawing in an active/non-finished exercise) <br /> to overrule use command/keyword "status" (no arguments required) |
3916 | @ note: object_type text: Any string or multiple strings may be placed anywhere on the canvas.<br />"backspace / delete / esc" will remove typed text if the mouse is clicked non the text.<br />You will need to hit "enter" to add the text to the array "userdraw_txt"<br />Placing the cursor somewhere on a typed text and hitting "delete/backspace/esc" , |
||
11080 | schaersvoo | 3917 | 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 | 3918 | @ note: object_type polygone: Will be finished (the object is closed) when clicked on the first point of the polygone again. |
3919 | @ note: all objects will be removed -after a javascript confirm box- when clicked on an object point with middle or right mouse button (e.g. event.which != 1 : all buttons but left) |
||
7614 | schaersvoo | 3920 | @ use command "filled", "opacity int,int" and "fillcolor color" to trigger coloured filling of fillable objects |
8224 | bpr | 3921 | @ use command "dashed" and/or "dashtype int,int" to trigger dashing |
7614 | schaersvoo | 3922 | @ use command "replyformat int" to control / adjust output formatting of javascript function read_canvas(); |
3923 | @ may be combined with onclick or drag xy of other components of flyscript objects (although not very usefull...) |
||
10953 | bpr | 3924 | @ may be combined with keyword 'userinput_xy' |
11088 | schaersvoo | 3925 | @ note: when zooming / panning after a drawing, the drawing will NOT be zoomed / panned...this is a "design" flaw and not a feature <br />To avoid trouble do not use zooming / panning together width userdraw.!<br />use command <a href="#multidraw">multidraw</a> is this is a problem for you... |
7614 | schaersvoo | 3926 | */ |
3927 | if( use_userdraw == TRUE ){ /* only one object type may be drawn*/ |
||
9213 | schaersvoo | 3928 | canvas_error("Only one userdraw primitive may be used in command 'userdraw' use command 'multidraw' for this..."); |
7614 | schaersvoo | 3929 | } |
8074 | schaersvoo | 3930 | reply_precision = precision; |
7614 | schaersvoo | 3931 | use_userdraw = TRUE; |
11041 | schaersvoo | 3932 | fprintf(js_include_file,"\n<!-- begin userdraw mouse events -->\nuserdraw_x = new Array();userdraw_y = new Array();\ |
3933 | userdraw_radius = new Array();var xy_cnt=0;var canvas_userdraw = create_canvas%d(%d,xsize,ysize);\ |
||
11001 | schaersvoo | 3934 | var context_userdraw = canvas_userdraw.getContext(\"2d\");var use_dashed = %d;\ |
3935 | if(use_dashed == 1){if( context_userdraw.setLineDash ){context_userdraw.setLineDash([%d,%d]);}else{if(context_userdraw.mozDash){context_userdraw.mozDash = [%d,%d];};};};\ |
||
3936 | if(wims_status != \"done\"){\ |
||
11006 | schaersvoo | 3937 | canvas_div.addEventListener(\"mousedown\" ,user_draw,false);\ |
3938 | canvas_div.addEventListener(\"mousemove\" ,user_drag,false);\ |
||
3939 | canvas_div.addEventListener(\"touchstart\",function(e){ e.preventDefault();user_draw(e.changedTouches[0]);},false);\ |
||
3940 | canvas_div.addEventListener(\"touchmove\" ,function(e){ e.preventDefault();user_drag(e.changedTouches[0]);},false);\ |
||
3941 | canvas_div.addEventListener(\"touchend\" ,function(e){ e.preventDefault();user_draw(e.changedTouches[0]);},false);\ |
||
11001 | schaersvoo | 3942 | }\n<!-- end userdraw mouse & touch events -->",canvas_root_id,DRAW_CANVAS,use_dashed,dashtype[0],dashtype[1],dashtype[0],dashtype[1]); |
7614 | schaersvoo | 3943 | draw_type = get_string_argument(infile,0); |
3944 | stroke_color = get_color(infile,1); |
||
3945 | if( strcmp(draw_type,"point") == 0 ){ |
||
3946 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
7876 | schaersvoo | 3947 | if(reply_format == 0 ){reply_format = 8;} |
7614 | schaersvoo | 3948 | /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */ |
8071 | schaersvoo | 3949 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
8224 | bpr | 3950 | if(use_input_xy == 1){ |
7652 | schaersvoo | 3951 | add_input_circle(js_include_file,1,1); |
8815 | schaersvoo | 3952 | add_input_xy(js_include_file,canvas_root_id,font_size,input_style); |
7652 | schaersvoo | 3953 | } |
7614 | schaersvoo | 3954 | 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); |
3955 | } |
||
3956 | else |
||
3957 | if( strcmp(draw_type,"points") == 0 ){ |
||
3958 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
7876 | schaersvoo | 3959 | if(reply_format == 0 ){reply_format = 8;} |
7614 | schaersvoo | 3960 | /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */ |
8071 | schaersvoo | 3961 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
8224 | bpr | 3962 | if(use_input_xy == 1){ |
7652 | schaersvoo | 3963 | add_input_circle(js_include_file,1,2); |
8815 | schaersvoo | 3964 | add_input_xy(js_include_file,canvas_root_id,font_size,input_style); |
7652 | schaersvoo | 3965 | } |
7614 | schaersvoo | 3966 | 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); |
3967 | } |
||
3968 | else |
||
3969 | if( strcmp(draw_type,"segment") == 0 ){ |
||
3970 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
3971 | if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;} |
||
7876 | schaersvoo | 3972 | if(reply_format == 0){reply_format = 11;} |
8071 | schaersvoo | 3973 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
8224 | bpr | 3974 | if(use_input_xy == 1){ |
7652 | schaersvoo | 3975 | add_input_segment(js_include_file,1); |
8815 | schaersvoo | 3976 | add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style); |
7652 | schaersvoo | 3977 | } |
7614 | schaersvoo | 3978 | add_js_segments(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]); |
3979 | } |
||
3980 | else |
||
10975 | schaersvoo | 3981 | if( strcmp(draw_type,"polyline") == 0 || strcmp(draw_type,"brokenline") == 0 ){ |
7663 | schaersvoo | 3982 | if( js_function[DRAW_POLYLINE] != 1 ){ js_function[DRAW_POLYLINE] = 1;} |
7876 | schaersvoo | 3983 | if(reply_format == 0){reply_format = 23;} |
8071 | schaersvoo | 3984 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7780 | schaersvoo | 3985 | if( use_input_xy == 1 ){ |
3986 | add_input_polyline(js_include_file); |
||
8815 | schaersvoo | 3987 | add_input_xy(js_include_file,canvas_root_id,font_size,input_style); |
7663 | schaersvoo | 3988 | } |
3989 | add_js_polyline(js_include_file,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]); |
||
3990 | } |
||
3991 | else |
||
7614 | schaersvoo | 3992 | if( strcmp(draw_type,"segments") == 0 ){ |
3993 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
3994 | if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;} |
||
7876 | schaersvoo | 3995 | if(reply_format == 0){reply_format = 11;} |
8071 | schaersvoo | 3996 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
8224 | bpr | 3997 | if(use_input_xy == 1){ |
7652 | schaersvoo | 3998 | add_input_segment(js_include_file,2); |
8815 | schaersvoo | 3999 | add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style); |
7652 | schaersvoo | 4000 | } |
7614 | schaersvoo | 4001 | add_js_segments(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]); |
4002 | } |
||
4003 | else |
||
4004 | if( strcmp(draw_type,"circle") == 0 ){ |
||
4005 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
7876 | schaersvoo | 4006 | if(reply_format == 0){reply_format = 10;} |
7614 | schaersvoo | 4007 | /* 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 | 4008 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
8224 | bpr | 4009 | if(use_input_xy == 1){ |
7652 | schaersvoo | 4010 | add_input_circle(js_include_file,2,1); |
8815 | schaersvoo | 4011 | add_input_xyr(js_include_file,canvas_root_id,font_size,input_style); |
7652 | schaersvoo | 4012 | } |
7614 | schaersvoo | 4013 | 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]); |
4014 | } |
||
4015 | else |
||
4016 | if( strcmp(draw_type,"circles") == 0 ){ |
||
4017 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
7876 | schaersvoo | 4018 | if(reply_format == 0){reply_format = 10;} |
7614 | schaersvoo | 4019 | /* 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n in x/y-range */ |
4020 | add_js_circles(js_include_file,2,draw_type,line_width,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]); |
||
8071 | schaersvoo | 4021 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
8224 | bpr | 4022 | if(use_input_xy == 1){ |
7652 | schaersvoo | 4023 | add_input_circle(js_include_file,2,2); |
8815 | schaersvoo | 4024 | add_input_xyr(js_include_file,canvas_root_id,font_size,input_style); |
7652 | schaersvoo | 4025 | } |
7614 | schaersvoo | 4026 | } |
4027 | else |
||
4028 | if(strcmp(draw_type,"crosshair") == 0 ){ |
||
4029 | if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;} |
||
7876 | schaersvoo | 4030 | if(reply_format == 0){reply_format = 8;} |
7614 | schaersvoo | 4031 | /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */ |
4032 | add_js_crosshairs(js_include_file,1,draw_type,line_width,crosshair_size ,stroke_color,stroke_opacity); |
||
8071 | schaersvoo | 4033 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
8224 | bpr | 4034 | if(use_input_xy == 1){ |
7654 | schaersvoo | 4035 | add_input_crosshair(js_include_file,1); |
8815 | schaersvoo | 4036 | add_input_xy(js_include_file,canvas_root_id,font_size,input_style); |
7654 | schaersvoo | 4037 | } |
7614 | schaersvoo | 4038 | } |
4039 | else |
||
4040 | if(strcmp(draw_type,"crosshairs") == 0 ){ |
||
4041 | if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;} |
||
7876 | schaersvoo | 4042 | if(reply_format == 0){reply_format = 8;} |
7614 | schaersvoo | 4043 | /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */ |
4044 | add_js_crosshairs(js_include_file,2,draw_type,line_width,crosshair_size ,stroke_color,stroke_opacity); |
||
8071 | schaersvoo | 4045 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
8224 | bpr | 4046 | if(use_input_xy == 1){ |
7654 | schaersvoo | 4047 | add_input_crosshair(js_include_file,2); |
8815 | schaersvoo | 4048 | add_input_xy(js_include_file,canvas_root_id,font_size,input_style); |
7654 | schaersvoo | 4049 | } |
7614 | schaersvoo | 4050 | } |
4051 | else |
||
4052 | if(strcmp(draw_type,"freehandline") == 0 ){ |
||
4053 | if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;} |
||
7876 | schaersvoo | 4054 | if(reply_format == 0){reply_format = 6;} |
8224 | bpr | 4055 | add_js_paths(js_include_file,1,draw_type,line_width,0,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]); |
7652 | schaersvoo | 4056 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 4057 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 4058 | } |
4059 | else |
||
4060 | if(strcmp(draw_type,"freehandlines") == 0 ){ |
||
4061 | if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;} |
||
7876 | schaersvoo | 4062 | if(reply_format == 0){reply_format = 6;} |
8224 | bpr | 4063 | add_js_paths(js_include_file,2,draw_type,line_width,0,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]); |
7652 | schaersvoo | 4064 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 4065 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 4066 | } |
4067 | else |
||
4068 | if(strcmp(draw_type,"path") == 0 ){ |
||
4069 | if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;} |
||
7876 | schaersvoo | 4070 | if(reply_format == 0){reply_format = 6;} |
8224 | bpr | 4071 | add_js_paths(js_include_file,1,draw_type,line_width,1,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]); |
7652 | schaersvoo | 4072 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 4073 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 4074 | } |
4075 | else |
||
4076 | if(strcmp(draw_type,"paths") == 0 ){ |
||
4077 | if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;} |
||
7876 | schaersvoo | 4078 | if(reply_format == 0){reply_format = 6;} |
8224 | bpr | 4079 | add_js_paths(js_include_file,2,draw_type,line_width,1,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]); |
7652 | schaersvoo | 4080 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 4081 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 4082 | } |
4083 | else |
||
4084 | if(strcmp(draw_type,"arrows") == 0 ){ |
||
4085 | if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;} |
||
7876 | schaersvoo | 4086 | if(reply_format == 0){reply_format = 11;} |
7874 | schaersvoo | 4087 | add_js_arrows(js_include_file,2,draw_type,line_width,1,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head); |
8224 | bpr | 4088 | if(use_input_xy == 1){ |
7654 | schaersvoo | 4089 | add_input_arrow(js_include_file,2); |
8815 | schaersvoo | 4090 | add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style); |
7654 | schaersvoo | 4091 | } |
8071 | schaersvoo | 4092 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 4093 | } |
4094 | else |
||
7874 | schaersvoo | 4095 | if(strcmp(draw_type,"arrows2") == 0 ){ |
4096 | if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;} |
||
7876 | schaersvoo | 4097 | if(reply_format == 0){reply_format = 11;} |
7874 | schaersvoo | 4098 | add_js_arrows(js_include_file,2,draw_type,line_width,2,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head); |
8224 | bpr | 4099 | if(use_input_xy == 1){ |
7874 | schaersvoo | 4100 | add_input_arrow(js_include_file,1); |
8815 | schaersvoo | 4101 | add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style); |
7874 | schaersvoo | 4102 | } |
8071 | schaersvoo | 4103 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7874 | schaersvoo | 4104 | } |
4105 | else |
||
4106 | if(strcmp(draw_type,"arrow2") == 0 ){ |
||
4107 | if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;} |
||
7876 | schaersvoo | 4108 | if(reply_format == 0){reply_format = 11;} |
7874 | schaersvoo | 4109 | add_js_arrows(js_include_file,1,draw_type,line_width,2,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head); |
8224 | bpr | 4110 | if(use_input_xy == 1){ |
7874 | schaersvoo | 4111 | add_input_arrow(js_include_file,1); |
8815 | schaersvoo | 4112 | add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style); |
7874 | schaersvoo | 4113 | } |
8071 | schaersvoo | 4114 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7874 | schaersvoo | 4115 | } |
4116 | else |
||
7614 | schaersvoo | 4117 | if(strcmp(draw_type,"arrow") == 0 ){ |
4118 | if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;} |
||
7876 | schaersvoo | 4119 | if(reply_format == 0){reply_format = 11;} |
7874 | schaersvoo | 4120 | add_js_arrows(js_include_file,1,draw_type,line_width,1,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head); |
8224 | bpr | 4121 | if(use_input_xy == 1){ |
7654 | schaersvoo | 4122 | add_input_arrow(js_include_file,1); |
8815 | schaersvoo | 4123 | add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style); |
7654 | schaersvoo | 4124 | } |
8071 | schaersvoo | 4125 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 4126 | } |
4127 | else |
||
4128 | if(strcmp(draw_type,"polygon") == 0){ |
||
4129 | if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;} |
||
7876 | schaersvoo | 4130 | if(reply_format == 0){reply_format = 2;} |
7614 | schaersvoo | 4131 | add_js_poly(js_include_file,-1,draw_type,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]); |
8071 | schaersvoo | 4132 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
4133 | if(use_input_xy == 2){ |
||
7780 | schaersvoo | 4134 | add_textarea_polygon(js_include_file); |
8815 | schaersvoo | 4135 | add_textarea_xy(js_include_file,canvas_root_id,input_style); |
7746 | schaersvoo | 4136 | } |
7614 | schaersvoo | 4137 | } |
8224 | bpr | 4138 | else |
7614 | schaersvoo | 4139 | if(strncmp(draw_type,"poly",4) == 0){ |
4140 | if(strlen(draw_type) < 5){canvas_error("use command \"userdraw poly[3-9],color\" eg userdraw poly6,blue");} |
||
4141 | if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;} |
||
7876 | schaersvoo | 4142 | if(reply_format == 0){reply_format = 2;} |
7614 | schaersvoo | 4143 | add_js_poly(js_include_file,(int) (draw_type[4]-'0'),draw_type,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]); |
7652 | schaersvoo | 4144 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 4145 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 4146 | } |
8224 | bpr | 4147 | else |
7614 | schaersvoo | 4148 | if(strcmp(draw_type,"triangle") == 0){ |
4149 | if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;} |
||
7876 | schaersvoo | 4150 | if(reply_format == 0){reply_format = 2;} |
7614 | schaersvoo | 4151 | add_js_poly(js_include_file,3,draw_type,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]); |
7652 | schaersvoo | 4152 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 4153 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 4154 | } |
8224 | bpr | 4155 | else |
7989 | schaersvoo | 4156 | if( strcmp(draw_type,"hline") == 0 ){ |
4157 | if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;} |
||
4158 | if(reply_format == 0){reply_format = 11;} |
||
4159 | add_js_hlines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]); |
||
8071 | schaersvoo | 4160 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
4161 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
||
7989 | schaersvoo | 4162 | } |
4163 | else |
||
4164 | if( strcmp(draw_type,"hlines") == 0 ){ |
||
4165 | if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;} |
||
4166 | if(reply_format == 0){reply_format = 11;} |
||
4167 | add_js_hlines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]); |
||
8071 | schaersvoo | 4168 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
4169 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
||
7989 | schaersvoo | 4170 | } |
4171 | else |
||
4172 | if( strcmp(draw_type,"vline") == 0 ){ |
||
4173 | if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;} |
||
4174 | if(reply_format == 0){reply_format = 11;} |
||
4175 | add_js_hlines(js_include_file,3,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]); |
||
8071 | schaersvoo | 4176 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
4177 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
||
7989 | schaersvoo | 4178 | } |
4179 | else |
||
4180 | if( strcmp(draw_type,"vlines") == 0 ){ |
||
4181 | if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;} |
||
4182 | if(reply_format == 0){reply_format = 11;} |
||
4183 | add_js_hlines(js_include_file,4,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]); |
||
8071 | schaersvoo | 4184 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
4185 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
||
7989 | schaersvoo | 4186 | } |
4187 | else |
||
7614 | schaersvoo | 4188 | if( strcmp(draw_type,"line") == 0 ){ |
4189 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
4190 | if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;} |
||
7876 | schaersvoo | 4191 | if(reply_format == 0){reply_format = 11;} |
7614 | schaersvoo | 4192 | add_js_lines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]); |
7747 | schaersvoo | 4193 | if( use_input_xy == 1 ){ |
7780 | schaersvoo | 4194 | add_input_line(js_include_file,1); |
8815 | schaersvoo | 4195 | add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style); |
7747 | schaersvoo | 4196 | } |
8071 | schaersvoo | 4197 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 4198 | } |
4199 | else |
||
4200 | if( strcmp(draw_type,"lines") == 0 ){ |
||
4201 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
4202 | if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;} |
||
7876 | schaersvoo | 4203 | if(reply_format == 0){reply_format = 11;} |
7614 | schaersvoo | 4204 | add_js_lines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]); |
7747 | schaersvoo | 4205 | if( use_input_xy == 1 ){ |
7780 | schaersvoo | 4206 | add_input_line(js_include_file,2); |
8815 | schaersvoo | 4207 | add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style); |
7746 | schaersvoo | 4208 | } |
8071 | schaersvoo | 4209 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 4210 | } |
4211 | else |
||
8362 | schaersvoo | 4212 | if( strcmp(draw_type,"demilines") == 0 || strcmp(draw_type,"halflines") == 0 ){ |
8244 | schaersvoo | 4213 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
4214 | if( js_function[DRAW_DEMILINES] != 1 ){ js_function[DRAW_DEMILINES] = 1;} |
||
4215 | if(reply_format == 0){reply_format = 11;} |
||
4216 | add_js_demilines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]); |
||
4217 | if( use_input_xy == 1 ){ |
||
4218 | add_input_demiline(js_include_file,2); |
||
8815 | schaersvoo | 4219 | add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style); |
8244 | schaersvoo | 4220 | } |
4221 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
||
4222 | } |
||
4223 | else |
||
8362 | schaersvoo | 4224 | if( strcmp(draw_type,"demiline") == 0 || strcmp(draw_type,"halfline") == 0 ){ |
8244 | schaersvoo | 4225 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
4226 | if( js_function[DRAW_DEMILINES] != 1 ){ js_function[DRAW_DEMILINES] = 1;} |
||
4227 | if(reply_format == 0){reply_format = 11;} |
||
4228 | add_js_demilines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]); |
||
4229 | if( use_input_xy == 1 ){ |
||
4230 | add_input_demiline(js_include_file,1); |
||
8815 | schaersvoo | 4231 | add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style); |
8244 | schaersvoo | 4232 | } |
4233 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
||
4234 | } |
||
4235 | else |
||
7614 | schaersvoo | 4236 | if( strcmp(draw_type,"rects") == 0){ |
4237 | if( js_function[DRAW_RECTS] != 1 ){ js_function[DRAW_RECTS] = 1;} |
||
7876 | schaersvoo | 4238 | if(reply_format == 0){reply_format = 2;} |
7614 | schaersvoo | 4239 | add_js_rect(js_include_file,2,0,draw_type,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]); |
7652 | schaersvoo | 4240 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 4241 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 4242 | } |
8224 | bpr | 4243 | else |
7614 | schaersvoo | 4244 | if( strcmp(draw_type,"roundrects") == 0){ |
4245 | if( js_function[DRAW_ROUNDRECTS] != 1 ){ js_function[DRAW_ROUNDRECTS] = 1;} |
||
7876 | schaersvoo | 4246 | if(reply_format == 0){reply_format = 2;} |
7614 | schaersvoo | 4247 | add_js_rect(js_include_file,2,1,draw_type,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]); |
7652 | schaersvoo | 4248 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 4249 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 4250 | } |
8224 | bpr | 4251 | else |
7614 | schaersvoo | 4252 | if( strcmp(draw_type,"rect") == 0){ |
4253 | if( js_function[DRAW_RECTS] != 1 ){ js_function[DRAW_RECTS] = 1;} |
||
7876 | schaersvoo | 4254 | if(reply_format == 0){reply_format = 2;} |
7614 | schaersvoo | 4255 | add_js_rect(js_include_file,1,0,draw_type,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]); |
7652 | schaersvoo | 4256 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 4257 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 4258 | } |
8224 | bpr | 4259 | else |
7614 | schaersvoo | 4260 | if( strcmp(draw_type,"roundrect") == 0){ |
4261 | if( js_function[DRAW_ROUNDRECTS] != 1 ){ js_function[DRAW_ROUNDRECTS] = 1;} |
||
7876 | schaersvoo | 4262 | if(reply_format == 0){reply_format = 2;} |
7614 | schaersvoo | 4263 | add_js_rect(js_include_file,1,1,draw_type,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]); |
7652 | schaersvoo | 4264 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 4265 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 4266 | } |
4267 | else |
||
8083 | schaersvoo | 4268 | if( strcmp(draw_type,"arcs") == 0){ |
4269 | if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;} |
||
4270 | if(reply_format == 0){reply_format = 25;} |
||
4271 | 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]); |
||
4272 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
||
4273 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
||
4274 | } |
||
4275 | else |
||
8071 | schaersvoo | 4276 | if( strcmp(draw_type,"arc") == 0){ |
4277 | if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;} |
||
11017 | schaersvoo | 4278 | if( js_function[JS_FIND_ANGLE] != 1 ){ js_function[JS_FIND_ANGLE] = 1;} |
8083 | schaersvoo | 4279 | if(reply_format == 0){reply_format = 25;} |
4280 | add_js_arc(js_include_file,canvas_root_id,1,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]); |
||
8071 | schaersvoo | 4281 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
4282 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
||
4283 | } |
||
4284 | else |
||
7614 | schaersvoo | 4285 | if( strcmp(draw_type,"text") == 0){ |
7876 | schaersvoo | 4286 | if(reply_format == 0){reply_format = 17;} |
11084 | schaersvoo | 4287 | add_js_text(js_include_file,canvas_root_id,font_size,font_family,stroke_color,stroke_opacity); |
7652 | schaersvoo | 4288 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 4289 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 4290 | } |
8116 | schaersvoo | 4291 | else |
4292 | if( strcmp(draw_type,"inputs") == 0){ |
||
8224 | bpr | 4293 | if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;} |
8127 | schaersvoo | 4294 | if(reply_format == 0){reply_format = 27;} |
11803 | schaersvoo | 4295 | add_js_inputs(js_include_file,canvas_root_id,2,input_cnt,input_style,line_width,use_offset); |
8116 | schaersvoo | 4296 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
4297 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
||
4298 | } |
||
4299 | else |
||
4300 | if( strcmp(draw_type,"input") == 0){ |
||
8224 | bpr | 4301 | if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;} |
8127 | schaersvoo | 4302 | if(reply_format == 0){reply_format = 27;} |
11803 | schaersvoo | 4303 | add_js_inputs(js_include_file,canvas_root_id,1,input_cnt,input_style,line_width,use_offset); |
8116 | schaersvoo | 4304 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
4305 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
||
4306 | } |
||
8193 | schaersvoo | 4307 | else |
11005 | schaersvoo | 4308 | if( strcmp(draw_type,"clickfill") == 0){ |
4309 | decimals = find_number_of_digits(precision); |
||
4310 | if(reply_format == 0){reply_format = 22;} |
||
4311 | add_js_clickfill(js_include_file,canvas_root_id,stroke_color,(int) (fill_opacity/0.0039215)); |
||
4312 | if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */ |
||
4313 | js_function[DRAW_FILLTOBORDER] = 1; |
||
11006 | schaersvoo | 4314 | add_js_filltoborder(js_include_file,canvas_root_id,canvas_type); |
11005 | schaersvoo | 4315 | } |
4316 | } |
||
4317 | else |
||
7614 | schaersvoo | 4318 | { |
4319 | canvas_error("unknown drawtype or typo? "); |
||
4320 | } |
||
4321 | reset(); |
||
4322 | break; |
||
8386 | schaersvoo | 4323 | |
4324 | case USERINPUT: |
||
4325 | /* |
||
4326 | @ userinput function | textarea | inputfield |
||
9382 | schaersvoo | 4327 | @ alternative : userinput_function |
4328 | @ alternative : userinput_textarea |
||
4329 | @ alternative : userinput_xy |
||
8386 | schaersvoo | 4330 | @ textarea and inputfield are only usable in combination with some 'userdraw draw_ type' |
4331 | @ function may be used any time (e.g. without userdraw) |
||
8815 | schaersvoo | 4332 | @ multiple 'userinput function' commands may be used. |
8386 | schaersvoo | 4333 | @ use command "functionlabel some_string" to define the inputfield text : default value "f(x)=" |
4334 | @ use command 'strokecolor some_color' to adjust the plot / functionlabel color |
||
8815 | schaersvoo | 4335 | @ use command 'inputstyle some_css' to adjust the inputfields |
4336 | @ use command 'fontsize int' to adjust the label fonts. (default 12px) |
||
4337 | @ the user input for the function will be corrected by a simple 'rawmath' implementation...<br />an error message will be shown if javascript can not interpret the user input |
||
8386 | schaersvoo | 4338 | */ |
4339 | temp = get_string_argument(infile,1); |
||
4340 | if(strstr(temp,"function") != 0 || strstr(temp,"curve") != 0 || strstr(temp,"plot") != 0 ){ |
||
4341 | if( js_function[DRAW_JSFUNCTION] != 1 ){ |
||
4342 | add_rawmath(js_include_file);/* add simple rawmath routine to correct user input of function */ |
||
4343 | js_function[DRAW_JSFUNCTION] = 1; |
||
4344 | if(reply_format == 0){reply_format = 24;}/* read canvas_input values */ |
||
8815 | schaersvoo | 4345 | 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 | 4346 | input_cnt++; |
4347 | } |
||
10953 | bpr | 4348 | else |
8386 | schaersvoo | 4349 | { |
4350 | /* no need to add DRAW_JSFUNCTION , just call it with the parameters */ |
||
8815 | schaersvoo | 4351 | 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 | 4352 | input_cnt++; |
4353 | } |
||
4354 | if( use_js_math == FALSE){/* add this stuff only once...*/ |
||
4355 | add_to_js_math(js_include_file); |
||
4356 | use_js_math = TRUE; |
||
4357 | } |
||
4358 | if( use_js_plot == FALSE){ |
||
4359 | use_js_plot = TRUE; |
||
4360 | add_jsplot(js_include_file,canvas_root_id); /* this plots the function on JSPLOT_CANVAS */ |
||
4361 | } |
||
4362 | } |
||
4363 | else |
||
4364 | { |
||
4365 | if(strstr(temp,"inputfield") != 0 ){ |
||
4366 | if( use_input_xy != 0 ){canvas_error("userinput_xy can not be combined with usertextarea_xy command");} |
||
4367 | if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */ |
||
4368 | use_input_xy = 1; |
||
4369 | } |
||
4370 | else |
||
4371 | { |
||
4372 | if(strstr(temp,"textarea") != 0 ){ |
||
4373 | if( use_input_xy != 0 ){canvas_error("usertextarea_xy can not be combined with userinput_xy command");} |
||
4374 | if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */ |
||
4375 | use_input_xy = 2; |
||
4376 | } |
||
4377 | else |
||
4378 | { |
||
4379 | canvas_error("userinput argument may be \"function,inputfield,textarea\""); |
||
4380 | } |
||
4381 | } |
||
4382 | } |
||
4383 | break; |
||
4384 | case USERINPUT_XY: |
||
4385 | /* |
||
4386 | @ userinput_xy |
||
9372 | schaersvoo | 4387 | @ keyword (no arguments required) |
8386 | schaersvoo | 4388 | @ to be used in combination with command "userdraw object_type,color" |
4389 | @ 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) |
||
4390 | @ the student may use this as correction for (x:y) on a drawing (or to draw without mouse, using just the coordinates) |
||
4391 | @ math input is allowed (e.g something like: 1+3,2*6,1/3,sqrt(3), sin(pi/4),10^-2,log(2)...)<br />eval function is 'protected' against code injection. |
||
11088 | schaersvoo | 4392 | @ can <b>not</b> be combined with command "intooltip tiptext" <br />note: the 'tooltip div element' is used for placing inputfields |
8386 | schaersvoo | 4393 | @ user drawings will not zoom on zooming (or pan on panning) |
8815 | schaersvoo | 4394 | @ use command 'inputstyle some_css' to adjust the inputarea. |
4395 | @ use command 'fontsize int' to adjust the text labels (if needed) |
||
8386 | schaersvoo | 4396 | */ |
4397 | /* add simple eval check to avoid code injection with unprotected eval(string) */ |
||
4398 | if( use_input_xy != 0 ){canvas_error("userinput_xy can not be combined with usertextarea_xy command");} |
||
4399 | if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */ |
||
4400 | use_input_xy = 1; |
||
4401 | break; |
||
4402 | |||
4403 | case USERINPUT_FUNCTION: |
||
4404 | /* |
||
4405 | @ userinput_function |
||
9372 | schaersvoo | 4406 | @ keyword (no arguments required) |
8386 | schaersvoo | 4407 | @ if set , a inputfield will be added to the page |
4408 | @ repeat keyword for more function input fields |
||
4409 | @ the userinput value will be plotted in the canvas |
||
10953 | bpr | 4410 | @ this value may be read with 'read_canvas()'. <br />for do it yourself js-scripters : If this is the first inputfield in the script, its id is canvas_input0 |
8386 | schaersvoo | 4411 | @ use before this command 'userinput_function',<br />commands like 'inputstyle some_css' , 'xlabel some_description' , 'opacity int,int' , 'linewidth int' , 'dashed' and 'dashtype int,int' to modify |
8815 | schaersvoo | 4412 | @ fontsize can be set using command 'fontsize int' |
8386 | schaersvoo | 4413 | @ incompatible with command 'intooltip link_text_or_image' : it uses the tooltip div for adding the inputfield |
4414 | */ |
||
4415 | if( js_function[DRAW_JSFUNCTION] != 1 ){ |
||
4416 | js_function[DRAW_JSFUNCTION] = 1; |
||
4417 | add_rawmath(js_include_file); |
||
4418 | if(reply_format == 0){reply_format = 24;}/* read canvas_input values */ |
||
8815 | schaersvoo | 4419 | 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 | 4420 | input_cnt++; |
4421 | } |
||
10953 | bpr | 4422 | else |
8386 | schaersvoo | 4423 | { |
4424 | /* no need to add DRAW_JSFUNCTION , just call it with the parameters */ |
||
8815 | schaersvoo | 4425 | 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 | 4426 | input_cnt++; |
4427 | } |
||
4428 | if( use_js_math == FALSE){/* add this stuff only once...*/ |
||
4429 | add_to_js_math(js_include_file); |
||
4430 | use_js_math = TRUE; |
||
4431 | } |
||
4432 | if( use_js_plot == FALSE){ |
||
4433 | use_js_plot = TRUE; |
||
4434 | add_jsplot(js_include_file,canvas_root_id); /* this plots the function on JSPLOT_CANVAS */ |
||
4435 | } |
||
4436 | break; |
||
4437 | |||
4438 | |||
4439 | |||
11806 | schaersvoo | 4440 | case USERTEXTAREA_XY: |
7788 | schaersvoo | 4441 | /* |
11806 | schaersvoo | 4442 | @ usertextarea_xy |
4443 | @ keyword (no arguments required) |
||
4444 | @ to be used in combination with command "userdraw object_type,color" wherein object_type is only segment / polyline for the time being... |
||
4445 | @ if set two textareas are added to the document<br />(one for x-values , one for y-values) |
||
4446 | @ the student may use this as correction for (x:y) on a drawing (or to draw without mouse, using just the coordinates) |
||
4447 | @ user drawings will not zoom on zooming (or pan on panning) |
||
4448 | @ use command 'inputstyle some_css' to adjust the inputarea. |
||
4449 | @ use command 'fontsize int' to adjust the text labels (if needed) |
||
7788 | schaersvoo | 4450 | */ |
11806 | schaersvoo | 4451 | if( use_input_xy != 0 ){canvas_error("usertextarea_xy can not be combined with userinput_xy command");} |
4452 | if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */ |
||
4453 | use_input_xy = 2; |
||
7788 | schaersvoo | 4454 | break; |
8386 | schaersvoo | 4455 | |
11806 | schaersvoo | 4456 | case VLINE: |
8386 | schaersvoo | 4457 | /* |
11806 | schaersvoo | 4458 | @ vline x,y,color |
4459 | @ alternative : verticalline |
||
4460 | @ draw a vertical line through point (x:y) in color 'color' |
||
4461 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
||
8386 | schaersvoo | 4462 | */ |
11806 | schaersvoo | 4463 | for(i=0;i<3;i++) { |
7614 | schaersvoo | 4464 | switch(i){ |
11806 | schaersvoo | 4465 | case 0: double_data[0] = get_real(infile,0);break; /* x-values */ |
4466 | case 1: double_data[1] = get_real(infile,0);break; /* y-values */ |
||
4467 | case 2: stroke_color=get_color(infile,1);/* name or hex color */ |
||
4468 | double_data[2] = double_data[0]; |
||
7614 | schaersvoo | 4469 | decimals = find_number_of_digits(precision); |
11806 | schaersvoo | 4470 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,100*ymin,decimals,100*ymax,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset); |
4471 | if(onclick > 0){click_cnt++;} |
||
4472 | /* click_cnt++; */ |
||
8379 | schaersvoo | 4473 | reset(); |
7614 | schaersvoo | 4474 | break; |
4475 | } |
||
4476 | } |
||
4477 | break; |
||
4478 | |||
11806 | schaersvoo | 4479 | case VLINES: |
11802 | schaersvoo | 4480 | /* |
11806 | schaersvoo | 4481 | @ vlines color,x1,y1,x2,y2.... |
4482 | @ alternative : verticallines |
||
4483 | @ draw vertical lines through points (x1:y1),(x2:y2)... in color 'color' |
||
4484 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually |
||
11802 | schaersvoo | 4485 | */ |
11806 | schaersvoo | 4486 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
4487 | fill_color = stroke_color; |
||
4488 | i=0; |
||
4489 | while( ! done ){ /* get next item until EOL*/ |
||
4490 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
4491 | if(i%2 == 0 ){ |
||
4492 | double_data[i] = get_real(infile,0); /* x */ |
||
7614 | schaersvoo | 4493 | } |
11806 | schaersvoo | 4494 | else |
4495 | { |
||
4496 | double_data[i] = get_real(infile,1); /* y */ |
||
7983 | schaersvoo | 4497 | } |
11806 | schaersvoo | 4498 | i++; |
7983 | schaersvoo | 4499 | } |
11806 | schaersvoo | 4500 | decimals = find_number_of_digits(precision); |
4501 | for(c = 0 ; c < i-1 ; c = c+2){ |
||
4502 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c],decimals,ymin,decimals,ymax,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset); |
||
4503 | if(onclick > 0){click_cnt++;} |
||
4504 | /* click_cnt++; */ |
||
4505 | } |
||
4506 | reset(); |
||
7983 | schaersvoo | 4507 | break; |
11806 | schaersvoo | 4508 | |
4509 | |||
4510 | case VIDEO: |
||
7614 | schaersvoo | 4511 | /* |
11806 | schaersvoo | 4512 | @ video x,y,w,h,videofile location |
4513 | @ x,y : left top corner of audio element (in xrange / yrange) |
||
4514 | @ w,y : width and height in pixels |
||
4515 | @ example:<br />wims getfile : video 0,0,120,120,myvideo.mp4 |
||
4516 | @ video format may be in *.mp4 (todo:other formats) |
||
7614 | schaersvoo | 4517 | */ |
11806 | schaersvoo | 4518 | if( js_function[DRAW_VIDEO] != 1 ){ js_function[DRAW_VIDEO] = 1;} |
7614 | schaersvoo | 4519 | for(i=0;i<5;i++){ |
4520 | switch(i){ |
||
11806 | schaersvoo | 4521 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */ |
4522 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system -> pixel */ |
||
4523 | case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */ |
||
4524 | case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */ |
||
4525 | case 4: temp = get_string(infile,1); |
||
4526 | string_length = snprintf(NULL,0, "draw_video(%d,%d,%d,%d,%d,\"%s\");\n",canvas_root_id,int_data[0],int_data[1],int_data[2],int_data[3],temp); |
||
7614 | schaersvoo | 4527 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
11806 | schaersvoo | 4528 | 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 | 4529 | add_to_buffer(tmp_buffer); |
4530 | break; |
||
4531 | default:break; |
||
4532 | } |
||
4533 | } |
||
4534 | reset(); |
||
4535 | break; |
||
11806 | schaersvoo | 4536 | |
7614 | schaersvoo | 4537 | case X_AXIS_STRINGS: |
4538 | /* |
||
4539 | @ xaxis num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n |
||
9385 | schaersvoo | 4540 | @ alternative : xaxistext num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n |
9346 | schaersvoo | 4541 | @ use these x-axis num1...num_n values instead of default xmin...xmax |
11044 | schaersvoo | 4542 | @ no need to use keyword <a href="#axisnumbering">axisnumbering</a> |
4543 | @ use command <a href="#axis">axis</a> to have visual x/y-axis lines (see command <a href="grid">grid</a> |
||
11088 | schaersvoo | 4544 | @ 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 | 4545 | @ a javascript error message will flag non-matching value:name pairs |
9341 | schaersvoo | 4546 | @ if the 'x-axis words' are too big and will overlap, a simple alternating offset will be applied |
11044 | schaersvoo | 4547 | @ to be used before command grid (see <a href="#grid">command grid</a>) |
7614 | schaersvoo | 4548 | @ example:<br />size 400,400<br />xrange 0,13<br />yrange -100,500<br />axis<br />xaxis 1:january:2:february:3:march:5:may:6:june:7:july:8:august:9:september:10:october:11:november:12:december<br />#'xmajor' steps should be synchronised with numbers eg. "1" in this example<br />grid 1,100,grey,1,4,6,grey |
4549 | */ |
||
4550 | temp = get_string(infile,1); |
||
4551 | if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");} |
||
4552 | if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/ |
||
4553 | fprintf(js_include_file,"x_strings = [\"%s\"];\n ",temp); |
||
4554 | use_axis_numbering = 1; |
||
4555 | break; |
||
9341 | schaersvoo | 4556 | case X_AXIS_STRINGS_UP: |
4557 | /* |
||
4558 | @ xaxisup num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n |
||
9385 | schaersvoo | 4559 | @ alternative : xaxistextup num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n |
9341 | schaersvoo | 4560 | @ the text will be rotated 90° up |
11044 | schaersvoo | 4561 | @ no need to use keyword <a href="#axisnumbering">axisnumbering</a> |
4562 | @ use command <a href="#axis">axis</a> to have visual x/y-axis lines (see command <a href="grid">grid</a> |
||
9346 | schaersvoo | 4563 | @ use these x-axis num1...num_n values instead of default xmin...xmax |
11088 | schaersvoo | 4564 | @ 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 | 4565 | @ a javascript error message will flag non-matching value:name pairs |
9341 | schaersvoo | 4566 | @ 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 | 4567 | @ to be used before command grid (see <a href="#grid">command grid</a>) |
9341 | schaersvoo | 4568 | @ example:<br />size 400,400<br />xrange 0,13<br />yrange -100,500<br />axis<br />xaxisup 1:january:2:february:3:march:5:may:6:june:7:july:8:august:9:september:10:october:11:november:12:december<br />#'xmajor' steps should be synchronised with numbers eg. "1" in this example<br />grid 1,100,grey,1,4,6,grey |
4569 | */ |
||
4570 | temp = get_string(infile,1); |
||
4571 | if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");} |
||
4572 | if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/ |
||
4573 | fprintf(js_include_file,"x_strings_up = 1;x_strings = [\"%s\"];\n ",temp); |
||
4574 | use_axis_numbering = 1; |
||
4575 | break; |
||
8224 | bpr | 4576 | |
11806 | schaersvoo | 4577 | case XERRORBARS: |
7614 | schaersvoo | 4578 | /* |
11806 | schaersvoo | 4579 | @ xerrorbars color,E1,E2,x1,y1,x2,y2,...,x_n,y_n |
4580 | @ 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' |
||
4581 | @ the errors E1 and E2 values are in xrange. |
||
4582 | @ use command 'linewidth int' to adust size |
||
4583 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!) |
||
7614 | schaersvoo | 4584 | */ |
11806 | schaersvoo | 4585 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
4586 | fill_color = stroke_color; |
||
4587 | i=0; |
||
4588 | while( ! done ){ /* get next item until EOL*/ |
||
4589 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
4590 | if(i%2 == 0 ){ |
||
4591 | double_data[i] = get_real(infile,0); /* x */ |
||
8071 | schaersvoo | 4592 | } |
11806 | schaersvoo | 4593 | else |
4594 | { |
||
4595 | double_data[i] = get_real(infile,1); /* y */ |
||
7614 | schaersvoo | 4596 | } |
11806 | schaersvoo | 4597 | i++; |
7614 | schaersvoo | 4598 | } |
11806 | schaersvoo | 4599 | decimals = find_number_of_digits(precision); |
4600 | for(c = 2 ; c < i-1 ; c = c+2){ |
||
4601 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,20,[%.*f],[%.*f],[%.2f],[%.2f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+1],double_data[0],double_data[1],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,1,0,0,0,use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset); |
||
4602 | /* click_cnt++; */ |
||
4603 | if(onclick > 0){click_cnt++;} |
||
4604 | } |
||
7614 | schaersvoo | 4605 | reset(); |
4606 | break; |
||
11806 | schaersvoo | 4607 | |
4608 | case XRANGE: |
||
7614 | schaersvoo | 4609 | /* |
11806 | schaersvoo | 4610 | @ xrange xmin,xmax |
4611 | @ alternative : rangex |
||
4612 | @ if not given: 0,xsize (eg in pixels) |
||
7614 | schaersvoo | 4613 | */ |
11806 | schaersvoo | 4614 | for(i = 0 ; i<2; i++){ |
7614 | schaersvoo | 4615 | switch(i){ |
11806 | schaersvoo | 4616 | case 0: xmin = get_real(infile,0);break; |
4617 | case 1: xmax = get_real(infile,1);break; |
||
7614 | schaersvoo | 4618 | default: break; |
4619 | } |
||
4620 | } |
||
11806 | schaersvoo | 4621 | if(xmin >= xmax){canvas_error(" xrange is not OK : xmin < xmax !\n");} |
4622 | fprintf(js_include_file,"var xmin = %f;var xmax = %f;\n",xmin,xmax); |
||
4623 | found_size_command++; |
||
7614 | schaersvoo | 4624 | break; |
8386 | schaersvoo | 4625 | |
4626 | |||
4627 | |||
11806 | schaersvoo | 4628 | case XSNAPTOGRID: |
7614 | schaersvoo | 4629 | /* |
11806 | schaersvoo | 4630 | @ xsnaptogrid |
4631 | @ keyword (no arguments required) |
||
4632 | @ a draggable object (use command "drag x|y|xy") will snap to the given x-grid values when dragged (mouseup) |
||
4633 | @ in case of userdraw the drawn points will snap to xmajor grid |
||
4634 | @ if no grid is defined ,points will snap to every integer xrange value. (eg snap_x=1) |
||
4635 | @ if you do not want a visible grid, but you only want a 'snaptogrid' with some value...define this grid with opacity 0. |
||
4636 | @ if xminor is defined (use keyword 'axis' to activate xminor), the drawing will snap to xminor <br />use only even dividers in x-minor...for example<br />xsnaptogrid<br />axis<br />grid 2,1,grey,4,4,7,red<br /> will snap on x=0, x=0.5, x=1, x=1.5 ....<br /> will snap on y=0, y=0.25 y=0.5 y=0.75 ...<br /> |
||
7614 | schaersvoo | 4637 | */ |
11806 | schaersvoo | 4638 | fprintf(js_include_file,"\nx_use_snap_to_grid = 1;y_use_snap_to_grid = 0;"); |
4639 | break; |
||
8386 | schaersvoo | 4640 | |
11806 | schaersvoo | 4641 | case XOFFSET: |
7614 | schaersvoo | 4642 | /* |
11806 | schaersvoo | 4643 | @ xoffset | centered |
4644 | @ keyword ; to place the text centered above the text coordinates(x:y) ... |
||
4645 | @ may be used for points or other things requirering centered labels |
||
4646 | @ 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 | 4647 | */ |
11806 | schaersvoo | 4648 | use_offset = 1; |
4649 | break; |
||
8386 | schaersvoo | 4650 | |
11806 | schaersvoo | 4651 | case XYOFFSET: |
7614 | schaersvoo | 4652 | /* |
11806 | schaersvoo | 4653 | @ xyoffset |
4654 | @ keyword ; to place the text (x:y) to (x+dx:y+dy)... dx/dy are dependent on fontsize/fontfamily |
||
4655 | @ may be used for points or other things requirering labels |
||
4656 | @ only active for commands <a href="#text">text</a> and <a href="#string">string</a> (e.g. objects in the drag/drop/onclick-librariy |
||
4657 | @ in case of inputfields the inputfield will be centered x and y on it's coordinates.<br />for example:<br />inputs 1,1,10,? <br />point 1,1,red <br /> the point will be completely invisible<br />note: keyword 'xyoffset' will also provide centering if used with <a href='#@userdraw'>input(s),color</a> |
||
7614 | schaersvoo | 4658 | */ |
11806 | schaersvoo | 4659 | use_offset = 2; |
4660 | break; |
||
8386 | schaersvoo | 4661 | |
7996 | schaersvoo | 4662 | case XUNIT: |
4663 | /* |
||
4664 | @ xunit some_unit_for_x-values |
||
4665 | @ unicode allowed (no html code) |
||
4666 | @ use together with command mousex |
||
9372 | schaersvoo | 4667 | @ will display the cursor x-coordinate in 'unit' |
7996 | schaersvoo | 4668 | */ |
4669 | fprintf(js_include_file,"unit_x = \"%s\";",get_string(infile,1)); |
||
4670 | break; |
||
11806 | schaersvoo | 4671 | |
4672 | case XLABEL: |
||
7996 | schaersvoo | 4673 | /* |
11806 | schaersvoo | 4674 | @ xlabel some_string |
4675 | @ will be used to create a label for the x-axis (label is in quadrant I) |
||
4676 | @ can only be used together with command 'grid'</a><br />not depending on keywords 'axis' and 'axisnumbering' |
||
4677 | @ font setting: italic Courier, fontsize will be slightly larger (fontsize + 4)<br />use command "fontsize" to adjust.<br />(command "fontfamily" is not active for this command) |
||
7996 | schaersvoo | 4678 | */ |
11806 | schaersvoo | 4679 | temp = get_string(infile,1); |
4680 | fprintf(js_include_file,"var xaxislabel = \"%s\";",temp); |
||
7996 | schaersvoo | 4681 | break; |
8071 | schaersvoo | 4682 | |
11806 | schaersvoo | 4683 | case XLOGBASE: |
7991 | schaersvoo | 4684 | /* |
11806 | schaersvoo | 4685 | @ xlogbase number |
4686 | @ sets the logbase number for the x-axis |
||
4687 | @ default value 10 |
||
4688 | @ use together with commands xlogscale / xylogscale |
||
7991 | schaersvoo | 4689 | */ |
11806 | schaersvoo | 4690 | fprintf(js_include_file,"xlogbase=%d;",(int)(get_real(infile,1))); |
7991 | schaersvoo | 4691 | break; |
4692 | |||
11806 | schaersvoo | 4693 | case XLOGSCALE: |
7614 | schaersvoo | 4694 | /* |
11806 | schaersvoo | 4695 | @ xlogscale ymajor,yminor,majorcolor,minorcolor |
4696 | @ the x/y-range are set using commands 'xrange xmin,xmax' and 'yrange ymin,ymax' |
||
4697 | @ ymajor is the major step on the y-axis; yminor is the divisor for the y-step |
||
4698 | @ the linewidth is set using command 'linewidth int' |
||
4699 | @ the opacity of major / minor grid lines is set by command <a href='#opacity'>'opacity</a>' |
||
4700 | @ default logbase number = 10 ... when needed , set the logbase number with command 'xlogbase number' |
||
4701 | @ 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> |
||
4702 | @ note: the complete canvas will be used for the 'log paper' |
||
4703 | @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values |
||
4704 | @ note: command 'mouse color,fontsize' will show the real values in the logpaper.<br />\ |
||
4705 | @ 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 |
||
4706 | @ note: in case of userdraw , the use of keyword <a href='#userinput_xy'>'userinput_xy'</a> may be handy ! |
||
4707 | @ <b>attention</b>: keyword 'snaptogrid' may not lead to the desired result... |
||
7614 | schaersvoo | 4708 | */ |
11806 | schaersvoo | 4709 | if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");} |
4710 | if( js_function[DRAW_XLOGSCALE] != 1 ){ js_function[DRAW_XLOGSCALE] = 1;} |
||
4711 | for(i=0;i<4;i++){ |
||
7614 | schaersvoo | 4712 | switch(i){ |
11806 | schaersvoo | 4713 | case 0: double_data[0] = get_real(infile,0);break; /* xmajor */ |
4714 | case 1: int_data[0] = (int) (get_real(infile,0));break; /* xminor */ |
||
4715 | case 2: stroke_color = get_color(infile,0); break; |
||
4716 | case 3: fill_color = get_color(infile,1); |
||
4717 | string_length = snprintf(NULL,0,"draw_grid%d(%d,%d,\"%s\",\"%s\",%.2f,%.2f,%d,\"%s\",\"%s\",%d,%f,%d,%d); ",canvas_root_id,GRID_CANVAS,line_width,stroke_color,fill_color,stroke_opacity,fill_opacity,font_size,font_family,font_color,use_axis_numbering,double_data[0],int_data[0],precision); |
||
4718 | tmp_buffer = my_newmem(string_length+1); |
||
4719 | 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); |
||
4720 | fprintf(js_include_file,"use_xlogscale=1;snap_y = %f;snap_x = xlogbase;",double_data[0]/int_data[0]); |
||
4721 | add_to_buffer(tmp_buffer); |
||
4722 | break; |
||
7614 | schaersvoo | 4723 | default:break; |
4724 | } |
||
4725 | } |
||
4726 | break; |
||
11806 | schaersvoo | 4727 | |
4728 | case XYLOGSCALE: |
||
7614 | schaersvoo | 4729 | /* |
11806 | schaersvoo | 4730 | @ xylogscale majorcolor,minorcolor |
4731 | @ the x/y-range are set using commands 'xrange xmin,xmax' and 'yrange ymin,ymax' |
||
4732 | @ the linewidth is set using command 'linewidth int' |
||
4733 | @ the opacity of major / minor grid lines is set by command 'opacity [0-255],[0-255]' |
||
4734 | @ default logbase number = 10 ... when needed , set the logbase number with command 'xlogbase number' and/or 'ylogbase number' |
||
4735 | @ 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> |
||
4736 | @ note: the complete canvas will be used for the 'log paper' |
||
4737 | @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values |
||
4738 | @ note: command 'mouse color,fontsize' will show the real values in the logpaper.<br />\ |
||
4739 | @ 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') |
||
4740 | @ note: in case of userdraw , the use of keyword 'userinput_xy' may be handy ! |
||
4741 | @ <b>attention</b>: keyword 'snaptogrid' may not lead to the desired result... |
||
7614 | schaersvoo | 4742 | */ |
11806 | schaersvoo | 4743 | if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");} |
4744 | if( js_function[DRAW_XYLOGSCALE] != 1 ){ js_function[DRAW_XYLOGSCALE] = 1;} |
||
4745 | for(i=0;i<2;i++){ |
||
7614 | schaersvoo | 4746 | switch(i){ |
11806 | schaersvoo | 4747 | case 0: stroke_color = get_color(infile,0); break; |
4748 | case 1: fill_color = get_color(infile,1); |
||
4749 | string_length = snprintf(NULL,0,"draw_grid%d(%d,%d,\"%s\",\"%s\",%.2f,%.2f,%d,\"%s\",\"%s\",%d,%d); ",canvas_root_id,GRID_CANVAS,line_width,stroke_color,fill_color,stroke_opacity,fill_opacity,font_size,font_family,font_color,use_axis_numbering,precision); |
||
4750 | tmp_buffer = my_newmem(string_length+1); |
||
4751 | 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); |
||
4752 | fprintf(js_include_file,"use_xlogscale=1;use_ylogscale=1;snap_x = xlogbase;snap_y = ylogbase;"); |
||
4753 | add_to_buffer(tmp_buffer); |
||
4754 | break; |
||
7614 | schaersvoo | 4755 | default:break; |
4756 | } |
||
4757 | } |
||
4758 | break; |
||
11806 | schaersvoo | 4759 | |
4760 | |||
4761 | case Y_AXIS_STRINGS: |
||
7647 | schaersvoo | 4762 | /* |
11806 | schaersvoo | 4763 | @ yaxis num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n |
4764 | @ alternativ : yaxistext num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n |
||
4765 | @ 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>) |
||
4766 | @ no need to use keyword <a href="#axisnumbering">axisnumbering</a> |
||
4767 | @ use command <a href="#axis">axis</a> to have visual x/y-axis lines (see command <a href="grid">grid</a> |
||
4768 | @ use these y-axis num1...num_n values instead of default ymin...ymax |
||
4769 | @ a javascript error message will flag non-matching value:name pairs |
||
4770 | @ to be used before command grid (see <a href="#grid">command grid</a>) |
||
4771 | @ example:<br />size 400,400<br />yrange 0,13<br />xrange -100,500<br />axis<br />yaxis 1:january:2:february:3:march:5:may:6:june:7:july:8:august:9:september:10:october:11:november:12:december<br />#'ymajor' steps should be synchronised with numbers eg. "1" in this example<br />grid 100,1,grey,4,1,6,grey |
||
7647 | schaersvoo | 4772 | */ |
11806 | schaersvoo | 4773 | temp = get_string(infile,1); |
4774 | if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");} |
||
4775 | if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/ |
||
4776 | fprintf(js_include_file,"y_strings = [\"%s\"];\n ",temp); |
||
4777 | use_axis_numbering = 1; |
||
4778 | break; |
||
4779 | |||
4780 | |||
4781 | case YERRORBARS: |
||
7614 | schaersvoo | 4782 | /* |
11806 | schaersvoo | 4783 | @ yerrorbars color,E1,E2,x1,y1,x2,y2,...,x_n,y_n |
4784 | @ draw multiple points with y-errorbars E1 (error value under point) and E2 (error value above point) at given coordinates in color 'color' |
||
4785 | @ the errors E1 and E2 values are in yrange. |
||
4786 | @ use command 'linewidth int' to adust size |
||
4787 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!) |
||
7614 | schaersvoo | 4788 | */ |
11806 | schaersvoo | 4789 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
4790 | fill_color = stroke_color; |
||
11772 | schaersvoo | 4791 | i=0; |
4792 | while( ! done ){ /* get next item until EOL*/ |
||
4793 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
4794 | if(i%2 == 0 ){ |
||
4795 | double_data[i] = get_real(infile,0); /* x */ |
||
4796 | } |
||
4797 | else |
||
4798 | { |
||
4799 | double_data[i] = get_real(infile,1); /* y */ |
||
4800 | } |
||
4801 | i++; |
||
4802 | } |
||
11806 | schaersvoo | 4803 | for(c = 2 ; c < i-1 ; c = c+2){ |
4804 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,19,[%.*f],[%.*f],[%.2f],[%.2f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+1],double_data[0],double_data[1],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,1,0,0,0,use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset); |
||
4805 | /* click_cnt++; */ |
||
4806 | if(onclick > 0){click_cnt++;} |
||
8083 | schaersvoo | 4807 | } |
11806 | schaersvoo | 4808 | decimals = find_number_of_digits(precision); |
8083 | schaersvoo | 4809 | reset(); |
11806 | schaersvoo | 4810 | break; |
4811 | |||
4812 | case YRANGE: |
||
7614 | schaersvoo | 4813 | /* |
11806 | schaersvoo | 4814 | @ yrange ymin,ymax |
4815 | @ alternative : rangey |
||
4816 | @ if not given 0,ysize (eg in pixels) |
||
7614 | schaersvoo | 4817 | */ |
11806 | schaersvoo | 4818 | for(i = 0 ; i<2; i++){ |
7614 | schaersvoo | 4819 | switch(i){ |
11806 | schaersvoo | 4820 | case 0: ymin = get_real(infile,0);break; |
4821 | case 1: ymax = get_real(infile,1);break; |
||
4822 | default: break; |
||
7614 | schaersvoo | 4823 | } |
4824 | } |
||
11806 | schaersvoo | 4825 | if(ymin >= ymax){canvas_error(" yrange is not OK : ymin < ymax !\n");} |
4826 | fprintf(js_include_file,"var ymin = %f;var ymax = %f;\n",ymin,ymax); |
||
4827 | found_size_command++; |
||
4828 | break; |
||
4829 | |||
4830 | case YSNAPTOGRID: |
||
7614 | schaersvoo | 4831 | /* |
11806 | schaersvoo | 4832 | @ ysnaptogrid |
4833 | @ keyword (no arguments required) |
||
4834 | @ a draggable object (use command "drag x|y|xy") will snap to the given y-grid values when dragged (mouseup) |
||
4835 | @ in case of userdraw the drawn points will snap to ymajor grid |
||
4836 | @ if no grid is defined ,points will snap to every integer yrange value. (eg snap_y=1) |
||
4837 | @ if you do not want a visible grid, but you only want a 'snaptogrid' with some value...define this grid with opacity 0. |
||
4838 | @ if yminor is defined (use keyword 'axis' to activate yminor), the drawing will snap to yminor <br />use only even dividers in y-minor...for example<br />ysnaptogrid<br />axis<br />grid 2,1,grey,4,4,7,red<br /> will snap on x=0, x=0.5, x=1, x=1.5 ....<br /> will snap on y=0, y=0.25 y=0.5 y=0.75 ...<br /> |
||
7614 | schaersvoo | 4839 | */ |
11806 | schaersvoo | 4840 | fprintf(js_include_file,"\nx_use_snap_to_grid = 0;y_use_snap_to_grid = 1;"); |
7614 | schaersvoo | 4841 | break; |
11080 | schaersvoo | 4842 | |
7614 | schaersvoo | 4843 | case YLABEL: |
4844 | /* |
||
4845 | @ ylabel some_string |
||
8224 | bpr | 4846 | @ will be used to create a (vertical) label for the y-axis (label is in quadrant I) |
9379 | schaersvoo | 4847 | @ can only be used together with command <a href="#grid">'grid'</a><br />not depending on keywords 'axis' and 'axisnumbering' |
10953 | bpr | 4848 | @ font setting: italic Courier, fontsize will be slightly larger (fontsize + 4)<br />use command "fontsize" to adjust.<br />(command "fontfamily" is not active for this command) |
7614 | schaersvoo | 4849 | */ |
4850 | temp = get_string(infile,1); |
||
7653 | schaersvoo | 4851 | fprintf(js_include_file,"var yaxislabel = \"%s\";",temp); |
7614 | schaersvoo | 4852 | break; |
7735 | schaersvoo | 4853 | case YLOGBASE: |
4854 | /* |
||
4855 | @ ylogbase number |
||
4856 | @ sets the logbase number for the y-axis |
||
4857 | @ default value 10 |
||
4858 | @ use together with commands ylogscale / xylogscale |
||
4859 | */ |
||
4860 | fprintf(js_include_file,"ylogbase=%d;",(int)(get_real(infile,1))); |
||
4861 | break; |
||
7614 | schaersvoo | 4862 | case YLOGSCALE: |
7729 | schaersvoo | 4863 | /* |
4864 | @ ylogscale xmajor,xminor,majorcolor,minorcolor |
||
4865 | @ the x/y-range are set using commands 'xrange xmin,xmax' and 'yrange ymin,ymax' |
||
4866 | @ xmajor is the major step on the x-axis; xminor is the divisor for the x-step |
||
4867 | @ the linewidth is set using command 'linewidth int' |
||
4868 | @ the opacity of major / minor grid lines is set by command 'opacity [0-255],[0-255]' |
||
7735 | schaersvoo | 4869 | @ default logbase number = 10 ... when needed , set the logbase number with command 'ylogbase number' |
8224 | bpr | 4870 | @ the x/y- axis numbering is triggered by keyword 'axisnumbering'<ul><li>use command 'precision' before 'ylogscale' command to set the precision (decimals) of the axis numbering</li><li>use commands 'xlabel some_text' and/or 'ylabel some_text' for text on axis : use command 'fontsize int' to set the fontsize (default 12px)</li><li>use command 'fontfamily fnt_family_string' to set the fonts for axis-numbering</li><li>use command'fontcolor' to set the colour</li></ul> |
11088 | schaersvoo | 4871 | @ note: the complete canvas will be used for the 'log paper' |
4872 | @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values |
||
4873 | @ note: command 'mouse color,fontsize' will show the real values in the logpaper.<br />\ |
||
4874 | @ 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') |
||
4875 | @ note: in case of userdraw , the use of keyword 'userinput_xy' may be handy ! |
||
9383 | schaersvoo | 4876 | @ <b>attention</b>: keyword 'snaptogrid' may not lead to the desired result... |
7729 | schaersvoo | 4877 | */ |
4878 | if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");} |
||
4879 | if( js_function[DRAW_YLOGSCALE] != 1 ){ js_function[DRAW_YLOGSCALE] = 1;} |
||
4880 | for(i=0;i<4;i++){ |
||
4881 | switch(i){ |
||
4882 | case 0: double_data[0] = get_real(infile,0);break; /* xmajor */ |
||
4883 | case 1: int_data[0] = (int) (get_real(infile,0));break; /* xminor */ |
||
4884 | case 2: stroke_color = get_color(infile,0); break; |
||
8224 | bpr | 4885 | case 3: fill_color = get_color(infile,1); |
7779 | schaersvoo | 4886 | string_length = snprintf(NULL,0,"draw_grid%d(%d,%d,\"%s\",\"%s\",%.2f,%.2f,%d,\"%s\",\"%s\",%d,%f,%d,%d); ",canvas_root_id,GRID_CANVAS,line_width,stroke_color,fill_color,stroke_opacity,fill_opacity,font_size,font_family,font_color,use_axis_numbering,double_data[0],int_data[0],precision); |
7729 | schaersvoo | 4887 | tmp_buffer = my_newmem(string_length+1); |
7779 | schaersvoo | 4888 | 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 | 4889 | fprintf(js_include_file,"use_ylogscale=1;snap_x = %f;snap_y = ylogbase;",double_data[0]/int_data[0]); |
7729 | schaersvoo | 4890 | add_to_buffer(tmp_buffer); |
4891 | break; |
||
4892 | default:break; |
||
4893 | } |
||
4894 | } |
||
7614 | schaersvoo | 4895 | break; |
11806 | schaersvoo | 4896 | |
4897 | case YUNIT: |
||
7735 | schaersvoo | 4898 | /* |
11806 | schaersvoo | 4899 | @ yunit some_unit_for_y-values |
4900 | @ unicode allowed (no html code) |
||
4901 | @ use together with command mousey |
||
4902 | @ will display the cursor y-coordinate in 'unit' |
||
7735 | schaersvoo | 4903 | */ |
11806 | schaersvoo | 4904 | fprintf(js_include_file,"unit_y = \"%s\";",get_string(infile,1)); |
4905 | break; |
||
4906 | |||
4907 | case ZOOM: |
||
4908 | /* |
||
4909 | @ zoom button_color |
||
4910 | @ introduce a very small 'controlpanel' at the lower right corner |
||
4911 | @ giving six 15×15px 'active' rectangle areas<br />(for ×,leftarrow,rightarrow,uparrow,downarrow and a '-' and a '+' sign ) for zooming and/or panning of the image |
||
4912 | @ the 'x' symbol will do a 'location.reload' of the page, and thus reset all canvas drawings. |
||
4913 | @ choose an appropriate colour, so the small 'x,arrows,-,+' are clearly visible |
||
4914 | @ command 'opacity' may be used to set stroke_opacity of 'buttons |
||
4915 | @ note: use command 'zoom' at the end of your script code (the same is true for command 'mouse') |
||
4916 | @ note: only objects that may be set draggable / clickable will be zoomed / panned |
||
4917 | @ note: when an object is dragged, zooming / panning will cause the coordinates to be reset to the original position :( <br />e.g. dragging / panning will get lost. (array with 'drag data' is erased)<br />This is a design flaw and not a feature !! |
||
4918 | */ |
||
4919 | fprintf(js_include_file,"use_pan_and_zoom = 1;"); |
||
4920 | use_pan_and_zoom = TRUE; |
||
4921 | stroke_color = get_color(infile,1); |
||
4922 | /* we use BG_CANVAS (0) */ |
||
4923 | add_zoom_buttons(js_include_file,canvas_root_id,stroke_color,stroke_opacity); |
||
4924 | done = TRUE; |
||
4925 | break; |
||
4926 | |||
4927 | /* ready */ |
||
7614 | schaersvoo | 4928 | default:sync_input(infile); |
4929 | break; |
||
4930 | } |
||
8224 | bpr | 4931 | } |
7614 | schaersvoo | 4932 | /* we are done parsing script file */ |
7983 | schaersvoo | 4933 | /* check if xrange / yrange was set explicit ... or use xmin=0 xmax=xsize ymin=0 ymax=ysize : Quadrant I */ |
4934 | if( found_size_command == 1 ){ |
||
4935 | fprintf(js_include_file,"var xmin = 0;var xmax = %d;var ymin = 0;var ymax = %d",xsize,ysize); |
||
4936 | } |
||
4937 | else |
||
4938 | { |
||
4939 | if( found_size_command != 3 ){ |
||
8222 | schaersvoo | 4940 | canvas_error("Please specify both xrange and yrange ..."); |
7983 | schaersvoo | 4941 | } |
4942 | } |
||
8257 | schaersvoo | 4943 | |
8222 | schaersvoo | 4944 | /* if needed, add generic draw functions (grid / xml etc) to buffer : these are no draggable/clickable shapes / objects ! */ |
11021 | schaersvoo | 4945 | add_javascript_function(js_function,canvas_root_id); |
7614 | schaersvoo | 4946 | /* add read_canvas() etc functions if needed */ |
8257 | schaersvoo | 4947 | if( reply_format > 0 ){ add_read_canvas(canvas_root_id,reply_format,reply_precision);} |
7797 | schaersvoo | 4948 | if( use_pan_and_zoom == TRUE ){ |
4949 | /* in case of zooming ... */ |
||
7729 | schaersvoo | 4950 | fprintf(js_include_file,"\n<!-- some extra global stuff : need to rethink panning and zooming !!! -->\n\ |
7797 | schaersvoo | 4951 | precision = %d;var xmin_start=xmin;var xmax_start=xmax;\ |
7729 | schaersvoo | 4952 | var ymin_start=ymin;var ymax_start=xmax;\ |
4953 | var zoom_x_increment=0;var zoom_y_increment=0;\ |
||
4954 | var pan_x_increment=0;var pan_y_increment=0;\ |
||
4955 | if(use_ylogscale == 0 ){\ |
||
7956 | schaersvoo | 4956 | 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 | 4957 | }else{\ |
4958 | zoom_x_increment = (xmax - xmin)/20;\ |
||
4959 | pan_x_increment = (xmax - xmin)/20;\ |
||
4960 | };\ |
||
9406 | schaersvoo | 4961 | var zoom_xy=[xmin,xmax,ymin,ymax];\ |
7653 | schaersvoo | 4962 | function start_canvas%d(type){\ |
9406 | schaersvoo | 4963 | zoom_xy=[xmin,xmax,ymin,ymax];\ |
7653 | schaersvoo | 4964 | switch(type){\ |
7729 | schaersvoo | 4965 | case 0:xmin = xmin + zoom_x_increment;ymin = ymin + zoom_y_increment;xmax = xmax - zoom_x_increment;ymax = ymax - zoom_y_increment;break;\ |
4966 | 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 | 4967 | case 2:xmin = xmin - pan_x_increment;ymin = ymin ;xmax = xmax - pan_x_increment;ymax = ymax;break;\ |
4968 | case 3:xmin = xmin + pan_x_increment;ymin = ymin ;xmax = xmax + pan_x_increment;ymax = ymax;break;\ |
||
4969 | case 4:xmin = xmin;ymin = ymin - pan_y_increment ;xmax = xmax;ymax = ymax - pan_y_increment;break;\ |
||
4970 | case 5:xmin = xmin;ymin = ymin + pan_y_increment ;xmax = xmax;ymax = ymax + pan_y_increment;break;\ |
||
11004 | schaersvoo | 4971 | case 6:xmin = xmin_start; xmax = xmax_start;ymin = ymin_start;ymax = ymax_start;break;\ |
7653 | schaersvoo | 4972 | default:break;\ |
4973 | };\ |
||
4974 | if(xmax<=xmin){xmin=xmin_start;xmax=xmax_start;};\ |
||
4975 | if(ymax<=ymin){ymin=ymin_start;ymax=ymax_start;};\ |
||
9406 | schaersvoo | 4976 | try{dragstuff.Zoom(xmin,xmax,ymin,ymax);}catch(e){};\ |
11088 | schaersvoo | 4977 | if(typeof(redraw_all%d) === 'function' ){redraw_all%d(zoom_xy);}\ |
9406 | schaersvoo | 4978 | %s ;\ |
7653 | schaersvoo | 4979 | };\ |
7797 | schaersvoo | 4980 | start_canvas%d(333);\ |
9438 | schaersvoo | 4981 | };\ |
4982 | \n<!-- end wims_canvas_function -->\n\ |
||
9406 | schaersvoo | 4983 | wims_canvas_function%d();\n",precision,canvas_root_id,canvas_root_id,canvas_root_id,buffer,canvas_root_id,canvas_root_id); |
7797 | schaersvoo | 4984 | } |
4985 | else |
||
4986 | { |
||
4987 | /* no zoom, just add buffer */ |
||
4988 | fprintf(js_include_file,"\n<!-- add buffer -->\n\ |
||
4989 | %s\ |
||
4990 | };\n\ |
||
4991 | <!-- end wims_canvas_function -->\n\ |
||
4992 | wims_canvas_function%d();\n",buffer,canvas_root_id); |
||
4993 | } |
||
7614 | schaersvoo | 4994 | /* done writing the javascript include file */ |
4995 | fclose(js_include_file); |
||
4996 | |||
4997 | } |
||
4998 | |||
4999 | /* if using a tooltip, this should always be printed to the *.phtml file, so stdout */ |
||
9329 | schaersvoo | 5000 | if( use_tooltip > 0 ){ |
5001 | if( use_tooltip == 1 ){ |
||
5002 | add_js_tooltip(canvas_root_id,tooltip_text,bgcolor,xsize,ysize); |
||
5003 | } |
||
5004 | else |
||
5005 | { |
||
5006 | if( use_tooltip == 2 ){ |
||
5007 | add_js_popup(canvas_root_id,xsize,ysize,getfile_cmd); |
||
5008 | } |
||
5009 | } |
||
5010 | } |
||
7614 | schaersvoo | 5011 | exit(EXIT_SUCCESS); |
5012 | } |
||
5013 | /* end main() */ |
||
5014 | |||
5015 | /****************************************************************************** |
||
5016 | ** |
||
5017 | ** sync_input |
||
5018 | ** |
||
5019 | ** synchronises input line - reads to end of line, leaving file pointer |
||
5020 | ** at first character of next line. |
||
5021 | ** |
||
5022 | ** Used by: |
||
5023 | ** main program - error handling. |
||
5024 | ** |
||
5025 | ******************************************************************************/ |
||
5026 | void sync_input(FILE *infile) |
||
5027 | { |
||
5028 | int c = 0; |
||
5029 | |||
7658 | schaersvoo | 5030 | if( c == '\n' || c == ';' ) return; |
5031 | while( ( (c=getc(infile)) != EOF ) && (c != '\n') && (c != '\r') && (c != ';')) ; |
||
7614 | schaersvoo | 5032 | if( c == EOF ) finished = 1; |
7658 | schaersvoo | 5033 | if( c == '\n' || c == '\r' || c == ';') line_number++; |
7614 | schaersvoo | 5034 | return; |
5035 | } |
||
5036 | |||
5037 | /******************************************************************************/ |
||
5038 | |||
5039 | char *str_replace(const char *str, const char *old, const char *new){ |
||
5040 | /* http://creativeandcritical.net/str-replace-c/ */ |
||
5041 | if(strlen(str) > MAX_BUFFER){canvas_error("string argument too big");} |
||
5042 | char *ret, *r; |
||
5043 | const char *p, *q; |
||
5044 | size_t oldlen = strlen(old); |
||
5045 | size_t count = 0; |
||
5046 | size_t retlen = 0; |
||
5047 | size_t newlen = strlen(new); |
||
5048 | if (oldlen != newlen){ |
||
5049 | for (count = 0, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen){ |
||
5050 | count++; |
||
5051 | retlen = p - str + strlen(p) + count * (newlen - oldlen); |
||
5052 | } |
||
8224 | bpr | 5053 | } |
7614 | schaersvoo | 5054 | else |
5055 | { |
||
5056 | retlen = strlen(str); |
||
5057 | } |
||
8224 | bpr | 5058 | |
7614 | schaersvoo | 5059 | if ((ret = malloc(retlen + 1)) == NULL){ |
5060 | ret = NULL; |
||
5061 | canvas_error("string argument is NULL"); |
||
5062 | } |
||
5063 | else |
||
5064 | { |
||
5065 | for (r = ret, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen) { |
||
5066 | size_t l = q - p; |
||
5067 | memcpy(r, p, l); |
||
5068 | r += l; |
||
5069 | memcpy(r, new, newlen); |
||
5070 | r += newlen; |
||
5071 | } |
||
5072 | strcpy(r, p); |
||
5073 | } |
||
5074 | return ret; |
||
5075 | } |
||
5076 | |||
5077 | /******************************************************************************/ |
||
7848 | bpr | 5078 | |
7614 | schaersvoo | 5079 | char *get_color(FILE *infile , int last){ |
5080 | int c,i = 0,is_hex = 0; |
||
5081 | char temp[MAX_COLOR_STRING], *string; |
||
8305 | schaersvoo | 5082 | const char *not_allowed = "0123456789"; |
10891 | schaersvoo | 5083 | while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != ',' ) && ( c != ';' ) && ( c != '\t' ) ){ |
7614 | schaersvoo | 5084 | if( i > MAX_COLOR_STRING ){ canvas_error("colour string is too big ... ? ");} |
5085 | if( c == '#' ){ |
||
5086 | is_hex = 1; |
||
5087 | } |
||
5088 | if( c != ' '){ |
||
8304 | schaersvoo | 5089 | 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 | 5090 | temp[i]=tolower(c); |
5091 | i++; |
||
5092 | } |
||
5093 | } |
||
10891 | schaersvoo | 5094 | if( ( c == '\n' || c == EOF || c == ';' || c == '\t' ) && last == 0){canvas_error("expecting more arguments in command");} |
5095 | if( c == '\n' || c == ';' || c == '\t' ){ done = TRUE; line_number++; } |
||
7614 | schaersvoo | 5096 | if( c == EOF ){finished = 1;} |
5097 | if( finished == 1 && last != 1 ){ canvas_error("expected more arguments");} |
||
5098 | temp[i]='\0'; |
||
5099 | if( strlen(temp) == 0 ){ canvas_error("expected a colorname or hexnumber, but found nothing !!");} |
||
5100 | if( is_hex == 1 ){ |
||
5101 | char red[3], green[3], blue[3]; |
||
5102 | red[0] = toupper(temp[1]); red[1] = toupper(temp[2]); red[2] = '\0'; |
||
5103 | green[0] = toupper(temp[3]); green[1] = toupper(temp[4]); green[2] = '\0'; |
||
5104 | blue[0] = toupper(temp[5]); blue[1] = toupper(temp[6]); blue[2] = '\0'; |
||
5105 | int r = (int) strtol(red, NULL, 16); |
||
5106 | int g = (int) strtol(green, NULL, 16); |
||
5107 | int b = (int) strtol(blue, NULL, 16); |
||
5108 | string = (char *)my_newmem(12); |
||
5109 | snprintf(string,11,"%d,%d,%d",r,g,b); |
||
5110 | return string; |
||
5111 | } |
||
5112 | else |
||
5113 | { |
||
5114 | string = (char *)my_newmem(sizeof(temp)); |
||
5115 | snprintf(string,sizeof(temp),"%s",temp); |
||
8304 | schaersvoo | 5116 | for( i = 0; i < NUMBER_OF_COLORNAMES ; i++ ){ |
7614 | schaersvoo | 5117 | if( strcmp( colors[i].name , string ) == 0 ){ |
5118 | return colors[i].rgb; |
||
5119 | } |
||
5120 | } |
||
8304 | schaersvoo | 5121 | canvas_error("I was expecting a color name or hexnumber...but found nothing."); |
7614 | schaersvoo | 5122 | } |
8304 | schaersvoo | 5123 | return "0,0,255"; |
7614 | schaersvoo | 5124 | } |
5125 | |||
5126 | char *get_string(FILE *infile,int last){ /* last = 0 : more arguments ; last=1 final argument */ |
||
5127 | int c,i=0; |
||
5128 | char temp[MAX_BUFFER], *string; |
||
10891 | schaersvoo | 5129 | while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != '\t') ){ |
7614 | schaersvoo | 5130 | temp[i]=c; |
5131 | i++; |
||
5132 | if(i > MAX_BUFFER){ canvas_error("string size too big...repeat command to fit string");break;} |
||
5133 | } |
||
10891 | schaersvoo | 5134 | if( ( c == '\n' || c == '\t' || c == EOF ) && last == 0){canvas_error("expecting more arguments in command");} |
5135 | if( c == '\n' || c == '\t') { done = TRUE; line_number++; } |
||
11022 | schaersvoo | 5136 | if( c == EOF ) {finished = 1;} |
7614 | schaersvoo | 5137 | temp[i]='\0'; |
11022 | schaersvoo | 5138 | if( strlen(temp) == 0 && last != 3 ){ canvas_error("expected a word or string, but found nothing !!");} |
7614 | schaersvoo | 5139 | string=(char *)my_newmem(strlen(temp)); |
5140 | snprintf(string,sizeof(temp),"%s",temp); |
||
5141 | return string; |
||
5142 | } |
||
5143 | |||
5144 | char *get_string_argument(FILE *infile,int last){ /* last = 0 : more arguments ; last=1 final argument */ |
||
5145 | int c,i=0; |
||
5146 | char temp[MAX_BUFFER], *string; |
||
10891 | schaersvoo | 5147 | while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != '\t') && ( c != ',')){ |
7614 | schaersvoo | 5148 | temp[i]=c; |
5149 | i++; |
||
5150 | if(i > MAX_BUFFER){ canvas_error("string size too big...will cut it off");break;} |
||
5151 | } |
||
8224 | bpr | 5152 | if( ( c == '\n' || c == EOF) && last == 0){canvas_error("expecting more arguments in command");} |
10891 | schaersvoo | 5153 | if( c == '\n' || c == '\t' ) { line_number++; } |
7614 | schaersvoo | 5154 | if( c == EOF ) {finished = 1;} |
9478 | schaersvoo | 5155 | if( finished == 1 && last == 0 ){ canvas_error("expected more arguments");} |
7614 | schaersvoo | 5156 | temp[i]='\0'; |
10953 | bpr | 5157 | /* |
8322 | schaersvoo | 5158 | 17.10.2014 removed (question Perrin) |
5159 | may cause some unwanted effects... |
||
7614 | schaersvoo | 5160 | if( strlen(temp) == 0 ){ canvas_error("expected a word or string (without comma) , but found nothing !!");} |
8322 | schaersvoo | 5161 | */ |
7614 | schaersvoo | 5162 | string=(char *)my_newmem(sizeof(temp)); |
5163 | snprintf(string,sizeof(temp),"%s",temp); |
||
5164 | done = TRUE; |
||
5165 | return string; |
||
5166 | } |
||
5167 | |||
5168 | double get_real(FILE *infile, int last){ /* accept anything that looks like an number ? last = 0 : more arguments ; last=1 final argument */ |
||
5169 | int c,i=0,found_calc = 0; |
||
5170 | double y; |
||
5171 | char tmp[MAX_INT]; |
||
10953 | bpr | 5172 | /* |
5173 | these things are 'allowed functions' : *,^,+,-,/,(,),e,arc,cos,tan,pi,log,ln,sqrt,abs |
||
8383 | schaersvoo | 5174 | but there should be a better way to avoid segfaults ! |
8348 | schaersvoo | 5175 | */ |
5176 | const char *allowed = "earcostanpilogqb*+-/^()";/* assuming these are allowed stuff in a 'number'*/ |
||
5177 | const char *not_allowed = "#dfhjkmuvwxyz{}[]%&~!$";/* avoid segmentation faults in a "atof()" and "wims eval" */ |
||
10891 | schaersvoo | 5178 | while(( (c=getc(infile)) != EOF ) && ( c != ',') && (c != '\n') && (c != '\t') && ( c != ';')){ |
7614 | schaersvoo | 5179 | if( c != ' ' ){ |
8224 | bpr | 5180 | if( i == 0 && c == '+' ){ |
7614 | schaersvoo | 5181 | continue; |
8224 | bpr | 5182 | } |
7614 | schaersvoo | 5183 | else |
5184 | { |
||
8304 | schaersvoo | 5185 | c = tolower(c); |
5186 | if( strchr(not_allowed,c) != 0 ){canvas_error("found a character not associated with a number...");} |
||
5187 | if( strchr(allowed,c) != 0 ){found_calc = 1;}/* hand the string over to wims eval() */ |
||
7614 | schaersvoo | 5188 | tmp[i] = c; |
5189 | i++; |
||
5190 | } |
||
5191 | } |
||
5192 | if( i > MAX_INT - 1){canvas_error("number too large");} |
||
5193 | } |
||
10891 | schaersvoo | 5194 | if( ( c == '\n' || c == EOF || c == ';' || c == '\t' ) && last == 0){canvas_error("expecting more arguments in command");} |
5195 | if( c == '\n' || c == ';' || c == '\t' ){ done = TRUE; line_number++; } |
||
7614 | schaersvoo | 5196 | if( c == EOF ){done = TRUE ; finished = 1;} |
5197 | tmp[i]='\0'; |
||
5198 | if( strlen(tmp) == 0 ){canvas_error("expected a number , but found nothing !!");} |
||
8304 | schaersvoo | 5199 | if( found_calc == 1 ){ /* use wims eval to calculate 2*pi/3 */ |
7848 | bpr | 5200 | void *f = eval_create(tmp); |
7614 | schaersvoo | 5201 | assert(f);if( f == NULL ){canvas_error("I'm having trouble parsing your \"expression\" ") ;} |
7848 | bpr | 5202 | y = eval_x(f, 1); |
7614 | schaersvoo | 5203 | /* if function is bogus; y = 1 : so no core dumps */ |
7848 | bpr | 5204 | eval_destroy(f); |
7614 | schaersvoo | 5205 | } |
5206 | else |
||
5207 | { |
||
5208 | y = atof(tmp); |
||
5209 | } |
||
5210 | return y; |
||
5211 | } |
||
8304 | schaersvoo | 5212 | |
5213 | |||
7614 | schaersvoo | 5214 | void canvas_error(char *msg){ |
8383 | schaersvoo | 5215 | fprintf(stdout,"\n</script><hr /><span style=\"color:red\">FATAL syntax error:line %d : %s</span><hr />",line_number,msg); |
7614 | schaersvoo | 5216 | finished = 1; |
5217 | exit(EXIT_SUCCESS); |
||
5218 | } |
||
5219 | |||
5220 | |||
5221 | /* convert x/y coordinates to pixel */ |
||
5222 | int x2px(double x){ |
||
5223 | return x*xsize/(xmax - xmin) - xsize*xmin/(xmax - xmin); |
||
5224 | } |
||
5225 | |||
5226 | int y2px(double y){ |
||
5227 | return -1*y*ysize/(ymax - ymin) + ymax*ysize/(ymax - ymin); |
||
5228 | } |
||
5229 | |||
5230 | double px2x(int x){ |
||
5231 | return (x*(xmax - xmin)/xsize + xmin); |
||
5232 | } |
||
5233 | double px2y(int y){ |
||
5234 | return (y*(ymax - ymin)/ysize + ymin); |
||
5235 | } |
||
5236 | |||
5237 | void add_to_buffer(char *tmp){ |
||
5238 | if( tmp == NULL || tmp == 0 ){ canvas_error("nothing to add_to_buffer()...");} |
||
5239 | /* do we have enough space left in buffer[MAX_BUFFER] ? */ |
||
5240 | int space_left = (int) (sizeof(buffer) - strlen(buffer)); |
||
5241 | if( space_left > strlen(tmp)){ |
||
5242 | strncat(buffer,tmp,space_left - 1);/* add safely "tmp" to the string buffer */ |
||
5243 | } |
||
5244 | else |
||
5245 | { |
||
5246 | canvas_error("buffer is too big\n"); |
||
5247 | } |
||
5248 | tmp = NULL;free(tmp); |
||
5249 | return; |
||
5250 | } |
||
5251 | |||
5252 | void reset(){ |
||
5253 | if(use_filled == TRUE){use_filled = FALSE;} |
||
5254 | if(use_dashed == TRUE){use_dashed = FALSE;} |
||
5255 | if(use_rotate == TRUE){use_rotate = FALSE;} |
||
8379 | schaersvoo | 5256 | onclick = 0; |
7614 | schaersvoo | 5257 | } |
5258 | |||
5259 | |||
5260 | |||
5261 | /* What reply format in read_canvas(); |
||
5262 | |||
5263 | note:if userdraw is combined with inputfields...every "userdraw" based answer will append "\n" and inputfield.value() |
||
5264 | 1 = x1,x2,x3,x4....x_n |
||
5265 | y1,y2,y3,y4....y_n |
||
5266 | |||
5267 | x/y in pixels |
||
5268 | |||
5269 | 2 = x1,x2,x3,x4....x_n |
||
5270 | y1,y2,y3,y4....y_n |
||
5271 | x/y in xrange / yrange coordinate system |
||
5272 | |||
5273 | 3 = x1,x2,x3,x4....x_n |
||
5274 | y1,y2,y3,y4....y_n |
||
5275 | r1,r2,r3,r4....r_n |
||
5276 | |||
8224 | bpr | 5277 | x/y in pixels |
7614 | schaersvoo | 5278 | r in pixels |
5279 | |||
5280 | 4 = x1,x2,x3,x4....x_n |
||
5281 | y1,y2,y3,y4....y_n |
||
5282 | r1,r2,r3,r4....r_n |
||
5283 | |||
5284 | x/y in xrange / yrange coordinate system |
||
5285 | r in pixels |
||
5286 | |||
5287 | 5 = Ax1,Ax2,Ax3,Ax4....Ax_n |
||
5288 | Ay1,Ay2,Ay3,Ay4....Ay_n |
||
5289 | Bx1,Bx2,Bx3,Bx4....Bx_n |
||
5290 | By1,By2,By3,By4....By_n |
||
5291 | Cx1,Cx2,Cx3,Cx4....Cx_n |
||
5292 | Cy1,Cy2,Cy3,Cy4....Cy_n |
||
5293 | .... |
||
5294 | Zx1,Zx2,Zx3,Zx4....Zx_n |
||
5295 | Zy1,Zy2,Zy3,Zy4....Zy_n |
||
8224 | bpr | 5296 | |
7614 | schaersvoo | 5297 | x/y in pixels |
5298 | |||
5299 | 6 = Ax1,Ax2,Ax3,Ax4....Ax_n |
||
5300 | Ay1,Ay2,Ay3,Ay4....Ay_n |
||
5301 | Bx1,Bx2,Bx3,Bx4....Bx_n |
||
5302 | By1,By2,By3,By4....By_n |
||
5303 | Cx1,Cx2,Cx3,Cx4....Cx_n |
||
5304 | Cy1,Cy2,Cy3,Cy4....Cy_n |
||
5305 | .... |
||
5306 | Zx1,Zx2,Zx3,Zx4....Zx_n |
||
5307 | Zy1,Zy2,Zy3,Zy4....Zy_n |
||
5308 | |||
5309 | x/y in xrange / yrange coordinate system |
||
8224 | bpr | 5310 | |
7614 | schaersvoo | 5311 | 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n |
8224 | bpr | 5312 | |
7614 | schaersvoo | 5313 | x/y in pixels |
5314 | |||
5315 | 8 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n |
||
8224 | bpr | 5316 | |
7614 | schaersvoo | 5317 | x/y in xrange / yrange coordinate system |
5318 | |||
8224 | bpr | 5319 | 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n |
7614 | schaersvoo | 5320 | |
5321 | x/y in pixels |
||
5322 | |||
8224 | bpr | 5323 | 10 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n |
7614 | schaersvoo | 5324 | |
5325 | x/y in xrange / yrange coordinate system |
||
5326 | |||
5327 | 11 = Ax1,Ay1,Ax2,Ay2 |
||
5328 | Bx1,By1,Bx2,By2 |
||
5329 | Cx1,Cy1,Cx2,Cy2 |
||
5330 | Dx1,Dy1,Dx2,Dy2 |
||
5331 | ...... |
||
5332 | Zx1,Zy1,Zx2,Zy2 |
||
8224 | bpr | 5333 | |
7614 | schaersvoo | 5334 | x/y in xrange / yrange coordinate system |
5335 | |||
5336 | 12 = Ax1,Ay1,Ax2,Ay2 |
||
5337 | Bx1,By1,Bx2,By2 |
||
5338 | Cx1,Cy1,Cx2,Cy2 |
||
5339 | Dx1,Dy1,Dx2,Dy2 |
||
5340 | ...... |
||
5341 | Zx1,Zy1,Zx2,Zy2 |
||
8224 | bpr | 5342 | |
7614 | schaersvoo | 5343 | x/y in pixels |
5344 | |||
5345 | 13 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2,Cx1:Cy1:Cx2:Cy2,Dx1:Dy1:Dx2:Dy2, ... ,Zx1:Zy1:Zx2:Zy2 |
||
5346 | |||
5347 | x/y in xrange / yrange coordinate system |
||
5348 | 14 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2....Zx1:Zy1:Zx2:Zy2 |
||
5349 | x/y in pixels |
||
5350 | 15 = reply from inputfields,textareas |
||
5351 | reply1,reply2,reply3,...,reply_n |
||
7984 | schaersvoo | 5352 | only fields set write (a.g. will not read 'readonly' inputfield values' |
7614 | schaersvoo | 5353 | |
5354 | 16 = read mathml inputfields only |
||
5355 | |||
11080 | schaersvoo | 5356 | 17 = read userdraw text only (x1,y1,text1\nx2,y2,text2..\n.x_n,y_n,text_n |
7614 | schaersvoo | 5357 | when ready : calculate size_t of string via snprintf(NULL,0,"blah blah..."); |
5358 | |||
5359 | 18 = read clock(s) : H1:M1:S1,H2:M2:S2,...H_n:M_n:S_n |
||
5360 | 19 = return clicked object number (analogue to shape-library onclick) |
||
5361 | 20 = return x/y-data in x-range/y-range of all 'draggable' images |
||
5362 | 21 = return verbatim coordinates (x1:y1) (x2:y2)...(x_n:y_n) |
||
5363 | 22 = array : x1,y1,x2,y2,x3,y3,x4,y4...x_n,y_n |
||
5364 | x/y in xrange / yrange coordinate system |
||
8224 | bpr | 5365 | 23 = answertype for a polyline : remove multiple occurences due to reclick on a point to create next polyline segment |
7984 | schaersvoo | 5366 | 24 = read all inputfield values: even those set 'readonly' |
8224 | bpr | 5367 | 25 = return all userdrawn arcs in degrees: |
5368 | 26 = return all userdrawn arcs in radians: |
||
11080 | schaersvoo | 5369 | 27 = return (only) userdraw inputfields array: x1,y1,text1 \n x2,y2,text2... |
8322 | schaersvoo | 5370 | 28 = x1,y1,r1,x2,y2,r2...x_n,y_n,r_n |
10953 | bpr | 5371 | x/y/r in xrange / yrange coordinate system: may be used to reinput into command |
8322 | schaersvoo | 5372 | 'circles color,x1,y1,r1,x2,y2,r2...x_n,y_n,r_n' |
5373 | will not return anything else (e.g. no inputfields , text etc) |
||
10953 | bpr | 5374 | 29 = mulidraw read : |
5375 | |||
7614 | schaersvoo | 5376 | */ |
5377 | |||
5378 | |||
8257 | schaersvoo | 5379 | void add_read_canvas(int canvas_root_id,int type_reply,int reply_precision){ |
7614 | schaersvoo | 5380 | /* just 1 reply type allowed */ |
8074 | schaersvoo | 5381 | fprintf(js_include_file,"\ |
5382 | \n<!-- begin set_reply_precision() -->\n\ |
||
5383 | function set_reply_precision(){\ |
||
5384 | var len = userdraw_x.length;\ |
||
5385 | var prec = %d;\ |
||
5386 | for(var p = 0 ; p < len ; p++ ){\ |
||
5387 | userdraw_x[p] = (Math.round(prec*userdraw_x[p]))/prec;\ |
||
5388 | userdraw_y[p] = (Math.round(prec*userdraw_y[p]))/prec;\ |
||
5389 | };\ |
||
5390 | len = userdraw_radius.length;\ |
||
5391 | if( len > 0 ){\ |
||
5392 | for(var p = 0 ; p < len ; p++ ){\ |
||
5393 | userdraw_radius[p] = (Math.round(prec*userdraw_radius[p]))/prec;\ |
||
5394 | };\ |
||
5395 | };\ |
||
5396 | };",reply_precision); |
||
7963 | schaersvoo | 5397 | |
7614 | schaersvoo | 5398 | switch(type_reply){ |
8224 | bpr | 5399 | /* |
7614 | schaersvoo | 5400 | answers may have: |
5401 | x-values,y-values,r-values,input-fields,mathml-inputfields,text-typed answers |
||
5402 | */ |
||
5403 | case 1: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 5404 | \n<!-- begin function 1 read_canvas%d() -->\n\ |
5405 | read_canvas%d = function(){\ |
||
7614 | schaersvoo | 5406 | if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\ |
8074 | schaersvoo | 5407 | set_reply_precision();\ |
7614 | schaersvoo | 5408 | if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\ |
5409 | var p = 0;var input_reply = new Array();\ |
||
5410 | if( document.getElementById(\"canvas_input0\")){\ |
||
5411 | var t = 0;\ |
||
5412 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
5413 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
5414 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
5415 | p++;\ |
||
5416 | };\ |
||
5417 | t++;\ |
||
5418 | };\ |
||
5419 | };\ |
||
11088 | schaersvoo | 5420 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 5421 | return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+input_reply + \"\\n\"+userdraw_text;\ |
5422 | }\ |
||
5423 | else\ |
||
5424 | {\ |
||
5425 | return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+input_reply;\ |
||
5426 | }\ |
||
5427 | }\ |
||
5428 | else\ |
||
5429 | {\ |
||
11088 | schaersvoo | 5430 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 5431 | return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_text;\ |
5432 | }\ |
||
5433 | else\ |
||
5434 | {\ |
||
5435 | return userdraw_x+\"\\n\"+userdraw_y;\ |
||
5436 | }\ |
||
5437 | };\ |
||
8108 | schaersvoo | 5438 | };\n\ |
8257 | schaersvoo | 5439 | <!-- end function 1 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 5440 | break; |
5441 | case 2: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 5442 | \n<!-- begin function 2 read_canvas%d() -->\n\ |
5443 | read_canvas%d = function(){\ |
||
7614 | schaersvoo | 5444 | if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\ |
8074 | schaersvoo | 5445 | set_reply_precision();\ |
7614 | schaersvoo | 5446 | var reply_x = new Array();var reply_y = new Array();var p = 0;\ |
8074 | schaersvoo | 5447 | var prec = %d;\ |
7614 | schaersvoo | 5448 | while(userdraw_x[p]){\ |
8074 | schaersvoo | 5449 | reply_x[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\ |
5450 | reply_y[p] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\ |
||
7614 | schaersvoo | 5451 | p++;\ |
5452 | };\ |
||
11806 | schaersvoo | 5453 | if(p == 0){return;};\ |
7614 | schaersvoo | 5454 | if( document.getElementById(\"canvas_input0\")){\ |
5455 | var p = 0;var input_reply = new Array();\ |
||
5456 | if( document.getElementById(\"canvas_input0\")){\ |
||
5457 | var t = 0;\ |
||
5458 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
5459 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
5460 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
5461 | p++;\ |
||
5462 | };\ |
||
5463 | t++;\ |
||
5464 | };\ |
||
5465 | };\ |
||
11088 | schaersvoo | 5466 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 5467 | return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
5468 | }\ |
||
5469 | else\ |
||
5470 | {\ |
||
5471 | return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply;\ |
||
5472 | }\ |
||
5473 | }\ |
||
5474 | else\ |
||
5475 | {\ |
||
11088 | schaersvoo | 5476 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 5477 | return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_text;\ |
5478 | }\ |
||
5479 | else\ |
||
5480 | {\ |
||
5481 | return reply_x+\"\\n\"+reply_y;\ |
||
5482 | };\ |
||
5483 | };\ |
||
8108 | schaersvoo | 5484 | };\n\ |
8257 | schaersvoo | 5485 | <!-- end function 2 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7614 | schaersvoo | 5486 | break; |
5487 | case 3: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 5488 | \n<!-- begin function 3 read_canvas%d() -->\n\ |
5489 | read_canvas%d = function(){\ |
||
7614 | schaersvoo | 5490 | if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\ |
8074 | schaersvoo | 5491 | set_reply_precision();\ |
7614 | schaersvoo | 5492 | if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\ |
5493 | var p = 0;var input_reply = new Array();\ |
||
5494 | if( document.getElementById(\"canvas_input0\")){\ |
||
5495 | var t = 0;\ |
||
5496 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
5497 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
5498 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
5499 | p++;\ |
||
5500 | };\ |
||
5501 | t++;\ |
||
5502 | };\ |
||
5503 | };\ |
||
11088 | schaersvoo | 5504 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 5505 | return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
5506 | }\ |
||
5507 | else\ |
||
5508 | {\ |
||
5509 | return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+input_reply;\ |
||
5510 | }\ |
||
5511 | }\ |
||
5512 | else\ |
||
5513 | {\ |
||
11088 | schaersvoo | 5514 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 5515 | return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+userdrawW_text;\ |
5516 | }\ |
||
5517 | else\ |
||
5518 | {\ |
||
5519 | return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius;\ |
||
5520 | }\ |
||
5521 | }\ |
||
8108 | schaersvoo | 5522 | };\n\ |
8257 | schaersvoo | 5523 | <!-- end function 3 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 5524 | break; |
5525 | case 4: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 5526 | \n<!-- begin function 4 read_canvas%d() -->\n\ |
5527 | read_canvas%d = function(){\ |
||
8074 | schaersvoo | 5528 | var prec = %d;\ |
7614 | schaersvoo | 5529 | var reply_x = new Array();var reply_y = new Array();var p = 0;\ |
5530 | while(userdraw_x[p]){\ |
||
8074 | schaersvoo | 5531 | reply_x[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\ |
5532 | reply_y[p] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;;\ |
||
7614 | schaersvoo | 5533 | p++;\ |
5534 | };\ |
||
11806 | schaersvoo | 5535 | if(p == 0){return;};\ |
7614 | schaersvoo | 5536 | if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\ |
5537 | var p = 0;var input_reply = new Array();\ |
||
5538 | if( document.getElementById(\"canvas_input0\")){\ |
||
5539 | var t = 0;\ |
||
5540 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
5541 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
5542 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
5543 | p++;\ |
||
5544 | };\ |
||
5545 | t++;\ |
||
5546 | };\ |
||
5547 | };\ |
||
11088 | schaersvoo | 5548 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 5549 | return reply_x+\"\\n\"+reply_y +\"\\n\"+userdraw_radius+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
5550 | }\ |
||
5551 | else\ |
||
5552 | {\ |
||
5553 | return reply_x+\"\\n\"+reply_y +\"\\n\"+userdraw_radius+\"\\n\"+input_reply;\ |
||
5554 | }\ |
||
5555 | }\ |
||
5556 | else\ |
||
5557 | {\ |
||
11088 | schaersvoo | 5558 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 5559 | return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_radius+\"\\n\"+userdraw_text;\ |
5560 | }\ |
||
5561 | else\ |
||
5562 | {\ |
||
5563 | return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_radius;\ |
||
5564 | }\ |
||
5565 | };\ |
||
8108 | schaersvoo | 5566 | };\n\ |
8257 | schaersvoo | 5567 | <!-- end function 4 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7614 | schaersvoo | 5568 | break; |
8224 | bpr | 5569 | /* |
5570 | attention: we reset userdraw_x / userdraw_y : because userdraw_x = [][] userdraw_y = [][] |
||
5571 | used for userdraw multiple paths |
||
7614 | schaersvoo | 5572 | */ |
5573 | case 5: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 5574 | \n<!-- begin function 5 read_canvas%d() -->\n\ |
5575 | read_canvas%d = function(){\ |
||
8074 | schaersvoo | 5576 | set_reply_precision();\ |
7614 | schaersvoo | 5577 | var p = 0;\ |
5578 | var reply = \"\";\ |
||
5579 | for(p = 0; p < userdraw_x.length;p++){\ |
||
5580 | if(userdraw_x[p] != null ){\ |
||
5581 | reply = reply + userdraw_x[p]+\"\\n\"+userdraw_y[p]+\"\\n\";\ |
||
5582 | };\ |
||
5583 | };\ |
||
11806 | schaersvoo | 5584 | if(p == 0){return;};\ |
7614 | schaersvoo | 5585 | userdraw_x = [];userdraw_y = [];\ |
5586 | if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\ |
||
5587 | var p = 0;var input_reply = new Array();\ |
||
5588 | if( document.getElementById(\"canvas_input0\")){\ |
||
5589 | var t = 0;\ |
||
5590 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
5591 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
5592 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
5593 | p++;\ |
||
5594 | };\ |
||
5595 | t++;\ |
||
5596 | };\ |
||
5597 | };\ |
||
11088 | schaersvoo | 5598 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 5599 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
5600 | }\ |
||
5601 | else\ |
||
5602 | {\ |
||
5603 | return reply +\"\\n\"+input_reply;\ |
||
5604 | }\ |
||
5605 | }\ |
||
5606 | else\ |
||
5607 | {\ |
||
11088 | schaersvoo | 5608 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 5609 | return reply+\"\\n\"+userdraw_text;\ |
5610 | }\ |
||
5611 | else\ |
||
5612 | {\ |
||
5613 | return reply;\ |
||
5614 | }\ |
||
5615 | };\ |
||
8108 | schaersvoo | 5616 | };\n\ |
8257 | schaersvoo | 5617 | <!-- end function 5 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 5618 | break; |
8224 | bpr | 5619 | /* |
5620 | attention: we reset userdraw_x / userdraw_y : because userdraw_x = [][] userdraw_y = [][] |
||
5621 | used for userdraw multiple paths |
||
7614 | schaersvoo | 5622 | */ |
5623 | case 6: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 5624 | \n<!-- begin function 6 read_canvas%d() -->\n\ |
5625 | read_canvas%d = function(){\ |
||
7614 | schaersvoo | 5626 | var p = 0;\ |
5627 | var reply = \"\";\ |
||
5628 | var tmp_x = new Array();\ |
||
5629 | var tmp_y = new Array();\ |
||
8074 | schaersvoo | 5630 | var prec = %d;\ |
7614 | schaersvoo | 5631 | for(p = 0 ; p < userdraw_x.length; p++){\ |
5632 | tmp_x = userdraw_x[p];\ |
||
5633 | tmp_y = userdraw_y[p];\ |
||
5634 | if(tmp_x != null){\ |
||
5635 | for(var i = 0 ; i < tmp_x.length ; i++){\ |
||
8074 | schaersvoo | 5636 | tmp_x[i] = (Math.round(prec*(px2x(tmp_x[i]))))/prec;\ |
5637 | tmp_y[i] = (Math.round(prec*(px2y(tmp_y[i]))))/prec;\ |
||
7614 | schaersvoo | 5638 | };\ |
5639 | reply = reply + tmp_x + \"\\n\" + tmp_y +\"\\n\";\ |
||
5640 | };\ |
||
5641 | };\ |
||
11806 | schaersvoo | 5642 | if(p == 0){return;};\ |
7614 | schaersvoo | 5643 | userdraw_x = [];userdraw_y = [];\ |
5644 | if( document.getElementById(\"canvas_input0\") ){\ |
||
5645 | var p = 0;var input_reply = new Array();\ |
||
5646 | if( document.getElementById(\"canvas_input0\")){\ |
||
5647 | var t = 0;\ |
||
5648 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
5649 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
5650 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
5651 | p++;\ |
||
5652 | };\ |
||
5653 | t++;\ |
||
5654 | };\ |
||
5655 | };\ |
||
11088 | schaersvoo | 5656 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 5657 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
5658 | }\ |
||
5659 | else\ |
||
5660 | {\ |
||
5661 | return reply +\"\\n\"+input_reply;\ |
||
5662 | }\ |
||
5663 | }\ |
||
5664 | else\ |
||
5665 | {\ |
||
11088 | schaersvoo | 5666 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 5667 | return reply +\"\\n\"+userdraw_text;\ |
5668 | }\ |
||
5669 | else\ |
||
5670 | {\ |
||
5671 | return reply;\ |
||
5672 | }\ |
||
5673 | };\ |
||
8108 | schaersvoo | 5674 | };\n\ |
8257 | schaersvoo | 5675 | <!-- end function 6 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7614 | schaersvoo | 5676 | break; |
5677 | case 7: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 5678 | \n<!-- begin function 7 read_canvas%d() -->\n\ |
5679 | read_canvas%d = function(){\ |
||
8074 | schaersvoo | 5680 | set_reply_precision();\ |
7614 | schaersvoo | 5681 | var reply = new Array();\ |
5682 | var p = 0;\ |
||
5683 | while(userdraw_x[p]){\ |
||
5684 | reply[p] = userdraw_x[p] +\":\" + userdraw_y[p];\ |
||
5685 | p++;\ |
||
5686 | };\ |
||
11806 | schaersvoo | 5687 | if(p == 0){return;};\ |
7614 | schaersvoo | 5688 | if( document.getElementById(\"canvas_input0\") ){\ |
5689 | var p = 0;var input_reply = new Array();\ |
||
5690 | if( document.getElementById(\"canvas_input0\")){\ |
||
5691 | var t = 0;\ |
||
5692 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
5693 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
5694 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
5695 | p++;\ |
||
5696 | };\ |
||
5697 | t++;\ |
||
5698 | };\ |
||
5699 | };\ |
||
11088 | schaersvoo | 5700 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 5701 | return reply+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
5702 | }\ |
||
5703 | else\ |
||
5704 | {\ |
||
5705 | return reply+\"\\n\"+input_reply;\ |
||
5706 | }\ |
||
7862 | schaersvoo | 5707 | }\ |
7614 | schaersvoo | 5708 | else\ |
5709 | {\ |
||
11088 | schaersvoo | 5710 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 5711 | return reply+\"\\n\"+userdraw_text;\ |
5712 | }\ |
||
5713 | else\ |
||
5714 | {\ |
||
5715 | return reply;\ |
||
5716 | }\ |
||
5717 | };\ |
||
8108 | schaersvoo | 5718 | };\n\ |
8257 | schaersvoo | 5719 | <!-- end function 7 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 5720 | break; |
5721 | case 8: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 5722 | \n<!-- begin function 8 read_canvas%d() -->\n\ |
5723 | read_canvas%d = function(){\ |
||
7614 | schaersvoo | 5724 | var reply = new Array();\ |
5725 | var p = 0;\ |
||
8074 | schaersvoo | 5726 | var prec = %d;\ |
7614 | schaersvoo | 5727 | while(userdraw_x[p]){\ |
8074 | schaersvoo | 5728 | reply[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec +\":\" + (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\ |
7614 | schaersvoo | 5729 | p++;\ |
5730 | };\ |
||
11806 | schaersvoo | 5731 | if(p == 0){return;};\ |
7614 | schaersvoo | 5732 | if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\ |
5733 | var p = 0;var input_reply = new Array();\ |
||
5734 | if( document.getElementById(\"canvas_input0\")){\ |
||
5735 | var t = 0;\ |
||
5736 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
5737 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
5738 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
5739 | p++;\ |
||
5740 | };\ |
||
5741 | t++;\ |
||
5742 | };\ |
||
5743 | };\ |
||
11088 | schaersvoo | 5744 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 5745 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
5746 | }\ |
||
5747 | else\ |
||
5748 | {\ |
||
5749 | return reply +\"\\n\"+input_reply;\ |
||
5750 | }\ |
||
5751 | }\ |
||
5752 | else\ |
||
5753 | {\ |
||
11088 | schaersvoo | 5754 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 5755 | return reply +\"\\n\"+userdraw_text;\ |
5756 | }\ |
||
5757 | else\ |
||
5758 | {\ |
||
5759 | return reply;\ |
||
5760 | }\ |
||
5761 | };\ |
||
8108 | schaersvoo | 5762 | };\n\ |
8257 | schaersvoo | 5763 | <!-- end function 8 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7614 | schaersvoo | 5764 | break; |
5765 | case 9: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 5766 | \n<!-- begin function 9 read_canvas%d() -->\n\ |
5767 | read_canvas%d = function(){\ |
||
8074 | schaersvoo | 5768 | set_reply_precision();\ |
7614 | schaersvoo | 5769 | var reply = new Array();\ |
5770 | var p = 0;\ |
||
5771 | while(userdraw_x[p]){\ |
||
5772 | reply[p] = userdraw_x[p] +\":\" + userdraw_y[p] + \":\" + userdraw_radius[p];\ |
||
5773 | p++;\ |
||
5774 | };\ |
||
11806 | schaersvoo | 5775 | if(p == 0){return;};\ |
7614 | schaersvoo | 5776 | if( document.getElementById(\"canvas_input0\") ){\ |
5777 | var p = 0;var input_reply = new Array();\ |
||
5778 | if( document.getElementById(\"canvas_input0\")){\ |
||
5779 | var t = 0;\ |
||
5780 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
5781 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
5782 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
5783 | p++;\ |
||
5784 | };\ |
||
5785 | t++;\ |
||
5786 | };\ |
||
5787 | };\ |
||
11088 | schaersvoo | 5788 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 5789 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
5790 | }\ |
||
5791 | else\ |
||
5792 | {\ |
||
5793 | return reply +\"\\n\"+input_reply;\ |
||
5794 | }\ |
||
5795 | }\ |
||
5796 | else\ |
||
5797 | {\ |
||
11088 | schaersvoo | 5798 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 5799 | return reply +\"\\n\"+userdraw_text;\ |
5800 | }\ |
||
5801 | else\ |
||
5802 | {\ |
||
5803 | return reply;\ |
||
5804 | }\ |
||
5805 | };\ |
||
8108 | schaersvoo | 5806 | };\n\ |
8257 | schaersvoo | 5807 | <!-- end function 9 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 5808 | break; |
5809 | case 10: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 5810 | \n<!-- begin function 10 read_canvas%d() -->\n\ |
5811 | read_canvas%d = function(){\ |
||
7614 | schaersvoo | 5812 | var reply = new Array();\ |
5813 | var p = 0;\ |
||
8074 | schaersvoo | 5814 | var prec = %d;\ |
7614 | schaersvoo | 5815 | while(userdraw_x[p]){\ |
8074 | schaersvoo | 5816 | reply[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec +\":\" + (Math.round(prec*(px2y(userdraw_y[p]))))/prec +\":\" + (Math.round(prec*userdraw_radius[p]))/prec;\ |
7614 | schaersvoo | 5817 | p++;\ |
5818 | };\ |
||
11806 | schaersvoo | 5819 | if(p == 0){return;};\ |
7614 | schaersvoo | 5820 | if( document.getElementById(\"canvas_input0\") ){\ |
5821 | var p = 0;var input_reply = new Array();\ |
||
5822 | if( document.getElementById(\"canvas_input0\")){\ |
||
5823 | var t = 0;\ |
||
5824 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
5825 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
5826 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
5827 | p++;\ |
||
5828 | };\ |
||
5829 | t++;\ |
||
5830 | };\ |
||
5831 | };\ |
||
11088 | schaersvoo | 5832 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 5833 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
5834 | }\ |
||
5835 | else\ |
||
5836 | {\ |
||
5837 | return reply +\"\\n\"+input_reply;\ |
||
5838 | }\ |
||
5839 | }\ |
||
5840 | else\ |
||
5841 | {\ |
||
11088 | schaersvoo | 5842 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 5843 | return reply +\"\\n\"+userdraw_text;\ |
5844 | }\ |
||
5845 | else\ |
||
5846 | {\ |
||
5847 | return reply;\ |
||
5848 | }\ |
||
5849 | };\ |
||
8108 | schaersvoo | 5850 | };\n\ |
8257 | schaersvoo | 5851 | <!-- end function 10 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7614 | schaersvoo | 5852 | break; |
5853 | case 11: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 5854 | \n<!-- begin function 11 read_canvas%d() -->\n\ |
5855 | read_canvas%d = function(){\ |
||
7614 | schaersvoo | 5856 | var reply = \"\";\ |
5857 | var p = 0;\ |
||
8074 | schaersvoo | 5858 | var prec = %d;\ |
7614 | schaersvoo | 5859 | while(userdraw_x[p]){\ |
8074 | schaersvoo | 5860 | 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 | 5861 | p = p+2;\ |
5862 | };\ |
||
11806 | schaersvoo | 5863 | if(p == 0){return;};\ |
7614 | schaersvoo | 5864 | if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\ |
5865 | var p = 0;var input_reply = new Array();\ |
||
5866 | if( document.getElementById(\"canvas_input0\")){\ |
||
5867 | var t = 0;\ |
||
5868 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
5869 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
5870 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
5871 | p++;\ |
||
5872 | };\ |
||
5873 | t++;\ |
||
5874 | };\ |
||
5875 | };\ |
||
11088 | schaersvoo | 5876 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 5877 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
5878 | }\ |
||
5879 | else\ |
||
5880 | {\ |
||
5881 | return reply +\"\\n\"+input_reply;\ |
||
5882 | }\ |
||
5883 | }\ |
||
5884 | else\ |
||
5885 | {\ |
||
11088 | schaersvoo | 5886 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 5887 | return reply +\"\\n\"+userdraw_text;\ |
5888 | }\ |
||
5889 | else\ |
||
5890 | {\ |
||
5891 | return reply;\ |
||
5892 | }\ |
||
5893 | };\ |
||
8108 | schaersvoo | 5894 | };\n\ |
8257 | schaersvoo | 5895 | <!-- end function 11 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7614 | schaersvoo | 5896 | break; |
5897 | case 12: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 5898 | \n<!-- begin function 12 read_canvas%d() -->\n\ |
5899 | read_canvas%d = function(){\ |
||
8074 | schaersvoo | 5900 | set_reply_precision();\ |
7614 | schaersvoo | 5901 | var reply = \"\";\ |
5902 | var p = 0;\ |
||
5903 | for(p = 0; p< userdraw_x.lenght;p = p+2){\ |
||
5904 | if(userdraw_x[p] != null){\ |
||
5905 | reply = reply + userdraw_x[p] +\",\" + userdraw_y[p] +\",\" + userdraw_x[p+1] +\",\" + userdraw_y[p+1] +\"\\n\" ;\ |
||
5906 | };\ |
||
5907 | };\ |
||
11806 | schaersvoo | 5908 | if(p == 0){return;};\ |
7614 | schaersvoo | 5909 | if( document.getElementById(\"canvas_input0\") ){\ |
5910 | var p = 0;var input_reply = new Array();\ |
||
5911 | if( document.getElementById(\"canvas_input0\")){\ |
||
5912 | var t = 0;\ |
||
5913 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
5914 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
5915 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
5916 | p++;\ |
||
5917 | };\ |
||
5918 | t++;\ |
||
5919 | };\ |
||
5920 | };\ |
||
11088 | schaersvoo | 5921 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 5922 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
5923 | }\ |
||
5924 | else\ |
||
5925 | {\ |
||
5926 | return reply +\"\\n\"+input_reply;\ |
||
5927 | }\ |
||
5928 | }\ |
||
5929 | else\ |
||
5930 | {\ |
||
11088 | schaersvoo | 5931 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 5932 | return reply +\"\\n\"+userdraw_text\ |
5933 | }\ |
||
5934 | else\ |
||
5935 | {\ |
||
5936 | return reply;\ |
||
5937 | }\ |
||
5938 | };\ |
||
8108 | schaersvoo | 5939 | };\n\ |
8257 | schaersvoo | 5940 | <!-- end function 12 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 5941 | break; |
5942 | case 13: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 5943 | \n<!-- begin function 13 read_canvas%d() -->\n\ |
5944 | read_canvas%d = function(){\ |
||
7614 | schaersvoo | 5945 | var reply = new Array();\ |
5946 | var p = 0;var i = 0;\ |
||
8074 | schaersvoo | 5947 | var prec = %d;\ |
7614 | schaersvoo | 5948 | while(userdraw_x[p]){\ |
8074 | schaersvoo | 5949 | 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 | 5950 | p = p+2;i++;\ |
5951 | };\ |
||
11806 | schaersvoo | 5952 | if(p == 0){return;};\ |
7614 | schaersvoo | 5953 | if( document.getElementById(\"canvas_input0\") ){\ |
5954 | var p = 0;var input_reply = new Array();\ |
||
5955 | if( document.getElementById(\"canvas_input0\")){\ |
||
5956 | var t = 0;\ |
||
5957 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
5958 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
5959 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
5960 | p++;\ |
||
5961 | };\ |
||
5962 | t++;\ |
||
5963 | };\ |
||
5964 | };\ |
||
11088 | schaersvoo | 5965 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 5966 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
5967 | }\ |
||
5968 | else\ |
||
5969 | {\ |
||
5970 | return reply +\"\\n\"+input_reply;\ |
||
5971 | }\ |
||
5972 | }\ |
||
5973 | else\ |
||
5974 | {\ |
||
11088 | schaersvoo | 5975 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 5976 | return reply +\"\\n\"+userdraw_text\ |
5977 | }\ |
||
5978 | else\ |
||
5979 | {\ |
||
5980 | return reply;\ |
||
5981 | }\ |
||
5982 | };\ |
||
8108 | schaersvoo | 5983 | };\n\ |
8257 | schaersvoo | 5984 | <!-- end function 13 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7614 | schaersvoo | 5985 | break; |
5986 | case 14: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 5987 | \n<!-- begin function 14 read_canvas%d() -->\n\ |
5988 | read_canvas%d = function(){\ |
||
8074 | schaersvoo | 5989 | set_reply_precision();\ |
7614 | schaersvoo | 5990 | var reply = new Array();\ |
5991 | var p = 0;var i = 0;\ |
||
5992 | while(userdraw_x[p]){\ |
||
5993 | reply[i] = userdraw_x[p] +\":\" + userdraw_y[p] +\":\" + userdraw_x[p+1] +\":\" + userdraw_y[p+1];\ |
||
5994 | p = p+2;i++;\ |
||
5995 | };\ |
||
11806 | schaersvoo | 5996 | if(p == 0){return;};\ |
7614 | schaersvoo | 5997 | if( document.getElementById(\"canvas_input0\") ){\ |
5998 | var p = 0;var input_reply = new Array();\ |
||
5999 | if( document.getElementById(\"canvas_input0\")){\ |
||
6000 | var t = 0;\ |
||
6001 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
6002 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
6003 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
6004 | p++;\ |
||
6005 | };\ |
||
6006 | t++;\ |
||
6007 | };\ |
||
6008 | };\ |
||
11088 | schaersvoo | 6009 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6010 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
6011 | }\ |
||
6012 | else\ |
||
6013 | {\ |
||
6014 | return reply +\"\\n\"+input_reply;\ |
||
6015 | }\ |
||
6016 | }\ |
||
6017 | else\ |
||
6018 | {\ |
||
11088 | schaersvoo | 6019 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6020 | return reply +\"\\n\"+userdraw_text;\ |
6021 | }\ |
||
6022 | else\ |
||
6023 | {\ |
||
6024 | return reply;\ |
||
6025 | }\ |
||
6026 | };\ |
||
8108 | schaersvoo | 6027 | };\n\ |
8257 | schaersvoo | 6028 | <!-- end function 14 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 6029 | break; |
6030 | case 15: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 6031 | \n<!-- begin function 15 read_canvas%d() -->\n\ |
6032 | read_canvas%d = function(){\ |
||
7614 | schaersvoo | 6033 | var input_reply = new Array();\ |
6034 | var p = 0;\ |
||
6035 | if( document.getElementById(\"canvas_input0\")){\ |
||
6036 | var t = 0;\ |
||
6037 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
6038 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
6039 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
6040 | p++;\ |
||
6041 | };\ |
||
6042 | t++;\ |
||
6043 | };\ |
||
6044 | };\ |
||
11088 | schaersvoo | 6045 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6046 | return input_reply +\"\\n\"+userdraw_text;\ |
6047 | }\ |
||
6048 | else\ |
||
6049 | {\ |
||
6050 | return input_reply;\ |
||
6051 | };\ |
||
8108 | schaersvoo | 6052 | };\n\ |
8257 | schaersvoo | 6053 | <!-- end function 15 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 6054 | break; |
6055 | case 16: fprintf(js_include_file,"\ |
||
7653 | schaersvoo | 6056 | \n<!-- begin function 16 read_mathml() -->\n\ |
7614 | schaersvoo | 6057 | function read_mathml(){\ |
6058 | var reply = new Array();\ |
||
6059 | var p = 0;\ |
||
6060 | if( document.getElementById(\"mathml0\")){\ |
||
6061 | while(document.getElementById(\"mathml\"+p)){\ |
||
6062 | reply[p] = document.getElementById(\"mathml\"+p).value;\ |
||
6063 | p++;\ |
||
6064 | };\ |
||
6065 | };\ |
||
6066 | return reply;\ |
||
6067 | };\ |
||
6068 | this.read_mathml = read_mathml;\n\ |
||
7653 | schaersvoo | 6069 | <!-- end function 16 read_mathml() -->"); |
7614 | schaersvoo | 6070 | break; |
6071 | case 17: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 6072 | \n<!-- begin function 17 read_canvas%d() -->\n\ |
6073 | read_canvas%d = function(){\ |
||
11080 | schaersvoo | 6074 | var len = userdraw_x.length;\ |
6075 | if( len == 0){alert(\"no text typed...\");return;}\ |
||
6076 | var rep = px2x(userdraw_x[0])+\",\"+px2y(userdraw_y[0])+\",\"+userdraw_text[0];\ |
||
6077 | for(var p = 1 ; p < len ; p++){\ |
||
6078 | rep = rep + \"\\n\" + px2x(userdraw_x[p]) + \",\" + px2y(userdraw_y[p]) + \",\" + userdraw_text[p];\ |
||
6079 | };\ |
||
6080 | return rep;\ |
||
8108 | schaersvoo | 6081 | };\n\ |
8257 | schaersvoo | 6082 | <!-- end function 17 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 6083 | break; |
6084 | case 18: fprintf(js_include_file,"\ |
||
10956 | schaersvoo | 6085 | \n<!-- javascript has no real modulo function -->\n\ |
6086 | function mod(n, m){\ |
||
6087 | var m = parseInt(((n %% m) + m) %% m);\ |
||
6088 | return m;\ |
||
6089 | };\ |
||
8257 | schaersvoo | 6090 | \n<!-- begin function 18 read_canvas%d() -->\n\ |
6091 | read_canvas%d = function(){\ |
||
7614 | schaersvoo | 6092 | var p = 0;\ |
6093 | var reply = new Array();\ |
||
6094 | var name;\ |
||
6095 | var t = true;\ |
||
8000 | schaersvoo | 6096 | var h;var m;var s;\ |
7614 | schaersvoo | 6097 | while(t){\ |
8000 | schaersvoo | 6098 | try{\ |
6099 | name = eval('clocks'+p);\ |
||
6100 | h = name.H;m = name.M;s = name.S;\ |
||
10956 | schaersvoo | 6101 | h = mod((h+m/60+s/3600),12);m = mod((m + s/60),60);s = mod(s,60);\ |
8000 | schaersvoo | 6102 | reply[p] = h+\":\"+m+\":\"+s;\ |
6103 | p++;\ |
||
6104 | }catch(e){t=false;};\ |
||
7614 | schaersvoo | 6105 | };\ |
8000 | schaersvoo | 6106 | if( p == 0 ){alert(\"clock(s) not modified...\");return;}\ |
7614 | schaersvoo | 6107 | return reply;\ |
8108 | schaersvoo | 6108 | };\n\ |
8257 | schaersvoo | 6109 | <!-- end function 18 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 6110 | break; |
6111 | case 19: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 6112 | \n<!-- begin function 19 read_canvas%d() -->\n\ |
6113 | read_canvas%d = function(){\ |
||
7614 | schaersvoo | 6114 | return reply[0];\ |
8108 | schaersvoo | 6115 | };\n\ |
8257 | schaersvoo | 6116 | <!-- end function 19 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id); |
8130 | schaersvoo | 6117 | break; |
7614 | schaersvoo | 6118 | case 20: fprintf(js_include_file,"\ |
8257 | schaersvoo | 6119 | \n<!-- begin function 20 read_canvas%d() -->\n\ |
6120 | read_canvas%d = function(){\ |
||
8074 | schaersvoo | 6121 | var prec = %d;\ |
7614 | schaersvoo | 6122 | var len = ext_drag_images.length;\ |
6123 | var reply = new Array(len);\ |
||
6124 | for(var p = 0 ; p < len ; p++){\ |
||
6125 | var img = ext_drag_images[p];\ |
||
8556 | schaersvoo | 6126 | reply[p] = p+\":\"+(Math.round(prec*(px2x(img[6]))))/prec+\":\"+(Math.round(prec*(px2y(img[7]))))/prec;\ |
7614 | schaersvoo | 6127 | };\ |
6128 | return reply;\ |
||
8108 | schaersvoo | 6129 | };\n\ |
8257 | schaersvoo | 6130 | <!-- end function 20 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7614 | schaersvoo | 6131 | break; |
6132 | case 21: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 6133 | \n<!-- begin function 21 read_canvas%d() -->\n\ |
6134 | read_canvas%d = function(){\ |
||
7614 | schaersvoo | 6135 | if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\ |
6136 | var reply_coord = new Array();var p = 0;\ |
||
8074 | schaersvoo | 6137 | var prec = %d;\ |
7614 | schaersvoo | 6138 | while(userdraw_x[p]){\ |
8074 | schaersvoo | 6139 | reply_coord[p] = \"(\"+(Math.round(prec*(px2x(userdraw_x[p]))))/prec+\":\"+(Math.round(prec*(px2y(userdraw_y[p]))))/prec+\")\";\ |
7614 | schaersvoo | 6140 | p++;\ |
6141 | };\ |
||
11806 | schaersvoo | 6142 | if(p == 0){return;};\ |
7614 | schaersvoo | 6143 | if( document.getElementById(\"canvas_input0\") ){\ |
6144 | var p = 0;var input_reply = new Array();\ |
||
6145 | if( document.getElementById(\"canvas_input0\")){\ |
||
6146 | var t = 0;\ |
||
6147 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
6148 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
6149 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
6150 | p++;\ |
||
6151 | };\ |
||
6152 | t++;\ |
||
6153 | };\ |
||
6154 | };\ |
||
11088 | schaersvoo | 6155 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6156 | return reply_coord+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
6157 | }\ |
||
6158 | else\ |
||
6159 | {\ |
||
6160 | return reply_coord+\"\\n\"+input_reply;\ |
||
6161 | }\ |
||
6162 | }\ |
||
6163 | else\ |
||
6164 | {\ |
||
11088 | schaersvoo | 6165 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6166 | return reply_coord+\"\\n\"+userdraw_text;\ |
6167 | }\ |
||
6168 | else\ |
||
6169 | {\ |
||
6170 | return reply_coord;\ |
||
6171 | };\ |
||
6172 | };\ |
||
8108 | schaersvoo | 6173 | };\n\ |
8257 | schaersvoo | 6174 | <!-- end function 21 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7614 | schaersvoo | 6175 | break; |
6176 | case 22: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 6177 | \n<!-- begin function 22 read_canvas%d() -->\n\ |
6178 | read_canvas%d = function(){\ |
||
7614 | schaersvoo | 6179 | var reply = new Array();\ |
7963 | schaersvoo | 6180 | var lu = userdraw_x.length;\ |
11806 | schaersvoo | 6181 | if(lu == 0){return;};\ |
7614 | schaersvoo | 6182 | var idx = 0;\ |
8074 | schaersvoo | 6183 | var prec = %d;\ |
7963 | schaersvoo | 6184 | for(var p = 0 ; p < lu ; p++){\ |
8074 | schaersvoo | 6185 | reply[idx] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;idx++;\ |
6186 | reply[idx] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;idx++;\ |
||
7614 | schaersvoo | 6187 | };\ |
6188 | if( document.getElementById(\"canvas_input0\") ){\ |
||
6189 | var p = 0;var input_reply = new Array();\ |
||
6190 | if( document.getElementById(\"canvas_input0\")){\ |
||
6191 | var t = 0;\ |
||
6192 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
6193 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
6194 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
6195 | p++;\ |
||
6196 | };\ |
||
6197 | t++;\ |
||
6198 | };\ |
||
6199 | };\ |
||
11088 | schaersvoo | 6200 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6201 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
6202 | }\ |
||
6203 | else\ |
||
6204 | {\ |
||
6205 | return reply +\"\\n\"+input_reply;\ |
||
6206 | }\ |
||
6207 | }\ |
||
6208 | else\ |
||
6209 | {\ |
||
11088 | schaersvoo | 6210 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6211 | return reply +\"\\n\"+userdraw_text;\ |
6212 | }\ |
||
6213 | else\ |
||
6214 | {\ |
||
6215 | return reply;\ |
||
6216 | }\ |
||
6217 | };\ |
||
8108 | schaersvoo | 6218 | };\n\ |
8257 | schaersvoo | 6219 | <!-- end function 22 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7614 | schaersvoo | 6220 | break; |
7782 | schaersvoo | 6221 | case 23: fprintf(js_include_file,"\ |
8257 | schaersvoo | 6222 | \n<!-- begin function 23 read_canvas%d() default 5 px marge -->\n\ |
6223 | read_canvas%d = function(){\ |
||
7782 | schaersvoo | 6224 | if( userdraw_x.length < 2){alert(\"nothing drawn...\");return;}\ |
6225 | var lu = userdraw_x.length;\ |
||
6226 | if( lu != userdraw_y.length ){ alert(\"x / y mismatch !\");return;}\ |
||
7962 | schaersvoo | 6227 | var reply_x = new Array();var reply_y = new Array();\ |
6228 | var marge = 5;var p = 0;\ |
||
8074 | schaersvoo | 6229 | var prec = %d;\ |
7782 | schaersvoo | 6230 | for(var i = 0; i < lu - 1 ; i++ ){\ |
10987 | schaersvoo | 6231 | if( Math.abs(userdraw_x[i] - userdraw_x[i+1]) || Math.abs(userdraw_y[i] - userdraw_y[i+1])){\ |
8074 | schaersvoo | 6232 | reply_x[p] = (Math.round(prec*(px2x(userdraw_x[i]))))/prec;reply_y[p] = (Math.round(prec*(px2y(userdraw_y[i]))))/prec;\ |
7962 | schaersvoo | 6233 | if( isNaN(reply_x[p]) || isNaN(reply_y[p]) ){ alert(\"hmmmm ?\");return; };\ |
6234 | p++;\ |
||
7782 | schaersvoo | 6235 | };\ |
8074 | schaersvoo | 6236 | 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 | 6237 | };\ |
6238 | if( document.getElementById(\"canvas_input0\")){\ |
||
6239 | var p = 0;var input_reply = new Array();\ |
||
6240 | if( document.getElementById(\"canvas_input0\")){\ |
||
6241 | var t = 0;\ |
||
6242 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
6243 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
6244 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
6245 | p++;\ |
||
6246 | };\ |
||
6247 | t++;\ |
||
6248 | };\ |
||
6249 | };\ |
||
11088 | schaersvoo | 6250 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7782 | schaersvoo | 6251 | return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
6252 | }\ |
||
6253 | else\ |
||
6254 | {\ |
||
6255 | return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply;\ |
||
6256 | }\ |
||
6257 | }\ |
||
6258 | else\ |
||
6259 | {\ |
||
11088 | schaersvoo | 6260 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7782 | schaersvoo | 6261 | return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_text;\ |
6262 | }\ |
||
6263 | else\ |
||
6264 | {\ |
||
6265 | return reply_x+\"\\n\"+reply_y;\ |
||
6266 | };\ |
||
6267 | };\ |
||
8108 | schaersvoo | 6268 | };\n\ |
8257 | schaersvoo | 6269 | <!-- end function 23 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7782 | schaersvoo | 6270 | break; |
7984 | schaersvoo | 6271 | case 24: fprintf(js_include_file,"\n\ |
8257 | schaersvoo | 6272 | <!-- begin function 24 read_canvas%d() -->\n\ |
6273 | read_canvas%d = function(){\ |
||
7984 | schaersvoo | 6274 | var input_reply = new Array();\ |
6275 | var p = 0;\ |
||
6276 | if( document.getElementById(\"canvas_input0\")){\ |
||
6277 | while(document.getElementById(\"canvas_input\"+p)){\ |
||
6278 | input_reply[p] = document.getElementById(\"canvas_input\"+p).value;\ |
||
6279 | p++;\ |
||
6280 | };\ |
||
6281 | return input_reply;\ |
||
6282 | };\ |
||
8108 | schaersvoo | 6283 | };\n\ |
8257 | schaersvoo | 6284 | <!-- end function 24 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id); |
7984 | schaersvoo | 6285 | break; |
8083 | schaersvoo | 6286 | case 25: |
8257 | schaersvoo | 6287 | fprintf(js_include_file,"\n<!-- begin function 25 read_canvas%d() : angle(s) in degrees-->\n\ |
6288 | read_canvas%d = function(){\ |
||
8083 | schaersvoo | 6289 | if( userdraw_radius.length < 1){alert(\"nothing drawn...\");return;}\ |
6290 | var lu = userdraw_radius.length;\ |
||
6291 | var prec = %d;\ |
||
6292 | var angle_reply = new Array(lu);\ |
||
6293 | for(var p = 0 ; p < lu ; p++){\ |
||
6294 | angle_reply[p] = (Math.round(prec*180*(userdraw_radius[p])/Math.PI))/prec;\ |
||
6295 | };\ |
||
6296 | return angle_reply;\ |
||
8108 | schaersvoo | 6297 | };\n\ |
8257 | schaersvoo | 6298 | <!-- end function 25 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
8083 | schaersvoo | 6299 | break; |
6300 | case 26: |
||
8257 | schaersvoo | 6301 | fprintf(js_include_file,"\n<!-- begin function 26 read_canvas%d() : angle(s) in radians-->\n\ |
6302 | read_canvas%d = function(){\ |
||
8083 | schaersvoo | 6303 | if( userdraw_radius.length < 1){alert(\"nothing drawn...\");return;}\ |
6304 | var lu = userdraw_radius.length;\ |
||
6305 | var prec = %d;\ |
||
6306 | var angle_reply = new Array(lu);\ |
||
6307 | for(var p = 0 ; p < lu ; p++){\ |
||
6308 | angle_reply[p] = (Math.round(prec*(userdraw_radius[p])))/prec;\ |
||
6309 | };\ |
||
6310 | return angle_reply;\ |
||
8108 | schaersvoo | 6311 | };\n\ |
8257 | schaersvoo | 6312 | <!-- end function 26 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
8083 | schaersvoo | 6313 | break; |
8127 | schaersvoo | 6314 | case 27: |
8257 | schaersvoo | 6315 | fprintf(js_include_file,"\n<!-- begin function 27 read_canvas%d() : inputfield(s) location and their values : -->\n\ |
6316 | read_canvas%d = function(){\ |
||
8127 | schaersvoo | 6317 | var lu = userdraw_x.length;\ |
6318 | if( lu < 1){alert(\"nothing drawn...\");return;}\ |
||
6319 | set_reply_precision();\ |
||
6320 | var prec = %d;\ |
||
11080 | schaersvoo | 6321 | var rep = (Math.round(prec*(px2x(userdraw_x[p]))))/prec+\",\"+(Math.round(prec*(px2y(userdraw_y[p]))))/prec+\",\"+ document.getElementById(\"canvas_input\"+p).value;\ |
8127 | schaersvoo | 6322 | for(var p = 0 ; p < lu ; p++){\ |
11080 | schaersvoo | 6323 | rep = rep = \"\\n\" + (Math.round(prec*(px2x(userdraw_x[p]))))/prec+\":\"+(Math.round(prec*(px2y(userdraw_y[p]))))/prec+\":\"+ document.getElementById(\"canvas_input\"+p).value;\ |
8127 | schaersvoo | 6324 | };\ |
11080 | schaersvoo | 6325 | return rep;\ |
8127 | schaersvoo | 6326 | };\n\ |
8257 | schaersvoo | 6327 | <!-- end function 27 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
8127 | schaersvoo | 6328 | break; |
8322 | schaersvoo | 6329 | case 28: |
6330 | fprintf(js_include_file,"\n<!-- begin function 28 read_canvas%d() -->\n\ |
||
6331 | read_canvas%d = function(){\ |
||
6332 | var prec = %d;\ |
||
6333 | var reply = new Array();var p = 0;\ |
||
6334 | var idx = 0;\ |
||
6335 | while(userdraw_x[p]){\ |
||
6336 | reply[idx] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\ |
||
6337 | idx++;\ |
||
6338 | reply[idx] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\ |
||
6339 | idx++;\ |
||
6340 | reply[idx] = (Math.round(prec*(px2x(userdraw_radius[p]) - px2x(0))))/prec;\ |
||
6341 | idx++;\ |
||
6342 | p++;\ |
||
6343 | };\ |
||
6344 | if( p == 0){alert(\"nothing drawn...\");return;}\ |
||
6345 | return reply;\ |
||
6346 | };\n\ |
||
9213 | schaersvoo | 6347 | <!-- end function 28 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
8322 | schaersvoo | 6348 | break; |
9213 | schaersvoo | 6349 | case 29: |
6350 | fprintf(js_include_file,"\n<!-- begin function 29 read_canvas%d() -->\n\ |
||
6351 | function xy_precision(array_x,array_y){\ |
||
6352 | var len = array_x.length;\ |
||
6353 | var x_array = new Array(len);\ |
||
6354 | var y_array = new Array(len);\ |
||
6355 | var prec = %d;\ |
||
6356 | for(var p = 0 ; p < len ; p++ ){\ |
||
6357 | x_array[p] = (Math.round(prec*(px2x(array_x[p]))))/prec;\ |
||
6358 | y_array[p] = (Math.round(prec*(px2y(array_y[p]))))/prec;\ |
||
6359 | };\ |
||
9230 | schaersvoo | 6360 | return x_array+\";\"+y_array;\ |
9213 | schaersvoo | 6361 | };\n\ |
6362 | function round_to_pixel(array_r){\ |
||
6363 | var len = array_r.length;\ |
||
6364 | for(var p = 0 ; p < len ; p++ ){\ |
||
6365 | array_r[p] = Math.round(array_r[p]);\ |
||
6366 | };\ |
||
6367 | return array_r;\ |
||
6368 | };\ |
||
6369 | read_canvas%d = function(){\ |
||
9300 | schaersvoo | 6370 | var reply=\" \";\ |
6371 | if( points_x && points_x.length > 0 ){reply = reply + xy_precision(points_x,points_y)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\ |
||
6372 | if( circles_x && circles_x.length > 0 ){ reply = reply + xy_precision(circles_x,circles_y)+\";\"+round_to_pixel(multi_radius)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\ |
||
6373 | if( segments_x && segments_x.length > 0 ){ reply = reply + xy_precision(segments_x,segments_y)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\ |
||
6374 | if( arrows_x && arrows_x.length > 0 ){ reply = reply + xy_precision(arrows_x,arrows_y)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\ |
||
6375 | if( lines_x && lines_x.length > 0 ){ reply = reply + xy_precision(lines_x,lines_y)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\ |
||
6376 | if( triangles_x && triangles_x.length > 0){ reply = reply + xy_precision(triangles_x,triangles_y)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\ |
||
11226 | schaersvoo | 6377 | if( polys_x && polys_x.length > 0){ reply = reply + xy_precision(polys_x,polys_y)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\ |
9372 | schaersvoo | 6378 | if( rects_x && rects_x.length > 0 ){ reply = reply + xy_precision(rects_x,rects_y)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\ |
9300 | schaersvoo | 6379 | if( closedpoly_x && closedpoly_x.length > 0){ closedpoly_x.pop();closedpoly_y.pop();reply = reply + xy_precision(closedpoly_x,closedpoly_y)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\ |
11230 | schaersvoo | 6380 | if( parallelogram_x && parallelogram_x.length > 0){ reply = reply + xy_precision(parallelogram_x,parallelogram_y)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\ |
9338 | schaersvoo | 6381 | if( text_x && text_x.length > 0){ reply = reply + xy_precision(text_x,text_y)+\";\"+text_abc+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\ |
9213 | schaersvoo | 6382 | return reply;\ |
6383 | };\n\ |
||
6384 | <!-- end function 29 read_canvas%d() -->",canvas_root_id,reply_precision,canvas_root_id,canvas_root_id); |
||
6385 | break; |
||
9289 | schaersvoo | 6386 | case 30: |
6387 | fprintf(js_include_file,"\n<!-- begin function 30 read_canvas%d() -->\n\ |
||
6388 | read_canvas%d = function(){\ |
||
6389 | var reply = new Array(3);\ |
||
6390 | var prec = %d;\ |
||
6391 | reply[0] = (Math.round(prec*(px2x(protractor_data[0]))))/prec;\ |
||
6392 | reply[1] = (Math.round(prec*(px2y(protractor_data[1]))))/prec;\ |
||
6393 | reply[2] = (Math.round(prec*(protractor_data[2])))/prec;\ |
||
6394 | return reply;\ |
||
6395 | };\n\ |
||
6396 | <!-- end function 30 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
||
6397 | break; |
||
6398 | case 31: |
||
6399 | fprintf(js_include_file,"\n<!-- begin function 31 read_canvas%d() -->\n\ |
||
6400 | read_canvas%d = function(){\ |
||
6401 | var reply = new Array(3);\ |
||
6402 | var prec = %d;\ |
||
6403 | reply[0] = (Math.round(prec*(px2x(ruler_data[0]))))/prec;\ |
||
6404 | reply[1] = (Math.round(prec*(px2y(ruler_data[1]))))/prec;\ |
||
6405 | reply[2] = (Math.round(prec*(ruler_data[2])))/prec;\ |
||
6406 | return reply;\ |
||
6407 | };\n\ |
||
6408 | <!-- end function 31 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
||
6409 | break; |
||
6410 | case 32: |
||
6411 | fprintf(js_include_file,"\n<!-- begin function 32 read_canvas%d() -->\n\ |
||
6412 | read_canvas%d = function(){\ |
||
6413 | var reply = new Array(6);\ |
||
6414 | var prec = %d;\ |
||
6415 | reply[0] = (Math.round(prec*(px2x(ruler_data[0]))))/prec;\ |
||
6416 | reply[1] = (Math.round(prec*(px2y(ruler_data[1]))))/prec;\ |
||
6417 | reply[2] = (Math.round(prec*(ruler_data[2])))/prec;\ |
||
6418 | reply[3] = (Math.round(prec*(px2x(protractor_data[0]))))/prec;\ |
||
6419 | reply[4] = (Math.round(prec*(px2y(protractor_data[1]))))/prec;\ |
||
6420 | reply[5] = (Math.round(prec*(protractor_data[2])))/prec;\ |
||
6421 | return reply;\ |
||
6422 | };\n\ |
||
6423 | <!-- end function 32 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
||
6424 | break; |
||
7614 | schaersvoo | 6425 | default: canvas_error("hmmm unknown replyformat...");break; |
6426 | } |
||
6427 | return; |
||
6428 | } |
||
6429 | |||
6430 | |||
8224 | bpr | 6431 | /* |
6432 | add drawfunction : |
||
7614 | schaersvoo | 6433 | - functions used by userdraw_primitives (circle,rect,path,triangle...) |
6434 | - things not covered by the drag&drop library (static objects like parallel, lattice ,gridfill , imagefill) |
||
6435 | - grid / mathml |
||
6436 | - will not scale or zoom in |
||
6437 | - will not be filled via pixel operations like fill / floodfill / filltoborder / clickfill |
||
8224 | bpr | 6438 | - is printed directly into 'js_include_file' |
7614 | schaersvoo | 6439 | */ |
6440 | |||
11021 | schaersvoo | 6441 | void add_javascript_function(int js_function[],int canvas_root_id){ |
7614 | schaersvoo | 6442 | int i; |
6443 | for(i = 0 ; i < MAX_JS_FUNCTIONS; i++){ |
||
11017 | schaersvoo | 6444 | if( js_function[i] == 1){ |
7614 | schaersvoo | 6445 | switch(i){ |
11026 | bpr | 6446 | case JS_FIND_ANGLE: |
11025 | schaersvoo | 6447 | fprintf(js_include_file,"\n\ |
6448 | <!-- function find_angle() -->\n\ |
||
6449 | function find_angle(xc,yc,x1,y1){\ |
||
11019 | schaersvoo | 6450 | var dx = x1 - xc;\ |
6451 | var dy = yc - y1;\ |
||
6452 | if( dx > 0 && dy < 0){ return Math.atan(-1*dy/dx);};\ |
||
6453 | if( dx < 0 && dy < 0){ return Math.PI + Math.atan(-1*dy/dx);};\ |
||
6454 | if( dx < 0 && dy > 0){ return Math.PI + Math.atan(-1*dy/dx);};\ |
||
6455 | if( dx > 0 && dy > 0){ return 2*Math.PI + Math.atan(-1*dy/dx);};};"); |
||
11017 | schaersvoo | 6456 | break; |
8448 | schaersvoo | 6457 | case DRAW_EXTERNAL_IMAGE: |
10953 | bpr | 6458 | /* the external_canvas is already created: it needs to be FIRST in order to do some drawing onto it |
8448 | schaersvoo | 6459 | draw_external_image(URL,int_data[2],int_data[3],int_data[6],int_data[7],int_data[0],int_data[1],int_data[6],int_data[7],ext_img_cnt,int_data[8],int_data[9]); |
6460 | */ |
||
7614 | schaersvoo | 6461 | fprintf(js_include_file,"\n<!-- drag external images --->\n\ |
7653 | schaersvoo | 6462 | var external_ctx = external_canvas.getContext(\"2d\");\ |
6463 | var external_canvas_rect = external_canvas.getBoundingClientRect();\ |
||
6464 | canvas_div.addEventListener(\"mousedown\",setxy,false);\ |
||
6465 | canvas_div.addEventListener(\"mouseup\",dragstop,false);\ |
||
6466 | canvas_div.addEventListener(\"mousemove\",dragxy,false);\ |
||
6467 | var selected_image = null;\ |
||
6468 | var ext_image_cnt = 0;\ |
||
6469 | var ext_drag_images = new Array();\ |
||
8448 | schaersvoo | 6470 | function draw_external_image(URL,sx,sy,swidth,sheight,x0,y0,width,height,idx,resizable,draggable,click_cnt){\ |
7653 | schaersvoo | 6471 | ext_image_cnt = idx;\ |
8448 | schaersvoo | 6472 | if(draggable == 1 ){\ |
6473 | reply[click_cnt] = 0;\ |
||
6474 | };\ |
||
7653 | schaersvoo | 6475 | var image = new Image();\ |
6476 | image.src = URL;\ |
||
6477 | image.onload = function(){\ |
||
8448 | schaersvoo | 6478 | if( sx < 1 ){ sx = 0; };\ |
6479 | if( sy < 1 ){ sy = 0; };\ |
||
6480 | if( swidth < 1 ){swidth = image.width;};\ |
||
6481 | if( sheight < 1 ){sheight = image.height;};\ |
||
6482 | if( width < 1 ){width = image.width;};\ |
||
6483 | if( height < 1 ){height = image.height;};\ |
||
6484 | if( resizable == 0 ){\ |
||
6485 | if( swidth > image.width ){ swidth = image.width; };\ |
||
6486 | if( sheight > image.height){ sheight = image.height;};\ |
||
6487 | if( width > image.width ){ width = image.width; };\ |
||
6488 | if( height > image.height){ height = image.height;};\ |
||
6489 | };\ |
||
6490 | var img = new Array(11);\ |
||
7653 | schaersvoo | 6491 | img[0] = draggable;img[1] = image;img[2] = sx;img[3] = sy;img[4] = swidth;img[5] = sheight;\ |
8448 | schaersvoo | 6492 | img[6] = x0;img[7] = y0;img[8] = width;img[9] = height;img[10] = click_cnt;\ |
7653 | schaersvoo | 6493 | ext_drag_images[idx] = img;\ |
6494 | external_ctx.drawImage(img[1],img[2],img[3],img[4],img[5],img[6],img[7],img[8],img[9]);\ |
||
6495 | };\ |
||
6496 | };\ |
||
6497 | function dragstop(evt){\ |
||
6498 | selected_image = null;return;\ |
||
6499 | };\ |
||
6500 | function dragxy(evt){\ |
||
6501 | if( selected_image != null ){\ |
||
6502 | var xoff = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);\ |
||
6503 | var yoff = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);\ |
||
6504 | var s_img = ext_drag_images[selected_image];\ |
||
6505 | s_img[6] = evt.clientX - external_canvas_rect.left + xoff;\ |
||
6506 | s_img[7] = evt.clientY - external_canvas_rect.top + yoff;\ |
||
8386 | schaersvoo | 6507 | if( use_snap_to_points == 1){\ |
6508 | var img_xy = snap_to_points(s_img[6],s_img[7]);\ |
||
6509 | s_img[6] = img_xy[0];s_img[7] = img_xy[1];\ |
||
6510 | }\ |
||
6511 | else\ |
||
6512 | {\ |
||
6513 | if( x_use_snap_to_grid == 1 ){\ |
||
6514 | s_img[6] = snap_to_x(s_img[6]);\ |
||
6515 | };\ |
||
6516 | if( y_use_snap_to_grid == 1 ){\ |
||
6517 | s_img[7] = snap_to_x(s_img[7]);\ |
||
6518 | };\ |
||
6519 | };\ |
||
7653 | schaersvoo | 6520 | ext_drag_images[selected_image] = s_img;\ |
6521 | external_ctx.clearRect(0,0,xsize,ysize);\ |
||
6522 | for(var i = 0; i <= ext_image_cnt ; i++){\ |
||
6523 | var img = ext_drag_images[i];\ |
||
6524 | external_ctx.drawImage(img[1],img[2],img[3],img[4],img[5],img[6],img[7],img[8],img[9]);\ |
||
6525 | };\ |
||
6526 | };\ |
||
6527 | };\ |
||
6528 | function setxy(evt){\ |
||
6529 | if( ! selected_image && evt.which == 1 ){\ |
||
6530 | var xoff = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);\ |
||
6531 | var yoff = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);\ |
||
6532 | var xm = evt.clientX - external_canvas_rect.left + xoff;\ |
||
6533 | var ym = evt.clientY - external_canvas_rect.top + yoff;\ |
||
8448 | schaersvoo | 6534 | var img;\ |
7653 | schaersvoo | 6535 | for(var p = 0 ; p <= ext_image_cnt ; p++){\ |
8448 | schaersvoo | 6536 | if( ext_drag_images[p] ){\ |
6537 | img = ext_drag_images[p];\ |
||
6538 | if( img[0] != 0 ){\ |
||
6539 | if( xm > img[6] && xm < img[6] + img[8]){\ |
||
6540 | if( ym > img[7] && ym < img[7] + img[9]){\ |
||
6541 | if( img[0] == 1){\ |
||
6542 | if( reply[img[10]] == 1 ){\ |
||
6543 | reply[img[10]] = 0;external_ctx.strokeStyle = '#ffffff';\ |
||
6544 | }\ |
||
6545 | else\ |
||
6546 | {\ |
||
6547 | reply[img[10]] = 1;external_ctx.strokeStyle = '#00ff00';\ |
||
6548 | };\ |
||
6549 | external_ctx.lineWidth = 6;\ |
||
6550 | external_ctx.beginPath();\ |
||
6551 | external_ctx.rect(img[6],img[7],img[8],img[9]);\ |
||
6552 | external_ctx.closePath();\ |
||
6553 | external_ctx.stroke();\ |
||
6554 | return;\ |
||
6555 | }\ |
||
6556 | else\ |
||
6557 | {\ |
||
6558 | img[6] = xm;\ |
||
6559 | img[7] = ym;\ |
||
6560 | ext_drag_images[p] = img;\ |
||
6561 | selected_image = p;\ |
||
6562 | dragxy(evt);\ |
||
6563 | };\ |
||
6564 | };\ |
||
7653 | schaersvoo | 6565 | };\ |
6566 | };\ |
||
6567 | };\ |
||
6568 | };\ |
||
6569 | }\ |
||
6570 | else\ |
||
6571 | {\ |
||
6572 | selected_image = null;\ |
||
6573 | };\ |
||
8448 | schaersvoo | 6574 | };"); |
7614 | schaersvoo | 6575 | break; |
8370 | schaersvoo | 6576 | case DRAW_BEZIER: |
6577 | fprintf(js_include_file,"\n<!-- draw bezier curve -->\n\ |
||
6578 | 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){\ |
||
6579 | var obj;\ |
||
6580 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
6581 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
6582 | }\ |
||
6583 | else\ |
||
6584 | {\ |
||
6585 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
6586 | };\ |
||
6587 | var ctx = obj.getContext(\"2d\");\ |
||
6588 | ctx.save();\ |
||
6589 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
6590 | ctx.lineWidth = linewidth;\ |
||
11088 | schaersvoo | 6591 | if(linewidth%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
8370 | schaersvoo | 6592 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);};\ |
6593 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);};\ |
||
6594 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
6595 | ctx.beginPath();\ |
||
6596 | ctx.moveTo(x2px(xy_points[0]),y2px(xy_points[1]));\ |
||
6597 | 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]));\ |
||
6598 | if(use_filled == 1){ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();}\ |
||
6599 | ctx.stroke();\ |
||
6600 | ctx.restore();\ |
||
6601 | };\n",canvas_root_id,canvas_root_id,canvas_root_id); |
||
6602 | break; |
||
7614 | schaersvoo | 6603 | case DRAW_GRIDFILL:/* not used for userdraw */ |
6604 | fprintf(js_include_file,"\n<!-- draw gridfill -->\n\ |
||
8105 | schaersvoo | 6605 | var draw_gridfill = function(canvas_type,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize){\ |
7614 | schaersvoo | 6606 | var obj;\ |
6607 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
6608 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
6609 | }\ |
||
6610 | else\ |
||
6611 | {\ |
||
6612 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
6613 | };\ |
||
6614 | var ctx = obj.getContext(\"2d\");\ |
||
6615 | var x,y;\ |
||
7883 | schaersvoo | 6616 | snap_x = dx;snap_y = dy;\ |
7614 | schaersvoo | 6617 | ctx.save();\ |
9462 | schaersvoo | 6618 | ctx.lineWidth = line_width;\ |
11088 | schaersvoo | 6619 | if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
7614 | schaersvoo | 6620 | ctx.strokeStyle=\"rgba(\"+color+\",\"+opacity+\")\";\ |
6621 | for( x = x0 ; x < xsize+dx ; x = x + dx ){\ |
||
6622 | ctx.moveTo(x,y0);\ |
||
6623 | ctx.lineTo(x,ysize);\ |
||
6624 | };\ |
||
7645 | schaersvoo | 6625 | for( y = y0 ; y < ysize+dy; y = y + dy ){\ |
7614 | schaersvoo | 6626 | ctx.moveTo(x0,y);\ |
6627 | ctx.lineTo(xsize,y);\ |
||
6628 | };\ |
||
6629 | ctx.stroke();\ |
||
6630 | ctx.restore();\ |
||
7653 | schaersvoo | 6631 | return;};",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 6632 | break; |
8224 | bpr | 6633 | |
7614 | schaersvoo | 6634 | case DRAW_IMAGEFILL:/* not used for userdraw */ |
6635 | fprintf(js_include_file,"\n<!-- draw imagefill -->\n\ |
||
8105 | schaersvoo | 6636 | var draw_imagefill = function(canvas_type,x0,y0,URL,xsize,ysize){\ |
7614 | schaersvoo | 6637 | var obj;\ |
6638 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
6639 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
6640 | }\ |
||
6641 | else\ |
||
6642 | {\ |
||
6643 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
6644 | };\ |
||
6645 | var ctx = obj.getContext(\"2d\");\ |
||
6646 | ctx.save();\ |
||
6647 | var img = new Image();\ |
||
6648 | img.src = URL;\ |
||
6649 | img.onload = function(){\ |
||
6650 | if( (img.width > xsize-x0) && (img.height > ysize-y0) ){\ |
||
6651 | ctx.drawImage(img,x0,y0,xsize,ysize);\ |
||
6652 | }\ |
||
6653 | else\ |
||
6654 | {\ |
||
6655 | var repeat = \"repeat\";\ |
||
6656 | if(img.width > xsize - x0){\ |
||
6657 | repeat = \"repeat-y\";\ |
||
6658 | }\ |
||
6659 | else\ |
||
6660 | {\ |
||
6661 | if( img.height > ysize -x0 ){\ |
||
6662 | repeat = \"repeat-x\";\ |
||
6663 | }\ |
||
6664 | }\ |
||
6665 | var pattern = ctx.createPattern(img,repeat);\ |
||
6666 | ctx.rect(x0,y0,xsize,ysize);\ |
||
6667 | ctx.fillStyle = pattern;\ |
||
6668 | }\ |
||
6669 | ctx.fill();\ |
||
6670 | };\ |
||
6671 | ctx.restore();\ |
||
6672 | return;\ |
||
7653 | schaersvoo | 6673 | };",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 6674 | break; |
8224 | bpr | 6675 | |
7614 | schaersvoo | 6676 | case DRAW_DOTFILL:/* not used for userdraw */ |
6677 | fprintf(js_include_file,"\n<!-- draw dotfill -->\n\ |
||
8105 | schaersvoo | 6678 | var draw_dotfill = function(canvas_type,x0,y0,dx,dy,radius,color,opacity,xsize,ysize){\ |
7614 | schaersvoo | 6679 | var obj;\ |
6680 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
6681 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
6682 | }\ |
||
6683 | else\ |
||
6684 | {\ |
||
6685 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
6686 | };\ |
||
6687 | var ctx = obj.getContext(\"2d\");\ |
||
6688 | var x,y;\ |
||
6689 | ctx.closePath();\ |
||
6690 | ctx.save();\ |
||
7645 | schaersvoo | 6691 | snap_x = dx;snap_y = dy;\ |
7614 | schaersvoo | 6692 | ctx.fillStyle=\"rgba(\"+color+\",\"+opacity+\")\";\ |
6693 | for( x = x0 ; x < xsize+dx ; x = x + dx ){\ |
||
6694 | for( y = y0 ; y < ysize+dy ; y = y + dy ){\ |
||
6695 | ctx.arc(x,y,radius,0,2*Math.PI,false);\ |
||
6696 | ctx.closePath();\ |
||
6697 | }\ |
||
6698 | }\ |
||
6699 | ctx.fill();\ |
||
6700 | ctx.restore();\ |
||
7653 | schaersvoo | 6701 | return;};",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 6702 | break; |
7645 | schaersvoo | 6703 | |
7647 | schaersvoo | 6704 | case DRAW_DIAMONDFILL:/* not used for userdraw */ |
7614 | schaersvoo | 6705 | fprintf(js_include_file,"\n<!-- draw hatch fill -->\n\ |
8105 | schaersvoo | 6706 | var draw_diamondfill = function(canvas_type,x0,y0,dx,dy,linewidth,stroke_color,stroke_opacity,xsize,ysize){\ |
7614 | schaersvoo | 6707 | var obj;\ |
6708 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
6709 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
6710 | }\ |
||
6711 | else\ |
||
6712 | {\ |
||
6713 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
6714 | };\ |
||
6715 | var ctx = obj.getContext(\"2d\");\ |
||
6716 | var x;\ |
||
6717 | var y;\ |
||
6718 | ctx.save();\ |
||
6719 | ctx.lineWidth = linewidth;\ |
||
11088 | schaersvoo | 6720 | if(linewidth%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
7614 | schaersvoo | 6721 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
6722 | y = ysize;\ |
||
6723 | for( x = x0 ; x < xsize ; x = x + dx ){\ |
||
6724 | ctx.moveTo(x,y0);\ |
||
6725 | ctx.lineTo(xsize,y);\ |
||
6726 | y = y - dy;\ |
||
6727 | };\ |
||
6728 | y = y0;\ |
||
6729 | for( x = xsize ; x > 0 ; x = x - dx){\ |
||
6730 | ctx.moveTo(x,ysize);\ |
||
6731 | ctx.lineTo(x0,y);\ |
||
6732 | y = y + dy;\ |
||
6733 | };\ |
||
6734 | x = x0;\ |
||
6735 | for( y = y0 ; y < ysize ; y = y + dy ){\ |
||
6736 | ctx.moveTo(xsize,y);\ |
||
6737 | ctx.lineTo(x,ysize);\ |
||
6738 | x = x + dx;\ |
||
6739 | };\ |
||
6740 | x = xsize;\ |
||
6741 | for( y = ysize ; y > y0 ; y = y - dy ){\ |
||
6742 | ctx.moveTo(x,y0);\ |
||
6743 | ctx.lineTo(x0,y);\ |
||
6744 | x = x - dx;\ |
||
6745 | };\ |
||
6746 | ctx.stroke();\ |
||
6747 | ctx.restore();\ |
||
6748 | return;\ |
||
7653 | schaersvoo | 6749 | }",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 6750 | break; |
8224 | bpr | 6751 | |
7647 | schaersvoo | 6752 | case DRAW_HATCHFILL:/* not used for userdraw */ |
6753 | fprintf(js_include_file,"\n<!-- draw hatch fill -->\n\ |
||
8105 | schaersvoo | 6754 | var draw_hatchfill = function(canvas_type,x0,y0,dx,dy,linewidth,stroke_color,stroke_opacity,xsize,ysize){\ |
7647 | schaersvoo | 6755 | var obj;\ |
6756 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
6757 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
6758 | }\ |
||
6759 | else\ |
||
6760 | {\ |
||
6761 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
6762 | };\ |
||
6763 | var ctx = obj.getContext(\"2d\");\ |
||
6764 | var x;\ |
||
6765 | var y;\ |
||
6766 | ctx.save();\ |
||
6767 | ctx.lineWidth = linewidth;\ |
||
11088 | schaersvoo | 6768 | if(linewidth%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
7647 | schaersvoo | 6769 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
6770 | y = ysize;\ |
||
6771 | for( x = x0 ; x < xsize ; x = x + dx ){\ |
||
6772 | ctx.moveTo(x,y0);\ |
||
6773 | ctx.lineTo(xsize,y);\ |
||
6774 | y = y - dy;\ |
||
6775 | };\ |
||
6776 | y = y0;\ |
||
6777 | for( x = xsize ; x >= dx ; x = x - dx){\ |
||
6778 | ctx.moveTo(x,ysize);\ |
||
6779 | ctx.lineTo(x0,y);\ |
||
6780 | y = y + dy;\ |
||
6781 | };\ |
||
6782 | ctx.stroke();\ |
||
6783 | ctx.restore();\ |
||
6784 | return;\ |
||
7653 | schaersvoo | 6785 | };",canvas_root_id,canvas_root_id,canvas_root_id); |
7647 | schaersvoo | 6786 | break; |
7614 | schaersvoo | 6787 | case DRAW_CIRCLES:/* used for userdraw */ |
6788 | fprintf(js_include_file,"\n<!-- draw circles -->\n\ |
||
8105 | schaersvoo | 6789 | 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 | 6790 | ctx.save();\ |
8071 | schaersvoo | 6791 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 6792 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
6793 | ctx.lineWidth = line_width;\ |
||
11088 | schaersvoo | 6794 | if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
7614 | schaersvoo | 6795 | for(var p = 0 ; p < x_points.length ; p++ ){\ |
6796 | ctx.beginPath();\ |
||
6797 | ctx.arc(x_points[p],y_points[p],radius[p],0,2*Math.PI,false);\ |
||
6798 | ctx.closePath();\ |
||
6799 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
6800 | if(use_filled == 1){ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();}\ |
||
6801 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
6802 | ctx.stroke();\ |
||
6803 | }\ |
||
6804 | ctx.restore();\ |
||
6805 | return;\ |
||
7653 | schaersvoo | 6806 | };"); |
7614 | schaersvoo | 6807 | break; |
7663 | schaersvoo | 6808 | case DRAW_POLYLINE:/* user for userdraw : draw lines through points */ |
6809 | fprintf(js_include_file,"\n<!-- draw polyline -->\n\ |
||
8105 | schaersvoo | 6810 | 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 | 6811 | ctx.save();\ |
8071 | schaersvoo | 6812 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7663 | schaersvoo | 6813 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
6814 | ctx.lineWidth = line_width;\ |
||
11088 | schaersvoo | 6815 | if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
7663 | schaersvoo | 6816 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
6817 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
6818 | ctx.clearRect(0,0,xsize,ysize);\ |
||
6819 | ctx.beginPath();\ |
||
6820 | for(var p = 0 ; p < x_points.length-1 ; p++ ){\ |
||
6821 | ctx.moveTo(x_points[p],y_points[p]);\ |
||
6822 | ctx.lineTo(x_points[p+1],y_points[p+1]);\ |
||
6823 | }\ |
||
6824 | ctx.closePath();\ |
||
6825 | ctx.stroke();\ |
||
6826 | ctx.fillStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
6827 | for(var p = 0 ; p < x_points.length ; p++ ){\ |
||
6828 | ctx.beginPath();\ |
||
6829 | ctx.arc(x_points[p],y_points[p],line_width,0,2*Math.PI,false);\ |
||
6830 | ctx.closePath();ctx.fill();ctx.stroke();\ |
||
6831 | };\ |
||
6832 | ctx.restore();\ |
||
6833 | return;\ |
||
6834 | };"); |
||
6835 | break; |
||
8224 | bpr | 6836 | |
7614 | schaersvoo | 6837 | case DRAW_SEGMENTS:/* used for userdraw */ |
6838 | fprintf(js_include_file,"\n<!-- draw segments -->\n\ |
||
8105 | schaersvoo | 6839 | 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 | 6840 | ctx.save();\ |
8071 | schaersvoo | 6841 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 6842 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
6843 | ctx.lineWidth = line_width;\ |
||
11088 | schaersvoo | 6844 | if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
7614 | schaersvoo | 6845 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
6846 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
6847 | for(var p = 0 ; p < x_points.length ; p = p+2 ){\ |
||
6848 | ctx.beginPath();\ |
||
6849 | ctx.moveTo(x_points[p],y_points[p]);\ |
||
6850 | ctx.lineTo(x_points[p+1],y_points[p+1]);\ |
||
6851 | ctx.closePath();\ |
||
6852 | ctx.stroke();\ |
||
6853 | }\ |
||
6854 | ctx.restore();\ |
||
6855 | return;\ |
||
6856 | };"); |
||
6857 | break; |
||
8224 | bpr | 6858 | |
7614 | schaersvoo | 6859 | case DRAW_LINES:/* used for userdraw */ |
6860 | fprintf(js_include_file,"\n<!-- draw lines -->\n\ |
||
6861 | function calc_line(x1,x2,y1,y2){\ |
||
6862 | var marge = 2;\ |
||
6863 | if(x1 < x2+marge && x1>x2-marge){\ |
||
6864 | return [x1,0,x1,ysize];\ |
||
6865 | };\ |
||
6866 | if(y1 < y2+marge && y1>y2-marge){\ |
||
6867 | return [0,y1,xsize,y1];\ |
||
6868 | };\ |
||
6869 | var Y1 = y1 - (x1)*(y2 - y1)/(x2 - x1);\ |
||
6870 | var Y2 = y1 + (xsize - x1)*(y2 - y1)/(x2 - x1);\ |
||
6871 | return [0,Y1,xsize,Y2];\ |
||
6872 | };\ |
||
8105 | schaersvoo | 6873 | 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 | 6874 | ctx.save();\ |
6875 | var line = new Array(4);\ |
||
8071 | schaersvoo | 6876 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 6877 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
6878 | ctx.lineWidth = line_width;\ |
||
11088 | schaersvoo | 6879 | if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
7614 | schaersvoo | 6880 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
6881 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
6882 | for(var p = 0 ; p < x_points.length ; p = p+2 ){\ |
||
6883 | line = calc_line(x_points[p],x_points[p+1],y_points[p],y_points[p+1]);\ |
||
6884 | ctx.beginPath();\ |
||
6885 | ctx.moveTo(line[0],line[1]);\ |
||
6886 | ctx.lineTo(line[2],line[3]);\ |
||
6887 | ctx.closePath();\ |
||
6888 | ctx.stroke();\ |
||
6889 | }\ |
||
6890 | ctx.restore();\ |
||
6891 | return;\ |
||
6892 | };"); |
||
6893 | break; |
||
6894 | |||
8244 | schaersvoo | 6895 | case DRAW_DEMILINES:/* used for userdraw */ |
6896 | fprintf(js_include_file,"\n<!-- draw demilines -->\n\ |
||
6897 | function find_inf_point(x1,y1,x2,y2){\ |
||
6898 | if(x1<x2+2 && x1>x2-2){if(y1<y2){return [x1,y1,x1,ysize];}else{return [x1,0,x1,y1];};};\ |
||
6899 | var rc = (y2 - y1)/(x2 - x1);var q = y1 - (x1)*rc;\ |
||
6900 | if( x1 < x2 ){ return [x1,y1,xsize,rc*xsize+q];}else{return [x1,y1,0,q];};\ |
||
6901 | };\ |
||
6902 | 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){\ |
||
6903 | ctx.save();\ |
||
6904 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
||
6905 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
||
6906 | ctx.lineWidth = line_width;\ |
||
11088 | schaersvoo | 6907 | if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
8244 | schaersvoo | 6908 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
6909 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
6910 | var pair = new Array(4);\ |
||
6911 | for(var p = 0 ; p < x_points.length ; p = p+2 ){\ |
||
6912 | pair = find_inf_point(x_points[p],y_points[p],x_points[p+1],y_points[p+1]);\ |
||
6913 | ctx.beginPath();\ |
||
6914 | ctx.moveTo(pair[0],pair[1]);\ |
||
6915 | ctx.lineTo(pair[2],pair[3]);\ |
||
6916 | ctx.closePath();\ |
||
6917 | ctx.stroke();\ |
||
6918 | }\ |
||
6919 | ctx.restore();\ |
||
6920 | return;\ |
||
6921 | };"); |
||
6922 | break; |
||
6923 | |||
7614 | schaersvoo | 6924 | case DRAW_CROSSHAIRS:/* used for userdraw */ |
6925 | fprintf(js_include_file,"\n<!-- draw crosshairs -->\n\ |
||
8105 | schaersvoo | 6926 | var draw_crosshairs = function(ctx,x_points,y_points,line_width,crosshair_size,stroke_color,stroke_opacity,use_rotate,angle,use_affine,affine_matrix){\ |
8071 | schaersvoo | 6927 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 6928 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
6929 | ctx.lineWidth = line_width;\ |
||
11088 | schaersvoo | 6930 | if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
7614 | schaersvoo | 6931 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
6932 | var x1,x2,y1,y2;\ |
||
6933 | for(var p = 0 ; p < x_points.length ; p++ ){\ |
||
6934 | x1 = x_points[p] - crosshair_size;\ |
||
6935 | x2 = x_points[p] + crosshair_size;\ |
||
6936 | y1 = y_points[p] - crosshair_size;\ |
||
6937 | y2 = y_points[p] + crosshair_size;\ |
||
6938 | ctx.beginPath();\ |
||
6939 | ctx.moveTo(x1,y1);\ |
||
6940 | ctx.lineTo(x2,y2);\ |
||
6941 | ctx.closePath();\ |
||
6942 | ctx.stroke();\ |
||
6943 | ctx.beginPath();\ |
||
6944 | ctx.moveTo(x2,y1);\ |
||
6945 | ctx.lineTo(x1,y2);\ |
||
6946 | ctx.closePath();\ |
||
6947 | ctx.stroke();\ |
||
6948 | }\ |
||
6949 | ctx.restore();\ |
||
6950 | return;\ |
||
7653 | schaersvoo | 6951 | };"); |
7614 | schaersvoo | 6952 | break; |
6953 | |||
6954 | case DRAW_RECTS:/* used for userdraw */ |
||
6955 | fprintf(js_include_file,"\n<!-- draw rects -->\n\ |
||
8105 | schaersvoo | 6956 | var draw_rects = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_affine,affine_matrix){\ |
7614 | schaersvoo | 6957 | ctx.save();\ |
8071 | schaersvoo | 6958 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 6959 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
6960 | ctx.lineWidth = line_width;\ |
||
11088 | schaersvoo | 6961 | if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
8448 | schaersvoo | 6962 | ctx.strokeStyle = 'rgba('+stroke_color+','+stroke_opacity+')';\ |
7614 | schaersvoo | 6963 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];}};\ |
6964 | for(var p = 0 ; p < x_points.length ; p = p + 2){\ |
||
6965 | ctx.beginPath();\ |
||
6966 | ctx.rect(x_points[p],y_points[p],x_points[p+1]-x_points[p],y_points[p+1]-y_points[p]);\ |
||
6967 | ctx.closePath();\ |
||
8448 | schaersvoo | 6968 | if(use_filled == 1 ){ctx.fillStyle = 'rgba('+fill_color+','+fill_opacity+')';ctx.fill();}\ |
7614 | schaersvoo | 6969 | ctx.stroke();\ |
6970 | };\ |
||
6971 | ctx.restore();\ |
||
6972 | return;\ |
||
7653 | schaersvoo | 6973 | };"); |
7614 | schaersvoo | 6974 | break; |
6975 | |||
6976 | case DRAW_ROUNDRECTS:/* used for userdraw */ |
||
6977 | fprintf(js_include_file,"\n<!-- draw round rects -->\n\ |
||
8105 | schaersvoo | 6978 | var draw_roundrects = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,use_rotate,angle,use_affine,affine_matrix){\ |
7614 | schaersvoo | 6979 | ctx.save();\ |
8071 | schaersvoo | 6980 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 6981 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
6982 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
||
9462 | schaersvoo | 6983 | ctx.lineWidth = line_width;\ |
11088 | schaersvoo | 6984 | if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
7614 | schaersvoo | 6985 | var x,y,w,h,r;\ |
6986 | for(var p = 0; p < x_points.length; p = p+2){\ |
||
6987 | 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);\ |
||
6988 | ctx.beginPath();ctx.moveTo(x + r, y);\ |
||
6989 | ctx.lineTo(x + w - r, y);\ |
||
6990 | ctx.quadraticCurveTo(x + w, y, x + w, y + r);\ |
||
6991 | ctx.lineTo(x + w, y + h - r);\ |
||
6992 | ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);\ |
||
6993 | ctx.lineTo(x + r, y + h);\ |
||
6994 | ctx.quadraticCurveTo(x, y + h, x, y + h - r);\ |
||
6995 | ctx.lineTo(x, y + r);\ |
||
6996 | ctx.quadraticCurveTo(x, y, x + r, y);\ |
||
6997 | ctx.closePath();if( use_dashed == 1 ){ctx.setLineDash([dashtype0,dashtype1]);};\ |
||
6998 | ctx.strokeStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
6999 | if( use_filled == 1 ){ctx.fillStyle =\"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();};\ |
||
7000 | ctx.stroke();\ |
||
7001 | }\ |
||
7002 | ctx.restore();\ |
||
7653 | schaersvoo | 7003 | };"); |
8224 | bpr | 7004 | break; |
7614 | schaersvoo | 7005 | |
7006 | case DRAW_ELLIPSES:/* not used for userdraw */ |
||
7007 | fprintf(js_include_file,"\n<!-- draw ellipses -->\n\ |
||
8105 | schaersvoo | 7008 | 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 | 7009 | var obj;\ |
7010 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
7011 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
7012 | }\ |
||
7013 | else\ |
||
7014 | {\ |
||
7015 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
7016 | };\ |
||
7017 | var ctx = obj.getContext(\"2d\");\ |
||
7018 | ctx.save();\ |
||
8071 | schaersvoo | 7019 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 7020 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
7021 | var cx,cy,ry,rx;\ |
||
7022 | ctx.lineWidth = line_width;\ |
||
11088 | schaersvoo | 7023 | if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
7614 | schaersvoo | 7024 | if( use_filled == 1 ){ctx.fillStyle =\"rgba(\"+fill_color+\",\"+fill_opacity+\")\";};\ |
7025 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
7026 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
7027 | for(var p=0;p< x_points.length;p = p+2){\ |
||
7028 | ctx.beginPath();\ |
||
7029 | cx = x_points[p];cy = y_points[p];rx = 0.25*x_points[p+1];ry = 0.25*y_points[p+1];\ |
||
7030 | ctx.translate(cx - rx, cy - ry);\ |
||
7031 | ctx.scale(rx, ry);\ |
||
7032 | ctx.arc(1, 1, 1, 0, 2 * Math.PI, false);\ |
||
7033 | if( use_filled == 1 ){ctx.fill();}\ |
||
7034 | ctx.stroke();\ |
||
7035 | };\ |
||
7036 | ctx.restore();\ |
||
7653 | schaersvoo | 7037 | };",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 7038 | break; |
7039 | |||
7040 | case DRAW_PATHS: /* used for userdraw */ |
||
7041 | fprintf(js_include_file,"\n<!-- draw paths -->\n\ |
||
8105 | schaersvoo | 7042 | 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 | 7043 | ctx.save();\ |
8071 | schaersvoo | 7044 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 7045 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
7046 | ctx.lineWidth = line_width;\ |
||
11088 | schaersvoo | 7047 | if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
7614 | schaersvoo | 7048 | ctx.lineJoin = \"round\";\ |
7049 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
7050 | ctx.beginPath();\ |
||
7051 | ctx.moveTo(x_points[0],y_points[0]);\ |
||
7052 | for(var p = 1 ; p < x_points.length ; p++ ){ctx.lineTo(x_points[p],y_points[p]);}\ |
||
7053 | if(closed_path == 1){ctx.lineTo(x_points[0],y_points[0]);ctx.closePath();}\ |
||
7054 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
7055 | if(use_filled == 1){ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();}\ |
||
7056 | ctx.stroke();\ |
||
7057 | ctx.restore();\ |
||
7058 | return;\ |
||
7059 | };"); |
||
8224 | bpr | 7060 | |
7614 | schaersvoo | 7061 | break; |
7062 | case DRAW_ARROWS:/* used for userdraw */ |
||
7063 | fprintf(js_include_file,"\n<!-- draw arrows -->\n\ |
||
8105 | schaersvoo | 7064 | 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 | 7065 | ctx.save();\ |
8071 | schaersvoo | 7066 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 7067 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
7068 | ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
7069 | ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
7070 | ctx.lineWidth = line_width;\ |
||
11088 | schaersvoo | 7071 | if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
7614 | schaersvoo | 7072 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
7073 | ctx.lineCap = \"round\";\ |
||
7074 | var x1,y1,x2,y2,dx,dy,len;\ |
||
7075 | for(var p = 0 ; p < x_points.length - 1 ; p = p +2){\ |
||
7874 | schaersvoo | 7076 | ctx.save();\ |
7614 | schaersvoo | 7077 | x1 = x_points[p];y1 = y_points[p];x2 = x_points[p+1];y2 = y_points[p+1];dx = x2 - x1;dy = y2 - y1;\ |
7078 | len = Math.sqrt(dx*dx+dy*dy);\ |
||
7079 | ctx.translate(x2,y2);\ |
||
7080 | ctx.rotate(Math.atan2(dy,dx));\ |
||
7081 | ctx.lineCap = \"round\";\ |
||
7082 | ctx.beginPath();\ |
||
7083 | ctx.moveTo(0,0);\ |
||
7084 | ctx.lineTo(-len,0);\ |
||
7085 | ctx.closePath();\ |
||
7086 | ctx.stroke();\ |
||
7087 | ctx.beginPath();\ |
||
7088 | ctx.moveTo(0,0);\ |
||
7089 | ctx.lineTo(-1*arrow_head,-0.5*arrow_head);\ |
||
7090 | ctx.lineTo(-1*arrow_head, 0.5*arrow_head);\ |
||
7091 | ctx.closePath();\ |
||
7092 | ctx.fill();\ |
||
7874 | schaersvoo | 7093 | ctx.restore();\ |
7614 | schaersvoo | 7094 | if( type == 2 ){\ |
7095 | ctx.save();\ |
||
7096 | ctx.translate(x1,y1);\ |
||
7097 | ctx.rotate(Math.atan2(-dy,-dx));\ |
||
7098 | ctx.beginPath();\ |
||
7099 | ctx.moveTo(0,0);\ |
||
8347 | schaersvoo | 7100 | ctx.lineTo(-1*arrow_head,-0.4*arrow_head);\ |
7101 | ctx.lineTo(-1*arrow_head, 0.4*arrow_head);\ |
||
7614 | schaersvoo | 7102 | ctx.closePath();\ |
7103 | ctx.stroke();\ |
||
7104 | ctx.fill();\ |
||
7874 | schaersvoo | 7105 | ctx.restore();\ |
8379 | schaersvoo | 7106 | };\ |
7107 | };\ |
||
7614 | schaersvoo | 7108 | ctx.restore();\ |
7109 | return;\ |
||
7653 | schaersvoo | 7110 | };"); |
7614 | schaersvoo | 7111 | break; |
7112 | |||
7113 | case DRAW_VIDEO:/* not used for userdraw */ |
||
7114 | fprintf(js_include_file,"\n<!-- draw video -->\n\ |
||
8105 | schaersvoo | 7115 | var draw_video = function(canvas_root_id,x,y,w,h,URL){\ |
7614 | schaersvoo | 7116 | var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\ |
7117 | var video_div = document.createElement(\"div\");\ |
||
7118 | canvas_div.appendChild(video_div);\ |
||
7119 | video_div.style.position = \"absolute\";\ |
||
7120 | video_div.style.left = x+\"px\";\ |
||
7121 | video_div.style.top = y+\"px\";\ |
||
7122 | video_div.style.width = w+\"px\";\ |
||
7123 | video_div.style.height = h+\"px\";\ |
||
7124 | var video = document.createElement(\"video\");\ |
||
7125 | video_div.appendChild(video);\ |
||
7126 | video.style.width = w+\"px\";\ |
||
7127 | video.style.height = h+\"px\";\ |
||
7128 | video.autobuffer = true;\ |
||
7129 | video.controls = true;video.autoplay = false;\ |
||
7130 | var src = document.createElement(\"source\");\ |
||
7131 | src.type = \"video/mp4\";\ |
||
7132 | src.src = URL;\ |
||
7133 | video.appendChild(src);\ |
||
7134 | video.load();\ |
||
7135 | return;\ |
||
8224 | bpr | 7136 | };"); |
7614 | schaersvoo | 7137 | break; |
8224 | bpr | 7138 | |
7614 | schaersvoo | 7139 | case DRAW_AUDIO:/* not used for userdraw */ |
7140 | fprintf(js_include_file,"\n<!-- draw audio -->\n\ |
||
8105 | schaersvoo | 7141 | var draw_audio = function(canvas_root_id,x,y,w,h,loop,visible,URL1,URL2){\ |
7614 | schaersvoo | 7142 | var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\ |
7143 | var audio_div = document.createElement(\"div\");\ |
||
7144 | canvas_div.appendChild(audio_div);\ |
||
7145 | audio_div.style.position = \"absolute\";\ |
||
7146 | audio_div.style.left = x+\"px\";\ |
||
7147 | audio_div.style.top = y+\"px\";\ |
||
7148 | audio_div.style.width = w+\"px\";\ |
||
7149 | audio_div.style.height = h+\"px\";\ |
||
7150 | var audio = document.createElement(\"audio\");\ |
||
7151 | audio_div.appendChild(audio);\ |
||
7152 | audio.setAttribute(\"style\",\"width:\"+w+\"px;height:\"+h+\"px\");\ |
||
7153 | audio.autobuffer = true;\ |
||
8379 | schaersvoo | 7154 | if(visible == 1 ){ audio.controls = true;audio.autoplay = false;}else{ audio.controls = false;audio.autoplay = true;};\ |
7155 | if(loop == 1 ){ audio.loop = true;}else{ audio.loop = false;};\ |
||
7614 | schaersvoo | 7156 | var src1 = document.createElement(\"source\");\ |
7157 | src1.type = \"audio/ogg\";\ |
||
7158 | src1.src = URL1;\ |
||
7159 | audio.appendChild(src1);\ |
||
7160 | var src2 = document.createElement(\"source\");\ |
||
7161 | src2.type = \"audio/mpeg\";\ |
||
7162 | src2.src = URL2;\ |
||
7163 | audio.appendChild(src2);\ |
||
7164 | audio.load();\ |
||
7165 | return;\ |
||
7653 | schaersvoo | 7166 | };"); |
7614 | schaersvoo | 7167 | break; |
8224 | bpr | 7168 | |
7614 | schaersvoo | 7169 | case DRAW_HTTP:/* not used for userdraw */ |
7170 | fprintf(js_include_file,"\n<!-- draw http -->\n\ |
||
8105 | schaersvoo | 7171 | var draw_http = function(canvas_root_id,x,y,w,h,URL){\ |
7614 | schaersvoo | 7172 | var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\ |
7173 | var http_div = document.createElement(\"div\");\ |
||
7174 | var iframe = document.createElement(\"iframe\");\ |
||
7175 | canvas_div.appendChild(http_div);\ |
||
7176 | http_div.appendChild(iframe);\ |
||
7177 | iframe.src = URL;\ |
||
7178 | iframe.setAttribute(\"width\",w);\ |
||
7179 | iframe.setAttribute(\"height\",h);\ |
||
7180 | return;\ |
||
7653 | schaersvoo | 7181 | };"); |
7614 | schaersvoo | 7182 | break; |
8224 | bpr | 7183 | |
11238 | schaersvoo | 7184 | case DRAW_XML: /* |
7185 | onclick=1 : click |
||
7186 | onclick=2 drag |
||
7187 | xy:drag_type = 0; |
||
7188 | x: drag_type = 1; |
||
7189 | y: drag_type = 2; |
||
7190 | */ |
||
7191 | |||
7614 | schaersvoo | 7192 | fprintf(js_include_file,"\n<!-- draw xml -->\n\ |
11756 | schaersvoo | 7193 | var draw_xml = function(canvas_root_id,x,y,mathml,drag_type,onclick,click_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity){\ |
7614 | schaersvoo | 7194 | var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\ |
7195 | var xml_div = document.createElement(\"div\");\ |
||
7196 | canvas_div.appendChild(xml_div);\ |
||
7197 | xml_div.innerHTML = mathml;\ |
||
8379 | schaersvoo | 7198 | xml_div.style.color = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
11745 | schaersvoo | 7199 | var color_org = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
11756 | schaersvoo | 7200 | var back_color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\ |
7201 | var no_color = \"rgba(255,255,255,0)\";\ |
||
7202 | xml_div.style.position = \"absolute\"; xml_div.style.left = x+\"px\";xml_div.style.top = y+\"px\";\ |
||
11745 | schaersvoo | 7203 | var dragging = false;\ |
11747 | schaersvoo | 7204 | if( onclick == 2 ){reply[click_cnt] = px2x(x)+','+px2y(y);};\ |
7205 | if( onclick == 1 ){reply[click_cnt] = 0;};\ |
||
7206 | if( onclick == 2 ){\ |
||
7207 | xml_div.onclick = function(){\ |
||
11756 | schaersvoo | 7208 | 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 | 7209 | canvas_div.onmousemove = function(evt){\ |
7210 | if(!dragging){return;};\ |
||
7211 | var x1;var y1;\ |
||
7212 | var mouse = dragstuff.getMouse(evt,xml_div);\ |
||
7213 | switch(drag_type){\ |
||
7214 | case 0: x1 = mouse.x;y1 = mouse.y;break;\ |
||
7215 | case 1: x1 = mouse.x;y1 = y;break;\ |
||
7216 | case 2: x1 = x;y1 = mouse.y;break;\ |
||
7217 | default:x1 = x;y1 = y; break;\ |
||
7218 | };\ |
||
7219 | if( x_use_snap_to_grid == 1 ){ x1 = snap_to_x(x1);};\ |
||
7220 | if( y_use_snap_to_grid == 1 ){ y1 = snap_to_y(y1);};\ |
||
7221 | if( use_snap_to_points != 0 ){ var xy = new Array(2);if( use_snap_to_points == 1 ){xy = snap_to_points(x1,y1);}else{xy = snap_to_fun(x1,y1);};x1 = xy[0];y1 = xy[1];};\ |
||
7222 | xml_div.style.left = x1 + 'px';xml_div.style.top = y1 + 'px';\ |
||
7223 | reply[click_cnt] = px2x(x1)+','+px2y(y1);\ |
||
11238 | schaersvoo | 7224 | };\ |
7614 | schaersvoo | 7225 | };\ |
11238 | schaersvoo | 7226 | };\ |
7227 | if(onclick == 1){\ |
||
11747 | schaersvoo | 7228 | xml_div.onclick = function(){\ |
11756 | schaersvoo | 7229 | 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 | 7230 | };\ |
7231 | return;\ |
||
11745 | schaersvoo | 7232 | };"); |
7614 | schaersvoo | 7233 | break; |
7654 | schaersvoo | 7234 | case DRAW_SGRAPH: |
8224 | bpr | 7235 | /* |
7654 | schaersvoo | 7236 | xstart = given |
7237 | ystart = given |
||
7238 | sgraph(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily) |
||
7239 | */ |
||
7240 | fprintf(js_include_file,"\n<!-- draw sgraph -->\n\ |
||
8105 | schaersvoo | 7241 | var draw_sgraph = function(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily,opacity,font_size){\ |
7658 | schaersvoo | 7242 | 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);};\ |
7243 | var ctx = obj.getContext(\"2d\");\ |
||
7244 | ctx.font = fontfamily;\ |
||
7245 | var minor_opacity = 0.8*opacity;\ |
||
7246 | ctx.clearRect(0,0,xsize,ysize);\ |
||
7976 | schaersvoo | 7247 | var zero_x = 0.1*xsize;\ |
7248 | var zero_y = 0.9*ysize;\ |
||
8129 | schaersvoo | 7249 | var snor_x;var snor_y;\ |
7654 | schaersvoo | 7250 | if( xstart != xmin){\ |
7658 | schaersvoo | 7251 | snor_x = 0.1*xsize;\ |
7252 | }\ |
||
7253 | else\ |
||
7254 | {\ |
||
7255 | snor_x = 0;\ |
||
7256 | xstart = xmin;\ |
||
7257 | };\ |
||
7258 | ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\ |
||
7259 | ctx.lineWidth = 2;\ |
||
7260 | ctx.beginPath();\ |
||
7261 | ctx.moveTo(xsize,zero_y);\ |
||
7262 | ctx.lineTo(zero_x,zero_y);\ |
||
7263 | ctx.lineTo(zero_x,0);\ |
||
7264 | ctx.stroke();\ |
||
7265 | ctx.closePath();\ |
||
7266 | ctx.beginPath();\ |
||
7267 | ctx.moveTo(zero_x,zero_y);\ |
||
7268 | ctx.lineTo(zero_x + 0.25*snor_x,zero_y - 0.1*snor_x);\ |
||
7269 | ctx.lineTo(zero_x + 0.5*snor_x,zero_y + 0.1*snor_x);\ |
||
7270 | ctx.lineTo(zero_x + 0.75*snor_x,zero_y - 0.1*snor_x);\ |
||
7271 | ctx.lineTo(zero_x + snor_x,zero_y);\ |
||
7272 | ctx.stroke();\ |
||
7273 | ctx.closePath();\ |
||
7274 | ctx.beginPath();\ |
||
7275 | var num = xstart;\ |
||
7660 | schaersvoo | 7276 | var flipflop = 1;\ |
7658 | schaersvoo | 7277 | var step_x = xmajor*(xsize - zero_x - snor_x)/(xmax - xstart);\ |
7976 | schaersvoo | 7278 | var txtsize;var txt_marge=step_x - 5;\ |
7658 | schaersvoo | 7279 | for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\ |
7976 | schaersvoo | 7280 | txtsize = ctx.measureText(num).width;\ |
7281 | if( txtsize > txt_marge ){if( flipflop == 1 ){flipflop = 0;}else{flipflop = 1;};};\ |
||
7282 | if( flipflop == 1){\ |
||
7283 | ctx.fillText(num,x - 0.5*txtsize,zero_y+font_size);\ |
||
7284 | }\ |
||
7285 | else\ |
||
7286 | {\ |
||
7287 | ctx.fillText(num,x - 0.5*txtsize,zero_y+2*font_size);\ |
||
8379 | schaersvoo | 7288 | };\ |
7976 | schaersvoo | 7289 | num = num + xmajor;\ |
7658 | schaersvoo | 7290 | };\ |
7291 | ctx.stroke();\ |
||
7292 | ctx.closePath();\ |
||
7293 | ctx.lineWidth = 1;\ |
||
7294 | ctx.beginPath();\ |
||
7295 | for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\ |
||
7296 | ctx.moveTo(x,zero_y);\ |
||
7297 | ctx.lineTo(x,0);\ |
||
7298 | };\ |
||
7299 | ctx.stroke();\ |
||
7300 | ctx.closePath();\ |
||
7301 | if( xminor > 1){\ |
||
7302 | ctx.lineWidth = 0.5;\ |
||
7303 | ctx.beginPath();\ |
||
7304 | ctx.strokeStyle = \"rgba(\"+minorcolor+\",\"+minor_opacity+\")\";\ |
||
7305 | var minor_step_x = step_x / xminor;\ |
||
7306 | var nx;\ |
||
7307 | for(var x = zero_x+snor_x; x < xsize;x = x + step_x){\ |
||
7308 | num = 1;\ |
||
7309 | for(var p = 1 ; p < xminor ; p++){\ |
||
7310 | nx = x + num*minor_step_x;\ |
||
7311 | ctx.moveTo(nx,zero_y);\ |
||
7312 | ctx.lineTo(nx,0);\ |
||
7313 | num++;\ |
||
7314 | };\ |
||
7315 | };\ |
||
7316 | ctx.stroke();\ |
||
7317 | ctx.closePath();\ |
||
7318 | ctx.beginPath();\ |
||
7319 | ctx.lineWidth = 2;\ |
||
7320 | ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\ |
||
7321 | for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\ |
||
7322 | ctx.moveTo(x,zero_y);ctx.lineTo(x,zero_y - 12);\ |
||
7323 | };\ |
||
7324 | for(var x = zero_x+snor_x ; x < xsize;x = x + minor_step_x){\ |
||
7325 | ctx.moveTo(x,zero_y);ctx.lineTo(x,zero_y - 6);\ |
||
7326 | };\ |
||
7327 | ctx.stroke();\ |
||
7328 | ctx.closePath();\ |
||
7329 | ctx.lineWidth = 0.5;\ |
||
7330 | };\ |
||
7331 | xmin = xstart - (xmajor*(zero_x+snor_x)/step_x);\ |
||
7332 | if( ystart != ymin){\ |
||
7333 | snor_y = 0.1*ysize;\ |
||
7334 | }\ |
||
7335 | else\ |
||
7336 | {\ |
||
7337 | snor_y = 0;\ |
||
7338 | ystart = ymin;\ |
||
7339 | };\ |
||
7340 | ctx.lineWidth = 2;\ |
||
7341 | ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\ |
||
7342 | ctx.beginPath();\ |
||
7343 | ctx.moveTo(zero_x,zero_y);\ |
||
7344 | ctx.lineTo(zero_x - 0.1*snor_y,zero_y - 0.25*snor_y);\ |
||
7345 | ctx.lineTo(zero_x + 0.1*snor_y,zero_y - 0.5*snor_y);\ |
||
7346 | ctx.lineTo(zero_x - 0.1*snor_y,zero_y - 0.75*snor_y);\ |
||
7347 | ctx.lineTo(zero_x,zero_y - snor_y);\ |
||
7348 | ctx.stroke();\ |
||
7349 | ctx.closePath();\ |
||
7350 | ctx.beginPath();\ |
||
7351 | ctx.lineWidth = 1;\ |
||
7352 | num = ystart;\ |
||
7353 | var step_y = ymajor*(zero_y - snor_y)/(ymax - ystart);\ |
||
7354 | for(var y = zero_y - snor_y ; y > 0; y = y - step_y){\ |
||
7355 | ctx.moveTo(zero_x,y);\ |
||
7356 | ctx.lineTo(xsize,y);\ |
||
7357 | ctx.fillText(num,zero_x - ctx.measureText(num+\" \").width,parseInt(y+0.2*font_size));\ |
||
7358 | num = num + ymajor;\ |
||
7359 | };\ |
||
7360 | ctx.stroke();\ |
||
7361 | ctx.closePath();\ |
||
7362 | if( yminor > 1){\ |
||
7363 | ctx.lineWidth = 0.5;\ |
||
7364 | ctx.beginPath();\ |
||
7365 | ctx.strokeStyle = \"rgba(\"+minorcolor+\",\"+minor_opacity+\")\";\ |
||
7366 | var minor_step_y = step_y / yminor;\ |
||
7367 | var ny;\ |
||
7368 | for(var y = 0 ; y < zero_y - snor_y ;y = y + step_y){\ |
||
7369 | num = 1;\ |
||
7370 | for(var p = 1 ;p < yminor;p++){\ |
||
7371 | ny = y + num*minor_step_y;\ |
||
7372 | ctx.moveTo(zero_x,ny);\ |
||
7373 | ctx.lineTo(xsize,ny);\ |
||
7374 | num++;\ |
||
7375 | };\ |
||
7376 | };\ |
||
7377 | ctx.stroke();\ |
||
7378 | ctx.closePath();\ |
||
7379 | ctx.lineWidth = 2;\ |
||
7380 | ctx.beginPath();\ |
||
7381 | ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\ |
||
7382 | for(var y = zero_y - snor_y ; y > 0 ;y = y - step_y){\ |
||
7383 | ctx.moveTo(zero_x,y);\ |
||
7384 | ctx.lineTo(zero_x+12,y);\ |
||
7385 | };\ |
||
7386 | for(var y = zero_y - snor_y ; y > 0 ;y = y - minor_step_y){\ |
||
7387 | ctx.moveTo(zero_x,y);\ |
||
7388 | ctx.lineTo(zero_x+6,y);\ |
||
7389 | };\ |
||
7390 | ctx.stroke();\ |
||
7391 | ctx.closePath();\ |
||
7392 | };\ |
||
7393 | ymin = ystart - (ymajor*(ysize - zero_y + snor_y)/step_y);\ |
||
11088 | schaersvoo | 7394 | if( typeof(legend%d) !== 'undefined' ){\ |
7654 | schaersvoo | 7395 | ctx.globalAlpha = 1.0;\ |
7396 | var y_offset = 2*font_size;\ |
||
7397 | var txt;var txt_size;\ |
||
7398 | var x_offset = xsize - 2*font_size;\ |
||
7399 | var l_length = legend%d.length;var barcolor = new Array();\ |
||
11088 | schaersvoo | 7400 | if( typeof(legendcolors%d) !== 'undefined' ){\ |
7654 | schaersvoo | 7401 | for(var p = 0 ; p < l_length ; p++){\ |
7402 | barcolor[p] = legendcolors%d[p];\ |
||
7403 | };\ |
||
7404 | }else{\ |
||
7405 | if( barcolor.length == 0 ){\ |
||
7406 | for(var p = 0 ; p < l_length ; p++){\ |
||
7407 | barcolor[p] = stroke_color;\ |
||
7408 | };\ |
||
7409 | };\ |
||
7410 | };\ |
||
7411 | for(var p = 0; p < l_length; p++){\ |
||
7412 | ctx.fillStyle = barcolor[p];\ |
||
7413 | txt = legend%d[p];\ |
||
7414 | txt_size = ctx.measureText(txt).width;\ |
||
7415 | ctx.fillText(legend%d[p],x_offset - txt_size, y_offset);\ |
||
7416 | y_offset = parseInt(y_offset + 1.5*font_size);\ |
||
7417 | };\ |
||
7418 | };\ |
||
11088 | schaersvoo | 7419 | if( typeof(xaxislabel) !== 'undefined' ){\ |
7658 | schaersvoo | 7420 | ctx.fillStyle = \'#000000\';\ |
7421 | var txt_size = ctx.measureText(xaxislabel).width + 4 ;\ |
||
7422 | ctx.fillText(xaxislabel,xsize - txt_size, zero_y - 7);\ |
||
7423 | };\ |
||
11088 | schaersvoo | 7424 | if( typeof(yaxislabel) !== 'undefined'){\ |
7658 | schaersvoo | 7425 | ctx.save();\ |
7426 | ctx.fillStyle = \'#000000\';\ |
||
7427 | var txt_size = ctx.measureText(yaxislabel).width;\ |
||
7428 | ctx.translate(zero_x+8 + font_size,txt_size+font_size);\ |
||
7429 | ctx.rotate(-0.5*Math.PI);\ |
||
7430 | ctx.fillText(yaxislabel,0,0);\ |
||
7874 | schaersvoo | 7431 | ctx.restore();\ |
7658 | schaersvoo | 7432 | };\ |
7654 | schaersvoo | 7433 | };\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); |
7434 | break; |
||
7614 | schaersvoo | 7435 | |
7436 | case DRAW_GRID:/* not used for userdraw */ |
||
7437 | fprintf(js_include_file,"\n<!-- draw grid -->\n\ |
||
8105 | schaersvoo | 7438 | 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 | 7439 | 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);};\ |
7440 | var ctx = obj.getContext(\"2d\");ctx.clearRect(0,0,xsize,ysize);\ |
||
7614 | schaersvoo | 7441 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
7442 | ctx.save();\ |
||
8071 | schaersvoo | 7443 | if( use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);};\ |
7614 | schaersvoo | 7444 | if( use_rotate == 1 ){ctx.translate(x2px(0),y2px(0));ctx.rotate(angle*Math.PI/180);ctx.translate(-1*(x2px(0)),-1*(y2px(0)));};\ |
7445 | var stroke_color = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
7446 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+1.0+\")\";\ |
||
7447 | var axis_color = \"rgba(\"+axis_color+\",\"+stroke_opacity+\")\";\ |
||
7448 | ctx.font = font_family;\ |
||
7988 | schaersvoo | 7449 | var barcolor = new Array();\ |
7614 | schaersvoo | 7450 | var xstep = xsize*xmajor/(xmax - xmin);\ |
7451 | var ystep = ysize*ymajor/(ymax - ymin);\ |
||
7452 | var x2step = xstep / xminor;\ |
||
7453 | var y2step = ystep / yminor;\ |
||
7996 | schaersvoo | 7454 | var zero_x = x2px(0);;var zero_y = y2px(0);var f_x;var f_y;\ |
7455 | if(xmin < 0 ){ f_x = -1;}else{ f_x = 1;}\ |
||
7456 | if(ymin < 0 ){ f_y = -1;}else{ f_y = 1;}\ |
||
11088 | schaersvoo | 7457 | if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
7614 | schaersvoo | 7458 | ctx.beginPath();\ |
7459 | ctx.lineWidth = line_width;\ |
||
7460 | ctx.strokeStyle = stroke_color;\ |
||
7461 | for(var p = zero_x ; p < xsize; p = p + xstep){\ |
||
7462 | ctx.moveTo(p,0);\ |
||
7463 | ctx.lineTo(p,ysize);\ |
||
7464 | };\ |
||
7465 | for(var p = zero_x ; p > 0; p = p - xstep){\ |
||
7466 | ctx.moveTo(p,0);\ |
||
7467 | ctx.lineTo(p,ysize);\ |
||
7468 | };\ |
||
7469 | for(var p = zero_y ; p < ysize; p = p + ystep){\ |
||
7470 | ctx.moveTo(0,p);\ |
||
7471 | ctx.lineTo(xsize,p);\ |
||
7472 | };\ |
||
7473 | for(var p = zero_y ; p > 0; p = p - ystep){\ |
||
7474 | ctx.moveTo(0,p);\ |
||
7475 | ctx.lineTo(xsize,p);\ |
||
7476 | };\ |
||
11088 | schaersvoo | 7477 | if( typeof(xaxislabel) !== 'undefined' ){\ |
7614 | schaersvoo | 7478 | ctx.save();\ |
7479 | ctx.font = \"italic \"+font_size+\"px Ariel\";\ |
||
7480 | var corr = ctx.measureText(xaxislabel).width;\ |
||
7481 | ctx.fillText(xaxislabel,xsize - 1.5*corr,zero_y - tics_length - 0.4*font_size);\ |
||
7482 | ctx.restore();\ |
||
7483 | };\ |
||
11088 | schaersvoo | 7484 | if( typeof(yaxislabel) !== 'undefined' ){\ |
7614 | schaersvoo | 7485 | ctx.save();\ |
7486 | ctx.font = \"italic \"+font_size+\"px Ariel\";\ |
||
7988 | schaersvoo | 7487 | var corr = ctx.measureText(yaxislabel).width;\ |
7614 | schaersvoo | 7488 | ctx.translate(zero_x+tics_length + font_size,corr+font_size);\ |
7489 | ctx.rotate(-0.5*Math.PI);\ |
||
7490 | ctx.fillText(yaxislabel,0,0);\ |
||
7491 | ctx.restore();\ |
||
7492 | };\ |
||
7493 | ctx.stroke();\ |
||
7494 | ctx.closePath();\ |
||
7495 | if( use_axis == 1 ){\ |
||
7988 | schaersvoo | 7496 | ctx.save();\ |
7614 | schaersvoo | 7497 | ctx.beginPath();\ |
7498 | ctx.strokeStyle = stroke_color;\ |
||
7499 | ctx.lineWidth = 0.6*line_width;\ |
||
7500 | for(var p = zero_x ; p < xsize; p = p + x2step){\ |
||
7501 | ctx.moveTo(p,0);\ |
||
7502 | ctx.lineTo(p,ysize);\ |
||
7503 | };\ |
||
7504 | for(var p = zero_x ; p > 0; p = p - x2step){\ |
||
7505 | ctx.moveTo(p,0);\ |
||
7506 | ctx.lineTo(p,ysize);\ |
||
7507 | };\ |
||
7508 | for(var p = zero_y ; p < ysize; p = p + y2step){\ |
||
7509 | ctx.moveTo(0,p);\ |
||
7510 | ctx.lineTo(xsize,p);\ |
||
7511 | };\ |
||
7512 | for(var p = zero_y ; p > 0; p = p - y2step){\ |
||
7513 | ctx.moveTo(0,p);\ |
||
7514 | ctx.lineTo(xsize,p);\ |
||
7515 | };\ |
||
7516 | ctx.stroke();\ |
||
7517 | ctx.closePath();\ |
||
7518 | ctx.beginPath();\ |
||
7519 | ctx.lineWidth = 2*line_width;\ |
||
7520 | ctx.strokeStyle = axis_color;\ |
||
7521 | ctx.moveTo(0,zero_y);\ |
||
7522 | ctx.lineTo(xsize,zero_y);\ |
||
7523 | ctx.moveTo(zero_x,0);\ |
||
7524 | ctx.lineTo(zero_x,ysize);\ |
||
7525 | ctx.stroke();\ |
||
7526 | ctx.closePath();\ |
||
7527 | ctx.lineWidth = line_width+0.5;\ |
||
7528 | ctx.beginPath();\ |
||
7529 | for(var p = zero_x ; p < xsize; p = p + xstep){\ |
||
7530 | ctx.moveTo(p,zero_y-tics_length);\ |
||
7531 | ctx.lineTo(p,zero_y+tics_length);\ |
||
7532 | };\ |
||
7533 | for(var p = zero_x ; p > 0; p = p - xstep){\ |
||
7534 | ctx.moveTo(p,zero_y-tics_length);\ |
||
7535 | ctx.lineTo(p,zero_y+tics_length);\ |
||
7536 | };\ |
||
7537 | for(var p = zero_y ; p < ysize; p = p + ystep){\ |
||
7538 | ctx.moveTo(zero_x-tics_length,p);\ |
||
7539 | ctx.lineTo(zero_x+tics_length,p);\ |
||
7540 | };\ |
||
7541 | for(var p = zero_y ; p > 0; p = p - ystep){\ |
||
7542 | ctx.moveTo(zero_x-tics_length,p);\ |
||
7543 | ctx.lineTo(zero_x+tics_length,p);\ |
||
7544 | };\ |
||
7545 | for(var p = zero_x ; p < xsize; p = p + x2step){\ |
||
7546 | ctx.moveTo(p,zero_y-0.5*tics_length);\ |
||
7547 | ctx.lineTo(p,zero_y+0.5*tics_length);\ |
||
7548 | };\ |
||
7549 | for(var p = zero_x ; p > 0; p = p - x2step){\ |
||
7550 | ctx.moveTo(p,zero_y-0.5*tics_length);\ |
||
7551 | ctx.lineTo(p,zero_y+0.5*tics_length);\ |
||
7552 | };\ |
||
7553 | for(var p = zero_y ; p < ysize; p = p + y2step){\ |
||
7554 | ctx.moveTo(zero_x-0.5*tics_length,p);\ |
||
7555 | ctx.lineTo(zero_x+0.5*tics_length,p);\ |
||
7556 | };\ |
||
7557 | for(var p = zero_y ; p > 0; p = p - y2step){\ |
||
7558 | ctx.moveTo(zero_x-0.5*tics_length,p);\ |
||
7559 | ctx.lineTo(zero_x+0.5*tics_length,p);\ |
||
7560 | };\ |
||
7561 | ctx.stroke();\ |
||
7562 | ctx.closePath();\ |
||
7988 | schaersvoo | 7563 | ctx.restore();\ |
7564 | };\ |
||
7565 | if( use_axis_numbering == 1 ){\ |
||
7566 | ctx.save();\ |
||
7567 | ctx.fillColor = axis_color;\ |
||
8110 | schaersvoo | 7568 | ctx.strokeStyle = axis_color;\ |
7569 | ctx.lineWidth = 2*line_width;\ |
||
7988 | schaersvoo | 7570 | ctx.font = font_family;\ |
7571 | var shift = zero_y+2*font_size;var flip=0;var skip=0;var corr;var cnt;var disp_cnt;var prec;\ |
||
7572 | if( x_strings != null ){\ |
||
7573 | var len = x_strings.length;if((len/2+0.5)%%2 == 0){ alert(\"xaxis number unpaired: text missing ! \");return;};\ |
||
8110 | schaersvoo | 7574 | ctx.beginPath();\ |
9341 | schaersvoo | 7575 | if( x_strings_up == null){\ |
7576 | for(var p = 0 ; p < len ; p = p+2){\ |
||
7577 | var x_nums = x2px(eval(x_strings[p]));\ |
||
7578 | var x_text = x_strings[p+1];\ |
||
7579 | corr = ctx.measureText(x_text).width;\ |
||
7580 | skip = 1.2*corr/xstep;\ |
||
7581 | if( zero_y+2*font_size > ysize ){shift = ysize - 2*font_size;};\ |
||
7582 | if( skip > 1 ){if(flip == 0 ){flip = 1; shift = shift + font_size;}else{flip = 0; shift = shift - font_size;}};\ |
||
7583 | ctx.fillText(x_text,parseInt(x_nums-0.5*corr),shift);\ |
||
7584 | ctx.moveTo(x_nums,zero_y - tics_length);\ |
||
7585 | ctx.lineTo(x_nums,zero_y + tics_length);\ |
||
7586 | };\ |
||
7587 | }\ |
||
7588 | else\ |
||
7589 | {\ |
||
7590 | for(var p = 0 ; p < len ; p = p+2){\ |
||
7591 | var x_nums = x2px(eval(x_strings[p]));\ |
||
7592 | var x_text = x_strings[p+1];\ |
||
7593 | corr = 2 + tics_length + zero_y + ctx.measureText(x_text).width;\ |
||
7594 | if( corr > ysize ){corr = ysize;};\ |
||
7595 | ctx.save();\ |
||
9346 | schaersvoo | 7596 | ctx.translate(x_nums+0.25*font_size, corr);\ |
9341 | schaersvoo | 7597 | ctx.rotate(-1.5708);\ |
7598 | ctx.fillText(x_text,0,0);\ |
||
7599 | ctx.restore();\ |
||
7600 | ctx.moveTo(x_nums,zero_y - tics_length);\ |
||
7601 | ctx.lineTo(x_nums,zero_y + tics_length);\ |
||
7602 | };\ |
||
7988 | schaersvoo | 7603 | };\ |
8110 | schaersvoo | 7604 | ctx.closePath();\ |
7988 | schaersvoo | 7605 | }\ |
7606 | else\ |
||
7607 | {\ |
||
7608 | skip = 1;cnt = px2x(zero_x);\ |
||
7609 | prec = Math.log(precision)/(Math.log(10));\ |
||
7610 | var y_basis;if(f_y == 1){ y_basis = ysize }else{ y_basis = zero_y + 1.4*font_size;};\ |
||
7611 | for( var p = zero_x ; p < xsize ; p = p+xstep){\ |
||
7612 | if(skip == 0 ){\ |
||
7990 | schaersvoo | 7613 | disp_cnt = cnt.toFixed(prec);\ |
7988 | schaersvoo | 7614 | corr = ctx.measureText(disp_cnt).width;\ |
7615 | skip = parseInt(1.2*corr/xstep);\ |
||
7616 | ctx.fillText(disp_cnt,p-0.5*corr,y_basis);\ |
||
7614 | schaersvoo | 7617 | }\ |
7988 | schaersvoo | 7618 | else\ |
7619 | {\ |
||
7620 | skip--;\ |
||
7614 | schaersvoo | 7621 | };\ |
7988 | schaersvoo | 7622 | cnt = cnt + xmajor;\ |
7614 | schaersvoo | 7623 | };\ |
7988 | schaersvoo | 7624 | cnt = px2x(zero_x);skip = 1;\ |
7625 | for( var p = zero_x ; p > 0 ; p = p-xstep){\ |
||
7626 | if(skip == 0 ){\ |
||
7990 | schaersvoo | 7627 | disp_cnt = cnt.toFixed(prec);\ |
7988 | schaersvoo | 7628 | corr = ctx.measureText(disp_cnt).width;\ |
7629 | skip = parseInt(1.2*corr/xstep);\ |
||
7630 | ctx.fillText(disp_cnt,p-0.5*corr,y_basis);\ |
||
7631 | }\ |
||
7632 | else\ |
||
7633 | {\ |
||
7634 | skip--;\ |
||
7614 | schaersvoo | 7635 | };\ |
7988 | schaersvoo | 7636 | cnt = cnt - xmajor;\ |
7614 | schaersvoo | 7637 | };\ |
7638 | };\ |
||
7988 | schaersvoo | 7639 | if( y_strings != null ){\ |
7640 | var len = y_strings.length;if((len/2+0.5)%%2 == 0){ alert(\"yaxis number unpaired: text missing ! \");return;};\ |
||
8110 | schaersvoo | 7641 | ctx.beginPath();\ |
7988 | schaersvoo | 7642 | for(var p = 0 ; p < len ; p = p+2){\ |
7643 | var y_nums = y2px(eval(y_strings[p]));\ |
||
7644 | var y_text = y_strings[p+1];\ |
||
7645 | corr = 2 + tics_length + ctx.measureText(y_text).width;\ |
||
7646 | if( corr > zero_x){corr = parseInt(zero_x+2); }\ |
||
8110 | schaersvoo | 7647 | ctx.fillText(y_text,zero_x - corr,y_nums + 0.5*font_size);\ |
7648 | ctx.moveTo(zero_x - tics_length,y_nums);\ |
||
7649 | ctx.lineTo(zero_x + tics_length,y_nums);\ |
||
7614 | schaersvoo | 7650 | };\ |
8110 | schaersvoo | 7651 | ctx.closePath();\ |
7988 | schaersvoo | 7652 | }\ |
7653 | else\ |
||
7654 | {\ |
||
7991 | schaersvoo | 7655 | if(f_x == 1){ corr = 1.5*tics_length; }\ |
7988 | schaersvoo | 7656 | cnt = px2y(zero_y);skip = 1;\ |
7657 | for( var p = zero_y ; p < ysize ; p = p+ystep){\ |
||
7658 | if(skip == 0 ){\ |
||
7659 | skip = parseInt(1.4*font_size/ystep);\ |
||
7990 | schaersvoo | 7660 | disp_cnt = cnt.toFixed(prec);\ |
7988 | schaersvoo | 7661 | if(f_x == -1 ){ corr = parseInt(zero_x - (2 + tics_length + ctx.measureText(disp_cnt).width));};\ |
7662 | ctx.fillText(disp_cnt,parseInt(corr),parseInt(p+(0.4*font_size)));\ |
||
7663 | }\ |
||
7664 | else\ |
||
7665 | {\ |
||
7666 | skip--;\ |
||
7667 | };\ |
||
7668 | cnt = cnt - ymajor;\ |
||
7614 | schaersvoo | 7669 | };\ |
7988 | schaersvoo | 7670 | corr = 0;cnt = px2y(zero_y);skip = 1;\ |
7991 | schaersvoo | 7671 | if(f_x == 1){ corr = 1.5*tics_length; }\ |
7988 | schaersvoo | 7672 | for( var p = zero_y ; p > 0 ; p = p-ystep){\ |
7673 | if(skip == 0 ){\ |
||
7674 | skip = parseInt(1.4*font_size/ystep);\ |
||
7990 | schaersvoo | 7675 | disp_cnt = cnt.toFixed(prec);\ |
7988 | schaersvoo | 7676 | if(f_x == -1 ){corr = parseInt(zero_x - (2 + tics_length + ctx.measureText(disp_cnt).width));};\ |
7677 | ctx.fillText(disp_cnt,parseInt(corr),parseInt(p+(0.4*font_size)));\ |
||
7678 | }\ |
||
7679 | else\ |
||
7680 | {\ |
||
7681 | skip--;\ |
||
7682 | };\ |
||
7683 | cnt = cnt + ymajor;\ |
||
7614 | schaersvoo | 7684 | };\ |
7685 | };\ |
||
7988 | schaersvoo | 7686 | ctx.stroke();\ |
7614 | schaersvoo | 7687 | ctx.restore();\ |
7688 | };\ |
||
11088 | schaersvoo | 7689 | if( typeof(legend0) !== 'undefined' ){\ |
7988 | schaersvoo | 7690 | ctx.save();\ |
7614 | schaersvoo | 7691 | ctx.globalAlpha = 1.0;\ |
7692 | ctx.font = \"bold \"+font_size+\"px Ariel\";\ |
||
7693 | var y_offset = 2*font_size;\ |
||
7694 | var txt;var txt_size;\ |
||
7695 | var x_offset = xsize - 2*font_size;\ |
||
7956 | schaersvoo | 7696 | var l_length = legend0.length;\ |
11088 | schaersvoo | 7697 | if( typeof(legendcolors0) !== 'undefined' ){\ |
7614 | schaersvoo | 7698 | for(var p = 0 ; p < l_length ; p++){\ |
7956 | schaersvoo | 7699 | barcolor[p] = legendcolors0[p];\ |
7614 | schaersvoo | 7700 | };\ |
7988 | schaersvoo | 7701 | }\ |
7702 | else\ |
||
7703 | {\ |
||
7614 | schaersvoo | 7704 | if( barcolor.length == 0 ){\ |
7705 | for(var p = 0 ; p < l_length ; p++){\ |
||
7706 | barcolor[p] = stroke_color;\ |
||
7707 | };\ |
||
7708 | };\ |
||
7709 | };\ |
||
7710 | for(var p = 0; p < l_length; p++){\ |
||
7711 | ctx.fillStyle = barcolor[p];\ |
||
7956 | schaersvoo | 7712 | txt = legend0[p];\ |
7614 | schaersvoo | 7713 | txt_size = ctx.measureText(txt).width;\ |
7956 | schaersvoo | 7714 | ctx.fillText(legend0[p],x_offset - txt_size, y_offset);\ |
7614 | schaersvoo | 7715 | y_offset = parseInt(y_offset + 1.5*font_size);\ |
7716 | };\ |
||
7988 | schaersvoo | 7717 | ctx.restore();\ |
7614 | schaersvoo | 7718 | };\ |
11088 | schaersvoo | 7719 | if( typeof(barchart_0) !== 'undefined' ){\ |
7991 | schaersvoo | 7720 | ctx.save();\ |
7721 | var num_barcharts = 0;\ |
||
7722 | var bar_name = eval('barchart_0');\ |
||
11088 | schaersvoo | 7723 | while( typeof(bar_name) !== 'undefined' ){\ |
7991 | schaersvoo | 7724 | try{ bar_name = eval('barchart_'+num_barcharts);num_barcharts++;}catch(e){break;};\ |
7725 | };\ |
||
9346 | schaersvoo | 7726 | var bar_width = parseInt(0.8*x2step/(num_barcharts));\ |
7991 | schaersvoo | 7727 | for(var i=0 ; i< num_barcharts ; i++){\ |
7728 | bar_name = eval('barchart_'+i);\ |
||
7729 | var bar_x = new Array();\ |
||
7730 | var bar_y = new Array();\ |
||
7731 | var lb = bar_name.length;\ |
||
7732 | var idx = 0;\ |
||
7733 | var dx = parseInt(0.5*i*bar_width);\ |
||
7734 | for( var p = 0 ; p < lb ; p = p + 3 ){\ |
||
7735 | bar_x[idx] = x2px(bar_name[p]);\ |
||
7736 | bar_y[idx] = y2px(bar_name[p+1]);\ |
||
7737 | barcolor[idx] = bar_name[p+2];\ |
||
7738 | idx++;\ |
||
7739 | };\ |
||
7740 | ctx.globalAlpha = fill_opacity;\ |
||
7741 | for( var p = 0; p < idx ; p++ ){\ |
||
11739 | schaersvoo | 7742 | ctx.beginPath();\ |
7991 | schaersvoo | 7743 | ctx.strokeStyle = barcolor[p];\ |
7744 | ctx.fillStyle = barcolor[p];\ |
||
9346 | schaersvoo | 7745 | ctx.rect(bar_x[p]-0.4*x2step+dx,bar_y[p],bar_width,zero_y - bar_y[p]);\ |
11739 | schaersvoo | 7746 | ctx.fill();\ |
7747 | ctx.stroke();\ |
||
7748 | ctx.closePath();\ |
||
7991 | schaersvoo | 7749 | };\ |
7750 | };\ |
||
7751 | ctx.restore();\ |
||
7752 | };\ |
||
11088 | schaersvoo | 7753 | if( typeof(linegraph_0) !== 'undefined' ){\ |
7996 | schaersvoo | 7754 | ctx.save();\ |
7755 | ctx.globalAlpha = 1.0;\ |
||
7756 | var i = 0;\ |
||
7757 | var line_name = eval('linegraph_'+i);\ |
||
11088 | schaersvoo | 7758 | while ( typeof(line_name) !== 'undefined' ){\ |
7996 | schaersvoo | 7759 | ctx.strokeStyle = 'rgba('+line_name[0]+','+stroke_opacity+')';\ |
7760 | ctx.lineWidth = parseInt(line_name[1]);\ |
||
7761 | if(line_name[2] == \"1\"){\ |
||
7762 | var d1 = parseInt(line_name[3]);\ |
||
7763 | var d2 = parseInt(line_name[4]);\ |
||
7764 | if(ctx.setLineDash){ ctx.setLineDash([d1,d2]); } else { ctx.mozDash = [d1,d2];};\ |
||
7765 | }\ |
||
7766 | else\ |
||
7767 | {\ |
||
7768 | if(ctx.setLineDash){ctx.setLineDash = null;}\ |
||
7769 | if(ctx.mozDash){ctx.mozDash = null;}\ |
||
7770 | };\ |
||
7771 | var data_x = new Array();\ |
||
7772 | var data_y = new Array();\ |
||
7773 | var lb = line_name.length;\ |
||
7774 | var idx = 0;\ |
||
7775 | for( var p = 5 ; p < lb ; p = p + 2 ){\ |
||
7776 | data_x[idx] = x2px(line_name[p]);\ |
||
7777 | data_y[idx] = y2px(line_name[p+1]);\ |
||
7778 | idx++;\ |
||
7779 | };\ |
||
7780 | for( var p = 0; p < idx ; p++){\ |
||
7781 | ctx.beginPath();\ |
||
7782 | ctx.moveTo(data_x[p],data_y[p]);\ |
||
7783 | ctx.lineTo(data_x[p+1],data_y[p+1]);\ |
||
7784 | ctx.stroke();\ |
||
7785 | ctx.closePath();\ |
||
7786 | };\ |
||
7787 | i++;\ |
||
7788 | try{ line_name = eval('linegraph_'+i); }catch(e){ break; }\ |
||
7789 | };\ |
||
7790 | ctx.restore();\ |
||
7791 | };\ |
||
7614 | schaersvoo | 7792 | return;\ |
7989 | schaersvoo | 7793 | };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 7794 | break; |
8224 | bpr | 7795 | |
7614 | schaersvoo | 7796 | case DRAW_PIECHART: |
7987 | schaersvoo | 7797 | fprintf(js_include_file,"\n<!-- draw piecharts -->\n\ |
7956 | schaersvoo | 7798 | function draw_piechart(canvas_type,x_center,y_center,radius, data_color_list,fill_opacity,legend_cnt,font_family){\ |
7614 | schaersvoo | 7799 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
7800 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
7801 | }\ |
||
7802 | else\ |
||
7803 | {\ |
||
7804 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
7805 | };\ |
||
7806 | var ld = data_color_list.length;\ |
||
7807 | var sum = 0;\ |
||
7808 | var idx = 0;\ |
||
7956 | schaersvoo | 7809 | var font_size = parseInt(font_family.replace(/[^0-9\\.]+/g, \"\"));\ |
7614 | schaersvoo | 7810 | var colors = new Array();\ |
7811 | var data = new Array();\ |
||
7812 | for(var p = 0;p < ld; p = p + 2){\ |
||
7813 | data[idx] = parseFloat(data_color_list[p]);\ |
||
7814 | sum = sum + data[idx];\ |
||
7815 | colors[idx] = data_color_list[p+1];\ |
||
7816 | idx++;\ |
||
7817 | };\ |
||
7818 | var ctx = obj.getContext(\"2d\");\ |
||
7819 | ctx.save();\ |
||
7820 | var angle;\ |
||
7821 | var angle_end = 0;\ |
||
7822 | var offset = Math.PI / 2;\ |
||
7823 | ctx.globalAlpha = fill_opacity;\ |
||
7824 | for(var p=0; p < idx; p++){\ |
||
7825 | ctx.beginPath();\ |
||
7826 | ctx.fillStyle = colors[p];\ |
||
7827 | ctx.moveTo(x_center,y_center);\ |
||
7828 | angle = Math.PI * (2 * data[p] / sum);\ |
||
7829 | ctx.arc(x_center,y_center, radius, angle_end - offset, angle_end + angle - offset, false);\ |
||
7830 | ctx.lineTo(x_center, y_center);\ |
||
7831 | ctx.fill();\ |
||
7832 | ctx.closePath();\ |
||
7833 | angle_end = angle_end + angle;\ |
||
7834 | };\ |
||
11088 | schaersvoo | 7835 | if(typeof(legend0) !== 'undefined'){\ |
7956 | schaersvoo | 7836 | var legenda = eval(\"legend\"+legend_cnt);\ |
7614 | schaersvoo | 7837 | ctx.globalAlpha = 1.0;\ |
7956 | schaersvoo | 7838 | ctx.font = font_family;\ |
7614 | schaersvoo | 7839 | var y_offset = font_size; \ |
7840 | var x_offset = 0;\ |
||
7841 | var txt;var txt_size;\ |
||
7842 | for(var p = 0; p < idx; p++){\ |
||
7843 | ctx.fillStyle = colors[p];\ |
||
7956 | schaersvoo | 7844 | txt = legenda[p];\ |
7614 | schaersvoo | 7845 | txt_size = ctx.measureText(txt).width;\ |
7846 | if( x_center + radius + txt_size > xsize ){ x_offset = x_center + radius + txt_size - xsize;} else { x_offset = 0; };\ |
||
7956 | schaersvoo | 7847 | ctx.fillText(txt,x_center + radius - x_offset, y_center - radius + y_offset);\ |
7614 | schaersvoo | 7848 | y_offset = parseInt(y_offset + 1.5*font_size);\ |
7849 | };\ |
||
7850 | };\ |
||
7851 | ctx.restore();\ |
||
7956 | schaersvoo | 7852 | };",canvas_root_id,canvas_root_id,canvas_root_id); |
8224 | bpr | 7853 | |
7614 | schaersvoo | 7854 | break; |
9433 | schaersvoo | 7855 | case DRAW_JSBOXPLOT: |
7856 | fprintf(js_include_file,"\n<!-- draw jsboxplots -->\n\ |
||
7857 | function statistics(data){\ |
||
7858 | var len = data.length;\ |
||
7859 | var min = 10000000;\ |
||
7860 | var max = -10000000;\ |
||
7861 | var sum = 0;var d;\ |
||
7862 | for(var i=0;i<len;i++){\ |
||
7863 | d = data[i];\ |
||
7864 | if(d < min){min = d;}else{if(d > max){max = d;};};\ |
||
7865 | sum+= parseFloat(data[i]);\ |
||
7866 | };\ |
||
7867 | var mean = parseFloat(sum/len);\ |
||
7868 | var variance = 0;\ |
||
7869 | for(var i=0;i<len;i++){\ |
||
7870 | d = data[i];\ |
||
7871 | variance += (d - mean)*(d - mean);\ |
||
7872 | };\ |
||
7873 | variance = parseFloat(variance / len);\ |
||
7874 | var std = Math.sqrt(variance);\ |
||
7875 | data.sort(function(a,b){return a - b;});\ |
||
7876 | var median;var Q1;var Q3;\ |
||
7877 | var half = Math.floor(0.5*len);\ |
||
7878 | var q1 = Math.floor(0.25*len);\ |
||
7879 | var q3 = Math.floor(0.75*len);\ |
||
7880 | var half = Math.floor(0.5*len);\ |
||
7881 | if(len %%2 == 1){\ |
||
7882 | median = data[half];\ |
||
7883 | Q1 = data[q1];\ |
||
7884 | Q3 = data[q3];\ |
||
7885 | }\ |
||
7886 | else\ |
||
7887 | {\ |
||
7888 | median = (data[half - 1] + data[half] )/2;\ |
||
7889 | Q1 = (data[q1 - 1] + data[q1] )/2;\ |
||
7890 | Q3 = (data[q3 - 1] + data[q3] )/2;\ |
||
7891 | };\ |
||
7892 | return [min,Q1,median,Q3,max];\ |
||
7893 | };"); |
||
7894 | break; |
||
7895 | case DRAW_BOXPLOT: |
||
7896 | fprintf(js_include_file,"\n<!-- draw boxplots -->\n\ |
||
9465 | schaersvoo | 7897 | draw_boxplot = function(canvas_type,xy,hw,cxy,data,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype0,dashtype1){\ |
9433 | schaersvoo | 7898 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
7899 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
7900 | }\ |
||
7901 | else\ |
||
7902 | {\ |
||
7903 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
7904 | };\ |
||
7905 | var ctx = obj.getContext(\"2d\");\ |
||
7906 | ctx.clearRect(0,0,xsize,ysize);\ |
||
7907 | ctx.save();\ |
||
7908 | ctx.lineWidth = line_width;\ |
||
11088 | schaersvoo | 7909 | if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
9433 | schaersvoo | 7910 | ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
7911 | ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\ |
||
7912 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{if(ctx.mozDash){ ctx.mozDash = [dashtype0,dashtype1];};};};\ |
||
7913 | var hh = 0.25*hw;\ |
||
9465 | schaersvoo | 7914 | switch(boxplot_source){\ |
11088 | schaersvoo | 7915 | case 1: if( typeof(jsboxplot_data) === 'undefined'){return;};data = statistics(jsboxplot_data);break;\ |
7916 | case 2: if( typeof(student_boxplot_data) === 'undefined'){return;};data = statistics(student_boxplot_data);break;\ |
||
7917 | case 3: if( typeof(student_boxplot) === 'undefined'){return;};data = student_boxplot;break;\ |
||
9465 | schaersvoo | 7918 | default: break;\ |
9433 | schaersvoo | 7919 | };\ |
7920 | var min,Q1,median,Q3,max;\ |
||
7921 | if(xy == 1 ){\ |
||
7922 | min=x2px(data[0]);Q1=x2px(data[1]);median=x2px(data[2]);Q3=x2px(data[3]);max=x2px(data[4]);\ |
||
7923 | hh = Math.abs(y2px(hh) - y2px(ystart));\ |
||
7924 | hw = Math.abs(y2px(hw) - y2px(ystart));\ |
||
7925 | cxy = y2px(cxy);\ |
||
9465 | schaersvoo | 7926 | ctx.beginPath();\ |
9433 | schaersvoo | 7927 | ctx.moveTo(min,cxy);\ |
7928 | ctx.lineTo(Q1,cxy);\ |
||
7929 | ctx.moveTo(Q3,cxy);\ |
||
7930 | ctx.lineTo(max,cxy);\ |
||
7931 | ctx.moveTo(min,cxy+hh);\ |
||
7932 | ctx.lineTo(min,cxy-hh);\ |
||
7933 | ctx.moveTo(max,cxy+hh);\ |
||
7934 | ctx.lineTo(max,cxy-hh);\ |
||
9465 | schaersvoo | 7935 | ctx.closePath();\ |
7936 | ctx.stroke();\ |
||
7937 | ctx.beginPath();\ |
||
9433 | schaersvoo | 7938 | ctx.rect(Q1,cxy-2*hh,median-Q1,hw);\ |
9465 | schaersvoo | 7939 | ctx.closePath();\ |
7940 | if( use_filled == 1 ){\ |
||
7941 | ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+fill_opacity+\")\";\ |
||
7942 | ctx.fill();\ |
||
7943 | };\ |
||
7944 | ctx.stroke();\ |
||
7945 | ctx.beginPath();\ |
||
9433 | schaersvoo | 7946 | ctx.rect(median,cxy-2*hh,Q3-median,hw);\ |
9465 | schaersvoo | 7947 | ctx.closePath();\ |
7948 | if( use_filled == 1 ){\ |
||
7949 | ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\ |
||
7950 | ctx.fill();\ |
||
7951 | };\ |
||
7952 | ctx.stroke();\ |
||
9433 | schaersvoo | 7953 | }else{\ |
7954 | min=y2px(data[0]);Q1=y2px(data[1]);median=y2px(data[2]);Q3=y2px(data[3]);max=y2px(data[4]);\ |
||
7955 | hh = Math.abs(x2px(hh) - x2px(xstart));\ |
||
7956 | hw = Math.abs(x2px(hw) - x2px(xstart));\ |
||
7957 | cxy = x2px(cxy);\ |
||
9465 | schaersvoo | 7958 | ctx.beginPath();\ |
9433 | schaersvoo | 7959 | ctx.moveTo(cxy,min);\ |
7960 | ctx.lineTo(cxy,Q1);\ |
||
7961 | ctx.moveTo(cxy,Q3);\ |
||
7962 | ctx.lineTo(cxy,max);\ |
||
7963 | ctx.moveTo(cxy + hh,min);\ |
||
7964 | ctx.lineTo(cxy - hh,min);\ |
||
7965 | ctx.moveTo(cxy + hh,max);\ |
||
7966 | ctx.lineTo(cxy - hh,max);\ |
||
9465 | schaersvoo | 7967 | ctx.closePath;\ |
7968 | ctx.stroke();\ |
||
7969 | ctx.beginPath();\ |
||
9433 | schaersvoo | 7970 | ctx.rect(cxy - 2*hh,Q1,hw,median - Q1);\ |
9465 | schaersvoo | 7971 | ctx.closePath();\ |
7972 | if( use_filled == 1 ){\ |
||
7973 | ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+fill_opacity+\")\";\ |
||
7974 | ctx.fill();\ |
||
7975 | };\ |
||
7976 | ctx.stroke();\ |
||
7977 | ctx.beginPath();\ |
||
9433 | schaersvoo | 7978 | ctx.rect(cxy - 2*hh,median,hw,Q3 - median);\ |
9465 | schaersvoo | 7979 | ctx.closePath();\ |
7980 | if( use_filled == 1 ){\ |
||
7981 | ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\ |
||
7982 | ctx.fill();\ |
||
7983 | };\ |
||
7984 | ctx.stroke();\ |
||
9433 | schaersvoo | 7985 | };\ |
7986 | ctx.restore();};",canvas_root_id,canvas_root_id,canvas_root_id); |
||
7987 | break; |
||
7614 | schaersvoo | 7988 | case DRAW_ARCS: |
7989 | fprintf(js_include_file,"\n<!-- draw arcs -->\n\ |
||
8105 | schaersvoo | 7990 | 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 | 7991 | ctx.save();\ |
7992 | if( use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{if(ctx.mozDash){ ctx.mozDash = [dashtype0,dashtype1];};};};\ |
||
8071 | schaersvoo | 7993 | if( use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);};\ |
7614 | schaersvoo | 7994 | if( use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);};\ |
7995 | if(end < start){var tmp = end;end = start;start=tmp;};\ |
||
8071 | schaersvoo | 7996 | start = 360 - start;\ |
7997 | end = 360 - end;\ |
||
7614 | schaersvoo | 7998 | ctx.lineWidth = line_width;\ |
11088 | schaersvoo | 7999 | if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
7614 | schaersvoo | 8000 | ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
8071 | schaersvoo | 8001 | ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\ |
8002 | ctx.beginPath();\ |
||
8003 | ctx.moveTo(xc,yc);\ |
||
8004 | ctx.arc(xc, yc, r, start*(Math.PI / 180), end*(Math.PI / 180),true);\ |
||
8005 | ctx.lineTo(xc,yc);\ |
||
8006 | ctx.closePath();\ |
||
7614 | schaersvoo | 8007 | if( use_filled == 1 ){\ |
8008 | ctx.fill();\ |
||
8071 | schaersvoo | 8009 | };\ |
8010 | ctx.stroke();\ |
||
7614 | schaersvoo | 8011 | ctx.restore();\ |
8071 | schaersvoo | 8012 | };"); |
8224 | bpr | 8013 | |
7614 | schaersvoo | 8014 | break; |
7983 | schaersvoo | 8015 | case DRAW_CENTERSTRING: |
8016 | fprintf(js_include_file,"\n<!-- draw centerstring -->\n\ |
||
8105 | schaersvoo | 8017 | var draw_centerstring = function(canvas_type,y,font_family,stroke_color,stroke_opacity,text){\ |
7983 | schaersvoo | 8018 | var obj;\ |
8019 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
8020 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
8021 | }\ |
||
8022 | else\ |
||
8023 | {\ |
||
8024 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
8025 | };\ |
||
8026 | var ctx = obj.getContext(\"2d\");\ |
||
8027 | ctx.save();\ |
||
9481 | schaersvoo | 8028 | ctx.clearRect(0,0,xsize,ysize);\ |
7983 | schaersvoo | 8029 | ctx.font = font_family;\ |
8030 | ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
8031 | var stringwidth = ctx.measureText(text).width;\ |
||
8032 | var x = parseInt((xsize - stringwidth)/2);if( x < 0 ){x = 0;};\ |
||
8033 | ctx.fillText(text,x,y2px(y));\ |
||
9481 | schaersvoo | 8034 | ctx.restore();\ |
7983 | schaersvoo | 8035 | return;\ |
8036 | };",canvas_root_id,canvas_root_id,canvas_root_id); |
||
8037 | break; |
||
7614 | schaersvoo | 8038 | case DRAW_TEXTS: |
8039 | fprintf(js_include_file,"\n<!-- draw text -->\n\ |
||
8105 | schaersvoo | 8040 | var draw_text = function(canvas_type,x,y,font_size,font_family,stroke_color,stroke_opacity,angle2,text,use_rotate,angle,use_affine,affine_matrix){\ |
7614 | schaersvoo | 8041 | var obj;\ |
8042 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
8043 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
8044 | }\ |
||
8045 | else\ |
||
8046 | {\ |
||
8047 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
8048 | };\ |
||
8049 | var ctx = obj.getContext(\"2d\");\ |
||
9868 | schaersvoo | 8050 | if( font_family != 'null' ){\ |
8051 | ctx.font = font_family;\ |
||
8052 | }\ |
||
8053 | else\ |
||
8054 | {\ |
||
8055 | ctx.font = font_size+'px Ariel';\ |
||
8056 | };\ |
||
7614 | schaersvoo | 8057 | if(angle2 == 0 && angle != 0){\ |
8058 | ctx.save();\ |
||
8071 | schaersvoo | 8059 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 8060 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
8061 | };\ |
||
8062 | ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
8063 | if(angle2 != 0){\ |
||
8064 | ctx.save();\ |
||
8065 | ctx.translate(x,y);\ |
||
8066 | ctx.rotate((360-angle2)*(Math.PI / 180));\ |
||
8067 | ctx.fillText(text,0,0);\ |
||
8068 | ctx.restore();\ |
||
8069 | }else{ctx.fillText(text,x,y);};\ |
||
8070 | ctx.restore();\ |
||
8071 | return;\ |
||
7653 | schaersvoo | 8072 | };",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 8073 | break; |
8074 | case DRAW_CURVE: |
||
8075 | fprintf(js_include_file,"\n<!-- draw curve -->\n\ |
||
8105 | schaersvoo | 8076 | 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 | 8077 | var obj;\ |
8078 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
8079 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
8080 | }\ |
||
8081 | else\ |
||
8082 | {\ |
||
8083 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
8084 | };\ |
||
8085 | var ctx = obj.getContext(\"2d\");\ |
||
8086 | ctx.save();\ |
||
8071 | schaersvoo | 8087 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 8088 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
8089 | ctx.beginPath();ctx.lineWidth = line_width;\ |
||
11088 | schaersvoo | 8090 | if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
7614 | schaersvoo | 8091 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
8092 | ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
8093 | ctx.moveTo(x2px(x_points[0]),y2px(y_points[0]));\ |
||
8094 | for(var p = 1 ; p < x_points.length ; p++){\ |
||
8095 | if( y2px(y_points[p]) > -5 && y2px(y_points[p]) < ysize+5 ){\ |
||
8096 | ctx.lineTo(x2px(x_points[p]),y2px(y_points[p]));\ |
||
8097 | }\ |
||
8098 | else\ |
||
8099 | {\ |
||
8100 | ctx.stroke();\ |
||
8101 | ctx.beginPath();\ |
||
8102 | p++;\ |
||
8103 | ctx.moveTo(x2px(x_points[p]),y2px(y_points[p]));\ |
||
8104 | };\ |
||
8105 | };\ |
||
8106 | ctx.stroke();\ |
||
8107 | ctx.restore();\ |
||
7653 | schaersvoo | 8108 | };",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 8109 | break; |
8224 | bpr | 8110 | |
7614 | schaersvoo | 8111 | case DRAW_INPUTS: |
8112 | fprintf(js_include_file,"\n<!-- draw input fields -->\n\ |
||
11803 | schaersvoo | 8113 | var draw_inputs = function(root_id,input_cnt,x,y,size,readonly,style,value,use_offset){\ |
7614 | schaersvoo | 8114 | var canvas_div = document.getElementById(\"canvas_div\"+root_id);\ |
8115 | var input = document.createElement(\"input\");\ |
||
8116 | input.setAttribute(\"id\",\"canvas_input\"+input_cnt);\ |
||
8117 | input.setAttribute(\"style\",\"position:absolute;left:\"+x+\"px;top:\"+y+\"px;\"+style);\ |
||
8118 | input.setAttribute(\"size\",size);\ |
||
8119 | input.setAttribute(\"value\",value);\ |
||
7877 | schaersvoo | 8120 | if( readonly == 0 || wims_status == \"done\" ){ input.setAttribute(\"readonly\",\"readonly\");if( wims_status == \"done\" ){input.setAttribute(\"value\",\"\");};};\ |
11803 | schaersvoo | 8121 | canvas_div.appendChild(input);\ |
8122 | if(use_offset != 0 ){ center_input('canvas_input'+input_cnt,x,y,style);};\ |
||
8123 | };\ |
||
8124 | function center_input(id,x,y,style){\ |
||
8125 | var inp = document.getElementById(id);\ |
||
8126 | var pos = inp.getBoundingClientRect();\ |
||
8127 | var center_x = parseInt(x - 0.5*(pos.width));\ |
||
8128 | var center_y = parseInt(y - 0.5*(pos.height));\ |
||
8129 | try{ inp.setAttribute(\"style\",\"position:absolute;left:\"+center_x+\"px;top:\"+center_y+\"px;\"+style );}\ |
||
8130 | catch(e){return;};\ |
||
8131 | };"); |
||
7614 | schaersvoo | 8132 | break; |
8224 | bpr | 8133 | |
7614 | schaersvoo | 8134 | case DRAW_TEXTAREAS: |
8135 | fprintf(js_include_file,"\n<!-- draw text area inputfields -->\n\ |
||
8105 | schaersvoo | 8136 | var draw_textareas = function(root_id,input_cnt,x,y,cols,rows,readonly,style,value){\ |
7614 | schaersvoo | 8137 | var canvas_div = document.getElementById(\"canvas_div\"+root_id);\ |
8138 | var textarea = document.createElement(\"textarea\");\ |
||
8139 | textarea.setAttribute(\"id\",\"canvas_input\"+input_cnt);\ |
||
8140 | textarea.setAttribute(\"style\",\"position:absolute;left:\"+x+\"px;top:\"+y+\"px;\"+style);\ |
||
8141 | textarea.setAttribute(\"cols\",cols);\ |
||
8142 | textarea.setAttribute(\"rows\",rows);\ |
||
7877 | schaersvoo | 8143 | textarea.value = value;\ |
8144 | if( readonly == 0 || wims_status == \"done\" ){ textarea.setAttribute(\"readonly\",\"readonly\");if( wims_status == \"done\" ){textarea.value=\"\";};};\ |
||
7653 | schaersvoo | 8145 | canvas_div.appendChild(textarea);};"); |
7614 | schaersvoo | 8146 | break; |
8224 | bpr | 8147 | |
7614 | schaersvoo | 8148 | case DRAW_PIXELS: |
8149 | fprintf(js_include_file,"\n<!-- draw pixel -->\n\ |
||
8105 | schaersvoo | 8150 | var draw_setpixel = function(x,y,color,opacity,pixelsize){\ |
7614 | schaersvoo | 8151 | var canvas = create_canvas%d(10,xsize,ysize);\ |
8152 | var d = 0.5*pixelsize;\ |
||
8153 | var ctx = canvas.getContext(\"2d\");\ |
||
9462 | schaersvoo | 8154 | if(pixelsize%%2 == 1){ ctx.translate(0.5,0.5);};\ |
7614 | schaersvoo | 8155 | ctx.fillStyle = \"rgba(\"+color+\",\"+opacity+\")\";\ |
8156 | ctx.clearRect(0,0,xsize,ysize);\ |
||
8157 | for(var p=0; p<x.length;p++){\ |
||
8158 | ctx.fillRect( x2px(x[p]) - d, y2px(y[p]) - d , pixelsize, pixelsize );\ |
||
8159 | };\ |
||
8160 | ctx.fill();ctx.stroke();\ |
||
8161 | };",canvas_root_id); |
||
8162 | break; |
||
8163 | |||
8164 | case DRAW_CLOCK: |
||
8165 | fprintf(js_include_file,"\n<!-- begin command clock -->\n\ |
||
8166 | var clock_canvas = create_canvas%d(%d,xsize,ysize);\ |
||
8167 | var clock_ctx = clock_canvas.getContext(\"2d\");\ |
||
8168 | var clock = function(xc,yc,radius,H,M,S,type,interaction,h_color,m_color,s_color,bg_color,fg_color){\ |
||
8130 | schaersvoo | 8169 | clock_ctx.clearRect(xc - radius,yc - radius,2*radius,2*radius);\ |
7614 | schaersvoo | 8170 | clock_ctx.save();\ |
7997 | schaersvoo | 8171 | clock_ctx.globalAlpha = clock_bg_opacity;\ |
7614 | schaersvoo | 8172 | this.type = type || 0;\ |
8173 | this.interaction = interaction || 0;\ |
||
7862 | schaersvoo | 8174 | this.H = H;\ |
8175 | this.M = M;\ |
||
8176 | this.S = S;\ |
||
7614 | schaersvoo | 8177 | this.xc = xc || xsize/2;\ |
8178 | this.yc = yc || ysize/2;\ |
||
8179 | this.radius = radius || xsize/4;\ |
||
8180 | var font_size = parseInt(0.2*this.radius);\ |
||
8181 | this.H_color = h_color || \"blue\";\ |
||
8182 | this.M_color = m_color || \"blue\";\ |
||
8183 | this.S_color = s_color || \"blue\";\ |
||
8184 | this.fg_color = fg_color || \"red\";\ |
||
8185 | this.bg_color = bg_color || \"white\";\ |
||
8186 | clock_ctx.translate(this.xc,this.yc);\ |
||
8187 | clock_ctx.beginPath();\ |
||
8188 | clock_ctx.arc(0,0,this.radius,0,2*Math.PI,false);\ |
||
8189 | clock_ctx.fillStyle = this.bg_color;\ |
||
8190 | clock_ctx.fill();\ |
||
8191 | clock_ctx.closePath();\ |
||
8192 | clock_ctx.beginPath();\ |
||
8193 | clock_ctx.font = font_size+\"px Arial\";\ |
||
8194 | clock_ctx.fillStyle = this.fg_color;\ |
||
8195 | clock_ctx.textAlign = \"center\";\ |
||
8196 | clock_ctx.textBaseline = 'middle';\ |
||
8197 | var angle;var x1,y1,x2,y2;\ |
||
8198 | var angle_cos;var angle_sin;\ |
||
7997 | schaersvoo | 8199 | clock_ctx.globalAlpha = clock_fg_opacity;\ |
7614 | schaersvoo | 8200 | switch(type){\ |
8201 | case 0:clock_ctx.beginPath();\ |
||
8202 | for(var p = 1; p <= 12 ; p++){\ |
||
8203 | angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 12));\ |
||
8204 | angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 12));\ |
||
8205 | x1 = 0.8*angle_cos;y1 = 0.8*angle_sin;x2 = angle_cos;y2 = angle_sin;\ |
||
8206 | clock_ctx.moveTo(x1,y1);\ |
||
8207 | clock_ctx.lineTo(x2,y2);\ |
||
8208 | };\ |
||
8209 | for(var p = 1; p <= 60 ; p++){\ |
||
8210 | angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 60));\ |
||
8211 | angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 60));\ |
||
8212 | x1 = 0.9*angle_cos;y1 = 0.9*angle_sin;x2 = angle_cos;y2 = angle_sin;\ |
||
8213 | clock_ctx.moveTo(x1,y1);\ |
||
8214 | clock_ctx.lineTo(x2,y2);\ |
||
8215 | };\ |
||
8216 | clock_ctx.closePath();\ |
||
8217 | clock_ctx.stroke();\ |
||
8218 | break;\ |
||
8219 | case 1:\ |
||
8220 | 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 | 8221 | case 2:\ |
8222 | 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 | 8223 | clock_ctx.beginPath();\ |
8224 | for(var p = 1; p <= 12 ; p++){\ |
||
8225 | angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 12));\ |
||
8226 | angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 12));\ |
||
8227 | x1 = 0.9*angle_cos;y1 = 0.9*angle_sin;x2 = angle_cos;y2 = angle_sin;\ |
||
8228 | clock_ctx.moveTo(x1,y1);\ |
||
8229 | clock_ctx.lineTo(x2,y2);\ |
||
8230 | };\ |
||
8231 | for(var p = 1; p <= 60 ; p++){\ |
||
8232 | angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 60));\ |
||
8233 | angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 60));\ |
||
8234 | x1 = 0.95*angle_cos;y1 = 0.95*angle_sin;x2 = angle_cos;y2 = angle_sin;\ |
||
8235 | clock_ctx.moveTo(x1,y1);\ |
||
8236 | clock_ctx.lineTo(x2,y2);\ |
||
8237 | };\ |
||
8238 | clock_ctx.closePath();\ |
||
8239 | clock_ctx.stroke();\ |
||
8240 | break;\ |
||
8241 | };\ |
||
8242 | angle = (this.H - 3 + this.M/60 ) * 2 * Math.PI / 12;\ |
||
8243 | clock_ctx.rotate(angle);\ |
||
8244 | clock_ctx.beginPath();\ |
||
8245 | clock_ctx.moveTo(-3, -2);\ |
||
8246 | clock_ctx.lineTo(-3, 2);\ |
||
11026 | bpr | 8247 | clock_ctx.lineTo(this.radius * 0.6, 1);\ |
8248 | clock_ctx.lineTo(this.radius * 0.6, -1);\ |
||
7614 | schaersvoo | 8249 | clock_ctx.fillStyle = this.H_color;\ |
8250 | clock_ctx.fill();\ |
||
8251 | clock_ctx.rotate(-angle);\ |
||
8252 | angle = (this.M - 15 + this.S/60) * 2 * Math.PI / 60;\ |
||
8253 | clock_ctx.rotate(angle);\ |
||
8254 | clock_ctx.beginPath();\ |
||
8255 | clock_ctx.moveTo(-3, -2);\ |
||
8256 | clock_ctx.lineTo(-3, 2);\ |
||
8257 | clock_ctx.lineTo(this.radius * 0.8, 1);\ |
||
8258 | clock_ctx.lineTo(this.radius * 0.8, -1);\ |
||
8259 | clock_ctx.fillStyle = this.M_color;\ |
||
8260 | clock_ctx.fill();\ |
||
8261 | clock_ctx.rotate(-angle);\ |
||
8262 | angle = (this.S - 15) * 2 * Math.PI / 60;\ |
||
8263 | clock_ctx.rotate(angle);\ |
||
8264 | clock_ctx.beginPath();\ |
||
8265 | clock_ctx.moveTo(0,0);\ |
||
11026 | bpr | 8266 | clock_ctx.lineTo(this.radius * 0.9, 1);\ |
8267 | clock_ctx.lineTo(this.radius * 0.9, -1);\ |
||
7614 | schaersvoo | 8268 | clock_ctx.strokeStyle = this.S_color;\ |
8269 | clock_ctx.stroke();\ |
||
8270 | clock_ctx.restore();\ |
||
7653 | schaersvoo | 8271 | };",canvas_root_id,CLOCK_CANVAS); |
7614 | schaersvoo | 8272 | break; |
8273 | |||
8274 | case DRAW_LATTICE: |
||
8275 | fprintf(js_include_file,"\n<!-- draw lattice -->\n\ |
||
8105 | schaersvoo | 8276 | var draw_lattice = function(canvas_type,line_width,x0,y0,dx1,dy1,dx2,dy2,n1,n2,fill_color,fill_opacity,stroke_color,stroke_opacity,use_rotate,angle,use_affine,affine_matrix){\ |
7614 | schaersvoo | 8277 | var obj;\ |
8278 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
8279 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
8280 | }\ |
||
8281 | else\ |
||
8282 | {\ |
||
8283 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
8284 | };\ |
||
8285 | var ctx = obj.getContext(\"2d\");\ |
||
8286 | ctx.save();\ |
||
8071 | schaersvoo | 8287 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 8288 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
8289 | ctx.fillStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
8290 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
8291 | var radius = line_width;\ |
||
8292 | var x = 0;\ |
||
8293 | var y = 0;\ |
||
8294 | var x_step_px = xsize/(xmax-xmin);\ |
||
8295 | var y_step_px = ysize/(ymax-ymin);\ |
||
8296 | var xv1 = dx1*x_step_px;\ |
||
8297 | var yv1 = dy1*y_step_px;\ |
||
8298 | var xv2 = dx2*x_step_px;\ |
||
8299 | var yv2 = dy2*y_step_px;\ |
||
8300 | for(var p = 0; p < n1 ;p++){\ |
||
8301 | x = p*xv1 + x0;\ |
||
8302 | y = p*yv1 + y0;\ |
||
8303 | for(var c = 0; c < n2 ; c++){\ |
||
8304 | ctx.beginPath();\ |
||
8305 | ctx.arc(x+c*xv2,y+c*yv2,radius,0,2*Math.PI,false);\ |
||
8306 | ctx.fill();\ |
||
8307 | ctx.stroke();\ |
||
8308 | ctx.closePath();\ |
||
8309 | };\ |
||
8310 | };\ |
||
8311 | ctx.restore();\ |
||
8312 | return;\ |
||
7653 | schaersvoo | 8313 | };",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 8314 | break; |
7735 | schaersvoo | 8315 | case DRAW_XYLOGSCALE: |
8316 | fprintf(js_include_file,"\n<!-- draw xylogscale -->\n\ |
||
8105 | schaersvoo | 8317 | 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 | 8318 | var obj;\ |
8319 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
8320 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
8321 | }\ |
||
8322 | else\ |
||
8323 | {\ |
||
8324 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
8325 | };\ |
||
8326 | var ctx = obj.getContext(\"2d\");\ |
||
7735 | schaersvoo | 8327 | ctx.clearRect(0,0,xsize,ysize);\ |
7956 | schaersvoo | 8328 | ctx.save();\ |
7739 | schaersvoo | 8329 | var xmarge;var ymarge;var x_e;var y_e;var num;var corr;var xtxt;var ytxt;\ |
7956 | schaersvoo | 8330 | var x_min = Math.log(xmin)/Math.log(xlogbase);\ |
8331 | var x_max = Math.log(xmax)/Math.log(xlogbase);\ |
||
8332 | var y_min = Math.log(ymin)/Math.log(ylogbase);\ |
||
8333 | var y_max = Math.log(ymax)/Math.log(ylogbase);\ |
||
7739 | schaersvoo | 8334 | if(use_axis_numbering == 1){\ |
7956 | schaersvoo | 8335 | ctx.font = font_family;\ |
8336 | xmarge = ctx.measureText(ylogbase+'^'+y_max.toFixed(0)+' ').width;\ |
||
8337 | ymarge = parseInt(1.5*font_size);\ |
||
8338 | ctx.save();\ |
||
8339 | ctx.fillStyle=\"rgba(255,215,0,0.2)\";\ |
||
8340 | ctx.rect(0,0,xmarge,ysize);\ |
||
8341 | ctx.rect(0,ysize-ymarge,xsize,ysize);\ |
||
8342 | ctx.fill();\ |
||
8343 | ctx.restore();\ |
||
8344 | }else{xmarge = 0;ymarge = 0;};\ |
||
11088 | schaersvoo | 8345 | if( typeof(xaxislabel) !== 'undefined' ){\ |
7956 | schaersvoo | 8346 | ctx.save();\ |
8347 | ctx.font = \"italic \"+font_size+\"px Ariel\";\ |
||
8348 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\ |
||
8349 | corr = ctx.measureText(xaxislabel).width;\ |
||
8350 | ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\ |
||
8351 | ctx.restore();\ |
||
8352 | };\ |
||
11088 | schaersvoo | 8353 | if( typeof(yaxislabel) !== 'undefined' ){\ |
7956 | schaersvoo | 8354 | ctx.save();\ |
8355 | ctx.font = \"italic \"+font_size+\"px Ariel\";\ |
||
8356 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\ |
||
8357 | corr = ctx.measureText(yaxislabel).width;\ |
||
8358 | ctx.translate(xmarge+font_size,corr+font_size);\ |
||
8359 | ctx.rotate(-0.5*Math.PI);\ |
||
8360 | ctx.fillText(yaxislabel,0,0);\ |
||
8361 | ctx.restore();\ |
||
8362 | };\ |
||
8363 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\ |
||
8364 | ctx.lineWidth = line_width;\ |
||
8365 | for(var p = x_min; p <= x_max ; p++){\ |
||
8366 | num = Math.pow(xlogbase,p);\ |
||
8367 | for(var i = 1 ; i < xlogbase ; i++){\ |
||
8368 | x_e = x2px(i*num);\ |
||
7735 | schaersvoo | 8369 | if( i == 1 ){\ |
7956 | schaersvoo | 8370 | ctx.lineWidth = line_width;\ |
8371 | ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\ |
||
7738 | schaersvoo | 8372 | if( use_axis_numbering == 1 && p > x_min){\ |
7956 | schaersvoo | 8373 | xtxt = xlogbase+'^'+p.toFixed(0);\ |
8374 | corr = 0.5*(ctx.measureText(xtxt).width);\ |
||
8375 | ctx.fillText(xtxt,x_e - corr,ysize - 4);\ |
||
8376 | };\ |
||
7735 | schaersvoo | 8377 | }else{\ |
7956 | schaersvoo | 8378 | ctx.lineWidth = 0.2*line_width;\ |
8379 | ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\ |
||
8380 | };\ |
||
7738 | schaersvoo | 8381 | if( x_e >= xmarge ){\ |
7956 | schaersvoo | 8382 | ctx.beginPath();\ |
8383 | ctx.moveTo(x_e,0);\ |
||
8384 | ctx.lineTo(x_e,ysize - ymarge);\ |
||
8385 | ctx.stroke();\ |
||
8386 | ctx.closePath();\ |
||
7738 | schaersvoo | 8387 | };\ |
7956 | schaersvoo | 8388 | };\ |
8389 | };\ |
||
8390 | for(var p = y_min; p <= y_max ; p++){\ |
||
8391 | num = Math.pow(ylogbase,p);\ |
||
8392 | for(var i = 1 ; i < ylogbase ; i++){\ |
||
8393 | y_e = y2px(i*num);\ |
||
8394 | if( i == 1 ){\ |
||
8395 | ctx.lineWidth = line_width;\ |
||
7735 | schaersvoo | 8396 | ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\ |
7956 | schaersvoo | 8397 | if( use_axis_numbering == 1 && p > y_min){\ |
8398 | ctx.fillText(ylogbase+'^'+p.toFixed(0),0,y_e);\ |
||
8399 | };\ |
||
8400 | }else{\ |
||
8401 | ctx.lineWidth = 0.2*line_width;\ |
||
8402 | ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\ |
||
8403 | };\ |
||
8404 | ctx.beginPath();\ |
||
8405 | ctx.moveTo(xmarge,y_e);\ |
||
8406 | ctx.lineTo(xsize,y_e);\ |
||
8407 | ctx.stroke();\ |
||
8408 | ctx.closePath();\ |
||
8409 | };\ |
||
8410 | };\ |
||
7735 | schaersvoo | 8411 | ctx.restore();\ |
8412 | };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id); |
||
8413 | break; |
||
7614 | schaersvoo | 8414 | |
7735 | schaersvoo | 8415 | case DRAW_XLOGSCALE: |
8416 | fprintf(js_include_file,"\n<!-- draw xlogscale -->\n\ |
||
8105 | schaersvoo | 8417 | 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 | 8418 | var obj;\ |
8419 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
8420 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
8421 | }\ |
||
8422 | else\ |
||
8423 | {\ |
||
8424 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
8425 | };\ |
||
8426 | var ctx = obj.getContext(\"2d\");\ |
||
7735 | schaersvoo | 8427 | ctx.clearRect(0,0,xsize,ysize);\ |
7956 | schaersvoo | 8428 | ctx.save();\ |
8429 | ctx.lineWidth = line_width;\ |
||
7739 | schaersvoo | 8430 | var prec = Math.log(precision)/Math.log(10);\ |
7735 | schaersvoo | 8431 | var x_min = Math.log(xmin)/Math.log(xlogbase);\ |
8432 | var x_max = Math.log(xmax)/Math.log(xlogbase);\ |
||
8433 | var y_min = 0;var y_max = ysize;var x_e;var corr;\ |
||
7739 | schaersvoo | 8434 | var xtxt;var ytxt;var num;var xmarge;var ymarge;\ |
8435 | if(use_axis_numbering == 1){\ |
||
7956 | schaersvoo | 8436 | ctx.font = font_family;\ |
8437 | xmarge = ctx.measureText(ymax.toFixed(prec)+' ').width;\ |
||
8438 | ymarge = parseInt(1.5*font_size);\ |
||
8439 | ctx.save();\ |
||
8440 | ctx.fillStyle=\"rgba(255,215,0,0.2)\";\ |
||
8441 | ctx.rect(0,0,xmarge,ysize);\ |
||
8442 | ctx.rect(0,ysize-ymarge,xsize,ysize);\ |
||
8443 | ctx.fill();\ |
||
8444 | ctx.restore();\ |
||
8445 | }else{xmarge = 0;ymarge = 0;};\ |
||
11088 | schaersvoo | 8446 | if( typeof(xaxislabel) !== 'undefined' ){\ |
7956 | schaersvoo | 8447 | ctx.save();\ |
8448 | ctx.font = \"italic \"+font_size+\"px Ariel\";\ |
||
8449 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\ |
||
8450 | corr = ctx.measureText(xaxislabel).width;\ |
||
8451 | ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\ |
||
8452 | ctx.restore();\ |
||
8453 | };\ |
||
11088 | schaersvoo | 8454 | if( typeof(yaxislabel) !== 'undefined' ){\ |
7956 | schaersvoo | 8455 | ctx.save();\ |
8456 | ctx.font = \"italic \"+font_size+\"px Ariel\";\ |
||
8457 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\ |
||
8458 | corr = ctx.measureText(yaxislabel).width;\ |
||
8459 | ctx.translate(xmarge+font_size,corr+font_size);\ |
||
8460 | ctx.rotate(-0.5*Math.PI);\ |
||
8461 | ctx.fillText(yaxislabel,0,0);\ |
||
8462 | ctx.restore();\ |
||
8463 | };\ |
||
8464 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\ |
||
8465 | ctx.lineWidth = line_width;\ |
||
8466 | for(var p = x_min; p <= x_max ; p++){\ |
||
8467 | num = Math.pow(xlogbase,p);\ |
||
8468 | for(var i = 1 ; i < xlogbase ; i++){\ |
||
8469 | x_e = x2px(i*num);\ |
||
7735 | schaersvoo | 8470 | if( i == 1 ){\ |
7956 | schaersvoo | 8471 | ctx.lineWidth = line_width;\ |
7739 | schaersvoo | 8472 | ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\ |
8473 | if( use_axis_numbering == 1 && p > x_min ){\ |
||
7735 | schaersvoo | 8474 | xtxt = xlogbase+'^'+p.toFixed(0);\ |
8475 | corr = 0.5*(ctx.measureText(xtxt).width);\ |
||
8476 | ctx.fillText(xtxt,x_e - corr,ysize - 4);\ |
||
8477 | };\ |
||
8478 | }else{\ |
||
7956 | schaersvoo | 8479 | ctx.lineWidth = 0.2*line_width;\ |
7735 | schaersvoo | 8480 | ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\ |
8481 | };\ |
||
7739 | schaersvoo | 8482 | if( x_e >= xmarge ){\ |
7956 | schaersvoo | 8483 | ctx.beginPath();\ |
8484 | ctx.moveTo(x_e,0);\ |
||
8485 | ctx.lineTo(x_e,ysize - ymarge);\ |
||
8486 | ctx.stroke();\ |
||
8487 | ctx.closePath();\ |
||
7739 | schaersvoo | 8488 | };\ |
8489 | };\ |
||
7956 | schaersvoo | 8490 | };\ |
7735 | schaersvoo | 8491 | var stepy = Math.abs(y2px(ymajor) - y2px(0));\ |
8492 | var minor_step = stepy / yminor;\ |
||
7749 | schaersvoo | 8493 | for(var y = 0 ; y < ysize - stepy ; y = y + stepy){\ |
7735 | schaersvoo | 8494 | ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\ |
7956 | schaersvoo | 8495 | ctx.lineWidth = line_width;\ |
8496 | ctx.beginPath();\ |
||
8497 | ctx.moveTo(xmarge,y);\ |
||
8498 | ctx.lineTo(xsize,y);\ |
||
8499 | ctx.stroke();\ |
||
8500 | ctx.closePath();\ |
||
7735 | schaersvoo | 8501 | if( use_axis_numbering == 1){\ |
8502 | ytxt = (px2y(y)).toFixed(prec);\ |
||
8503 | ctx.fillText( ytxt,0 ,y + 0.5*font_size );\ |
||
8504 | };\ |
||
8505 | for(var dy = 1 ; dy < yminor ; dy++){\ |
||
8506 | ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\ |
||
7956 | schaersvoo | 8507 | ctx.lineWidth = 0.2*line_width;\ |
8508 | ctx.beginPath();\ |
||
7739 | schaersvoo | 8509 | ctx.moveTo(xmarge,y+dy*minor_step);\ |
7956 | schaersvoo | 8510 | ctx.lineTo(xsize,y+dy*minor_step);\ |
8511 | ctx.stroke();\ |
||
8512 | ctx.closePath();\ |
||
7735 | schaersvoo | 8513 | };\ |
8514 | };\ |
||
7956 | schaersvoo | 8515 | ctx.restore();\ |
8516 | };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id); |
||
7735 | schaersvoo | 8517 | break; |
7729 | schaersvoo | 8518 | case DRAW_YLOGSCALE: |
8519 | fprintf(js_include_file,"\n<!-- draw ylogscale -->\n\ |
||
8105 | schaersvoo | 8520 | 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 | 8521 | var obj;\ |
8522 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
8523 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
8524 | }\ |
||
8525 | else\ |
||
8526 | {\ |
||
8527 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
8528 | };\ |
||
8529 | var ctx = obj.getContext(\"2d\");\ |
||
7729 | schaersvoo | 8530 | ctx.clearRect(0,0,xsize,ysize);\ |
7956 | schaersvoo | 8531 | ctx.save();\ |
8532 | ctx.lineWidth = line_width;\ |
||
7735 | schaersvoo | 8533 | var y_min = Math.log(ymin)/Math.log(ylogbase);\ |
8534 | var y_max = Math.log(ymax)/Math.log(ylogbase);\ |
||
8109 | schaersvoo | 8535 | var x_min = 0;var x_max = xsize;var y_s;var y_e;var num;var xmarge;var ymarge;\ |
7739 | schaersvoo | 8536 | if(use_axis_numbering == 1){\ |
7956 | schaersvoo | 8537 | ctx.font = font_family;\ |
8538 | xmarge = ctx.measureText(ylogbase+\"^\"+y_max.toFixed(0)+' ').width;\ |
||
8539 | ymarge = 2*font_size;\ |
||
8540 | ctx.save();\ |
||
8541 | ctx.fillStyle=\"rgba(255,215,0,0.2)\";\ |
||
8542 | ctx.rect(0,0,xmarge,ysize);\ |
||
8543 | ctx.rect(0,ysize-ymarge,xsize,ysize);\ |
||
8544 | ctx.fill();\ |
||
8545 | ctx.restore();\ |
||
8546 | }else{xmarge = 0;ymarge = 0;};\ |
||
11088 | schaersvoo | 8547 | if( typeof(xaxislabel) !== 'undefined' ){\ |
7956 | schaersvoo | 8548 | ctx.save();\ |
8549 | ctx.font = \"italic \"+font_size+\"px Ariel\";\ |
||
8550 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\ |
||
8551 | corr = ctx.measureText(xaxislabel).width;\ |
||
8552 | ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\ |
||
8553 | ctx.restore();\ |
||
8554 | };\ |
||
11088 | schaersvoo | 8555 | if( typeof(yaxislabel) !== 'undefined' ){\ |
7956 | schaersvoo | 8556 | ctx.save();\ |
8557 | ctx.font = \"italic \"+font_size+\"px Ariel\";\ |
||
8558 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\ |
||
8559 | corr = ctx.measureText(yaxislabel).width;\ |
||
8560 | ctx.translate(xmarge+font_size,corr+font_size);\ |
||
8561 | ctx.rotate(-0.5*Math.PI);\ |
||
8562 | ctx.fillText(yaxislabel,0,0);\ |
||
8563 | ctx.restore();\ |
||
8564 | };\ |
||
8565 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\ |
||
8566 | ctx.lineWidth = line_width;\ |
||
8567 | for(var p = y_min; p <= y_max ; p++){\ |
||
8568 | num = Math.pow(ylogbase,p);\ |
||
8569 | for(var i = 1 ; i < ylogbase ; i++){\ |
||
8570 | y_e = y2px(i*num);\ |
||
7729 | schaersvoo | 8571 | if( i == 1 ){\ |
7956 | schaersvoo | 8572 | ctx.lineWidth = line_width;\ |
7729 | schaersvoo | 8573 | ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\ |
7739 | schaersvoo | 8574 | if( use_axis_numbering == 1 && p > y_min){\ |
7735 | schaersvoo | 8575 | ctx.fillText(ylogbase+'^'+p.toFixed(0),0,y_e);\ |
7729 | schaersvoo | 8576 | };\ |
8577 | }else{\ |
||
7956 | schaersvoo | 8578 | ctx.lineWidth = 0.2*line_width;\ |
7729 | schaersvoo | 8579 | ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\ |
8580 | };\ |
||
7956 | schaersvoo | 8581 | ctx.beginPath();\ |
8582 | ctx.moveTo(xmarge,y_e);\ |
||
8583 | ctx.lineTo(xsize,y_e);\ |
||
8584 | ctx.stroke();\ |
||
8585 | ctx.closePath();\ |
||
8586 | };\ |
||
8587 | };\ |
||
7729 | schaersvoo | 8588 | var stepx = Math.abs(x2px(xmajor) - x2px(0));\ |
8589 | var minor_step = stepx / xminor;\ |
||
8590 | var prec = Math.log(precision)/Math.log(10);\ |
||
8591 | var xtxt;var corr;var flip = 0;\ |
||
7749 | schaersvoo | 8592 | for(var x = stepx ; x < xsize ; x = x + stepx){\ |
7729 | schaersvoo | 8593 | ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\ |
7956 | schaersvoo | 8594 | ctx.lineWidth = line_width;\ |
8595 | ctx.beginPath();\ |
||
8596 | ctx.moveTo(x,ysize-ymarge);\ |
||
8597 | ctx.lineTo(x,0);\ |
||
8598 | ctx.stroke();\ |
||
8599 | ctx.closePath();\ |
||
7729 | schaersvoo | 8600 | if( use_axis_numbering == 1){\ |
8601 | xtxt = (px2x(x)).toFixed(prec);\ |
||
8602 | corr = 0.5*(ctx.measureText(xtxt).width);\ |
||
8603 | if(flip == 0 ){flip = 1;ctx.fillText( xtxt,x - corr ,ysize - 0.2*font_size );}else{\ |
||
8604 | flip = 0;ctx.fillText( xtxt,x - corr ,ysize - 1.2*font_size );};\ |
||
8605 | };\ |
||
8606 | for(var dx = 1 ; dx < xminor ; dx++){\ |
||
8607 | ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\ |
||
7956 | schaersvoo | 8608 | ctx.lineWidth = 0.2*line_width;\ |
8609 | ctx.beginPath();\ |
||
7739 | schaersvoo | 8610 | ctx.moveTo(x+dx*minor_step,ysize - ymarge);\ |
7956 | schaersvoo | 8611 | ctx.lineTo(x+dx*minor_step,0);\ |
8612 | ctx.stroke();\ |
||
8613 | ctx.closePath();\ |
||
7735 | schaersvoo | 8614 | };\ |
8615 | };\ |
||
7956 | schaersvoo | 8616 | ctx.restore();\ |
8617 | };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id); |
||
7729 | schaersvoo | 8618 | break; |
9213 | schaersvoo | 8619 | |
7614 | schaersvoo | 8620 | default:break; |
8621 | } |
||
8622 | } |
||
8623 | } |
||
8624 | return; |
||
8625 | } |
||
8626 | |||
8627 | void check_string_length(int L){ |
||
9466 | schaersvoo | 8628 | if( L > MAX_BUFFER-1){ |
7614 | schaersvoo | 8629 | canvas_error("problem with your arguments to command..."); |
8630 | } |
||
8631 | return; |
||
8632 | } |
||
8633 | |||
8634 | |||
8635 | int get_token(FILE *infile){ |
||
8636 | int c,i=0; |
||
8637 | char temp[MAX_INT], *input_type; |
||
8638 | char *line="line", |
||
8639 | *audio="audio", |
||
8640 | *blink="blink", |
||
8641 | *arrowhead="arrowhead", |
||
8642 | *crosshairsize="crosshairsize", |
||
8643 | *crosshair="crosshair", |
||
8644 | *crosshairs="crosshairs", |
||
8645 | *audioobject="audioobject", |
||
8646 | *style="style", |
||
8647 | *mouse="mouse", |
||
7991 | schaersvoo | 8648 | *mousex="mousex", |
8649 | *mousey="mousey", |
||
8071 | schaersvoo | 8650 | *mouse_display="display", |
8651 | *mouse_degree="mouse_degree", |
||
7614 | schaersvoo | 8652 | *userdraw="userdraw", |
8653 | *highlight="highlight", |
||
8654 | *http="http", |
||
8655 | *rays="rays", |
||
8656 | *dashtype="dashtype", |
||
8657 | *dashed="dashed", |
||
8658 | *filled="filled", |
||
8659 | *lattice="lattice", |
||
8660 | *parallel="parallel", |
||
8661 | *segment="segment", |
||
8299 | schaersvoo | 8662 | *segments="segments", |
7614 | schaersvoo | 8663 | *dsegment="dsegment", |
9374 | schaersvoo | 8664 | *dsegments="dsegments", |
7614 | schaersvoo | 8665 | *seg="seg", |
9383 | schaersvoo | 8666 | *segs="segs", |
7614 | schaersvoo | 8667 | *bgimage="bgimage", |
8668 | *bgcolor="bgcolor", |
||
8669 | *strokecolor="strokecolor", |
||
8670 | *backgroundimage="backgroundimage", |
||
8671 | *text="text", |
||
8672 | *textup="textup", |
||
8673 | *mouseprecision="mouseprecision", |
||
8674 | *precision="precision", |
||
8675 | *plotsteps="plotsteps", |
||
8676 | *plotstep="plotstep", |
||
8677 | *tsteps="tsteps", |
||
8678 | *curve="curve", |
||
8679 | *dcurve="dcurve", |
||
8680 | *plot="plot", |
||
8681 | *dplot="dplot", |
||
7788 | schaersvoo | 8682 | *levelcurve="levelcurve", |
7614 | schaersvoo | 8683 | *fontsize="fontsize", |
8684 | *fontcolor="fontcolor", |
||
8685 | *axis="axis", |
||
8686 | *axisnumbering="axisnumbering", |
||
8687 | *axisnumbers="axisnumbers", |
||
8688 | *arrow="arrow", |
||
9382 | schaersvoo | 8689 | *vector="vector", |
8690 | *vectors="vectors", |
||
7614 | schaersvoo | 8691 | *darrow="darrow", |
8692 | *arrow2="arrow2", |
||
8693 | *darrow2="darrow2", |
||
8304 | schaersvoo | 8694 | *arrows="arrows", |
8347 | schaersvoo | 8695 | *arrows2="arrows2", |
7614 | schaersvoo | 8696 | *zoom="zoom", |
8697 | *grid="grid", |
||
8698 | *hline="hline", |
||
7786 | schaersvoo | 8699 | *dhline="dhline", |
7614 | schaersvoo | 8700 | *drag="drag", |
8701 | *horizontalline="horizontalline", |
||
9383 | schaersvoo | 8702 | *horizontallines="horizontallines", |
7614 | schaersvoo | 8703 | *vline="vline", |
7786 | schaersvoo | 8704 | *dvline="dvline", |
7614 | schaersvoo | 8705 | *verticalline="verticalline", |
9383 | schaersvoo | 8706 | *verticallines="verticallines", |
7614 | schaersvoo | 8707 | *triangle="triangle", |
9306 | schaersvoo | 8708 | *triangles="triangles", |
7614 | schaersvoo | 8709 | *ftriangle="ftriangle", |
9374 | schaersvoo | 8710 | *ftriangles="ftriangles", |
7614 | schaersvoo | 8711 | *mathml="mathml", |
8712 | *html="html", |
||
8713 | *input="input", |
||
8146 | schaersvoo | 8714 | *clearbutton="clearbutton", |
9386 | schaersvoo | 8715 | *erase="erase", |
8716 | *delete="delete", |
||
7614 | schaersvoo | 8717 | *inputstyle="inputstyle", |
8718 | *textarea="textarea", |
||
8719 | *trange="trange", |
||
8720 | *ranget="ranget", |
||
8721 | *xrange="xrange", |
||
8722 | *yrange="yrange", |
||
8723 | *rangex="rangex", |
||
8724 | *rangey="rangey", |
||
8370 | schaersvoo | 8725 | *path="path", |
7614 | schaersvoo | 8726 | *polyline="polyline", |
8351 | schaersvoo | 8727 | *brokenline="brokenline", |
7614 | schaersvoo | 8728 | *lines="lines", |
8729 | *poly="poly", |
||
8730 | *polygon="polygon", |
||
8731 | *fpolygon="fpolygon", |
||
8732 | *fpoly="fpoly", |
||
8733 | *filledpoly="filledpoly", |
||
8734 | *filledpolygon="filledpolygon", |
||
8735 | *rect="rect", |
||
8736 | *frect="frect", |
||
8737 | *rectangle="rectangle", |
||
8738 | *frectangle="frectangle", |
||
8739 | *square="square", |
||
8740 | *fsquare="fsquare", |
||
9374 | schaersvoo | 8741 | *fsquares="fsquares", |
8363 | schaersvoo | 8742 | *rects="rects", |
8743 | *frects="frects", |
||
7614 | schaersvoo | 8744 | *dline="dline", |
8745 | *arc="arc", |
||
8746 | *filledarc="filledarc", |
||
9374 | schaersvoo | 8747 | *farc="farc", |
7614 | schaersvoo | 8748 | *size="size", |
8749 | *string="string", |
||
8750 | *stringup="stringup", |
||
8751 | *copy="copy", |
||
8752 | *copyresized="copyresized", |
||
8753 | *opacity="opacity", |
||
8754 | *transparent="transparent", |
||
8755 | *fill="fill", |
||
8756 | *point="point", |
||
8757 | *points="points", |
||
8758 | *linewidth="linewidth", |
||
8759 | *circle="circle", |
||
8304 | schaersvoo | 8760 | *circles="circles", |
7614 | schaersvoo | 8761 | *fcircle="fcircle", |
9374 | schaersvoo | 8762 | *fcircles="fcircles", |
7614 | schaersvoo | 8763 | *disk="disk", |
9374 | schaersvoo | 8764 | *disks="disks", |
7614 | schaersvoo | 8765 | *comment="#", |
8766 | *end="end", |
||
8767 | *ellipse="ellipse", |
||
8768 | *fellipse="fellipse", |
||
8769 | *rotate="rotate", |
||
7785 | schaersvoo | 8770 | *affine="affine", |
9907 | schaersvoo | 8771 | *rotationcenter="rotationcenter", |
8772 | *killrotate="killrotate", |
||
7785 | schaersvoo | 8773 | *killaffine="killaffine", |
7614 | schaersvoo | 8774 | *fontfamily="fontfamily", |
8775 | *fillcolor="fillcolor", |
||
8776 | *clicktile="clicktile", |
||
8777 | *clicktile_colors="clicktile_colors", |
||
8778 | *translation="translation", |
||
8779 | *translate="translate", |
||
8780 | *killtranslation="killtranslation", |
||
8781 | *killtranslate="killtranslate", |
||
8782 | *onclick="onclick", |
||
8370 | schaersvoo | 8783 | *roundrects="roundrects", |
7614 | schaersvoo | 8784 | *roundrect="roundrect", |
8785 | *froundrect="froundrect", |
||
9374 | schaersvoo | 8786 | *froundrects="froundrects", |
7614 | schaersvoo | 8787 | *roundrectangle="roundrectangle", |
8788 | *patternfill="patternfill", |
||
8789 | *hatchfill="hatchfill", |
||
8790 | *diafill="diafill", |
||
7647 | schaersvoo | 8791 | *diamondfill="diamondfill", |
7614 | schaersvoo | 8792 | *dotfill="dotfill", |
8793 | *gridfill="gridfill", |
||
8794 | *imagefill="imagefill", |
||
7735 | schaersvoo | 8795 | *xlogbase="xlogbase", |
8796 | *ylogbase="ylogbase", |
||
7614 | schaersvoo | 8797 | *xlogscale="xlogscale", |
8798 | *ylogscale="ylogscale", |
||
8799 | *xylogscale="xylogscale", |
||
8800 | *intooltip="intooltip", |
||
9329 | schaersvoo | 8801 | *popup="popup", |
7614 | schaersvoo | 8802 | *replyformat="replyformat", |
8803 | *floodfill="floodfill", |
||
11772 | schaersvoo | 8804 | *fillall="fillall", |
7614 | schaersvoo | 8805 | *filltoborder="filltoborder", |
8806 | *setpixel="setpixel", |
||
8807 | *pixels="pixels", |
||
8808 | *pixelsize="pixelsize", |
||
8809 | *xaxis="xaxis", |
||
9341 | schaersvoo | 8810 | *xaxisup="xaxisup", |
7614 | schaersvoo | 8811 | *yaxis="yaxis", |
8812 | *xaxistext="xaxistext", |
||
9341 | schaersvoo | 8813 | *xaxistextup="xaxistextup", |
7614 | schaersvoo | 8814 | *yaxistext="yaxistext", |
8815 | *piechart="piechart", |
||
9433 | schaersvoo | 8816 | *boxplot="boxplot", |
9465 | schaersvoo | 8817 | *boxplotdata="boxplotdata", |
8818 | *userboxplot="userboxplot", |
||
8819 | *userboxplotdata="userboxplotdata", |
||
7614 | schaersvoo | 8820 | *legend="legend", |
8821 | *legendcolors="legendcolors", |
||
8822 | *xlabel="xlabel", |
||
8823 | *ylabel="ylabel", |
||
8824 | *barchart="barchart", |
||
8825 | *linegraph="linegraph", |
||
8826 | *clock="clock", |
||
8827 | *animate="animate", |
||
8828 | *video="video", |
||
8829 | *status="status", |
||
7877 | schaersvoo | 8830 | *nostatus="nostatus", |
7652 | schaersvoo | 8831 | *snaptogrid="snaptogrid", |
7784 | schaersvoo | 8832 | *xsnaptogrid="xsnaptogrid", |
8833 | *ysnaptogrid="ysnaptogrid", |
||
8379 | schaersvoo | 8834 | *snaptopoints="snaptopoints", |
9213 | schaersvoo | 8835 | *snaptofunction="snaptofunction", |
8836 | *snaptofun="snaptofun", |
||
7654 | schaersvoo | 8837 | *userinput_xy="userinput_xy", |
8193 | schaersvoo | 8838 | *userinput_function="userinput_function", |
7663 | schaersvoo | 8839 | *usertextarea_xy="usertextarea_xy", |
8222 | schaersvoo | 8840 | *userinput="userinput", |
7823 | schaersvoo | 8841 | *jsmath="jsmath", |
7858 | schaersvoo | 8842 | *trace_jscurve="trace_jscurve", |
7838 | schaersvoo | 8843 | *setlimits="setlimits", |
7858 | schaersvoo | 8844 | *jscurve="jscurve", |
8845 | *jsplot="jsplot", |
||
7983 | schaersvoo | 8846 | *sgraph="sgraph", |
7984 | schaersvoo | 8847 | *title="title", |
7996 | schaersvoo | 8848 | *centerstring="centerstring", |
8849 | *xunit="xunit", |
||
8071 | schaersvoo | 8850 | *yunit="yunit", |
8101 | schaersvoo | 8851 | *slider="slider", |
8105 | schaersvoo | 8852 | *killslider="killslider", |
8244 | schaersvoo | 8853 | *angle="angle", |
8365 | schaersvoo | 8854 | *halflines="halflines", |
8855 | *demilines="demilines", |
||
8244 | schaersvoo | 8856 | *halfline="halfline", |
8297 | schaersvoo | 8857 | *demiline="demiline", |
8366 | schaersvoo | 8858 | *hlines="hlines", |
8859 | *vlines="vlines", |
||
8370 | schaersvoo | 8860 | *bezier="bezier", |
9213 | schaersvoo | 8861 | *functionlabel="functionlabel", |
8862 | *sliderfunction_x="sliderfunction_x", |
||
8863 | *sliderfunction_y="sliderfunction_y", |
||
8864 | *multidraw="multidraw", |
||
8865 | *multilinewidth="multilinewidth", |
||
8866 | *multistrokecolors="multistrokecolors", |
||
8867 | *multifillcolors="multifillcolors", |
||
8868 | *multistrokeopacity="multistrokeopacity", |
||
8869 | *multifillopacity="multifillopacity", |
||
8870 | *multifill="multifill", |
||
8871 | *multidash="multidash", |
||
8872 | *multilabel="multilabel", |
||
8873 | *multiuserinput="multiuserinput", |
||
9289 | schaersvoo | 8874 | *multisnaptogrid="multisnaptogrid", |
8875 | *protractor="protractor", |
||
9386 | schaersvoo | 8876 | *ruler="ruler", |
8877 | *cursor="cursor", |
||
9427 | schaersvoo | 8878 | *pointer="pointer", |
8879 | *yerrorbars="yerrorbars", |
||
11006 | schaersvoo | 8880 | *xerrorbars="xerrorbars", |
11044 | schaersvoo | 8881 | *noxaxis="noxaxis", |
8882 | *noyaxis="noyaxis", |
||
11767 | schaersvoo | 8883 | *colorpalette="colorpalette", |
11802 | schaersvoo | 8884 | *xoffset="xoffset", |
8885 | *centered="centered", |
||
8886 | *xyoffset="xyoffset", |
||
8887 | *resetoffset="resetoffset", |
||
11006 | schaersvoo | 8888 | *canvastype="canvastype"; |
7614 | schaersvoo | 8889 | |
10891 | schaersvoo | 8890 | while(((c = getc(infile)) != EOF)&&(c!='\n')&&(c!=',')&&(c!='=')&&(c!='\r')&&(c!='\t')){ |
8891 | if( i == 0 && (c == ' ') ){ continue; /* white spaces or tabs allowed before first command identifier */ |
||
8892 | }else{ |
||
8893 | if( c == ' ' ){ |
||
7614 | schaersvoo | 8894 | break; |
10891 | schaersvoo | 8895 | }else{ |
8896 | temp[i] = c; |
||
8897 | if(i > MAX_INT - 2){canvas_error("command string too long !");} |
||
8898 | i++; |
||
8899 | } |
||
8900 | } |
||
8901 | if(temp[0] == '#'){ break; } |
||
7614 | schaersvoo | 8902 | } |
10891 | schaersvoo | 8903 | if (c == '\n' || c == '\r' || c == '\t' ){ line_number++; } |
8904 | if (c == EOF) {finished=1;return 0;} |
||
7614 | schaersvoo | 8905 | |
8906 | temp[i]='\0'; |
||
8907 | input_type=(char*)my_newmem(strlen(temp)); |
||
8908 | snprintf(input_type,sizeof(temp),"%s",temp); |
||
10891 | schaersvoo | 8909 | /* fprintf(stdout,"temp = %s <br/>",input_type); */ |
7614 | schaersvoo | 8910 | if( strcmp(input_type, size) == 0 ){ |
8911 | free(input_type); |
||
8912 | return SIZE; |
||
8913 | } |
||
8914 | if( strcmp(input_type, xrange) == 0 ){ |
||
8915 | free(input_type); |
||
8916 | return XRANGE; |
||
8917 | } |
||
8918 | if( strcmp(input_type, rangex) == 0 ){ |
||
8919 | free(input_type); |
||
8920 | return XRANGE; |
||
8921 | } |
||
8922 | if( strcmp(input_type, trange) == 0 ){ |
||
8923 | free(input_type); |
||
8924 | return TRANGE; |
||
8925 | } |
||
8926 | if( strcmp(input_type, ranget) == 0 ){ |
||
8927 | free(input_type); |
||
8928 | return TRANGE; |
||
8929 | } |
||
8930 | if( strcmp(input_type, yrange) == 0 ){ |
||
8931 | free(input_type); |
||
8932 | return YRANGE; |
||
8933 | } |
||
8934 | if( strcmp(input_type, rangey) == 0 ){ |
||
8935 | free(input_type); |
||
8936 | return YRANGE; |
||
8937 | } |
||
8938 | if( strcmp(input_type, linewidth) == 0 ){ |
||
8939 | free(input_type); |
||
8940 | return LINEWIDTH; |
||
8941 | } |
||
8942 | if( strcmp(input_type, dashed) == 0 ){ |
||
8943 | free(input_type); |
||
8944 | return DASHED; |
||
8945 | } |
||
8946 | if( strcmp(input_type, dashtype) == 0 ){ |
||
8947 | free(input_type); |
||
8948 | return DASHTYPE; |
||
8949 | } |
||
8950 | if( strcmp(input_type, axisnumbering) == 0 ){ |
||
8951 | free(input_type); |
||
8952 | return AXIS_NUMBERING; |
||
8953 | } |
||
8954 | if( strcmp(input_type, axisnumbers) == 0 ){ |
||
8955 | free(input_type); |
||
8956 | return AXIS_NUMBERING; |
||
8957 | } |
||
8958 | if( strcmp(input_type, axis) == 0 ){ |
||
8959 | free(input_type); |
||
8960 | return AXIS; |
||
8961 | } |
||
8962 | if( strcmp(input_type, grid) == 0 ){ |
||
8963 | free(input_type); |
||
8964 | return GRID; |
||
8965 | } |
||
9383 | schaersvoo | 8966 | if( strcmp(input_type, hlines) == 0 || strcmp(input_type, horizontallines) == 0 ){ |
8366 | schaersvoo | 8967 | free(input_type); |
8968 | return HLINES; |
||
8969 | } |
||
9383 | schaersvoo | 8970 | if( strcmp(input_type, vlines) == 0 || strcmp(input_type, verticallines) == 0 ){ |
8366 | schaersvoo | 8971 | free(input_type); |
8972 | return VLINES; |
||
8973 | } |
||
9383 | schaersvoo | 8974 | if( strcmp(input_type, hline) == 0 || strcmp(input_type, horizontalline) == 0 ){ |
7614 | schaersvoo | 8975 | free(input_type); |
8976 | return HLINE; |
||
8977 | } |
||
8978 | if( strcmp(input_type, vline) == 0 || strcmp(input_type, verticalline) == 0 ){ |
||
8979 | free(input_type); |
||
8980 | return VLINE; |
||
8981 | } |
||
8982 | if( strcmp(input_type, line) == 0 ){ |
||
8983 | free(input_type); |
||
8984 | return LINE; |
||
8985 | } |
||
9383 | schaersvoo | 8986 | if( strcmp(input_type, segments) == 0 || strcmp(input_type, segs) == 0 ){ |
8299 | schaersvoo | 8987 | free(input_type); |
8988 | return SEGMENTS; |
||
8989 | } |
||
7614 | schaersvoo | 8990 | if( strcmp(input_type, seg) == 0 || strcmp(input_type, segment) == 0 ){ |
8991 | free(input_type); |
||
8992 | return SEGMENT; |
||
8993 | } |
||
9374 | schaersvoo | 8994 | if( strcmp(input_type, dsegments) == 0 ){ |
8995 | free(input_type); |
||
8996 | use_dashed = TRUE; |
||
8997 | return SEGMENTS; |
||
8998 | } |
||
7614 | schaersvoo | 8999 | if( strcmp(input_type, dsegment) == 0 ){ |
9000 | free(input_type); |
||
9001 | use_dashed = TRUE; |
||
9002 | return SEGMENT; |
||
9003 | } |
||
9004 | if( strcmp(input_type, crosshairsize) == 0 ){ |
||
9005 | free(input_type); |
||
9006 | return CROSSHAIRSIZE; |
||
9007 | } |
||
9008 | if( strcmp(input_type, arrowhead) == 0 ){ |
||
9009 | free(input_type); |
||
9010 | return ARROWHEAD; |
||
9011 | } |
||
9012 | if( strcmp(input_type, crosshairs) == 0 ){ |
||
9013 | free(input_type); |
||
9014 | return CROSSHAIRS; |
||
9015 | } |
||
9016 | if( strcmp(input_type, crosshair) == 0 ){ |
||
9017 | free(input_type); |
||
9018 | return CROSSHAIR; |
||
9019 | } |
||
9020 | if( strcmp(input_type, onclick) == 0 ){ |
||
9021 | free(input_type); |
||
9022 | return ONCLICK; |
||
9023 | } |
||
9024 | if( strcmp(input_type, drag) == 0 ){ |
||
9025 | free(input_type); |
||
9026 | return DRAG; |
||
9027 | } |
||
9028 | if( strcmp(input_type, userdraw) == 0 ){ |
||
9029 | free(input_type); |
||
9030 | return USERDRAW; |
||
9031 | } |
||
9032 | if( strcmp(input_type, highlight) == 0 || strcmp(input_type, style) == 0 ){ |
||
9033 | free(input_type); |
||
9034 | return STYLE; |
||
9035 | } |
||
9036 | if( strcmp(input_type, fillcolor) == 0 ){ |
||
9037 | free(input_type); |
||
9038 | return FILLCOLOR; |
||
9039 | } |
||
9040 | if( strcmp(input_type, strokecolor) == 0 ){ |
||
9041 | free(input_type); |
||
9042 | return STROKECOLOR; |
||
9043 | } |
||
9044 | if( strcmp(input_type, filled) == 0 ){ |
||
9045 | free(input_type); |
||
9046 | return FILLED; |
||
9047 | } |
||
9048 | if( strcmp(input_type, http) == 0 ){ |
||
9049 | free(input_type); |
||
9050 | return HTTP; |
||
9051 | } |
||
9052 | if( strcmp(input_type, rays) == 0 ){ |
||
9053 | free(input_type); |
||
9054 | return RAYS; |
||
9055 | } |
||
9056 | if( strcmp(input_type, lattice) == 0 ){ |
||
9057 | free(input_type); |
||
9058 | return LATTICE; |
||
9059 | } |
||
9060 | if( strcmp(input_type, bgimage) == 0 ){ |
||
9061 | free(input_type); |
||
9062 | return BGIMAGE; |
||
9063 | } |
||
9064 | if( strcmp(input_type, bgcolor) == 0 ){ |
||
9065 | free(input_type); |
||
9066 | return BGCOLOR; |
||
9067 | } |
||
9068 | if( strcmp(input_type, backgroundimage) == 0 ){ |
||
9069 | free(input_type); |
||
9070 | return BGIMAGE; |
||
9071 | } |
||
9072 | if( strcmp(input_type, text) == 0 ){ |
||
9073 | free(input_type); |
||
9074 | return FLY_TEXT; |
||
9075 | } |
||
9076 | if( strcmp(input_type, textup) == 0 ){ |
||
9077 | free(input_type); |
||
9078 | return FLY_TEXTUP; |
||
9079 | } |
||
9080 | if( strcmp(input_type, mouse) == 0 ){ |
||
9081 | free(input_type); |
||
9082 | return MOUSE; |
||
9083 | } |
||
7991 | schaersvoo | 9084 | if( strcmp(input_type, mousex) == 0 ){ |
9085 | free(input_type); |
||
9086 | return MOUSEX; |
||
9087 | } |
||
9088 | if( strcmp(input_type, mousey) == 0 ){ |
||
9089 | free(input_type); |
||
9090 | return MOUSEY; |
||
9091 | } |
||
8071 | schaersvoo | 9092 | if( strcmp(input_type, mouse_degree) == 0 ){ |
9093 | free(input_type); |
||
9094 | return MOUSE_DEGREE; |
||
9095 | } |
||
9096 | if( strcmp(input_type, mouse_display) == 0 ){ |
||
9097 | free(input_type); |
||
9098 | return MOUSE_DISPLAY; |
||
9099 | } |
||
7614 | schaersvoo | 9100 | if( strcmp(input_type, mouseprecision) == 0 ){ |
9101 | free(input_type); |
||
9102 | return MOUSE_PRECISION; |
||
9103 | } |
||
9104 | if( strcmp(input_type, precision) == 0 ){ |
||
9105 | free(input_type); |
||
9106 | return MOUSE_PRECISION; |
||
9107 | } |
||
9108 | if( strcmp(input_type, curve) == 0 ){ |
||
9109 | free(input_type); |
||
9110 | return CURVE; |
||
9111 | } |
||
9112 | if( strcmp(input_type, dcurve) == 0 ){ |
||
7788 | schaersvoo | 9113 | use_dashed = TRUE; |
7614 | schaersvoo | 9114 | free(input_type); |
9115 | return CURVE; |
||
9116 | } |
||
9117 | if( strcmp(input_type, plot) == 0 ){ |
||
9118 | free(input_type); |
||
9119 | return CURVE; |
||
9120 | } |
||
9121 | if( strcmp(input_type, dplot) == 0 ){ |
||
7788 | schaersvoo | 9122 | use_dashed = TRUE; |
7614 | schaersvoo | 9123 | free(input_type); |
9124 | return CURVE; |
||
9125 | } |
||
7788 | schaersvoo | 9126 | if( strcmp(input_type, levelcurve) == 0 ){ |
9127 | free(input_type); |
||
9128 | return LEVELCURVE; |
||
9129 | } |
||
7614 | schaersvoo | 9130 | if( strcmp(input_type, plotsteps) == 0 ){ |
9131 | free(input_type); |
||
9132 | return PLOTSTEPS; |
||
9133 | } |
||
9134 | if( strcmp(input_type, plotstep) == 0 ){ |
||
9135 | free(input_type); |
||
9136 | return PLOTSTEPS; |
||
9137 | } |
||
9138 | if( strcmp(input_type, tsteps) == 0 ){ |
||
9139 | free(input_type); |
||
9140 | return PLOTSTEPS; |
||
9141 | } |
||
9142 | if( strcmp(input_type, fontsize) == 0 ){ |
||
9143 | free(input_type); |
||
9144 | return FONTSIZE; |
||
9145 | } |
||
9146 | if( strcmp(input_type, fontcolor) == 0 ){ |
||
9147 | free(input_type); |
||
9148 | return FONTCOLOR; |
||
9149 | } |
||
9150 | if( strcmp(input_type, arrow2) == 0 ){ |
||
9151 | free(input_type); |
||
9152 | return ARROW2; |
||
9153 | } |
||
9154 | if( strcmp(input_type, darrow) == 0 ){ |
||
9155 | free(input_type); |
||
8071 | schaersvoo | 9156 | use_dashed = TRUE; |
7614 | schaersvoo | 9157 | return ARROW; |
9158 | } |
||
9159 | if( strcmp(input_type, darrow2) == 0 ){ |
||
9160 | free(input_type); |
||
9161 | use_dashed = TRUE; |
||
9162 | return ARROW2; |
||
9163 | } |
||
8347 | schaersvoo | 9164 | if( strcmp(input_type, arrows2) == 0 ){ |
9165 | free(input_type); |
||
9166 | return ARROWS2; |
||
9167 | } |
||
9382 | schaersvoo | 9168 | if( strcmp(input_type, arrows) == 0 || strcmp(input_type, vectors) == 0 ){ |
8304 | schaersvoo | 9169 | free(input_type); |
9170 | return ARROWS; |
||
9171 | } |
||
9382 | schaersvoo | 9172 | if( strcmp(input_type, arrow) == 0 || strcmp(input_type, vector) == 0 ){ |
8304 | schaersvoo | 9173 | free(input_type); |
9174 | return ARROW; |
||
9175 | } |
||
7614 | schaersvoo | 9176 | if( strcmp(input_type, zoom) == 0 ){ |
9177 | free(input_type); |
||
9178 | return ZOOM; |
||
9179 | } |
||
9180 | if( strcmp(input_type, triangle) == 0 ){ |
||
9181 | free(input_type); |
||
9182 | return TRIANGLE; |
||
9183 | } |
||
9306 | schaersvoo | 9184 | if( strcmp(input_type, triangles) == 0 ){ |
9185 | free(input_type); |
||
9186 | return TRIANGLES; |
||
9187 | } |
||
9374 | schaersvoo | 9188 | if( strcmp(input_type, ftriangles) == 0 ){ |
9189 | free(input_type); |
||
9190 | use_filled = TRUE; |
||
9191 | return TRIANGLES; |
||
9192 | } |
||
7614 | schaersvoo | 9193 | if( strcmp(input_type, ftriangle) == 0 ){ |
9194 | free(input_type); |
||
9195 | use_filled = TRUE; |
||
9196 | return TRIANGLE; |
||
9197 | } |
||
9198 | if( strcmp(input_type, input) == 0 ){ |
||
9199 | free(input_type); |
||
9200 | return INPUT; |
||
9201 | } |
||
9202 | if( strcmp(input_type, inputstyle) == 0 ){ |
||
9203 | free(input_type); |
||
9204 | return INPUTSTYLE; |
||
9205 | } |
||
9206 | if( strcmp(input_type, textarea) == 0 ){ |
||
9207 | free(input_type); |
||
9208 | return TEXTAREA; |
||
9209 | } |
||
9210 | if( strcmp(input_type, mathml) == 0 ){ |
||
9211 | free(input_type); |
||
9212 | return MATHML; |
||
9213 | } |
||
9214 | if( strcmp(input_type, html) == 0 ){ |
||
9215 | free(input_type); |
||
9216 | return MATHML; |
||
9217 | } |
||
9218 | if( strcmp(input_type, fontfamily) == 0 ){ |
||
9219 | free(input_type); |
||
9220 | return FONTFAMILY; |
||
9221 | } |
||
10975 | schaersvoo | 9222 | if( strcmp(input_type, polyline) == 0 || strcmp(input_type, path) == 0 || strcmp(input_type, brokenline) == 0 ){ |
7614 | schaersvoo | 9223 | free(input_type); |
9224 | return POLYLINE; |
||
9225 | } |
||
8351 | schaersvoo | 9226 | if( strcmp(input_type, lines) == 0 ){ |
9227 | free(input_type); |
||
9228 | return LINES; |
||
9229 | } |
||
9374 | schaersvoo | 9230 | if( strcmp(input_type, rects) == 0){ |
8363 | schaersvoo | 9231 | free(input_type); |
9232 | return RECTS; |
||
9233 | } |
||
9383 | schaersvoo | 9234 | if( strcmp(input_type, frects) == 0 ){ |
8363 | schaersvoo | 9235 | free(input_type); |
9374 | schaersvoo | 9236 | use_filled = TRUE; |
8363 | schaersvoo | 9237 | return RECTS; |
9238 | } |
||
7614 | schaersvoo | 9239 | if( strcmp(input_type, rect) == 0 || strcmp(input_type, rectangle) == 0 ){ |
9240 | free(input_type); |
||
9241 | return RECT; |
||
9242 | } |
||
9374 | schaersvoo | 9243 | if( strcmp(input_type, square) == 0 ){ |
9244 | free(input_type); |
||
9245 | return RECT; |
||
9246 | } |
||
9247 | if( strcmp(input_type, fsquare) == 0 ){ |
||
9248 | free(input_type); |
||
9249 | use_filled = TRUE; |
||
9250 | return SQUARE; |
||
9251 | } |
||
9252 | if( strcmp(input_type, fsquares) == 0 ){ |
||
9253 | free(input_type); |
||
9254 | use_filled = TRUE; |
||
9255 | return RECTS; |
||
9256 | } |
||
8370 | schaersvoo | 9257 | if( strcmp(input_type, roundrects) == 0 ){ |
9258 | free(input_type); |
||
9259 | return ROUNDRECTS; |
||
9260 | } |
||
7614 | schaersvoo | 9261 | if( strcmp(input_type, roundrect) == 0 || strcmp(input_type, roundrectangle) == 0 ){ |
9262 | free(input_type); |
||
9263 | return ROUNDRECT; |
||
9264 | } |
||
9374 | schaersvoo | 9265 | if( strcmp(input_type, froundrects) == 0 ){ |
7614 | schaersvoo | 9266 | free(input_type); |
9267 | use_filled = TRUE; |
||
9374 | schaersvoo | 9268 | return ROUNDRECTS; |
7614 | schaersvoo | 9269 | } |
9374 | schaersvoo | 9270 | if( strcmp(input_type, froundrect) == 0 ){ |
7614 | schaersvoo | 9271 | free(input_type); |
9272 | use_filled = TRUE; |
||
9374 | schaersvoo | 9273 | return ROUNDRECT; |
7614 | schaersvoo | 9274 | } |
9275 | if( strcmp(input_type, dline) == 0 ){ |
||
9276 | use_dashed = TRUE; |
||
9277 | free(input_type); |
||
9278 | return LINE; |
||
9279 | } |
||
7786 | schaersvoo | 9280 | if( strcmp(input_type, dvline) == 0 ){ |
9281 | use_dashed = TRUE; |
||
9282 | free(input_type); |
||
9283 | return VLINE; |
||
9284 | } |
||
9285 | if( strcmp(input_type, dhline) == 0 ){ |
||
9286 | use_dashed = TRUE; |
||
9287 | free(input_type); |
||
9288 | return HLINE; |
||
9289 | } |
||
9386 | schaersvoo | 9290 | if( strcmp(input_type, halflines) == 0 || strcmp(input_type, demilines) == 0 ){ |
9291 | free(input_type); |
||
9292 | return HALFLINES; |
||
9293 | } |
||
9294 | if( strcmp(input_type, halfline) == 0 || strcmp(input_type, demiline) == 0 ){ |
||
9295 | free(input_type); |
||
9296 | return HALFLINE; |
||
9297 | } |
||
7614 | schaersvoo | 9298 | if( strcmp(input_type, frect) == 0 || strcmp(input_type, frectangle) == 0 ){ |
9299 | use_filled = TRUE; |
||
9300 | free(input_type); |
||
9301 | return RECT; |
||
9302 | } |
||
8304 | schaersvoo | 9303 | if( strcmp(input_type, circles) == 0 ){ |
9304 | free(input_type); |
||
9305 | return CIRCLES; |
||
9306 | } |
||
7614 | schaersvoo | 9307 | if( strcmp(input_type, fcircle) == 0 || strcmp(input_type, disk) == 0 ){ |
9308 | use_filled = TRUE; |
||
9309 | free(input_type); |
||
9310 | return CIRCLE; |
||
9311 | } |
||
9374 | schaersvoo | 9312 | if( strcmp(input_type, fcircles) == 0 || strcmp(input_type, disks) == 0 ){ |
9313 | use_filled = TRUE; |
||
9314 | free(input_type); |
||
9315 | return CIRCLES; |
||
9316 | } |
||
7614 | schaersvoo | 9317 | if( strcmp(input_type, circle) == 0 ){ |
9318 | free(input_type); |
||
9319 | return CIRCLE; |
||
9320 | } |
||
9321 | if( strcmp(input_type, point) == 0 ){ |
||
9322 | free(input_type); |
||
9323 | return POINT; |
||
9324 | } |
||
9325 | if( strcmp(input_type, points) == 0 ){ |
||
9326 | free(input_type); |
||
9327 | return POINTS; |
||
9328 | } |
||
9374 | schaersvoo | 9329 | if( strcmp(input_type, filledarc) == 0 || strcmp(input_type, farc) == 0 ){ |
7614 | schaersvoo | 9330 | use_filled = TRUE; |
9331 | free(input_type); |
||
9332 | return ARC; |
||
9333 | } |
||
9334 | if( strcmp(input_type, arc) == 0 ){ |
||
9335 | free(input_type); |
||
9336 | return ARC; |
||
9337 | } |
||
9338 | if( strcmp(input_type, poly) == 0 || strcmp(input_type, polygon) == 0 ){ |
||
9339 | free(input_type); |
||
9340 | return POLY; |
||
9341 | } |
||
9342 | if( strcmp(input_type, fpoly) == 0 || strcmp(input_type, filledpoly) == 0 || strcmp(input_type,filledpolygon) == 0 || strcmp(input_type,fpolygon) == 0 ){ |
||
9343 | use_filled = TRUE; |
||
9344 | free(input_type); |
||
9345 | return POLY; |
||
9346 | } |
||
9347 | if( strcmp(input_type, ellipse) == 0){ |
||
9348 | free(input_type); |
||
9349 | return ELLIPSE; |
||
9350 | } |
||
9351 | if( strcmp(input_type, string) == 0 ){ |
||
9352 | free(input_type); |
||
9353 | return STRING; |
||
9354 | } |
||
9355 | if( strcmp(input_type, stringup) == 0 ){ |
||
9356 | free(input_type); |
||
9357 | return STRINGUP; |
||
9358 | } |
||
9385 | schaersvoo | 9359 | if( strcmp(input_type, opacity) == 0 || strcmp(input_type, transparent) == 0 ){ |
7614 | schaersvoo | 9360 | free(input_type); |
9361 | return OPACITY; |
||
9362 | } |
||
9363 | if( strcmp(input_type, comment) == 0){ |
||
9364 | free(input_type); |
||
9365 | return COMMENT; |
||
9366 | } |
||
9367 | if( strcmp(input_type, fellipse) == 0){ |
||
9368 | free(input_type); |
||
9369 | use_filled = TRUE; |
||
9370 | return ELLIPSE; |
||
8224 | bpr | 9371 | } |
9386 | schaersvoo | 9372 | if( strcmp(input_type, clearbutton) == 0 || strcmp(input_type, erase) == 0 || strcmp(input_type, delete) == 0){ |
7614 | schaersvoo | 9373 | free(input_type); |
8146 | schaersvoo | 9374 | return CLEARBUTTON; |
7614 | schaersvoo | 9375 | } |
9376 | if( strcmp(input_type, translation) == 0 || strcmp(input_type, translate) == 0 ){ |
||
9377 | free(input_type); |
||
9378 | return TRANSLATION; |
||
9379 | } |
||
9380 | if( strcmp(input_type, killtranslation) == 0 || strcmp(input_type, killtranslate) == 0){ |
||
9381 | free(input_type); |
||
9382 | return KILLTRANSLATION; |
||
9383 | } |
||
9384 | if( strcmp(input_type, rotate) == 0){ |
||
9385 | free(input_type); |
||
9386 | return ROTATE; |
||
9387 | } |
||
9907 | schaersvoo | 9388 | if( strcmp(input_type, killrotate) == 0){ |
9389 | free(input_type); |
||
9390 | return KILLROTATE; |
||
9391 | } |
||
9392 | if( strcmp(input_type, rotationcenter) == 0){ |
||
9393 | free(input_type); |
||
9394 | return ROTATION_CENTER; |
||
9395 | } |
||
7785 | schaersvoo | 9396 | if( strcmp(input_type, affine) == 0){ |
9397 | free(input_type); |
||
9398 | return AFFINE; |
||
9399 | } |
||
9400 | if( strcmp(input_type, killaffine) == 0){ |
||
9401 | free(input_type); |
||
9402 | return KILLAFFINE; |
||
9403 | } |
||
7614 | schaersvoo | 9404 | if( strcmp(input_type, slider) == 0 ){ |
9405 | free(input_type); |
||
9406 | return SLIDER; |
||
9407 | } |
||
8101 | schaersvoo | 9408 | if( strcmp(input_type, killslider) == 0 ){ |
9409 | free(input_type); |
||
9410 | return KILLSLIDER; |
||
9411 | } |
||
7614 | schaersvoo | 9412 | if( strcmp(input_type, copy) == 0 ){ |
9413 | free(input_type); |
||
9414 | return COPY; |
||
9415 | } |
||
9416 | if( strcmp(input_type, copyresized) == 0 ){ |
||
9417 | free(input_type); |
||
9418 | return COPYRESIZED; |
||
9419 | } |
||
9420 | if( strcmp(input_type, xlogscale) == 0 ){ |
||
9421 | free(input_type); |
||
9422 | return XLOGSCALE; |
||
9423 | } |
||
9424 | if( strcmp(input_type, ylogscale) == 0 ){ |
||
9425 | free(input_type); |
||
9426 | return YLOGSCALE; |
||
9427 | } |
||
9428 | if( strcmp(input_type, xylogscale) == 0 ){ |
||
9429 | free(input_type); |
||
9430 | return XYLOGSCALE; |
||
9431 | } |
||
9432 | if( strcmp(input_type, ylogscale) == 0 ){ |
||
9433 | free(input_type); |
||
9434 | return YLOGSCALE; |
||
9435 | } |
||
7735 | schaersvoo | 9436 | if( strcmp(input_type, xlogbase) == 0 ){ |
7614 | schaersvoo | 9437 | free(input_type); |
7735 | schaersvoo | 9438 | return XLOGBASE; |
7614 | schaersvoo | 9439 | } |
7735 | schaersvoo | 9440 | if( strcmp(input_type, ylogbase) == 0 ){ |
9441 | free(input_type); |
||
9442 | return YLOGBASE; |
||
9443 | } |
||
7614 | schaersvoo | 9444 | if( strcmp(input_type, intooltip) == 0 ){ |
9445 | free(input_type); |
||
9446 | return INTOOLTIP; |
||
9447 | } |
||
9329 | schaersvoo | 9448 | if( strcmp(input_type, popup) == 0 ){ |
9449 | free(input_type); |
||
9450 | return POPUP; |
||
9451 | } |
||
7614 | schaersvoo | 9452 | if( strcmp(input_type,video) == 0 ){ |
9453 | free(input_type); |
||
9454 | return VIDEO; |
||
9455 | } |
||
11772 | schaersvoo | 9456 | if( strcmp(input_type,fillall) == 0 ){ |
9457 | free(input_type); |
||
9458 | return FILLALL; |
||
9459 | } |
||
7614 | schaersvoo | 9460 | if( strcmp(input_type,floodfill) == 0 || strcmp(input_type,fill) == 0 ){ |
9461 | free(input_type); |
||
9462 | return FLOODFILL; |
||
8224 | bpr | 9463 | } |
7614 | schaersvoo | 9464 | if( strcmp(input_type,filltoborder) == 0 ){ |
9465 | free(input_type); |
||
9466 | return FILLTOBORDER; |
||
8224 | bpr | 9467 | } |
7614 | schaersvoo | 9468 | if( strcmp(input_type, replyformat) == 0 ){ |
9469 | free(input_type); |
||
9470 | return REPLYFORMAT; |
||
9471 | } |
||
9472 | if( strcmp(input_type, pixelsize) == 0 ){ |
||
9473 | free(input_type); |
||
9474 | return PIXELSIZE; |
||
9475 | } |
||
9476 | if( strcmp(input_type, setpixel) == 0 ){ |
||
9477 | free(input_type); |
||
9478 | return SETPIXEL; |
||
9479 | } |
||
9480 | if( strcmp(input_type, pixels) == 0 ){ |
||
9481 | free(input_type); |
||
9482 | return PIXELS; |
||
9483 | } |
||
9484 | if( strcmp(input_type, xaxis) == 0 || strcmp(input_type, xaxistext) == 0 ){ |
||
9485 | free(input_type); |
||
9486 | return X_AXIS_STRINGS; |
||
9487 | } |
||
9341 | schaersvoo | 9488 | if( strcmp(input_type, xaxisup) == 0 || strcmp(input_type, xaxistextup) == 0 ){ |
9489 | free(input_type); |
||
9490 | return X_AXIS_STRINGS_UP; |
||
9491 | } |
||
7614 | schaersvoo | 9492 | if( strcmp(input_type, yaxis) == 0 || strcmp(input_type, yaxistext) == 0 ){ |
9493 | free(input_type); |
||
9494 | return Y_AXIS_STRINGS; |
||
9495 | } |
||
9496 | if( strcmp(input_type, legend) == 0 ){ |
||
9497 | free(input_type); |
||
9498 | return LEGEND; |
||
9499 | } |
||
9500 | if( strcmp(input_type, legendcolors) == 0 ){ |
||
9501 | free(input_type); |
||
9502 | return LEGENDCOLORS; |
||
9503 | } |
||
9504 | if( strcmp(input_type, xlabel) == 0 ){ |
||
9505 | free(input_type); |
||
9506 | return XLABEL; |
||
9507 | } |
||
9508 | if( strcmp(input_type, ylabel) == 0 ){ |
||
9509 | free(input_type); |
||
9510 | return YLABEL; |
||
9511 | } |
||
8370 | schaersvoo | 9512 | if( strcmp(input_type, bezier) == 0 ){ |
9513 | free(input_type); |
||
9514 | return BEZIER; |
||
9515 | } |
||
7614 | schaersvoo | 9516 | if( strcmp(input_type, animate) == 0 ){ |
9517 | free(input_type); |
||
9518 | return ANIMATE; |
||
9519 | } |
||
9354 | schaersvoo | 9520 | /* these are bitmap related flydraw commands...must be removed. eventually */ |
7614 | schaersvoo | 9521 | if( strcmp(input_type, transparent) == 0 ){ |
9522 | free(input_type); |
||
9523 | return TRANSPARENT; |
||
9524 | } |
||
7877 | schaersvoo | 9525 | if( strcmp(input_type, status) == 0 || strcmp(input_type, nostatus) == 0 ){ |
7614 | schaersvoo | 9526 | free(input_type); |
9527 | return STATUS; |
||
9528 | } |
||
7784 | schaersvoo | 9529 | if( strcmp(input_type, xsnaptogrid) == 0 ){ |
9530 | free(input_type); |
||
9531 | return XSNAPTOGRID; |
||
9532 | } |
||
9533 | if( strcmp(input_type, ysnaptogrid) == 0 ){ |
||
9534 | free(input_type); |
||
9535 | return YSNAPTOGRID; |
||
9536 | } |
||
8379 | schaersvoo | 9537 | if( strcmp(input_type, snaptogrid) == 0 ){ |
9538 | free(input_type); |
||
9539 | return SNAPTOGRID; |
||
9540 | } |
||
9541 | if( strcmp(input_type, snaptopoints) == 0 ){ |
||
9542 | free(input_type); |
||
9543 | return SNAPTOPOINTS; |
||
9544 | } |
||
9213 | schaersvoo | 9545 | if( strcmp(input_type, snaptofunction) == 0 || strcmp(input_type, snaptofun) == 0 ){ |
9546 | free(input_type); |
||
9547 | return SNAPTOFUNCTION; |
||
9548 | } |
||
7652 | schaersvoo | 9549 | if( strcmp(input_type, userinput_xy) == 0 ){ |
7614 | schaersvoo | 9550 | free(input_type); |
7652 | schaersvoo | 9551 | return USERINPUT_XY; |
9552 | } |
||
8193 | schaersvoo | 9553 | if( strcmp(input_type, userinput_function) == 0 ){ |
9554 | free(input_type); |
||
9555 | return USERINPUT_FUNCTION; |
||
9556 | } |
||
7663 | schaersvoo | 9557 | if( strcmp(input_type, usertextarea_xy) == 0 ){ |
9558 | free(input_type); |
||
9559 | return USERTEXTAREA_XY; |
||
9560 | } |
||
8222 | schaersvoo | 9561 | if( strcmp(input_type, userinput) == 0 ){ |
9562 | free(input_type); |
||
9563 | return USERINPUT; |
||
9564 | } |
||
8105 | schaersvoo | 9565 | if( strcmp(input_type, angle) == 0 ){ |
7996 | schaersvoo | 9566 | free(input_type); |
8105 | schaersvoo | 9567 | return ANGLE; |
9568 | } |
||
8297 | schaersvoo | 9569 | if( strcmp(input_type, functionlabel) == 0 ){ |
8244 | schaersvoo | 9570 | free(input_type); |
8297 | schaersvoo | 9571 | return FUNCTION_LABEL; |
9572 | } |
||
9213 | schaersvoo | 9573 | if( strcmp(input_type, sliderfunction_x) == 0 ){ |
8297 | schaersvoo | 9574 | free(input_type); |
9213 | schaersvoo | 9575 | return SLIDER_X; |
9576 | } |
||
9577 | if( strcmp(input_type, sliderfunction_y) == 0 ){ |
||
9578 | free(input_type); |
||
9579 | return SLIDER_Y; |
||
9580 | } |
||
9581 | if( strcmp(input_type, multidraw) == 0 ){ |
||
9582 | free(input_type); |
||
9583 | return MULTIDRAW; |
||
9584 | } |
||
9585 | if( strcmp(input_type, multistrokeopacity) == 0 ){ |
||
9586 | free(input_type); |
||
9587 | return MULTISTROKEOPACITY; |
||
9588 | } |
||
9589 | if( strcmp(input_type, multifillopacity) == 0 ){ |
||
9590 | free(input_type); |
||
9591 | return MULTIFILLOPACITY; |
||
9592 | } |
||
9593 | if( strcmp(input_type, multilinewidth) == 0 ){ |
||
9594 | free(input_type); |
||
9595 | return MULTILINEWIDTH; |
||
9596 | } |
||
9597 | if( strcmp(input_type, multistrokecolors) == 0 ){ |
||
9598 | free(input_type); |
||
9599 | return MULTISTROKECOLORS; |
||
9600 | } |
||
9601 | if( strcmp(input_type, multifill) == 0 ){ |
||
9602 | free(input_type); |
||
9603 | return MULTIFILL; |
||
9604 | } |
||
9605 | if( strcmp(input_type, multifillcolors) == 0 ){ |
||
9606 | free(input_type); |
||
9607 | return MULTIFILLCOLORS; |
||
9608 | } |
||
9609 | if( strcmp(input_type, multilabel) == 0 ){ |
||
9610 | free(input_type); |
||
9611 | return MULTILABEL; |
||
9612 | } |
||
9613 | if( strcmp(input_type, multidash) == 0 ){ |
||
9614 | free(input_type); |
||
9615 | return MULTIDASH; |
||
9616 | } |
||
9617 | if( strcmp(input_type, multisnaptogrid) == 0 ){ |
||
9618 | free(input_type); |
||
9619 | return MULTISNAPTOGRID; |
||
9620 | } |
||
9621 | if( strcmp(input_type, multiuserinput) == 0 ){ |
||
9622 | free(input_type); |
||
9623 | return MULTIUSERINPUT; |
||
9624 | } |
||
9386 | schaersvoo | 9625 | if( strcmp(input_type, parallel) == 0 ){ |
9626 | free(input_type); |
||
9627 | return PARALLEL; |
||
9628 | } |
||
9289 | schaersvoo | 9629 | if( strcmp(input_type, protractor) == 0 ){ |
9630 | free(input_type); |
||
9631 | return PROTRACTOR; |
||
9632 | } |
||
9633 | if( strcmp(input_type, ruler) == 0 ){ |
||
9634 | free(input_type); |
||
9635 | return RULER; |
||
9636 | } |
||
9386 | schaersvoo | 9637 | if( strcmp(input_type, cursor) == 0 || strcmp(input_type, pointer) == 0 ){ |
9213 | schaersvoo | 9638 | free(input_type); |
9386 | schaersvoo | 9639 | return CURSOR; |
9640 | } |
||
9641 | if( strcmp(input_type, sgraph) == 0 ){ |
||
9642 | free(input_type); |
||
9643 | return SGRAPH; |
||
9644 | } |
||
9645 | if( strcmp(input_type, jsmath) == 0 ){ |
||
9646 | free(input_type); |
||
9647 | return JSMATH; |
||
9648 | } |
||
9649 | if( strcmp(input_type, trace_jscurve) == 0 ){ |
||
9650 | free(input_type); |
||
9651 | return TRACE_JSCURVE; |
||
9652 | } |
||
9653 | if( strcmp(input_type, jscurve) == 0 || strcmp(input_type, jsplot) == 0 ){ |
||
9654 | free(input_type); |
||
9655 | return JSCURVE; |
||
9656 | } |
||
9657 | if( strcmp(input_type, centerstring) == 0 || strcmp(input_type, title) == 0 ){ |
||
9658 | free(input_type); |
||
9659 | return CENTERSTRING; |
||
9660 | } |
||
9661 | if( strcmp(input_type, setlimits) == 0 ){ |
||
9662 | free(input_type); |
||
9663 | return SETLIMITS; |
||
9664 | } |
||
9665 | if( strcmp(input_type, xunit) == 0 ){ |
||
9666 | free(input_type); |
||
9667 | return XUNIT; |
||
9668 | } |
||
9669 | if( strcmp(input_type, yunit) == 0 ){ |
||
9670 | free(input_type); |
||
9671 | return YUNIT; |
||
9672 | } |
||
9673 | if( strcmp(input_type, fill) == 0 ){ |
||
9674 | free(input_type); |
||
9675 | return FLOODFILL; |
||
9676 | } |
||
9677 | if( strcmp(input_type, end) == 0){ |
||
9678 | free(input_type); |
||
9679 | return END; |
||
9680 | } |
||
9681 | if( strcmp(input_type, blink) == 0 ){ |
||
9682 | free(input_type); |
||
9683 | return BLINK; |
||
9684 | } |
||
9685 | if( strcmp(input_type, audio) == 0 ){ |
||
9686 | free(input_type); |
||
9687 | return AUDIO; |
||
9688 | } |
||
9689 | if( strcmp(input_type, audioobject) == 0 ){ |
||
9690 | free(input_type); |
||
9691 | return AUDIOOBJECT; |
||
9692 | } |
||
9693 | if( strcmp(input_type, patternfill) == 0 ){ |
||
9694 | free(input_type); |
||
9695 | return PATTERNFILL; |
||
9696 | } |
||
9697 | if( strcmp(input_type, hatchfill) == 0 ){ |
||
9698 | free(input_type); |
||
9699 | return HATCHFILL; |
||
9700 | } |
||
9701 | if( strcmp(input_type, diafill) == 0 || strcmp(input_type, diamondfill) == 0 ){ |
||
9702 | free(input_type); |
||
9703 | return DIAMONDFILL; |
||
9704 | } |
||
9705 | if( strcmp(input_type, dotfill) == 0 ){ |
||
9706 | free(input_type); |
||
9707 | return DOTFILL; |
||
9708 | } |
||
9709 | if( strcmp(input_type, gridfill) == 0 ){ |
||
9710 | free(input_type); |
||
9711 | return GRIDFILL; |
||
9712 | } |
||
9713 | if( strcmp(input_type, imagefill) == 0 ){ |
||
9714 | free(input_type); |
||
9715 | return IMAGEFILL; |
||
9716 | } |
||
9717 | if( strcmp(input_type, clicktile_colors) == 0 ){ |
||
9718 | free(input_type); |
||
9719 | return CLICKTILE_COLORS; |
||
9720 | } |
||
9721 | if( strcmp(input_type, clicktile) == 0 ){ |
||
9722 | free(input_type); |
||
9723 | return CLICKTILE; |
||
9724 | } |
||
9725 | if( strcmp(input_type, piechart) == 0 ){ |
||
9726 | free(input_type); |
||
9727 | return PIECHART; |
||
9728 | } |
||
9433 | schaersvoo | 9729 | if( strcmp(input_type, boxplot) == 0 ){ |
9730 | free(input_type); |
||
9731 | return BOXPLOT; |
||
9732 | } |
||
9465 | schaersvoo | 9733 | if( strcmp(input_type, boxplotdata) == 0 ){ |
9433 | schaersvoo | 9734 | free(input_type); |
9465 | schaersvoo | 9735 | return BOXPLOTDATA; |
9433 | schaersvoo | 9736 | } |
9465 | schaersvoo | 9737 | if( strcmp(input_type, userboxplot) == 0 ){ |
9738 | free(input_type); |
||
9739 | return USERBOXPLOT; |
||
9740 | } |
||
9741 | if( strcmp(input_type, userboxplotdata) == 0 ){ |
||
9742 | free(input_type); |
||
9743 | return USERBOXPLOT; |
||
9744 | } |
||
9386 | schaersvoo | 9745 | if( strcmp(input_type, barchart) == 0 ){ |
9746 | free(input_type); |
||
9747 | return BARCHART; |
||
9748 | } |
||
9749 | if( strcmp(input_type, linegraph) == 0 ){ |
||
9750 | free(input_type); |
||
9751 | return LINEGRAPH; |
||
9752 | } |
||
9753 | if( strcmp(input_type, clock) == 0 ){ |
||
9754 | free(input_type); |
||
9755 | return CLOCK; |
||
9756 | } |
||
9427 | schaersvoo | 9757 | if( strcmp(input_type, yerrorbars) == 0 ){ |
9386 | schaersvoo | 9758 | free(input_type); |
9427 | schaersvoo | 9759 | return YERRORBARS; |
9760 | } |
||
9761 | if( strcmp(input_type, xerrorbars) == 0 ){ |
||
9762 | free(input_type); |
||
9763 | return XERRORBARS; |
||
9764 | } |
||
11006 | schaersvoo | 9765 | if( strcmp(input_type, canvastype) == 0 ){ |
9427 | schaersvoo | 9766 | free(input_type); |
11006 | schaersvoo | 9767 | return CANVASTYPE; |
9768 | } |
||
11044 | schaersvoo | 9769 | if( strcmp(input_type, noyaxis) == 0 ){ |
11006 | schaersvoo | 9770 | free(input_type); |
11044 | schaersvoo | 9771 | return NOYAXIS; |
9772 | } |
||
9773 | if( strcmp(input_type, noxaxis) == 0 ){ |
||
9774 | free(input_type); |
||
9775 | return NOXAXIS; |
||
9776 | } |
||
11767 | schaersvoo | 9777 | if( strcmp(input_type, colorpalette) == 0 ){ |
11044 | schaersvoo | 9778 | free(input_type); |
11767 | schaersvoo | 9779 | return COLORPALETTE; |
9780 | } |
||
11802 | schaersvoo | 9781 | if( strcmp(input_type, resetoffset) == 0 ){ |
11767 | schaersvoo | 9782 | free(input_type); |
11802 | schaersvoo | 9783 | return RESETOFFSET; |
9784 | } |
||
9785 | if( strcmp(input_type, xyoffset) == 0 ){ |
||
9786 | free(input_type); |
||
9787 | return XYOFFSET; |
||
9788 | } |
||
9789 | if( strcmp(input_type, xoffset) == 0 || strcmp(input_type, centered) == 0 ){ |
||
9790 | free(input_type); |
||
9791 | return XOFFSET; |
||
9792 | } |
||
9793 | free(input_type); |
||
7614 | schaersvoo | 9794 | ungetc(c,infile); |
9795 | return 0; |
||
9796 | } |