Rev 7842 | Rev 7856 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
7614 | schaersvoo | 1 | /* |
2 | 27/7/2013 version 0.01 |
||
3 | "Inspired" by FLY program: http://martin.gleeson.com/fly |
||
4 | ********************************************************************************* |
||
5 | * J.M. Evers 7/2013 * |
||
6 | * This is all just amateur scriblings... So no copyrights. * |
||
7 | * This source code file, and compiled objects derived from it, * |
||
8 | * can be used and distributed without restriction, including for commercial use * |
||
9 | * No warrenty whatsoever * |
||
10 | ********************************************************************************* |
||
11 | */ |
||
7848 | bpr | 12 | #include "../../Lib/libwims.h" |
13 | #include "canvasdraw.h" |
||
7842 | bpr | 14 | #include <assert.h> |
7848 | bpr | 15 | #include "canvasmacro.c" |
7614 | schaersvoo | 16 | |
17 | /****************************************************************************** |
||
18 | ** Internal Functions |
||
19 | ******************************************************************************/ |
||
20 | void add_to_buffer(char *tmp); /* add tmp_buffer to the buffer */ |
||
21 | void sync_input(FILE *infile);/* proceed with inputfile */ |
||
22 | void canvas_error(char *msg); |
||
23 | void add_javascript_functions(int js_functions[], int canvas_root_id); |
||
24 | void reset();/* reset some global variables like "use_filled" , "use_dashed" */ |
||
25 | int get_token(FILE *infile); /* read next char until EOL*/ |
||
26 | int x2px(double x); |
||
27 | int y2px(double y); |
||
28 | double px2x(int x); |
||
29 | double px2y(int y); |
||
30 | double get_real(FILE *infile,int last); /* read a values; calculation and symbols allowed */ |
||
31 | char *str_replace ( const char *word, const char *sub_word, const char *rep_word ); |
||
32 | char *get_color(FILE *infile,int last); /* read hex-color or colorname -> hex */ |
||
33 | char *get_string(FILE *infile,int last); /* get the string at theend of a command */ |
||
34 | char *get_string_argument(FILE *infile,int last); /* the same, but with "comma" as separator */ |
||
35 | char *convert_hex2rgb(char *hexcolor); |
||
36 | void add_read_canvas(int reply_format); |
||
37 | void make_js_include(int canvas_root_id); |
||
38 | void check_string_length(int length);/* checks if the length of string argument of command is correct */ |
||
7842 | bpr | 39 | FILE *js_include_file; |
7614 | schaersvoo | 40 | FILE *get_file(int *line_number, char **filename); |
41 | FILE *infile; /* will be stdin */ |
||
42 | /****************************************************************************** |
||
43 | ** global |
||
44 | ******************************************************************************/ |
||
45 | int finished = FALSE;/* main variable for signalling the end of the fly-script ; if finished = 1 ; write to stdout or canvasz */ |
||
46 | int line_number = 1;/* used in canvas_error() ; keep track of line number in canvasdraw/fly - script */ |
||
47 | /* set some variables to avoid trouble (NaN) in case of syntax and other usage errors */ |
||
48 | int xsize = 320; |
||
49 | int ysize = 320; |
||
50 | double xmin = 0.0; |
||
51 | double xmax = 320.0; |
||
52 | double ymin = 0.0; |
||
53 | double ymax = 320.0; |
||
54 | double tmax = 2; |
||
55 | double tmin = -2; |
||
56 | /* flag to indicate parsing of line status */ |
||
7842 | bpr | 57 | int done = FALSE; |
7614 | schaersvoo | 58 | int type; /* eg command number */ |
59 | int onclick = 0;/* 0 = noninteractive ; 1 = onclick ; 2 = draggable*/ |
||
7785 | schaersvoo | 60 | int use_affine = FALSE; |
7614 | schaersvoo | 61 | int use_rotate = FALSE; |
62 | int use_translate = FALSE; |
||
63 | int use_filled = FALSE; |
||
64 | int use_dashed = FALSE; /* dashing not natively supported in firefox , for now... */ |
||
65 | char buffer[MAX_BUFFER];/* contains js-functions with arguments ... all other basic code is directly printed into js-include file */ |
||
66 | |||
67 | /****************************************************************************** |
||
68 | ** Main Program |
||
69 | ******************************************************************************/ |
||
70 | int main(int argc, char *argv[]){ |
||
71 | /* need unique id for every call to canvasdraw : rand(); is too slow...will result in many identical id's */ |
||
72 | struct timeval tv;struct timezone tz;gettimeofday(&tv, &tz);unsigned int canvas_root_id = (unsigned int) tv.tv_usec; |
||
73 | infile = stdin;/* read flyscript via stdin */ |
||
74 | int i,c; |
||
75 | double double_data[MAX_INT+1]; |
||
76 | int int_data[MAX_INT+1]; |
||
77 | for(i=0;i<MAX_INT;i++){int_data[i]=0;double_data[i]=0;} |
||
78 | int use_parametric = FALSE;/* will be reset after parametric plotting */ |
||
79 | int use_axis = FALSE; |
||
80 | int use_axis_numbering = FALSE; |
||
7797 | schaersvoo | 81 | int use_pan_and_zoom = FALSE; |
7614 | schaersvoo | 82 | int line_width = 1; |
83 | int decimals = 2; |
||
84 | int precision = 100; /* 10 = 1;100=2;1000=3 decimal display for mouse coordinates or grid coordinate */ |
||
85 | int use_userdraw = FALSE; /* flag to indicate user interaction: incompatible with "drag & drop" code !! */ |
||
86 | int drag_type = -1;/* 0,1,2 : xy,x,y */ |
||
87 | int use_tooltip = FALSE; |
||
88 | char *tooltip_text = "Click here"; |
||
89 | char *temp = ""; /* */ |
||
90 | char *bgcolor = "";/* used for background of canvas_div ; default is tranparent */ |
||
91 | char *stroke_color = "255,0,0"; |
||
92 | char *fill_color = "0,255,0"; |
||
93 | char *font_family = "12px Ariel"; /* commands xaxistext,yaxistext,legend,text/textup/string/stringup may us this */ |
||
94 | char *font_color = "#00000"; |
||
95 | char *draw_type = "points"; |
||
96 | char *fly_font = "normal"; |
||
97 | char *input_style = ""; |
||
98 | char *flytext = ""; |
||
7785 | schaersvoo | 99 | char *affine_matrix = "[1,0,0,1,0,0]"; |
7614 | schaersvoo | 100 | int pixelsize = 1; |
101 | int reply_format = 0; |
||
102 | int input_cnt = 0; |
||
103 | int ext_img_cnt = 0; |
||
104 | int font_size = 12; |
||
105 | int dashtype[2] = { 2 , 2 }; |
||
106 | int js_function[MAX_JS_FUNCTIONS]; /* javascript functions include objects on demand basis : only once per object type */ |
||
107 | for(i=0;i<MAX_JS_FUNCTIONS;i++){js_function[i]=0;} |
||
108 | int arrow_head = 8; /* size in px*/ |
||
7833 | schaersvoo | 109 | int crosshair_size = 5; /* size in px*/ |
7842 | bpr | 110 | int plot_steps = 250; |
7614 | schaersvoo | 111 | int found_size_command = 0; |
112 | int click_cnt = 1; |
||
113 | int clock_cnt = 0; /* counts the amount of clocks used -> unique object clock%d */ |
||
114 | int linegraph_cnt = 0; /* identifier for command 'linegraph' ; multiple line graphs may be plotted in a single plot*/ |
||
115 | double angle = 0.0; |
||
116 | int translate_x = 0; |
||
117 | int translate_y = 0; |
||
118 | int clickfillmarge = 20; |
||
119 | int animation_type = 9; /* == object type curve in drag library */ |
||
7823 | schaersvoo | 120 | int use_input_xy = 0; /* 1= input fields 2= textarea 3=calc y value*/ |
7614 | schaersvoo | 121 | size_t string_length = 0; |
122 | double stroke_opacity = 0.8; |
||
123 | double fill_opacity = 0.8; |
||
124 | char *URL = "http://localhost/images"; |
||
125 | memset(buffer,'\0',MAX_BUFFER); |
||
126 | void *tmp_buffer = ""; |
||
7842 | bpr | 127 | |
7614 | schaersvoo | 128 | /* default writing a unzipped js-include file into wims getfile directory */ |
129 | char *w_wims_session = getenv("w_wims_session"); |
||
7842 | bpr | 130 | if( w_wims_session == NULL || *w_wims_session == 0 ){ |
7614 | schaersvoo | 131 | canvas_error("Hmmm, your wims environment does not exist...\nCanvasdraw should be used within wims."); |
132 | } |
||
133 | int L0=strlen(w_wims_session) + 21; |
||
134 | char *getfile_dir = my_newmem(L0); /* create memory to fit string precisely */ |
||
135 | snprintf(getfile_dir,L0, "../sessions/%s/getfile",w_wims_session);/* string will fit precisely */ |
||
136 | mode_t process_mask = umask(0); /* check if file exists */ |
||
137 | int result = mkdir(getfile_dir, S_IRWXU | S_IRWXG | S_IRWXO); |
||
138 | if( result == 0 || errno == EEXIST ){ |
||
139 | umask(process_mask); /* be sure to set correct permission */ |
||
7842 | bpr | 140 | char *w_session = getenv("w_session"); |
7614 | schaersvoo | 141 | int L1 = (int) (strlen(w_session)) + find_number_of_digits(canvas_root_id) + 48; |
142 | char *getfile_cmd = my_newmem(L1); /* create memory to fit string precisely */ |
||
7842 | bpr | 143 | 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 | 144 | /* write the include tag to html page:<script type="text/javascript" src="wims.cgi?session=%s&cmd=getfile&special_parm=11223344_js"></script> */ |
145 | /* now write file into getfile dir*/ |
||
146 | char *w_wims_home = getenv("w_wims_home"); /* "/home/users/wims" : we need absolute path for location */ |
||
147 | int L2 = (int) (strlen(w_wims_home)) + (int) (strlen(w_wims_session)) + find_number_of_digits(canvas_root_id) + 23; |
||
148 | char *location = my_newmem(L2); /* create memory to fit string precisely */ |
||
149 | snprintf(location,L2,"%s/sessions/%s/getfile/%d.js",w_wims_home,w_wims_session,canvas_root_id);/*absolute path */ |
||
150 | js_include_file = fopen(location,"w");/* open the file location for writing */ |
||
151 | /* check on opening...if nogood : mount readonly? disk full? permissions not set correctly? */ |
||
152 | if(js_include_file == NULL){ canvas_error("SHOULD NOT HAPPEN : could not write to javascript include file...check your system logfiles !" );} |
||
153 | |||
154 | /* ----------------------------------------------------- */ |
||
155 | /* while more lines to process */ |
||
156 | |||
157 | while(!finished){ |
||
158 | if(line_number>1 && found_size_command == FALSE){canvas_error("command \"size xsize,ysize\" needs to come first ! ");} |
||
159 | type = get_token(infile); |
||
160 | done = FALSE; |
||
161 | /* |
||
162 | @canvasdraw |
||
7842 | bpr | 163 | @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...) |
7749 | schaersvoo | 164 | @General syntax <ul><li>The transparency of all objects can be controlled by command 'opacity [0-255],[0,255]'</il><li>a line based object can be controlled by command 'linewidth int'</li><li>a line based object may be dashed by using keyword 'dashed' before the object command.<br />the dashing type can be controled by command 'dashtype int,int'</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 'filled' before the object command.<br />The fill colour will be the stroke colour...(19/10/2013)<li> a draggable object can be set draggable by a preceding command 'drag x/y/xy'<br />The translation can be read by javascript:read_dragdrop();<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 zoom and will be translated in case of panning</li><li> a 'onclick object' can be set 'clickable' by the preceding keyword 'onclick'<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 (in stead 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.<br />example:<br />size 200,200;xrange -5,5;yrange -5,5;hline 0,0,black;vline 0,0,black<br />plot red,sin(x)<br />drag xy<br />html 0,0,5,-5, &euro; <br />lines green,2,0,2,-2,-2,2,-2,0;rectangle 1,1,4,4,purple;frectangle -1,-1,-4,-4,yellow</li></ul> |
7614 | schaersvoo | 165 | */ |
166 | switch(type){ |
||
167 | case END: |
||
168 | finished = 1; |
||
169 | done = TRUE; |
||
170 | break; |
||
171 | case 0: |
||
172 | sync_input(infile); |
||
173 | break; |
||
174 | case COMMENT: |
||
175 | sync_input(infile); |
||
176 | break; |
||
177 | case EMPTY: |
||
178 | sync_input(infile); |
||
179 | break; |
||
180 | case SIZE: |
||
181 | /* |
||
182 | @size width,height |
||
183 | @set canvas size in pixels |
||
184 | @mandatory first command |
||
7647 | schaersvoo | 185 | @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) |
7614 | schaersvoo | 186 | */ |
187 | found_size_command = TRUE; |
||
188 | xsize = (int)(abs(round(get_real(infile,0)))); /* just to be sure that sizes > 0 */ |
||
189 | ysize = (int)(abs(round(get_real(infile,1)))); |
||
190 | /* sometimes we want xrange / yrange to be in pixels...without telling x/y-range */ |
||
191 | xmin = 0;xmax = xsize; |
||
7647 | schaersvoo | 192 | ymin = 0;ymax = ysize; |
7614 | schaersvoo | 193 | |
7842 | bpr | 194 | /* |
7614 | schaersvoo | 195 | The sequence in which stuff is finally printed is important !! |
196 | for example, when writing a 'include.js" the may not be a "script tag <script>" etc etc |
||
197 | */ |
||
198 | fprintf(stdout,"\n<script type=\"text/javascript\">var wims_status = \"$status\";</script>\n<!-- canvasdraw div and tooltip placeholder, if needed -->\n<div tabindex=\"0\" id=\"canvas_div%d\" style=\"position:relative;width:%dpx;height:%dpx;\" ></div><div id=\"tooltip_placeholder_div%d\" style=\"display:block\"><span id=\"tooltip_placeholder%d\" style=\"display:none\"></span></div>\n",canvas_root_id,xsize,ysize,canvas_root_id,canvas_root_id); |
||
199 | fprintf(js_include_file,"\n<!-- begin generated javascript include for canvasdraw -->\n"); |
||
200 | fprintf(stdout,"<!-- include actual object code via include file -->\n<script type=\"text/javascript\" src=\"%s\"></script>\n",getfile_cmd); |
||
7729 | schaersvoo | 201 | fprintf(js_include_file,"var wims_canvas_function%d = function(){\n<!-- common used stuff -->\n\ |
202 | var xsize = %d;\ |
||
203 | var ysize = %d;\ |
||
7797 | schaersvoo | 204 | var precision = 100;\ |
7729 | schaersvoo | 205 | var canvas_div = document.getElementById(\"canvas_div%d\");\ |
206 | 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;};\ |
||
207 | 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;};\ |
||
7735 | schaersvoo | 208 | function x2px(x){if(use_xlogscale == 0 ){return 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);};};\ |
209 | function px2x(px){if(use_xlogscale == 0 ){return (Math.round((px*(xmax - xmin)/xsize + xmin)*precision))/precision;}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);};};\ |
||
210 | function px2y(py){if(use_ylogscale == 0 ){return (Math.round((ymax -py*(ymax - ymin)/ysize)*precision))/precision;}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);};};\ |
||
211 | function y2px(y){if(use_ylogscale == 0){return -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);};};\ |
||
7729 | schaersvoo | 212 | function scale_x_radius(rx){return parseInt(x2px(rx) - x2px(0));};\ |
213 | function scale_y_radius(ry){return parseInt(y2px(ry) - y2px(0));};\ |
||
214 | function distance(x1,y1,x2,y2){return parseInt(Math.sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) ));};\ |
||
215 | 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) ));};\ |
||
216 | 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;};\ |
||
7735 | schaersvoo | 217 | var xlogbase = 10;\ |
218 | var ylogbase = 10;\ |
||
7729 | schaersvoo | 219 | var use_xlogscale = 0;\ |
220 | var use_ylogscale = 0;\ |
||
221 | var x_strings = null;\ |
||
222 | var y_strings = null;\ |
||
223 | var use_pan_and_zoom = 0;\ |
||
7784 | schaersvoo | 224 | var x_use_snap_to_grid = 0;\ |
225 | var y_use_snap_to_grid = 0;\ |
||
7729 | schaersvoo | 226 | var xstart = 0;\ |
227 | var ystart = 0",canvas_root_id,xsize,ysize,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id); |
||
7614 | schaersvoo | 228 | /* default add the drag code : nearly always used ...*/ |
229 | add_drag_code(js_include_file,DRAG_CANVAS,canvas_root_id); |
||
230 | break; |
||
231 | case XRANGE: |
||
232 | /* |
||
233 | @ xrange xmin,xmax |
||
7842 | bpr | 234 | @ if not given: 0,xsize (eg in pixels) |
7614 | schaersvoo | 235 | */ |
236 | for(i = 0 ; i<2; i++){ |
||
237 | switch(i){ |
||
238 | case 0: xmin = get_real(infile,0);break; |
||
239 | case 1: xmax = get_real(infile,1);break; |
||
240 | default: break; |
||
241 | } |
||
242 | } |
||
243 | if(xmin >= xmax){canvas_error(" xrange is not OK : xmin < xmax !\n");} |
||
244 | fprintf(js_include_file,"var xmin = %f;var xmax = %f;",xmin,xmax); |
||
245 | break; |
||
246 | case YRANGE: |
||
247 | /* |
||
248 | @ yrange ymin,ymax |
||
249 | @ if not given 0,ysize (eg in pixels) |
||
250 | */ |
||
251 | for(i = 0 ; i<2; i++){ |
||
252 | switch(i){ |
||
253 | case 0: ymin = get_real(infile,0);break; |
||
254 | case 1: ymax = get_real(infile,1);break; |
||
255 | default: break; |
||
256 | } |
||
257 | } |
||
258 | if(ymin >= ymax){canvas_error(" yrange is not OK : ymin < ymax !\n");} |
||
259 | fprintf(js_include_file,"var ymin = %f;var ymax = %f;",ymin,ymax); |
||
260 | break; |
||
261 | case TRANGE: |
||
262 | /* |
||
263 | @ trange tmin,tmax |
||
264 | @ default -2,2 |
||
265 | */ |
||
266 | use_parametric = TRUE; |
||
267 | for(i = 0 ; i<2; i++){ |
||
268 | switch(i){ |
||
269 | case 0: tmin = get_real(infile,0);break; |
||
270 | case 1: tmax = get_real(infile,1);break; |
||
271 | default: break; |
||
272 | } |
||
273 | } |
||
274 | if(tmin >= tmax ){canvas_error(" trange is not OK : tmin < tmax!\n");} |
||
275 | break; |
||
276 | case LINEWIDTH: |
||
277 | /* |
||
278 | @ linewidth int |
||
279 | @ default 1 |
||
280 | */ |
||
281 | line_width = (int) (get_real(infile,1)); |
||
282 | break; |
||
283 | case ARROWHEAD: |
||
284 | /* |
||
285 | @ arrowhead int |
||
286 | @ default 8 (pixels) |
||
287 | */ |
||
288 | arrow_head = (int) (get_real(infile,1)); |
||
289 | break; |
||
290 | case CROSSHAIRSIZE: |
||
291 | /* |
||
292 | @ crosshairsize int |
||
293 | @ default 10 (px) |
||
294 | */ |
||
295 | crosshair_size = (int) (get_real(infile,1)); |
||
296 | break; |
||
297 | case CROSSHAIR: |
||
298 | /* |
||
299 | @ crosshair x,y,color |
||
300 | @ draw a single crosshair point at (x;y) in color 'color' |
||
301 | @ use command 'crosshairsize int' and / or 'linewidth int' to adust |
||
302 | @ may be set draggable / onclick |
||
303 | */ |
||
304 | for(i=0;i<3;i++){ |
||
305 | switch(i){ |
||
306 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
307 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
308 | case 2: stroke_color = get_color(infile,1);/* name or hex color */ |
||
309 | decimals = find_number_of_digits(precision); |
||
7785 | schaersvoo | 310 | 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));\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); |
7614 | schaersvoo | 311 | click_cnt++;reset(); |
312 | break; |
||
313 | default:break; |
||
314 | } |
||
315 | } |
||
316 | break; |
||
317 | case CROSSHAIRS: |
||
318 | /* |
||
319 | @ crosshairs color,x1,y1,x2,y2,...,x_n,y_n |
||
320 | @ draw multiple crosshair points at given coordinates in color 'color' |
||
321 | @ use command 'crosshairsize int' and / or 'linewidth int' to adust |
||
322 | @ may be set draggable / onclick individually (!) |
||
323 | */ |
||
324 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
325 | fill_color = stroke_color; |
||
326 | i=0; |
||
327 | while( ! done ){ /* get next item until EOL*/ |
||
328 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
329 | if(i%2 == 0 ){ |
||
330 | double_data[i] = get_real(infile,0); /* x */ |
||
331 | } |
||
332 | else |
||
333 | { |
||
334 | double_data[i] = get_real(infile,1); /* y */ |
||
335 | } |
||
336 | i++; |
||
337 | } |
||
338 | decimals = find_number_of_digits(precision); |
||
339 | for(c=0 ; c < i-1 ; c = c+2){ |
||
7785 | schaersvoo | 340 | 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));\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); |
7614 | schaersvoo | 341 | click_cnt++; |
342 | } |
||
343 | reset(); |
||
344 | break; |
||
345 | case POINT: |
||
346 | /* |
||
347 | @ point x,y,color |
||
348 | @ draw a single point at (x;y) in color 'color' |
||
349 | @ use command 'linewidth int' to adust size |
||
350 | @ may be set draggable / onclick |
||
7842 | bpr | 351 | @ will not resize on zooming <br />(command 'circle x,y,r,color' will resize on zooming) |
7614 | schaersvoo | 352 | */ |
353 | for(i=0;i<3;i++){ |
||
354 | switch(i){ |
||
355 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
356 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
357 | case 2: stroke_color = get_color(infile,1);/* name or hex color */ |
||
358 | decimals = find_number_of_digits(precision); |
||
7785 | schaersvoo | 359 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,2,[%.*f],[%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[1],line_width,line_width,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); |
7614 | schaersvoo | 360 | click_cnt++;break; |
361 | default: break; |
||
362 | } |
||
363 | } |
||
364 | reset(); |
||
365 | break; |
||
366 | case POINTS: |
||
367 | /* |
||
7634 | schaersvoo | 368 | @ points color,x1,y1,x2,y2,...,x_n,y_n |
7614 | schaersvoo | 369 | @ draw multiple points at given coordinates in color 'color' |
370 | @ use command 'linewidth int' to adust size |
||
371 | @ may be set draggable / onclick individually (!) |
||
372 | */ |
||
373 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
374 | fill_color = stroke_color; |
||
375 | i=0; |
||
376 | while( ! done ){ /* get next item until EOL*/ |
||
377 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
378 | if(i%2 == 0 ){ |
||
379 | double_data[i] = get_real(infile,0); /* x */ |
||
380 | } |
||
381 | else |
||
382 | { |
||
383 | double_data[i] = get_real(infile,1); /* y */ |
||
384 | } |
||
385 | i++; |
||
386 | } |
||
7842 | bpr | 387 | decimals = find_number_of_digits(precision); |
7614 | schaersvoo | 388 | for(c = 0 ; c < i-1 ; c = c+2){ |
7785 | schaersvoo | 389 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,2,[%.*f],[%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+1],line_width,line_width,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); |
7614 | schaersvoo | 390 | click_cnt++; |
391 | } |
||
392 | reset(); |
||
393 | break; |
||
394 | case SEGMENT: |
||
395 | /* |
||
396 | @ segment x1,y1,x2,y2,color |
||
397 | @ draw a line segment between points (x1:y1)--(x2:y2) in color 'color' |
||
398 | @ may be set draggable / onclick |
||
399 | */ |
||
400 | for(i=0;i<5;i++) { |
||
401 | switch(i){ |
||
402 | case 0: double_data[0]= get_real(infile,0);break; /* x1-values */ |
||
403 | case 1: double_data[1]= get_real(infile,0);break; /* y1-values */ |
||
404 | case 2: double_data[2]= get_real(infile,0);break; /* x2-values */ |
||
405 | case 3: double_data[3]= get_real(infile,0);break; /* y2-values */ |
||
406 | case 4: stroke_color=get_color(infile,1);/* name or hex color */ |
||
407 | decimals = find_number_of_digits(precision); |
||
7785 | schaersvoo | 408 | 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));\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); |
7614 | schaersvoo | 409 | click_cnt++;reset(); |
410 | break; |
||
411 | default: break; |
||
412 | } |
||
413 | } |
||
414 | break; |
||
415 | case LINE: |
||
416 | /* |
||
417 | @ line x1,y1,x2,y2,color |
||
418 | @ draw a line through points (x1:y1)--(x2:y2) in color 'color' |
||
419 | @ or use command 'curve color,formula' to draw the line <br />(uses more points to draw the line; is however better draggable) |
||
420 | @ may be set draggable / onclick |
||
421 | */ |
||
422 | for(i=0;i<5;i++){ |
||
423 | switch(i){ |
||
424 | case 0: double_data[10]= get_real(infile,0);break; /* x-values */ |
||
425 | case 1: double_data[11]= get_real(infile,0);break; /* y-values */ |
||
426 | case 2: double_data[12]= get_real(infile,0);break; /* x-values */ |
||
427 | case 3: double_data[13]= get_real(infile,0);break; /* y-values */ |
||
428 | case 4: stroke_color=get_color(infile,1);/* name or hex color */ |
||
429 | if( double_data[10] == double_data[12] ){ /* vertical line*/ |
||
430 | double_data[1] = xmin; |
||
431 | double_data[3] = ymax; |
||
432 | double_data[0] = double_data[10]; |
||
433 | double_data[2] = double_data[10]; |
||
434 | } |
||
435 | else |
||
436 | { |
||
437 | if( double_data[11] == double_data[13] ){ /* horizontal line */ |
||
438 | double_data[1] = double_data[11]; |
||
439 | double_data[3] = double_data[11]; |
||
440 | double_data[0] = ymin; |
||
441 | double_data[2] = xmax; |
||
442 | } |
||
443 | else |
||
444 | { |
||
445 | /* m */ |
||
446 | double_data[5] = (double_data[13] - double_data[11]) /(double_data[12] - double_data[10]); |
||
447 | /* q */ |
||
448 | double_data[6] = double_data[11] - ((double_data[13] - double_data[11]) /(double_data[12] - double_data[10]))*double_data[10]; |
||
7842 | bpr | 449 | |
7614 | schaersvoo | 450 | /*xmin,m*xmin+q,xmax,m*xmax+q*/ |
7842 | bpr | 451 | |
7614 | schaersvoo | 452 | double_data[1] = (double_data[5])*(xmin)+(double_data[6]); |
453 | double_data[3] = (double_data[5])*(xmax)+(double_data[6]); |
||
454 | double_data[0] = xmin; |
||
455 | double_data[2] = xmax; |
||
456 | } |
||
457 | } |
||
458 | decimals = find_number_of_digits(precision); |
||
7785 | schaersvoo | 459 | 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));\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); |
7614 | schaersvoo | 460 | click_cnt++;reset(); |
461 | break; |
||
462 | } |
||
463 | } |
||
464 | break; |
||
7842 | bpr | 465 | case HLINE: |
7614 | schaersvoo | 466 | /* |
467 | @ hline x,y,color |
||
468 | @ draw a horizontal line through point (x:y) in color 'color' |
||
469 | @ or use command 'curve color,formula' to draw the line <br />(uses more points to draw the line; is however better draggable) |
||
470 | @ may be set draggable / onclick |
||
471 | */ |
||
472 | for(i=0;i<3;i++) { |
||
473 | switch(i){ |
||
474 | case 0: double_data[0] = get_real(infile,0);break; /* x-values */ |
||
475 | case 1: double_data[1] = get_real(infile,0);break; /* y-values */ |
||
476 | case 2: stroke_color = get_color(infile,1);/* name or hex color */ |
||
477 | double_data[3] = double_data[1]; |
||
478 | decimals = find_number_of_digits(precision); |
||
7785 | schaersvoo | 479 | 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));\n",click_cnt,onclick,drag_type,decimals,xmin,decimals,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); |
7614 | schaersvoo | 480 | click_cnt++;reset(); |
481 | break; |
||
482 | } |
||
483 | } |
||
484 | break; |
||
485 | case VLINE: |
||
486 | /* |
||
487 | @ vline x,y,color |
||
488 | @ draw a vertical line through point (x:y) in color 'color' |
||
489 | @ may be set draggable / onclick |
||
490 | */ |
||
491 | for(i=0;i<3;i++) { |
||
492 | switch(i){ |
||
493 | case 0: double_data[0] = get_real(infile,0);break; /* x-values */ |
||
494 | case 1: double_data[1] = get_real(infile,0);break; /* y-values */ |
||
495 | case 2: stroke_color=get_color(infile,1);/* name or hex color */ |
||
496 | double_data[2] = double_data[0]; |
||
497 | decimals = find_number_of_digits(precision); |
||
7785 | schaersvoo | 498 | 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));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],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); |
7614 | schaersvoo | 499 | click_cnt++;reset(); |
500 | break; |
||
501 | } |
||
502 | } |
||
503 | break; |
||
504 | case SQUARE: |
||
505 | /* |
||
506 | @ square x,y,side,color |
||
507 | @ draw a square with left top corner (x:y) with side 'side' in color 'color' |
||
508 | @ use command 'fsquare x,y,side,color' for a filled square |
||
509 | @ use command/keyword 'filled' before command 'square x,y,side,color' |
||
510 | @ use command 'fillcolor color' before 'fsquare' to set the fill colour. |
||
511 | @ may be set draggable / onclick |
||
512 | */ |
||
513 | for(i=0;i<5;i++){ |
||
514 | switch(i){ |
||
515 | case 0:double_data[0] = get_real(infile,0);break; /* x-values */ |
||
516 | case 1:double_data[1] = get_real(infile,0);break; /* y-values */ |
||
517 | case 2:double_data[2] = get_real(infile,0); |
||
518 | double_data[3] = double_data[2]; |
||
519 | break; /* x-values */ |
||
520 | case 3:stroke_color = get_color(infile,1);/* name or hex color */ |
||
521 | decimals = find_number_of_digits(precision); |
||
7785 | schaersvoo | 522 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,1,[%.*f,%.*f],[%.*f,%.*f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s));\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,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix); |
7614 | schaersvoo | 523 | click_cnt++;reset(); |
524 | break; |
||
525 | } |
||
526 | } |
||
527 | break; |
||
528 | case ROUNDRECT: |
||
529 | /* |
||
530 | @ roundrect x1,y1,x2,y2,radius,color |
||
531 | @ use command 'froundrect x1,y1,x2,y2,radius,color' for a filled rectangle |
||
532 | @ use command/keyword 'filled' before command 'roundrect x1,y1,x2,y2,radius,color' |
||
533 | @ use command 'fillcolor color' before 'froundrect' to set the fill colour. |
||
534 | @ may be set draggable / onclick |
||
535 | */ |
||
536 | for(i=0;i<6;i++){ |
||
537 | switch(i){ |
||
538 | case 0:double_data[0] = get_real(infile,0);break; /* x-values */ |
||
539 | case 1:double_data[1] = get_real(infile,0);break; /* y-values */ |
||
540 | case 2:double_data[2] = get_real(infile,0);break; /* x-values */ |
||
541 | case 3:double_data[3] = get_real(infile,0);break; /* y-values */ |
||
542 | case 4:int_data[0] = (int) (get_real(infile,0));break; /* radius value in pixels */ |
||
543 | case 5:stroke_color = get_color(infile,1);/* name or hex color */ |
||
544 | decimals = find_number_of_digits(precision); |
||
7785 | schaersvoo | 545 | 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));\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); |
7614 | schaersvoo | 546 | click_cnt++;reset(); |
547 | break; |
||
548 | } |
||
549 | } |
||
550 | break; |
||
551 | case RECT: |
||
552 | /* |
||
553 | @ rect x1,y1,x2,y2,color |
||
554 | @ use command 'rect x1,y1,x2,y2,color' for a filled rectangle |
||
555 | @ use command/keyword 'filled' before command 'rect x1,y1,x2,y2,color' |
||
556 | @ use command 'fillcolor color' before 'frect' to set the fill colour. |
||
557 | @ may be set draggable / onclick |
||
558 | */ |
||
559 | for(i=0;i<5;i++){ |
||
560 | switch(i){ |
||
561 | case 0:double_data[0] = get_real(infile,0);break; /* x-values */ |
||
562 | case 1:double_data[1] = get_real(infile,0);break; /* y-values */ |
||
563 | case 2:double_data[2] = get_real(infile,0);break; /* x-values */ |
||
564 | case 3:double_data[3] = get_real(infile,0);break; /* y-values */ |
||
565 | case 4:stroke_color = get_color(infile,1);/* name or hex color */ |
||
566 | decimals = find_number_of_digits(precision); |
||
7785 | schaersvoo | 567 | 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));\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); |
7614 | schaersvoo | 568 | click_cnt++;reset(); |
569 | break; |
||
570 | } |
||
571 | } |
||
572 | break; |
||
573 | case POLYLINE: |
||
574 | /* |
||
575 | @ polyline color,x1,y1,x2,y2...x_n,y_n |
||
576 | @ may be set draggable / onclick |
||
577 | */ |
||
578 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
579 | i=0; |
||
580 | c=0; |
||
581 | while( ! done ){ /* get next item until EOL*/ |
||
582 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
583 | for( c = 0 ; c < 2; c++){ |
||
584 | if(c == 0 ){ |
||
585 | double_data[i] = get_real(infile,0); |
||
586 | i++; |
||
587 | } |
||
588 | else |
||
589 | { |
||
590 | double_data[i] = get_real(infile,1); |
||
591 | i++; |
||
592 | } |
||
593 | } |
||
594 | } |
||
595 | /* draw path : not closed & not filled */ |
||
596 | decimals = find_number_of_digits(precision); |
||
7785 | schaersvoo | 597 | 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));\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); |
7614 | schaersvoo | 598 | click_cnt++;reset(); |
599 | break; |
||
600 | case POLY: |
||
601 | /* |
||
602 | @ poly color,x1,y1,x2,y2...x_n,y_n |
||
603 | @ draw closed polygon |
||
604 | @ use command 'fpoly' to fill it, use command 'fillcolor color' to set the fill color |
||
605 | @ may be set draggable / onclick |
||
606 | */ |
||
607 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
608 | i=0; |
||
609 | c=0; |
||
610 | while( ! done ){ /* get next item until EOL*/ |
||
611 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
612 | for( c = 0 ; c < 2; c++){ |
||
613 | if(c == 0 ){ |
||
614 | double_data[i] = get_real(infile,0); |
||
615 | i++; |
||
616 | } |
||
617 | else |
||
618 | { |
||
619 | double_data[i] = get_real(infile,1); |
||
620 | i++; |
||
621 | } |
||
622 | } |
||
623 | } |
||
624 | /* draw path : closed & optional filled */ |
||
625 | decimals = find_number_of_digits(precision); |
||
7785 | schaersvoo | 626 | 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));\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); |
7614 | schaersvoo | 627 | click_cnt++;reset(); |
628 | break; |
||
7842 | bpr | 629 | case ARC: |
7614 | schaersvoo | 630 | /* |
631 | @ arc xc,yc,width,height,start_angle,end_angle,color |
||
632 | @ can not be set "onclick" or "drag xy" |
||
633 | @ attention: width == height == radius in pixels) |
||
634 | */ |
||
635 | for(i=0;i<7;i++){ |
||
636 | switch(i){ |
||
637 | case 0:double_data[0] = get_real(infile,0);break; /* x-values */ |
||
638 | case 1:double_data[1] = get_real(infile,0);break; /* y-values */ |
||
639 | case 2:int_data[0] = (int)(get_real(infile,0));break; /* width in pixels ! */ |
||
640 | case 3:int_data[1] = (int)(get_real(infile,0));break; /* height in pixels ! */ |
||
641 | case 4:double_data[2] = get_real(infile,0);break; /* start angle in degrees */ |
||
642 | case 5:double_data[3] = get_real(infile,0);break; /* end angle in degrees */ |
||
643 | case 6:stroke_color = get_color(infile,1);/* name or hex color */ |
||
644 | /* in Shape library: |
||
645 | x[0] = x[1] = xc |
||
646 | y[0] = y[1] = yc |
||
7842 | bpr | 647 | w[0] = w[1] = radius = width = height |
648 | h[0] = start_angle ; h[1] = end_engle |
||
7614 | schaersvoo | 649 | */ |
650 | decimals = find_number_of_digits(precision); |
||
7785 | schaersvoo | 651 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,12,[%.*f,%.*f],[%.*f,%.*f],[%d,%d],[%.*f,%.*f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[0],decimals,double_data[1],decimals,double_data[1],int_data[0],int_data[0],decimals,double_data[2],decimals,double_data[3],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); |
7614 | schaersvoo | 652 | reset(); |
653 | break; |
||
654 | } |
||
655 | } |
||
656 | break; |
||
657 | case ELLIPSE: |
||
658 | /* |
||
659 | @ ellipse xc,yc,radius_x,radius_y,color |
||
7842 | bpr | 660 | @ a ellipse with center xc/yc in x/y-range |
7614 | schaersvoo | 661 | @ radius_x and radius_y are in pixels |
662 | @ may be set draggable / onclick |
||
7842 | bpr | 663 | @ will shrink / expand on zoom out / zoom in |
7614 | schaersvoo | 664 | */ |
665 | for(i=0;i<5;i++){ |
||
666 | switch(i){ |
||
667 | case 0:double_data[0] = get_real(infile,0);break; /* x-values */ |
||
668 | case 1:double_data[1] = get_real(infile,0);break; /* y-values */ |
||
669 | case 2:double_data[2] = get_real(infile,0);break; /* rx -> px */ |
||
7842 | bpr | 670 | case 3:double_data[3] = get_real(infile,0);break; /* ry -> px */ |
7614 | schaersvoo | 671 | case 4:stroke_color = get_color(infile,1);/* name or hex color */ |
672 | decimals = find_number_of_digits(precision); |
||
7785 | schaersvoo | 673 | 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));\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); |
7614 | schaersvoo | 674 | click_cnt++;reset(); |
675 | break; |
||
676 | } |
||
677 | } |
||
678 | break; |
||
679 | case DASHTYPE: |
||
680 | /* |
||
681 | @ dashtype int ,int |
||
682 | @ When dashed is set, the objects will be drawn with this dashtyp |
||
683 | @ default value "dashtype 2,2" |
||
684 | */ |
||
685 | for(i=0;i<2;i++){ |
||
686 | switch(i){ |
||
687 | case 0 : dashtype[0] = (int) line_width*( get_real(infile,0)) ; break; |
||
688 | case 1 : dashtype[1] = (int) line_width*( get_real(infile,1)) ; break; |
||
689 | } |
||
690 | } |
||
691 | break; |
||
692 | case CIRCLE: |
||
693 | /* |
||
694 | @ circle xc,yc,width (2*r in pixels),color |
||
695 | @ use command 'fcircle xc,yc,d,color' or command 'filled' for a filled disk |
||
696 | @ use command 'fillcolor color' to set the fillcolor |
||
697 | @ may be set draggable / onclick |
||
7842 | bpr | 698 | @ will shrink / expand on zoom out / zoom in |
7614 | schaersvoo | 699 | */ |
700 | for(i=0;i<4;i++){ |
||
701 | switch(i){ |
||
702 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
703 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
704 | case 2: double_data[2] = px2x((get_real(infile,0))/2) - px2x(0);break; /* radius in 'dx' xrange*/ |
||
705 | case 3: stroke_color = get_color(infile,1);/* name or hex color */ |
||
706 | decimals = find_number_of_digits(precision); |
||
7785 | schaersvoo | 707 | 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));\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); |
7614 | schaersvoo | 708 | click_cnt++;reset(); |
709 | break; |
||
710 | } |
||
711 | } |
||
712 | break; |
||
713 | case RAYS: |
||
714 | /* |
||
715 | @ rays color,xc,yc,x1,y1,x2,y2,x3,y3...x_n,y_n |
||
716 | @ draw rays in color 'color' and center (xc:yc) |
||
7786 | schaersvoo | 717 | @ may be set draggable or onclick (every individual ray) |
7614 | schaersvoo | 718 | */ |
719 | stroke_color=get_color(infile,0); |
||
7786 | schaersvoo | 720 | fill_color = stroke_color; |
721 | double_data[0] = get_real(infile,0);/* xc */ |
||
722 | double_data[1] = get_real(infile,0);/* yc */ |
||
723 | i=2; |
||
724 | while( ! done ){ /* get next item until EOL*/ |
||
725 | if(i > MAX_INT - 1){canvas_error("in command rays to many points / rays in argument: repeat command multiple times to fit");} |
||
726 | if(i%2 == 0 ){ |
||
727 | double_data[i] = get_real(infile,0); /* x */ |
||
7614 | schaersvoo | 728 | } |
7786 | schaersvoo | 729 | else |
730 | { |
||
731 | double_data[i] = get_real(infile,1); /* y */ |
||
7614 | schaersvoo | 732 | } |
7786 | schaersvoo | 733 | fprintf(js_include_file,"/* double_data[%d] = %f */\n",i,double_data[i]); |
734 | i++; |
||
7614 | schaersvoo | 735 | } |
7842 | bpr | 736 | |
737 | if( i%2 != 0 ){canvas_error("in command rays: unpaired x or y value");} |
||
738 | decimals = find_number_of_digits(precision); |
||
7786 | schaersvoo | 739 | for(c=2; c<i;c = c+2){ |
7614 | schaersvoo | 740 | click_cnt++; |
7786 | schaersvoo | 741 | 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));\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); |
7614 | schaersvoo | 742 | } |
743 | reset(); |
||
744 | break; |
||
745 | case ARROW: |
||
746 | /* |
||
747 | @ arrow x1,y1,x2,y2,h,color |
||
748 | @ draw a single headed arrow/vector from (x1:y1) to (x2:y2)<br />with arrowhead size h in px and in color 'color' |
||
749 | @ use command 'linewidth int' to adjust thickness of the arrow |
||
750 | @ may be set draggable / onclick |
||
751 | */ |
||
752 | for(i=0;i<6;i++){ |
||
753 | switch(i){ |
||
754 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
755 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
756 | case 2: double_data[2] = get_real(infile,0);break; /* x */ |
||
757 | case 3: double_data[3] = get_real(infile,0);break; /* y */ |
||
758 | case 4: arrow_head = (int) get_real(infile,0);break;/* h */ |
||
759 | case 5: stroke_color = get_color(infile,1);/* name or hex color */ |
||
760 | decimals = find_number_of_digits(precision); |
||
7785 | schaersvoo | 761 | 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));\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); |
7614 | schaersvoo | 762 | click_cnt++; |
763 | reset(); |
||
764 | break; |
||
765 | } |
||
766 | } |
||
767 | break; |
||
768 | case ARROW2: |
||
769 | /* |
||
770 | @ arrow2 x1,y1,x2,y2,h,color |
||
771 | @ draw a double headed arrow/vector from (x1:y1) to (x2:y2)<br />with arrowhead size h in px and in color 'color' |
||
772 | @ use command 'arrowhead int' to adjust the arrow head size |
||
773 | @ use command 'linewidth int' to adjust thickness of the arrow |
||
774 | @ may be set draggable / onclick |
||
775 | */ |
||
776 | for(i=0;i<6;i++){ |
||
777 | switch(i){ |
||
778 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
779 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
780 | case 2: double_data[2] = get_real(infile,0);break; /* x */ |
||
781 | case 3: double_data[3] = get_real(infile,0);break; /* y */ |
||
782 | case 4: arrow_head = (int) get_real(infile,0);break;/* h */ |
||
783 | case 5: stroke_color = get_color(infile,1);/* name or hex color */ |
||
784 | decimals = find_number_of_digits(precision); |
||
7785 | schaersvoo | 785 | 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));\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); |
7614 | schaersvoo | 786 | click_cnt++;reset(); |
787 | break; |
||
788 | } |
||
789 | } |
||
790 | break; |
||
7842 | bpr | 791 | case PARALLEL: |
7614 | schaersvoo | 792 | /* |
793 | @ parallel x1,y1,x2,y2,dx,dy,n,[colorname or #hexcolor] |
||
7842 | bpr | 794 | @ can not be set "onclick" or "drag xy" |
7614 | schaersvoo | 795 | */ |
796 | for( i = 0;i < 8; i++ ){ |
||
797 | switch(i){ |
||
798 | case 0: double_data[0] = get_real(infile,0);break; /* x1-values -> x-pixels*/ |
||
799 | case 1: double_data[1] = get_real(infile,0);break; /* y1-values -> y-pixels*/ |
||
800 | case 2: double_data[2] = get_real(infile,0);break; /* x2-values -> x-pixels*/ |
||
801 | case 3: double_data[3] = get_real(infile,0);break; /* y2-values -> y-pixels*/ |
||
802 | case 4: double_data[4] = xmin + get_real(infile,0);break; /* xv -> x-pixels */ |
||
803 | case 5: double_data[5] = ymax + get_real(infile,0);break; /* yv -> y-pixels */ |
||
804 | case 6: int_data[0] = (int) (get_real(infile,0));break; /* n */ |
||
805 | case 7: stroke_color=get_color(infile,1);/* name or hex color */ |
||
806 | decimals = find_number_of_digits(precision); |
||
7785 | schaersvoo | 807 | 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));\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); |
7614 | schaersvoo | 808 | click_cnt++;reset(); |
809 | break; |
||
810 | default: break; |
||
811 | } |
||
812 | } |
||
813 | break; |
||
814 | case TRIANGLE: |
||
815 | /* |
||
816 | @triangle x1,y1,x2,y2,x3,y3,color |
||
817 | @may be set draggable / onclic |
||
818 | */ |
||
819 | for(i=0;i<7;i++){ |
||
820 | switch(i){ |
||
821 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
822 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
823 | case 2: double_data[2] = get_real(infile,0);break; /* x */ |
||
824 | case 3: double_data[3] = get_real(infile,0);break; /* y */ |
||
825 | case 4: double_data[4] = get_real(infile,0);break; /* x */ |
||
826 | case 5: double_data[5] = get_real(infile,0);break; /* y */ |
||
827 | case 6: stroke_color = get_color(infile,1);/* name or hex color */ |
||
828 | decimals = find_number_of_digits(precision); |
||
7785 | schaersvoo | 829 | 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));\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); |
7614 | schaersvoo | 830 | click_cnt++;reset(); |
831 | break; |
||
832 | default: break; |
||
833 | } |
||
834 | } |
||
835 | break; |
||
836 | case LATTICE: |
||
837 | /* |
||
838 | @lattice x0,y0,xv1,yv1,xv2,yv2,n1,n2,color |
||
7842 | bpr | 839 | @can not be set "onclick" or "drag xy" |
7614 | schaersvoo | 840 | */ |
841 | if( js_function[DRAW_LATTICE] != 1 ){ js_function[DRAW_LATTICE] = 1;} |
||
842 | for( i = 0; i<9; i++){ |
||
843 | switch(i){ |
||
844 | case 0: int_data[0] = x2px(get_real(infile,0));break; /* x0-values -> x-pixels*/ |
||
845 | case 1: int_data[1] = y2px(get_real(infile,0));break; /* y0-values -> y-pixels*/ |
||
846 | case 2: int_data[2] = (int) (get_real(infile,0));break; /* x1-values -> x-pixels*/ |
||
847 | case 3: int_data[3] = (int) (get_real(infile,0));break; /* y1-values -> y-pixels*/ |
||
848 | case 4: int_data[4] = (int) (get_real(infile,0));break; /* x2-values -> x-pixels*/ |
||
849 | case 5: int_data[5] = (int) (get_real(infile,0));break; /* y2-values -> y-pixels*/ |
||
850 | case 6: int_data[6] = (int) (get_real(infile,0));break; /* n1-values */ |
||
851 | case 7: int_data[7] = (int) (get_real(infile,0));break; /* n2-values */ |
||
852 | case 8: stroke_color=get_color(infile,1); |
||
853 | decimals = find_number_of_digits(precision); |
||
854 | string_length = snprintf(NULL,0,"draw_lattice(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%.2f,%d,[%d,%d]);",STATIC_CANVAS,line_width,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],fill_color,fill_opacity,stroke_color,stroke_opacity,use_rotate,angle,use_translate,translate_x,translate_y); |
||
855 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
856 | snprintf(tmp_buffer,string_length,"draw_lattice(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%.2f,%d,[%d,%d]);",STATIC_CANVAS,line_width,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],fill_color,fill_opacity,stroke_color,stroke_opacity,use_rotate,angle,use_translate,translate_x,translate_y); |
||
857 | add_to_buffer(tmp_buffer); |
||
858 | break; |
||
859 | default:break; |
||
860 | } |
||
861 | } |
||
862 | reset(); |
||
863 | break; |
||
864 | case SNAPTOGRID: |
||
865 | /* |
||
866 | @ snaptogrid |
||
867 | @ keyword (no arguments rewquired) needs to be defined before command 'userdraw' and after command 'grid' |
||
868 | @ in case of userdraw the drawn points will snap to xmajor / ymajor grid |
||
7784 | schaersvoo | 869 | @ if xminor / yminor is defined, 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 /> |
7614 | schaersvoo | 870 | */ |
7784 | schaersvoo | 871 | fprintf(js_include_file,"\nx_use_snap_to_grid = 1;y_use_snap_to_grid = 1;var snap_x = 1;var snap_y = 1;function snap_to_x(x){return x2px(snap_x*(Math.round((px2x(x))/snap_x)));};function snap_to_y(y){return y2px(snap_y*(Math.round((px2y(y))/snap_y)));};\n"); |
7614 | schaersvoo | 872 | break; |
7784 | schaersvoo | 873 | case XSNAPTOGRID: |
874 | /* |
||
875 | @ xsnaptogrid |
||
876 | @ keyword (no arguments rewquired) needs to be defined before command 'userdraw' and after command 'grid' |
||
877 | @ in case of userdraw the drawn points will snap to xmajor grid |
||
878 | @ if xminor / yminor is defined, 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 /> |
||
879 | */ |
||
880 | fprintf(js_include_file,"\nx_use_snap_to_grid = 1;var snap_x = 1;if (typeof snap_y === 'undefined') { var snap_y = 1;};var snap_y = 1;function snap_to_x(x){return x2px(snap_x*(Math.round((px2x(x))/snap_x)));};\n"); |
||
881 | break; |
||
882 | case YSNAPTOGRID: |
||
883 | /* |
||
884 | @ ysnaptogrid |
||
885 | @ keyword (no arguments rewquired) needs to be defined before command 'userdraw' and after command 'grid' |
||
886 | @ in case of userdraw the drawn points will snap to ymajor grid |
||
887 | @ if xminor / yminor is defined, 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 /> |
||
888 | */ |
||
889 | fprintf(js_include_file,"\ny_use_snap_to_grid = 1;if (typeof snap_x === 'undefined') { var snap_x = 1;};var snap_y = 1;\nfunction snap_to_y(y){return y2px(snap_y*(Math.round((px2y(y))/snap_y)));};\n"); |
||
890 | break; |
||
7663 | schaersvoo | 891 | case USERTEXTAREA_XY: |
892 | /* |
||
893 | @ usertextarea_xy |
||
7842 | bpr | 894 | @ keyword |
7663 | schaersvoo | 895 | @ to be used in combination with command "userdraw object_type,color" wherein object_type is only segment / polyline for the time being... |
7842 | bpr | 896 | @ if set two textareas are added to the document<br />(one for x-values , one for y-values) |
7663 | schaersvoo | 897 | @ the student may use this as correction for (x:y) on a drawing (or to draw without mouse, using just the coordinates) |
898 | @ can not be combined with command "intooltip tiptext" <br />note: the 'tooltip div element' is used for placing inputfields |
||
7842 | bpr | 899 | @ user drawings will not zoom on zooming (or pan on panning) |
7663 | schaersvoo | 900 | */ |
7749 | schaersvoo | 901 | if(use_tooltip == TRUE){canvas_error("usertextarea_xy can not be combined with intooltip command");} |
902 | if( use_input_xy == 1 ){canvas_error("usertextarea_xy can not be combined with userinput_xy command");} |
||
903 | fprintf(js_include_file,"function safe_eval(exp){if(exp.indexOf('^') != -1){exp = exp.replace(/\\s*(.*)\\^\\s*(.*)/ig, \"pow($1, $2)\");};var reg = /(?:[a-z$_][a-z0-9$_]*)|(?:[;={}\\[\\]\"'!&<>^\\\\?:])/ig;var valid = true;exp = exp.replace(reg,function($0){if (Math.hasOwnProperty($0)){return \"Math.\"+$0;}else{valid = false;};});if (!valid){alert(\"hmmm \"+exp+\" ?\"); exp = null;}else{try { exp = eval(exp); } catch (e) {alert(\"Invalid arithmetic expression\"); exp = null;};};return exp;};"); |
||
904 | use_input_xy = 2; |
||
905 | break; |
||
7652 | schaersvoo | 906 | case USERINPUT_XY: |
907 | /* |
||
908 | @ userinput_xy |
||
7842 | bpr | 909 | @ keyword |
7652 | schaersvoo | 910 | @ to be used in combination with command "userdraw object_type,color" |
7842 | bpr | 911 | @ 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) |
7652 | schaersvoo | 912 | @ the student may use this as correction for (x:y) on a drawing (or to draw without mouse, using just the coordinates) |
7749 | schaersvoo | 913 | @ 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. |
7652 | schaersvoo | 914 | @ can not be combined with command "intooltip tiptext" <br />note: the 'tooltip div element' is used for placing inputfields |
7842 | bpr | 915 | @ user drawings will not zoom on zooming (or pan on panning) |
7652 | schaersvoo | 916 | */ |
7749 | schaersvoo | 917 | if(use_tooltip == TRUE){canvas_error("userinput_xy can not be combined with intooltip command");} |
918 | /* add simple eval check to avoid code injection with unprotected eval(string) */ |
||
919 | fprintf(js_include_file,"function safe_eval(exp){if(exp.indexOf('^') != -1){exp = exp.replace(/\\s*(.*)\\^\\s*(.*)/ig, \"pow($1, $2)\");};var reg = /(?:[a-z$_][a-z0-9$_]*)|(?:[;={}\\[\\]\"'!&<>^\\\\?:])/ig;var valid = true;exp = exp.replace(reg,function($0){if (Math.hasOwnProperty($0)){return \"Math.\"+$0;}else{valid = false;};});if (!valid){alert(\"hmmm \"+exp+\" ?\"); exp = null;}else{try { exp = eval(exp); } catch (e) {alert(\"Invalid arithmetic expression\"); exp = null;};};return exp;};"); |
||
920 | use_input_xy = 1; |
||
921 | break; |
||
7614 | schaersvoo | 922 | case USERDRAW: |
923 | /* |
||
924 | @ userdraw object_type,color |
||
7663 | schaersvoo | 925 | @ implemented object_type: <ul><li>point</li><li>points</li><li>crosshair</li><li>crosshairs</li><li>line</li><li>lines</li><li>segment</li><li>segments</li><li>polyline</li><li>circle</li><li>circles</li><li>arrow</li><li>arrows</li><li>triangle</li><li>polygon</li><li>poly[3-9]</li><li>rect</li><li>roundrect</li><li>rects</li><li>roundrects</li><li>freehandline</li><li>freehandlines</li><li>path</li><li>paths</li><li>text</li></ul> |
7614 | schaersvoo | 926 | @ 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) |
927 | @ note: object_type text: Any string or multiple strings may be placed anywhere on the canvas.<br />while typing the background of every typed char will be lightblue..."backspace / delete / esc" will remove typed text.<br />You will need to hit "enter" to add the text to the array "userdraw_txt()" : lightblue background will disappear<br />Placing the cursor somewhere on a typed text and hitting "delete/backspace/esc" , a confirm will popup asking to delete the selected text.This text will be removed from the "userdraw_txt()" answer array.<br />Use commands 'fontsize' and 'fontfamily' to control the text appearance |
||
7842 | bpr | 928 | @ note: object_type polygone: Will be finished (the object is closed) when clicked on the first point of the polygone again. |
7614 | schaersvoo | 929 | @ note: all objects will be removed -after a javascript confirm box- when clicked on an object point with middle or right mouse butten (e.g. event.which != 1 : all buttons but left) |
930 | @ use command "filled", "opacity int,int" and "fillcolor color" to trigger coloured filling of fillable objects |
||
7842 | bpr | 931 | @ use command "dashed" and/or "dashtype int,int" to trigger dashing |
7614 | schaersvoo | 932 | @ use command "replyformat int" to control / adjust output formatting of javascript function read_canvas(); |
933 | @ may be combined with onclick or drag xy of other components of flyscript objects (although not very usefull...) |
||
7842 | bpr | 934 | @ may be combined with keyword 'userinput_xy' or |
7653 | schaersvoo | 935 | @ 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.! |
7614 | schaersvoo | 936 | */ |
937 | if( use_userdraw == TRUE ){ /* only one object type may be drawn*/ |
||
938 | canvas_error("Only one userdraw primitive may be used: read documentation !!"); |
||
939 | } |
||
940 | use_userdraw = TRUE; |
||
7653 | schaersvoo | 941 | fprintf(js_include_file,"<!-- begin userdraw mouse events -->\nvar userdraw_x = new Array();var userdraw_y = new Array();var userdraw_radius = new Array();var xy_cnt=0;var canvas_userdraw = create_canvas%d(%d,xsize,ysize);var context_userdraw = canvas_userdraw.getContext(\"2d\");var use_dashed = %d;if(use_dashed == 1){if( context_userdraw.setLineDash ){context_userdraw.setLineDash([%d,%d]);}else{if(context_userdraw.mozDash){context_userdraw.mozDash = [%d,%d];};};};if(wims_status != \"done\"){canvas_div.addEventListener(\"mousedown\",user_draw,false);canvas_div.addEventListener(\"mousemove\",user_drag,false);canvas_div.addEventListener(\"touchstart\",user_draw,false);canvas_div.addEventListener(\"touchmove\",user_drag,false);}\n<!-- end userdraw mouse events -->",canvas_root_id,DRAW_CANVAS,use_dashed,dashtype[0],dashtype[1],dashtype[0],dashtype[1]); |
7614 | schaersvoo | 942 | draw_type = get_string_argument(infile,0); |
943 | stroke_color = get_color(infile,1); |
||
944 | if( strcmp(draw_type,"point") == 0 ){ |
||
945 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
946 | if(reply_format < 1 ){reply_format = 8;} |
||
947 | /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */ |
||
7842 | bpr | 948 | if(use_input_xy == 1){ |
7652 | schaersvoo | 949 | add_input_circle(js_include_file,1,1); |
950 | add_input_xy(js_include_file,canvas_root_id); |
||
951 | } |
||
7614 | schaersvoo | 952 | 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); |
953 | } |
||
954 | else |
||
955 | if( strcmp(draw_type,"points") == 0 ){ |
||
956 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
957 | if(reply_format < 1 ){reply_format = 8;} |
||
958 | /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */ |
||
7842 | bpr | 959 | if(use_input_xy == 1){ |
7652 | schaersvoo | 960 | add_input_circle(js_include_file,1,2); |
961 | add_input_xy(js_include_file,canvas_root_id); |
||
962 | } |
||
7614 | schaersvoo | 963 | 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); |
964 | } |
||
965 | else |
||
966 | if( strcmp(draw_type,"segment") == 0 ){ |
||
967 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
968 | if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;} |
||
969 | if(reply_format < 1){reply_format = 11;} |
||
7842 | bpr | 970 | if(use_input_xy == 1){ |
7652 | schaersvoo | 971 | add_input_segment(js_include_file,1); |
972 | add_input_x1y1x2y2(js_include_file,canvas_root_id); |
||
973 | } |
||
7614 | schaersvoo | 974 | add_js_segments(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]); |
975 | } |
||
976 | else |
||
7663 | schaersvoo | 977 | if( strcmp(draw_type,"polyline") == 0 ){ |
978 | if( js_function[DRAW_POLYLINE] != 1 ){ js_function[DRAW_POLYLINE] = 1;} |
||
7782 | schaersvoo | 979 | if(reply_format < 1){reply_format = 23;} |
7780 | schaersvoo | 980 | if( use_input_xy == 1 ){ |
981 | add_input_polyline(js_include_file); |
||
982 | add_input_xy(js_include_file,canvas_root_id); |
||
7663 | schaersvoo | 983 | } |
984 | add_js_polyline(js_include_file,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]); |
||
985 | } |
||
986 | else |
||
7614 | schaersvoo | 987 | if( strcmp(draw_type,"segments") == 0 ){ |
988 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
989 | if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;} |
||
990 | if(reply_format < 1){reply_format = 11;} |
||
7842 | bpr | 991 | if(use_input_xy == 1){ |
7652 | schaersvoo | 992 | add_input_segment(js_include_file,2); |
993 | add_input_x1y1x2y2(js_include_file,canvas_root_id); |
||
994 | } |
||
7614 | schaersvoo | 995 | add_js_segments(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]); |
996 | } |
||
997 | else |
||
998 | if( strcmp(draw_type,"circle") == 0 ){ |
||
999 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
1000 | if(reply_format < 1){reply_format = 10;} |
||
1001 | /* 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n in x/y-range */ |
||
7842 | bpr | 1002 | if(use_input_xy == 1){ |
7652 | schaersvoo | 1003 | add_input_circle(js_include_file,2,1); |
1004 | add_input_xyr(js_include_file,canvas_root_id); |
||
1005 | } |
||
7614 | schaersvoo | 1006 | 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]); |
1007 | } |
||
1008 | else |
||
1009 | if( strcmp(draw_type,"circles") == 0 ){ |
||
1010 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
1011 | if(reply_format < 1){reply_format = 10;} |
||
1012 | /* 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n in x/y-range */ |
||
1013 | 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]); |
||
7842 | bpr | 1014 | if(use_input_xy == 1){ |
7652 | schaersvoo | 1015 | add_input_circle(js_include_file,2,2); |
1016 | add_input_xyr(js_include_file,canvas_root_id); |
||
1017 | } |
||
7614 | schaersvoo | 1018 | } |
1019 | else |
||
1020 | if(strcmp(draw_type,"crosshair") == 0 ){ |
||
1021 | if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;} |
||
1022 | if(reply_format < 1){reply_format = 8;} |
||
1023 | /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */ |
||
1024 | add_js_crosshairs(js_include_file,1,draw_type,line_width,crosshair_size ,stroke_color,stroke_opacity); |
||
7842 | bpr | 1025 | if(use_input_xy == 1){ |
7654 | schaersvoo | 1026 | add_input_crosshair(js_include_file,1); |
1027 | add_input_xy(js_include_file,canvas_root_id); |
||
1028 | } |
||
7614 | schaersvoo | 1029 | } |
1030 | else |
||
1031 | if(strcmp(draw_type,"crosshairs") == 0 ){ |
||
1032 | if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;} |
||
1033 | if(reply_format < 1){reply_format = 8;} |
||
1034 | /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */ |
||
1035 | add_js_crosshairs(js_include_file,2,draw_type,line_width,crosshair_size ,stroke_color,stroke_opacity); |
||
7842 | bpr | 1036 | if(use_input_xy == 1){ |
7654 | schaersvoo | 1037 | add_input_crosshair(js_include_file,2); |
1038 | add_input_xy(js_include_file,canvas_root_id); |
||
1039 | } |
||
7614 | schaersvoo | 1040 | } |
1041 | else |
||
1042 | if(strcmp(draw_type,"freehandline") == 0 ){ |
||
1043 | if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;} |
||
1044 | if(reply_format < 1){reply_format = 6;} |
||
7842 | bpr | 1045 | 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 | 1046 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 1047 | } |
1048 | else |
||
1049 | if(strcmp(draw_type,"freehandlines") == 0 ){ |
||
1050 | if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;} |
||
1051 | if(reply_format < 1){reply_format = 6;} |
||
7842 | bpr | 1052 | 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 | 1053 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 1054 | } |
1055 | else |
||
1056 | if(strcmp(draw_type,"path") == 0 ){ |
||
1057 | if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;} |
||
1058 | if(reply_format < 1){reply_format = 6;} |
||
7842 | bpr | 1059 | 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 | 1060 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 1061 | } |
1062 | else |
||
1063 | if(strcmp(draw_type,"paths") == 0 ){ |
||
1064 | if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;} |
||
1065 | if(reply_format < 1){reply_format = 6;} |
||
7842 | bpr | 1066 | 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 | 1067 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 1068 | } |
1069 | else |
||
1070 | if(strcmp(draw_type,"arrows") == 0 ){ |
||
1071 | if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;} |
||
1072 | if(reply_format < 1){reply_format = 11;} |
||
1073 | add_js_arrows(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head); |
||
7842 | bpr | 1074 | if(use_input_xy == 1){ |
7654 | schaersvoo | 1075 | add_input_arrow(js_include_file,2); |
1076 | add_input_x1y1x2y2(js_include_file,canvas_root_id); |
||
1077 | } |
||
7614 | schaersvoo | 1078 | } |
1079 | else |
||
1080 | if(strcmp(draw_type,"arrow") == 0 ){ |
||
1081 | if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;} |
||
1082 | if(reply_format < 1){reply_format = 11;} |
||
1083 | add_js_arrows(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head); |
||
7842 | bpr | 1084 | if(use_input_xy == 1){ |
7654 | schaersvoo | 1085 | add_input_arrow(js_include_file,1); |
1086 | add_input_x1y1x2y2(js_include_file,canvas_root_id); |
||
1087 | } |
||
7614 | schaersvoo | 1088 | } |
1089 | else |
||
1090 | if(strcmp(draw_type,"polygon") == 0){ |
||
1091 | if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;} |
||
1092 | if(reply_format < 1){reply_format = 2;} |
||
1093 | 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]); |
||
7780 | schaersvoo | 1094 | if( use_input_xy == 2 ){ |
1095 | add_textarea_polygon(js_include_file); |
||
1096 | add_textarea_xy(js_include_file,canvas_root_id); |
||
7746 | schaersvoo | 1097 | } |
7614 | schaersvoo | 1098 | } |
7842 | bpr | 1099 | else |
7614 | schaersvoo | 1100 | if(strncmp(draw_type,"poly",4) == 0){ |
1101 | if(strlen(draw_type) < 5){canvas_error("use command \"userdraw poly[3-9],color\" eg userdraw poly6,blue");} |
||
1102 | if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;} |
||
1103 | if(reply_format < 1){reply_format = 2;} |
||
1104 | 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 | 1105 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 1106 | } |
7842 | bpr | 1107 | else |
7614 | schaersvoo | 1108 | if(strcmp(draw_type,"triangle") == 0){ |
1109 | if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;} |
||
1110 | if(reply_format < 1){reply_format = 2;} |
||
1111 | 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 | 1112 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 1113 | } |
7842 | bpr | 1114 | else |
7614 | schaersvoo | 1115 | if( strcmp(draw_type,"line") == 0 ){ |
1116 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
1117 | if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;} |
||
1118 | if(reply_format < 1){reply_format = 11;} |
||
1119 | add_js_lines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]); |
||
7747 | schaersvoo | 1120 | if( use_input_xy == 1 ){ |
7780 | schaersvoo | 1121 | add_input_line(js_include_file,1); |
7747 | schaersvoo | 1122 | add_input_x1y1x2y2(js_include_file,canvas_root_id); |
1123 | } |
||
7614 | schaersvoo | 1124 | } |
1125 | else |
||
1126 | if( strcmp(draw_type,"lines") == 0 ){ |
||
1127 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
1128 | if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;} |
||
1129 | if(reply_format < 1){reply_format = 11;} |
||
1130 | add_js_lines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]); |
||
7747 | schaersvoo | 1131 | if( use_input_xy == 1 ){ |
7780 | schaersvoo | 1132 | add_input_line(js_include_file,2); |
7747 | schaersvoo | 1133 | add_input_x1y1x2y2(js_include_file,canvas_root_id); |
7746 | schaersvoo | 1134 | } |
7614 | schaersvoo | 1135 | } |
1136 | else |
||
1137 | if( strcmp(draw_type,"rects") == 0){ |
||
1138 | if( js_function[DRAW_RECTS] != 1 ){ js_function[DRAW_RECTS] = 1;} |
||
1139 | if(reply_format < 1){reply_format = 2;} |
||
1140 | 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 | 1141 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 1142 | } |
7842 | bpr | 1143 | else |
7614 | schaersvoo | 1144 | if( strcmp(draw_type,"roundrects") == 0){ |
1145 | if( js_function[DRAW_ROUNDRECTS] != 1 ){ js_function[DRAW_ROUNDRECTS] = 1;} |
||
1146 | if(reply_format < 1){reply_format = 2;} |
||
1147 | 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 | 1148 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 1149 | } |
7842 | bpr | 1150 | else |
7614 | schaersvoo | 1151 | if( strcmp(draw_type,"rect") == 0){ |
1152 | if( js_function[DRAW_RECTS] != 1 ){ js_function[DRAW_RECTS] = 1;} |
||
1153 | if(reply_format < 1){reply_format = 2;} |
||
1154 | 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 | 1155 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 1156 | } |
7842 | bpr | 1157 | else |
7614 | schaersvoo | 1158 | if( strcmp(draw_type,"roundrect") == 0){ |
1159 | if( js_function[DRAW_ROUNDRECTS] != 1 ){ js_function[DRAW_ROUNDRECTS] = 1;} |
||
1160 | if(reply_format < 1){reply_format = 2;} |
||
1161 | 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 | 1162 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 1163 | } |
1164 | else |
||
1165 | if( strcmp(draw_type,"text") == 0){ |
||
7842 | bpr | 1166 | if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;} |
7614 | schaersvoo | 1167 | if(reply_format < 1){reply_format = 17;} |
1168 | add_js_text(js_include_file,canvas_root_id,font_size,font_family,font_color,stroke_opacity,use_rotate,angle,use_translate,translate_x,translate_y); |
||
7652 | schaersvoo | 1169 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 1170 | } |
7842 | bpr | 1171 | else |
7614 | schaersvoo | 1172 | { |
1173 | canvas_error("unknown drawtype or typo? "); |
||
1174 | } |
||
1175 | reset(); |
||
1176 | break; |
||
1177 | case PLOTSTEPS: |
||
1178 | /* |
||
1179 | @ plotsteps a_number |
||
1180 | @ default 150 |
||
1181 | @ use with care ! |
||
1182 | */ |
||
1183 | plot_steps = (int) (get_real(infile,1)); |
||
1184 | break; |
||
1185 | case FONTSIZE: |
||
1186 | /* |
||
1187 | @fontsize font_size |
||
1188 | @default value 12 |
||
1189 | */ |
||
1190 | font_size = (int) (get_real(infile,1)); |
||
1191 | break; |
||
1192 | case FONTCOLOR: |
||
1193 | /* |
||
1194 | @fontcolor color |
||
1195 | @color: hexcolor or colorname |
||
1196 | @default: black |
||
1197 | @example usage: x/y-axis text |
||
1198 | */ |
||
1199 | font_color = get_color(infile,1); |
||
1200 | break; |
||
1201 | case ANIMATE: |
||
1202 | /* |
||
1203 | @animate type |
||
1204 | @type may be "point" (nothing else , yet...) |
||
1205 | @the point is a filled rectangle ; adjust colour with command 'fillcolor colorname/hexnumber' |
||
1206 | @will animate a point on the next plot/curve command |
||
1207 | @the curve will not be draw |
||
1208 | @moves repeatedly from xmin to xmax |
||
1209 | */ |
||
1210 | if( strstr(get_string(infile,1),"point") != 0 ){animation_type = 15;}else{canvas_error("the only animation type (for now) is \"point\"...");} |
||
1211 | break; |
||
7788 | schaersvoo | 1212 | case LEVELCURVE: |
1213 | /* |
||
1214 | @levelcurve color,expression in x/y,l1,l2,... |
||
7792 | schaersvoo | 1215 | @draws very primitive level curves for expression, with levels l1,l2,l3,...,l_n |
1216 | @the quality is <b>not to be compared</b> with the Flydraw levelcurve. <br />(choose flydraw if you want quality...) |
||
1217 | @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 |
||
1218 | @note : the arrays for holding the javascript data are limited in size |
||
1219 | @note : reduce image size if javascript data arrays get overloaded<br />(command 'plotsteps int' will not control the data size of the plot...) |
||
7788 | schaersvoo | 1220 | */ |
7792 | schaersvoo | 1221 | fill_color = get_color(infile,0); |
7788 | schaersvoo | 1222 | char *fun1 = get_string_argument(infile,0); |
1223 | if( strlen(fun1) == 0 ){canvas_error("function is NOT OK !");} |
||
1224 | i = 0; |
||
1225 | done = FALSE; |
||
1226 | while( !done ){ |
||
1227 | double_data[i] = get_real(infile,1); |
||
1228 | i++; |
||
1229 | } |
||
1230 | for(c = 0 ; c < i; c++){ |
||
1231 | 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));\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); |
||
1232 | click_cnt++; |
||
1233 | } |
||
1234 | reset(); |
||
1235 | break; |
||
7823 | schaersvoo | 1236 | case TRACE_JSMATH: |
1237 | /* |
||
1238 | @trace_jsmath some_javascript_math_function |
||
1239 | @will use a crosshair to trace the jsmath curve |
||
1240 | @two inputfields will display the current x/y-values (approximated) |
||
7842 | bpr | 1241 | @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 |
7823 | schaersvoo | 1242 | @use linewidth,strokecolor,crosshairsize to adjust the corsshair. |
1243 | @example: trace_jsmath Math.pow(x,2)+4*x+16 |
||
1244 | @example: trace_jsmath Math.sin(Math.pow(x,Math.Pi))+Math.sqrt(x) |
||
1245 | @no check is done on the validity of your function and/or syntax<br />use error console to debug any errors... |
||
7833 | schaersvoo | 1246 | @can not be combined with commands 'mouse color,fontsize' and 'intooltip tip_text' |
7823 | schaersvoo | 1247 | */ |
1248 | if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;} |
||
7833 | schaersvoo | 1249 | if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;} |
7823 | schaersvoo | 1250 | 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); |
1251 | break; |
||
1252 | case JSMATH: |
||
1253 | /* |
||
1254 | @jsmath some_javascript_math_function |
||
1255 | @will calculate an y-value from a userinput x-value and draws a crosshairs on these coordinates. |
||
7842 | bpr | 1256 | @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 |
7823 | schaersvoo | 1257 | @example: jsmath Math.pow(x,2)+4*x+16 |
1258 | @example: jsmath Math.sin(Math.pow(x,Math.Pi))+Math.sqrt(x) |
||
1259 | @no check is done on the validity of your function and/or syntax<br />use error console to debug any errors... |
||
7833 | schaersvoo | 1260 | @can not be combined with commands 'mouse color,fontsize' and 'intooltip tip_text' |
7823 | schaersvoo | 1261 | */ |
1262 | if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;} |
||
1263 | add_calc_y(js_include_file,canvas_root_id,get_string(infile,1)); |
||
1264 | break; |
||
7614 | schaersvoo | 1265 | case CURVE: |
1266 | /* |
||
1267 | @curve color,formula(x) |
||
1268 | @plot color,formula(x) |
||
1269 | @use command trange before command curve / plot (trange -pi,pi)<br />curve color,formula1(t),formula2(t) |
||
1270 | @use command "precision" to increase the number of digits of the plotted points |
||
1271 | @use command "plotsteps" to increase / decrease the amount of plotted points (default 150) |
||
1272 | @may be set draggable / onclick |
||
1273 | */ |
||
1274 | if( use_parametric == TRUE ){ /* parametric color,fun1(t),fun2(t)*/ |
||
1275 | use_parametric = FALSE; |
||
1276 | stroke_color = get_color(infile,0); |
||
1277 | char *fun1 = get_string_argument(infile,0); |
||
1278 | char *fun2 = get_string_argument(infile,1); |
||
1279 | if( strlen(fun1) == 0 || strlen(fun2) == 0 ){canvas_error("parametric functions are NOT OK !");} |
||
7785 | schaersvoo | 1280 | 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));\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); |
7614 | schaersvoo | 1281 | click_cnt++; |
1282 | } |
||
1283 | else |
||
1284 | { |
||
1285 | stroke_color = get_color(infile,0); |
||
1286 | char *fun1 = get_string_argument(infile,1); |
||
7842 | bpr | 1287 | if( strlen(fun1) == 0 ){canvas_error("function is NOT OK !");} |
7785 | schaersvoo | 1288 | 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));\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); |
7614 | schaersvoo | 1289 | click_cnt++; |
1290 | } |
||
7788 | schaersvoo | 1291 | animation_type = 9;/* reset to curve plotting without animation */ |
7614 | schaersvoo | 1292 | reset(); |
1293 | break; |
||
1294 | case FLY_TEXT: |
||
1295 | /* |
||
1296 | @ text fontcolor,x,y,font,text_string |
||
1297 | @ font may be described by keywords : giant,huge,normal,small,tiny |
||
7842 | bpr | 1298 | @ use command 'fontsize' to increase base fontsize for the keywords |
7614 | schaersvoo | 1299 | @ may be set "onclick" or "drag xy" |
1300 | @ backwards compatible with flydraw |
||
1301 | @ unicode supported: text red,0,0,huge,\\u2232 |
||
1302 | @ use command 'string' and 'fontfamily' for a more fine grained control over html5 canvas text element |
||
1303 | @ 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 rested 'fontfamily' to something lke 'fontfamily Ariel' before the old flydraw commands. |
||
1304 | */ |
||
1305 | for(i = 0; i < 5 ;i++){ |
||
1306 | switch(i){ |
||
1307 | case 0: stroke_color = get_color(infile,0);break;/* font_color == stroke_color name or hex color */ |
||
1308 | case 1: double_data[0] = get_real(infile,0);break; /* x */ |
||
1309 | case 2: double_data[1] = get_real(infile,0);break; /* y */ |
||
1310 | case 3: fly_font = get_string_argument(infile,0); |
||
1311 | if(strcmp(fly_font,"giant") == 0){ |
||
1312 | font_size = (int)(font_size + 24); |
||
1313 | } |
||
1314 | else |
||
1315 | { |
||
1316 | if(strcmp(fly_font,"huge") == 0){ |
||
1317 | font_size = (int)(font_size + 14); |
||
1318 | } |
||
1319 | else |
||
1320 | { |
||
1321 | if(strcmp(fly_font,"large") == 0){ |
||
1322 | font_size = (int)(font_size + 6); |
||
1323 | } |
||
1324 | else |
||
1325 | { |
||
1326 | if(strcmp(fly_font,"small") == 0){ |
||
1327 | font_size = (int)(font_size - 4); |
||
1328 | if(font_size<0){font_size = 8;} |
||
1329 | } |
||
1330 | } |
||
1331 | } |
||
1332 | } |
||
1333 | break; /* font_size ! */ |
||
7842 | bpr | 1334 | case 4: |
7614 | schaersvoo | 1335 | temp = get_string_argument(infile,1); |
1336 | decimals = find_number_of_digits(precision); |
||
7785 | schaersvoo | 1337 | 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,%d,\"%s\",%d,\"%s\",%d,%s));\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,0,0,temp,font_size,font_family,use_affine,affine_matrix); |
7614 | schaersvoo | 1338 | click_cnt++;reset();break; |
1339 | default:break; |
||
1340 | } |
||
1341 | } |
||
1342 | break; |
||
1343 | case FLY_TEXTUP: |
||
1344 | /* |
||
1345 | @ textup fontcolor,x,y,font,text_string |
||
1346 | @ can <b>not</b> be set "onclick" or "drag xy" (because of translaton matrix...mouse incompatible) |
||
1347 | @ font may be described by keywords : giant,huge,normal,small,tiny |
||
7842 | bpr | 1348 | @ use command 'fontsize' to increase base fontsize for the keywords |
7614 | schaersvoo | 1349 | @ backwards compatible with flydraw |
1350 | @ unicode supported: textup red,0,0,huge,\\u2232 |
||
1351 | @ use command 'stringup' and 'fontfamily' for a more fine grained control over html5 canvas text element |
||
1352 | @ 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 rested 'fontfamily' to something lke 'fontfamily Ariel' before the old flydraw commands. |
||
1353 | */ |
||
7842 | bpr | 1354 | if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;} |
7614 | schaersvoo | 1355 | for(i = 0; i<5 ;i++){ |
1356 | switch(i){ |
||
1357 | case 0: font_color = get_color(infile,0);break;/* name or hex color */ |
||
1358 | case 1: int_data[0] = x2px(get_real(infile,0));break; /* x */ |
||
1359 | case 2: int_data[1] = y2px(get_real(infile,0));break; /* y */ |
||
1360 | case 3: fly_font = get_string_argument(infile,0); |
||
1361 | if(strcmp(fly_font,"giant") == 0){ |
||
1362 | font_size = (int)(font_size + 24); |
||
1363 | } |
||
1364 | else |
||
1365 | { |
||
1366 | if(strcmp(fly_font,"huge") == 0){ |
||
1367 | font_size = (int)(font_size + 14); |
||
1368 | } |
||
1369 | else |
||
1370 | { |
||
1371 | if(strcmp(fly_font,"large") == 0){ |
||
1372 | font_size = (int)(font_size + 6); |
||
1373 | } |
||
1374 | else |
||
1375 | { |
||
1376 | if(strcmp(fly_font,"small") == 0){ |
||
1377 | font_size = (int)(font_size - 4); |
||
1378 | if(font_size<0){font_size = 8;} |
||
1379 | } |
||
1380 | } |
||
1381 | } |
||
1382 | } |
||
1383 | break; /* font_size ! */ |
||
7842 | bpr | 1384 | case 4: |
7614 | schaersvoo | 1385 | decimals = find_number_of_digits(precision); |
1386 | temp = get_string_argument(infile,1); |
||
1387 | string_length = snprintf(NULL,0,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,90,\"%s\",%d,%.2f,%d,[%d,%d]);\n",STATIC_CANVAS,int_data[0],int_data[1],font_size,font_family,font_color,stroke_opacity,temp,use_rotate,angle,use_translate,translate_x,translate_y); |
||
1388 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
1389 | snprintf(tmp_buffer,string_length,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,90,\"%s\",%d,%.2f,%d,[%d,%d]);\n",STATIC_CANVAS,int_data[0],int_data[1],font_size,font_family,font_color,stroke_opacity,temp,use_rotate,angle,use_translate,translate_x,translate_y); |
||
1390 | add_to_buffer(tmp_buffer); |
||
1391 | break; |
||
1392 | default:break; |
||
1393 | } |
||
1394 | } |
||
1395 | reset(); |
||
1396 | break; |
||
1397 | case FONTFAMILY: |
||
1398 | /* |
||
1399 | @ fontfamily font_description |
||
1400 | @ set the font family; for browsers that support it |
||
1401 | @ font_description: Ariel ,Courier, Helvetica etc |
||
1402 | @ 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 |
||
1403 | @ use correct syntax : 'font style' 'font size'px 'fontfamily' |
||
1404 | */ |
||
1405 | font_family = get_string(infile,1); |
||
1406 | break; |
||
1407 | case STRINGUP: |
||
7842 | bpr | 1408 | /* |
1409 | @ stringup color,x,y,rotation_degrees,the text string |
||
7614 | schaersvoo | 1410 | @ can <b>not</b> be set "onclick" or "drag xy" (because of translaton matrix...mouse incompatible) |
1411 | @ unicode supported: stringup red,0,0,45,\\u2232 |
||
1412 | @ use a command like 'fontfamily bold 34px Courier' <br />to set fonts on browser that support font change |
||
1413 | |||
1414 | */ |
||
1415 | if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;} /* can not be added to shape library : rotate / mouse issues */ |
||
1416 | for(i=0;i<6;i++){ |
||
1417 | switch(i){ |
||
1418 | case 0: font_color = get_color(infile,0);break;/* name or hex color */ |
||
1419 | case 1: int_data[0] = x2px(get_real(infile,0));break; /* x */ |
||
1420 | case 2: int_data[1] = y2px(get_real(infile,0));break; /* y */ |
||
1421 | case 3: double_data[0] = get_real(infile,0);break;/* rotation */ |
||
1422 | case 4: decimals = find_number_of_digits(precision); |
||
1423 | temp = get_string_argument(infile,1); |
||
1424 | string_length = snprintf(NULL,0,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,%.2f,\"%s\",%d,%.2f,%d,[%d,%d]);\n",STATIC_CANVAS,int_data[0],int_data[1],font_size,font_family,font_color,stroke_opacity,double_data[0],temp,use_rotate,angle,use_translate,translate_x,translate_y); |
||
1425 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
1426 | snprintf(tmp_buffer,string_length,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,%.2f,\"%s\",%d,%.2f,%d,[%d,%d]);\n",STATIC_CANVAS,int_data[0],int_data[1],font_size,font_family,font_color,stroke_opacity,double_data[0],temp,use_rotate,angle,use_translate,translate_x,translate_y); |
||
1427 | add_to_buffer(tmp_buffer); |
||
1428 | break; |
||
1429 | default:break; |
||
1430 | } |
||
1431 | } |
||
1432 | reset(); |
||
1433 | break; |
||
1434 | case STRING: |
||
7842 | bpr | 1435 | /* |
7614 | schaersvoo | 1436 | @ string color,x,y,the text string |
1437 | @ may be set "onclick" or "drag xy" |
||
1438 | @ unicode supported: string red,0,0,\\u2232 |
||
7842 | bpr | 1439 | @ use a command like 'fontfamily italic 24px Ariel' <br />to set fonts on browser that support font change |
7614 | schaersvoo | 1440 | */ |
1441 | for(i=0;i<5;i++){ |
||
1442 | switch(i){ |
||
1443 | case 0: stroke_color = get_color(infile,0);break;/* name or hex color */ |
||
1444 | case 1: double_data[0] = get_real(infile,0);break; /* x in xrange*/ |
||
1445 | case 2: double_data[1] = get_real(infile,0);break; /* y in yrange*/ |
||
1446 | case 3: decimals = find_number_of_digits(precision); |
||
1447 | temp = get_string_argument(infile,1); |
||
1448 | decimals = find_number_of_digits(precision); |
||
7785 | schaersvoo | 1449 | 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,%d,\"%s\",%d,\"%s\",%d,%s));\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,0,0,temp,font_size,font_family,use_affine,affine_matrix); |
7614 | schaersvoo | 1450 | click_cnt++;reset();break; |
1451 | break; |
||
1452 | default:break; |
||
1453 | } |
||
1454 | } |
||
1455 | break; |
||
1456 | case MATHML: |
||
1457 | /* |
||
1458 | @ mathml x1,y1,x2,y2,mathml_string |
||
7842 | bpr | 1459 | @ mathml will be displayed in a rectangle left top (x1:y1) , right bottom (x2:y2) |
7614 | schaersvoo | 1460 | @ can be set onclick <br />(however dragging is not supported)<br />javascript:read_dragdrop(); will return click number of mathml-object |
7842 | bpr | 1461 | @ 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 />attention: if after this mathml-input object other user-interactions are included, these will read mathml too using "read_canvas();" |
7614 | schaersvoo | 1462 | @ 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.... |
7842 | bpr | 1463 | |
7614 | schaersvoo | 1464 | */ |
1465 | if( js_function[DRAW_XML] != 1 ){ js_function[DRAW_XML] = 1;} |
||
1466 | for(i=0;i<5;i++){ |
||
1467 | switch(i){ |
||
1468 | case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */ |
||
1469 | case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system -> pixel height */ |
||
1470 | case 2: int_data[2]=x2px(get_real(infile,0)) - int_data[0];break; /* width in x/y-range coord system -> pixel width */ |
||
1471 | case 3: int_data[3]=y2px(get_real(infile,0)) - int_data[1];break; /* height in x/y-range coord system -> pixel height */ |
||
1472 | case 4: decimals = find_number_of_digits(precision); |
||
7842 | bpr | 1473 | if(onclick == 1 ){ onclick = click_cnt;click_cnt++;} |
7614 | schaersvoo | 1474 | temp = get_string(infile,1); |
1475 | if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'"); } |
||
1476 | string_length = snprintf(NULL,0,"draw_xml(%d,%d,%d,%d,%d,\"%s\",%d);\n",canvas_root_id,int_data[0],int_data[1],int_data[2],int_data[3],temp,onclick); |
||
1477 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
1478 | snprintf(tmp_buffer,string_length,"draw_xml(%d,%d,%d,%d,%d,\"%s\",%d);\n",canvas_root_id,int_data[0],int_data[1],int_data[2],int_data[3],temp,onclick); |
||
1479 | add_to_buffer(tmp_buffer); |
||
7842 | bpr | 1480 | /* |
1481 | in case inputs are present , trigger adding the read_mathml() |
||
7614 | schaersvoo | 1482 | if no other reply_format is defined |
1483 | note: all other reply types will include a reading of elements with id='mathml'+p) |
||
1484 | */ |
||
1485 | if(strstr(temp,"mathml0") != NULL){ |
||
1486 | if(reply_format < 1 ){reply_format = 16;} /* no other reply type is defined */ |
||
1487 | } |
||
1488 | break; |
||
1489 | default:break; |
||
1490 | } |
||
1491 | } |
||
1492 | reset(); |
||
1493 | break; |
||
1494 | case HTTP: |
||
1495 | /* |
||
1496 | @http x1,y1,x2,y2,http://some_adress.com |
||
7842 | bpr | 1497 | @an active html-page will be displayed in an "iframe" rectangle left top (x1:y1) , right bottom (x2:y2) |
7614 | schaersvoo | 1498 | @do not use interactivity (or mouse) if the mouse needs to be active in the iframe |
1499 | @can not be 'set onclick' or 'drag xy' |
||
1500 | */ |
||
7842 | bpr | 1501 | if( js_function[DRAW_HTTP] != 1 ){ js_function[DRAW_HTTP] = 1;} |
7614 | schaersvoo | 1502 | for(i=0;i<5;i++){ |
1503 | switch(i){ |
||
1504 | case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */ |
||
1505 | case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system -> pixel height */ |
||
1506 | case 2: int_data[2]=x2px(get_real(infile,0)) - int_data[0];break; /* width in x/y-range coord system -> pixel width */ |
||
1507 | case 3: int_data[3]=y2px(get_real(infile,0)) - int_data[1];break; /* height in x/y-range coord system -> pixel height */ |
||
1508 | case 4: decimals = find_number_of_digits(precision); |
||
1509 | temp = get_string(infile,1); |
||
1510 | if(strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'");} |
||
1511 | 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); |
||
1512 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
1513 | 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); |
||
1514 | add_to_buffer(tmp_buffer); |
||
1515 | break; |
||
1516 | } |
||
1517 | } |
||
1518 | reset(); |
||
1519 | break; |
||
1520 | case HTML: |
||
1521 | /* |
||
1522 | @ html x1,y1,x2,y2,html_string |
||
1523 | @ all tags are allowed |
||
1524 | @ can be set onclick <br />(dragging not supported)<br />javascript:read_dragdrop(); will return click number of mathml-object |
||
1525 | @ if inputfields are incorporated (with id's : id='mathml0',id='mathml1',...id='mathml_n')<br />the user_input values will be read by javascript:read_canvas(); <br />If other inputfields (command input / command textarea) or userdraw is performed, these values will NOT be read as well. |
||
7842 | bpr | 1526 | |
7614 | schaersvoo | 1527 | note: uses the same code as 'mathml' |
1528 | */ |
||
1529 | break; |
||
1530 | case X_AXIS_STRINGS: |
||
1531 | /* |
||
1532 | @ xaxis num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n |
||
1533 | @ xaxistext num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n |
||
1534 | @ use these x-axis values in stead of default xmin...xmax |
||
1535 | @ use command "fontcolor", "fontsize" , "fontfamily" to adjust font <br />defaults: black,12,Ariel |
||
1536 | @ if the 'x-axis words' are to big amd will overlap, a simple alternating offset will be applied |
||
1537 | @ 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 |
||
1538 | @ example:<br />size 400,400<br />xrange -5*pi,5*pi<br />yrange -100,500<br />axis<br />xaxis -4*pi:-4\\u03c0:-3*pi:-3\\u03c0:-2*pi:-2\\u03c0:-1*pi:-\\u03c0:0:0:pi:\\u03c0:2*pi:2\\u03c01:3*pi:3\\u03c0:4*pi:4\\u03c0<br />#'xmajor' steps should be synchronised with numbers eg. "1" in this example<br />grid pi,1,grey,1,3,6,grey |
||
1539 | */ |
||
1540 | temp = get_string(infile,1); |
||
1541 | if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");} |
||
1542 | if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/ |
||
1543 | fprintf(js_include_file,"x_strings = [\"%s\"];\n ",temp); |
||
1544 | use_axis_numbering = 1; |
||
1545 | break; |
||
1546 | case Y_AXIS_STRINGS: |
||
1547 | /* |
||
1548 | @ yaxis num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n |
||
1549 | @ yaxistext num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n |
||
1550 | @ use command "fontcolor", "fontsize" , "fontfamily" to adjust font <br />defaults: black,12,Ariel |
||
1551 | @ use these y-axis values in stead of default ymin...ymax |
||
1552 | @ 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 |
||
1553 | */ |
||
1554 | temp = get_string(infile,1); |
||
1555 | if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");} |
||
1556 | if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/ |
||
1557 | fprintf(js_include_file,"y_strings = [\"%s\"];\n ",temp); |
||
1558 | use_axis_numbering = 1; |
||
1559 | break; |
||
7842 | bpr | 1560 | |
7614 | schaersvoo | 1561 | case AXIS_NUMBERING: |
1562 | /* |
||
7842 | bpr | 1563 | @ axisnumbering |
7614 | schaersvoo | 1564 | @ keyword, no aguments required |
1565 | */ |
||
1566 | use_axis_numbering = 1; |
||
1567 | break; |
||
1568 | case AXIS: |
||
1569 | /* |
||
1570 | @ axis |
||
1571 | @ keyword, no aguments required |
||
1572 | |||
1573 | */ |
||
1574 | use_axis = TRUE; |
||
1575 | break; |
||
7654 | schaersvoo | 1576 | case SGRAPH: |
1577 | /* |
||
1578 | @ sgraph xstart,ystart,xmajor,ymajor,xminor,yminor,majorgrid_color,minorgrid_color |
||
1579 | @ primitive implementation of a 'broken scale' graph... |
||
1580 | @ not very versatile. |
||
1581 | @ 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 |
||
1582 | */ |
||
7842 | bpr | 1583 | if( js_function[DRAW_SGRAPH] != 1 ){ js_function[DRAW_SGRAPH] = 1;} |
7654 | schaersvoo | 1584 | for(i = 0 ; i < 8 ;i++){ |
1585 | switch(i){ |
||
1586 | case 0:double_data[0] = get_real(infile,0);break; |
||
1587 | case 1:double_data[1] = get_real(infile,0);break; |
||
1588 | case 2:double_data[2] = get_real(infile,0);break; |
||
1589 | case 3:double_data[3] = get_real(infile,0);break; |
||
1590 | case 4:int_data[0] = (int)(get_real(infile,0));break; |
||
1591 | case 5:int_data[1] = (int)(get_real(infile,0));break; |
||
1592 | case 6:stroke_color = get_color(infile,0);break; |
||
1593 | case 7:font_color = get_color(infile,1); |
||
7658 | schaersvoo | 1594 | 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); |
7654 | schaersvoo | 1595 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
7658 | schaersvoo | 1596 | 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); |
7654 | schaersvoo | 1597 | add_to_buffer(tmp_buffer); |
1598 | break; |
||
1599 | default:break; |
||
1600 | } |
||
1601 | } |
||
1602 | /* sgraph(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily,opacity)*/ |
||
1603 | break; |
||
7614 | schaersvoo | 1604 | case GRID:/* xmajor,ymajor,color [,xminor,yminor,tick length (px) ,color]*/ |
1605 | /* |
||
1606 | @ grid step_x,step_y,gridcolor |
||
1607 | @ use command "fontcolor", "fontsize" , "fontfamily" to adjust font <br />defaults: black,12,Ariel |
||
1608 | @ if keywords "axis" or "axisnumbering" 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 |
||
7654 | schaersvoo | 1609 | @ 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) |
7614 | schaersvoo | 1610 | @ can not be set "onclick" or "drag xy" |
1611 | @ use commands 'xlabel some_string' and/or 'ylabel some_string' to label axis;<br />use command "fontsize" to adjust size (the font family is non-configurable 'italic your_fontsize px Ariel') |
||
1612 | @ see commands "xaxis" or "xaxistext", "yaxis" or "yaxistext" to set tailormade values on axis (the used font is set by command fontfamily; default '12px Ariel') |
||
1613 | @ see command "legend" to set a legend for the graph ;<br />use command "fontsize" to adjust size (the font family is non-configurable 'bold your_fontsize px Ariel') |
||
1614 | */ |
||
7729 | schaersvoo | 1615 | if( js_function[DRAW_YLOGSCALE] == 1 ){canvas_error("only one grid type is allowed...");} |
7614 | schaersvoo | 1616 | if( js_function[DRAW_GRID] != 1 ){ js_function[DRAW_GRID] = 1;} |
1617 | for(i=0;i<4;i++){ |
||
1618 | switch(i){ |
||
1619 | case 0:double_data[0] = get_real(infile,0);break;/* xmajor */ |
||
1620 | case 1:double_data[1] = get_real(infile,0);break;/* ymajor */ |
||
1621 | case 2: |
||
1622 | if( use_axis == TRUE ){ |
||
1623 | stroke_color = get_color(infile,0); |
||
1624 | done = FALSE; |
||
1625 | int_data[0] = (int) (get_real(infile,0));/* xminor */ |
||
1626 | int_data[1] = (int) (get_real(infile,0));/* yminor */ |
||
1627 | int_data[2] = (int) (get_real(infile,0));/* tic_length */ |
||
1628 | fill_color = get_color(infile,1); /* used as axis_color*/ |
||
1629 | } |
||
1630 | else |
||
1631 | { |
||
1632 | int_data[0] = 1; |
||
1633 | int_data[1] = 1; |
||
1634 | stroke_color = get_color(infile,1); |
||
1635 | fill_color = stroke_color; |
||
1636 | } |
||
1637 | if( double_data[0] <= 0 || double_data[1] <= 0 || int_data[0] <= 0 || int_data[1] <= 0 ){canvas_error("major or minor tickt must be positive !");} |
||
7634 | schaersvoo | 1638 | /* set snap_x snap_y values in pixels */ |
7647 | schaersvoo | 1639 | fprintf(js_include_file,"snap_x = %f;snap_y = %f\n;",double_data[0] / int_data[0],double_data[1] / int_data[1]); |
7614 | schaersvoo | 1640 | /* 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_translate,vector,use_dashed,dashtype0,dashtype1,font_color,fill_opacity){ */ |
1641 | |||
1642 | 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,[%d,%d],%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_translate,translate_x,translate_y,use_dashed,dashtype[0],dashtype[1],font_color,fill_opacity); |
||
1643 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
1644 | 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,[%d,%d],%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_translate,translate_x,translate_y,use_dashed,dashtype[0],dashtype[1],font_color,fill_opacity); |
||
1645 | add_to_buffer(tmp_buffer); |
||
1646 | break; |
||
1647 | } |
||
1648 | } |
||
1649 | reset(); |
||
1650 | break; |
||
1651 | case OPACITY: |
||
1652 | /* |
||
1653 | @ opacity 0-255,0-255 |
||
1654 | @ |
||
1655 | */ |
||
1656 | for(i = 0 ; i<2;i++){ |
||
1657 | switch(i){ |
||
1658 | case 0: double_data[0]=(int)(get_real(infile,0));break; |
||
1659 | case 1: double_data[1]=(int)(get_real(infile,1));break; |
||
1660 | default: break; |
||
1661 | } |
||
1662 | } |
||
1663 | if( double_data[0] < 0 || double_data[0] > 255 || double_data[1] < 0 || double_data[1] > 255 ){ canvas_error("opacity [0 - 255] , [0 - 255]");}/* typo or non-RGB ? */ |
||
1664 | stroke_opacity = (double) (0.0039215*double_data[0]);/* 0.0 - 1.0 */ |
||
1665 | fill_opacity = (double) (0.0039215*double_data[1]);/* 0.0 - 1.0 */ |
||
1666 | break; |
||
1667 | case ROTATE: |
||
1668 | /* |
||
1669 | @rotate rotation_angle |
||
1670 | @ |
||
1671 | */ |
||
1672 | use_rotate = TRUE; |
||
1673 | use_translate = TRUE; |
||
1674 | translate_x = x2px(0); |
||
1675 | translate_y = y2px(0); |
||
1676 | angle = get_real(infile,1); |
||
1677 | break; |
||
7785 | schaersvoo | 1678 | case KILLAFFINE: |
1679 | /* |
||
1680 | @ killaffine |
||
1681 | @ keyword : resets the transformation matrix to 1,0,0,1,0,0 |
||
1682 | */ |
||
1683 | use_affine = FALSE; |
||
7842 | bpr | 1684 | snprintf(affine_matrix,14,"[1,0,0,1,0,0]"); |
7785 | schaersvoo | 1685 | break; |
1686 | case AFFINE: |
||
1687 | /* |
||
1688 | @affine a,b,c,d,tx,ty |
||
7842 | bpr | 1689 | @ defines a transformation matrix for subsequent objects |
7785 | schaersvoo | 1690 | @ use keyword 'killaffine' to end the transformation |
1691 | @ note 1: only 'draggable' / 'noclick' objects can be transformed. |
||
1692 | @ note 2: do not use 'onclick' or 'drag xy' with tranformation objects : the mouse coordinates do not get transformed (yet) |
||
1693 | @ note 3: no matrix operations on the transformation matrix implemented (yet) |
||
1694 | @ a : Scales the drawings horizontally |
||
1695 | @ b : Skews the drawings horizontally |
||
1696 | @ c : Skews the drawings vertically |
||
1697 | @ d : Scales the drawings vertically |
||
7786 | schaersvoo | 1698 | @ tx: Moves the drawings horizontally in pixels ! |
1699 | @ ty: Moves the drawings vertically in pixels ! |
||
7785 | schaersvoo | 1700 | */ |
1701 | for(i = 0 ; i<6;i++){ |
||
1702 | switch(i){ |
||
1703 | case 0: double_data[0] = get_real(infile,0);break; |
||
1704 | case 1: double_data[1] = get_real(infile,0);break; |
||
1705 | case 2: double_data[2] = get_real(infile,0);break; |
||
1706 | case 3: double_data[3] = get_real(infile,0);break; |
||
1707 | case 4: int_data[0] = (int)(get_real(infile,0));break; |
||
1708 | case 5: int_data[1] = (int)(get_real(infile,1)); |
||
1709 | use_affine = TRUE; |
||
1710 | string_length = snprintf(NULL,0,"[%.2f,%.2f,%.2f,%.2f,%d,%d] ",double_data[0],double_data[1],double_data[2],double_data[3],int_data[0],int_data[1]); |
||
1711 | check_string_length(string_length);affine_matrix = my_newmem(string_length+1); |
||
7842 | bpr | 1712 | snprintf(affine_matrix,string_length,"[%.2f,%.2f,%.2f,%.2f,%d,%d] ",double_data[0],double_data[1],double_data[2],double_data[3],int_data[0],int_data[1]); |
7785 | schaersvoo | 1713 | break; |
1714 | default: break; |
||
1715 | } |
||
1716 | } |
||
1717 | break; |
||
7614 | schaersvoo | 1718 | case KILLTRANSLATION: |
1719 | /* |
||
1720 | killtranslation |
||
1721 | */ |
||
1722 | break; |
||
1723 | case TRANSLATION: |
||
1724 | /* |
||
1725 | @translation tx,ty |
||
1726 | @ |
||
1727 | */ |
||
1728 | use_translate = TRUE; |
||
1729 | translate_x = get_real(infile,0); |
||
1730 | translate_y = get_real(infile,1); |
||
1731 | break; |
||
1732 | case DASHED: |
||
1733 | /* |
||
1734 | @ keyword "dashed" |
||
1735 | @ next object will be drawn with a dashed line |
||
1736 | @ change dashing scheme by using command "dashtype int,int) |
||
1737 | */ |
||
1738 | use_dashed = TRUE; |
||
1739 | break; |
||
1740 | case FILLED: |
||
1741 | /* |
||
7842 | bpr | 1742 | @ keyword "filled" |
1743 | @ the next 'fillable' object (only) will be filled |
||
7614 | schaersvoo | 1744 | @ use command "fillcolor color" to set fillcolor |
1745 | @ use command "opacity 0-255,0-255" to set stroke and fill-opacity |
||
1746 | @ 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 ! |
||
1747 | */ |
||
1748 | use_filled = TRUE; |
||
1749 | break; |
||
1750 | case STYLE: |
||
1751 | /* |
||
1752 | @highlight color,opacity,linewidth |
||
1753 | @ NOT IMPLEMENTED |
||
1754 | @ use command "onclick" : when the object receives a userclick it will increase it's linewidth |
||
1755 | */ |
||
1756 | break; |
||
1757 | case FILLCOLOR: |
||
1758 | /* |
||
1759 | @ fillcolor colorname or #hex |
||
1760 | @ Set the color for a filled object : mainly used for command 'userdraw obj,stroke_color' |
||
1761 | @ All fillable massive object will have a fillcolor == strokecolor (just to be compatible with flydraw...) |
||
1762 | */ |
||
1763 | fill_color = get_color(infile,1); |
||
1764 | break; |
||
1765 | case STROKECOLOR: |
||
1766 | /* |
||
1767 | @ strokecolor colorname or #hex |
||
1768 | @ to be used for commands that do not supply a color argument (like command 'linegraph') |
||
1769 | */ |
||
1770 | stroke_color = get_color(infile,1); |
||
1771 | break; |
||
7842 | bpr | 1772 | case BGIMAGE: |
7614 | schaersvoo | 1773 | /* |
1774 | @bgimage image_location |
||
1775 | @use an image as background .<br />(we use the background of 'canvas_div' ) |
||
1776 | @the background image will be resized to match "width = xsize" and "height = ysize" |
||
1777 | */ |
||
1778 | URL = get_string(infile,1); |
||
1779 | 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); |
||
1780 | break; |
||
7842 | bpr | 1781 | case BGCOLOR: |
7614 | schaersvoo | 1782 | /* |
1783 | @bgcolor colorname or #hex |
||
1784 | @use this color as background of the "div" containing the canvas(es) |
||
1785 | */ |
||
1786 | /* [255,255,255]*/ |
||
1787 | bgcolor = get_string(infile,1); |
||
1788 | if(strstr(bgcolor,"#") == NULL){ /* convert colorname -> #ff00ff */ |
||
1789 | int found = 0; |
||
1790 | for( i = 0; i < NUMBER_OF_COLORNAMES ; i++ ){ |
||
1791 | if( strcmp( colors[i].name , bgcolor ) == 0 ){ |
||
1792 | bgcolor = colors[i].hex; |
||
1793 | found = 1; |
||
1794 | break; |
||
1795 | } |
||
1796 | } |
||
1797 | if(found == 0){canvas_error("your bgcolor is not in my rgb.txt data list : use hexcolor...something like #a0ffc4");} |
||
1798 | } |
||
1799 | fprintf(js_include_file,"<!-- set background color of canvas div -->\ncanvas_div.style.backgroundColor = \"%s\";canvas_div.style.opacity = %f;\n",bgcolor,fill_opacity); |
||
1800 | break; |
||
1801 | case COPY: |
||
1802 | /* |
||
1803 | @ copy x,y,x1,y1,x2,y2,[filename URL] |
||
1804 | @ Insert the region from (x1,y1) to (x2,y2) (in pixels) of [filename] to (x,y) in x/y-range |
||
1805 | @ If x1=y1=x2=y2=-1, the whole [filename URL] is copied. |
||
7842 | bpr | 1806 | @ [filename] is the URL of the image |
7614 | schaersvoo | 1807 | @ URL is normal URL of network reachable image file location<br />(eg special url for 'classexo' not -yet- implemented) |
1808 | @ if command 'drag x/y/xy' 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 valuid for the next image<br />draggable / non-draggable images may be mixed |
||
7842 | bpr | 1809 | @ if you want to draw / userdraw on an "imported" image, make sure it is transparent.<br />for example GNUPlot: set terminal gif transparent |
7614 | schaersvoo | 1810 | |
1811 | context.drawImage(img,sx,sy,swidth,sheight,x,y,width,height); |
||
1812 | draw_external_image(canvas_type,URL,sx,sy,swidth,sheight,x,y,width,height,drag_drop){ |
||
1813 | */ |
||
1814 | for(i = 0 ; i<7;i++){ |
||
1815 | switch(i){ |
||
1816 | case 0: int_data[0]=x2px(get_real(infile,0));break; /* x left top corner in x/y range */ |
||
1817 | case 1: int_data[1]=y2px(get_real(infile,0));break; /* y left top corner in x/y range */ |
||
1818 | case 2: int_data[2]=(int)(get_real(infile,0));break;/* x1 in px of external image */ |
||
1819 | case 3: int_data[3]=(int)(get_real(infile,0));break;/* y1 in px of external image */ |
||
1820 | case 4: int_data[4]=(int)(get_real(infile,0));break;/* x2 --> width */ |
||
1821 | case 5: int_data[5]=(int)(get_real(infile,0)) ;break;/* y2 --> height */ |
||
1822 | case 6: URL = get_string(infile,1); |
||
1823 | int_data[6] = int_data[4] - int_data[2];/* swidth & width (if not scaling )*/ |
||
1824 | int_data[7] = int_data[5] - int_data[3];/* sheight & height (if not scaling )*/ |
||
1825 | if( drag_type > -1 ){ |
||
1826 | if( js_function[DRAG_EXTERNAL_IMAGE] != 1 ){ js_function[DRAG_EXTERNAL_IMAGE] = 1;} |
||
1827 | if(reply_format < 1 ){reply_format = 20;} |
||
1828 | string_length = snprintf(NULL,0,"drag_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,%d);\n",URL,int_data[2],int_data[3],int_data[6],int_data[7],int_data[0],int_data[1],int_data[6],int_data[7],ext_img_cnt,1); |
||
1829 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
7842 | bpr | 1830 | snprintf(tmp_buffer,string_length,"drag_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,%d);\n",URL,int_data[2],int_data[3],int_data[6],int_data[7],int_data[0],int_data[1],int_data[6],int_data[7],ext_img_cnt,1); |
7614 | schaersvoo | 1831 | drag_type = -1; |
1832 | ext_img_cnt++; |
||
1833 | } |
||
1834 | else |
||
1835 | { |
||
1836 | if( js_function[DRAW_EXTERNAL_IMAGE] != 1 ){ js_function[DRAW_EXTERNAL_IMAGE] = 1;} |
||
1837 | /* |
||
1838 | draw_external_image = function(URL,sx,sy,swidth,sheight,x0,y0,width,height,draggable){\n\ |
||
1839 | */ |
||
1840 | string_length = snprintf(NULL,0,"draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,0);\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]); |
||
1841 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
1842 | snprintf(tmp_buffer,string_length,"draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,0);\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]); |
||
1843 | } |
||
1844 | add_to_buffer(tmp_buffer); |
||
1845 | break; |
||
1846 | default: break; |
||
1847 | } |
||
1848 | } |
||
1849 | reset(); |
||
1850 | break; |
||
1851 | /* |
||
1852 | context.drawImage(img,sx,sy,swidth,sheight,x,y,width,height); |
||
1853 | img Specifies the image, canvas, or video element to use |
||
1854 | sx The x coordinate where to start clipping : x1 = int_data[0] |
||
1855 | sy The y coordinate where to start clipping : x2 = int_data[1] |
||
7842 | bpr | 1856 | swidth The width of the clipped image : int_data[2] - int_data[0] |
7614 | schaersvoo | 1857 | sheight The height of the clipped image : int_data[3] - int_data[1] |
1858 | x The x coordinate where to place the image on the canvas : dx1 = int_data[4] |
||
1859 | y The y coordinate where to place the image on the canvas : dy1 = int_data[5] |
||
1860 | width The width of the image to use (stretch or reduce the image) : dx2 - dx1 = int_data[6] |
||
1861 | height The height of the image to use (stretch or reduce the image) : dy2 - dy1 = int_data[7] |
||
1862 | */ |
||
1863 | case COPYRESIZED: |
||
1864 | /* |
||
1865 | @ copyresized x1,y2,x2,y2,dx1,dy1,dx2,dy2,image_file_url |
||
7842 | bpr | 1866 | @ 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 |
7614 | schaersvoo | 1867 | @ If x1=y1=x2=y2=-1, the whole [filename / URL ] is copied and resized. |
1868 | @ URL is normal URL of network reachable image file location<br />(eg special url for 'classexo' not -yet- implemented) |
||
1869 | @ if command 'drag x/y/xy' 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 valuid for the next image<br />draggable / non-draggable images may be mixed |
||
7842 | bpr | 1870 | @ if you want to draw / userdraw on an "imported" image, make sure it is transparent.<br />for example GNUPlot: set terminal gif transparent |
7614 | schaersvoo | 1871 | */ |
1872 | for(i = 0 ; i<9;i++){ |
||
1873 | switch(i){ |
||
1874 | case 0: int_data[0] = (int)(get_real(infile,0));break; /* x1 */ |
||
1875 | case 1: int_data[1] = (int)(get_real(infile,0));break; /* y1 */ |
||
1876 | case 2: int_data[2] = (int)(get_real(infile,0));break;/* x2 */ |
||
1877 | case 3: int_data[3] = (int)(get_real(infile,0));break;/* y2 */ |
||
1878 | case 4: int_data[4] = x2px(get_real(infile,0));break;/* dx1 */ |
||
1879 | case 5: int_data[5] = y2px(get_real(infile,0));break;/* dy1 */ |
||
1880 | case 6: int_data[6] = x2px(get_real(infile,0));break;/* dx2 */ |
||
1881 | case 7: int_data[7] = y2px(get_real(infile,0));break;/* dy2 */ |
||
1882 | case 8: URL = get_string(infile,1); |
||
1883 | if( drag_type > -1 ){ |
||
1884 | if( js_function[DRAG_EXTERNAL_IMAGE] != 1 ){ js_function[DRAG_EXTERNAL_IMAGE] = 1;} |
||
1885 | if(reply_format < 1 ){reply_format = 20;} |
||
1886 | string_length = snprintf(NULL,0,"drag_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,%d);\n",URL,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],ext_img_cnt,1); |
||
1887 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
1888 | snprintf(tmp_buffer,string_length,"drag_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,%d);\n",URL,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],ext_img_cnt,1); |
||
1889 | drag_type = -1; |
||
1890 | ext_img_cnt++; |
||
1891 | } |
||
1892 | else |
||
1893 | { |
||
1894 | if( js_function[DRAW_EXTERNAL_IMAGE] != 1 ){ js_function[DRAW_EXTERNAL_IMAGE] = 1;} |
||
1895 | string_length = snprintf(NULL,0,"draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,0);\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]); |
||
1896 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
1897 | snprintf(tmp_buffer,string_length,"draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,0);\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]); |
||
1898 | } |
||
1899 | add_to_buffer(tmp_buffer); |
||
1900 | default: break; |
||
1901 | } |
||
1902 | } |
||
1903 | reset(); |
||
1904 | break; |
||
1905 | case BUTTON: |
||
1906 | /* |
||
1907 | button x,y,value |
||
1908 | */ |
||
1909 | break; |
||
1910 | case INPUTSTYLE: |
||
1911 | /* |
||
1912 | @ inputstyle style_description |
||
1913 | @ example: inputstyle color:blue;font-weight:bold;font-style:italic;font-size:16pt |
||
1914 | */ |
||
1915 | input_style = get_string(infile,1); |
||
1916 | break; |
||
1917 | case INPUT: |
||
7842 | bpr | 1918 | /* |
7614 | schaersvoo | 1919 | @ input x,y,size,editable,value |
7842 | bpr | 1920 | @ to set inputfield "readonly", use editable = 0 |
7614 | schaersvoo | 1921 | @ only active inputfields (editable = 1) will be read with read_canvas(); |
1922 | @ may be further controlled by "inputstyle" (inputcss is not yet implemented...) |
||
1923 | @ if mathml inputfields are present and / or some userdraw is performed, these data will NOT be send as well (javascript:read_canvas();) |
||
1924 | */ |
||
7842 | bpr | 1925 | if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;} |
7614 | schaersvoo | 1926 | for(i = 0 ; i<5;i++){ |
1927 | switch(i){ |
||
1928 | case 0: int_data[0]=x2px(get_real(infile,0));break;/* x in px */ |
||
1929 | case 1: int_data[1]=y2px(get_real(infile,0));break;/* y in px */ |
||
1930 | case 2: int_data[2]=abs( (int)(get_real(infile,0)));break; /* size */ |
||
1931 | case 3: if( get_real(infile,1) >0){int_data[3] = 1;}else{int_data[3] = 0;};break; /* readonly */ |
||
7842 | bpr | 1932 | case 4: |
7614 | schaersvoo | 1933 | temp = get_string_argument(infile,1); |
1934 | string_length = snprintf(NULL,0, "draw_inputs(%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],input_style,temp); |
||
1935 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
1936 | snprintf(tmp_buffer,string_length,"draw_inputs(%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],input_style,temp); |
||
1937 | add_to_buffer(tmp_buffer); |
||
1938 | input_cnt++;break; |
||
1939 | default: break; |
||
1940 | } |
||
1941 | } |
||
1942 | if(reply_format < 1 ){reply_format = 15;} |
||
1943 | reset(); |
||
1944 | break; |
||
1945 | case TEXTAREA: |
||
7842 | bpr | 1946 | /* |
7614 | schaersvoo | 1947 | @ textarea x,y,cols,rows,readonly,value |
1948 | @ may be further controlled by "inputstyle" |
||
1949 | @ if mathml inputfields are present and / or some userdraw is performed, these data will NOT be send as well (javascript:read_canvas();) |
||
1950 | */ |
||
7842 | bpr | 1951 | if( js_function[DRAW_TEXTAREAS] != 1 ){ js_function[DRAW_TEXTAREAS] = 1;} |
7614 | schaersvoo | 1952 | for(i = 0 ; i<6;i++){ |
1953 | switch(i){ |
||
1954 | case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in px */ |
||
1955 | case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in px */ |
||
1956 | case 2: int_data[2]=abs( (int)(get_real(infile,0)));break;/* cols */ |
||
1957 | case 3: int_data[3]=abs( (int)(get_real(infile,0)));break;/* rows */ |
||
1958 | case 4: if( get_real(infile,1) >0){int_data[4] = 1;}else{int_data[3] = 0;};break; /* readonly */ |
||
1959 | case 5: temp = get_string_argument(infile,1); |
||
1960 | 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); |
||
1961 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
1962 | 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); |
||
1963 | add_to_buffer(tmp_buffer); |
||
1964 | input_cnt++;break; |
||
1965 | default: break; |
||
1966 | } |
||
1967 | } |
||
1968 | if(reply_format < 1 ){reply_format = 15;} |
||
1969 | reset(); |
||
1970 | break; |
||
1971 | case MOUSE_PRECISION: |
||
1972 | /* |
||
1973 | @ precision int |
||
1974 | @ 10 = 1 decimal ; 100 = 2 decimals etc |
||
1975 | @ may be used / changed before every object |
||
1976 | */ |
||
1977 | precision = (int) (get_real(infile,1)); |
||
1978 | break; |
||
7838 | schaersvoo | 1979 | case SETLIMITS: |
1980 | /* |
||
7842 | bpr | 1981 | @setlimits |
7838 | schaersvoo | 1982 | @keyword : if set, it will produce 4 inputfields for 'xmin,xmax,ymin,ymax' and an 'ok' button |
1983 | @may be used for inputfield based zooming / panning |
||
7842 | bpr | 1984 | @note:the input value will not be checked on validity |
7838 | schaersvoo | 1985 | */ |
1986 | add_setlimits(js_include_file,canvas_root_id); |
||
1987 | /* add_setlimits provides 'fprintf(js_include_file,"use_pan_and_zoom = 1;");' */ |
||
1988 | use_pan_and_zoom = TRUE; |
||
1989 | done = TRUE; |
||
1990 | break; |
||
7614 | schaersvoo | 1991 | case ZOOM: |
1992 | /* |
||
1993 | @ zoom button_color |
||
1994 | @ introduce a controlpanel at the lower right corner |
||
1995 | @ giving six 15x15pixel 'active' rectangle areas<br />(for x,leftarrow,rightarrow,uparrow,downarrow and a '-' and a '+' sign ) for zooming and/or panning of the image |
||
1996 | @ the 'x' symbol will do a 'location.reload' of the page, and thus reset all canvas drawings. |
||
1997 | @ choose an appropriate colour, so the small 'x,arrows,-,+' are clearly visible |
||
7842 | bpr | 1998 | @ command 'opacity' may be used to set stroke_opacity of 'buttons |
7614 | schaersvoo | 1999 | @ NOTE: only objects that may be set draggable / clickable will be zoomed / panned |
2000 | @ 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 !! |
||
2001 | */ |
||
7653 | schaersvoo | 2002 | fprintf(js_include_file,"use_pan_and_zoom = 1;"); |
7797 | schaersvoo | 2003 | use_pan_and_zoom = TRUE; |
7614 | schaersvoo | 2004 | if( js_function[DRAW_ZOOM_BUTTONS] != 1 ){ js_function[DRAW_ZOOM_BUTTONS] = 1;} |
2005 | /* we use BG_CANVAS (0) */ |
||
2006 | stroke_color = get_color(infile,1); |
||
7653 | schaersvoo | 2007 | string_length = snprintf(NULL,0," draw_zoom_buttons(%d,\"%s\",%f);",BG_CANVAS,stroke_color,stroke_opacity); |
7614 | schaersvoo | 2008 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
7653 | schaersvoo | 2009 | snprintf(tmp_buffer,MAX_BUFFER-1,"draw_zoom_buttons(%d,\"%s\",%f);",BG_CANVAS,stroke_color,stroke_opacity); |
7614 | schaersvoo | 2010 | add_to_buffer(tmp_buffer); |
2011 | done = TRUE; |
||
2012 | break; |
||
2013 | case ONCLICK: |
||
2014 | /* |
||
2015 | @ onclick |
||
2016 | @ keyword, no arguments |
||
2017 | @ if the next object is clicked, it's 'object sequence number' in fly script is returned <br /> by javascript:read_canvas(); |
||
7842 | bpr | 2018 | @ Line based object will show an increase in linewidth<br />Font based objects will show the text in 'bold' when clicked. |
7614 | schaersvoo | 2019 | @ NOTE: not all objects may be set clickable |
2020 | */ |
||
7842 | bpr | 2021 | |
7614 | schaersvoo | 2022 | onclick = 1; |
2023 | break; |
||
2024 | case DRAG: |
||
2025 | /* |
||
2026 | @ drag [x][y][xy] |
||
2027 | @ the next object will be draggable in x / y / xy direction |
||
2028 | @ the displacement can be read by 'javascript:read_dragdrop();' |
||
7842 | bpr | 2029 | @ 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. |
7614 | schaersvoo | 2030 | @ 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 !! |
2031 | */ |
||
2032 | temp = get_string(infile,1); |
||
7842 | bpr | 2033 | if(strstr(temp,"xy") != NULL ){ |
7614 | schaersvoo | 2034 | drag_type = 0; |
2035 | } |
||
2036 | else |
||
2037 | { |
||
7842 | bpr | 2038 | if(strstr(temp,"x") != NULL ){ |
7614 | schaersvoo | 2039 | drag_type = 1; |
2040 | } |
||
2041 | else |
||
2042 | { |
||
2043 | drag_type = 2; |
||
2044 | } |
||
2045 | } |
||
2046 | onclick = 2; |
||
2047 | /* if(use_userdraw == TRUE ){canvas_error("\"drag & drop\" may not be combined with \"userdraw\" or \"pan and zoom\" \n");} */ |
||
2048 | break; |
||
2049 | case BLINK: |
||
2050 | /* |
||
2051 | @ blink time(seconds) |
||
2052 | @ NOT IMPLEMETED -YET |
||
2053 | */ |
||
2054 | break; |
||
2055 | case MOUSE: |
||
2056 | /* |
||
2057 | @ mouse color,fontsize |
||
2058 | @ will display the cursor coordinates in 'color' and 'font size'<br /> using default fontfamily Ariel |
||
2059 | */ |
||
2060 | stroke_color = get_color(infile,0); |
||
2061 | font_size = (int) (get_real(infile,1)); |
||
7839 | schaersvoo | 2062 | tmp_buffer = my_newmem(26); |
2063 | snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer); |
||
7614 | schaersvoo | 2064 | add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity); |
2065 | break; |
||
2066 | case INTOOLTIP: |
||
2067 | /* |
||
2068 | @ intooltip link_text |
||
2069 | @ link_text is a single line (span-element) |
||
2070 | @ link_text may also be an image URL http://some_server/images/my_image.png |
||
2071 | @ link_text may contain HTML markup |
||
2072 | @ the canvas will be displayed in a tooltip on 'link_text' |
||
2073 | @ the canvas is default transparent: use command 'bgcolor color' to adjust background-color<br />the link test will alos be shown with this bgcolor. |
||
2074 | */ |
||
7823 | schaersvoo | 2075 | if(use_input_xy != FALSE ){canvas_error("intooltip can not be combined with userinput_xy command");} |
7614 | schaersvoo | 2076 | use_tooltip = TRUE; |
2077 | tooltip_text = get_string(infile,1); |
||
2078 | if(strstr(tooltip_text,"\"") != 0 ){ tooltip_text = str_replace(tooltip_text,"\"","'"); } |
||
2079 | break; |
||
2080 | case AUDIO: |
||
2081 | /* |
||
2082 | @ audio x,y,w,h,loop,visible,audiofile location |
||
2083 | @ x,y : left top corner of audio element (in xrange / yrange) |
||
2084 | @ w,y : width and height in pixels |
||
2085 | @ loop : 0 or 1 ( 1 = loop audio fragment) |
||
2086 | @ visible : 0 or 1 (1 = show controls) |
||
2087 | @ audio format may be in *.mp3 or *.ogg |
||
2088 | @ If you are using *.mp3 : be aware that FireFox will not (never) play this ! (Pattented format) |
||
2089 | @ if you are using *.ogg : be aware that Microsoft based systems not support it natively |
||
2090 | @ To avoid problems supply both types (mp3 and ogg) of audiofiles.<br />the program will use both as source tag |
||
2091 | @ 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 /> |
||
2092 | */ |
||
2093 | if( js_function[DRAW_AUDIO] != 1 ){ js_function[DRAW_AUDIO] = 1;} |
||
2094 | for(i=0;i<7;i++){ |
||
2095 | switch(i){ |
||
2096 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */ |
||
2097 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system -> pixel */ |
||
2098 | case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */ |
||
2099 | case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */ |
||
2100 | case 4: int_data[4] = (int) (get_real(infile,0)); if(int_data[4] != TRUE){int_data[4] = FALSE;} break; /* loop boolean */ |
||
2101 | case 5: int_data[5] = (int) (get_real(infile,0)); if(int_data[5] != TRUE){int_data[5] = FALSE;} break; /* visible boolean */ |
||
7842 | bpr | 2102 | case 6: |
7614 | schaersvoo | 2103 | temp = get_string(infile,1); |
2104 | if( strstr(temp,".mp3") != 0 ){ temp = str_replace(temp,".mp3","");} |
||
2105 | if( strstr(temp,".ogg") != 0 ){ temp = str_replace(temp,".ogg","");} |
||
2106 | 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); |
||
2107 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
2108 | 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); |
||
2109 | add_to_buffer(tmp_buffer); |
||
2110 | break; |
||
2111 | default:break; |
||
2112 | } |
||
2113 | } |
||
2114 | reset(); |
||
2115 | break; |
||
2116 | case VIDEO: |
||
2117 | /* |
||
2118 | @ video x,y,w,h,videofile location |
||
2119 | @ x,y : left top corner of audio element (in xrange / yrange) |
||
2120 | @ w,y : width and height in pixels |
||
2121 | @ example:<br />wims getfile : video 0,0,120,120,myvideo.mp4 |
||
2122 | @ video format may be in *.mp4 (todo:other formats) |
||
2123 | */ |
||
2124 | if( js_function[DRAW_VIDEO] != 1 ){ js_function[DRAW_VIDEO] = 1;} |
||
2125 | for(i=0;i<5;i++){ |
||
2126 | switch(i){ |
||
2127 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */ |
||
2128 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system -> pixel */ |
||
2129 | case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */ |
||
2130 | case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */ |
||
2131 | case 4: temp = get_string(infile,1); |
||
2132 | 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); |
||
2133 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
2134 | 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); |
||
2135 | add_to_buffer(tmp_buffer); |
||
2136 | break; |
||
2137 | default:break; |
||
2138 | } |
||
2139 | } |
||
2140 | reset(); |
||
2141 | break; |
||
2142 | case HATCHFILL: |
||
2143 | /* |
||
2144 | @ hatchfill x0,y0,dx,dy,color |
||
2145 | @ x0,y0 in xrange / yrange |
||
2146 | @ distances dx,dy in pixels |
||
2147 | */ |
||
2148 | if( js_function[DRAW_HATCHFILL] != 1 ){ js_function[DRAW_HATCHFILL] = 1;} |
||
2149 | for(i=0;i<5;i++){ |
||
2150 | switch(i){ |
||
2151 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */ |
||
2152 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y */ |
||
2153 | case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */ |
||
2154 | case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/ |
||
2155 | case 4: stroke_color = get_color(infile,1); |
||
2156 | /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */ |
||
2157 | 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); |
||
2158 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
2159 | 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); |
||
2160 | add_to_buffer(tmp_buffer); |
||
2161 | break; |
||
2162 | default:break; |
||
2163 | } |
||
2164 | } |
||
2165 | reset(); |
||
2166 | break; |
||
7647 | schaersvoo | 2167 | case DIAMONDFILL: |
2168 | /* |
||
2169 | @ diamondfill x0,y0,dx,dy,color |
||
2170 | @ x0,y0 in xrange / yrange |
||
2171 | @ distances dx,dy in pixels |
||
2172 | */ |
||
2173 | if( js_function[DRAW_DIAMONDFILL] != 1 ){ js_function[DRAW_DIAMONDFILL] = 1;} |
||
2174 | for(i=0;i<5;i++){ |
||
2175 | switch(i){ |
||
2176 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */ |
||
2177 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y */ |
||
2178 | case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */ |
||
2179 | case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/ |
||
2180 | case 4: stroke_color = get_color(infile,1); |
||
2181 | /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */ |
||
2182 | 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); |
||
2183 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
2184 | 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); |
||
2185 | add_to_buffer(tmp_buffer); |
||
2186 | break; |
||
2187 | default:break; |
||
2188 | } |
||
2189 | } |
||
2190 | reset(); |
||
2191 | break; |
||
7614 | schaersvoo | 2192 | case GRIDFILL: |
2193 | /* |
||
2194 | @ gridfill x0,y0,dx,dy,color |
||
2195 | @ x0,y0 in xrange / yrange |
||
2196 | @ distances dx,dy in pixels |
||
2197 | */ |
||
2198 | if( js_function[DRAW_GRIDFILL] != 1 ){ js_function[DRAW_GRIDFILL] = 1;} |
||
2199 | for(i=0;i<5;i++){ |
||
2200 | switch(i){ |
||
2201 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */ |
||
2202 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y */ |
||
2203 | case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */ |
||
2204 | case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/ |
||
2205 | case 4: stroke_color = get_color(infile,1); |
||
2206 | /* draw_gridfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */ |
||
2207 | 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); |
||
2208 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
2209 | 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); |
||
2210 | add_to_buffer(tmp_buffer); |
||
2211 | break; |
||
2212 | default:break; |
||
2213 | } |
||
2214 | } |
||
2215 | reset(); |
||
2216 | break; |
||
2217 | case DOTFILL: |
||
2218 | /* |
||
2219 | @ dotfill x0,y0,dx,dy,color |
||
2220 | @ x0,y0 in xrange / yrange |
||
2221 | @ distances dx,dy in pixels |
||
2222 | @ radius of dots is linewidth |
||
2223 | */ |
||
2224 | if( js_function[DRAW_DOTFILL] != 1 ){ js_function[DRAW_DOTFILL] = 1;} |
||
2225 | for(i=0;i<5;i++){ |
||
2226 | switch(i){ |
||
2227 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */ |
||
2228 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y */ |
||
2229 | case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */ |
||
2230 | case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/ |
||
2231 | case 4: stroke_color = get_color(infile,1); |
||
2232 | /* draw_dotfill(ctx,x0,y0,dx,dy,radius,color,opacity,xsize,ysize) */ |
||
2233 | 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); |
||
2234 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
2235 | 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); |
||
2236 | add_to_buffer(tmp_buffer); |
||
2237 | break; |
||
2238 | default:break; |
||
2239 | } |
||
2240 | } |
||
2241 | reset(); |
||
2242 | break; |
||
2243 | case IMAGEFILL: |
||
2244 | /* |
||
2245 | @ imagefill dx,dy,image_url |
||
2246 | @ The next suitable <b>filled object</b> will be filled with "image_url" tiled |
||
2247 | @ After pattern filling ,the fill-color should be reset ! |
||
2248 | @ wims getins / image from class directory : imagefill 80,80,my_image.gif |
||
2249 | @ normal url : imagefill 80,80,$module_dir/gifs/my_image.gif |
||
2250 | @ normal url : imagefill 80,80,http://adres/a/b/c/my_image.jpg |
||
2251 | @ if dx,dy is larger than the image, the whole image will be background to the next object. |
||
2252 | */ |
||
2253 | if( js_function[DRAW_IMAGEFILL] != 1 ){ js_function[DRAW_IMAGEFILL] = 1;} |
||
2254 | for(i=0 ;i < 3 ; i++){ |
||
2255 | switch(i){ |
||
2256 | case 0:int_data[0] = (int) (get_real(infile,0));break; |
||
2257 | case 1:int_data[1] = (int) (get_real(infile,0));break; |
||
2258 | case 2: URL = get_string_argument(infile,1); |
||
2259 | 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); |
||
2260 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
2261 | 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); |
||
2262 | add_to_buffer(tmp_buffer); |
||
2263 | break; |
||
2264 | } |
||
2265 | } |
||
2266 | break; |
||
2267 | case FILLTOBORDER: |
||
2268 | /* |
||
2269 | @ filltoborder x,y,bordercolor,color |
||
7842 | bpr | 2270 | @ fill the region of point (x:y) bounded by 'bordercolor' with color 'color' |
7614 | schaersvoo | 2271 | @ any other color will not act as border to the bucket fill |
2272 | @ use this command after all boundary objects are declared. |
||
2273 | @ 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.. |
||
2274 | */ |
||
2275 | for(i=0 ;i < 4 ; i++){ |
||
2276 | switch(i){ |
||
2277 | case 0:double_data[0] = get_real(infile,0);break; |
||
2278 | case 1:double_data[1] = get_real(infile,0);break; |
||
2279 | case 2:bgcolor = get_color(infile,0);break; |
||
2280 | case 3:fill_color = get_color(infile,1); |
||
2281 | if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */ |
||
2282 | js_function[DRAW_FILLTOBORDER] = 1; |
||
2283 | add_js_filltoborder(js_include_file,canvas_root_id); |
||
2284 | } |
||
2285 | decimals = find_number_of_digits(precision); |
||
2286 | string_length = snprintf(NULL,0, "filltoborder(%.*f,%.*f,[%s,%d],[%s,%d]);\n",decimals,double_data[0],decimals,double_data[1],bgcolor,(int) (fill_opacity/0.0039215),fill_color,(int) (fill_opacity/0.0039215)); |
||
2287 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
2288 | snprintf(tmp_buffer,string_length,"filltoborder(%.*f,%.*f,[%s,%d],[%s,%d]);\n",decimals,double_data[0],decimals,double_data[1],bgcolor,(int) (fill_opacity/0.0039215),fill_color,(int) (fill_opacity/0.0039215)); |
||
2289 | add_to_buffer(tmp_buffer); |
||
2290 | break; |
||
2291 | default:break; |
||
2292 | } |
||
2293 | } |
||
2294 | break; |
||
2295 | case FLOODFILL: |
||
2296 | /* |
||
2297 | @ floodfill x,y,color |
||
2298 | @ alternative syntax: fill x,y,color |
||
2299 | @ fill the region of point (x:y) with color 'color' |
||
2300 | @ any other color or size of picture (borders of picture) will act as border to the bucket fill |
||
2301 | @ use this command after all boundary objects are declared. |
||
2302 | @ Use command 'clickfill,color' for user click driven flood fill. |
||
2303 | @ NOTE: recognised colour boundaries are in the "drag canvas" e.g. only for objects that can be set draggable / clickable |
||
2304 | @ 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.. |
||
2305 | */ |
||
2306 | for(i=0 ;i < 4 ; i++){ |
||
2307 | switch(i){ |
||
2308 | case 0:double_data[0] = get_real(infile,0);break; |
||
2309 | case 1:double_data[1] = get_real(infile,0);break; |
||
2310 | case 2:fill_color = get_color(infile,1); |
||
2311 | if(js_function[DRAW_FLOODFILL] != 1 ){/* use only once */ |
||
2312 | js_function[DRAW_FLOODFILL] = 1; |
||
2313 | add_js_floodfill(js_include_file,canvas_root_id); |
||
2314 | } |
||
2315 | decimals = find_number_of_digits(precision);/*floodfill(interaction,x,y,[R,G,B,A]) */ |
||
2316 | string_length = snprintf(NULL,0, "floodfill(0,%.*f,%.*f,[%s,%d]);\n",decimals,double_data[0],decimals,double_data[1],fill_color,(int) (fill_opacity/0.0039215)); |
||
2317 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
2318 | snprintf(tmp_buffer,string_length,"floodfill(0,%.*f,%.*f,[%s,%d]);\n",decimals,double_data[0],decimals,double_data[1],fill_color,(int) (fill_opacity/0.0039215)); |
||
2319 | add_to_buffer(tmp_buffer); |
||
2320 | break; |
||
2321 | default:break; |
||
2322 | } |
||
2323 | } |
||
2324 | break; |
||
2325 | case CLICKFILLMARGE: |
||
2326 | clickfillmarge = (int) (get_real(infile,1)); |
||
2327 | break; |
||
2328 | /* |
||
2329 | @ clickfillmarge int |
||
2330 | @ default 20 (pixels) |
||
2331 | @ when using command "clickfill fillcolor" a coloured area my be reverted ("undo") <br />back to background colour with a middle mouse click<br />when the click is in a 40x40 rectangle around a stored m mouseclick (userdraw_x[] and userdraw_y[]) |
||
2332 | */ |
||
2333 | case CLICKFILL: |
||
2334 | /* |
||
2335 | @ clickfill fillcolor |
||
2336 | @ user left mouse click will floodfill the area with fillcolor |
||
2337 | @ multiple areas may be coloured |
||
2338 | @ the coloured areas can be removed (changed to "bgcolor") by middle / right mouse click <br />(if the click is in an 40x40 pixel area of the click coordinate that "painted" the area) |
||
2339 | @ the answer will be read as the (x:y) click coordinates per coloured area |
||
2340 | @ background color of main div may be set by using command "bgcolor color" |
||
2341 | @ may not be combined with command "userdraw" |
||
2342 | @ NOTE: recognised colour boundaries are in the "drag canvas" e.g. only for objects that can be set draggable / clickable |
||
2343 | */ |
||
2344 | fill_color = get_color(infile,1); |
||
2345 | if(js_function[DRAW_FLOODFILL] != 1 ){/* use only once */ |
||
2346 | js_function[DRAW_FLOODFILL] = 1; |
||
2347 | add_js_floodfill(js_include_file,canvas_root_id); |
||
2348 | } |
||
7653 | schaersvoo | 2349 | fprintf(js_include_file,"\n<!-- begin command clickfill -->\nvar marge_xy = %d;var userdraw_x = new Array();var userdraw_y = new Array();var user_clickfill_cnt = 0;\ncanvas_div.addEventListener(\"mousedown\",clickfill,false);function clickfill(evt){var x = evt.clientX - findPosX(canvas_div) + document.body.scrollLeft + document.documentElement.scrollLeft;var y = evt.clientY - findPosY(canvas_div) + document.body.scrollTop + document.documentElement.scrollTop;if(evt.which != 1){for(var p=0; p < user_clickfill_cnt;p++){if(userdraw_x[p] + marge_xy > x && userdraw_x[p] - marge_xy < x){if(userdraw_y[p] + marge_xy > y && userdraw_y[p] - marge_xy < y){if(confirm(\"Clear ?\")){floodfill(1,userdraw_x[p],userdraw_y[p],canvas_div.style.backgroundColor);userdraw_x.splice(p,2);userdraw_y.splice(p,2);user_clickfill_cnt--;return;};};};};};userdraw_x[user_clickfill_cnt] = x;userdraw_y[user_clickfill_cnt] = y;user_clickfill_cnt++;floodfill(1,x,y,[%s,%d]);};",clickfillmarge,fill_color,(int) (fill_opacity/0.0039215)); |
7614 | schaersvoo | 2350 | add_read_canvas(1); |
2351 | break; |
||
2352 | case SETPIXEL: |
||
2353 | /* |
||
2354 | @ setpixel x,y,color |
||
2355 | @ A "point" with diameter 1 pixel centeres at (x:y) in xrange / yrange |
||
2356 | @ pixels can not be dragged or clicked |
||
2357 | @ "pixelsize = 1" may be changed by command "pixelsize int" |
||
2358 | */ |
||
2359 | if( js_function[DRAW_PIXELS] != 1 ){ js_function[DRAW_PIXELS] = 1;} |
||
2360 | for(i=0;i<3;i++){ |
||
2361 | switch(i){ |
||
2362 | case 0: double_data[0] = get_real(infile,0); break; /* x */ |
||
2363 | case 1: double_data[1] = get_real(infile,0); break; /* y */ |
||
2364 | case 2: stroke_color = get_color(infile,1); |
||
2365 | string_length = snprintf(NULL,0,"draw_setpixel([%f],[%f],\"%s\",%.2f,%d);\n",double_data[0],double_data[1],stroke_color,stroke_opacity,pixelsize); |
||
2366 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
2367 | snprintf(tmp_buffer,string_length,"draw_setpixel([%f],[%f],\"%s\",%.2f,%d);\n",double_data[0],double_data[1],stroke_color,stroke_opacity,pixelsize); |
||
2368 | add_to_buffer(tmp_buffer); |
||
2369 | break; |
||
2370 | default:break; |
||
2371 | } |
||
2372 | } |
||
2373 | reset(); |
||
2374 | break; |
||
2375 | case PIXELSIZE: |
||
2376 | /* |
||
2377 | @ pixelsize int |
||
2378 | @ in case you want to deviate from default pixelsize = 1... |
||
2379 | */ |
||
2380 | pixelsize = (int) get_real(infile,1); |
||
2381 | break; |
||
2382 | case PIXELS: |
||
2383 | /* |
||
2384 | @ pixels color,x1,y1,x2,y2,x3,y3... |
||
2385 | @ Draw "points" with diameter 1 pixel |
||
2386 | @ pixels can not be dragged or clicked |
||
2387 | @ "pixelsize = 1" may be changed by command "pixelsize int" |
||
2388 | */ |
||
2389 | if( js_function[DRAW_PIXELS] != 1 ){ js_function[DRAW_PIXELS] = 1;} |
||
2390 | stroke_color=get_color(infile,0); |
||
2391 | i=0; |
||
2392 | c=0; |
||
2393 | while( ! done ){ /* get next item until EOL*/ |
||
2394 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
2395 | for( c = 0 ; c < 2; c++){ |
||
2396 | if(c == 0 ){ |
||
2397 | double_data[i] = get_real(infile,0); |
||
2398 | i++; |
||
2399 | } |
||
2400 | else |
||
2401 | { |
||
2402 | double_data[i] = get_real(infile,1); |
||
2403 | i++; |
||
2404 | } |
||
2405 | } |
||
2406 | } |
||
2407 | decimals = find_number_of_digits(precision); |
||
2408 | /* *double_xy2js_array(double xy[],int len,int decimals) */ |
||
2409 | string_length = snprintf(NULL,0, "draw_setpixel(%s,\"%s\",%.2f,%d);\n",double_xy2js_array(double_data,i,decimals),stroke_color,stroke_opacity,pixelsize); |
||
2410 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
2411 | snprintf(tmp_buffer,string_length,"draw_setpixel(%s,\"%s\",%.2f,%d);\n",double_xy2js_array(double_data,i,decimals),stroke_color,stroke_opacity,pixelsize); |
||
2412 | add_to_buffer(tmp_buffer); |
||
2413 | break; |
||
2414 | case REPLYFORMAT: |
||
2415 | /* |
||
2416 | @ replyformat number |
||
2417 | @ default values should be fine ! |
||
7782 | schaersvoo | 2418 | @ 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,x2:y2:text2...x_n:y_n:text_n</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>21 = (x1:y1) (x2:y2) ... (x_n:y_n)<br />verbatim coordinate return</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>replyformat 23 : can only be used for drawtype 'polyline'<br />a typical click sequence in drawtype polyline isx1,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></ul> |
7614 | schaersvoo | 2419 | @ note to 'userdraw text,color' : the x / y-values are in pixels ! (this to avoid too lengthy calculations in javascript...) |
2420 | */ |
||
2421 | reply_format = (int) get_real(infile,1); |
||
2422 | break; |
||
2423 | case LEGENDCOLORS: |
||
2424 | /* |
||
2425 | @ legendcolors color1:color2:color3:...:color_n |
||
2426 | @ will be used to colour a legend |
||
2427 | @ make sure the number of colours match the number of legend items |
||
7842 | bpr | 2428 | @ command 'legend' in case of 'piechart' and 'barchart' will use these colours per default (no need to specify 'legendcolors' |
7614 | schaersvoo | 2429 | */ |
2430 | temp = get_string(infile,1); |
||
2431 | if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); } |
||
7653 | schaersvoo | 2432 | fprintf(js_include_file,"var legendcolors%d = [\"%s\"];",canvas_root_id,temp); |
7614 | schaersvoo | 2433 | break; |
2434 | case LEGEND: |
||
2435 | /* |
||
2436 | @ legend string1:string2:string3....string_n |
||
2437 | @ will be used to create a legend for a graph |
||
7842 | bpr | 2438 | @ also see command 'piechart' |
7614 | schaersvoo | 2439 | */ |
2440 | temp = get_string(infile,1); |
||
2441 | if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); } |
||
7653 | schaersvoo | 2442 | fprintf(js_include_file,"var legend%d = [\"%s\"];",canvas_root_id,temp); |
7614 | schaersvoo | 2443 | break; |
2444 | case XLABEL: |
||
2445 | /* |
||
2446 | @ xlabel some_string |
||
2447 | @ will be used to create a label for the x-axis (label is in quadrant I) |
||
2448 | @ can only be used together with command 'grid'<br />not depending on keywords 'axis' and 'axisnumbering' |
||
7842 | bpr | 2449 | @ font setting: italic Courier, fontsize will be slightly larger (fontsize + 4) |
7614 | schaersvoo | 2450 | */ |
2451 | temp = get_string(infile,1); |
||
7653 | schaersvoo | 2452 | fprintf(js_include_file,"var xaxislabel = \"%s\";",temp); |
7614 | schaersvoo | 2453 | break; |
2454 | case YLABEL: |
||
2455 | /* |
||
2456 | @ ylabel some_string |
||
7842 | bpr | 2457 | @ will be used to create a (vertical) label for the y-axis (label is in quadrant I) |
7614 | schaersvoo | 2458 | @ can only be used together with command 'grid'<br />not depending on keywords 'axis' and 'axisnumbering' |
7842 | bpr | 2459 | @ font setting: italic Courier, fontsize will be slightly larger (fontsize + 4) |
7614 | schaersvoo | 2460 | */ |
2461 | temp = get_string(infile,1); |
||
7653 | schaersvoo | 2462 | fprintf(js_include_file,"var yaxislabel = \"%s\";",temp); |
7614 | schaersvoo | 2463 | break; |
2464 | case LINEGRAPH: /* scheme: var linegraph_0 = [ 'stroke_color','line_width','use_dashed' ,'dashtype0','dashtype1','x1','y1',...,'x_n','y_n'];*/ |
||
2465 | /* |
||
2466 | @ linegraph x1:y1;x2:y2...x_n:y;2 |
||
2467 | @ will plot your data in a graph |
||
2468 | @ may only to be used together with command 'grid' |
||
2469 | @ can be used together with freestyle x-axis/y-axis texts : see commands 'xaxis' and 'yaxis' |
||
2470 | @ use command 'legend' to provide an optional legend in right-top-corner |
||
2471 | @ also see command 'piechart' |
||
2472 | @ multiple linegraphs may be used in a single plot |
||
2473 | @ <ul><li>use command 'strokecolor' before command 'linegraph' to set the color of this graph</li><li>use command 'linewidth' before command 'linegraph' to set linewidth of this graph</li><li>use command 'dashed' before command 'linegraph' to set dashing of the graph</li><li>if dashing is set, use command 'dashtype' before command 'linegraph' to set the type of dashing of the graph</li></ul> |
||
7842 | bpr | 2474 | */ |
7614 | schaersvoo | 2475 | temp = get_string(infile,1); |
2476 | if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); } |
||
7653 | schaersvoo | 2477 | 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); |
7614 | schaersvoo | 2478 | linegraph_cnt++; |
2479 | reset(); |
||
2480 | break; |
||
2481 | case CLOCK: |
||
2482 | /* |
||
2483 | @ clock x,y,r(px),H,M,S,type hourglass,interactive [ ,H_color,M_color,S_color,background_color,foreground_color ] |
||
2484 | @ type hourglass:<br />type = 0 : only segments<br />type = 1 : only numbers<br />type = 2 : numbers and segments |
||
2485 | @ colors are optional: if not defined, default values will be used<br />default colours: clock 0,0,60,4,35,45,1,2,[space]<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,white,white,black,yellow |
||
2486 | @ 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></ul> |
||
2487 | @ canvasdraw will not check validity of colornames...the javascript console is your best friend |
||
2488 | @ no combinations with other reply_types allowed, for now |
||
7783 | schaersvoo | 2489 | @ if interactive, 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 |
7614 | schaersvoo | 2490 | */ |
2491 | if( js_function[DRAW_CLOCK] != 1 ){ js_function[DRAW_CLOCK] = 1;} |
||
2492 | |||
2493 | /* var clock = function(xc,yc,radius,H,M,S,h_color,m_color,s_color,bg_color,fg_color) */ |
||
2494 | for(i=0;i<9;i++){ |
||
2495 | switch(i){ |
||
2496 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* xc */ |
||
2497 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* yc */ |
||
2498 | case 2: int_data[2] = get_real(infile,0);break;/* radius in px */ |
||
2499 | case 3: int_data[3] = get_real(infile,0);break;/* hours */ |
||
2500 | case 4: int_data[4] = get_real(infile,0);break;/* minutes */ |
||
2501 | case 5: int_data[5] = get_real(infile,0);break;/* seconds */ |
||
7783 | schaersvoo | 2502 | 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 */ |
7614 | schaersvoo | 2503 | case 7: int_data[7] = (int)(get_real(infile,0));/* interactive 0,1,2*/ |
7783 | schaersvoo | 2504 | switch(int_data[7]){ |
2505 | case 0:break; |
||
2506 | case 1:if(clock_cnt == 0){ |
||
2507 | if( reply_format == 0 ){ |
||
7614 | schaersvoo | 2508 | reply_format = 18; /* user sets clock */ |
7783 | schaersvoo | 2509 | /* 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"); |
7614 | schaersvoo | 2510 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
2511 | 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"); |
||
2512 | add_to_buffer(tmp_buffer); |
||
7783 | schaersvoo | 2513 | */ |
2514 | fprintf(js_include_file,"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"); |
||
2515 | } |
||
2516 | else |
||
2517 | { |
||
2518 | canvas_error("interactive clock may not be used together with other reply_types..."); |
||
2519 | } |
||
2520 | fprintf(stdout,"<br /><input type=\"button\" onclick=\"javascript:set_clock(%d,1,1)\" value=\"H+\" /><input type=\"button\" onclick=\"javascript:set_clock(%d,1,-1)\" value=\"H-\" /><input type=\"button\" onclick=\"javascript:set_clock(%d,2,1)\" value=\"M+\" /><input type=\"button\" onclick=\"javascript:set_clock(%d,2,-1)\" value=\"M-\" /><input type=\"button\" onclick=\"javascript:set_clock(%d,3,1)\" value=\"S+\" /><input type=\"button\" onclick=\"javascript:set_clock(%d,3,-1)\" value=\"S-\" /><br />",clock_cnt,clock_cnt,clock_cnt,clock_cnt,clock_cnt,clock_cnt); |
||
2521 | } |
||
2522 | break; |
||
2523 | case 2:if( reply_format == 0 ){ |
||
2524 | reply_format = 19; /* "onclick */ |
||
2525 | fprintf(js_include_file,"\n<!-- begin onclick handler for clocks -->\nvar reply = new Array();\n\ncanvas_div.addEventListener( 'mousedown', user_click,false);\n\nfunction user_click(evt){if(evt.which == 1){var canvas_rect = clock_canvas.getBoundingClientRect();\nvar x = evt.clientX - canvas_rect.left;\nvar y = evt.clientY - canvas_rect.top;\nvar p = 0;\nvar name;\nvar t = true;\nwhile(t){try{name = eval('clocks'+p);\nif( x < name.xc + name.radius && x > name.xc - name.radius ){if( y < name.yc + name.radius && y > name.yc - name.radius ){reply[0] = p;\nname = 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);\n};\n}else{clock_ctx.clearRect(name.xc-name.radius,name.yc-name.radius,name.xc+name.radius,name.yc+name.radius);\nname = 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};\np++;\n}catch(e){t=false;\n};\n};\n};\n};\n\n<!-- end onclick handler for clocks -->\n "); |
||
2526 | } |
||
2527 | else |
||
2528 | { |
||
2529 | if( reply_format != 19){ |
||
7614 | schaersvoo | 2530 | canvas_error("clickable clock(s) may not be used together with other reply_types..."); |
2531 | } |
||
7783 | schaersvoo | 2532 | } |
2533 | break; |
||
2534 | default: canvas_error("interactive must be set 0,1 or 2");break; |
||
2535 | } |
||
2536 | break; |
||
7842 | bpr | 2537 | case 8: |
7614 | schaersvoo | 2538 | temp = get_string(infile,1); |
2539 | if( strstr( temp,",") != 0 ){ temp = str_replace(temp,",","\",\""); } |
||
2540 | if( strlen(temp) < 1 ){temp = ",\"\",\"\",\"\",\"\",\"\"";} |
||
2541 | 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); |
||
2542 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
2543 | 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); |
||
2544 | add_to_buffer(tmp_buffer); |
||
2545 | clock_cnt++; |
||
2546 | break; |
||
2547 | default:break; |
||
2548 | } |
||
2549 | } |
||
2550 | break; |
||
2551 | case BARCHART: |
||
2552 | /* |
||
2553 | @ barchart x_1:y_1:color_1:x_2:y_2:color_2:...x_n:y_n:color_n |
||
2554 | @ will be used to create a legend for bar graph |
||
2555 | @ may only to be used together with command 'grid' |
||
2556 | @ can be used together with freestyle x-axis/y-axis texts : see commands 'xaxis' and 'yaxis' |
||
2557 | @ use command 'legend' to provide an optional legend in right-top-corner |
||
7842 | bpr | 2558 | @ also see command 'piechart' |
7614 | schaersvoo | 2559 | */ |
2560 | temp = get_string(infile,1); |
||
2561 | if( strstr( temp,":" ) != 0 ){ temp = str_replace(temp,":","\",\""); } |
||
7653 | schaersvoo | 2562 | fprintf(js_include_file,"var barchart%d = [\"%s\"];",canvas_root_id,temp); |
7614 | schaersvoo | 2563 | reset(); |
2564 | break; |
||
2565 | case PIECHART: |
||
2566 | /* |
||
2567 | @ piechart xc,yc,radius,'data+colorlist' |
||
2568 | @ (xc : yc) center of circle diagram in xrange/yrange |
||
2569 | @ radius in pixels |
||
2570 | @ 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 |
||
2571 | @ example data+colorlist : 132:red:23565:green:323:black:234324:orange:23434:yellow:2543:white |
||
2572 | @ the number of colors must match the number of data. |
||
2573 | @ use command "opacity 0-255,0-255" to adjust fill_opacity of colours |
||
2574 | @ use command "legend string1:string2:...:string_n" 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... |
||
2575 | */ |
||
7842 | bpr | 2576 | if( js_function[DRAW_PIECHART] != 1 ){ js_function[DRAW_PIECHART] = 1;} |
7614 | schaersvoo | 2577 | for(i=0;i<5;i++){ |
2578 | switch(i){ |
||
2579 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */ |
||
2580 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y */ |
||
2581 | case 2: int_data[2] = (int)(get_real(infile,1));break;/* radius*/ |
||
2582 | case 3: temp = get_string(infile,1); |
||
2583 | if( strstr( temp, ":" ) != 0 ){ temp = str_replace(temp,":","\",\"");} |
||
2584 | 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,font_size,font_family); |
||
2585 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
2586 | 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,font_size,font_family); |
||
2587 | add_to_buffer(tmp_buffer); |
||
2588 | break; |
||
2589 | default:break; |
||
2590 | } |
||
2591 | } |
||
2592 | reset(); |
||
2593 | break; |
||
2594 | case STATUS: |
||
2595 | fprintf(js_include_file,"\nstatus=\"waiting\";\n"); |
||
2596 | break; |
||
7735 | schaersvoo | 2597 | case XLOGBASE: |
7729 | schaersvoo | 2598 | /* |
7735 | schaersvoo | 2599 | @ xlogbase number |
2600 | @ sets the logbase number for the x-axis |
||
7729 | schaersvoo | 2601 | @ default value 10 |
7735 | schaersvoo | 2602 | @ use together with commands xlogscale / xylogscale |
7729 | schaersvoo | 2603 | */ |
7735 | schaersvoo | 2604 | fprintf(js_include_file,"xlogbase=%d;",(int)(get_real(infile,1))); |
7729 | schaersvoo | 2605 | break; |
7735 | schaersvoo | 2606 | case YLOGBASE: |
2607 | /* |
||
2608 | @ ylogbase number |
||
2609 | @ sets the logbase number for the y-axis |
||
2610 | @ default value 10 |
||
2611 | @ use together with commands ylogscale / xylogscale |
||
2612 | */ |
||
2613 | fprintf(js_include_file,"ylogbase=%d;",(int)(get_real(infile,1))); |
||
2614 | break; |
||
7614 | schaersvoo | 2615 | case XLOGSCALE: |
2616 | /* |
||
7735 | schaersvoo | 2617 | @ xlogscale ymajor,yminor,majorcolor,minorcolor |
2618 | @ the x/y-range are set using commands 'xrange xmin,xmax' and 'yrange ymin,ymax' |
||
2619 | @ ymajor is the major step on the y-axis; yminor is the divisor for the y-step |
||
2620 | @ the linewidth is set using command 'linewidth int' |
||
2621 | @ the opacity of major / minor grid lines is set by command 'opacity [0-255],[0-255]' |
||
2622 | @ default logbase number = 10 ... when needed , set the logbase number with command 'xlogbase number' |
||
7842 | bpr | 2623 | @ 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> |
7735 | schaersvoo | 2624 | @ note: the complete canvas will be used for the 'log paper' |
2625 | @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values |
||
2626 | @ note: command 'mouse color,fontsize' will show the real values in the logpaper.<br />\ |
||
7842 | bpr | 2627 | @ note: when using something like 'xrange 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') |
7735 | schaersvoo | 2628 | @ note: in case of userdraw , the use of keyword 'userinput_xy' may be handy ! |
2629 | @ attention: keyword 'snaptogrid' may not lead to the desired result... |
||
7614 | schaersvoo | 2630 | */ |
7735 | schaersvoo | 2631 | if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");} |
2632 | if( js_function[DRAW_XLOGSCALE] != 1 ){ js_function[DRAW_XLOGSCALE] = 1;} |
||
2633 | for(i=0;i<4;i++){ |
||
2634 | switch(i){ |
||
2635 | case 0: double_data[0] = get_real(infile,0);break; /* xmajor */ |
||
2636 | case 1: int_data[0] = (int) (get_real(infile,0));break; /* xminor */ |
||
2637 | case 2: stroke_color = get_color(infile,0); break; |
||
7842 | bpr | 2638 | case 3: fill_color = get_color(infile,1); |
7779 | schaersvoo | 2639 | 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); |
7735 | schaersvoo | 2640 | tmp_buffer = my_newmem(string_length+1); |
7779 | schaersvoo | 2641 | 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 | 2642 | fprintf(js_include_file,"use_xlogscale=1;snap_y = %f;snap_x = xlogbase;",double_data[0]/int_data[0]); |
2643 | add_to_buffer(tmp_buffer); |
||
2644 | break; |
||
2645 | default:break; |
||
2646 | } |
||
2647 | } |
||
7614 | schaersvoo | 2648 | break; |
2649 | case YLOGSCALE: |
||
7729 | schaersvoo | 2650 | /* |
2651 | @ ylogscale xmajor,xminor,majorcolor,minorcolor |
||
2652 | @ the x/y-range are set using commands 'xrange xmin,xmax' and 'yrange ymin,ymax' |
||
2653 | @ xmajor is the major step on the x-axis; xminor is the divisor for the x-step |
||
2654 | @ the linewidth is set using command 'linewidth int' |
||
2655 | @ the opacity of major / minor grid lines is set by command 'opacity [0-255],[0-255]' |
||
7735 | schaersvoo | 2656 | @ default logbase number = 10 ... when needed , set the logbase number with command 'ylogbase number' |
7842 | bpr | 2657 | @ 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> |
7729 | schaersvoo | 2658 | @ note: the complete canvas will be used for the 'log paper' |
2659 | @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values |
||
2660 | @ note: command 'mouse color,fontsize' will show the real values in the logpaper.<br />\ |
||
7842 | bpr | 2661 | @ 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') |
7735 | schaersvoo | 2662 | @ note: in case of userdraw , the use of keyword 'userinput_xy' may be handy ! |
2663 | @ attention: keyword 'snaptogrid' may not lead to the desired result... |
||
7729 | schaersvoo | 2664 | */ |
2665 | if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");} |
||
2666 | if( js_function[DRAW_YLOGSCALE] != 1 ){ js_function[DRAW_YLOGSCALE] = 1;} |
||
2667 | for(i=0;i<4;i++){ |
||
2668 | switch(i){ |
||
2669 | case 0: double_data[0] = get_real(infile,0);break; /* xmajor */ |
||
2670 | case 1: int_data[0] = (int) (get_real(infile,0));break; /* xminor */ |
||
2671 | case 2: stroke_color = get_color(infile,0); break; |
||
7842 | bpr | 2672 | case 3: fill_color = get_color(infile,1); |
7779 | schaersvoo | 2673 | 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 | 2674 | tmp_buffer = my_newmem(string_length+1); |
7779 | schaersvoo | 2675 | 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 | 2676 | fprintf(js_include_file,"use_ylogscale=1;snap_x = %f;snap_y = ylogbase;",double_data[0]/int_data[0]); |
7729 | schaersvoo | 2677 | add_to_buffer(tmp_buffer); |
2678 | break; |
||
2679 | default:break; |
||
2680 | } |
||
2681 | } |
||
7614 | schaersvoo | 2682 | break; |
2683 | case XYLOGSCALE: |
||
7735 | schaersvoo | 2684 | /* |
2685 | @ xylogscale majorcolor,minorcolor |
||
2686 | @ the x/y-range are set using commands 'xrange xmin,xmax' and 'yrange ymin,ymax' |
||
2687 | @ the linewidth is set using command 'linewidth int' |
||
2688 | @ the opacity of major / minor grid lines is set by command 'opacity [0-255],[0-255]' |
||
2689 | @ default logbase number = 10 ... when needed , set the logbase number with command 'xlogbase number' and/or 'ylogbase number' |
||
7842 | bpr | 2690 | @ 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> |
7735 | schaersvoo | 2691 | @ note: the complete canvas will be used for the 'log paper' |
2692 | @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values |
||
2693 | @ note: command 'mouse color,fontsize' will show the real values in the logpaper.<br />\ |
||
7842 | bpr | 2694 | @ 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') |
7735 | schaersvoo | 2695 | @ note: in case of userdraw , the use of keyword 'userinput_xy' may be handy ! |
2696 | @ attention: keyword 'snaptogrid' may not lead to the desired result... |
||
2697 | */ |
||
2698 | if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");} |
||
2699 | if( js_function[DRAW_XYLOGSCALE] != 1 ){ js_function[DRAW_XYLOGSCALE] = 1;} |
||
2700 | for(i=0;i<2;i++){ |
||
2701 | switch(i){ |
||
2702 | case 0: stroke_color = get_color(infile,0); break; |
||
7842 | bpr | 2703 | case 1: fill_color = get_color(infile,1); |
7779 | schaersvoo | 2704 | 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); |
7735 | schaersvoo | 2705 | tmp_buffer = my_newmem(string_length+1); |
7779 | schaersvoo | 2706 | 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); |
7735 | schaersvoo | 2707 | fprintf(js_include_file,"use_xlogscale=1;use_ylogscale=1;snap_x = xlogbase;snap_y = ylogbase;"); |
2708 | add_to_buffer(tmp_buffer); |
||
2709 | break; |
||
2710 | default:break; |
||
2711 | } |
||
2712 | } |
||
2713 | break; |
||
7614 | schaersvoo | 2714 | default:sync_input(infile); |
2715 | break; |
||
2716 | } |
||
7842 | bpr | 2717 | } |
7614 | schaersvoo | 2718 | /* we are done parsing script file */ |
7842 | bpr | 2719 | |
7614 | schaersvoo | 2720 | /* if needed, add generic draw functions (grid / xml etc) to buffer : these are no draggable shapes / objects ! */ |
2721 | add_javascript_functions(js_function,canvas_root_id); |
||
2722 | /* add read_canvas() etc functions if needed */ |
||
2723 | if( reply_format > 0 ){ add_read_canvas(reply_format);} |
||
7797 | schaersvoo | 2724 | if( use_pan_and_zoom == TRUE ){ |
2725 | /* in case of zooming ... */ |
||
7729 | schaersvoo | 2726 | fprintf(js_include_file,"\n<!-- some extra global stuff : need to rethink panning and zooming !!! -->\n\ |
7797 | schaersvoo | 2727 | precision = %d;var xmin_start=xmin;var xmax_start=xmax;\ |
7729 | schaersvoo | 2728 | var ymin_start=ymin;var ymax_start=xmax;\ |
2729 | var zoom_x_increment=0;var zoom_y_increment=0;\ |
||
2730 | var pan_x_increment=0;var pan_y_increment=0;\ |
||
2731 | if(use_ylogscale == 0 ){\ |
||
2732 | zoom_x_increment = (xmax - xmin)/20;zoom_y_increment = (xmax - xmin)/20;pan_x_increment = (xmax - xmin)/20;pan_y_increment = (ymax - ymin)/20;\ |
||
2733 | }else{\ |
||
2734 | zoom_x_increment = (xmax - xmin)/20;\ |
||
2735 | pan_x_increment = (xmax - xmin)/20;\ |
||
2736 | };\ |
||
7653 | schaersvoo | 2737 | function start_canvas%d(type){\ |
2738 | switch(type){\ |
||
7729 | schaersvoo | 2739 | case 0:xmin = xmin + zoom_x_increment;ymin = ymin + zoom_y_increment;xmax = xmax - zoom_x_increment;ymax = ymax - zoom_y_increment;break;\ |
2740 | 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 | 2741 | case 2:xmin = xmin - pan_x_increment;ymin = ymin ;xmax = xmax - pan_x_increment;ymax = ymax;break;\ |
2742 | case 3:xmin = xmin + pan_x_increment;ymin = ymin ;xmax = xmax + pan_x_increment;ymax = ymax;break;\ |
||
2743 | case 4:xmin = xmin;ymin = ymin - pan_y_increment ;xmax = xmax;ymax = ymax - pan_y_increment;break;\ |
||
2744 | case 5:xmin = xmin;ymin = ymin + pan_y_increment ;xmax = xmax;ymax = ymax + pan_y_increment;break;\ |
||
2745 | case 6:location.reload();break;\ |
||
2746 | default:break;\ |
||
2747 | };\ |
||
2748 | if(xmax<=xmin){xmin=xmin_start;xmax=xmax_start;};\ |
||
2749 | if(ymax<=ymin){ymin=ymin_start;ymax=ymax_start;};\ |
||
2750 | try{dragstuff.Zoom(xmin,xmax,ymin,ymax);}catch(e){}\ |
||
2751 | %s\ |
||
2752 | };\ |
||
7797 | schaersvoo | 2753 | start_canvas%d(333);\ |
7614 | schaersvoo | 2754 | };\n\ |
2755 | <!-- end wims_canvas_function -->\n\ |
||
7797 | schaersvoo | 2756 | wims_canvas_function%d();\n",precision,canvas_root_id,buffer,canvas_root_id,canvas_root_id); |
2757 | } |
||
2758 | else |
||
2759 | { |
||
2760 | /* no zoom, just add buffer */ |
||
2761 | fprintf(js_include_file,"\n<!-- add buffer -->\n\ |
||
2762 | %s\ |
||
2763 | };\n\ |
||
2764 | <!-- end wims_canvas_function -->\n\ |
||
2765 | wims_canvas_function%d();\n",buffer,canvas_root_id); |
||
2766 | } |
||
7614 | schaersvoo | 2767 | /* done writing the javascript include file */ |
2768 | fclose(js_include_file); |
||
2769 | |||
2770 | } |
||
2771 | |||
2772 | /* if using a tooltip, this should always be printed to the *.phtml file, so stdout */ |
||
2773 | if(use_tooltip == TRUE){ |
||
2774 | add_js_tooltip(canvas_root_id,tooltip_text,bgcolor,xsize,ysize); |
||
2775 | } |
||
2776 | exit(EXIT_SUCCESS); |
||
2777 | } |
||
2778 | /* end main() */ |
||
2779 | |||
2780 | /****************************************************************************** |
||
2781 | ** |
||
2782 | ** sync_input |
||
2783 | ** |
||
2784 | ** synchronises input line - reads to end of line, leaving file pointer |
||
2785 | ** at first character of next line. |
||
2786 | ** |
||
2787 | ** Used by: |
||
2788 | ** main program - error handling. |
||
2789 | ** |
||
2790 | ******************************************************************************/ |
||
2791 | void sync_input(FILE *infile) |
||
2792 | { |
||
2793 | int c = 0; |
||
2794 | |||
7658 | schaersvoo | 2795 | if( c == '\n' || c == ';' ) return; |
2796 | while( ( (c=getc(infile)) != EOF ) && (c != '\n') && (c != '\r') && (c != ';')) ; |
||
7614 | schaersvoo | 2797 | if( c == EOF ) finished = 1; |
7658 | schaersvoo | 2798 | if( c == '\n' || c == '\r' || c == ';') line_number++; |
7614 | schaersvoo | 2799 | return; |
2800 | } |
||
2801 | |||
2802 | /******************************************************************************/ |
||
2803 | |||
2804 | char *str_replace(const char *str, const char *old, const char *new){ |
||
2805 | /* http://creativeandcritical.net/str-replace-c/ */ |
||
2806 | if(strlen(str) > MAX_BUFFER){canvas_error("string argument too big");} |
||
2807 | char *ret, *r; |
||
2808 | const char *p, *q; |
||
2809 | size_t oldlen = strlen(old); |
||
2810 | size_t count = 0; |
||
2811 | size_t retlen = 0; |
||
2812 | size_t newlen = strlen(new); |
||
2813 | if (oldlen != newlen){ |
||
2814 | for (count = 0, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen){ |
||
2815 | count++; |
||
2816 | retlen = p - str + strlen(p) + count * (newlen - oldlen); |
||
2817 | } |
||
7842 | bpr | 2818 | } |
7614 | schaersvoo | 2819 | else |
2820 | { |
||
2821 | retlen = strlen(str); |
||
2822 | } |
||
7842 | bpr | 2823 | |
7614 | schaersvoo | 2824 | if ((ret = malloc(retlen + 1)) == NULL){ |
2825 | ret = NULL; |
||
2826 | canvas_error("string argument is NULL"); |
||
2827 | } |
||
2828 | else |
||
2829 | { |
||
2830 | for (r = ret, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen) { |
||
2831 | size_t l = q - p; |
||
2832 | memcpy(r, p, l); |
||
2833 | r += l; |
||
2834 | memcpy(r, new, newlen); |
||
2835 | r += newlen; |
||
2836 | } |
||
2837 | strcpy(r, p); |
||
2838 | } |
||
2839 | return ret; |
||
2840 | } |
||
2841 | |||
2842 | /******************************************************************************/ |
||
2843 | /* |
||
2844 | avoid the use of ctypes.h for tolower() toupper(); |
||
2845 | it gives trouble in FreeBSD 9.0 / 9.1 when used in a chroot environment (C library bug) : Undefined symbol "_ThreadRuneLocale" |
||
2846 | Upper case -> Lower case : c = c - 'A'+ 'a'; |
||
2847 | Lower case -> Upper case c = c + 'A' - 'a'; |
||
7848 | bpr | 2848 | |
7614 | schaersvoo | 2849 | int tolower(int c){ |
2850 | if(c <= 'Z'){ |
||
2851 | if (c >= 'A'){ |
||
2852 | return c - 'A' + 'a'; |
||
2853 | } |
||
2854 | } |
||
2855 | return c; |
||
7842 | bpr | 2856 | } |
7614 | schaersvoo | 2857 | |
2858 | int toupper(int c){ |
||
2859 | if(c >= 'a' && c <= 'z'){ |
||
2860 | return c + 'A' - 'a'; |
||
2861 | } |
||
2862 | return c; |
||
7842 | bpr | 2863 | } |
7848 | bpr | 2864 | */ |
7614 | schaersvoo | 2865 | char *get_color(FILE *infile , int last){ |
2866 | int c,i = 0,is_hex = 0; |
||
2867 | char temp[MAX_COLOR_STRING], *string; |
||
7748 | schaersvoo | 2868 | while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != ',' ) && ( c != ';' ) ){ |
7614 | schaersvoo | 2869 | if( i > MAX_COLOR_STRING ){ canvas_error("colour string is too big ... ? ");} |
2870 | if( c == '#' ){ |
||
2871 | is_hex = 1; |
||
2872 | } |
||
2873 | if( c != ' '){ |
||
2874 | temp[i]=tolower(c); |
||
2875 | i++; |
||
2876 | } |
||
2877 | } |
||
7842 | bpr | 2878 | if( ( c == '\n' || c == EOF || c == ';' ) && last == 0){canvas_error("expecting more arguments in command");} |
7748 | schaersvoo | 2879 | if( c == '\n' || c == ';' ){ done = TRUE; line_number++; } |
7614 | schaersvoo | 2880 | if( c == EOF ){finished = 1;} |
2881 | if( finished == 1 && last != 1 ){ canvas_error("expected more arguments");} |
||
2882 | temp[i]='\0'; |
||
2883 | if( strlen(temp) == 0 ){ canvas_error("expected a colorname or hexnumber, but found nothing !!");} |
||
2884 | if( is_hex == 1 ){ |
||
2885 | char red[3], green[3], blue[3]; |
||
2886 | red[0] = toupper(temp[1]); red[1] = toupper(temp[2]); red[2] = '\0'; |
||
2887 | green[0] = toupper(temp[3]); green[1] = toupper(temp[4]); green[2] = '\0'; |
||
2888 | blue[0] = toupper(temp[5]); blue[1] = toupper(temp[6]); blue[2] = '\0'; |
||
2889 | int r = (int) strtol(red, NULL, 16); |
||
2890 | int g = (int) strtol(green, NULL, 16); |
||
2891 | int b = (int) strtol(blue, NULL, 16); |
||
2892 | string = (char *)my_newmem(12); |
||
2893 | snprintf(string,11,"%d,%d,%d",r,g,b); |
||
2894 | return string; |
||
2895 | } |
||
2896 | else |
||
2897 | { |
||
2898 | string = (char *)my_newmem(sizeof(temp)); |
||
2899 | snprintf(string,sizeof(temp),"%s",temp); |
||
2900 | for( i = 0; i <= NUMBER_OF_COLORNAMES ; i++ ){ |
||
2901 | if( strcmp( colors[i].name , string ) == 0 ){ |
||
2902 | return colors[i].rgb; |
||
2903 | } |
||
2904 | } |
||
2905 | } |
||
2906 | /* not found...return error */ |
||
2907 | free(string);string = NULL; |
||
2908 | canvas_error("I was expecting a color name or hexnumber...but found nothing."); |
||
2909 | return NULL; |
||
2910 | } |
||
2911 | |||
2912 | char *get_string(FILE *infile,int last){ /* last = 0 : more arguments ; last=1 final argument */ |
||
2913 | int c,i=0; |
||
2914 | char temp[MAX_BUFFER], *string; |
||
7748 | schaersvoo | 2915 | while(( (c=getc(infile)) != EOF ) && ( c != '\n') ){ |
7614 | schaersvoo | 2916 | temp[i]=c; |
2917 | i++; |
||
2918 | if(i > MAX_BUFFER){ canvas_error("string size too big...repeat command to fit string");break;} |
||
2919 | } |
||
7842 | bpr | 2920 | if( ( c == '\n' || c == EOF ) && last == 0){canvas_error("expecting more arguments in command");} |
7748 | schaersvoo | 2921 | if( c == '\n') { done = TRUE; line_number++; } |
7614 | schaersvoo | 2922 | if( c == EOF ) { |
2923 | finished = 1; |
||
2924 | if( last != 1 ){ canvas_error("expected more arguments");} |
||
2925 | } |
||
2926 | temp[i]='\0'; |
||
2927 | if( strlen(temp) == 0 ){ canvas_error("expected a word or string, but found nothing !!");} |
||
2928 | string=(char *)my_newmem(strlen(temp)); |
||
2929 | snprintf(string,sizeof(temp),"%s",temp); |
||
2930 | return string; |
||
2931 | } |
||
2932 | |||
2933 | char *get_string_argument(FILE *infile,int last){ /* last = 0 : more arguments ; last=1 final argument */ |
||
2934 | int c,i=0; |
||
2935 | char temp[MAX_BUFFER], *string; |
||
7748 | schaersvoo | 2936 | while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != ',')){ |
7614 | schaersvoo | 2937 | temp[i]=c; |
2938 | i++; |
||
2939 | if(i > MAX_BUFFER){ canvas_error("string size too big...will cut it off");break;} |
||
2940 | } |
||
7842 | bpr | 2941 | if( ( c == '\n' || c == EOF) && last == 0){canvas_error("expecting more arguments in command");} |
7748 | schaersvoo | 2942 | if( c == '\n') { line_number++; } |
7614 | schaersvoo | 2943 | if( c == EOF ) {finished = 1;} |
2944 | if( finished == 1 && last != 1 ){ canvas_error("expected more arguments");} |
||
2945 | temp[i]='\0'; |
||
2946 | if( strlen(temp) == 0 ){ canvas_error("expected a word or string (without comma) , but found nothing !!");} |
||
2947 | string=(char *)my_newmem(sizeof(temp)); |
||
2948 | snprintf(string,sizeof(temp),"%s",temp); |
||
2949 | done = TRUE; |
||
2950 | return string; |
||
2951 | } |
||
2952 | |||
2953 | double get_real(FILE *infile, int last){ /* accept anything that looks like an number ? last = 0 : more arguments ; last=1 final argument */ |
||
2954 | int c,i=0,found_calc = 0; |
||
2955 | double y; |
||
2956 | char tmp[MAX_INT]; |
||
7658 | schaersvoo | 2957 | while(( (c=getc(infile)) != EOF ) && ( c != ',') && (c != '\n') && ( c != ';')){ |
7614 | schaersvoo | 2958 | if( c != ' ' ){ |
7842 | bpr | 2959 | /* |
2960 | libmatheval will segfault when for example: "xrange -10,+10" or "xrange -10,10+" is used |
||
7614 | schaersvoo | 2961 | We will check after assert() if it's a NULL pointer...and exit program via : |
2962 | canvas_error("I'm having trouble parsing your \"expression\" "); |
||
2963 | */ |
||
7842 | bpr | 2964 | if( i == 0 && c == '+' ){ |
7614 | schaersvoo | 2965 | continue; |
7842 | bpr | 2966 | } |
7614 | schaersvoo | 2967 | else |
2968 | { |
||
2969 | if(canvas_iscalculation(c) != 0){ |
||
2970 | found_calc = 1; |
||
2971 | c = tolower(c); |
||
2972 | } |
||
2973 | tmp[i] = c; |
||
2974 | i++; |
||
2975 | } |
||
2976 | } |
||
2977 | if( i > MAX_INT - 1){canvas_error("number too large");} |
||
2978 | } |
||
7842 | bpr | 2979 | if( ( c == '\n' || c == EOF || c == ';' ) && last == 0){canvas_error("expecting more arguments in command");} |
7658 | schaersvoo | 2980 | if( c == '\n' || c == ';' ){ done = TRUE; line_number++; } |
7614 | schaersvoo | 2981 | if( c == EOF ){done = TRUE ; finished = 1;} |
2982 | tmp[i]='\0'; |
||
2983 | if( strlen(tmp) == 0 ){canvas_error("expected a number , but found nothing !!");} |
||
2984 | if( found_calc == 1 ){ /* use libmatheval to calculate 2*pi/3 */ |
||
7848 | bpr | 2985 | void *f = eval_create(tmp); |
7614 | schaersvoo | 2986 | assert(f);if( f == NULL ){canvas_error("I'm having trouble parsing your \"expression\" ") ;} |
7848 | bpr | 2987 | y = eval_x(f, 1); |
7614 | schaersvoo | 2988 | /* if function is bogus; y = 1 : so no core dumps */ |
7848 | bpr | 2989 | eval_destroy(f); |
7614 | schaersvoo | 2990 | } |
2991 | else |
||
2992 | { |
||
2993 | y = atof(tmp); |
||
2994 | } |
||
2995 | return y; |
||
2996 | } |
||
2997 | void canvas_error(char *msg){ |
||
7748 | schaersvoo | 2998 | fprintf(stdout,"\n</script><hr /><span style=\"color:red\">FATAL syntax error:line %d : %s</span><hr />",line_number-1,msg); |
7614 | schaersvoo | 2999 | finished = 1; |
3000 | exit(EXIT_SUCCESS); |
||
3001 | } |
||
3002 | |||
3003 | |||
3004 | /* convert x/y coordinates to pixel */ |
||
3005 | int x2px(double x){ |
||
3006 | return x*xsize/(xmax - xmin) - xsize*xmin/(xmax - xmin); |
||
3007 | } |
||
3008 | |||
3009 | int y2px(double y){ |
||
3010 | return -1*y*ysize/(ymax - ymin) + ymax*ysize/(ymax - ymin); |
||
3011 | } |
||
3012 | |||
3013 | double px2x(int x){ |
||
3014 | return (x*(xmax - xmin)/xsize + xmin); |
||
3015 | } |
||
3016 | double px2y(int y){ |
||
3017 | return (y*(ymax - ymin)/ysize + ymin); |
||
3018 | } |
||
3019 | |||
3020 | void add_to_buffer(char *tmp){ |
||
3021 | if( tmp == NULL || tmp == 0 ){ canvas_error("nothing to add_to_buffer()...");} |
||
3022 | /* do we have enough space left in buffer[MAX_BUFFER] ? */ |
||
3023 | int space_left = (int) (sizeof(buffer) - strlen(buffer)); |
||
3024 | if( space_left > strlen(tmp)){ |
||
3025 | strncat(buffer,tmp,space_left - 1);/* add safely "tmp" to the string buffer */ |
||
3026 | } |
||
3027 | else |
||
3028 | { |
||
3029 | canvas_error("buffer is too big\n"); |
||
3030 | } |
||
3031 | tmp = NULL;free(tmp); |
||
3032 | return; |
||
3033 | } |
||
3034 | |||
3035 | void reset(){ |
||
3036 | if(use_filled == TRUE){use_filled = FALSE;} |
||
3037 | if(use_dashed == TRUE){use_dashed = FALSE;} |
||
3038 | if(use_translate == TRUE){use_translate = FALSE;} |
||
3039 | if(use_rotate == TRUE){use_rotate = FALSE;} |
||
3040 | onclick = 0; |
||
3041 | } |
||
3042 | |||
3043 | |||
3044 | |||
3045 | /* What reply format in read_canvas(); |
||
3046 | |||
3047 | note:if userdraw is combined with inputfields...every "userdraw" based answer will append "\n" and inputfield.value() |
||
3048 | 1 = x1,x2,x3,x4....x_n |
||
3049 | y1,y2,y3,y4....y_n |
||
3050 | |||
3051 | x/y in pixels |
||
3052 | |||
3053 | 2 = x1,x2,x3,x4....x_n |
||
3054 | y1,y2,y3,y4....y_n |
||
3055 | x/y in xrange / yrange coordinate system |
||
3056 | |||
3057 | 3 = x1,x2,x3,x4....x_n |
||
3058 | y1,y2,y3,y4....y_n |
||
3059 | r1,r2,r3,r4....r_n |
||
3060 | |||
7842 | bpr | 3061 | x/y in pixels |
7614 | schaersvoo | 3062 | r in pixels |
3063 | |||
3064 | 4 = x1,x2,x3,x4....x_n |
||
3065 | y1,y2,y3,y4....y_n |
||
3066 | r1,r2,r3,r4....r_n |
||
3067 | |||
3068 | x/y in xrange / yrange coordinate system |
||
3069 | r in pixels |
||
3070 | |||
3071 | 5 = Ax1,Ax2,Ax3,Ax4....Ax_n |
||
3072 | Ay1,Ay2,Ay3,Ay4....Ay_n |
||
3073 | Bx1,Bx2,Bx3,Bx4....Bx_n |
||
3074 | By1,By2,By3,By4....By_n |
||
3075 | Cx1,Cx2,Cx3,Cx4....Cx_n |
||
3076 | Cy1,Cy2,Cy3,Cy4....Cy_n |
||
3077 | .... |
||
3078 | Zx1,Zx2,Zx3,Zx4....Zx_n |
||
3079 | Zy1,Zy2,Zy3,Zy4....Zy_n |
||
7842 | bpr | 3080 | |
7614 | schaersvoo | 3081 | x/y in pixels |
3082 | |||
3083 | 6 = Ax1,Ax2,Ax3,Ax4....Ax_n |
||
3084 | Ay1,Ay2,Ay3,Ay4....Ay_n |
||
3085 | Bx1,Bx2,Bx3,Bx4....Bx_n |
||
3086 | By1,By2,By3,By4....By_n |
||
3087 | Cx1,Cx2,Cx3,Cx4....Cx_n |
||
3088 | Cy1,Cy2,Cy3,Cy4....Cy_n |
||
3089 | .... |
||
3090 | Zx1,Zx2,Zx3,Zx4....Zx_n |
||
3091 | Zy1,Zy2,Zy3,Zy4....Zy_n |
||
3092 | |||
3093 | x/y in xrange / yrange coordinate system |
||
7842 | bpr | 3094 | |
7614 | schaersvoo | 3095 | 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n |
7842 | bpr | 3096 | |
7614 | schaersvoo | 3097 | x/y in pixels |
3098 | |||
3099 | 8 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n |
||
7842 | bpr | 3100 | |
7614 | schaersvoo | 3101 | x/y in xrange / yrange coordinate system |
3102 | |||
7842 | bpr | 3103 | 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n |
7614 | schaersvoo | 3104 | |
3105 | x/y in pixels |
||
3106 | |||
7842 | bpr | 3107 | 10 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n |
7614 | schaersvoo | 3108 | |
3109 | x/y in xrange / yrange coordinate system |
||
3110 | |||
3111 | 11 = Ax1,Ay1,Ax2,Ay2 |
||
3112 | Bx1,By1,Bx2,By2 |
||
3113 | Cx1,Cy1,Cx2,Cy2 |
||
3114 | Dx1,Dy1,Dx2,Dy2 |
||
3115 | ...... |
||
3116 | Zx1,Zy1,Zx2,Zy2 |
||
7842 | bpr | 3117 | |
7614 | schaersvoo | 3118 | x/y in xrange / yrange coordinate system |
3119 | |||
3120 | 12 = Ax1,Ay1,Ax2,Ay2 |
||
3121 | Bx1,By1,Bx2,By2 |
||
3122 | Cx1,Cy1,Cx2,Cy2 |
||
3123 | Dx1,Dy1,Dx2,Dy2 |
||
3124 | ...... |
||
3125 | Zx1,Zy1,Zx2,Zy2 |
||
7842 | bpr | 3126 | |
7614 | schaersvoo | 3127 | x/y in pixels |
3128 | |||
3129 | 13 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2,Cx1:Cy1:Cx2:Cy2,Dx1:Dy1:Dx2:Dy2, ... ,Zx1:Zy1:Zx2:Zy2 |
||
3130 | |||
3131 | x/y in xrange / yrange coordinate system |
||
3132 | 14 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2....Zx1:Zy1:Zx2:Zy2 |
||
3133 | x/y in pixels |
||
3134 | 15 = reply from inputfields,textareas |
||
3135 | reply1,reply2,reply3,...,reply_n |
||
3136 | |||
3137 | 16 = read mathml inputfields only |
||
3138 | |||
3139 | 17 = read userdraw text only (x1:y1:text1,x2:y2:text2...x_n:y_n:text_n |
||
3140 | when ready : calculate size_t of string via snprintf(NULL,0,"blah blah..."); |
||
3141 | |||
3142 | 18 = read clock(s) : H1:M1:S1,H2:M2:S2,...H_n:M_n:S_n |
||
3143 | 19 = return clicked object number (analogue to shape-library onclick) |
||
3144 | 20 = return x/y-data in x-range/y-range of all 'draggable' images |
||
3145 | 21 = return verbatim coordinates (x1:y1) (x2:y2)...(x_n:y_n) |
||
3146 | 22 = array : x1,y1,x2,y2,x3,y3,x4,y4...x_n,y_n |
||
3147 | x/y in xrange / yrange coordinate system |
||
7842 | bpr | 3148 | 23 = answertype for a polyline : remove multiple occurences due to reclick on a point to create next polyline segment |
7614 | schaersvoo | 3149 | */ |
3150 | |||
3151 | |||
3152 | void add_read_canvas(int type_reply){ |
||
3153 | /* just 1 reply type allowed */ |
||
3154 | switch(type_reply){ |
||
3155 | /* TO DO |
||
7842 | bpr | 3156 | !!!! NEED TO SIMPLIFY !!!! |
7614 | schaersvoo | 3157 | answers may have: |
3158 | x-values,y-values,r-values,input-fields,mathml-inputfields,text-typed answers |
||
3159 | */ |
||
3160 | case 1: fprintf(js_include_file,"\ |
||
7653 | schaersvoo | 3161 | \n<!-- begin function 1 read_canvas() -->\n\ |
7614 | schaersvoo | 3162 | function read_canvas(){\ |
3163 | if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\ |
||
3164 | if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\ |
||
3165 | var p = 0;var input_reply = new Array();\ |
||
3166 | if( document.getElementById(\"canvas_input0\")){\ |
||
3167 | var t = 0;\ |
||
3168 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
3169 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
3170 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
3171 | p++;\ |
||
3172 | };\ |
||
3173 | t++;\ |
||
3174 | };\ |
||
3175 | };\ |
||
3176 | if( typeof userdraw_text != 'undefined' ){\ |
||
3177 | return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+input_reply + \"\\n\"+userdraw_text;\ |
||
3178 | }\ |
||
3179 | else\ |
||
3180 | {\ |
||
3181 | return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+input_reply;\ |
||
3182 | }\ |
||
3183 | }\ |
||
3184 | else\ |
||
3185 | {\ |
||
3186 | if( typeof userdraw_text != 'undefined' ){\ |
||
3187 | return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_text;\ |
||
3188 | }\ |
||
3189 | else\ |
||
3190 | {\ |
||
3191 | return userdraw_x+\"\\n\"+userdraw_y;\ |
||
3192 | }\ |
||
3193 | };\ |
||
3194 | };\ |
||
3195 | this.read_canvas = read_canvas;\n\ |
||
7653 | schaersvoo | 3196 | <!-- end function 1 read_canvas() -->"); |
7614 | schaersvoo | 3197 | break; |
3198 | case 2: fprintf(js_include_file,"\ |
||
7653 | schaersvoo | 3199 | \n<!-- begin function 2 read_canvas() -->\n\ |
7614 | schaersvoo | 3200 | function read_canvas(){\ |
3201 | if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\ |
||
3202 | var reply_x = new Array();var reply_y = new Array();var p = 0;\ |
||
3203 | while(userdraw_x[p]){\ |
||
3204 | reply_x[p] = px2x(userdraw_x[p]);\ |
||
3205 | reply_y[p] = px2y(userdraw_y[p]);\ |
||
3206 | p++;\ |
||
3207 | };\ |
||
3208 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
3209 | if( document.getElementById(\"canvas_input0\")){\ |
||
3210 | var p = 0;var input_reply = new Array();\ |
||
3211 | if( document.getElementById(\"canvas_input0\")){\ |
||
3212 | var t = 0;\ |
||
3213 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
3214 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
3215 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
3216 | p++;\ |
||
3217 | };\ |
||
3218 | t++;\ |
||
3219 | };\ |
||
3220 | };\ |
||
3221 | if( typeof userdraw_text != 'undefined' ){\ |
||
3222 | return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
3223 | }\ |
||
3224 | else\ |
||
3225 | {\ |
||
3226 | return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply;\ |
||
3227 | }\ |
||
3228 | }\ |
||
3229 | else\ |
||
3230 | {\ |
||
3231 | if( typeof userdraw_text != 'undefined' ){\ |
||
3232 | return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_text;\ |
||
3233 | }\ |
||
3234 | else\ |
||
3235 | {\ |
||
3236 | return reply_x+\"\\n\"+reply_y;\ |
||
3237 | };\ |
||
3238 | };\ |
||
3239 | };\ |
||
3240 | this.read_canvas = read_canvas;\n\ |
||
7653 | schaersvoo | 3241 | <!-- end function 2 read_canvas() -->"); |
7614 | schaersvoo | 3242 | break; |
3243 | case 3: fprintf(js_include_file,"\ |
||
7653 | schaersvoo | 3244 | \n<!-- begin function 3 read_canvas() -->\n\ |
7614 | schaersvoo | 3245 | function read_canvas(){\ |
3246 | if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\ |
||
3247 | if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\ |
||
3248 | var p = 0;var input_reply = new Array();\ |
||
3249 | if( document.getElementById(\"canvas_input0\")){\ |
||
3250 | var t = 0;\ |
||
3251 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
3252 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
3253 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
3254 | p++;\ |
||
3255 | };\ |
||
3256 | t++;\ |
||
3257 | };\ |
||
3258 | };\ |
||
3259 | if( typeof userdraw_text != 'undefined' ){\ |
||
3260 | return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
3261 | }\ |
||
3262 | else\ |
||
3263 | {\ |
||
3264 | return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+input_reply;\ |
||
3265 | }\ |
||
3266 | }\ |
||
3267 | else\ |
||
3268 | {\ |
||
3269 | if( typeof userdraw_text != 'undefined' ){\ |
||
3270 | return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+userdrawW_text;\ |
||
3271 | }\ |
||
3272 | else\ |
||
3273 | {\ |
||
3274 | return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius;\ |
||
3275 | }\ |
||
3276 | }\ |
||
3277 | };\ |
||
3278 | this.read_canvas = read_canvas;\n\ |
||
7653 | schaersvoo | 3279 | <!-- end function 3 read_canvas() -->"); |
7614 | schaersvoo | 3280 | break; |
3281 | case 4: fprintf(js_include_file,"\ |
||
7653 | schaersvoo | 3282 | \n<!-- begin function 4 read_canvas() -->\n\ |
7614 | schaersvoo | 3283 | function read_canvas(){\ |
3284 | var reply_x = new Array();var reply_y = new Array();var p = 0;\ |
||
3285 | while(userdraw_x[p]){\ |
||
3286 | reply_x[p] = px2x(userdraw_x[p]);\ |
||
3287 | reply_y[p] = px2y(userdraw_y[p]);\ |
||
3288 | p++;\ |
||
3289 | };\ |
||
3290 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
3291 | if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\ |
||
3292 | var p = 0;var input_reply = new Array();\ |
||
3293 | if( document.getElementById(\"canvas_input0\")){\ |
||
3294 | var t = 0;\ |
||
3295 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
3296 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
3297 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
3298 | p++;\ |
||
3299 | };\ |
||
3300 | t++;\ |
||
3301 | };\ |
||
3302 | };\ |
||
3303 | if( typeof userdraw_text != 'undefined' ){\ |
||
3304 | return reply_x+\"\\n\"+reply_y +\"\\n\"+userdraw_radius+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
3305 | }\ |
||
3306 | else\ |
||
3307 | {\ |
||
3308 | return reply_x+\"\\n\"+reply_y +\"\\n\"+userdraw_radius+\"\\n\"+input_reply;\ |
||
3309 | }\ |
||
3310 | }\ |
||
3311 | else\ |
||
3312 | {\ |
||
3313 | if( typeof userdraw_text != 'undefined' ){\ |
||
3314 | return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_radius+\"\\n\"+userdraw_text;\ |
||
3315 | }\ |
||
3316 | else\ |
||
3317 | {\ |
||
3318 | return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_radius;\ |
||
3319 | }\ |
||
3320 | };\ |
||
3321 | };\ |
||
3322 | this.read_canvas = read_canvas;\n\ |
||
7653 | schaersvoo | 3323 | <!-- end function 4 read_canvas() -->"); |
7614 | schaersvoo | 3324 | break; |
7842 | bpr | 3325 | /* |
3326 | attention: we reset userdraw_x / userdraw_y : because userdraw_x = [][] userdraw_y = [][] |
||
3327 | used for userdraw multiple paths |
||
7614 | schaersvoo | 3328 | */ |
3329 | case 5: fprintf(js_include_file,"\ |
||
7653 | schaersvoo | 3330 | \n<!-- begin function 5 read_canvas() -->\n\ |
7614 | schaersvoo | 3331 | function read_canvas(){\ |
3332 | var p = 0;\ |
||
3333 | var reply = \"\";\ |
||
3334 | for(p = 0; p < userdraw_x.length;p++){\ |
||
3335 | if(userdraw_x[p] != null ){\ |
||
3336 | reply = reply + userdraw_x[p]+\"\\n\"+userdraw_y[p]+\"\\n\";\ |
||
3337 | };\ |
||
3338 | };\ |
||
3339 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
3340 | userdraw_x = [];userdraw_y = [];\ |
||
3341 | if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\ |
||
3342 | var p = 0;var input_reply = new Array();\ |
||
3343 | if( document.getElementById(\"canvas_input0\")){\ |
||
3344 | var t = 0;\ |
||
3345 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
3346 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
3347 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
3348 | p++;\ |
||
3349 | };\ |
||
3350 | t++;\ |
||
3351 | };\ |
||
3352 | };\ |
||
3353 | if( typeof userdraw_text != 'undefined' ){\ |
||
3354 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
3355 | }\ |
||
3356 | else\ |
||
3357 | {\ |
||
3358 | return reply +\"\\n\"+input_reply;\ |
||
3359 | }\ |
||
3360 | }\ |
||
3361 | else\ |
||
3362 | {\ |
||
3363 | if( typeof userdraw_text != 'undefined' ){\ |
||
3364 | return reply+\"\\n\"+userdraw_text;\ |
||
3365 | }\ |
||
3366 | else\ |
||
3367 | {\ |
||
3368 | return reply;\ |
||
3369 | }\ |
||
3370 | };\ |
||
3371 | };\ |
||
7654 | schaersvoo | 3372 | this.read_canvas = rdad_canvas;\n\ |
7653 | schaersvoo | 3373 | <!-- end function 5 read_canvas() -->"); |
7614 | schaersvoo | 3374 | break; |
7842 | bpr | 3375 | /* |
3376 | attention: we reset userdraw_x / userdraw_y : because userdraw_x = [][] userdraw_y = [][] |
||
3377 | used for userdraw multiple paths |
||
7614 | schaersvoo | 3378 | */ |
3379 | case 6: fprintf(js_include_file,"\ |
||
7653 | schaersvoo | 3380 | \n<!-- begin function 6 read_canvas() -->\n\ |
7614 | schaersvoo | 3381 | function read_canvas(){\ |
3382 | var p = 0;\ |
||
3383 | var reply = \"\";\ |
||
3384 | var tmp_x = new Array();\ |
||
3385 | var tmp_y = new Array();\ |
||
3386 | for(p = 0 ; p < userdraw_x.length; p++){\ |
||
3387 | tmp_x = userdraw_x[p];\ |
||
3388 | tmp_y = userdraw_y[p];\ |
||
3389 | if(tmp_x != null){\ |
||
3390 | for(var i = 0 ; i < tmp_x.length ; i++){\ |
||
3391 | tmp_x[i] = px2x(tmp_x[i]);\ |
||
3392 | tmp_y[i] = px2y(tmp_y[i]);\ |
||
3393 | };\ |
||
3394 | reply = reply + tmp_x + \"\\n\" + tmp_y +\"\\n\";\ |
||
3395 | };\ |
||
3396 | };\ |
||
3397 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
3398 | userdraw_x = [];userdraw_y = [];\ |
||
3399 | if( document.getElementById(\"canvas_input0\") ){\ |
||
3400 | var p = 0;var input_reply = new Array();\ |
||
3401 | if( document.getElementById(\"canvas_input0\")){\ |
||
3402 | var t = 0;\ |
||
3403 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
3404 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
3405 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
3406 | p++;\ |
||
3407 | };\ |
||
3408 | t++;\ |
||
3409 | };\ |
||
3410 | };\ |
||
3411 | if( typeof userdraw_text != 'undefined' ){\ |
||
3412 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
3413 | }\ |
||
3414 | else\ |
||
3415 | {\ |
||
3416 | return reply +\"\\n\"+input_reply;\ |
||
3417 | }\ |
||
3418 | }\ |
||
3419 | else\ |
||
3420 | {\ |
||
3421 | if( typeof userdraw_text != 'undefined' ){\ |
||
3422 | return reply +\"\\n\"+userdraw_text;\ |
||
3423 | }\ |
||
3424 | else\ |
||
3425 | {\ |
||
3426 | return reply;\ |
||
3427 | }\ |
||
3428 | };\ |
||
3429 | };\ |
||
3430 | this.read_canvas = read_canvas;\n\ |
||
7653 | schaersvoo | 3431 | <!-- end function 6 read_canvas() -->"); |
7614 | schaersvoo | 3432 | break; |
3433 | case 7: fprintf(js_include_file,"\ |
||
7653 | schaersvoo | 3434 | \n<!-- begin function 7 read_canvas() -->\n\ |
7614 | schaersvoo | 3435 | function read_canvas(){\ |
3436 | var reply = new Array();\ |
||
3437 | var p = 0;\ |
||
3438 | while(userdraw_x[p]){\ |
||
3439 | reply[p] = userdraw_x[p] +\":\" + userdraw_y[p];\ |
||
3440 | p++;\ |
||
3441 | };\ |
||
3442 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
3443 | if( document.getElementById(\"canvas_input0\") ){\ |
||
3444 | var p = 0;var input_reply = new Array();\ |
||
3445 | if( document.getElementById(\"canvas_input0\")){\ |
||
3446 | var t = 0;\ |
||
3447 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
3448 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
3449 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
3450 | p++;\ |
||
3451 | };\ |
||
3452 | t++;\ |
||
3453 | };\ |
||
3454 | };\ |
||
3455 | if( typeof userdraw_text != 'undefined' ){\ |
||
3456 | return reply+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
3457 | }\ |
||
3458 | else\ |
||
3459 | {\ |
||
3460 | return reply+\"\\n\"+input_reply;\ |
||
3461 | }\ |
||
3462 | };\ |
||
3463 | else\ |
||
3464 | {\ |
||
3465 | if( typeof userdraw_text != 'undefined' ){\ |
||
3466 | return reply+\"\\n\"+userdraw_text;\ |
||
3467 | }\ |
||
3468 | else\ |
||
3469 | {\ |
||
3470 | return reply;\ |
||
3471 | }\ |
||
3472 | };\ |
||
3473 | };\ |
||
3474 | this.read_canvas = read_canvas;\n\ |
||
7653 | schaersvoo | 3475 | <!-- end function 7 read_canvas() -->"); |
7614 | schaersvoo | 3476 | break; |
3477 | case 8: fprintf(js_include_file,"\ |
||
7653 | schaersvoo | 3478 | \n<!-- begin function 8 read_canvas() -->\n\ |
7614 | schaersvoo | 3479 | function read_canvas(){\ |
3480 | var reply = new Array();\ |
||
3481 | var p = 0;\ |
||
3482 | while(userdraw_x[p]){\ |
||
3483 | reply[p] = px2x(userdraw_x[p]) +\":\" + px2y(userdraw_y[p]);\ |
||
3484 | p++;\ |
||
3485 | };\ |
||
3486 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
3487 | if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\ |
||
3488 | var p = 0;var input_reply = new Array();\ |
||
3489 | if( document.getElementById(\"canvas_input0\")){\ |
||
3490 | var t = 0;\ |
||
3491 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
3492 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
3493 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
3494 | p++;\ |
||
3495 | };\ |
||
3496 | t++;\ |
||
3497 | };\ |
||
3498 | };\ |
||
3499 | if( typeof userdraw_text != 'undefined' ){\ |
||
3500 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
3501 | }\ |
||
3502 | else\ |
||
3503 | {\ |
||
3504 | return reply +\"\\n\"+input_reply;\ |
||
3505 | }\ |
||
3506 | }\ |
||
3507 | else\ |
||
3508 | {\ |
||
3509 | if( typeof userdraw_text != 'undefined' ){\ |
||
3510 | return reply +\"\\n\"+userdraw_text;\ |
||
3511 | }\ |
||
3512 | else\ |
||
3513 | {\ |
||
3514 | return reply;\ |
||
3515 | }\ |
||
3516 | };\ |
||
3517 | };\ |
||
3518 | this.read_canvas = read_canvas;\n\ |
||
7653 | schaersvoo | 3519 | <!-- end function 8 read_canvas() -->"); |
7614 | schaersvoo | 3520 | break; |
3521 | case 9: fprintf(js_include_file,"\ |
||
7653 | schaersvoo | 3522 | \n<!-- begin function 9 read_canvas() -->\n\ |
7614 | schaersvoo | 3523 | function read_canvas(){\ |
3524 | var reply = new Array();\ |
||
3525 | var p = 0;\ |
||
3526 | while(userdraw_x[p]){\ |
||
3527 | reply[p] = userdraw_x[p] +\":\" + userdraw_y[p] + \":\" + userdraw_radius[p];\ |
||
3528 | p++;\ |
||
3529 | };\ |
||
3530 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
3531 | if( document.getElementById(\"canvas_input0\") ){\ |
||
3532 | var p = 0;var input_reply = new Array();\ |
||
3533 | if( document.getElementById(\"canvas_input0\")){\ |
||
3534 | var t = 0;\ |
||
3535 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
3536 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
3537 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
3538 | p++;\ |
||
3539 | };\ |
||
3540 | t++;\ |
||
3541 | };\ |
||
3542 | };\ |
||
3543 | if( typeof userdraw_text != 'undefined' ){\ |
||
3544 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
3545 | }\ |
||
3546 | else\ |
||
3547 | {\ |
||
3548 | return reply +\"\\n\"+input_reply;\ |
||
3549 | }\ |
||
3550 | }\ |
||
3551 | else\ |
||
3552 | {\ |
||
3553 | if( typeof userdraw_text != 'undefined' ){\ |
||
3554 | return reply +\"\\n\"+userdraw_text;\ |
||
3555 | }\ |
||
3556 | else\ |
||
3557 | {\ |
||
3558 | return reply;\ |
||
3559 | }\ |
||
3560 | };\ |
||
3561 | };\ |
||
3562 | this.read_canvas = read_canvas;\n\ |
||
7653 | schaersvoo | 3563 | <!-- end function 9 read_canvas() -->"); |
7614 | schaersvoo | 3564 | break; |
3565 | case 10: fprintf(js_include_file,"\ |
||
7653 | schaersvoo | 3566 | \n<!-- begin function 10 read_canvas() -->\n\ |
7614 | schaersvoo | 3567 | function read_canvas(){\ |
3568 | var reply = new Array();\ |
||
3569 | var p = 0;\ |
||
3570 | while(userdraw_x[p]){\ |
||
3571 | reply[p] = px2x(userdraw_x[p]) +\":\" + px2y(userdraw_y[p]) +\":\" + userdraw_radius[p];\ |
||
3572 | p++;\ |
||
3573 | };\ |
||
3574 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
3575 | if( document.getElementById(\"canvas_input0\") ){\ |
||
3576 | var p = 0;var input_reply = new Array();\ |
||
3577 | if( document.getElementById(\"canvas_input0\")){\ |
||
3578 | var t = 0;\ |
||
3579 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
3580 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
3581 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
3582 | p++;\ |
||
3583 | };\ |
||
3584 | t++;\ |
||
3585 | };\ |
||
3586 | };\ |
||
3587 | if( typeof userdraw_text != 'undefined' ){\ |
||
3588 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
3589 | }\ |
||
3590 | else\ |
||
3591 | {\ |
||
3592 | return reply +\"\\n\"+input_reply;\ |
||
3593 | }\ |
||
3594 | }\ |
||
3595 | else\ |
||
3596 | {\ |
||
3597 | if( typeof userdraw_text != 'undefined' ){\ |
||
3598 | return reply +\"\\n\"+userdraw_text;\ |
||
3599 | }\ |
||
3600 | else\ |
||
3601 | {\ |
||
3602 | return reply;\ |
||
3603 | }\ |
||
3604 | };\ |
||
3605 | };\ |
||
3606 | this.read_canvas = read_canvas;\n\ |
||
7653 | schaersvoo | 3607 | <!-- end function 10 read_canvas() -->"); |
7614 | schaersvoo | 3608 | break; |
3609 | case 11: fprintf(js_include_file,"\ |
||
7653 | schaersvoo | 3610 | \n<!-- begin function 11 read_canvas() -->\n\ |
7614 | schaersvoo | 3611 | function read_canvas(){\ |
3612 | var reply = \"\";\ |
||
3613 | var p = 0;\ |
||
3614 | while(userdraw_x[p]){\ |
||
3615 | reply = reply + px2x(userdraw_x[p]) +\",\" + px2y(userdraw_y[p]) +\",\" + px2x(userdraw_x[p+1]) +\",\" + px2y(userdraw_y[p+1]) +\"\\n\" ;\ |
||
3616 | p = p+2;\ |
||
3617 | };\ |
||
3618 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
3619 | if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\ |
||
3620 | var p = 0;var input_reply = new Array();\ |
||
3621 | if( document.getElementById(\"canvas_input0\")){\ |
||
3622 | var t = 0;\ |
||
3623 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
3624 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
3625 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
3626 | p++;\ |
||
3627 | };\ |
||
3628 | t++;\ |
||
3629 | };\ |
||
3630 | };\ |
||
3631 | if( typeof userdraw_text != 'undefined' ){\ |
||
3632 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
3633 | }\ |
||
3634 | else\ |
||
3635 | {\ |
||
3636 | return reply +\"\\n\"+input_reply;\ |
||
3637 | }\ |
||
3638 | }\ |
||
3639 | else\ |
||
3640 | {\ |
||
3641 | if( typeof userdraw_text != 'undefined' ){\ |
||
3642 | return reply +\"\\n\"+userdraw_text;\ |
||
3643 | }\ |
||
3644 | else\ |
||
3645 | {\ |
||
3646 | return reply;\ |
||
3647 | }\ |
||
3648 | };\ |
||
3649 | };\ |
||
3650 | this.read_canvas = read_canvas;\n\ |
||
7653 | schaersvoo | 3651 | <!-- end function 11 read_canvas() -->"); |
7614 | schaersvoo | 3652 | break; |
3653 | case 12: fprintf(js_include_file,"\ |
||
7653 | schaersvoo | 3654 | \n<!-- begin function 12 read_canvas() -->\n\ |
7614 | schaersvoo | 3655 | function read_canvas(){\ |
3656 | var reply = \"\";\ |
||
3657 | var p = 0;\ |
||
3658 | for(p = 0; p< userdraw_x.lenght;p = p+2){\ |
||
3659 | if(userdraw_x[p] != null){\ |
||
3660 | reply = reply + userdraw_x[p] +\",\" + userdraw_y[p] +\",\" + userdraw_x[p+1] +\",\" + userdraw_y[p+1] +\"\\n\" ;\ |
||
3661 | };\ |
||
3662 | };\ |
||
3663 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
3664 | if( document.getElementById(\"canvas_input0\") ){\ |
||
3665 | var p = 0;var input_reply = new Array();\ |
||
3666 | if( document.getElementById(\"canvas_input0\")){\ |
||
3667 | var t = 0;\ |
||
3668 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
3669 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
3670 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
3671 | p++;\ |
||
3672 | };\ |
||
3673 | t++;\ |
||
3674 | };\ |
||
3675 | };\ |
||
3676 | if( typeof userdraw_text != 'undefined' ){\ |
||
3677 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
3678 | }\ |
||
3679 | else\ |
||
3680 | {\ |
||
3681 | return reply +\"\\n\"+input_reply;\ |
||
3682 | }\ |
||
3683 | }\ |
||
3684 | else\ |
||
3685 | {\ |
||
3686 | if( typeof userdraw_text != 'undefined' ){\ |
||
3687 | return reply +\"\\n\"+userdraw_text\ |
||
3688 | }\ |
||
3689 | else\ |
||
3690 | {\ |
||
3691 | return reply;\ |
||
3692 | }\ |
||
3693 | };\ |
||
3694 | };\ |
||
3695 | this.read_canvas = read_canvas;\n\ |
||
7653 | schaersvoo | 3696 | <!-- end function 12 read_canvas() -->"); |
7614 | schaersvoo | 3697 | break; |
3698 | case 13: fprintf(js_include_file,"\ |
||
7653 | schaersvoo | 3699 | \n<!-- begin function 13 read_canvas() -->\n\ |
7614 | schaersvoo | 3700 | function read_canvas(){\ |
3701 | var reply = new Array();\ |
||
3702 | var p = 0;var i = 0;\ |
||
3703 | while(userdraw_x[p]){\ |
||
3704 | reply[i] = px2x(userdraw_x[p]) +\":\" + px2y(userdraw_y[p]) +\":\" + px2x(userdraw_x[p+1]) +\":\" + px2y(userdraw_y[p+1]);\ |
||
3705 | p = p+2;i++;\ |
||
3706 | };\ |
||
3707 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
3708 | if( document.getElementById(\"canvas_input0\") ){\ |
||
3709 | var p = 0;var input_reply = new Array();\ |
||
3710 | if( document.getElementById(\"canvas_input0\")){\ |
||
3711 | var t = 0;\ |
||
3712 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
3713 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
3714 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
3715 | p++;\ |
||
3716 | };\ |
||
3717 | t++;\ |
||
3718 | };\ |
||
3719 | };\ |
||
3720 | if( typeof userdraw_text != 'undefined' ){\ |
||
3721 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
3722 | }\ |
||
3723 | else\ |
||
3724 | {\ |
||
3725 | return reply +\"\\n\"+input_reply;\ |
||
3726 | }\ |
||
3727 | }\ |
||
3728 | else\ |
||
3729 | {\ |
||
3730 | if( typeof userdraw_text != 'undefined' ){\ |
||
3731 | return reply +\"\\n\"+userdraw_text\ |
||
3732 | }\ |
||
3733 | else\ |
||
3734 | {\ |
||
3735 | return reply;\ |
||
3736 | }\ |
||
3737 | };\ |
||
3738 | };\ |
||
3739 | this.read_canvas = read_canvas;\n\ |
||
7653 | schaersvoo | 3740 | <!-- end function 13 read_canvas() -->"); |
7614 | schaersvoo | 3741 | break; |
3742 | case 14: fprintf(js_include_file,"\ |
||
7653 | schaersvoo | 3743 | \n<!-- begin function 14 read_canvas() -->\n\ |
7614 | schaersvoo | 3744 | function read_canvas(){\ |
3745 | var reply = new Array();\ |
||
3746 | var p = 0;var i = 0;\ |
||
3747 | while(userdraw_x[p]){\ |
||
3748 | reply[i] = userdraw_x[p] +\":\" + userdraw_y[p] +\":\" + userdraw_x[p+1] +\":\" + userdraw_y[p+1];\ |
||
3749 | p = p+2;i++;\ |
||
3750 | };\ |
||
3751 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
3752 | if( document.getElementById(\"canvas_input0\") ){\ |
||
3753 | var p = 0;var input_reply = new Array();\ |
||
3754 | if( document.getElementById(\"canvas_input0\")){\ |
||
3755 | var t = 0;\ |
||
3756 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
3757 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
3758 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
3759 | p++;\ |
||
3760 | };\ |
||
3761 | t++;\ |
||
3762 | };\ |
||
3763 | };\ |
||
3764 | if( typeof userdraw_text != 'undefined' ){\ |
||
3765 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
3766 | }\ |
||
3767 | else\ |
||
3768 | {\ |
||
3769 | return reply +\"\\n\"+input_reply;\ |
||
3770 | }\ |
||
3771 | }\ |
||
3772 | else\ |
||
3773 | {\ |
||
3774 | if( typeof userdraw_text != 'undefined' ){\ |
||
3775 | return reply +\"\\n\"+userdraw_text;\ |
||
3776 | }\ |
||
3777 | else\ |
||
3778 | {\ |
||
3779 | return reply;\ |
||
3780 | }\ |
||
3781 | };\ |
||
3782 | };\ |
||
3783 | this.read_canvas = read_canvas;\n\ |
||
7653 | schaersvoo | 3784 | <!-- end function 14 read_canvas() -->"); |
7614 | schaersvoo | 3785 | break; |
3786 | case 15: fprintf(js_include_file,"\ |
||
7653 | schaersvoo | 3787 | \n<!-- begin function 15 read_canvas() -->\n\ |
7614 | schaersvoo | 3788 | function read_canvas(){\ |
3789 | var input_reply = new Array();\ |
||
3790 | var p = 0;\ |
||
3791 | if( document.getElementById(\"canvas_input0\")){\ |
||
3792 | var t = 0;\ |
||
3793 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
3794 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
3795 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
3796 | p++;\ |
||
3797 | };\ |
||
3798 | t++;\ |
||
3799 | };\ |
||
3800 | };\ |
||
3801 | if( typeof userdraw_text != 'undefined' ){\ |
||
3802 | return input_reply +\"\\n\"+userdraw_text;\ |
||
3803 | }\ |
||
3804 | else\ |
||
3805 | {\ |
||
3806 | return input_reply;\ |
||
3807 | };\ |
||
3808 | };\ |
||
3809 | this.read_canvas = read_canvas;\n\ |
||
7653 | schaersvoo | 3810 | <!-- end function 15 read_canvas() -->"); |
7614 | schaersvoo | 3811 | break; |
3812 | case 16: fprintf(js_include_file,"\ |
||
7653 | schaersvoo | 3813 | \n<!-- begin function 16 read_mathml() -->\n\ |
7614 | schaersvoo | 3814 | function read_mathml(){\ |
3815 | var reply = new Array();\ |
||
3816 | var p = 0;\ |
||
3817 | if( document.getElementById(\"mathml0\")){\ |
||
3818 | while(document.getElementById(\"mathml\"+p)){\ |
||
3819 | reply[p] = document.getElementById(\"mathml\"+p).value;\ |
||
3820 | p++;\ |
||
3821 | };\ |
||
3822 | };\ |
||
3823 | return reply;\ |
||
3824 | };\ |
||
3825 | this.read_mathml = read_mathml;\n\ |
||
7653 | schaersvoo | 3826 | <!-- end function 16 read_mathml() -->"); |
7614 | schaersvoo | 3827 | break; |
3828 | case 17: fprintf(js_include_file,"\ |
||
7653 | schaersvoo | 3829 | \n<!-- begin function 17 read_canvas() -->\n\ |
7614 | schaersvoo | 3830 | function read_canvas(){\ |
3831 | if( userdraw_text.length == 0){alert(\"no text typed...\");return;}\ |
||
3832 | return userdraw_text;\ |
||
3833 | };\ |
||
3834 | this.read_canvas = read_canvas;\n\ |
||
7653 | schaersvoo | 3835 | <!-- end function 17 read_canvas() -->"); |
7614 | schaersvoo | 3836 | break; |
3837 | case 18: fprintf(js_include_file,"\ |
||
7653 | schaersvoo | 3838 | \n<!-- begin function 18 read_canvas() -->\n\ |
7614 | schaersvoo | 3839 | function read_canvas(){\ |
3840 | var p = 0;\ |
||
3841 | var reply = new Array();\ |
||
3842 | var name;\ |
||
3843 | var t = true;\ |
||
3844 | while(t){\ |
||
3845 | try{ name = eval('clocks'+p);\ |
||
3846 | reply[p] = parseInt((name.H+name.M/60+name.S/3600)%%12)+\":\"+parseInt((name.M + name.S/60)%%60)+\":\"+(name.S)%%60;p++}catch(e){t=false;};\ |
||
3847 | };\ |
||
3848 | if( p == 0){alert(\"clock(s) not modified...\");return;}\ |
||
3849 | return reply;\ |
||
3850 | };\ |
||
3851 | this.read_canvas = read_canvas;\n\ |
||
7653 | schaersvoo | 3852 | <!-- end function 18 read_canvas() -->"); |
7614 | schaersvoo | 3853 | break; |
3854 | case 19: fprintf(js_include_file,"\ |
||
7653 | schaersvoo | 3855 | \n<!-- begin function 19 read_canvas() -->\n\ |
7614 | schaersvoo | 3856 | function read_canvas(){\ |
3857 | return reply[0];\ |
||
3858 | };\ |
||
3859 | this.read_canvas = read_canvas;\n\ |
||
7653 | schaersvoo | 3860 | <!-- end function 19 read_canvas() -->"); |
7614 | schaersvoo | 3861 | case 20: fprintf(js_include_file,"\ |
7653 | schaersvoo | 3862 | \n<!-- begin function 20 read_canvas() -->\n\ |
7614 | schaersvoo | 3863 | function read_canvas(){\ |
3864 | var len = ext_drag_images.length;\ |
||
3865 | var reply = new Array(len);\ |
||
3866 | for(var p = 0 ; p < len ; p++){\ |
||
3867 | var img = ext_drag_images[p];\ |
||
3868 | reply[p] = px2x(img[6])+\":\"+px2y(img[7]);\ |
||
3869 | };\ |
||
3870 | return reply;\ |
||
3871 | };\ |
||
3872 | this.read_canvas = read_canvas;\n\ |
||
7653 | schaersvoo | 3873 | <!-- end function 20 read_canvas() -->"); |
7614 | schaersvoo | 3874 | break; |
3875 | case 21: fprintf(js_include_file,"\ |
||
7653 | schaersvoo | 3876 | \n<!-- begin function 21 read_canvas() -->\n\ |
7614 | schaersvoo | 3877 | function read_canvas(){\ |
3878 | if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\ |
||
3879 | var reply_coord = new Array();var p = 0;\ |
||
3880 | while(userdraw_x[p]){\ |
||
3881 | reply_coord[p] = \"(\"+px2x(userdraw_x[p])+\":\"+px2y(userdraw_y[p])+\")\";\ |
||
3882 | p++;\ |
||
3883 | };\ |
||
3884 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
3885 | if( document.getElementById(\"canvas_input0\") ){\ |
||
3886 | var p = 0;var input_reply = new Array();\ |
||
3887 | if( document.getElementById(\"canvas_input0\")){\ |
||
3888 | var t = 0;\ |
||
3889 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
3890 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
3891 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
3892 | p++;\ |
||
3893 | };\ |
||
3894 | t++;\ |
||
3895 | };\ |
||
3896 | };\ |
||
3897 | if( typeof userdraw_text != 'undefined' ){\ |
||
3898 | return reply_coord+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
3899 | }\ |
||
3900 | else\ |
||
3901 | {\ |
||
3902 | return reply_coord+\"\\n\"+input_reply;\ |
||
3903 | }\ |
||
3904 | }\ |
||
3905 | else\ |
||
3906 | {\ |
||
3907 | if( typeof userdraw_text != 'undefined' ){\ |
||
3908 | return reply_coord+\"\\n\"+userdraw_text;\ |
||
3909 | }\ |
||
3910 | else\ |
||
3911 | {\ |
||
3912 | return reply_coord;\ |
||
3913 | };\ |
||
3914 | };\ |
||
3915 | };\ |
||
3916 | this.read_canvas = read_canvas;\n\ |
||
7653 | schaersvoo | 3917 | <!-- end function 21 read_canvas() -->"); |
7614 | schaersvoo | 3918 | break; |
3919 | case 22: fprintf(js_include_file,"\ |
||
7653 | schaersvoo | 3920 | \n<!-- begin function 22 read_canvas() -->\n\ |
7614 | schaersvoo | 3921 | function read_canvas(){\ |
3922 | var reply = new Array();\ |
||
3923 | var p = 0;\ |
||
3924 | var idx = 0;\ |
||
3925 | while(userdraw_x[p]){\ |
||
3926 | reply[idx] = px2x(userdraw_x[p]);\ |
||
3927 | idx++;\ |
||
3928 | reply[idx] = px2y(userdraw_y[p]);\ |
||
3929 | idx++;p++;\ |
||
3930 | };\ |
||
3931 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
3932 | if( document.getElementById(\"canvas_input0\") ){\ |
||
3933 | var p = 0;var input_reply = new Array();\ |
||
3934 | if( document.getElementById(\"canvas_input0\")){\ |
||
3935 | var t = 0;\ |
||
3936 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
3937 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
3938 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
3939 | p++;\ |
||
3940 | };\ |
||
3941 | t++;\ |
||
3942 | };\ |
||
3943 | };\ |
||
3944 | if( typeof userdraw_text != 'undefined' ){\ |
||
3945 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
3946 | }\ |
||
3947 | else\ |
||
3948 | {\ |
||
3949 | return reply +\"\\n\"+input_reply;\ |
||
3950 | }\ |
||
3951 | }\ |
||
3952 | else\ |
||
3953 | {\ |
||
3954 | if( typeof userdraw_text != 'undefined' ){\ |
||
3955 | return reply +\"\\n\"+userdraw_text;\ |
||
3956 | }\ |
||
3957 | else\ |
||
3958 | {\ |
||
3959 | return reply;\ |
||
3960 | }\ |
||
3961 | };\ |
||
3962 | };\ |
||
3963 | this.read_canvas = read_canvas;\n\ |
||
7653 | schaersvoo | 3964 | <!-- end function 22 read_canvas() -->"); |
7614 | schaersvoo | 3965 | break; |
7782 | schaersvoo | 3966 | case 23: fprintf(js_include_file,"\ |
3967 | \n<!-- begin function 23 read_canvas() default 5 px marge -->\n\ |
||
3968 | function read_canvas(){\ |
||
3969 | if( userdraw_x.length < 2){alert(\"nothing drawn...\");return;}\ |
||
3970 | var reply_x = new Array();var reply_y = new Array();var p = 0;\ |
||
3971 | var lu = userdraw_x.length;\ |
||
3972 | if( lu != userdraw_y.length ){ alert(\"x / y mismatch !\");return;}\ |
||
3973 | var marge = 5;\ |
||
3974 | reply_x[p] = px2x(userdraw_x[0]);reply_y[p] = px2y(userdraw_y[0]);p++;\ |
||
3975 | for(var i = 0; i < lu - 1 ; i++ ){\ |
||
3976 | if( (userdraw_x[i] < (userdraw_x[i+1] + marge)) && (userdraw_x[i] > (userdraw_x[i+1] - marge)) ){\ |
||
3977 | if( (userdraw_y[i] < (userdraw_y[i+1] + marge)) && (userdraw_y[i] > (userdraw_y[i+1] - marge)) ){\ |
||
3978 | reply_x[p] = px2x(userdraw_x[i]);reply_y[p] = px2y(userdraw_y[i]);\ |
||
3979 | if( isNaN(reply_x[p]) || isNaN(reply_y[p]) ){ alert(\"hmmmm ?\");return; };\ |
||
3980 | p++;\ |
||
3981 | };\ |
||
3982 | };\ |
||
3983 | };\ |
||
3984 | if( document.getElementById(\"canvas_input0\")){\ |
||
3985 | var p = 0;var input_reply = new Array();\ |
||
3986 | if( document.getElementById(\"canvas_input0\")){\ |
||
3987 | var t = 0;\ |
||
3988 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
3989 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
3990 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
3991 | p++;\ |
||
3992 | };\ |
||
3993 | t++;\ |
||
3994 | };\ |
||
3995 | };\ |
||
3996 | if( typeof userdraw_text != 'undefined' ){\ |
||
3997 | return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
3998 | }\ |
||
3999 | else\ |
||
4000 | {\ |
||
4001 | return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply;\ |
||
4002 | }\ |
||
4003 | }\ |
||
4004 | else\ |
||
4005 | {\ |
||
4006 | if( typeof userdraw_text != 'undefined' ){\ |
||
4007 | return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_text;\ |
||
4008 | }\ |
||
4009 | else\ |
||
4010 | {\ |
||
4011 | return reply_x+\"\\n\"+reply_y;\ |
||
4012 | };\ |
||
4013 | };\ |
||
4014 | };\ |
||
4015 | this.read_canvas = read_canvas;\n\ |
||
4016 | <!-- end function 23 read_canvas() -->"); |
||
4017 | break; |
||
7614 | schaersvoo | 4018 | |
4019 | default: canvas_error("hmmm unknown replyformat...");break; |
||
4020 | } |
||
4021 | return; |
||
4022 | } |
||
4023 | |||
4024 | |||
7842 | bpr | 4025 | /* |
4026 | add drawfunction : |
||
7614 | schaersvoo | 4027 | - functions used by userdraw_primitives (circle,rect,path,triangle...) |
4028 | - things not covered by the drag&drop library (static objects like parallel, lattice ,gridfill , imagefill) |
||
4029 | - grid / mathml |
||
4030 | - will not scale or zoom in |
||
4031 | - will not be filled via pixel operations like fill / floodfill / filltoborder / clickfill |
||
7842 | bpr | 4032 | - is printed directly into 'js_include_file' |
7614 | schaersvoo | 4033 | */ |
4034 | |||
4035 | void add_javascript_functions(int js_functions[],int canvas_root_id){ |
||
4036 | int i; |
||
4037 | for(i = 0 ; i < MAX_JS_FUNCTIONS; i++){ |
||
4038 | if( js_functions[i] == 1){ |
||
4039 | switch(i){ |
||
4040 | case DRAG_EXTERNAL_IMAGE: |
||
4041 | fprintf(js_include_file,"\n<!-- drag external images --->\n\ |
||
7653 | schaersvoo | 4042 | var external_canvas = create_canvas%d(7,xsize,ysize);\ |
4043 | var external_ctx = external_canvas.getContext(\"2d\");\ |
||
4044 | var external_canvas_rect = external_canvas.getBoundingClientRect();\ |
||
4045 | canvas_div.addEventListener(\"mousedown\",setxy,false);\ |
||
4046 | canvas_div.addEventListener(\"mouseup\",dragstop,false);\ |
||
4047 | canvas_div.addEventListener(\"mousemove\",dragxy,false);\ |
||
4048 | var selected_image = null;\ |
||
4049 | var ext_image_cnt = 0;\ |
||
4050 | var ext_drag_images = new Array();\ |
||
4051 | function drag_external_image(URL,sx,sy,swidth,sheight,x0,y0,width,height,idx,draggable){\ |
||
4052 | ext_image_cnt = idx;\ |
||
4053 | var image = new Image();\ |
||
4054 | image.src = URL;\ |
||
4055 | image.onload = function(){\ |
||
4056 | if( x0 < 1 ){ x0 = 0; };if( y0 < 1 ){ y0 = 0; };if( sx < 1 ){ sx = 0; };if( sy < 1 ){ sy = 0; };\ |
||
4057 | if( width < 1 ){ width = image.width; };if( height < 1 ){ height = image.height; };\ |
||
4058 | if( swidth < 1 ){ swidth = image.width; };if( sheight < 1 ){ sheight = image.height; };\ |
||
4059 | img = new Array(10);\ |
||
4060 | img[0] = draggable;img[1] = image;img[2] = sx;img[3] = sy;img[4] = swidth;img[5] = sheight;\ |
||
4061 | img[6] = x0;img[7] = y0;img[8] = width;img[9] = height;\ |
||
4062 | ext_drag_images[idx] = img;\ |
||
4063 | external_ctx.drawImage(img[1],img[2],img[3],img[4],img[5],img[6],img[7],img[8],img[9]);\ |
||
4064 | };\ |
||
4065 | };\ |
||
4066 | function dragstop(evt){\ |
||
4067 | selected_image = null;return;\ |
||
4068 | };\ |
||
4069 | function dragxy(evt){\ |
||
4070 | if( selected_image != null ){\ |
||
4071 | var xoff = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);\ |
||
4072 | var yoff = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);\ |
||
4073 | var s_img = ext_drag_images[selected_image];\ |
||
4074 | s_img[6] = evt.clientX - external_canvas_rect.left + xoff;\ |
||
4075 | s_img[7] = evt.clientY - external_canvas_rect.top + yoff;\ |
||
4076 | ext_drag_images[selected_image] = s_img;\ |
||
4077 | external_ctx.clearRect(0,0,xsize,ysize);\ |
||
4078 | for(var i = 0; i <= ext_image_cnt ; i++){\ |
||
4079 | var img = ext_drag_images[i];\ |
||
4080 | external_ctx.drawImage(img[1],img[2],img[3],img[4],img[5],img[6],img[7],img[8],img[9]);\ |
||
4081 | };\ |
||
4082 | };\ |
||
4083 | };\ |
||
4084 | function setxy(evt){\ |
||
4085 | if( ! selected_image && evt.which == 1 ){\ |
||
4086 | var xoff = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);\ |
||
4087 | var yoff = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);\ |
||
4088 | var xm = evt.clientX - external_canvas_rect.left + xoff;\ |
||
4089 | var ym = evt.clientY - external_canvas_rect.top + yoff;\ |
||
4090 | for(var p = 0 ; p <= ext_image_cnt ; p++){\ |
||
4091 | var img = ext_drag_images[p];\ |
||
4092 | if( img[0] == 1 ){\ |
||
4093 | var w = img.width;\ |
||
4094 | var h = img.height;\ |
||
4095 | if( xm > img[6] && xm < img[6] + img[4]){\ |
||
4096 | if( ym > img[7] && ym < img[7] + img[5]){\ |
||
4097 | img[6] = xm;\ |
||
4098 | img[7] = ym;\ |
||
4099 | ext_drag_images[p] = img;\ |
||
4100 | selected_image = p;\ |
||
4101 | dragxy(evt);\ |
||
4102 | };\ |
||
4103 | };\ |
||
4104 | };\ |
||
4105 | };\ |
||
4106 | }\ |
||
4107 | else\ |
||
4108 | {\ |
||
4109 | selected_image = null;\ |
||
4110 | };\ |
||
7614 | schaersvoo | 4111 | };",canvas_root_id); |
4112 | break; |
||
4113 | |||
4114 | case DRAW_EXTERNAL_IMAGE: |
||
4115 | fprintf(js_include_file,"\n<!-- draw external images -->\n\ |
||
4116 | draw_external_image = function(URL,sx,sy,swidth,sheight,x0,y0,width,height,draggable){\ |
||
4117 | var image = new Image();\ |
||
4118 | image.src = URL;\ |
||
4119 | var canvas_bg_div = document.getElementById(\"canvas_div%d\");\ |
||
4120 | image.onload = function(){\ |
||
4121 | if( x0 < 1 ){ x0 = 0; };\ |
||
4122 | if( y0 < 1 ){ y0 = 0; };\ |
||
4123 | if( sx < 1 ){ sx = 0; };\ |
||
4124 | if( sy < 1 ){ sy = 0; };\ |
||
4125 | if( width < 1 ){ width = image.width;};\ |
||
4126 | if( height < 1 ){ height = image.height;};\ |
||
4127 | if( swidth < 1 ){ swidth = image.width;};\ |
||
4128 | if( sheight < 1 ){ sheight = image.height;};\ |
||
4129 | var ml = x0 - sx;\ |
||
4130 | var mh = y0 - sy;\ |
||
4131 | canvas_bg_div.style.backgroundPosition= \"left \"+ml+\"px top \"+mh+\"px\";\ |
||
4132 | canvas_bg_div.style.backgroundSize = width+\"px \"+height+\"px\";\ |
||
4133 | canvas_bg_div.style.backgroundRepeat = \"no-repeat\";\ |
||
4134 | canvas_bg_div.style.backgroundPosition= sx+\"px \"+sy+\"px\";\ |
||
4135 | canvas_bg_div.style.backgroundImage = \"url(\" + URL + \")\";\ |
||
4136 | };\ |
||
7842 | bpr | 4137 | };",canvas_root_id); |
7614 | schaersvoo | 4138 | break; |
7842 | bpr | 4139 | |
7614 | schaersvoo | 4140 | case DRAW_ZOOM_BUTTONS: /* 6 rectangles 15x15 px forbidden zone for drawing : y < ysize - 15*/ |
4141 | fprintf(js_include_file,"\n<!-- draw zoom buttons -->\n\ |
||
4142 | draw_zoom_buttons = function(canvas_type,color,opacity){\ |
||
4143 | var obj;\ |
||
4144 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
4145 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
4146 | }\ |
||
4147 | else\ |
||
4148 | {\ |
||
4149 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
4150 | };\ |
||
4151 | var ctx = obj.getContext(\"2d\");\ |
||
4152 | ctx.font =\"18px Ariel\";\ |
||
4153 | ctx.textAlign = \"right\";\ |
||
4154 | ctx.fillStyle=\"rgba(\"+color+\",\"+opacity+\")\";\ |
||
4155 | ctx.fillText(\"+\",xsize,ysize);\ |
||
4156 | ctx.fillText(\"\\u2212\",xsize - 15,ysize);\ |
||
4157 | ctx.fillText(\"\\u2192\",xsize - 30,ysize-2);\ |
||
4158 | ctx.fillText(\"\\u2190\",xsize - 45,ysize-2);\ |
||
4159 | ctx.fillText(\"\\u2191\",xsize - 60,ysize-2);\ |
||
4160 | ctx.fillText(\"\\u2193\",xsize - 75,ysize-2);\ |
||
4161 | ctx.fillText(\"\\u00D7\",xsize - 90,ysize-2);\ |
||
4162 | ctx.stroke();\ |
||
7653 | schaersvoo | 4163 | };",canvas_root_id,canvas_root_id,canvas_root_id); |
7842 | bpr | 4164 | |
7614 | schaersvoo | 4165 | break; |
4166 | case DRAW_GRIDFILL:/* not used for userdraw */ |
||
4167 | fprintf(js_include_file,"\n<!-- draw gridfill -->\n\ |
||
4168 | draw_gridfill = function(canvas_type,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize){\ |
||
4169 | var obj;\ |
||
4170 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
4171 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
4172 | }\ |
||
4173 | else\ |
||
4174 | {\ |
||
4175 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
4176 | };\ |
||
4177 | var ctx = obj.getContext(\"2d\");\ |
||
4178 | var x,y;\ |
||
4179 | ctx.save();\ |
||
4180 | ctx.strokeStyle=\"rgba(\"+color+\",\"+opacity+\")\";\ |
||
7645 | schaersvoo | 4181 | snap_x = dx;snap_y = dy;\ |
7614 | schaersvoo | 4182 | for( x = x0 ; x < xsize+dx ; x = x + dx ){\ |
4183 | ctx.moveTo(x,y0);\ |
||
4184 | ctx.lineTo(x,ysize);\ |
||
4185 | };\ |
||
7645 | schaersvoo | 4186 | for( y = y0 ; y < ysize+dy; y = y + dy ){\ |
7614 | schaersvoo | 4187 | ctx.moveTo(x0,y);\ |
4188 | ctx.lineTo(xsize,y);\ |
||
4189 | };\ |
||
4190 | ctx.stroke();\ |
||
4191 | ctx.restore();\ |
||
7653 | schaersvoo | 4192 | return;};",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 4193 | break; |
7842 | bpr | 4194 | |
7614 | schaersvoo | 4195 | case DRAW_IMAGEFILL:/* not used for userdraw */ |
4196 | fprintf(js_include_file,"\n<!-- draw imagefill -->\n\ |
||
4197 | draw_imagefill = function(canvas_type,x0,y0,URL,xsize,ysize){\ |
||
4198 | var obj;\ |
||
4199 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
4200 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
4201 | }\ |
||
4202 | else\ |
||
4203 | {\ |
||
4204 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
4205 | };\ |
||
4206 | var ctx = obj.getContext(\"2d\");\ |
||
4207 | ctx.save();\ |
||
4208 | var img = new Image();\ |
||
4209 | img.src = URL;\ |
||
4210 | img.onload = function(){\ |
||
4211 | if( (img.width > xsize-x0) && (img.height > ysize-y0) ){\ |
||
4212 | ctx.drawImage(img,x0,y0,xsize,ysize);\ |
||
4213 | }\ |
||
4214 | else\ |
||
4215 | {\ |
||
4216 | var repeat = \"repeat\";\ |
||
4217 | if(img.width > xsize - x0){\ |
||
4218 | repeat = \"repeat-y\";\ |
||
4219 | }\ |
||
4220 | else\ |
||
4221 | {\ |
||
4222 | if( img.height > ysize -x0 ){\ |
||
4223 | repeat = \"repeat-x\";\ |
||
4224 | }\ |
||
4225 | }\ |
||
4226 | var pattern = ctx.createPattern(img,repeat);\ |
||
4227 | ctx.rect(x0,y0,xsize,ysize);\ |
||
4228 | ctx.fillStyle = pattern;\ |
||
4229 | }\ |
||
4230 | ctx.fill();\ |
||
4231 | };\ |
||
4232 | ctx.restore();\ |
||
4233 | return;\ |
||
7653 | schaersvoo | 4234 | };",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 4235 | break; |
7842 | bpr | 4236 | |
7614 | schaersvoo | 4237 | case DRAW_DOTFILL:/* not used for userdraw */ |
4238 | fprintf(js_include_file,"\n<!-- draw dotfill -->\n\ |
||
4239 | draw_dotfill = function(canvas_type,x0,y0,dx,dy,radius,color,opacity,xsize,ysize){\ |
||
4240 | var obj;\ |
||
4241 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
4242 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
4243 | }\ |
||
4244 | else\ |
||
4245 | {\ |
||
4246 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
4247 | };\ |
||
4248 | var ctx = obj.getContext(\"2d\");\ |
||
4249 | var x,y;\ |
||
4250 | ctx.closePath();\ |
||
4251 | ctx.save();\ |
||
7645 | schaersvoo | 4252 | snap_x = dx;snap_y = dy;\ |
7614 | schaersvoo | 4253 | ctx.fillStyle=\"rgba(\"+color+\",\"+opacity+\")\";\ |
4254 | for( x = x0 ; x < xsize+dx ; x = x + dx ){\ |
||
4255 | for( y = y0 ; y < ysize+dy ; y = y + dy ){\ |
||
4256 | ctx.arc(x,y,radius,0,2*Math.PI,false);\ |
||
4257 | ctx.closePath();\ |
||
4258 | }\ |
||
4259 | }\ |
||
4260 | ctx.fill();\ |
||
4261 | ctx.restore();\ |
||
7653 | schaersvoo | 4262 | return;};",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 4263 | break; |
7645 | schaersvoo | 4264 | |
7647 | schaersvoo | 4265 | case DRAW_DIAMONDFILL:/* not used for userdraw */ |
7614 | schaersvoo | 4266 | fprintf(js_include_file,"\n<!-- draw hatch fill -->\n\ |
7647 | schaersvoo | 4267 | draw_diamondfill = function(canvas_type,x0,y0,dx,dy,linewidth,stroke_color,stroke_opacity,xsize,ysize){\ |
7614 | schaersvoo | 4268 | var obj;\ |
4269 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
4270 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
4271 | }\ |
||
4272 | else\ |
||
4273 | {\ |
||
4274 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
4275 | };\ |
||
4276 | var ctx = obj.getContext(\"2d\");\ |
||
4277 | var x;\ |
||
4278 | var y;\ |
||
4279 | ctx.save();\ |
||
4280 | ctx.lineWidth = linewidth;\ |
||
4281 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
4282 | y = ysize;\ |
||
4283 | for( x = x0 ; x < xsize ; x = x + dx ){\ |
||
4284 | ctx.moveTo(x,y0);\ |
||
4285 | ctx.lineTo(xsize,y);\ |
||
4286 | y = y - dy;\ |
||
4287 | };\ |
||
4288 | y = y0;\ |
||
4289 | for( x = xsize ; x > 0 ; x = x - dx){\ |
||
4290 | ctx.moveTo(x,ysize);\ |
||
4291 | ctx.lineTo(x0,y);\ |
||
4292 | y = y + dy;\ |
||
4293 | };\ |
||
4294 | x = x0;\ |
||
4295 | for( y = y0 ; y < ysize ; y = y + dy ){\ |
||
4296 | ctx.moveTo(xsize,y);\ |
||
4297 | ctx.lineTo(x,ysize);\ |
||
4298 | x = x + dx;\ |
||
4299 | };\ |
||
4300 | x = xsize;\ |
||
4301 | for( y = ysize ; y > y0 ; y = y - dy ){\ |
||
4302 | ctx.moveTo(x,y0);\ |
||
4303 | ctx.lineTo(x0,y);\ |
||
4304 | x = x - dx;\ |
||
4305 | };\ |
||
4306 | ctx.stroke();\ |
||
4307 | ctx.restore();\ |
||
4308 | return;\ |
||
7653 | schaersvoo | 4309 | }",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 4310 | break; |
7842 | bpr | 4311 | |
7647 | schaersvoo | 4312 | case DRAW_HATCHFILL:/* not used for userdraw */ |
4313 | fprintf(js_include_file,"\n<!-- draw hatch fill -->\n\ |
||
4314 | draw_hatchfill = function(canvas_type,x0,y0,dx,dy,linewidth,stroke_color,stroke_opacity,xsize,ysize){\ |
||
4315 | var obj;\ |
||
4316 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
4317 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
4318 | }\ |
||
4319 | else\ |
||
4320 | {\ |
||
4321 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
4322 | };\ |
||
4323 | var ctx = obj.getContext(\"2d\");\ |
||
4324 | var x;\ |
||
4325 | var y;\ |
||
4326 | ctx.save();\ |
||
4327 | ctx.lineWidth = linewidth;\ |
||
4328 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
4329 | y = ysize;\ |
||
4330 | for( x = x0 ; x < xsize ; x = x + dx ){\ |
||
4331 | ctx.moveTo(x,y0);\ |
||
4332 | ctx.lineTo(xsize,y);\ |
||
4333 | y = y - dy;\ |
||
4334 | };\ |
||
4335 | y = y0;\ |
||
4336 | for( x = xsize ; x >= dx ; x = x - dx){\ |
||
4337 | ctx.moveTo(x,ysize);\ |
||
4338 | ctx.lineTo(x0,y);\ |
||
4339 | y = y + dy;\ |
||
4340 | };\ |
||
4341 | ctx.stroke();\ |
||
4342 | ctx.restore();\ |
||
4343 | return;\ |
||
7653 | schaersvoo | 4344 | };",canvas_root_id,canvas_root_id,canvas_root_id); |
7647 | schaersvoo | 4345 | break; |
7614 | schaersvoo | 4346 | case DRAW_CIRCLES:/* used for userdraw */ |
4347 | fprintf(js_include_file,"\n<!-- draw circles -->\n\ |
||
4348 | 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_translate,vector){\ |
||
4349 | ctx.save();\ |
||
4350 | if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\ |
||
4351 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
||
4352 | ctx.lineWidth = line_width;\ |
||
4353 | for(var p = 0 ; p < x_points.length ; p++ ){\ |
||
4354 | ctx.beginPath();\ |
||
4355 | ctx.arc(x_points[p],y_points[p],radius[p],0,2*Math.PI,false);\ |
||
4356 | ctx.closePath();\ |
||
4357 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
4358 | if(use_filled == 1){ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();}\ |
||
4359 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
4360 | ctx.stroke();\ |
||
4361 | }\ |
||
4362 | ctx.restore();\ |
||
4363 | return;\ |
||
7653 | schaersvoo | 4364 | };"); |
7614 | schaersvoo | 4365 | break; |
7663 | schaersvoo | 4366 | case DRAW_POLYLINE:/* user for userdraw : draw lines through points */ |
4367 | fprintf(js_include_file,"\n<!-- draw polyline -->\n\ |
||
4368 | draw_polyline = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_translate,vector){\ |
||
4369 | ctx.save();\ |
||
4370 | if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\ |
||
4371 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
||
4372 | ctx.lineWidth = line_width;\ |
||
4373 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
4374 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
4375 | ctx.clearRect(0,0,xsize,ysize);\ |
||
4376 | ctx.beginPath();\ |
||
4377 | for(var p = 0 ; p < x_points.length-1 ; p++ ){\ |
||
4378 | ctx.moveTo(x_points[p],y_points[p]);\ |
||
4379 | ctx.lineTo(x_points[p+1],y_points[p+1]);\ |
||
4380 | }\ |
||
4381 | ctx.closePath();\ |
||
4382 | ctx.stroke();\ |
||
4383 | ctx.fillStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
4384 | for(var p = 0 ; p < x_points.length ; p++ ){\ |
||
4385 | ctx.beginPath();\ |
||
4386 | ctx.arc(x_points[p],y_points[p],line_width,0,2*Math.PI,false);\ |
||
4387 | ctx.closePath();ctx.fill();ctx.stroke();\ |
||
4388 | };\ |
||
4389 | ctx.restore();\ |
||
4390 | return;\ |
||
4391 | };"); |
||
4392 | break; |
||
7842 | bpr | 4393 | |
7614 | schaersvoo | 4394 | case DRAW_SEGMENTS:/* used for userdraw */ |
4395 | fprintf(js_include_file,"\n<!-- draw segments -->\n\ |
||
4396 | draw_segments = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_translate,vector){\ |
||
4397 | ctx.save();\ |
||
4398 | if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\ |
||
4399 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
||
4400 | ctx.lineWidth = line_width;\ |
||
4401 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
4402 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
4403 | for(var p = 0 ; p < x_points.length ; p = p+2 ){\ |
||
4404 | ctx.beginPath();\ |
||
4405 | ctx.moveTo(x_points[p],y_points[p]);\ |
||
4406 | ctx.lineTo(x_points[p+1],y_points[p+1]);\ |
||
4407 | ctx.closePath();\ |
||
4408 | ctx.stroke();\ |
||
4409 | }\ |
||
4410 | ctx.restore();\ |
||
4411 | return;\ |
||
4412 | };"); |
||
4413 | break; |
||
7842 | bpr | 4414 | |
7614 | schaersvoo | 4415 | case DRAW_LINES:/* used for userdraw */ |
4416 | fprintf(js_include_file,"\n<!-- draw lines -->\n\ |
||
4417 | function calc_line(x1,x2,y1,y2){\ |
||
4418 | var marge = 2;\ |
||
4419 | if(x1 < x2+marge && x1>x2-marge){\ |
||
4420 | return [x1,0,x1,ysize];\ |
||
4421 | };\ |
||
4422 | if(y1 < y2+marge && y1>y2-marge){\ |
||
4423 | return [0,y1,xsize,y1];\ |
||
4424 | };\ |
||
4425 | var Y1 = y1 - (x1)*(y2 - y1)/(x2 - x1);\ |
||
4426 | var Y2 = y1 + (xsize - x1)*(y2 - y1)/(x2 - x1);\ |
||
4427 | return [0,Y1,xsize,Y2];\ |
||
4428 | };\ |
||
4429 | draw_lines = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_translate,vector){\ |
||
4430 | ctx.save();\ |
||
4431 | var line = new Array(4);\ |
||
4432 | if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\ |
||
4433 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
||
4434 | ctx.lineWidth = line_width;\ |
||
4435 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
4436 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
4437 | for(var p = 0 ; p < x_points.length ; p = p+2 ){\ |
||
4438 | line = calc_line(x_points[p],x_points[p+1],y_points[p],y_points[p+1]);\ |
||
4439 | ctx.beginPath();\ |
||
4440 | ctx.moveTo(line[0],line[1]);\ |
||
4441 | ctx.lineTo(line[2],line[3]);\ |
||
4442 | ctx.closePath();\ |
||
4443 | ctx.stroke();\ |
||
4444 | }\ |
||
4445 | ctx.restore();\ |
||
4446 | return;\ |
||
4447 | };"); |
||
4448 | break; |
||
4449 | |||
4450 | case DRAW_CROSSHAIRS:/* used for userdraw */ |
||
4451 | fprintf(js_include_file,"\n<!-- draw crosshairs -->\n\ |
||
4452 | draw_crosshairs = function(ctx,x_points,y_points,line_width,crosshair_size,stroke_color,stroke_opacity,use_rotate,angle,use_translate,vector){\ |
||
4453 | if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\ |
||
4454 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
||
4455 | ctx.lineWidth = line_width;\ |
||
4456 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
4457 | var x1,x2,y1,y2;\ |
||
4458 | for(var p = 0 ; p < x_points.length ; p++ ){\ |
||
4459 | x1 = x_points[p] - crosshair_size;\ |
||
4460 | x2 = x_points[p] + crosshair_size;\ |
||
4461 | y1 = y_points[p] - crosshair_size;\ |
||
4462 | y2 = y_points[p] + crosshair_size;\ |
||
4463 | ctx.beginPath();\ |
||
4464 | ctx.moveTo(x1,y1);\ |
||
4465 | ctx.lineTo(x2,y2);\ |
||
4466 | ctx.closePath();\ |
||
4467 | ctx.stroke();\ |
||
4468 | ctx.beginPath();\ |
||
4469 | ctx.moveTo(x2,y1);\ |
||
4470 | ctx.lineTo(x1,y2);\ |
||
4471 | ctx.closePath();\ |
||
4472 | ctx.stroke();\ |
||
4473 | }\ |
||
4474 | ctx.restore();\ |
||
4475 | return;\ |
||
7653 | schaersvoo | 4476 | };"); |
7614 | schaersvoo | 4477 | break; |
4478 | |||
4479 | case DRAW_RECTS:/* used for userdraw */ |
||
4480 | fprintf(js_include_file,"\n<!-- draw rects -->\n\ |
||
4481 | 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_translate,vector){\ |
||
4482 | ctx.save();\ |
||
4483 | if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\ |
||
4484 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
||
4485 | ctx.lineWidth = line_width;\ |
||
4486 | ctx.strokeStyle = \"rgba('+stroke_color+','+stroke_opacity+')\";\ |
||
4487 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];}};\ |
||
4488 | for(var p = 0 ; p < x_points.length ; p = p + 2){\ |
||
4489 | ctx.beginPath();\ |
||
4490 | ctx.rect(x_points[p],y_points[p],x_points[p+1]-x_points[p],y_points[p+1]-y_points[p]);\ |
||
4491 | ctx.closePath();\ |
||
4492 | if(use_filled == 1 ){ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();}\ |
||
4493 | ctx.stroke();\ |
||
4494 | };\ |
||
4495 | ctx.restore();\ |
||
4496 | return;\ |
||
7653 | schaersvoo | 4497 | };"); |
7614 | schaersvoo | 4498 | break; |
4499 | |||
4500 | case DRAW_ROUNDRECTS:/* used for userdraw */ |
||
4501 | fprintf(js_include_file,"\n<!-- draw round rects -->\n\ |
||
4502 | 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_translate,vector){\ |
||
4503 | ctx.save();\ |
||
4504 | if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\ |
||
4505 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
4506 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
||
4507 | var x,y,w,h,r;\ |
||
4508 | for(var p = 0; p < x_points.length; p = p+2){\ |
||
4509 | 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);\ |
||
4510 | ctx.beginPath();ctx.moveTo(x + r, y);\ |
||
4511 | ctx.lineTo(x + w - r, y);\ |
||
4512 | ctx.quadraticCurveTo(x + w, y, x + w, y + r);\ |
||
4513 | ctx.lineTo(x + w, y + h - r);\ |
||
4514 | ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);\ |
||
4515 | ctx.lineTo(x + r, y + h);\ |
||
4516 | ctx.quadraticCurveTo(x, y + h, x, y + h - r);\ |
||
4517 | ctx.lineTo(x, y + r);\ |
||
4518 | ctx.quadraticCurveTo(x, y, x + r, y);\ |
||
4519 | ctx.closePath();if( use_dashed == 1 ){ctx.setLineDash([dashtype0,dashtype1]);};\ |
||
4520 | ctx.strokeStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
4521 | if( use_filled == 1 ){ctx.fillStyle =\"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();};\ |
||
4522 | ctx.stroke();\ |
||
4523 | }\ |
||
4524 | ctx.restore();\ |
||
7653 | schaersvoo | 4525 | };"); |
7842 | bpr | 4526 | break; |
7614 | schaersvoo | 4527 | |
4528 | case DRAW_ELLIPSES:/* not used for userdraw */ |
||
4529 | fprintf(js_include_file,"\n<!-- draw ellipses -->\n\ |
||
4530 | 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_translate,vector){\ |
||
4531 | var obj;\ |
||
4532 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
4533 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
4534 | }\ |
||
4535 | else\ |
||
4536 | {\ |
||
4537 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
4538 | };\ |
||
4539 | var ctx = obj.getContext(\"2d\");\ |
||
4540 | ctx.save();\ |
||
4541 | if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\ |
||
4542 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
||
4543 | var cx,cy,ry,rx;\ |
||
4544 | ctx.lineWidth = line_width;\ |
||
4545 | if( use_filled == 1 ){ctx.fillStyle =\"rgba(\"+fill_color+\",\"+fill_opacity+\")\";};\ |
||
4546 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
4547 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
4548 | for(var p=0;p< x_points.length;p = p+2){\ |
||
4549 | ctx.beginPath();\ |
||
4550 | cx = x_points[p];cy = y_points[p];rx = 0.25*x_points[p+1];ry = 0.25*y_points[p+1];\ |
||
4551 | ctx.translate(cx - rx, cy - ry);\ |
||
4552 | ctx.scale(rx, ry);\ |
||
4553 | ctx.arc(1, 1, 1, 0, 2 * Math.PI, false);\ |
||
4554 | if( use_filled == 1 ){ctx.fill();}\ |
||
4555 | ctx.stroke();\ |
||
4556 | };\ |
||
4557 | ctx.restore();\ |
||
7653 | schaersvoo | 4558 | };",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 4559 | break; |
4560 | |||
4561 | case DRAW_PATHS: /* used for userdraw */ |
||
4562 | fprintf(js_include_file,"\n<!-- draw paths -->\n\ |
||
4563 | 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_translate,vector){\ |
||
4564 | ctx.save();\ |
||
4565 | if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\ |
||
4566 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
||
4567 | ctx.lineWidth = line_width;\ |
||
4568 | ctx.lineJoin = \"round\";\ |
||
4569 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
4570 | ctx.beginPath();\ |
||
4571 | ctx.moveTo(x_points[0],y_points[0]);\ |
||
4572 | for(var p = 1 ; p < x_points.length ; p++ ){ctx.lineTo(x_points[p],y_points[p]);}\ |
||
4573 | if(closed_path == 1){ctx.lineTo(x_points[0],y_points[0]);ctx.closePath();}\ |
||
4574 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
4575 | if(use_filled == 1){ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();}\ |
||
4576 | ctx.stroke();\ |
||
4577 | ctx.restore();\ |
||
4578 | return;\ |
||
4579 | };"); |
||
7842 | bpr | 4580 | |
7614 | schaersvoo | 4581 | break; |
4582 | case DRAW_ARROWS:/* used for userdraw */ |
||
4583 | fprintf(js_include_file,"\n<!-- draw arrows -->\n\ |
||
4584 | 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_translate,vector){\ |
||
4585 | ctx.save();\ |
||
4586 | if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\ |
||
4587 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
||
4588 | ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
4589 | ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
4590 | ctx.lineWidth = line_width;\ |
||
4591 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
4592 | ctx.lineCap = \"round\";\ |
||
4593 | ctx.save();\ |
||
4594 | var x1,y1,x2,y2,dx,dy,len;\ |
||
4595 | for(var p = 0 ; p < x_points.length - 1 ; p = p +2){\ |
||
4596 | ctx.restore();ctx.save();\ |
||
4597 | x1 = x_points[p];y1 = y_points[p];x2 = x_points[p+1];y2 = y_points[p+1];dx = x2 - x1;dy = y2 - y1;\ |
||
4598 | len = Math.sqrt(dx*dx+dy*dy);\ |
||
4599 | ctx.translate(x2,y2);\ |
||
4600 | ctx.rotate(Math.atan2(dy,dx));\ |
||
4601 | ctx.lineCap = \"round\";\ |
||
4602 | ctx.beginPath();\ |
||
4603 | ctx.moveTo(0,0);\ |
||
4604 | ctx.lineTo(-len,0);\ |
||
4605 | ctx.closePath();\ |
||
4606 | ctx.stroke();\ |
||
4607 | ctx.beginPath();\ |
||
4608 | ctx.moveTo(0,0);\ |
||
4609 | ctx.lineTo(-1*arrow_head,-0.5*arrow_head);\ |
||
4610 | ctx.lineTo(-1*arrow_head, 0.5*arrow_head);\ |
||
4611 | ctx.closePath();\ |
||
4612 | ctx.fill();\ |
||
4613 | if( type == 2 ){\ |
||
4614 | ctx.restore();\ |
||
4615 | ctx.save();\ |
||
4616 | ctx.translate(x1,y1);\ |
||
4617 | ctx.rotate(Math.atan2(-dy,-dx));\ |
||
4618 | ctx.beginPath();\ |
||
4619 | ctx.moveTo(0,0);\ |
||
4620 | ctx.lineTo(-1*arrow_head,-0.5*arrow_head);\ |
||
4621 | ctx.lineTo(-1*arrow_head, 0.5*arrow_head);\ |
||
4622 | ctx.closePath();\ |
||
4623 | ctx.stroke();\ |
||
4624 | ctx.fill();\ |
||
4625 | }\ |
||
4626 | }\ |
||
4627 | ctx.restore();\ |
||
4628 | return;\ |
||
7653 | schaersvoo | 4629 | };"); |
7614 | schaersvoo | 4630 | break; |
4631 | |||
4632 | case DRAW_VIDEO:/* not used for userdraw */ |
||
4633 | fprintf(js_include_file,"\n<!-- draw video -->\n\ |
||
4634 | draw_video = function(canvas_root_id,x,y,w,h,URL){\ |
||
4635 | var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\ |
||
4636 | var video_div = document.createElement(\"div\");\ |
||
4637 | canvas_div.appendChild(video_div);\ |
||
4638 | video_div.style.position = \"absolute\";\ |
||
4639 | video_div.style.left = x+\"px\";\ |
||
4640 | video_div.style.top = y+\"px\";\ |
||
4641 | video_div.style.width = w+\"px\";\ |
||
4642 | video_div.style.height = h+\"px\";\ |
||
4643 | var video = document.createElement(\"video\");\ |
||
4644 | video_div.appendChild(video);\ |
||
4645 | video.style.width = w+\"px\";\ |
||
4646 | video.style.height = h+\"px\";\ |
||
4647 | video.autobuffer = true;\ |
||
4648 | video.controls = true;video.autoplay = false;\ |
||
4649 | var src = document.createElement(\"source\");\ |
||
4650 | src.type = \"video/mp4\";\ |
||
4651 | src.src = URL;\ |
||
4652 | video.appendChild(src);\ |
||
4653 | video.load();\ |
||
4654 | return;\ |
||
7842 | bpr | 4655 | };"); |
7614 | schaersvoo | 4656 | break; |
7842 | bpr | 4657 | |
7614 | schaersvoo | 4658 | case DRAW_AUDIO:/* not used for userdraw */ |
4659 | fprintf(js_include_file,"\n<!-- draw audio -->\n\ |
||
4660 | draw_audio = function(canvas_root_id,x,y,w,h,loop,visible,URL1,URL2){\ |
||
4661 | var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\ |
||
4662 | var audio_div = document.createElement(\"div\");\ |
||
4663 | canvas_div.appendChild(audio_div);\ |
||
4664 | audio_div.style.position = \"absolute\";\ |
||
4665 | audio_div.style.left = x+\"px\";\ |
||
4666 | audio_div.style.top = y+\"px\";\ |
||
4667 | audio_div.style.width = w+\"px\";\ |
||
4668 | audio_div.style.height = h+\"px\";\ |
||
4669 | var audio = document.createElement(\"audio\");\ |
||
4670 | audio_div.appendChild(audio);\ |
||
4671 | audio.setAttribute(\"style\",\"width:\"+w+\"px;height:\"+h+\"px\");\ |
||
4672 | audio.autobuffer = true;\ |
||
4673 | if(visible == 1 ){ audio.controls = true;audio.autoplay = false;}else{ audio.controls = false;audio.autoplay = true;}\ |
||
4674 | if(loop == 1 ){ audio.loop = true;}else{ audio.loop = false;}\ |
||
4675 | var src1 = document.createElement(\"source\");\ |
||
4676 | src1.type = \"audio/ogg\";\ |
||
4677 | src1.src = URL1;\ |
||
4678 | audio.appendChild(src1);\ |
||
4679 | var src2 = document.createElement(\"source\");\ |
||
4680 | src2.type = \"audio/mpeg\";\ |
||
4681 | src2.src = URL2;\ |
||
4682 | audio.appendChild(src2);\ |
||
4683 | audio.load();\ |
||
4684 | return;\ |
||
7653 | schaersvoo | 4685 | };"); |
7614 | schaersvoo | 4686 | break; |
7842 | bpr | 4687 | |
7614 | schaersvoo | 4688 | case DRAW_HTTP:/* not used for userdraw */ |
4689 | fprintf(js_include_file,"\n<!-- draw http -->\n\ |
||
4690 | draw_http = function(canvas_root_id,x,y,w,h,URL){\ |
||
4691 | var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\ |
||
4692 | var http_div = document.createElement(\"div\");\ |
||
4693 | var iframe = document.createElement(\"iframe\");\ |
||
4694 | canvas_div.appendChild(http_div);\ |
||
4695 | http_div.appendChild(iframe);\ |
||
4696 | iframe.src = URL;\ |
||
4697 | iframe.setAttribute(\"width\",w);\ |
||
4698 | iframe.setAttribute(\"height\",h);\ |
||
4699 | return;\ |
||
7653 | schaersvoo | 4700 | };"); |
7614 | schaersvoo | 4701 | break; |
7842 | bpr | 4702 | |
7614 | schaersvoo | 4703 | case DRAW_XML: |
4704 | fprintf(js_include_file,"\n<!-- draw xml -->\n\ |
||
4705 | draw_xml = function(canvas_root_id,x,y,w,h,mathml,onclick){\ |
||
4706 | var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\ |
||
4707 | var xml_div = document.createElement(\"div\");\ |
||
4708 | canvas_div.appendChild(xml_div);\ |
||
4709 | xml_div.innerHTML = mathml;\ |
||
4710 | if(onclick != 0){\ |
||
4711 | xml_div.onclick = function(){\ |
||
4712 | reply[0] = onclick;\ |
||
4713 | alert(\"send \"+onclick+\" ?\");\ |
||
4714 | };\ |
||
4715 | };\ |
||
4716 | xml_div.style.position = \"absolute\";\ |
||
4717 | xml_div.style.left = x+\"px\";\ |
||
4718 | xml_div.style.top = y+\"px\";\ |
||
4719 | xml_div.style.width = w+\"px\";\ |
||
4720 | xml_div.style.height = h+\"px\";\ |
||
4721 | return;\ |
||
7653 | schaersvoo | 4722 | };" |
7614 | schaersvoo | 4723 | ); |
4724 | break; |
||
7654 | schaersvoo | 4725 | case DRAW_SGRAPH: |
7842 | bpr | 4726 | /* |
7654 | schaersvoo | 4727 | xstart = given |
4728 | ystart = given |
||
4729 | sgraph(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily) |
||
4730 | */ |
||
4731 | fprintf(js_include_file,"\n<!-- draw sgraph -->\n\ |
||
7658 | schaersvoo | 4732 | draw_sgraph = function(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily,opacity,font_size){\ |
4733 | 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);};\ |
||
4734 | var ctx = obj.getContext(\"2d\");\ |
||
4735 | ctx.font = fontfamily;\ |
||
4736 | var minor_opacity = 0.8*opacity;\ |
||
4737 | ctx.clearRect(0,0,xsize,ysize);\ |
||
4738 | var d_x = 1.8*font_size;\ |
||
4739 | var d_y = ctx.measureText(\"+ymax+\").width;\ |
||
4740 | var dx = xsize / (xmax - xmin);\ |
||
4741 | var dy = ysize / (ymax - ymin);\ |
||
4742 | var zero_x = d_y + dx;\ |
||
4743 | var zero_y = ysize - dy - d_x;\ |
||
7659 | schaersvoo | 4744 | var snor_x;\ |
7654 | schaersvoo | 4745 | if( xstart != xmin){\ |
7658 | schaersvoo | 4746 | snor_x = 0.1*xsize;\ |
4747 | }\ |
||
4748 | else\ |
||
4749 | {\ |
||
4750 | snor_x = 0;\ |
||
4751 | xstart = xmin;\ |
||
4752 | };\ |
||
4753 | ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\ |
||
4754 | ctx.lineWidth = 2;\ |
||
4755 | ctx.beginPath();\ |
||
4756 | ctx.moveTo(xsize,zero_y);\ |
||
4757 | ctx.lineTo(zero_x,zero_y);\ |
||
4758 | ctx.lineTo(zero_x,0);\ |
||
4759 | ctx.stroke();\ |
||
4760 | ctx.closePath();\ |
||
4761 | ctx.beginPath();\ |
||
4762 | ctx.moveTo(zero_x,zero_y);\ |
||
4763 | ctx.lineTo(zero_x + 0.25*snor_x,zero_y - 0.1*snor_x);\ |
||
4764 | ctx.lineTo(zero_x + 0.5*snor_x,zero_y + 0.1*snor_x);\ |
||
4765 | ctx.lineTo(zero_x + 0.75*snor_x,zero_y - 0.1*snor_x);\ |
||
4766 | ctx.lineTo(zero_x + snor_x,zero_y);\ |
||
4767 | ctx.stroke();\ |
||
4768 | ctx.closePath();\ |
||
4769 | ctx.beginPath();\ |
||
4770 | var num = xstart;\ |
||
7660 | schaersvoo | 4771 | var flipflop = 1;\ |
7658 | schaersvoo | 4772 | var step_x = xmajor*(xsize - zero_x - snor_x)/(xmax - xstart);\ |
4773 | for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\ |
||
7660 | schaersvoo | 4774 | if( 0.5*ctx.measureText(num).width > step_x ){\ |
4775 | if( flipflop == 1 ){flipflop = 0;}else{flipflop = 1;};\ |
||
4776 | };\ |
||
4777 | if( flipflop == 1){\ |
||
7658 | schaersvoo | 4778 | ctx.fillText(num,x - 0.5*ctx.measureText(num).width,zero_y+font_size);\ |
4779 | }\ |
||
4780 | else\ |
||
4781 | {\ |
||
4782 | ctx.fillText(num,x - 0.5*ctx.measureText(num).width,zero_y+2*font_size);\ |
||
4783 | }\ |
||
4784 | num = num + xmajor;\ |
||
4785 | };\ |
||
4786 | ctx.stroke();\ |
||
4787 | ctx.closePath();\ |
||
4788 | ctx.lineWidth = 1;\ |
||
4789 | ctx.beginPath();\ |
||
4790 | for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\ |
||
4791 | ctx.moveTo(x,zero_y);\ |
||
4792 | ctx.lineTo(x,0);\ |
||
4793 | };\ |
||
4794 | ctx.stroke();\ |
||
4795 | ctx.closePath();\ |
||
4796 | if( xminor > 1){\ |
||
4797 | ctx.lineWidth = 0.5;\ |
||
4798 | ctx.beginPath();\ |
||
4799 | ctx.strokeStyle = \"rgba(\"+minorcolor+\",\"+minor_opacity+\")\";\ |
||
4800 | var minor_step_x = step_x / xminor;\ |
||
4801 | var nx;\ |
||
4802 | for(var x = zero_x+snor_x; x < xsize;x = x + step_x){\ |
||
4803 | num = 1;\ |
||
4804 | for(var p = 1 ; p < xminor ; p++){\ |
||
4805 | nx = x + num*minor_step_x;\ |
||
4806 | ctx.moveTo(nx,zero_y);\ |
||
4807 | ctx.lineTo(nx,0);\ |
||
4808 | num++;\ |
||
4809 | };\ |
||
4810 | };\ |
||
4811 | ctx.stroke();\ |
||
4812 | ctx.closePath();\ |
||
4813 | ctx.beginPath();\ |
||
4814 | ctx.lineWidth = 2;\ |
||
4815 | ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\ |
||
4816 | for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\ |
||
4817 | ctx.moveTo(x,zero_y);ctx.lineTo(x,zero_y - 12);\ |
||
4818 | };\ |
||
4819 | for(var x = zero_x+snor_x ; x < xsize;x = x + minor_step_x){\ |
||
4820 | ctx.moveTo(x,zero_y);ctx.lineTo(x,zero_y - 6);\ |
||
4821 | };\ |
||
4822 | ctx.stroke();\ |
||
4823 | ctx.closePath();\ |
||
4824 | ctx.lineWidth = 0.5;\ |
||
4825 | };\ |
||
4826 | xmin = xstart - (xmajor*(zero_x+snor_x)/step_x);\ |
||
4827 | if( ystart != ymin){\ |
||
4828 | snor_y = 0.1*ysize;\ |
||
4829 | }\ |
||
4830 | else\ |
||
4831 | {\ |
||
4832 | snor_y = 0;\ |
||
4833 | ystart = ymin;\ |
||
4834 | };\ |
||
4835 | ctx.lineWidth = 2;\ |
||
4836 | ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\ |
||
4837 | ctx.beginPath();\ |
||
4838 | ctx.moveTo(zero_x,zero_y);\ |
||
4839 | ctx.lineTo(zero_x - 0.1*snor_y,zero_y - 0.25*snor_y);\ |
||
4840 | ctx.lineTo(zero_x + 0.1*snor_y,zero_y - 0.5*snor_y);\ |
||
4841 | ctx.lineTo(zero_x - 0.1*snor_y,zero_y - 0.75*snor_y);\ |
||
4842 | ctx.lineTo(zero_x,zero_y - snor_y);\ |
||
4843 | ctx.stroke();\ |
||
4844 | ctx.closePath();\ |
||
4845 | ctx.beginPath();\ |
||
4846 | ctx.lineWidth = 1;\ |
||
4847 | num = ystart;\ |
||
4848 | var step_y = ymajor*(zero_y - snor_y)/(ymax - ystart);\ |
||
4849 | for(var y = zero_y - snor_y ; y > 0; y = y - step_y){\ |
||
4850 | ctx.moveTo(zero_x,y);\ |
||
4851 | ctx.lineTo(xsize,y);\ |
||
4852 | ctx.fillText(num,zero_x - ctx.measureText(num+\" \").width,parseInt(y+0.2*font_size));\ |
||
4853 | num = num + ymajor;\ |
||
4854 | };\ |
||
4855 | ctx.stroke();\ |
||
4856 | ctx.closePath();\ |
||
4857 | if( yminor > 1){\ |
||
4858 | ctx.lineWidth = 0.5;\ |
||
4859 | ctx.beginPath();\ |
||
4860 | ctx.strokeStyle = \"rgba(\"+minorcolor+\",\"+minor_opacity+\")\";\ |
||
4861 | var minor_step_y = step_y / yminor;\ |
||
4862 | var ny;\ |
||
4863 | for(var y = 0 ; y < zero_y - snor_y ;y = y + step_y){\ |
||
4864 | num = 1;\ |
||
4865 | for(var p = 1 ;p < yminor;p++){\ |
||
4866 | ny = y + num*minor_step_y;\ |
||
4867 | ctx.moveTo(zero_x,ny);\ |
||
4868 | ctx.lineTo(xsize,ny);\ |
||
4869 | num++;\ |
||
4870 | };\ |
||
4871 | };\ |
||
4872 | ctx.stroke();\ |
||
4873 | ctx.closePath();\ |
||
4874 | ctx.lineWidth = 2;\ |
||
4875 | ctx.beginPath();\ |
||
4876 | ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\ |
||
4877 | for(var y = zero_y - snor_y ; y > 0 ;y = y - step_y){\ |
||
4878 | ctx.moveTo(zero_x,y);\ |
||
4879 | ctx.lineTo(zero_x+12,y);\ |
||
4880 | };\ |
||
4881 | for(var y = zero_y - snor_y ; y > 0 ;y = y - minor_step_y){\ |
||
4882 | ctx.moveTo(zero_x,y);\ |
||
4883 | ctx.lineTo(zero_x+6,y);\ |
||
4884 | };\ |
||
4885 | ctx.stroke();\ |
||
4886 | ctx.closePath();\ |
||
4887 | };\ |
||
4888 | ymin = ystart - (ymajor*(ysize - zero_y + snor_y)/step_y);\ |
||
7654 | schaersvoo | 4889 | if( typeof legend%d !== 'undefined' ){\ |
4890 | ctx.globalAlpha = 1.0;\ |
||
4891 | var y_offset = 2*font_size;\ |
||
4892 | var txt;var txt_size;\ |
||
4893 | var x_offset = xsize - 2*font_size;\ |
||
4894 | var l_length = legend%d.length;var barcolor = new Array();\ |
||
4895 | if( typeof legendcolors%d !== 'undefined' ){\ |
||
4896 | for(var p = 0 ; p < l_length ; p++){\ |
||
4897 | barcolor[p] = legendcolors%d[p];\ |
||
4898 | };\ |
||
4899 | }else{\ |
||
4900 | if( barcolor.length == 0 ){\ |
||
4901 | for(var p = 0 ; p < l_length ; p++){\ |
||
4902 | barcolor[p] = stroke_color;\ |
||
4903 | };\ |
||
4904 | };\ |
||
4905 | };\ |
||
4906 | for(var p = 0; p < l_length; p++){\ |
||
4907 | ctx.fillStyle = barcolor[p];\ |
||
4908 | txt = legend%d[p];\ |
||
4909 | txt_size = ctx.measureText(txt).width;\ |
||
4910 | ctx.fillText(legend%d[p],x_offset - txt_size, y_offset);\ |
||
4911 | y_offset = parseInt(y_offset + 1.5*font_size);\ |
||
4912 | };\ |
||
4913 | };\ |
||
7660 | schaersvoo | 4914 | if( typeof xaxislabel !== 'undefined' ){\ |
7658 | schaersvoo | 4915 | ctx.fillStyle = \'#000000\';\ |
4916 | var txt_size = ctx.measureText(xaxislabel).width + 4 ;\ |
||
4917 | ctx.fillText(xaxislabel,xsize - txt_size, zero_y - 7);\ |
||
4918 | };\ |
||
7660 | schaersvoo | 4919 | if( typeof yaxislabel !== 'undefined'){\ |
7658 | schaersvoo | 4920 | ctx.save();\ |
4921 | ctx.fillStyle = \'#000000\';\ |
||
4922 | var txt_size = ctx.measureText(yaxislabel).width;\ |
||
4923 | ctx.translate(zero_x+8 + font_size,txt_size+font_size);\ |
||
4924 | ctx.rotate(-0.5*Math.PI);\ |
||
4925 | ctx.fillText(yaxislabel,0,0);\ |
||
4926 | ctx.save();\ |
||
4927 | };\ |
||
7654 | schaersvoo | 4928 | };\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); |
4929 | break; |
||
7614 | schaersvoo | 4930 | |
4931 | case DRAW_GRID:/* not used for userdraw */ |
||
4932 | fprintf(js_include_file,"\n<!-- draw grid -->\n\ |
||
4933 | 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_translate,vector,use_dashed,dashtype0,dashtype1,font_color,fill_opacity){\ |
||
4934 | var obj;\ |
||
4935 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
4936 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
4937 | }\ |
||
4938 | else\ |
||
4939 | {\ |
||
4940 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
4941 | };\ |
||
4942 | var ctx = obj.getContext(\"2d\");\ |
||
4943 | ctx.clearRect(0,0,xsize,ysize);\ |
||
4944 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
4945 | ctx.save();\ |
||
4946 | if( use_translate == 1 ){ctx.translate(vector[0],vector[1]);};\ |
||
4947 | if( use_rotate == 1 ){ctx.translate(x2px(0),y2px(0));ctx.rotate(angle*Math.PI/180);ctx.translate(-1*(x2px(0)),-1*(y2px(0)));};\ |
||
4948 | var stroke_color = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
4949 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+1.0+\")\";\ |
||
4950 | var axis_color = \"rgba(\"+axis_color+\",\"+stroke_opacity+\")\";\ |
||
4951 | ctx.font = font_family;\ |
||
4952 | var xstep = xsize*xmajor/(xmax - xmin);\ |
||
4953 | var ystep = ysize*ymajor/(ymax - ymin);\ |
||
4954 | var x2step = xstep / xminor;\ |
||
4955 | var y2step = ystep / yminor;\ |
||
7654 | schaersvoo | 4956 | var zero_x;var zero_y;var f_x;var f_y;\ |
4957 | if(xmin < 0 ){zero_x = x2px(0);f_x = 1;}else{zero_x = x2px(xmin);f_x = -1;}\ |
||
4958 | if(ymin < 0 ){zero_y = y2px(0);f_y = 1;}else{zero_y = y2px(ymin);f_y = -1;}\ |
||
7614 | schaersvoo | 4959 | ctx.beginPath();\ |
4960 | ctx.lineWidth = line_width;\ |
||
4961 | ctx.strokeStyle = stroke_color;\ |
||
4962 | for(var p = zero_x ; p < xsize; p = p + xstep){\ |
||
4963 | ctx.moveTo(p,0);\ |
||
4964 | ctx.lineTo(p,ysize);\ |
||
4965 | };\ |
||
4966 | for(var p = zero_x ; p > 0; p = p - xstep){\ |
||
4967 | ctx.moveTo(p,0);\ |
||
4968 | ctx.lineTo(p,ysize);\ |
||
4969 | };\ |
||
4970 | for(var p = zero_y ; p < ysize; p = p + ystep){\ |
||
4971 | ctx.moveTo(0,p);\ |
||
4972 | ctx.lineTo(xsize,p);\ |
||
4973 | };\ |
||
4974 | for(var p = zero_y ; p > 0; p = p - ystep){\ |
||
4975 | ctx.moveTo(0,p);\ |
||
4976 | ctx.lineTo(xsize,p);\ |
||
4977 | };\ |
||
4978 | if( typeof xaxislabel !== 'undefined' ){\ |
||
4979 | ctx.save();\ |
||
4980 | ctx.font = \"italic \"+font_size+\"px Ariel\";\ |
||
4981 | var corr = ctx.measureText(xaxislabel).width;\ |
||
4982 | ctx.fillText(xaxislabel,xsize - 1.5*corr,zero_y - tics_length - 0.4*font_size);\ |
||
4983 | ctx.restore();\ |
||
4984 | };\ |
||
4985 | if( typeof yaxislabel !== 'undefined' ){\ |
||
4986 | ctx.save();\ |
||
4987 | ctx.font = \"italic \"+font_size+\"px Ariel\";\ |
||
4988 | corr = ctx.measureText(yaxislabel).width;\ |
||
4989 | ctx.translate(zero_x+tics_length + font_size,corr+font_size);\ |
||
4990 | ctx.rotate(-0.5*Math.PI);\ |
||
4991 | ctx.fillText(yaxislabel,0,0);\ |
||
4992 | ctx.restore();\ |
||
4993 | };\ |
||
4994 | ctx.stroke();\ |
||
4995 | ctx.closePath();\ |
||
4996 | if( use_axis == 1 ){\ |
||
4997 | ctx.beginPath();\ |
||
4998 | ctx.strokeStyle = stroke_color;\ |
||
4999 | ctx.lineWidth = 0.6*line_width;\ |
||
5000 | for(var p = zero_x ; p < xsize; p = p + x2step){\ |
||
5001 | ctx.moveTo(p,0);\ |
||
5002 | ctx.lineTo(p,ysize);\ |
||
5003 | };\ |
||
5004 | for(var p = zero_x ; p > 0; p = p - x2step){\ |
||
5005 | ctx.moveTo(p,0);\ |
||
5006 | ctx.lineTo(p,ysize);\ |
||
5007 | };\ |
||
5008 | for(var p = zero_y ; p < ysize; p = p + y2step){\ |
||
5009 | ctx.moveTo(0,p);\ |
||
5010 | ctx.lineTo(xsize,p);\ |
||
5011 | };\ |
||
5012 | for(var p = zero_y ; p > 0; p = p - y2step){\ |
||
5013 | ctx.moveTo(0,p);\ |
||
5014 | ctx.lineTo(xsize,p);\ |
||
5015 | };\ |
||
5016 | ctx.stroke();\ |
||
5017 | ctx.closePath();\ |
||
5018 | ctx.beginPath();\ |
||
5019 | ctx.lineWidth = 2*line_width;\ |
||
5020 | ctx.strokeStyle = axis_color;\ |
||
5021 | ctx.moveTo(0,zero_y);\ |
||
5022 | ctx.lineTo(xsize,zero_y);\ |
||
5023 | ctx.moveTo(zero_x,0);\ |
||
5024 | ctx.lineTo(zero_x,ysize);\ |
||
5025 | ctx.stroke();\ |
||
5026 | ctx.closePath();\ |
||
5027 | ctx.lineWidth = line_width+0.5;\ |
||
5028 | ctx.beginPath();\ |
||
5029 | for(var p = zero_x ; p < xsize; p = p + xstep){\ |
||
5030 | ctx.moveTo(p,zero_y-tics_length);\ |
||
5031 | ctx.lineTo(p,zero_y+tics_length);\ |
||
5032 | };\ |
||
5033 | for(var p = zero_x ; p > 0; p = p - xstep){\ |
||
5034 | ctx.moveTo(p,zero_y-tics_length);\ |
||
5035 | ctx.lineTo(p,zero_y+tics_length);\ |
||
5036 | };\ |
||
5037 | for(var p = zero_y ; p < ysize; p = p + ystep){\ |
||
5038 | ctx.moveTo(zero_x-tics_length,p);\ |
||
5039 | ctx.lineTo(zero_x+tics_length,p);\ |
||
5040 | };\ |
||
5041 | for(var p = zero_y ; p > 0; p = p - ystep){\ |
||
5042 | ctx.moveTo(zero_x-tics_length,p);\ |
||
5043 | ctx.lineTo(zero_x+tics_length,p);\ |
||
5044 | };\ |
||
5045 | for(var p = zero_x ; p < xsize; p = p + x2step){\ |
||
5046 | ctx.moveTo(p,zero_y-0.5*tics_length);\ |
||
5047 | ctx.lineTo(p,zero_y+0.5*tics_length);\ |
||
5048 | };\ |
||
5049 | for(var p = zero_x ; p > 0; p = p - x2step){\ |
||
5050 | ctx.moveTo(p,zero_y-0.5*tics_length);\ |
||
5051 | ctx.lineTo(p,zero_y+0.5*tics_length);\ |
||
5052 | };\ |
||
5053 | for(var p = zero_y ; p < ysize; p = p + y2step){\ |
||
5054 | ctx.moveTo(zero_x-0.5*tics_length,p);\ |
||
5055 | ctx.lineTo(zero_x+0.5*tics_length,p);\ |
||
5056 | };\ |
||
5057 | for(var p = zero_y ; p > 0; p = p - y2step){\ |
||
5058 | ctx.moveTo(zero_x-0.5*tics_length,p);\ |
||
5059 | ctx.lineTo(zero_x+0.5*tics_length,p);\ |
||
5060 | };\ |
||
5061 | ctx.stroke();\ |
||
5062 | ctx.closePath();\ |
||
5063 | if( use_axis_numbering == 1 ){\ |
||
5064 | var shift = zero_y+2*font_size;var flip=0;var skip=0;var corr;var cnt;var disp_cnt;var prec;\ |
||
5065 | if( x_strings != null ){\ |
||
5066 | var f = 1.4;\ |
||
5067 | var len = x_strings.length;if((len/2+0.5)%%2 == 0){ alert(\"xaxis number unpaired: text missing ! \");return;};\ |
||
5068 | for(var p = 0 ; p < len ; p = p+2){\ |
||
5069 | var x_nums = x2px(eval(x_strings[p]));\ |
||
5070 | var x_text = x_strings[p+1];\ |
||
5071 | corr = ctx.measureText(x_text).width;\ |
||
5072 | skip = 1.2*corr/xstep;\ |
||
5073 | if( zero_y+2*font_size > ysize ){shift = ysize - 2*font_size;};\ |
||
5074 | if( skip > 1 ){if(flip == 0 ){flip = 1; shift = shift + font_size;}else{flip = 0; shift = shift - font_size;}};\ |
||
5075 | ctx.fillText(x_text,parseInt(x_nums-0.5*corr),shift);\ |
||
5076 | }\ |
||
5077 | }\ |
||
5078 | else\ |
||
5079 | {\ |
||
7654 | schaersvoo | 5080 | corr=0;skip = 1;cnt = px2x(zero_x);\ |
7614 | schaersvoo | 5081 | prec = Math.log(precision)/(Math.log(10));\ |
7654 | schaersvoo | 5082 | for( var p = zero_x ; p < xsize ; p = p+xstep){\ |
7614 | schaersvoo | 5083 | if(skip == 0 ){\ |
5084 | disp_cnt = cnt.toFixed(prec);\ |
||
5085 | corr = ctx.measureText(disp_cnt).width;\ |
||
5086 | skip = parseInt(1.2*corr/xstep);\ |
||
7654 | schaersvoo | 5087 | ctx.fillText(disp_cnt,p-0.5*corr,parseInt(zero_y+(1.4*f_x*font_size)));\ |
7614 | schaersvoo | 5088 | }\ |
5089 | else\ |
||
5090 | {\ |
||
5091 | skip--;\ |
||
5092 | };\ |
||
5093 | cnt = cnt + xmajor;\ |
||
5094 | };\ |
||
7654 | schaersvoo | 5095 | cnt = px2x(zero_x);skip = 1;\ |
5096 | for( var p = zero_x ; p > 0 ; p = p-xstep){\ |
||
7614 | schaersvoo | 5097 | if(skip == 0 ){\ |
5098 | disp_cnt = cnt.toFixed(prec);\ |
||
5099 | corr = ctx.measureText(disp_cnt).width;\ |
||
5100 | skip = parseInt(1.2*corr/xstep);\ |
||
7654 | schaersvoo | 5101 | ctx.fillText(disp_cnt,p-0.5*corr,parseInt(zero_y+(1.4*f_x*font_size)));\ |
7614 | schaersvoo | 5102 | }\ |
5103 | else\ |
||
5104 | {\ |
||
5105 | skip--;\ |
||
5106 | };\ |
||
5107 | cnt = cnt - xmajor;\ |
||
5108 | };\ |
||
5109 | };\ |
||
5110 | if( y_strings != null ){\ |
||
5111 | var len = y_strings.length;if((len/2+0.5)%%2 == 0){ alert(\"yaxis number unpaired: text missing ! \");return;};\ |
||
5112 | for(var p = 0 ; p < len ; p = p+2){\ |
||
5113 | var y_nums = y2px(eval(y_strings[p]));\ |
||
5114 | var y_text = y_strings[p+1];\ |
||
5115 | var f = 1.4;\ |
||
5116 | corr = 2 + tics_length + ctx.measureText(y_text).width;\ |
||
5117 | if( corr > zero_x){corr = parseInt(zero_x+2); }\ |
||
5118 | ctx.fillText(y_text,zero_x - corr,y_nums);\ |
||
5119 | };\ |
||
5120 | }\ |
||
5121 | else\ |
||
5122 | {\ |
||
7654 | schaersvoo | 5123 | corr = 0;cnt = px2y(zero_y);skip = 1;\ |
5124 | for( var p = zero_y ; p < ysize ; p = p+ystep){\ |
||
7614 | schaersvoo | 5125 | if(skip == 0 ){\ |
5126 | skip = parseInt(1.4*font_size/ystep);\ |
||
5127 | disp_cnt = cnt.toFixed(prec);\ |
||
7654 | schaersvoo | 5128 | if(f_y == 1){corr = 2 + tics_length + ctx.measureText(disp_cnt).width;}\ |
5129 | ctx.fillText(disp_cnt,parseInt(zero_x - corr),parseInt(p+(0.4*font_size)));\ |
||
7614 | schaersvoo | 5130 | }\ |
5131 | else\ |
||
5132 | {\ |
||
5133 | skip--;\ |
||
5134 | };\ |
||
5135 | cnt = cnt - ymajor;\ |
||
5136 | }\ |
||
7654 | schaersvoo | 5137 | corr = 0;cnt = px2y(zero_y);skip = 1;\ |
5138 | for( var p = zero_y ; p > 0 ; p = p-ystep){\ |
||
7614 | schaersvoo | 5139 | if(skip == 0 ){\ |
5140 | skip = parseInt(1.4*font_size/ystep);\ |
||
5141 | disp_cnt = cnt.toFixed(prec);\ |
||
7654 | schaersvoo | 5142 | if(f_y == 1){corr = 2 + tics_length + ctx.measureText(disp_cnt).width;}\ |
5143 | ctx.fillText(disp_cnt,parseInt(zero_x - corr),parseInt(p+(0.4*font_size)));\ |
||
7614 | schaersvoo | 5144 | }\ |
5145 | else\ |
||
5146 | {\ |
||
5147 | skip--;\ |
||
5148 | };\ |
||
5149 | cnt = cnt + ymajor;\ |
||
5150 | }\ |
||
5151 | };\ |
||
5152 | };\ |
||
5153 | ctx.strokeStyle = stroke_color;\ |
||
5154 | ctx.lineWidth = 2;\ |
||
5155 | ctx.beginPath();\ |
||
5156 | ctx.rect(0,0,xsize,ysize);\ |
||
5157 | ctx.closePath();\ |
||
5158 | ctx.stroke();\ |
||
5159 | };\ |
||
5160 | if( typeof linegraph_0 !== 'undefined' ){\ |
||
5161 | ctx.restore();\ |
||
5162 | ctx.save();\ |
||
5163 | ctx.globalAlpha = 1.0;\ |
||
5164 | var i = 0;\ |
||
5165 | var line_name = eval('linegraph_'+i);\ |
||
5166 | while ( typeof line_name !== 'undefined' ){\ |
||
5167 | ctx.strokeStyle = 'rgba('+line_name[0]+','+stroke_opacity+')';\ |
||
5168 | ctx.lineWidth = parseInt(line_name[1]);\ |
||
5169 | if(line_name[2] == \"1\"){\ |
||
5170 | var d1 = parseInt(line_name[3]);\ |
||
5171 | var d2 = parseInt(line_name[4]);\ |
||
5172 | if(ctx.setLineDash){ ctx.setLineDash(d1,d2); } else { ctx.mozDash = [d1,d2];};\ |
||
5173 | }\ |
||
5174 | else\ |
||
5175 | {\ |
||
5176 | if(ctx.setLineDash){ctx.setLineDash = null;}\ |
||
5177 | if(ctx.mozDash){ctx.mozDash = null;}\ |
||
5178 | };\ |
||
5179 | var data_x = new Array();\ |
||
5180 | var data_y = new Array();\ |
||
5181 | var lb = line_name.length;\ |
||
5182 | var idx = 0;\ |
||
5183 | for( var p = 5 ; p < lb ; p = p + 2 ){\ |
||
5184 | data_x[idx] = x2px(line_name[p]);\ |
||
5185 | data_y[idx] = y2px(line_name[p+1]);\ |
||
5186 | idx++;\ |
||
5187 | };\ |
||
5188 | for( var p = 0; p < idx ; p++){\ |
||
5189 | ctx.beginPath();\ |
||
5190 | ctx.moveTo(data_x[p],data_y[p]);\ |
||
5191 | ctx.lineTo(data_x[p+1],data_y[p+1]);\ |
||
5192 | ctx.stroke();\ |
||
5193 | ctx.closePath();\ |
||
5194 | };\ |
||
5195 | i++;\ |
||
5196 | try{ line_name = eval('linegraph_'+i); }catch(e){ break; }\ |
||
5197 | };\ |
||
5198 | };\ |
||
5199 | var barcolor = new Array();\ |
||
5200 | if( typeof barchart%d !== 'undefined' ){\ |
||
5201 | ctx.restore();\ |
||
5202 | ctx.save();\ |
||
5203 | ctx.globalAlpha = 1.0;\ |
||
5204 | var bar_x = new Array();\ |
||
5205 | var bar_y = new Array();\ |
||
5206 | var lb = barchart%d.length;\ |
||
5207 | var idx = 0;\ |
||
5208 | for( var p = 0 ; p < lb ; p = p + 3 ){\ |
||
5209 | bar_x[idx] = x2px(barchart%d[p]);\ |
||
5210 | bar_y[idx] = y2px(barchart%d[p+1]);\ |
||
5211 | barcolor[idx] = barchart%d[p+2];\ |
||
5212 | idx++;\ |
||
5213 | };\ |
||
5214 | var dx = parseInt(0.6*xstep);\ |
||
5215 | ctx.globalAlpha = fill_opacity;\ |
||
5216 | for( var p = 0; p < idx ; p++ ){\ |
||
5217 | ctx.beginPath();\ |
||
5218 | ctx.strokeStyle = barcolor[p];\ |
||
5219 | ctx.fillStyle = barcolor[p];\ |
||
5220 | ctx.rect(bar_x[p]-0.5*dx,bar_y[p],dx,zero_y - bar_y[p]);\ |
||
5221 | ctx.fill();\ |
||
5222 | ctx.stroke();\ |
||
5223 | ctx.closePath();\ |
||
5224 | };\ |
||
5225 | };\ |
||
5226 | if( typeof legend%d !== 'undefined' ){\ |
||
5227 | ctx.globalAlpha = 1.0;\ |
||
5228 | ctx.font = \"bold \"+font_size+\"px Ariel\";\ |
||
5229 | var y_offset = 2*font_size;\ |
||
5230 | var txt;var txt_size;\ |
||
5231 | var x_offset = xsize - 2*font_size;\ |
||
5232 | var l_length = legend%d.length;\ |
||
5233 | if( typeof legendcolors%d !== 'undefined' ){\ |
||
5234 | for(var p = 0 ; p < l_length ; p++){\ |
||
5235 | barcolor[p] = legendcolors%d[p];\ |
||
5236 | };\ |
||
5237 | }else{\ |
||
5238 | if( barcolor.length == 0 ){\ |
||
5239 | for(var p = 0 ; p < l_length ; p++){\ |
||
5240 | barcolor[p] = stroke_color;\ |
||
5241 | };\ |
||
5242 | };\ |
||
5243 | };\ |
||
5244 | for(var p = 0; p < l_length; p++){\ |
||
5245 | ctx.fillStyle = barcolor[p];\ |
||
5246 | txt = legend%d[p];\ |
||
5247 | txt_size = ctx.measureText(txt).width;\ |
||
5248 | ctx.fillText(legend%d[p],x_offset - txt_size, y_offset);\ |
||
5249 | y_offset = parseInt(y_offset + 1.5*font_size);\ |
||
5250 | };\ |
||
5251 | };\ |
||
5252 | ctx.restore();\ |
||
5253 | return;\ |
||
7653 | schaersvoo | 5254 | };",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,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 5255 | break; |
7842 | bpr | 5256 | |
7614 | schaersvoo | 5257 | case DRAW_PIECHART: |
5258 | fprintf(js_include_file,"\n<!-- draw piechars -->\n\ |
||
5259 | function draw_piechart(canvas_type,x_center,y_center,radius, data_color_list,fill_opacity,font_size,font_family){\ |
||
5260 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
5261 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
5262 | }\ |
||
5263 | else\ |
||
5264 | {\ |
||
5265 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
5266 | };\ |
||
5267 | var ld = data_color_list.length;\ |
||
5268 | var sum = 0;\ |
||
5269 | var idx = 0;\ |
||
5270 | var colors = new Array();\ |
||
5271 | var data = new Array();\ |
||
5272 | for(var p = 0;p < ld; p = p + 2){\ |
||
5273 | data[idx] = parseFloat(data_color_list[p]);\ |
||
5274 | sum = sum + data[idx];\ |
||
5275 | colors[idx] = data_color_list[p+1];\ |
||
5276 | idx++;\ |
||
5277 | };\ |
||
5278 | var ctx = obj.getContext(\"2d\");\ |
||
5279 | ctx.save();\ |
||
5280 | var angle;\ |
||
5281 | var angle_end = 0;\ |
||
5282 | var offset = Math.PI / 2;\ |
||
5283 | ctx.globalAlpha = fill_opacity;\ |
||
5284 | for(var p=0; p < idx; p++){\ |
||
5285 | ctx.beginPath();\ |
||
5286 | ctx.fillStyle = colors[p];\ |
||
5287 | ctx.moveTo(x_center,y_center);\ |
||
5288 | angle = Math.PI * (2 * data[p] / sum);\ |
||
5289 | ctx.arc(x_center,y_center, radius, angle_end - offset, angle_end + angle - offset, false);\ |
||
5290 | ctx.lineTo(x_center, y_center);\ |
||
5291 | ctx.fill();\ |
||
5292 | ctx.closePath();\ |
||
5293 | angle_end = angle_end + angle;\ |
||
5294 | };\ |
||
5295 | if( typeof legend%d !== 'undefined' ){\ |
||
5296 | ctx.globalAlpha = 1.0;\ |
||
5297 | ctx.font = font_size+\"px \"+font_family;\ |
||
5298 | var y_offset = font_size; \ |
||
5299 | var x_offset = 0;\ |
||
5300 | var txt;var txt_size;\ |
||
5301 | for(var p = 0; p < idx; p++){\ |
||
5302 | ctx.fillStyle = colors[p];\ |
||
5303 | txt = legend%d[p];\ |
||
5304 | txt_size = ctx.measureText(txt).width;\ |
||
5305 | if( x_center + radius + txt_size > xsize ){ x_offset = x_center + radius + txt_size - xsize;} else { x_offset = 0; };\ |
||
5306 | ctx.fillText(legend%d[p],x_center + radius - x_offset, y_center - radius + y_offset);\ |
||
5307 | y_offset = parseInt(y_offset + 1.5*font_size);\ |
||
5308 | };\ |
||
5309 | };\ |
||
5310 | ctx.restore();\ |
||
7653 | schaersvoo | 5311 | };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id); |
7842 | bpr | 5312 | |
7614 | schaersvoo | 5313 | break; |
5314 | case DRAW_ARCS: |
||
5315 | fprintf(js_include_file,"\n<!-- draw arcs -->\n\ |
||
5316 | draw_arc = function(canvas_type,xc,yc,r,start,end,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,use_rotate,angle,use_translate,vector){\ |
||
5317 | var obj;\ |
||
5318 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
5319 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
5320 | }\ |
||
5321 | else\ |
||
5322 | {\ |
||
5323 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
5324 | };\ |
||
5325 | var ctx = obj.getContext(\"2d\");\ |
||
5326 | ctx.save();\ |
||
5327 | if( use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{if(ctx.mozDash){ ctx.mozDash = [dashtype0,dashtype1];};};};\ |
||
5328 | if( use_translate == 1 ){ctx.translate(vector[0],vector[1]);};\ |
||
5329 | if( use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);};\ |
||
5330 | if(end < start){var tmp = end;end = start;start=tmp;};\ |
||
5331 | start=360-start;\ |
||
5332 | end=360-end;\ |
||
5333 | ctx.lineWidth = line_width;\ |
||
5334 | ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
5335 | if( use_filled == 1 ){\ |
||
5336 | ctx.beginPath();\ |
||
5337 | ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\ |
||
5338 | var x1 = xc + r*Math.cos(Math.PI*start/180);\ |
||
5339 | var y1 = yc + r*Math.sin(Math.PI*start/180);\ |
||
5340 | var x2 = xc + r*Math.cos(Math.PI*end/180);\ |
||
5341 | var y2 = yc + r*Math.sin(Math.PI*end/180);\ |
||
5342 | ctx.beginPath();\ |
||
5343 | ctx.moveTo(x1,y1);\ |
||
5344 | ctx.lineTo(xc,yc);\ |
||
5345 | ctx.moveTo(xc,yc);\ |
||
5346 | ctx.lineTo(x2,y2);\ |
||
5347 | ctx.closePath();\ |
||
5348 | ctx.arc(xc, yc, r, start*(Math.PI / 180), end*(Math.PI / 180),true);\ |
||
5349 | ctx.fill();\ |
||
5350 | ctx.stroke();\ |
||
5351 | }\ |
||
5352 | else\ |
||
5353 | {\ |
||
5354 | ctx.beginPath();\ |
||
5355 | ctx.arc(xc, yc, r, start*(Math.PI / 180), end*(Math.PI / 180),true);\ |
||
5356 | ctx.stroke();\ |
||
5357 | ctx.closePath();\ |
||
5358 | }\ |
||
5359 | ctx.restore();\ |
||
7653 | schaersvoo | 5360 | };",canvas_root_id,canvas_root_id,canvas_root_id); |
7842 | bpr | 5361 | |
7614 | schaersvoo | 5362 | break; |
5363 | case DRAW_TEXTS: |
||
5364 | fprintf(js_include_file,"\n<!-- draw text -->\n\ |
||
5365 | draw_text = function(canvas_type,x,y,font_size,font_family,stroke_color,stroke_opacity,angle2,text,use_rotate,angle,use_translate,vector){\ |
||
5366 | var obj;\ |
||
5367 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
5368 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
5369 | }\ |
||
5370 | else\ |
||
5371 | {\ |
||
5372 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
5373 | };\ |
||
5374 | var ctx = obj.getContext(\"2d\");\ |
||
5375 | if(angle2 == 0 && angle != 0){\ |
||
5376 | ctx.save();\ |
||
5377 | if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\ |
||
5378 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
||
5379 | };\ |
||
5380 | if( font_family.indexOf('px') != null ){\ |
||
5381 | ctx.font = font_family;\ |
||
5382 | }\ |
||
5383 | else\ |
||
5384 | {\ |
||
5385 | ctx.font = \"+font_size+'px '+font_family \";\ |
||
5386 | };\ |
||
5387 | ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
5388 | if(angle2 != 0){\ |
||
5389 | ctx.save();\ |
||
5390 | ctx.translate(x,y);\ |
||
5391 | ctx.rotate((360-angle2)*(Math.PI / 180));\ |
||
5392 | ctx.fillText(text,0,0);\ |
||
5393 | ctx.restore();\ |
||
5394 | }else{ctx.fillText(text,x,y);};\ |
||
5395 | ctx.restore();\ |
||
5396 | return;\ |
||
7653 | schaersvoo | 5397 | };",canvas_root_id,canvas_root_id,canvas_root_id); |
7842 | bpr | 5398 | |
7614 | schaersvoo | 5399 | break; |
5400 | case DRAW_CURVE: |
||
5401 | fprintf(js_include_file,"\n<!-- draw curve -->\n\ |
||
5402 | draw_curve = function(canvas_type,type,x_points,y_points,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,use_rotate,angle,use_translate,vector){\ |
||
5403 | var obj;\ |
||
5404 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
5405 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
5406 | }\ |
||
5407 | else\ |
||
5408 | {\ |
||
5409 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
5410 | };\ |
||
5411 | var ctx = obj.getContext(\"2d\");\ |
||
5412 | ctx.save();\ |
||
5413 | if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\ |
||
5414 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
||
5415 | ctx.beginPath();ctx.lineWidth = line_width;\ |
||
5416 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
5417 | ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
5418 | ctx.moveTo(x2px(x_points[0]),y2px(y_points[0]));\ |
||
5419 | for(var p = 1 ; p < x_points.length ; p++){\ |
||
5420 | if( y2px(y_points[p]) > -5 && y2px(y_points[p]) < ysize+5 ){\ |
||
5421 | ctx.lineTo(x2px(x_points[p]),y2px(y_points[p]));\ |
||
5422 | }\ |
||
5423 | else\ |
||
5424 | {\ |
||
5425 | ctx.stroke();\ |
||
5426 | ctx.beginPath();\ |
||
5427 | p++;\ |
||
5428 | ctx.moveTo(x2px(x_points[p]),y2px(y_points[p]));\ |
||
5429 | };\ |
||
5430 | };\ |
||
5431 | ctx.stroke();\ |
||
5432 | ctx.restore();\ |
||
7653 | schaersvoo | 5433 | };",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 5434 | break; |
7842 | bpr | 5435 | |
7614 | schaersvoo | 5436 | case DRAW_INPUTS: |
5437 | fprintf(js_include_file,"\n<!-- draw input fields -->\n\ |
||
5438 | draw_inputs = function(root_id,input_cnt,x,y,size,readonly,style,value){\ |
||
5439 | var canvas_div = document.getElementById(\"canvas_div\"+root_id);\ |
||
5440 | var input = document.createElement(\"input\");\ |
||
5441 | input.setAttribute(\"id\",\"canvas_input\"+input_cnt);\ |
||
5442 | input.setAttribute(\"style\",\"position:absolute;left:\"+x+\"px;top:\"+y+\"px;\"+style);\ |
||
5443 | input.setAttribute(\"size\",size);\ |
||
5444 | input.setAttribute(\"value\",value);\ |
||
5445 | if( readonly == 0 ){ input.setAttribute(\"readonly\",\"readonly\");};\ |
||
7653 | schaersvoo | 5446 | canvas_div.appendChild(input);};"); |
7614 | schaersvoo | 5447 | break; |
7842 | bpr | 5448 | |
7614 | schaersvoo | 5449 | case DRAW_TEXTAREAS: |
5450 | fprintf(js_include_file,"\n<!-- draw text area inputfields -->\n\ |
||
5451 | draw_textareas = function(root_id,input_cnt,x,y,cols,rows,readonly,style,value){\ |
||
5452 | var canvas_div = document.getElementById(\"canvas_div\"+root_id);\ |
||
5453 | var textarea = document.createElement(\"textarea\");\ |
||
5454 | textarea.setAttribute(\"id\",\"canvas_input\"+input_cnt);\ |
||
5455 | textarea.setAttribute(\"style\",\"position:absolute;left:\"+x+\"px;top:\"+y+\"px;\"+style);\ |
||
5456 | textarea.setAttribute(\"cols\",cols);\ |
||
5457 | textarea.setAttribute(\"rows\",rows);\ |
||
5458 | textarea.innerHTML = value;\ |
||
7653 | schaersvoo | 5459 | canvas_div.appendChild(textarea);};"); |
7614 | schaersvoo | 5460 | break; |
7842 | bpr | 5461 | |
7614 | schaersvoo | 5462 | case DRAW_PIXELS: |
5463 | fprintf(js_include_file,"\n<!-- draw pixel -->\n\ |
||
5464 | draw_setpixel = function(x,y,color,opacity,pixelsize){\ |
||
5465 | var canvas = create_canvas%d(10,xsize,ysize);\ |
||
5466 | var d = 0.5*pixelsize;\ |
||
5467 | var ctx = canvas.getContext(\"2d\");\ |
||
5468 | ctx.fillStyle = \"rgba(\"+color+\",\"+opacity+\")\";\ |
||
5469 | ctx.clearRect(0,0,xsize,ysize);\ |
||
5470 | for(var p=0; p<x.length;p++){\ |
||
5471 | ctx.fillRect( x2px(x[p]) - d, y2px(y[p]) - d , pixelsize, pixelsize );\ |
||
5472 | };\ |
||
5473 | ctx.fill();ctx.stroke();\ |
||
5474 | };",canvas_root_id); |
||
5475 | break; |
||
5476 | |||
5477 | case DRAW_CLOCK: |
||
5478 | fprintf(js_include_file,"\n<!-- begin command clock -->\n\ |
||
5479 | var clock_canvas = create_canvas%d(%d,xsize,ysize);\ |
||
5480 | var clock_ctx = clock_canvas.getContext(\"2d\");\ |
||
5481 | var clock = function(xc,yc,radius,H,M,S,type,interaction,h_color,m_color,s_color,bg_color,fg_color){\ |
||
5482 | clock_ctx.save();\ |
||
5483 | this.type = type || 0;\ |
||
5484 | this.interaction = interaction || 0;\ |
||
5485 | this.H = H || parseInt(110*(Math.random()));\ |
||
5486 | this.M = M || parseInt(590*(Math.random()));\ |
||
5487 | this.S = S || parseInt(590*(Math.random()));\ |
||
5488 | this.xc = xc || xsize/2;\ |
||
5489 | this.yc = yc || ysize/2;\ |
||
5490 | this.radius = radius || xsize/4;\ |
||
5491 | var font_size = parseInt(0.2*this.radius);\ |
||
5492 | this.H_color = h_color || \"blue\";\ |
||
5493 | this.M_color = m_color || \"blue\";\ |
||
5494 | this.S_color = s_color || \"blue\";\ |
||
5495 | this.fg_color = fg_color || \"red\";\ |
||
5496 | this.bg_color = bg_color || \"white\";\ |
||
5497 | clock_ctx.translate(this.xc,this.yc);\ |
||
5498 | clock_ctx.beginPath();\ |
||
5499 | clock_ctx.arc(0,0,this.radius,0,2*Math.PI,false);\ |
||
5500 | clock_ctx.fillStyle = this.bg_color;\ |
||
5501 | clock_ctx.fill();\ |
||
5502 | clock_ctx.closePath();\ |
||
5503 | clock_ctx.beginPath();\ |
||
5504 | clock_ctx.font = font_size+\"px Arial\";\ |
||
5505 | clock_ctx.fillStyle = this.fg_color;\ |
||
5506 | clock_ctx.textAlign = \"center\";\ |
||
5507 | clock_ctx.textBaseline = 'middle';\ |
||
5508 | var angle;var x1,y1,x2,y2;\ |
||
5509 | var angle_cos;var angle_sin;\ |
||
5510 | switch(type){\ |
||
5511 | case 0:clock_ctx.beginPath();\ |
||
5512 | for(var p = 1; p <= 12 ; p++){\ |
||
5513 | angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 12));\ |
||
5514 | angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 12));\ |
||
5515 | x1 = 0.8*angle_cos;y1 = 0.8*angle_sin;x2 = angle_cos;y2 = angle_sin;\ |
||
5516 | clock_ctx.moveTo(x1,y1);\ |
||
5517 | clock_ctx.lineTo(x2,y2);\ |
||
5518 | };\ |
||
5519 | for(var p = 1; p <= 60 ; p++){\ |
||
5520 | angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 60));\ |
||
5521 | angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 60));\ |
||
5522 | x1 = 0.9*angle_cos;y1 = 0.9*angle_sin;x2 = angle_cos;y2 = angle_sin;\ |
||
5523 | clock_ctx.moveTo(x1,y1);\ |
||
5524 | clock_ctx.lineTo(x2,y2);\ |
||
5525 | };\ |
||
5526 | clock_ctx.closePath();\ |
||
5527 | clock_ctx.stroke();\ |
||
5528 | break;\ |
||
5529 | case 1:\ |
||
5530 | 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;\ |
||
5531 | case 2:for(var p= 1; p <= 12 ; p++){ angle = (p - 3) * (Math.PI * 2) / 12;x1 = 1.1*this.radius*Math.cos(angle);y1 = 1.1*this.radius*Math.sin(angle);clock_ctx.fillText(p, x1, y1);};\ |
||
5532 | clock_ctx.beginPath();\ |
||
5533 | for(var p = 1; p <= 12 ; p++){\ |
||
5534 | angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 12));\ |
||
5535 | angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 12));\ |
||
5536 | x1 = 0.9*angle_cos;y1 = 0.9*angle_sin;x2 = angle_cos;y2 = angle_sin;\ |
||
5537 | clock_ctx.moveTo(x1,y1);\ |
||
5538 | clock_ctx.lineTo(x2,y2);\ |
||
5539 | };\ |
||
5540 | for(var p = 1; p <= 60 ; p++){\ |
||
5541 | angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 60));\ |
||
5542 | angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 60));\ |
||
5543 | x1 = 0.95*angle_cos;y1 = 0.95*angle_sin;x2 = angle_cos;y2 = angle_sin;\ |
||
5544 | clock_ctx.moveTo(x1,y1);\ |
||
5545 | clock_ctx.lineTo(x2,y2);\ |
||
5546 | };\ |
||
5547 | clock_ctx.closePath();\ |
||
5548 | clock_ctx.stroke();\ |
||
5549 | break;\ |
||
5550 | };\ |
||
5551 | angle = (this.H - 3 + this.M/60 ) * 2 * Math.PI / 12;\ |
||
5552 | clock_ctx.rotate(angle);\ |
||
5553 | clock_ctx.beginPath();\ |
||
5554 | clock_ctx.moveTo(-3, -2);\ |
||
5555 | clock_ctx.lineTo(-3, 2);\ |
||
5556 | clock_ctx.lineTo(this.radius * 0.7, 1);\ |
||
5557 | clock_ctx.lineTo(this.radius * 0.7, -1);\ |
||
5558 | clock_ctx.fillStyle = this.H_color;\ |
||
5559 | clock_ctx.fill();\ |
||
5560 | clock_ctx.rotate(-angle);\ |
||
5561 | angle = (this.M - 15 + this.S/60) * 2 * Math.PI / 60;\ |
||
5562 | clock_ctx.rotate(angle);\ |
||
5563 | clock_ctx.beginPath();\ |
||
5564 | clock_ctx.moveTo(-3, -2);\ |
||
5565 | clock_ctx.lineTo(-3, 2);\ |
||
5566 | clock_ctx.lineTo(this.radius * 0.8, 1);\ |
||
5567 | clock_ctx.lineTo(this.radius * 0.8, -1);\ |
||
5568 | clock_ctx.fillStyle = this.M_color;\ |
||
5569 | clock_ctx.fill();\ |
||
5570 | clock_ctx.rotate(-angle);\ |
||
5571 | angle = (this.S - 15) * 2 * Math.PI / 60;\ |
||
5572 | clock_ctx.rotate(angle);\ |
||
5573 | clock_ctx.beginPath();\ |
||
5574 | clock_ctx.moveTo(0,0);\ |
||
5575 | clock_ctx.lineTo(this.radius * 0.95, 0);\ |
||
5576 | clock_ctx.lineTo(this.radius * 0.9, -1);\ |
||
5577 | clock_ctx.strokeStyle = this.S_color;\ |
||
5578 | clock_ctx.stroke();\ |
||
5579 | clock_ctx.restore();\ |
||
7653 | schaersvoo | 5580 | };",canvas_root_id,CLOCK_CANVAS); |
7614 | schaersvoo | 5581 | break; |
5582 | |||
5583 | case DRAW_LATTICE: |
||
5584 | fprintf(js_include_file,"\n<!-- draw lattice -->\n\ |
||
5585 | 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_translate,vector){\ |
||
5586 | var obj;\ |
||
5587 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
5588 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
5589 | }\ |
||
5590 | else\ |
||
5591 | {\ |
||
5592 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
5593 | };\ |
||
5594 | var ctx = obj.getContext(\"2d\");\ |
||
5595 | ctx.save();\ |
||
5596 | if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\ |
||
5597 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
||
5598 | ctx.fillStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
5599 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
5600 | var radius = line_width;\ |
||
5601 | var x = 0;\ |
||
5602 | var y = 0;\ |
||
5603 | var x_step_px = xsize/(xmax-xmin);\ |
||
5604 | var y_step_px = ysize/(ymax-ymin);\ |
||
5605 | var xv1 = dx1*x_step_px;\ |
||
5606 | var yv1 = dy1*y_step_px;\ |
||
5607 | var xv2 = dx2*x_step_px;\ |
||
5608 | var yv2 = dy2*y_step_px;\ |
||
5609 | for(var p = 0; p < n1 ;p++){\ |
||
5610 | x = p*xv1 + x0;\ |
||
5611 | y = p*yv1 + y0;\ |
||
5612 | for(var c = 0; c < n2 ; c++){\ |
||
5613 | ctx.beginPath();\ |
||
5614 | ctx.arc(x+c*xv2,y+c*yv2,radius,0,2*Math.PI,false);\ |
||
5615 | ctx.fill();\ |
||
5616 | ctx.stroke();\ |
||
5617 | ctx.closePath();\ |
||
5618 | };\ |
||
5619 | };\ |
||
5620 | ctx.restore();\ |
||
5621 | return;\ |
||
7653 | schaersvoo | 5622 | };",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 5623 | break; |
7735 | schaersvoo | 5624 | case DRAW_XYLOGSCALE: |
5625 | fprintf(js_include_file,"\n<!-- draw xylogscale -->\n\ |
||
7779 | schaersvoo | 5626 | 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){\n\ |
7735 | schaersvoo | 5627 | var obj;\n\ |
5628 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\n\ |
||
5629 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\n\ |
||
5630 | }\n\ |
||
5631 | else\n\ |
||
5632 | {\n\ |
||
5633 | obj = create_canvas%d(canvas_type,xsize,ysize);\n\ |
||
5634 | };\n\ |
||
5635 | var ctx = obj.getContext(\"2d\");\n\ |
||
5636 | ctx.clearRect(0,0,xsize,ysize);\ |
||
5637 | ctx.save();\n\ |
||
7739 | schaersvoo | 5638 | var xmarge;var ymarge;var x_e;var y_e;var num;var corr;var xtxt;var ytxt;\ |
5639 | var x_min = Math.log(xmin)/Math.log(xlogbase);\n\ |
||
5640 | var x_max = Math.log(xmax)/Math.log(xlogbase);\n\ |
||
5641 | var y_min = Math.log(ymin)/Math.log(ylogbase);\n\ |
||
5642 | var y_max = Math.log(ymax)/Math.log(ylogbase);\n\ |
||
5643 | if(use_axis_numbering == 1){\ |
||
5644 | ctx.font = font_family;\n\ |
||
5645 | xmarge = ctx.measureText(ylogbase+'^'+y_max.toFixed(0)+' ').width;\n\ |
||
5646 | ymarge = parseInt(1.5*font_size);\n\ |
||
5647 | ctx.save();\n\ |
||
5648 | ctx.fillStyle=\"rgba(255,215,0,0.2)\";\n\ |
||
5649 | ctx.rect(0,0,xmarge,ysize);\n\ |
||
5650 | ctx.rect(0,ysize-ymarge,xsize,ysize);\n\ |
||
5651 | ctx.fill();\n\ |
||
5652 | ctx.restore();\n\ |
||
5653 | }else{xmarge = 0;ymarge = 0;};\n\ |
||
7735 | schaersvoo | 5654 | if( typeof xaxislabel !== 'undefined' ){\ |
7739 | schaersvoo | 5655 | ctx.save();\n\ |
5656 | ctx.font = \"italic \"+font_size+\"px Ariel\";\n\ |
||
5657 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\n\ |
||
5658 | corr = ctx.measureText(xaxislabel).width;\n\ |
||
5659 | ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\n\ |
||
5660 | ctx.restore();\n\ |
||
5661 | };\n\ |
||
7735 | schaersvoo | 5662 | if( typeof yaxislabel !== 'undefined' ){\ |
7739 | schaersvoo | 5663 | ctx.save();\n\ |
5664 | ctx.font = \"italic \"+font_size+\"px Ariel\";\n\ |
||
5665 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\n\ |
||
5666 | corr = ctx.measureText(yaxislabel).width;\n\ |
||
5667 | ctx.translate(xmarge+font_size,corr+font_size);\n\ |
||
5668 | ctx.rotate(-0.5*Math.PI);\n\ |
||
5669 | ctx.fillText(yaxislabel,0,0);\n\ |
||
5670 | ctx.restore();\n\ |
||
5671 | };\n\ |
||
5672 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\n\ |
||
5673 | ctx.lineWidth = line_width;\n\n\ |
||
7735 | schaersvoo | 5674 | for(var p = x_min; p <= x_max ; p++){\n\ |
7739 | schaersvoo | 5675 | num = Math.pow(xlogbase,p);\n\n\ |
7735 | schaersvoo | 5676 | for(var i = 1 ; i < xlogbase ; i++){\n\ |
7739 | schaersvoo | 5677 | x_e = x2px(i*num);\n\n\ |
7735 | schaersvoo | 5678 | if( i == 1 ){\ |
7739 | schaersvoo | 5679 | ctx.lineWidth = line_width;\n\n\ |
5680 | ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\n\ |
||
7738 | schaersvoo | 5681 | if( use_axis_numbering == 1 && p > x_min){\ |
7739 | schaersvoo | 5682 | xtxt = xlogbase+'^'+p.toFixed(0);\n\ |
5683 | corr = 0.5*(ctx.measureText(xtxt).width);\n\ |
||
5684 | ctx.fillText(xtxt,x_e - corr,ysize - 4);\n\ |
||
5685 | };\n\ |
||
7735 | schaersvoo | 5686 | }else{\ |
7739 | schaersvoo | 5687 | ctx.lineWidth = 0.2*line_width;\n\n\ |
5688 | ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\n\ |
||
5689 | };\n\ |
||
7738 | schaersvoo | 5690 | if( x_e >= xmarge ){\ |
5691 | ctx.beginPath();\n\ |
||
5692 | ctx.moveTo(x_e,0);\n\ |
||
7739 | schaersvoo | 5693 | ctx.lineTo(x_e,ysize - ymarge);\n\n\ |
7738 | schaersvoo | 5694 | ctx.stroke();\n\ |
5695 | ctx.closePath();\n\ |
||
5696 | };\ |
||
7735 | schaersvoo | 5697 | };\n\ |
5698 | };\n\ |
||
5699 | for(var p = y_min; p <= y_max ; p++){\n\ |
||
5700 | num = Math.pow(ylogbase,p);\n\ |
||
5701 | for(var i = 1 ; i < ylogbase ; i++){\n\ |
||
5702 | y_e = y2px(i*num);\n\ |
||
7739 | schaersvoo | 5703 | if( i == 1 ){\n\ |
7735 | schaersvoo | 5704 | ctx.lineWidth = line_width;\n\ |
5705 | ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\ |
||
7739 | schaersvoo | 5706 | if( use_axis_numbering == 1 && p > y_min){\n\ |
5707 | ctx.fillText(ylogbase+'^'+p.toFixed(0),0,y_e);\n\ |
||
5708 | };\n\ |
||
5709 | }else{\n\ |
||
7735 | schaersvoo | 5710 | ctx.lineWidth = 0.2*line_width;\n\ |
7739 | schaersvoo | 5711 | ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\n\ |
5712 | };\n\ |
||
7735 | schaersvoo | 5713 | ctx.beginPath();\n\ |
7738 | schaersvoo | 5714 | ctx.moveTo(xmarge,y_e);\n\ |
7735 | schaersvoo | 5715 | ctx.lineTo(xsize,y_e);\n\ |
5716 | ctx.stroke();\n\ |
||
5717 | ctx.closePath();\n\ |
||
5718 | };\n\ |
||
5719 | };\n\ |
||
5720 | ctx.restore();\ |
||
5721 | };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id); |
||
5722 | break; |
||
7614 | schaersvoo | 5723 | |
7735 | schaersvoo | 5724 | case DRAW_XLOGSCALE: |
5725 | fprintf(js_include_file,"\n<!-- draw xlogscale -->\n\ |
||
7779 | schaersvoo | 5726 | 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){\n\ |
7735 | schaersvoo | 5727 | var obj;\n\ |
5728 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\n\ |
||
5729 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\n\ |
||
5730 | }\n\ |
||
5731 | else\n\ |
||
5732 | {\n\ |
||
5733 | obj = create_canvas%d(canvas_type,xsize,ysize);\n\ |
||
5734 | };\n\ |
||
5735 | var ctx = obj.getContext(\"2d\");\n\ |
||
5736 | ctx.clearRect(0,0,xsize,ysize);\ |
||
5737 | ctx.save();\n\ |
||
5738 | ctx.lineWidth = line_width;\n\ |
||
7739 | schaersvoo | 5739 | var prec = Math.log(precision)/Math.log(10);\ |
7735 | schaersvoo | 5740 | var x_min = Math.log(xmin)/Math.log(xlogbase);\ |
5741 | var x_max = Math.log(xmax)/Math.log(xlogbase);\ |
||
5742 | var y_min = 0;var y_max = ysize;var x_e;var corr;\ |
||
7739 | schaersvoo | 5743 | var xtxt;var ytxt;var num;var xmarge;var ymarge;\ |
5744 | if(use_axis_numbering == 1){\ |
||
5745 | ctx.font = font_family;\n\ |
||
5746 | xmarge = ctx.measureText(ymax.toFixed(prec)+' ').width;\n\ |
||
5747 | ymarge = parseInt(1.5*font_size);\n\ |
||
5748 | ctx.save();\n\ |
||
5749 | ctx.fillStyle=\"rgba(255,215,0,0.2)\";\n\ |
||
5750 | ctx.rect(0,0,xmarge,ysize);\n\ |
||
5751 | ctx.rect(0,ysize-ymarge,xsize,ysize);\n\ |
||
5752 | ctx.fill();\n\ |
||
5753 | ctx.restore();\n\ |
||
5754 | }else{xmarge = 0;ymarge = 0;};\n\ |
||
5755 | if( typeof xaxislabel !== 'undefined' ){\ |
||
5756 | ctx.save();\n\ |
||
5757 | ctx.font = \"italic \"+font_size+\"px Ariel\";\n\ |
||
5758 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\n\ |
||
5759 | corr = ctx.measureText(xaxislabel).width;\n\ |
||
5760 | ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\n\ |
||
5761 | ctx.restore();\n\ |
||
5762 | };\n\ |
||
5763 | if( typeof yaxislabel !== 'undefined' ){\ |
||
5764 | ctx.save();\n\ |
||
5765 | ctx.font = \"italic \"+font_size+\"px Ariel\";\n\ |
||
5766 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\n\ |
||
5767 | corr = ctx.measureText(yaxislabel).width;\n\ |
||
5768 | ctx.translate(xmarge+font_size,corr+font_size);\n\ |
||
5769 | ctx.rotate(-0.5*Math.PI);\n\ |
||
5770 | ctx.fillText(yaxislabel,0,0);\n\ |
||
5771 | ctx.restore();\n\ |
||
5772 | };\n\ |
||
5773 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\n\ |
||
5774 | ctx.lineWidth = line_width;\n\n\ |
||
7735 | schaersvoo | 5775 | for(var p = x_min; p <= x_max ; p++){\n\ |
5776 | num = Math.pow(xlogbase,p);\n\ |
||
5777 | for(var i = 1 ; i < xlogbase ; i++){\n\ |
||
5778 | x_e = x2px(i*num);\n\ |
||
5779 | if( i == 1 ){\ |
||
7739 | schaersvoo | 5780 | ctx.lineWidth = line_width;\n\ |
5781 | ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\ |
||
5782 | if( use_axis_numbering == 1 && p > x_min ){\ |
||
7735 | schaersvoo | 5783 | xtxt = xlogbase+'^'+p.toFixed(0);\ |
5784 | corr = 0.5*(ctx.measureText(xtxt).width);\ |
||
5785 | ctx.fillText(xtxt,x_e - corr,ysize - 4);\ |
||
5786 | };\ |
||
5787 | }else{\ |
||
5788 | ctx.lineWidth = 0.2*line_width;\n\ |
||
5789 | ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\ |
||
5790 | };\ |
||
7739 | schaersvoo | 5791 | if( x_e >= xmarge ){\ |
5792 | ctx.beginPath();\n\ |
||
5793 | ctx.moveTo(x_e,0);\n\ |
||
5794 | ctx.lineTo(x_e,ysize - ymarge);\n\n\ |
||
5795 | ctx.stroke();\n\ |
||
5796 | ctx.closePath();\n\ |
||
5797 | };\ |
||
5798 | };\ |
||
7735 | schaersvoo | 5799 | };\n\ |
5800 | var stepy = Math.abs(y2px(ymajor) - y2px(0));\ |
||
5801 | var minor_step = stepy / yminor;\ |
||
7749 | schaersvoo | 5802 | for(var y = 0 ; y < ysize - stepy ; y = y + stepy){\ |
7735 | schaersvoo | 5803 | ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\ |
5804 | ctx.lineWidth = line_width;\n\ |
||
5805 | ctx.beginPath();\n\ |
||
7739 | schaersvoo | 5806 | ctx.moveTo(xmarge,y);\n\ |
7735 | schaersvoo | 5807 | ctx.lineTo(xsize,y);\n\ |
5808 | ctx.stroke();\n\ |
||
5809 | ctx.closePath();\n\ |
||
5810 | if( use_axis_numbering == 1){\ |
||
5811 | ytxt = (px2y(y)).toFixed(prec);\ |
||
5812 | ctx.fillText( ytxt,0 ,y + 0.5*font_size );\ |
||
5813 | };\ |
||
5814 | for(var dy = 1 ; dy < yminor ; dy++){\ |
||
5815 | ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\ |
||
5816 | ctx.lineWidth = 0.2*line_width;\n\ |
||
5817 | ctx.beginPath();\n\ |
||
7739 | schaersvoo | 5818 | ctx.moveTo(xmarge,y+dy*minor_step);\ |
7735 | schaersvoo | 5819 | ctx.lineTo(xsize,y+dy*minor_step);\n\ |
5820 | ctx.stroke();\n\ |
||
5821 | ctx.closePath();\n\ |
||
5822 | };\ |
||
5823 | };\ |
||
5824 | ctx.restore();\n\ |
||
5825 | };\n",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id); |
||
5826 | break; |
||
7729 | schaersvoo | 5827 | case DRAW_YLOGSCALE: |
5828 | fprintf(js_include_file,"\n<!-- draw ylogscale -->\n\ |
||
7779 | schaersvoo | 5829 | 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){\n\ |
7729 | schaersvoo | 5830 | var obj;\n\ |
5831 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\n\ |
||
5832 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\n\ |
||
5833 | }\n\ |
||
5834 | else\n\ |
||
5835 | {\n\ |
||
5836 | obj = create_canvas%d(canvas_type,xsize,ysize);\n\ |
||
5837 | };\n\ |
||
5838 | var ctx = obj.getContext(\"2d\");\n\ |
||
5839 | ctx.clearRect(0,0,xsize,ysize);\ |
||
5840 | ctx.save();\n\ |
||
5841 | ctx.lineWidth = line_width;\n\ |
||
7735 | schaersvoo | 5842 | var y_min = Math.log(ymin)/Math.log(ylogbase);\ |
5843 | var y_max = Math.log(ymax)/Math.log(ylogbase);\ |
||
5844 | var x_min = 0;var x_max = xsize;var y_s;var y_e;var num;\ |
||
7739 | schaersvoo | 5845 | if(use_axis_numbering == 1){\ |
5846 | ctx.font = font_family;\n\ |
||
5847 | xmarge = ctx.measureText(ylogbase+\"^\"+y_max.toFixed(0)+' ').width;\n\ |
||
5848 | ymarge = 2*font_size;\n\ |
||
5849 | ctx.save();\n\ |
||
5850 | ctx.fillStyle=\"rgba(255,215,0,0.2)\";\n\ |
||
5851 | ctx.rect(0,0,xmarge,ysize);\n\ |
||
5852 | ctx.rect(0,ysize-ymarge,xsize,ysize);\n\ |
||
5853 | ctx.fill();\n\ |
||
5854 | ctx.restore();\n\ |
||
5855 | }else{xmarge = 0;ymarge = 0;};\n\ |
||
5856 | if( typeof xaxislabel !== 'undefined' ){\ |
||
5857 | ctx.save();\n\ |
||
5858 | ctx.font = \"italic \"+font_size+\"px Ariel\";\n\ |
||
5859 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\n\ |
||
5860 | corr = ctx.measureText(xaxislabel).width;\n\ |
||
5861 | ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\n\ |
||
5862 | ctx.restore();\n\ |
||
5863 | };\n\ |
||
5864 | if( typeof yaxislabel !== 'undefined' ){\ |
||
5865 | ctx.save();\n\ |
||
5866 | ctx.font = \"italic \"+font_size+\"px Ariel\";\n\ |
||
5867 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\n\ |
||
5868 | corr = ctx.measureText(yaxislabel).width;\n\ |
||
5869 | ctx.translate(xmarge+font_size,corr+font_size);\n\ |
||
5870 | ctx.rotate(-0.5*Math.PI);\n\ |
||
5871 | ctx.fillText(yaxislabel,0,0);\n\ |
||
5872 | ctx.restore();\n\ |
||
5873 | };\n\ |
||
5874 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\n\ |
||
5875 | ctx.lineWidth = line_width;\n\n\ |
||
7729 | schaersvoo | 5876 | for(var p = y_min; p <= y_max ; p++){\n\ |
7735 | schaersvoo | 5877 | num = Math.pow(ylogbase,p);\n\ |
5878 | for(var i = 1 ; i < ylogbase ; i++){\n\ |
||
7729 | schaersvoo | 5879 | y_e = y2px(i*num);\n\ |
5880 | if( i == 1 ){\ |
||
5881 | ctx.lineWidth = line_width;\n\ |
||
5882 | ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\ |
||
7739 | schaersvoo | 5883 | if( use_axis_numbering == 1 && p > y_min){\ |
7735 | schaersvoo | 5884 | ctx.fillText(ylogbase+'^'+p.toFixed(0),0,y_e);\ |
7729 | schaersvoo | 5885 | };\ |
5886 | }else{\ |
||
5887 | ctx.lineWidth = 0.2*line_width;\n\ |
||
5888 | ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\ |
||
5889 | };\ |
||
5890 | ctx.beginPath();\n\ |
||
7739 | schaersvoo | 5891 | ctx.moveTo(xmarge,y_e);\n\ |
7735 | schaersvoo | 5892 | ctx.lineTo(xsize,y_e);\n\ |
7729 | schaersvoo | 5893 | ctx.stroke();\n\ |
5894 | ctx.closePath();\n\ |
||
5895 | };\n\ |
||
5896 | };\n\ |
||
5897 | var stepx = Math.abs(x2px(xmajor) - x2px(0));\ |
||
5898 | var minor_step = stepx / xminor;\ |
||
5899 | var prec = Math.log(precision)/Math.log(10);\ |
||
5900 | var xtxt;var corr;var flip = 0;\ |
||
7749 | schaersvoo | 5901 | for(var x = stepx ; x < xsize ; x = x + stepx){\ |
7729 | schaersvoo | 5902 | ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\ |
5903 | ctx.lineWidth = line_width;\n\ |
||
5904 | ctx.beginPath();\n\ |
||
7739 | schaersvoo | 5905 | ctx.moveTo(x,ysize-ymarge);\n\ |
7729 | schaersvoo | 5906 | ctx.lineTo(x,0);\n\ |
5907 | ctx.stroke();\n\ |
||
5908 | ctx.closePath();\n\ |
||
5909 | if( use_axis_numbering == 1){\ |
||
5910 | xtxt = (px2x(x)).toFixed(prec);\ |
||
5911 | corr = 0.5*(ctx.measureText(xtxt).width);\ |
||
5912 | if(flip == 0 ){flip = 1;ctx.fillText( xtxt,x - corr ,ysize - 0.2*font_size );}else{\ |
||
5913 | flip = 0;ctx.fillText( xtxt,x - corr ,ysize - 1.2*font_size );};\ |
||
5914 | };\ |
||
5915 | for(var dx = 1 ; dx < xminor ; dx++){\ |
||
5916 | ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\ |
||
5917 | ctx.lineWidth = 0.2*line_width;\n\ |
||
5918 | ctx.beginPath();\n\ |
||
7739 | schaersvoo | 5919 | ctx.moveTo(x+dx*minor_step,ysize - ymarge);\ |
7729 | schaersvoo | 5920 | ctx.lineTo(x+dx*minor_step,0);\n\ |
5921 | ctx.stroke();\n\ |
||
5922 | ctx.closePath();\n\ |
||
7735 | schaersvoo | 5923 | };\ |
5924 | };\ |
||
7729 | schaersvoo | 5925 | ctx.restore();\n\ |
5926 | };\n",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id); |
||
5927 | |||
5928 | break; |
||
7735 | schaersvoo | 5929 | |
5930 | |||
7614 | schaersvoo | 5931 | default:break; |
5932 | } |
||
5933 | } |
||
5934 | } |
||
5935 | return; |
||
5936 | } |
||
5937 | |||
5938 | void check_string_length(int L){ |
||
5939 | if(L<1 || L > MAX_BUFFER-1){ |
||
5940 | canvas_error("problem with your arguments to command..."); |
||
5941 | } |
||
5942 | return; |
||
5943 | } |
||
5944 | |||
5945 | |||
5946 | int get_token(FILE *infile){ |
||
5947 | int c,i=0; |
||
5948 | char temp[MAX_INT], *input_type; |
||
5949 | char *line="line", |
||
5950 | *audio="audio", |
||
5951 | *blink="blink", |
||
5952 | *arrowhead="arrowhead", |
||
5953 | *crosshairsize="crosshairsize", |
||
5954 | *crosshair="crosshair", |
||
5955 | *crosshairs="crosshairs", |
||
5956 | *audioobject="audioobject", |
||
5957 | *style="style", |
||
5958 | *mouse="mouse", |
||
5959 | *userdraw="userdraw", |
||
5960 | *highlight="highlight", |
||
5961 | *http="http", |
||
5962 | *rays="rays", |
||
5963 | *dashtype="dashtype", |
||
5964 | *dashed="dashed", |
||
5965 | *filled="filled", |
||
5966 | *lattice="lattice", |
||
5967 | *parallel="parallel", |
||
5968 | *segment="segment", |
||
5969 | *dsegment="dsegment", |
||
5970 | *seg="seg", |
||
5971 | *bgimage="bgimage", |
||
5972 | *bgcolor="bgcolor", |
||
5973 | *strokecolor="strokecolor", |
||
5974 | *backgroundimage="backgroundimage", |
||
5975 | *text="text", |
||
5976 | *textup="textup", |
||
5977 | *mouseprecision="mouseprecision", |
||
5978 | *precision="precision", |
||
5979 | *plotsteps="plotsteps", |
||
5980 | *plotstep="plotstep", |
||
5981 | *tsteps="tsteps", |
||
5982 | *curve="curve", |
||
5983 | *dcurve="dcurve", |
||
5984 | *plot="plot", |
||
5985 | *dplot="dplot", |
||
7788 | schaersvoo | 5986 | *levelcurve="levelcurve", |
7614 | schaersvoo | 5987 | *fontsize="fontsize", |
5988 | *fontcolor="fontcolor", |
||
5989 | *axis="axis", |
||
5990 | *axisnumbering="axisnumbering", |
||
5991 | *axisnumbers="axisnumbers", |
||
5992 | *arrow="arrow", |
||
5993 | *darrow="darrow", |
||
5994 | *arrow2="arrow2", |
||
5995 | *darrow2="darrow2", |
||
5996 | *zoom="zoom", |
||
5997 | *grid="grid", |
||
5998 | *hline="hline", |
||
7786 | schaersvoo | 5999 | *dhline="dhline", |
7614 | schaersvoo | 6000 | *drag="drag", |
6001 | *horizontalline="horizontalline", |
||
6002 | *vline="vline", |
||
7786 | schaersvoo | 6003 | *dvline="dvline", |
7614 | schaersvoo | 6004 | *verticalline="verticalline", |
6005 | *triangle="triangle", |
||
6006 | *ftriangle="ftriangle", |
||
6007 | *mathml="mathml", |
||
6008 | *html="html", |
||
6009 | *input="input", |
||
6010 | *button="button", |
||
6011 | *inputstyle="inputstyle", |
||
6012 | *textarea="textarea", |
||
6013 | *trange="trange", |
||
6014 | *ranget="ranget", |
||
6015 | *xrange="xrange", |
||
6016 | *yrange="yrange", |
||
6017 | *rangex="rangex", |
||
6018 | *rangey="rangey", |
||
6019 | *polyline="polyline", |
||
6020 | *lines="lines", |
||
6021 | *poly="poly", |
||
6022 | *polygon="polygon", |
||
6023 | *fpolygon="fpolygon", |
||
6024 | *fpoly="fpoly", |
||
6025 | *filledpoly="filledpoly", |
||
6026 | *filledpolygon="filledpolygon", |
||
6027 | *rect="rect", |
||
6028 | *frect="frect", |
||
6029 | *rectangle="rectangle", |
||
6030 | *frectangle="frectangle", |
||
6031 | *square="square", |
||
6032 | *fsquare="fsquare", |
||
6033 | *dline="dline", |
||
6034 | *arc="arc", |
||
6035 | *filledarc="filledarc", |
||
6036 | *size="size", |
||
6037 | *string="string", |
||
6038 | *stringup="stringup", |
||
6039 | *copy="copy", |
||
6040 | *copyresized="copyresized", |
||
6041 | *opacity="opacity", |
||
6042 | *transparent="transparent", |
||
6043 | *fill="fill", |
||
6044 | *slider="slider", |
||
6045 | *point="point", |
||
6046 | *points="points", |
||
6047 | *linewidth="linewidth", |
||
6048 | *circle="circle", |
||
6049 | *fcircle="fcircle", |
||
6050 | *disk="disk", |
||
6051 | *comment="#", |
||
6052 | *end="end", |
||
6053 | *ellipse="ellipse", |
||
6054 | *fellipse="fellipse", |
||
6055 | *rotate="rotate", |
||
7785 | schaersvoo | 6056 | *affine="affine", |
6057 | *killaffine="killaffine", |
||
7614 | schaersvoo | 6058 | *fontfamily="fontfamily", |
6059 | *fillcolor="fillcolor", |
||
6060 | *clicktile="clicktile", |
||
6061 | *clicktile_colors="clicktile_colors", |
||
6062 | *translation="translation", |
||
6063 | *translate="translate", |
||
6064 | *killtranslation="killtranslation", |
||
6065 | *killtranslate="killtranslate", |
||
6066 | *onclick="onclick", |
||
6067 | *roundrect="roundrect", |
||
6068 | *froundrect="froundrect", |
||
6069 | *roundrectangle="roundrectangle", |
||
6070 | *patternfill="patternfill", |
||
6071 | *hatchfill="hatchfill", |
||
6072 | *diafill="diafill", |
||
7647 | schaersvoo | 6073 | *diamondfill="diamondfill", |
7614 | schaersvoo | 6074 | *dotfill="dotfill", |
6075 | *gridfill="gridfill", |
||
6076 | *imagefill="imagefill", |
||
7735 | schaersvoo | 6077 | *xlogbase="xlogbase", |
6078 | *ylogbase="ylogbase", |
||
7614 | schaersvoo | 6079 | *xlogscale="xlogscale", |
6080 | *ylogscale="ylogscale", |
||
6081 | *xylogscale="xylogscale", |
||
6082 | *intooltip="intooltip", |
||
6083 | *replyformat="replyformat", |
||
6084 | *floodfill="floodfill", |
||
6085 | *filltoborder="filltoborder", |
||
6086 | *clickfill="clickfill", |
||
6087 | *setpixel="setpixel", |
||
6088 | *pixels="pixels", |
||
6089 | *pixelsize="pixelsize", |
||
6090 | *clickfillmarge="clickfillmarge", |
||
6091 | *xaxis="xaxis", |
||
6092 | *yaxis="yaxis", |
||
6093 | *xaxistext="xaxistext", |
||
6094 | *yaxistext="yaxistext", |
||
6095 | *piechart="piechart", |
||
6096 | *legend="legend", |
||
6097 | *legendcolors="legendcolors", |
||
6098 | *xlabel="xlabel", |
||
6099 | *ylabel="ylabel", |
||
6100 | *barchart="barchart", |
||
6101 | *linegraph="linegraph", |
||
6102 | *clock="clock", |
||
6103 | *animate="animate", |
||
6104 | *video="video", |
||
6105 | *status="status", |
||
7652 | schaersvoo | 6106 | *snaptogrid="snaptogrid", |
7784 | schaersvoo | 6107 | *xsnaptogrid="xsnaptogrid", |
6108 | *ysnaptogrid="ysnaptogrid", |
||
7654 | schaersvoo | 6109 | *userinput_xy="userinput_xy", |
7663 | schaersvoo | 6110 | *usertextarea_xy="usertextarea_xy", |
7823 | schaersvoo | 6111 | *jsmath="jsmath", |
6112 | *trace_jsmath="trace_jsmath", |
||
7838 | schaersvoo | 6113 | *setlimits="setlimits", |
7654 | schaersvoo | 6114 | *sgraph="sgraph"; |
7614 | schaersvoo | 6115 | |
6116 | while(((c = getc(infile)) != EOF)&&(c!='\n')&&(c!=',')&&(c!='=')&&(c!='\r')){ |
||
6117 | if( i == 0 && (c == ' ' || c == '\t') ){ |
||
6118 | continue; /* white spaces or tabs allowed before first command identifier */ |
||
6119 | } |
||
6120 | else |
||
6121 | { |
||
6122 | if( c == ' ' || c == '\t' ){ |
||
6123 | break; |
||
6124 | } |
||
6125 | else |
||
6126 | { |
||
6127 | temp[i] = c; |
||
6128 | if(i > MAX_INT - 2){canvas_error("command string too long !");} |
||
6129 | i++; |
||
6130 | } |
||
6131 | } |
||
6132 | if(temp[0] == '#') break; |
||
6133 | } |
||
6134 | if (c == EOF) finished = 1; |
||
6135 | |||
6136 | if (c == '\n' || c == '\r') { |
||
6137 | line_number++; |
||
6138 | if (i == 0) { return EMPTY; } |
||
6139 | } else if (c == EOF) { |
||
6140 | return 0; |
||
6141 | } |
||
6142 | |||
6143 | temp[i]='\0'; |
||
6144 | input_type=(char*)my_newmem(strlen(temp)); |
||
6145 | snprintf(input_type,sizeof(temp),"%s",temp); |
||
6146 | |||
6147 | if( strcmp(input_type, size) == 0 ){ |
||
6148 | free(input_type); |
||
6149 | return SIZE; |
||
6150 | } |
||
6151 | if( strcmp(input_type, xrange) == 0 ){ |
||
6152 | free(input_type); |
||
6153 | return XRANGE; |
||
6154 | } |
||
6155 | if( strcmp(input_type, rangex) == 0 ){ |
||
6156 | free(input_type); |
||
6157 | return XRANGE; |
||
6158 | } |
||
6159 | if( strcmp(input_type, trange) == 0 ){ |
||
6160 | free(input_type); |
||
6161 | return TRANGE; |
||
6162 | } |
||
6163 | if( strcmp(input_type, ranget) == 0 ){ |
||
6164 | free(input_type); |
||
6165 | return TRANGE; |
||
6166 | } |
||
6167 | if( strcmp(input_type, yrange) == 0 ){ |
||
6168 | free(input_type); |
||
6169 | return YRANGE; |
||
6170 | } |
||
6171 | if( strcmp(input_type, rangey) == 0 ){ |
||
6172 | free(input_type); |
||
6173 | return YRANGE; |
||
6174 | } |
||
6175 | if( strcmp(input_type, linewidth) == 0 ){ |
||
6176 | free(input_type); |
||
6177 | return LINEWIDTH; |
||
6178 | } |
||
6179 | if( strcmp(input_type, dashed) == 0 ){ |
||
6180 | free(input_type); |
||
6181 | return DASHED; |
||
6182 | } |
||
6183 | if( strcmp(input_type, dashtype) == 0 ){ |
||
6184 | free(input_type); |
||
6185 | return DASHTYPE; |
||
6186 | } |
||
6187 | if( strcmp(input_type, axisnumbering) == 0 ){ |
||
6188 | free(input_type); |
||
6189 | return AXIS_NUMBERING; |
||
6190 | } |
||
6191 | if( strcmp(input_type, axisnumbers) == 0 ){ |
||
6192 | free(input_type); |
||
6193 | return AXIS_NUMBERING; |
||
6194 | } |
||
6195 | if( strcmp(input_type, axis) == 0 ){ |
||
6196 | free(input_type); |
||
6197 | return AXIS; |
||
6198 | } |
||
6199 | if( strcmp(input_type, grid) == 0 ){ |
||
6200 | free(input_type); |
||
6201 | return GRID; |
||
6202 | } |
||
6203 | if( strcmp(input_type, parallel) == 0 ){ |
||
6204 | free(input_type); |
||
6205 | return PARALLEL; |
||
6206 | } |
||
6207 | if( strcmp(input_type, hline) == 0 || strcmp(input_type, horizontalline) == 0 ){ |
||
6208 | free(input_type); |
||
6209 | return HLINE; |
||
6210 | } |
||
6211 | if( strcmp(input_type, vline) == 0 || strcmp(input_type, verticalline) == 0 ){ |
||
6212 | free(input_type); |
||
6213 | return VLINE; |
||
6214 | } |
||
6215 | if( strcmp(input_type, line) == 0 ){ |
||
6216 | free(input_type); |
||
6217 | return LINE; |
||
6218 | } |
||
6219 | if( strcmp(input_type, seg) == 0 || strcmp(input_type, segment) == 0 ){ |
||
6220 | free(input_type); |
||
6221 | return SEGMENT; |
||
6222 | } |
||
6223 | if( strcmp(input_type, dsegment) == 0 ){ |
||
6224 | free(input_type); |
||
6225 | use_dashed = TRUE; |
||
6226 | return SEGMENT; |
||
6227 | } |
||
6228 | if( strcmp(input_type, crosshairsize) == 0 ){ |
||
6229 | free(input_type); |
||
6230 | return CROSSHAIRSIZE; |
||
6231 | } |
||
6232 | if( strcmp(input_type, arrowhead) == 0 ){ |
||
6233 | free(input_type); |
||
6234 | return ARROWHEAD; |
||
6235 | } |
||
6236 | if( strcmp(input_type, crosshairs) == 0 ){ |
||
6237 | free(input_type); |
||
6238 | return CROSSHAIRS; |
||
6239 | } |
||
6240 | if( strcmp(input_type, crosshair) == 0 ){ |
||
6241 | free(input_type); |
||
6242 | return CROSSHAIR; |
||
6243 | } |
||
6244 | if( strcmp(input_type, onclick) == 0 ){ |
||
6245 | free(input_type); |
||
6246 | return ONCLICK; |
||
6247 | } |
||
6248 | if( strcmp(input_type, drag) == 0 ){ |
||
6249 | free(input_type); |
||
6250 | return DRAG; |
||
6251 | } |
||
6252 | if( strcmp(input_type, userdraw) == 0 ){ |
||
6253 | free(input_type); |
||
6254 | return USERDRAW; |
||
6255 | } |
||
6256 | if( strcmp(input_type, highlight) == 0 || strcmp(input_type, style) == 0 ){ |
||
6257 | free(input_type); |
||
6258 | return STYLE; |
||
6259 | } |
||
6260 | if( strcmp(input_type, fillcolor) == 0 ){ |
||
6261 | free(input_type); |
||
6262 | return FILLCOLOR; |
||
6263 | } |
||
6264 | if( strcmp(input_type, strokecolor) == 0 ){ |
||
6265 | free(input_type); |
||
6266 | return STROKECOLOR; |
||
6267 | } |
||
6268 | if( strcmp(input_type, filled) == 0 ){ |
||
6269 | free(input_type); |
||
6270 | return FILLED; |
||
6271 | } |
||
6272 | if( strcmp(input_type, http) == 0 ){ |
||
6273 | free(input_type); |
||
6274 | return HTTP; |
||
6275 | } |
||
6276 | if( strcmp(input_type, rays) == 0 ){ |
||
6277 | free(input_type); |
||
6278 | return RAYS; |
||
6279 | } |
||
6280 | if( strcmp(input_type, lattice) == 0 ){ |
||
6281 | free(input_type); |
||
6282 | return LATTICE; |
||
6283 | } |
||
6284 | if( strcmp(input_type, bgimage) == 0 ){ |
||
6285 | free(input_type); |
||
6286 | return BGIMAGE; |
||
6287 | } |
||
6288 | if( strcmp(input_type, bgcolor) == 0 ){ |
||
6289 | free(input_type); |
||
6290 | return BGCOLOR; |
||
6291 | } |
||
6292 | if( strcmp(input_type, backgroundimage) == 0 ){ |
||
6293 | free(input_type); |
||
6294 | return BGIMAGE; |
||
6295 | } |
||
6296 | if( strcmp(input_type, text) == 0 ){ |
||
6297 | free(input_type); |
||
6298 | return FLY_TEXT; |
||
6299 | } |
||
6300 | if( strcmp(input_type, textup) == 0 ){ |
||
6301 | free(input_type); |
||
6302 | return FLY_TEXTUP; |
||
6303 | } |
||
6304 | if( strcmp(input_type, mouse) == 0 ){ |
||
6305 | free(input_type); |
||
6306 | return MOUSE; |
||
6307 | } |
||
6308 | if( strcmp(input_type, mouseprecision) == 0 ){ |
||
6309 | free(input_type); |
||
6310 | return MOUSE_PRECISION; |
||
6311 | } |
||
6312 | if( strcmp(input_type, precision) == 0 ){ |
||
6313 | free(input_type); |
||
6314 | return MOUSE_PRECISION; |
||
6315 | } |
||
6316 | if( strcmp(input_type, curve) == 0 ){ |
||
6317 | free(input_type); |
||
6318 | return CURVE; |
||
6319 | } |
||
6320 | if( strcmp(input_type, dcurve) == 0 ){ |
||
7788 | schaersvoo | 6321 | use_dashed = TRUE; |
7614 | schaersvoo | 6322 | free(input_type); |
6323 | return CURVE; |
||
6324 | } |
||
6325 | if( strcmp(input_type, plot) == 0 ){ |
||
6326 | free(input_type); |
||
6327 | return CURVE; |
||
6328 | } |
||
6329 | if( strcmp(input_type, dplot) == 0 ){ |
||
7788 | schaersvoo | 6330 | use_dashed = TRUE; |
7614 | schaersvoo | 6331 | free(input_type); |
6332 | return CURVE; |
||
6333 | } |
||
7788 | schaersvoo | 6334 | if( strcmp(input_type, levelcurve) == 0 ){ |
6335 | free(input_type); |
||
6336 | return LEVELCURVE; |
||
6337 | } |
||
7614 | schaersvoo | 6338 | if( strcmp(input_type, plotsteps) == 0 ){ |
6339 | free(input_type); |
||
6340 | return PLOTSTEPS; |
||
6341 | } |
||
6342 | if( strcmp(input_type, plotstep) == 0 ){ |
||
6343 | free(input_type); |
||
6344 | return PLOTSTEPS; |
||
6345 | } |
||
6346 | if( strcmp(input_type, tsteps) == 0 ){ |
||
6347 | free(input_type); |
||
6348 | return PLOTSTEPS; |
||
6349 | } |
||
6350 | if( strcmp(input_type, fontsize) == 0 ){ |
||
6351 | free(input_type); |
||
6352 | return FONTSIZE; |
||
6353 | } |
||
6354 | if( strcmp(input_type, fontcolor) == 0 ){ |
||
6355 | free(input_type); |
||
6356 | return FONTCOLOR; |
||
6357 | } |
||
6358 | if( strcmp(input_type, arrow) == 0 ){ |
||
6359 | free(input_type); |
||
6360 | return ARROW; |
||
6361 | } |
||
6362 | if( strcmp(input_type, arrow2) == 0 ){ |
||
6363 | free(input_type); |
||
6364 | return ARROW2; |
||
6365 | } |
||
6366 | if( strcmp(input_type, darrow) == 0 ){ |
||
6367 | free(input_type); |
||
6368 | return ARROW; |
||
6369 | } |
||
6370 | if( strcmp(input_type, darrow2) == 0 ){ |
||
6371 | free(input_type); |
||
6372 | use_dashed = TRUE; |
||
6373 | return ARROW2; |
||
6374 | } |
||
6375 | if( strcmp(input_type, zoom) == 0 ){ |
||
6376 | free(input_type); |
||
6377 | return ZOOM; |
||
6378 | } |
||
6379 | if( strcmp(input_type, triangle) == 0 ){ |
||
6380 | free(input_type); |
||
6381 | return TRIANGLE; |
||
6382 | } |
||
6383 | if( strcmp(input_type, ftriangle) == 0 ){ |
||
6384 | free(input_type); |
||
6385 | use_filled = TRUE; |
||
6386 | return TRIANGLE; |
||
6387 | } |
||
6388 | if( strcmp(input_type, input) == 0 ){ |
||
6389 | free(input_type); |
||
6390 | return INPUT; |
||
6391 | } |
||
6392 | if( strcmp(input_type, inputstyle) == 0 ){ |
||
6393 | free(input_type); |
||
6394 | return INPUTSTYLE; |
||
6395 | } |
||
6396 | if( strcmp(input_type, textarea) == 0 ){ |
||
6397 | free(input_type); |
||
6398 | return TEXTAREA; |
||
6399 | } |
||
6400 | if( strcmp(input_type, mathml) == 0 ){ |
||
6401 | free(input_type); |
||
6402 | return MATHML; |
||
6403 | } |
||
6404 | if( strcmp(input_type, html) == 0 ){ |
||
6405 | free(input_type); |
||
6406 | return MATHML; |
||
6407 | } |
||
6408 | if( strcmp(input_type, fontfamily) == 0 ){ |
||
6409 | free(input_type); |
||
6410 | return FONTFAMILY; |
||
6411 | } |
||
6412 | if( strcmp(input_type, lines) == 0 || strcmp(input_type, polyline) == 0 ){ |
||
6413 | free(input_type); |
||
6414 | return POLYLINE; |
||
6415 | } |
||
6416 | if( strcmp(input_type, rect) == 0 || strcmp(input_type, rectangle) == 0 ){ |
||
6417 | free(input_type); |
||
6418 | return RECT; |
||
6419 | } |
||
6420 | if( strcmp(input_type, roundrect) == 0 || strcmp(input_type, roundrectangle) == 0 ){ |
||
6421 | free(input_type); |
||
6422 | return ROUNDRECT; |
||
6423 | } |
||
6424 | if( strcmp(input_type, froundrect) == 0 ){ |
||
6425 | free(input_type); |
||
6426 | use_filled = TRUE; |
||
6427 | return ROUNDRECT; |
||
6428 | } |
||
6429 | if( strcmp(input_type, square) == 0 ){ |
||
6430 | free(input_type); |
||
6431 | return SQUARE; |
||
6432 | } |
||
6433 | if( strcmp(input_type, fsquare) == 0 ){ |
||
6434 | free(input_type); |
||
6435 | use_filled = TRUE; |
||
6436 | return SQUARE; |
||
6437 | } |
||
6438 | if( strcmp(input_type, dline) == 0 ){ |
||
6439 | use_dashed = TRUE; |
||
6440 | free(input_type); |
||
6441 | return LINE; |
||
6442 | } |
||
7786 | schaersvoo | 6443 | if( strcmp(input_type, dvline) == 0 ){ |
6444 | use_dashed = TRUE; |
||
6445 | free(input_type); |
||
6446 | return VLINE; |
||
6447 | } |
||
6448 | if( strcmp(input_type, dhline) == 0 ){ |
||
6449 | use_dashed = TRUE; |
||
6450 | free(input_type); |
||
6451 | return HLINE; |
||
6452 | } |
||
7614 | schaersvoo | 6453 | if( strcmp(input_type, frect) == 0 || strcmp(input_type, frectangle) == 0 ){ |
6454 | use_filled = TRUE; |
||
6455 | free(input_type); |
||
6456 | return RECT; |
||
6457 | } |
||
6458 | if( strcmp(input_type, fcircle) == 0 || strcmp(input_type, disk) == 0 ){ |
||
6459 | use_filled = TRUE; |
||
6460 | free(input_type); |
||
6461 | return CIRCLE; |
||
6462 | } |
||
6463 | if( strcmp(input_type, circle) == 0 ){ |
||
6464 | free(input_type); |
||
6465 | return CIRCLE; |
||
6466 | } |
||
6467 | if( strcmp(input_type, point) == 0 ){ |
||
6468 | free(input_type); |
||
6469 | return POINT; |
||
6470 | } |
||
6471 | if( strcmp(input_type, points) == 0 ){ |
||
6472 | free(input_type); |
||
6473 | return POINTS; |
||
6474 | } |
||
6475 | if( strcmp(input_type, filledarc) == 0 ){ |
||
6476 | use_filled = TRUE; |
||
6477 | free(input_type); |
||
6478 | return ARC; |
||
6479 | } |
||
6480 | if( strcmp(input_type, arc) == 0 ){ |
||
6481 | free(input_type); |
||
6482 | return ARC; |
||
6483 | } |
||
6484 | if( strcmp(input_type, poly) == 0 || strcmp(input_type, polygon) == 0 ){ |
||
6485 | free(input_type); |
||
6486 | return POLY; |
||
6487 | } |
||
6488 | if( strcmp(input_type, fpoly) == 0 || strcmp(input_type, filledpoly) == 0 || strcmp(input_type,filledpolygon) == 0 || strcmp(input_type,fpolygon) == 0 ){ |
||
6489 | use_filled = TRUE; |
||
6490 | free(input_type); |
||
6491 | return POLY; |
||
6492 | } |
||
6493 | if( strcmp(input_type, ellipse) == 0){ |
||
6494 | free(input_type); |
||
6495 | return ELLIPSE; |
||
6496 | } |
||
6497 | if( strcmp(input_type, fill) == 0 ){ |
||
6498 | free(input_type); |
||
6499 | return FLOODFILL; |
||
6500 | } |
||
6501 | if( strcmp(input_type, string) == 0 ){ |
||
6502 | free(input_type); |
||
6503 | return STRING; |
||
6504 | } |
||
6505 | if( strcmp(input_type, stringup) == 0 ){ |
||
6506 | free(input_type); |
||
6507 | return STRINGUP; |
||
6508 | } |
||
6509 | if( strcmp(input_type, opacity) == 0 ){ |
||
6510 | free(input_type); |
||
6511 | return OPACITY; |
||
6512 | } |
||
6513 | if( strcmp(input_type, comment) == 0){ |
||
6514 | free(input_type); |
||
6515 | return COMMENT; |
||
6516 | } |
||
6517 | if( strcmp(input_type, end) == 0){ |
||
6518 | free(input_type); |
||
6519 | return END; |
||
6520 | } |
||
6521 | if( strcmp(input_type, fellipse) == 0){ |
||
6522 | free(input_type); |
||
6523 | use_filled = TRUE; |
||
6524 | return ELLIPSE; |
||
7842 | bpr | 6525 | } |
7614 | schaersvoo | 6526 | if( strcmp(input_type, blink) == 0 ){ |
6527 | free(input_type); |
||
6528 | return BLINK; |
||
6529 | } |
||
6530 | if( strcmp(input_type, button) == 0){ |
||
6531 | free(input_type); |
||
6532 | return BUTTON; |
||
6533 | } |
||
6534 | if( strcmp(input_type, translation) == 0 || strcmp(input_type, translate) == 0 ){ |
||
6535 | free(input_type); |
||
6536 | return TRANSLATION; |
||
6537 | } |
||
6538 | if( strcmp(input_type, killtranslation) == 0 || strcmp(input_type, killtranslate) == 0){ |
||
6539 | free(input_type); |
||
6540 | return KILLTRANSLATION; |
||
6541 | } |
||
6542 | if( strcmp(input_type, rotate) == 0){ |
||
6543 | free(input_type); |
||
6544 | return ROTATE; |
||
6545 | } |
||
7785 | schaersvoo | 6546 | if( strcmp(input_type, affine) == 0){ |
6547 | free(input_type); |
||
6548 | return AFFINE; |
||
6549 | } |
||
6550 | if( strcmp(input_type, killaffine) == 0){ |
||
6551 | free(input_type); |
||
6552 | return KILLAFFINE; |
||
6553 | } |
||
7614 | schaersvoo | 6554 | if( strcmp(input_type, audio) == 0 ){ |
6555 | free(input_type); |
||
6556 | return AUDIO; |
||
6557 | } |
||
6558 | if( strcmp(input_type, audioobject) == 0 ){ |
||
6559 | free(input_type); |
||
6560 | return AUDIOOBJECT; |
||
6561 | } |
||
6562 | if( strcmp(input_type, slider) == 0 ){ |
||
6563 | free(input_type); |
||
6564 | return SLIDER; |
||
6565 | } |
||
6566 | if( strcmp(input_type, copy) == 0 ){ |
||
6567 | free(input_type); |
||
6568 | return COPY; |
||
6569 | } |
||
6570 | if( strcmp(input_type, copyresized) == 0 ){ |
||
6571 | free(input_type); |
||
6572 | return COPYRESIZED; |
||
6573 | } |
||
6574 | if( strcmp(input_type, patternfill) == 0 ){ |
||
6575 | free(input_type); |
||
6576 | return PATTERNFILL; |
||
6577 | } |
||
6578 | if( strcmp(input_type, hatchfill) == 0 ){ |
||
6579 | free(input_type); |
||
6580 | return HATCHFILL; |
||
6581 | } |
||
7647 | schaersvoo | 6582 | if( strcmp(input_type, diafill) == 0 || strcmp(input_type, diamondfill) == 0 ){ |
7614 | schaersvoo | 6583 | free(input_type); |
7647 | schaersvoo | 6584 | return DIAMONDFILL; |
7614 | schaersvoo | 6585 | } |
6586 | if( strcmp(input_type, dotfill) == 0 ){ |
||
6587 | free(input_type); |
||
6588 | return DOTFILL; |
||
6589 | } |
||
6590 | if( strcmp(input_type, gridfill) == 0 ){ |
||
6591 | free(input_type); |
||
6592 | return GRIDFILL; |
||
6593 | } |
||
6594 | if( strcmp(input_type, imagefill) == 0 ){ |
||
6595 | free(input_type); |
||
6596 | return IMAGEFILL; |
||
6597 | } |
||
6598 | if( strcmp(input_type, clicktile_colors) == 0 ){ |
||
6599 | free(input_type); |
||
6600 | return CLICKTILE_COLORS; |
||
6601 | } |
||
6602 | if( strcmp(input_type, clicktile) == 0 ){ |
||
6603 | free(input_type); |
||
6604 | return CLICKTILE; |
||
6605 | } |
||
6606 | if( strcmp(input_type, xlogscale) == 0 ){ |
||
6607 | free(input_type); |
||
6608 | return XLOGSCALE; |
||
6609 | } |
||
6610 | if( strcmp(input_type, ylogscale) == 0 ){ |
||
6611 | free(input_type); |
||
6612 | return YLOGSCALE; |
||
6613 | } |
||
6614 | if( strcmp(input_type, xylogscale) == 0 ){ |
||
6615 | free(input_type); |
||
6616 | return XYLOGSCALE; |
||
6617 | } |
||
6618 | if( strcmp(input_type, ylogscale) == 0 ){ |
||
6619 | free(input_type); |
||
6620 | return YLOGSCALE; |
||
6621 | } |
||
7735 | schaersvoo | 6622 | if( strcmp(input_type, xlogbase) == 0 ){ |
7614 | schaersvoo | 6623 | free(input_type); |
7735 | schaersvoo | 6624 | return XLOGBASE; |
7614 | schaersvoo | 6625 | } |
7735 | schaersvoo | 6626 | if( strcmp(input_type, ylogbase) == 0 ){ |
6627 | free(input_type); |
||
6628 | return YLOGBASE; |
||
6629 | } |
||
7614 | schaersvoo | 6630 | if( strcmp(input_type, intooltip) == 0 ){ |
6631 | free(input_type); |
||
6632 | return INTOOLTIP; |
||
6633 | } |
||
6634 | if( strcmp(input_type,video) == 0 ){ |
||
6635 | free(input_type); |
||
6636 | return VIDEO; |
||
6637 | } |
||
6638 | if( strcmp(input_type,floodfill) == 0 || strcmp(input_type,fill) == 0 ){ |
||
6639 | free(input_type); |
||
6640 | return FLOODFILL; |
||
7842 | bpr | 6641 | } |
7614 | schaersvoo | 6642 | if( strcmp(input_type,filltoborder) == 0 ){ |
6643 | free(input_type); |
||
6644 | return FILLTOBORDER; |
||
7842 | bpr | 6645 | } |
7614 | schaersvoo | 6646 | if( strcmp(input_type,clickfill) == 0 ){ |
6647 | free(input_type); |
||
6648 | return CLICKFILL; |
||
7842 | bpr | 6649 | } |
7614 | schaersvoo | 6650 | if( strcmp(input_type, replyformat) == 0 ){ |
6651 | free(input_type); |
||
6652 | return REPLYFORMAT; |
||
6653 | } |
||
6654 | if( strcmp(input_type, pixelsize) == 0 ){ |
||
6655 | free(input_type); |
||
6656 | return PIXELSIZE; |
||
6657 | } |
||
6658 | if( strcmp(input_type, setpixel) == 0 ){ |
||
6659 | free(input_type); |
||
6660 | return SETPIXEL; |
||
6661 | } |
||
6662 | if( strcmp(input_type, pixels) == 0 ){ |
||
6663 | free(input_type); |
||
6664 | return PIXELS; |
||
6665 | } |
||
6666 | if( strcmp(input_type, clickfillmarge) == 0 ){ |
||
6667 | free(input_type); |
||
6668 | return CLICKFILLMARGE; |
||
6669 | } |
||
6670 | if( strcmp(input_type, xaxis) == 0 || strcmp(input_type, xaxistext) == 0 ){ |
||
6671 | free(input_type); |
||
6672 | return X_AXIS_STRINGS; |
||
6673 | } |
||
6674 | if( strcmp(input_type, yaxis) == 0 || strcmp(input_type, yaxistext) == 0 ){ |
||
6675 | free(input_type); |
||
6676 | return Y_AXIS_STRINGS; |
||
6677 | } |
||
6678 | if( strcmp(input_type, piechart) == 0 ){ |
||
6679 | free(input_type); |
||
6680 | return PIECHART; |
||
6681 | } |
||
6682 | if( strcmp(input_type, barchart) == 0 ){ |
||
6683 | free(input_type); |
||
6684 | return BARCHART; |
||
6685 | } |
||
6686 | if( strcmp(input_type, linegraph) == 0 ){ |
||
6687 | free(input_type); |
||
6688 | return LINEGRAPH; |
||
6689 | } |
||
6690 | if( strcmp(input_type, clock) == 0 ){ |
||
6691 | free(input_type); |
||
6692 | return CLOCK; |
||
6693 | } |
||
6694 | if( strcmp(input_type, legend) == 0 ){ |
||
6695 | free(input_type); |
||
6696 | return LEGEND; |
||
6697 | } |
||
6698 | if( strcmp(input_type, legendcolors) == 0 ){ |
||
6699 | free(input_type); |
||
6700 | return LEGENDCOLORS; |
||
6701 | } |
||
6702 | if( strcmp(input_type, xlabel) == 0 ){ |
||
6703 | free(input_type); |
||
6704 | return XLABEL; |
||
6705 | } |
||
6706 | if( strcmp(input_type, ylabel) == 0 ){ |
||
6707 | free(input_type); |
||
6708 | return YLABEL; |
||
6709 | } |
||
6710 | if( strcmp(input_type, animate) == 0 ){ |
||
6711 | free(input_type); |
||
6712 | return ANIMATE; |
||
6713 | } |
||
6714 | /* these are bitmap related flydraw commmands...must be removed. eventually */ |
||
6715 | if( strcmp(input_type, transparent) == 0 ){ |
||
6716 | free(input_type); |
||
6717 | return TRANSPARENT; |
||
6718 | } |
||
6719 | if( strcmp(input_type, status) == 0 ){ |
||
6720 | free(input_type); |
||
6721 | return STATUS; |
||
6722 | } |
||
6723 | if( strcmp(input_type, snaptogrid) == 0 ){ |
||
6724 | free(input_type); |
||
6725 | return SNAPTOGRID; |
||
6726 | } |
||
7784 | schaersvoo | 6727 | if( strcmp(input_type, xsnaptogrid) == 0 ){ |
6728 | free(input_type); |
||
6729 | return XSNAPTOGRID; |
||
6730 | } |
||
6731 | if( strcmp(input_type, ysnaptogrid) == 0 ){ |
||
6732 | free(input_type); |
||
6733 | return YSNAPTOGRID; |
||
6734 | } |
||
7652 | schaersvoo | 6735 | if( strcmp(input_type, userinput_xy) == 0 ){ |
7614 | schaersvoo | 6736 | free(input_type); |
7652 | schaersvoo | 6737 | return USERINPUT_XY; |
6738 | } |
||
7663 | schaersvoo | 6739 | if( strcmp(input_type, usertextarea_xy) == 0 ){ |
6740 | free(input_type); |
||
6741 | return USERTEXTAREA_XY; |
||
6742 | } |
||
7654 | schaersvoo | 6743 | if( strcmp(input_type, sgraph) == 0 ){ |
7652 | schaersvoo | 6744 | free(input_type); |
7654 | schaersvoo | 6745 | return SGRAPH; |
6746 | } |
||
7823 | schaersvoo | 6747 | if( strcmp(input_type, jsmath) == 0 ){ |
7654 | schaersvoo | 6748 | free(input_type); |
7823 | schaersvoo | 6749 | return JSMATH; |
6750 | } |
||
6751 | if( strcmp(input_type, trace_jsmath) == 0 ){ |
||
6752 | free(input_type); |
||
6753 | return TRACE_JSMATH; |
||
6754 | } |
||
7838 | schaersvoo | 6755 | if( strcmp(input_type, setlimits) == 0 ){ |
7823 | schaersvoo | 6756 | free(input_type); |
7838 | schaersvoo | 6757 | return SETLIMITS; |
6758 | } |
||
6759 | free(input_type); |
||
7614 | schaersvoo | 6760 | ungetc(c,infile); |
6761 | return 0; |
||
6762 | } |