Rev 7786 | Rev 7792 | 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 | */ |
||
12 | #include <stdio.h> |
||
13 | #include <stdlib.h> |
||
14 | #include <errno.h> |
||
15 | #include <string.h> |
||
16 | #include <unistd.h> |
||
17 | #include <time.h> /* use for random id's */ |
||
18 | #include <math.h> |
||
19 | /* |
||
20 | #include <ctype.h> |
||
21 | 11/2013 |
||
22 | removed: FreeBSD 9.0 / 9.1 C-lib bug...in chroot it will result in: Undefined symbol "_ThreadRuneLocale" implemented own versions of tolower() / toupper() |
||
23 | Clang is fine (FreeBSD 10.0) |
||
24 | */ |
||
25 | |||
26 | /* |
||
27 | in case svgdraw is in ~/src/Misc/svgdraw |
||
28 | #include "../svgdraw/include/matheval.h" |
||
29 | */ |
||
30 | #include "include/matheval.h" |
||
31 | #include <assert.h> |
||
32 | #include "canvasdraw.h" |
||
7634 | schaersvoo | 33 | #include<sys/stat.h> |
7614 | schaersvoo | 34 | |
35 | /* needed for gettimeofday */ |
||
36 | #include <sys/time.h> |
||
37 | #include "canvasmacro.c" |
||
38 | /****************************************************************************** |
||
39 | ** Internal Functions |
||
40 | ******************************************************************************/ |
||
41 | void add_to_buffer(char *tmp); /* add tmp_buffer to the buffer */ |
||
42 | void sync_input(FILE *infile);/* proceed with inputfile */ |
||
43 | void canvas_error(char *msg); |
||
44 | void add_javascript_functions(int js_functions[], int canvas_root_id); |
||
45 | void reset();/* reset some global variables like "use_filled" , "use_dashed" */ |
||
46 | int get_token(FILE *infile); /* read next char until EOL*/ |
||
47 | int x2px(double x); |
||
48 | int y2px(double y); |
||
49 | double px2x(int x); |
||
50 | double px2y(int y); |
||
51 | double get_real(FILE *infile,int last); /* read a values; calculation and symbols allowed */ |
||
52 | char *str_replace ( const char *word, const char *sub_word, const char *rep_word ); |
||
53 | char *get_color(FILE *infile,int last); /* read hex-color or colorname -> hex */ |
||
54 | char *get_string(FILE *infile,int last); /* get the string at theend of a command */ |
||
55 | char *get_string_argument(FILE *infile,int last); /* the same, but with "comma" as separator */ |
||
56 | char *convert_hex2rgb(char *hexcolor); |
||
57 | void add_read_canvas(int reply_format); |
||
58 | void make_js_include(int canvas_root_id); |
||
59 | void check_string_length(int length);/* checks if the length of string argument of command is correct */ |
||
60 | FILE *js_include_file; |
||
61 | FILE *get_file(int *line_number, char **filename); |
||
62 | FILE *infile; /* will be stdin */ |
||
63 | /****************************************************************************** |
||
64 | ** global |
||
65 | ******************************************************************************/ |
||
66 | int finished = FALSE;/* main variable for signalling the end of the fly-script ; if finished = 1 ; write to stdout or canvasz */ |
||
67 | int line_number = 1;/* used in canvas_error() ; keep track of line number in canvasdraw/fly - script */ |
||
68 | /* set some variables to avoid trouble (NaN) in case of syntax and other usage errors */ |
||
69 | int xsize = 320; |
||
70 | int ysize = 320; |
||
71 | double xmin = 0.0; |
||
72 | double xmax = 320.0; |
||
73 | double ymin = 0.0; |
||
74 | double ymax = 320.0; |
||
75 | double tmax = 2; |
||
76 | double tmin = -2; |
||
77 | /* flag to indicate parsing of line status */ |
||
78 | int done = FALSE; |
||
79 | int type; /* eg command number */ |
||
80 | int onclick = 0;/* 0 = noninteractive ; 1 = onclick ; 2 = draggable*/ |
||
7785 | schaersvoo | 81 | int use_affine = FALSE; |
7614 | schaersvoo | 82 | int use_rotate = FALSE; |
83 | int use_translate = FALSE; |
||
84 | int use_filled = FALSE; |
||
85 | int use_dashed = FALSE; /* dashing not natively supported in firefox , for now... */ |
||
86 | char buffer[MAX_BUFFER];/* contains js-functions with arguments ... all other basic code is directly printed into js-include file */ |
||
87 | |||
88 | /****************************************************************************** |
||
89 | ** Main Program |
||
90 | ******************************************************************************/ |
||
91 | int main(int argc, char *argv[]){ |
||
92 | /* need unique id for every call to canvasdraw : rand(); is too slow...will result in many identical id's */ |
||
93 | struct timeval tv;struct timezone tz;gettimeofday(&tv, &tz);unsigned int canvas_root_id = (unsigned int) tv.tv_usec; |
||
94 | infile = stdin;/* read flyscript via stdin */ |
||
95 | int i,c; |
||
96 | double double_data[MAX_INT+1]; |
||
97 | int int_data[MAX_INT+1]; |
||
98 | for(i=0;i<MAX_INT;i++){int_data[i]=0;double_data[i]=0;} |
||
99 | int use_parametric = FALSE;/* will be reset after parametric plotting */ |
||
100 | int use_axis = FALSE; |
||
101 | int use_axis_numbering = FALSE; |
||
102 | int line_width = 1; |
||
103 | int decimals = 2; |
||
104 | int precision = 100; /* 10 = 1;100=2;1000=3 decimal display for mouse coordinates or grid coordinate */ |
||
105 | int use_userdraw = FALSE; /* flag to indicate user interaction: incompatible with "drag & drop" code !! */ |
||
106 | int drag_type = -1;/* 0,1,2 : xy,x,y */ |
||
107 | int use_tooltip = FALSE; |
||
108 | char *tooltip_text = "Click here"; |
||
109 | char *temp = ""; /* */ |
||
110 | char *bgcolor = "";/* used for background of canvas_div ; default is tranparent */ |
||
111 | char *stroke_color = "255,0,0"; |
||
112 | char *fill_color = "0,255,0"; |
||
113 | char *font_family = "12px Ariel"; /* commands xaxistext,yaxistext,legend,text/textup/string/stringup may us this */ |
||
114 | char *font_color = "#00000"; |
||
115 | char *draw_type = "points"; |
||
116 | char *fly_font = "normal"; |
||
117 | char *input_style = ""; |
||
118 | char *flytext = ""; |
||
7785 | schaersvoo | 119 | char *affine_matrix = "[1,0,0,1,0,0]"; |
7614 | schaersvoo | 120 | int pixelsize = 1; |
121 | int reply_format = 0; |
||
122 | int input_cnt = 0; |
||
123 | int ext_img_cnt = 0; |
||
124 | int font_size = 12; |
||
125 | int dashtype[2] = { 2 , 2 }; |
||
126 | int js_function[MAX_JS_FUNCTIONS]; /* javascript functions include objects on demand basis : only once per object type */ |
||
127 | for(i=0;i<MAX_JS_FUNCTIONS;i++){js_function[i]=0;} |
||
128 | int arrow_head = 8; /* size in px*/ |
||
129 | int crosshair_size = 10; /* size in px*/ |
||
130 | int plot_steps = 150; |
||
131 | int found_size_command = 0; |
||
132 | int click_cnt = 1; |
||
133 | int clock_cnt = 0; /* counts the amount of clocks used -> unique object clock%d */ |
||
134 | int linegraph_cnt = 0; /* identifier for command 'linegraph' ; multiple line graphs may be plotted in a single plot*/ |
||
135 | int use_mouse_coordinates = FALSE; |
||
136 | double angle = 0.0; |
||
137 | int translate_x = 0; |
||
138 | int translate_y = 0; |
||
139 | int clickfillmarge = 20; |
||
140 | int animation_type = 9; /* == object type curve in drag library */ |
||
7663 | schaersvoo | 141 | int use_input_xy = 0; |
7614 | schaersvoo | 142 | size_t string_length = 0; |
143 | double stroke_opacity = 0.8; |
||
144 | double fill_opacity = 0.8; |
||
145 | char *URL = "http://localhost/images"; |
||
146 | memset(buffer,'\0',MAX_BUFFER); |
||
147 | void *tmp_buffer = ""; |
||
148 | |||
149 | /* default writing a unzipped js-include file into wims getfile directory */ |
||
150 | char *w_wims_session = getenv("w_wims_session"); |
||
151 | if( w_wims_session == NULL || *w_wims_session == 0 ){ |
||
152 | canvas_error("Hmmm, your wims environment does not exist...\nCanvasdraw should be used within wims."); |
||
153 | } |
||
154 | int L0=strlen(w_wims_session) + 21; |
||
155 | char *getfile_dir = my_newmem(L0); /* create memory to fit string precisely */ |
||
156 | snprintf(getfile_dir,L0, "../sessions/%s/getfile",w_wims_session);/* string will fit precisely */ |
||
157 | mode_t process_mask = umask(0); /* check if file exists */ |
||
158 | int result = mkdir(getfile_dir, S_IRWXU | S_IRWXG | S_IRWXO); |
||
159 | if( result == 0 || errno == EEXIST ){ |
||
160 | umask(process_mask); /* be sure to set correct permission */ |
||
161 | char *w_session = getenv("w_session"); |
||
162 | int L1 = (int) (strlen(w_session)) + find_number_of_digits(canvas_root_id) + 48; |
||
163 | char *getfile_cmd = my_newmem(L1); /* create memory to fit string precisely */ |
||
164 | 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 */ |
||
165 | /* write the include tag to html page:<script type="text/javascript" src="wims.cgi?session=%s&cmd=getfile&special_parm=11223344_js"></script> */ |
||
166 | /* now write file into getfile dir*/ |
||
167 | char *w_wims_home = getenv("w_wims_home"); /* "/home/users/wims" : we need absolute path for location */ |
||
168 | int L2 = (int) (strlen(w_wims_home)) + (int) (strlen(w_wims_session)) + find_number_of_digits(canvas_root_id) + 23; |
||
169 | char *location = my_newmem(L2); /* create memory to fit string precisely */ |
||
170 | snprintf(location,L2,"%s/sessions/%s/getfile/%d.js",w_wims_home,w_wims_session,canvas_root_id);/*absolute path */ |
||
171 | js_include_file = fopen(location,"w");/* open the file location for writing */ |
||
172 | /* check on opening...if nogood : mount readonly? disk full? permissions not set correctly? */ |
||
173 | if(js_include_file == NULL){ canvas_error("SHOULD NOT HAPPEN : could not write to javascript include file...check your system logfiles !" );} |
||
174 | |||
175 | /* ----------------------------------------------------- */ |
||
176 | /* while more lines to process */ |
||
177 | |||
178 | while(!finished){ |
||
179 | if(line_number>1 && found_size_command == FALSE){canvas_error("command \"size xsize,ysize\" needs to come first ! ");} |
||
180 | type = get_token(infile); |
||
181 | done = FALSE; |
||
182 | /* |
||
183 | @canvasdraw |
||
184 | @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 | 185 | @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 | 186 | */ |
187 | switch(type){ |
||
188 | case END: |
||
189 | finished = 1; |
||
190 | done = TRUE; |
||
191 | break; |
||
192 | case 0: |
||
193 | sync_input(infile); |
||
194 | break; |
||
195 | case COMMENT: |
||
196 | sync_input(infile); |
||
197 | break; |
||
198 | case EMPTY: |
||
199 | sync_input(infile); |
||
200 | break; |
||
201 | case SIZE: |
||
202 | /* |
||
203 | @size width,height |
||
204 | @set canvas size in pixels |
||
205 | @mandatory first command |
||
7647 | schaersvoo | 206 | @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 | 207 | */ |
208 | found_size_command = TRUE; |
||
209 | xsize = (int)(abs(round(get_real(infile,0)))); /* just to be sure that sizes > 0 */ |
||
210 | ysize = (int)(abs(round(get_real(infile,1)))); |
||
211 | /* sometimes we want xrange / yrange to be in pixels...without telling x/y-range */ |
||
212 | xmin = 0;xmax = xsize; |
||
7647 | schaersvoo | 213 | ymin = 0;ymax = ysize; |
7614 | schaersvoo | 214 | |
215 | /* |
||
216 | The sequence in which stuff is finally printed is important !! |
||
217 | for example, when writing a 'include.js" the may not be a "script tag <script>" etc etc |
||
218 | */ |
||
219 | 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); |
||
220 | fprintf(js_include_file,"\n<!-- begin generated javascript include for canvasdraw -->\n"); |
||
221 | fprintf(stdout,"<!-- include actual object code via include file -->\n<script type=\"text/javascript\" src=\"%s\"></script>\n",getfile_cmd); |
||
7729 | schaersvoo | 222 | fprintf(js_include_file,"var wims_canvas_function%d = function(){\n<!-- common used stuff -->\n\ |
223 | var xsize = %d;\ |
||
224 | var ysize = %d;\ |
||
225 | var canvas_div = document.getElementById(\"canvas_div%d\");\ |
||
226 | 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;};\ |
||
227 | 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 | 228 | 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);};};\ |
229 | 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);};};\ |
||
230 | 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);};};\ |
||
231 | 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 | 232 | function scale_x_radius(rx){return parseInt(x2px(rx) - x2px(0));};\ |
233 | function scale_y_radius(ry){return parseInt(y2px(ry) - y2px(0));};\ |
||
234 | function distance(x1,y1,x2,y2){return parseInt(Math.sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) ));};\ |
||
235 | 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) ));};\ |
||
236 | 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 | 237 | var xlogbase = 10;\ |
238 | var ylogbase = 10;\ |
||
7729 | schaersvoo | 239 | var use_xlogscale = 0;\ |
240 | var use_ylogscale = 0;\ |
||
241 | var x_strings = null;\ |
||
242 | var y_strings = null;\ |
||
243 | var use_pan_and_zoom = 0;\ |
||
7784 | schaersvoo | 244 | var x_use_snap_to_grid = 0;\ |
245 | var y_use_snap_to_grid = 0;\ |
||
7729 | schaersvoo | 246 | var xstart = 0;\ |
247 | 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 | 248 | /* default add the drag code : nearly always used ...*/ |
249 | add_drag_code(js_include_file,DRAG_CANVAS,canvas_root_id); |
||
250 | break; |
||
251 | case XRANGE: |
||
252 | /* |
||
253 | @ xrange xmin,xmax |
||
254 | @ if not given: 0,xsize (eg in pixels) |
||
255 | */ |
||
256 | for(i = 0 ; i<2; i++){ |
||
257 | switch(i){ |
||
258 | case 0: xmin = get_real(infile,0);break; |
||
259 | case 1: xmax = get_real(infile,1);break; |
||
260 | default: break; |
||
261 | } |
||
262 | } |
||
263 | if(xmin >= xmax){canvas_error(" xrange is not OK : xmin < xmax !\n");} |
||
264 | fprintf(js_include_file,"var xmin = %f;var xmax = %f;",xmin,xmax); |
||
265 | break; |
||
266 | case YRANGE: |
||
267 | /* |
||
268 | @ yrange ymin,ymax |
||
269 | @ if not given 0,ysize (eg in pixels) |
||
270 | */ |
||
271 | for(i = 0 ; i<2; i++){ |
||
272 | switch(i){ |
||
273 | case 0: ymin = get_real(infile,0);break; |
||
274 | case 1: ymax = get_real(infile,1);break; |
||
275 | default: break; |
||
276 | } |
||
277 | } |
||
278 | if(ymin >= ymax){canvas_error(" yrange is not OK : ymin < ymax !\n");} |
||
279 | fprintf(js_include_file,"var ymin = %f;var ymax = %f;",ymin,ymax); |
||
280 | break; |
||
281 | case TRANGE: |
||
282 | /* |
||
283 | @ trange tmin,tmax |
||
284 | @ default -2,2 |
||
285 | */ |
||
286 | use_parametric = TRUE; |
||
287 | for(i = 0 ; i<2; i++){ |
||
288 | switch(i){ |
||
289 | case 0: tmin = get_real(infile,0);break; |
||
290 | case 1: tmax = get_real(infile,1);break; |
||
291 | default: break; |
||
292 | } |
||
293 | } |
||
294 | if(tmin >= tmax ){canvas_error(" trange is not OK : tmin < tmax!\n");} |
||
295 | break; |
||
296 | case LINEWIDTH: |
||
297 | /* |
||
298 | @ linewidth int |
||
299 | @ default 1 |
||
300 | */ |
||
301 | line_width = (int) (get_real(infile,1)); |
||
302 | break; |
||
303 | case ARROWHEAD: |
||
304 | /* |
||
305 | @ arrowhead int |
||
306 | @ default 8 (pixels) |
||
307 | */ |
||
308 | arrow_head = (int) (get_real(infile,1)); |
||
309 | break; |
||
310 | case CROSSHAIRSIZE: |
||
311 | /* |
||
312 | @ crosshairsize int |
||
313 | @ default 10 (px) |
||
314 | */ |
||
315 | crosshair_size = (int) (get_real(infile,1)); |
||
316 | break; |
||
317 | case CROSSHAIR: |
||
318 | /* |
||
319 | @ crosshair x,y,color |
||
320 | @ draw a single crosshair point at (x;y) in color 'color' |
||
321 | @ use command 'crosshairsize int' and / or 'linewidth int' to adust |
||
322 | @ may be set draggable / onclick |
||
323 | */ |
||
324 | for(i=0;i<3;i++){ |
||
325 | switch(i){ |
||
326 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
327 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
328 | case 2: stroke_color = get_color(infile,1);/* name or hex color */ |
||
329 | decimals = find_number_of_digits(precision); |
||
7785 | schaersvoo | 330 | 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 | 331 | click_cnt++;reset(); |
332 | break; |
||
333 | default:break; |
||
334 | } |
||
335 | } |
||
336 | break; |
||
337 | case CROSSHAIRS: |
||
338 | /* |
||
339 | @ crosshairs color,x1,y1,x2,y2,...,x_n,y_n |
||
340 | @ draw multiple crosshair points at given coordinates in color 'color' |
||
341 | @ use command 'crosshairsize int' and / or 'linewidth int' to adust |
||
342 | @ may be set draggable / onclick individually (!) |
||
343 | */ |
||
344 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
345 | fill_color = stroke_color; |
||
346 | i=0; |
||
347 | while( ! done ){ /* get next item until EOL*/ |
||
348 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
349 | if(i%2 == 0 ){ |
||
350 | double_data[i] = get_real(infile,0); /* x */ |
||
351 | } |
||
352 | else |
||
353 | { |
||
354 | double_data[i] = get_real(infile,1); /* y */ |
||
355 | } |
||
356 | i++; |
||
357 | } |
||
358 | decimals = find_number_of_digits(precision); |
||
359 | for(c=0 ; c < i-1 ; c = c+2){ |
||
7785 | schaersvoo | 360 | 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 | 361 | click_cnt++; |
362 | } |
||
363 | reset(); |
||
364 | break; |
||
365 | case POINT: |
||
366 | /* |
||
367 | @ point x,y,color |
||
368 | @ draw a single point at (x;y) in color 'color' |
||
369 | @ use command 'linewidth int' to adust size |
||
370 | @ may be set draggable / onclick |
||
371 | @ will not resize on zooming <br />(command 'circle x,y,r,color' will resize on zooming) |
||
372 | */ |
||
373 | for(i=0;i<3;i++){ |
||
374 | switch(i){ |
||
375 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
376 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
377 | case 2: stroke_color = get_color(infile,1);/* name or hex color */ |
||
378 | decimals = find_number_of_digits(precision); |
||
7785 | schaersvoo | 379 | 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 | 380 | click_cnt++;break; |
381 | default: break; |
||
382 | } |
||
383 | } |
||
384 | reset(); |
||
385 | break; |
||
386 | case POINTS: |
||
387 | /* |
||
7634 | schaersvoo | 388 | @ points color,x1,y1,x2,y2,...,x_n,y_n |
7614 | schaersvoo | 389 | @ draw multiple points at given coordinates in color 'color' |
390 | @ use command 'linewidth int' to adust size |
||
391 | @ may be set draggable / onclick individually (!) |
||
392 | */ |
||
393 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
394 | fill_color = stroke_color; |
||
395 | i=0; |
||
396 | while( ! done ){ /* get next item until EOL*/ |
||
397 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
398 | if(i%2 == 0 ){ |
||
399 | double_data[i] = get_real(infile,0); /* x */ |
||
400 | } |
||
401 | else |
||
402 | { |
||
403 | double_data[i] = get_real(infile,1); /* y */ |
||
404 | } |
||
405 | i++; |
||
406 | } |
||
407 | decimals = find_number_of_digits(precision); |
||
408 | for(c = 0 ; c < i-1 ; c = c+2){ |
||
7785 | schaersvoo | 409 | 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 | 410 | click_cnt++; |
411 | } |
||
412 | reset(); |
||
413 | break; |
||
414 | case SEGMENT: |
||
415 | /* |
||
416 | @ segment x1,y1,x2,y2,color |
||
417 | @ draw a line segment between points (x1:y1)--(x2:y2) in color 'color' |
||
418 | @ may be set draggable / onclick |
||
419 | */ |
||
420 | for(i=0;i<5;i++) { |
||
421 | switch(i){ |
||
422 | case 0: double_data[0]= get_real(infile,0);break; /* x1-values */ |
||
423 | case 1: double_data[1]= get_real(infile,0);break; /* y1-values */ |
||
424 | case 2: double_data[2]= get_real(infile,0);break; /* x2-values */ |
||
425 | case 3: double_data[3]= get_real(infile,0);break; /* y2-values */ |
||
426 | case 4: stroke_color=get_color(infile,1);/* name or hex color */ |
||
427 | decimals = find_number_of_digits(precision); |
||
7785 | schaersvoo | 428 | 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 | 429 | click_cnt++;reset(); |
430 | break; |
||
431 | default: break; |
||
432 | } |
||
433 | } |
||
434 | break; |
||
435 | case LINE: |
||
436 | /* |
||
437 | @ line x1,y1,x2,y2,color |
||
438 | @ draw a line through points (x1:y1)--(x2:y2) in color 'color' |
||
439 | @ or use command 'curve color,formula' to draw the line <br />(uses more points to draw the line; is however better draggable) |
||
440 | @ may be set draggable / onclick |
||
441 | */ |
||
442 | for(i=0;i<5;i++){ |
||
443 | switch(i){ |
||
444 | case 0: double_data[10]= get_real(infile,0);break; /* x-values */ |
||
445 | case 1: double_data[11]= get_real(infile,0);break; /* y-values */ |
||
446 | case 2: double_data[12]= get_real(infile,0);break; /* x-values */ |
||
447 | case 3: double_data[13]= get_real(infile,0);break; /* y-values */ |
||
448 | case 4: stroke_color=get_color(infile,1);/* name or hex color */ |
||
449 | if( double_data[10] == double_data[12] ){ /* vertical line*/ |
||
450 | double_data[1] = xmin; |
||
451 | double_data[3] = ymax; |
||
452 | double_data[0] = double_data[10]; |
||
453 | double_data[2] = double_data[10]; |
||
454 | } |
||
455 | else |
||
456 | { |
||
457 | if( double_data[11] == double_data[13] ){ /* horizontal line */ |
||
458 | double_data[1] = double_data[11]; |
||
459 | double_data[3] = double_data[11]; |
||
460 | double_data[0] = ymin; |
||
461 | double_data[2] = xmax; |
||
462 | } |
||
463 | else |
||
464 | { |
||
465 | /* m */ |
||
466 | double_data[5] = (double_data[13] - double_data[11]) /(double_data[12] - double_data[10]); |
||
467 | /* q */ |
||
468 | double_data[6] = double_data[11] - ((double_data[13] - double_data[11]) /(double_data[12] - double_data[10]))*double_data[10]; |
||
469 | |||
470 | /*xmin,m*xmin+q,xmax,m*xmax+q*/ |
||
471 | |||
472 | double_data[1] = (double_data[5])*(xmin)+(double_data[6]); |
||
473 | double_data[3] = (double_data[5])*(xmax)+(double_data[6]); |
||
474 | double_data[0] = xmin; |
||
475 | double_data[2] = xmax; |
||
476 | } |
||
477 | } |
||
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,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 | 480 | click_cnt++;reset(); |
481 | break; |
||
482 | } |
||
483 | } |
||
484 | break; |
||
485 | case HLINE: |
||
486 | /* |
||
487 | @ hline x,y,color |
||
488 | @ draw a horizontal line through point (x:y) in color 'color' |
||
489 | @ or use command 'curve color,formula' to draw the line <br />(uses more points to draw the line; is however better draggable) |
||
490 | @ may be set draggable / onclick |
||
491 | */ |
||
492 | for(i=0;i<3;i++) { |
||
493 | switch(i){ |
||
494 | case 0: double_data[0] = get_real(infile,0);break; /* x-values */ |
||
495 | case 1: double_data[1] = get_real(infile,0);break; /* y-values */ |
||
496 | case 2: stroke_color = get_color(infile,1);/* name or hex color */ |
||
497 | double_data[3] = double_data[1]; |
||
498 | decimals = find_number_of_digits(precision); |
||
7785 | schaersvoo | 499 | 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 | 500 | click_cnt++;reset(); |
501 | break; |
||
502 | } |
||
503 | } |
||
504 | break; |
||
505 | case VLINE: |
||
506 | /* |
||
507 | @ vline x,y,color |
||
508 | @ draw a vertical line through point (x:y) in color 'color' |
||
509 | @ may be set draggable / onclick |
||
510 | */ |
||
511 | for(i=0;i<3;i++) { |
||
512 | switch(i){ |
||
513 | case 0: double_data[0] = get_real(infile,0);break; /* x-values */ |
||
514 | case 1: double_data[1] = get_real(infile,0);break; /* y-values */ |
||
515 | case 2: stroke_color=get_color(infile,1);/* name or hex color */ |
||
516 | double_data[2] = double_data[0]; |
||
517 | decimals = find_number_of_digits(precision); |
||
7785 | schaersvoo | 518 | 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 | 519 | click_cnt++;reset(); |
520 | break; |
||
521 | } |
||
522 | } |
||
523 | break; |
||
524 | case SQUARE: |
||
525 | /* |
||
526 | @ square x,y,side,color |
||
527 | @ draw a square with left top corner (x:y) with side 'side' in color 'color' |
||
528 | @ use command 'fsquare x,y,side,color' for a filled square |
||
529 | @ use command/keyword 'filled' before command 'square x,y,side,color' |
||
530 | @ use command 'fillcolor color' before 'fsquare' to set the fill colour. |
||
531 | @ may be set draggable / onclick |
||
532 | */ |
||
533 | for(i=0;i<5;i++){ |
||
534 | switch(i){ |
||
535 | case 0:double_data[0] = get_real(infile,0);break; /* x-values */ |
||
536 | case 1:double_data[1] = get_real(infile,0);break; /* y-values */ |
||
537 | case 2:double_data[2] = get_real(infile,0); |
||
538 | double_data[3] = double_data[2]; |
||
539 | break; /* x-values */ |
||
540 | case 3:stroke_color = get_color(infile,1);/* name or hex color */ |
||
541 | decimals = find_number_of_digits(precision); |
||
7785 | schaersvoo | 542 | 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 | 543 | click_cnt++;reset(); |
544 | break; |
||
545 | } |
||
546 | } |
||
547 | break; |
||
548 | case ROUNDRECT: |
||
549 | /* |
||
550 | @ roundrect x1,y1,x2,y2,radius,color |
||
551 | @ use command 'froundrect x1,y1,x2,y2,radius,color' for a filled rectangle |
||
552 | @ use command/keyword 'filled' before command 'roundrect x1,y1,x2,y2,radius,color' |
||
553 | @ use command 'fillcolor color' before 'froundrect' to set the fill colour. |
||
554 | @ may be set draggable / onclick |
||
555 | */ |
||
556 | for(i=0;i<6;i++){ |
||
557 | switch(i){ |
||
558 | case 0:double_data[0] = get_real(infile,0);break; /* x-values */ |
||
559 | case 1:double_data[1] = get_real(infile,0);break; /* y-values */ |
||
560 | case 2:double_data[2] = get_real(infile,0);break; /* x-values */ |
||
561 | case 3:double_data[3] = get_real(infile,0);break; /* y-values */ |
||
562 | case 4:int_data[0] = (int) (get_real(infile,0));break; /* radius value in pixels */ |
||
563 | case 5:stroke_color = get_color(infile,1);/* name or hex color */ |
||
564 | decimals = find_number_of_digits(precision); |
||
7785 | schaersvoo | 565 | 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 | 566 | click_cnt++;reset(); |
567 | break; |
||
568 | } |
||
569 | } |
||
570 | break; |
||
571 | case RECT: |
||
572 | /* |
||
573 | @ rect x1,y1,x2,y2,color |
||
574 | @ use command 'rect x1,y1,x2,y2,color' for a filled rectangle |
||
575 | @ use command/keyword 'filled' before command 'rect x1,y1,x2,y2,color' |
||
576 | @ use command 'fillcolor color' before 'frect' to set the fill colour. |
||
577 | @ may be set draggable / onclick |
||
578 | */ |
||
579 | for(i=0;i<5;i++){ |
||
580 | switch(i){ |
||
581 | case 0:double_data[0] = get_real(infile,0);break; /* x-values */ |
||
582 | case 1:double_data[1] = get_real(infile,0);break; /* y-values */ |
||
583 | case 2:double_data[2] = get_real(infile,0);break; /* x-values */ |
||
584 | case 3:double_data[3] = get_real(infile,0);break; /* y-values */ |
||
585 | case 4:stroke_color = get_color(infile,1);/* name or hex color */ |
||
586 | decimals = find_number_of_digits(precision); |
||
7785 | schaersvoo | 587 | 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 | 588 | click_cnt++;reset(); |
589 | break; |
||
590 | } |
||
591 | } |
||
592 | break; |
||
593 | case POLYLINE: |
||
594 | /* |
||
595 | @ polyline color,x1,y1,x2,y2...x_n,y_n |
||
596 | @ may be set draggable / onclick |
||
597 | */ |
||
598 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
599 | i=0; |
||
600 | c=0; |
||
601 | while( ! done ){ /* get next item until EOL*/ |
||
602 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
603 | for( c = 0 ; c < 2; c++){ |
||
604 | if(c == 0 ){ |
||
605 | double_data[i] = get_real(infile,0); |
||
606 | i++; |
||
607 | } |
||
608 | else |
||
609 | { |
||
610 | double_data[i] = get_real(infile,1); |
||
611 | i++; |
||
612 | } |
||
613 | } |
||
614 | } |
||
615 | /* draw path : not closed & not filled */ |
||
616 | decimals = find_number_of_digits(precision); |
||
7785 | schaersvoo | 617 | 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 | 618 | click_cnt++;reset(); |
619 | break; |
||
620 | case POLY: |
||
621 | /* |
||
622 | @ poly color,x1,y1,x2,y2...x_n,y_n |
||
623 | @ draw closed polygon |
||
624 | @ use command 'fpoly' to fill it, use command 'fillcolor color' to set the fill color |
||
625 | @ may be set draggable / onclick |
||
626 | */ |
||
627 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
628 | i=0; |
||
629 | c=0; |
||
630 | while( ! done ){ /* get next item until EOL*/ |
||
631 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
632 | for( c = 0 ; c < 2; c++){ |
||
633 | if(c == 0 ){ |
||
634 | double_data[i] = get_real(infile,0); |
||
635 | i++; |
||
636 | } |
||
637 | else |
||
638 | { |
||
639 | double_data[i] = get_real(infile,1); |
||
640 | i++; |
||
641 | } |
||
642 | } |
||
643 | } |
||
644 | /* draw path : closed & optional filled */ |
||
645 | decimals = find_number_of_digits(precision); |
||
7785 | schaersvoo | 646 | 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 | 647 | click_cnt++;reset(); |
648 | break; |
||
649 | case ARC: |
||
650 | /* |
||
651 | @ arc xc,yc,width,height,start_angle,end_angle,color |
||
652 | @ can not be set "onclick" or "drag xy" |
||
653 | @ attention: width == height == radius in pixels) |
||
654 | */ |
||
655 | for(i=0;i<7;i++){ |
||
656 | switch(i){ |
||
657 | case 0:double_data[0] = get_real(infile,0);break; /* x-values */ |
||
658 | case 1:double_data[1] = get_real(infile,0);break; /* y-values */ |
||
659 | case 2:int_data[0] = (int)(get_real(infile,0));break; /* width in pixels ! */ |
||
660 | case 3:int_data[1] = (int)(get_real(infile,0));break; /* height in pixels ! */ |
||
661 | case 4:double_data[2] = get_real(infile,0);break; /* start angle in degrees */ |
||
662 | case 5:double_data[3] = get_real(infile,0);break; /* end angle in degrees */ |
||
663 | case 6:stroke_color = get_color(infile,1);/* name or hex color */ |
||
664 | /* in Shape library: |
||
665 | x[0] = x[1] = xc |
||
666 | y[0] = y[1] = yc |
||
667 | w[0] = w[1] = radius = width = height |
||
668 | h[0] = start_angle ; h[1] = end_engle |
||
669 | */ |
||
670 | decimals = find_number_of_digits(precision); |
||
7785 | schaersvoo | 671 | 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 | 672 | reset(); |
673 | break; |
||
674 | } |
||
675 | } |
||
676 | break; |
||
677 | case ELLIPSE: |
||
678 | /* |
||
679 | @ ellipse xc,yc,radius_x,radius_y,color |
||
680 | @ a ellipse with center xc/yc in x/y-range |
||
681 | @ radius_x and radius_y are in pixels |
||
682 | @ may be set draggable / onclick |
||
683 | @ will shrink / expand on zoom out / zoom in |
||
684 | */ |
||
685 | for(i=0;i<5;i++){ |
||
686 | switch(i){ |
||
687 | case 0:double_data[0] = get_real(infile,0);break; /* x-values */ |
||
688 | case 1:double_data[1] = get_real(infile,0);break; /* y-values */ |
||
689 | case 2:double_data[2] = get_real(infile,0);break; /* rx -> px */ |
||
690 | case 3:double_data[3] = get_real(infile,0);break; /* ry -> px */ |
||
691 | case 4:stroke_color = get_color(infile,1);/* name or hex color */ |
||
692 | decimals = find_number_of_digits(precision); |
||
7785 | schaersvoo | 693 | 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 | 694 | click_cnt++;reset(); |
695 | break; |
||
696 | } |
||
697 | } |
||
698 | break; |
||
699 | case DASHTYPE: |
||
700 | /* |
||
701 | @ dashtype int ,int |
||
702 | @ When dashed is set, the objects will be drawn with this dashtyp |
||
703 | @ default value "dashtype 2,2" |
||
704 | */ |
||
705 | for(i=0;i<2;i++){ |
||
706 | switch(i){ |
||
707 | case 0 : dashtype[0] = (int) line_width*( get_real(infile,0)) ; break; |
||
708 | case 1 : dashtype[1] = (int) line_width*( get_real(infile,1)) ; break; |
||
709 | } |
||
710 | } |
||
711 | break; |
||
712 | case CIRCLE: |
||
713 | /* |
||
714 | @ circle xc,yc,width (2*r in pixels),color |
||
715 | @ use command 'fcircle xc,yc,d,color' or command 'filled' for a filled disk |
||
716 | @ use command 'fillcolor color' to set the fillcolor |
||
717 | @ may be set draggable / onclick |
||
718 | @ will shrink / expand on zoom out / zoom in |
||
719 | */ |
||
720 | for(i=0;i<4;i++){ |
||
721 | switch(i){ |
||
722 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
723 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
724 | case 2: double_data[2] = px2x((get_real(infile,0))/2) - px2x(0);break; /* radius in 'dx' xrange*/ |
||
725 | case 3: stroke_color = get_color(infile,1);/* name or hex color */ |
||
726 | decimals = find_number_of_digits(precision); |
||
7785 | schaersvoo | 727 | 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 | 728 | click_cnt++;reset(); |
729 | break; |
||
730 | } |
||
731 | } |
||
732 | break; |
||
733 | case RAYS: |
||
734 | /* |
||
735 | @ rays color,xc,yc,x1,y1,x2,y2,x3,y3...x_n,y_n |
||
736 | @ draw rays in color 'color' and center (xc:yc) |
||
7786 | schaersvoo | 737 | @ may be set draggable or onclick (every individual ray) |
7614 | schaersvoo | 738 | */ |
739 | stroke_color=get_color(infile,0); |
||
7786 | schaersvoo | 740 | fill_color = stroke_color; |
741 | double_data[0] = get_real(infile,0);/* xc */ |
||
742 | double_data[1] = get_real(infile,0);/* yc */ |
||
743 | i=2; |
||
744 | while( ! done ){ /* get next item until EOL*/ |
||
745 | if(i > MAX_INT - 1){canvas_error("in command rays to many points / rays in argument: repeat command multiple times to fit");} |
||
746 | if(i%2 == 0 ){ |
||
747 | double_data[i] = get_real(infile,0); /* x */ |
||
7614 | schaersvoo | 748 | } |
7786 | schaersvoo | 749 | else |
750 | { |
||
751 | double_data[i] = get_real(infile,1); /* y */ |
||
7614 | schaersvoo | 752 | } |
7786 | schaersvoo | 753 | fprintf(js_include_file,"/* double_data[%d] = %f */\n",i,double_data[i]); |
754 | i++; |
||
7614 | schaersvoo | 755 | } |
7786 | schaersvoo | 756 | |
757 | if( i%2 != 0 ){canvas_error("in command rays: unpaired x or y value");} |
||
758 | decimals = find_number_of_digits(precision); |
||
759 | for(c=2; c<i;c = c+2){ |
||
7614 | schaersvoo | 760 | click_cnt++; |
7786 | schaersvoo | 761 | 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 | 762 | } |
763 | reset(); |
||
764 | break; |
||
765 | case ARROW: |
||
766 | /* |
||
767 | @ arrow x1,y1,x2,y2,h,color |
||
768 | @ draw a single headed arrow/vector from (x1:y1) to (x2:y2)<br />with arrowhead size h in px and in color 'color' |
||
769 | @ use command 'linewidth int' to adjust thickness of the arrow |
||
770 | @ may be set draggable / onclick |
||
771 | */ |
||
772 | for(i=0;i<6;i++){ |
||
773 | switch(i){ |
||
774 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
775 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
776 | case 2: double_data[2] = get_real(infile,0);break; /* x */ |
||
777 | case 3: double_data[3] = get_real(infile,0);break; /* y */ |
||
778 | case 4: arrow_head = (int) get_real(infile,0);break;/* h */ |
||
779 | case 5: stroke_color = get_color(infile,1);/* name or hex color */ |
||
780 | decimals = find_number_of_digits(precision); |
||
7785 | schaersvoo | 781 | 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 | 782 | click_cnt++; |
783 | reset(); |
||
784 | break; |
||
785 | } |
||
786 | } |
||
787 | break; |
||
788 | case ARROW2: |
||
789 | /* |
||
790 | @ arrow2 x1,y1,x2,y2,h,color |
||
791 | @ draw a double headed arrow/vector from (x1:y1) to (x2:y2)<br />with arrowhead size h in px and in color 'color' |
||
792 | @ use command 'arrowhead int' to adjust the arrow head size |
||
793 | @ use command 'linewidth int' to adjust thickness of the arrow |
||
794 | @ may be set draggable / onclick |
||
795 | */ |
||
796 | for(i=0;i<6;i++){ |
||
797 | switch(i){ |
||
798 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
799 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
800 | case 2: double_data[2] = get_real(infile,0);break; /* x */ |
||
801 | case 3: double_data[3] = get_real(infile,0);break; /* y */ |
||
802 | case 4: arrow_head = (int) get_real(infile,0);break;/* h */ |
||
803 | case 5: stroke_color = get_color(infile,1);/* name or hex color */ |
||
804 | decimals = find_number_of_digits(precision); |
||
7785 | schaersvoo | 805 | 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 | 806 | click_cnt++;reset(); |
807 | break; |
||
808 | } |
||
809 | } |
||
810 | break; |
||
811 | case PARALLEL: |
||
812 | /* |
||
813 | @ parallel x1,y1,x2,y2,dx,dy,n,[colorname or #hexcolor] |
||
814 | @ can not be set "onclick" or "drag xy" |
||
815 | */ |
||
816 | for( i = 0;i < 8; i++ ){ |
||
817 | switch(i){ |
||
818 | case 0: double_data[0] = get_real(infile,0);break; /* x1-values -> x-pixels*/ |
||
819 | case 1: double_data[1] = get_real(infile,0);break; /* y1-values -> y-pixels*/ |
||
820 | case 2: double_data[2] = get_real(infile,0);break; /* x2-values -> x-pixels*/ |
||
821 | case 3: double_data[3] = get_real(infile,0);break; /* y2-values -> y-pixels*/ |
||
822 | case 4: double_data[4] = xmin + get_real(infile,0);break; /* xv -> x-pixels */ |
||
823 | case 5: double_data[5] = ymax + get_real(infile,0);break; /* yv -> y-pixels */ |
||
824 | case 6: int_data[0] = (int) (get_real(infile,0));break; /* n */ |
||
825 | case 7: stroke_color=get_color(infile,1);/* name or hex color */ |
||
826 | decimals = find_number_of_digits(precision); |
||
7785 | schaersvoo | 827 | 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 | 828 | click_cnt++;reset(); |
829 | break; |
||
830 | default: break; |
||
831 | } |
||
832 | } |
||
833 | break; |
||
834 | case TRIANGLE: |
||
835 | /* |
||
836 | @triangle x1,y1,x2,y2,x3,y3,color |
||
837 | @may be set draggable / onclic |
||
838 | */ |
||
839 | for(i=0;i<7;i++){ |
||
840 | switch(i){ |
||
841 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
842 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
843 | case 2: double_data[2] = get_real(infile,0);break; /* x */ |
||
844 | case 3: double_data[3] = get_real(infile,0);break; /* y */ |
||
845 | case 4: double_data[4] = get_real(infile,0);break; /* x */ |
||
846 | case 5: double_data[5] = get_real(infile,0);break; /* y */ |
||
847 | case 6: stroke_color = get_color(infile,1);/* name or hex color */ |
||
848 | decimals = find_number_of_digits(precision); |
||
7785 | schaersvoo | 849 | 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 | 850 | click_cnt++;reset(); |
851 | break; |
||
852 | default: break; |
||
853 | } |
||
854 | } |
||
855 | break; |
||
856 | case LATTICE: |
||
857 | /* |
||
858 | @lattice x0,y0,xv1,yv1,xv2,yv2,n1,n2,color |
||
859 | @can not be set "onclick" or "drag xy" |
||
860 | */ |
||
861 | if( js_function[DRAW_LATTICE] != 1 ){ js_function[DRAW_LATTICE] = 1;} |
||
862 | for( i = 0; i<9; i++){ |
||
863 | switch(i){ |
||
864 | case 0: int_data[0] = x2px(get_real(infile,0));break; /* x0-values -> x-pixels*/ |
||
865 | case 1: int_data[1] = y2px(get_real(infile,0));break; /* y0-values -> y-pixels*/ |
||
866 | case 2: int_data[2] = (int) (get_real(infile,0));break; /* x1-values -> x-pixels*/ |
||
867 | case 3: int_data[3] = (int) (get_real(infile,0));break; /* y1-values -> y-pixels*/ |
||
868 | case 4: int_data[4] = (int) (get_real(infile,0));break; /* x2-values -> x-pixels*/ |
||
869 | case 5: int_data[5] = (int) (get_real(infile,0));break; /* y2-values -> y-pixels*/ |
||
870 | case 6: int_data[6] = (int) (get_real(infile,0));break; /* n1-values */ |
||
871 | case 7: int_data[7] = (int) (get_real(infile,0));break; /* n2-values */ |
||
872 | case 8: stroke_color=get_color(infile,1); |
||
873 | decimals = find_number_of_digits(precision); |
||
874 | 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); |
||
875 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
876 | 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); |
||
877 | add_to_buffer(tmp_buffer); |
||
878 | break; |
||
879 | default:break; |
||
880 | } |
||
881 | } |
||
882 | reset(); |
||
883 | break; |
||
884 | case SNAPTOGRID: |
||
885 | /* |
||
886 | @ snaptogrid |
||
887 | @ keyword (no arguments rewquired) needs to be defined before command 'userdraw' and after command 'grid' |
||
888 | @ in case of userdraw the drawn points will snap to xmajor / ymajor grid |
||
7784 | schaersvoo | 889 | @ 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 | 890 | */ |
7784 | schaersvoo | 891 | 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 | 892 | break; |
7784 | schaersvoo | 893 | case XSNAPTOGRID: |
894 | /* |
||
895 | @ xsnaptogrid |
||
896 | @ keyword (no arguments rewquired) needs to be defined before command 'userdraw' and after command 'grid' |
||
897 | @ in case of userdraw the drawn points will snap to xmajor grid |
||
898 | @ 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 /> |
||
899 | */ |
||
900 | 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"); |
||
901 | break; |
||
902 | case YSNAPTOGRID: |
||
903 | /* |
||
904 | @ ysnaptogrid |
||
905 | @ keyword (no arguments rewquired) needs to be defined before command 'userdraw' and after command 'grid' |
||
906 | @ in case of userdraw the drawn points will snap to ymajor grid |
||
907 | @ 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 /> |
||
908 | */ |
||
909 | 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"); |
||
910 | break; |
||
7663 | schaersvoo | 911 | case USERTEXTAREA_XY: |
912 | /* |
||
913 | @ usertextarea_xy |
||
914 | @ keyword |
||
915 | @ to be used in combination with command "userdraw object_type,color" wherein object_type is only segment / polyline for the time being... |
||
916 | @ if set two textareas are added to the document<br />(one for x-values , one for y-values) |
||
917 | @ the student may use this as correction for (x:y) on a drawing (or to draw without mouse, using just the coordinates) |
||
918 | @ can not be combined with command "intooltip tiptext" <br />note: the 'tooltip div element' is used for placing inputfields |
||
919 | @ user drawings will not zoom on zooming (or pan on panning) |
||
920 | */ |
||
7749 | schaersvoo | 921 | if(use_tooltip == TRUE){canvas_error("usertextarea_xy can not be combined with intooltip command");} |
922 | if( use_input_xy == 1 ){canvas_error("usertextarea_xy can not be combined with userinput_xy command");} |
||
923 | 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;};"); |
||
924 | use_input_xy = 2; |
||
925 | break; |
||
7652 | schaersvoo | 926 | case USERINPUT_XY: |
927 | /* |
||
928 | @ userinput_xy |
||
929 | @ keyword |
||
930 | @ to be used in combination with command "userdraw object_type,color" |
||
931 | @ 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) |
||
932 | @ the student may use this as correction for (x:y) on a drawing (or to draw without mouse, using just the coordinates) |
||
7749 | schaersvoo | 933 | @ 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 | 934 | @ can not be combined with command "intooltip tiptext" <br />note: the 'tooltip div element' is used for placing inputfields |
7653 | schaersvoo | 935 | @ user drawings will not zoom on zooming (or pan on panning) |
7652 | schaersvoo | 936 | */ |
7749 | schaersvoo | 937 | if(use_tooltip == TRUE){canvas_error("userinput_xy can not be combined with intooltip command");} |
938 | /* add simple eval check to avoid code injection with unprotected eval(string) */ |
||
939 | 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;};"); |
||
940 | use_input_xy = 1; |
||
941 | break; |
||
7614 | schaersvoo | 942 | case USERDRAW: |
943 | /* |
||
944 | @ userdraw object_type,color |
||
7663 | schaersvoo | 945 | @ 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 | 946 | @ 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) |
947 | @ 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 |
||
948 | @ note: object_type polygone: Will be finished (the object is closed) when clicked on the first point of the polygone again. |
||
949 | @ 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) |
||
950 | @ use command "filled", "opacity int,int" and "fillcolor color" to trigger coloured filling of fillable objects |
||
951 | @ use command "dashed" and/or "dashtype int,int" to trigger dashing |
||
952 | @ use command "replyformat int" to control / adjust output formatting of javascript function read_canvas(); |
||
953 | @ may be combined with onclick or drag xy of other components of flyscript objects (although not very usefull...) |
||
7663 | schaersvoo | 954 | @ may be combined with keyword 'userinput_xy' or |
7653 | schaersvoo | 955 | @ 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 | 956 | */ |
957 | if( use_userdraw == TRUE ){ /* only one object type may be drawn*/ |
||
958 | canvas_error("Only one userdraw primitive may be used: read documentation !!"); |
||
959 | } |
||
960 | use_userdraw = TRUE; |
||
7653 | schaersvoo | 961 | 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 | 962 | draw_type = get_string_argument(infile,0); |
963 | stroke_color = get_color(infile,1); |
||
964 | if( strcmp(draw_type,"point") == 0 ){ |
||
965 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
966 | if(reply_format < 1 ){reply_format = 8;} |
||
967 | /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */ |
||
7652 | schaersvoo | 968 | if(use_input_xy == 1){ |
969 | add_input_circle(js_include_file,1,1); |
||
970 | add_input_xy(js_include_file,canvas_root_id); |
||
971 | } |
||
7614 | schaersvoo | 972 | 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); |
973 | } |
||
974 | else |
||
975 | if( strcmp(draw_type,"points") == 0 ){ |
||
976 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
977 | if(reply_format < 1 ){reply_format = 8;} |
||
978 | /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */ |
||
7652 | schaersvoo | 979 | if(use_input_xy == 1){ |
980 | add_input_circle(js_include_file,1,2); |
||
981 | add_input_xy(js_include_file,canvas_root_id); |
||
982 | } |
||
7614 | schaersvoo | 983 | 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); |
984 | } |
||
985 | else |
||
986 | if( strcmp(draw_type,"segment") == 0 ){ |
||
987 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
988 | if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;} |
||
989 | if(reply_format < 1){reply_format = 11;} |
||
7652 | schaersvoo | 990 | if(use_input_xy == 1){ |
991 | add_input_segment(js_include_file,1); |
||
992 | add_input_x1y1x2y2(js_include_file,canvas_root_id); |
||
993 | } |
||
7614 | schaersvoo | 994 | add_js_segments(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]); |
995 | } |
||
996 | else |
||
7663 | schaersvoo | 997 | if( strcmp(draw_type,"polyline") == 0 ){ |
998 | if( js_function[DRAW_POLYLINE] != 1 ){ js_function[DRAW_POLYLINE] = 1;} |
||
7782 | schaersvoo | 999 | if(reply_format < 1){reply_format = 23;} |
7780 | schaersvoo | 1000 | if( use_input_xy == 1 ){ |
1001 | add_input_polyline(js_include_file); |
||
1002 | add_input_xy(js_include_file,canvas_root_id); |
||
7663 | schaersvoo | 1003 | } |
1004 | add_js_polyline(js_include_file,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]); |
||
1005 | } |
||
1006 | else |
||
7614 | schaersvoo | 1007 | if( strcmp(draw_type,"segments") == 0 ){ |
1008 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
1009 | if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;} |
||
1010 | if(reply_format < 1){reply_format = 11;} |
||
7652 | schaersvoo | 1011 | if(use_input_xy == 1){ |
1012 | add_input_segment(js_include_file,2); |
||
1013 | add_input_x1y1x2y2(js_include_file,canvas_root_id); |
||
1014 | } |
||
7614 | schaersvoo | 1015 | add_js_segments(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]); |
1016 | } |
||
1017 | else |
||
1018 | if( strcmp(draw_type,"circle") == 0 ){ |
||
1019 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
1020 | if(reply_format < 1){reply_format = 10;} |
||
1021 | /* 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n in x/y-range */ |
||
7652 | schaersvoo | 1022 | if(use_input_xy == 1){ |
1023 | add_input_circle(js_include_file,2,1); |
||
1024 | add_input_xyr(js_include_file,canvas_root_id); |
||
1025 | } |
||
7614 | schaersvoo | 1026 | 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]); |
1027 | } |
||
1028 | else |
||
1029 | if( strcmp(draw_type,"circles") == 0 ){ |
||
1030 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
1031 | if(reply_format < 1){reply_format = 10;} |
||
1032 | /* 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n in x/y-range */ |
||
1033 | 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]); |
||
7652 | schaersvoo | 1034 | if(use_input_xy == 1){ |
1035 | add_input_circle(js_include_file,2,2); |
||
1036 | add_input_xyr(js_include_file,canvas_root_id); |
||
1037 | } |
||
7614 | schaersvoo | 1038 | } |
1039 | else |
||
1040 | if(strcmp(draw_type,"crosshair") == 0 ){ |
||
1041 | if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;} |
||
1042 | if(reply_format < 1){reply_format = 8;} |
||
1043 | /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */ |
||
1044 | add_js_crosshairs(js_include_file,1,draw_type,line_width,crosshair_size ,stroke_color,stroke_opacity); |
||
7654 | schaersvoo | 1045 | if(use_input_xy == 1){ |
1046 | add_input_crosshair(js_include_file,1); |
||
1047 | add_input_xy(js_include_file,canvas_root_id); |
||
1048 | } |
||
7614 | schaersvoo | 1049 | } |
1050 | else |
||
1051 | if(strcmp(draw_type,"crosshairs") == 0 ){ |
||
1052 | if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;} |
||
1053 | if(reply_format < 1){reply_format = 8;} |
||
1054 | /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */ |
||
1055 | add_js_crosshairs(js_include_file,2,draw_type,line_width,crosshair_size ,stroke_color,stroke_opacity); |
||
7654 | schaersvoo | 1056 | if(use_input_xy == 1){ |
1057 | add_input_crosshair(js_include_file,2); |
||
1058 | add_input_xy(js_include_file,canvas_root_id); |
||
1059 | } |
||
7614 | schaersvoo | 1060 | } |
1061 | else |
||
1062 | if(strcmp(draw_type,"freehandline") == 0 ){ |
||
1063 | if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;} |
||
1064 | if(reply_format < 1){reply_format = 6;} |
||
1065 | 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 | 1066 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 1067 | } |
1068 | else |
||
1069 | if(strcmp(draw_type,"freehandlines") == 0 ){ |
||
1070 | if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;} |
||
1071 | if(reply_format < 1){reply_format = 6;} |
||
1072 | 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 | 1073 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 1074 | } |
1075 | else |
||
1076 | if(strcmp(draw_type,"path") == 0 ){ |
||
1077 | if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;} |
||
1078 | if(reply_format < 1){reply_format = 6;} |
||
1079 | 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 | 1080 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 1081 | } |
1082 | else |
||
1083 | if(strcmp(draw_type,"paths") == 0 ){ |
||
1084 | if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;} |
||
1085 | if(reply_format < 1){reply_format = 6;} |
||
1086 | 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 | 1087 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 1088 | } |
1089 | else |
||
1090 | if(strcmp(draw_type,"arrows") == 0 ){ |
||
1091 | if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;} |
||
1092 | if(reply_format < 1){reply_format = 11;} |
||
1093 | add_js_arrows(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head); |
||
7654 | schaersvoo | 1094 | if(use_input_xy == 1){ |
1095 | add_input_arrow(js_include_file,2); |
||
1096 | add_input_x1y1x2y2(js_include_file,canvas_root_id); |
||
1097 | } |
||
7614 | schaersvoo | 1098 | } |
1099 | else |
||
1100 | if(strcmp(draw_type,"arrow") == 0 ){ |
||
1101 | if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;} |
||
1102 | if(reply_format < 1){reply_format = 11;} |
||
1103 | add_js_arrows(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head); |
||
7654 | schaersvoo | 1104 | if(use_input_xy == 1){ |
1105 | add_input_arrow(js_include_file,1); |
||
1106 | add_input_x1y1x2y2(js_include_file,canvas_root_id); |
||
1107 | } |
||
7614 | schaersvoo | 1108 | } |
1109 | else |
||
1110 | if(strcmp(draw_type,"polygon") == 0){ |
||
1111 | if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;} |
||
1112 | if(reply_format < 1){reply_format = 2;} |
||
1113 | 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 | 1114 | if( use_input_xy == 2 ){ |
1115 | add_textarea_polygon(js_include_file); |
||
1116 | add_textarea_xy(js_include_file,canvas_root_id); |
||
7746 | schaersvoo | 1117 | } |
7614 | schaersvoo | 1118 | } |
1119 | else |
||
1120 | if(strncmp(draw_type,"poly",4) == 0){ |
||
1121 | if(strlen(draw_type) < 5){canvas_error("use command \"userdraw poly[3-9],color\" eg userdraw poly6,blue");} |
||
1122 | if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;} |
||
1123 | if(reply_format < 1){reply_format = 2;} |
||
1124 | 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 | 1125 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 1126 | } |
1127 | else |
||
1128 | if(strcmp(draw_type,"triangle") == 0){ |
||
1129 | if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;} |
||
1130 | if(reply_format < 1){reply_format = 2;} |
||
1131 | 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 | 1132 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 1133 | } |
1134 | else |
||
1135 | if( strcmp(draw_type,"line") == 0 ){ |
||
1136 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
1137 | if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;} |
||
1138 | if(reply_format < 1){reply_format = 11;} |
||
1139 | add_js_lines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]); |
||
7747 | schaersvoo | 1140 | if( use_input_xy == 1 ){ |
7780 | schaersvoo | 1141 | add_input_line(js_include_file,1); |
7747 | schaersvoo | 1142 | add_input_x1y1x2y2(js_include_file,canvas_root_id); |
1143 | } |
||
7614 | schaersvoo | 1144 | } |
1145 | else |
||
1146 | if( strcmp(draw_type,"lines") == 0 ){ |
||
1147 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
1148 | if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;} |
||
1149 | if(reply_format < 1){reply_format = 11;} |
||
1150 | add_js_lines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]); |
||
7747 | schaersvoo | 1151 | if( use_input_xy == 1 ){ |
7780 | schaersvoo | 1152 | add_input_line(js_include_file,2); |
7747 | schaersvoo | 1153 | add_input_x1y1x2y2(js_include_file,canvas_root_id); |
7746 | schaersvoo | 1154 | } |
7614 | schaersvoo | 1155 | } |
1156 | else |
||
1157 | if( strcmp(draw_type,"rects") == 0){ |
||
1158 | if( js_function[DRAW_RECTS] != 1 ){ js_function[DRAW_RECTS] = 1;} |
||
1159 | if(reply_format < 1){reply_format = 2;} |
||
1160 | 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 | 1161 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 1162 | } |
1163 | else |
||
1164 | if( strcmp(draw_type,"roundrects") == 0){ |
||
1165 | if( js_function[DRAW_ROUNDRECTS] != 1 ){ js_function[DRAW_ROUNDRECTS] = 1;} |
||
1166 | if(reply_format < 1){reply_format = 2;} |
||
1167 | 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 | 1168 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 1169 | } |
1170 | else |
||
1171 | if( strcmp(draw_type,"rect") == 0){ |
||
1172 | if( js_function[DRAW_RECTS] != 1 ){ js_function[DRAW_RECTS] = 1;} |
||
1173 | if(reply_format < 1){reply_format = 2;} |
||
1174 | 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 | 1175 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 1176 | } |
1177 | else |
||
1178 | if( strcmp(draw_type,"roundrect") == 0){ |
||
1179 | if( js_function[DRAW_ROUNDRECTS] != 1 ){ js_function[DRAW_ROUNDRECTS] = 1;} |
||
1180 | if(reply_format < 1){reply_format = 2;} |
||
1181 | 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 | 1182 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 1183 | } |
1184 | else |
||
1185 | if( strcmp(draw_type,"text") == 0){ |
||
1186 | if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;} |
||
1187 | if(reply_format < 1){reply_format = 17;} |
||
1188 | 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 | 1189 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 1190 | } |
1191 | else |
||
1192 | { |
||
1193 | canvas_error("unknown drawtype or typo? "); |
||
1194 | } |
||
1195 | reset(); |
||
1196 | break; |
||
1197 | case PLOTSTEPS: |
||
1198 | /* |
||
1199 | @ plotsteps a_number |
||
1200 | @ default 150 |
||
1201 | @ use with care ! |
||
1202 | */ |
||
1203 | plot_steps = (int) (get_real(infile,1)); |
||
1204 | break; |
||
1205 | case FONTSIZE: |
||
1206 | /* |
||
1207 | @fontsize font_size |
||
1208 | @default value 12 |
||
1209 | */ |
||
1210 | font_size = (int) (get_real(infile,1)); |
||
1211 | break; |
||
1212 | case FONTCOLOR: |
||
1213 | /* |
||
1214 | @fontcolor color |
||
1215 | @color: hexcolor or colorname |
||
1216 | @default: black |
||
1217 | @example usage: x/y-axis text |
||
1218 | */ |
||
1219 | font_color = get_color(infile,1); |
||
1220 | break; |
||
1221 | case ANIMATE: |
||
1222 | /* |
||
1223 | @animate type |
||
1224 | @type may be "point" (nothing else , yet...) |
||
1225 | @the point is a filled rectangle ; adjust colour with command 'fillcolor colorname/hexnumber' |
||
1226 | @will animate a point on the next plot/curve command |
||
1227 | @the curve will not be draw |
||
1228 | @moves repeatedly from xmin to xmax |
||
1229 | */ |
||
1230 | if( strstr(get_string(infile,1),"point") != 0 ){animation_type = 15;}else{canvas_error("the only animation type (for now) is \"point\"...");} |
||
1231 | break; |
||
7788 | schaersvoo | 1232 | case LEVELCURVE: |
1233 | /* |
||
1234 | @levelcurve color,expression in x/y,l1,l2,... |
||
1235 | @Draws (pixel) level curves for expression, with levels l1, l2,... |
||
1236 | @Take care : the arrays for holding the javascript data are limited in size !! |
||
1237 | */ |
||
1238 | stroke_color = get_color(infile,0); |
||
1239 | char *fun1 = get_string_argument(infile,0); |
||
1240 | if( strlen(fun1) == 0 ){canvas_error("function is NOT OK !");} |
||
1241 | i = 0; |
||
1242 | done = FALSE; |
||
1243 | while( !done ){ |
||
1244 | double_data[i] = get_real(infile,1); |
||
1245 | i++; |
||
1246 | } |
||
1247 | for(c = 0 ; c < i; c++){ |
||
1248 | 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); |
||
1249 | click_cnt++; |
||
1250 | } |
||
1251 | reset(); |
||
1252 | break; |
||
7614 | schaersvoo | 1253 | case CURVE: |
1254 | /* |
||
1255 | @curve color,formula(x) |
||
1256 | @plot color,formula(x) |
||
1257 | @use command trange before command curve / plot (trange -pi,pi)<br />curve color,formula1(t),formula2(t) |
||
1258 | @use command "precision" to increase the number of digits of the plotted points |
||
1259 | @use command "plotsteps" to increase / decrease the amount of plotted points (default 150) |
||
1260 | @may be set draggable / onclick |
||
1261 | */ |
||
1262 | if( use_parametric == TRUE ){ /* parametric color,fun1(t),fun2(t)*/ |
||
1263 | use_parametric = FALSE; |
||
1264 | stroke_color = get_color(infile,0); |
||
1265 | char *fun1 = get_string_argument(infile,0); |
||
1266 | char *fun2 = get_string_argument(infile,1); |
||
1267 | if( strlen(fun1) == 0 || strlen(fun2) == 0 ){canvas_error("parametric functions are NOT OK !");} |
||
7785 | schaersvoo | 1268 | 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 | 1269 | click_cnt++; |
1270 | } |
||
1271 | else |
||
1272 | { |
||
1273 | stroke_color = get_color(infile,0); |
||
1274 | char *fun1 = get_string_argument(infile,1); |
||
1275 | if( strlen(fun1) == 0 ){canvas_error("function is NOT OK !");} |
||
7785 | schaersvoo | 1276 | 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 | 1277 | click_cnt++; |
1278 | } |
||
7788 | schaersvoo | 1279 | animation_type = 9;/* reset to curve plotting without animation */ |
7614 | schaersvoo | 1280 | reset(); |
1281 | break; |
||
1282 | case FLY_TEXT: |
||
1283 | /* |
||
1284 | @ text fontcolor,x,y,font,text_string |
||
1285 | @ font may be described by keywords : giant,huge,normal,small,tiny |
||
1286 | @ use command 'fontsize' to increase base fontsize for the keywords |
||
1287 | @ may be set "onclick" or "drag xy" |
||
1288 | @ backwards compatible with flydraw |
||
1289 | @ unicode supported: text red,0,0,huge,\\u2232 |
||
1290 | @ use command 'string' and 'fontfamily' for a more fine grained control over html5 canvas text element |
||
1291 | @ 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. |
||
1292 | */ |
||
1293 | for(i = 0; i < 5 ;i++){ |
||
1294 | switch(i){ |
||
1295 | case 0: stroke_color = get_color(infile,0);break;/* font_color == stroke_color name or hex color */ |
||
1296 | case 1: double_data[0] = get_real(infile,0);break; /* x */ |
||
1297 | case 2: double_data[1] = get_real(infile,0);break; /* y */ |
||
1298 | case 3: fly_font = get_string_argument(infile,0); |
||
1299 | if(strcmp(fly_font,"giant") == 0){ |
||
1300 | font_size = (int)(font_size + 24); |
||
1301 | } |
||
1302 | else |
||
1303 | { |
||
1304 | if(strcmp(fly_font,"huge") == 0){ |
||
1305 | font_size = (int)(font_size + 14); |
||
1306 | } |
||
1307 | else |
||
1308 | { |
||
1309 | if(strcmp(fly_font,"large") == 0){ |
||
1310 | font_size = (int)(font_size + 6); |
||
1311 | } |
||
1312 | else |
||
1313 | { |
||
1314 | if(strcmp(fly_font,"small") == 0){ |
||
1315 | font_size = (int)(font_size - 4); |
||
1316 | if(font_size<0){font_size = 8;} |
||
1317 | } |
||
1318 | } |
||
1319 | } |
||
1320 | } |
||
1321 | break; /* font_size ! */ |
||
1322 | case 4: |
||
1323 | temp = get_string_argument(infile,1); |
||
1324 | decimals = find_number_of_digits(precision); |
||
7785 | schaersvoo | 1325 | 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 | 1326 | click_cnt++;reset();break; |
1327 | default:break; |
||
1328 | } |
||
1329 | } |
||
1330 | break; |
||
1331 | case FLY_TEXTUP: |
||
1332 | /* |
||
1333 | @ textup fontcolor,x,y,font,text_string |
||
1334 | @ can <b>not</b> be set "onclick" or "drag xy" (because of translaton matrix...mouse incompatible) |
||
1335 | @ font may be described by keywords : giant,huge,normal,small,tiny |
||
1336 | @ use command 'fontsize' to increase base fontsize for the keywords |
||
1337 | @ backwards compatible with flydraw |
||
1338 | @ unicode supported: textup red,0,0,huge,\\u2232 |
||
1339 | @ use command 'stringup' and 'fontfamily' for a more fine grained control over html5 canvas text element |
||
1340 | @ 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. |
||
1341 | */ |
||
1342 | if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;} |
||
1343 | for(i = 0; i<5 ;i++){ |
||
1344 | switch(i){ |
||
1345 | case 0: font_color = get_color(infile,0);break;/* name or hex color */ |
||
1346 | case 1: int_data[0] = x2px(get_real(infile,0));break; /* x */ |
||
1347 | case 2: int_data[1] = y2px(get_real(infile,0));break; /* y */ |
||
1348 | case 3: fly_font = get_string_argument(infile,0); |
||
1349 | if(strcmp(fly_font,"giant") == 0){ |
||
1350 | font_size = (int)(font_size + 24); |
||
1351 | } |
||
1352 | else |
||
1353 | { |
||
1354 | if(strcmp(fly_font,"huge") == 0){ |
||
1355 | font_size = (int)(font_size + 14); |
||
1356 | } |
||
1357 | else |
||
1358 | { |
||
1359 | if(strcmp(fly_font,"large") == 0){ |
||
1360 | font_size = (int)(font_size + 6); |
||
1361 | } |
||
1362 | else |
||
1363 | { |
||
1364 | if(strcmp(fly_font,"small") == 0){ |
||
1365 | font_size = (int)(font_size - 4); |
||
1366 | if(font_size<0){font_size = 8;} |
||
1367 | } |
||
1368 | } |
||
1369 | } |
||
1370 | } |
||
1371 | break; /* font_size ! */ |
||
1372 | case 4: |
||
1373 | decimals = find_number_of_digits(precision); |
||
1374 | temp = get_string_argument(infile,1); |
||
1375 | 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); |
||
1376 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
1377 | 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); |
||
1378 | add_to_buffer(tmp_buffer); |
||
1379 | break; |
||
1380 | default:break; |
||
1381 | } |
||
1382 | } |
||
1383 | reset(); |
||
1384 | break; |
||
1385 | case FONTFAMILY: |
||
1386 | /* |
||
1387 | @ fontfamily font_description |
||
1388 | @ set the font family; for browsers that support it |
||
1389 | @ font_description: Ariel ,Courier, Helvetica etc |
||
1390 | @ 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 |
||
1391 | @ use correct syntax : 'font style' 'font size'px 'fontfamily' |
||
1392 | */ |
||
1393 | font_family = get_string(infile,1); |
||
1394 | break; |
||
1395 | case STRINGUP: |
||
1396 | /* |
||
1397 | @ stringup color,x,y,rotation_degrees,the text string |
||
1398 | @ can <b>not</b> be set "onclick" or "drag xy" (because of translaton matrix...mouse incompatible) |
||
1399 | @ unicode supported: stringup red,0,0,45,\\u2232 |
||
1400 | @ use a command like 'fontfamily bold 34px Courier' <br />to set fonts on browser that support font change |
||
1401 | |||
1402 | */ |
||
1403 | if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;} /* can not be added to shape library : rotate / mouse issues */ |
||
1404 | for(i=0;i<6;i++){ |
||
1405 | switch(i){ |
||
1406 | case 0: font_color = get_color(infile,0);break;/* name or hex color */ |
||
1407 | case 1: int_data[0] = x2px(get_real(infile,0));break; /* x */ |
||
1408 | case 2: int_data[1] = y2px(get_real(infile,0));break; /* y */ |
||
1409 | case 3: double_data[0] = get_real(infile,0);break;/* rotation */ |
||
1410 | case 4: decimals = find_number_of_digits(precision); |
||
1411 | temp = get_string_argument(infile,1); |
||
1412 | 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); |
||
1413 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
1414 | 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); |
||
1415 | add_to_buffer(tmp_buffer); |
||
1416 | break; |
||
1417 | default:break; |
||
1418 | } |
||
1419 | } |
||
1420 | reset(); |
||
1421 | break; |
||
1422 | case STRING: |
||
1423 | /* |
||
1424 | @ string color,x,y,the text string |
||
1425 | @ may be set "onclick" or "drag xy" |
||
1426 | @ unicode supported: string red,0,0,\\u2232 |
||
1427 | @ use a command like 'fontfamily italic 24px Ariel' <br />to set fonts on browser that support font change |
||
1428 | */ |
||
1429 | for(i=0;i<5;i++){ |
||
1430 | switch(i){ |
||
1431 | case 0: stroke_color = get_color(infile,0);break;/* name or hex color */ |
||
1432 | case 1: double_data[0] = get_real(infile,0);break; /* x in xrange*/ |
||
1433 | case 2: double_data[1] = get_real(infile,0);break; /* y in yrange*/ |
||
1434 | case 3: decimals = find_number_of_digits(precision); |
||
1435 | temp = get_string_argument(infile,1); |
||
1436 | decimals = find_number_of_digits(precision); |
||
7785 | schaersvoo | 1437 | 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 | 1438 | click_cnt++;reset();break; |
1439 | break; |
||
1440 | default:break; |
||
1441 | } |
||
1442 | } |
||
1443 | break; |
||
1444 | case MATHML: |
||
1445 | /* |
||
1446 | @ mathml x1,y1,x2,y2,mathml_string |
||
1447 | @ mathml will be displayed in a rectangle left top (x1:y1) , right bottom (x2:y2) |
||
1448 | @ can be set onclick <br />(however dragging is not supported)<br />javascript:read_dragdrop(); will return click number of mathml-object |
||
1449 | @ 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();" |
||
1450 | @ 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.... |
||
7653 | schaersvoo | 1451 | |
7614 | schaersvoo | 1452 | */ |
1453 | if( js_function[DRAW_XML] != 1 ){ js_function[DRAW_XML] = 1;} |
||
1454 | for(i=0;i<5;i++){ |
||
1455 | switch(i){ |
||
1456 | case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */ |
||
1457 | case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system -> pixel height */ |
||
1458 | case 2: int_data[2]=x2px(get_real(infile,0)) - int_data[0];break; /* width in x/y-range coord system -> pixel width */ |
||
1459 | case 3: int_data[3]=y2px(get_real(infile,0)) - int_data[1];break; /* height in x/y-range coord system -> pixel height */ |
||
1460 | case 4: decimals = find_number_of_digits(precision); |
||
1461 | if(onclick == 1 ){ onclick = click_cnt;click_cnt++;} |
||
1462 | temp = get_string(infile,1); |
||
1463 | if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'"); } |
||
1464 | 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); |
||
1465 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
1466 | 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); |
||
1467 | add_to_buffer(tmp_buffer); |
||
1468 | /* |
||
1469 | in case inputs are present , trigger adding the read_mathml() |
||
1470 | if no other reply_format is defined |
||
1471 | note: all other reply types will include a reading of elements with id='mathml'+p) |
||
1472 | */ |
||
1473 | if(strstr(temp,"mathml0") != NULL){ |
||
1474 | if(reply_format < 1 ){reply_format = 16;} /* no other reply type is defined */ |
||
1475 | } |
||
1476 | break; |
||
1477 | default:break; |
||
1478 | } |
||
1479 | } |
||
1480 | reset(); |
||
1481 | break; |
||
1482 | case HTTP: |
||
1483 | /* |
||
1484 | @http x1,y1,x2,y2,http://some_adress.com |
||
1485 | @an active html-page will be displayed in an "iframe" rectangle left top (x1:y1) , right bottom (x2:y2) |
||
1486 | @do not use interactivity (or mouse) if the mouse needs to be active in the iframe |
||
1487 | @can not be 'set onclick' or 'drag xy' |
||
1488 | */ |
||
1489 | if( js_function[DRAW_HTTP] != 1 ){ js_function[DRAW_HTTP] = 1;} |
||
1490 | for(i=0;i<5;i++){ |
||
1491 | switch(i){ |
||
1492 | case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */ |
||
1493 | case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system -> pixel height */ |
||
1494 | case 2: int_data[2]=x2px(get_real(infile,0)) - int_data[0];break; /* width in x/y-range coord system -> pixel width */ |
||
1495 | case 3: int_data[3]=y2px(get_real(infile,0)) - int_data[1];break; /* height in x/y-range coord system -> pixel height */ |
||
1496 | case 4: decimals = find_number_of_digits(precision); |
||
1497 | temp = get_string(infile,1); |
||
1498 | if(strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'");} |
||
1499 | 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); |
||
1500 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
1501 | 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); |
||
1502 | add_to_buffer(tmp_buffer); |
||
1503 | break; |
||
1504 | } |
||
1505 | } |
||
1506 | reset(); |
||
1507 | break; |
||
1508 | case HTML: |
||
1509 | /* |
||
1510 | @ html x1,y1,x2,y2,html_string |
||
1511 | @ all tags are allowed |
||
1512 | @ can be set onclick <br />(dragging not supported)<br />javascript:read_dragdrop(); will return click number of mathml-object |
||
1513 | @ 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. |
||
1514 | |||
1515 | note: uses the same code as 'mathml' |
||
1516 | */ |
||
1517 | break; |
||
1518 | case X_AXIS_STRINGS: |
||
1519 | /* |
||
1520 | @ xaxis num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n |
||
1521 | @ xaxistext num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n |
||
1522 | @ use these x-axis values in stead of default xmin...xmax |
||
1523 | @ use command "fontcolor", "fontsize" , "fontfamily" to adjust font <br />defaults: black,12,Ariel |
||
1524 | @ if the 'x-axis words' are to big amd will overlap, a simple alternating offset will be applied |
||
1525 | @ 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 |
||
1526 | @ 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 |
||
1527 | */ |
||
1528 | temp = get_string(infile,1); |
||
1529 | if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");} |
||
1530 | if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/ |
||
1531 | fprintf(js_include_file,"x_strings = [\"%s\"];\n ",temp); |
||
1532 | use_axis_numbering = 1; |
||
1533 | break; |
||
1534 | case Y_AXIS_STRINGS: |
||
1535 | /* |
||
1536 | @ yaxis num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n |
||
1537 | @ yaxistext num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n |
||
1538 | @ use command "fontcolor", "fontsize" , "fontfamily" to adjust font <br />defaults: black,12,Ariel |
||
1539 | @ use these y-axis values in stead of default ymin...ymax |
||
1540 | @ 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 |
||
1541 | */ |
||
1542 | temp = get_string(infile,1); |
||
1543 | if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");} |
||
1544 | if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/ |
||
1545 | fprintf(js_include_file,"y_strings = [\"%s\"];\n ",temp); |
||
1546 | use_axis_numbering = 1; |
||
1547 | break; |
||
1548 | |||
1549 | case AXIS_NUMBERING: |
||
1550 | /* |
||
1551 | @ axisnumbering |
||
1552 | @ keyword, no aguments required |
||
1553 | */ |
||
1554 | use_axis_numbering = 1; |
||
1555 | break; |
||
1556 | case AXIS: |
||
1557 | /* |
||
1558 | @ axis |
||
1559 | @ keyword, no aguments required |
||
1560 | |||
1561 | */ |
||
1562 | use_axis = TRUE; |
||
1563 | break; |
||
7654 | schaersvoo | 1564 | case SGRAPH: |
1565 | /* |
||
1566 | @ sgraph xstart,ystart,xmajor,ymajor,xminor,yminor,majorgrid_color,minorgrid_color |
||
1567 | @ primitive implementation of a 'broken scale' graph... |
||
1568 | @ not very versatile. |
||
1569 | @ 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 |
||
1570 | */ |
||
1571 | if( js_function[DRAW_SGRAPH] != 1 ){ js_function[DRAW_SGRAPH] = 1;} |
||
1572 | for(i = 0 ; i < 8 ;i++){ |
||
1573 | switch(i){ |
||
1574 | case 0:double_data[0] = get_real(infile,0);break; |
||
1575 | case 1:double_data[1] = get_real(infile,0);break; |
||
1576 | case 2:double_data[2] = get_real(infile,0);break; |
||
1577 | case 3:double_data[3] = get_real(infile,0);break; |
||
1578 | case 4:int_data[0] = (int)(get_real(infile,0));break; |
||
1579 | case 5:int_data[1] = (int)(get_real(infile,0));break; |
||
1580 | case 6:stroke_color = get_color(infile,0);break; |
||
1581 | case 7:font_color = get_color(infile,1); |
||
7658 | schaersvoo | 1582 | 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 | 1583 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
7658 | schaersvoo | 1584 | 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 | 1585 | add_to_buffer(tmp_buffer); |
1586 | break; |
||
1587 | default:break; |
||
1588 | } |
||
1589 | } |
||
1590 | /* sgraph(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily,opacity)*/ |
||
1591 | break; |
||
7614 | schaersvoo | 1592 | case GRID:/* xmajor,ymajor,color [,xminor,yminor,tick length (px) ,color]*/ |
1593 | /* |
||
1594 | @ grid step_x,step_y,gridcolor |
||
1595 | @ use command "fontcolor", "fontsize" , "fontfamily" to adjust font <br />defaults: black,12,Ariel |
||
1596 | @ 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 | 1597 | @ 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 | 1598 | @ can not be set "onclick" or "drag xy" |
1599 | @ 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') |
||
1600 | @ 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') |
||
1601 | @ 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') |
||
1602 | */ |
||
7729 | schaersvoo | 1603 | if( js_function[DRAW_YLOGSCALE] == 1 ){canvas_error("only one grid type is allowed...");} |
7614 | schaersvoo | 1604 | if( js_function[DRAW_GRID] != 1 ){ js_function[DRAW_GRID] = 1;} |
1605 | for(i=0;i<4;i++){ |
||
1606 | switch(i){ |
||
1607 | case 0:double_data[0] = get_real(infile,0);break;/* xmajor */ |
||
1608 | case 1:double_data[1] = get_real(infile,0);break;/* ymajor */ |
||
1609 | case 2: |
||
1610 | if( use_axis == TRUE ){ |
||
1611 | stroke_color = get_color(infile,0); |
||
1612 | done = FALSE; |
||
1613 | int_data[0] = (int) (get_real(infile,0));/* xminor */ |
||
1614 | int_data[1] = (int) (get_real(infile,0));/* yminor */ |
||
1615 | int_data[2] = (int) (get_real(infile,0));/* tic_length */ |
||
1616 | fill_color = get_color(infile,1); /* used as axis_color*/ |
||
1617 | } |
||
1618 | else |
||
1619 | { |
||
1620 | int_data[0] = 1; |
||
1621 | int_data[1] = 1; |
||
1622 | stroke_color = get_color(infile,1); |
||
1623 | fill_color = stroke_color; |
||
1624 | } |
||
1625 | 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 | 1626 | /* set snap_x snap_y values in pixels */ |
7647 | schaersvoo | 1627 | 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 | 1628 | /* 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){ */ |
1629 | |||
1630 | 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); |
||
1631 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
1632 | 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); |
||
1633 | add_to_buffer(tmp_buffer); |
||
1634 | break; |
||
1635 | } |
||
1636 | } |
||
1637 | reset(); |
||
1638 | break; |
||
1639 | case OPACITY: |
||
1640 | /* |
||
1641 | @ opacity 0-255,0-255 |
||
1642 | @ |
||
1643 | */ |
||
1644 | for(i = 0 ; i<2;i++){ |
||
1645 | switch(i){ |
||
1646 | case 0: double_data[0]=(int)(get_real(infile,0));break; |
||
1647 | case 1: double_data[1]=(int)(get_real(infile,1));break; |
||
1648 | default: break; |
||
1649 | } |
||
1650 | } |
||
1651 | 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 ? */ |
||
1652 | stroke_opacity = (double) (0.0039215*double_data[0]);/* 0.0 - 1.0 */ |
||
1653 | fill_opacity = (double) (0.0039215*double_data[1]);/* 0.0 - 1.0 */ |
||
1654 | break; |
||
1655 | case ROTATE: |
||
1656 | /* |
||
1657 | @rotate rotation_angle |
||
1658 | @ |
||
1659 | */ |
||
1660 | use_rotate = TRUE; |
||
1661 | use_translate = TRUE; |
||
1662 | translate_x = x2px(0); |
||
1663 | translate_y = y2px(0); |
||
1664 | angle = get_real(infile,1); |
||
1665 | break; |
||
7785 | schaersvoo | 1666 | case KILLAFFINE: |
1667 | /* |
||
1668 | @ killaffine |
||
1669 | @ keyword : resets the transformation matrix to 1,0,0,1,0,0 |
||
1670 | */ |
||
1671 | use_affine = FALSE; |
||
1672 | snprintf(affine_matrix,14,"[1,0,0,1,0,0]"); |
||
1673 | break; |
||
1674 | case AFFINE: |
||
1675 | /* |
||
1676 | @affine a,b,c,d,tx,ty |
||
1677 | @ defines a transformation matrix for subsequent objects |
||
1678 | @ use keyword 'killaffine' to end the transformation |
||
1679 | @ note 1: only 'draggable' / 'noclick' objects can be transformed. |
||
1680 | @ note 2: do not use 'onclick' or 'drag xy' with tranformation objects : the mouse coordinates do not get transformed (yet) |
||
1681 | @ note 3: no matrix operations on the transformation matrix implemented (yet) |
||
1682 | @ a : Scales the drawings horizontally |
||
1683 | @ b : Skews the drawings horizontally |
||
1684 | @ c : Skews the drawings vertically |
||
1685 | @ d : Scales the drawings vertically |
||
7786 | schaersvoo | 1686 | @ tx: Moves the drawings horizontally in pixels ! |
1687 | @ ty: Moves the drawings vertically in pixels ! |
||
7785 | schaersvoo | 1688 | */ |
1689 | for(i = 0 ; i<6;i++){ |
||
1690 | switch(i){ |
||
1691 | case 0: double_data[0] = get_real(infile,0);break; |
||
1692 | case 1: double_data[1] = get_real(infile,0);break; |
||
1693 | case 2: double_data[2] = get_real(infile,0);break; |
||
1694 | case 3: double_data[3] = get_real(infile,0);break; |
||
1695 | case 4: int_data[0] = (int)(get_real(infile,0));break; |
||
1696 | case 5: int_data[1] = (int)(get_real(infile,1)); |
||
1697 | use_affine = TRUE; |
||
1698 | 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]); |
||
1699 | check_string_length(string_length);affine_matrix = my_newmem(string_length+1); |
||
1700 | 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]); |
||
1701 | break; |
||
1702 | default: break; |
||
1703 | } |
||
1704 | } |
||
1705 | break; |
||
7614 | schaersvoo | 1706 | case KILLTRANSLATION: |
1707 | /* |
||
1708 | killtranslation |
||
1709 | */ |
||
1710 | break; |
||
1711 | case TRANSLATION: |
||
1712 | /* |
||
1713 | @translation tx,ty |
||
1714 | @ |
||
1715 | */ |
||
1716 | use_translate = TRUE; |
||
1717 | translate_x = get_real(infile,0); |
||
1718 | translate_y = get_real(infile,1); |
||
1719 | break; |
||
1720 | case DASHED: |
||
1721 | /* |
||
1722 | @ keyword "dashed" |
||
1723 | @ next object will be drawn with a dashed line |
||
1724 | @ change dashing scheme by using command "dashtype int,int) |
||
1725 | */ |
||
1726 | use_dashed = TRUE; |
||
1727 | break; |
||
1728 | case FILLED: |
||
1729 | /* |
||
1730 | @ keyword "filled" |
||
1731 | @ the next 'fillable' object (only) will be filled |
||
1732 | @ use command "fillcolor color" to set fillcolor |
||
1733 | @ use command "opacity 0-255,0-255" to set stroke and fill-opacity |
||
1734 | @ 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 ! |
||
1735 | */ |
||
1736 | use_filled = TRUE; |
||
1737 | break; |
||
1738 | case STYLE: |
||
1739 | /* |
||
1740 | @highlight color,opacity,linewidth |
||
1741 | @ NOT IMPLEMENTED |
||
1742 | @ use command "onclick" : when the object receives a userclick it will increase it's linewidth |
||
1743 | */ |
||
1744 | break; |
||
1745 | case FILLCOLOR: |
||
1746 | /* |
||
1747 | @ fillcolor colorname or #hex |
||
1748 | @ Set the color for a filled object : mainly used for command 'userdraw obj,stroke_color' |
||
1749 | @ All fillable massive object will have a fillcolor == strokecolor (just to be compatible with flydraw...) |
||
1750 | */ |
||
1751 | fill_color = get_color(infile,1); |
||
1752 | break; |
||
1753 | case STROKECOLOR: |
||
1754 | /* |
||
1755 | @ strokecolor colorname or #hex |
||
1756 | @ to be used for commands that do not supply a color argument (like command 'linegraph') |
||
1757 | */ |
||
1758 | stroke_color = get_color(infile,1); |
||
1759 | break; |
||
1760 | case BGIMAGE: |
||
1761 | /* |
||
1762 | @bgimage image_location |
||
1763 | @use an image as background .<br />(we use the background of 'canvas_div' ) |
||
1764 | @the background image will be resized to match "width = xsize" and "height = ysize" |
||
1765 | */ |
||
1766 | URL = get_string(infile,1); |
||
1767 | 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); |
||
1768 | break; |
||
1769 | case BGCOLOR: |
||
1770 | /* |
||
1771 | @bgcolor colorname or #hex |
||
1772 | @use this color as background of the "div" containing the canvas(es) |
||
1773 | */ |
||
1774 | /* [255,255,255]*/ |
||
1775 | bgcolor = get_string(infile,1); |
||
1776 | if(strstr(bgcolor,"#") == NULL){ /* convert colorname -> #ff00ff */ |
||
1777 | int found = 0; |
||
1778 | for( i = 0; i < NUMBER_OF_COLORNAMES ; i++ ){ |
||
1779 | if( strcmp( colors[i].name , bgcolor ) == 0 ){ |
||
1780 | bgcolor = colors[i].hex; |
||
1781 | found = 1; |
||
1782 | break; |
||
1783 | } |
||
1784 | } |
||
1785 | if(found == 0){canvas_error("your bgcolor is not in my rgb.txt data list : use hexcolor...something like #a0ffc4");} |
||
1786 | } |
||
1787 | fprintf(js_include_file,"<!-- set background color of canvas div -->\ncanvas_div.style.backgroundColor = \"%s\";canvas_div.style.opacity = %f;\n",bgcolor,fill_opacity); |
||
1788 | break; |
||
1789 | case COPY: |
||
1790 | /* |
||
1791 | @ copy x,y,x1,y1,x2,y2,[filename URL] |
||
1792 | @ Insert the region from (x1,y1) to (x2,y2) (in pixels) of [filename] to (x,y) in x/y-range |
||
1793 | @ If x1=y1=x2=y2=-1, the whole [filename URL] is copied. |
||
1794 | @ [filename] is the URL of the image |
||
1795 | @ URL is normal URL of network reachable image file location<br />(eg special url for 'classexo' not -yet- implemented) |
||
1796 | @ 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 |
||
1797 | @ if you want to draw / userdraw on an "imported" image, make sure it is transparent.<br />for example GNUPlot: set terminal gif transparent |
||
1798 | |||
1799 | context.drawImage(img,sx,sy,swidth,sheight,x,y,width,height); |
||
1800 | draw_external_image(canvas_type,URL,sx,sy,swidth,sheight,x,y,width,height,drag_drop){ |
||
1801 | */ |
||
1802 | for(i = 0 ; i<7;i++){ |
||
1803 | switch(i){ |
||
1804 | case 0: int_data[0]=x2px(get_real(infile,0));break; /* x left top corner in x/y range */ |
||
1805 | case 1: int_data[1]=y2px(get_real(infile,0));break; /* y left top corner in x/y range */ |
||
1806 | case 2: int_data[2]=(int)(get_real(infile,0));break;/* x1 in px of external image */ |
||
1807 | case 3: int_data[3]=(int)(get_real(infile,0));break;/* y1 in px of external image */ |
||
1808 | case 4: int_data[4]=(int)(get_real(infile,0));break;/* x2 --> width */ |
||
1809 | case 5: int_data[5]=(int)(get_real(infile,0)) ;break;/* y2 --> height */ |
||
1810 | case 6: URL = get_string(infile,1); |
||
1811 | int_data[6] = int_data[4] - int_data[2];/* swidth & width (if not scaling )*/ |
||
1812 | int_data[7] = int_data[5] - int_data[3];/* sheight & height (if not scaling )*/ |
||
1813 | if( drag_type > -1 ){ |
||
1814 | if( js_function[DRAG_EXTERNAL_IMAGE] != 1 ){ js_function[DRAG_EXTERNAL_IMAGE] = 1;} |
||
1815 | if(reply_format < 1 ){reply_format = 20;} |
||
1816 | 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); |
||
1817 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
1818 | 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); |
||
1819 | drag_type = -1; |
||
1820 | ext_img_cnt++; |
||
1821 | } |
||
1822 | else |
||
1823 | { |
||
1824 | if( js_function[DRAW_EXTERNAL_IMAGE] != 1 ){ js_function[DRAW_EXTERNAL_IMAGE] = 1;} |
||
1825 | /* |
||
1826 | draw_external_image = function(URL,sx,sy,swidth,sheight,x0,y0,width,height,draggable){\n\ |
||
1827 | */ |
||
1828 | 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]); |
||
1829 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
1830 | 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]); |
||
1831 | } |
||
1832 | add_to_buffer(tmp_buffer); |
||
1833 | break; |
||
1834 | default: break; |
||
1835 | } |
||
1836 | } |
||
1837 | reset(); |
||
1838 | break; |
||
1839 | /* |
||
1840 | context.drawImage(img,sx,sy,swidth,sheight,x,y,width,height); |
||
1841 | img Specifies the image, canvas, or video element to use |
||
1842 | sx The x coordinate where to start clipping : x1 = int_data[0] |
||
1843 | sy The y coordinate where to start clipping : x2 = int_data[1] |
||
1844 | swidth The width of the clipped image : int_data[2] - int_data[0] |
||
1845 | sheight The height of the clipped image : int_data[3] - int_data[1] |
||
1846 | x The x coordinate where to place the image on the canvas : dx1 = int_data[4] |
||
1847 | y The y coordinate where to place the image on the canvas : dy1 = int_data[5] |
||
1848 | width The width of the image to use (stretch or reduce the image) : dx2 - dx1 = int_data[6] |
||
1849 | height The height of the image to use (stretch or reduce the image) : dy2 - dy1 = int_data[7] |
||
1850 | */ |
||
1851 | case COPYRESIZED: |
||
1852 | /* |
||
1853 | @ copyresized x1,y2,x2,y2,dx1,dy1,dx2,dy2,image_file_url |
||
1854 | @ 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 |
||
1855 | @ If x1=y1=x2=y2=-1, the whole [filename / URL ] is copied and resized. |
||
1856 | @ URL is normal URL of network reachable image file location<br />(eg special url for 'classexo' not -yet- implemented) |
||
1857 | @ 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 |
||
1858 | @ if you want to draw / userdraw on an "imported" image, make sure it is transparent.<br />for example GNUPlot: set terminal gif transparent |
||
1859 | */ |
||
1860 | for(i = 0 ; i<9;i++){ |
||
1861 | switch(i){ |
||
1862 | case 0: int_data[0] = (int)(get_real(infile,0));break; /* x1 */ |
||
1863 | case 1: int_data[1] = (int)(get_real(infile,0));break; /* y1 */ |
||
1864 | case 2: int_data[2] = (int)(get_real(infile,0));break;/* x2 */ |
||
1865 | case 3: int_data[3] = (int)(get_real(infile,0));break;/* y2 */ |
||
1866 | case 4: int_data[4] = x2px(get_real(infile,0));break;/* dx1 */ |
||
1867 | case 5: int_data[5] = y2px(get_real(infile,0));break;/* dy1 */ |
||
1868 | case 6: int_data[6] = x2px(get_real(infile,0));break;/* dx2 */ |
||
1869 | case 7: int_data[7] = y2px(get_real(infile,0));break;/* dy2 */ |
||
1870 | case 8: URL = get_string(infile,1); |
||
1871 | if( drag_type > -1 ){ |
||
1872 | if( js_function[DRAG_EXTERNAL_IMAGE] != 1 ){ js_function[DRAG_EXTERNAL_IMAGE] = 1;} |
||
1873 | if(reply_format < 1 ){reply_format = 20;} |
||
1874 | 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); |
||
1875 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
1876 | 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); |
||
1877 | drag_type = -1; |
||
1878 | ext_img_cnt++; |
||
1879 | } |
||
1880 | else |
||
1881 | { |
||
1882 | if( js_function[DRAW_EXTERNAL_IMAGE] != 1 ){ js_function[DRAW_EXTERNAL_IMAGE] = 1;} |
||
1883 | 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]); |
||
1884 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
1885 | 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]); |
||
1886 | } |
||
1887 | add_to_buffer(tmp_buffer); |
||
1888 | default: break; |
||
1889 | } |
||
1890 | } |
||
1891 | reset(); |
||
1892 | break; |
||
1893 | case BUTTON: |
||
1894 | /* |
||
1895 | button x,y,value |
||
1896 | */ |
||
1897 | break; |
||
1898 | case INPUTSTYLE: |
||
1899 | /* |
||
1900 | @ inputstyle style_description |
||
1901 | @ example: inputstyle color:blue;font-weight:bold;font-style:italic;font-size:16pt |
||
1902 | */ |
||
1903 | input_style = get_string(infile,1); |
||
1904 | break; |
||
1905 | case INPUT: |
||
1906 | /* |
||
1907 | @ input x,y,size,editable,value |
||
1908 | @ to set inputfield "readonly", use editable = 0 |
||
1909 | @ only active inputfields (editable = 1) will be read with read_canvas(); |
||
1910 | @ may be further controlled by "inputstyle" (inputcss is not yet implemented...) |
||
1911 | @ if mathml inputfields are present and / or some userdraw is performed, these data will NOT be send as well (javascript:read_canvas();) |
||
1912 | */ |
||
1913 | if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;} |
||
1914 | for(i = 0 ; i<5;i++){ |
||
1915 | switch(i){ |
||
1916 | case 0: int_data[0]=x2px(get_real(infile,0));break;/* x in px */ |
||
1917 | case 1: int_data[1]=y2px(get_real(infile,0));break;/* y in px */ |
||
1918 | case 2: int_data[2]=abs( (int)(get_real(infile,0)));break; /* size */ |
||
1919 | case 3: if( get_real(infile,1) >0){int_data[3] = 1;}else{int_data[3] = 0;};break; /* readonly */ |
||
1920 | case 4: |
||
1921 | temp = get_string_argument(infile,1); |
||
1922 | 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); |
||
1923 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
1924 | 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); |
||
1925 | add_to_buffer(tmp_buffer); |
||
1926 | input_cnt++;break; |
||
1927 | default: break; |
||
1928 | } |
||
1929 | } |
||
1930 | if(reply_format < 1 ){reply_format = 15;} |
||
1931 | reset(); |
||
1932 | break; |
||
1933 | case TEXTAREA: |
||
1934 | /* |
||
1935 | @ textarea x,y,cols,rows,readonly,value |
||
1936 | @ may be further controlled by "inputstyle" |
||
1937 | @ if mathml inputfields are present and / or some userdraw is performed, these data will NOT be send as well (javascript:read_canvas();) |
||
1938 | */ |
||
1939 | if( js_function[DRAW_TEXTAREAS] != 1 ){ js_function[DRAW_TEXTAREAS] = 1;} |
||
1940 | for(i = 0 ; i<6;i++){ |
||
1941 | switch(i){ |
||
1942 | case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in px */ |
||
1943 | case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in px */ |
||
1944 | case 2: int_data[2]=abs( (int)(get_real(infile,0)));break;/* cols */ |
||
1945 | case 3: int_data[3]=abs( (int)(get_real(infile,0)));break;/* rows */ |
||
1946 | case 4: if( get_real(infile,1) >0){int_data[4] = 1;}else{int_data[3] = 0;};break; /* readonly */ |
||
1947 | case 5: temp = get_string_argument(infile,1); |
||
1948 | 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); |
||
1949 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
1950 | 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); |
||
1951 | add_to_buffer(tmp_buffer); |
||
1952 | input_cnt++;break; |
||
1953 | default: break; |
||
1954 | } |
||
1955 | } |
||
1956 | if(reply_format < 1 ){reply_format = 15;} |
||
1957 | reset(); |
||
1958 | break; |
||
1959 | case MOUSE_PRECISION: |
||
1960 | /* |
||
1961 | @ precision int |
||
1962 | @ 10 = 1 decimal ; 100 = 2 decimals etc |
||
1963 | @ may be used / changed before every object |
||
1964 | */ |
||
1965 | precision = (int) (get_real(infile,1)); |
||
1966 | break; |
||
1967 | case ZOOM: |
||
1968 | /* |
||
1969 | @ zoom button_color |
||
1970 | @ introduce a controlpanel at the lower right corner |
||
1971 | @ 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 |
||
1972 | @ the 'x' symbol will do a 'location.reload' of the page, and thus reset all canvas drawings. |
||
1973 | @ choose an appropriate colour, so the small 'x,arrows,-,+' are clearly visible |
||
1974 | @ command 'opacity' may be used to set stroke_opacity of 'buttons |
||
1975 | @ NOTE: only objects that may be set draggable / clickable will be zoomed / panned |
||
1976 | @ 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 !! |
||
1977 | */ |
||
7653 | schaersvoo | 1978 | fprintf(js_include_file,"use_pan_and_zoom = 1;"); |
7614 | schaersvoo | 1979 | if( js_function[DRAW_ZOOM_BUTTONS] != 1 ){ js_function[DRAW_ZOOM_BUTTONS] = 1;} |
1980 | /* we use BG_CANVAS (0) */ |
||
1981 | stroke_color = get_color(infile,1); |
||
7653 | schaersvoo | 1982 | string_length = snprintf(NULL,0," draw_zoom_buttons(%d,\"%s\",%f);",BG_CANVAS,stroke_color,stroke_opacity); |
7614 | schaersvoo | 1983 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
7653 | schaersvoo | 1984 | snprintf(tmp_buffer,MAX_BUFFER-1,"draw_zoom_buttons(%d,\"%s\",%f);",BG_CANVAS,stroke_color,stroke_opacity); |
7614 | schaersvoo | 1985 | add_to_buffer(tmp_buffer); |
1986 | done = TRUE; |
||
1987 | break; |
||
1988 | case ONCLICK: |
||
1989 | /* |
||
1990 | @ onclick |
||
1991 | @ keyword, no arguments |
||
1992 | @ if the next object is clicked, it's 'object sequence number' in fly script is returned <br /> by javascript:read_canvas(); |
||
1993 | @ Line based object will show an increase in linewidth<br />Font based objects will show the text in 'bold' when clicked. |
||
1994 | @ NOTE: not all objects may be set clickable |
||
1995 | */ |
||
1996 | |||
1997 | onclick = 1; |
||
1998 | break; |
||
1999 | case DRAG: |
||
2000 | /* |
||
2001 | @ drag [x][y][xy] |
||
2002 | @ the next object will be draggable in x / y / xy direction |
||
2003 | @ the displacement can be read by 'javascript:read_dragdrop();' |
||
2004 | @ 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. |
||
2005 | @ 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 !! |
||
2006 | */ |
||
2007 | temp = get_string(infile,1); |
||
2008 | if(strstr(temp,"xy") != NULL ){ |
||
2009 | drag_type = 0; |
||
2010 | } |
||
2011 | else |
||
2012 | { |
||
2013 | if(strstr(temp,"x") != NULL ){ |
||
2014 | drag_type = 1; |
||
2015 | } |
||
2016 | else |
||
2017 | { |
||
2018 | drag_type = 2; |
||
2019 | } |
||
2020 | } |
||
2021 | onclick = 2; |
||
2022 | /* if(use_userdraw == TRUE ){canvas_error("\"drag & drop\" may not be combined with \"userdraw\" or \"pan and zoom\" \n");} */ |
||
2023 | break; |
||
2024 | case BLINK: |
||
2025 | /* |
||
2026 | @ blink time(seconds) |
||
2027 | @ NOT IMPLEMETED -YET |
||
2028 | */ |
||
2029 | break; |
||
2030 | case MOUSE: |
||
2031 | /* |
||
2032 | @ mouse color,fontsize |
||
2033 | @ will display the cursor coordinates in 'color' and 'font size'<br /> using default fontfamily Ariel |
||
2034 | */ |
||
2035 | use_mouse_coordinates = TRUE; /* will add & call function "use_mouse_coordinates(){}" in current_canvas /current_context */ |
||
2036 | stroke_color = get_color(infile,0); |
||
2037 | font_size = (int) (get_real(infile,1)); |
||
2038 | add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity); |
||
2039 | break; |
||
2040 | case INTOOLTIP: |
||
2041 | /* |
||
2042 | @ intooltip link_text |
||
2043 | @ link_text is a single line (span-element) |
||
2044 | @ link_text may also be an image URL http://some_server/images/my_image.png |
||
2045 | @ link_text may contain HTML markup |
||
2046 | @ the canvas will be displayed in a tooltip on 'link_text' |
||
2047 | @ the canvas is default transparent: use command 'bgcolor color' to adjust background-color<br />the link test will alos be shown with this bgcolor. |
||
2048 | */ |
||
7652 | schaersvoo | 2049 | if(use_input_xy == TRUE){canvas_error("intooltip can not be combined with userinput_xy command");} |
7614 | schaersvoo | 2050 | use_tooltip = TRUE; |
2051 | tooltip_text = get_string(infile,1); |
||
2052 | if(strstr(tooltip_text,"\"") != 0 ){ tooltip_text = str_replace(tooltip_text,"\"","'"); } |
||
2053 | break; |
||
2054 | case AUDIO: |
||
2055 | /* |
||
2056 | @ audio x,y,w,h,loop,visible,audiofile location |
||
2057 | @ x,y : left top corner of audio element (in xrange / yrange) |
||
2058 | @ w,y : width and height in pixels |
||
2059 | @ loop : 0 or 1 ( 1 = loop audio fragment) |
||
2060 | @ visible : 0 or 1 (1 = show controls) |
||
2061 | @ audio format may be in *.mp3 or *.ogg |
||
2062 | @ If you are using *.mp3 : be aware that FireFox will not (never) play this ! (Pattented format) |
||
2063 | @ if you are using *.ogg : be aware that Microsoft based systems not support it natively |
||
2064 | @ To avoid problems supply both types (mp3 and ogg) of audiofiles.<br />the program will use both as source tag |
||
2065 | @ 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 /> |
||
2066 | */ |
||
2067 | if( js_function[DRAW_AUDIO] != 1 ){ js_function[DRAW_AUDIO] = 1;} |
||
2068 | for(i=0;i<7;i++){ |
||
2069 | switch(i){ |
||
2070 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */ |
||
2071 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system -> pixel */ |
||
2072 | case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */ |
||
2073 | case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */ |
||
2074 | case 4: int_data[4] = (int) (get_real(infile,0)); if(int_data[4] != TRUE){int_data[4] = FALSE;} break; /* loop boolean */ |
||
2075 | case 5: int_data[5] = (int) (get_real(infile,0)); if(int_data[5] != TRUE){int_data[5] = FALSE;} break; /* visible boolean */ |
||
2076 | case 6: |
||
2077 | temp = get_string(infile,1); |
||
2078 | if( strstr(temp,".mp3") != 0 ){ temp = str_replace(temp,".mp3","");} |
||
2079 | if( strstr(temp,".ogg") != 0 ){ temp = str_replace(temp,".ogg","");} |
||
2080 | 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); |
||
2081 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
2082 | 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); |
||
2083 | add_to_buffer(tmp_buffer); |
||
2084 | break; |
||
2085 | default:break; |
||
2086 | } |
||
2087 | } |
||
2088 | reset(); |
||
2089 | break; |
||
2090 | case VIDEO: |
||
2091 | /* |
||
2092 | @ video x,y,w,h,videofile location |
||
2093 | @ x,y : left top corner of audio element (in xrange / yrange) |
||
2094 | @ w,y : width and height in pixels |
||
2095 | @ example:<br />wims getfile : video 0,0,120,120,myvideo.mp4 |
||
2096 | @ video format may be in *.mp4 (todo:other formats) |
||
2097 | */ |
||
2098 | if( js_function[DRAW_VIDEO] != 1 ){ js_function[DRAW_VIDEO] = 1;} |
||
2099 | for(i=0;i<5;i++){ |
||
2100 | switch(i){ |
||
2101 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */ |
||
2102 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system -> pixel */ |
||
2103 | case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */ |
||
2104 | case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */ |
||
2105 | case 4: temp = get_string(infile,1); |
||
2106 | 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); |
||
2107 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
2108 | 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); |
||
2109 | add_to_buffer(tmp_buffer); |
||
2110 | break; |
||
2111 | default:break; |
||
2112 | } |
||
2113 | } |
||
2114 | reset(); |
||
2115 | break; |
||
2116 | case HATCHFILL: |
||
2117 | /* |
||
2118 | @ hatchfill x0,y0,dx,dy,color |
||
2119 | @ x0,y0 in xrange / yrange |
||
2120 | @ distances dx,dy in pixels |
||
2121 | */ |
||
2122 | if( js_function[DRAW_HATCHFILL] != 1 ){ js_function[DRAW_HATCHFILL] = 1;} |
||
2123 | for(i=0;i<5;i++){ |
||
2124 | switch(i){ |
||
2125 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */ |
||
2126 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y */ |
||
2127 | case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */ |
||
2128 | case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/ |
||
2129 | case 4: stroke_color = get_color(infile,1); |
||
2130 | /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */ |
||
2131 | 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); |
||
2132 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
2133 | 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); |
||
2134 | add_to_buffer(tmp_buffer); |
||
2135 | break; |
||
2136 | default:break; |
||
2137 | } |
||
2138 | } |
||
2139 | reset(); |
||
2140 | break; |
||
7647 | schaersvoo | 2141 | case DIAMONDFILL: |
2142 | /* |
||
2143 | @ diamondfill x0,y0,dx,dy,color |
||
2144 | @ x0,y0 in xrange / yrange |
||
2145 | @ distances dx,dy in pixels |
||
2146 | */ |
||
2147 | if( js_function[DRAW_DIAMONDFILL] != 1 ){ js_function[DRAW_DIAMONDFILL] = 1;} |
||
2148 | for(i=0;i<5;i++){ |
||
2149 | switch(i){ |
||
2150 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */ |
||
2151 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y */ |
||
2152 | case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */ |
||
2153 | case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/ |
||
2154 | case 4: stroke_color = get_color(infile,1); |
||
2155 | /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */ |
||
2156 | 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); |
||
2157 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
2158 | 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); |
||
2159 | add_to_buffer(tmp_buffer); |
||
2160 | break; |
||
2161 | default:break; |
||
2162 | } |
||
2163 | } |
||
2164 | reset(); |
||
2165 | break; |
||
7614 | schaersvoo | 2166 | case GRIDFILL: |
2167 | /* |
||
2168 | @ gridfill x0,y0,dx,dy,color |
||
2169 | @ x0,y0 in xrange / yrange |
||
2170 | @ distances dx,dy in pixels |
||
2171 | */ |
||
2172 | if( js_function[DRAW_GRIDFILL] != 1 ){ js_function[DRAW_GRIDFILL] = 1;} |
||
2173 | for(i=0;i<5;i++){ |
||
2174 | switch(i){ |
||
2175 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */ |
||
2176 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y */ |
||
2177 | case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */ |
||
2178 | case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/ |
||
2179 | case 4: stroke_color = get_color(infile,1); |
||
2180 | /* draw_gridfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */ |
||
2181 | 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); |
||
2182 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
2183 | 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); |
||
2184 | add_to_buffer(tmp_buffer); |
||
2185 | break; |
||
2186 | default:break; |
||
2187 | } |
||
2188 | } |
||
2189 | reset(); |
||
2190 | break; |
||
2191 | case DOTFILL: |
||
2192 | /* |
||
2193 | @ dotfill x0,y0,dx,dy,color |
||
2194 | @ x0,y0 in xrange / yrange |
||
2195 | @ distances dx,dy in pixels |
||
2196 | @ radius of dots is linewidth |
||
2197 | */ |
||
2198 | if( js_function[DRAW_DOTFILL] != 1 ){ js_function[DRAW_DOTFILL] = 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_dotfill(ctx,x0,y0,dx,dy,radius,color,opacity,xsize,ysize) */ |
||
2207 | 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); |
||
2208 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
2209 | 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); |
||
2210 | add_to_buffer(tmp_buffer); |
||
2211 | break; |
||
2212 | default:break; |
||
2213 | } |
||
2214 | } |
||
2215 | reset(); |
||
2216 | break; |
||
2217 | case IMAGEFILL: |
||
2218 | /* |
||
2219 | @ imagefill dx,dy,image_url |
||
2220 | @ The next suitable <b>filled object</b> will be filled with "image_url" tiled |
||
2221 | @ After pattern filling ,the fill-color should be reset ! |
||
2222 | @ wims getins / image from class directory : imagefill 80,80,my_image.gif |
||
2223 | @ normal url : imagefill 80,80,$module_dir/gifs/my_image.gif |
||
2224 | @ normal url : imagefill 80,80,http://adres/a/b/c/my_image.jpg |
||
2225 | @ if dx,dy is larger than the image, the whole image will be background to the next object. |
||
2226 | */ |
||
2227 | if( js_function[DRAW_IMAGEFILL] != 1 ){ js_function[DRAW_IMAGEFILL] = 1;} |
||
2228 | for(i=0 ;i < 3 ; i++){ |
||
2229 | switch(i){ |
||
2230 | case 0:int_data[0] = (int) (get_real(infile,0));break; |
||
2231 | case 1:int_data[1] = (int) (get_real(infile,0));break; |
||
2232 | case 2: URL = get_string_argument(infile,1); |
||
2233 | 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); |
||
2234 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
2235 | 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); |
||
2236 | add_to_buffer(tmp_buffer); |
||
2237 | break; |
||
2238 | } |
||
2239 | } |
||
2240 | break; |
||
2241 | case FILLTOBORDER: |
||
2242 | /* |
||
2243 | @ filltoborder x,y,bordercolor,color |
||
2244 | @ fill the region of point (x:y) bounded by 'bordercolor' with color 'color' |
||
2245 | @ any other color will not act as border to the bucket fill |
||
2246 | @ use this command after all boundary objects are declared. |
||
2247 | @ 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.. |
||
2248 | */ |
||
2249 | for(i=0 ;i < 4 ; i++){ |
||
2250 | switch(i){ |
||
2251 | case 0:double_data[0] = get_real(infile,0);break; |
||
2252 | case 1:double_data[1] = get_real(infile,0);break; |
||
2253 | case 2:bgcolor = get_color(infile,0);break; |
||
2254 | case 3:fill_color = get_color(infile,1); |
||
2255 | if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */ |
||
2256 | js_function[DRAW_FILLTOBORDER] = 1; |
||
2257 | add_js_filltoborder(js_include_file,canvas_root_id); |
||
2258 | } |
||
2259 | decimals = find_number_of_digits(precision); |
||
2260 | 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)); |
||
2261 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
2262 | 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)); |
||
2263 | add_to_buffer(tmp_buffer); |
||
2264 | break; |
||
2265 | default:break; |
||
2266 | } |
||
2267 | } |
||
2268 | break; |
||
2269 | case FLOODFILL: |
||
2270 | /* |
||
2271 | @ floodfill x,y,color |
||
2272 | @ alternative syntax: fill x,y,color |
||
2273 | @ fill the region of point (x:y) with color 'color' |
||
2274 | @ any other color or size of picture (borders of picture) will act as border to the bucket fill |
||
2275 | @ use this command after all boundary objects are declared. |
||
2276 | @ Use command 'clickfill,color' for user click driven flood fill. |
||
2277 | @ NOTE: recognised colour boundaries are in the "drag canvas" e.g. only for objects that can be set draggable / clickable |
||
2278 | @ 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.. |
||
2279 | */ |
||
2280 | for(i=0 ;i < 4 ; i++){ |
||
2281 | switch(i){ |
||
2282 | case 0:double_data[0] = get_real(infile,0);break; |
||
2283 | case 1:double_data[1] = get_real(infile,0);break; |
||
2284 | case 2:fill_color = get_color(infile,1); |
||
2285 | if(js_function[DRAW_FLOODFILL] != 1 ){/* use only once */ |
||
2286 | js_function[DRAW_FLOODFILL] = 1; |
||
2287 | add_js_floodfill(js_include_file,canvas_root_id); |
||
2288 | } |
||
2289 | decimals = find_number_of_digits(precision);/*floodfill(interaction,x,y,[R,G,B,A]) */ |
||
2290 | 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)); |
||
2291 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
2292 | 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)); |
||
2293 | add_to_buffer(tmp_buffer); |
||
2294 | break; |
||
2295 | default:break; |
||
2296 | } |
||
2297 | } |
||
2298 | break; |
||
2299 | case CLICKFILLMARGE: |
||
2300 | clickfillmarge = (int) (get_real(infile,1)); |
||
2301 | break; |
||
2302 | /* |
||
2303 | @ clickfillmarge int |
||
2304 | @ default 20 (pixels) |
||
2305 | @ 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[]) |
||
2306 | */ |
||
2307 | case CLICKFILL: |
||
2308 | /* |
||
2309 | @ clickfill fillcolor |
||
2310 | @ user left mouse click will floodfill the area with fillcolor |
||
2311 | @ multiple areas may be coloured |
||
2312 | @ 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) |
||
2313 | @ the answer will be read as the (x:y) click coordinates per coloured area |
||
2314 | @ background color of main div may be set by using command "bgcolor color" |
||
2315 | @ may not be combined with command "userdraw" |
||
2316 | @ NOTE: recognised colour boundaries are in the "drag canvas" e.g. only for objects that can be set draggable / clickable |
||
2317 | */ |
||
2318 | fill_color = get_color(infile,1); |
||
2319 | if(js_function[DRAW_FLOODFILL] != 1 ){/* use only once */ |
||
2320 | js_function[DRAW_FLOODFILL] = 1; |
||
2321 | add_js_floodfill(js_include_file,canvas_root_id); |
||
2322 | } |
||
7653 | schaersvoo | 2323 | 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 | 2324 | add_read_canvas(1); |
2325 | break; |
||
2326 | case SETPIXEL: |
||
2327 | /* |
||
2328 | @ setpixel x,y,color |
||
2329 | @ A "point" with diameter 1 pixel centeres at (x:y) in xrange / yrange |
||
2330 | @ pixels can not be dragged or clicked |
||
2331 | @ "pixelsize = 1" may be changed by command "pixelsize int" |
||
2332 | */ |
||
2333 | if( js_function[DRAW_PIXELS] != 1 ){ js_function[DRAW_PIXELS] = 1;} |
||
2334 | for(i=0;i<3;i++){ |
||
2335 | switch(i){ |
||
2336 | case 0: double_data[0] = get_real(infile,0); break; /* x */ |
||
2337 | case 1: double_data[1] = get_real(infile,0); break; /* y */ |
||
2338 | case 2: stroke_color = get_color(infile,1); |
||
2339 | string_length = snprintf(NULL,0,"draw_setpixel([%f],[%f],\"%s\",%.2f,%d);\n",double_data[0],double_data[1],stroke_color,stroke_opacity,pixelsize); |
||
2340 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
2341 | snprintf(tmp_buffer,string_length,"draw_setpixel([%f],[%f],\"%s\",%.2f,%d);\n",double_data[0],double_data[1],stroke_color,stroke_opacity,pixelsize); |
||
2342 | add_to_buffer(tmp_buffer); |
||
2343 | break; |
||
2344 | default:break; |
||
2345 | } |
||
2346 | } |
||
2347 | reset(); |
||
2348 | break; |
||
2349 | case PIXELSIZE: |
||
2350 | /* |
||
2351 | @ pixelsize int |
||
2352 | @ in case you want to deviate from default pixelsize = 1... |
||
2353 | */ |
||
2354 | pixelsize = (int) get_real(infile,1); |
||
2355 | break; |
||
2356 | case PIXELS: |
||
2357 | /* |
||
2358 | @ pixels color,x1,y1,x2,y2,x3,y3... |
||
2359 | @ Draw "points" with diameter 1 pixel |
||
2360 | @ pixels can not be dragged or clicked |
||
2361 | @ "pixelsize = 1" may be changed by command "pixelsize int" |
||
2362 | */ |
||
2363 | if( js_function[DRAW_PIXELS] != 1 ){ js_function[DRAW_PIXELS] = 1;} |
||
2364 | stroke_color=get_color(infile,0); |
||
2365 | i=0; |
||
2366 | c=0; |
||
2367 | while( ! done ){ /* get next item until EOL*/ |
||
2368 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
2369 | for( c = 0 ; c < 2; c++){ |
||
2370 | if(c == 0 ){ |
||
2371 | double_data[i] = get_real(infile,0); |
||
2372 | i++; |
||
2373 | } |
||
2374 | else |
||
2375 | { |
||
2376 | double_data[i] = get_real(infile,1); |
||
2377 | i++; |
||
2378 | } |
||
2379 | } |
||
2380 | } |
||
2381 | decimals = find_number_of_digits(precision); |
||
2382 | /* *double_xy2js_array(double xy[],int len,int decimals) */ |
||
2383 | string_length = snprintf(NULL,0, "draw_setpixel(%s,\"%s\",%.2f,%d);\n",double_xy2js_array(double_data,i,decimals),stroke_color,stroke_opacity,pixelsize); |
||
2384 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
2385 | snprintf(tmp_buffer,string_length,"draw_setpixel(%s,\"%s\",%.2f,%d);\n",double_xy2js_array(double_data,i,decimals),stroke_color,stroke_opacity,pixelsize); |
||
2386 | add_to_buffer(tmp_buffer); |
||
2387 | break; |
||
2388 | case REPLYFORMAT: |
||
2389 | /* |
||
2390 | @ replyformat number |
||
2391 | @ default values should be fine ! |
||
7782 | schaersvoo | 2392 | @ 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 | 2393 | @ note to 'userdraw text,color' : the x / y-values are in pixels ! (this to avoid too lengthy calculations in javascript...) |
2394 | */ |
||
2395 | reply_format = (int) get_real(infile,1); |
||
2396 | break; |
||
2397 | case LEGENDCOLORS: |
||
2398 | /* |
||
2399 | @ legendcolors color1:color2:color3:...:color_n |
||
2400 | @ will be used to colour a legend |
||
2401 | @ make sure the number of colours match the number of legend items |
||
2402 | @ command 'legend' in case of 'piechart' and 'barchart' will use these colours per default (no need to specify 'legendcolors' |
||
2403 | */ |
||
2404 | temp = get_string(infile,1); |
||
2405 | if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); } |
||
7653 | schaersvoo | 2406 | fprintf(js_include_file,"var legendcolors%d = [\"%s\"];",canvas_root_id,temp); |
7614 | schaersvoo | 2407 | break; |
2408 | case LEGEND: |
||
2409 | /* |
||
2410 | @ legend string1:string2:string3....string_n |
||
2411 | @ will be used to create a legend for a graph |
||
2412 | @ also see command 'piechart' |
||
2413 | */ |
||
2414 | temp = get_string(infile,1); |
||
2415 | if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); } |
||
7653 | schaersvoo | 2416 | fprintf(js_include_file,"var legend%d = [\"%s\"];",canvas_root_id,temp); |
7614 | schaersvoo | 2417 | break; |
2418 | case XLABEL: |
||
2419 | /* |
||
2420 | @ xlabel some_string |
||
2421 | @ will be used to create a label for the x-axis (label is in quadrant I) |
||
2422 | @ can only be used together with command 'grid'<br />not depending on keywords 'axis' and 'axisnumbering' |
||
2423 | @ font setting: italic Courier, fontsize will be slightly larger (fontsize + 4) |
||
2424 | */ |
||
2425 | temp = get_string(infile,1); |
||
7653 | schaersvoo | 2426 | fprintf(js_include_file,"var xaxislabel = \"%s\";",temp); |
7614 | schaersvoo | 2427 | break; |
2428 | case YLABEL: |
||
2429 | /* |
||
2430 | @ ylabel some_string |
||
2431 | @ will be used to create a (vertical) label for the y-axis (label is in quadrant I) |
||
2432 | @ can only be used together with command 'grid'<br />not depending on keywords 'axis' and 'axisnumbering' |
||
2433 | @ font setting: italic Courier, fontsize will be slightly larger (fontsize + 4) |
||
2434 | */ |
||
2435 | temp = get_string(infile,1); |
||
7653 | schaersvoo | 2436 | fprintf(js_include_file,"var yaxislabel = \"%s\";",temp); |
7614 | schaersvoo | 2437 | break; |
2438 | case LINEGRAPH: /* scheme: var linegraph_0 = [ 'stroke_color','line_width','use_dashed' ,'dashtype0','dashtype1','x1','y1',...,'x_n','y_n'];*/ |
||
2439 | /* |
||
2440 | @ linegraph x1:y1;x2:y2...x_n:y;2 |
||
2441 | @ will plot your data in a graph |
||
2442 | @ may only to be used together with command 'grid' |
||
2443 | @ can be used together with freestyle x-axis/y-axis texts : see commands 'xaxis' and 'yaxis' |
||
2444 | @ use command 'legend' to provide an optional legend in right-top-corner |
||
2445 | @ also see command 'piechart' |
||
2446 | @ multiple linegraphs may be used in a single plot |
||
2447 | @ <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> |
||
2448 | */ |
||
2449 | temp = get_string(infile,1); |
||
2450 | if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); } |
||
7653 | schaersvoo | 2451 | 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 | 2452 | linegraph_cnt++; |
2453 | reset(); |
||
2454 | break; |
||
2455 | case CLOCK: |
||
2456 | /* |
||
2457 | @ clock x,y,r(px),H,M,S,type hourglass,interactive [ ,H_color,M_color,S_color,background_color,foreground_color ] |
||
2458 | @ type hourglass:<br />type = 0 : only segments<br />type = 1 : only numbers<br />type = 2 : numbers and segments |
||
2459 | @ 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 |
||
2460 | @ 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> |
||
2461 | @ canvasdraw will not check validity of colornames...the javascript console is your best friend |
||
2462 | @ no combinations with other reply_types allowed, for now |
||
7783 | schaersvoo | 2463 | @ 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 | 2464 | */ |
2465 | if( js_function[DRAW_CLOCK] != 1 ){ js_function[DRAW_CLOCK] = 1;} |
||
2466 | |||
2467 | /* var clock = function(xc,yc,radius,H,M,S,h_color,m_color,s_color,bg_color,fg_color) */ |
||
2468 | for(i=0;i<9;i++){ |
||
2469 | switch(i){ |
||
2470 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* xc */ |
||
2471 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* yc */ |
||
2472 | case 2: int_data[2] = get_real(infile,0);break;/* radius in px */ |
||
2473 | case 3: int_data[3] = get_real(infile,0);break;/* hours */ |
||
2474 | case 4: int_data[4] = get_real(infile,0);break;/* minutes */ |
||
2475 | case 5: int_data[5] = get_real(infile,0);break;/* seconds */ |
||
7783 | schaersvoo | 2476 | 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 | 2477 | case 7: int_data[7] = (int)(get_real(infile,0));/* interactive 0,1,2*/ |
7783 | schaersvoo | 2478 | switch(int_data[7]){ |
2479 | case 0:break; |
||
2480 | case 1:if(clock_cnt == 0){ |
||
2481 | if( reply_format == 0 ){ |
||
7614 | schaersvoo | 2482 | reply_format = 18; /* user sets clock */ |
7783 | schaersvoo | 2483 | /* 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 | 2484 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
2485 | 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"); |
||
2486 | add_to_buffer(tmp_buffer); |
||
7783 | schaersvoo | 2487 | */ |
2488 | 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"); |
||
2489 | } |
||
2490 | else |
||
2491 | { |
||
2492 | canvas_error("interactive clock may not be used together with other reply_types..."); |
||
2493 | } |
||
2494 | 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); |
||
2495 | } |
||
2496 | break; |
||
2497 | case 2:if( reply_format == 0 ){ |
||
2498 | reply_format = 19; /* "onclick */ |
||
2499 | 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 "); |
||
2500 | } |
||
2501 | else |
||
2502 | { |
||
2503 | if( reply_format != 19){ |
||
7614 | schaersvoo | 2504 | canvas_error("clickable clock(s) may not be used together with other reply_types..."); |
2505 | } |
||
7783 | schaersvoo | 2506 | } |
2507 | break; |
||
2508 | default: canvas_error("interactive must be set 0,1 or 2");break; |
||
2509 | } |
||
2510 | break; |
||
7614 | schaersvoo | 2511 | case 8: |
2512 | temp = get_string(infile,1); |
||
2513 | if( strstr( temp,",") != 0 ){ temp = str_replace(temp,",","\",\""); } |
||
2514 | if( strlen(temp) < 1 ){temp = ",\"\",\"\",\"\",\"\",\"\"";} |
||
2515 | 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); |
||
2516 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
2517 | 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); |
||
2518 | add_to_buffer(tmp_buffer); |
||
2519 | clock_cnt++; |
||
2520 | break; |
||
2521 | default:break; |
||
2522 | } |
||
2523 | } |
||
2524 | break; |
||
2525 | case BARCHART: |
||
2526 | /* |
||
2527 | @ barchart x_1:y_1:color_1:x_2:y_2:color_2:...x_n:y_n:color_n |
||
2528 | @ will be used to create a legend for bar graph |
||
2529 | @ may only to be used together with command 'grid' |
||
2530 | @ can be used together with freestyle x-axis/y-axis texts : see commands 'xaxis' and 'yaxis' |
||
2531 | @ use command 'legend' to provide an optional legend in right-top-corner |
||
2532 | @ also see command 'piechart' |
||
2533 | */ |
||
2534 | temp = get_string(infile,1); |
||
2535 | if( strstr( temp,":" ) != 0 ){ temp = str_replace(temp,":","\",\""); } |
||
7653 | schaersvoo | 2536 | fprintf(js_include_file,"var barchart%d = [\"%s\"];",canvas_root_id,temp); |
7614 | schaersvoo | 2537 | reset(); |
2538 | break; |
||
2539 | case PIECHART: |
||
2540 | /* |
||
2541 | @ piechart xc,yc,radius,'data+colorlist' |
||
2542 | @ (xc : yc) center of circle diagram in xrange/yrange |
||
2543 | @ radius in pixels |
||
2544 | @ 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 |
||
2545 | @ example data+colorlist : 132:red:23565:green:323:black:234324:orange:23434:yellow:2543:white |
||
2546 | @ the number of colors must match the number of data. |
||
2547 | @ use command "opacity 0-255,0-255" to adjust fill_opacity of colours |
||
2548 | @ 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... |
||
2549 | */ |
||
2550 | if( js_function[DRAW_PIECHART] != 1 ){ js_function[DRAW_PIECHART] = 1;} |
||
2551 | for(i=0;i<5;i++){ |
||
2552 | switch(i){ |
||
2553 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */ |
||
2554 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y */ |
||
2555 | case 2: int_data[2] = (int)(get_real(infile,1));break;/* radius*/ |
||
2556 | case 3: temp = get_string(infile,1); |
||
2557 | if( strstr( temp, ":" ) != 0 ){ temp = str_replace(temp,":","\",\"");} |
||
2558 | 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); |
||
2559 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
2560 | 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); |
||
2561 | add_to_buffer(tmp_buffer); |
||
2562 | break; |
||
2563 | default:break; |
||
2564 | } |
||
2565 | } |
||
2566 | reset(); |
||
2567 | break; |
||
2568 | case STATUS: |
||
2569 | fprintf(js_include_file,"\nstatus=\"waiting\";\n"); |
||
2570 | break; |
||
7735 | schaersvoo | 2571 | case XLOGBASE: |
7729 | schaersvoo | 2572 | /* |
7735 | schaersvoo | 2573 | @ xlogbase number |
2574 | @ sets the logbase number for the x-axis |
||
7729 | schaersvoo | 2575 | @ default value 10 |
7735 | schaersvoo | 2576 | @ use together with commands xlogscale / xylogscale |
7729 | schaersvoo | 2577 | */ |
7735 | schaersvoo | 2578 | fprintf(js_include_file,"xlogbase=%d;",(int)(get_real(infile,1))); |
7729 | schaersvoo | 2579 | break; |
7735 | schaersvoo | 2580 | case YLOGBASE: |
2581 | /* |
||
2582 | @ ylogbase number |
||
2583 | @ sets the logbase number for the y-axis |
||
2584 | @ default value 10 |
||
2585 | @ use together with commands ylogscale / xylogscale |
||
2586 | */ |
||
2587 | fprintf(js_include_file,"ylogbase=%d;",(int)(get_real(infile,1))); |
||
2588 | break; |
||
7614 | schaersvoo | 2589 | case XLOGSCALE: |
2590 | /* |
||
7735 | schaersvoo | 2591 | @ xlogscale ymajor,yminor,majorcolor,minorcolor |
2592 | @ the x/y-range are set using commands 'xrange xmin,xmax' and 'yrange ymin,ymax' |
||
2593 | @ ymajor is the major step on the y-axis; yminor is the divisor for the y-step |
||
2594 | @ the linewidth is set using command 'linewidth int' |
||
2595 | @ the opacity of major / minor grid lines is set by command 'opacity [0-255],[0-255]' |
||
2596 | @ default logbase number = 10 ... when needed , set the logbase number with command 'xlogbase number' |
||
7779 | schaersvoo | 2597 | @ 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 | 2598 | @ note: the complete canvas will be used for the 'log paper' |
2599 | @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values |
||
2600 | @ note: command 'mouse color,fontsize' will show the real values in the logpaper.<br />\ |
||
2601 | @ 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') |
||
2602 | @ note: in case of userdraw , the use of keyword 'userinput_xy' may be handy ! |
||
2603 | @ attention: keyword 'snaptogrid' may not lead to the desired result... |
||
7614 | schaersvoo | 2604 | */ |
7735 | schaersvoo | 2605 | if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");} |
2606 | if( js_function[DRAW_XLOGSCALE] != 1 ){ js_function[DRAW_XLOGSCALE] = 1;} |
||
2607 | for(i=0;i<4;i++){ |
||
2608 | switch(i){ |
||
2609 | case 0: double_data[0] = get_real(infile,0);break; /* xmajor */ |
||
2610 | case 1: int_data[0] = (int) (get_real(infile,0));break; /* xminor */ |
||
2611 | case 2: stroke_color = get_color(infile,0); break; |
||
2612 | case 3: fill_color = get_color(infile,1); |
||
7779 | schaersvoo | 2613 | 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 | 2614 | tmp_buffer = my_newmem(string_length+1); |
7779 | schaersvoo | 2615 | 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 | 2616 | fprintf(js_include_file,"use_xlogscale=1;snap_y = %f;snap_x = xlogbase;",double_data[0]/int_data[0]); |
2617 | add_to_buffer(tmp_buffer); |
||
2618 | break; |
||
2619 | default:break; |
||
2620 | } |
||
2621 | } |
||
7614 | schaersvoo | 2622 | break; |
2623 | case YLOGSCALE: |
||
7729 | schaersvoo | 2624 | /* |
2625 | @ ylogscale xmajor,xminor,majorcolor,minorcolor |
||
2626 | @ the x/y-range are set using commands 'xrange xmin,xmax' and 'yrange ymin,ymax' |
||
2627 | @ xmajor is the major step on the x-axis; xminor is the divisor for the x-step |
||
2628 | @ the linewidth is set using command 'linewidth int' |
||
2629 | @ the opacity of major / minor grid lines is set by command 'opacity [0-255],[0-255]' |
||
7735 | schaersvoo | 2630 | @ default logbase number = 10 ... when needed , set the logbase number with command 'ylogbase number' |
7779 | schaersvoo | 2631 | @ 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 | 2632 | @ note: the complete canvas will be used for the 'log paper' |
2633 | @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values |
||
2634 | @ note: command 'mouse color,fontsize' will show the real values in the logpaper.<br />\ |
||
2635 | @ 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 | 2636 | @ note: in case of userdraw , the use of keyword 'userinput_xy' may be handy ! |
2637 | @ attention: keyword 'snaptogrid' may not lead to the desired result... |
||
7729 | schaersvoo | 2638 | */ |
2639 | if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");} |
||
2640 | if( js_function[DRAW_YLOGSCALE] != 1 ){ js_function[DRAW_YLOGSCALE] = 1;} |
||
2641 | for(i=0;i<4;i++){ |
||
2642 | switch(i){ |
||
2643 | case 0: double_data[0] = get_real(infile,0);break; /* xmajor */ |
||
2644 | case 1: int_data[0] = (int) (get_real(infile,0));break; /* xminor */ |
||
2645 | case 2: stroke_color = get_color(infile,0); break; |
||
2646 | case 3: fill_color = get_color(infile,1); |
||
7779 | schaersvoo | 2647 | 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 | 2648 | tmp_buffer = my_newmem(string_length+1); |
7779 | schaersvoo | 2649 | 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 | 2650 | fprintf(js_include_file,"use_ylogscale=1;snap_x = %f;snap_y = ylogbase;",double_data[0]/int_data[0]); |
7729 | schaersvoo | 2651 | add_to_buffer(tmp_buffer); |
2652 | break; |
||
2653 | default:break; |
||
2654 | } |
||
2655 | } |
||
7614 | schaersvoo | 2656 | break; |
2657 | case XYLOGSCALE: |
||
7735 | schaersvoo | 2658 | /* |
2659 | @ xylogscale majorcolor,minorcolor |
||
2660 | @ the x/y-range are set using commands 'xrange xmin,xmax' and 'yrange ymin,ymax' |
||
2661 | @ the linewidth is set using command 'linewidth int' |
||
2662 | @ the opacity of major / minor grid lines is set by command 'opacity [0-255],[0-255]' |
||
2663 | @ default logbase number = 10 ... when needed , set the logbase number with command 'xlogbase number' and/or 'ylogbase number' |
||
7739 | schaersvoo | 2664 | @ 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 | 2665 | @ note: the complete canvas will be used for the 'log paper' |
2666 | @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values |
||
2667 | @ note: command 'mouse color,fontsize' will show the real values in the logpaper.<br />\ |
||
2668 | @ 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') |
||
2669 | @ note: in case of userdraw , the use of keyword 'userinput_xy' may be handy ! |
||
2670 | @ attention: keyword 'snaptogrid' may not lead to the desired result... |
||
2671 | */ |
||
2672 | if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");} |
||
2673 | if( js_function[DRAW_XYLOGSCALE] != 1 ){ js_function[DRAW_XYLOGSCALE] = 1;} |
||
2674 | for(i=0;i<2;i++){ |
||
2675 | switch(i){ |
||
2676 | case 0: stroke_color = get_color(infile,0); break; |
||
2677 | case 1: fill_color = get_color(infile,1); |
||
7779 | schaersvoo | 2678 | 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 | 2679 | tmp_buffer = my_newmem(string_length+1); |
7779 | schaersvoo | 2680 | 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 | 2681 | fprintf(js_include_file,"use_xlogscale=1;use_ylogscale=1;snap_x = xlogbase;snap_y = ylogbase;"); |
2682 | add_to_buffer(tmp_buffer); |
||
2683 | break; |
||
2684 | default:break; |
||
2685 | } |
||
2686 | } |
||
2687 | break; |
||
7614 | schaersvoo | 2688 | default:sync_input(infile); |
2689 | break; |
||
2690 | } |
||
2691 | } |
||
2692 | /* we are done parsing script file */ |
||
2693 | |||
2694 | /* if needed, add generic draw functions (grid / xml etc) to buffer : these are no draggable shapes / objects ! */ |
||
2695 | add_javascript_functions(js_function,canvas_root_id); |
||
2696 | /* add read_canvas() etc functions if needed */ |
||
2697 | if( reply_format > 0 ){ add_read_canvas(reply_format);} |
||
2698 | /* using mouse coordinate display ? */ |
||
2699 | if( use_mouse_coordinates == TRUE ){ |
||
2700 | tmp_buffer = my_newmem(26); |
||
2701 | snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer); |
||
2702 | } |
||
2703 | /* add global variables / contants */ |
||
7729 | schaersvoo | 2704 | fprintf(js_include_file,"\n<!-- some extra global stuff : need to rethink panning and zooming !!! -->\n\ |
2705 | var precision = %d;var xmin=%f;var xmax=%f;var ymin=%f;\ |
||
2706 | var ymax=%f;var xmin_start=xmin;var xmax_start=xmax;\ |
||
2707 | var ymin_start=ymin;var ymax_start=xmax;\ |
||
2708 | var zoom_x_increment=0;var zoom_y_increment=0;\ |
||
2709 | var pan_x_increment=0;var pan_y_increment=0;\ |
||
2710 | if(use_ylogscale == 0 ){\ |
||
2711 | zoom_x_increment = (xmax - xmin)/20;zoom_y_increment = (xmax - xmin)/20;pan_x_increment = (xmax - xmin)/20;pan_y_increment = (ymax - ymin)/20;\ |
||
2712 | }else{\ |
||
2713 | zoom_x_increment = (xmax - xmin)/20;\ |
||
2714 | pan_x_increment = (xmax - xmin)/20;\ |
||
2715 | };\ |
||
7653 | schaersvoo | 2716 | function start_canvas%d(type){\ |
2717 | switch(type){\ |
||
7729 | schaersvoo | 2718 | case 0:xmin = xmin + zoom_x_increment;ymin = ymin + zoom_y_increment;xmax = xmax - zoom_x_increment;ymax = ymax - zoom_y_increment;break;\ |
2719 | 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 | 2720 | case 2:xmin = xmin - pan_x_increment;ymin = ymin ;xmax = xmax - pan_x_increment;ymax = ymax;break;\ |
2721 | case 3:xmin = xmin + pan_x_increment;ymin = ymin ;xmax = xmax + pan_x_increment;ymax = ymax;break;\ |
||
2722 | case 4:xmin = xmin;ymin = ymin - pan_y_increment ;xmax = xmax;ymax = ymax - pan_y_increment;break;\ |
||
2723 | case 5:xmin = xmin;ymin = ymin + pan_y_increment ;xmax = xmax;ymax = ymax + pan_y_increment;break;\ |
||
2724 | case 6:location.reload();break;\ |
||
2725 | default:break;\ |
||
2726 | };\ |
||
2727 | if(xmax<=xmin){xmin=xmin_start;xmax=xmax_start;};\ |
||
2728 | if(ymax<=ymin){ymin=ymin_start;ymax=ymax_start;};\ |
||
2729 | try{dragstuff.Zoom(xmin,xmax,ymin,ymax);}catch(e){}\ |
||
2730 | %s\ |
||
2731 | };\ |
||
2732 | start_canvas%d(22);\ |
||
7614 | schaersvoo | 2733 | };\n\ |
2734 | <!-- end wims_canvas_function -->\n\ |
||
7729 | schaersvoo | 2735 | wims_canvas_function%d();\n",precision,xmin,xmax,ymin,ymax,canvas_root_id,buffer,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 2736 | /* done writing the javascript include file */ |
2737 | fclose(js_include_file); |
||
2738 | |||
2739 | } |
||
2740 | |||
2741 | /* if using a tooltip, this should always be printed to the *.phtml file, so stdout */ |
||
2742 | if(use_tooltip == TRUE){ |
||
2743 | add_js_tooltip(canvas_root_id,tooltip_text,bgcolor,xsize,ysize); |
||
2744 | } |
||
2745 | exit(EXIT_SUCCESS); |
||
2746 | } |
||
2747 | /* end main() */ |
||
2748 | |||
2749 | /****************************************************************************** |
||
2750 | ** |
||
2751 | ** sync_input |
||
2752 | ** |
||
2753 | ** synchronises input line - reads to end of line, leaving file pointer |
||
2754 | ** at first character of next line. |
||
2755 | ** |
||
2756 | ** Used by: |
||
2757 | ** main program - error handling. |
||
2758 | ** |
||
2759 | ******************************************************************************/ |
||
2760 | void sync_input(FILE *infile) |
||
2761 | { |
||
2762 | int c = 0; |
||
2763 | |||
7658 | schaersvoo | 2764 | if( c == '\n' || c == ';' ) return; |
2765 | while( ( (c=getc(infile)) != EOF ) && (c != '\n') && (c != '\r') && (c != ';')) ; |
||
7614 | schaersvoo | 2766 | if( c == EOF ) finished = 1; |
7658 | schaersvoo | 2767 | if( c == '\n' || c == '\r' || c == ';') line_number++; |
7614 | schaersvoo | 2768 | return; |
2769 | } |
||
2770 | |||
2771 | /******************************************************************************/ |
||
2772 | |||
2773 | char *str_replace(const char *str, const char *old, const char *new){ |
||
2774 | /* http://creativeandcritical.net/str-replace-c/ */ |
||
2775 | if(strlen(str) > MAX_BUFFER){canvas_error("string argument too big");} |
||
2776 | char *ret, *r; |
||
2777 | const char *p, *q; |
||
2778 | size_t oldlen = strlen(old); |
||
2779 | size_t count = 0; |
||
2780 | size_t retlen = 0; |
||
2781 | size_t newlen = strlen(new); |
||
2782 | if (oldlen != newlen){ |
||
2783 | for (count = 0, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen){ |
||
2784 | count++; |
||
2785 | retlen = p - str + strlen(p) + count * (newlen - oldlen); |
||
2786 | } |
||
2787 | } |
||
2788 | else |
||
2789 | { |
||
2790 | retlen = strlen(str); |
||
2791 | } |
||
2792 | |||
2793 | if ((ret = malloc(retlen + 1)) == NULL){ |
||
2794 | ret = NULL; |
||
2795 | canvas_error("string argument is NULL"); |
||
2796 | } |
||
2797 | else |
||
2798 | { |
||
2799 | for (r = ret, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen) { |
||
2800 | size_t l = q - p; |
||
2801 | memcpy(r, p, l); |
||
2802 | r += l; |
||
2803 | memcpy(r, new, newlen); |
||
2804 | r += newlen; |
||
2805 | } |
||
2806 | strcpy(r, p); |
||
2807 | } |
||
2808 | return ret; |
||
2809 | } |
||
2810 | |||
2811 | /******************************************************************************/ |
||
2812 | /* |
||
2813 | avoid the use of ctypes.h for tolower() toupper(); |
||
2814 | it gives trouble in FreeBSD 9.0 / 9.1 when used in a chroot environment (C library bug) : Undefined symbol "_ThreadRuneLocale" |
||
2815 | Upper case -> Lower case : c = c - 'A'+ 'a'; |
||
2816 | Lower case -> Upper case c = c + 'A' - 'a'; |
||
2817 | */ |
||
2818 | int tolower(int c){ |
||
2819 | if(c <= 'Z'){ |
||
2820 | if (c >= 'A'){ |
||
2821 | return c - 'A' + 'a'; |
||
2822 | } |
||
2823 | } |
||
2824 | return c; |
||
2825 | } |
||
2826 | |||
2827 | int toupper(int c){ |
||
2828 | if(c >= 'a' && c <= 'z'){ |
||
2829 | return c + 'A' - 'a'; |
||
2830 | } |
||
2831 | return c; |
||
2832 | } |
||
2833 | |||
2834 | char *get_color(FILE *infile , int last){ |
||
2835 | int c,i = 0,is_hex = 0; |
||
2836 | char temp[MAX_COLOR_STRING], *string; |
||
7748 | schaersvoo | 2837 | while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != ',' ) && ( c != ';' ) ){ |
7614 | schaersvoo | 2838 | if( i > MAX_COLOR_STRING ){ canvas_error("colour string is too big ... ? ");} |
2839 | if( c == '#' ){ |
||
2840 | is_hex = 1; |
||
2841 | } |
||
2842 | if( c != ' '){ |
||
2843 | temp[i]=tolower(c); |
||
2844 | i++; |
||
2845 | } |
||
2846 | } |
||
7658 | schaersvoo | 2847 | if( ( c == '\n' || c == EOF || c == ';' ) && last == 0){canvas_error("expecting more arguments in command");} |
7748 | schaersvoo | 2848 | if( c == '\n' || c == ';' ){ done = TRUE; line_number++; } |
7614 | schaersvoo | 2849 | if( c == EOF ){finished = 1;} |
2850 | if( finished == 1 && last != 1 ){ canvas_error("expected more arguments");} |
||
2851 | temp[i]='\0'; |
||
2852 | if( strlen(temp) == 0 ){ canvas_error("expected a colorname or hexnumber, but found nothing !!");} |
||
2853 | if( is_hex == 1 ){ |
||
2854 | char red[3], green[3], blue[3]; |
||
2855 | red[0] = toupper(temp[1]); red[1] = toupper(temp[2]); red[2] = '\0'; |
||
2856 | green[0] = toupper(temp[3]); green[1] = toupper(temp[4]); green[2] = '\0'; |
||
2857 | blue[0] = toupper(temp[5]); blue[1] = toupper(temp[6]); blue[2] = '\0'; |
||
2858 | int r = (int) strtol(red, NULL, 16); |
||
2859 | int g = (int) strtol(green, NULL, 16); |
||
2860 | int b = (int) strtol(blue, NULL, 16); |
||
2861 | string = (char *)my_newmem(12); |
||
2862 | snprintf(string,11,"%d,%d,%d",r,g,b); |
||
2863 | return string; |
||
2864 | } |
||
2865 | else |
||
2866 | { |
||
2867 | string = (char *)my_newmem(sizeof(temp)); |
||
2868 | snprintf(string,sizeof(temp),"%s",temp); |
||
2869 | for( i = 0; i <= NUMBER_OF_COLORNAMES ; i++ ){ |
||
2870 | if( strcmp( colors[i].name , string ) == 0 ){ |
||
2871 | return colors[i].rgb; |
||
2872 | } |
||
2873 | } |
||
2874 | } |
||
2875 | /* not found...return error */ |
||
2876 | free(string);string = NULL; |
||
2877 | canvas_error("I was expecting a color name or hexnumber...but found nothing."); |
||
2878 | return NULL; |
||
2879 | } |
||
2880 | |||
2881 | char *get_string(FILE *infile,int last){ /* last = 0 : more arguments ; last=1 final argument */ |
||
2882 | int c,i=0; |
||
2883 | char temp[MAX_BUFFER], *string; |
||
7748 | schaersvoo | 2884 | while(( (c=getc(infile)) != EOF ) && ( c != '\n') ){ |
7614 | schaersvoo | 2885 | temp[i]=c; |
2886 | i++; |
||
2887 | if(i > MAX_BUFFER){ canvas_error("string size too big...repeat command to fit string");break;} |
||
2888 | } |
||
7748 | schaersvoo | 2889 | if( ( c == '\n' || c == EOF ) && last == 0){canvas_error("expecting more arguments in command");} |
2890 | if( c == '\n') { done = TRUE; line_number++; } |
||
7614 | schaersvoo | 2891 | if( c == EOF ) { |
2892 | finished = 1; |
||
2893 | if( last != 1 ){ canvas_error("expected more arguments");} |
||
2894 | } |
||
2895 | temp[i]='\0'; |
||
2896 | if( strlen(temp) == 0 ){ canvas_error("expected a word or string, but found nothing !!");} |
||
2897 | string=(char *)my_newmem(strlen(temp)); |
||
2898 | snprintf(string,sizeof(temp),"%s",temp); |
||
2899 | return string; |
||
2900 | } |
||
2901 | |||
2902 | char *get_string_argument(FILE *infile,int last){ /* last = 0 : more arguments ; last=1 final argument */ |
||
2903 | int c,i=0; |
||
2904 | char temp[MAX_BUFFER], *string; |
||
7748 | schaersvoo | 2905 | while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != ',')){ |
7614 | schaersvoo | 2906 | temp[i]=c; |
2907 | i++; |
||
2908 | if(i > MAX_BUFFER){ canvas_error("string size too big...will cut it off");break;} |
||
2909 | } |
||
7748 | schaersvoo | 2910 | if( ( c == '\n' || c == EOF) && last == 0){canvas_error("expecting more arguments in command");} |
2911 | if( c == '\n') { line_number++; } |
||
7614 | schaersvoo | 2912 | if( c == EOF ) {finished = 1;} |
2913 | if( finished == 1 && last != 1 ){ canvas_error("expected more arguments");} |
||
2914 | temp[i]='\0'; |
||
2915 | if( strlen(temp) == 0 ){ canvas_error("expected a word or string (without comma) , but found nothing !!");} |
||
2916 | string=(char *)my_newmem(sizeof(temp)); |
||
2917 | snprintf(string,sizeof(temp),"%s",temp); |
||
2918 | done = TRUE; |
||
2919 | return string; |
||
2920 | } |
||
2921 | |||
2922 | double get_real(FILE *infile, int last){ /* accept anything that looks like an number ? last = 0 : more arguments ; last=1 final argument */ |
||
2923 | int c,i=0,found_calc = 0; |
||
2924 | double y; |
||
2925 | char tmp[MAX_INT]; |
||
7658 | schaersvoo | 2926 | while(( (c=getc(infile)) != EOF ) && ( c != ',') && (c != '\n') && ( c != ';')){ |
7614 | schaersvoo | 2927 | if( c != ' ' ){ |
2928 | /* |
||
2929 | libmatheval will segfault when for example: "xrange -10,+10" or "xrange -10,10+" is used |
||
2930 | We will check after assert() if it's a NULL pointer...and exit program via : |
||
2931 | canvas_error("I'm having trouble parsing your \"expression\" "); |
||
2932 | */ |
||
2933 | if( i == 0 && c == '+' ){ |
||
2934 | continue; |
||
2935 | } |
||
2936 | else |
||
2937 | { |
||
2938 | if(canvas_iscalculation(c) != 0){ |
||
2939 | found_calc = 1; |
||
2940 | c = tolower(c); |
||
2941 | } |
||
2942 | tmp[i] = c; |
||
2943 | i++; |
||
2944 | } |
||
2945 | } |
||
2946 | if( i > MAX_INT - 1){canvas_error("number too large");} |
||
2947 | } |
||
7658 | schaersvoo | 2948 | if( ( c == '\n' || c == EOF || c == ';' ) && last == 0){canvas_error("expecting more arguments in command");} |
2949 | if( c == '\n' || c == ';' ){ done = TRUE; line_number++; } |
||
7614 | schaersvoo | 2950 | if( c == EOF ){done = TRUE ; finished = 1;} |
2951 | tmp[i]='\0'; |
||
2952 | if( strlen(tmp) == 0 ){canvas_error("expected a number , but found nothing !!");} |
||
2953 | if( found_calc == 1 ){ /* use libmatheval to calculate 2*pi/3 */ |
||
2954 | void *f = evaluator_create(tmp); |
||
2955 | assert(f);if( f == NULL ){canvas_error("I'm having trouble parsing your \"expression\" ") ;} |
||
2956 | y = evaluator_evaluate_x(f, 1); |
||
2957 | /* if function is bogus; y = 1 : so no core dumps */ |
||
2958 | evaluator_destroy(f); |
||
2959 | } |
||
2960 | else |
||
2961 | { |
||
2962 | y = atof(tmp); |
||
2963 | } |
||
2964 | return y; |
||
2965 | } |
||
2966 | void canvas_error(char *msg){ |
||
7748 | schaersvoo | 2967 | fprintf(stdout,"\n</script><hr /><span style=\"color:red\">FATAL syntax error:line %d : %s</span><hr />",line_number-1,msg); |
7614 | schaersvoo | 2968 | finished = 1; |
2969 | exit(EXIT_SUCCESS); |
||
2970 | } |
||
2971 | |||
2972 | |||
2973 | /* convert x/y coordinates to pixel */ |
||
2974 | int x2px(double x){ |
||
2975 | return x*xsize/(xmax - xmin) - xsize*xmin/(xmax - xmin); |
||
2976 | } |
||
2977 | |||
2978 | int y2px(double y){ |
||
2979 | return -1*y*ysize/(ymax - ymin) + ymax*ysize/(ymax - ymin); |
||
2980 | } |
||
2981 | |||
2982 | double px2x(int x){ |
||
2983 | return (x*(xmax - xmin)/xsize + xmin); |
||
2984 | } |
||
2985 | double px2y(int y){ |
||
2986 | return (y*(ymax - ymin)/ysize + ymin); |
||
2987 | } |
||
2988 | |||
2989 | void add_to_buffer(char *tmp){ |
||
2990 | if( tmp == NULL || tmp == 0 ){ canvas_error("nothing to add_to_buffer()...");} |
||
2991 | /* do we have enough space left in buffer[MAX_BUFFER] ? */ |
||
2992 | int space_left = (int) (sizeof(buffer) - strlen(buffer)); |
||
2993 | if( space_left > strlen(tmp)){ |
||
2994 | strncat(buffer,tmp,space_left - 1);/* add safely "tmp" to the string buffer */ |
||
2995 | } |
||
2996 | else |
||
2997 | { |
||
2998 | canvas_error("buffer is too big\n"); |
||
2999 | } |
||
3000 | tmp = NULL;free(tmp); |
||
3001 | return; |
||
3002 | } |
||
3003 | |||
3004 | void reset(){ |
||
3005 | if(use_filled == TRUE){use_filled = FALSE;} |
||
3006 | if(use_dashed == TRUE){use_dashed = FALSE;} |
||
3007 | if(use_translate == TRUE){use_translate = FALSE;} |
||
3008 | if(use_rotate == TRUE){use_rotate = FALSE;} |
||
3009 | onclick = 0; |
||
3010 | } |
||
3011 | |||
3012 | |||
3013 | |||
3014 | /* What reply format in read_canvas(); |
||
3015 | |||
3016 | note:if userdraw is combined with inputfields...every "userdraw" based answer will append "\n" and inputfield.value() |
||
3017 | 1 = x1,x2,x3,x4....x_n |
||
3018 | y1,y2,y3,y4....y_n |
||
3019 | |||
3020 | x/y in pixels |
||
3021 | |||
3022 | 2 = x1,x2,x3,x4....x_n |
||
3023 | y1,y2,y3,y4....y_n |
||
3024 | x/y in xrange / yrange coordinate system |
||
3025 | |||
3026 | 3 = x1,x2,x3,x4....x_n |
||
3027 | y1,y2,y3,y4....y_n |
||
3028 | r1,r2,r3,r4....r_n |
||
3029 | |||
3030 | x/y in pixels |
||
3031 | r in pixels |
||
3032 | |||
3033 | 4 = x1,x2,x3,x4....x_n |
||
3034 | y1,y2,y3,y4....y_n |
||
3035 | r1,r2,r3,r4....r_n |
||
3036 | |||
3037 | x/y in xrange / yrange coordinate system |
||
3038 | r in pixels |
||
3039 | |||
3040 | 5 = Ax1,Ax2,Ax3,Ax4....Ax_n |
||
3041 | Ay1,Ay2,Ay3,Ay4....Ay_n |
||
3042 | Bx1,Bx2,Bx3,Bx4....Bx_n |
||
3043 | By1,By2,By3,By4....By_n |
||
3044 | Cx1,Cx2,Cx3,Cx4....Cx_n |
||
3045 | Cy1,Cy2,Cy3,Cy4....Cy_n |
||
3046 | .... |
||
3047 | Zx1,Zx2,Zx3,Zx4....Zx_n |
||
3048 | Zy1,Zy2,Zy3,Zy4....Zy_n |
||
3049 | |||
3050 | x/y in pixels |
||
3051 | |||
3052 | 6 = Ax1,Ax2,Ax3,Ax4....Ax_n |
||
3053 | Ay1,Ay2,Ay3,Ay4....Ay_n |
||
3054 | Bx1,Bx2,Bx3,Bx4....Bx_n |
||
3055 | By1,By2,By3,By4....By_n |
||
3056 | Cx1,Cx2,Cx3,Cx4....Cx_n |
||
3057 | Cy1,Cy2,Cy3,Cy4....Cy_n |
||
3058 | .... |
||
3059 | Zx1,Zx2,Zx3,Zx4....Zx_n |
||
3060 | Zy1,Zy2,Zy3,Zy4....Zy_n |
||
3061 | |||
3062 | x/y in xrange / yrange coordinate system |
||
3063 | |||
3064 | 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n |
||
3065 | |||
3066 | x/y in pixels |
||
3067 | |||
3068 | 8 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n |
||
3069 | |||
3070 | x/y in xrange / yrange coordinate system |
||
3071 | |||
3072 | 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n |
||
3073 | |||
3074 | x/y in pixels |
||
3075 | |||
3076 | 10 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n |
||
3077 | |||
3078 | x/y in xrange / yrange coordinate system |
||
3079 | |||
3080 | 11 = Ax1,Ay1,Ax2,Ay2 |
||
3081 | Bx1,By1,Bx2,By2 |
||
3082 | Cx1,Cy1,Cx2,Cy2 |
||
3083 | Dx1,Dy1,Dx2,Dy2 |
||
3084 | ...... |
||
3085 | Zx1,Zy1,Zx2,Zy2 |
||
3086 | |||
3087 | x/y in xrange / yrange coordinate system |
||
3088 | |||
3089 | 12 = Ax1,Ay1,Ax2,Ay2 |
||
3090 | Bx1,By1,Bx2,By2 |
||
3091 | Cx1,Cy1,Cx2,Cy2 |
||
3092 | Dx1,Dy1,Dx2,Dy2 |
||
3093 | ...... |
||
3094 | Zx1,Zy1,Zx2,Zy2 |
||
3095 | |||
3096 | x/y in pixels |
||
3097 | |||
3098 | 13 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2,Cx1:Cy1:Cx2:Cy2,Dx1:Dy1:Dx2:Dy2, ... ,Zx1:Zy1:Zx2:Zy2 |
||
3099 | |||
3100 | x/y in xrange / yrange coordinate system |
||
3101 | 14 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2....Zx1:Zy1:Zx2:Zy2 |
||
3102 | x/y in pixels |
||
3103 | 15 = reply from inputfields,textareas |
||
3104 | reply1,reply2,reply3,...,reply_n |
||
3105 | |||
3106 | 16 = read mathml inputfields only |
||
3107 | |||
3108 | 17 = read userdraw text only (x1:y1:text1,x2:y2:text2...x_n:y_n:text_n |
||
3109 | when ready : calculate size_t of string via snprintf(NULL,0,"blah blah..."); |
||
3110 | |||
3111 | 18 = read clock(s) : H1:M1:S1,H2:M2:S2,...H_n:M_n:S_n |
||
3112 | 19 = return clicked object number (analogue to shape-library onclick) |
||
3113 | 20 = return x/y-data in x-range/y-range of all 'draggable' images |
||
3114 | 21 = return verbatim coordinates (x1:y1) (x2:y2)...(x_n:y_n) |
||
3115 | 22 = array : x1,y1,x2,y2,x3,y3,x4,y4...x_n,y_n |
||
3116 | x/y in xrange / yrange coordinate system |
||
7782 | schaersvoo | 3117 | 23 = answertype for a polyline : remove multiple occurences due to reclick on a point to create next polyline segment |
7614 | schaersvoo | 3118 | */ |
3119 | |||
3120 | |||
3121 | void add_read_canvas(int type_reply){ |
||
3122 | /* just 1 reply type allowed */ |
||
3123 | switch(type_reply){ |
||
3124 | /* TO DO |
||
3125 | !!!! NEED TO SIMPLIFY !!!! |
||
3126 | answers may have: |
||
3127 | x-values,y-values,r-values,input-fields,mathml-inputfields,text-typed answers |
||
3128 | */ |
||
3129 | case 1: fprintf(js_include_file,"\ |
||
7653 | schaersvoo | 3130 | \n<!-- begin function 1 read_canvas() -->\n\ |
7614 | schaersvoo | 3131 | function read_canvas(){\ |
3132 | if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\ |
||
3133 | if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\ |
||
3134 | var p = 0;var input_reply = new Array();\ |
||
3135 | if( document.getElementById(\"canvas_input0\")){\ |
||
3136 | var t = 0;\ |
||
3137 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
3138 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
3139 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
3140 | p++;\ |
||
3141 | };\ |
||
3142 | t++;\ |
||
3143 | };\ |
||
3144 | };\ |
||
3145 | if( typeof userdraw_text != 'undefined' ){\ |
||
3146 | return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+input_reply + \"\\n\"+userdraw_text;\ |
||
3147 | }\ |
||
3148 | else\ |
||
3149 | {\ |
||
3150 | return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+input_reply;\ |
||
3151 | }\ |
||
3152 | }\ |
||
3153 | else\ |
||
3154 | {\ |
||
3155 | if( typeof userdraw_text != 'undefined' ){\ |
||
3156 | return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_text;\ |
||
3157 | }\ |
||
3158 | else\ |
||
3159 | {\ |
||
3160 | return userdraw_x+\"\\n\"+userdraw_y;\ |
||
3161 | }\ |
||
3162 | };\ |
||
3163 | };\ |
||
3164 | this.read_canvas = read_canvas;\n\ |
||
7653 | schaersvoo | 3165 | <!-- end function 1 read_canvas() -->"); |
7614 | schaersvoo | 3166 | break; |
3167 | case 2: fprintf(js_include_file,"\ |
||
7653 | schaersvoo | 3168 | \n<!-- begin function 2 read_canvas() -->\n\ |
7614 | schaersvoo | 3169 | function read_canvas(){\ |
3170 | if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\ |
||
3171 | var reply_x = new Array();var reply_y = new Array();var p = 0;\ |
||
3172 | while(userdraw_x[p]){\ |
||
3173 | reply_x[p] = px2x(userdraw_x[p]);\ |
||
3174 | reply_y[p] = px2y(userdraw_y[p]);\ |
||
3175 | p++;\ |
||
3176 | };\ |
||
3177 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
3178 | if( document.getElementById(\"canvas_input0\")){\ |
||
3179 | var p = 0;var input_reply = new Array();\ |
||
3180 | if( document.getElementById(\"canvas_input0\")){\ |
||
3181 | var t = 0;\ |
||
3182 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
3183 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
3184 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
3185 | p++;\ |
||
3186 | };\ |
||
3187 | t++;\ |
||
3188 | };\ |
||
3189 | };\ |
||
3190 | if( typeof userdraw_text != 'undefined' ){\ |
||
3191 | return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
3192 | }\ |
||
3193 | else\ |
||
3194 | {\ |
||
3195 | return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply;\ |
||
3196 | }\ |
||
3197 | }\ |
||
3198 | else\ |
||
3199 | {\ |
||
3200 | if( typeof userdraw_text != 'undefined' ){\ |
||
3201 | return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_text;\ |
||
3202 | }\ |
||
3203 | else\ |
||
3204 | {\ |
||
3205 | return reply_x+\"\\n\"+reply_y;\ |
||
3206 | };\ |
||
3207 | };\ |
||
3208 | };\ |
||
3209 | this.read_canvas = read_canvas;\n\ |
||
7653 | schaersvoo | 3210 | <!-- end function 2 read_canvas() -->"); |
7614 | schaersvoo | 3211 | break; |
3212 | case 3: fprintf(js_include_file,"\ |
||
7653 | schaersvoo | 3213 | \n<!-- begin function 3 read_canvas() -->\n\ |
7614 | schaersvoo | 3214 | function read_canvas(){\ |
3215 | if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\ |
||
3216 | if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\ |
||
3217 | var p = 0;var input_reply = new Array();\ |
||
3218 | if( document.getElementById(\"canvas_input0\")){\ |
||
3219 | var t = 0;\ |
||
3220 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
3221 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
3222 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
3223 | p++;\ |
||
3224 | };\ |
||
3225 | t++;\ |
||
3226 | };\ |
||
3227 | };\ |
||
3228 | if( typeof userdraw_text != 'undefined' ){\ |
||
3229 | return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
3230 | }\ |
||
3231 | else\ |
||
3232 | {\ |
||
3233 | return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+input_reply;\ |
||
3234 | }\ |
||
3235 | }\ |
||
3236 | else\ |
||
3237 | {\ |
||
3238 | if( typeof userdraw_text != 'undefined' ){\ |
||
3239 | return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+userdrawW_text;\ |
||
3240 | }\ |
||
3241 | else\ |
||
3242 | {\ |
||
3243 | return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius;\ |
||
3244 | }\ |
||
3245 | }\ |
||
3246 | };\ |
||
3247 | this.read_canvas = read_canvas;\n\ |
||
7653 | schaersvoo | 3248 | <!-- end function 3 read_canvas() -->"); |
7614 | schaersvoo | 3249 | break; |
3250 | case 4: fprintf(js_include_file,"\ |
||
7653 | schaersvoo | 3251 | \n<!-- begin function 4 read_canvas() -->\n\ |
7614 | schaersvoo | 3252 | function read_canvas(){\ |
3253 | var reply_x = new Array();var reply_y = new Array();var p = 0;\ |
||
3254 | while(userdraw_x[p]){\ |
||
3255 | reply_x[p] = px2x(userdraw_x[p]);\ |
||
3256 | reply_y[p] = px2y(userdraw_y[p]);\ |
||
3257 | p++;\ |
||
3258 | };\ |
||
3259 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
3260 | if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\ |
||
3261 | var p = 0;var input_reply = new Array();\ |
||
3262 | if( document.getElementById(\"canvas_input0\")){\ |
||
3263 | var t = 0;\ |
||
3264 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
3265 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
3266 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
3267 | p++;\ |
||
3268 | };\ |
||
3269 | t++;\ |
||
3270 | };\ |
||
3271 | };\ |
||
3272 | if( typeof userdraw_text != 'undefined' ){\ |
||
3273 | return reply_x+\"\\n\"+reply_y +\"\\n\"+userdraw_radius+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
3274 | }\ |
||
3275 | else\ |
||
3276 | {\ |
||
3277 | return reply_x+\"\\n\"+reply_y +\"\\n\"+userdraw_radius+\"\\n\"+input_reply;\ |
||
3278 | }\ |
||
3279 | }\ |
||
3280 | else\ |
||
3281 | {\ |
||
3282 | if( typeof userdraw_text != 'undefined' ){\ |
||
3283 | return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_radius+\"\\n\"+userdraw_text;\ |
||
3284 | }\ |
||
3285 | else\ |
||
3286 | {\ |
||
3287 | return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_radius;\ |
||
3288 | }\ |
||
3289 | };\ |
||
3290 | };\ |
||
3291 | this.read_canvas = read_canvas;\n\ |
||
7653 | schaersvoo | 3292 | <!-- end function 4 read_canvas() -->"); |
7614 | schaersvoo | 3293 | break; |
3294 | /* |
||
3295 | attention: we reset userdraw_x / userdraw_y : because userdraw_x = [][] userdraw_y = [][] |
||
3296 | used for userdraw multiple paths |
||
3297 | */ |
||
3298 | case 5: fprintf(js_include_file,"\ |
||
7653 | schaersvoo | 3299 | \n<!-- begin function 5 read_canvas() -->\n\ |
7614 | schaersvoo | 3300 | function read_canvas(){\ |
3301 | var p = 0;\ |
||
3302 | var reply = \"\";\ |
||
3303 | for(p = 0; p < userdraw_x.length;p++){\ |
||
3304 | if(userdraw_x[p] != null ){\ |
||
3305 | reply = reply + userdraw_x[p]+\"\\n\"+userdraw_y[p]+\"\\n\";\ |
||
3306 | };\ |
||
3307 | };\ |
||
3308 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
3309 | userdraw_x = [];userdraw_y = [];\ |
||
3310 | if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\ |
||
3311 | var p = 0;var input_reply = new Array();\ |
||
3312 | if( document.getElementById(\"canvas_input0\")){\ |
||
3313 | var t = 0;\ |
||
3314 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
3315 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
3316 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
3317 | p++;\ |
||
3318 | };\ |
||
3319 | t++;\ |
||
3320 | };\ |
||
3321 | };\ |
||
3322 | if( typeof userdraw_text != 'undefined' ){\ |
||
3323 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
3324 | }\ |
||
3325 | else\ |
||
3326 | {\ |
||
3327 | return reply +\"\\n\"+input_reply;\ |
||
3328 | }\ |
||
3329 | }\ |
||
3330 | else\ |
||
3331 | {\ |
||
3332 | if( typeof userdraw_text != 'undefined' ){\ |
||
3333 | return reply+\"\\n\"+userdraw_text;\ |
||
3334 | }\ |
||
3335 | else\ |
||
3336 | {\ |
||
3337 | return reply;\ |
||
3338 | }\ |
||
3339 | };\ |
||
3340 | };\ |
||
7654 | schaersvoo | 3341 | this.read_canvas = rdad_canvas;\n\ |
7653 | schaersvoo | 3342 | <!-- end function 5 read_canvas() -->"); |
7614 | schaersvoo | 3343 | break; |
3344 | /* |
||
3345 | attention: we reset userdraw_x / userdraw_y : because userdraw_x = [][] userdraw_y = [][] |
||
3346 | used for userdraw multiple paths |
||
3347 | */ |
||
3348 | case 6: fprintf(js_include_file,"\ |
||
7653 | schaersvoo | 3349 | \n<!-- begin function 6 read_canvas() -->\n\ |
7614 | schaersvoo | 3350 | function read_canvas(){\ |
3351 | var p = 0;\ |
||
3352 | var reply = \"\";\ |
||
3353 | var tmp_x = new Array();\ |
||
3354 | var tmp_y = new Array();\ |
||
3355 | for(p = 0 ; p < userdraw_x.length; p++){\ |
||
3356 | tmp_x = userdraw_x[p];\ |
||
3357 | tmp_y = userdraw_y[p];\ |
||
3358 | if(tmp_x != null){\ |
||
3359 | for(var i = 0 ; i < tmp_x.length ; i++){\ |
||
3360 | tmp_x[i] = px2x(tmp_x[i]);\ |
||
3361 | tmp_y[i] = px2y(tmp_y[i]);\ |
||
3362 | };\ |
||
3363 | reply = reply + tmp_x + \"\\n\" + tmp_y +\"\\n\";\ |
||
3364 | };\ |
||
3365 | };\ |
||
3366 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
3367 | userdraw_x = [];userdraw_y = [];\ |
||
3368 | if( document.getElementById(\"canvas_input0\") ){\ |
||
3369 | var p = 0;var input_reply = new Array();\ |
||
3370 | if( document.getElementById(\"canvas_input0\")){\ |
||
3371 | var t = 0;\ |
||
3372 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
3373 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
3374 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
3375 | p++;\ |
||
3376 | };\ |
||
3377 | t++;\ |
||
3378 | };\ |
||
3379 | };\ |
||
3380 | if( typeof userdraw_text != 'undefined' ){\ |
||
3381 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
3382 | }\ |
||
3383 | else\ |
||
3384 | {\ |
||
3385 | return reply +\"\\n\"+input_reply;\ |
||
3386 | }\ |
||
3387 | }\ |
||
3388 | else\ |
||
3389 | {\ |
||
3390 | if( typeof userdraw_text != 'undefined' ){\ |
||
3391 | return reply +\"\\n\"+userdraw_text;\ |
||
3392 | }\ |
||
3393 | else\ |
||
3394 | {\ |
||
3395 | return reply;\ |
||
3396 | }\ |
||
3397 | };\ |
||
3398 | };\ |
||
3399 | this.read_canvas = read_canvas;\n\ |
||
7653 | schaersvoo | 3400 | <!-- end function 6 read_canvas() -->"); |
7614 | schaersvoo | 3401 | break; |
3402 | case 7: fprintf(js_include_file,"\ |
||
7653 | schaersvoo | 3403 | \n<!-- begin function 7 read_canvas() -->\n\ |
7614 | schaersvoo | 3404 | function read_canvas(){\ |
3405 | var reply = new Array();\ |
||
3406 | var p = 0;\ |
||
3407 | while(userdraw_x[p]){\ |
||
3408 | reply[p] = userdraw_x[p] +\":\" + userdraw_y[p];\ |
||
3409 | p++;\ |
||
3410 | };\ |
||
3411 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
3412 | if( document.getElementById(\"canvas_input0\") ){\ |
||
3413 | var p = 0;var input_reply = new Array();\ |
||
3414 | if( document.getElementById(\"canvas_input0\")){\ |
||
3415 | var t = 0;\ |
||
3416 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
3417 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
3418 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
3419 | p++;\ |
||
3420 | };\ |
||
3421 | t++;\ |
||
3422 | };\ |
||
3423 | };\ |
||
3424 | if( typeof userdraw_text != 'undefined' ){\ |
||
3425 | return reply+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
3426 | }\ |
||
3427 | else\ |
||
3428 | {\ |
||
3429 | return reply+\"\\n\"+input_reply;\ |
||
3430 | }\ |
||
3431 | };\ |
||
3432 | else\ |
||
3433 | {\ |
||
3434 | if( typeof userdraw_text != 'undefined' ){\ |
||
3435 | return reply+\"\\n\"+userdraw_text;\ |
||
3436 | }\ |
||
3437 | else\ |
||
3438 | {\ |
||
3439 | return reply;\ |
||
3440 | }\ |
||
3441 | };\ |
||
3442 | };\ |
||
3443 | this.read_canvas = read_canvas;\n\ |
||
7653 | schaersvoo | 3444 | <!-- end function 7 read_canvas() -->"); |
7614 | schaersvoo | 3445 | break; |
3446 | case 8: fprintf(js_include_file,"\ |
||
7653 | schaersvoo | 3447 | \n<!-- begin function 8 read_canvas() -->\n\ |
7614 | schaersvoo | 3448 | function read_canvas(){\ |
3449 | var reply = new Array();\ |
||
3450 | var p = 0;\ |
||
3451 | while(userdraw_x[p]){\ |
||
3452 | reply[p] = px2x(userdraw_x[p]) +\":\" + px2y(userdraw_y[p]);\ |
||
3453 | p++;\ |
||
3454 | };\ |
||
3455 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
3456 | if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\ |
||
3457 | var p = 0;var input_reply = new Array();\ |
||
3458 | if( document.getElementById(\"canvas_input0\")){\ |
||
3459 | var t = 0;\ |
||
3460 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
3461 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
3462 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
3463 | p++;\ |
||
3464 | };\ |
||
3465 | t++;\ |
||
3466 | };\ |
||
3467 | };\ |
||
3468 | if( typeof userdraw_text != 'undefined' ){\ |
||
3469 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
3470 | }\ |
||
3471 | else\ |
||
3472 | {\ |
||
3473 | return reply +\"\\n\"+input_reply;\ |
||
3474 | }\ |
||
3475 | }\ |
||
3476 | else\ |
||
3477 | {\ |
||
3478 | if( typeof userdraw_text != 'undefined' ){\ |
||
3479 | return reply +\"\\n\"+userdraw_text;\ |
||
3480 | }\ |
||
3481 | else\ |
||
3482 | {\ |
||
3483 | return reply;\ |
||
3484 | }\ |
||
3485 | };\ |
||
3486 | };\ |
||
3487 | this.read_canvas = read_canvas;\n\ |
||
7653 | schaersvoo | 3488 | <!-- end function 8 read_canvas() -->"); |
7614 | schaersvoo | 3489 | break; |
3490 | case 9: fprintf(js_include_file,"\ |
||
7653 | schaersvoo | 3491 | \n<!-- begin function 9 read_canvas() -->\n\ |
7614 | schaersvoo | 3492 | function read_canvas(){\ |
3493 | var reply = new Array();\ |
||
3494 | var p = 0;\ |
||
3495 | while(userdraw_x[p]){\ |
||
3496 | reply[p] = userdraw_x[p] +\":\" + userdraw_y[p] + \":\" + userdraw_radius[p];\ |
||
3497 | p++;\ |
||
3498 | };\ |
||
3499 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
3500 | if( document.getElementById(\"canvas_input0\") ){\ |
||
3501 | var p = 0;var input_reply = new Array();\ |
||
3502 | if( document.getElementById(\"canvas_input0\")){\ |
||
3503 | var t = 0;\ |
||
3504 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
3505 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
3506 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
3507 | p++;\ |
||
3508 | };\ |
||
3509 | t++;\ |
||
3510 | };\ |
||
3511 | };\ |
||
3512 | if( typeof userdraw_text != 'undefined' ){\ |
||
3513 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
3514 | }\ |
||
3515 | else\ |
||
3516 | {\ |
||
3517 | return reply +\"\\n\"+input_reply;\ |
||
3518 | }\ |
||
3519 | }\ |
||
3520 | else\ |
||
3521 | {\ |
||
3522 | if( typeof userdraw_text != 'undefined' ){\ |
||
3523 | return reply +\"\\n\"+userdraw_text;\ |
||
3524 | }\ |
||
3525 | else\ |
||
3526 | {\ |
||
3527 | return reply;\ |
||
3528 | }\ |
||
3529 | };\ |
||
3530 | };\ |
||
3531 | this.read_canvas = read_canvas;\n\ |
||
7653 | schaersvoo | 3532 | <!-- end function 9 read_canvas() -->"); |
7614 | schaersvoo | 3533 | break; |
3534 | case 10: fprintf(js_include_file,"\ |
||
7653 | schaersvoo | 3535 | \n<!-- begin function 10 read_canvas() -->\n\ |
7614 | schaersvoo | 3536 | function read_canvas(){\ |
3537 | var reply = new Array();\ |
||
3538 | var p = 0;\ |
||
3539 | while(userdraw_x[p]){\ |
||
3540 | reply[p] = px2x(userdraw_x[p]) +\":\" + px2y(userdraw_y[p]) +\":\" + userdraw_radius[p];\ |
||
3541 | p++;\ |
||
3542 | };\ |
||
3543 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
3544 | if( document.getElementById(\"canvas_input0\") ){\ |
||
3545 | var p = 0;var input_reply = new Array();\ |
||
3546 | if( document.getElementById(\"canvas_input0\")){\ |
||
3547 | var t = 0;\ |
||
3548 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
3549 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
3550 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
3551 | p++;\ |
||
3552 | };\ |
||
3553 | t++;\ |
||
3554 | };\ |
||
3555 | };\ |
||
3556 | if( typeof userdraw_text != 'undefined' ){\ |
||
3557 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
3558 | }\ |
||
3559 | else\ |
||
3560 | {\ |
||
3561 | return reply +\"\\n\"+input_reply;\ |
||
3562 | }\ |
||
3563 | }\ |
||
3564 | else\ |
||
3565 | {\ |
||
3566 | if( typeof userdraw_text != 'undefined' ){\ |
||
3567 | return reply +\"\\n\"+userdraw_text;\ |
||
3568 | }\ |
||
3569 | else\ |
||
3570 | {\ |
||
3571 | return reply;\ |
||
3572 | }\ |
||
3573 | };\ |
||
3574 | };\ |
||
3575 | this.read_canvas = read_canvas;\n\ |
||
7653 | schaersvoo | 3576 | <!-- end function 10 read_canvas() -->"); |
7614 | schaersvoo | 3577 | break; |
3578 | case 11: fprintf(js_include_file,"\ |
||
7653 | schaersvoo | 3579 | \n<!-- begin function 11 read_canvas() -->\n\ |
7614 | schaersvoo | 3580 | function read_canvas(){\ |
3581 | var reply = \"\";\ |
||
3582 | var p = 0;\ |
||
3583 | while(userdraw_x[p]){\ |
||
3584 | reply = reply + px2x(userdraw_x[p]) +\",\" + px2y(userdraw_y[p]) +\",\" + px2x(userdraw_x[p+1]) +\",\" + px2y(userdraw_y[p+1]) +\"\\n\" ;\ |
||
3585 | p = p+2;\ |
||
3586 | };\ |
||
3587 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
3588 | if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\ |
||
3589 | var p = 0;var input_reply = new Array();\ |
||
3590 | if( document.getElementById(\"canvas_input0\")){\ |
||
3591 | var t = 0;\ |
||
3592 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
3593 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
3594 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
3595 | p++;\ |
||
3596 | };\ |
||
3597 | t++;\ |
||
3598 | };\ |
||
3599 | };\ |
||
3600 | if( typeof userdraw_text != 'undefined' ){\ |
||
3601 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
3602 | }\ |
||
3603 | else\ |
||
3604 | {\ |
||
3605 | return reply +\"\\n\"+input_reply;\ |
||
3606 | }\ |
||
3607 | }\ |
||
3608 | else\ |
||
3609 | {\ |
||
3610 | if( typeof userdraw_text != 'undefined' ){\ |
||
3611 | return reply +\"\\n\"+userdraw_text;\ |
||
3612 | }\ |
||
3613 | else\ |
||
3614 | {\ |
||
3615 | return reply;\ |
||
3616 | }\ |
||
3617 | };\ |
||
3618 | };\ |
||
3619 | this.read_canvas = read_canvas;\n\ |
||
7653 | schaersvoo | 3620 | <!-- end function 11 read_canvas() -->"); |
7614 | schaersvoo | 3621 | break; |
3622 | case 12: fprintf(js_include_file,"\ |
||
7653 | schaersvoo | 3623 | \n<!-- begin function 12 read_canvas() -->\n\ |
7614 | schaersvoo | 3624 | function read_canvas(){\ |
3625 | var reply = \"\";\ |
||
3626 | var p = 0;\ |
||
3627 | for(p = 0; p< userdraw_x.lenght;p = p+2){\ |
||
3628 | if(userdraw_x[p] != null){\ |
||
3629 | reply = reply + userdraw_x[p] +\",\" + userdraw_y[p] +\",\" + userdraw_x[p+1] +\",\" + userdraw_y[p+1] +\"\\n\" ;\ |
||
3630 | };\ |
||
3631 | };\ |
||
3632 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
3633 | if( document.getElementById(\"canvas_input0\") ){\ |
||
3634 | var p = 0;var input_reply = new Array();\ |
||
3635 | if( document.getElementById(\"canvas_input0\")){\ |
||
3636 | var t = 0;\ |
||
3637 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
3638 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
3639 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
3640 | p++;\ |
||
3641 | };\ |
||
3642 | t++;\ |
||
3643 | };\ |
||
3644 | };\ |
||
3645 | if( typeof userdraw_text != 'undefined' ){\ |
||
3646 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
3647 | }\ |
||
3648 | else\ |
||
3649 | {\ |
||
3650 | return reply +\"\\n\"+input_reply;\ |
||
3651 | }\ |
||
3652 | }\ |
||
3653 | else\ |
||
3654 | {\ |
||
3655 | if( typeof userdraw_text != 'undefined' ){\ |
||
3656 | return reply +\"\\n\"+userdraw_text\ |
||
3657 | }\ |
||
3658 | else\ |
||
3659 | {\ |
||
3660 | return reply;\ |
||
3661 | }\ |
||
3662 | };\ |
||
3663 | };\ |
||
3664 | this.read_canvas = read_canvas;\n\ |
||
7653 | schaersvoo | 3665 | <!-- end function 12 read_canvas() -->"); |
7614 | schaersvoo | 3666 | break; |
3667 | case 13: fprintf(js_include_file,"\ |
||
7653 | schaersvoo | 3668 | \n<!-- begin function 13 read_canvas() -->\n\ |
7614 | schaersvoo | 3669 | function read_canvas(){\ |
3670 | var reply = new Array();\ |
||
3671 | var p = 0;var i = 0;\ |
||
3672 | while(userdraw_x[p]){\ |
||
3673 | reply[i] = px2x(userdraw_x[p]) +\":\" + px2y(userdraw_y[p]) +\":\" + px2x(userdraw_x[p+1]) +\":\" + px2y(userdraw_y[p+1]);\ |
||
3674 | p = p+2;i++;\ |
||
3675 | };\ |
||
3676 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
3677 | if( document.getElementById(\"canvas_input0\") ){\ |
||
3678 | var p = 0;var input_reply = new Array();\ |
||
3679 | if( document.getElementById(\"canvas_input0\")){\ |
||
3680 | var t = 0;\ |
||
3681 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
3682 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
3683 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
3684 | p++;\ |
||
3685 | };\ |
||
3686 | t++;\ |
||
3687 | };\ |
||
3688 | };\ |
||
3689 | if( typeof userdraw_text != 'undefined' ){\ |
||
3690 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
3691 | }\ |
||
3692 | else\ |
||
3693 | {\ |
||
3694 | return reply +\"\\n\"+input_reply;\ |
||
3695 | }\ |
||
3696 | }\ |
||
3697 | else\ |
||
3698 | {\ |
||
3699 | if( typeof userdraw_text != 'undefined' ){\ |
||
3700 | return reply +\"\\n\"+userdraw_text\ |
||
3701 | }\ |
||
3702 | else\ |
||
3703 | {\ |
||
3704 | return reply;\ |
||
3705 | }\ |
||
3706 | };\ |
||
3707 | };\ |
||
3708 | this.read_canvas = read_canvas;\n\ |
||
7653 | schaersvoo | 3709 | <!-- end function 13 read_canvas() -->"); |
7614 | schaersvoo | 3710 | break; |
3711 | case 14: fprintf(js_include_file,"\ |
||
7653 | schaersvoo | 3712 | \n<!-- begin function 14 read_canvas() -->\n\ |
7614 | schaersvoo | 3713 | function read_canvas(){\ |
3714 | var reply = new Array();\ |
||
3715 | var p = 0;var i = 0;\ |
||
3716 | while(userdraw_x[p]){\ |
||
3717 | reply[i] = userdraw_x[p] +\":\" + userdraw_y[p] +\":\" + userdraw_x[p+1] +\":\" + userdraw_y[p+1];\ |
||
3718 | p = p+2;i++;\ |
||
3719 | };\ |
||
3720 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
3721 | if( document.getElementById(\"canvas_input0\") ){\ |
||
3722 | var p = 0;var input_reply = new Array();\ |
||
3723 | if( document.getElementById(\"canvas_input0\")){\ |
||
3724 | var t = 0;\ |
||
3725 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
3726 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
3727 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
3728 | p++;\ |
||
3729 | };\ |
||
3730 | t++;\ |
||
3731 | };\ |
||
3732 | };\ |
||
3733 | if( typeof userdraw_text != 'undefined' ){\ |
||
3734 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
3735 | }\ |
||
3736 | else\ |
||
3737 | {\ |
||
3738 | return reply +\"\\n\"+input_reply;\ |
||
3739 | }\ |
||
3740 | }\ |
||
3741 | else\ |
||
3742 | {\ |
||
3743 | if( typeof userdraw_text != 'undefined' ){\ |
||
3744 | return reply +\"\\n\"+userdraw_text;\ |
||
3745 | }\ |
||
3746 | else\ |
||
3747 | {\ |
||
3748 | return reply;\ |
||
3749 | }\ |
||
3750 | };\ |
||
3751 | };\ |
||
3752 | this.read_canvas = read_canvas;\n\ |
||
7653 | schaersvoo | 3753 | <!-- end function 14 read_canvas() -->"); |
7614 | schaersvoo | 3754 | break; |
3755 | case 15: fprintf(js_include_file,"\ |
||
7653 | schaersvoo | 3756 | \n<!-- begin function 15 read_canvas() -->\n\ |
7614 | schaersvoo | 3757 | function read_canvas(){\ |
3758 | var input_reply = new Array();\ |
||
3759 | var p = 0;\ |
||
3760 | if( document.getElementById(\"canvas_input0\")){\ |
||
3761 | var t = 0;\ |
||
3762 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
3763 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
3764 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
3765 | p++;\ |
||
3766 | };\ |
||
3767 | t++;\ |
||
3768 | };\ |
||
3769 | };\ |
||
3770 | if( typeof userdraw_text != 'undefined' ){\ |
||
3771 | return input_reply +\"\\n\"+userdraw_text;\ |
||
3772 | }\ |
||
3773 | else\ |
||
3774 | {\ |
||
3775 | return input_reply;\ |
||
3776 | };\ |
||
3777 | };\ |
||
3778 | this.read_canvas = read_canvas;\n\ |
||
7653 | schaersvoo | 3779 | <!-- end function 15 read_canvas() -->"); |
7614 | schaersvoo | 3780 | break; |
3781 | case 16: fprintf(js_include_file,"\ |
||
7653 | schaersvoo | 3782 | \n<!-- begin function 16 read_mathml() -->\n\ |
7614 | schaersvoo | 3783 | function read_mathml(){\ |
3784 | var reply = new Array();\ |
||
3785 | var p = 0;\ |
||
3786 | if( document.getElementById(\"mathml0\")){\ |
||
3787 | while(document.getElementById(\"mathml\"+p)){\ |
||
3788 | reply[p] = document.getElementById(\"mathml\"+p).value;\ |
||
3789 | p++;\ |
||
3790 | };\ |
||
3791 | };\ |
||
3792 | return reply;\ |
||
3793 | };\ |
||
3794 | this.read_mathml = read_mathml;\n\ |
||
7653 | schaersvoo | 3795 | <!-- end function 16 read_mathml() -->"); |
7614 | schaersvoo | 3796 | break; |
3797 | case 17: fprintf(js_include_file,"\ |
||
7653 | schaersvoo | 3798 | \n<!-- begin function 17 read_canvas() -->\n\ |
7614 | schaersvoo | 3799 | function read_canvas(){\ |
3800 | if( userdraw_text.length == 0){alert(\"no text typed...\");return;}\ |
||
3801 | return userdraw_text;\ |
||
3802 | };\ |
||
3803 | this.read_canvas = read_canvas;\n\ |
||
7653 | schaersvoo | 3804 | <!-- end function 17 read_canvas() -->"); |
7614 | schaersvoo | 3805 | break; |
3806 | case 18: fprintf(js_include_file,"\ |
||
7653 | schaersvoo | 3807 | \n<!-- begin function 18 read_canvas() -->\n\ |
7614 | schaersvoo | 3808 | function read_canvas(){\ |
3809 | var p = 0;\ |
||
3810 | var reply = new Array();\ |
||
3811 | var name;\ |
||
3812 | var t = true;\ |
||
3813 | while(t){\ |
||
3814 | try{ name = eval('clocks'+p);\ |
||
3815 | 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;};\ |
||
3816 | };\ |
||
3817 | if( p == 0){alert(\"clock(s) not modified...\");return;}\ |
||
3818 | return reply;\ |
||
3819 | };\ |
||
3820 | this.read_canvas = read_canvas;\n\ |
||
7653 | schaersvoo | 3821 | <!-- end function 18 read_canvas() -->"); |
7614 | schaersvoo | 3822 | break; |
3823 | case 19: fprintf(js_include_file,"\ |
||
7653 | schaersvoo | 3824 | \n<!-- begin function 19 read_canvas() -->\n\ |
7614 | schaersvoo | 3825 | function read_canvas(){\ |
3826 | return reply[0];\ |
||
3827 | };\ |
||
3828 | this.read_canvas = read_canvas;\n\ |
||
7653 | schaersvoo | 3829 | <!-- end function 19 read_canvas() -->"); |
7614 | schaersvoo | 3830 | case 20: fprintf(js_include_file,"\ |
7653 | schaersvoo | 3831 | \n<!-- begin function 20 read_canvas() -->\n\ |
7614 | schaersvoo | 3832 | function read_canvas(){\ |
3833 | var len = ext_drag_images.length;\ |
||
3834 | var reply = new Array(len);\ |
||
3835 | for(var p = 0 ; p < len ; p++){\ |
||
3836 | var img = ext_drag_images[p];\ |
||
3837 | reply[p] = px2x(img[6])+\":\"+px2y(img[7]);\ |
||
3838 | };\ |
||
3839 | return reply;\ |
||
3840 | };\ |
||
3841 | this.read_canvas = read_canvas;\n\ |
||
7653 | schaersvoo | 3842 | <!-- end function 20 read_canvas() -->"); |
7614 | schaersvoo | 3843 | break; |
3844 | case 21: fprintf(js_include_file,"\ |
||
7653 | schaersvoo | 3845 | \n<!-- begin function 21 read_canvas() -->\n\ |
7614 | schaersvoo | 3846 | function read_canvas(){\ |
3847 | if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\ |
||
3848 | var reply_coord = new Array();var p = 0;\ |
||
3849 | while(userdraw_x[p]){\ |
||
3850 | reply_coord[p] = \"(\"+px2x(userdraw_x[p])+\":\"+px2y(userdraw_y[p])+\")\";\ |
||
3851 | p++;\ |
||
3852 | };\ |
||
3853 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
3854 | if( document.getElementById(\"canvas_input0\") ){\ |
||
3855 | var p = 0;var input_reply = new Array();\ |
||
3856 | if( document.getElementById(\"canvas_input0\")){\ |
||
3857 | var t = 0;\ |
||
3858 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
3859 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
3860 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
3861 | p++;\ |
||
3862 | };\ |
||
3863 | t++;\ |
||
3864 | };\ |
||
3865 | };\ |
||
3866 | if( typeof userdraw_text != 'undefined' ){\ |
||
3867 | return reply_coord+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
3868 | }\ |
||
3869 | else\ |
||
3870 | {\ |
||
3871 | return reply_coord+\"\\n\"+input_reply;\ |
||
3872 | }\ |
||
3873 | }\ |
||
3874 | else\ |
||
3875 | {\ |
||
3876 | if( typeof userdraw_text != 'undefined' ){\ |
||
3877 | return reply_coord+\"\\n\"+userdraw_text;\ |
||
3878 | }\ |
||
3879 | else\ |
||
3880 | {\ |
||
3881 | return reply_coord;\ |
||
3882 | };\ |
||
3883 | };\ |
||
3884 | };\ |
||
3885 | this.read_canvas = read_canvas;\n\ |
||
7653 | schaersvoo | 3886 | <!-- end function 21 read_canvas() -->"); |
7614 | schaersvoo | 3887 | break; |
3888 | case 22: fprintf(js_include_file,"\ |
||
7653 | schaersvoo | 3889 | \n<!-- begin function 22 read_canvas() -->\n\ |
7614 | schaersvoo | 3890 | function read_canvas(){\ |
3891 | var reply = new Array();\ |
||
3892 | var p = 0;\ |
||
3893 | var idx = 0;\ |
||
3894 | while(userdraw_x[p]){\ |
||
3895 | reply[idx] = px2x(userdraw_x[p]);\ |
||
3896 | idx++;\ |
||
3897 | reply[idx] = px2y(userdraw_y[p]);\ |
||
3898 | idx++;p++;\ |
||
3899 | };\ |
||
3900 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
3901 | if( document.getElementById(\"canvas_input0\") ){\ |
||
3902 | var p = 0;var input_reply = new Array();\ |
||
3903 | if( document.getElementById(\"canvas_input0\")){\ |
||
3904 | var t = 0;\ |
||
3905 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
3906 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
3907 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
3908 | p++;\ |
||
3909 | };\ |
||
3910 | t++;\ |
||
3911 | };\ |
||
3912 | };\ |
||
3913 | if( typeof userdraw_text != 'undefined' ){\ |
||
3914 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
3915 | }\ |
||
3916 | else\ |
||
3917 | {\ |
||
3918 | return reply +\"\\n\"+input_reply;\ |
||
3919 | }\ |
||
3920 | }\ |
||
3921 | else\ |
||
3922 | {\ |
||
3923 | if( typeof userdraw_text != 'undefined' ){\ |
||
3924 | return reply +\"\\n\"+userdraw_text;\ |
||
3925 | }\ |
||
3926 | else\ |
||
3927 | {\ |
||
3928 | return reply;\ |
||
3929 | }\ |
||
3930 | };\ |
||
3931 | };\ |
||
3932 | this.read_canvas = read_canvas;\n\ |
||
7653 | schaersvoo | 3933 | <!-- end function 22 read_canvas() -->"); |
7614 | schaersvoo | 3934 | break; |
7782 | schaersvoo | 3935 | case 23: fprintf(js_include_file,"\ |
3936 | \n<!-- begin function 23 read_canvas() default 5 px marge -->\n\ |
||
3937 | function read_canvas(){\ |
||
3938 | if( userdraw_x.length < 2){alert(\"nothing drawn...\");return;}\ |
||
3939 | var reply_x = new Array();var reply_y = new Array();var p = 0;\ |
||
3940 | var lu = userdraw_x.length;\ |
||
3941 | if( lu != userdraw_y.length ){ alert(\"x / y mismatch !\");return;}\ |
||
3942 | var marge = 5;\ |
||
3943 | reply_x[p] = px2x(userdraw_x[0]);reply_y[p] = px2y(userdraw_y[0]);p++;\ |
||
3944 | for(var i = 0; i < lu - 1 ; i++ ){\ |
||
3945 | if( (userdraw_x[i] < (userdraw_x[i+1] + marge)) && (userdraw_x[i] > (userdraw_x[i+1] - marge)) ){\ |
||
3946 | if( (userdraw_y[i] < (userdraw_y[i+1] + marge)) && (userdraw_y[i] > (userdraw_y[i+1] - marge)) ){\ |
||
3947 | reply_x[p] = px2x(userdraw_x[i]);reply_y[p] = px2y(userdraw_y[i]);\ |
||
3948 | if( isNaN(reply_x[p]) || isNaN(reply_y[p]) ){ alert(\"hmmmm ?\");return; };\ |
||
3949 | p++;\ |
||
3950 | };\ |
||
3951 | };\ |
||
3952 | };\ |
||
3953 | if( document.getElementById(\"canvas_input0\")){\ |
||
3954 | var p = 0;var input_reply = new Array();\ |
||
3955 | if( document.getElementById(\"canvas_input0\")){\ |
||
3956 | var t = 0;\ |
||
3957 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
3958 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
3959 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
3960 | p++;\ |
||
3961 | };\ |
||
3962 | t++;\ |
||
3963 | };\ |
||
3964 | };\ |
||
3965 | if( typeof userdraw_text != 'undefined' ){\ |
||
3966 | return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
3967 | }\ |
||
3968 | else\ |
||
3969 | {\ |
||
3970 | return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply;\ |
||
3971 | }\ |
||
3972 | }\ |
||
3973 | else\ |
||
3974 | {\ |
||
3975 | if( typeof userdraw_text != 'undefined' ){\ |
||
3976 | return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_text;\ |
||
3977 | }\ |
||
3978 | else\ |
||
3979 | {\ |
||
3980 | return reply_x+\"\\n\"+reply_y;\ |
||
3981 | };\ |
||
3982 | };\ |
||
3983 | };\ |
||
3984 | this.read_canvas = read_canvas;\n\ |
||
3985 | <!-- end function 23 read_canvas() -->"); |
||
3986 | break; |
||
7614 | schaersvoo | 3987 | |
3988 | default: canvas_error("hmmm unknown replyformat...");break; |
||
3989 | } |
||
3990 | return; |
||
3991 | } |
||
3992 | |||
3993 | |||
3994 | /* |
||
3995 | add drawfunction : |
||
3996 | - functions used by userdraw_primitives (circle,rect,path,triangle...) |
||
3997 | - things not covered by the drag&drop library (static objects like parallel, lattice ,gridfill , imagefill) |
||
3998 | - grid / mathml |
||
3999 | - will not scale or zoom in |
||
4000 | - will not be filled via pixel operations like fill / floodfill / filltoborder / clickfill |
||
4001 | - is printed directly into 'js_include_file' |
||
4002 | */ |
||
4003 | |||
4004 | void add_javascript_functions(int js_functions[],int canvas_root_id){ |
||
4005 | int i; |
||
4006 | for(i = 0 ; i < MAX_JS_FUNCTIONS; i++){ |
||
4007 | if( js_functions[i] == 1){ |
||
4008 | switch(i){ |
||
4009 | case DRAG_EXTERNAL_IMAGE: |
||
4010 | fprintf(js_include_file,"\n<!-- drag external images --->\n\ |
||
7653 | schaersvoo | 4011 | var external_canvas = create_canvas%d(7,xsize,ysize);\ |
4012 | var external_ctx = external_canvas.getContext(\"2d\");\ |
||
4013 | var external_canvas_rect = external_canvas.getBoundingClientRect();\ |
||
4014 | canvas_div.addEventListener(\"mousedown\",setxy,false);\ |
||
4015 | canvas_div.addEventListener(\"mouseup\",dragstop,false);\ |
||
4016 | canvas_div.addEventListener(\"mousemove\",dragxy,false);\ |
||
4017 | var selected_image = null;\ |
||
4018 | var ext_image_cnt = 0;\ |
||
4019 | var ext_drag_images = new Array();\ |
||
4020 | function drag_external_image(URL,sx,sy,swidth,sheight,x0,y0,width,height,idx,draggable){\ |
||
4021 | ext_image_cnt = idx;\ |
||
4022 | var image = new Image();\ |
||
4023 | image.src = URL;\ |
||
4024 | image.onload = function(){\ |
||
4025 | if( x0 < 1 ){ x0 = 0; };if( y0 < 1 ){ y0 = 0; };if( sx < 1 ){ sx = 0; };if( sy < 1 ){ sy = 0; };\ |
||
4026 | if( width < 1 ){ width = image.width; };if( height < 1 ){ height = image.height; };\ |
||
4027 | if( swidth < 1 ){ swidth = image.width; };if( sheight < 1 ){ sheight = image.height; };\ |
||
4028 | img = new Array(10);\ |
||
4029 | img[0] = draggable;img[1] = image;img[2] = sx;img[3] = sy;img[4] = swidth;img[5] = sheight;\ |
||
4030 | img[6] = x0;img[7] = y0;img[8] = width;img[9] = height;\ |
||
4031 | ext_drag_images[idx] = img;\ |
||
4032 | external_ctx.drawImage(img[1],img[2],img[3],img[4],img[5],img[6],img[7],img[8],img[9]);\ |
||
4033 | };\ |
||
4034 | };\ |
||
4035 | function dragstop(evt){\ |
||
4036 | selected_image = null;return;\ |
||
4037 | };\ |
||
4038 | function dragxy(evt){\ |
||
4039 | if( selected_image != null ){\ |
||
4040 | var xoff = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);\ |
||
4041 | var yoff = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);\ |
||
4042 | var s_img = ext_drag_images[selected_image];\ |
||
4043 | s_img[6] = evt.clientX - external_canvas_rect.left + xoff;\ |
||
4044 | s_img[7] = evt.clientY - external_canvas_rect.top + yoff;\ |
||
4045 | ext_drag_images[selected_image] = s_img;\ |
||
4046 | external_ctx.clearRect(0,0,xsize,ysize);\ |
||
4047 | for(var i = 0; i <= ext_image_cnt ; i++){\ |
||
4048 | var img = ext_drag_images[i];\ |
||
4049 | external_ctx.drawImage(img[1],img[2],img[3],img[4],img[5],img[6],img[7],img[8],img[9]);\ |
||
4050 | };\ |
||
4051 | };\ |
||
4052 | };\ |
||
4053 | function setxy(evt){\ |
||
4054 | if( ! selected_image && evt.which == 1 ){\ |
||
4055 | var xoff = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);\ |
||
4056 | var yoff = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);\ |
||
4057 | var xm = evt.clientX - external_canvas_rect.left + xoff;\ |
||
4058 | var ym = evt.clientY - external_canvas_rect.top + yoff;\ |
||
4059 | for(var p = 0 ; p <= ext_image_cnt ; p++){\ |
||
4060 | var img = ext_drag_images[p];\ |
||
4061 | if( img[0] == 1 ){\ |
||
4062 | var w = img.width;\ |
||
4063 | var h = img.height;\ |
||
4064 | if( xm > img[6] && xm < img[6] + img[4]){\ |
||
4065 | if( ym > img[7] && ym < img[7] + img[5]){\ |
||
4066 | img[6] = xm;\ |
||
4067 | img[7] = ym;\ |
||
4068 | ext_drag_images[p] = img;\ |
||
4069 | selected_image = p;\ |
||
4070 | dragxy(evt);\ |
||
4071 | };\ |
||
4072 | };\ |
||
4073 | };\ |
||
4074 | };\ |
||
4075 | }\ |
||
4076 | else\ |
||
4077 | {\ |
||
4078 | selected_image = null;\ |
||
4079 | };\ |
||
7614 | schaersvoo | 4080 | };",canvas_root_id); |
4081 | break; |
||
4082 | |||
4083 | case DRAW_EXTERNAL_IMAGE: |
||
4084 | fprintf(js_include_file,"\n<!-- draw external images -->\n\ |
||
4085 | draw_external_image = function(URL,sx,sy,swidth,sheight,x0,y0,width,height,draggable){\ |
||
4086 | var image = new Image();\ |
||
4087 | image.src = URL;\ |
||
4088 | var canvas_bg_div = document.getElementById(\"canvas_div%d\");\ |
||
4089 | image.onload = function(){\ |
||
4090 | if( x0 < 1 ){ x0 = 0; };\ |
||
4091 | if( y0 < 1 ){ y0 = 0; };\ |
||
4092 | if( sx < 1 ){ sx = 0; };\ |
||
4093 | if( sy < 1 ){ sy = 0; };\ |
||
4094 | if( width < 1 ){ width = image.width;};\ |
||
4095 | if( height < 1 ){ height = image.height;};\ |
||
4096 | if( swidth < 1 ){ swidth = image.width;};\ |
||
4097 | if( sheight < 1 ){ sheight = image.height;};\ |
||
4098 | var ml = x0 - sx;\ |
||
4099 | var mh = y0 - sy;\ |
||
4100 | canvas_bg_div.style.backgroundPosition= \"left \"+ml+\"px top \"+mh+\"px\";\ |
||
4101 | canvas_bg_div.style.backgroundSize = width+\"px \"+height+\"px\";\ |
||
4102 | canvas_bg_div.style.backgroundRepeat = \"no-repeat\";\ |
||
4103 | canvas_bg_div.style.backgroundPosition= sx+\"px \"+sy+\"px\";\ |
||
4104 | canvas_bg_div.style.backgroundImage = \"url(\" + URL + \")\";\ |
||
4105 | };\ |
||
7653 | schaersvoo | 4106 | };",canvas_root_id); |
7614 | schaersvoo | 4107 | break; |
4108 | |||
4109 | case DRAW_ZOOM_BUTTONS: /* 6 rectangles 15x15 px forbidden zone for drawing : y < ysize - 15*/ |
||
4110 | fprintf(js_include_file,"\n<!-- draw zoom buttons -->\n\ |
||
4111 | draw_zoom_buttons = function(canvas_type,color,opacity){\ |
||
4112 | var obj;\ |
||
4113 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
4114 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
4115 | }\ |
||
4116 | else\ |
||
4117 | {\ |
||
4118 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
4119 | };\ |
||
4120 | var ctx = obj.getContext(\"2d\");\ |
||
4121 | ctx.font =\"18px Ariel\";\ |
||
4122 | ctx.textAlign = \"right\";\ |
||
4123 | ctx.fillStyle=\"rgba(\"+color+\",\"+opacity+\")\";\ |
||
4124 | ctx.fillText(\"+\",xsize,ysize);\ |
||
4125 | ctx.fillText(\"\\u2212\",xsize - 15,ysize);\ |
||
4126 | ctx.fillText(\"\\u2192\",xsize - 30,ysize-2);\ |
||
4127 | ctx.fillText(\"\\u2190\",xsize - 45,ysize-2);\ |
||
4128 | ctx.fillText(\"\\u2191\",xsize - 60,ysize-2);\ |
||
4129 | ctx.fillText(\"\\u2193\",xsize - 75,ysize-2);\ |
||
4130 | ctx.fillText(\"\\u00D7\",xsize - 90,ysize-2);\ |
||
4131 | ctx.stroke();\ |
||
7653 | schaersvoo | 4132 | };",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 4133 | |
4134 | break; |
||
4135 | case DRAW_GRIDFILL:/* not used for userdraw */ |
||
4136 | fprintf(js_include_file,"\n<!-- draw gridfill -->\n\ |
||
4137 | draw_gridfill = function(canvas_type,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize){\ |
||
4138 | var obj;\ |
||
4139 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
4140 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
4141 | }\ |
||
4142 | else\ |
||
4143 | {\ |
||
4144 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
4145 | };\ |
||
4146 | var ctx = obj.getContext(\"2d\");\ |
||
4147 | var x,y;\ |
||
4148 | ctx.save();\ |
||
4149 | ctx.strokeStyle=\"rgba(\"+color+\",\"+opacity+\")\";\ |
||
7645 | schaersvoo | 4150 | snap_x = dx;snap_y = dy;\ |
7614 | schaersvoo | 4151 | for( x = x0 ; x < xsize+dx ; x = x + dx ){\ |
4152 | ctx.moveTo(x,y0);\ |
||
4153 | ctx.lineTo(x,ysize);\ |
||
4154 | };\ |
||
7645 | schaersvoo | 4155 | for( y = y0 ; y < ysize+dy; y = y + dy ){\ |
7614 | schaersvoo | 4156 | ctx.moveTo(x0,y);\ |
4157 | ctx.lineTo(xsize,y);\ |
||
4158 | };\ |
||
4159 | ctx.stroke();\ |
||
4160 | ctx.restore();\ |
||
7653 | schaersvoo | 4161 | return;};",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 4162 | break; |
4163 | |||
4164 | case DRAW_IMAGEFILL:/* not used for userdraw */ |
||
4165 | fprintf(js_include_file,"\n<!-- draw imagefill -->\n\ |
||
4166 | draw_imagefill = function(canvas_type,x0,y0,URL,xsize,ysize){\ |
||
4167 | var obj;\ |
||
4168 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
4169 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
4170 | }\ |
||
4171 | else\ |
||
4172 | {\ |
||
4173 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
4174 | };\ |
||
4175 | var ctx = obj.getContext(\"2d\");\ |
||
4176 | ctx.save();\ |
||
4177 | var img = new Image();\ |
||
4178 | img.src = URL;\ |
||
4179 | img.onload = function(){\ |
||
4180 | if( (img.width > xsize-x0) && (img.height > ysize-y0) ){\ |
||
4181 | ctx.drawImage(img,x0,y0,xsize,ysize);\ |
||
4182 | }\ |
||
4183 | else\ |
||
4184 | {\ |
||
4185 | var repeat = \"repeat\";\ |
||
4186 | if(img.width > xsize - x0){\ |
||
4187 | repeat = \"repeat-y\";\ |
||
4188 | }\ |
||
4189 | else\ |
||
4190 | {\ |
||
4191 | if( img.height > ysize -x0 ){\ |
||
4192 | repeat = \"repeat-x\";\ |
||
4193 | }\ |
||
4194 | }\ |
||
4195 | var pattern = ctx.createPattern(img,repeat);\ |
||
4196 | ctx.rect(x0,y0,xsize,ysize);\ |
||
4197 | ctx.fillStyle = pattern;\ |
||
4198 | }\ |
||
4199 | ctx.fill();\ |
||
4200 | };\ |
||
4201 | ctx.restore();\ |
||
4202 | return;\ |
||
7653 | schaersvoo | 4203 | };",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 4204 | break; |
4205 | |||
4206 | case DRAW_DOTFILL:/* not used for userdraw */ |
||
4207 | fprintf(js_include_file,"\n<!-- draw dotfill -->\n\ |
||
4208 | draw_dotfill = function(canvas_type,x0,y0,dx,dy,radius,color,opacity,xsize,ysize){\ |
||
4209 | var obj;\ |
||
4210 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
4211 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
4212 | }\ |
||
4213 | else\ |
||
4214 | {\ |
||
4215 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
4216 | };\ |
||
4217 | var ctx = obj.getContext(\"2d\");\ |
||
4218 | var x,y;\ |
||
4219 | ctx.closePath();\ |
||
4220 | ctx.save();\ |
||
7645 | schaersvoo | 4221 | snap_x = dx;snap_y = dy;\ |
7614 | schaersvoo | 4222 | ctx.fillStyle=\"rgba(\"+color+\",\"+opacity+\")\";\ |
4223 | for( x = x0 ; x < xsize+dx ; x = x + dx ){\ |
||
4224 | for( y = y0 ; y < ysize+dy ; y = y + dy ){\ |
||
4225 | ctx.arc(x,y,radius,0,2*Math.PI,false);\ |
||
4226 | ctx.closePath();\ |
||
4227 | }\ |
||
4228 | }\ |
||
4229 | ctx.fill();\ |
||
4230 | ctx.restore();\ |
||
7653 | schaersvoo | 4231 | return;};",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 4232 | break; |
7645 | schaersvoo | 4233 | |
7647 | schaersvoo | 4234 | case DRAW_DIAMONDFILL:/* not used for userdraw */ |
7614 | schaersvoo | 4235 | fprintf(js_include_file,"\n<!-- draw hatch fill -->\n\ |
7647 | schaersvoo | 4236 | draw_diamondfill = function(canvas_type,x0,y0,dx,dy,linewidth,stroke_color,stroke_opacity,xsize,ysize){\ |
7614 | schaersvoo | 4237 | var obj;\ |
4238 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
4239 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
4240 | }\ |
||
4241 | else\ |
||
4242 | {\ |
||
4243 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
4244 | };\ |
||
4245 | var ctx = obj.getContext(\"2d\");\ |
||
4246 | var x;\ |
||
4247 | var y;\ |
||
4248 | ctx.save();\ |
||
4249 | ctx.lineWidth = linewidth;\ |
||
4250 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
4251 | y = ysize;\ |
||
4252 | for( x = x0 ; x < xsize ; x = x + dx ){\ |
||
4253 | ctx.moveTo(x,y0);\ |
||
4254 | ctx.lineTo(xsize,y);\ |
||
4255 | y = y - dy;\ |
||
4256 | };\ |
||
4257 | y = y0;\ |
||
4258 | for( x = xsize ; x > 0 ; x = x - dx){\ |
||
4259 | ctx.moveTo(x,ysize);\ |
||
4260 | ctx.lineTo(x0,y);\ |
||
4261 | y = y + dy;\ |
||
4262 | };\ |
||
4263 | x = x0;\ |
||
4264 | for( y = y0 ; y < ysize ; y = y + dy ){\ |
||
4265 | ctx.moveTo(xsize,y);\ |
||
4266 | ctx.lineTo(x,ysize);\ |
||
4267 | x = x + dx;\ |
||
4268 | };\ |
||
4269 | x = xsize;\ |
||
4270 | for( y = ysize ; y > y0 ; y = y - dy ){\ |
||
4271 | ctx.moveTo(x,y0);\ |
||
4272 | ctx.lineTo(x0,y);\ |
||
4273 | x = x - dx;\ |
||
4274 | };\ |
||
4275 | ctx.stroke();\ |
||
4276 | ctx.restore();\ |
||
4277 | return;\ |
||
7653 | schaersvoo | 4278 | }",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 4279 | break; |
7647 | schaersvoo | 4280 | |
4281 | case DRAW_HATCHFILL:/* not used for userdraw */ |
||
4282 | fprintf(js_include_file,"\n<!-- draw hatch fill -->\n\ |
||
4283 | draw_hatchfill = function(canvas_type,x0,y0,dx,dy,linewidth,stroke_color,stroke_opacity,xsize,ysize){\ |
||
4284 | var obj;\ |
||
4285 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
4286 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
4287 | }\ |
||
4288 | else\ |
||
4289 | {\ |
||
4290 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
4291 | };\ |
||
4292 | var ctx = obj.getContext(\"2d\");\ |
||
4293 | var x;\ |
||
4294 | var y;\ |
||
4295 | ctx.save();\ |
||
4296 | ctx.lineWidth = linewidth;\ |
||
4297 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
4298 | y = ysize;\ |
||
4299 | for( x = x0 ; x < xsize ; x = x + dx ){\ |
||
4300 | ctx.moveTo(x,y0);\ |
||
4301 | ctx.lineTo(xsize,y);\ |
||
4302 | y = y - dy;\ |
||
4303 | };\ |
||
4304 | y = y0;\ |
||
4305 | for( x = xsize ; x >= dx ; x = x - dx){\ |
||
4306 | ctx.moveTo(x,ysize);\ |
||
4307 | ctx.lineTo(x0,y);\ |
||
4308 | y = y + dy;\ |
||
4309 | };\ |
||
4310 | ctx.stroke();\ |
||
4311 | ctx.restore();\ |
||
4312 | return;\ |
||
7653 | schaersvoo | 4313 | };",canvas_root_id,canvas_root_id,canvas_root_id); |
7647 | schaersvoo | 4314 | break; |
7614 | schaersvoo | 4315 | case DRAW_CIRCLES:/* used for userdraw */ |
4316 | fprintf(js_include_file,"\n<!-- draw circles -->\n\ |
||
4317 | 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){\ |
||
4318 | ctx.save();\ |
||
4319 | if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\ |
||
4320 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
||
4321 | ctx.lineWidth = line_width;\ |
||
4322 | for(var p = 0 ; p < x_points.length ; p++ ){\ |
||
4323 | ctx.beginPath();\ |
||
4324 | ctx.arc(x_points[p],y_points[p],radius[p],0,2*Math.PI,false);\ |
||
4325 | ctx.closePath();\ |
||
4326 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
4327 | if(use_filled == 1){ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();}\ |
||
4328 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
4329 | ctx.stroke();\ |
||
4330 | }\ |
||
4331 | ctx.restore();\ |
||
4332 | return;\ |
||
7653 | schaersvoo | 4333 | };"); |
7614 | schaersvoo | 4334 | break; |
7663 | schaersvoo | 4335 | case DRAW_POLYLINE:/* user for userdraw : draw lines through points */ |
4336 | fprintf(js_include_file,"\n<!-- draw polyline -->\n\ |
||
4337 | draw_polyline = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_translate,vector){\ |
||
4338 | ctx.save();\ |
||
4339 | if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\ |
||
4340 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
||
4341 | ctx.lineWidth = line_width;\ |
||
4342 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
4343 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
4344 | ctx.clearRect(0,0,xsize,ysize);\ |
||
4345 | ctx.beginPath();\ |
||
4346 | for(var p = 0 ; p < x_points.length-1 ; p++ ){\ |
||
4347 | ctx.moveTo(x_points[p],y_points[p]);\ |
||
4348 | ctx.lineTo(x_points[p+1],y_points[p+1]);\ |
||
4349 | }\ |
||
4350 | ctx.closePath();\ |
||
4351 | ctx.stroke();\ |
||
4352 | ctx.fillStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
4353 | for(var p = 0 ; p < x_points.length ; p++ ){\ |
||
4354 | ctx.beginPath();\ |
||
4355 | ctx.arc(x_points[p],y_points[p],line_width,0,2*Math.PI,false);\ |
||
4356 | ctx.closePath();ctx.fill();ctx.stroke();\ |
||
4357 | };\ |
||
4358 | ctx.restore();\ |
||
4359 | return;\ |
||
4360 | };"); |
||
4361 | break; |
||
7614 | schaersvoo | 4362 | |
4363 | case DRAW_SEGMENTS:/* used for userdraw */ |
||
4364 | fprintf(js_include_file,"\n<!-- draw segments -->\n\ |
||
4365 | draw_segments = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_translate,vector){\ |
||
4366 | ctx.save();\ |
||
4367 | if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\ |
||
4368 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
||
4369 | ctx.lineWidth = line_width;\ |
||
4370 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
4371 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
4372 | for(var p = 0 ; p < x_points.length ; p = p+2 ){\ |
||
4373 | ctx.beginPath();\ |
||
4374 | ctx.moveTo(x_points[p],y_points[p]);\ |
||
4375 | ctx.lineTo(x_points[p+1],y_points[p+1]);\ |
||
4376 | ctx.closePath();\ |
||
4377 | ctx.stroke();\ |
||
4378 | }\ |
||
4379 | ctx.restore();\ |
||
4380 | return;\ |
||
4381 | };"); |
||
4382 | break; |
||
4383 | |||
4384 | case DRAW_LINES:/* used for userdraw */ |
||
4385 | fprintf(js_include_file,"\n<!-- draw lines -->\n\ |
||
4386 | function calc_line(x1,x2,y1,y2){\ |
||
4387 | var marge = 2;\ |
||
4388 | if(x1 < x2+marge && x1>x2-marge){\ |
||
4389 | return [x1,0,x1,ysize];\ |
||
4390 | };\ |
||
4391 | if(y1 < y2+marge && y1>y2-marge){\ |
||
4392 | return [0,y1,xsize,y1];\ |
||
4393 | };\ |
||
4394 | var Y1 = y1 - (x1)*(y2 - y1)/(x2 - x1);\ |
||
4395 | var Y2 = y1 + (xsize - x1)*(y2 - y1)/(x2 - x1);\ |
||
4396 | return [0,Y1,xsize,Y2];\ |
||
4397 | };\ |
||
4398 | draw_lines = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_translate,vector){\ |
||
4399 | ctx.save();\ |
||
4400 | var line = new Array(4);\ |
||
4401 | if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\ |
||
4402 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
||
4403 | ctx.lineWidth = line_width;\ |
||
4404 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
4405 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
4406 | for(var p = 0 ; p < x_points.length ; p = p+2 ){\ |
||
4407 | line = calc_line(x_points[p],x_points[p+1],y_points[p],y_points[p+1]);\ |
||
4408 | ctx.beginPath();\ |
||
4409 | ctx.moveTo(line[0],line[1]);\ |
||
4410 | ctx.lineTo(line[2],line[3]);\ |
||
4411 | ctx.closePath();\ |
||
4412 | ctx.stroke();\ |
||
4413 | }\ |
||
4414 | ctx.restore();\ |
||
4415 | return;\ |
||
4416 | };"); |
||
4417 | break; |
||
4418 | |||
4419 | case DRAW_CROSSHAIRS:/* used for userdraw */ |
||
4420 | fprintf(js_include_file,"\n<!-- draw crosshairs -->\n\ |
||
4421 | draw_crosshairs = function(ctx,x_points,y_points,line_width,crosshair_size,stroke_color,stroke_opacity,use_rotate,angle,use_translate,vector){\ |
||
4422 | if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\ |
||
4423 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
||
4424 | ctx.lineWidth = line_width;\ |
||
4425 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
4426 | var x1,x2,y1,y2;\ |
||
4427 | for(var p = 0 ; p < x_points.length ; p++ ){\ |
||
4428 | x1 = x_points[p] - crosshair_size;\ |
||
4429 | x2 = x_points[p] + crosshair_size;\ |
||
4430 | y1 = y_points[p] - crosshair_size;\ |
||
4431 | y2 = y_points[p] + crosshair_size;\ |
||
4432 | ctx.beginPath();\ |
||
4433 | ctx.moveTo(x1,y1);\ |
||
4434 | ctx.lineTo(x2,y2);\ |
||
4435 | ctx.closePath();\ |
||
4436 | ctx.stroke();\ |
||
4437 | ctx.beginPath();\ |
||
4438 | ctx.moveTo(x2,y1);\ |
||
4439 | ctx.lineTo(x1,y2);\ |
||
4440 | ctx.closePath();\ |
||
4441 | ctx.stroke();\ |
||
4442 | }\ |
||
4443 | ctx.restore();\ |
||
4444 | return;\ |
||
7653 | schaersvoo | 4445 | };"); |
7614 | schaersvoo | 4446 | break; |
4447 | |||
4448 | case DRAW_RECTS:/* used for userdraw */ |
||
4449 | fprintf(js_include_file,"\n<!-- draw rects -->\n\ |
||
4450 | 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){\ |
||
4451 | ctx.save();\ |
||
4452 | if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\ |
||
4453 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
||
4454 | ctx.lineWidth = line_width;\ |
||
4455 | ctx.strokeStyle = \"rgba('+stroke_color+','+stroke_opacity+')\";\ |
||
4456 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];}};\ |
||
4457 | for(var p = 0 ; p < x_points.length ; p = p + 2){\ |
||
4458 | ctx.beginPath();\ |
||
4459 | ctx.rect(x_points[p],y_points[p],x_points[p+1]-x_points[p],y_points[p+1]-y_points[p]);\ |
||
4460 | ctx.closePath();\ |
||
4461 | if(use_filled == 1 ){ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();}\ |
||
4462 | ctx.stroke();\ |
||
4463 | };\ |
||
4464 | ctx.restore();\ |
||
4465 | return;\ |
||
7653 | schaersvoo | 4466 | };"); |
7614 | schaersvoo | 4467 | break; |
4468 | |||
4469 | case DRAW_ROUNDRECTS:/* used for userdraw */ |
||
4470 | fprintf(js_include_file,"\n<!-- draw round rects -->\n\ |
||
4471 | 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){\ |
||
4472 | ctx.save();\ |
||
4473 | if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\ |
||
4474 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
4475 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
||
4476 | var x,y,w,h,r;\ |
||
4477 | for(var p = 0; p < x_points.length; p = p+2){\ |
||
4478 | 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);\ |
||
4479 | ctx.beginPath();ctx.moveTo(x + r, y);\ |
||
4480 | ctx.lineTo(x + w - r, y);\ |
||
4481 | ctx.quadraticCurveTo(x + w, y, x + w, y + r);\ |
||
4482 | ctx.lineTo(x + w, y + h - r);\ |
||
4483 | ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);\ |
||
4484 | ctx.lineTo(x + r, y + h);\ |
||
4485 | ctx.quadraticCurveTo(x, y + h, x, y + h - r);\ |
||
4486 | ctx.lineTo(x, y + r);\ |
||
4487 | ctx.quadraticCurveTo(x, y, x + r, y);\ |
||
4488 | ctx.closePath();if( use_dashed == 1 ){ctx.setLineDash([dashtype0,dashtype1]);};\ |
||
4489 | ctx.strokeStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
4490 | if( use_filled == 1 ){ctx.fillStyle =\"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();};\ |
||
4491 | ctx.stroke();\ |
||
4492 | }\ |
||
4493 | ctx.restore();\ |
||
7653 | schaersvoo | 4494 | };"); |
7614 | schaersvoo | 4495 | break; |
4496 | |||
4497 | case DRAW_ELLIPSES:/* not used for userdraw */ |
||
4498 | fprintf(js_include_file,"\n<!-- draw ellipses -->\n\ |
||
4499 | 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){\ |
||
4500 | var obj;\ |
||
4501 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
4502 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
4503 | }\ |
||
4504 | else\ |
||
4505 | {\ |
||
4506 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
4507 | };\ |
||
4508 | var ctx = obj.getContext(\"2d\");\ |
||
4509 | ctx.save();\ |
||
4510 | if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\ |
||
4511 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
||
4512 | var cx,cy,ry,rx;\ |
||
4513 | ctx.lineWidth = line_width;\ |
||
4514 | if( use_filled == 1 ){ctx.fillStyle =\"rgba(\"+fill_color+\",\"+fill_opacity+\")\";};\ |
||
4515 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
4516 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
4517 | for(var p=0;p< x_points.length;p = p+2){\ |
||
4518 | ctx.beginPath();\ |
||
4519 | cx = x_points[p];cy = y_points[p];rx = 0.25*x_points[p+1];ry = 0.25*y_points[p+1];\ |
||
4520 | ctx.translate(cx - rx, cy - ry);\ |
||
4521 | ctx.scale(rx, ry);\ |
||
4522 | ctx.arc(1, 1, 1, 0, 2 * Math.PI, false);\ |
||
4523 | if( use_filled == 1 ){ctx.fill();}\ |
||
4524 | ctx.stroke();\ |
||
4525 | };\ |
||
4526 | ctx.restore();\ |
||
7653 | schaersvoo | 4527 | };",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 4528 | break; |
4529 | |||
4530 | case DRAW_PATHS: /* used for userdraw */ |
||
4531 | fprintf(js_include_file,"\n<!-- draw paths -->\n\ |
||
4532 | 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){\ |
||
4533 | ctx.save();\ |
||
4534 | if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\ |
||
4535 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
||
4536 | ctx.lineWidth = line_width;\ |
||
4537 | ctx.lineJoin = \"round\";\ |
||
4538 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
4539 | ctx.beginPath();\ |
||
4540 | ctx.moveTo(x_points[0],y_points[0]);\ |
||
4541 | for(var p = 1 ; p < x_points.length ; p++ ){ctx.lineTo(x_points[p],y_points[p]);}\ |
||
4542 | if(closed_path == 1){ctx.lineTo(x_points[0],y_points[0]);ctx.closePath();}\ |
||
4543 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
4544 | if(use_filled == 1){ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();}\ |
||
4545 | ctx.stroke();\ |
||
4546 | ctx.restore();\ |
||
4547 | return;\ |
||
4548 | };"); |
||
4549 | |||
4550 | break; |
||
4551 | case DRAW_ARROWS:/* used for userdraw */ |
||
4552 | fprintf(js_include_file,"\n<!-- draw arrows -->\n\ |
||
4553 | 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){\ |
||
4554 | ctx.save();\ |
||
4555 | if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\ |
||
4556 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
||
4557 | ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
4558 | ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
4559 | ctx.lineWidth = line_width;\ |
||
4560 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
4561 | ctx.lineCap = \"round\";\ |
||
4562 | ctx.save();\ |
||
4563 | var x1,y1,x2,y2,dx,dy,len;\ |
||
4564 | for(var p = 0 ; p < x_points.length - 1 ; p = p +2){\ |
||
4565 | ctx.restore();ctx.save();\ |
||
4566 | x1 = x_points[p];y1 = y_points[p];x2 = x_points[p+1];y2 = y_points[p+1];dx = x2 - x1;dy = y2 - y1;\ |
||
4567 | len = Math.sqrt(dx*dx+dy*dy);\ |
||
4568 | ctx.translate(x2,y2);\ |
||
4569 | ctx.rotate(Math.atan2(dy,dx));\ |
||
4570 | ctx.lineCap = \"round\";\ |
||
4571 | ctx.beginPath();\ |
||
4572 | ctx.moveTo(0,0);\ |
||
4573 | ctx.lineTo(-len,0);\ |
||
4574 | ctx.closePath();\ |
||
4575 | ctx.stroke();\ |
||
4576 | ctx.beginPath();\ |
||
4577 | ctx.moveTo(0,0);\ |
||
4578 | ctx.lineTo(-1*arrow_head,-0.5*arrow_head);\ |
||
4579 | ctx.lineTo(-1*arrow_head, 0.5*arrow_head);\ |
||
4580 | ctx.closePath();\ |
||
4581 | ctx.fill();\ |
||
4582 | if( type == 2 ){\ |
||
4583 | ctx.restore();\ |
||
4584 | ctx.save();\ |
||
4585 | ctx.translate(x1,y1);\ |
||
4586 | ctx.rotate(Math.atan2(-dy,-dx));\ |
||
4587 | ctx.beginPath();\ |
||
4588 | ctx.moveTo(0,0);\ |
||
4589 | ctx.lineTo(-1*arrow_head,-0.5*arrow_head);\ |
||
4590 | ctx.lineTo(-1*arrow_head, 0.5*arrow_head);\ |
||
4591 | ctx.closePath();\ |
||
4592 | ctx.stroke();\ |
||
4593 | ctx.fill();\ |
||
4594 | }\ |
||
4595 | }\ |
||
4596 | ctx.restore();\ |
||
4597 | return;\ |
||
7653 | schaersvoo | 4598 | };"); |
7614 | schaersvoo | 4599 | break; |
4600 | |||
4601 | case DRAW_VIDEO:/* not used for userdraw */ |
||
4602 | fprintf(js_include_file,"\n<!-- draw video -->\n\ |
||
4603 | draw_video = function(canvas_root_id,x,y,w,h,URL){\ |
||
4604 | var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\ |
||
4605 | var video_div = document.createElement(\"div\");\ |
||
4606 | canvas_div.appendChild(video_div);\ |
||
4607 | video_div.style.position = \"absolute\";\ |
||
4608 | video_div.style.left = x+\"px\";\ |
||
4609 | video_div.style.top = y+\"px\";\ |
||
4610 | video_div.style.width = w+\"px\";\ |
||
4611 | video_div.style.height = h+\"px\";\ |
||
4612 | var video = document.createElement(\"video\");\ |
||
4613 | video_div.appendChild(video);\ |
||
4614 | video.style.width = w+\"px\";\ |
||
4615 | video.style.height = h+\"px\";\ |
||
4616 | video.autobuffer = true;\ |
||
4617 | video.controls = true;video.autoplay = false;\ |
||
4618 | var src = document.createElement(\"source\");\ |
||
4619 | src.type = \"video/mp4\";\ |
||
4620 | src.src = URL;\ |
||
4621 | video.appendChild(src);\ |
||
4622 | video.load();\ |
||
4623 | return;\ |
||
7653 | schaersvoo | 4624 | };"); |
7614 | schaersvoo | 4625 | break; |
4626 | |||
4627 | case DRAW_AUDIO:/* not used for userdraw */ |
||
4628 | fprintf(js_include_file,"\n<!-- draw audio -->\n\ |
||
4629 | draw_audio = function(canvas_root_id,x,y,w,h,loop,visible,URL1,URL2){\ |
||
4630 | var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\ |
||
4631 | var audio_div = document.createElement(\"div\");\ |
||
4632 | canvas_div.appendChild(audio_div);\ |
||
4633 | audio_div.style.position = \"absolute\";\ |
||
4634 | audio_div.style.left = x+\"px\";\ |
||
4635 | audio_div.style.top = y+\"px\";\ |
||
4636 | audio_div.style.width = w+\"px\";\ |
||
4637 | audio_div.style.height = h+\"px\";\ |
||
4638 | var audio = document.createElement(\"audio\");\ |
||
4639 | audio_div.appendChild(audio);\ |
||
4640 | audio.setAttribute(\"style\",\"width:\"+w+\"px;height:\"+h+\"px\");\ |
||
4641 | audio.autobuffer = true;\ |
||
4642 | if(visible == 1 ){ audio.controls = true;audio.autoplay = false;}else{ audio.controls = false;audio.autoplay = true;}\ |
||
4643 | if(loop == 1 ){ audio.loop = true;}else{ audio.loop = false;}\ |
||
4644 | var src1 = document.createElement(\"source\");\ |
||
4645 | src1.type = \"audio/ogg\";\ |
||
4646 | src1.src = URL1;\ |
||
4647 | audio.appendChild(src1);\ |
||
4648 | var src2 = document.createElement(\"source\");\ |
||
4649 | src2.type = \"audio/mpeg\";\ |
||
4650 | src2.src = URL2;\ |
||
4651 | audio.appendChild(src2);\ |
||
4652 | audio.load();\ |
||
4653 | return;\ |
||
7653 | schaersvoo | 4654 | };"); |
7614 | schaersvoo | 4655 | break; |
4656 | |||
4657 | case DRAW_HTTP:/* not used for userdraw */ |
||
4658 | fprintf(js_include_file,"\n<!-- draw http -->\n\ |
||
4659 | draw_http = function(canvas_root_id,x,y,w,h,URL){\ |
||
4660 | var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\ |
||
4661 | var http_div = document.createElement(\"div\");\ |
||
4662 | var iframe = document.createElement(\"iframe\");\ |
||
4663 | canvas_div.appendChild(http_div);\ |
||
4664 | http_div.appendChild(iframe);\ |
||
4665 | iframe.src = URL;\ |
||
4666 | iframe.setAttribute(\"width\",w);\ |
||
4667 | iframe.setAttribute(\"height\",h);\ |
||
4668 | return;\ |
||
7653 | schaersvoo | 4669 | };"); |
7614 | schaersvoo | 4670 | break; |
4671 | |||
4672 | case DRAW_XML: |
||
4673 | fprintf(js_include_file,"\n<!-- draw xml -->\n\ |
||
4674 | draw_xml = function(canvas_root_id,x,y,w,h,mathml,onclick){\ |
||
4675 | var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\ |
||
4676 | var xml_div = document.createElement(\"div\");\ |
||
4677 | canvas_div.appendChild(xml_div);\ |
||
4678 | xml_div.innerHTML = mathml;\ |
||
4679 | if(onclick != 0){\ |
||
4680 | xml_div.onclick = function(){\ |
||
4681 | reply[0] = onclick;\ |
||
4682 | alert(\"send \"+onclick+\" ?\");\ |
||
4683 | };\ |
||
4684 | };\ |
||
4685 | xml_div.style.position = \"absolute\";\ |
||
4686 | xml_div.style.left = x+\"px\";\ |
||
4687 | xml_div.style.top = y+\"px\";\ |
||
4688 | xml_div.style.width = w+\"px\";\ |
||
4689 | xml_div.style.height = h+\"px\";\ |
||
4690 | return;\ |
||
7653 | schaersvoo | 4691 | };" |
7614 | schaersvoo | 4692 | ); |
4693 | break; |
||
7654 | schaersvoo | 4694 | case DRAW_SGRAPH: |
4695 | /* |
||
4696 | xstart = given |
||
4697 | ystart = given |
||
4698 | sgraph(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily) |
||
4699 | */ |
||
4700 | fprintf(js_include_file,"\n<!-- draw sgraph -->\n\ |
||
7658 | schaersvoo | 4701 | draw_sgraph = function(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily,opacity,font_size){\ |
4702 | 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);};\ |
||
4703 | var ctx = obj.getContext(\"2d\");\ |
||
4704 | ctx.font = fontfamily;\ |
||
4705 | var minor_opacity = 0.8*opacity;\ |
||
4706 | ctx.clearRect(0,0,xsize,ysize);\ |
||
4707 | var d_x = 1.8*font_size;\ |
||
4708 | var d_y = ctx.measureText(\"+ymax+\").width;\ |
||
4709 | var dx = xsize / (xmax - xmin);\ |
||
4710 | var dy = ysize / (ymax - ymin);\ |
||
4711 | var zero_x = d_y + dx;\ |
||
4712 | var zero_y = ysize - dy - d_x;\ |
||
7659 | schaersvoo | 4713 | var snor_x;\ |
7654 | schaersvoo | 4714 | if( xstart != xmin){\ |
7658 | schaersvoo | 4715 | snor_x = 0.1*xsize;\ |
4716 | }\ |
||
4717 | else\ |
||
4718 | {\ |
||
4719 | snor_x = 0;\ |
||
4720 | xstart = xmin;\ |
||
4721 | };\ |
||
4722 | ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\ |
||
4723 | ctx.lineWidth = 2;\ |
||
4724 | ctx.beginPath();\ |
||
4725 | ctx.moveTo(xsize,zero_y);\ |
||
4726 | ctx.lineTo(zero_x,zero_y);\ |
||
4727 | ctx.lineTo(zero_x,0);\ |
||
4728 | ctx.stroke();\ |
||
4729 | ctx.closePath();\ |
||
4730 | ctx.beginPath();\ |
||
4731 | ctx.moveTo(zero_x,zero_y);\ |
||
4732 | ctx.lineTo(zero_x + 0.25*snor_x,zero_y - 0.1*snor_x);\ |
||
4733 | ctx.lineTo(zero_x + 0.5*snor_x,zero_y + 0.1*snor_x);\ |
||
4734 | ctx.lineTo(zero_x + 0.75*snor_x,zero_y - 0.1*snor_x);\ |
||
4735 | ctx.lineTo(zero_x + snor_x,zero_y);\ |
||
4736 | ctx.stroke();\ |
||
4737 | ctx.closePath();\ |
||
4738 | ctx.beginPath();\ |
||
4739 | var num = xstart;\ |
||
7660 | schaersvoo | 4740 | var flipflop = 1;\ |
7658 | schaersvoo | 4741 | var step_x = xmajor*(xsize - zero_x - snor_x)/(xmax - xstart);\ |
4742 | for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\ |
||
7660 | schaersvoo | 4743 | if( 0.5*ctx.measureText(num).width > step_x ){\ |
4744 | if( flipflop == 1 ){flipflop = 0;}else{flipflop = 1;};\ |
||
4745 | };\ |
||
4746 | if( flipflop == 1){\ |
||
7658 | schaersvoo | 4747 | ctx.fillText(num,x - 0.5*ctx.measureText(num).width,zero_y+font_size);\ |
4748 | }\ |
||
4749 | else\ |
||
4750 | {\ |
||
4751 | ctx.fillText(num,x - 0.5*ctx.measureText(num).width,zero_y+2*font_size);\ |
||
4752 | }\ |
||
4753 | num = num + xmajor;\ |
||
4754 | };\ |
||
4755 | ctx.stroke();\ |
||
4756 | ctx.closePath();\ |
||
4757 | ctx.lineWidth = 1;\ |
||
4758 | ctx.beginPath();\ |
||
4759 | for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\ |
||
4760 | ctx.moveTo(x,zero_y);\ |
||
4761 | ctx.lineTo(x,0);\ |
||
4762 | };\ |
||
4763 | ctx.stroke();\ |
||
4764 | ctx.closePath();\ |
||
4765 | if( xminor > 1){\ |
||
4766 | ctx.lineWidth = 0.5;\ |
||
4767 | ctx.beginPath();\ |
||
4768 | ctx.strokeStyle = \"rgba(\"+minorcolor+\",\"+minor_opacity+\")\";\ |
||
4769 | var minor_step_x = step_x / xminor;\ |
||
4770 | var nx;\ |
||
4771 | for(var x = zero_x+snor_x; x < xsize;x = x + step_x){\ |
||
4772 | num = 1;\ |
||
4773 | for(var p = 1 ; p < xminor ; p++){\ |
||
4774 | nx = x + num*minor_step_x;\ |
||
4775 | ctx.moveTo(nx,zero_y);\ |
||
4776 | ctx.lineTo(nx,0);\ |
||
4777 | num++;\ |
||
4778 | };\ |
||
4779 | };\ |
||
4780 | ctx.stroke();\ |
||
4781 | ctx.closePath();\ |
||
4782 | ctx.beginPath();\ |
||
4783 | ctx.lineWidth = 2;\ |
||
4784 | ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\ |
||
4785 | for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\ |
||
4786 | ctx.moveTo(x,zero_y);ctx.lineTo(x,zero_y - 12);\ |
||
4787 | };\ |
||
4788 | for(var x = zero_x+snor_x ; x < xsize;x = x + minor_step_x){\ |
||
4789 | ctx.moveTo(x,zero_y);ctx.lineTo(x,zero_y - 6);\ |
||
4790 | };\ |
||
4791 | ctx.stroke();\ |
||
4792 | ctx.closePath();\ |
||
4793 | ctx.lineWidth = 0.5;\ |
||
4794 | };\ |
||
4795 | xmin = xstart - (xmajor*(zero_x+snor_x)/step_x);\ |
||
4796 | if( ystart != ymin){\ |
||
4797 | snor_y = 0.1*ysize;\ |
||
4798 | }\ |
||
4799 | else\ |
||
4800 | {\ |
||
4801 | snor_y = 0;\ |
||
4802 | ystart = ymin;\ |
||
4803 | };\ |
||
4804 | ctx.lineWidth = 2;\ |
||
4805 | ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\ |
||
4806 | ctx.beginPath();\ |
||
4807 | ctx.moveTo(zero_x,zero_y);\ |
||
4808 | ctx.lineTo(zero_x - 0.1*snor_y,zero_y - 0.25*snor_y);\ |
||
4809 | ctx.lineTo(zero_x + 0.1*snor_y,zero_y - 0.5*snor_y);\ |
||
4810 | ctx.lineTo(zero_x - 0.1*snor_y,zero_y - 0.75*snor_y);\ |
||
4811 | ctx.lineTo(zero_x,zero_y - snor_y);\ |
||
4812 | ctx.stroke();\ |
||
4813 | ctx.closePath();\ |
||
4814 | ctx.beginPath();\ |
||
4815 | ctx.lineWidth = 1;\ |
||
4816 | num = ystart;\ |
||
4817 | var step_y = ymajor*(zero_y - snor_y)/(ymax - ystart);\ |
||
4818 | for(var y = zero_y - snor_y ; y > 0; y = y - step_y){\ |
||
4819 | ctx.moveTo(zero_x,y);\ |
||
4820 | ctx.lineTo(xsize,y);\ |
||
4821 | ctx.fillText(num,zero_x - ctx.measureText(num+\" \").width,parseInt(y+0.2*font_size));\ |
||
4822 | num = num + ymajor;\ |
||
4823 | };\ |
||
4824 | ctx.stroke();\ |
||
4825 | ctx.closePath();\ |
||
4826 | if( yminor > 1){\ |
||
4827 | ctx.lineWidth = 0.5;\ |
||
4828 | ctx.beginPath();\ |
||
4829 | ctx.strokeStyle = \"rgba(\"+minorcolor+\",\"+minor_opacity+\")\";\ |
||
4830 | var minor_step_y = step_y / yminor;\ |
||
4831 | var ny;\ |
||
4832 | for(var y = 0 ; y < zero_y - snor_y ;y = y + step_y){\ |
||
4833 | num = 1;\ |
||
4834 | for(var p = 1 ;p < yminor;p++){\ |
||
4835 | ny = y + num*minor_step_y;\ |
||
4836 | ctx.moveTo(zero_x,ny);\ |
||
4837 | ctx.lineTo(xsize,ny);\ |
||
4838 | num++;\ |
||
4839 | };\ |
||
4840 | };\ |
||
4841 | ctx.stroke();\ |
||
4842 | ctx.closePath();\ |
||
4843 | ctx.lineWidth = 2;\ |
||
4844 | ctx.beginPath();\ |
||
4845 | ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\ |
||
4846 | for(var y = zero_y - snor_y ; y > 0 ;y = y - step_y){\ |
||
4847 | ctx.moveTo(zero_x,y);\ |
||
4848 | ctx.lineTo(zero_x+12,y);\ |
||
4849 | };\ |
||
4850 | for(var y = zero_y - snor_y ; y > 0 ;y = y - minor_step_y){\ |
||
4851 | ctx.moveTo(zero_x,y);\ |
||
4852 | ctx.lineTo(zero_x+6,y);\ |
||
4853 | };\ |
||
4854 | ctx.stroke();\ |
||
4855 | ctx.closePath();\ |
||
4856 | };\ |
||
4857 | ymin = ystart - (ymajor*(ysize - zero_y + snor_y)/step_y);\ |
||
7654 | schaersvoo | 4858 | if( typeof legend%d !== 'undefined' ){\ |
4859 | ctx.globalAlpha = 1.0;\ |
||
4860 | var y_offset = 2*font_size;\ |
||
4861 | var txt;var txt_size;\ |
||
4862 | var x_offset = xsize - 2*font_size;\ |
||
4863 | var l_length = legend%d.length;var barcolor = new Array();\ |
||
4864 | if( typeof legendcolors%d !== 'undefined' ){\ |
||
4865 | for(var p = 0 ; p < l_length ; p++){\ |
||
4866 | barcolor[p] = legendcolors%d[p];\ |
||
4867 | };\ |
||
4868 | }else{\ |
||
4869 | if( barcolor.length == 0 ){\ |
||
4870 | for(var p = 0 ; p < l_length ; p++){\ |
||
4871 | barcolor[p] = stroke_color;\ |
||
4872 | };\ |
||
4873 | };\ |
||
4874 | };\ |
||
4875 | for(var p = 0; p < l_length; p++){\ |
||
4876 | ctx.fillStyle = barcolor[p];\ |
||
4877 | txt = legend%d[p];\ |
||
4878 | txt_size = ctx.measureText(txt).width;\ |
||
4879 | ctx.fillText(legend%d[p],x_offset - txt_size, y_offset);\ |
||
4880 | y_offset = parseInt(y_offset + 1.5*font_size);\ |
||
4881 | };\ |
||
4882 | };\ |
||
7660 | schaersvoo | 4883 | if( typeof xaxislabel !== 'undefined' ){\ |
7658 | schaersvoo | 4884 | ctx.fillStyle = \'#000000\';\ |
4885 | var txt_size = ctx.measureText(xaxislabel).width + 4 ;\ |
||
4886 | ctx.fillText(xaxislabel,xsize - txt_size, zero_y - 7);\ |
||
4887 | };\ |
||
7660 | schaersvoo | 4888 | if( typeof yaxislabel !== 'undefined'){\ |
7658 | schaersvoo | 4889 | ctx.save();\ |
4890 | ctx.fillStyle = \'#000000\';\ |
||
4891 | var txt_size = ctx.measureText(yaxislabel).width;\ |
||
4892 | ctx.translate(zero_x+8 + font_size,txt_size+font_size);\ |
||
4893 | ctx.rotate(-0.5*Math.PI);\ |
||
4894 | ctx.fillText(yaxislabel,0,0);\ |
||
4895 | ctx.save();\ |
||
4896 | };\ |
||
7654 | schaersvoo | 4897 | };\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); |
4898 | break; |
||
7614 | schaersvoo | 4899 | |
4900 | case DRAW_GRID:/* not used for userdraw */ |
||
4901 | fprintf(js_include_file,"\n<!-- draw grid -->\n\ |
||
4902 | 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){\ |
||
4903 | var obj;\ |
||
4904 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
4905 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
4906 | }\ |
||
4907 | else\ |
||
4908 | {\ |
||
4909 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
4910 | };\ |
||
4911 | var ctx = obj.getContext(\"2d\");\ |
||
4912 | ctx.clearRect(0,0,xsize,ysize);\ |
||
4913 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
4914 | ctx.save();\ |
||
4915 | if( use_translate == 1 ){ctx.translate(vector[0],vector[1]);};\ |
||
4916 | if( use_rotate == 1 ){ctx.translate(x2px(0),y2px(0));ctx.rotate(angle*Math.PI/180);ctx.translate(-1*(x2px(0)),-1*(y2px(0)));};\ |
||
4917 | var stroke_color = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
4918 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+1.0+\")\";\ |
||
4919 | var axis_color = \"rgba(\"+axis_color+\",\"+stroke_opacity+\")\";\ |
||
4920 | ctx.font = font_family;\ |
||
4921 | var xstep = xsize*xmajor/(xmax - xmin);\ |
||
4922 | var ystep = ysize*ymajor/(ymax - ymin);\ |
||
4923 | var x2step = xstep / xminor;\ |
||
4924 | var y2step = ystep / yminor;\ |
||
7654 | schaersvoo | 4925 | var zero_x;var zero_y;var f_x;var f_y;\ |
4926 | if(xmin < 0 ){zero_x = x2px(0);f_x = 1;}else{zero_x = x2px(xmin);f_x = -1;}\ |
||
4927 | if(ymin < 0 ){zero_y = y2px(0);f_y = 1;}else{zero_y = y2px(ymin);f_y = -1;}\ |
||
7614 | schaersvoo | 4928 | ctx.beginPath();\ |
4929 | ctx.lineWidth = line_width;\ |
||
4930 | ctx.strokeStyle = stroke_color;\ |
||
4931 | for(var p = zero_x ; p < xsize; p = p + xstep){\ |
||
4932 | ctx.moveTo(p,0);\ |
||
4933 | ctx.lineTo(p,ysize);\ |
||
4934 | };\ |
||
4935 | for(var p = zero_x ; p > 0; p = p - xstep){\ |
||
4936 | ctx.moveTo(p,0);\ |
||
4937 | ctx.lineTo(p,ysize);\ |
||
4938 | };\ |
||
4939 | for(var p = zero_y ; p < ysize; p = p + ystep){\ |
||
4940 | ctx.moveTo(0,p);\ |
||
4941 | ctx.lineTo(xsize,p);\ |
||
4942 | };\ |
||
4943 | for(var p = zero_y ; p > 0; p = p - ystep){\ |
||
4944 | ctx.moveTo(0,p);\ |
||
4945 | ctx.lineTo(xsize,p);\ |
||
4946 | };\ |
||
4947 | if( typeof xaxislabel !== 'undefined' ){\ |
||
4948 | ctx.save();\ |
||
4949 | ctx.font = \"italic \"+font_size+\"px Ariel\";\ |
||
4950 | var corr = ctx.measureText(xaxislabel).width;\ |
||
4951 | ctx.fillText(xaxislabel,xsize - 1.5*corr,zero_y - tics_length - 0.4*font_size);\ |
||
4952 | ctx.restore();\ |
||
4953 | };\ |
||
4954 | if( typeof yaxislabel !== 'undefined' ){\ |
||
4955 | ctx.save();\ |
||
4956 | ctx.font = \"italic \"+font_size+\"px Ariel\";\ |
||
4957 | corr = ctx.measureText(yaxislabel).width;\ |
||
4958 | ctx.translate(zero_x+tics_length + font_size,corr+font_size);\ |
||
4959 | ctx.rotate(-0.5*Math.PI);\ |
||
4960 | ctx.fillText(yaxislabel,0,0);\ |
||
4961 | ctx.restore();\ |
||
4962 | };\ |
||
4963 | ctx.stroke();\ |
||
4964 | ctx.closePath();\ |
||
4965 | if( use_axis == 1 ){\ |
||
4966 | ctx.beginPath();\ |
||
4967 | ctx.strokeStyle = stroke_color;\ |
||
4968 | ctx.lineWidth = 0.6*line_width;\ |
||
4969 | for(var p = zero_x ; p < xsize; p = p + x2step){\ |
||
4970 | ctx.moveTo(p,0);\ |
||
4971 | ctx.lineTo(p,ysize);\ |
||
4972 | };\ |
||
4973 | for(var p = zero_x ; p > 0; p = p - x2step){\ |
||
4974 | ctx.moveTo(p,0);\ |
||
4975 | ctx.lineTo(p,ysize);\ |
||
4976 | };\ |
||
4977 | for(var p = zero_y ; p < ysize; p = p + y2step){\ |
||
4978 | ctx.moveTo(0,p);\ |
||
4979 | ctx.lineTo(xsize,p);\ |
||
4980 | };\ |
||
4981 | for(var p = zero_y ; p > 0; p = p - y2step){\ |
||
4982 | ctx.moveTo(0,p);\ |
||
4983 | ctx.lineTo(xsize,p);\ |
||
4984 | };\ |
||
4985 | ctx.stroke();\ |
||
4986 | ctx.closePath();\ |
||
4987 | ctx.beginPath();\ |
||
4988 | ctx.lineWidth = 2*line_width;\ |
||
4989 | ctx.strokeStyle = axis_color;\ |
||
4990 | ctx.moveTo(0,zero_y);\ |
||
4991 | ctx.lineTo(xsize,zero_y);\ |
||
4992 | ctx.moveTo(zero_x,0);\ |
||
4993 | ctx.lineTo(zero_x,ysize);\ |
||
4994 | ctx.stroke();\ |
||
4995 | ctx.closePath();\ |
||
4996 | ctx.lineWidth = line_width+0.5;\ |
||
4997 | ctx.beginPath();\ |
||
4998 | for(var p = zero_x ; p < xsize; p = p + xstep){\ |
||
4999 | ctx.moveTo(p,zero_y-tics_length);\ |
||
5000 | ctx.lineTo(p,zero_y+tics_length);\ |
||
5001 | };\ |
||
5002 | for(var p = zero_x ; p > 0; p = p - xstep){\ |
||
5003 | ctx.moveTo(p,zero_y-tics_length);\ |
||
5004 | ctx.lineTo(p,zero_y+tics_length);\ |
||
5005 | };\ |
||
5006 | for(var p = zero_y ; p < ysize; p = p + ystep){\ |
||
5007 | ctx.moveTo(zero_x-tics_length,p);\ |
||
5008 | ctx.lineTo(zero_x+tics_length,p);\ |
||
5009 | };\ |
||
5010 | for(var p = zero_y ; p > 0; p = p - ystep){\ |
||
5011 | ctx.moveTo(zero_x-tics_length,p);\ |
||
5012 | ctx.lineTo(zero_x+tics_length,p);\ |
||
5013 | };\ |
||
5014 | for(var p = zero_x ; p < xsize; p = p + x2step){\ |
||
5015 | ctx.moveTo(p,zero_y-0.5*tics_length);\ |
||
5016 | ctx.lineTo(p,zero_y+0.5*tics_length);\ |
||
5017 | };\ |
||
5018 | for(var p = zero_x ; p > 0; p = p - x2step){\ |
||
5019 | ctx.moveTo(p,zero_y-0.5*tics_length);\ |
||
5020 | ctx.lineTo(p,zero_y+0.5*tics_length);\ |
||
5021 | };\ |
||
5022 | for(var p = zero_y ; p < ysize; p = p + y2step){\ |
||
5023 | ctx.moveTo(zero_x-0.5*tics_length,p);\ |
||
5024 | ctx.lineTo(zero_x+0.5*tics_length,p);\ |
||
5025 | };\ |
||
5026 | for(var p = zero_y ; p > 0; p = p - y2step){\ |
||
5027 | ctx.moveTo(zero_x-0.5*tics_length,p);\ |
||
5028 | ctx.lineTo(zero_x+0.5*tics_length,p);\ |
||
5029 | };\ |
||
5030 | ctx.stroke();\ |
||
5031 | ctx.closePath();\ |
||
5032 | if( use_axis_numbering == 1 ){\ |
||
5033 | var shift = zero_y+2*font_size;var flip=0;var skip=0;var corr;var cnt;var disp_cnt;var prec;\ |
||
5034 | if( x_strings != null ){\ |
||
5035 | var f = 1.4;\ |
||
5036 | var len = x_strings.length;if((len/2+0.5)%%2 == 0){ alert(\"xaxis number unpaired: text missing ! \");return;};\ |
||
5037 | for(var p = 0 ; p < len ; p = p+2){\ |
||
5038 | var x_nums = x2px(eval(x_strings[p]));\ |
||
5039 | var x_text = x_strings[p+1];\ |
||
5040 | corr = ctx.measureText(x_text).width;\ |
||
5041 | skip = 1.2*corr/xstep;\ |
||
5042 | if( zero_y+2*font_size > ysize ){shift = ysize - 2*font_size;};\ |
||
5043 | if( skip > 1 ){if(flip == 0 ){flip = 1; shift = shift + font_size;}else{flip = 0; shift = shift - font_size;}};\ |
||
5044 | ctx.fillText(x_text,parseInt(x_nums-0.5*corr),shift);\ |
||
5045 | }\ |
||
5046 | }\ |
||
5047 | else\ |
||
5048 | {\ |
||
7654 | schaersvoo | 5049 | corr=0;skip = 1;cnt = px2x(zero_x);\ |
7614 | schaersvoo | 5050 | prec = Math.log(precision)/(Math.log(10));\ |
7654 | schaersvoo | 5051 | for( var p = zero_x ; p < xsize ; p = p+xstep){\ |
7614 | schaersvoo | 5052 | if(skip == 0 ){\ |
5053 | disp_cnt = cnt.toFixed(prec);\ |
||
5054 | corr = ctx.measureText(disp_cnt).width;\ |
||
5055 | skip = parseInt(1.2*corr/xstep);\ |
||
7654 | schaersvoo | 5056 | ctx.fillText(disp_cnt,p-0.5*corr,parseInt(zero_y+(1.4*f_x*font_size)));\ |
7614 | schaersvoo | 5057 | }\ |
5058 | else\ |
||
5059 | {\ |
||
5060 | skip--;\ |
||
5061 | };\ |
||
5062 | cnt = cnt + xmajor;\ |
||
5063 | };\ |
||
7654 | schaersvoo | 5064 | cnt = px2x(zero_x);skip = 1;\ |
5065 | for( var p = zero_x ; p > 0 ; p = p-xstep){\ |
||
7614 | schaersvoo | 5066 | if(skip == 0 ){\ |
5067 | disp_cnt = cnt.toFixed(prec);\ |
||
5068 | corr = ctx.measureText(disp_cnt).width;\ |
||
5069 | skip = parseInt(1.2*corr/xstep);\ |
||
7654 | schaersvoo | 5070 | ctx.fillText(disp_cnt,p-0.5*corr,parseInt(zero_y+(1.4*f_x*font_size)));\ |
7614 | schaersvoo | 5071 | }\ |
5072 | else\ |
||
5073 | {\ |
||
5074 | skip--;\ |
||
5075 | };\ |
||
5076 | cnt = cnt - xmajor;\ |
||
5077 | };\ |
||
5078 | };\ |
||
5079 | if( y_strings != null ){\ |
||
5080 | var len = y_strings.length;if((len/2+0.5)%%2 == 0){ alert(\"yaxis number unpaired: text missing ! \");return;};\ |
||
5081 | for(var p = 0 ; p < len ; p = p+2){\ |
||
5082 | var y_nums = y2px(eval(y_strings[p]));\ |
||
5083 | var y_text = y_strings[p+1];\ |
||
5084 | var f = 1.4;\ |
||
5085 | corr = 2 + tics_length + ctx.measureText(y_text).width;\ |
||
5086 | if( corr > zero_x){corr = parseInt(zero_x+2); }\ |
||
5087 | ctx.fillText(y_text,zero_x - corr,y_nums);\ |
||
5088 | };\ |
||
5089 | }\ |
||
5090 | else\ |
||
5091 | {\ |
||
7654 | schaersvoo | 5092 | corr = 0;cnt = px2y(zero_y);skip = 1;\ |
5093 | for( var p = zero_y ; p < ysize ; p = p+ystep){\ |
||
7614 | schaersvoo | 5094 | if(skip == 0 ){\ |
5095 | skip = parseInt(1.4*font_size/ystep);\ |
||
5096 | disp_cnt = cnt.toFixed(prec);\ |
||
7654 | schaersvoo | 5097 | if(f_y == 1){corr = 2 + tics_length + ctx.measureText(disp_cnt).width;}\ |
5098 | ctx.fillText(disp_cnt,parseInt(zero_x - corr),parseInt(p+(0.4*font_size)));\ |
||
7614 | schaersvoo | 5099 | }\ |
5100 | else\ |
||
5101 | {\ |
||
5102 | skip--;\ |
||
5103 | };\ |
||
5104 | cnt = cnt - ymajor;\ |
||
5105 | }\ |
||
7654 | schaersvoo | 5106 | corr = 0;cnt = px2y(zero_y);skip = 1;\ |
5107 | for( var p = zero_y ; p > 0 ; p = p-ystep){\ |
||
7614 | schaersvoo | 5108 | if(skip == 0 ){\ |
5109 | skip = parseInt(1.4*font_size/ystep);\ |
||
5110 | disp_cnt = cnt.toFixed(prec);\ |
||
7654 | schaersvoo | 5111 | if(f_y == 1){corr = 2 + tics_length + ctx.measureText(disp_cnt).width;}\ |
5112 | ctx.fillText(disp_cnt,parseInt(zero_x - corr),parseInt(p+(0.4*font_size)));\ |
||
7614 | schaersvoo | 5113 | }\ |
5114 | else\ |
||
5115 | {\ |
||
5116 | skip--;\ |
||
5117 | };\ |
||
5118 | cnt = cnt + ymajor;\ |
||
5119 | }\ |
||
5120 | };\ |
||
5121 | };\ |
||
5122 | ctx.strokeStyle = stroke_color;\ |
||
5123 | ctx.lineWidth = 2;\ |
||
5124 | ctx.beginPath();\ |
||
5125 | ctx.rect(0,0,xsize,ysize);\ |
||
5126 | ctx.closePath();\ |
||
5127 | ctx.stroke();\ |
||
5128 | };\ |
||
5129 | if( typeof linegraph_0 !== 'undefined' ){\ |
||
5130 | ctx.restore();\ |
||
5131 | ctx.save();\ |
||
5132 | ctx.globalAlpha = 1.0;\ |
||
5133 | var i = 0;\ |
||
5134 | var line_name = eval('linegraph_'+i);\ |
||
5135 | while ( typeof line_name !== 'undefined' ){\ |
||
5136 | ctx.strokeStyle = 'rgba('+line_name[0]+','+stroke_opacity+')';\ |
||
5137 | ctx.lineWidth = parseInt(line_name[1]);\ |
||
5138 | if(line_name[2] == \"1\"){\ |
||
5139 | var d1 = parseInt(line_name[3]);\ |
||
5140 | var d2 = parseInt(line_name[4]);\ |
||
5141 | if(ctx.setLineDash){ ctx.setLineDash(d1,d2); } else { ctx.mozDash = [d1,d2];};\ |
||
5142 | }\ |
||
5143 | else\ |
||
5144 | {\ |
||
5145 | if(ctx.setLineDash){ctx.setLineDash = null;}\ |
||
5146 | if(ctx.mozDash){ctx.mozDash = null;}\ |
||
5147 | };\ |
||
5148 | var data_x = new Array();\ |
||
5149 | var data_y = new Array();\ |
||
5150 | var lb = line_name.length;\ |
||
5151 | var idx = 0;\ |
||
5152 | for( var p = 5 ; p < lb ; p = p + 2 ){\ |
||
5153 | data_x[idx] = x2px(line_name[p]);\ |
||
5154 | data_y[idx] = y2px(line_name[p+1]);\ |
||
5155 | idx++;\ |
||
5156 | };\ |
||
5157 | for( var p = 0; p < idx ; p++){\ |
||
5158 | ctx.beginPath();\ |
||
5159 | ctx.moveTo(data_x[p],data_y[p]);\ |
||
5160 | ctx.lineTo(data_x[p+1],data_y[p+1]);\ |
||
5161 | ctx.stroke();\ |
||
5162 | ctx.closePath();\ |
||
5163 | };\ |
||
5164 | i++;\ |
||
5165 | try{ line_name = eval('linegraph_'+i); }catch(e){ break; }\ |
||
5166 | };\ |
||
5167 | };\ |
||
5168 | var barcolor = new Array();\ |
||
5169 | if( typeof barchart%d !== 'undefined' ){\ |
||
5170 | ctx.restore();\ |
||
5171 | ctx.save();\ |
||
5172 | ctx.globalAlpha = 1.0;\ |
||
5173 | var bar_x = new Array();\ |
||
5174 | var bar_y = new Array();\ |
||
5175 | var lb = barchart%d.length;\ |
||
5176 | var idx = 0;\ |
||
5177 | for( var p = 0 ; p < lb ; p = p + 3 ){\ |
||
5178 | bar_x[idx] = x2px(barchart%d[p]);\ |
||
5179 | bar_y[idx] = y2px(barchart%d[p+1]);\ |
||
5180 | barcolor[idx] = barchart%d[p+2];\ |
||
5181 | idx++;\ |
||
5182 | };\ |
||
5183 | var dx = parseInt(0.6*xstep);\ |
||
5184 | ctx.globalAlpha = fill_opacity;\ |
||
5185 | for( var p = 0; p < idx ; p++ ){\ |
||
5186 | ctx.beginPath();\ |
||
5187 | ctx.strokeStyle = barcolor[p];\ |
||
5188 | ctx.fillStyle = barcolor[p];\ |
||
5189 | ctx.rect(bar_x[p]-0.5*dx,bar_y[p],dx,zero_y - bar_y[p]);\ |
||
5190 | ctx.fill();\ |
||
5191 | ctx.stroke();\ |
||
5192 | ctx.closePath();\ |
||
5193 | };\ |
||
5194 | };\ |
||
5195 | if( typeof legend%d !== 'undefined' ){\ |
||
5196 | ctx.globalAlpha = 1.0;\ |
||
5197 | ctx.font = \"bold \"+font_size+\"px Ariel\";\ |
||
5198 | var y_offset = 2*font_size;\ |
||
5199 | var txt;var txt_size;\ |
||
5200 | var x_offset = xsize - 2*font_size;\ |
||
5201 | var l_length = legend%d.length;\ |
||
5202 | if( typeof legendcolors%d !== 'undefined' ){\ |
||
5203 | for(var p = 0 ; p < l_length ; p++){\ |
||
5204 | barcolor[p] = legendcolors%d[p];\ |
||
5205 | };\ |
||
5206 | }else{\ |
||
5207 | if( barcolor.length == 0 ){\ |
||
5208 | for(var p = 0 ; p < l_length ; p++){\ |
||
5209 | barcolor[p] = stroke_color;\ |
||
5210 | };\ |
||
5211 | };\ |
||
5212 | };\ |
||
5213 | for(var p = 0; p < l_length; p++){\ |
||
5214 | ctx.fillStyle = barcolor[p];\ |
||
5215 | txt = legend%d[p];\ |
||
5216 | txt_size = ctx.measureText(txt).width;\ |
||
5217 | ctx.fillText(legend%d[p],x_offset - txt_size, y_offset);\ |
||
5218 | y_offset = parseInt(y_offset + 1.5*font_size);\ |
||
5219 | };\ |
||
5220 | };\ |
||
5221 | ctx.restore();\ |
||
5222 | return;\ |
||
7653 | schaersvoo | 5223 | };",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 | 5224 | break; |
5225 | |||
5226 | case DRAW_PIECHART: |
||
5227 | fprintf(js_include_file,"\n<!-- draw piechars -->\n\ |
||
5228 | function draw_piechart(canvas_type,x_center,y_center,radius, data_color_list,fill_opacity,font_size,font_family){\ |
||
5229 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
5230 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
5231 | }\ |
||
5232 | else\ |
||
5233 | {\ |
||
5234 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
5235 | };\ |
||
5236 | var ld = data_color_list.length;\ |
||
5237 | var sum = 0;\ |
||
5238 | var idx = 0;\ |
||
5239 | var colors = new Array();\ |
||
5240 | var data = new Array();\ |
||
5241 | for(var p = 0;p < ld; p = p + 2){\ |
||
5242 | data[idx] = parseFloat(data_color_list[p]);\ |
||
5243 | sum = sum + data[idx];\ |
||
5244 | colors[idx] = data_color_list[p+1];\ |
||
5245 | idx++;\ |
||
5246 | };\ |
||
5247 | var ctx = obj.getContext(\"2d\");\ |
||
5248 | ctx.save();\ |
||
5249 | var angle;\ |
||
5250 | var angle_end = 0;\ |
||
5251 | var offset = Math.PI / 2;\ |
||
5252 | ctx.globalAlpha = fill_opacity;\ |
||
5253 | for(var p=0; p < idx; p++){\ |
||
5254 | ctx.beginPath();\ |
||
5255 | ctx.fillStyle = colors[p];\ |
||
5256 | ctx.moveTo(x_center,y_center);\ |
||
5257 | angle = Math.PI * (2 * data[p] / sum);\ |
||
5258 | ctx.arc(x_center,y_center, radius, angle_end - offset, angle_end + angle - offset, false);\ |
||
5259 | ctx.lineTo(x_center, y_center);\ |
||
5260 | ctx.fill();\ |
||
5261 | ctx.closePath();\ |
||
5262 | angle_end = angle_end + angle;\ |
||
5263 | };\ |
||
5264 | if( typeof legend%d !== 'undefined' ){\ |
||
5265 | ctx.globalAlpha = 1.0;\ |
||
5266 | ctx.font = font_size+\"px \"+font_family;\ |
||
5267 | var y_offset = font_size; \ |
||
5268 | var x_offset = 0;\ |
||
5269 | var txt;var txt_size;\ |
||
5270 | for(var p = 0; p < idx; p++){\ |
||
5271 | ctx.fillStyle = colors[p];\ |
||
5272 | txt = legend%d[p];\ |
||
5273 | txt_size = ctx.measureText(txt).width;\ |
||
5274 | if( x_center + radius + txt_size > xsize ){ x_offset = x_center + radius + txt_size - xsize;} else { x_offset = 0; };\ |
||
5275 | ctx.fillText(legend%d[p],x_center + radius - x_offset, y_center - radius + y_offset);\ |
||
5276 | y_offset = parseInt(y_offset + 1.5*font_size);\ |
||
5277 | };\ |
||
5278 | };\ |
||
5279 | ctx.restore();\ |
||
7653 | schaersvoo | 5280 | };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 5281 | |
5282 | break; |
||
5283 | case DRAW_ARCS: |
||
5284 | fprintf(js_include_file,"\n<!-- draw arcs -->\n\ |
||
5285 | 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){\ |
||
5286 | var obj;\ |
||
5287 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
5288 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
5289 | }\ |
||
5290 | else\ |
||
5291 | {\ |
||
5292 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
5293 | };\ |
||
5294 | var ctx = obj.getContext(\"2d\");\ |
||
5295 | ctx.save();\ |
||
5296 | if( use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{if(ctx.mozDash){ ctx.mozDash = [dashtype0,dashtype1];};};};\ |
||
5297 | if( use_translate == 1 ){ctx.translate(vector[0],vector[1]);};\ |
||
5298 | if( use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);};\ |
||
5299 | if(end < start){var tmp = end;end = start;start=tmp;};\ |
||
5300 | start=360-start;\ |
||
5301 | end=360-end;\ |
||
5302 | ctx.lineWidth = line_width;\ |
||
5303 | ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
5304 | if( use_filled == 1 ){\ |
||
5305 | ctx.beginPath();\ |
||
5306 | ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\ |
||
5307 | var x1 = xc + r*Math.cos(Math.PI*start/180);\ |
||
5308 | var y1 = yc + r*Math.sin(Math.PI*start/180);\ |
||
5309 | var x2 = xc + r*Math.cos(Math.PI*end/180);\ |
||
5310 | var y2 = yc + r*Math.sin(Math.PI*end/180);\ |
||
5311 | ctx.beginPath();\ |
||
5312 | ctx.moveTo(x1,y1);\ |
||
5313 | ctx.lineTo(xc,yc);\ |
||
5314 | ctx.moveTo(xc,yc);\ |
||
5315 | ctx.lineTo(x2,y2);\ |
||
5316 | ctx.closePath();\ |
||
5317 | ctx.arc(xc, yc, r, start*(Math.PI / 180), end*(Math.PI / 180),true);\ |
||
5318 | ctx.fill();\ |
||
5319 | ctx.stroke();\ |
||
5320 | }\ |
||
5321 | else\ |
||
5322 | {\ |
||
5323 | ctx.beginPath();\ |
||
5324 | ctx.arc(xc, yc, r, start*(Math.PI / 180), end*(Math.PI / 180),true);\ |
||
5325 | ctx.stroke();\ |
||
5326 | ctx.closePath();\ |
||
5327 | }\ |
||
5328 | ctx.restore();\ |
||
7653 | schaersvoo | 5329 | };",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 5330 | |
5331 | break; |
||
5332 | case DRAW_TEXTS: |
||
5333 | fprintf(js_include_file,"\n<!-- draw text -->\n\ |
||
5334 | draw_text = function(canvas_type,x,y,font_size,font_family,stroke_color,stroke_opacity,angle2,text,use_rotate,angle,use_translate,vector){\ |
||
5335 | var obj;\ |
||
5336 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
5337 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
5338 | }\ |
||
5339 | else\ |
||
5340 | {\ |
||
5341 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
5342 | };\ |
||
5343 | var ctx = obj.getContext(\"2d\");\ |
||
5344 | if(angle2 == 0 && angle != 0){\ |
||
5345 | ctx.save();\ |
||
5346 | if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\ |
||
5347 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
||
5348 | };\ |
||
5349 | if( font_family.indexOf('px') != null ){\ |
||
5350 | ctx.font = font_family;\ |
||
5351 | }\ |
||
5352 | else\ |
||
5353 | {\ |
||
5354 | ctx.font = \"+font_size+'px '+font_family \";\ |
||
5355 | };\ |
||
5356 | ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
5357 | if(angle2 != 0){\ |
||
5358 | ctx.save();\ |
||
5359 | ctx.translate(x,y);\ |
||
5360 | ctx.rotate((360-angle2)*(Math.PI / 180));\ |
||
5361 | ctx.fillText(text,0,0);\ |
||
5362 | ctx.restore();\ |
||
5363 | }else{ctx.fillText(text,x,y);};\ |
||
5364 | ctx.restore();\ |
||
5365 | return;\ |
||
7653 | schaersvoo | 5366 | };",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 5367 | |
5368 | break; |
||
5369 | case DRAW_CURVE: |
||
5370 | fprintf(js_include_file,"\n<!-- draw curve -->\n\ |
||
5371 | 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){\ |
||
5372 | var obj;\ |
||
5373 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
5374 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
5375 | }\ |
||
5376 | else\ |
||
5377 | {\ |
||
5378 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
5379 | };\ |
||
5380 | var ctx = obj.getContext(\"2d\");\ |
||
5381 | ctx.save();\ |
||
5382 | if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\ |
||
5383 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
||
5384 | ctx.beginPath();ctx.lineWidth = line_width;\ |
||
5385 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
5386 | ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
5387 | ctx.moveTo(x2px(x_points[0]),y2px(y_points[0]));\ |
||
5388 | for(var p = 1 ; p < x_points.length ; p++){\ |
||
5389 | if( y2px(y_points[p]) > -5 && y2px(y_points[p]) < ysize+5 ){\ |
||
5390 | ctx.lineTo(x2px(x_points[p]),y2px(y_points[p]));\ |
||
5391 | }\ |
||
5392 | else\ |
||
5393 | {\ |
||
5394 | ctx.stroke();\ |
||
5395 | ctx.beginPath();\ |
||
5396 | p++;\ |
||
5397 | ctx.moveTo(x2px(x_points[p]),y2px(y_points[p]));\ |
||
5398 | };\ |
||
5399 | };\ |
||
5400 | ctx.stroke();\ |
||
5401 | ctx.restore();\ |
||
7653 | schaersvoo | 5402 | };",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 5403 | break; |
5404 | |||
5405 | case DRAW_INPUTS: |
||
5406 | fprintf(js_include_file,"\n<!-- draw input fields -->\n\ |
||
5407 | draw_inputs = function(root_id,input_cnt,x,y,size,readonly,style,value){\ |
||
5408 | var canvas_div = document.getElementById(\"canvas_div\"+root_id);\ |
||
5409 | var input = document.createElement(\"input\");\ |
||
5410 | input.setAttribute(\"id\",\"canvas_input\"+input_cnt);\ |
||
5411 | input.setAttribute(\"style\",\"position:absolute;left:\"+x+\"px;top:\"+y+\"px;\"+style);\ |
||
5412 | input.setAttribute(\"size\",size);\ |
||
5413 | input.setAttribute(\"value\",value);\ |
||
5414 | if( readonly == 0 ){ input.setAttribute(\"readonly\",\"readonly\");};\ |
||
7653 | schaersvoo | 5415 | canvas_div.appendChild(input);};"); |
7614 | schaersvoo | 5416 | break; |
5417 | |||
5418 | case DRAW_TEXTAREAS: |
||
5419 | fprintf(js_include_file,"\n<!-- draw text area inputfields -->\n\ |
||
5420 | draw_textareas = function(root_id,input_cnt,x,y,cols,rows,readonly,style,value){\ |
||
5421 | var canvas_div = document.getElementById(\"canvas_div\"+root_id);\ |
||
5422 | var textarea = document.createElement(\"textarea\");\ |
||
5423 | textarea.setAttribute(\"id\",\"canvas_input\"+input_cnt);\ |
||
5424 | textarea.setAttribute(\"style\",\"position:absolute;left:\"+x+\"px;top:\"+y+\"px;\"+style);\ |
||
5425 | textarea.setAttribute(\"cols\",cols);\ |
||
5426 | textarea.setAttribute(\"rows\",rows);\ |
||
5427 | textarea.innerHTML = value;\ |
||
7653 | schaersvoo | 5428 | canvas_div.appendChild(textarea);};"); |
7614 | schaersvoo | 5429 | break; |
5430 | |||
5431 | case DRAW_PIXELS: |
||
5432 | fprintf(js_include_file,"\n<!-- draw pixel -->\n\ |
||
5433 | draw_setpixel = function(x,y,color,opacity,pixelsize){\ |
||
5434 | var canvas = create_canvas%d(10,xsize,ysize);\ |
||
5435 | var d = 0.5*pixelsize;\ |
||
5436 | var ctx = canvas.getContext(\"2d\");\ |
||
5437 | ctx.fillStyle = \"rgba(\"+color+\",\"+opacity+\")\";\ |
||
5438 | ctx.clearRect(0,0,xsize,ysize);\ |
||
5439 | for(var p=0; p<x.length;p++){\ |
||
5440 | ctx.fillRect( x2px(x[p]) - d, y2px(y[p]) - d , pixelsize, pixelsize );\ |
||
5441 | };\ |
||
5442 | ctx.fill();ctx.stroke();\ |
||
5443 | };",canvas_root_id); |
||
5444 | break; |
||
5445 | |||
5446 | case DRAW_CLOCK: |
||
5447 | fprintf(js_include_file,"\n<!-- begin command clock -->\n\ |
||
5448 | var clock_canvas = create_canvas%d(%d,xsize,ysize);\ |
||
5449 | var clock_ctx = clock_canvas.getContext(\"2d\");\ |
||
5450 | var clock = function(xc,yc,radius,H,M,S,type,interaction,h_color,m_color,s_color,bg_color,fg_color){\ |
||
5451 | clock_ctx.save();\ |
||
5452 | this.type = type || 0;\ |
||
5453 | this.interaction = interaction || 0;\ |
||
5454 | this.H = H || parseInt(110*(Math.random()));\ |
||
5455 | this.M = M || parseInt(590*(Math.random()));\ |
||
5456 | this.S = S || parseInt(590*(Math.random()));\ |
||
5457 | this.xc = xc || xsize/2;\ |
||
5458 | this.yc = yc || ysize/2;\ |
||
5459 | this.radius = radius || xsize/4;\ |
||
5460 | var font_size = parseInt(0.2*this.radius);\ |
||
5461 | this.H_color = h_color || \"blue\";\ |
||
5462 | this.M_color = m_color || \"blue\";\ |
||
5463 | this.S_color = s_color || \"blue\";\ |
||
5464 | this.fg_color = fg_color || \"red\";\ |
||
5465 | this.bg_color = bg_color || \"white\";\ |
||
5466 | clock_ctx.translate(this.xc,this.yc);\ |
||
5467 | clock_ctx.beginPath();\ |
||
5468 | clock_ctx.arc(0,0,this.radius,0,2*Math.PI,false);\ |
||
5469 | clock_ctx.fillStyle = this.bg_color;\ |
||
5470 | clock_ctx.fill();\ |
||
5471 | clock_ctx.closePath();\ |
||
5472 | clock_ctx.beginPath();\ |
||
5473 | clock_ctx.font = font_size+\"px Arial\";\ |
||
5474 | clock_ctx.fillStyle = this.fg_color;\ |
||
5475 | clock_ctx.textAlign = \"center\";\ |
||
5476 | clock_ctx.textBaseline = 'middle';\ |
||
5477 | var angle;var x1,y1,x2,y2;\ |
||
5478 | var angle_cos;var angle_sin;\ |
||
5479 | switch(type){\ |
||
5480 | case 0:clock_ctx.beginPath();\ |
||
5481 | for(var p = 1; p <= 12 ; p++){\ |
||
5482 | angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 12));\ |
||
5483 | angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 12));\ |
||
5484 | x1 = 0.8*angle_cos;y1 = 0.8*angle_sin;x2 = angle_cos;y2 = angle_sin;\ |
||
5485 | clock_ctx.moveTo(x1,y1);\ |
||
5486 | clock_ctx.lineTo(x2,y2);\ |
||
5487 | };\ |
||
5488 | for(var p = 1; p <= 60 ; p++){\ |
||
5489 | angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 60));\ |
||
5490 | angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 60));\ |
||
5491 | x1 = 0.9*angle_cos;y1 = 0.9*angle_sin;x2 = angle_cos;y2 = angle_sin;\ |
||
5492 | clock_ctx.moveTo(x1,y1);\ |
||
5493 | clock_ctx.lineTo(x2,y2);\ |
||
5494 | };\ |
||
5495 | clock_ctx.closePath();\ |
||
5496 | clock_ctx.stroke();\ |
||
5497 | break;\ |
||
5498 | case 1:\ |
||
5499 | 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;\ |
||
5500 | 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);};\ |
||
5501 | clock_ctx.beginPath();\ |
||
5502 | for(var p = 1; p <= 12 ; p++){\ |
||
5503 | angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 12));\ |
||
5504 | angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 12));\ |
||
5505 | x1 = 0.9*angle_cos;y1 = 0.9*angle_sin;x2 = angle_cos;y2 = angle_sin;\ |
||
5506 | clock_ctx.moveTo(x1,y1);\ |
||
5507 | clock_ctx.lineTo(x2,y2);\ |
||
5508 | };\ |
||
5509 | for(var p = 1; p <= 60 ; p++){\ |
||
5510 | angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 60));\ |
||
5511 | angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 60));\ |
||
5512 | x1 = 0.95*angle_cos;y1 = 0.95*angle_sin;x2 = angle_cos;y2 = angle_sin;\ |
||
5513 | clock_ctx.moveTo(x1,y1);\ |
||
5514 | clock_ctx.lineTo(x2,y2);\ |
||
5515 | };\ |
||
5516 | clock_ctx.closePath();\ |
||
5517 | clock_ctx.stroke();\ |
||
5518 | break;\ |
||
5519 | };\ |
||
5520 | angle = (this.H - 3 + this.M/60 ) * 2 * Math.PI / 12;\ |
||
5521 | clock_ctx.rotate(angle);\ |
||
5522 | clock_ctx.beginPath();\ |
||
5523 | clock_ctx.moveTo(-3, -2);\ |
||
5524 | clock_ctx.lineTo(-3, 2);\ |
||
5525 | clock_ctx.lineTo(this.radius * 0.7, 1);\ |
||
5526 | clock_ctx.lineTo(this.radius * 0.7, -1);\ |
||
5527 | clock_ctx.fillStyle = this.H_color;\ |
||
5528 | clock_ctx.fill();\ |
||
5529 | clock_ctx.rotate(-angle);\ |
||
5530 | angle = (this.M - 15 + this.S/60) * 2 * Math.PI / 60;\ |
||
5531 | clock_ctx.rotate(angle);\ |
||
5532 | clock_ctx.beginPath();\ |
||
5533 | clock_ctx.moveTo(-3, -2);\ |
||
5534 | clock_ctx.lineTo(-3, 2);\ |
||
5535 | clock_ctx.lineTo(this.radius * 0.8, 1);\ |
||
5536 | clock_ctx.lineTo(this.radius * 0.8, -1);\ |
||
5537 | clock_ctx.fillStyle = this.M_color;\ |
||
5538 | clock_ctx.fill();\ |
||
5539 | clock_ctx.rotate(-angle);\ |
||
5540 | angle = (this.S - 15) * 2 * Math.PI / 60;\ |
||
5541 | clock_ctx.rotate(angle);\ |
||
5542 | clock_ctx.beginPath();\ |
||
5543 | clock_ctx.moveTo(0,0);\ |
||
5544 | clock_ctx.lineTo(this.radius * 0.95, 0);\ |
||
5545 | clock_ctx.lineTo(this.radius * 0.9, -1);\ |
||
5546 | clock_ctx.strokeStyle = this.S_color;\ |
||
5547 | clock_ctx.stroke();\ |
||
5548 | clock_ctx.restore();\ |
||
7653 | schaersvoo | 5549 | };",canvas_root_id,CLOCK_CANVAS); |
7614 | schaersvoo | 5550 | break; |
5551 | |||
5552 | case DRAW_LATTICE: |
||
5553 | fprintf(js_include_file,"\n<!-- draw lattice -->\n\ |
||
5554 | 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){\ |
||
5555 | var obj;\ |
||
5556 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
5557 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
5558 | }\ |
||
5559 | else\ |
||
5560 | {\ |
||
5561 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
5562 | };\ |
||
5563 | var ctx = obj.getContext(\"2d\");\ |
||
5564 | ctx.save();\ |
||
5565 | if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\ |
||
5566 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
||
5567 | ctx.fillStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
5568 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
5569 | var radius = line_width;\ |
||
5570 | var x = 0;\ |
||
5571 | var y = 0;\ |
||
5572 | var x_step_px = xsize/(xmax-xmin);\ |
||
5573 | var y_step_px = ysize/(ymax-ymin);\ |
||
5574 | var xv1 = dx1*x_step_px;\ |
||
5575 | var yv1 = dy1*y_step_px;\ |
||
5576 | var xv2 = dx2*x_step_px;\ |
||
5577 | var yv2 = dy2*y_step_px;\ |
||
5578 | for(var p = 0; p < n1 ;p++){\ |
||
5579 | x = p*xv1 + x0;\ |
||
5580 | y = p*yv1 + y0;\ |
||
5581 | for(var c = 0; c < n2 ; c++){\ |
||
5582 | ctx.beginPath();\ |
||
5583 | ctx.arc(x+c*xv2,y+c*yv2,radius,0,2*Math.PI,false);\ |
||
5584 | ctx.fill();\ |
||
5585 | ctx.stroke();\ |
||
5586 | ctx.closePath();\ |
||
5587 | };\ |
||
5588 | };\ |
||
5589 | ctx.restore();\ |
||
5590 | return;\ |
||
7653 | schaersvoo | 5591 | };",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 5592 | break; |
7735 | schaersvoo | 5593 | case DRAW_XYLOGSCALE: |
5594 | fprintf(js_include_file,"\n<!-- draw xylogscale -->\n\ |
||
7779 | schaersvoo | 5595 | 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 | 5596 | var obj;\n\ |
5597 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\n\ |
||
5598 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\n\ |
||
5599 | }\n\ |
||
5600 | else\n\ |
||
5601 | {\n\ |
||
5602 | obj = create_canvas%d(canvas_type,xsize,ysize);\n\ |
||
5603 | };\n\ |
||
5604 | var ctx = obj.getContext(\"2d\");\n\ |
||
5605 | ctx.clearRect(0,0,xsize,ysize);\ |
||
5606 | ctx.save();\n\ |
||
7739 | schaersvoo | 5607 | var xmarge;var ymarge;var x_e;var y_e;var num;var corr;var xtxt;var ytxt;\ |
5608 | var x_min = Math.log(xmin)/Math.log(xlogbase);\n\ |
||
5609 | var x_max = Math.log(xmax)/Math.log(xlogbase);\n\ |
||
5610 | var y_min = Math.log(ymin)/Math.log(ylogbase);\n\ |
||
5611 | var y_max = Math.log(ymax)/Math.log(ylogbase);\n\ |
||
5612 | if(use_axis_numbering == 1){\ |
||
5613 | ctx.font = font_family;\n\ |
||
5614 | xmarge = ctx.measureText(ylogbase+'^'+y_max.toFixed(0)+' ').width;\n\ |
||
5615 | ymarge = parseInt(1.5*font_size);\n\ |
||
5616 | ctx.save();\n\ |
||
5617 | ctx.fillStyle=\"rgba(255,215,0,0.2)\";\n\ |
||
5618 | ctx.rect(0,0,xmarge,ysize);\n\ |
||
5619 | ctx.rect(0,ysize-ymarge,xsize,ysize);\n\ |
||
5620 | ctx.fill();\n\ |
||
5621 | ctx.restore();\n\ |
||
5622 | }else{xmarge = 0;ymarge = 0;};\n\ |
||
7735 | schaersvoo | 5623 | if( typeof xaxislabel !== 'undefined' ){\ |
7739 | schaersvoo | 5624 | ctx.save();\n\ |
5625 | ctx.font = \"italic \"+font_size+\"px Ariel\";\n\ |
||
5626 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\n\ |
||
5627 | corr = ctx.measureText(xaxislabel).width;\n\ |
||
5628 | ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\n\ |
||
5629 | ctx.restore();\n\ |
||
5630 | };\n\ |
||
7735 | schaersvoo | 5631 | if( typeof yaxislabel !== 'undefined' ){\ |
7739 | schaersvoo | 5632 | ctx.save();\n\ |
5633 | ctx.font = \"italic \"+font_size+\"px Ariel\";\n\ |
||
5634 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\n\ |
||
5635 | corr = ctx.measureText(yaxislabel).width;\n\ |
||
5636 | ctx.translate(xmarge+font_size,corr+font_size);\n\ |
||
5637 | ctx.rotate(-0.5*Math.PI);\n\ |
||
5638 | ctx.fillText(yaxislabel,0,0);\n\ |
||
5639 | ctx.restore();\n\ |
||
5640 | };\n\ |
||
5641 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\n\ |
||
5642 | ctx.lineWidth = line_width;\n\n\ |
||
7735 | schaersvoo | 5643 | for(var p = x_min; p <= x_max ; p++){\n\ |
7739 | schaersvoo | 5644 | num = Math.pow(xlogbase,p);\n\n\ |
7735 | schaersvoo | 5645 | for(var i = 1 ; i < xlogbase ; i++){\n\ |
7739 | schaersvoo | 5646 | x_e = x2px(i*num);\n\n\ |
7735 | schaersvoo | 5647 | if( i == 1 ){\ |
7739 | schaersvoo | 5648 | ctx.lineWidth = line_width;\n\n\ |
5649 | ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\n\ |
||
7738 | schaersvoo | 5650 | if( use_axis_numbering == 1 && p > x_min){\ |
7739 | schaersvoo | 5651 | xtxt = xlogbase+'^'+p.toFixed(0);\n\ |
5652 | corr = 0.5*(ctx.measureText(xtxt).width);\n\ |
||
5653 | ctx.fillText(xtxt,x_e - corr,ysize - 4);\n\ |
||
5654 | };\n\ |
||
7735 | schaersvoo | 5655 | }else{\ |
7739 | schaersvoo | 5656 | ctx.lineWidth = 0.2*line_width;\n\n\ |
5657 | ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\n\ |
||
5658 | };\n\ |
||
7738 | schaersvoo | 5659 | if( x_e >= xmarge ){\ |
5660 | ctx.beginPath();\n\ |
||
5661 | ctx.moveTo(x_e,0);\n\ |
||
7739 | schaersvoo | 5662 | ctx.lineTo(x_e,ysize - ymarge);\n\n\ |
7738 | schaersvoo | 5663 | ctx.stroke();\n\ |
5664 | ctx.closePath();\n\ |
||
5665 | };\ |
||
7735 | schaersvoo | 5666 | };\n\ |
5667 | };\n\ |
||
5668 | for(var p = y_min; p <= y_max ; p++){\n\ |
||
5669 | num = Math.pow(ylogbase,p);\n\ |
||
5670 | for(var i = 1 ; i < ylogbase ; i++){\n\ |
||
5671 | y_e = y2px(i*num);\n\ |
||
7739 | schaersvoo | 5672 | if( i == 1 ){\n\ |
7735 | schaersvoo | 5673 | ctx.lineWidth = line_width;\n\ |
5674 | ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\ |
||
7739 | schaersvoo | 5675 | if( use_axis_numbering == 1 && p > y_min){\n\ |
5676 | ctx.fillText(ylogbase+'^'+p.toFixed(0),0,y_e);\n\ |
||
5677 | };\n\ |
||
5678 | }else{\n\ |
||
7735 | schaersvoo | 5679 | ctx.lineWidth = 0.2*line_width;\n\ |
7739 | schaersvoo | 5680 | ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\n\ |
5681 | };\n\ |
||
7735 | schaersvoo | 5682 | ctx.beginPath();\n\ |
7738 | schaersvoo | 5683 | ctx.moveTo(xmarge,y_e);\n\ |
7735 | schaersvoo | 5684 | ctx.lineTo(xsize,y_e);\n\ |
5685 | ctx.stroke();\n\ |
||
5686 | ctx.closePath();\n\ |
||
5687 | };\n\ |
||
5688 | };\n\ |
||
5689 | ctx.restore();\ |
||
5690 | };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id); |
||
5691 | break; |
||
7614 | schaersvoo | 5692 | |
7735 | schaersvoo | 5693 | case DRAW_XLOGSCALE: |
5694 | fprintf(js_include_file,"\n<!-- draw xlogscale -->\n\ |
||
7779 | schaersvoo | 5695 | 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 | 5696 | var obj;\n\ |
5697 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\n\ |
||
5698 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\n\ |
||
5699 | }\n\ |
||
5700 | else\n\ |
||
5701 | {\n\ |
||
5702 | obj = create_canvas%d(canvas_type,xsize,ysize);\n\ |
||
5703 | };\n\ |
||
5704 | var ctx = obj.getContext(\"2d\");\n\ |
||
5705 | ctx.clearRect(0,0,xsize,ysize);\ |
||
5706 | ctx.save();\n\ |
||
5707 | ctx.lineWidth = line_width;\n\ |
||
7739 | schaersvoo | 5708 | var prec = Math.log(precision)/Math.log(10);\ |
7735 | schaersvoo | 5709 | var x_min = Math.log(xmin)/Math.log(xlogbase);\ |
5710 | var x_max = Math.log(xmax)/Math.log(xlogbase);\ |
||
5711 | var y_min = 0;var y_max = ysize;var x_e;var corr;\ |
||
7739 | schaersvoo | 5712 | var xtxt;var ytxt;var num;var xmarge;var ymarge;\ |
5713 | if(use_axis_numbering == 1){\ |
||
5714 | ctx.font = font_family;\n\ |
||
5715 | xmarge = ctx.measureText(ymax.toFixed(prec)+' ').width;\n\ |
||
5716 | ymarge = parseInt(1.5*font_size);\n\ |
||
5717 | ctx.save();\n\ |
||
5718 | ctx.fillStyle=\"rgba(255,215,0,0.2)\";\n\ |
||
5719 | ctx.rect(0,0,xmarge,ysize);\n\ |
||
5720 | ctx.rect(0,ysize-ymarge,xsize,ysize);\n\ |
||
5721 | ctx.fill();\n\ |
||
5722 | ctx.restore();\n\ |
||
5723 | }else{xmarge = 0;ymarge = 0;};\n\ |
||
5724 | if( typeof xaxislabel !== 'undefined' ){\ |
||
5725 | ctx.save();\n\ |
||
5726 | ctx.font = \"italic \"+font_size+\"px Ariel\";\n\ |
||
5727 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\n\ |
||
5728 | corr = ctx.measureText(xaxislabel).width;\n\ |
||
5729 | ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\n\ |
||
5730 | ctx.restore();\n\ |
||
5731 | };\n\ |
||
5732 | if( typeof yaxislabel !== 'undefined' ){\ |
||
5733 | ctx.save();\n\ |
||
5734 | ctx.font = \"italic \"+font_size+\"px Ariel\";\n\ |
||
5735 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\n\ |
||
5736 | corr = ctx.measureText(yaxislabel).width;\n\ |
||
5737 | ctx.translate(xmarge+font_size,corr+font_size);\n\ |
||
5738 | ctx.rotate(-0.5*Math.PI);\n\ |
||
5739 | ctx.fillText(yaxislabel,0,0);\n\ |
||
5740 | ctx.restore();\n\ |
||
5741 | };\n\ |
||
5742 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\n\ |
||
5743 | ctx.lineWidth = line_width;\n\n\ |
||
7735 | schaersvoo | 5744 | for(var p = x_min; p <= x_max ; p++){\n\ |
5745 | num = Math.pow(xlogbase,p);\n\ |
||
5746 | for(var i = 1 ; i < xlogbase ; i++){\n\ |
||
5747 | x_e = x2px(i*num);\n\ |
||
5748 | if( i == 1 ){\ |
||
7739 | schaersvoo | 5749 | ctx.lineWidth = line_width;\n\ |
5750 | ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\ |
||
5751 | if( use_axis_numbering == 1 && p > x_min ){\ |
||
7735 | schaersvoo | 5752 | xtxt = xlogbase+'^'+p.toFixed(0);\ |
5753 | corr = 0.5*(ctx.measureText(xtxt).width);\ |
||
5754 | ctx.fillText(xtxt,x_e - corr,ysize - 4);\ |
||
5755 | };\ |
||
5756 | }else{\ |
||
5757 | ctx.lineWidth = 0.2*line_width;\n\ |
||
5758 | ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\ |
||
5759 | };\ |
||
7739 | schaersvoo | 5760 | if( x_e >= xmarge ){\ |
5761 | ctx.beginPath();\n\ |
||
5762 | ctx.moveTo(x_e,0);\n\ |
||
5763 | ctx.lineTo(x_e,ysize - ymarge);\n\n\ |
||
5764 | ctx.stroke();\n\ |
||
5765 | ctx.closePath();\n\ |
||
5766 | };\ |
||
5767 | };\ |
||
7735 | schaersvoo | 5768 | };\n\ |
5769 | var stepy = Math.abs(y2px(ymajor) - y2px(0));\ |
||
5770 | var minor_step = stepy / yminor;\ |
||
7749 | schaersvoo | 5771 | for(var y = 0 ; y < ysize - stepy ; y = y + stepy){\ |
7735 | schaersvoo | 5772 | ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\ |
5773 | ctx.lineWidth = line_width;\n\ |
||
5774 | ctx.beginPath();\n\ |
||
7739 | schaersvoo | 5775 | ctx.moveTo(xmarge,y);\n\ |
7735 | schaersvoo | 5776 | ctx.lineTo(xsize,y);\n\ |
5777 | ctx.stroke();\n\ |
||
5778 | ctx.closePath();\n\ |
||
5779 | if( use_axis_numbering == 1){\ |
||
5780 | ytxt = (px2y(y)).toFixed(prec);\ |
||
5781 | ctx.fillText( ytxt,0 ,y + 0.5*font_size );\ |
||
5782 | };\ |
||
5783 | for(var dy = 1 ; dy < yminor ; dy++){\ |
||
5784 | ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\ |
||
5785 | ctx.lineWidth = 0.2*line_width;\n\ |
||
5786 | ctx.beginPath();\n\ |
||
7739 | schaersvoo | 5787 | ctx.moveTo(xmarge,y+dy*minor_step);\ |
7735 | schaersvoo | 5788 | ctx.lineTo(xsize,y+dy*minor_step);\n\ |
5789 | ctx.stroke();\n\ |
||
5790 | ctx.closePath();\n\ |
||
5791 | };\ |
||
5792 | };\ |
||
5793 | ctx.restore();\n\ |
||
5794 | };\n",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id); |
||
5795 | break; |
||
7729 | schaersvoo | 5796 | case DRAW_YLOGSCALE: |
5797 | fprintf(js_include_file,"\n<!-- draw ylogscale -->\n\ |
||
7779 | schaersvoo | 5798 | 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 | 5799 | var obj;\n\ |
5800 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\n\ |
||
5801 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\n\ |
||
5802 | }\n\ |
||
5803 | else\n\ |
||
5804 | {\n\ |
||
5805 | obj = create_canvas%d(canvas_type,xsize,ysize);\n\ |
||
5806 | };\n\ |
||
5807 | var ctx = obj.getContext(\"2d\");\n\ |
||
5808 | ctx.clearRect(0,0,xsize,ysize);\ |
||
5809 | ctx.save();\n\ |
||
5810 | ctx.lineWidth = line_width;\n\ |
||
7735 | schaersvoo | 5811 | var y_min = Math.log(ymin)/Math.log(ylogbase);\ |
5812 | var y_max = Math.log(ymax)/Math.log(ylogbase);\ |
||
5813 | var x_min = 0;var x_max = xsize;var y_s;var y_e;var num;\ |
||
7739 | schaersvoo | 5814 | if(use_axis_numbering == 1){\ |
5815 | ctx.font = font_family;\n\ |
||
5816 | xmarge = ctx.measureText(ylogbase+\"^\"+y_max.toFixed(0)+' ').width;\n\ |
||
5817 | ymarge = 2*font_size;\n\ |
||
5818 | ctx.save();\n\ |
||
5819 | ctx.fillStyle=\"rgba(255,215,0,0.2)\";\n\ |
||
5820 | ctx.rect(0,0,xmarge,ysize);\n\ |
||
5821 | ctx.rect(0,ysize-ymarge,xsize,ysize);\n\ |
||
5822 | ctx.fill();\n\ |
||
5823 | ctx.restore();\n\ |
||
5824 | }else{xmarge = 0;ymarge = 0;};\n\ |
||
5825 | if( typeof xaxislabel !== 'undefined' ){\ |
||
5826 | ctx.save();\n\ |
||
5827 | ctx.font = \"italic \"+font_size+\"px Ariel\";\n\ |
||
5828 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\n\ |
||
5829 | corr = ctx.measureText(xaxislabel).width;\n\ |
||
5830 | ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\n\ |
||
5831 | ctx.restore();\n\ |
||
5832 | };\n\ |
||
5833 | if( typeof yaxislabel !== 'undefined' ){\ |
||
5834 | ctx.save();\n\ |
||
5835 | ctx.font = \"italic \"+font_size+\"px Ariel\";\n\ |
||
5836 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\n\ |
||
5837 | corr = ctx.measureText(yaxislabel).width;\n\ |
||
5838 | ctx.translate(xmarge+font_size,corr+font_size);\n\ |
||
5839 | ctx.rotate(-0.5*Math.PI);\n\ |
||
5840 | ctx.fillText(yaxislabel,0,0);\n\ |
||
5841 | ctx.restore();\n\ |
||
5842 | };\n\ |
||
5843 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\n\ |
||
5844 | ctx.lineWidth = line_width;\n\n\ |
||
7729 | schaersvoo | 5845 | for(var p = y_min; p <= y_max ; p++){\n\ |
7735 | schaersvoo | 5846 | num = Math.pow(ylogbase,p);\n\ |
5847 | for(var i = 1 ; i < ylogbase ; i++){\n\ |
||
7729 | schaersvoo | 5848 | y_e = y2px(i*num);\n\ |
5849 | if( i == 1 ){\ |
||
5850 | ctx.lineWidth = line_width;\n\ |
||
5851 | ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\ |
||
7739 | schaersvoo | 5852 | if( use_axis_numbering == 1 && p > y_min){\ |
7735 | schaersvoo | 5853 | ctx.fillText(ylogbase+'^'+p.toFixed(0),0,y_e);\ |
7729 | schaersvoo | 5854 | };\ |
5855 | }else{\ |
||
5856 | ctx.lineWidth = 0.2*line_width;\n\ |
||
5857 | ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\ |
||
5858 | };\ |
||
5859 | ctx.beginPath();\n\ |
||
7739 | schaersvoo | 5860 | ctx.moveTo(xmarge,y_e);\n\ |
7735 | schaersvoo | 5861 | ctx.lineTo(xsize,y_e);\n\ |
7729 | schaersvoo | 5862 | ctx.stroke();\n\ |
5863 | ctx.closePath();\n\ |
||
5864 | };\n\ |
||
5865 | };\n\ |
||
5866 | var stepx = Math.abs(x2px(xmajor) - x2px(0));\ |
||
5867 | var minor_step = stepx / xminor;\ |
||
5868 | var prec = Math.log(precision)/Math.log(10);\ |
||
5869 | var xtxt;var corr;var flip = 0;\ |
||
7749 | schaersvoo | 5870 | for(var x = stepx ; x < xsize ; x = x + stepx){\ |
7729 | schaersvoo | 5871 | ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\ |
5872 | ctx.lineWidth = line_width;\n\ |
||
5873 | ctx.beginPath();\n\ |
||
7739 | schaersvoo | 5874 | ctx.moveTo(x,ysize-ymarge);\n\ |
7729 | schaersvoo | 5875 | ctx.lineTo(x,0);\n\ |
5876 | ctx.stroke();\n\ |
||
5877 | ctx.closePath();\n\ |
||
5878 | if( use_axis_numbering == 1){\ |
||
5879 | xtxt = (px2x(x)).toFixed(prec);\ |
||
5880 | corr = 0.5*(ctx.measureText(xtxt).width);\ |
||
5881 | if(flip == 0 ){flip = 1;ctx.fillText( xtxt,x - corr ,ysize - 0.2*font_size );}else{\ |
||
5882 | flip = 0;ctx.fillText( xtxt,x - corr ,ysize - 1.2*font_size );};\ |
||
5883 | };\ |
||
5884 | for(var dx = 1 ; dx < xminor ; dx++){\ |
||
5885 | ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\ |
||
5886 | ctx.lineWidth = 0.2*line_width;\n\ |
||
5887 | ctx.beginPath();\n\ |
||
7739 | schaersvoo | 5888 | ctx.moveTo(x+dx*minor_step,ysize - ymarge);\ |
7729 | schaersvoo | 5889 | ctx.lineTo(x+dx*minor_step,0);\n\ |
5890 | ctx.stroke();\n\ |
||
5891 | ctx.closePath();\n\ |
||
7735 | schaersvoo | 5892 | };\ |
5893 | };\ |
||
7729 | schaersvoo | 5894 | ctx.restore();\n\ |
5895 | };\n",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id); |
||
5896 | |||
5897 | break; |
||
7735 | schaersvoo | 5898 | |
5899 | |||
7614 | schaersvoo | 5900 | default:break; |
5901 | } |
||
5902 | } |
||
5903 | } |
||
5904 | return; |
||
5905 | } |
||
5906 | |||
5907 | void check_string_length(int L){ |
||
5908 | if(L<1 || L > MAX_BUFFER-1){ |
||
5909 | canvas_error("problem with your arguments to command..."); |
||
5910 | } |
||
5911 | return; |
||
5912 | } |
||
5913 | |||
5914 | |||
5915 | int get_token(FILE *infile){ |
||
5916 | int c,i=0; |
||
5917 | char temp[MAX_INT], *input_type; |
||
5918 | char *line="line", |
||
5919 | *audio="audio", |
||
5920 | *blink="blink", |
||
5921 | *arrowhead="arrowhead", |
||
5922 | *crosshairsize="crosshairsize", |
||
5923 | *crosshair="crosshair", |
||
5924 | *crosshairs="crosshairs", |
||
5925 | *audioobject="audioobject", |
||
5926 | *style="style", |
||
5927 | *mouse="mouse", |
||
5928 | *userdraw="userdraw", |
||
5929 | *highlight="highlight", |
||
5930 | *http="http", |
||
5931 | *rays="rays", |
||
5932 | *dashtype="dashtype", |
||
5933 | *dashed="dashed", |
||
5934 | *filled="filled", |
||
5935 | *lattice="lattice", |
||
5936 | *parallel="parallel", |
||
5937 | *segment="segment", |
||
5938 | *dsegment="dsegment", |
||
5939 | *seg="seg", |
||
5940 | *bgimage="bgimage", |
||
5941 | *bgcolor="bgcolor", |
||
5942 | *strokecolor="strokecolor", |
||
5943 | *backgroundimage="backgroundimage", |
||
5944 | *text="text", |
||
5945 | *textup="textup", |
||
5946 | *mouseprecision="mouseprecision", |
||
5947 | *precision="precision", |
||
5948 | *plotsteps="plotsteps", |
||
5949 | *plotstep="plotstep", |
||
5950 | *tsteps="tsteps", |
||
5951 | *curve="curve", |
||
5952 | *dcurve="dcurve", |
||
5953 | *plot="plot", |
||
5954 | *dplot="dplot", |
||
7788 | schaersvoo | 5955 | *levelcurve="levelcurve", |
7614 | schaersvoo | 5956 | *fontsize="fontsize", |
5957 | *fontcolor="fontcolor", |
||
5958 | *axis="axis", |
||
5959 | *axisnumbering="axisnumbering", |
||
5960 | *axisnumbers="axisnumbers", |
||
5961 | *arrow="arrow", |
||
5962 | *darrow="darrow", |
||
5963 | *arrow2="arrow2", |
||
5964 | *darrow2="darrow2", |
||
5965 | *zoom="zoom", |
||
5966 | *grid="grid", |
||
5967 | *hline="hline", |
||
7786 | schaersvoo | 5968 | *dhline="dhline", |
7614 | schaersvoo | 5969 | *drag="drag", |
5970 | *horizontalline="horizontalline", |
||
5971 | *vline="vline", |
||
7786 | schaersvoo | 5972 | *dvline="dvline", |
7614 | schaersvoo | 5973 | *verticalline="verticalline", |
5974 | *triangle="triangle", |
||
5975 | *ftriangle="ftriangle", |
||
5976 | *mathml="mathml", |
||
5977 | *html="html", |
||
5978 | *input="input", |
||
5979 | *button="button", |
||
5980 | *inputstyle="inputstyle", |
||
5981 | *textarea="textarea", |
||
5982 | *trange="trange", |
||
5983 | *ranget="ranget", |
||
5984 | *xrange="xrange", |
||
5985 | *yrange="yrange", |
||
5986 | *rangex="rangex", |
||
5987 | *rangey="rangey", |
||
5988 | *polyline="polyline", |
||
5989 | *lines="lines", |
||
5990 | *poly="poly", |
||
5991 | *polygon="polygon", |
||
5992 | *fpolygon="fpolygon", |
||
5993 | *fpoly="fpoly", |
||
5994 | *filledpoly="filledpoly", |
||
5995 | *filledpolygon="filledpolygon", |
||
5996 | *rect="rect", |
||
5997 | *frect="frect", |
||
5998 | *rectangle="rectangle", |
||
5999 | *frectangle="frectangle", |
||
6000 | *square="square", |
||
6001 | *fsquare="fsquare", |
||
6002 | *dline="dline", |
||
6003 | *arc="arc", |
||
6004 | *filledarc="filledarc", |
||
6005 | *size="size", |
||
6006 | *string="string", |
||
6007 | *stringup="stringup", |
||
6008 | *copy="copy", |
||
6009 | *copyresized="copyresized", |
||
6010 | *opacity="opacity", |
||
6011 | *transparent="transparent", |
||
6012 | *fill="fill", |
||
6013 | *slider="slider", |
||
6014 | *point="point", |
||
6015 | *points="points", |
||
6016 | *linewidth="linewidth", |
||
6017 | *circle="circle", |
||
6018 | *fcircle="fcircle", |
||
6019 | *disk="disk", |
||
6020 | *comment="#", |
||
6021 | *end="end", |
||
6022 | *ellipse="ellipse", |
||
6023 | *fellipse="fellipse", |
||
6024 | *rotate="rotate", |
||
7785 | schaersvoo | 6025 | *affine="affine", |
6026 | *killaffine="killaffine", |
||
7614 | schaersvoo | 6027 | *fontfamily="fontfamily", |
6028 | *fillcolor="fillcolor", |
||
6029 | *clicktile="clicktile", |
||
6030 | *clicktile_colors="clicktile_colors", |
||
6031 | *translation="translation", |
||
6032 | *translate="translate", |
||
6033 | *killtranslation="killtranslation", |
||
6034 | *killtranslate="killtranslate", |
||
6035 | *onclick="onclick", |
||
6036 | *roundrect="roundrect", |
||
6037 | *froundrect="froundrect", |
||
6038 | *roundrectangle="roundrectangle", |
||
6039 | *patternfill="patternfill", |
||
6040 | *hatchfill="hatchfill", |
||
6041 | *diafill="diafill", |
||
7647 | schaersvoo | 6042 | *diamondfill="diamondfill", |
7614 | schaersvoo | 6043 | *dotfill="dotfill", |
6044 | *gridfill="gridfill", |
||
6045 | *imagefill="imagefill", |
||
7735 | schaersvoo | 6046 | *xlogbase="xlogbase", |
6047 | *ylogbase="ylogbase", |
||
7614 | schaersvoo | 6048 | *xlogscale="xlogscale", |
6049 | *ylogscale="ylogscale", |
||
6050 | *xylogscale="xylogscale", |
||
6051 | *intooltip="intooltip", |
||
6052 | *replyformat="replyformat", |
||
6053 | *floodfill="floodfill", |
||
6054 | *filltoborder="filltoborder", |
||
6055 | *clickfill="clickfill", |
||
6056 | *setpixel="setpixel", |
||
6057 | *pixels="pixels", |
||
6058 | *pixelsize="pixelsize", |
||
6059 | *clickfillmarge="clickfillmarge", |
||
6060 | *xaxis="xaxis", |
||
6061 | *yaxis="yaxis", |
||
6062 | *xaxistext="xaxistext", |
||
6063 | *yaxistext="yaxistext", |
||
6064 | *piechart="piechart", |
||
6065 | *legend="legend", |
||
6066 | *legendcolors="legendcolors", |
||
6067 | *xlabel="xlabel", |
||
6068 | *ylabel="ylabel", |
||
6069 | *barchart="barchart", |
||
6070 | *linegraph="linegraph", |
||
6071 | *clock="clock", |
||
6072 | *animate="animate", |
||
6073 | *video="video", |
||
6074 | *status="status", |
||
7652 | schaersvoo | 6075 | *snaptogrid="snaptogrid", |
7784 | schaersvoo | 6076 | *xsnaptogrid="xsnaptogrid", |
6077 | *ysnaptogrid="ysnaptogrid", |
||
7654 | schaersvoo | 6078 | *userinput_xy="userinput_xy", |
7663 | schaersvoo | 6079 | *usertextarea_xy="usertextarea_xy", |
7654 | schaersvoo | 6080 | *sgraph="sgraph"; |
7614 | schaersvoo | 6081 | |
6082 | while(((c = getc(infile)) != EOF)&&(c!='\n')&&(c!=',')&&(c!='=')&&(c!='\r')){ |
||
6083 | if( i == 0 && (c == ' ' || c == '\t') ){ |
||
6084 | continue; /* white spaces or tabs allowed before first command identifier */ |
||
6085 | } |
||
6086 | else |
||
6087 | { |
||
6088 | if( c == ' ' || c == '\t' ){ |
||
6089 | break; |
||
6090 | } |
||
6091 | else |
||
6092 | { |
||
6093 | temp[i] = c; |
||
6094 | if(i > MAX_INT - 2){canvas_error("command string too long !");} |
||
6095 | i++; |
||
6096 | } |
||
6097 | } |
||
6098 | if(temp[0] == '#') break; |
||
6099 | } |
||
6100 | if (c == EOF) finished = 1; |
||
6101 | |||
6102 | if (c == '\n' || c == '\r') { |
||
6103 | line_number++; |
||
6104 | if (i == 0) { return EMPTY; } |
||
6105 | } else if (c == EOF) { |
||
6106 | return 0; |
||
6107 | } |
||
6108 | |||
6109 | temp[i]='\0'; |
||
6110 | input_type=(char*)my_newmem(strlen(temp)); |
||
6111 | snprintf(input_type,sizeof(temp),"%s",temp); |
||
6112 | |||
6113 | if( strcmp(input_type, size) == 0 ){ |
||
6114 | free(input_type); |
||
6115 | return SIZE; |
||
6116 | } |
||
6117 | if( strcmp(input_type, xrange) == 0 ){ |
||
6118 | free(input_type); |
||
6119 | return XRANGE; |
||
6120 | } |
||
6121 | if( strcmp(input_type, rangex) == 0 ){ |
||
6122 | free(input_type); |
||
6123 | return XRANGE; |
||
6124 | } |
||
6125 | if( strcmp(input_type, trange) == 0 ){ |
||
6126 | free(input_type); |
||
6127 | return TRANGE; |
||
6128 | } |
||
6129 | if( strcmp(input_type, ranget) == 0 ){ |
||
6130 | free(input_type); |
||
6131 | return TRANGE; |
||
6132 | } |
||
6133 | if( strcmp(input_type, yrange) == 0 ){ |
||
6134 | free(input_type); |
||
6135 | return YRANGE; |
||
6136 | } |
||
6137 | if( strcmp(input_type, rangey) == 0 ){ |
||
6138 | free(input_type); |
||
6139 | return YRANGE; |
||
6140 | } |
||
6141 | if( strcmp(input_type, linewidth) == 0 ){ |
||
6142 | free(input_type); |
||
6143 | return LINEWIDTH; |
||
6144 | } |
||
6145 | if( strcmp(input_type, dashed) == 0 ){ |
||
6146 | free(input_type); |
||
6147 | return DASHED; |
||
6148 | } |
||
6149 | if( strcmp(input_type, dashtype) == 0 ){ |
||
6150 | free(input_type); |
||
6151 | return DASHTYPE; |
||
6152 | } |
||
6153 | if( strcmp(input_type, axisnumbering) == 0 ){ |
||
6154 | free(input_type); |
||
6155 | return AXIS_NUMBERING; |
||
6156 | } |
||
6157 | if( strcmp(input_type, axisnumbers) == 0 ){ |
||
6158 | free(input_type); |
||
6159 | return AXIS_NUMBERING; |
||
6160 | } |
||
6161 | if( strcmp(input_type, axis) == 0 ){ |
||
6162 | free(input_type); |
||
6163 | return AXIS; |
||
6164 | } |
||
6165 | if( strcmp(input_type, grid) == 0 ){ |
||
6166 | free(input_type); |
||
6167 | return GRID; |
||
6168 | } |
||
6169 | if( strcmp(input_type, parallel) == 0 ){ |
||
6170 | free(input_type); |
||
6171 | return PARALLEL; |
||
6172 | } |
||
6173 | if( strcmp(input_type, hline) == 0 || strcmp(input_type, horizontalline) == 0 ){ |
||
6174 | free(input_type); |
||
6175 | return HLINE; |
||
6176 | } |
||
6177 | if( strcmp(input_type, vline) == 0 || strcmp(input_type, verticalline) == 0 ){ |
||
6178 | free(input_type); |
||
6179 | return VLINE; |
||
6180 | } |
||
6181 | if( strcmp(input_type, line) == 0 ){ |
||
6182 | free(input_type); |
||
6183 | return LINE; |
||
6184 | } |
||
6185 | if( strcmp(input_type, seg) == 0 || strcmp(input_type, segment) == 0 ){ |
||
6186 | free(input_type); |
||
6187 | return SEGMENT; |
||
6188 | } |
||
6189 | if( strcmp(input_type, dsegment) == 0 ){ |
||
6190 | free(input_type); |
||
6191 | use_dashed = TRUE; |
||
6192 | return SEGMENT; |
||
6193 | } |
||
6194 | if( strcmp(input_type, crosshairsize) == 0 ){ |
||
6195 | free(input_type); |
||
6196 | return CROSSHAIRSIZE; |
||
6197 | } |
||
6198 | if( strcmp(input_type, arrowhead) == 0 ){ |
||
6199 | free(input_type); |
||
6200 | return ARROWHEAD; |
||
6201 | } |
||
6202 | if( strcmp(input_type, crosshairs) == 0 ){ |
||
6203 | free(input_type); |
||
6204 | return CROSSHAIRS; |
||
6205 | } |
||
6206 | if( strcmp(input_type, crosshair) == 0 ){ |
||
6207 | free(input_type); |
||
6208 | return CROSSHAIR; |
||
6209 | } |
||
6210 | if( strcmp(input_type, onclick) == 0 ){ |
||
6211 | free(input_type); |
||
6212 | return ONCLICK; |
||
6213 | } |
||
6214 | if( strcmp(input_type, drag) == 0 ){ |
||
6215 | free(input_type); |
||
6216 | return DRAG; |
||
6217 | } |
||
6218 | if( strcmp(input_type, userdraw) == 0 ){ |
||
6219 | free(input_type); |
||
6220 | return USERDRAW; |
||
6221 | } |
||
6222 | if( strcmp(input_type, highlight) == 0 || strcmp(input_type, style) == 0 ){ |
||
6223 | free(input_type); |
||
6224 | return STYLE; |
||
6225 | } |
||
6226 | if( strcmp(input_type, fillcolor) == 0 ){ |
||
6227 | free(input_type); |
||
6228 | return FILLCOLOR; |
||
6229 | } |
||
6230 | if( strcmp(input_type, strokecolor) == 0 ){ |
||
6231 | free(input_type); |
||
6232 | return STROKECOLOR; |
||
6233 | } |
||
6234 | if( strcmp(input_type, filled) == 0 ){ |
||
6235 | free(input_type); |
||
6236 | return FILLED; |
||
6237 | } |
||
6238 | if( strcmp(input_type, http) == 0 ){ |
||
6239 | free(input_type); |
||
6240 | return HTTP; |
||
6241 | } |
||
6242 | if( strcmp(input_type, rays) == 0 ){ |
||
6243 | free(input_type); |
||
6244 | return RAYS; |
||
6245 | } |
||
6246 | if( strcmp(input_type, lattice) == 0 ){ |
||
6247 | free(input_type); |
||
6248 | return LATTICE; |
||
6249 | } |
||
6250 | if( strcmp(input_type, bgimage) == 0 ){ |
||
6251 | free(input_type); |
||
6252 | return BGIMAGE; |
||
6253 | } |
||
6254 | if( strcmp(input_type, bgcolor) == 0 ){ |
||
6255 | free(input_type); |
||
6256 | return BGCOLOR; |
||
6257 | } |
||
6258 | if( strcmp(input_type, backgroundimage) == 0 ){ |
||
6259 | free(input_type); |
||
6260 | return BGIMAGE; |
||
6261 | } |
||
6262 | if( strcmp(input_type, text) == 0 ){ |
||
6263 | free(input_type); |
||
6264 | return FLY_TEXT; |
||
6265 | } |
||
6266 | if( strcmp(input_type, textup) == 0 ){ |
||
6267 | free(input_type); |
||
6268 | return FLY_TEXTUP; |
||
6269 | } |
||
6270 | if( strcmp(input_type, mouse) == 0 ){ |
||
6271 | free(input_type); |
||
6272 | return MOUSE; |
||
6273 | } |
||
6274 | if( strcmp(input_type, mouseprecision) == 0 ){ |
||
6275 | free(input_type); |
||
6276 | return MOUSE_PRECISION; |
||
6277 | } |
||
6278 | if( strcmp(input_type, precision) == 0 ){ |
||
6279 | free(input_type); |
||
6280 | return MOUSE_PRECISION; |
||
6281 | } |
||
6282 | if( strcmp(input_type, curve) == 0 ){ |
||
6283 | free(input_type); |
||
6284 | return CURVE; |
||
6285 | } |
||
6286 | if( strcmp(input_type, dcurve) == 0 ){ |
||
7788 | schaersvoo | 6287 | use_dashed = TRUE; |
7614 | schaersvoo | 6288 | free(input_type); |
6289 | return CURVE; |
||
6290 | } |
||
6291 | if( strcmp(input_type, plot) == 0 ){ |
||
6292 | free(input_type); |
||
6293 | return CURVE; |
||
6294 | } |
||
6295 | if( strcmp(input_type, dplot) == 0 ){ |
||
7788 | schaersvoo | 6296 | use_dashed = TRUE; |
7614 | schaersvoo | 6297 | free(input_type); |
6298 | return CURVE; |
||
6299 | } |
||
7788 | schaersvoo | 6300 | if( strcmp(input_type, levelcurve) == 0 ){ |
6301 | free(input_type); |
||
6302 | return LEVELCURVE; |
||
6303 | } |
||
7614 | schaersvoo | 6304 | if( strcmp(input_type, plotsteps) == 0 ){ |
6305 | free(input_type); |
||
6306 | return PLOTSTEPS; |
||
6307 | } |
||
6308 | if( strcmp(input_type, plotstep) == 0 ){ |
||
6309 | free(input_type); |
||
6310 | return PLOTSTEPS; |
||
6311 | } |
||
6312 | if( strcmp(input_type, tsteps) == 0 ){ |
||
6313 | free(input_type); |
||
6314 | return PLOTSTEPS; |
||
6315 | } |
||
6316 | if( strcmp(input_type, fontsize) == 0 ){ |
||
6317 | free(input_type); |
||
6318 | return FONTSIZE; |
||
6319 | } |
||
6320 | if( strcmp(input_type, fontcolor) == 0 ){ |
||
6321 | free(input_type); |
||
6322 | return FONTCOLOR; |
||
6323 | } |
||
6324 | if( strcmp(input_type, arrow) == 0 ){ |
||
6325 | free(input_type); |
||
6326 | return ARROW; |
||
6327 | } |
||
6328 | if( strcmp(input_type, arrow2) == 0 ){ |
||
6329 | free(input_type); |
||
6330 | return ARROW2; |
||
6331 | } |
||
6332 | if( strcmp(input_type, darrow) == 0 ){ |
||
6333 | free(input_type); |
||
6334 | return ARROW; |
||
6335 | } |
||
6336 | if( strcmp(input_type, darrow2) == 0 ){ |
||
6337 | free(input_type); |
||
6338 | use_dashed = TRUE; |
||
6339 | return ARROW2; |
||
6340 | } |
||
6341 | if( strcmp(input_type, zoom) == 0 ){ |
||
6342 | free(input_type); |
||
6343 | return ZOOM; |
||
6344 | } |
||
6345 | if( strcmp(input_type, triangle) == 0 ){ |
||
6346 | free(input_type); |
||
6347 | return TRIANGLE; |
||
6348 | } |
||
6349 | if( strcmp(input_type, ftriangle) == 0 ){ |
||
6350 | free(input_type); |
||
6351 | use_filled = TRUE; |
||
6352 | return TRIANGLE; |
||
6353 | } |
||
6354 | if( strcmp(input_type, input) == 0 ){ |
||
6355 | free(input_type); |
||
6356 | return INPUT; |
||
6357 | } |
||
6358 | if( strcmp(input_type, inputstyle) == 0 ){ |
||
6359 | free(input_type); |
||
6360 | return INPUTSTYLE; |
||
6361 | } |
||
6362 | if( strcmp(input_type, textarea) == 0 ){ |
||
6363 | free(input_type); |
||
6364 | return TEXTAREA; |
||
6365 | } |
||
6366 | if( strcmp(input_type, mathml) == 0 ){ |
||
6367 | free(input_type); |
||
6368 | return MATHML; |
||
6369 | } |
||
6370 | if( strcmp(input_type, html) == 0 ){ |
||
6371 | free(input_type); |
||
6372 | return MATHML; |
||
6373 | } |
||
6374 | if( strcmp(input_type, fontfamily) == 0 ){ |
||
6375 | free(input_type); |
||
6376 | return FONTFAMILY; |
||
6377 | } |
||
6378 | if( strcmp(input_type, lines) == 0 || strcmp(input_type, polyline) == 0 ){ |
||
6379 | free(input_type); |
||
6380 | return POLYLINE; |
||
6381 | } |
||
6382 | if( strcmp(input_type, rect) == 0 || strcmp(input_type, rectangle) == 0 ){ |
||
6383 | free(input_type); |
||
6384 | return RECT; |
||
6385 | } |
||
6386 | if( strcmp(input_type, roundrect) == 0 || strcmp(input_type, roundrectangle) == 0 ){ |
||
6387 | free(input_type); |
||
6388 | return ROUNDRECT; |
||
6389 | } |
||
6390 | if( strcmp(input_type, froundrect) == 0 ){ |
||
6391 | free(input_type); |
||
6392 | use_filled = TRUE; |
||
6393 | return ROUNDRECT; |
||
6394 | } |
||
6395 | if( strcmp(input_type, square) == 0 ){ |
||
6396 | free(input_type); |
||
6397 | return SQUARE; |
||
6398 | } |
||
6399 | if( strcmp(input_type, fsquare) == 0 ){ |
||
6400 | free(input_type); |
||
6401 | use_filled = TRUE; |
||
6402 | return SQUARE; |
||
6403 | } |
||
6404 | if( strcmp(input_type, dline) == 0 ){ |
||
6405 | use_dashed = TRUE; |
||
6406 | free(input_type); |
||
6407 | return LINE; |
||
6408 | } |
||
7786 | schaersvoo | 6409 | if( strcmp(input_type, dvline) == 0 ){ |
6410 | use_dashed = TRUE; |
||
6411 | free(input_type); |
||
6412 | return VLINE; |
||
6413 | } |
||
6414 | if( strcmp(input_type, dhline) == 0 ){ |
||
6415 | use_dashed = TRUE; |
||
6416 | free(input_type); |
||
6417 | return HLINE; |
||
6418 | } |
||
7614 | schaersvoo | 6419 | if( strcmp(input_type, frect) == 0 || strcmp(input_type, frectangle) == 0 ){ |
6420 | use_filled = TRUE; |
||
6421 | free(input_type); |
||
6422 | return RECT; |
||
6423 | } |
||
6424 | if( strcmp(input_type, fcircle) == 0 || strcmp(input_type, disk) == 0 ){ |
||
6425 | use_filled = TRUE; |
||
6426 | free(input_type); |
||
6427 | return CIRCLE; |
||
6428 | } |
||
6429 | if( strcmp(input_type, circle) == 0 ){ |
||
6430 | free(input_type); |
||
6431 | return CIRCLE; |
||
6432 | } |
||
6433 | if( strcmp(input_type, point) == 0 ){ |
||
6434 | free(input_type); |
||
6435 | return POINT; |
||
6436 | } |
||
6437 | if( strcmp(input_type, points) == 0 ){ |
||
6438 | free(input_type); |
||
6439 | return POINTS; |
||
6440 | } |
||
6441 | if( strcmp(input_type, filledarc) == 0 ){ |
||
6442 | use_filled = TRUE; |
||
6443 | free(input_type); |
||
6444 | return ARC; |
||
6445 | } |
||
6446 | if( strcmp(input_type, arc) == 0 ){ |
||
6447 | free(input_type); |
||
6448 | return ARC; |
||
6449 | } |
||
6450 | if( strcmp(input_type, poly) == 0 || strcmp(input_type, polygon) == 0 ){ |
||
6451 | free(input_type); |
||
6452 | return POLY; |
||
6453 | } |
||
6454 | if( strcmp(input_type, fpoly) == 0 || strcmp(input_type, filledpoly) == 0 || strcmp(input_type,filledpolygon) == 0 || strcmp(input_type,fpolygon) == 0 ){ |
||
6455 | use_filled = TRUE; |
||
6456 | free(input_type); |
||
6457 | return POLY; |
||
6458 | } |
||
6459 | if( strcmp(input_type, ellipse) == 0){ |
||
6460 | free(input_type); |
||
6461 | return ELLIPSE; |
||
6462 | } |
||
6463 | if( strcmp(input_type, fill) == 0 ){ |
||
6464 | free(input_type); |
||
6465 | return FLOODFILL; |
||
6466 | } |
||
6467 | if( strcmp(input_type, string) == 0 ){ |
||
6468 | free(input_type); |
||
6469 | return STRING; |
||
6470 | } |
||
6471 | if( strcmp(input_type, stringup) == 0 ){ |
||
6472 | free(input_type); |
||
6473 | return STRINGUP; |
||
6474 | } |
||
6475 | if( strcmp(input_type, opacity) == 0 ){ |
||
6476 | free(input_type); |
||
6477 | return OPACITY; |
||
6478 | } |
||
6479 | if( strcmp(input_type, comment) == 0){ |
||
6480 | free(input_type); |
||
6481 | return COMMENT; |
||
6482 | } |
||
6483 | if( strcmp(input_type, end) == 0){ |
||
6484 | free(input_type); |
||
6485 | return END; |
||
6486 | } |
||
6487 | if( strcmp(input_type, fellipse) == 0){ |
||
6488 | free(input_type); |
||
6489 | use_filled = TRUE; |
||
6490 | return ELLIPSE; |
||
6491 | } |
||
6492 | if( strcmp(input_type, blink) == 0 ){ |
||
6493 | free(input_type); |
||
6494 | return BLINK; |
||
6495 | } |
||
6496 | if( strcmp(input_type, button) == 0){ |
||
6497 | free(input_type); |
||
6498 | return BUTTON; |
||
6499 | } |
||
6500 | if( strcmp(input_type, translation) == 0 || strcmp(input_type, translate) == 0 ){ |
||
6501 | free(input_type); |
||
6502 | return TRANSLATION; |
||
6503 | } |
||
6504 | if( strcmp(input_type, killtranslation) == 0 || strcmp(input_type, killtranslate) == 0){ |
||
6505 | free(input_type); |
||
6506 | return KILLTRANSLATION; |
||
6507 | } |
||
6508 | if( strcmp(input_type, rotate) == 0){ |
||
6509 | free(input_type); |
||
6510 | return ROTATE; |
||
6511 | } |
||
7785 | schaersvoo | 6512 | if( strcmp(input_type, affine) == 0){ |
6513 | free(input_type); |
||
6514 | return AFFINE; |
||
6515 | } |
||
6516 | if( strcmp(input_type, killaffine) == 0){ |
||
6517 | free(input_type); |
||
6518 | return KILLAFFINE; |
||
6519 | } |
||
7614 | schaersvoo | 6520 | if( strcmp(input_type, audio) == 0 ){ |
6521 | free(input_type); |
||
6522 | return AUDIO; |
||
6523 | } |
||
6524 | if( strcmp(input_type, audioobject) == 0 ){ |
||
6525 | free(input_type); |
||
6526 | return AUDIOOBJECT; |
||
6527 | } |
||
6528 | if( strcmp(input_type, slider) == 0 ){ |
||
6529 | free(input_type); |
||
6530 | return SLIDER; |
||
6531 | } |
||
6532 | if( strcmp(input_type, copy) == 0 ){ |
||
6533 | free(input_type); |
||
6534 | return COPY; |
||
6535 | } |
||
6536 | if( strcmp(input_type, copyresized) == 0 ){ |
||
6537 | free(input_type); |
||
6538 | return COPYRESIZED; |
||
6539 | } |
||
6540 | if( strcmp(input_type, patternfill) == 0 ){ |
||
6541 | free(input_type); |
||
6542 | return PATTERNFILL; |
||
6543 | } |
||
6544 | if( strcmp(input_type, hatchfill) == 0 ){ |
||
6545 | free(input_type); |
||
6546 | return HATCHFILL; |
||
6547 | } |
||
7647 | schaersvoo | 6548 | if( strcmp(input_type, diafill) == 0 || strcmp(input_type, diamondfill) == 0 ){ |
7614 | schaersvoo | 6549 | free(input_type); |
7647 | schaersvoo | 6550 | return DIAMONDFILL; |
7614 | schaersvoo | 6551 | } |
6552 | if( strcmp(input_type, dotfill) == 0 ){ |
||
6553 | free(input_type); |
||
6554 | return DOTFILL; |
||
6555 | } |
||
6556 | if( strcmp(input_type, gridfill) == 0 ){ |
||
6557 | free(input_type); |
||
6558 | return GRIDFILL; |
||
6559 | } |
||
6560 | if( strcmp(input_type, imagefill) == 0 ){ |
||
6561 | free(input_type); |
||
6562 | return IMAGEFILL; |
||
6563 | } |
||
6564 | if( strcmp(input_type, clicktile_colors) == 0 ){ |
||
6565 | free(input_type); |
||
6566 | return CLICKTILE_COLORS; |
||
6567 | } |
||
6568 | if( strcmp(input_type, clicktile) == 0 ){ |
||
6569 | free(input_type); |
||
6570 | return CLICKTILE; |
||
6571 | } |
||
6572 | if( strcmp(input_type, xlogscale) == 0 ){ |
||
6573 | free(input_type); |
||
6574 | return XLOGSCALE; |
||
6575 | } |
||
6576 | if( strcmp(input_type, ylogscale) == 0 ){ |
||
6577 | free(input_type); |
||
6578 | return YLOGSCALE; |
||
6579 | } |
||
6580 | if( strcmp(input_type, xylogscale) == 0 ){ |
||
6581 | free(input_type); |
||
6582 | return XYLOGSCALE; |
||
6583 | } |
||
6584 | if( strcmp(input_type, ylogscale) == 0 ){ |
||
6585 | free(input_type); |
||
6586 | return YLOGSCALE; |
||
6587 | } |
||
7735 | schaersvoo | 6588 | if( strcmp(input_type, xlogbase) == 0 ){ |
7614 | schaersvoo | 6589 | free(input_type); |
7735 | schaersvoo | 6590 | return XLOGBASE; |
7614 | schaersvoo | 6591 | } |
7735 | schaersvoo | 6592 | if( strcmp(input_type, ylogbase) == 0 ){ |
6593 | free(input_type); |
||
6594 | return YLOGBASE; |
||
6595 | } |
||
7614 | schaersvoo | 6596 | if( strcmp(input_type, intooltip) == 0 ){ |
6597 | free(input_type); |
||
6598 | return INTOOLTIP; |
||
6599 | } |
||
6600 | if( strcmp(input_type,video) == 0 ){ |
||
6601 | free(input_type); |
||
6602 | return VIDEO; |
||
6603 | } |
||
6604 | if( strcmp(input_type,floodfill) == 0 || strcmp(input_type,fill) == 0 ){ |
||
6605 | free(input_type); |
||
6606 | return FLOODFILL; |
||
6607 | } |
||
6608 | if( strcmp(input_type,filltoborder) == 0 ){ |
||
6609 | free(input_type); |
||
6610 | return FILLTOBORDER; |
||
6611 | } |
||
6612 | if( strcmp(input_type,clickfill) == 0 ){ |
||
6613 | free(input_type); |
||
6614 | return CLICKFILL; |
||
6615 | } |
||
6616 | if( strcmp(input_type, replyformat) == 0 ){ |
||
6617 | free(input_type); |
||
6618 | return REPLYFORMAT; |
||
6619 | } |
||
6620 | if( strcmp(input_type, pixelsize) == 0 ){ |
||
6621 | free(input_type); |
||
6622 | return PIXELSIZE; |
||
6623 | } |
||
6624 | if( strcmp(input_type, setpixel) == 0 ){ |
||
6625 | free(input_type); |
||
6626 | return SETPIXEL; |
||
6627 | } |
||
6628 | if( strcmp(input_type, pixels) == 0 ){ |
||
6629 | free(input_type); |
||
6630 | return PIXELS; |
||
6631 | } |
||
6632 | if( strcmp(input_type, clickfillmarge) == 0 ){ |
||
6633 | free(input_type); |
||
6634 | return CLICKFILLMARGE; |
||
6635 | } |
||
6636 | if( strcmp(input_type, xaxis) == 0 || strcmp(input_type, xaxistext) == 0 ){ |
||
6637 | free(input_type); |
||
6638 | return X_AXIS_STRINGS; |
||
6639 | } |
||
6640 | if( strcmp(input_type, yaxis) == 0 || strcmp(input_type, yaxistext) == 0 ){ |
||
6641 | free(input_type); |
||
6642 | return Y_AXIS_STRINGS; |
||
6643 | } |
||
6644 | if( strcmp(input_type, piechart) == 0 ){ |
||
6645 | free(input_type); |
||
6646 | return PIECHART; |
||
6647 | } |
||
6648 | if( strcmp(input_type, barchart) == 0 ){ |
||
6649 | free(input_type); |
||
6650 | return BARCHART; |
||
6651 | } |
||
6652 | if( strcmp(input_type, linegraph) == 0 ){ |
||
6653 | free(input_type); |
||
6654 | return LINEGRAPH; |
||
6655 | } |
||
6656 | if( strcmp(input_type, clock) == 0 ){ |
||
6657 | free(input_type); |
||
6658 | return CLOCK; |
||
6659 | } |
||
6660 | if( strcmp(input_type, legend) == 0 ){ |
||
6661 | free(input_type); |
||
6662 | return LEGEND; |
||
6663 | } |
||
6664 | if( strcmp(input_type, legendcolors) == 0 ){ |
||
6665 | free(input_type); |
||
6666 | return LEGENDCOLORS; |
||
6667 | } |
||
6668 | if( strcmp(input_type, xlabel) == 0 ){ |
||
6669 | free(input_type); |
||
6670 | return XLABEL; |
||
6671 | } |
||
6672 | if( strcmp(input_type, ylabel) == 0 ){ |
||
6673 | free(input_type); |
||
6674 | return YLABEL; |
||
6675 | } |
||
6676 | if( strcmp(input_type, animate) == 0 ){ |
||
6677 | free(input_type); |
||
6678 | return ANIMATE; |
||
6679 | } |
||
6680 | /* these are bitmap related flydraw commmands...must be removed. eventually */ |
||
6681 | if( strcmp(input_type, transparent) == 0 ){ |
||
6682 | free(input_type); |
||
6683 | return TRANSPARENT; |
||
6684 | } |
||
6685 | if( strcmp(input_type, status) == 0 ){ |
||
6686 | free(input_type); |
||
6687 | return STATUS; |
||
6688 | } |
||
6689 | if( strcmp(input_type, snaptogrid) == 0 ){ |
||
6690 | free(input_type); |
||
6691 | return SNAPTOGRID; |
||
6692 | } |
||
7784 | schaersvoo | 6693 | if( strcmp(input_type, xsnaptogrid) == 0 ){ |
6694 | free(input_type); |
||
6695 | return XSNAPTOGRID; |
||
6696 | } |
||
6697 | if( strcmp(input_type, ysnaptogrid) == 0 ){ |
||
6698 | free(input_type); |
||
6699 | return YSNAPTOGRID; |
||
6700 | } |
||
7652 | schaersvoo | 6701 | if( strcmp(input_type, userinput_xy) == 0 ){ |
7614 | schaersvoo | 6702 | free(input_type); |
7652 | schaersvoo | 6703 | return USERINPUT_XY; |
6704 | } |
||
7663 | schaersvoo | 6705 | if( strcmp(input_type, usertextarea_xy) == 0 ){ |
6706 | free(input_type); |
||
6707 | return USERTEXTAREA_XY; |
||
6708 | } |
||
7654 | schaersvoo | 6709 | if( strcmp(input_type, sgraph) == 0 ){ |
7652 | schaersvoo | 6710 | free(input_type); |
7654 | schaersvoo | 6711 | return SGRAPH; |
6712 | } |
||
6713 | free(input_type); |
||
7614 | schaersvoo | 6714 | ungetc(c,infile); |
6715 | return 0; |
||
6716 | } |
||
6717 | |||
7729 | schaersvoo | 6718 |