Rev 8262 | Rev 8299 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
7614 | schaersvoo | 1 | /* |
2 | 27/7/2013 version 0.01 |
||
3 | "Inspired" by FLY program: http://martin.gleeson.com/fly |
||
4 | ********************************************************************************* |
||
5 | * J.M. Evers 7/2013 * |
||
6 | * This is all just amateur scriblings... So no copyrights. * |
||
7 | * This source code file, and compiled objects derived from it, * |
||
8 | * can be used and distributed without restriction, including for commercial use * |
||
9 | * No warrenty whatsoever * |
||
10 | ********************************************************************************* |
||
11 | */ |
||
7848 | bpr | 12 | #include "canvasdraw.h" |
7614 | schaersvoo | 13 | |
14 | /****************************************************************************** |
||
15 | ** Internal Functions |
||
16 | ******************************************************************************/ |
||
17 | void add_to_buffer(char *tmp); /* add tmp_buffer to the buffer */ |
||
18 | void sync_input(FILE *infile);/* proceed with inputfile */ |
||
19 | void add_javascript_functions(int js_functions[], int canvas_root_id); |
||
20 | void reset();/* reset some global variables like "use_filled" , "use_dashed" */ |
||
21 | int get_token(FILE *infile); /* read next char until EOL*/ |
||
8225 | bpr | 22 | /* |
7614 | schaersvoo | 23 | int x2px(double x); |
24 | int y2px(double y); |
||
8225 | bpr | 25 | */ |
7614 | schaersvoo | 26 | double px2x(int x); |
27 | double px2y(int y); |
||
7906 | schaersvoo | 28 | double get_real(FILE *infile,int last); /* read a value; calculation and symbols allowed */ |
7614 | schaersvoo | 29 | char *str_replace ( const char *word, const char *sub_word, const char *rep_word ); |
30 | char *get_color(FILE *infile,int last); /* read hex-color or colorname -> hex */ |
||
7906 | schaersvoo | 31 | char *get_string(FILE *infile,int last); /* get the string at the end of a command */ |
7614 | schaersvoo | 32 | char *get_string_argument(FILE *infile,int last); /* the same, but with "comma" as separator */ |
33 | char *convert_hex2rgb(char *hexcolor); |
||
8257 | schaersvoo | 34 | void add_read_canvas(int canvas_root_id,int reply_format,int reply_precision); |
7614 | schaersvoo | 35 | void make_js_include(int canvas_root_id); |
36 | void check_string_length(int length);/* checks if the length of string argument of command is correct */ |
||
8224 | bpr | 37 | FILE *js_include_file; |
7614 | schaersvoo | 38 | FILE *get_file(int *line_number, char **filename); |
39 | FILE *infile; /* will be stdin */ |
||
40 | /****************************************************************************** |
||
41 | ** global |
||
42 | ******************************************************************************/ |
||
43 | int finished = FALSE;/* main variable for signalling the end of the fly-script ; if finished = 1 ; write to stdout or canvasz */ |
||
44 | int line_number = 1;/* used in canvas_error() ; keep track of line number in canvasdraw/fly - script */ |
||
45 | /* set some variables to avoid trouble (NaN) in case of syntax and other usage errors */ |
||
46 | int xsize = 320; |
||
47 | int ysize = 320; |
||
48 | double xmin = 0.0; |
||
49 | double xmax = 320.0; |
||
50 | double ymin = 0.0; |
||
51 | double ymax = 320.0; |
||
52 | double tmax = 2; |
||
53 | double tmin = -2; |
||
54 | /* flag to indicate parsing of line status */ |
||
8224 | bpr | 55 | int done = FALSE; |
7614 | schaersvoo | 56 | int type; /* eg command number */ |
57 | int onclick = 0;/* 0 = noninteractive ; 1 = onclick ; 2 = draggable*/ |
||
8097 | schaersvoo | 58 | int slider = 0;/* slider=1 : x-values ; slider=2 : y-values;slider=3 angle values */ |
7785 | schaersvoo | 59 | int use_affine = FALSE; |
7614 | schaersvoo | 60 | int use_rotate = FALSE; |
61 | int use_filled = FALSE; |
||
62 | int use_dashed = FALSE; /* dashing not natively supported in firefox , for now... */ |
||
8097 | schaersvoo | 63 | |
7614 | schaersvoo | 64 | char buffer[MAX_BUFFER];/* contains js-functions with arguments ... all other basic code is directly printed into js-include file */ |
65 | |||
66 | /****************************************************************************** |
||
67 | ** Main Program |
||
68 | ******************************************************************************/ |
||
69 | int main(int argc, char *argv[]){ |
||
70 | /* need unique id for every call to canvasdraw : rand(); is too slow...will result in many identical id's */ |
||
71 | struct timeval tv;struct timezone tz;gettimeofday(&tv, &tz);unsigned int canvas_root_id = (unsigned int) tv.tv_usec; |
||
72 | infile = stdin;/* read flyscript via stdin */ |
||
73 | int i,c; |
||
74 | double double_data[MAX_INT+1]; |
||
75 | int int_data[MAX_INT+1]; |
||
76 | for(i=0;i<MAX_INT;i++){int_data[i]=0;double_data[i]=0;} |
||
77 | int use_parametric = FALSE;/* will be reset after parametric plotting */ |
||
78 | int use_axis = FALSE; |
||
79 | int use_axis_numbering = FALSE; |
||
7797 | schaersvoo | 80 | int use_pan_and_zoom = FALSE; |
7956 | schaersvoo | 81 | int use_safe_eval = FALSE; /* if true, add just once : js function to evaluate userinput values for plotting etc */ |
7858 | schaersvoo | 82 | int use_js_math = FALSE; /* if true add js-function to convert math_function --> javascript math_function */ |
83 | int use_js_plot = FALSE; /* if true , let js-engine plot the curve */ |
||
7614 | schaersvoo | 84 | int line_width = 1; |
85 | int decimals = 2; |
||
86 | int precision = 100; /* 10 = 1;100=2;1000=3 decimal display for mouse coordinates or grid coordinate */ |
||
87 | int use_userdraw = FALSE; /* flag to indicate user interaction: incompatible with "drag & drop" code !! */ |
||
88 | int drag_type = -1;/* 0,1,2 : xy,x,y */ |
||
89 | int use_tooltip = FALSE; |
||
90 | char *tooltip_text = "Click here"; |
||
91 | char *temp = ""; /* */ |
||
92 | char *bgcolor = "";/* used for background of canvas_div ; default is tranparent */ |
||
93 | char *stroke_color = "255,0,0"; |
||
94 | char *fill_color = "0,255,0"; |
||
95 | char *font_family = "12px Ariel"; /* commands xaxistext,yaxistext,legend,text/textup/string/stringup may us this */ |
||
96 | char *font_color = "#00000"; |
||
97 | char *draw_type = "points"; |
||
98 | char *fly_font = "normal"; |
||
99 | char *input_style = ""; |
||
100 | char *flytext = ""; |
||
7785 | schaersvoo | 101 | char *affine_matrix = "[1,0,0,1,0,0]"; |
8297 | schaersvoo | 102 | char *function_label = "f(x)="; |
7614 | schaersvoo | 103 | int pixelsize = 1; |
104 | int reply_format = 0; |
||
105 | int input_cnt = 0; |
||
106 | int ext_img_cnt = 0; |
||
8071 | schaersvoo | 107 | int slider_cnt = 0; |
7614 | schaersvoo | 108 | int font_size = 12; |
8071 | schaersvoo | 109 | int dashtype[2] = { 4 , 4 }; |
7614 | schaersvoo | 110 | int js_function[MAX_JS_FUNCTIONS]; /* javascript functions include objects on demand basis : only once per object type */ |
111 | for(i=0;i<MAX_JS_FUNCTIONS;i++){js_function[i]=0;} |
||
112 | int arrow_head = 8; /* size in px*/ |
||
7833 | schaersvoo | 113 | int crosshair_size = 5; /* size in px*/ |
8224 | bpr | 114 | int plot_steps = 250; |
7983 | schaersvoo | 115 | int found_size_command = 0; /* 1 = found size ; 2 = found xrange; 3 = found yrange*/ |
7614 | schaersvoo | 116 | int click_cnt = 1; |
117 | int clock_cnt = 0; /* counts the amount of clocks used -> unique object clock%d */ |
||
118 | int linegraph_cnt = 0; /* identifier for command 'linegraph' ; multiple line graphs may be plotted in a single plot*/ |
||
7989 | schaersvoo | 119 | int barchart_cnt = 0; /* identifier for command 'barchart' ; multiple charts may be plotted in a single plot*/ |
7956 | schaersvoo | 120 | int legend_cnt = -1; /* to allow multiple legends to be used, for multiple piecharts etc */ |
8074 | schaersvoo | 121 | int reply_precision = 100; /* used for precision of student answers / drawings */ |
7614 | schaersvoo | 122 | double angle = 0.0; |
123 | int clickfillmarge = 20; |
||
124 | int animation_type = 9; /* == object type curve in drag library */ |
||
7823 | schaersvoo | 125 | int use_input_xy = 0; /* 1= input fields 2= textarea 3=calc y value*/ |
8112 | schaersvoo | 126 | int use_slider_display = 0; /* in case of a slider, should we display it's value ?*/ |
7614 | schaersvoo | 127 | size_t string_length = 0; |
128 | double stroke_opacity = 0.8; |
||
129 | double fill_opacity = 0.8; |
||
130 | char *URL = "http://localhost/images"; |
||
131 | memset(buffer,'\0',MAX_BUFFER); |
||
132 | void *tmp_buffer = ""; |
||
8224 | bpr | 133 | |
7614 | schaersvoo | 134 | /* default writing a unzipped js-include file into wims getfile directory */ |
135 | char *w_wims_session = getenv("w_wims_session"); |
||
8224 | bpr | 136 | if( w_wims_session == NULL || *w_wims_session == 0 ){ |
7614 | schaersvoo | 137 | canvas_error("Hmmm, your wims environment does not exist...\nCanvasdraw should be used within wims."); |
138 | } |
||
139 | int L0=strlen(w_wims_session) + 21; |
||
140 | char *getfile_dir = my_newmem(L0); /* create memory to fit string precisely */ |
||
141 | snprintf(getfile_dir,L0, "../sessions/%s/getfile",w_wims_session);/* string will fit precisely */ |
||
142 | mode_t process_mask = umask(0); /* check if file exists */ |
||
143 | int result = mkdir(getfile_dir, S_IRWXU | S_IRWXG | S_IRWXO); |
||
144 | if( result == 0 || errno == EEXIST ){ |
||
145 | umask(process_mask); /* be sure to set correct permission */ |
||
8224 | bpr | 146 | char *w_session = getenv("w_session"); |
7614 | schaersvoo | 147 | int L1 = (int) (strlen(w_session)) + find_number_of_digits(canvas_root_id) + 48; |
148 | char *getfile_cmd = my_newmem(L1); /* create memory to fit string precisely */ |
||
8224 | bpr | 149 | snprintf(getfile_cmd,L1,"wims.cgi?session=%s&cmd=getfile&special_parm=%d.js",w_session,canvas_root_id);/* extension ".gz" is MANDATORY for webserver */ |
7614 | schaersvoo | 150 | /* write the include tag to html page:<script type="text/javascript" src="wims.cgi?session=%s&cmd=getfile&special_parm=11223344_js"></script> */ |
151 | /* now write file into getfile dir*/ |
||
152 | char *w_wims_home = getenv("w_wims_home"); /* "/home/users/wims" : we need absolute path for location */ |
||
153 | int L2 = (int) (strlen(w_wims_home)) + (int) (strlen(w_wims_session)) + find_number_of_digits(canvas_root_id) + 23; |
||
154 | char *location = my_newmem(L2); /* create memory to fit string precisely */ |
||
155 | snprintf(location,L2,"%s/sessions/%s/getfile/%d.js",w_wims_home,w_wims_session,canvas_root_id);/*absolute path */ |
||
156 | js_include_file = fopen(location,"w");/* open the file location for writing */ |
||
157 | /* check on opening...if nogood : mount readonly? disk full? permissions not set correctly? */ |
||
158 | if(js_include_file == NULL){ canvas_error("SHOULD NOT HAPPEN : could not write to javascript include file...check your system logfiles !" );} |
||
159 | |||
160 | /* ----------------------------------------------------- */ |
||
161 | /* while more lines to process */ |
||
162 | |||
163 | while(!finished){ |
||
7983 | schaersvoo | 164 | if(line_number>1 && found_size_command == 0){canvas_error("command \"size xsize,ysize\" needs to come first ! ");} |
7614 | schaersvoo | 165 | type = get_token(infile); |
166 | done = FALSE; |
||
167 | /* |
||
168 | @canvasdraw |
||
8224 | bpr | 169 | @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...) |
8262 | schaersvoo | 170 | @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><li> all draggable objects may have a slider for translation / rotation; several objects may be translated / rotated by a single slider</li> <li> a draggable object can be set draggable by a preceding command 'drag x/y/xy'<br />The translation can be read by javascript:read_dragdrop();The replyformat is : object_number : x-orig : y-orig : x-drag : y-drag<br />The x-orig/y-orig will be returned in maximum precision (javascript float)...<br />the x-drag/y-drag will be returned in defined 'precision' number of decimals<br />Multiple objects may be set draggable / clickable (no limit)<br /> not all flydraw objects may be dragged / clicked<br />Only draggable / clickable objects will be scaled on 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.</li></ul> |
171 | @If needed multiple interactive scripts may be used in a single webpage.<br />A function 'read_canvas()' and / or 'read_dragdrop()' can read all interactive userdata from these images.<br />The global array 'canvas_scripts' will contain all unique random "canvas_root_id" of the included scripts.<br />The included local javascript "read" functions "read_canvas%d()" and "read_dragdrop%d()" will have this "%d = canvas_root_id"<br />e.g. canvas_scripts[0] will be the random id of the first script in the page and will thus provide a function<br />fun = eval("read_canvas"+canvas_scripts[0]) to read user based drawings / inputfield in this first image.<br />The read_dragdrop is analogue.<br />Use command 'replyformat' to format the replies for an individual canvas script,<br />To read all user interactions from all included canvas scripts , use something like:<br /><em>function read_all_canvas_images(){<br /> var script_len = canvas_scripts.length;<br /> var draw_reply = "";<br /> var found_result = false;<br /> for(var p = 0 ; p < script_len ; p++){<br /> var fun = eval("read_canvas"+canvas_scripts[p]);<br /> if( typeof fun === 'function'){<br /> var result = fun();<br /> if( result && result.length != 0){<br /> if(script_len == 1 ){ return result;};<br /> found_result = true;<br /> draw_reply = draw_reply + result + "\\n";<br /> };<br /> };<br /> };<br /> if( found_result ){return draw_reply;}else{return null;};<br />};</em> |
||
7614 | schaersvoo | 172 | */ |
173 | switch(type){ |
||
174 | case END: |
||
175 | finished = 1; |
||
176 | done = TRUE; |
||
177 | break; |
||
178 | case 0: |
||
179 | sync_input(infile); |
||
180 | break; |
||
181 | case COMMENT: |
||
182 | sync_input(infile); |
||
183 | break; |
||
184 | case EMPTY: |
||
185 | sync_input(infile); |
||
186 | break; |
||
187 | case SIZE: |
||
188 | /* |
||
189 | @size width,height |
||
190 | @set canvas size in pixels |
||
191 | @mandatory first command |
||
7906 | schaersvoo | 192 | @if xrange and/or yrange is not given the range will be set to pixels :<br />xrange 0,xsize yrange 0,ysize<br />note: lower left corner is Origin (0:0) !!! this in contrast to flydraw |
7614 | schaersvoo | 193 | */ |
7983 | schaersvoo | 194 | found_size_command = 1; |
7614 | schaersvoo | 195 | xsize = (int)(abs(round(get_real(infile,0)))); /* just to be sure that sizes > 0 */ |
196 | ysize = (int)(abs(round(get_real(infile,1)))); |
||
197 | /* sometimes we want xrange / yrange to be in pixels...without telling x/y-range */ |
||
198 | xmin = 0;xmax = xsize; |
||
7647 | schaersvoo | 199 | ymin = 0;ymax = ysize; |
7614 | schaersvoo | 200 | |
8224 | bpr | 201 | /* |
7614 | schaersvoo | 202 | The sequence in which stuff is finally printed is important !! |
203 | for example, when writing a 'include.js" the may not be a "script tag <script>" etc etc |
||
204 | */ |
||
8257 | schaersvoo | 205 | fprintf(stdout,"\n<script type=\"text/javascript\">\ |
206 | if( typeof wims_status === 'undefined' ){ var wims_status = \"$status\";};\ |
||
207 | if( typeof use_dragdrop_reply === 'undefined' ){ var use_dragdrop_reply = false;};\ |
||
208 | if( typeof canvas_scripts === 'undefined' ){ var canvas_scripts = new Array();};\ |
||
209 | canvas_scripts.push(\"%d\");</script>\n\ |
||
210 | <!-- canvasdraw div and tooltip placeholder, if needed -->\n<div tabindex=\"0\" id=\"canvas_div%d\" style=\"position:relative;width:%dpx;height:%dpx;margin-left:auto;margin-right:auto;\" ></div><div id=\"tooltip_placeholder_div%d\" style=\"display:block;margin-bottom:4px;\"><span id=\"tooltip_placeholder%d\" style=\"display:none;\"></span></div>\n",canvas_root_id,canvas_root_id,xsize,ysize,canvas_root_id,canvas_root_id); |
||
211 | fprintf(stdout,"<!-- include actual object code via include file -->\n<script id=\"canvas_script%d\" type=\"text/javascript\" src=\"%s\"></script>\n",canvas_root_id,getfile_cmd); |
||
8146 | schaersvoo | 212 | fprintf(js_include_file,"\n<!-- begin generated javascript include for canvasdraw -->\n\ |
8108 | schaersvoo | 213 | \"use strict\";\n\ |
8146 | schaersvoo | 214 | <!-- these variables and functions must be global -->\n\ |
8257 | schaersvoo | 215 | var read_dragdrop%d;\ |
216 | var read_canvas%d;\ |
||
8130 | schaersvoo | 217 | var set_clock;\ |
8146 | schaersvoo | 218 | var clear_draw_area;\ |
8257 | schaersvoo | 219 | var wims_canvas_function%d = function(){\n<!-- common used stuff -->\n\ |
8146 | schaersvoo | 220 | var userdraw_x = [];var userdraw_y = [];var userdraw_radius = [];\n\ |
7729 | schaersvoo | 221 | var xsize = %d;\ |
222 | var ysize = %d;\ |
||
7797 | schaersvoo | 223 | var precision = 100;\ |
7729 | schaersvoo | 224 | var canvas_div = document.getElementById(\"canvas_div%d\");\ |
8105 | schaersvoo | 225 | var create_canvas%d = function(canvas_type,size_x,size_y){var cnv;if(document.getElementById(\"wims_canvas%d\"+canvas_type)){ cnv = document.getElementById(\"wims_canvas%d\"+canvas_type);}else{try{ cnv = document.createElement(\"canvas\"); }catch(e){alert(\"Your browser does not support HTML5 CANVAS:GET FIREFOX !\");return;};canvas_div.appendChild(cnv);};cnv.width = size_x;cnv.height = size_y;cnv.style.top = 0;cnv.style.left = 0;cnv.style.position = \"absolute\";cnv.id = \"wims_canvas%d\"+canvas_type;return cnv;};\ |
7729 | schaersvoo | 226 | 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;};\ |
7990 | schaersvoo | 227 | function x2px(x){if(use_xlogscale == 0 ){return parseFloat(x*xsize/(xmax - xmin) - xsize*xmin/(xmax - xmin));}else{var x_max = Math.log(xmax)/Math.log(xlogbase);var x_min = Math.log(xmin)/Math.log(xlogbase);var x_in = Math.log(x)/Math.log(xlogbase);return x_in*xsize/(x_max - x_min) - xsize*x_min/(x_max - x_min);};};\ |
228 | function px2x(px){if(use_xlogscale == 0 ){return parseFloat(px*(xmax - xmin)/xsize + xmin);}else{var x_max = Math.log(xmax)/Math.log(xlogbase);var x_min = Math.log(xmin)/Math.log(xlogbase);var x_out = x_min +px*(x_max - x_min)/(xsize);return Math.pow(xlogbase,x_out);};};\ |
||
229 | function px2y(py){if(use_ylogscale == 0 ){return parseFloat(ymax - py*(ymax - ymin)/ysize);}else{var y_max = Math.log(ymax)/Math.log(ylogbase);var y_min = Math.log(ymin)/Math.log(ylogbase);var y_out = y_max +py*(y_min - y_max)/(ysize);return Math.pow(ylogbase,y_out);};};\ |
||
230 | function y2px(y){if(use_ylogscale == 0){return parseFloat(-1*y*ysize/(ymax - ymin) + ymax*ysize/(ymax - ymin));}else{var y_max = Math.log(ymax)/Math.log(ylogbase);var y_min = Math.log(ymin)/Math.log(ylogbase);var y_in = Math.log(y)/Math.log(ylogbase);return (y_max - y_in)*ysize/(y_max - y_min);};};\ |
||
8071 | schaersvoo | 231 | function scale_x_radius(rx){return rx*xsize/(xmax - xmin);};\ |
232 | function scale_y_radius(ry){return ry*ysize/(ymax - ymin);};\ |
||
7729 | schaersvoo | 233 | function distance(x1,y1,x2,y2){return parseInt(Math.sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) ));};\ |
234 | 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) ));};\ |
||
8105 | schaersvoo | 235 | 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;};\ |
236 | function slide(obj,dx,dy){for(var p = 0 ; p < obj.x.length; p++){obj.x[p] = x2px(obj.xorg[p] + dx);obj.y[p] = y2px(obj.yorg[p] + dy);};return obj;};\ |
||
7881 | schaersvoo | 237 | var x_use_snap_to_grid = 0;var y_use_snap_to_grid = 0;var snap_x = 1;var snap_y = 1;\ |
238 | function snap_to_x(x){return x2px(snap_x*(Math.round((px2x(x))/snap_x)));};\ |
||
239 | function snap_to_y(y){return y2px(snap_y*(Math.round((px2y(y))/snap_y)));};\ |
||
7735 | schaersvoo | 240 | var xlogbase = 10;\ |
241 | var ylogbase = 10;\ |
||
7729 | schaersvoo | 242 | var use_xlogscale = 0;\ |
243 | var use_ylogscale = 0;\ |
||
244 | var x_strings = null;\ |
||
245 | var y_strings = null;\ |
||
246 | var use_pan_and_zoom = 0;\ |
||
7858 | schaersvoo | 247 | var use_jsmath = 0;\ |
7729 | schaersvoo | 248 | var xstart = 0;\ |
7996 | schaersvoo | 249 | var ystart = 0;\ |
250 | var unit_x=\" \";\ |
||
8257 | schaersvoo | 251 | var unit_y=\" \";",canvas_root_id,canvas_root_id,canvas_root_id,xsize,ysize,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 252 | /* default add the drag code : nearly always used ...*/ |
8257 | schaersvoo | 253 | add_drag_code(js_include_file,DRAG_CANVAS,canvas_root_id); |
254 | |||
7614 | schaersvoo | 255 | break; |
256 | case XRANGE: |
||
257 | /* |
||
258 | @ xrange xmin,xmax |
||
8224 | bpr | 259 | @ if not given: 0,xsize (eg in pixels) |
7614 | schaersvoo | 260 | */ |
261 | for(i = 0 ; i<2; i++){ |
||
262 | switch(i){ |
||
263 | case 0: xmin = get_real(infile,0);break; |
||
264 | case 1: xmax = get_real(infile,1);break; |
||
265 | default: break; |
||
266 | } |
||
267 | } |
||
268 | if(xmin >= xmax){canvas_error(" xrange is not OK : xmin < xmax !\n");} |
||
269 | fprintf(js_include_file,"var xmin = %f;var xmax = %f;",xmin,xmax); |
||
7983 | schaersvoo | 270 | found_size_command++; |
7614 | schaersvoo | 271 | break; |
272 | case YRANGE: |
||
273 | /* |
||
274 | @ yrange ymin,ymax |
||
275 | @ if not given 0,ysize (eg in pixels) |
||
276 | */ |
||
277 | for(i = 0 ; i<2; i++){ |
||
278 | switch(i){ |
||
279 | case 0: ymin = get_real(infile,0);break; |
||
280 | case 1: ymax = get_real(infile,1);break; |
||
281 | default: break; |
||
282 | } |
||
283 | } |
||
284 | if(ymin >= ymax){canvas_error(" yrange is not OK : ymin < ymax !\n");} |
||
285 | fprintf(js_include_file,"var ymin = %f;var ymax = %f;",ymin,ymax); |
||
7983 | schaersvoo | 286 | found_size_command++; |
7614 | schaersvoo | 287 | break; |
288 | case TRANGE: |
||
289 | /* |
||
290 | @ trange tmin,tmax |
||
291 | @ default -2,2 |
||
292 | */ |
||
293 | use_parametric = TRUE; |
||
294 | for(i = 0 ; i<2; i++){ |
||
295 | switch(i){ |
||
296 | case 0: tmin = get_real(infile,0);break; |
||
297 | case 1: tmax = get_real(infile,1);break; |
||
298 | default: break; |
||
299 | } |
||
300 | } |
||
301 | if(tmin >= tmax ){canvas_error(" trange is not OK : tmin < tmax!\n");} |
||
302 | break; |
||
303 | case LINEWIDTH: |
||
304 | /* |
||
305 | @ linewidth int |
||
306 | @ default 1 |
||
307 | */ |
||
308 | line_width = (int) (get_real(infile,1)); |
||
309 | break; |
||
310 | case ARROWHEAD: |
||
311 | /* |
||
312 | @ arrowhead int |
||
313 | @ default 8 (pixels) |
||
314 | */ |
||
315 | arrow_head = (int) (get_real(infile,1)); |
||
316 | break; |
||
317 | case CROSSHAIRSIZE: |
||
318 | /* |
||
319 | @ crosshairsize int |
||
320 | @ default 10 (px) |
||
321 | */ |
||
322 | crosshair_size = (int) (get_real(infile,1)); |
||
323 | break; |
||
324 | case CROSSHAIR: |
||
325 | /* |
||
326 | @ crosshair x,y,color |
||
327 | @ draw a single crosshair point at (x;y) in color 'color' |
||
7956 | schaersvoo | 328 | @ use command 'crosshairsize int' and / or 'linewidth int' to adust |
7614 | schaersvoo | 329 | @ may be set draggable / onclick |
330 | */ |
||
331 | for(i=0;i<3;i++){ |
||
332 | switch(i){ |
||
333 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
334 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
335 | case 2: stroke_color = get_color(infile,1);/* name or hex color */ |
||
336 | decimals = find_number_of_digits(precision); |
||
8097 | schaersvoo | 337 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,7,[%.*f],[%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[1],crosshair_size,crosshair_size,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,0,0,0,use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt); |
7614 | schaersvoo | 338 | click_cnt++;reset(); |
339 | break; |
||
340 | default:break; |
||
341 | } |
||
342 | } |
||
343 | break; |
||
344 | case CROSSHAIRS: |
||
345 | /* |
||
346 | @ crosshairs color,x1,y1,x2,y2,...,x_n,y_n |
||
347 | @ draw multiple crosshair points at given coordinates in color 'color' |
||
7956 | schaersvoo | 348 | @ use command 'crosshairsize int' and / or 'linewidth int' to adust |
7614 | schaersvoo | 349 | @ may be set draggable / onclick individually (!) |
350 | */ |
||
351 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
352 | fill_color = stroke_color; |
||
353 | i=0; |
||
354 | while( ! done ){ /* get next item until EOL*/ |
||
355 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
356 | if(i%2 == 0 ){ |
||
357 | double_data[i] = get_real(infile,0); /* x */ |
||
358 | } |
||
359 | else |
||
360 | { |
||
361 | double_data[i] = get_real(infile,1); /* y */ |
||
362 | } |
||
363 | i++; |
||
364 | } |
||
365 | decimals = find_number_of_digits(precision); |
||
366 | for(c=0 ; c < i-1 ; c = c+2){ |
||
8097 | schaersvoo | 367 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,7,[%.*f],[%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+1],crosshair_size,crosshair_size,line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,1,0,0,0,use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt); |
7614 | schaersvoo | 368 | click_cnt++; |
369 | } |
||
370 | reset(); |
||
371 | break; |
||
372 | case POINT: |
||
373 | /* |
||
374 | @ point x,y,color |
||
375 | @ draw a single point at (x;y) in color 'color' |
||
7956 | schaersvoo | 376 | @ use command 'linewidth int' to adust size |
7614 | schaersvoo | 377 | @ may be set draggable / onclick |
8224 | bpr | 378 | @ will not resize on zooming <br />(command 'circle x,y,r,color' will resize on zooming) |
7614 | schaersvoo | 379 | */ |
380 | for(i=0;i<3;i++){ |
||
381 | switch(i){ |
||
382 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
383 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
384 | case 2: stroke_color = get_color(infile,1);/* name or hex color */ |
||
385 | decimals = find_number_of_digits(precision); |
||
8097 | schaersvoo | 386 | 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,%d,%d));\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,slider,slider_cnt); |
7614 | schaersvoo | 387 | click_cnt++;break; |
388 | default: break; |
||
389 | } |
||
390 | } |
||
391 | reset(); |
||
392 | break; |
||
393 | case POINTS: |
||
394 | /* |
||
7634 | schaersvoo | 395 | @ points color,x1,y1,x2,y2,...,x_n,y_n |
7614 | schaersvoo | 396 | @ draw multiple points at given coordinates in color 'color' |
7956 | schaersvoo | 397 | @ use command 'linewidth int' to adust size |
7614 | schaersvoo | 398 | @ may be set draggable / onclick individually (!) |
399 | */ |
||
400 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
401 | fill_color = stroke_color; |
||
402 | i=0; |
||
403 | while( ! done ){ /* get next item until EOL*/ |
||
404 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
405 | if(i%2 == 0 ){ |
||
406 | double_data[i] = get_real(infile,0); /* x */ |
||
407 | } |
||
408 | else |
||
409 | { |
||
410 | double_data[i] = get_real(infile,1); /* y */ |
||
411 | } |
||
412 | i++; |
||
413 | } |
||
8224 | bpr | 414 | decimals = find_number_of_digits(precision); |
7614 | schaersvoo | 415 | for(c = 0 ; c < i-1 ; c = c+2){ |
8097 | schaersvoo | 416 | 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,%d,%d));\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,slider,slider_cnt); |
7614 | schaersvoo | 417 | click_cnt++; |
418 | } |
||
419 | reset(); |
||
420 | break; |
||
421 | case SEGMENT: |
||
422 | /* |
||
423 | @ segment x1,y1,x2,y2,color |
||
424 | @ draw a line segment between points (x1:y1)--(x2:y2) in color 'color' |
||
425 | @ may be set draggable / onclick |
||
426 | */ |
||
427 | for(i=0;i<5;i++) { |
||
428 | switch(i){ |
||
429 | case 0: double_data[0]= get_real(infile,0);break; /* x1-values */ |
||
430 | case 1: double_data[1]= get_real(infile,0);break; /* y1-values */ |
||
431 | case 2: double_data[2]= get_real(infile,0);break; /* x2-values */ |
||
432 | case 3: double_data[3]= get_real(infile,0);break; /* y2-values */ |
||
433 | case 4: stroke_color=get_color(infile,1);/* name or hex color */ |
||
434 | decimals = find_number_of_digits(precision); |
||
8097 | schaersvoo | 435 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,double_data[1],decimals,double_data[3],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt); |
7614 | schaersvoo | 436 | click_cnt++;reset(); |
437 | break; |
||
438 | default: break; |
||
439 | } |
||
440 | } |
||
441 | break; |
||
442 | case LINE: |
||
443 | /* |
||
444 | @ line x1,y1,x2,y2,color |
||
445 | @ draw a line through points (x1:y1)--(x2:y2) in color 'color' |
||
446 | @ or use command 'curve color,formula' to draw the line <br />(uses more points to draw the line; is however better draggable) |
||
447 | @ may be set draggable / onclick |
||
448 | */ |
||
449 | for(i=0;i<5;i++){ |
||
450 | switch(i){ |
||
451 | case 0: double_data[10]= get_real(infile,0);break; /* x-values */ |
||
452 | case 1: double_data[11]= get_real(infile,0);break; /* y-values */ |
||
453 | case 2: double_data[12]= get_real(infile,0);break; /* x-values */ |
||
454 | case 3: double_data[13]= get_real(infile,0);break; /* y-values */ |
||
455 | case 4: stroke_color=get_color(infile,1);/* name or hex color */ |
||
456 | if( double_data[10] == double_data[12] ){ /* vertical line*/ |
||
457 | double_data[1] = xmin; |
||
458 | double_data[3] = ymax; |
||
459 | double_data[0] = double_data[10]; |
||
460 | double_data[2] = double_data[10]; |
||
461 | } |
||
462 | else |
||
463 | { |
||
464 | if( double_data[11] == double_data[13] ){ /* horizontal line */ |
||
465 | double_data[1] = double_data[11]; |
||
466 | double_data[3] = double_data[11]; |
||
467 | double_data[0] = ymin; |
||
468 | double_data[2] = xmax; |
||
469 | } |
||
470 | else |
||
471 | { |
||
472 | /* m */ |
||
473 | double_data[5] = (double_data[13] - double_data[11]) /(double_data[12] - double_data[10]); |
||
474 | /* q */ |
||
475 | double_data[6] = double_data[11] - ((double_data[13] - double_data[11]) /(double_data[12] - double_data[10]))*double_data[10]; |
||
8224 | bpr | 476 | |
7614 | schaersvoo | 477 | /*xmin,m*xmin+q,xmax,m*xmax+q*/ |
8224 | bpr | 478 | |
7614 | schaersvoo | 479 | double_data[1] = (double_data[5])*(xmin)+(double_data[6]); |
480 | double_data[3] = (double_data[5])*(xmax)+(double_data[6]); |
||
481 | double_data[0] = xmin; |
||
482 | double_data[2] = xmax; |
||
483 | } |
||
484 | } |
||
485 | decimals = find_number_of_digits(precision); |
||
8097 | schaersvoo | 486 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,double_data[1],decimals,double_data[3],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt); |
7614 | schaersvoo | 487 | click_cnt++;reset(); |
488 | break; |
||
489 | } |
||
490 | } |
||
491 | break; |
||
8244 | schaersvoo | 492 | case HALFLINE: |
493 | /* |
||
494 | @ demiline x1,y1,x2,y2,color |
||
495 | @ alternative : halfline |
||
496 | @ draws a halfline starting in (x1:y1) and through (x2:y2) in color 'color' (colorname or hex) |
||
497 | @ may be set draggable / onclick |
||
498 | */ |
||
499 | for(i=0;i<5;i++){ |
||
500 | switch(i){ |
||
501 | case 0: double_data[0]= get_real(infile,0);break; /* x-values */ |
||
502 | case 1: double_data[1]= get_real(infile,0);break; /* y-values */ |
||
503 | case 2: double_data[10]= get_real(infile,0);break; /* x-values */ |
||
504 | case 3: double_data[11]= get_real(infile,0);break; /* y-values */ |
||
505 | case 4: stroke_color=get_color(infile,1);/* name or hex color */ |
||
506 | if(double_data[0] == double_data[10]){ /* vertical halfline */ |
||
507 | if(double_data[1] < double_data[11]){ |
||
508 | double_data[3] = ymax + 1000; |
||
509 | } |
||
510 | else |
||
511 | { |
||
512 | double_data[3] = ymin - 1000; |
||
513 | } |
||
514 | double_data[2] = double_data[0]; |
||
515 | } |
||
516 | else |
||
517 | { /* horizontal halfline*/ |
||
518 | if( double_data[1] == double_data[11] ){ |
||
519 | if( double_data[0] < double_data[10] ){ |
||
520 | double_data[2] = xmax + 1000; /* halfline to the right */ |
||
521 | } |
||
522 | else |
||
523 | { |
||
524 | double_data[2] = xmin - 1000; /* halfline to the left */ |
||
525 | } |
||
526 | double_data[3] = double_data[1]; |
||
527 | } |
||
528 | else |
||
529 | { |
||
530 | /* any other halfline */ |
||
531 | /* slope */ |
||
532 | double_data[12] = (double_data[11] - double_data[1])/(double_data[10] - double_data[0]); |
||
533 | /* const */ |
||
534 | double_data[13] = double_data[1] - double_data[12]*double_data[0]; |
||
535 | if( double_data[0] < double_data[10] ){ |
||
536 | double_data[2] = double_data[2] + 1000; |
||
537 | } |
||
538 | else |
||
539 | { |
||
540 | double_data[2] = double_data[2] - 1000; |
||
541 | } |
||
542 | double_data[3] = double_data[12]*double_data[2] + double_data[13]; |
||
543 | } |
||
544 | } |
||
545 | decimals = find_number_of_digits(precision); |
||
546 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,18,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,double_data[1],decimals,double_data[3],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt); |
||
547 | click_cnt++;reset(); |
||
548 | break; |
||
549 | } |
||
550 | } |
||
551 | |||
552 | break; |
||
8224 | bpr | 553 | case HLINE: |
7614 | schaersvoo | 554 | /* |
555 | @ hline x,y,color |
||
556 | @ draw a horizontal line through point (x:y) in color 'color' |
||
557 | @ or use command 'curve color,formula' to draw the line <br />(uses more points to draw the line; is however better draggable) |
||
558 | @ may be set draggable / onclick |
||
559 | */ |
||
560 | for(i=0;i<3;i++) { |
||
561 | switch(i){ |
||
562 | case 0: double_data[0] = get_real(infile,0);break; /* x-values */ |
||
563 | case 1: double_data[1] = get_real(infile,0);break; /* y-values */ |
||
564 | case 2: stroke_color = get_color(infile,1);/* name or hex color */ |
||
565 | double_data[3] = double_data[1]; |
||
566 | decimals = find_number_of_digits(precision); |
||
8097 | schaersvoo | 567 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\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,slider,slider_cnt); |
7614 | schaersvoo | 568 | click_cnt++;reset(); |
569 | break; |
||
570 | } |
||
571 | } |
||
572 | break; |
||
573 | case VLINE: |
||
574 | /* |
||
575 | @ vline x,y,color |
||
576 | @ draw a vertical line through point (x:y) in color 'color' |
||
577 | @ may be set draggable / onclick |
||
578 | */ |
||
579 | for(i=0;i<3;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: stroke_color=get_color(infile,1);/* name or hex color */ |
||
584 | double_data[2] = double_data[0]; |
||
585 | decimals = find_number_of_digits(precision); |
||
8097 | schaersvoo | 586 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\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,slider,slider_cnt); |
7614 | schaersvoo | 587 | click_cnt++;reset(); |
588 | break; |
||
589 | } |
||
590 | } |
||
591 | break; |
||
592 | case SQUARE: |
||
593 | /* |
||
8071 | schaersvoo | 594 | @ square x,y,side (px) ,color |
7614 | schaersvoo | 595 | @ draw a square with left top corner (x:y) with side 'side' in color 'color' |
596 | @ use command 'fsquare x,y,side,color' for a filled square |
||
597 | @ use command/keyword 'filled' before command 'square x,y,side,color' |
||
598 | @ use command 'fillcolor color' before 'fsquare' to set the fill colour. |
||
599 | @ may be set draggable / onclick |
||
600 | */ |
||
601 | for(i=0;i<5;i++){ |
||
602 | switch(i){ |
||
8071 | schaersvoo | 603 | case 0:double_data[0] = get_real(infile,0);break; /* x1-values */ |
604 | case 1:double_data[1] = get_real(infile,0);break; /* y1-values */ |
||
605 | case 2:double_data[2] = (int) (get_real(infile,0));break; /* width in px */ |
||
606 | case 3: |
||
607 | stroke_color = get_color(infile,1);/* name or hex color */ |
||
7614 | schaersvoo | 608 | decimals = find_number_of_digits(precision); |
8071 | schaersvoo | 609 | double_data[3] = double_data[0] + (xmax - xmin)*double_data[2]/xsize; |
610 | double_data[4] = double_data[1] + -1*(ymax - ymin)*double_data[2]/ysize; |
||
8097 | schaersvoo | 611 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,1,[%.*f,%.*f,%.*f,%.*f],[%.*f,%.*f,%.*f,%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[3],decimals,double_data[3],decimals,double_data[0],decimals,double_data[1],decimals,double_data[1],decimals,double_data[4],decimals,double_data[4],line_width,line_width,line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt); |
7614 | schaersvoo | 612 | click_cnt++;reset(); |
613 | break; |
||
614 | } |
||
615 | } |
||
616 | break; |
||
617 | case ROUNDRECT: |
||
618 | /* |
||
619 | @ roundrect x1,y1,x2,y2,radius,color |
||
620 | @ use command 'froundrect x1,y1,x2,y2,radius,color' for a filled rectangle |
||
621 | @ use command/keyword 'filled' before command 'roundrect x1,y1,x2,y2,radius,color' |
||
622 | @ use command 'fillcolor color' before 'froundrect' to set the fill colour. |
||
623 | @ may be set draggable / onclick |
||
624 | */ |
||
625 | for(i=0;i<6;i++){ |
||
626 | switch(i){ |
||
627 | case 0:double_data[0] = get_real(infile,0);break; /* x-values */ |
||
628 | case 1:double_data[1] = get_real(infile,0);break; /* y-values */ |
||
629 | case 2:double_data[2] = get_real(infile,0);break; /* x-values */ |
||
630 | case 3:double_data[3] = get_real(infile,0);break; /* y-values */ |
||
631 | case 4:int_data[0] = (int) (get_real(infile,0));break; /* radius value in pixels */ |
||
632 | case 5:stroke_color = get_color(infile,1);/* name or hex color */ |
||
8071 | schaersvoo | 633 | /* ensure no inverted roundrect is produced... */ |
634 | if( double_data[0] > double_data[2] ){double_data[4] = double_data[0];double_data[0] = double_data[2];double_data[2] = double_data[4];} |
||
8224 | bpr | 635 | if( double_data[3] > double_data[1] ){double_data[4] = double_data[1];double_data[1] = double_data[3];double_data[3] = double_data[4];} |
7614 | schaersvoo | 636 | decimals = find_number_of_digits(precision); |
8097 | schaersvoo | 637 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,6,[%.*f,%.*f],[%.*f,%.*f],[%d,%d],[%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,double_data[1],decimals,double_data[3],int_data[0],int_data[0],int_data[0],int_data[0],line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt); |
7614 | schaersvoo | 638 | click_cnt++;reset(); |
639 | break; |
||
640 | } |
||
641 | } |
||
642 | break; |
||
643 | case RECT: |
||
644 | /* |
||
645 | @ rect x1,y1,x2,y2,color |
||
646 | @ use command 'rect x1,y1,x2,y2,color' for a filled rectangle |
||
647 | @ use command/keyword 'filled' before command 'rect x1,y1,x2,y2,color' |
||
648 | @ use command 'fillcolor color' before 'frect' to set the fill colour. |
||
649 | @ may be set draggable / onclick |
||
650 | */ |
||
651 | for(i=0;i<5;i++){ |
||
652 | switch(i){ |
||
653 | case 0:double_data[0] = get_real(infile,0);break; /* x-values */ |
||
654 | case 1:double_data[1] = get_real(infile,0);break; /* y-values */ |
||
655 | case 2:double_data[2] = get_real(infile,0);break; /* x-values */ |
||
656 | case 3:double_data[3] = get_real(infile,0);break; /* y-values */ |
||
657 | case 4:stroke_color = get_color(infile,1);/* name or hex color */ |
||
658 | decimals = find_number_of_digits(precision); |
||
8097 | schaersvoo | 659 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,1,[%.*f,%.*f,%.*f,%.*f],[%.*f,%.*f,%.*f,%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,double_data[2],decimals,double_data[0],decimals,double_data[1],decimals,double_data[1],decimals,double_data[3],decimals,double_data[3],line_width,line_width,line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt); |
7614 | schaersvoo | 660 | click_cnt++;reset(); |
661 | break; |
||
662 | } |
||
663 | } |
||
664 | break; |
||
665 | case POLYLINE: |
||
666 | /* |
||
667 | @ polyline color,x1,y1,x2,y2...x_n,y_n |
||
668 | @ may be set draggable / onclick |
||
669 | */ |
||
670 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
671 | i=0; |
||
672 | c=0; |
||
673 | while( ! done ){ /* get next item until EOL*/ |
||
674 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
675 | for( c = 0 ; c < 2; c++){ |
||
676 | if(c == 0 ){ |
||
677 | double_data[i] = get_real(infile,0); |
||
678 | i++; |
||
679 | } |
||
680 | else |
||
681 | { |
||
682 | double_data[i] = get_real(infile,1); |
||
683 | i++; |
||
684 | } |
||
685 | } |
||
686 | } |
||
687 | /* draw path : not closed & not filled */ |
||
688 | decimals = find_number_of_digits(precision); |
||
8097 | schaersvoo | 689 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,4,%s,[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,double_xy2js_array(double_data,i,decimals),line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt); |
7614 | schaersvoo | 690 | click_cnt++;reset(); |
691 | break; |
||
692 | case POLY: |
||
693 | /* |
||
694 | @ poly color,x1,y1,x2,y2...x_n,y_n |
||
695 | @ draw closed polygon |
||
696 | @ use command 'fpoly' to fill it, use command 'fillcolor color' to set the fill color |
||
697 | @ may be set draggable / onclick |
||
698 | */ |
||
699 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
700 | i=0; |
||
701 | c=0; |
||
702 | while( ! done ){ /* get next item until EOL*/ |
||
703 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
704 | for( c = 0 ; c < 2; c++){ |
||
705 | if(c == 0 ){ |
||
706 | double_data[i] = get_real(infile,0); |
||
707 | i++; |
||
708 | } |
||
709 | else |
||
710 | { |
||
711 | double_data[i] = get_real(infile,1); |
||
712 | i++; |
||
713 | } |
||
714 | } |
||
715 | } |
||
716 | /* draw path : closed & optional filled */ |
||
717 | decimals = find_number_of_digits(precision); |
||
8097 | schaersvoo | 718 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,5,%s,[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,double_xy2js_array(double_data,i,decimals),line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt); |
7614 | schaersvoo | 719 | click_cnt++;reset(); |
720 | break; |
||
8224 | bpr | 721 | case ARC: |
7614 | schaersvoo | 722 | /* |
723 | @ arc xc,yc,width,height,start_angle,end_angle,color |
||
724 | @ can not be set "onclick" or "drag xy" |
||
8105 | schaersvoo | 725 | @ attention: width == height == radius in pixels |
726 | @ will not zoom in or zoom out (because radius is given in pixels an not in x/y-system !). Panning will work |
||
727 | @ use command 'angle' for scalable angle |
||
7614 | schaersvoo | 728 | */ |
729 | for(i=0;i<7;i++){ |
||
730 | switch(i){ |
||
731 | case 0:double_data[0] = get_real(infile,0);break; /* x-values */ |
||
732 | case 1:double_data[1] = get_real(infile,0);break; /* y-values */ |
||
733 | case 2:int_data[0] = (int)(get_real(infile,0));break; /* width in pixels ! */ |
||
734 | case 3:int_data[1] = (int)(get_real(infile,0));break; /* height in pixels ! */ |
||
735 | case 4:double_data[2] = get_real(infile,0);break; /* start angle in degrees */ |
||
736 | case 5:double_data[3] = get_real(infile,0);break; /* end angle in degrees */ |
||
737 | case 6:stroke_color = get_color(infile,1);/* name or hex color */ |
||
738 | /* in Shape library: |
||
739 | x[0] = x[1] = xc |
||
740 | y[0] = y[1] = yc |
||
8224 | bpr | 741 | w[0] = w[1] = radius = width = height |
742 | h[0] = start_angle ; h[1] = end_engle |
||
7614 | schaersvoo | 743 | */ |
744 | decimals = find_number_of_digits(precision); |
||
8097 | schaersvoo | 745 | 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,%d,%d));\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,slider,slider_cnt); |
7614 | schaersvoo | 746 | reset(); |
747 | break; |
||
748 | } |
||
749 | } |
||
750 | break; |
||
8224 | bpr | 751 | case ANGLE: |
8105 | schaersvoo | 752 | /* |
753 | @ angle xc,yc,width,start_angle,end_angle,color |
||
754 | @ width is in x-range |
||
755 | @ will zoom in/out |
||
756 | @ if size is controlled by command 'slider' use radians to set limits of slider. |
||
757 | */ |
||
758 | for(i=0;i<7;i++){ |
||
759 | switch(i){ |
||
760 | case 0:double_data[0] = get_real(infile,0);break; /* x-values */ |
||
761 | case 1:double_data[1] = get_real(infile,0);break; /* y-values */ |
||
762 | case 2:double_data[2] = get_real(infile,0);break; /* width in pixels ! */ |
||
763 | case 3:double_data[3] = get_real(infile,0);break; /* start angle in degrees */ |
||
764 | case 4:double_data[4] = get_real(infile,0);break; /* end angle in degrees */ |
||
765 | case 5:stroke_color = get_color(infile,1);/* name or hex color */ |
||
766 | decimals = find_number_of_digits(precision); |
||
767 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,17,[%.*f,%.*f],[%.*f,%.*f],[%.*f,%.*f],[%.*f,%.*f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[0],decimals,double_data[1],decimals,double_data[1],decimals,double_data[2],decimals,double_data[2],decimals,double_data[3],decimals,double_data[4],line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt); |
||
768 | reset(); |
||
769 | break; |
||
770 | } |
||
771 | } |
||
772 | break; |
||
773 | |||
7614 | schaersvoo | 774 | case ELLIPSE: |
775 | /* |
||
776 | @ ellipse xc,yc,radius_x,radius_y,color |
||
8224 | bpr | 777 | @ a ellipse with center xc/yc in x/y-range |
7614 | schaersvoo | 778 | @ radius_x and radius_y are in pixels |
779 | @ may be set draggable / onclick |
||
8224 | bpr | 780 | @ will shrink / expand on zoom out / zoom in |
7614 | schaersvoo | 781 | */ |
782 | for(i=0;i<5;i++){ |
||
783 | switch(i){ |
||
784 | case 0:double_data[0] = get_real(infile,0);break; /* x-values */ |
||
785 | case 1:double_data[1] = get_real(infile,0);break; /* y-values */ |
||
786 | case 2:double_data[2] = get_real(infile,0);break; /* rx -> px */ |
||
8224 | bpr | 787 | case 3:double_data[3] = get_real(infile,0);break; /* ry -> px */ |
7614 | schaersvoo | 788 | case 4:stroke_color = get_color(infile,1);/* name or hex color */ |
789 | decimals = find_number_of_digits(precision); |
||
8097 | schaersvoo | 790 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,3,[%.*f],[%.*f],[%.*f],[%.*f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[1],decimals,double_data[2],decimals,double_data[3],line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt); |
7614 | schaersvoo | 791 | click_cnt++;reset(); |
792 | break; |
||
793 | } |
||
794 | } |
||
795 | break; |
||
796 | case DASHTYPE: |
||
797 | /* |
||
798 | @ dashtype int ,int |
||
7956 | schaersvoo | 799 | @ When dashed is set, the objects will be drawn with this dashtyp |
7614 | schaersvoo | 800 | @ default value "dashtype 2,2" |
801 | */ |
||
802 | for(i=0;i<2;i++){ |
||
803 | switch(i){ |
||
804 | case 0 : dashtype[0] = (int) line_width*( get_real(infile,0)) ; break; |
||
805 | case 1 : dashtype[1] = (int) line_width*( get_real(infile,1)) ; break; |
||
806 | } |
||
807 | } |
||
808 | break; |
||
809 | case CIRCLE: |
||
810 | /* |
||
811 | @ circle xc,yc,width (2*r in pixels),color |
||
812 | @ use command 'fcircle xc,yc,d,color' or command 'filled' for a filled disk |
||
813 | @ use command 'fillcolor color' to set the fillcolor |
||
814 | @ may be set draggable / onclick |
||
8224 | bpr | 815 | @ will shrink / expand on zoom out / zoom in |
7614 | schaersvoo | 816 | */ |
817 | for(i=0;i<4;i++){ |
||
818 | switch(i){ |
||
819 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
820 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
8116 | schaersvoo | 821 | case 2: double_data[2] = px2x((get_real(infile,0))/2) - px2x(0);break; /* for zoom in/out : radius in 'dx' xrange*/ |
7614 | schaersvoo | 822 | case 3: stroke_color = get_color(infile,1);/* name or hex color */ |
823 | decimals = find_number_of_digits(precision); |
||
8097 | schaersvoo | 824 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,13,[%.*f],[%.*f],[%.3f],[%.3f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[1],double_data[2],double_data[2],line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt); |
7614 | schaersvoo | 825 | click_cnt++;reset(); |
826 | break; |
||
827 | } |
||
828 | } |
||
829 | break; |
||
830 | case RAYS: |
||
831 | /* |
||
832 | @ rays color,xc,yc,x1,y1,x2,y2,x3,y3...x_n,y_n |
||
833 | @ draw rays in color 'color' and center (xc:yc) |
||
7786 | schaersvoo | 834 | @ may be set draggable or onclick (every individual ray) |
7614 | schaersvoo | 835 | */ |
836 | stroke_color=get_color(infile,0); |
||
7786 | schaersvoo | 837 | fill_color = stroke_color; |
838 | double_data[0] = get_real(infile,0);/* xc */ |
||
839 | double_data[1] = get_real(infile,0);/* yc */ |
||
840 | i=2; |
||
841 | while( ! done ){ /* get next item until EOL*/ |
||
842 | if(i > MAX_INT - 1){canvas_error("in command rays to many points / rays in argument: repeat command multiple times to fit");} |
||
843 | if(i%2 == 0 ){ |
||
844 | double_data[i] = get_real(infile,0); /* x */ |
||
7614 | schaersvoo | 845 | } |
7786 | schaersvoo | 846 | else |
847 | { |
||
848 | double_data[i] = get_real(infile,1); /* y */ |
||
7614 | schaersvoo | 849 | } |
7786 | schaersvoo | 850 | fprintf(js_include_file,"/* double_data[%d] = %f */\n",i,double_data[i]); |
851 | i++; |
||
7614 | schaersvoo | 852 | } |
8224 | bpr | 853 | |
854 | if( i%2 != 0 ){canvas_error("in command rays: unpaired x or y value");} |
||
855 | decimals = find_number_of_digits(precision); |
||
7786 | schaersvoo | 856 | for(c=2; c<i;c = c+2){ |
7614 | schaersvoo | 857 | click_cnt++; |
8097 | schaersvoo | 858 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[c],decimals,double_data[1],decimals,double_data[c+1],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt); |
7614 | schaersvoo | 859 | } |
860 | reset(); |
||
861 | break; |
||
862 | case ARROW: |
||
863 | /* |
||
864 | @ arrow x1,y1,x2,y2,h,color |
||
865 | @ draw a single headed arrow/vector from (x1:y1) to (x2:y2)<br />with arrowhead size h in px and in color 'color' |
||
866 | @ use command 'linewidth int' to adjust thickness of the arrow |
||
867 | @ may be set draggable / onclick |
||
868 | */ |
||
869 | for(i=0;i<6;i++){ |
||
870 | switch(i){ |
||
871 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
872 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
873 | case 2: double_data[2] = get_real(infile,0);break; /* x */ |
||
874 | case 3: double_data[3] = get_real(infile,0);break; /* y */ |
||
875 | case 4: arrow_head = (int) get_real(infile,0);break;/* h */ |
||
876 | case 5: stroke_color = get_color(infile,1);/* name or hex color */ |
||
877 | decimals = find_number_of_digits(precision); |
||
8097 | schaersvoo | 878 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,8,[%.*f,%.*f],[%.*f,%.*f],[%d,%d],[%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,double_data[1],decimals,double_data[3],arrow_head,arrow_head,arrow_head,arrow_head,line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt); |
7614 | schaersvoo | 879 | click_cnt++; |
880 | reset(); |
||
881 | break; |
||
882 | } |
||
883 | } |
||
884 | break; |
||
885 | case ARROW2: |
||
886 | /* |
||
887 | @ arrow2 x1,y1,x2,y2,h,color |
||
888 | @ draw a double headed arrow/vector from (x1:y1) to (x2:y2)<br />with arrowhead size h in px and in color 'color' |
||
889 | @ use command 'arrowhead int' to adjust the arrow head size |
||
890 | @ use command 'linewidth int' to adjust thickness of the arrow |
||
891 | @ may be set draggable / onclick |
||
892 | */ |
||
893 | for(i=0;i<6;i++){ |
||
894 | switch(i){ |
||
895 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
896 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
897 | case 2: double_data[2] = get_real(infile,0);break; /* x */ |
||
898 | case 3: double_data[3] = get_real(infile,0);break; /* y */ |
||
899 | case 4: arrow_head = (int) get_real(infile,0);break;/* h */ |
||
900 | case 5: stroke_color = get_color(infile,1);/* name or hex color */ |
||
901 | decimals = find_number_of_digits(precision); |
||
8097 | schaersvoo | 902 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,10,[%.*f,%.*f],[%.*f,%.*f],[%d,%d],[%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,double_data[1],decimals,double_data[3],arrow_head,arrow_head,arrow_head,arrow_head,line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt); |
7614 | schaersvoo | 903 | click_cnt++;reset(); |
904 | break; |
||
905 | } |
||
906 | } |
||
907 | break; |
||
8224 | bpr | 908 | case PARALLEL: |
7614 | schaersvoo | 909 | /* |
910 | @ parallel x1,y1,x2,y2,dx,dy,n,[colorname or #hexcolor] |
||
8224 | bpr | 911 | @ can not be set "onclick" or "drag xy" |
7614 | schaersvoo | 912 | */ |
913 | for( i = 0;i < 8; i++ ){ |
||
914 | switch(i){ |
||
915 | case 0: double_data[0] = get_real(infile,0);break; /* x1-values -> x-pixels*/ |
||
916 | case 1: double_data[1] = get_real(infile,0);break; /* y1-values -> y-pixels*/ |
||
917 | case 2: double_data[2] = get_real(infile,0);break; /* x2-values -> x-pixels*/ |
||
918 | case 3: double_data[3] = get_real(infile,0);break; /* y2-values -> y-pixels*/ |
||
919 | case 4: double_data[4] = xmin + get_real(infile,0);break; /* xv -> x-pixels */ |
||
920 | case 5: double_data[5] = ymax + get_real(infile,0);break; /* yv -> y-pixels */ |
||
921 | case 6: int_data[0] = (int) (get_real(infile,0));break; /* n */ |
||
922 | case 7: stroke_color=get_color(infile,1);/* name or hex color */ |
||
923 | decimals = find_number_of_digits(precision); |
||
8097 | schaersvoo | 924 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,11,[%.*f,%.*f,%.*f],[%.*f,%.*f,%.*f],[%d,%d,%d],[%d,%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,double_data[4],decimals,double_data[1],decimals,double_data[3],decimals,double_data[5],int_data[0],int_data[0],int_data[0],int_data[0],int_data[0],int_data[0],line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt); |
7614 | schaersvoo | 925 | click_cnt++;reset(); |
926 | break; |
||
927 | default: break; |
||
928 | } |
||
929 | } |
||
930 | break; |
||
931 | case TRIANGLE: |
||
932 | /* |
||
933 | @triangle x1,y1,x2,y2,x3,y3,color |
||
7956 | schaersvoo | 934 | @may be set draggable / onclic |
7614 | schaersvoo | 935 | */ |
936 | for(i=0;i<7;i++){ |
||
937 | switch(i){ |
||
938 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
939 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
940 | case 2: double_data[2] = get_real(infile,0);break; /* x */ |
||
941 | case 3: double_data[3] = get_real(infile,0);break; /* y */ |
||
942 | case 4: double_data[4] = get_real(infile,0);break; /* x */ |
||
943 | case 5: double_data[5] = get_real(infile,0);break; /* y */ |
||
944 | case 6: stroke_color = get_color(infile,1);/* name or hex color */ |
||
945 | decimals = find_number_of_digits(precision); |
||
8097 | schaersvoo | 946 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,5,%s,[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,double_xy2js_array(double_data,6,decimals),line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt); |
7614 | schaersvoo | 947 | click_cnt++;reset(); |
948 | break; |
||
949 | default: break; |
||
950 | } |
||
951 | } |
||
952 | break; |
||
953 | case LATTICE: |
||
954 | /* |
||
955 | @lattice x0,y0,xv1,yv1,xv2,yv2,n1,n2,color |
||
8224 | bpr | 956 | @can not be set "onclick" or "drag xy" |
7614 | schaersvoo | 957 | */ |
958 | if( js_function[DRAW_LATTICE] != 1 ){ js_function[DRAW_LATTICE] = 1;} |
||
959 | for( i = 0; i<9; i++){ |
||
960 | switch(i){ |
||
961 | case 0: int_data[0] = x2px(get_real(infile,0));break; /* x0-values -> x-pixels*/ |
||
962 | case 1: int_data[1] = y2px(get_real(infile,0));break; /* y0-values -> y-pixels*/ |
||
963 | case 2: int_data[2] = (int) (get_real(infile,0));break; /* x1-values -> x-pixels*/ |
||
8071 | schaersvoo | 964 | case 3: int_data[3] = (int) -1*(get_real(infile,0));break; /* y1-values -> y-pixels*/ |
7614 | schaersvoo | 965 | case 4: int_data[4] = (int) (get_real(infile,0));break; /* x2-values -> x-pixels*/ |
8071 | schaersvoo | 966 | case 5: int_data[5] = (int) -1*(get_real(infile,0));break; /* y2-values -> y-pixels*/ |
7614 | schaersvoo | 967 | case 6: int_data[6] = (int) (get_real(infile,0));break; /* n1-values */ |
968 | case 7: int_data[7] = (int) (get_real(infile,0));break; /* n2-values */ |
||
969 | case 8: stroke_color=get_color(infile,1); |
||
970 | decimals = find_number_of_digits(precision); |
||
8071 | schaersvoo | 971 | string_length = snprintf(NULL,0,"draw_lattice(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%.2f,%d,%s);",STATIC_CANVAS,line_width,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],fill_color,fill_opacity,stroke_color,stroke_opacity,use_rotate,angle,use_affine,affine_matrix); |
7614 | schaersvoo | 972 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
8071 | schaersvoo | 973 | snprintf(tmp_buffer,string_length,"draw_lattice(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%.2f,%d,%s);",STATIC_CANVAS,line_width,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],fill_color,fill_opacity,stroke_color,stroke_opacity,use_rotate,angle,use_affine,affine_matrix); |
7614 | schaersvoo | 974 | add_to_buffer(tmp_buffer); |
975 | break; |
||
976 | default:break; |
||
977 | } |
||
978 | } |
||
979 | reset(); |
||
980 | break; |
||
981 | case SNAPTOGRID: |
||
982 | /* |
||
983 | @ snaptogrid |
||
984 | @ keyword (no arguments rewquired) needs to be defined before command 'userdraw' and after command 'grid' |
||
985 | @ in case of userdraw the drawn points will snap to xmajor / ymajor grid |
||
7784 | schaersvoo | 986 | @ 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 | 987 | */ |
7881 | schaersvoo | 988 | fprintf(js_include_file,"\nx_use_snap_to_grid = 1;y_use_snap_to_grid = 1;"); |
7614 | schaersvoo | 989 | break; |
7784 | schaersvoo | 990 | case XSNAPTOGRID: |
991 | /* |
||
992 | @ xsnaptogrid |
||
993 | @ keyword (no arguments rewquired) needs to be defined before command 'userdraw' and after command 'grid' |
||
994 | @ in case of userdraw the drawn points will snap to xmajor grid |
||
7856 | schaersvoo | 995 | @ if xminor 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 /> |
7784 | schaersvoo | 996 | */ |
7881 | schaersvoo | 997 | fprintf(js_include_file,"\nx_use_snap_to_grid = 1;y_use_snap_to_grid = 0;"); |
7784 | schaersvoo | 998 | break; |
999 | case YSNAPTOGRID: |
||
1000 | /* |
||
1001 | @ ysnaptogrid |
||
1002 | @ keyword (no arguments rewquired) needs to be defined before command 'userdraw' and after command 'grid' |
||
1003 | @ in case of userdraw the drawn points will snap to ymajor grid |
||
7856 | schaersvoo | 1004 | @ if 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 /> |
7784 | schaersvoo | 1005 | */ |
7881 | schaersvoo | 1006 | fprintf(js_include_file,"\nx_use_snap_to_grid = 0;y_use_snap_to_grid = 1;"); |
7784 | schaersvoo | 1007 | break; |
8222 | schaersvoo | 1008 | case USERINPUT: |
1009 | /* |
||
1010 | @ userinput function | textarea | inputfield |
||
1011 | @ alternative command + argment to keywords "userinput_function","userinput_textarea" and "userinput_xy" |
||
1012 | @ textarea and inputfield are only usable in combination with some 'userdraw draw_ type' |
||
1013 | @ function may be used any time (e.g. without userdraw) |
||
8297 | schaersvoo | 1014 | @ use command "functionlabel some_string" to define the inputfield text : default value "f(x)=" |
1015 | @ use command 'strokecolor some_color' to adjust the plot / functionlabel color |
||
1016 | @ the userinput for the function will be corrected by a simple 'rawmath' implementation... |
||
8222 | schaersvoo | 1017 | */ |
1018 | temp = get_string_argument(infile,1); |
||
1019 | if(strstr(temp,"function") != 0 || strstr(temp,"curve") != 0 || strstr(temp,"plot") != 0 ){ |
||
8224 | bpr | 1020 | if( js_function[DRAW_JSFUNCTION] != 1 ){ |
8297 | schaersvoo | 1021 | add_rawmath(js_include_file);/* add simple rawmath routine to correct user input of function */ |
8222 | schaersvoo | 1022 | js_function[DRAW_JSFUNCTION] = 1; |
1023 | if(reply_format == 0){reply_format = 24;}/* read canvas_input values */ |
||
8297 | schaersvoo | 1024 | add_input_jsfunction(js_include_file,canvas_root_id,input_style,function_label,input_cnt,stroke_color,stroke_opacity,line_width,use_dashed,dashtype[0],dashtype[1]); |
8222 | schaersvoo | 1025 | input_cnt++; |
1026 | } |
||
8297 | schaersvoo | 1027 | else |
1028 | { |
||
1029 | /* no need to add DRAW_JSFUNCTION , just call it with the parameters */ |
||
1030 | fprintf(js_include_file,"add_input_jsfunction(%d,\"%s\",\"%s\",%d,\"%s\",\"%.2f\",%d,%d,%d);\n",input_cnt,input_style,function_label,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]); |
||
1031 | input_cnt++; |
||
1032 | } |
||
8222 | schaersvoo | 1033 | if( use_js_math == FALSE){/* add this stuff only once...*/ |
1034 | add_to_js_math(js_include_file); |
||
1035 | use_js_math = TRUE; |
||
1036 | } |
||
1037 | if( use_js_plot == FALSE){ |
||
1038 | use_js_plot = TRUE; |
||
1039 | add_jsplot(js_include_file,canvas_root_id); /* this plots the function on JSPLOT_CANVAS */ |
||
1040 | } |
||
1041 | } |
||
1042 | else |
||
1043 | { |
||
1044 | if(strstr(temp,"inputfield") != 0 ){ |
||
1045 | if( use_input_xy != 0 ){canvas_error("userinput_xy can not be combined with usertextarea_xy command");} |
||
1046 | if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */ |
||
1047 | use_input_xy = 1; |
||
1048 | } |
||
1049 | else |
||
1050 | { |
||
1051 | if(strstr(temp,"textarea") != 0 ){ |
||
1052 | if( use_input_xy != 0 ){canvas_error("usertextarea_xy can not be combined with userinput_xy command");} |
||
1053 | if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */ |
||
1054 | use_input_xy = 2; |
||
1055 | } |
||
1056 | else |
||
1057 | { |
||
1058 | canvas_error("userinput argument may be \"function,inputfield,textarea\""); |
||
1059 | } |
||
1060 | } |
||
1061 | } |
||
1062 | break; |
||
7663 | schaersvoo | 1063 | case USERTEXTAREA_XY: |
1064 | /* |
||
1065 | @ usertextarea_xy |
||
8224 | bpr | 1066 | @ keyword |
7663 | schaersvoo | 1067 | @ to be used in combination with command "userdraw object_type,color" wherein object_type is only segment / polyline for the time being... |
8224 | bpr | 1068 | @ if set two textareas are added to the document<br />(one for x-values , one for y-values) |
7663 | schaersvoo | 1069 | @ the student may use this as correction for (x:y) on a drawing (or to draw without mouse, using just the coordinates) |
8224 | bpr | 1070 | @ user drawings will not zoom on zooming (or pan on panning) |
7663 | schaersvoo | 1071 | */ |
7856 | schaersvoo | 1072 | if( use_input_xy != 0 ){canvas_error("usertextarea_xy can not be combined with userinput_xy command");} |
7956 | schaersvoo | 1073 | if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */ |
7749 | schaersvoo | 1074 | use_input_xy = 2; |
1075 | break; |
||
7652 | schaersvoo | 1076 | case USERINPUT_XY: |
1077 | /* |
||
1078 | @ userinput_xy |
||
8224 | bpr | 1079 | @ keyword |
7652 | schaersvoo | 1080 | @ to be used in combination with command "userdraw object_type,color" |
8224 | bpr | 1081 | @ if set two (or three) input fields are added to the document<br />(one for x-values , one for y-values and in case of drawing circle one for radius-values) |
7652 | schaersvoo | 1082 | @ the student may use this as correction for (x:y) on a drawing (or to draw without mouse, using just the coordinates) |
7749 | schaersvoo | 1083 | @ 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 | 1084 | @ can not be combined with command "intooltip tiptext" <br />note: the 'tooltip div element' is used for placing inputfields |
8224 | bpr | 1085 | @ user drawings will not zoom on zooming (or pan on panning) |
7652 | schaersvoo | 1086 | */ |
7749 | schaersvoo | 1087 | /* add simple eval check to avoid code injection with unprotected eval(string) */ |
7856 | schaersvoo | 1088 | if( use_input_xy != 0 ){canvas_error("userinput_xy can not be combined with usertextarea_xy command");} |
7956 | schaersvoo | 1089 | if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */ |
7749 | schaersvoo | 1090 | use_input_xy = 1; |
1091 | break; |
||
8297 | schaersvoo | 1092 | case FUNCTION_LABEL: |
1093 | function_label = get_string_argument(infile,1); |
||
1094 | break; |
||
8193 | schaersvoo | 1095 | case USERINPUT_FUNCTION: |
1096 | /* |
||
1097 | @ userinput_function |
||
1098 | @ keyword |
||
1099 | @ if set , a inputfield will be added to the page |
||
8297 | schaersvoo | 1100 | @ repeat keyword for more function input fields |
8193 | schaersvoo | 1101 | @ the userinput value will be plotted in the canvas |
1102 | @ this value may be read with 'read_canvas()'. <br />for do it yourself js-scripters : If this is the first inputfield in the script, it's id is canvas_input0 |
||
1103 | @ use before this command 'userinput_function',<br />commands like 'inputstyle some_css' , 'xlabel some_description' , 'opacity int,int' , 'linewidth int' , 'dashed' and 'dashtype int,int' to modify |
||
1104 | @ incompatible with command 'intooltip link_text_or_image' : it uses the tooltip div for adding the inputfield |
||
1105 | */ |
||
8224 | bpr | 1106 | if( js_function[DRAW_JSFUNCTION] != 1 ){ |
8193 | schaersvoo | 1107 | js_function[DRAW_JSFUNCTION] = 1; |
8297 | schaersvoo | 1108 | add_rawmath(js_include_file); |
8193 | schaersvoo | 1109 | if(reply_format == 0){reply_format = 24;}/* read canvas_input values */ |
8297 | schaersvoo | 1110 | add_input_jsfunction(js_include_file,canvas_root_id,input_style,function_label,input_cnt,stroke_color,stroke_opacity,line_width,use_dashed,dashtype[0],dashtype[1]); |
8193 | schaersvoo | 1111 | input_cnt++; |
1112 | } |
||
8297 | schaersvoo | 1113 | else |
1114 | { |
||
1115 | /* no need to add DRAW_JSFUNCTION , just call it with the parameters */ |
||
1116 | fprintf(js_include_file,"add_input_jsfunction(%d,\"%s\",\"%s\",%d,\"%s\",\"%.2f\",%d,%d,%d);\n",input_cnt,input_style,function_label,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]); |
||
1117 | input_cnt++; |
||
1118 | } |
||
8193 | schaersvoo | 1119 | if( use_js_math == FALSE){/* add this stuff only once...*/ |
1120 | add_to_js_math(js_include_file); |
||
1121 | use_js_math = TRUE; |
||
1122 | } |
||
1123 | if( use_js_plot == FALSE){ |
||
1124 | use_js_plot = TRUE; |
||
1125 | add_jsplot(js_include_file,canvas_root_id); /* this plots the function on JSPLOT_CANVAS */ |
||
1126 | } |
||
1127 | break; |
||
7614 | schaersvoo | 1128 | case USERDRAW: |
1129 | /* |
||
1130 | @ userdraw object_type,color |
||
8244 | schaersvoo | 1131 | @ implemented object_type: <ul><li>point</li><li>points</li><li>crosshair</li><li>crosshairs</li><li>line</li><li>lines</li><li>vline</li><li>vlines</li><li>hline</li><li>hlines</li><li>demiline</li><li>demilines</li><li>segment</li><li>segments</li><li>polyline</li><li>circle</li><li>circles</li><li>arrow</li><li>arrow2 (double arrow)</li><li>arrows</li><li>arrows2 (double arrows)</li><li>triangle</li><li>polygon</li><li>poly[3-9]</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><li>arc</li><li>arcs</li><li>input<br/>place a single inputfield on 'canvas'<br />use commands 'inputstyle' for css styling: use command 'linewidth' for adjusting the input field size (default 1)</li><li>inputs<br/>place multiple inputfield : placing inputfields on top of each other is not possible</li></ul> |
7614 | schaersvoo | 1132 | @ 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) |
7956 | schaersvoo | 1133 | @ 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 |
8224 | bpr | 1134 | @ note: object_type polygone: Will be finished (the object is closed) when clicked on the first point of the polygone again. |
7614 | schaersvoo | 1135 | @ 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) |
1136 | @ use command "filled", "opacity int,int" and "fillcolor color" to trigger coloured filling of fillable objects |
||
8224 | bpr | 1137 | @ use command "dashed" and/or "dashtype int,int" to trigger dashing |
7614 | schaersvoo | 1138 | @ use command "replyformat int" to control / adjust output formatting of javascript function read_canvas(); |
1139 | @ may be combined with onclick or drag xy of other components of flyscript objects (although not very usefull...) |
||
8224 | bpr | 1140 | @ may be combined with keyword 'userinput_xy' or |
7653 | schaersvoo | 1141 | @ 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 | 1142 | */ |
1143 | if( use_userdraw == TRUE ){ /* only one object type may be drawn*/ |
||
1144 | canvas_error("Only one userdraw primitive may be used: read documentation !!"); |
||
1145 | } |
||
8074 | schaersvoo | 1146 | reply_precision = precision; |
7614 | schaersvoo | 1147 | use_userdraw = TRUE; |
8130 | schaersvoo | 1148 | fprintf(js_include_file,"\n<!-- begin userdraw mouse events -->\nuserdraw_x = new Array();userdraw_y = new Array();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 | 1149 | draw_type = get_string_argument(infile,0); |
1150 | stroke_color = get_color(infile,1); |
||
1151 | if( strcmp(draw_type,"point") == 0 ){ |
||
1152 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
7876 | schaersvoo | 1153 | if(reply_format == 0 ){reply_format = 8;} |
7614 | schaersvoo | 1154 | /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */ |
8071 | schaersvoo | 1155 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
8224 | bpr | 1156 | if(use_input_xy == 1){ |
7652 | schaersvoo | 1157 | add_input_circle(js_include_file,1,1); |
1158 | add_input_xy(js_include_file,canvas_root_id); |
||
1159 | } |
||
7614 | schaersvoo | 1160 | 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); |
1161 | } |
||
1162 | else |
||
1163 | if( strcmp(draw_type,"points") == 0 ){ |
||
1164 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
7876 | schaersvoo | 1165 | if(reply_format == 0 ){reply_format = 8;} |
7614 | schaersvoo | 1166 | /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */ |
8071 | schaersvoo | 1167 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
8224 | bpr | 1168 | if(use_input_xy == 1){ |
7652 | schaersvoo | 1169 | add_input_circle(js_include_file,1,2); |
1170 | add_input_xy(js_include_file,canvas_root_id); |
||
1171 | } |
||
7614 | schaersvoo | 1172 | 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); |
1173 | } |
||
1174 | else |
||
1175 | if( strcmp(draw_type,"segment") == 0 ){ |
||
1176 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
1177 | if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;} |
||
7876 | schaersvoo | 1178 | if(reply_format == 0){reply_format = 11;} |
8071 | schaersvoo | 1179 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
8224 | bpr | 1180 | if(use_input_xy == 1){ |
7652 | schaersvoo | 1181 | add_input_segment(js_include_file,1); |
1182 | add_input_x1y1x2y2(js_include_file,canvas_root_id); |
||
1183 | } |
||
7614 | schaersvoo | 1184 | add_js_segments(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]); |
1185 | } |
||
1186 | else |
||
7663 | schaersvoo | 1187 | if( strcmp(draw_type,"polyline") == 0 ){ |
1188 | if( js_function[DRAW_POLYLINE] != 1 ){ js_function[DRAW_POLYLINE] = 1;} |
||
7876 | schaersvoo | 1189 | if(reply_format == 0){reply_format = 23;} |
8071 | schaersvoo | 1190 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7780 | schaersvoo | 1191 | if( use_input_xy == 1 ){ |
1192 | add_input_polyline(js_include_file); |
||
1193 | add_input_xy(js_include_file,canvas_root_id); |
||
7663 | schaersvoo | 1194 | } |
1195 | add_js_polyline(js_include_file,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]); |
||
1196 | } |
||
1197 | else |
||
7614 | schaersvoo | 1198 | if( strcmp(draw_type,"segments") == 0 ){ |
1199 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
1200 | if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;} |
||
7876 | schaersvoo | 1201 | if(reply_format == 0){reply_format = 11;} |
8071 | schaersvoo | 1202 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
8224 | bpr | 1203 | if(use_input_xy == 1){ |
7652 | schaersvoo | 1204 | add_input_segment(js_include_file,2); |
1205 | add_input_x1y1x2y2(js_include_file,canvas_root_id); |
||
1206 | } |
||
7614 | schaersvoo | 1207 | add_js_segments(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]); |
1208 | } |
||
1209 | else |
||
1210 | if( strcmp(draw_type,"circle") == 0 ){ |
||
1211 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
7876 | schaersvoo | 1212 | if(reply_format == 0){reply_format = 10;} |
7614 | schaersvoo | 1213 | /* 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n in x/y-range */ |
8071 | schaersvoo | 1214 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
8224 | bpr | 1215 | if(use_input_xy == 1){ |
7652 | schaersvoo | 1216 | add_input_circle(js_include_file,2,1); |
1217 | add_input_xyr(js_include_file,canvas_root_id); |
||
1218 | } |
||
7614 | schaersvoo | 1219 | 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]); |
1220 | } |
||
1221 | else |
||
1222 | if( strcmp(draw_type,"circles") == 0 ){ |
||
1223 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
7876 | schaersvoo | 1224 | if(reply_format == 0){reply_format = 10;} |
7614 | schaersvoo | 1225 | /* 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n in x/y-range */ |
1226 | add_js_circles(js_include_file,2,draw_type,line_width,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]); |
||
8071 | schaersvoo | 1227 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
8224 | bpr | 1228 | if(use_input_xy == 1){ |
7652 | schaersvoo | 1229 | add_input_circle(js_include_file,2,2); |
1230 | add_input_xyr(js_include_file,canvas_root_id); |
||
1231 | } |
||
7614 | schaersvoo | 1232 | } |
1233 | else |
||
1234 | if(strcmp(draw_type,"crosshair") == 0 ){ |
||
1235 | if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;} |
||
7876 | schaersvoo | 1236 | if(reply_format == 0){reply_format = 8;} |
7614 | schaersvoo | 1237 | /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */ |
1238 | add_js_crosshairs(js_include_file,1,draw_type,line_width,crosshair_size ,stroke_color,stroke_opacity); |
||
8071 | schaersvoo | 1239 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
8224 | bpr | 1240 | if(use_input_xy == 1){ |
7654 | schaersvoo | 1241 | add_input_crosshair(js_include_file,1); |
1242 | add_input_xy(js_include_file,canvas_root_id); |
||
1243 | } |
||
7614 | schaersvoo | 1244 | } |
1245 | else |
||
1246 | if(strcmp(draw_type,"crosshairs") == 0 ){ |
||
1247 | if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;} |
||
7876 | schaersvoo | 1248 | if(reply_format == 0){reply_format = 8;} |
7614 | schaersvoo | 1249 | /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */ |
1250 | add_js_crosshairs(js_include_file,2,draw_type,line_width,crosshair_size ,stroke_color,stroke_opacity); |
||
8071 | schaersvoo | 1251 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
8224 | bpr | 1252 | if(use_input_xy == 1){ |
7654 | schaersvoo | 1253 | add_input_crosshair(js_include_file,2); |
1254 | add_input_xy(js_include_file,canvas_root_id); |
||
1255 | } |
||
7614 | schaersvoo | 1256 | } |
1257 | else |
||
1258 | if(strcmp(draw_type,"freehandline") == 0 ){ |
||
1259 | if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;} |
||
7876 | schaersvoo | 1260 | if(reply_format == 0){reply_format = 6;} |
8224 | bpr | 1261 | 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 | 1262 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 1263 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 1264 | } |
1265 | else |
||
1266 | if(strcmp(draw_type,"freehandlines") == 0 ){ |
||
1267 | if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;} |
||
7876 | schaersvoo | 1268 | if(reply_format == 0){reply_format = 6;} |
8224 | bpr | 1269 | 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 | 1270 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 1271 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 1272 | } |
1273 | else |
||
1274 | if(strcmp(draw_type,"path") == 0 ){ |
||
1275 | if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;} |
||
7876 | schaersvoo | 1276 | if(reply_format == 0){reply_format = 6;} |
8224 | bpr | 1277 | 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 | 1278 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 1279 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 1280 | } |
1281 | else |
||
1282 | if(strcmp(draw_type,"paths") == 0 ){ |
||
1283 | if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;} |
||
7876 | schaersvoo | 1284 | if(reply_format == 0){reply_format = 6;} |
8224 | bpr | 1285 | 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 | 1286 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 1287 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 1288 | } |
1289 | else |
||
1290 | if(strcmp(draw_type,"arrows") == 0 ){ |
||
1291 | if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;} |
||
7876 | schaersvoo | 1292 | if(reply_format == 0){reply_format = 11;} |
7874 | schaersvoo | 1293 | add_js_arrows(js_include_file,2,draw_type,line_width,1,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head); |
8224 | bpr | 1294 | if(use_input_xy == 1){ |
7654 | schaersvoo | 1295 | add_input_arrow(js_include_file,2); |
1296 | add_input_x1y1x2y2(js_include_file,canvas_root_id); |
||
1297 | } |
||
8071 | schaersvoo | 1298 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 1299 | } |
1300 | else |
||
7874 | schaersvoo | 1301 | if(strcmp(draw_type,"arrows2") == 0 ){ |
1302 | if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;} |
||
7876 | schaersvoo | 1303 | if(reply_format == 0){reply_format = 11;} |
7874 | schaersvoo | 1304 | add_js_arrows(js_include_file,2,draw_type,line_width,2,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head); |
8224 | bpr | 1305 | if(use_input_xy == 1){ |
7874 | schaersvoo | 1306 | add_input_arrow(js_include_file,1); |
1307 | add_input_x1y1x2y2(js_include_file,canvas_root_id); |
||
1308 | } |
||
8071 | schaersvoo | 1309 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7874 | schaersvoo | 1310 | } |
1311 | else |
||
1312 | if(strcmp(draw_type,"arrow2") == 0 ){ |
||
1313 | if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;} |
||
7876 | schaersvoo | 1314 | if(reply_format == 0){reply_format = 11;} |
7874 | schaersvoo | 1315 | add_js_arrows(js_include_file,1,draw_type,line_width,2,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head); |
8224 | bpr | 1316 | if(use_input_xy == 1){ |
7874 | schaersvoo | 1317 | add_input_arrow(js_include_file,1); |
1318 | add_input_x1y1x2y2(js_include_file,canvas_root_id); |
||
1319 | } |
||
8071 | schaersvoo | 1320 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7874 | schaersvoo | 1321 | } |
1322 | else |
||
7614 | schaersvoo | 1323 | if(strcmp(draw_type,"arrow") == 0 ){ |
1324 | if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;} |
||
7876 | schaersvoo | 1325 | if(reply_format == 0){reply_format = 11;} |
7874 | schaersvoo | 1326 | add_js_arrows(js_include_file,1,draw_type,line_width,1,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head); |
8224 | bpr | 1327 | if(use_input_xy == 1){ |
7654 | schaersvoo | 1328 | add_input_arrow(js_include_file,1); |
1329 | add_input_x1y1x2y2(js_include_file,canvas_root_id); |
||
1330 | } |
||
8071 | schaersvoo | 1331 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 1332 | } |
1333 | else |
||
1334 | if(strcmp(draw_type,"polygon") == 0){ |
||
1335 | if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;} |
||
7876 | schaersvoo | 1336 | if(reply_format == 0){reply_format = 2;} |
7614 | schaersvoo | 1337 | add_js_poly(js_include_file,-1,draw_type,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]); |
8071 | schaersvoo | 1338 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
1339 | if(use_input_xy == 2){ |
||
7780 | schaersvoo | 1340 | add_textarea_polygon(js_include_file); |
1341 | add_textarea_xy(js_include_file,canvas_root_id); |
||
7746 | schaersvoo | 1342 | } |
7614 | schaersvoo | 1343 | } |
8224 | bpr | 1344 | else |
7614 | schaersvoo | 1345 | if(strncmp(draw_type,"poly",4) == 0){ |
1346 | if(strlen(draw_type) < 5){canvas_error("use command \"userdraw poly[3-9],color\" eg userdraw poly6,blue");} |
||
1347 | if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;} |
||
7876 | schaersvoo | 1348 | if(reply_format == 0){reply_format = 2;} |
7614 | schaersvoo | 1349 | 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 | 1350 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 1351 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 1352 | } |
8224 | bpr | 1353 | else |
7614 | schaersvoo | 1354 | if(strcmp(draw_type,"triangle") == 0){ |
1355 | if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;} |
||
7876 | schaersvoo | 1356 | if(reply_format == 0){reply_format = 2;} |
7614 | schaersvoo | 1357 | 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 | 1358 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 1359 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 1360 | } |
8224 | bpr | 1361 | else |
7989 | schaersvoo | 1362 | if( strcmp(draw_type,"hline") == 0 ){ |
1363 | if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;} |
||
1364 | if(reply_format == 0){reply_format = 11;} |
||
1365 | add_js_hlines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]); |
||
8071 | schaersvoo | 1366 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
1367 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
||
7989 | schaersvoo | 1368 | } |
1369 | else |
||
1370 | if( strcmp(draw_type,"hlines") == 0 ){ |
||
1371 | if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;} |
||
1372 | if(reply_format == 0){reply_format = 11;} |
||
1373 | add_js_hlines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]); |
||
8071 | schaersvoo | 1374 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
1375 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
||
7989 | schaersvoo | 1376 | } |
1377 | else |
||
1378 | if( strcmp(draw_type,"vline") == 0 ){ |
||
1379 | if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;} |
||
1380 | if(reply_format == 0){reply_format = 11;} |
||
1381 | add_js_hlines(js_include_file,3,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]); |
||
8071 | schaersvoo | 1382 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
1383 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
||
7989 | schaersvoo | 1384 | } |
1385 | else |
||
1386 | if( strcmp(draw_type,"vlines") == 0 ){ |
||
1387 | if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;} |
||
1388 | if(reply_format == 0){reply_format = 11;} |
||
1389 | add_js_hlines(js_include_file,4,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]); |
||
8071 | schaersvoo | 1390 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
1391 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
||
7989 | schaersvoo | 1392 | } |
1393 | else |
||
7614 | schaersvoo | 1394 | if( strcmp(draw_type,"line") == 0 ){ |
1395 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
1396 | if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;} |
||
7876 | schaersvoo | 1397 | if(reply_format == 0){reply_format = 11;} |
7614 | schaersvoo | 1398 | add_js_lines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]); |
7747 | schaersvoo | 1399 | if( use_input_xy == 1 ){ |
7780 | schaersvoo | 1400 | add_input_line(js_include_file,1); |
7747 | schaersvoo | 1401 | add_input_x1y1x2y2(js_include_file,canvas_root_id); |
1402 | } |
||
8071 | schaersvoo | 1403 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 1404 | } |
1405 | else |
||
1406 | if( strcmp(draw_type,"lines") == 0 ){ |
||
1407 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
1408 | if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;} |
||
7876 | schaersvoo | 1409 | if(reply_format == 0){reply_format = 11;} |
7614 | schaersvoo | 1410 | add_js_lines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]); |
7747 | schaersvoo | 1411 | if( use_input_xy == 1 ){ |
7780 | schaersvoo | 1412 | add_input_line(js_include_file,2); |
7747 | schaersvoo | 1413 | add_input_x1y1x2y2(js_include_file,canvas_root_id); |
7746 | schaersvoo | 1414 | } |
8071 | schaersvoo | 1415 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 1416 | } |
1417 | else |
||
8244 | schaersvoo | 1418 | if( strcmp(draw_type,"demilines") == 0 || strcmp(draw_type,"demilines") == 0 ){ |
1419 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
1420 | if( js_function[DRAW_DEMILINES] != 1 ){ js_function[DRAW_DEMILINES] = 1;} |
||
1421 | if(reply_format == 0){reply_format = 11;} |
||
1422 | add_js_demilines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]); |
||
1423 | if( use_input_xy == 1 ){ |
||
1424 | add_input_demiline(js_include_file,2); |
||
1425 | add_input_x1y1x2y2(js_include_file,canvas_root_id); |
||
1426 | } |
||
1427 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
||
1428 | } |
||
1429 | else |
||
1430 | if( strcmp(draw_type,"demiline") == 0 || strcmp(draw_type,"demilines") == 0 ){ |
||
1431 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
1432 | if( js_function[DRAW_DEMILINES] != 1 ){ js_function[DRAW_DEMILINES] = 1;} |
||
1433 | if(reply_format == 0){reply_format = 11;} |
||
1434 | add_js_demilines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]); |
||
1435 | if( use_input_xy == 1 ){ |
||
1436 | add_input_demiline(js_include_file,1); |
||
1437 | add_input_x1y1x2y2(js_include_file,canvas_root_id); |
||
1438 | } |
||
1439 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
||
1440 | } |
||
1441 | else |
||
7614 | schaersvoo | 1442 | if( strcmp(draw_type,"rects") == 0){ |
1443 | if( js_function[DRAW_RECTS] != 1 ){ js_function[DRAW_RECTS] = 1;} |
||
7876 | schaersvoo | 1444 | if(reply_format == 0){reply_format = 2;} |
7614 | schaersvoo | 1445 | 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 | 1446 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 1447 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 1448 | } |
8224 | bpr | 1449 | else |
7614 | schaersvoo | 1450 | if( strcmp(draw_type,"roundrects") == 0){ |
1451 | if( js_function[DRAW_ROUNDRECTS] != 1 ){ js_function[DRAW_ROUNDRECTS] = 1;} |
||
7876 | schaersvoo | 1452 | if(reply_format == 0){reply_format = 2;} |
7614 | schaersvoo | 1453 | 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 | 1454 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 1455 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 1456 | } |
8224 | bpr | 1457 | else |
7614 | schaersvoo | 1458 | if( strcmp(draw_type,"rect") == 0){ |
1459 | if( js_function[DRAW_RECTS] != 1 ){ js_function[DRAW_RECTS] = 1;} |
||
7876 | schaersvoo | 1460 | if(reply_format == 0){reply_format = 2;} |
7614 | schaersvoo | 1461 | 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 | 1462 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 1463 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 1464 | } |
8224 | bpr | 1465 | else |
7614 | schaersvoo | 1466 | if( strcmp(draw_type,"roundrect") == 0){ |
1467 | if( js_function[DRAW_ROUNDRECTS] != 1 ){ js_function[DRAW_ROUNDRECTS] = 1;} |
||
7876 | schaersvoo | 1468 | if(reply_format == 0){reply_format = 2;} |
7614 | schaersvoo | 1469 | 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 | 1470 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 1471 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 1472 | } |
1473 | else |
||
8083 | schaersvoo | 1474 | if( strcmp(draw_type,"arcs") == 0){ |
1475 | if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;} |
||
1476 | if(reply_format == 0){reply_format = 25;} |
||
1477 | add_js_arc(js_include_file,canvas_root_id,2,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]); |
||
1478 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
||
1479 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
||
1480 | } |
||
1481 | else |
||
8071 | schaersvoo | 1482 | if( strcmp(draw_type,"arc") == 0){ |
1483 | if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;} |
||
8083 | schaersvoo | 1484 | if(reply_format == 0){reply_format = 25;} |
1485 | add_js_arc(js_include_file,canvas_root_id,1,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]); |
||
8071 | schaersvoo | 1486 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
1487 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
||
1488 | } |
||
1489 | else |
||
7614 | schaersvoo | 1490 | if( strcmp(draw_type,"text") == 0){ |
8224 | bpr | 1491 | if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;} |
7876 | schaersvoo | 1492 | if(reply_format == 0){reply_format = 17;} |
8071 | schaersvoo | 1493 | add_js_text(js_include_file,canvas_root_id,font_size,font_family,font_color,stroke_opacity); |
7652 | schaersvoo | 1494 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 1495 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 1496 | } |
8116 | schaersvoo | 1497 | else |
1498 | if( strcmp(draw_type,"inputs") == 0){ |
||
8224 | bpr | 1499 | if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;} |
8127 | schaersvoo | 1500 | if(reply_format == 0){reply_format = 27;} |
8116 | schaersvoo | 1501 | add_js_inputs(js_include_file,canvas_root_id,2,input_cnt,input_style,line_width); |
1502 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
||
1503 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
||
1504 | } |
||
1505 | else |
||
1506 | if( strcmp(draw_type,"input") == 0){ |
||
8224 | bpr | 1507 | if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;} |
8127 | schaersvoo | 1508 | if(reply_format == 0){reply_format = 27;} |
8116 | schaersvoo | 1509 | add_js_inputs(js_include_file,canvas_root_id,1,input_cnt,input_style,line_width); |
1510 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
||
1511 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
||
1512 | } |
||
8193 | schaersvoo | 1513 | else |
7614 | schaersvoo | 1514 | { |
1515 | canvas_error("unknown drawtype or typo? "); |
||
1516 | } |
||
1517 | reset(); |
||
1518 | break; |
||
1519 | case PLOTSTEPS: |
||
1520 | /* |
||
1521 | @ plotsteps a_number |
||
1522 | @ default 150 |
||
1523 | @ use with care ! |
||
1524 | */ |
||
1525 | plot_steps = (int) (get_real(infile,1)); |
||
1526 | break; |
||
1527 | case FONTSIZE: |
||
1528 | /* |
||
1529 | @fontsize font_size |
||
1530 | @default value 12 |
||
1531 | */ |
||
1532 | font_size = (int) (get_real(infile,1)); |
||
1533 | break; |
||
1534 | case FONTCOLOR: |
||
1535 | /* |
||
1536 | @fontcolor color |
||
1537 | @color: hexcolor or colorname |
||
1538 | @default: black |
||
1539 | @example usage: x/y-axis text |
||
1540 | */ |
||
1541 | font_color = get_color(infile,1); |
||
1542 | break; |
||
1543 | case ANIMATE: |
||
1544 | /* |
||
1545 | @animate type |
||
8109 | schaersvoo | 1546 | @REMOVED : this should be done with a slider |
7614 | schaersvoo | 1547 | @type may be "point" (nothing else , yet...) |
1548 | @the point is a filled rectangle ; adjust colour with command 'fillcolor colorname/hexnumber' |
||
1549 | @will animate a point on the next plot/curve command |
||
1550 | @the curve will not be draw |
||
1551 | @moves repeatedly from xmin to xmax |
||
1552 | */ |
||
1553 | if( strstr(get_string(infile,1),"point") != 0 ){animation_type = 15;}else{canvas_error("the only animation type (for now) is \"point\"...");} |
||
1554 | break; |
||
7788 | schaersvoo | 1555 | case LEVELCURVE: |
1556 | /* |
||
1557 | @levelcurve color,expression in x/y,l1,l2,... |
||
7792 | schaersvoo | 1558 | @draws very primitive level curves for expression, with levels l1,l2,l3,...,l_n |
1559 | @the quality is <b>not to be compared</b> with the Flydraw levelcurve. <br />(choose flydraw if you want quality...) |
||
1560 | @every individual level curve may be set 'onclick / drag xy' <br />e.g. every single level curve (l1,l2,l3...l_n) has a unique identifier |
||
1561 | @note : the arrays for holding the javascript data are limited in size |
||
1562 | @note : reduce image size if javascript data arrays get overloaded<br />(command 'plotsteps int' will not control the data size of the plot...) |
||
7788 | schaersvoo | 1563 | */ |
7792 | schaersvoo | 1564 | fill_color = get_color(infile,0); |
7788 | schaersvoo | 1565 | char *fun1 = get_string_argument(infile,0); |
1566 | if( strlen(fun1) == 0 ){canvas_error("function is NOT OK !");} |
||
1567 | i = 0; |
||
1568 | done = FALSE; |
||
1569 | while( !done ){ |
||
1570 | double_data[i] = get_real(infile,1); |
||
1571 | i++; |
||
1572 | } |
||
1573 | for(c = 0 ; c < i; c++){ |
||
8097 | schaersvoo | 1574 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,16,%s,[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,eval_levelcurve(xsize,ysize,fun1,xmin,xmax,ymin,ymax,plot_steps,precision,double_data[c]),line_width,line_width,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt); |
7788 | schaersvoo | 1575 | click_cnt++; |
1576 | } |
||
1577 | reset(); |
||
1578 | break; |
||
7858 | schaersvoo | 1579 | case TRACE_JSCURVE: |
7823 | schaersvoo | 1580 | /* |
7858 | schaersvoo | 1581 | @trace_jscurve some_math_function |
7823 | schaersvoo | 1582 | @will use a crosshair to trace the jsmath curve |
7856 | schaersvoo | 1583 | @two inputfields will display the current x/y-values (numerical evaluation by javascript) |
8224 | bpr | 1584 | @default labels 'x' and 'y'<br />the commands 'xlabel some_x_axis_name' and 'ylabel some_y_axis_name' will set the label for the input fields |
7823 | schaersvoo | 1585 | @use linewidth,strokecolor,crosshairsize to adjust the corsshair. |
7858 | schaersvoo | 1586 | @the client browser will convert your math function to javascript math.<br />use parenthesis and rawmath : use 2*x in stead of 2x etc etc<br />no check is done on the validity of your function and/or syntax<br />use error console to debug any errors... |
7823 | schaersvoo | 1587 | */ |
1588 | if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;} |
||
7833 | schaersvoo | 1589 | if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;} |
7858 | schaersvoo | 1590 | if( use_js_math == FALSE){ |
1591 | add_to_js_math(js_include_file); |
||
1592 | use_js_math = TRUE; |
||
1593 | } |
||
7823 | schaersvoo | 1594 | add_trace_js_mouse(js_include_file,TRACE_CANVAS,canvas_root_id,stroke_color,get_string(infile,1),font_size,stroke_opacity,line_width,crosshair_size); |
1595 | break; |
||
1596 | case JSMATH: |
||
1597 | /* |
||
7858 | schaersvoo | 1598 | @jsmath some_math_function |
7856 | schaersvoo | 1599 | @will calculate an y-value from a userinput x-value and draws a crosshair on these coordinates. |
8224 | bpr | 1600 | @default labels 'x' and 'y'<br />the commands 'xlabel some_x_axis_name' and 'ylabel some_y_axis_name' will set the label for the input fields |
7858 | schaersvoo | 1601 | @example: jsmath sin(x^2) |
1602 | @the client browser will convert your math function to javascript math.<br />use parenthesis and rawmath : use 2*x in stead of 2x etc etc<br />no check is done on the validity of your function and/or syntax<br />use error console to debug any errors... |
||
7823 | schaersvoo | 1603 | */ |
1604 | if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;} |
||
7858 | schaersvoo | 1605 | if( use_js_math == FALSE){ |
1606 | add_to_js_math(js_include_file); |
||
1607 | use_js_math = TRUE; |
||
1608 | } |
||
7823 | schaersvoo | 1609 | add_calc_y(js_include_file,canvas_root_id,get_string(infile,1)); |
1610 | break; |
||
7858 | schaersvoo | 1611 | case JSCURVE: |
1612 | /* |
||
1613 | @jscurve color,formula(x) |
||
1614 | @your function will be plotted by the javascript engine of the client browser. |
||
7983 | schaersvoo | 1615 | @use only basic math in your curve:<br /> sqrt,^,asin,acos,atan,log,pi,abs,sin,cos,tan,e |
7858 | schaersvoo | 1616 | @use parenthesis and rawmath : use 2*x in stead of 2x ; use 2^(sin(x))...etc etc<br />use error console to debug any errors... |
7981 | schaersvoo | 1617 | @Attention : last "precision" command in the canvasdraw script determines the calculation precision of the javascript curve plot ! |
7858 | schaersvoo | 1618 | @no validity check is done by wims. |
1619 | @zooming & panning are implemented :<br />use command 'zoom color' for mouse driven zooming<br />or use keyword 'setlimits' for inputfields setting xmin/xmax, ymin/ymax |
||
1620 | @use command 'trace_jscurve formula(x)` for tracing |
||
1621 | @use commmand 'jsmath formula(x)` for calculating and displaying indiviual points on the curve |
||
1622 | @can not be set draggable / onclick (yet) |
||
8224 | bpr | 1623 | @commands plotjump / plotstep are not active for 'jscurve' |
7858 | schaersvoo | 1624 | */ |
1625 | stroke_color = get_color(infile,0); |
||
1626 | if( use_js_math == FALSE){/* add this stuff only once...*/ |
||
1627 | add_to_js_math(js_include_file); |
||
1628 | use_js_math = TRUE; |
||
1629 | } |
||
1630 | if( use_js_plot == FALSE){ |
||
1631 | use_js_plot = TRUE; |
||
1632 | add_jsplot(js_include_file,canvas_root_id); /* this plots the function on JSPLOT_CANVAS */ |
||
1633 | } |
||
1634 | temp = get_string_argument(infile,1); |
||
1635 | string_length = snprintf(NULL,0, "jsplot(%d,\"%s\",%d,\"%s\",%.2f,%d,%d,%d); ",JSPLOT_CANVAS+use_js_plot,temp,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]); |
||
1636 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
1637 | snprintf(tmp_buffer,string_length,"jsplot(%d,\"%s\",%d,\"%s\",%.2f,%d,%d,%d); ",JSPLOT_CANVAS+use_js_plot,temp,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]); |
||
1638 | add_to_buffer(tmp_buffer); |
||
1639 | use_js_plot++; /* we need to create multiple canvasses, so we may zoom and pan ?? */ |
||
1640 | |||
1641 | break; |
||
7614 | schaersvoo | 1642 | case CURVE: |
1643 | /* |
||
1644 | @curve color,formula(x) |
||
1645 | @plot color,formula(x) |
||
1646 | @use command trange before command curve / plot (trange -pi,pi)<br />curve color,formula1(t),formula2(t) |
||
1647 | @use command "precision" to increase the number of digits of the plotted points |
||
1648 | @use command "plotsteps" to increase / decrease the amount of plotted points (default 150) |
||
1649 | @may be set draggable / onclick |
||
1650 | */ |
||
1651 | if( use_parametric == TRUE ){ /* parametric color,fun1(t),fun2(t)*/ |
||
1652 | use_parametric = FALSE; |
||
1653 | stroke_color = get_color(infile,0); |
||
1654 | char *fun1 = get_string_argument(infile,0); |
||
1655 | char *fun2 = get_string_argument(infile,1); |
||
1656 | if( strlen(fun1) == 0 || strlen(fun2) == 0 ){canvas_error("parametric functions are NOT OK !");} |
||
8097 | schaersvoo | 1657 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,%s,[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,animation_type,eval_parametric(xsize,ysize,fun1,fun2,xmin,xmax,ymin,ymax,tmin,tmax,plot_steps,precision),2*line_width,2*line_width,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt); |
7614 | schaersvoo | 1658 | click_cnt++; |
1659 | } |
||
1660 | else |
||
1661 | { |
||
1662 | stroke_color = get_color(infile,0); |
||
1663 | char *fun1 = get_string_argument(infile,1); |
||
8224 | bpr | 1664 | if( strlen(fun1) == 0 ){canvas_error("function is NOT OK !");} |
8097 | schaersvoo | 1665 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,%s,[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,animation_type,eval(xsize,ysize,fun1,xmin,xmax,ymin,ymax,plot_steps,precision),line_width,line_width,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt); |
7614 | schaersvoo | 1666 | click_cnt++; |
1667 | } |
||
7788 | schaersvoo | 1668 | animation_type = 9;/* reset to curve plotting without animation */ |
7614 | schaersvoo | 1669 | reset(); |
1670 | break; |
||
1671 | case FLY_TEXT: |
||
1672 | /* |
||
1673 | @ text fontcolor,x,y,font,text_string |
||
1674 | @ font may be described by keywords : giant,huge,normal,small,tiny |
||
8224 | bpr | 1675 | @ use command 'fontsize' to increase base fontsize for these keywords |
7614 | schaersvoo | 1676 | @ may be set "onclick" or "drag xy" |
1677 | @ backwards compatible with flydraw |
||
1678 | @ unicode supported: text red,0,0,huge,\\u2232 |
||
7874 | schaersvoo | 1679 | @ use command 'string' combined with 'fontfamily' for a more fine grained control over html5 canvas text element |
1680 | @ Avoid mixing old flydraw commands 'text' 'textup' with new canvasdraw commands 'string' stringup'<br />If the fontfamily was set completely like "fontfamily italic 24px Ariel".<br />In that case reset 'fontfamily' to something lke 'fontfamily Ariel' before the old flydraw commands. |
||
7614 | schaersvoo | 1681 | */ |
1682 | for(i = 0; i < 5 ;i++){ |
||
1683 | switch(i){ |
||
1684 | case 0: stroke_color = get_color(infile,0);break;/* font_color == stroke_color name or hex color */ |
||
1685 | case 1: double_data[0] = get_real(infile,0);break; /* x */ |
||
1686 | case 2: double_data[1] = get_real(infile,0);break; /* y */ |
||
1687 | case 3: fly_font = get_string_argument(infile,0); |
||
1688 | if(strcmp(fly_font,"giant") == 0){ |
||
1689 | font_size = (int)(font_size + 24); |
||
1690 | } |
||
1691 | else |
||
1692 | { |
||
1693 | if(strcmp(fly_font,"huge") == 0){ |
||
1694 | font_size = (int)(font_size + 14); |
||
1695 | } |
||
1696 | else |
||
1697 | { |
||
1698 | if(strcmp(fly_font,"large") == 0){ |
||
1699 | font_size = (int)(font_size + 6); |
||
1700 | } |
||
1701 | else |
||
1702 | { |
||
1703 | if(strcmp(fly_font,"small") == 0){ |
||
1704 | font_size = (int)(font_size - 4); |
||
1705 | if(font_size<0){font_size = 8;} |
||
1706 | } |
||
1707 | } |
||
1708 | } |
||
1709 | } |
||
1710 | break; /* font_size ! */ |
||
8224 | bpr | 1711 | case 4: |
7614 | schaersvoo | 1712 | temp = get_string_argument(infile,1); |
1713 | decimals = find_number_of_digits(precision); |
||
8097 | schaersvoo | 1714 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,14,[%.*f],[%.*f],[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[1],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,0,0,0,use_rotate,angle,temp,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt); |
7614 | schaersvoo | 1715 | click_cnt++;reset();break; |
1716 | default:break; |
||
1717 | } |
||
1718 | } |
||
1719 | break; |
||
1720 | case FLY_TEXTUP: |
||
1721 | /* |
||
1722 | @ textup fontcolor,x,y,font,text_string |
||
1723 | @ can <b>not</b> be set "onclick" or "drag xy" (because of translaton matrix...mouse incompatible) |
||
1724 | @ font may be described by keywords : giant,huge,normal,small,tiny |
||
8224 | bpr | 1725 | @ use command 'fontsize' to increase base fontsize for the keywords |
7614 | schaersvoo | 1726 | @ backwards compatible with flydraw |
1727 | @ unicode supported: textup red,0,0,huge,\\u2232 |
||
1728 | @ use command 'stringup' and 'fontfamily' for a more fine grained control over html5 canvas text element |
||
7874 | schaersvoo | 1729 | @ Avoid mixing old flydraw commands 'text' 'textup' with new canvasdraw commands 'string' stringup'<br />If the fontfamily was set completely like "fontfamily italic 24px Ariel".<br />In that case reset 'fontfamily' to something lke 'fontfamily Ariel' before the old flydraw commands. |
7614 | schaersvoo | 1730 | */ |
8224 | bpr | 1731 | if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;} |
7614 | schaersvoo | 1732 | for(i = 0; i<5 ;i++){ |
1733 | switch(i){ |
||
1734 | case 0: font_color = get_color(infile,0);break;/* name or hex color */ |
||
1735 | case 1: int_data[0] = x2px(get_real(infile,0));break; /* x */ |
||
1736 | case 2: int_data[1] = y2px(get_real(infile,0));break; /* y */ |
||
1737 | case 3: fly_font = get_string_argument(infile,0); |
||
1738 | if(strcmp(fly_font,"giant") == 0){ |
||
1739 | font_size = (int)(font_size + 24); |
||
1740 | } |
||
1741 | else |
||
1742 | { |
||
1743 | if(strcmp(fly_font,"huge") == 0){ |
||
1744 | font_size = (int)(font_size + 14); |
||
1745 | } |
||
1746 | else |
||
1747 | { |
||
1748 | if(strcmp(fly_font,"large") == 0){ |
||
1749 | font_size = (int)(font_size + 6); |
||
1750 | } |
||
1751 | else |
||
1752 | { |
||
1753 | if(strcmp(fly_font,"small") == 0){ |
||
1754 | font_size = (int)(font_size - 4); |
||
1755 | if(font_size<0){font_size = 8;} |
||
1756 | } |
||
1757 | } |
||
1758 | } |
||
1759 | } |
||
1760 | break; /* font_size ! */ |
||
8224 | bpr | 1761 | case 4: |
7614 | schaersvoo | 1762 | decimals = find_number_of_digits(precision); |
1763 | temp = get_string_argument(infile,1); |
||
8071 | schaersvoo | 1764 | string_length = snprintf(NULL,0,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,90,\"%s\",%d,%.2f,%d,%s);\n",STATIC_CANVAS,int_data[0],int_data[1],font_size,font_family,font_color,stroke_opacity,temp,use_rotate,angle,use_affine,affine_matrix); |
7614 | schaersvoo | 1765 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
8071 | schaersvoo | 1766 | snprintf(tmp_buffer,string_length,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,90,\"%s\",%d,%.2f,%d,%s);\n",STATIC_CANVAS,int_data[0],int_data[1],font_size,font_family,font_color,stroke_opacity,temp,use_rotate,angle,use_affine,affine_matrix); |
7614 | schaersvoo | 1767 | add_to_buffer(tmp_buffer); |
1768 | break; |
||
1769 | default:break; |
||
1770 | } |
||
1771 | } |
||
1772 | reset(); |
||
1773 | break; |
||
1774 | case FONTFAMILY: |
||
1775 | /* |
||
1776 | @ fontfamily font_description |
||
1777 | @ set the font family; for browsers that support it |
||
1778 | @ font_description: Ariel ,Courier, Helvetica etc |
||
1779 | @ 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 |
||
1780 | @ use correct syntax : 'font style' 'font size'px 'fontfamily' |
||
1781 | */ |
||
1782 | font_family = get_string(infile,1); |
||
1783 | break; |
||
1784 | case STRINGUP: |
||
8224 | bpr | 1785 | /* |
1786 | @ stringup color,x,y,rotation_degrees,the text string |
||
7614 | schaersvoo | 1787 | @ can <b>not</b> be set "onclick" or "drag xy" (because of translaton matrix...mouse incompatible) |
1788 | @ unicode supported: stringup red,0,0,45,\\u2232 |
||
1789 | @ use a command like 'fontfamily bold 34px Courier' <br />to set fonts on browser that support font change |
||
1790 | |||
1791 | */ |
||
1792 | if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;} /* can not be added to shape library : rotate / mouse issues */ |
||
1793 | for(i=0;i<6;i++){ |
||
1794 | switch(i){ |
||
1795 | case 0: font_color = get_color(infile,0);break;/* name or hex color */ |
||
1796 | case 1: int_data[0] = x2px(get_real(infile,0));break; /* x */ |
||
1797 | case 2: int_data[1] = y2px(get_real(infile,0));break; /* y */ |
||
1798 | case 3: double_data[0] = get_real(infile,0);break;/* rotation */ |
||
1799 | case 4: decimals = find_number_of_digits(precision); |
||
1800 | temp = get_string_argument(infile,1); |
||
8071 | schaersvoo | 1801 | string_length = snprintf(NULL,0,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,%.2f,\"%s\",%d,%.2f,%d,%s);\n",STATIC_CANVAS,int_data[0],int_data[1],font_size,font_family,font_color,stroke_opacity,double_data[0],temp,use_rotate,angle,use_affine,affine_matrix); |
7614 | schaersvoo | 1802 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
8071 | schaersvoo | 1803 | snprintf(tmp_buffer,string_length,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,%.2f,\"%s\",%d,%.2f,%d,%s);\n",STATIC_CANVAS,int_data[0],int_data[1],font_size,font_family,font_color,stroke_opacity,double_data[0],temp,use_rotate,angle,use_affine,affine_matrix); |
7614 | schaersvoo | 1804 | add_to_buffer(tmp_buffer); |
1805 | break; |
||
1806 | default:break; |
||
1807 | } |
||
1808 | } |
||
1809 | reset(); |
||
1810 | break; |
||
1811 | case STRING: |
||
8224 | bpr | 1812 | /* |
7614 | schaersvoo | 1813 | @ string color,x,y,the text string |
1814 | @ may be set "onclick" or "drag xy" |
||
1815 | @ unicode supported: string red,0,0,\\u2232 |
||
8224 | bpr | 1816 | @ use a command like 'fontfamily italic 24px Ariel' <br />to set fonts on browser that support font change |
7614 | schaersvoo | 1817 | */ |
1818 | for(i=0;i<5;i++){ |
||
1819 | switch(i){ |
||
1820 | case 0: stroke_color = get_color(infile,0);break;/* name or hex color */ |
||
1821 | case 1: double_data[0] = get_real(infile,0);break; /* x in xrange*/ |
||
1822 | case 2: double_data[1] = get_real(infile,0);break; /* y in yrange*/ |
||
1823 | case 3: decimals = find_number_of_digits(precision); |
||
1824 | temp = get_string_argument(infile,1); |
||
1825 | decimals = find_number_of_digits(precision); |
||
8097 | schaersvoo | 1826 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,14,[%.*f],[%.*f],[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[1],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,0,0,0,use_rotate,angle,temp,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt); |
7614 | schaersvoo | 1827 | click_cnt++;reset();break; |
1828 | default:break; |
||
1829 | } |
||
1830 | } |
||
1831 | break; |
||
7983 | schaersvoo | 1832 | case CENTERSTRING: |
8224 | bpr | 1833 | /* |
7983 | schaersvoo | 1834 | @ centerstring color,y-value,the text string |
7984 | schaersvoo | 1835 | @ title color,y-value,the text string |
7983 | schaersvoo | 1836 | @ draw a string centered on the canvas at y = y-value |
1837 | @ can not set "onclick" or "drag xy" (...) |
||
1838 | @ unicode supported: centerstring red,5,\\u2232 |
||
8224 | bpr | 1839 | @ use a command like 'fontfamily italic 24px Ariel' <br />to set fonts on browser that support font change |
7983 | schaersvoo | 1840 | */ |
1841 | if( js_function[DRAW_CENTERSTRING] != 1 ){ js_function[DRAW_CENTERSTRING] = 1;} |
||
1842 | for(i=0;i<3;i++){ |
||
1843 | switch(i){ |
||
1844 | case 0: stroke_color = get_color(infile,0);break;/* name or hex color */ |
||
1845 | case 1: double_data[0] = get_real(infile,0);break; /* y in xrange*/ |
||
1846 | case 2: temp = get_string_argument(infile,1); |
||
1847 | /* draw_text = function(canvas_type,y,font_family,stroke_color,stroke_opacity,text) */ |
||
1848 | decimals = find_number_of_digits(precision); |
||
1849 | string_length = snprintf(NULL,0, |
||
1850 | "draw_centerstring(%d,%.*f,\"%s\",\"%s\",%.2f,\"%s\");\n",canvas_root_id,decimals,double_data[0],font_family,stroke_color,stroke_opacity,temp); |
||
1851 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
1852 | snprintf(tmp_buffer,string_length,"draw_centerstring(%d,%.*f,\"%s\",\"%s\",%.2f,\"%s\");\n",canvas_root_id,decimals,double_data[0],font_family,stroke_color,stroke_opacity,temp); |
||
1853 | add_to_buffer(tmp_buffer); |
||
1854 | break; |
||
1855 | default:break; |
||
1856 | } |
||
1857 | } |
||
1858 | break; |
||
7614 | schaersvoo | 1859 | case MATHML: |
1860 | /* |
||
1861 | @ mathml x1,y1,x2,y2,mathml_string |
||
8224 | bpr | 1862 | @ mathml will be displayed in a rectangle left top (x1:y1) , right bottom (x2:y2) |
7614 | schaersvoo | 1863 | @ can be set onclick <br />(however dragging is not supported)<br />javascript:read_dragdrop(); will return click number of mathml-object |
8224 | bpr | 1864 | @ if inputfields are incorporated in mathml (with id's : id='mathml0',id='mathml1',...id='mathml_n')<br />the user_input values will be read by javascript:read_mathml();<br />attention: if after this mathml-input object other user-interactions are included, these will read mathml too using "read_canvas();" |
7614 | schaersvoo | 1865 | @ 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.... |
8224 | bpr | 1866 | |
7614 | schaersvoo | 1867 | */ |
1868 | if( js_function[DRAW_XML] != 1 ){ js_function[DRAW_XML] = 1;} |
||
1869 | for(i=0;i<5;i++){ |
||
1870 | switch(i){ |
||
1871 | case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */ |
||
1872 | case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system -> pixel height */ |
||
1873 | case 2: int_data[2]=x2px(get_real(infile,0)) - int_data[0];break; /* width in x/y-range coord system -> pixel width */ |
||
1874 | case 3: int_data[3]=y2px(get_real(infile,0)) - int_data[1];break; /* height in x/y-range coord system -> pixel height */ |
||
1875 | case 4: decimals = find_number_of_digits(precision); |
||
8224 | bpr | 1876 | if(onclick == 1 ){ onclick = click_cnt;click_cnt++;} |
7614 | schaersvoo | 1877 | temp = get_string(infile,1); |
1878 | if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'"); } |
||
1879 | 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); |
||
1880 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
1881 | 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); |
||
1882 | add_to_buffer(tmp_buffer); |
||
8224 | bpr | 1883 | /* |
1884 | in case inputs are present , trigger adding the read_mathml() |
||
7614 | schaersvoo | 1885 | if no other reply_format is defined |
1886 | note: all other reply types will include a reading of elements with id='mathml'+p) |
||
1887 | */ |
||
1888 | if(strstr(temp,"mathml0") != NULL){ |
||
7876 | schaersvoo | 1889 | if(reply_format == 0 ){reply_format = 16;} /* no other reply type is defined */ |
7614 | schaersvoo | 1890 | } |
1891 | break; |
||
1892 | default:break; |
||
1893 | } |
||
1894 | } |
||
1895 | reset(); |
||
1896 | break; |
||
1897 | case HTTP: |
||
1898 | /* |
||
1899 | @http x1,y1,x2,y2,http://some_adress.com |
||
8224 | bpr | 1900 | @an active html-page will be displayed in an "iframe" rectangle left top (x1:y1) , right bottom (x2:y2) |
7614 | schaersvoo | 1901 | @do not use interactivity (or mouse) if the mouse needs to be active in the iframe |
1902 | @can not be 'set onclick' or 'drag xy' |
||
1903 | */ |
||
8224 | bpr | 1904 | if( js_function[DRAW_HTTP] != 1 ){ js_function[DRAW_HTTP] = 1;} |
7614 | schaersvoo | 1905 | for(i=0;i<5;i++){ |
1906 | switch(i){ |
||
1907 | case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */ |
||
1908 | case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system -> pixel height */ |
||
1909 | case 2: int_data[2]=x2px(get_real(infile,0)) - int_data[0];break; /* width in x/y-range coord system -> pixel width */ |
||
1910 | case 3: int_data[3]=y2px(get_real(infile,0)) - int_data[1];break; /* height in x/y-range coord system -> pixel height */ |
||
1911 | case 4: decimals = find_number_of_digits(precision); |
||
1912 | temp = get_string(infile,1); |
||
1913 | if(strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'");} |
||
1914 | 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); |
||
1915 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
1916 | 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); |
||
1917 | add_to_buffer(tmp_buffer); |
||
1918 | break; |
||
1919 | } |
||
1920 | } |
||
1921 | reset(); |
||
1922 | break; |
||
1923 | case HTML: |
||
1924 | /* |
||
1925 | @ html x1,y1,x2,y2,html_string |
||
1926 | @ all tags are allowed |
||
1927 | @ can be set onclick <br />(dragging not supported)<br />javascript:read_dragdrop(); will return click number of mathml-object |
||
1928 | @ 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. |
||
8224 | bpr | 1929 | |
7614 | schaersvoo | 1930 | note: uses the same code as 'mathml' |
1931 | */ |
||
1932 | break; |
||
1933 | case X_AXIS_STRINGS: |
||
1934 | /* |
||
1935 | @ xaxis num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n |
||
1936 | @ xaxistext num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n |
||
1937 | @ use these x-axis values in stead of default xmin...xmax |
||
1938 | @ use command "fontcolor", "fontsize" , "fontfamily" to adjust font <br />defaults: black,12,Ariel |
||
1939 | @ if the 'x-axis words' are to big amd will overlap, a simple alternating offset will be applied |
||
1940 | @ 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 |
||
1941 | @ 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 |
||
1942 | */ |
||
1943 | temp = get_string(infile,1); |
||
1944 | if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");} |
||
1945 | if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/ |
||
1946 | fprintf(js_include_file,"x_strings = [\"%s\"];\n ",temp); |
||
1947 | use_axis_numbering = 1; |
||
1948 | break; |
||
1949 | case Y_AXIS_STRINGS: |
||
1950 | /* |
||
1951 | @ yaxis num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n |
||
1952 | @ yaxistext num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n |
||
1953 | @ use command "fontcolor", "fontsize" , "fontfamily" to adjust font <br />defaults: black,12,Ariel |
||
1954 | @ use these y-axis values in stead of default ymin...ymax |
||
1955 | @ 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 |
||
1956 | */ |
||
1957 | temp = get_string(infile,1); |
||
1958 | if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");} |
||
1959 | if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/ |
||
1960 | fprintf(js_include_file,"y_strings = [\"%s\"];\n ",temp); |
||
1961 | use_axis_numbering = 1; |
||
1962 | break; |
||
8224 | bpr | 1963 | |
7614 | schaersvoo | 1964 | case AXIS_NUMBERING: |
1965 | /* |
||
8224 | bpr | 1966 | @ axisnumbering |
8101 | schaersvoo | 1967 | @ keyword, no arguments required |
7614 | schaersvoo | 1968 | */ |
1969 | use_axis_numbering = 1; |
||
1970 | break; |
||
1971 | case AXIS: |
||
1972 | /* |
||
1973 | @ axis |
||
8101 | schaersvoo | 1974 | @ keyword, no arguments required |
7614 | schaersvoo | 1975 | |
1976 | */ |
||
1977 | use_axis = TRUE; |
||
1978 | break; |
||
8101 | schaersvoo | 1979 | case KILLSLIDER: |
1980 | /* |
||
1981 | @ killslider |
||
1982 | @ keyword, no arguments required |
||
1983 | @ ends grouping of object under a preciously defined slider |
||
1984 | */ |
||
1985 | slider = 0; |
||
1986 | break; |
||
8071 | schaersvoo | 1987 | case SLIDER: |
1988 | /* |
||
8097 | schaersvoo | 1989 | @ slider start_value,end_value,width px,height px,type,label |
1990 | @ type: xy,x,y,angle |
||
8112 | schaersvoo | 1991 | @ if a value display is desired, use<br />type:xy display,x display,y display,angle radian,angle degree |
1992 | @ is a unit for x / y value display is needed, use commands 'xunit' and / or 'yunit' |
||
8101 | schaersvoo | 1993 | @ use commmand 'slider' before draggable/clickable objects. |
1994 | @ a slider will affect all draggable objects after the 'slider' command...<br />and can be used to group translate / rotate several objects...<br />until a next 'slider' or keyword 'killslider' |
||
8097 | schaersvoo | 1995 | @ amount of sliders is not limited. |
8101 | schaersvoo | 1996 | @ javascript:read_dragdrop(); will return an array with 'object_number:slider_value' |
8097 | schaersvoo | 1997 | @ type=xy: will produce a 2D 'slider' [rectangle width x heigh px] in your web page |
1998 | @ every draggable object may have it's own slider (no limit in amount of sliders) |
||
8071 | schaersvoo | 1999 | @ label: some slider text |
2000 | @ use fillcolor for slider ball |
||
2001 | @ use strokecolor for slider bar |
||
8097 | schaersvoo | 2002 | @ use fontfamily / fontcolor to set used fonts |
8071 | schaersvoo | 2003 | @ use opacity (only fill opacity will be used) to set transparency |
8111 | schaersvoo | 2004 | @ the slider canvas will be added to the 'tooltip div' : so incompatible with command tooltip ; setlimits etc |
8071 | schaersvoo | 2005 | */ |
2006 | for(i=0; i<6 ; i++){ |
||
2007 | switch(i){ |
||
2008 | case 0: double_data[0] = get_real(infile,0);break; /* start value */ |
||
2009 | case 1: double_data[1] = get_real(infile,0);break; /* end value */ |
||
2010 | case 2: int_data[0] = (int)(get_real(infile,0));break; /* width */ |
||
2011 | case 3: int_data[1] = (int)(get_real(infile,0));break; /* height */ |
||
8111 | schaersvoo | 2012 | case 4: temp = get_string_argument(infile,0); /* type : xy,x,y,angle */ |
8112 | schaersvoo | 2013 | /* xy display*/ |
2014 | if(strstr(temp,"xy")!= 0){ |
||
8097 | schaersvoo | 2015 | slider = 4; |
2016 | } |
||
2017 | else |
||
2018 | { |
||
8112 | schaersvoo | 2019 | if(strstr(temp,"x") != 0){ |
8097 | schaersvoo | 2020 | slider = 1; |
2021 | } |
||
2022 | else |
||
2023 | { |
||
8112 | schaersvoo | 2024 | if(strstr(temp,"y") != 0){ |
8097 | schaersvoo | 2025 | slider = 2; |
2026 | } |
||
2027 | else |
||
2028 | { |
||
8112 | schaersvoo | 2029 | if(strstr(temp,"angle") != 0){ /* angle diplay radian */ |
8097 | schaersvoo | 2030 | slider = 3; |
2031 | } |
||
2032 | else |
||
8112 | schaersvoo | 2033 | { |
8097 | schaersvoo | 2034 | canvas_error("slider types may be : x , y , xy , angle"); |
8112 | schaersvoo | 2035 | } |
8097 | schaersvoo | 2036 | } |
2037 | } |
||
2038 | } |
||
8112 | schaersvoo | 2039 | if(strstr(temp,"display")!=0){ |
2040 | use_slider_display = 1; /* show x xy values in canvas window */ |
||
2041 | } |
||
2042 | else |
||
2043 | { |
||
2044 | if(strstr(temp,"degree")!= 0){ |
||
2045 | use_slider_display = 2; /* show angle values in canvas window */ |
||
2046 | } |
||
2047 | else |
||
2048 | { |
||
2049 | if(strstr(temp,"radian")!=0){ |
||
2050 | use_slider_display = 3; /* show radian values in canvas window */ |
||
2051 | } |
||
2052 | } |
||
2053 | } |
||
2054 | if(use_slider_display != 0 && slider_cnt == 0){ /*add just once the display js-code */ |
||
2055 | add_slider_display(js_include_file,canvas_root_id,precision,font_size,font_color,stroke_opacity); |
||
2056 | } |
||
8097 | schaersvoo | 2057 | break; |
2058 | case 5: /* some string used for slider description */ |
||
8071 | schaersvoo | 2059 | slider_cnt++; |
8097 | schaersvoo | 2060 | if(slider == 4){ |
8112 | schaersvoo | 2061 | add_xyslider(js_include_file,canvas_root_id,double_data[0],double_data[1],int_data[0],int_data[1],slider,get_string_argument(infile,1),slider_cnt,stroke_color,fill_color,line_width,fill_opacity,font_family,font_color,use_slider_display ); |
8097 | schaersvoo | 2062 | }else{ |
8112 | schaersvoo | 2063 | add_slider(js_include_file,canvas_root_id,double_data[0],double_data[1],int_data[0],int_data[1],slider,get_string_argument(infile,1),slider_cnt,stroke_color,fill_color,line_width,fill_opacity,font_family,font_color,use_slider_display); |
8097 | schaersvoo | 2064 | } |
8071 | schaersvoo | 2065 | break; |
2066 | } |
||
8097 | schaersvoo | 2067 | } |
8071 | schaersvoo | 2068 | break; |
7654 | schaersvoo | 2069 | case SGRAPH: |
2070 | /* |
||
2071 | @ sgraph xstart,ystart,xmajor,ymajor,xminor,yminor,majorgrid_color,minorgrid_color |
||
2072 | @ primitive implementation of a 'broken scale' graph... |
||
7976 | schaersvoo | 2073 | @ not very versatile: only usable in combination with userdraw <br />eg no other objects will obey this "coordinate system"<br />if you want to place an object into this coordinate system, be aware that 10% or 20% of xsize and/or ysize is 'lost'.<br />Use these "formulas" to recalculate the virtual coordinates:<br />factor=0.8 in case xstart != xmin (or ystart != ymin)<br />factor=0.9 in case xstart = xmin (or ystart = ymin)<br />px_x_point = ((factor*xsize)/(xmax - xstart))*(x_point - xmax)+xsize<br />x_recalculated = px*(xmax - xmin)/xsize + $xmin<br />px_y_point = -1*factor*y_point*ysize/(ymax - ystart) + ymax*factor*ysize/(ymax - ystart)<br />y_recalculated = ymax - py*(ymax - ymin)/ysize<br /> |
8224 | bpr | 2074 | @ 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 |
7654 | schaersvoo | 2075 | */ |
8224 | bpr | 2076 | if( js_function[DRAW_SGRAPH] != 1 ){ js_function[DRAW_SGRAPH] = 1;} |
7654 | schaersvoo | 2077 | for(i = 0 ; i < 8 ;i++){ |
2078 | switch(i){ |
||
2079 | case 0:double_data[0] = get_real(infile,0);break; |
||
2080 | case 1:double_data[1] = get_real(infile,0);break; |
||
2081 | case 2:double_data[2] = get_real(infile,0);break; |
||
2082 | case 3:double_data[3] = get_real(infile,0);break; |
||
2083 | case 4:int_data[0] = (int)(get_real(infile,0));break; |
||
2084 | case 5:int_data[1] = (int)(get_real(infile,0));break; |
||
2085 | case 6:stroke_color = get_color(infile,0);break; |
||
2086 | case 7:font_color = get_color(infile,1); |
||
7658 | schaersvoo | 2087 | 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 | 2088 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
7658 | schaersvoo | 2089 | 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 | 2090 | add_to_buffer(tmp_buffer); |
2091 | break; |
||
2092 | default:break; |
||
2093 | } |
||
2094 | } |
||
2095 | /* sgraph(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily,opacity)*/ |
||
2096 | break; |
||
7614 | schaersvoo | 2097 | case GRID:/* xmajor,ymajor,color [,xminor,yminor,tick length (px) ,color]*/ |
2098 | /* |
||
2099 | @ grid step_x,step_y,gridcolor |
||
2100 | @ use command "fontcolor", "fontsize" , "fontfamily" to adjust font <br />defaults: black,12,Ariel |
||
2101 | @ 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 | 2102 | @ 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 | 2103 | @ can not be set "onclick" or "drag xy" |
2104 | @ 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') |
||
2105 | @ 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') |
||
2106 | @ 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') |
||
2107 | */ |
||
7729 | schaersvoo | 2108 | if( js_function[DRAW_YLOGSCALE] == 1 ){canvas_error("only one grid type is allowed...");} |
7614 | schaersvoo | 2109 | if( js_function[DRAW_GRID] != 1 ){ js_function[DRAW_GRID] = 1;} |
2110 | for(i=0;i<4;i++){ |
||
2111 | switch(i){ |
||
2112 | case 0:double_data[0] = get_real(infile,0);break;/* xmajor */ |
||
2113 | case 1:double_data[1] = get_real(infile,0);break;/* ymajor */ |
||
2114 | case 2: |
||
2115 | if( use_axis == TRUE ){ |
||
2116 | stroke_color = get_color(infile,0); |
||
2117 | done = FALSE; |
||
2118 | int_data[0] = (int) (get_real(infile,0));/* xminor */ |
||
2119 | int_data[1] = (int) (get_real(infile,0));/* yminor */ |
||
2120 | int_data[2] = (int) (get_real(infile,0));/* tic_length */ |
||
2121 | fill_color = get_color(infile,1); /* used as axis_color*/ |
||
2122 | } |
||
2123 | else |
||
2124 | { |
||
2125 | int_data[0] = 1; |
||
2126 | int_data[1] = 1; |
||
2127 | stroke_color = get_color(infile,1); |
||
2128 | fill_color = stroke_color; |
||
2129 | } |
||
2130 | 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 | 2131 | /* set snap_x snap_y values in pixels */ |
7988 | schaersvoo | 2132 | fprintf(js_include_file,"snap_x = %f;snap_y = %f;",double_data[0] / int_data[0],double_data[1] / int_data[1]); |
8071 | schaersvoo | 2133 | string_length = snprintf(NULL,0, "draw_grid%d(%d,%d,%.2f,%.*f,%.*f,%d,%d,%d,%d,\"%s\",\"%s\",%d,\"%s\",%d,%d,%d,%.2f,%d,%s,%d,%d,%d,\"%s\",%.2f);\n",canvas_root_id,GRID_CANVAS,precision,stroke_opacity,decimals,double_data[0],decimals,double_data[1],int_data[0],int_data[1],int_data[2],line_width,stroke_color,fill_color,font_size,font_family,use_axis,use_axis_numbering,use_rotate,angle,use_affine,affine_matrix,use_dashed,dashtype[0],dashtype[1],font_color,fill_opacity); |
7614 | schaersvoo | 2134 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
8071 | schaersvoo | 2135 | snprintf(tmp_buffer,string_length,"draw_grid%d(%d,%d,%.2f,%.*f,%.*f,%d,%d,%d,%d,\"%s\",\"%s\",%d,\"%s\",%d,%d,%d,%.2f,%d,%s,%d,%d,%d,\"%s\",%.2f);\n",canvas_root_id,GRID_CANVAS,precision,stroke_opacity,decimals,double_data[0],decimals,double_data[1],int_data[0],int_data[1],int_data[2],line_width,stroke_color,fill_color,font_size,font_family,use_axis,use_axis_numbering,use_rotate,angle,use_affine,affine_matrix,use_dashed,dashtype[0],dashtype[1],font_color,fill_opacity); |
7614 | schaersvoo | 2136 | add_to_buffer(tmp_buffer); |
2137 | break; |
||
2138 | } |
||
2139 | } |
||
2140 | reset(); |
||
2141 | break; |
||
2142 | case OPACITY: |
||
2143 | /* |
||
2144 | @ opacity 0-255,0-255 |
||
2145 | @ |
||
2146 | */ |
||
2147 | for(i = 0 ; i<2;i++){ |
||
2148 | switch(i){ |
||
2149 | case 0: double_data[0]=(int)(get_real(infile,0));break; |
||
2150 | case 1: double_data[1]=(int)(get_real(infile,1));break; |
||
2151 | default: break; |
||
2152 | } |
||
2153 | } |
||
2154 | 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 ? */ |
||
2155 | stroke_opacity = (double) (0.0039215*double_data[0]);/* 0.0 - 1.0 */ |
||
2156 | fill_opacity = (double) (0.0039215*double_data[1]);/* 0.0 - 1.0 */ |
||
2157 | break; |
||
2158 | case ROTATE: |
||
2159 | /* |
||
2160 | @rotate rotation_angle |
||
8097 | schaersvoo | 2161 | @angle in degrees |
7614 | schaersvoo | 2162 | */ |
2163 | use_rotate = TRUE; |
||
8097 | schaersvoo | 2164 | angle = -1*(get_real(infile,1));/* -1 : to be compatible with Flydraw... */ |
7614 | schaersvoo | 2165 | break; |
7785 | schaersvoo | 2166 | case KILLAFFINE: |
2167 | /* |
||
2168 | @ killaffine |
||
2169 | @ keyword : resets the transformation matrix to 1,0,0,1,0,0 |
||
2170 | */ |
||
2171 | use_affine = FALSE; |
||
8224 | bpr | 2172 | snprintf(affine_matrix,14,"[1,0,0,1,0,0]"); |
7785 | schaersvoo | 2173 | break; |
2174 | case AFFINE: |
||
2175 | /* |
||
2176 | @affine a,b,c,d,tx,ty |
||
8224 | bpr | 2177 | @ defines a transformation matrix for subsequent objects |
7785 | schaersvoo | 2178 | @ use keyword 'killaffine' to end the transformation |
2179 | @ note 1: only 'draggable' / 'noclick' objects can be transformed. |
||
2180 | @ note 2: do not use 'onclick' or 'drag xy' with tranformation objects : the mouse coordinates do not get transformed (yet) |
||
2181 | @ note 3: no matrix operations on the transformation matrix implemented (yet) |
||
2182 | @ a : Scales the drawings horizontally |
||
2183 | @ b : Skews the drawings horizontally |
||
2184 | @ c : Skews the drawings vertically |
||
2185 | @ d : Scales the drawings vertically |
||
8071 | schaersvoo | 2186 | @ tx: Moves the drawings horizontally in xrange coordinate system |
8224 | bpr | 2187 | @ ty: Moves the drawings vertically in yrange coordinate system |
8071 | schaersvoo | 2188 | @ the data precision is 2 decimals (printf : %2.f) |
7785 | schaersvoo | 2189 | */ |
2190 | for(i = 0 ; i<6;i++){ |
||
2191 | switch(i){ |
||
2192 | case 0: double_data[0] = get_real(infile,0);break; |
||
2193 | case 1: double_data[1] = get_real(infile,0);break; |
||
2194 | case 2: double_data[2] = get_real(infile,0);break; |
||
2195 | case 3: double_data[3] = get_real(infile,0);break; |
||
8071 | schaersvoo | 2196 | case 4: double_data[4] = get_real(infile,0);break; |
2197 | case 5: double_data[5] = get_real(infile,1); |
||
7785 | schaersvoo | 2198 | use_affine = TRUE; |
8071 | schaersvoo | 2199 | string_length = snprintf(NULL,0, "[%.2f,%.2f,%.2f,%.2f,%.2f,%.2f] ",double_data[0],double_data[1],double_data[2],double_data[3],double_data[4]*xsize/(xmax - xmin),-1*double_data[5]*ysize/(ymax - ymin)); |
7785 | schaersvoo | 2200 | check_string_length(string_length);affine_matrix = my_newmem(string_length+1); |
8224 | bpr | 2201 | snprintf(affine_matrix,string_length,"[%.2f,%.2f,%.2f,%.2f,%.2f,%.2f] ",double_data[0],double_data[1],double_data[2],double_data[3],double_data[4]*xsize/(xmax - xmin),-1*double_data[5]*ysize/(ymax - ymin)); |
8071 | schaersvoo | 2202 | break; |
7785 | schaersvoo | 2203 | default: break; |
2204 | } |
||
2205 | } |
||
2206 | break; |
||
7614 | schaersvoo | 2207 | case KILLTRANSLATION: |
2208 | /* |
||
2209 | killtranslation |
||
2210 | */ |
||
8071 | schaersvoo | 2211 | use_affine = FALSE; |
8224 | bpr | 2212 | snprintf(affine_matrix,14,"[1,0,0,1,0,0]"); |
7614 | schaersvoo | 2213 | break; |
2214 | case TRANSLATION: |
||
2215 | /* |
||
2216 | @translation tx,ty |
||
8071 | schaersvoo | 2217 | @will translate the next object tx in xrange and ty in yrange |
2218 | @uase command 'killtranstation' to end the command |
||
7614 | schaersvoo | 2219 | */ |
8071 | schaersvoo | 2220 | for(i = 0 ; i<2;i++){ |
2221 | switch(i){ |
||
2222 | case 0: double_data[0] = get_real(infile,0);break; |
||
2223 | case 1: double_data[1] = get_real(infile,1); |
||
2224 | use_affine = TRUE; |
||
2225 | string_length = snprintf(NULL,0, "[1,0,0,1,%.2f,%.2f] ",double_data[0]*xsize/(xmax - xmin),-1*double_data[1]*ysize/(ymax - ymin)); |
||
2226 | check_string_length(string_length);affine_matrix = my_newmem(string_length+1); |
||
2227 | snprintf(affine_matrix,string_length,"[1,0,0,1,%.2f,%.2f] ",double_data[0]*xsize/(xmax - xmin),-1*double_data[1]*ysize/(ymax - ymin)); |
||
2228 | break; |
||
2229 | default: break; |
||
2230 | } |
||
2231 | } |
||
2232 | break; |
||
2233 | |||
7614 | schaersvoo | 2234 | case DASHED: |
2235 | /* |
||
2236 | @ keyword "dashed" |
||
2237 | @ next object will be drawn with a dashed line |
||
2238 | @ change dashing scheme by using command "dashtype int,int) |
||
2239 | */ |
||
2240 | use_dashed = TRUE; |
||
2241 | break; |
||
2242 | case FILLED: |
||
2243 | /* |
||
8224 | bpr | 2244 | @ keyword "filled" |
2245 | @ the next 'fillable' object (only) will be filled |
||
7614 | schaersvoo | 2246 | @ use command "fillcolor color" to set fillcolor |
2247 | @ use command "opacity 0-255,0-255" to set stroke and fill-opacity |
||
2248 | @ 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 ! |
||
2249 | */ |
||
2250 | use_filled = TRUE; |
||
2251 | break; |
||
2252 | case STYLE: |
||
2253 | /* |
||
2254 | @highlight color,opacity,linewidth |
||
2255 | @ NOT IMPLEMENTED |
||
2256 | @ use command "onclick" : when the object receives a userclick it will increase it's linewidth |
||
2257 | */ |
||
2258 | break; |
||
2259 | case FILLCOLOR: |
||
2260 | /* |
||
2261 | @ fillcolor colorname or #hex |
||
2262 | @ Set the color for a filled object : mainly used for command 'userdraw obj,stroke_color' |
||
2263 | @ All fillable massive object will have a fillcolor == strokecolor (just to be compatible with flydraw...) |
||
2264 | */ |
||
2265 | fill_color = get_color(infile,1); |
||
2266 | break; |
||
2267 | case STROKECOLOR: |
||
2268 | /* |
||
2269 | @ strokecolor colorname or #hex |
||
2270 | @ to be used for commands that do not supply a color argument (like command 'linegraph') |
||
2271 | */ |
||
2272 | stroke_color = get_color(infile,1); |
||
2273 | break; |
||
8224 | bpr | 2274 | case BGIMAGE: |
7614 | schaersvoo | 2275 | /* |
2276 | @bgimage image_location |
||
2277 | @use an image as background .<br />(we use the background of 'canvas_div' ) |
||
2278 | @the background image will be resized to match "width = xsize" and "height = ysize" |
||
2279 | */ |
||
2280 | URL = get_string(infile,1); |
||
2281 | 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); |
||
2282 | break; |
||
8224 | bpr | 2283 | case BGCOLOR: |
7614 | schaersvoo | 2284 | /* |
2285 | @bgcolor colorname or #hex |
||
2286 | @use this color as background of the "div" containing the canvas(es) |
||
2287 | */ |
||
2288 | /* [255,255,255]*/ |
||
2289 | bgcolor = get_string(infile,1); |
||
2290 | if(strstr(bgcolor,"#") == NULL){ /* convert colorname -> #ff00ff */ |
||
2291 | int found = 0; |
||
2292 | for( i = 0; i < NUMBER_OF_COLORNAMES ; i++ ){ |
||
2293 | if( strcmp( colors[i].name , bgcolor ) == 0 ){ |
||
2294 | bgcolor = colors[i].hex; |
||
2295 | found = 1; |
||
2296 | break; |
||
2297 | } |
||
2298 | } |
||
2299 | if(found == 0){canvas_error("your bgcolor is not in my rgb.txt data list : use hexcolor...something like #a0ffc4");} |
||
2300 | } |
||
2301 | fprintf(js_include_file,"<!-- set background color of canvas div -->\ncanvas_div.style.backgroundColor = \"%s\";canvas_div.style.opacity = %f;\n",bgcolor,fill_opacity); |
||
2302 | break; |
||
2303 | case COPY: |
||
2304 | /* |
||
2305 | @ copy x,y,x1,y1,x2,y2,[filename URL] |
||
2306 | @ Insert the region from (x1,y1) to (x2,y2) (in pixels) of [filename] to (x,y) in x/y-range |
||
2307 | @ If x1=y1=x2=y2=-1, the whole [filename URL] is copied. |
||
8224 | bpr | 2308 | @ [filename] is the URL of the image |
7614 | schaersvoo | 2309 | @ URL is normal URL of network reachable image file location<br />(eg special url for 'classexo' not -yet- implemented) |
2310 | @ 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 |
||
8224 | bpr | 2311 | @ if you want to draw / userdraw on an "imported" image, make sure it is transparent.<br />for example GNUPlot: set terminal gif transparent |
7614 | schaersvoo | 2312 | |
2313 | context.drawImage(img,sx,sy,swidth,sheight,x,y,width,height); |
||
2314 | draw_external_image(canvas_type,URL,sx,sy,swidth,sheight,x,y,width,height,drag_drop){ |
||
2315 | */ |
||
2316 | for(i = 0 ; i<7;i++){ |
||
2317 | switch(i){ |
||
2318 | case 0: int_data[0]=x2px(get_real(infile,0));break; /* x left top corner in x/y range */ |
||
2319 | case 1: int_data[1]=y2px(get_real(infile,0));break; /* y left top corner in x/y range */ |
||
2320 | case 2: int_data[2]=(int)(get_real(infile,0));break;/* x1 in px of external image */ |
||
2321 | case 3: int_data[3]=(int)(get_real(infile,0));break;/* y1 in px of external image */ |
||
2322 | case 4: int_data[4]=(int)(get_real(infile,0));break;/* x2 --> width */ |
||
2323 | case 5: int_data[5]=(int)(get_real(infile,0)) ;break;/* y2 --> height */ |
||
2324 | case 6: URL = get_string(infile,1); |
||
2325 | int_data[6] = int_data[4] - int_data[2];/* swidth & width (if not scaling )*/ |
||
2326 | int_data[7] = int_data[5] - int_data[3];/* sheight & height (if not scaling )*/ |
||
2327 | if( drag_type > -1 ){ |
||
2328 | if( js_function[DRAG_EXTERNAL_IMAGE] != 1 ){ js_function[DRAG_EXTERNAL_IMAGE] = 1;} |
||
7876 | schaersvoo | 2329 | if(reply_format == 0 ){reply_format = 20;} |
7614 | schaersvoo | 2330 | 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); |
2331 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
8224 | bpr | 2332 | snprintf(tmp_buffer,string_length,"drag_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,%d);\n",URL,int_data[2],int_data[3],int_data[6],int_data[7],int_data[0],int_data[1],int_data[6],int_data[7],ext_img_cnt,1); |
7614 | schaersvoo | 2333 | drag_type = -1; |
2334 | ext_img_cnt++; |
||
2335 | } |
||
2336 | else |
||
2337 | { |
||
2338 | if( js_function[DRAW_EXTERNAL_IMAGE] != 1 ){ js_function[DRAW_EXTERNAL_IMAGE] = 1;} |
||
2339 | /* |
||
2340 | draw_external_image = function(URL,sx,sy,swidth,sheight,x0,y0,width,height,draggable){\n\ |
||
2341 | */ |
||
2342 | 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]); |
||
2343 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
2344 | 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]); |
||
2345 | } |
||
2346 | add_to_buffer(tmp_buffer); |
||
2347 | break; |
||
2348 | default: break; |
||
2349 | } |
||
2350 | } |
||
2351 | reset(); |
||
2352 | break; |
||
2353 | /* |
||
2354 | context.drawImage(img,sx,sy,swidth,sheight,x,y,width,height); |
||
2355 | img Specifies the image, canvas, or video element to use |
||
2356 | sx The x coordinate where to start clipping : x1 = int_data[0] |
||
2357 | sy The y coordinate where to start clipping : x2 = int_data[1] |
||
8224 | bpr | 2358 | swidth The width of the clipped image : int_data[2] - int_data[0] |
7614 | schaersvoo | 2359 | sheight The height of the clipped image : int_data[3] - int_data[1] |
2360 | x The x coordinate where to place the image on the canvas : dx1 = int_data[4] |
||
2361 | y The y coordinate where to place the image on the canvas : dy1 = int_data[5] |
||
2362 | width The width of the image to use (stretch or reduce the image) : dx2 - dx1 = int_data[6] |
||
2363 | height The height of the image to use (stretch or reduce the image) : dy2 - dy1 = int_data[7] |
||
2364 | */ |
||
2365 | case COPYRESIZED: |
||
2366 | /* |
||
2367 | @ copyresized x1,y2,x2,y2,dx1,dy1,dx2,dy2,image_file_url |
||
8224 | bpr | 2368 | @ Insert the region from (x1,y1) to (x2,y2) (in pixels) of [ filename], <br />possibly resized,<br />to the region of (dx1,dy1) to (dx2,dy2) in x/y-range |
7614 | schaersvoo | 2369 | @ If x1=y1=x2=y2=-1, the whole [filename / URL ] is copied and resized. |
2370 | @ URL is normal URL of network reachable image file location<br />(eg special url for 'classexo' not -yet- implemented) |
||
2371 | @ 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 |
||
8224 | bpr | 2372 | @ if you want to draw / userdraw on an "imported" image, make sure it is transparent.<br />for example GNUPlot: set terminal gif transparent |
7614 | schaersvoo | 2373 | */ |
2374 | for(i = 0 ; i<9;i++){ |
||
2375 | switch(i){ |
||
2376 | case 0: int_data[0] = (int)(get_real(infile,0));break; /* x1 */ |
||
2377 | case 1: int_data[1] = (int)(get_real(infile,0));break; /* y1 */ |
||
2378 | case 2: int_data[2] = (int)(get_real(infile,0));break;/* x2 */ |
||
2379 | case 3: int_data[3] = (int)(get_real(infile,0));break;/* y2 */ |
||
2380 | case 4: int_data[4] = x2px(get_real(infile,0));break;/* dx1 */ |
||
2381 | case 5: int_data[5] = y2px(get_real(infile,0));break;/* dy1 */ |
||
2382 | case 6: int_data[6] = x2px(get_real(infile,0));break;/* dx2 */ |
||
2383 | case 7: int_data[7] = y2px(get_real(infile,0));break;/* dy2 */ |
||
2384 | case 8: URL = get_string(infile,1); |
||
2385 | if( drag_type > -1 ){ |
||
2386 | if( js_function[DRAG_EXTERNAL_IMAGE] != 1 ){ js_function[DRAG_EXTERNAL_IMAGE] = 1;} |
||
7876 | schaersvoo | 2387 | if(reply_format == 0 ){reply_format = 20;} |
7614 | schaersvoo | 2388 | 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); |
2389 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
2390 | 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); |
||
2391 | drag_type = -1; |
||
2392 | ext_img_cnt++; |
||
2393 | } |
||
2394 | else |
||
2395 | { |
||
2396 | if( js_function[DRAW_EXTERNAL_IMAGE] != 1 ){ js_function[DRAW_EXTERNAL_IMAGE] = 1;} |
||
2397 | 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]); |
||
2398 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
2399 | 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]); |
||
2400 | } |
||
2401 | add_to_buffer(tmp_buffer); |
||
2402 | default: break; |
||
2403 | } |
||
2404 | } |
||
2405 | reset(); |
||
2406 | break; |
||
8146 | schaersvoo | 2407 | case CLEARBUTTON: |
7614 | schaersvoo | 2408 | /* |
8146 | schaersvoo | 2409 | @clearbutton value |
2410 | @adds a button to clear the userdraw canvas with text 'value' |
||
8193 | schaersvoo | 2411 | @normally userdraw primitives have the option to use middle/right mouse button on<br /> a point of the object to remove this specific object...this clear button will remove all drawings |
8146 | schaersvoo | 2412 | @uses the tooltip placeholder div element: may not be used with command 'intooltip' |
8224 | bpr | 2413 | @use command 'inputstyle' to style the button... |
7614 | schaersvoo | 2414 | */ |
8146 | schaersvoo | 2415 | add_clear_button(js_include_file,canvas_root_id,input_style,get_string(infile,1)); |
7614 | schaersvoo | 2416 | break; |
2417 | case INPUTSTYLE: |
||
2418 | /* |
||
2419 | @ inputstyle style_description |
||
2420 | @ example: inputstyle color:blue;font-weight:bold;font-style:italic;font-size:16pt |
||
2421 | */ |
||
2422 | input_style = get_string(infile,1); |
||
2423 | break; |
||
2424 | case INPUT: |
||
8224 | bpr | 2425 | /* |
7614 | schaersvoo | 2426 | @ input x,y,size,editable,value |
8224 | bpr | 2427 | @ to set inputfield "readonly", use editable = 0 |
7614 | schaersvoo | 2428 | @ only active inputfields (editable = 1) will be read with read_canvas(); |
8224 | bpr | 2429 | @ if "$status=done" (e.g. in answer.phtml) the inputfield will be clearedand set readonly<br />Override this by keyword 'status' |
7614 | schaersvoo | 2430 | @ may be further controlled by "inputstyle" (inputcss is not yet implemented...) |
2431 | @ if mathml inputfields are present and / or some userdraw is performed, these data will NOT be send as well (javascript:read_canvas();) |
||
2432 | */ |
||
8224 | bpr | 2433 | if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;} |
7614 | schaersvoo | 2434 | for(i = 0 ; i<5;i++){ |
2435 | switch(i){ |
||
2436 | case 0: int_data[0]=x2px(get_real(infile,0));break;/* x in px */ |
||
2437 | case 1: int_data[1]=y2px(get_real(infile,0));break;/* y in px */ |
||
2438 | case 2: int_data[2]=abs( (int)(get_real(infile,0)));break; /* size */ |
||
2439 | case 3: if( get_real(infile,1) >0){int_data[3] = 1;}else{int_data[3] = 0;};break; /* readonly */ |
||
8224 | bpr | 2440 | case 4: |
7614 | schaersvoo | 2441 | temp = get_string_argument(infile,1); |
2442 | 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); |
||
2443 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
2444 | 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); |
||
2445 | add_to_buffer(tmp_buffer); |
||
2446 | input_cnt++;break; |
||
2447 | default: break; |
||
2448 | } |
||
2449 | } |
||
7876 | schaersvoo | 2450 | if(reply_format == 0 ){reply_format = 15;} |
7614 | schaersvoo | 2451 | reset(); |
2452 | break; |
||
2453 | case TEXTAREA: |
||
8224 | bpr | 2454 | /* |
7614 | schaersvoo | 2455 | @ textarea x,y,cols,rows,readonly,value |
2456 | @ may be further controlled by "inputstyle" |
||
8224 | bpr | 2457 | @ if "$status=done" (e.g. in answer.phtml) the inputfield will be clearedand set readonly<br />Override this by keyword 'status' |
7614 | schaersvoo | 2458 | @ if mathml inputfields are present and / or some userdraw is performed, these data will NOT be send as well (javascript:read_canvas();) |
2459 | */ |
||
8224 | bpr | 2460 | if( js_function[DRAW_TEXTAREAS] != 1 ){ js_function[DRAW_TEXTAREAS] = 1;} |
7614 | schaersvoo | 2461 | for(i = 0 ; i<6;i++){ |
2462 | switch(i){ |
||
2463 | case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in px */ |
||
2464 | case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in px */ |
||
2465 | case 2: int_data[2]=abs( (int)(get_real(infile,0)));break;/* cols */ |
||
2466 | case 3: int_data[3]=abs( (int)(get_real(infile,0)));break;/* rows */ |
||
2467 | case 4: if( get_real(infile,1) >0){int_data[4] = 1;}else{int_data[3] = 0;};break; /* readonly */ |
||
2468 | case 5: temp = get_string_argument(infile,1); |
||
2469 | 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); |
||
2470 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
2471 | 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); |
||
2472 | add_to_buffer(tmp_buffer); |
||
2473 | input_cnt++;break; |
||
2474 | default: break; |
||
2475 | } |
||
2476 | } |
||
7876 | schaersvoo | 2477 | if(reply_format == 0 ){reply_format = 15;} |
7614 | schaersvoo | 2478 | reset(); |
2479 | break; |
||
2480 | case MOUSE_PRECISION: |
||
2481 | /* |
||
2482 | @ precision int |
||
8074 | schaersvoo | 2483 | @ 1 = no decimals ; 10 = 1 decimal ; 100 = 2 decimals etc |
7614 | schaersvoo | 2484 | @ may be used / changed before every object |
8074 | schaersvoo | 2485 | @ In case of user interaction (like 'userdraw') this value will be used to determine the amount of decimals in the reply / answer |
7614 | schaersvoo | 2486 | */ |
2487 | precision = (int) (get_real(infile,1)); |
||
8074 | schaersvoo | 2488 | if(precision < 1 ){precision = 1;}; |
7614 | schaersvoo | 2489 | break; |
7838 | schaersvoo | 2490 | case SETLIMITS: |
2491 | /* |
||
8224 | bpr | 2492 | @setlimits |
7838 | schaersvoo | 2493 | @keyword : if set, it will produce 4 inputfields for 'xmin,xmax,ymin,ymax' and an 'ok' button |
2494 | @may be used for inputfield based zooming / panning |
||
7858 | schaersvoo | 2495 | @use command xlabel / ylabel to change text from xmin to 'xlabel'min etc |
8224 | bpr | 2496 | @note:the input value will not be checked on validity |
7838 | schaersvoo | 2497 | */ |
7956 | schaersvoo | 2498 | if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */ |
7838 | schaersvoo | 2499 | add_setlimits(js_include_file,canvas_root_id); |
2500 | /* add_setlimits provides 'fprintf(js_include_file,"use_pan_and_zoom = 1;");' */ |
||
2501 | use_pan_and_zoom = TRUE; |
||
2502 | done = TRUE; |
||
2503 | break; |
||
7614 | schaersvoo | 2504 | case ZOOM: |
2505 | /* |
||
2506 | @ zoom button_color |
||
2507 | @ introduce a controlpanel at the lower right corner |
||
2508 | @ 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 |
||
2509 | @ the 'x' symbol will do a 'location.reload' of the page, and thus reset all canvas drawings. |
||
2510 | @ choose an appropriate colour, so the small 'x,arrows,-,+' are clearly visible |
||
8224 | bpr | 2511 | @ command 'opacity' may be used to set stroke_opacity of 'buttons |
2512 | @ NOTE: use command 'zoom' at the end of your script code (the same is true for commanmd 'mouse') |
||
7614 | schaersvoo | 2513 | @ NOTE: only objects that may be set draggable / clickable will be zoomed / panned |
2514 | @ 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 !! |
||
2515 | */ |
||
7653 | schaersvoo | 2516 | fprintf(js_include_file,"use_pan_and_zoom = 1;"); |
7797 | schaersvoo | 2517 | use_pan_and_zoom = TRUE; |
7988 | schaersvoo | 2518 | stroke_color = get_color(infile,1); |
7614 | schaersvoo | 2519 | /* we use BG_CANVAS (0) */ |
7988 | schaersvoo | 2520 | add_zoom_buttons(js_include_file,canvas_root_id,stroke_color,stroke_opacity); |
7614 | schaersvoo | 2521 | done = TRUE; |
2522 | break; |
||
2523 | case ONCLICK: |
||
2524 | /* |
||
2525 | @ onclick |
||
2526 | @ keyword, no arguments |
||
2527 | @ if the next object is clicked, it's 'object sequence number' in fly script is returned <br /> by javascript:read_canvas(); |
||
8224 | bpr | 2528 | @ Line based object will show an increase in linewidth<br />Font based objects will show the text in 'bold' when clicked. |
7906 | schaersvoo | 2529 | @ NOTE: not all objects may be set clickable |
7614 | schaersvoo | 2530 | */ |
8257 | schaersvoo | 2531 | fprintf(js_include_file,"use_dragdrop_reply = true;"); |
7614 | schaersvoo | 2532 | onclick = 1; |
2533 | break; |
||
2534 | case DRAG: |
||
2535 | /* |
||
2536 | @ drag [x][y][xy] |
||
2537 | @ the next object will be draggable in x / y / xy direction |
||
2538 | @ the displacement can be read by 'javascript:read_dragdrop();' |
||
8074 | schaersvoo | 2539 | @ the precision (default 2 decimals) in the student reply may be set with command 'precision'.<br />Use this 'precision' command before this command 'drag x|y|xy' ! |
7906 | schaersvoo | 2540 | @ the answer is : object_number : Xorg : Yorg : Xnew : Ynew<br />wherein object_number is the place of the draggable object in your script.<br />Only draggable object will have an object_number (e.g things like point,crosshair,line,segment,circle,rect,triangle...etc) |
7881 | schaersvoo | 2541 | @ use keywordd 'snaptogrid' , 'xsnaptogrid' or 'ysnaptogrid' to switch from free to discrete movement |
8224 | bpr | 2542 | @ in case of external images (commands copy / copyresized) the external image can be set draggable ; always xy. <br />The function javascript;read_canvas() will return the xy-coordinates of all images. |
7614 | schaersvoo | 2543 | @ 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 !! |
2544 | */ |
||
2545 | temp = get_string(infile,1); |
||
8224 | bpr | 2546 | if(strstr(temp,"xy") != NULL ){ |
7614 | schaersvoo | 2547 | drag_type = 0; |
2548 | } |
||
2549 | else |
||
2550 | { |
||
8224 | bpr | 2551 | if(strstr(temp,"x") != NULL ){ |
7614 | schaersvoo | 2552 | drag_type = 1; |
2553 | } |
||
2554 | else |
||
2555 | { |
||
2556 | drag_type = 2; |
||
2557 | } |
||
2558 | } |
||
8257 | schaersvoo | 2559 | fprintf(js_include_file,"dragdrop_precision = %d;use_dragdrop_reply = true;",precision); |
7614 | schaersvoo | 2560 | onclick = 2; |
8257 | schaersvoo | 2561 | |
7614 | schaersvoo | 2562 | /* if(use_userdraw == TRUE ){canvas_error("\"drag & drop\" may not be combined with \"userdraw\" or \"pan and zoom\" \n");} */ |
2563 | break; |
||
2564 | case BLINK: |
||
2565 | /* |
||
2566 | @ blink time(seconds) |
||
2567 | @ NOT IMPLEMETED -YET |
||
2568 | */ |
||
2569 | break; |
||
7996 | schaersvoo | 2570 | case XUNIT: |
2571 | /* |
||
2572 | @ xunit some_unit_for_x-values |
||
2573 | @ unicode allowed (no html code) |
||
2574 | @ use together with command mousex |
||
2575 | @ will display the cursor x-coordinate 'unit' |
||
2576 | */ |
||
2577 | fprintf(js_include_file,"unit_x = \"%s\";",get_string(infile,1)); |
||
2578 | break; |
||
2579 | case YUNIT: |
||
2580 | /* |
||
2581 | @ yunit some_unit_for_y-values |
||
2582 | @ unicode allowed (no html code) |
||
2583 | @ use together with command mousex |
||
2584 | @ will display the cursor y-coordinate 'unit' |
||
2585 | */ |
||
2586 | fprintf(js_include_file,"unit_y = \"%s\";",get_string(infile,1)); |
||
2587 | break; |
||
8071 | schaersvoo | 2588 | case MOUSE_DISPLAY: |
2589 | /* |
||
8129 | schaersvoo | 2590 | @display x|y|xy|degree|radius,color,fontsize |
2591 | @will display the mouse cursor coordinates as x-only,y-only,(x:y),<br />the radius of a circle (this only in case 'userdraw circle(s),color' !!<br />or the angle in degrees ( rhe angle between x-axis;(0:0);(x:y) |
||
2592 | @use commands 'xunit' and / or 'yunit' to add the units to the mouse values |
||
8071 | schaersvoo | 2593 | @just like commands 'mouse','mousex','mousey','mouse_degree'...only other name) |
2594 | */ |
||
2595 | temp = get_string_argument(infile,0); |
||
8112 | schaersvoo | 2596 | if( strstr(temp,"xy") != NULL ){ |
2597 | int_data[0] = 2; |
||
8071 | schaersvoo | 2598 | }else{ |
8112 | schaersvoo | 2599 | if( strstr(temp,"y") != NULL ){ |
2600 | int_data[0] = 1; |
||
8071 | schaersvoo | 2601 | }else{ |
8112 | schaersvoo | 2602 | if( strstr(temp,"x") != NULL ){ |
2603 | int_data[0] = 0; |
||
8129 | schaersvoo | 2604 | }else{ |
8112 | schaersvoo | 2605 | if(strstr(temp,"degree") != NULL){ |
2606 | int_data[0] = 3; |
||
8071 | schaersvoo | 2607 | }else{ |
8129 | schaersvoo | 2608 | if(strstr(temp,"radius") != NULL){ |
2609 | int_data[0] = 4; |
||
2610 | }else{ |
||
2611 | int_data[0] = 2; |
||
2612 | } |
||
8112 | schaersvoo | 2613 | } |
8129 | schaersvoo | 2614 | } |
8071 | schaersvoo | 2615 | } |
8129 | schaersvoo | 2616 | } |
8071 | schaersvoo | 2617 | stroke_color = get_color(infile,0); |
2618 | font_size = (int) (get_real(infile,1)); |
||
2619 | tmp_buffer = my_newmem(26); |
||
2620 | snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer); |
||
2621 | add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,int_data[0]); |
||
2622 | break; |
||
2623 | case MOUSE_DEGREE: |
||
2624 | /* |
||
2625 | @ mouse_degree color,fontsize |
||
8099 | schaersvoo | 2626 | @ will display the angle in degrees between x-axis, (0:0) and the cursor (x:y) in 'color' and 'font size'<br /> using default fontfamily Ariel |
8071 | schaersvoo | 2627 | @ The angle is positive in QI and QIII and the angle value is negative in QII and QIV |
8224 | bpr | 2628 | @ NOTE: use command 'mouse' at the end of your script code (the same is true for command 'zoom') |
8071 | schaersvoo | 2629 | |
2630 | */ |
||
2631 | stroke_color = get_color(infile,0); |
||
2632 | font_size = (int) (get_real(infile,1)); |
||
2633 | tmp_buffer = my_newmem(26); |
||
2634 | snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer); |
||
2635 | add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,3); |
||
2636 | break; |
||
7991 | schaersvoo | 2637 | case MOUSEX: |
2638 | /* |
||
2639 | @ mousex color,fontsize |
||
2640 | @ will display the cursor x-coordinate in 'color' and 'font size'<br /> using default fontfamily Ariel |
||
8224 | bpr | 2641 | @ NOTE: use command 'mouse' at the end of your script code (the same is true for command 'zoom') |
7991 | schaersvoo | 2642 | |
2643 | */ |
||
2644 | stroke_color = get_color(infile,0); |
||
2645 | font_size = (int) (get_real(infile,1)); |
||
2646 | tmp_buffer = my_newmem(26); |
||
2647 | snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer); |
||
2648 | add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,0); |
||
2649 | break; |
||
2650 | case MOUSEY: |
||
2651 | /* |
||
2652 | @ mousey color,fontsize |
||
2653 | @ will display the cursor y-coordinate in 'color' and 'font size'<br /> using default fontfamily Ariel |
||
8224 | bpr | 2654 | @ NOTE: use command 'mouse' at the end of your script code (the same is true for command 'zoom') |
7991 | schaersvoo | 2655 | |
2656 | */ |
||
2657 | stroke_color = get_color(infile,0); |
||
2658 | font_size = (int) (get_real(infile,1)); |
||
2659 | tmp_buffer = my_newmem(26); |
||
2660 | snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer); |
||
2661 | add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,1); |
||
2662 | break; |
||
7614 | schaersvoo | 2663 | case MOUSE: |
2664 | /* |
||
2665 | @ mouse color,fontsize |
||
7991 | schaersvoo | 2666 | @ will display the cursor (x:y) coordinates in 'color' and 'font size'<br /> using default fontfamily Ariel |
8224 | bpr | 2667 | @ NOTE: use command 'mouse' at the end of your script code (the same is true for commanmd 'zoom') |
7988 | schaersvoo | 2668 | |
7614 | schaersvoo | 2669 | */ |
2670 | stroke_color = get_color(infile,0); |
||
2671 | font_size = (int) (get_real(infile,1)); |
||
7839 | schaersvoo | 2672 | tmp_buffer = my_newmem(26); |
2673 | snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer); |
||
7991 | schaersvoo | 2674 | add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,2); |
7614 | schaersvoo | 2675 | break; |
2676 | case INTOOLTIP: |
||
2677 | /* |
||
2678 | @ intooltip link_text |
||
2679 | @ link_text is a single line (span-element) |
||
2680 | @ link_text may also be an image URL http://some_server/images/my_image.png |
||
2681 | @ link_text may contain HTML markup |
||
2682 | @ the canvas will be displayed in a tooltip on 'link_text' |
||
2683 | @ the canvas is default transparent: use command 'bgcolor color' to adjust background-color<br />the link test will alos be shown with this bgcolor. |
||
2684 | */ |
||
7823 | schaersvoo | 2685 | if(use_input_xy != FALSE ){canvas_error("intooltip can not be combined with userinput_xy command");} |
7614 | schaersvoo | 2686 | use_tooltip = TRUE; |
2687 | tooltip_text = get_string(infile,1); |
||
2688 | if(strstr(tooltip_text,"\"") != 0 ){ tooltip_text = str_replace(tooltip_text,"\"","'"); } |
||
2689 | break; |
||
2690 | case AUDIO: |
||
2691 | /* |
||
2692 | @ audio x,y,w,h,loop,visible,audiofile location |
||
2693 | @ x,y : left top corner of audio element (in xrange / yrange) |
||
2694 | @ w,y : width and height in pixels |
||
2695 | @ loop : 0 or 1 ( 1 = loop audio fragment) |
||
2696 | @ visible : 0 or 1 (1 = show controls) |
||
2697 | @ audio format may be in *.mp3 or *.ogg |
||
2698 | @ If you are using *.mp3 : be aware that FireFox will not (never) play this ! (Pattented format) |
||
2699 | @ if you are using *.ogg : be aware that Microsoft based systems not support it natively |
||
2700 | @ To avoid problems supply both types (mp3 and ogg) of audiofiles.<br />the program will use both as source tag |
||
2701 | @ 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 /> |
||
2702 | */ |
||
2703 | if( js_function[DRAW_AUDIO] != 1 ){ js_function[DRAW_AUDIO] = 1;} |
||
2704 | for(i=0;i<7;i++){ |
||
2705 | switch(i){ |
||
2706 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */ |
||
2707 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system -> pixel */ |
||
2708 | case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */ |
||
2709 | case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */ |
||
2710 | case 4: int_data[4] = (int) (get_real(infile,0)); if(int_data[4] != TRUE){int_data[4] = FALSE;} break; /* loop boolean */ |
||
2711 | case 5: int_data[5] = (int) (get_real(infile,0)); if(int_data[5] != TRUE){int_data[5] = FALSE;} break; /* visible boolean */ |
||
8224 | bpr | 2712 | case 6: |
7614 | schaersvoo | 2713 | temp = get_string(infile,1); |
2714 | if( strstr(temp,".mp3") != 0 ){ temp = str_replace(temp,".mp3","");} |
||
2715 | if( strstr(temp,".ogg") != 0 ){ temp = str_replace(temp,".ogg","");} |
||
2716 | 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); |
||
2717 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
2718 | 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); |
||
2719 | add_to_buffer(tmp_buffer); |
||
2720 | break; |
||
2721 | default:break; |
||
2722 | } |
||
2723 | } |
||
2724 | reset(); |
||
2725 | break; |
||
2726 | case VIDEO: |
||
2727 | /* |
||
2728 | @ video x,y,w,h,videofile location |
||
2729 | @ x,y : left top corner of audio element (in xrange / yrange) |
||
2730 | @ w,y : width and height in pixels |
||
2731 | @ example:<br />wims getfile : video 0,0,120,120,myvideo.mp4 |
||
2732 | @ video format may be in *.mp4 (todo:other formats) |
||
2733 | */ |
||
2734 | if( js_function[DRAW_VIDEO] != 1 ){ js_function[DRAW_VIDEO] = 1;} |
||
2735 | for(i=0;i<5;i++){ |
||
2736 | switch(i){ |
||
2737 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */ |
||
2738 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system -> pixel */ |
||
2739 | case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */ |
||
2740 | case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */ |
||
2741 | case 4: temp = get_string(infile,1); |
||
2742 | 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); |
||
2743 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
2744 | 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); |
||
2745 | add_to_buffer(tmp_buffer); |
||
2746 | break; |
||
2747 | default:break; |
||
2748 | } |
||
2749 | } |
||
2750 | reset(); |
||
2751 | break; |
||
2752 | case HATCHFILL: |
||
2753 | /* |
||
2754 | @ hatchfill x0,y0,dx,dy,color |
||
2755 | @ x0,y0 in xrange / yrange |
||
2756 | @ distances dx,dy in pixels |
||
2757 | */ |
||
2758 | if( js_function[DRAW_HATCHFILL] != 1 ){ js_function[DRAW_HATCHFILL] = 1;} |
||
2759 | for(i=0;i<5;i++){ |
||
2760 | switch(i){ |
||
2761 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */ |
||
2762 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y */ |
||
2763 | case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */ |
||
2764 | case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/ |
||
2765 | case 4: stroke_color = get_color(infile,1); |
||
2766 | /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */ |
||
2767 | 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); |
||
2768 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
2769 | 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); |
||
2770 | add_to_buffer(tmp_buffer); |
||
2771 | break; |
||
2772 | default:break; |
||
2773 | } |
||
2774 | } |
||
2775 | reset(); |
||
2776 | break; |
||
7647 | schaersvoo | 2777 | case DIAMONDFILL: |
2778 | /* |
||
2779 | @ diamondfill x0,y0,dx,dy,color |
||
2780 | @ x0,y0 in xrange / yrange |
||
2781 | @ distances dx,dy in pixels |
||
2782 | */ |
||
2783 | if( js_function[DRAW_DIAMONDFILL] != 1 ){ js_function[DRAW_DIAMONDFILL] = 1;} |
||
2784 | for(i=0;i<5;i++){ |
||
2785 | switch(i){ |
||
2786 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */ |
||
2787 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y */ |
||
2788 | case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */ |
||
2789 | case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/ |
||
2790 | case 4: stroke_color = get_color(infile,1); |
||
2791 | /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */ |
||
2792 | 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); |
||
2793 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
2794 | 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); |
||
2795 | add_to_buffer(tmp_buffer); |
||
2796 | break; |
||
2797 | default:break; |
||
2798 | } |
||
2799 | } |
||
2800 | reset(); |
||
2801 | break; |
||
7614 | schaersvoo | 2802 | case GRIDFILL: |
2803 | /* |
||
2804 | @ gridfill x0,y0,dx,dy,color |
||
2805 | @ x0,y0 in xrange / yrange |
||
2806 | @ distances dx,dy in pixels |
||
7883 | schaersvoo | 2807 | @ a draggable object may snap_to_grid (using keywords xysnaptogrid,xsnaprogrid, ysnaptogrid) |
2808 | @ userdraw object may snap_to_grid |
||
7614 | schaersvoo | 2809 | */ |
2810 | if( js_function[DRAW_GRIDFILL] != 1 ){ js_function[DRAW_GRIDFILL] = 1;} |
||
2811 | for(i=0;i<5;i++){ |
||
2812 | switch(i){ |
||
2813 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */ |
||
2814 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y */ |
||
2815 | case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */ |
||
2816 | case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/ |
||
2817 | case 4: stroke_color = get_color(infile,1); |
||
2818 | 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); |
||
2819 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
2820 | 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); |
||
2821 | add_to_buffer(tmp_buffer); |
||
2822 | break; |
||
2823 | default:break; |
||
2824 | } |
||
2825 | } |
||
2826 | reset(); |
||
2827 | break; |
||
2828 | case DOTFILL: |
||
2829 | /* |
||
2830 | @ dotfill x0,y0,dx,dy,color |
||
2831 | @ x0,y0 in xrange / yrange |
||
2832 | @ distances dx,dy in pixels |
||
2833 | @ radius of dots is linewidth |
||
2834 | */ |
||
2835 | if( js_function[DRAW_DOTFILL] != 1 ){ js_function[DRAW_DOTFILL] = 1;} |
||
2836 | for(i=0;i<5;i++){ |
||
2837 | switch(i){ |
||
2838 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */ |
||
2839 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y */ |
||
2840 | case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */ |
||
2841 | case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/ |
||
2842 | case 4: stroke_color = get_color(infile,1); |
||
2843 | /* draw_dotfill(ctx,x0,y0,dx,dy,radius,color,opacity,xsize,ysize) */ |
||
2844 | 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); |
||
2845 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
2846 | 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); |
||
2847 | add_to_buffer(tmp_buffer); |
||
2848 | break; |
||
2849 | default:break; |
||
2850 | } |
||
2851 | } |
||
2852 | reset(); |
||
2853 | break; |
||
2854 | case IMAGEFILL: |
||
2855 | /* |
||
2856 | @ imagefill dx,dy,image_url |
||
2857 | @ The next suitable <b>filled object</b> will be filled with "image_url" tiled |
||
2858 | @ After pattern filling ,the fill-color should be reset ! |
||
2859 | @ wims getins / image from class directory : imagefill 80,80,my_image.gif |
||
2860 | @ normal url : imagefill 80,80,$module_dir/gifs/my_image.gif |
||
2861 | @ normal url : imagefill 80,80,http://adres/a/b/c/my_image.jpg |
||
2862 | @ if dx,dy is larger than the image, the whole image will be background to the next object. |
||
2863 | */ |
||
2864 | if( js_function[DRAW_IMAGEFILL] != 1 ){ js_function[DRAW_IMAGEFILL] = 1;} |
||
2865 | for(i=0 ;i < 3 ; i++){ |
||
2866 | switch(i){ |
||
2867 | case 0:int_data[0] = (int) (get_real(infile,0));break; |
||
2868 | case 1:int_data[1] = (int) (get_real(infile,0));break; |
||
2869 | case 2: URL = get_string_argument(infile,1); |
||
2870 | 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); |
||
2871 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
2872 | 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); |
||
2873 | add_to_buffer(tmp_buffer); |
||
2874 | break; |
||
2875 | } |
||
2876 | } |
||
8083 | schaersvoo | 2877 | reset(); |
7614 | schaersvoo | 2878 | break; |
2879 | case FILLTOBORDER: |
||
2880 | /* |
||
2881 | @ filltoborder x,y,bordercolor,color |
||
8224 | bpr | 2882 | @ fill the region of point (x:y) bounded by 'bordercolor' with color 'color' |
7614 | schaersvoo | 2883 | @ any other color will not act as border to the bucket fill |
2884 | @ use this command after all boundary objects are declared. |
||
2885 | @ 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.. |
||
2886 | */ |
||
2887 | for(i=0 ;i < 4 ; i++){ |
||
2888 | switch(i){ |
||
2889 | case 0:double_data[0] = get_real(infile,0);break; |
||
2890 | case 1:double_data[1] = get_real(infile,0);break; |
||
2891 | case 2:bgcolor = get_color(infile,0);break; |
||
2892 | case 3:fill_color = get_color(infile,1); |
||
2893 | if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */ |
||
2894 | js_function[DRAW_FILLTOBORDER] = 1; |
||
2895 | add_js_filltoborder(js_include_file,canvas_root_id); |
||
2896 | } |
||
2897 | decimals = find_number_of_digits(precision); |
||
7895 | schaersvoo | 2898 | /* we need to set a timeout: the canvas is not yet draw in memory? when floodfill is called directly... */ |
8071 | schaersvoo | 2899 | string_length = snprintf(NULL,0, "setTimeout(function(){filltoborder(%.*f,%.*f,[%s,%d],[%s,%d]);},1000);\n",decimals,double_data[0],decimals,double_data[1],bgcolor,(int) (fill_opacity/0.0039215),fill_color,(int) (fill_opacity/0.0039215)); |
7614 | schaersvoo | 2900 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
8071 | schaersvoo | 2901 | snprintf(tmp_buffer,string_length,"setTimeout(function(){filltoborder(%.*f,%.*f,[%s,%d],[%s,%d]);},1000);\n",decimals,double_data[0],decimals,double_data[1],bgcolor,(int) (fill_opacity/0.0039215),fill_color,(int) (fill_opacity/0.0039215)); |
7614 | schaersvoo | 2902 | add_to_buffer(tmp_buffer); |
2903 | break; |
||
2904 | default:break; |
||
8083 | schaersvoo | 2905 | } |
2906 | } |
||
2907 | reset(); |
||
7614 | schaersvoo | 2908 | break; |
2909 | case FLOODFILL: |
||
2910 | /* |
||
2911 | @ floodfill x,y,color |
||
2912 | @ alternative syntax: fill x,y,color |
||
2913 | @ fill the region of point (x:y) with color 'color' |
||
2914 | @ any other color or size of picture (borders of picture) will act as border to the bucket fill |
||
2915 | @ use this command after all boundary objects are declared. |
||
2916 | @ Use command 'clickfill,color' for user click driven flood fill. |
||
2917 | @ NOTE: recognised colour boundaries are in the "drag canvas" e.g. only for objects that can be set draggable / clickable |
||
2918 | @ 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.. |
||
2919 | */ |
||
2920 | for(i=0 ;i < 4 ; i++){ |
||
2921 | switch(i){ |
||
2922 | case 0:double_data[0] = get_real(infile,0);break; |
||
2923 | case 1:double_data[1] = get_real(infile,0);break; |
||
2924 | case 2:fill_color = get_color(infile,1); |
||
2925 | if(js_function[DRAW_FLOODFILL] != 1 ){/* use only once */ |
||
2926 | js_function[DRAW_FLOODFILL] = 1; |
||
2927 | add_js_floodfill(js_include_file,canvas_root_id); |
||
2928 | } |
||
2929 | decimals = find_number_of_digits(precision);/*floodfill(interaction,x,y,[R,G,B,A]) */ |
||
7895 | schaersvoo | 2930 | /* we need to set a timeout: the canvas is not yet draw in memory? when floodfill is called directly... */ |
2931 | string_length = snprintf(NULL,0, "setTimeout(function(){floodfill(0,%.*f,%.*f,[%s,%d]);},1000);\n",decimals,double_data[0],decimals,double_data[1],fill_color,(int) (fill_opacity/0.0039215)); |
||
7614 | schaersvoo | 2932 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
7895 | schaersvoo | 2933 | snprintf(tmp_buffer,string_length,"setTimeout(function(){floodfill(0,%.*f,%.*f,[%s,%d]);},1000);\n",decimals,double_data[0],decimals,double_data[1],fill_color,(int) (fill_opacity/0.0039215)); |
7614 | schaersvoo | 2934 | add_to_buffer(tmp_buffer); |
2935 | break; |
||
2936 | default:break; |
||
8083 | schaersvoo | 2937 | } |
2938 | } |
||
2939 | reset(); |
||
7614 | schaersvoo | 2940 | break; |
2941 | case CLICKFILLMARGE: |
||
2942 | clickfillmarge = (int) (get_real(infile,1)); |
||
2943 | break; |
||
2944 | /* |
||
2945 | @ clickfillmarge int |
||
2946 | @ default 20 (pixels) |
||
2947 | @ 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[]) |
||
2948 | */ |
||
2949 | case CLICKFILL: |
||
2950 | /* |
||
2951 | @ clickfill fillcolor |
||
2952 | @ user left mouse click will floodfill the area with fillcolor |
||
2953 | @ multiple areas may be coloured |
||
2954 | @ 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) |
||
2955 | @ the answer will be read as the (x:y) click coordinates per coloured area |
||
2956 | @ background color of main div may be set by using command "bgcolor color" |
||
2957 | @ may not be combined with command "userdraw" |
||
2958 | @ NOTE: recognised colour boundaries are in the "drag canvas" e.g. only for objects that can be set draggable / clickable |
||
2959 | */ |
||
2960 | fill_color = get_color(infile,1); |
||
2961 | if(js_function[DRAW_FLOODFILL] != 1 ){/* use only once */ |
||
2962 | js_function[DRAW_FLOODFILL] = 1; |
||
2963 | add_js_floodfill(js_include_file,canvas_root_id); |
||
2964 | } |
||
8130 | schaersvoo | 2965 | fprintf(js_include_file,"\n<!-- begin command clickfill -->\nvar marge_xy = %d;userdraw_x = new Array();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 || [255,255,255,0]);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)); |
8257 | schaersvoo | 2966 | add_read_canvas(canvas_root_id,1,reply_precision); |
8083 | schaersvoo | 2967 | reset(); |
7614 | schaersvoo | 2968 | break; |
2969 | case SETPIXEL: |
||
2970 | /* |
||
2971 | @ setpixel x,y,color |
||
2972 | @ A "point" with diameter 1 pixel centeres at (x:y) in xrange / yrange |
||
2973 | @ pixels can not be dragged or clicked |
||
2974 | @ "pixelsize = 1" may be changed by command "pixelsize int" |
||
2975 | */ |
||
2976 | if( js_function[DRAW_PIXELS] != 1 ){ js_function[DRAW_PIXELS] = 1;} |
||
2977 | for(i=0;i<3;i++){ |
||
2978 | switch(i){ |
||
2979 | case 0: double_data[0] = get_real(infile,0); break; /* x */ |
||
2980 | case 1: double_data[1] = get_real(infile,0); break; /* y */ |
||
2981 | case 2: stroke_color = get_color(infile,1); |
||
2982 | string_length = snprintf(NULL,0,"draw_setpixel([%f],[%f],\"%s\",%.2f,%d);\n",double_data[0],double_data[1],stroke_color,stroke_opacity,pixelsize); |
||
2983 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
2984 | snprintf(tmp_buffer,string_length,"draw_setpixel([%f],[%f],\"%s\",%.2f,%d);\n",double_data[0],double_data[1],stroke_color,stroke_opacity,pixelsize); |
||
2985 | add_to_buffer(tmp_buffer); |
||
2986 | break; |
||
2987 | default:break; |
||
2988 | } |
||
2989 | } |
||
2990 | reset(); |
||
2991 | break; |
||
2992 | case PIXELSIZE: |
||
2993 | /* |
||
2994 | @ pixelsize int |
||
2995 | @ in case you want to deviate from default pixelsize = 1... |
||
2996 | */ |
||
2997 | pixelsize = (int) get_real(infile,1); |
||
2998 | break; |
||
2999 | case PIXELS: |
||
3000 | /* |
||
3001 | @ pixels color,x1,y1,x2,y2,x3,y3... |
||
3002 | @ Draw "points" with diameter 1 pixel |
||
3003 | @ pixels can not be dragged or clicked |
||
3004 | @ "pixelsize = 1" may be changed by command "pixelsize int" |
||
3005 | */ |
||
3006 | if( js_function[DRAW_PIXELS] != 1 ){ js_function[DRAW_PIXELS] = 1;} |
||
3007 | stroke_color=get_color(infile,0); |
||
3008 | i=0; |
||
3009 | c=0; |
||
3010 | while( ! done ){ /* get next item until EOL*/ |
||
3011 | if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");} |
||
3012 | for( c = 0 ; c < 2; c++){ |
||
3013 | if(c == 0 ){ |
||
3014 | double_data[i] = get_real(infile,0); |
||
3015 | i++; |
||
3016 | } |
||
3017 | else |
||
3018 | { |
||
3019 | double_data[i] = get_real(infile,1); |
||
3020 | i++; |
||
3021 | } |
||
3022 | } |
||
3023 | } |
||
3024 | decimals = find_number_of_digits(precision); |
||
3025 | /* *double_xy2js_array(double xy[],int len,int decimals) */ |
||
3026 | string_length = snprintf(NULL,0, "draw_setpixel(%s,\"%s\",%.2f,%d);\n",double_xy2js_array(double_data,i,decimals),stroke_color,stroke_opacity,pixelsize); |
||
3027 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
3028 | snprintf(tmp_buffer,string_length,"draw_setpixel(%s,\"%s\",%.2f,%d);\n",double_xy2js_array(double_data,i,decimals),stroke_color,stroke_opacity,pixelsize); |
||
3029 | add_to_buffer(tmp_buffer); |
||
8083 | schaersvoo | 3030 | reset(); |
7614 | schaersvoo | 3031 | break; |
3032 | case REPLYFORMAT: |
||
3033 | /* |
||
3034 | @ replyformat number |
||
8257 | schaersvoo | 3035 | @ use number=-1 to deactivate the js-functions read_canvas() and read_dragdrop() |
7614 | schaersvoo | 3036 | @ default values should be fine ! |
8074 | schaersvoo | 3037 | @ use command 'precision [0,1,10,100,1000,10000...]' before command 'replyformat' to set the desired number of decimals in the student reply / drawing |
7963 | schaersvoo | 3038 | @ the last value for 'precision int' will be used to calculate the reply coordinates, if needed (read_canvas();) |
8127 | schaersvoo | 3039 | @ 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><li>replyformat 24 = read all inputfield values: even those set 'readonly'</li><li>format 25 = angle1,angle2...angle_n : will return the radius (one or many) of the user drawn circle segment in degrees </li><li>format 26 = rad1,rad2...rad_n : will return the radius (one or many) of the user drawn circle segment in radians </li><li>27 = return (only) userdraw inputfields array: x1:y1:text1,x2:y2:text2...</li></ul> |
7614 | schaersvoo | 3040 | @ note to 'userdraw text,color' : the x / y-values are in pixels ! (this to avoid too lengthy calculations in javascript...) |
3041 | */ |
||
3042 | reply_format = (int) get_real(infile,1); |
||
8074 | schaersvoo | 3043 | reply_precision = precision; |
7614 | schaersvoo | 3044 | break; |
3045 | case LEGENDCOLORS: |
||
3046 | /* |
||
3047 | @ legendcolors color1:color2:color3:...:color_n |
||
7956 | schaersvoo | 3048 | @ will be used to colour a legend: use this command after the legend command ! e.g.<br />legend test1:test2:test3<br />legendcolors blue:red:orange<br /> |
7614 | schaersvoo | 3049 | @ make sure the number of colours match the number of legend items |
8224 | bpr | 3050 | @ command 'legend' in case of 'piechart' and 'barchart' will use these colours per default (no need to specify 'legendcolors' |
7614 | schaersvoo | 3051 | */ |
7956 | schaersvoo | 3052 | if(legend_cnt == -1){canvas_error("use command \"legend\" before command \"legendcolors\" ! ");} |
7614 | schaersvoo | 3053 | temp = get_string(infile,1); |
3054 | if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); } |
||
7956 | schaersvoo | 3055 | fprintf(js_include_file,"var legendcolors%d = [\"%s\"];",legend_cnt,temp); |
7614 | schaersvoo | 3056 | break; |
3057 | case LEGEND: |
||
3058 | /* |
||
3059 | @ legend string1:string2:string3....string_n |
||
3060 | @ will be used to create a legend for a graph |
||
8224 | bpr | 3061 | @ also see command 'piechart' |
7956 | schaersvoo | 3062 | @ will use the same colors per default as used in the graphs : use command 'legendcolors' to override the default |
7614 | schaersvoo | 3063 | */ |
3064 | temp = get_string(infile,1); |
||
3065 | if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); } |
||
7956 | schaersvoo | 3066 | legend_cnt++; /* attention :starts with -1 : it will be used in piechart etc */ |
3067 | fprintf(js_include_file,"var legend%d = [\"%s\"];",legend_cnt,temp); |
||
7614 | schaersvoo | 3068 | break; |
3069 | case XLABEL: |
||
3070 | /* |
||
3071 | @ xlabel some_string |
||
3072 | @ will be used to create a label for the x-axis (label is in quadrant I) |
||
3073 | @ can only be used together with command 'grid'<br />not depending on keywords 'axis' and 'axisnumbering' |
||
8224 | bpr | 3074 | @ font setting: italic Courier, fontsize will be slightly larger (fontsize + 4) |
7614 | schaersvoo | 3075 | */ |
3076 | temp = get_string(infile,1); |
||
7653 | schaersvoo | 3077 | fprintf(js_include_file,"var xaxislabel = \"%s\";",temp); |
7614 | schaersvoo | 3078 | break; |
3079 | case YLABEL: |
||
3080 | /* |
||
3081 | @ ylabel some_string |
||
8224 | bpr | 3082 | @ will be used to create a (vertical) label for the y-axis (label is in quadrant I) |
7614 | schaersvoo | 3083 | @ can only be used together with command 'grid'<br />not depending on keywords 'axis' and 'axisnumbering' |
8224 | bpr | 3084 | @ font setting: italic Courier, fontsize will be slightly larger (fontsize + 4) |
7614 | schaersvoo | 3085 | */ |
3086 | temp = get_string(infile,1); |
||
7653 | schaersvoo | 3087 | fprintf(js_include_file,"var yaxislabel = \"%s\";",temp); |
7614 | schaersvoo | 3088 | break; |
3089 | case LINEGRAPH: /* scheme: var linegraph_0 = [ 'stroke_color','line_width','use_dashed' ,'dashtype0','dashtype1','x1','y1',...,'x_n','y_n'];*/ |
||
3090 | /* |
||
7996 | schaersvoo | 3091 | @ linegraph x1:y1;x2:y2...x_n:y_n |
7614 | schaersvoo | 3092 | @ will plot your data in a graph |
3093 | @ may only to be used together with command 'grid' |
||
3094 | @ can be used together with freestyle x-axis/y-axis texts : see commands 'xaxis' and 'yaxis' |
||
3095 | @ use command 'legend' to provide an optional legend in right-top-corner |
||
3096 | @ also see command 'piechart' |
||
3097 | @ multiple linegraphs may be used in a single plot |
||
7989 | schaersvoo | 3098 | @ NOTE: your arguments are not checked by canvasdraw : use your javascript console in case of trouble... |
7614 | schaersvoo | 3099 | @ <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> |
8224 | bpr | 3100 | */ |
7614 | schaersvoo | 3101 | temp = get_string(infile,1); |
3102 | if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); } |
||
7653 | schaersvoo | 3103 | 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 | 3104 | linegraph_cnt++; |
3105 | reset(); |
||
3106 | break; |
||
7989 | schaersvoo | 3107 | case BARCHART: |
3108 | /* |
||
3109 | @ barchart x_1:y_1:color_1:x_2:y_2:color_2:...x_n:y_n:color_n |
||
3110 | @ will be used to create a legend for bar graph |
||
3111 | @ may only to be used together with command 'grid' |
||
3112 | @ can be used together with freestyle x-axis/y-axis texts : see commands 'xaxis' and 'yaxis' |
||
3113 | @ use command 'legend' to provide an optional legend in right-top-corner |
||
3114 | @ also see command 'piechart' |
||
3115 | @ NOTE: your arguments are not checked by canvasdraw : use your javascript console in case of trouble... |
||
3116 | */ |
||
3117 | temp = get_string(infile,1); |
||
3118 | if( strstr( temp,":" ) != 0 ){ temp = str_replace(temp,":","\",\""); } |
||
3119 | fprintf(js_include_file,"var barchart_%d = [\"%s\"];",barchart_cnt,temp); |
||
3120 | barchart_cnt++; |
||
3121 | reset(); |
||
3122 | break; |
||
7614 | schaersvoo | 3123 | case CLOCK: |
3124 | /* |
||
3125 | @ clock x,y,r(px),H,M,S,type hourglass,interactive [ ,H_color,M_color,S_color,background_color,foreground_color ] |
||
7997 | schaersvoo | 3126 | @ use command 'opacity stroke-opacity,fill-opacity' to adjust foreground (stroke) and background (fill) transparency |
7614 | schaersvoo | 3127 | @ type hourglass:<br />type = 0 : only segments<br />type = 1 : only numbers<br />type = 2 : numbers and segments |
3128 | @ 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 |
||
7862 | schaersvoo | 3129 | @ if you don't want a seconds hand (or minutes...), just make it invisible by using the background color of the hourglass... |
7614 | schaersvoo | 3130 | @ 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> |
3131 | @ canvasdraw will not check validity of colornames...the javascript console is your best friend |
||
3132 | @ no combinations with other reply_types allowed, for now |
||
7783 | schaersvoo | 3133 | @ 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 |
8262 | schaersvoo | 3134 | @ NOTE: if you need multiple clocks on a webpage, use multiple 'clock' commands in a single script !<br />and <i>not multiple canvas scripts</i> in a single page |
7614 | schaersvoo | 3135 | */ |
3136 | if( js_function[DRAW_CLOCK] != 1 ){ js_function[DRAW_CLOCK] = 1;} |
||
3137 | |||
3138 | /* var clock = function(xc,yc,radius,H,M,S,h_color,m_color,s_color,bg_color,fg_color) */ |
||
3139 | for(i=0;i<9;i++){ |
||
3140 | switch(i){ |
||
3141 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* xc */ |
||
3142 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* yc */ |
||
3143 | case 2: int_data[2] = get_real(infile,0);break;/* radius in px */ |
||
3144 | case 3: int_data[3] = get_real(infile,0);break;/* hours */ |
||
3145 | case 4: int_data[4] = get_real(infile,0);break;/* minutes */ |
||
3146 | case 5: int_data[5] = get_real(infile,0);break;/* seconds */ |
||
7783 | schaersvoo | 3147 | 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 | 3148 | case 7: int_data[7] = (int)(get_real(infile,0));/* interactive 0,1,2*/ |
7783 | schaersvoo | 3149 | switch(int_data[7]){ |
3150 | case 0:break; |
||
3151 | case 1:if(clock_cnt == 0){ |
||
3152 | if( reply_format == 0 ){ |
||
7614 | schaersvoo | 3153 | reply_format = 18; /* user sets clock */ |
7783 | schaersvoo | 3154 | /* 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 | 3155 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
3156 | 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"); |
||
3157 | add_to_buffer(tmp_buffer); |
||
7783 | schaersvoo | 3158 | */ |
8130 | schaersvoo | 3159 | fprintf(js_include_file,"set_clock = function(num,type,diff){if(wims_status == \"done\"){return;};var name = eval(\"clocks\"+num);switch(type){case 1:name.H = parseInt(name.H+diff);break;case 2:name.M = parseInt(name.M+diff);break;case 3:name.S = parseInt(name.S+diff);break;default: break;};name = new clock(name.xc,name.yc,name.radius,name.H,name.M,name.S,name.type,name.interaction,name.H_color,name.M_color,name.S_color,name.bg_color,name.fg_color);};\n"); |
7783 | schaersvoo | 3160 | } |
3161 | else |
||
3162 | { |
||
3163 | canvas_error("interactive clock may not be used together with other reply_types..."); |
||
3164 | } |
||
3165 | } |
||
8130 | schaersvoo | 3166 | fprintf(stdout,"<p style=\"text-align:center\"><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,1,1)\" value=\"H+\" /><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,2,1)\" value=\"M+\" /><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,3,1)\" value=\"S+\" /><br /><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,1,-1)\" value=\"H−\" /><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,2,-1)\" value=\"M−\" /><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,3,-1)\" value=\"S−\" /></p>",input_style,clock_cnt,input_style,clock_cnt,input_style,clock_cnt,input_style,clock_cnt,input_style,clock_cnt,input_style,clock_cnt); |
7783 | schaersvoo | 3167 | break; |
3168 | case 2:if( reply_format == 0 ){ |
||
3169 | reply_format = 19; /* "onclick */ |
||
8130 | schaersvoo | 3170 | 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 = new clock(name.xc,name.yc,name.radius,name.H,name.M,name.S,name.type,name.interaction,name.H_color,name.M_color,name.S_color,\"lightblue\",name.fg_color);\n};\n}else{clock_ctx.clearRect(name.xc-name.radius,name.yc-name.radius,name.xc+name.radius,name.yc+name.radius);\nname = new clock(name.xc,name.yc,name.radius,name.H,name.M,name.S,name.type,name.interaction,name.H_color,name.M_color,name.S_color,name.bg_color,name.fg_color);\n};\np++;\n}catch(e){t=false;\n};\n};\n};\n};\n\n<!-- end onclick handler for clocks -->\n "); |
7783 | schaersvoo | 3171 | } |
3172 | else |
||
3173 | { |
||
3174 | if( reply_format != 19){ |
||
7614 | schaersvoo | 3175 | canvas_error("clickable clock(s) may not be used together with other reply_types..."); |
3176 | } |
||
7783 | schaersvoo | 3177 | } |
3178 | break; |
||
3179 | default: canvas_error("interactive must be set 0,1 or 2");break; |
||
3180 | } |
||
3181 | break; |
||
8224 | bpr | 3182 | case 8: |
8130 | schaersvoo | 3183 | if(clock_cnt == 0 ){ /* set opacity's just once .... it should be a argument to clock() , for now it's OK */ |
3184 | fprintf(js_include_file,"var clock_bg_opacity = %.2f;var clock_fg_opacity = %.2f;",fill_opacity,stroke_opacity); |
||
3185 | } |
||
7614 | schaersvoo | 3186 | temp = get_string(infile,1); |
3187 | if( strstr( temp,",") != 0 ){ temp = str_replace(temp,",","\",\""); } |
||
3188 | if( strlen(temp) < 1 ){temp = ",\"\",\"\",\"\",\"\",\"\"";} |
||
8130 | schaersvoo | 3189 | string_length = snprintf(NULL,0,"var 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); |
7614 | schaersvoo | 3190 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
8130 | schaersvoo | 3191 | snprintf(tmp_buffer,string_length,"var 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); |
7614 | schaersvoo | 3192 | add_to_buffer(tmp_buffer); |
3193 | clock_cnt++; |
||
3194 | break; |
||
3195 | default:break; |
||
3196 | } |
||
3197 | } |
||
3198 | break; |
||
3199 | case PIECHART: |
||
3200 | /* |
||
3201 | @ piechart xc,yc,radius,'data+colorlist' |
||
3202 | @ (xc : yc) center of circle diagram in xrange/yrange |
||
3203 | @ radius in pixels |
||
3204 | @ 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 |
||
3205 | @ example data+colorlist : 132:red:23565:green:323:black:234324:orange:23434:yellow:2543:white |
||
3206 | @ the number of colors must match the number of data. |
||
3207 | @ use command "opacity 0-255,0-255" to adjust fill_opacity of colours |
||
8224 | bpr | 3208 | @ 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...<br />use command 'fontfamily' to set the font of the legend. |
7614 | schaersvoo | 3209 | */ |
8224 | bpr | 3210 | if( js_function[DRAW_PIECHART] != 1 ){ js_function[DRAW_PIECHART] = 1;} |
7614 | schaersvoo | 3211 | for(i=0;i<5;i++){ |
3212 | switch(i){ |
||
3213 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */ |
||
3214 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y */ |
||
3215 | case 2: int_data[2] = (int)(get_real(infile,1));break;/* radius*/ |
||
3216 | case 3: temp = get_string(infile,1); |
||
3217 | if( strstr( temp, ":" ) != 0 ){ temp = str_replace(temp,":","\",\"");} |
||
7956 | schaersvoo | 3218 | string_length = snprintf(NULL,0,"draw_piechart(%d,%d,%d,%d,[\"%s\"],%.2f,%d,\"%s\");\n",PIECHART,int_data[0],int_data[1],int_data[2],temp,fill_opacity,legend_cnt,font_family); |
7614 | schaersvoo | 3219 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
7956 | schaersvoo | 3220 | snprintf(tmp_buffer,string_length,"draw_piechart(%d,%d,%d,%d,[\"%s\"],%.2f,%d,\"%s\");\n",PIECHART,int_data[0],int_data[1],int_data[2],temp,fill_opacity,legend_cnt,font_family); |
7614 | schaersvoo | 3221 | add_to_buffer(tmp_buffer); |
3222 | break; |
||
3223 | default:break; |
||
3224 | } |
||
3225 | } |
||
3226 | reset(); |
||
3227 | break; |
||
3228 | case STATUS: |
||
7877 | schaersvoo | 3229 | /* |
3230 | @status |
||
3231 | @keyword |
||
3232 | @alernative keyword: nostatus |
||
3233 | @used to override the effects of "status=done" in wims (answer.phtml) |
||
3234 | @affects inputfields / textarea's in canvasimage and all userdraw based commands |
||
3235 | @e.g.: if keyword 'status' is set, the pupil will be able to modify the canvas when the 'wims status variable' is set to 'done' |
||
3236 | */ |
||
8224 | bpr | 3237 | |
7877 | schaersvoo | 3238 | fprintf(js_include_file,"\nwims_status=\"waiting\";\n"); |
7614 | schaersvoo | 3239 | break; |
7735 | schaersvoo | 3240 | case XLOGBASE: |
7729 | schaersvoo | 3241 | /* |
7735 | schaersvoo | 3242 | @ xlogbase number |
3243 | @ sets the logbase number for the x-axis |
||
7729 | schaersvoo | 3244 | @ default value 10 |
7735 | schaersvoo | 3245 | @ use together with commands xlogscale / xylogscale |
7729 | schaersvoo | 3246 | */ |
7735 | schaersvoo | 3247 | fprintf(js_include_file,"xlogbase=%d;",(int)(get_real(infile,1))); |
7729 | schaersvoo | 3248 | break; |
7735 | schaersvoo | 3249 | case YLOGBASE: |
3250 | /* |
||
3251 | @ ylogbase number |
||
3252 | @ sets the logbase number for the y-axis |
||
3253 | @ default value 10 |
||
3254 | @ use together with commands ylogscale / xylogscale |
||
3255 | */ |
||
3256 | fprintf(js_include_file,"ylogbase=%d;",(int)(get_real(infile,1))); |
||
3257 | break; |
||
7614 | schaersvoo | 3258 | case XLOGSCALE: |
3259 | /* |
||
7735 | schaersvoo | 3260 | @ xlogscale ymajor,yminor,majorcolor,minorcolor |
3261 | @ the x/y-range are set using commands 'xrange xmin,xmax' and 'yrange ymin,ymax' |
||
3262 | @ ymajor is the major step on the y-axis; yminor is the divisor for the y-step |
||
3263 | @ the linewidth is set using command 'linewidth int' |
||
3264 | @ the opacity of major / minor grid lines is set by command 'opacity [0-255],[0-255]' |
||
3265 | @ default logbase number = 10 ... when needed , set the logbase number with command 'xlogbase number' |
||
8224 | bpr | 3266 | @ 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 | 3267 | @ note: the complete canvas will be used for the 'log paper' |
3268 | @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values |
||
3269 | @ note: command 'mouse color,fontsize' will show the real values in the logpaper.<br />\ |
||
8224 | bpr | 3270 | @ note: when using something like 'xrange 0.0001,0.01'...combined with commands 'mouse color,fontsize' and/or 'userdraw type,color'...<br /> make sure the precision is set accordingly (eg command 'precision 10000') |
7735 | schaersvoo | 3271 | @ note: in case of userdraw , the use of keyword 'userinput_xy' may be handy ! |
3272 | @ attention: keyword 'snaptogrid' may not lead to the desired result... |
||
7614 | schaersvoo | 3273 | */ |
7735 | schaersvoo | 3274 | if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");} |
3275 | if( js_function[DRAW_XLOGSCALE] != 1 ){ js_function[DRAW_XLOGSCALE] = 1;} |
||
3276 | for(i=0;i<4;i++){ |
||
3277 | switch(i){ |
||
3278 | case 0: double_data[0] = get_real(infile,0);break; /* xmajor */ |
||
3279 | case 1: int_data[0] = (int) (get_real(infile,0));break; /* xminor */ |
||
3280 | case 2: stroke_color = get_color(infile,0); break; |
||
8224 | bpr | 3281 | case 3: fill_color = get_color(infile,1); |
7779 | schaersvoo | 3282 | 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 | 3283 | tmp_buffer = my_newmem(string_length+1); |
7779 | schaersvoo | 3284 | 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 | 3285 | fprintf(js_include_file,"use_xlogscale=1;snap_y = %f;snap_x = xlogbase;",double_data[0]/int_data[0]); |
3286 | add_to_buffer(tmp_buffer); |
||
3287 | break; |
||
3288 | default:break; |
||
3289 | } |
||
3290 | } |
||
7614 | schaersvoo | 3291 | break; |
3292 | case YLOGSCALE: |
||
7729 | schaersvoo | 3293 | /* |
3294 | @ ylogscale xmajor,xminor,majorcolor,minorcolor |
||
3295 | @ the x/y-range are set using commands 'xrange xmin,xmax' and 'yrange ymin,ymax' |
||
3296 | @ xmajor is the major step on the x-axis; xminor is the divisor for the x-step |
||
3297 | @ the linewidth is set using command 'linewidth int' |
||
3298 | @ the opacity of major / minor grid lines is set by command 'opacity [0-255],[0-255]' |
||
7735 | schaersvoo | 3299 | @ default logbase number = 10 ... when needed , set the logbase number with command 'ylogbase number' |
8224 | bpr | 3300 | @ 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 | 3301 | @ note: the complete canvas will be used for the 'log paper' |
3302 | @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values |
||
3303 | @ note: command 'mouse color,fontsize' will show the real values in the logpaper.<br />\ |
||
8224 | bpr | 3304 | @ 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 | 3305 | @ note: in case of userdraw , the use of keyword 'userinput_xy' may be handy ! |
3306 | @ attention: keyword 'snaptogrid' may not lead to the desired result... |
||
7729 | schaersvoo | 3307 | */ |
3308 | if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");} |
||
3309 | if( js_function[DRAW_YLOGSCALE] != 1 ){ js_function[DRAW_YLOGSCALE] = 1;} |
||
3310 | for(i=0;i<4;i++){ |
||
3311 | switch(i){ |
||
3312 | case 0: double_data[0] = get_real(infile,0);break; /* xmajor */ |
||
3313 | case 1: int_data[0] = (int) (get_real(infile,0));break; /* xminor */ |
||
3314 | case 2: stroke_color = get_color(infile,0); break; |
||
8224 | bpr | 3315 | case 3: fill_color = get_color(infile,1); |
7779 | schaersvoo | 3316 | 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 | 3317 | tmp_buffer = my_newmem(string_length+1); |
7779 | schaersvoo | 3318 | 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 | 3319 | fprintf(js_include_file,"use_ylogscale=1;snap_x = %f;snap_y = ylogbase;",double_data[0]/int_data[0]); |
7729 | schaersvoo | 3320 | add_to_buffer(tmp_buffer); |
3321 | break; |
||
3322 | default:break; |
||
3323 | } |
||
3324 | } |
||
7614 | schaersvoo | 3325 | break; |
3326 | case XYLOGSCALE: |
||
7735 | schaersvoo | 3327 | /* |
3328 | @ xylogscale majorcolor,minorcolor |
||
3329 | @ the x/y-range are set using commands 'xrange xmin,xmax' and 'yrange ymin,ymax' |
||
3330 | @ the linewidth is set using command 'linewidth int' |
||
3331 | @ the opacity of major / minor grid lines is set by command 'opacity [0-255],[0-255]' |
||
3332 | @ default logbase number = 10 ... when needed , set the logbase number with command 'xlogbase number' and/or 'ylogbase number' |
||
8224 | bpr | 3333 | @ 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 | 3334 | @ note: the complete canvas will be used for the 'log paper' |
3335 | @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values |
||
3336 | @ note: command 'mouse color,fontsize' will show the real values in the logpaper.<br />\ |
||
8224 | bpr | 3337 | @ 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 | 3338 | @ note: in case of userdraw , the use of keyword 'userinput_xy' may be handy ! |
3339 | @ attention: keyword 'snaptogrid' may not lead to the desired result... |
||
3340 | */ |
||
3341 | if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");} |
||
3342 | if( js_function[DRAW_XYLOGSCALE] != 1 ){ js_function[DRAW_XYLOGSCALE] = 1;} |
||
3343 | for(i=0;i<2;i++){ |
||
3344 | switch(i){ |
||
3345 | case 0: stroke_color = get_color(infile,0); break; |
||
8224 | bpr | 3346 | case 1: fill_color = get_color(infile,1); |
7779 | schaersvoo | 3347 | 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 | 3348 | tmp_buffer = my_newmem(string_length+1); |
7779 | schaersvoo | 3349 | 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 | 3350 | fprintf(js_include_file,"use_xlogscale=1;use_ylogscale=1;snap_x = xlogbase;snap_y = ylogbase;"); |
3351 | add_to_buffer(tmp_buffer); |
||
3352 | break; |
||
3353 | default:break; |
||
3354 | } |
||
3355 | } |
||
3356 | break; |
||
7614 | schaersvoo | 3357 | default:sync_input(infile); |
3358 | break; |
||
3359 | } |
||
8224 | bpr | 3360 | } |
7614 | schaersvoo | 3361 | /* we are done parsing script file */ |
7983 | schaersvoo | 3362 | /* check if xrange / yrange was set explicit ... or use xmin=0 xmax=xsize ymin=0 ymax=ysize : Quadrant I */ |
3363 | if( found_size_command == 1 ){ |
||
3364 | fprintf(js_include_file,"var xmin = 0;var xmax = %d;var ymin = 0;var ymax = %d",xsize,ysize); |
||
3365 | } |
||
3366 | else |
||
3367 | { |
||
3368 | if( found_size_command != 3 ){ |
||
8222 | schaersvoo | 3369 | canvas_error("Please specify both xrange and yrange ..."); |
7983 | schaersvoo | 3370 | } |
3371 | } |
||
8257 | schaersvoo | 3372 | |
8222 | schaersvoo | 3373 | /* if needed, add generic draw functions (grid / xml etc) to buffer : these are no draggable/clickable shapes / objects ! */ |
7614 | schaersvoo | 3374 | add_javascript_functions(js_function,canvas_root_id); |
3375 | /* add read_canvas() etc functions if needed */ |
||
8257 | schaersvoo | 3376 | if( reply_format > 0 ){ add_read_canvas(canvas_root_id,reply_format,reply_precision);} |
7797 | schaersvoo | 3377 | if( use_pan_and_zoom == TRUE ){ |
3378 | /* in case of zooming ... */ |
||
7729 | schaersvoo | 3379 | fprintf(js_include_file,"\n<!-- some extra global stuff : need to rethink panning and zooming !!! -->\n\ |
7797 | schaersvoo | 3380 | precision = %d;var xmin_start=xmin;var xmax_start=xmax;\ |
7729 | schaersvoo | 3381 | var ymin_start=ymin;var ymax_start=xmax;\ |
3382 | var zoom_x_increment=0;var zoom_y_increment=0;\ |
||
3383 | var pan_x_increment=0;var pan_y_increment=0;\ |
||
3384 | if(use_ylogscale == 0 ){\ |
||
7956 | schaersvoo | 3385 | zoom_x_increment = (xmax - xmin)/20;zoom_y_increment = (ymax - ymin)/20;pan_x_increment = (xmax - xmin)/20;pan_y_increment = (ymax - ymin)/20;\ |
7729 | schaersvoo | 3386 | }else{\ |
3387 | zoom_x_increment = (xmax - xmin)/20;\ |
||
3388 | pan_x_increment = (xmax - xmin)/20;\ |
||
3389 | };\ |
||
7653 | schaersvoo | 3390 | function start_canvas%d(type){\ |
3391 | switch(type){\ |
||
7729 | schaersvoo | 3392 | case 0:xmin = xmin + zoom_x_increment;ymin = ymin + zoom_y_increment;xmax = xmax - zoom_x_increment;ymax = ymax - zoom_y_increment;break;\ |
3393 | 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 | 3394 | case 2:xmin = xmin - pan_x_increment;ymin = ymin ;xmax = xmax - pan_x_increment;ymax = ymax;break;\ |
3395 | case 3:xmin = xmin + pan_x_increment;ymin = ymin ;xmax = xmax + pan_x_increment;ymax = ymax;break;\ |
||
3396 | case 4:xmin = xmin;ymin = ymin - pan_y_increment ;xmax = xmax;ymax = ymax - pan_y_increment;break;\ |
||
3397 | case 5:xmin = xmin;ymin = ymin + pan_y_increment ;xmax = xmax;ymax = ymax + pan_y_increment;break;\ |
||
3398 | case 6:location.reload();break;\ |
||
3399 | default:break;\ |
||
3400 | };\ |
||
3401 | if(xmax<=xmin){xmin=xmin_start;xmax=xmax_start;};\ |
||
3402 | if(ymax<=ymin){ymin=ymin_start;ymax=ymax_start;};\ |
||
3403 | try{dragstuff.Zoom(xmin,xmax,ymin,ymax);}catch(e){}\ |
||
3404 | %s\ |
||
3405 | };\ |
||
7797 | schaersvoo | 3406 | start_canvas%d(333);\ |
7614 | schaersvoo | 3407 | };\n\ |
3408 | <!-- end wims_canvas_function -->\n\ |
||
7797 | schaersvoo | 3409 | wims_canvas_function%d();\n",precision,canvas_root_id,buffer,canvas_root_id,canvas_root_id); |
3410 | } |
||
3411 | else |
||
3412 | { |
||
3413 | /* no zoom, just add buffer */ |
||
3414 | fprintf(js_include_file,"\n<!-- add buffer -->\n\ |
||
3415 | %s\ |
||
3416 | };\n\ |
||
3417 | <!-- end wims_canvas_function -->\n\ |
||
3418 | wims_canvas_function%d();\n",buffer,canvas_root_id); |
||
3419 | } |
||
7614 | schaersvoo | 3420 | /* done writing the javascript include file */ |
3421 | fclose(js_include_file); |
||
3422 | |||
3423 | } |
||
3424 | |||
3425 | /* if using a tooltip, this should always be printed to the *.phtml file, so stdout */ |
||
3426 | if(use_tooltip == TRUE){ |
||
3427 | add_js_tooltip(canvas_root_id,tooltip_text,bgcolor,xsize,ysize); |
||
3428 | } |
||
3429 | exit(EXIT_SUCCESS); |
||
3430 | } |
||
3431 | /* end main() */ |
||
3432 | |||
3433 | /****************************************************************************** |
||
3434 | ** |
||
3435 | ** sync_input |
||
3436 | ** |
||
3437 | ** synchronises input line - reads to end of line, leaving file pointer |
||
3438 | ** at first character of next line. |
||
3439 | ** |
||
3440 | ** Used by: |
||
3441 | ** main program - error handling. |
||
3442 | ** |
||
3443 | ******************************************************************************/ |
||
3444 | void sync_input(FILE *infile) |
||
3445 | { |
||
3446 | int c = 0; |
||
3447 | |||
7658 | schaersvoo | 3448 | if( c == '\n' || c == ';' ) return; |
3449 | while( ( (c=getc(infile)) != EOF ) && (c != '\n') && (c != '\r') && (c != ';')) ; |
||
7614 | schaersvoo | 3450 | if( c == EOF ) finished = 1; |
7658 | schaersvoo | 3451 | if( c == '\n' || c == '\r' || c == ';') line_number++; |
7614 | schaersvoo | 3452 | return; |
3453 | } |
||
3454 | |||
3455 | /******************************************************************************/ |
||
3456 | |||
3457 | char *str_replace(const char *str, const char *old, const char *new){ |
||
3458 | /* http://creativeandcritical.net/str-replace-c/ */ |
||
3459 | if(strlen(str) > MAX_BUFFER){canvas_error("string argument too big");} |
||
3460 | char *ret, *r; |
||
3461 | const char *p, *q; |
||
3462 | size_t oldlen = strlen(old); |
||
3463 | size_t count = 0; |
||
3464 | size_t retlen = 0; |
||
3465 | size_t newlen = strlen(new); |
||
3466 | if (oldlen != newlen){ |
||
3467 | for (count = 0, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen){ |
||
3468 | count++; |
||
3469 | retlen = p - str + strlen(p) + count * (newlen - oldlen); |
||
3470 | } |
||
8224 | bpr | 3471 | } |
7614 | schaersvoo | 3472 | else |
3473 | { |
||
3474 | retlen = strlen(str); |
||
3475 | } |
||
8224 | bpr | 3476 | |
7614 | schaersvoo | 3477 | if ((ret = malloc(retlen + 1)) == NULL){ |
3478 | ret = NULL; |
||
3479 | canvas_error("string argument is NULL"); |
||
3480 | } |
||
3481 | else |
||
3482 | { |
||
3483 | for (r = ret, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen) { |
||
3484 | size_t l = q - p; |
||
3485 | memcpy(r, p, l); |
||
3486 | r += l; |
||
3487 | memcpy(r, new, newlen); |
||
3488 | r += newlen; |
||
3489 | } |
||
3490 | strcpy(r, p); |
||
3491 | } |
||
3492 | return ret; |
||
3493 | } |
||
3494 | |||
3495 | /******************************************************************************/ |
||
7848 | bpr | 3496 | |
7614 | schaersvoo | 3497 | char *get_color(FILE *infile , int last){ |
3498 | int c,i = 0,is_hex = 0; |
||
3499 | char temp[MAX_COLOR_STRING], *string; |
||
7748 | schaersvoo | 3500 | while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != ',' ) && ( c != ';' ) ){ |
7614 | schaersvoo | 3501 | if( i > MAX_COLOR_STRING ){ canvas_error("colour string is too big ... ? ");} |
3502 | if( c == '#' ){ |
||
3503 | is_hex = 1; |
||
3504 | } |
||
3505 | if( c != ' '){ |
||
3506 | temp[i]=tolower(c); |
||
3507 | i++; |
||
3508 | } |
||
3509 | } |
||
8224 | bpr | 3510 | if( ( c == '\n' || c == EOF || c == ';' ) && last == 0){canvas_error("expecting more arguments in command");} |
7748 | schaersvoo | 3511 | if( c == '\n' || c == ';' ){ done = TRUE; line_number++; } |
7614 | schaersvoo | 3512 | if( c == EOF ){finished = 1;} |
3513 | if( finished == 1 && last != 1 ){ canvas_error("expected more arguments");} |
||
3514 | temp[i]='\0'; |
||
3515 | if( strlen(temp) == 0 ){ canvas_error("expected a colorname or hexnumber, but found nothing !!");} |
||
3516 | if( is_hex == 1 ){ |
||
3517 | char red[3], green[3], blue[3]; |
||
3518 | red[0] = toupper(temp[1]); red[1] = toupper(temp[2]); red[2] = '\0'; |
||
3519 | green[0] = toupper(temp[3]); green[1] = toupper(temp[4]); green[2] = '\0'; |
||
3520 | blue[0] = toupper(temp[5]); blue[1] = toupper(temp[6]); blue[2] = '\0'; |
||
3521 | int r = (int) strtol(red, NULL, 16); |
||
3522 | int g = (int) strtol(green, NULL, 16); |
||
3523 | int b = (int) strtol(blue, NULL, 16); |
||
3524 | string = (char *)my_newmem(12); |
||
3525 | snprintf(string,11,"%d,%d,%d",r,g,b); |
||
3526 | return string; |
||
3527 | } |
||
3528 | else |
||
3529 | { |
||
3530 | string = (char *)my_newmem(sizeof(temp)); |
||
3531 | snprintf(string,sizeof(temp),"%s",temp); |
||
3532 | for( i = 0; i <= NUMBER_OF_COLORNAMES ; i++ ){ |
||
3533 | if( strcmp( colors[i].name , string ) == 0 ){ |
||
3534 | return colors[i].rgb; |
||
3535 | } |
||
3536 | } |
||
3537 | } |
||
3538 | /* not found...return error */ |
||
3539 | free(string);string = NULL; |
||
3540 | canvas_error("I was expecting a color name or hexnumber...but found nothing."); |
||
3541 | return NULL; |
||
3542 | } |
||
3543 | |||
3544 | char *get_string(FILE *infile,int last){ /* last = 0 : more arguments ; last=1 final argument */ |
||
3545 | int c,i=0; |
||
3546 | char temp[MAX_BUFFER], *string; |
||
7748 | schaersvoo | 3547 | while(( (c=getc(infile)) != EOF ) && ( c != '\n') ){ |
7614 | schaersvoo | 3548 | temp[i]=c; |
3549 | i++; |
||
3550 | if(i > MAX_BUFFER){ canvas_error("string size too big...repeat command to fit string");break;} |
||
3551 | } |
||
8224 | bpr | 3552 | if( ( c == '\n' || c == EOF ) && last == 0){canvas_error("expecting more arguments in command");} |
7748 | schaersvoo | 3553 | if( c == '\n') { done = TRUE; line_number++; } |
7614 | schaersvoo | 3554 | if( c == EOF ) { |
3555 | finished = 1; |
||
3556 | if( last != 1 ){ canvas_error("expected more arguments");} |
||
3557 | } |
||
3558 | temp[i]='\0'; |
||
3559 | if( strlen(temp) == 0 ){ canvas_error("expected a word or string, but found nothing !!");} |
||
3560 | string=(char *)my_newmem(strlen(temp)); |
||
3561 | snprintf(string,sizeof(temp),"%s",temp); |
||
3562 | return string; |
||
3563 | } |
||
3564 | |||
3565 | char *get_string_argument(FILE *infile,int last){ /* last = 0 : more arguments ; last=1 final argument */ |
||
3566 | int c,i=0; |
||
3567 | char temp[MAX_BUFFER], *string; |
||
7748 | schaersvoo | 3568 | while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != ',')){ |
7614 | schaersvoo | 3569 | temp[i]=c; |
3570 | i++; |
||
3571 | if(i > MAX_BUFFER){ canvas_error("string size too big...will cut it off");break;} |
||
3572 | } |
||
8224 | bpr | 3573 | if( ( c == '\n' || c == EOF) && last == 0){canvas_error("expecting more arguments in command");} |
7748 | schaersvoo | 3574 | if( c == '\n') { line_number++; } |
7614 | schaersvoo | 3575 | if( c == EOF ) {finished = 1;} |
3576 | if( finished == 1 && last != 1 ){ canvas_error("expected more arguments");} |
||
3577 | temp[i]='\0'; |
||
3578 | if( strlen(temp) == 0 ){ canvas_error("expected a word or string (without comma) , but found nothing !!");} |
||
3579 | string=(char *)my_newmem(sizeof(temp)); |
||
3580 | snprintf(string,sizeof(temp),"%s",temp); |
||
3581 | done = TRUE; |
||
3582 | return string; |
||
3583 | } |
||
3584 | |||
3585 | double get_real(FILE *infile, int last){ /* accept anything that looks like an number ? last = 0 : more arguments ; last=1 final argument */ |
||
3586 | int c,i=0,found_calc = 0; |
||
3587 | double y; |
||
3588 | char tmp[MAX_INT]; |
||
7658 | schaersvoo | 3589 | while(( (c=getc(infile)) != EOF ) && ( c != ',') && (c != '\n') && ( c != ';')){ |
7614 | schaersvoo | 3590 | if( c != ' ' ){ |
8224 | bpr | 3591 | /* |
3592 | libmatheval will segfault when for example: "xrange -10,+10" or "xrange -10,10+" is used |
||
7614 | schaersvoo | 3593 | We will check after assert() if it's a NULL pointer...and exit program via : |
3594 | canvas_error("I'm having trouble parsing your \"expression\" "); |
||
3595 | */ |
||
8224 | bpr | 3596 | if( i == 0 && c == '+' ){ |
7614 | schaersvoo | 3597 | continue; |
8224 | bpr | 3598 | } |
7614 | schaersvoo | 3599 | else |
3600 | { |
||
3601 | if(canvas_iscalculation(c) != 0){ |
||
3602 | found_calc = 1; |
||
3603 | c = tolower(c); |
||
3604 | } |
||
3605 | tmp[i] = c; |
||
3606 | i++; |
||
3607 | } |
||
3608 | } |
||
3609 | if( i > MAX_INT - 1){canvas_error("number too large");} |
||
3610 | } |
||
8224 | bpr | 3611 | if( ( c == '\n' || c == EOF || c == ';' ) && last == 0){canvas_error("expecting more arguments in command");} |
7658 | schaersvoo | 3612 | if( c == '\n' || c == ';' ){ done = TRUE; line_number++; } |
7614 | schaersvoo | 3613 | if( c == EOF ){done = TRUE ; finished = 1;} |
3614 | tmp[i]='\0'; |
||
3615 | if( strlen(tmp) == 0 ){canvas_error("expected a number , but found nothing !!");} |
||
3616 | if( found_calc == 1 ){ /* use libmatheval to calculate 2*pi/3 */ |
||
7848 | bpr | 3617 | void *f = eval_create(tmp); |
7614 | schaersvoo | 3618 | assert(f);if( f == NULL ){canvas_error("I'm having trouble parsing your \"expression\" ") ;} |
7848 | bpr | 3619 | y = eval_x(f, 1); |
7614 | schaersvoo | 3620 | /* if function is bogus; y = 1 : so no core dumps */ |
7848 | bpr | 3621 | eval_destroy(f); |
7614 | schaersvoo | 3622 | } |
3623 | else |
||
3624 | { |
||
3625 | y = atof(tmp); |
||
3626 | } |
||
3627 | return y; |
||
3628 | } |
||
3629 | void canvas_error(char *msg){ |
||
7748 | schaersvoo | 3630 | fprintf(stdout,"\n</script><hr /><span style=\"color:red\">FATAL syntax error:line %d : %s</span><hr />",line_number-1,msg); |
7614 | schaersvoo | 3631 | finished = 1; |
3632 | exit(EXIT_SUCCESS); |
||
3633 | } |
||
3634 | |||
3635 | |||
3636 | /* convert x/y coordinates to pixel */ |
||
3637 | int x2px(double x){ |
||
3638 | return x*xsize/(xmax - xmin) - xsize*xmin/(xmax - xmin); |
||
3639 | } |
||
3640 | |||
3641 | int y2px(double y){ |
||
3642 | return -1*y*ysize/(ymax - ymin) + ymax*ysize/(ymax - ymin); |
||
3643 | } |
||
3644 | |||
3645 | double px2x(int x){ |
||
3646 | return (x*(xmax - xmin)/xsize + xmin); |
||
3647 | } |
||
3648 | double px2y(int y){ |
||
3649 | return (y*(ymax - ymin)/ysize + ymin); |
||
3650 | } |
||
3651 | |||
3652 | void add_to_buffer(char *tmp){ |
||
3653 | if( tmp == NULL || tmp == 0 ){ canvas_error("nothing to add_to_buffer()...");} |
||
3654 | /* do we have enough space left in buffer[MAX_BUFFER] ? */ |
||
3655 | int space_left = (int) (sizeof(buffer) - strlen(buffer)); |
||
3656 | if( space_left > strlen(tmp)){ |
||
3657 | strncat(buffer,tmp,space_left - 1);/* add safely "tmp" to the string buffer */ |
||
3658 | } |
||
3659 | else |
||
3660 | { |
||
3661 | canvas_error("buffer is too big\n"); |
||
3662 | } |
||
3663 | tmp = NULL;free(tmp); |
||
3664 | return; |
||
3665 | } |
||
3666 | |||
3667 | void reset(){ |
||
3668 | if(use_filled == TRUE){use_filled = FALSE;} |
||
3669 | if(use_dashed == TRUE){use_dashed = FALSE;} |
||
3670 | if(use_rotate == TRUE){use_rotate = FALSE;} |
||
8101 | schaersvoo | 3671 | onclick = 0; |
7614 | schaersvoo | 3672 | } |
3673 | |||
3674 | |||
3675 | |||
3676 | /* What reply format in read_canvas(); |
||
3677 | |||
3678 | note:if userdraw is combined with inputfields...every "userdraw" based answer will append "\n" and inputfield.value() |
||
3679 | 1 = x1,x2,x3,x4....x_n |
||
3680 | y1,y2,y3,y4....y_n |
||
3681 | |||
3682 | x/y in pixels |
||
3683 | |||
3684 | 2 = x1,x2,x3,x4....x_n |
||
3685 | y1,y2,y3,y4....y_n |
||
3686 | x/y in xrange / yrange coordinate system |
||
3687 | |||
3688 | 3 = x1,x2,x3,x4....x_n |
||
3689 | y1,y2,y3,y4....y_n |
||
3690 | r1,r2,r3,r4....r_n |
||
3691 | |||
8224 | bpr | 3692 | x/y in pixels |
7614 | schaersvoo | 3693 | r in pixels |
3694 | |||
3695 | 4 = x1,x2,x3,x4....x_n |
||
3696 | y1,y2,y3,y4....y_n |
||
3697 | r1,r2,r3,r4....r_n |
||
3698 | |||
3699 | x/y in xrange / yrange coordinate system |
||
3700 | r in pixels |
||
3701 | |||
3702 | 5 = Ax1,Ax2,Ax3,Ax4....Ax_n |
||
3703 | Ay1,Ay2,Ay3,Ay4....Ay_n |
||
3704 | Bx1,Bx2,Bx3,Bx4....Bx_n |
||
3705 | By1,By2,By3,By4....By_n |
||
3706 | Cx1,Cx2,Cx3,Cx4....Cx_n |
||
3707 | Cy1,Cy2,Cy3,Cy4....Cy_n |
||
3708 | .... |
||
3709 | Zx1,Zx2,Zx3,Zx4....Zx_n |
||
3710 | Zy1,Zy2,Zy3,Zy4....Zy_n |
||
8224 | bpr | 3711 | |
7614 | schaersvoo | 3712 | x/y in pixels |
3713 | |||
3714 | 6 = Ax1,Ax2,Ax3,Ax4....Ax_n |
||
3715 | Ay1,Ay2,Ay3,Ay4....Ay_n |
||
3716 | Bx1,Bx2,Bx3,Bx4....Bx_n |
||
3717 | By1,By2,By3,By4....By_n |
||
3718 | Cx1,Cx2,Cx3,Cx4....Cx_n |
||
3719 | Cy1,Cy2,Cy3,Cy4....Cy_n |
||
3720 | .... |
||
3721 | Zx1,Zx2,Zx3,Zx4....Zx_n |
||
3722 | Zy1,Zy2,Zy3,Zy4....Zy_n |
||
3723 | |||
3724 | x/y in xrange / yrange coordinate system |
||
8224 | bpr | 3725 | |
7614 | schaersvoo | 3726 | 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n |
8224 | bpr | 3727 | |
7614 | schaersvoo | 3728 | x/y in pixels |
3729 | |||
3730 | 8 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n |
||
8224 | bpr | 3731 | |
7614 | schaersvoo | 3732 | x/y in xrange / yrange coordinate system |
3733 | |||
8224 | bpr | 3734 | 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n |
7614 | schaersvoo | 3735 | |
3736 | x/y in pixels |
||
3737 | |||
8224 | bpr | 3738 | 10 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n |
7614 | schaersvoo | 3739 | |
3740 | x/y in xrange / yrange coordinate system |
||
3741 | |||
3742 | 11 = Ax1,Ay1,Ax2,Ay2 |
||
3743 | Bx1,By1,Bx2,By2 |
||
3744 | Cx1,Cy1,Cx2,Cy2 |
||
3745 | Dx1,Dy1,Dx2,Dy2 |
||
3746 | ...... |
||
3747 | Zx1,Zy1,Zx2,Zy2 |
||
8224 | bpr | 3748 | |
7614 | schaersvoo | 3749 | x/y in xrange / yrange coordinate system |
3750 | |||
3751 | 12 = Ax1,Ay1,Ax2,Ay2 |
||
3752 | Bx1,By1,Bx2,By2 |
||
3753 | Cx1,Cy1,Cx2,Cy2 |
||
3754 | Dx1,Dy1,Dx2,Dy2 |
||
3755 | ...... |
||
3756 | Zx1,Zy1,Zx2,Zy2 |
||
8224 | bpr | 3757 | |
7614 | schaersvoo | 3758 | x/y in pixels |
3759 | |||
3760 | 13 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2,Cx1:Cy1:Cx2:Cy2,Dx1:Dy1:Dx2:Dy2, ... ,Zx1:Zy1:Zx2:Zy2 |
||
3761 | |||
3762 | x/y in xrange / yrange coordinate system |
||
3763 | 14 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2....Zx1:Zy1:Zx2:Zy2 |
||
3764 | x/y in pixels |
||
3765 | 15 = reply from inputfields,textareas |
||
3766 | reply1,reply2,reply3,...,reply_n |
||
7984 | schaersvoo | 3767 | only fields set write (a.g. will not read 'readonly' inputfield values' |
7614 | schaersvoo | 3768 | |
3769 | 16 = read mathml inputfields only |
||
3770 | |||
3771 | 17 = read userdraw text only (x1:y1:text1,x2:y2:text2...x_n:y_n:text_n |
||
3772 | when ready : calculate size_t of string via snprintf(NULL,0,"blah blah..."); |
||
3773 | |||
3774 | 18 = read clock(s) : H1:M1:S1,H2:M2:S2,...H_n:M_n:S_n |
||
3775 | 19 = return clicked object number (analogue to shape-library onclick) |
||
3776 | 20 = return x/y-data in x-range/y-range of all 'draggable' images |
||
3777 | 21 = return verbatim coordinates (x1:y1) (x2:y2)...(x_n:y_n) |
||
3778 | 22 = array : x1,y1,x2,y2,x3,y3,x4,y4...x_n,y_n |
||
3779 | x/y in xrange / yrange coordinate system |
||
8224 | bpr | 3780 | 23 = answertype for a polyline : remove multiple occurences due to reclick on a point to create next polyline segment |
7984 | schaersvoo | 3781 | 24 = read all inputfield values: even those set 'readonly' |
8224 | bpr | 3782 | 25 = return all userdrawn arcs in degrees: |
3783 | 26 = return all userdrawn arcs in radians: |
||
8127 | schaersvoo | 3784 | 27 = return (only) userdraw inputfields array: x1:y1:text1,x2:y2:text2... |
7614 | schaersvoo | 3785 | */ |
3786 | |||
3787 | |||
8257 | schaersvoo | 3788 | void add_read_canvas(int canvas_root_id,int type_reply,int reply_precision){ |
7614 | schaersvoo | 3789 | /* just 1 reply type allowed */ |
8074 | schaersvoo | 3790 | fprintf(js_include_file,"\ |
3791 | \n<!-- begin set_reply_precision() -->\n\ |
||
3792 | function set_reply_precision(){\ |
||
3793 | var len = userdraw_x.length;\ |
||
3794 | var prec = %d;\ |
||
3795 | for(var p = 0 ; p < len ; p++ ){\ |
||
3796 | userdraw_x[p] = (Math.round(prec*userdraw_x[p]))/prec;\ |
||
3797 | userdraw_y[p] = (Math.round(prec*userdraw_y[p]))/prec;\ |
||
3798 | };\ |
||
3799 | len = userdraw_radius.length;\ |
||
3800 | if( len > 0 ){\ |
||
3801 | for(var p = 0 ; p < len ; p++ ){\ |
||
3802 | userdraw_radius[p] = (Math.round(prec*userdraw_radius[p]))/prec;\ |
||
3803 | };\ |
||
3804 | };\ |
||
3805 | };",reply_precision); |
||
7963 | schaersvoo | 3806 | |
7614 | schaersvoo | 3807 | switch(type_reply){ |
8224 | bpr | 3808 | /* |
7614 | schaersvoo | 3809 | answers may have: |
3810 | x-values,y-values,r-values,input-fields,mathml-inputfields,text-typed answers |
||
3811 | */ |
||
3812 | case 1: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 3813 | \n<!-- begin function 1 read_canvas%d() -->\n\ |
3814 | read_canvas%d = function(){\ |
||
7614 | schaersvoo | 3815 | if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\ |
8074 | schaersvoo | 3816 | set_reply_precision();\ |
7614 | schaersvoo | 3817 | if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\ |
3818 | var p = 0;var input_reply = new Array();\ |
||
3819 | if( document.getElementById(\"canvas_input0\")){\ |
||
3820 | var t = 0;\ |
||
3821 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
3822 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
3823 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
3824 | p++;\ |
||
3825 | };\ |
||
3826 | t++;\ |
||
3827 | };\ |
||
3828 | };\ |
||
3829 | if( typeof userdraw_text != 'undefined' ){\ |
||
3830 | return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+input_reply + \"\\n\"+userdraw_text;\ |
||
3831 | }\ |
||
3832 | else\ |
||
3833 | {\ |
||
3834 | return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+input_reply;\ |
||
3835 | }\ |
||
3836 | }\ |
||
3837 | else\ |
||
3838 | {\ |
||
3839 | if( typeof userdraw_text != 'undefined' ){\ |
||
3840 | return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_text;\ |
||
3841 | }\ |
||
3842 | else\ |
||
3843 | {\ |
||
3844 | return userdraw_x+\"\\n\"+userdraw_y;\ |
||
3845 | }\ |
||
3846 | };\ |
||
8108 | schaersvoo | 3847 | };\n\ |
8257 | schaersvoo | 3848 | <!-- end function 1 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 3849 | break; |
3850 | case 2: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 3851 | \n<!-- begin function 2 read_canvas%d() -->\n\ |
3852 | read_canvas%d = function(){\ |
||
7614 | schaersvoo | 3853 | if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\ |
8074 | schaersvoo | 3854 | set_reply_precision();\ |
7614 | schaersvoo | 3855 | var reply_x = new Array();var reply_y = new Array();var p = 0;\ |
8074 | schaersvoo | 3856 | var prec = %d;\ |
7614 | schaersvoo | 3857 | while(userdraw_x[p]){\ |
8074 | schaersvoo | 3858 | reply_x[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\ |
3859 | reply_y[p] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\ |
||
7614 | schaersvoo | 3860 | p++;\ |
3861 | };\ |
||
3862 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
3863 | if( document.getElementById(\"canvas_input0\")){\ |
||
3864 | var p = 0;var input_reply = new Array();\ |
||
3865 | if( document.getElementById(\"canvas_input0\")){\ |
||
3866 | var t = 0;\ |
||
3867 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
3868 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
3869 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
3870 | p++;\ |
||
3871 | };\ |
||
3872 | t++;\ |
||
3873 | };\ |
||
3874 | };\ |
||
3875 | if( typeof userdraw_text != 'undefined' ){\ |
||
3876 | return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
3877 | }\ |
||
3878 | else\ |
||
3879 | {\ |
||
3880 | return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply;\ |
||
3881 | }\ |
||
3882 | }\ |
||
3883 | else\ |
||
3884 | {\ |
||
3885 | if( typeof userdraw_text != 'undefined' ){\ |
||
3886 | return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_text;\ |
||
3887 | }\ |
||
3888 | else\ |
||
3889 | {\ |
||
3890 | return reply_x+\"\\n\"+reply_y;\ |
||
3891 | };\ |
||
3892 | };\ |
||
8108 | schaersvoo | 3893 | };\n\ |
8257 | schaersvoo | 3894 | <!-- end function 2 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7614 | schaersvoo | 3895 | break; |
3896 | case 3: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 3897 | \n<!-- begin function 3 read_canvas%d() -->\n\ |
3898 | read_canvas%d = function(){\ |
||
7614 | schaersvoo | 3899 | if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\ |
8074 | schaersvoo | 3900 | set_reply_precision();\ |
7614 | schaersvoo | 3901 | if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\ |
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 userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
3915 | }\ |
||
3916 | else\ |
||
3917 | {\ |
||
3918 | return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+input_reply;\ |
||
3919 | }\ |
||
3920 | }\ |
||
3921 | else\ |
||
3922 | {\ |
||
3923 | if( typeof userdraw_text != 'undefined' ){\ |
||
3924 | return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+userdrawW_text;\ |
||
3925 | }\ |
||
3926 | else\ |
||
3927 | {\ |
||
3928 | return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius;\ |
||
3929 | }\ |
||
3930 | }\ |
||
8108 | schaersvoo | 3931 | };\n\ |
8257 | schaersvoo | 3932 | <!-- end function 3 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 3933 | break; |
3934 | case 4: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 3935 | \n<!-- begin function 4 read_canvas%d() -->\n\ |
3936 | read_canvas%d = function(){\ |
||
8074 | schaersvoo | 3937 | var prec = %d;\ |
7614 | schaersvoo | 3938 | var reply_x = new Array();var reply_y = new Array();var p = 0;\ |
3939 | while(userdraw_x[p]){\ |
||
8074 | schaersvoo | 3940 | reply_x[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\ |
3941 | reply_y[p] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;;\ |
||
7614 | schaersvoo | 3942 | p++;\ |
3943 | };\ |
||
3944 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
3945 | if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\ |
||
3946 | var p = 0;var input_reply = new Array();\ |
||
3947 | if( document.getElementById(\"canvas_input0\")){\ |
||
3948 | var t = 0;\ |
||
3949 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
3950 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
3951 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
3952 | p++;\ |
||
3953 | };\ |
||
3954 | t++;\ |
||
3955 | };\ |
||
3956 | };\ |
||
3957 | if( typeof userdraw_text != 'undefined' ){\ |
||
3958 | return reply_x+\"\\n\"+reply_y +\"\\n\"+userdraw_radius+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
3959 | }\ |
||
3960 | else\ |
||
3961 | {\ |
||
3962 | return reply_x+\"\\n\"+reply_y +\"\\n\"+userdraw_radius+\"\\n\"+input_reply;\ |
||
3963 | }\ |
||
3964 | }\ |
||
3965 | else\ |
||
3966 | {\ |
||
3967 | if( typeof userdraw_text != 'undefined' ){\ |
||
3968 | return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_radius+\"\\n\"+userdraw_text;\ |
||
3969 | }\ |
||
3970 | else\ |
||
3971 | {\ |
||
3972 | return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_radius;\ |
||
3973 | }\ |
||
3974 | };\ |
||
8108 | schaersvoo | 3975 | };\n\ |
8257 | schaersvoo | 3976 | <!-- end function 4 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7614 | schaersvoo | 3977 | break; |
8224 | bpr | 3978 | /* |
3979 | attention: we reset userdraw_x / userdraw_y : because userdraw_x = [][] userdraw_y = [][] |
||
3980 | used for userdraw multiple paths |
||
7614 | schaersvoo | 3981 | */ |
3982 | case 5: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 3983 | \n<!-- begin function 5 read_canvas%d() -->\n\ |
3984 | read_canvas%d = function(){\ |
||
8074 | schaersvoo | 3985 | set_reply_precision();\ |
7614 | schaersvoo | 3986 | var p = 0;\ |
3987 | var reply = \"\";\ |
||
3988 | for(p = 0; p < userdraw_x.length;p++){\ |
||
3989 | if(userdraw_x[p] != null ){\ |
||
3990 | reply = reply + userdraw_x[p]+\"\\n\"+userdraw_y[p]+\"\\n\";\ |
||
3991 | };\ |
||
3992 | };\ |
||
3993 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
3994 | userdraw_x = [];userdraw_y = [];\ |
||
3995 | if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\ |
||
3996 | var p = 0;var input_reply = new Array();\ |
||
3997 | if( document.getElementById(\"canvas_input0\")){\ |
||
3998 | var t = 0;\ |
||
3999 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
4000 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
4001 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
4002 | p++;\ |
||
4003 | };\ |
||
4004 | t++;\ |
||
4005 | };\ |
||
4006 | };\ |
||
4007 | if( typeof userdraw_text != 'undefined' ){\ |
||
4008 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
4009 | }\ |
||
4010 | else\ |
||
4011 | {\ |
||
4012 | return reply +\"\\n\"+input_reply;\ |
||
4013 | }\ |
||
4014 | }\ |
||
4015 | else\ |
||
4016 | {\ |
||
4017 | if( typeof userdraw_text != 'undefined' ){\ |
||
4018 | return reply+\"\\n\"+userdraw_text;\ |
||
4019 | }\ |
||
4020 | else\ |
||
4021 | {\ |
||
4022 | return reply;\ |
||
4023 | }\ |
||
4024 | };\ |
||
8108 | schaersvoo | 4025 | };\n\ |
8257 | schaersvoo | 4026 | <!-- end function 5 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 4027 | break; |
8224 | bpr | 4028 | /* |
4029 | attention: we reset userdraw_x / userdraw_y : because userdraw_x = [][] userdraw_y = [][] |
||
4030 | used for userdraw multiple paths |
||
7614 | schaersvoo | 4031 | */ |
4032 | case 6: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 4033 | \n<!-- begin function 6 read_canvas%d() -->\n\ |
4034 | read_canvas%d = function(){\ |
||
7614 | schaersvoo | 4035 | var p = 0;\ |
4036 | var reply = \"\";\ |
||
4037 | var tmp_x = new Array();\ |
||
4038 | var tmp_y = new Array();\ |
||
8074 | schaersvoo | 4039 | var prec = %d;\ |
7614 | schaersvoo | 4040 | for(p = 0 ; p < userdraw_x.length; p++){\ |
4041 | tmp_x = userdraw_x[p];\ |
||
4042 | tmp_y = userdraw_y[p];\ |
||
4043 | if(tmp_x != null){\ |
||
4044 | for(var i = 0 ; i < tmp_x.length ; i++){\ |
||
8074 | schaersvoo | 4045 | tmp_x[i] = (Math.round(prec*(px2x(tmp_x[i]))))/prec;\ |
4046 | tmp_y[i] = (Math.round(prec*(px2y(tmp_y[i]))))/prec;\ |
||
7614 | schaersvoo | 4047 | };\ |
4048 | reply = reply + tmp_x + \"\\n\" + tmp_y +\"\\n\";\ |
||
4049 | };\ |
||
4050 | };\ |
||
4051 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
4052 | userdraw_x = [];userdraw_y = [];\ |
||
4053 | if( document.getElementById(\"canvas_input0\") ){\ |
||
4054 | var p = 0;var input_reply = new Array();\ |
||
4055 | if( document.getElementById(\"canvas_input0\")){\ |
||
4056 | var t = 0;\ |
||
4057 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
4058 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
4059 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
4060 | p++;\ |
||
4061 | };\ |
||
4062 | t++;\ |
||
4063 | };\ |
||
4064 | };\ |
||
4065 | if( typeof userdraw_text != 'undefined' ){\ |
||
4066 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
4067 | }\ |
||
4068 | else\ |
||
4069 | {\ |
||
4070 | return reply +\"\\n\"+input_reply;\ |
||
4071 | }\ |
||
4072 | }\ |
||
4073 | else\ |
||
4074 | {\ |
||
4075 | if( typeof userdraw_text != 'undefined' ){\ |
||
4076 | return reply +\"\\n\"+userdraw_text;\ |
||
4077 | }\ |
||
4078 | else\ |
||
4079 | {\ |
||
4080 | return reply;\ |
||
4081 | }\ |
||
4082 | };\ |
||
8108 | schaersvoo | 4083 | };\n\ |
8257 | schaersvoo | 4084 | <!-- end function 6 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7614 | schaersvoo | 4085 | break; |
4086 | case 7: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 4087 | \n<!-- begin function 7 read_canvas%d() -->\n\ |
4088 | read_canvas%d = function(){\ |
||
8074 | schaersvoo | 4089 | set_reply_precision();\ |
7614 | schaersvoo | 4090 | var reply = new Array();\ |
4091 | var p = 0;\ |
||
4092 | while(userdraw_x[p]){\ |
||
4093 | reply[p] = userdraw_x[p] +\":\" + userdraw_y[p];\ |
||
4094 | p++;\ |
||
4095 | };\ |
||
4096 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
4097 | if( document.getElementById(\"canvas_input0\") ){\ |
||
4098 | var p = 0;var input_reply = new Array();\ |
||
4099 | if( document.getElementById(\"canvas_input0\")){\ |
||
4100 | var t = 0;\ |
||
4101 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
4102 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
4103 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
4104 | p++;\ |
||
4105 | };\ |
||
4106 | t++;\ |
||
4107 | };\ |
||
4108 | };\ |
||
4109 | if( typeof userdraw_text != 'undefined' ){\ |
||
4110 | return reply+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
4111 | }\ |
||
4112 | else\ |
||
4113 | {\ |
||
4114 | return reply+\"\\n\"+input_reply;\ |
||
4115 | }\ |
||
7862 | schaersvoo | 4116 | }\ |
7614 | schaersvoo | 4117 | else\ |
4118 | {\ |
||
4119 | if( typeof userdraw_text != 'undefined' ){\ |
||
4120 | return reply+\"\\n\"+userdraw_text;\ |
||
4121 | }\ |
||
4122 | else\ |
||
4123 | {\ |
||
4124 | return reply;\ |
||
4125 | }\ |
||
4126 | };\ |
||
8108 | schaersvoo | 4127 | };\n\ |
8257 | schaersvoo | 4128 | <!-- end function 7 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 4129 | break; |
4130 | case 8: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 4131 | \n<!-- begin function 8 read_canvas%d() -->\n\ |
4132 | read_canvas%d = function(){\ |
||
7614 | schaersvoo | 4133 | var reply = new Array();\ |
4134 | var p = 0;\ |
||
8074 | schaersvoo | 4135 | var prec = %d;\ |
7614 | schaersvoo | 4136 | while(userdraw_x[p]){\ |
8074 | schaersvoo | 4137 | reply[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec +\":\" + (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\ |
7614 | schaersvoo | 4138 | p++;\ |
4139 | };\ |
||
4140 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
4141 | if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\ |
||
4142 | var p = 0;var input_reply = new Array();\ |
||
4143 | if( document.getElementById(\"canvas_input0\")){\ |
||
4144 | var t = 0;\ |
||
4145 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
4146 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
4147 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
4148 | p++;\ |
||
4149 | };\ |
||
4150 | t++;\ |
||
4151 | };\ |
||
4152 | };\ |
||
4153 | if( typeof userdraw_text != 'undefined' ){\ |
||
4154 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
4155 | }\ |
||
4156 | else\ |
||
4157 | {\ |
||
4158 | return reply +\"\\n\"+input_reply;\ |
||
4159 | }\ |
||
4160 | }\ |
||
4161 | else\ |
||
4162 | {\ |
||
4163 | if( typeof userdraw_text != 'undefined' ){\ |
||
4164 | return reply +\"\\n\"+userdraw_text;\ |
||
4165 | }\ |
||
4166 | else\ |
||
4167 | {\ |
||
4168 | return reply;\ |
||
4169 | }\ |
||
4170 | };\ |
||
8108 | schaersvoo | 4171 | };\n\ |
8257 | schaersvoo | 4172 | <!-- end function 8 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7614 | schaersvoo | 4173 | break; |
4174 | case 9: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 4175 | \n<!-- begin function 9 read_canvas%d() -->\n\ |
4176 | read_canvas%d = function(){\ |
||
8074 | schaersvoo | 4177 | set_reply_precision();\ |
7614 | schaersvoo | 4178 | var reply = new Array();\ |
4179 | var p = 0;\ |
||
4180 | while(userdraw_x[p]){\ |
||
4181 | reply[p] = userdraw_x[p] +\":\" + userdraw_y[p] + \":\" + userdraw_radius[p];\ |
||
4182 | p++;\ |
||
4183 | };\ |
||
4184 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
4185 | if( document.getElementById(\"canvas_input0\") ){\ |
||
4186 | var p = 0;var input_reply = new Array();\ |
||
4187 | if( document.getElementById(\"canvas_input0\")){\ |
||
4188 | var t = 0;\ |
||
4189 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
4190 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
4191 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
4192 | p++;\ |
||
4193 | };\ |
||
4194 | t++;\ |
||
4195 | };\ |
||
4196 | };\ |
||
4197 | if( typeof userdraw_text != 'undefined' ){\ |
||
4198 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
4199 | }\ |
||
4200 | else\ |
||
4201 | {\ |
||
4202 | return reply +\"\\n\"+input_reply;\ |
||
4203 | }\ |
||
4204 | }\ |
||
4205 | else\ |
||
4206 | {\ |
||
4207 | if( typeof userdraw_text != 'undefined' ){\ |
||
4208 | return reply +\"\\n\"+userdraw_text;\ |
||
4209 | }\ |
||
4210 | else\ |
||
4211 | {\ |
||
4212 | return reply;\ |
||
4213 | }\ |
||
4214 | };\ |
||
8108 | schaersvoo | 4215 | };\n\ |
8257 | schaersvoo | 4216 | <!-- end function 9 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 4217 | break; |
4218 | case 10: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 4219 | \n<!-- begin function 10 read_canvas%d() -->\n\ |
4220 | read_canvas%d = function(){\ |
||
7614 | schaersvoo | 4221 | var reply = new Array();\ |
4222 | var p = 0;\ |
||
8074 | schaersvoo | 4223 | var prec = %d;\ |
7614 | schaersvoo | 4224 | while(userdraw_x[p]){\ |
8074 | schaersvoo | 4225 | reply[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec +\":\" + (Math.round(prec*(px2y(userdraw_y[p]))))/prec +\":\" + (Math.round(prec*userdraw_radius[p]))/prec;\ |
7614 | schaersvoo | 4226 | p++;\ |
4227 | };\ |
||
4228 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
4229 | if( document.getElementById(\"canvas_input0\") ){\ |
||
4230 | var p = 0;var input_reply = new Array();\ |
||
4231 | if( document.getElementById(\"canvas_input0\")){\ |
||
4232 | var t = 0;\ |
||
4233 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
4234 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
4235 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
4236 | p++;\ |
||
4237 | };\ |
||
4238 | t++;\ |
||
4239 | };\ |
||
4240 | };\ |
||
4241 | if( typeof userdraw_text != 'undefined' ){\ |
||
4242 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
4243 | }\ |
||
4244 | else\ |
||
4245 | {\ |
||
4246 | return reply +\"\\n\"+input_reply;\ |
||
4247 | }\ |
||
4248 | }\ |
||
4249 | else\ |
||
4250 | {\ |
||
4251 | if( typeof userdraw_text != 'undefined' ){\ |
||
4252 | return reply +\"\\n\"+userdraw_text;\ |
||
4253 | }\ |
||
4254 | else\ |
||
4255 | {\ |
||
4256 | return reply;\ |
||
4257 | }\ |
||
4258 | };\ |
||
8108 | schaersvoo | 4259 | };\n\ |
8257 | schaersvoo | 4260 | <!-- end function 10 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7614 | schaersvoo | 4261 | break; |
4262 | case 11: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 4263 | \n<!-- begin function 11 read_canvas%d() -->\n\ |
4264 | read_canvas%d = function(){\ |
||
7614 | schaersvoo | 4265 | var reply = \"\";\ |
4266 | var p = 0;\ |
||
8074 | schaersvoo | 4267 | var prec = %d;\ |
7614 | schaersvoo | 4268 | while(userdraw_x[p]){\ |
8074 | schaersvoo | 4269 | reply = reply + (Math.round(prec*(px2x(userdraw_x[p]))))/prec +\",\" + (Math.round(prec*(px2y(userdraw_y[p]))))/prec +\",\" + (Math.round(prec*(px2x(userdraw_x[p+1]))))/prec +\",\" + (Math.round(prec*(px2y(userdraw_y[p+1]))))/prec +\"\\n\" ;\ |
7614 | schaersvoo | 4270 | p = p+2;\ |
4271 | };\ |
||
4272 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
4273 | if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\ |
||
4274 | var p = 0;var input_reply = new Array();\ |
||
4275 | if( document.getElementById(\"canvas_input0\")){\ |
||
4276 | var t = 0;\ |
||
4277 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
4278 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
4279 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
4280 | p++;\ |
||
4281 | };\ |
||
4282 | t++;\ |
||
4283 | };\ |
||
4284 | };\ |
||
4285 | if( typeof userdraw_text != 'undefined' ){\ |
||
4286 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
4287 | }\ |
||
4288 | else\ |
||
4289 | {\ |
||
4290 | return reply +\"\\n\"+input_reply;\ |
||
4291 | }\ |
||
4292 | }\ |
||
4293 | else\ |
||
4294 | {\ |
||
4295 | if( typeof userdraw_text != 'undefined' ){\ |
||
4296 | return reply +\"\\n\"+userdraw_text;\ |
||
4297 | }\ |
||
4298 | else\ |
||
4299 | {\ |
||
4300 | return reply;\ |
||
4301 | }\ |
||
4302 | };\ |
||
8108 | schaersvoo | 4303 | };\n\ |
8257 | schaersvoo | 4304 | <!-- end function 11 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7614 | schaersvoo | 4305 | break; |
4306 | case 12: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 4307 | \n<!-- begin function 12 read_canvas%d() -->\n\ |
4308 | read_canvas%d = function(){\ |
||
8074 | schaersvoo | 4309 | set_reply_precision();\ |
7614 | schaersvoo | 4310 | var reply = \"\";\ |
4311 | var p = 0;\ |
||
4312 | for(p = 0; p< userdraw_x.lenght;p = p+2){\ |
||
4313 | if(userdraw_x[p] != null){\ |
||
4314 | reply = reply + userdraw_x[p] +\",\" + userdraw_y[p] +\",\" + userdraw_x[p+1] +\",\" + userdraw_y[p+1] +\"\\n\" ;\ |
||
4315 | };\ |
||
4316 | };\ |
||
4317 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
4318 | if( document.getElementById(\"canvas_input0\") ){\ |
||
4319 | var p = 0;var input_reply = new Array();\ |
||
4320 | if( document.getElementById(\"canvas_input0\")){\ |
||
4321 | var t = 0;\ |
||
4322 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
4323 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
4324 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
4325 | p++;\ |
||
4326 | };\ |
||
4327 | t++;\ |
||
4328 | };\ |
||
4329 | };\ |
||
4330 | if( typeof userdraw_text != 'undefined' ){\ |
||
4331 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
4332 | }\ |
||
4333 | else\ |
||
4334 | {\ |
||
4335 | return reply +\"\\n\"+input_reply;\ |
||
4336 | }\ |
||
4337 | }\ |
||
4338 | else\ |
||
4339 | {\ |
||
4340 | if( typeof userdraw_text != 'undefined' ){\ |
||
4341 | return reply +\"\\n\"+userdraw_text\ |
||
4342 | }\ |
||
4343 | else\ |
||
4344 | {\ |
||
4345 | return reply;\ |
||
4346 | }\ |
||
4347 | };\ |
||
8108 | schaersvoo | 4348 | };\n\ |
8257 | schaersvoo | 4349 | <!-- end function 12 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 4350 | break; |
4351 | case 13: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 4352 | \n<!-- begin function 13 read_canvas%d() -->\n\ |
4353 | read_canvas%d = function(){\ |
||
7614 | schaersvoo | 4354 | var reply = new Array();\ |
4355 | var p = 0;var i = 0;\ |
||
8074 | schaersvoo | 4356 | var prec = %d;\ |
7614 | schaersvoo | 4357 | while(userdraw_x[p]){\ |
8074 | schaersvoo | 4358 | reply[i] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec +\":\" + (Math.round(prec*(px2y(userdraw_y[p]))))/prec +\":\" + (Math.round(prec*(px2x(userdraw_x[p+1]))))/prec +\":\" + (Math.round(prec*(px2y(userdraw_y[p+1]))))/prec;\ |
7614 | schaersvoo | 4359 | p = p+2;i++;\ |
4360 | };\ |
||
4361 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
4362 | if( document.getElementById(\"canvas_input0\") ){\ |
||
4363 | var p = 0;var input_reply = new Array();\ |
||
4364 | if( document.getElementById(\"canvas_input0\")){\ |
||
4365 | var t = 0;\ |
||
4366 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
4367 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
4368 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
4369 | p++;\ |
||
4370 | };\ |
||
4371 | t++;\ |
||
4372 | };\ |
||
4373 | };\ |
||
4374 | if( typeof userdraw_text != 'undefined' ){\ |
||
4375 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
4376 | }\ |
||
4377 | else\ |
||
4378 | {\ |
||
4379 | return reply +\"\\n\"+input_reply;\ |
||
4380 | }\ |
||
4381 | }\ |
||
4382 | else\ |
||
4383 | {\ |
||
4384 | if( typeof userdraw_text != 'undefined' ){\ |
||
4385 | return reply +\"\\n\"+userdraw_text\ |
||
4386 | }\ |
||
4387 | else\ |
||
4388 | {\ |
||
4389 | return reply;\ |
||
4390 | }\ |
||
4391 | };\ |
||
8108 | schaersvoo | 4392 | };\n\ |
8257 | schaersvoo | 4393 | <!-- end function 13 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7614 | schaersvoo | 4394 | break; |
4395 | case 14: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 4396 | \n<!-- begin function 14 read_canvas%d() -->\n\ |
4397 | read_canvas%d = function(){\ |
||
8074 | schaersvoo | 4398 | set_reply_precision();\ |
7614 | schaersvoo | 4399 | var reply = new Array();\ |
4400 | var p = 0;var i = 0;\ |
||
4401 | while(userdraw_x[p]){\ |
||
4402 | reply[i] = userdraw_x[p] +\":\" + userdraw_y[p] +\":\" + userdraw_x[p+1] +\":\" + userdraw_y[p+1];\ |
||
4403 | p = p+2;i++;\ |
||
4404 | };\ |
||
4405 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
4406 | if( document.getElementById(\"canvas_input0\") ){\ |
||
4407 | var p = 0;var input_reply = new Array();\ |
||
4408 | if( document.getElementById(\"canvas_input0\")){\ |
||
4409 | var t = 0;\ |
||
4410 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
4411 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
4412 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
4413 | p++;\ |
||
4414 | };\ |
||
4415 | t++;\ |
||
4416 | };\ |
||
4417 | };\ |
||
4418 | if( typeof userdraw_text != 'undefined' ){\ |
||
4419 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
4420 | }\ |
||
4421 | else\ |
||
4422 | {\ |
||
4423 | return reply +\"\\n\"+input_reply;\ |
||
4424 | }\ |
||
4425 | }\ |
||
4426 | else\ |
||
4427 | {\ |
||
4428 | if( typeof userdraw_text != 'undefined' ){\ |
||
4429 | return reply +\"\\n\"+userdraw_text;\ |
||
4430 | }\ |
||
4431 | else\ |
||
4432 | {\ |
||
4433 | return reply;\ |
||
4434 | }\ |
||
4435 | };\ |
||
8108 | schaersvoo | 4436 | };\n\ |
8257 | schaersvoo | 4437 | <!-- end function 14 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 4438 | break; |
4439 | case 15: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 4440 | \n<!-- begin function 15 read_canvas%d() -->\n\ |
4441 | read_canvas%d = function(){\ |
||
7614 | schaersvoo | 4442 | var input_reply = new Array();\ |
4443 | var p = 0;\ |
||
4444 | if( document.getElementById(\"canvas_input0\")){\ |
||
4445 | var t = 0;\ |
||
4446 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
4447 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
4448 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
4449 | p++;\ |
||
4450 | };\ |
||
4451 | t++;\ |
||
4452 | };\ |
||
4453 | };\ |
||
4454 | if( typeof userdraw_text != 'undefined' ){\ |
||
4455 | return input_reply +\"\\n\"+userdraw_text;\ |
||
4456 | }\ |
||
4457 | else\ |
||
4458 | {\ |
||
4459 | return input_reply;\ |
||
4460 | };\ |
||
8108 | schaersvoo | 4461 | };\n\ |
8257 | schaersvoo | 4462 | <!-- end function 15 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 4463 | break; |
4464 | case 16: fprintf(js_include_file,"\ |
||
7653 | schaersvoo | 4465 | \n<!-- begin function 16 read_mathml() -->\n\ |
7614 | schaersvoo | 4466 | function read_mathml(){\ |
4467 | var reply = new Array();\ |
||
4468 | var p = 0;\ |
||
4469 | if( document.getElementById(\"mathml0\")){\ |
||
4470 | while(document.getElementById(\"mathml\"+p)){\ |
||
4471 | reply[p] = document.getElementById(\"mathml\"+p).value;\ |
||
4472 | p++;\ |
||
4473 | };\ |
||
4474 | };\ |
||
4475 | return reply;\ |
||
4476 | };\ |
||
4477 | this.read_mathml = read_mathml;\n\ |
||
7653 | schaersvoo | 4478 | <!-- end function 16 read_mathml() -->"); |
7614 | schaersvoo | 4479 | break; |
4480 | case 17: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 4481 | \n<!-- begin function 17 read_canvas%d() -->\n\ |
4482 | read_canvas%d = function(){\ |
||
7614 | schaersvoo | 4483 | if( userdraw_text.length == 0){alert(\"no text typed...\");return;}\ |
4484 | return userdraw_text;\ |
||
8108 | schaersvoo | 4485 | };\n\ |
8257 | schaersvoo | 4486 | <!-- end function 17 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 4487 | break; |
4488 | case 18: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 4489 | \n<!-- begin function 18 read_canvas%d() -->\n\ |
4490 | read_canvas%d = function(){\ |
||
7614 | schaersvoo | 4491 | var p = 0;\ |
4492 | var reply = new Array();\ |
||
4493 | var name;\ |
||
4494 | var t = true;\ |
||
8000 | schaersvoo | 4495 | var h;var m;var s;\ |
7614 | schaersvoo | 4496 | while(t){\ |
8000 | schaersvoo | 4497 | try{\ |
4498 | name = eval('clocks'+p);\ |
||
4499 | h = name.H;m = name.M;s = name.S;\ |
||
4500 | if(s < 0){s = 60 + s;m = m - 1;};\ |
||
4501 | if(m < 0){m = 60 + m;h = h - 1;};\ |
||
4502 | if(h < 0){h = 12 + h;};\ |
||
4503 | h = parseInt((h+m/60+s/3600)%%12);m = parseInt((m + s/60)%%60);s = parseInt(s%%60);\ |
||
4504 | reply[p] = h+\":\"+m+\":\"+s;\ |
||
4505 | p++;\ |
||
4506 | }catch(e){t=false;};\ |
||
7614 | schaersvoo | 4507 | };\ |
8000 | schaersvoo | 4508 | if( p == 0 ){alert(\"clock(s) not modified...\");return;}\ |
7614 | schaersvoo | 4509 | return reply;\ |
8108 | schaersvoo | 4510 | };\n\ |
8257 | schaersvoo | 4511 | <!-- end function 18 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 4512 | break; |
4513 | case 19: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 4514 | \n<!-- begin function 19 read_canvas%d() -->\n\ |
4515 | read_canvas%d = function(){\ |
||
7614 | schaersvoo | 4516 | return reply[0];\ |
8108 | schaersvoo | 4517 | };\n\ |
8257 | schaersvoo | 4518 | <!-- end function 19 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id); |
8130 | schaersvoo | 4519 | break; |
7614 | schaersvoo | 4520 | case 20: fprintf(js_include_file,"\ |
8257 | schaersvoo | 4521 | \n<!-- begin function 20 read_canvas%d() -->\n\ |
4522 | read_canvas%d = function(){\ |
||
8074 | schaersvoo | 4523 | var prec = %d;\ |
7614 | schaersvoo | 4524 | var len = ext_drag_images.length;\ |
4525 | var reply = new Array(len);\ |
||
4526 | for(var p = 0 ; p < len ; p++){\ |
||
4527 | var img = ext_drag_images[p];\ |
||
8074 | schaersvoo | 4528 | reply[p] = (Math.round(prec*(px2x(img[6]))))/prec+\":\"+(Math.round(prec*(px2y(img[7]))))/prec;\ |
7614 | schaersvoo | 4529 | };\ |
4530 | return reply;\ |
||
8108 | schaersvoo | 4531 | };\n\ |
8257 | schaersvoo | 4532 | <!-- end function 20 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7614 | schaersvoo | 4533 | break; |
4534 | case 21: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 4535 | \n<!-- begin function 21 read_canvas%d() -->\n\ |
4536 | read_canvas%d = function(){\ |
||
7614 | schaersvoo | 4537 | if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\ |
4538 | var reply_coord = new Array();var p = 0;\ |
||
8074 | schaersvoo | 4539 | var prec = %d;\ |
7614 | schaersvoo | 4540 | while(userdraw_x[p]){\ |
8074 | schaersvoo | 4541 | reply_coord[p] = \"(\"+(Math.round(prec*(px2x(userdraw_x[p]))))/prec+\":\"+(Math.round(prec*(px2y(userdraw_y[p]))))/prec+\")\";\ |
7614 | schaersvoo | 4542 | p++;\ |
4543 | };\ |
||
4544 | if(p == 0){alert(\"nothing drawn...\");return;};\ |
||
4545 | if( document.getElementById(\"canvas_input0\") ){\ |
||
4546 | var p = 0;var input_reply = new Array();\ |
||
4547 | if( document.getElementById(\"canvas_input0\")){\ |
||
4548 | var t = 0;\ |
||
4549 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
4550 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
4551 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
4552 | p++;\ |
||
4553 | };\ |
||
4554 | t++;\ |
||
4555 | };\ |
||
4556 | };\ |
||
4557 | if( typeof userdraw_text != 'undefined' ){\ |
||
4558 | return reply_coord+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
4559 | }\ |
||
4560 | else\ |
||
4561 | {\ |
||
4562 | return reply_coord+\"\\n\"+input_reply;\ |
||
4563 | }\ |
||
4564 | }\ |
||
4565 | else\ |
||
4566 | {\ |
||
4567 | if( typeof userdraw_text != 'undefined' ){\ |
||
4568 | return reply_coord+\"\\n\"+userdraw_text;\ |
||
4569 | }\ |
||
4570 | else\ |
||
4571 | {\ |
||
4572 | return reply_coord;\ |
||
4573 | };\ |
||
4574 | };\ |
||
8108 | schaersvoo | 4575 | };\n\ |
8257 | schaersvoo | 4576 | <!-- end function 21 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7614 | schaersvoo | 4577 | break; |
4578 | case 22: fprintf(js_include_file,"\ |
||
8257 | schaersvoo | 4579 | \n<!-- begin function 22 read_canvas%d() -->\n\ |
4580 | read_canvas%d = function(){\ |
||
7614 | schaersvoo | 4581 | var reply = new Array();\ |
7963 | schaersvoo | 4582 | var lu = userdraw_x.length;\ |
4583 | if(lu == 0){alert(\"nothing drawn...\");return;};\ |
||
7614 | schaersvoo | 4584 | var idx = 0;\ |
8074 | schaersvoo | 4585 | var prec = %d;\ |
7963 | schaersvoo | 4586 | for(var p = 0 ; p < lu ; p++){\ |
8074 | schaersvoo | 4587 | reply[idx] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;idx++;\ |
4588 | reply[idx] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;idx++;\ |
||
7614 | schaersvoo | 4589 | };\ |
4590 | if( document.getElementById(\"canvas_input0\") ){\ |
||
4591 | var p = 0;var input_reply = new Array();\ |
||
4592 | if( document.getElementById(\"canvas_input0\")){\ |
||
4593 | var t = 0;\ |
||
4594 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
4595 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
4596 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
4597 | p++;\ |
||
4598 | };\ |
||
4599 | t++;\ |
||
4600 | };\ |
||
4601 | };\ |
||
4602 | if( typeof userdraw_text != 'undefined' ){\ |
||
4603 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
4604 | }\ |
||
4605 | else\ |
||
4606 | {\ |
||
4607 | return reply +\"\\n\"+input_reply;\ |
||
4608 | }\ |
||
4609 | }\ |
||
4610 | else\ |
||
4611 | {\ |
||
4612 | if( typeof userdraw_text != 'undefined' ){\ |
||
4613 | return reply +\"\\n\"+userdraw_text;\ |
||
4614 | }\ |
||
4615 | else\ |
||
4616 | {\ |
||
4617 | return reply;\ |
||
4618 | }\ |
||
4619 | };\ |
||
8108 | schaersvoo | 4620 | };\n\ |
8257 | schaersvoo | 4621 | <!-- end function 22 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7614 | schaersvoo | 4622 | break; |
7782 | schaersvoo | 4623 | case 23: fprintf(js_include_file,"\ |
8257 | schaersvoo | 4624 | \n<!-- begin function 23 read_canvas%d() default 5 px marge -->\n\ |
4625 | read_canvas%d = function(){\ |
||
7782 | schaersvoo | 4626 | if( userdraw_x.length < 2){alert(\"nothing drawn...\");return;}\ |
4627 | var lu = userdraw_x.length;\ |
||
4628 | if( lu != userdraw_y.length ){ alert(\"x / y mismatch !\");return;}\ |
||
7962 | schaersvoo | 4629 | var reply_x = new Array();var reply_y = new Array();\ |
4630 | var marge = 5;var p = 0;\ |
||
8074 | schaersvoo | 4631 | var prec = %d;\ |
7782 | schaersvoo | 4632 | for(var i = 0; i < lu - 1 ; i++ ){\ |
7962 | schaersvoo | 4633 | if( Math.abs(userdraw_x[i] - userdraw_x[i+1])){\ |
8074 | schaersvoo | 4634 | reply_x[p] = (Math.round(prec*(px2x(userdraw_x[i]))))/prec;reply_y[p] = (Math.round(prec*(px2y(userdraw_y[i]))))/prec;\ |
7962 | schaersvoo | 4635 | if( isNaN(reply_x[p]) || isNaN(reply_y[p]) ){ alert(\"hmmmm ?\");return; };\ |
4636 | p++;\ |
||
7782 | schaersvoo | 4637 | };\ |
8074 | schaersvoo | 4638 | reply_x[p] = (Math.round(prec*(px2x(userdraw_x[lu-1]))))/prec;reply_y[p] = (Math.round(prec*(px2y(userdraw_y[lu-1]))))/prec;\ |
7782 | schaersvoo | 4639 | };\ |
4640 | if( document.getElementById(\"canvas_input0\")){\ |
||
4641 | var p = 0;var input_reply = new Array();\ |
||
4642 | if( document.getElementById(\"canvas_input0\")){\ |
||
4643 | var t = 0;\ |
||
4644 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
4645 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
4646 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
4647 | p++;\ |
||
4648 | };\ |
||
4649 | t++;\ |
||
4650 | };\ |
||
4651 | };\ |
||
4652 | if( typeof userdraw_text != 'undefined' ){\ |
||
4653 | return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
||
4654 | }\ |
||
4655 | else\ |
||
4656 | {\ |
||
4657 | return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply;\ |
||
4658 | }\ |
||
4659 | }\ |
||
4660 | else\ |
||
4661 | {\ |
||
4662 | if( typeof userdraw_text != 'undefined' ){\ |
||
4663 | return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_text;\ |
||
4664 | }\ |
||
4665 | else\ |
||
4666 | {\ |
||
4667 | return reply_x+\"\\n\"+reply_y;\ |
||
4668 | };\ |
||
4669 | };\ |
||
8108 | schaersvoo | 4670 | };\n\ |
8257 | schaersvoo | 4671 | <!-- end function 23 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7782 | schaersvoo | 4672 | break; |
7984 | schaersvoo | 4673 | case 24: fprintf(js_include_file,"\n\ |
8257 | schaersvoo | 4674 | <!-- begin function 24 read_canvas%d() -->\n\ |
4675 | read_canvas%d = function(){\ |
||
7984 | schaersvoo | 4676 | var input_reply = new Array();\ |
4677 | var p = 0;\ |
||
4678 | if( document.getElementById(\"canvas_input0\")){\ |
||
4679 | while(document.getElementById(\"canvas_input\"+p)){\ |
||
4680 | input_reply[p] = document.getElementById(\"canvas_input\"+p).value;\ |
||
4681 | p++;\ |
||
4682 | };\ |
||
4683 | return input_reply;\ |
||
4684 | };\ |
||
8108 | schaersvoo | 4685 | };\n\ |
8257 | schaersvoo | 4686 | <!-- end function 24 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id); |
7984 | schaersvoo | 4687 | break; |
8083 | schaersvoo | 4688 | case 25: |
8257 | schaersvoo | 4689 | fprintf(js_include_file,"\n<!-- begin function 25 read_canvas%d() : angle(s) in degrees-->\n\ |
4690 | read_canvas%d = function(){\ |
||
8083 | schaersvoo | 4691 | if( userdraw_radius.length < 1){alert(\"nothing drawn...\");return;}\ |
4692 | var lu = userdraw_radius.length;\ |
||
4693 | var prec = %d;\ |
||
4694 | var angle_reply = new Array(lu);\ |
||
4695 | for(var p = 0 ; p < lu ; p++){\ |
||
4696 | angle_reply[p] = (Math.round(prec*180*(userdraw_radius[p])/Math.PI))/prec;\ |
||
4697 | };\ |
||
4698 | return angle_reply;\ |
||
8108 | schaersvoo | 4699 | };\n\ |
8257 | schaersvoo | 4700 | <!-- end function 25 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
8083 | schaersvoo | 4701 | break; |
4702 | case 26: |
||
8257 | schaersvoo | 4703 | fprintf(js_include_file,"\n<!-- begin function 26 read_canvas%d() : angle(s) in radians-->\n\ |
4704 | read_canvas%d = function(){\ |
||
8083 | schaersvoo | 4705 | if( userdraw_radius.length < 1){alert(\"nothing drawn...\");return;}\ |
4706 | var lu = userdraw_radius.length;\ |
||
4707 | var prec = %d;\ |
||
4708 | var angle_reply = new Array(lu);\ |
||
4709 | for(var p = 0 ; p < lu ; p++){\ |
||
4710 | angle_reply[p] = (Math.round(prec*(userdraw_radius[p])))/prec;\ |
||
4711 | };\ |
||
4712 | return angle_reply;\ |
||
8108 | schaersvoo | 4713 | };\n\ |
8257 | schaersvoo | 4714 | <!-- end function 26 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
8083 | schaersvoo | 4715 | break; |
8127 | schaersvoo | 4716 | case 27: |
8257 | schaersvoo | 4717 | fprintf(js_include_file,"\n<!-- begin function 27 read_canvas%d() : inputfield(s) location and their values : -->\n\ |
4718 | read_canvas%d = function(){\ |
||
8127 | schaersvoo | 4719 | var lu = userdraw_x.length;\ |
4720 | if( lu < 1){alert(\"nothing drawn...\");return;}\ |
||
4721 | set_reply_precision();\ |
||
4722 | var prec = %d;\ |
||
4723 | for(var p = 0 ; p < lu ; p++){\ |
||
4724 | reply[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec+\":\"+(Math.round(prec*(px2y(userdraw_y[p]))))/prec+\":\"+ document.getElementById(\"canvas_input\"+p).value;\ |
||
4725 | };\ |
||
4726 | return reply;\ |
||
4727 | };\n\ |
||
8257 | schaersvoo | 4728 | <!-- end function 27 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
8127 | schaersvoo | 4729 | break; |
7614 | schaersvoo | 4730 | default: canvas_error("hmmm unknown replyformat...");break; |
4731 | } |
||
4732 | return; |
||
4733 | } |
||
4734 | |||
4735 | |||
8224 | bpr | 4736 | /* |
4737 | add drawfunction : |
||
7614 | schaersvoo | 4738 | - functions used by userdraw_primitives (circle,rect,path,triangle...) |
4739 | - things not covered by the drag&drop library (static objects like parallel, lattice ,gridfill , imagefill) |
||
4740 | - grid / mathml |
||
4741 | - will not scale or zoom in |
||
4742 | - will not be filled via pixel operations like fill / floodfill / filltoborder / clickfill |
||
8224 | bpr | 4743 | - is printed directly into 'js_include_file' |
7614 | schaersvoo | 4744 | */ |
4745 | |||
4746 | void add_javascript_functions(int js_functions[],int canvas_root_id){ |
||
4747 | int i; |
||
4748 | for(i = 0 ; i < MAX_JS_FUNCTIONS; i++){ |
||
4749 | if( js_functions[i] == 1){ |
||
4750 | switch(i){ |
||
4751 | case DRAG_EXTERNAL_IMAGE: |
||
4752 | fprintf(js_include_file,"\n<!-- drag external images --->\n\ |
||
7653 | schaersvoo | 4753 | var external_canvas = create_canvas%d(7,xsize,ysize);\ |
4754 | var external_ctx = external_canvas.getContext(\"2d\");\ |
||
4755 | var external_canvas_rect = external_canvas.getBoundingClientRect();\ |
||
4756 | canvas_div.addEventListener(\"mousedown\",setxy,false);\ |
||
4757 | canvas_div.addEventListener(\"mouseup\",dragstop,false);\ |
||
4758 | canvas_div.addEventListener(\"mousemove\",dragxy,false);\ |
||
4759 | var selected_image = null;\ |
||
4760 | var ext_image_cnt = 0;\ |
||
4761 | var ext_drag_images = new Array();\ |
||
4762 | function drag_external_image(URL,sx,sy,swidth,sheight,x0,y0,width,height,idx,draggable){\ |
||
4763 | ext_image_cnt = idx;\ |
||
4764 | var image = new Image();\ |
||
4765 | image.src = URL;\ |
||
4766 | image.onload = function(){\ |
||
4767 | if( x0 < 1 ){ x0 = 0; };if( y0 < 1 ){ y0 = 0; };if( sx < 1 ){ sx = 0; };if( sy < 1 ){ sy = 0; };\ |
||
4768 | if( width < 1 ){ width = image.width; };if( height < 1 ){ height = image.height; };\ |
||
4769 | if( swidth < 1 ){ swidth = image.width; };if( sheight < 1 ){ sheight = image.height; };\ |
||
8112 | schaersvoo | 4770 | var img = new Array(10);\ |
7653 | schaersvoo | 4771 | img[0] = draggable;img[1] = image;img[2] = sx;img[3] = sy;img[4] = swidth;img[5] = sheight;\ |
4772 | img[6] = x0;img[7] = y0;img[8] = width;img[9] = height;\ |
||
4773 | ext_drag_images[idx] = img;\ |
||
4774 | external_ctx.drawImage(img[1],img[2],img[3],img[4],img[5],img[6],img[7],img[8],img[9]);\ |
||
4775 | };\ |
||
4776 | };\ |
||
4777 | function dragstop(evt){\ |
||
4778 | selected_image = null;return;\ |
||
4779 | };\ |
||
4780 | function dragxy(evt){\ |
||
4781 | if( selected_image != null ){\ |
||
4782 | var xoff = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);\ |
||
4783 | var yoff = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);\ |
||
4784 | var s_img = ext_drag_images[selected_image];\ |
||
4785 | s_img[6] = evt.clientX - external_canvas_rect.left + xoff;\ |
||
4786 | s_img[7] = evt.clientY - external_canvas_rect.top + yoff;\ |
||
4787 | ext_drag_images[selected_image] = s_img;\ |
||
4788 | external_ctx.clearRect(0,0,xsize,ysize);\ |
||
4789 | for(var i = 0; i <= ext_image_cnt ; i++){\ |
||
4790 | var img = ext_drag_images[i];\ |
||
4791 | external_ctx.drawImage(img[1],img[2],img[3],img[4],img[5],img[6],img[7],img[8],img[9]);\ |
||
4792 | };\ |
||
4793 | };\ |
||
4794 | };\ |
||
4795 | function setxy(evt){\ |
||
4796 | if( ! selected_image && evt.which == 1 ){\ |
||
4797 | var xoff = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);\ |
||
4798 | var yoff = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);\ |
||
4799 | var xm = evt.clientX - external_canvas_rect.left + xoff;\ |
||
4800 | var ym = evt.clientY - external_canvas_rect.top + yoff;\ |
||
4801 | for(var p = 0 ; p <= ext_image_cnt ; p++){\ |
||
4802 | var img = ext_drag_images[p];\ |
||
4803 | if( img[0] == 1 ){\ |
||
4804 | var w = img.width;\ |
||
4805 | var h = img.height;\ |
||
4806 | if( xm > img[6] && xm < img[6] + img[4]){\ |
||
4807 | if( ym > img[7] && ym < img[7] + img[5]){\ |
||
4808 | img[6] = xm;\ |
||
4809 | img[7] = ym;\ |
||
4810 | ext_drag_images[p] = img;\ |
||
4811 | selected_image = p;\ |
||
4812 | dragxy(evt);\ |
||
4813 | };\ |
||
4814 | };\ |
||
4815 | };\ |
||
4816 | };\ |
||
4817 | }\ |
||
4818 | else\ |
||
4819 | {\ |
||
4820 | selected_image = null;\ |
||
4821 | };\ |
||
7614 | schaersvoo | 4822 | };",canvas_root_id); |
4823 | break; |
||
4824 | |||
4825 | case DRAW_EXTERNAL_IMAGE: |
||
4826 | fprintf(js_include_file,"\n<!-- draw external images -->\n\ |
||
8105 | schaersvoo | 4827 | var draw_external_image = function(URL,sx,sy,swidth,sheight,x0,y0,width,height,draggable){\ |
7614 | schaersvoo | 4828 | var image = new Image();\ |
4829 | image.src = URL;\ |
||
4830 | var canvas_bg_div = document.getElementById(\"canvas_div%d\");\ |
||
4831 | image.onload = function(){\ |
||
4832 | if( x0 < 1 ){ x0 = 0; };\ |
||
4833 | if( y0 < 1 ){ y0 = 0; };\ |
||
4834 | if( sx < 1 ){ sx = 0; };\ |
||
4835 | if( sy < 1 ){ sy = 0; };\ |
||
4836 | if( width < 1 ){ width = image.width;};\ |
||
4837 | if( height < 1 ){ height = image.height;};\ |
||
4838 | if( swidth < 1 ){ swidth = image.width;};\ |
||
4839 | if( sheight < 1 ){ sheight = image.height;};\ |
||
4840 | var ml = x0 - sx;\ |
||
4841 | var mh = y0 - sy;\ |
||
4842 | canvas_bg_div.style.backgroundPosition= \"left \"+ml+\"px top \"+mh+\"px\";\ |
||
4843 | canvas_bg_div.style.backgroundSize = width+\"px \"+height+\"px\";\ |
||
4844 | canvas_bg_div.style.backgroundRepeat = \"no-repeat\";\ |
||
4845 | canvas_bg_div.style.backgroundPosition= sx+\"px \"+sy+\"px\";\ |
||
4846 | canvas_bg_div.style.backgroundImage = \"url(\" + URL + \")\";\ |
||
4847 | };\ |
||
8224 | bpr | 4848 | };",canvas_root_id); |
7614 | schaersvoo | 4849 | break; |
4850 | case DRAW_GRIDFILL:/* not used for userdraw */ |
||
4851 | fprintf(js_include_file,"\n<!-- draw gridfill -->\n\ |
||
8105 | schaersvoo | 4852 | var draw_gridfill = function(canvas_type,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize){\ |
7614 | schaersvoo | 4853 | var obj;\ |
4854 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
4855 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
4856 | }\ |
||
4857 | else\ |
||
4858 | {\ |
||
4859 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
4860 | };\ |
||
4861 | var ctx = obj.getContext(\"2d\");\ |
||
4862 | var x,y;\ |
||
7883 | schaersvoo | 4863 | snap_x = dx;snap_y = dy;\ |
7614 | schaersvoo | 4864 | ctx.save();\ |
4865 | ctx.strokeStyle=\"rgba(\"+color+\",\"+opacity+\")\";\ |
||
4866 | for( x = x0 ; x < xsize+dx ; x = x + dx ){\ |
||
4867 | ctx.moveTo(x,y0);\ |
||
4868 | ctx.lineTo(x,ysize);\ |
||
4869 | };\ |
||
7645 | schaersvoo | 4870 | for( y = y0 ; y < ysize+dy; y = y + dy ){\ |
7614 | schaersvoo | 4871 | ctx.moveTo(x0,y);\ |
4872 | ctx.lineTo(xsize,y);\ |
||
4873 | };\ |
||
4874 | ctx.stroke();\ |
||
4875 | ctx.restore();\ |
||
7653 | schaersvoo | 4876 | return;};",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 4877 | break; |
8224 | bpr | 4878 | |
7614 | schaersvoo | 4879 | case DRAW_IMAGEFILL:/* not used for userdraw */ |
4880 | fprintf(js_include_file,"\n<!-- draw imagefill -->\n\ |
||
8105 | schaersvoo | 4881 | var draw_imagefill = function(canvas_type,x0,y0,URL,xsize,ysize){\ |
7614 | schaersvoo | 4882 | var obj;\ |
4883 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
4884 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
4885 | }\ |
||
4886 | else\ |
||
4887 | {\ |
||
4888 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
4889 | };\ |
||
4890 | var ctx = obj.getContext(\"2d\");\ |
||
4891 | ctx.save();\ |
||
4892 | var img = new Image();\ |
||
4893 | img.src = URL;\ |
||
4894 | img.onload = function(){\ |
||
4895 | if( (img.width > xsize-x0) && (img.height > ysize-y0) ){\ |
||
4896 | ctx.drawImage(img,x0,y0,xsize,ysize);\ |
||
4897 | }\ |
||
4898 | else\ |
||
4899 | {\ |
||
4900 | var repeat = \"repeat\";\ |
||
4901 | if(img.width > xsize - x0){\ |
||
4902 | repeat = \"repeat-y\";\ |
||
4903 | }\ |
||
4904 | else\ |
||
4905 | {\ |
||
4906 | if( img.height > ysize -x0 ){\ |
||
4907 | repeat = \"repeat-x\";\ |
||
4908 | }\ |
||
4909 | }\ |
||
4910 | var pattern = ctx.createPattern(img,repeat);\ |
||
4911 | ctx.rect(x0,y0,xsize,ysize);\ |
||
4912 | ctx.fillStyle = pattern;\ |
||
4913 | }\ |
||
4914 | ctx.fill();\ |
||
4915 | };\ |
||
4916 | ctx.restore();\ |
||
4917 | return;\ |
||
7653 | schaersvoo | 4918 | };",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 4919 | break; |
8224 | bpr | 4920 | |
7614 | schaersvoo | 4921 | case DRAW_DOTFILL:/* not used for userdraw */ |
4922 | fprintf(js_include_file,"\n<!-- draw dotfill -->\n\ |
||
8105 | schaersvoo | 4923 | var draw_dotfill = function(canvas_type,x0,y0,dx,dy,radius,color,opacity,xsize,ysize){\ |
7614 | schaersvoo | 4924 | var obj;\ |
4925 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
4926 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
4927 | }\ |
||
4928 | else\ |
||
4929 | {\ |
||
4930 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
4931 | };\ |
||
4932 | var ctx = obj.getContext(\"2d\");\ |
||
4933 | var x,y;\ |
||
4934 | ctx.closePath();\ |
||
4935 | ctx.save();\ |
||
7645 | schaersvoo | 4936 | snap_x = dx;snap_y = dy;\ |
7614 | schaersvoo | 4937 | ctx.fillStyle=\"rgba(\"+color+\",\"+opacity+\")\";\ |
4938 | for( x = x0 ; x < xsize+dx ; x = x + dx ){\ |
||
4939 | for( y = y0 ; y < ysize+dy ; y = y + dy ){\ |
||
4940 | ctx.arc(x,y,radius,0,2*Math.PI,false);\ |
||
4941 | ctx.closePath();\ |
||
4942 | }\ |
||
4943 | }\ |
||
4944 | ctx.fill();\ |
||
4945 | ctx.restore();\ |
||
7653 | schaersvoo | 4946 | return;};",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 4947 | break; |
7645 | schaersvoo | 4948 | |
7647 | schaersvoo | 4949 | case DRAW_DIAMONDFILL:/* not used for userdraw */ |
7614 | schaersvoo | 4950 | fprintf(js_include_file,"\n<!-- draw hatch fill -->\n\ |
8105 | schaersvoo | 4951 | var draw_diamondfill = function(canvas_type,x0,y0,dx,dy,linewidth,stroke_color,stroke_opacity,xsize,ysize){\ |
7614 | schaersvoo | 4952 | var obj;\ |
4953 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
4954 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
4955 | }\ |
||
4956 | else\ |
||
4957 | {\ |
||
4958 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
4959 | };\ |
||
4960 | var ctx = obj.getContext(\"2d\");\ |
||
4961 | var x;\ |
||
4962 | var y;\ |
||
4963 | ctx.save();\ |
||
4964 | ctx.lineWidth = linewidth;\ |
||
4965 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
4966 | y = ysize;\ |
||
4967 | for( x = x0 ; x < xsize ; x = x + dx ){\ |
||
4968 | ctx.moveTo(x,y0);\ |
||
4969 | ctx.lineTo(xsize,y);\ |
||
4970 | y = y - dy;\ |
||
4971 | };\ |
||
4972 | y = y0;\ |
||
4973 | for( x = xsize ; x > 0 ; x = x - dx){\ |
||
4974 | ctx.moveTo(x,ysize);\ |
||
4975 | ctx.lineTo(x0,y);\ |
||
4976 | y = y + dy;\ |
||
4977 | };\ |
||
4978 | x = x0;\ |
||
4979 | for( y = y0 ; y < ysize ; y = y + dy ){\ |
||
4980 | ctx.moveTo(xsize,y);\ |
||
4981 | ctx.lineTo(x,ysize);\ |
||
4982 | x = x + dx;\ |
||
4983 | };\ |
||
4984 | x = xsize;\ |
||
4985 | for( y = ysize ; y > y0 ; y = y - dy ){\ |
||
4986 | ctx.moveTo(x,y0);\ |
||
4987 | ctx.lineTo(x0,y);\ |
||
4988 | x = x - dx;\ |
||
4989 | };\ |
||
4990 | ctx.stroke();\ |
||
4991 | ctx.restore();\ |
||
4992 | return;\ |
||
7653 | schaersvoo | 4993 | }",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 4994 | break; |
8224 | bpr | 4995 | |
7647 | schaersvoo | 4996 | case DRAW_HATCHFILL:/* not used for userdraw */ |
4997 | fprintf(js_include_file,"\n<!-- draw hatch fill -->\n\ |
||
8105 | schaersvoo | 4998 | var draw_hatchfill = function(canvas_type,x0,y0,dx,dy,linewidth,stroke_color,stroke_opacity,xsize,ysize){\ |
7647 | schaersvoo | 4999 | var obj;\ |
5000 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
5001 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
5002 | }\ |
||
5003 | else\ |
||
5004 | {\ |
||
5005 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
5006 | };\ |
||
5007 | var ctx = obj.getContext(\"2d\");\ |
||
5008 | var x;\ |
||
5009 | var y;\ |
||
5010 | ctx.save();\ |
||
5011 | ctx.lineWidth = linewidth;\ |
||
5012 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
5013 | y = ysize;\ |
||
5014 | for( x = x0 ; x < xsize ; x = x + dx ){\ |
||
5015 | ctx.moveTo(x,y0);\ |
||
5016 | ctx.lineTo(xsize,y);\ |
||
5017 | y = y - dy;\ |
||
5018 | };\ |
||
5019 | y = y0;\ |
||
5020 | for( x = xsize ; x >= dx ; x = x - dx){\ |
||
5021 | ctx.moveTo(x,ysize);\ |
||
5022 | ctx.lineTo(x0,y);\ |
||
5023 | y = y + dy;\ |
||
5024 | };\ |
||
5025 | ctx.stroke();\ |
||
5026 | ctx.restore();\ |
||
5027 | return;\ |
||
7653 | schaersvoo | 5028 | };",canvas_root_id,canvas_root_id,canvas_root_id); |
7647 | schaersvoo | 5029 | break; |
7614 | schaersvoo | 5030 | case DRAW_CIRCLES:/* used for userdraw */ |
5031 | fprintf(js_include_file,"\n<!-- draw circles -->\n\ |
||
8105 | schaersvoo | 5032 | var draw_circles = function(ctx,x_points,y_points,radius,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_affine,affine_matrix){\ |
7614 | schaersvoo | 5033 | ctx.save();\ |
8071 | schaersvoo | 5034 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 5035 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
5036 | ctx.lineWidth = line_width;\ |
||
5037 | for(var p = 0 ; p < x_points.length ; p++ ){\ |
||
5038 | ctx.beginPath();\ |
||
5039 | ctx.arc(x_points[p],y_points[p],radius[p],0,2*Math.PI,false);\ |
||
5040 | ctx.closePath();\ |
||
5041 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
5042 | if(use_filled == 1){ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();}\ |
||
5043 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
5044 | ctx.stroke();\ |
||
5045 | }\ |
||
5046 | ctx.restore();\ |
||
5047 | return;\ |
||
7653 | schaersvoo | 5048 | };"); |
7614 | schaersvoo | 5049 | break; |
7663 | schaersvoo | 5050 | case DRAW_POLYLINE:/* user for userdraw : draw lines through points */ |
5051 | fprintf(js_include_file,"\n<!-- draw polyline -->\n\ |
||
8105 | schaersvoo | 5052 | var draw_polyline = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_affine,affine_matrix){\ |
7663 | schaersvoo | 5053 | ctx.save();\ |
8071 | schaersvoo | 5054 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7663 | schaersvoo | 5055 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
5056 | ctx.lineWidth = line_width;\ |
||
5057 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
5058 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
5059 | ctx.clearRect(0,0,xsize,ysize);\ |
||
5060 | ctx.beginPath();\ |
||
5061 | for(var p = 0 ; p < x_points.length-1 ; p++ ){\ |
||
5062 | ctx.moveTo(x_points[p],y_points[p]);\ |
||
5063 | ctx.lineTo(x_points[p+1],y_points[p+1]);\ |
||
5064 | }\ |
||
5065 | ctx.closePath();\ |
||
5066 | ctx.stroke();\ |
||
5067 | ctx.fillStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
5068 | for(var p = 0 ; p < x_points.length ; p++ ){\ |
||
5069 | ctx.beginPath();\ |
||
5070 | ctx.arc(x_points[p],y_points[p],line_width,0,2*Math.PI,false);\ |
||
5071 | ctx.closePath();ctx.fill();ctx.stroke();\ |
||
5072 | };\ |
||
5073 | ctx.restore();\ |
||
5074 | return;\ |
||
5075 | };"); |
||
5076 | break; |
||
8224 | bpr | 5077 | |
7614 | schaersvoo | 5078 | case DRAW_SEGMENTS:/* used for userdraw */ |
5079 | fprintf(js_include_file,"\n<!-- draw segments -->\n\ |
||
8105 | schaersvoo | 5080 | var draw_segments = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_affine,affine_matrix){\ |
7614 | schaersvoo | 5081 | ctx.save();\ |
8071 | schaersvoo | 5082 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 5083 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
5084 | ctx.lineWidth = line_width;\ |
||
5085 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
5086 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
5087 | for(var p = 0 ; p < x_points.length ; p = p+2 ){\ |
||
5088 | ctx.beginPath();\ |
||
5089 | ctx.moveTo(x_points[p],y_points[p]);\ |
||
5090 | ctx.lineTo(x_points[p+1],y_points[p+1]);\ |
||
5091 | ctx.closePath();\ |
||
5092 | ctx.stroke();\ |
||
5093 | }\ |
||
5094 | ctx.restore();\ |
||
5095 | return;\ |
||
5096 | };"); |
||
5097 | break; |
||
8224 | bpr | 5098 | |
7614 | schaersvoo | 5099 | case DRAW_LINES:/* used for userdraw */ |
5100 | fprintf(js_include_file,"\n<!-- draw lines -->\n\ |
||
5101 | function calc_line(x1,x2,y1,y2){\ |
||
5102 | var marge = 2;\ |
||
5103 | if(x1 < x2+marge && x1>x2-marge){\ |
||
5104 | return [x1,0,x1,ysize];\ |
||
5105 | };\ |
||
5106 | if(y1 < y2+marge && y1>y2-marge){\ |
||
5107 | return [0,y1,xsize,y1];\ |
||
5108 | };\ |
||
5109 | var Y1 = y1 - (x1)*(y2 - y1)/(x2 - x1);\ |
||
5110 | var Y2 = y1 + (xsize - x1)*(y2 - y1)/(x2 - x1);\ |
||
5111 | return [0,Y1,xsize,Y2];\ |
||
5112 | };\ |
||
8105 | schaersvoo | 5113 | var draw_lines = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_affine,affine_matrix){\ |
7614 | schaersvoo | 5114 | ctx.save();\ |
5115 | var line = new Array(4);\ |
||
8071 | schaersvoo | 5116 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 5117 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
5118 | ctx.lineWidth = line_width;\ |
||
5119 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
5120 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
5121 | for(var p = 0 ; p < x_points.length ; p = p+2 ){\ |
||
5122 | line = calc_line(x_points[p],x_points[p+1],y_points[p],y_points[p+1]);\ |
||
5123 | ctx.beginPath();\ |
||
5124 | ctx.moveTo(line[0],line[1]);\ |
||
5125 | ctx.lineTo(line[2],line[3]);\ |
||
5126 | ctx.closePath();\ |
||
5127 | ctx.stroke();\ |
||
5128 | }\ |
||
5129 | ctx.restore();\ |
||
5130 | return;\ |
||
5131 | };"); |
||
5132 | break; |
||
5133 | |||
8244 | schaersvoo | 5134 | case DRAW_DEMILINES:/* used for userdraw */ |
5135 | fprintf(js_include_file,"\n<!-- draw demilines -->\n\ |
||
5136 | function find_inf_point(x1,y1,x2,y2){\ |
||
5137 | if(x1<x2+2 && x1>x2-2){if(y1<y2){return [x1,y1,x1,ysize];}else{return [x1,0,x1,y1];};};\ |
||
5138 | var rc = (y2 - y1)/(x2 - x1);var q = y1 - (x1)*rc;\ |
||
5139 | if( x1 < x2 ){ return [x1,y1,xsize,rc*xsize+q];}else{return [x1,y1,0,q];};\ |
||
5140 | };\ |
||
5141 | var draw_demilines = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_affine,affine_matrix){\ |
||
5142 | ctx.save();\ |
||
5143 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
||
5144 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
||
5145 | ctx.lineWidth = line_width;\ |
||
5146 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
5147 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
5148 | var pair = new Array(4);\ |
||
5149 | for(var p = 0 ; p < x_points.length ; p = p+2 ){\ |
||
5150 | pair = find_inf_point(x_points[p],y_points[p],x_points[p+1],y_points[p+1]);\ |
||
5151 | ctx.beginPath();\ |
||
5152 | ctx.moveTo(pair[0],pair[1]);\ |
||
5153 | ctx.lineTo(pair[2],pair[3]);\ |
||
5154 | ctx.closePath();\ |
||
5155 | ctx.stroke();\ |
||
5156 | }\ |
||
5157 | ctx.restore();\ |
||
5158 | return;\ |
||
5159 | };"); |
||
5160 | break; |
||
5161 | |||
7614 | schaersvoo | 5162 | case DRAW_CROSSHAIRS:/* used for userdraw */ |
5163 | fprintf(js_include_file,"\n<!-- draw crosshairs -->\n\ |
||
8105 | schaersvoo | 5164 | var draw_crosshairs = function(ctx,x_points,y_points,line_width,crosshair_size,stroke_color,stroke_opacity,use_rotate,angle,use_affine,affine_matrix){\ |
8071 | schaersvoo | 5165 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 5166 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
5167 | ctx.lineWidth = line_width;\ |
||
5168 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
5169 | var x1,x2,y1,y2;\ |
||
5170 | for(var p = 0 ; p < x_points.length ; p++ ){\ |
||
5171 | x1 = x_points[p] - crosshair_size;\ |
||
5172 | x2 = x_points[p] + crosshair_size;\ |
||
5173 | y1 = y_points[p] - crosshair_size;\ |
||
5174 | y2 = y_points[p] + crosshair_size;\ |
||
5175 | ctx.beginPath();\ |
||
5176 | ctx.moveTo(x1,y1);\ |
||
5177 | ctx.lineTo(x2,y2);\ |
||
5178 | ctx.closePath();\ |
||
5179 | ctx.stroke();\ |
||
5180 | ctx.beginPath();\ |
||
5181 | ctx.moveTo(x2,y1);\ |
||
5182 | ctx.lineTo(x1,y2);\ |
||
5183 | ctx.closePath();\ |
||
5184 | ctx.stroke();\ |
||
5185 | }\ |
||
5186 | ctx.restore();\ |
||
5187 | return;\ |
||
7653 | schaersvoo | 5188 | };"); |
7614 | schaersvoo | 5189 | break; |
5190 | |||
5191 | case DRAW_RECTS:/* used for userdraw */ |
||
5192 | fprintf(js_include_file,"\n<!-- draw rects -->\n\ |
||
8105 | schaersvoo | 5193 | var draw_rects = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_affine,affine_matrix){\ |
7614 | schaersvoo | 5194 | ctx.save();\ |
8071 | schaersvoo | 5195 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 5196 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
5197 | ctx.lineWidth = line_width;\ |
||
5198 | ctx.strokeStyle = \"rgba('+stroke_color+','+stroke_opacity+')\";\ |
||
5199 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];}};\ |
||
5200 | for(var p = 0 ; p < x_points.length ; p = p + 2){\ |
||
5201 | ctx.beginPath();\ |
||
5202 | ctx.rect(x_points[p],y_points[p],x_points[p+1]-x_points[p],y_points[p+1]-y_points[p]);\ |
||
5203 | ctx.closePath();\ |
||
5204 | if(use_filled == 1 ){ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();}\ |
||
5205 | ctx.stroke();\ |
||
5206 | };\ |
||
5207 | ctx.restore();\ |
||
5208 | return;\ |
||
7653 | schaersvoo | 5209 | };"); |
7614 | schaersvoo | 5210 | break; |
5211 | |||
5212 | case DRAW_ROUNDRECTS:/* used for userdraw */ |
||
5213 | fprintf(js_include_file,"\n<!-- draw round rects -->\n\ |
||
8105 | schaersvoo | 5214 | var draw_roundrects = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,use_rotate,angle,use_affine,affine_matrix){\ |
7614 | schaersvoo | 5215 | ctx.save();\ |
8071 | schaersvoo | 5216 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 5217 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
5218 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
||
5219 | var x,y,w,h,r;\ |
||
5220 | for(var p = 0; p < x_points.length; p = p+2){\ |
||
5221 | 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);\ |
||
5222 | ctx.beginPath();ctx.moveTo(x + r, y);\ |
||
5223 | ctx.lineTo(x + w - r, y);\ |
||
5224 | ctx.quadraticCurveTo(x + w, y, x + w, y + r);\ |
||
5225 | ctx.lineTo(x + w, y + h - r);\ |
||
5226 | ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);\ |
||
5227 | ctx.lineTo(x + r, y + h);\ |
||
5228 | ctx.quadraticCurveTo(x, y + h, x, y + h - r);\ |
||
5229 | ctx.lineTo(x, y + r);\ |
||
5230 | ctx.quadraticCurveTo(x, y, x + r, y);\ |
||
5231 | ctx.closePath();if( use_dashed == 1 ){ctx.setLineDash([dashtype0,dashtype1]);};\ |
||
5232 | ctx.strokeStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
5233 | if( use_filled == 1 ){ctx.fillStyle =\"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();};\ |
||
5234 | ctx.stroke();\ |
||
5235 | }\ |
||
5236 | ctx.restore();\ |
||
7653 | schaersvoo | 5237 | };"); |
8224 | bpr | 5238 | break; |
7614 | schaersvoo | 5239 | |
5240 | case DRAW_ELLIPSES:/* not used for userdraw */ |
||
5241 | fprintf(js_include_file,"\n<!-- draw ellipses -->\n\ |
||
8105 | schaersvoo | 5242 | var draw_ellipses = function(canvas_type,x_points,y_points,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,use_rotate,angle,use_affine,affine_matrix){\ |
7614 | schaersvoo | 5243 | var obj;\ |
5244 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
5245 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
5246 | }\ |
||
5247 | else\ |
||
5248 | {\ |
||
5249 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
5250 | };\ |
||
5251 | var ctx = obj.getContext(\"2d\");\ |
||
5252 | ctx.save();\ |
||
8071 | schaersvoo | 5253 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 5254 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
5255 | var cx,cy,ry,rx;\ |
||
5256 | ctx.lineWidth = line_width;\ |
||
5257 | if( use_filled == 1 ){ctx.fillStyle =\"rgba(\"+fill_color+\",\"+fill_opacity+\")\";};\ |
||
5258 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
5259 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
5260 | for(var p=0;p< x_points.length;p = p+2){\ |
||
5261 | ctx.beginPath();\ |
||
5262 | cx = x_points[p];cy = y_points[p];rx = 0.25*x_points[p+1];ry = 0.25*y_points[p+1];\ |
||
5263 | ctx.translate(cx - rx, cy - ry);\ |
||
5264 | ctx.scale(rx, ry);\ |
||
5265 | ctx.arc(1, 1, 1, 0, 2 * Math.PI, false);\ |
||
5266 | if( use_filled == 1 ){ctx.fill();}\ |
||
5267 | ctx.stroke();\ |
||
5268 | };\ |
||
5269 | ctx.restore();\ |
||
7653 | schaersvoo | 5270 | };",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 5271 | break; |
5272 | |||
5273 | case DRAW_PATHS: /* used for userdraw */ |
||
5274 | fprintf(js_include_file,"\n<!-- draw paths -->\n\ |
||
8105 | schaersvoo | 5275 | var draw_paths = function(ctx,x_points,y_points,line_width,closed_path,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,use_rotate,angle,use_affine,affine_matrix){\ |
7614 | schaersvoo | 5276 | ctx.save();\ |
8071 | schaersvoo | 5277 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 5278 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
5279 | ctx.lineWidth = line_width;\ |
||
5280 | ctx.lineJoin = \"round\";\ |
||
5281 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
5282 | ctx.beginPath();\ |
||
5283 | ctx.moveTo(x_points[0],y_points[0]);\ |
||
5284 | for(var p = 1 ; p < x_points.length ; p++ ){ctx.lineTo(x_points[p],y_points[p]);}\ |
||
5285 | if(closed_path == 1){ctx.lineTo(x_points[0],y_points[0]);ctx.closePath();}\ |
||
5286 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
5287 | if(use_filled == 1){ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();}\ |
||
5288 | ctx.stroke();\ |
||
5289 | ctx.restore();\ |
||
5290 | return;\ |
||
5291 | };"); |
||
8224 | bpr | 5292 | |
7614 | schaersvoo | 5293 | break; |
5294 | case DRAW_ARROWS:/* used for userdraw */ |
||
5295 | fprintf(js_include_file,"\n<!-- draw arrows -->\n\ |
||
8105 | schaersvoo | 5296 | var draw_arrows = function(ctx,x_points,y_points,arrow_head,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,type,use_rotate,angle,use_affine,affine_matrix){\ |
7614 | schaersvoo | 5297 | ctx.save();\ |
8071 | schaersvoo | 5298 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 5299 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
5300 | ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
5301 | ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
5302 | ctx.lineWidth = line_width;\ |
||
5303 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
5304 | ctx.lineCap = \"round\";\ |
||
5305 | var x1,y1,x2,y2,dx,dy,len;\ |
||
5306 | for(var p = 0 ; p < x_points.length - 1 ; p = p +2){\ |
||
7874 | schaersvoo | 5307 | ctx.save();\ |
7614 | schaersvoo | 5308 | x1 = x_points[p];y1 = y_points[p];x2 = x_points[p+1];y2 = y_points[p+1];dx = x2 - x1;dy = y2 - y1;\ |
5309 | len = Math.sqrt(dx*dx+dy*dy);\ |
||
5310 | ctx.translate(x2,y2);\ |
||
5311 | ctx.rotate(Math.atan2(dy,dx));\ |
||
5312 | ctx.lineCap = \"round\";\ |
||
5313 | ctx.beginPath();\ |
||
5314 | ctx.moveTo(0,0);\ |
||
5315 | ctx.lineTo(-len,0);\ |
||
5316 | ctx.closePath();\ |
||
5317 | ctx.stroke();\ |
||
5318 | ctx.beginPath();\ |
||
5319 | ctx.moveTo(0,0);\ |
||
5320 | ctx.lineTo(-1*arrow_head,-0.5*arrow_head);\ |
||
5321 | ctx.lineTo(-1*arrow_head, 0.5*arrow_head);\ |
||
5322 | ctx.closePath();\ |
||
5323 | ctx.fill();\ |
||
7874 | schaersvoo | 5324 | ctx.restore();\ |
7614 | schaersvoo | 5325 | if( type == 2 ){\ |
5326 | ctx.save();\ |
||
5327 | ctx.translate(x1,y1);\ |
||
5328 | ctx.rotate(Math.atan2(-dy,-dx));\ |
||
5329 | ctx.beginPath();\ |
||
5330 | ctx.moveTo(0,0);\ |
||
5331 | ctx.lineTo(-1*arrow_head,-0.5*arrow_head);\ |
||
5332 | ctx.lineTo(-1*arrow_head, 0.5*arrow_head);\ |
||
5333 | ctx.closePath();\ |
||
5334 | ctx.stroke();\ |
||
5335 | ctx.fill();\ |
||
7874 | schaersvoo | 5336 | ctx.restore();\ |
7614 | schaersvoo | 5337 | }\ |
5338 | }\ |
||
5339 | ctx.restore();\ |
||
5340 | return;\ |
||
7653 | schaersvoo | 5341 | };"); |
7614 | schaersvoo | 5342 | break; |
5343 | |||
5344 | case DRAW_VIDEO:/* not used for userdraw */ |
||
5345 | fprintf(js_include_file,"\n<!-- draw video -->\n\ |
||
8105 | schaersvoo | 5346 | var draw_video = function(canvas_root_id,x,y,w,h,URL){\ |
7614 | schaersvoo | 5347 | var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\ |
5348 | var video_div = document.createElement(\"div\");\ |
||
5349 | canvas_div.appendChild(video_div);\ |
||
5350 | video_div.style.position = \"absolute\";\ |
||
5351 | video_div.style.left = x+\"px\";\ |
||
5352 | video_div.style.top = y+\"px\";\ |
||
5353 | video_div.style.width = w+\"px\";\ |
||
5354 | video_div.style.height = h+\"px\";\ |
||
5355 | var video = document.createElement(\"video\");\ |
||
5356 | video_div.appendChild(video);\ |
||
5357 | video.style.width = w+\"px\";\ |
||
5358 | video.style.height = h+\"px\";\ |
||
5359 | video.autobuffer = true;\ |
||
5360 | video.controls = true;video.autoplay = false;\ |
||
5361 | var src = document.createElement(\"source\");\ |
||
5362 | src.type = \"video/mp4\";\ |
||
5363 | src.src = URL;\ |
||
5364 | video.appendChild(src);\ |
||
5365 | video.load();\ |
||
5366 | return;\ |
||
8224 | bpr | 5367 | };"); |
7614 | schaersvoo | 5368 | break; |
8224 | bpr | 5369 | |
7614 | schaersvoo | 5370 | case DRAW_AUDIO:/* not used for userdraw */ |
5371 | fprintf(js_include_file,"\n<!-- draw audio -->\n\ |
||
8105 | schaersvoo | 5372 | var draw_audio = function(canvas_root_id,x,y,w,h,loop,visible,URL1,URL2){\ |
7614 | schaersvoo | 5373 | var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\ |
5374 | var audio_div = document.createElement(\"div\");\ |
||
5375 | canvas_div.appendChild(audio_div);\ |
||
5376 | audio_div.style.position = \"absolute\";\ |
||
5377 | audio_div.style.left = x+\"px\";\ |
||
5378 | audio_div.style.top = y+\"px\";\ |
||
5379 | audio_div.style.width = w+\"px\";\ |
||
5380 | audio_div.style.height = h+\"px\";\ |
||
5381 | var audio = document.createElement(\"audio\");\ |
||
5382 | audio_div.appendChild(audio);\ |
||
5383 | audio.setAttribute(\"style\",\"width:\"+w+\"px;height:\"+h+\"px\");\ |
||
5384 | audio.autobuffer = true;\ |
||
5385 | if(visible == 1 ){ audio.controls = true;audio.autoplay = false;}else{ audio.controls = false;audio.autoplay = true;}\ |
||
5386 | if(loop == 1 ){ audio.loop = true;}else{ audio.loop = false;}\ |
||
5387 | var src1 = document.createElement(\"source\");\ |
||
5388 | src1.type = \"audio/ogg\";\ |
||
5389 | src1.src = URL1;\ |
||
5390 | audio.appendChild(src1);\ |
||
5391 | var src2 = document.createElement(\"source\");\ |
||
5392 | src2.type = \"audio/mpeg\";\ |
||
5393 | src2.src = URL2;\ |
||
5394 | audio.appendChild(src2);\ |
||
5395 | audio.load();\ |
||
5396 | return;\ |
||
7653 | schaersvoo | 5397 | };"); |
7614 | schaersvoo | 5398 | break; |
8224 | bpr | 5399 | |
7614 | schaersvoo | 5400 | case DRAW_HTTP:/* not used for userdraw */ |
5401 | fprintf(js_include_file,"\n<!-- draw http -->\n\ |
||
8105 | schaersvoo | 5402 | var draw_http = function(canvas_root_id,x,y,w,h,URL){\ |
7614 | schaersvoo | 5403 | var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\ |
5404 | var http_div = document.createElement(\"div\");\ |
||
5405 | var iframe = document.createElement(\"iframe\");\ |
||
5406 | canvas_div.appendChild(http_div);\ |
||
5407 | http_div.appendChild(iframe);\ |
||
5408 | iframe.src = URL;\ |
||
5409 | iframe.setAttribute(\"width\",w);\ |
||
5410 | iframe.setAttribute(\"height\",h);\ |
||
5411 | return;\ |
||
7653 | schaersvoo | 5412 | };"); |
7614 | schaersvoo | 5413 | break; |
8224 | bpr | 5414 | |
7614 | schaersvoo | 5415 | case DRAW_XML: |
5416 | fprintf(js_include_file,"\n<!-- draw xml -->\n\ |
||
8105 | schaersvoo | 5417 | var draw_xml = function(canvas_root_id,x,y,w,h,mathml,onclick){\ |
7614 | schaersvoo | 5418 | var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\ |
5419 | var xml_div = document.createElement(\"div\");\ |
||
5420 | canvas_div.appendChild(xml_div);\ |
||
5421 | xml_div.innerHTML = mathml;\ |
||
5422 | if(onclick != 0){\ |
||
5423 | xml_div.onclick = function(){\ |
||
5424 | reply[0] = onclick;\ |
||
5425 | alert(\"send \"+onclick+\" ?\");\ |
||
5426 | };\ |
||
5427 | };\ |
||
5428 | xml_div.style.position = \"absolute\";\ |
||
5429 | xml_div.style.left = x+\"px\";\ |
||
5430 | xml_div.style.top = y+\"px\";\ |
||
5431 | xml_div.style.width = w+\"px\";\ |
||
5432 | xml_div.style.height = h+\"px\";\ |
||
5433 | return;\ |
||
7653 | schaersvoo | 5434 | };" |
7614 | schaersvoo | 5435 | ); |
5436 | break; |
||
7654 | schaersvoo | 5437 | case DRAW_SGRAPH: |
8224 | bpr | 5438 | /* |
7654 | schaersvoo | 5439 | xstart = given |
5440 | ystart = given |
||
5441 | sgraph(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily) |
||
5442 | */ |
||
5443 | fprintf(js_include_file,"\n<!-- draw sgraph -->\n\ |
||
8105 | schaersvoo | 5444 | var draw_sgraph = function(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily,opacity,font_size){\ |
7658 | schaersvoo | 5445 | 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);};\ |
5446 | var ctx = obj.getContext(\"2d\");\ |
||
5447 | ctx.font = fontfamily;\ |
||
5448 | var minor_opacity = 0.8*opacity;\ |
||
5449 | ctx.clearRect(0,0,xsize,ysize);\ |
||
7976 | schaersvoo | 5450 | var zero_x = 0.1*xsize;\ |
5451 | var zero_y = 0.9*ysize;\ |
||
8129 | schaersvoo | 5452 | var snor_x;var snor_y;\ |
7654 | schaersvoo | 5453 | if( xstart != xmin){\ |
7658 | schaersvoo | 5454 | snor_x = 0.1*xsize;\ |
5455 | }\ |
||
5456 | else\ |
||
5457 | {\ |
||
5458 | snor_x = 0;\ |
||
5459 | xstart = xmin;\ |
||
5460 | };\ |
||
5461 | ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\ |
||
5462 | ctx.lineWidth = 2;\ |
||
5463 | ctx.beginPath();\ |
||
5464 | ctx.moveTo(xsize,zero_y);\ |
||
5465 | ctx.lineTo(zero_x,zero_y);\ |
||
5466 | ctx.lineTo(zero_x,0);\ |
||
5467 | ctx.stroke();\ |
||
5468 | ctx.closePath();\ |
||
5469 | ctx.beginPath();\ |
||
5470 | ctx.moveTo(zero_x,zero_y);\ |
||
5471 | ctx.lineTo(zero_x + 0.25*snor_x,zero_y - 0.1*snor_x);\ |
||
5472 | ctx.lineTo(zero_x + 0.5*snor_x,zero_y + 0.1*snor_x);\ |
||
5473 | ctx.lineTo(zero_x + 0.75*snor_x,zero_y - 0.1*snor_x);\ |
||
5474 | ctx.lineTo(zero_x + snor_x,zero_y);\ |
||
5475 | ctx.stroke();\ |
||
5476 | ctx.closePath();\ |
||
5477 | ctx.beginPath();\ |
||
5478 | var num = xstart;\ |
||
7660 | schaersvoo | 5479 | var flipflop = 1;\ |
7658 | schaersvoo | 5480 | var step_x = xmajor*(xsize - zero_x - snor_x)/(xmax - xstart);\ |
7976 | schaersvoo | 5481 | var txtsize;var txt_marge=step_x - 5;\ |
7658 | schaersvoo | 5482 | for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\ |
7976 | schaersvoo | 5483 | txtsize = ctx.measureText(num).width;\ |
5484 | if( txtsize > txt_marge ){if( flipflop == 1 ){flipflop = 0;}else{flipflop = 1;};};\ |
||
5485 | if( flipflop == 1){\ |
||
5486 | ctx.fillText(num,x - 0.5*txtsize,zero_y+font_size);\ |
||
5487 | }\ |
||
5488 | else\ |
||
5489 | {\ |
||
5490 | ctx.fillText(num,x - 0.5*txtsize,zero_y+2*font_size);\ |
||
5491 | }\ |
||
5492 | num = num + xmajor;\ |
||
7658 | schaersvoo | 5493 | };\ |
5494 | ctx.stroke();\ |
||
5495 | ctx.closePath();\ |
||
5496 | ctx.lineWidth = 1;\ |
||
5497 | ctx.beginPath();\ |
||
5498 | for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\ |
||
5499 | ctx.moveTo(x,zero_y);\ |
||
5500 | ctx.lineTo(x,0);\ |
||
5501 | };\ |
||
5502 | ctx.stroke();\ |
||
5503 | ctx.closePath();\ |
||
5504 | if( xminor > 1){\ |
||
5505 | ctx.lineWidth = 0.5;\ |
||
5506 | ctx.beginPath();\ |
||
5507 | ctx.strokeStyle = \"rgba(\"+minorcolor+\",\"+minor_opacity+\")\";\ |
||
5508 | var minor_step_x = step_x / xminor;\ |
||
5509 | var nx;\ |
||
5510 | for(var x = zero_x+snor_x; x < xsize;x = x + step_x){\ |
||
5511 | num = 1;\ |
||
5512 | for(var p = 1 ; p < xminor ; p++){\ |
||
5513 | nx = x + num*minor_step_x;\ |
||
5514 | ctx.moveTo(nx,zero_y);\ |
||
5515 | ctx.lineTo(nx,0);\ |
||
5516 | num++;\ |
||
5517 | };\ |
||
5518 | };\ |
||
5519 | ctx.stroke();\ |
||
5520 | ctx.closePath();\ |
||
5521 | ctx.beginPath();\ |
||
5522 | ctx.lineWidth = 2;\ |
||
5523 | ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\ |
||
5524 | for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\ |
||
5525 | ctx.moveTo(x,zero_y);ctx.lineTo(x,zero_y - 12);\ |
||
5526 | };\ |
||
5527 | for(var x = zero_x+snor_x ; x < xsize;x = x + minor_step_x){\ |
||
5528 | ctx.moveTo(x,zero_y);ctx.lineTo(x,zero_y - 6);\ |
||
5529 | };\ |
||
5530 | ctx.stroke();\ |
||
5531 | ctx.closePath();\ |
||
5532 | ctx.lineWidth = 0.5;\ |
||
5533 | };\ |
||
5534 | xmin = xstart - (xmajor*(zero_x+snor_x)/step_x);\ |
||
5535 | if( ystart != ymin){\ |
||
5536 | snor_y = 0.1*ysize;\ |
||
5537 | }\ |
||
5538 | else\ |
||
5539 | {\ |
||
5540 | snor_y = 0;\ |
||
5541 | ystart = ymin;\ |
||
5542 | };\ |
||
5543 | ctx.lineWidth = 2;\ |
||
5544 | ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\ |
||
5545 | ctx.beginPath();\ |
||
5546 | ctx.moveTo(zero_x,zero_y);\ |
||
5547 | ctx.lineTo(zero_x - 0.1*snor_y,zero_y - 0.25*snor_y);\ |
||
5548 | ctx.lineTo(zero_x + 0.1*snor_y,zero_y - 0.5*snor_y);\ |
||
5549 | ctx.lineTo(zero_x - 0.1*snor_y,zero_y - 0.75*snor_y);\ |
||
5550 | ctx.lineTo(zero_x,zero_y - snor_y);\ |
||
5551 | ctx.stroke();\ |
||
5552 | ctx.closePath();\ |
||
5553 | ctx.beginPath();\ |
||
5554 | ctx.lineWidth = 1;\ |
||
5555 | num = ystart;\ |
||
5556 | var step_y = ymajor*(zero_y - snor_y)/(ymax - ystart);\ |
||
5557 | for(var y = zero_y - snor_y ; y > 0; y = y - step_y){\ |
||
5558 | ctx.moveTo(zero_x,y);\ |
||
5559 | ctx.lineTo(xsize,y);\ |
||
5560 | ctx.fillText(num,zero_x - ctx.measureText(num+\" \").width,parseInt(y+0.2*font_size));\ |
||
5561 | num = num + ymajor;\ |
||
5562 | };\ |
||
5563 | ctx.stroke();\ |
||
5564 | ctx.closePath();\ |
||
5565 | if( yminor > 1){\ |
||
5566 | ctx.lineWidth = 0.5;\ |
||
5567 | ctx.beginPath();\ |
||
5568 | ctx.strokeStyle = \"rgba(\"+minorcolor+\",\"+minor_opacity+\")\";\ |
||
5569 | var minor_step_y = step_y / yminor;\ |
||
5570 | var ny;\ |
||
5571 | for(var y = 0 ; y < zero_y - snor_y ;y = y + step_y){\ |
||
5572 | num = 1;\ |
||
5573 | for(var p = 1 ;p < yminor;p++){\ |
||
5574 | ny = y + num*minor_step_y;\ |
||
5575 | ctx.moveTo(zero_x,ny);\ |
||
5576 | ctx.lineTo(xsize,ny);\ |
||
5577 | num++;\ |
||
5578 | };\ |
||
5579 | };\ |
||
5580 | ctx.stroke();\ |
||
5581 | ctx.closePath();\ |
||
5582 | ctx.lineWidth = 2;\ |
||
5583 | ctx.beginPath();\ |
||
5584 | ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\ |
||
5585 | for(var y = zero_y - snor_y ; y > 0 ;y = y - step_y){\ |
||
5586 | ctx.moveTo(zero_x,y);\ |
||
5587 | ctx.lineTo(zero_x+12,y);\ |
||
5588 | };\ |
||
5589 | for(var y = zero_y - snor_y ; y > 0 ;y = y - minor_step_y){\ |
||
5590 | ctx.moveTo(zero_x,y);\ |
||
5591 | ctx.lineTo(zero_x+6,y);\ |
||
5592 | };\ |
||
5593 | ctx.stroke();\ |
||
5594 | ctx.closePath();\ |
||
5595 | };\ |
||
5596 | ymin = ystart - (ymajor*(ysize - zero_y + snor_y)/step_y);\ |
||
7654 | schaersvoo | 5597 | if( typeof legend%d !== 'undefined' ){\ |
5598 | ctx.globalAlpha = 1.0;\ |
||
5599 | var y_offset = 2*font_size;\ |
||
5600 | var txt;var txt_size;\ |
||
5601 | var x_offset = xsize - 2*font_size;\ |
||
5602 | var l_length = legend%d.length;var barcolor = new Array();\ |
||
5603 | if( typeof legendcolors%d !== 'undefined' ){\ |
||
5604 | for(var p = 0 ; p < l_length ; p++){\ |
||
5605 | barcolor[p] = legendcolors%d[p];\ |
||
5606 | };\ |
||
5607 | }else{\ |
||
5608 | if( barcolor.length == 0 ){\ |
||
5609 | for(var p = 0 ; p < l_length ; p++){\ |
||
5610 | barcolor[p] = stroke_color;\ |
||
5611 | };\ |
||
5612 | };\ |
||
5613 | };\ |
||
5614 | for(var p = 0; p < l_length; p++){\ |
||
5615 | ctx.fillStyle = barcolor[p];\ |
||
5616 | txt = legend%d[p];\ |
||
5617 | txt_size = ctx.measureText(txt).width;\ |
||
5618 | ctx.fillText(legend%d[p],x_offset - txt_size, y_offset);\ |
||
5619 | y_offset = parseInt(y_offset + 1.5*font_size);\ |
||
5620 | };\ |
||
5621 | };\ |
||
7660 | schaersvoo | 5622 | if( typeof xaxislabel !== 'undefined' ){\ |
7658 | schaersvoo | 5623 | ctx.fillStyle = \'#000000\';\ |
5624 | var txt_size = ctx.measureText(xaxislabel).width + 4 ;\ |
||
5625 | ctx.fillText(xaxislabel,xsize - txt_size, zero_y - 7);\ |
||
5626 | };\ |
||
7660 | schaersvoo | 5627 | if( typeof yaxislabel !== 'undefined'){\ |
7658 | schaersvoo | 5628 | ctx.save();\ |
5629 | ctx.fillStyle = \'#000000\';\ |
||
5630 | var txt_size = ctx.measureText(yaxislabel).width;\ |
||
5631 | ctx.translate(zero_x+8 + font_size,txt_size+font_size);\ |
||
5632 | ctx.rotate(-0.5*Math.PI);\ |
||
5633 | ctx.fillText(yaxislabel,0,0);\ |
||
7874 | schaersvoo | 5634 | ctx.restore();\ |
7658 | schaersvoo | 5635 | };\ |
7654 | schaersvoo | 5636 | };\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); |
5637 | break; |
||
7614 | schaersvoo | 5638 | |
5639 | case DRAW_GRID:/* not used for userdraw */ |
||
5640 | fprintf(js_include_file,"\n<!-- draw grid -->\n\ |
||
8105 | schaersvoo | 5641 | var draw_grid%d = function(canvas_type,precision,stroke_opacity,xmajor,ymajor,xminor,yminor,tics_length,line_width,stroke_color,axis_color,font_size,font_family,use_axis,use_axis_numbering,use_rotate,angle,use_affine,affine_matrix,use_dashed,dashtype0,dashtype1,font_color,fill_opacity){\ |
7988 | schaersvoo | 5642 | 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);};\ |
5643 | var ctx = obj.getContext(\"2d\");ctx.clearRect(0,0,xsize,ysize);\ |
||
7614 | schaersvoo | 5644 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
5645 | ctx.save();\ |
||
8071 | schaersvoo | 5646 | if( use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);};\ |
7614 | schaersvoo | 5647 | if( use_rotate == 1 ){ctx.translate(x2px(0),y2px(0));ctx.rotate(angle*Math.PI/180);ctx.translate(-1*(x2px(0)),-1*(y2px(0)));};\ |
5648 | var stroke_color = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
5649 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+1.0+\")\";\ |
||
5650 | var axis_color = \"rgba(\"+axis_color+\",\"+stroke_opacity+\")\";\ |
||
5651 | ctx.font = font_family;\ |
||
7988 | schaersvoo | 5652 | var barcolor = new Array();\ |
7614 | schaersvoo | 5653 | var xstep = xsize*xmajor/(xmax - xmin);\ |
5654 | var ystep = ysize*ymajor/(ymax - ymin);\ |
||
5655 | var x2step = xstep / xminor;\ |
||
5656 | var y2step = ystep / yminor;\ |
||
7996 | schaersvoo | 5657 | var zero_x = x2px(0);;var zero_y = y2px(0);var f_x;var f_y;\ |
5658 | if(xmin < 0 ){ f_x = -1;}else{ f_x = 1;}\ |
||
5659 | if(ymin < 0 ){ f_y = -1;}else{ f_y = 1;}\ |
||
7614 | schaersvoo | 5660 | ctx.beginPath();\ |
5661 | ctx.lineWidth = line_width;\ |
||
5662 | ctx.strokeStyle = stroke_color;\ |
||
5663 | for(var p = zero_x ; p < xsize; p = p + xstep){\ |
||
5664 | ctx.moveTo(p,0);\ |
||
5665 | ctx.lineTo(p,ysize);\ |
||
5666 | };\ |
||
5667 | for(var p = zero_x ; p > 0; p = p - xstep){\ |
||
5668 | ctx.moveTo(p,0);\ |
||
5669 | ctx.lineTo(p,ysize);\ |
||
5670 | };\ |
||
5671 | for(var p = zero_y ; p < ysize; p = p + ystep){\ |
||
5672 | ctx.moveTo(0,p);\ |
||
5673 | ctx.lineTo(xsize,p);\ |
||
5674 | };\ |
||
5675 | for(var p = zero_y ; p > 0; p = p - ystep){\ |
||
5676 | ctx.moveTo(0,p);\ |
||
5677 | ctx.lineTo(xsize,p);\ |
||
5678 | };\ |
||
5679 | if( typeof xaxislabel !== 'undefined' ){\ |
||
5680 | ctx.save();\ |
||
5681 | ctx.font = \"italic \"+font_size+\"px Ariel\";\ |
||
5682 | var corr = ctx.measureText(xaxislabel).width;\ |
||
5683 | ctx.fillText(xaxislabel,xsize - 1.5*corr,zero_y - tics_length - 0.4*font_size);\ |
||
5684 | ctx.restore();\ |
||
5685 | };\ |
||
5686 | if( typeof yaxislabel !== 'undefined' ){\ |
||
5687 | ctx.save();\ |
||
5688 | ctx.font = \"italic \"+font_size+\"px Ariel\";\ |
||
7988 | schaersvoo | 5689 | var corr = ctx.measureText(yaxislabel).width;\ |
7614 | schaersvoo | 5690 | ctx.translate(zero_x+tics_length + font_size,corr+font_size);\ |
5691 | ctx.rotate(-0.5*Math.PI);\ |
||
5692 | ctx.fillText(yaxislabel,0,0);\ |
||
5693 | ctx.restore();\ |
||
5694 | };\ |
||
5695 | ctx.stroke();\ |
||
5696 | ctx.closePath();\ |
||
5697 | if( use_axis == 1 ){\ |
||
7988 | schaersvoo | 5698 | ctx.save();\ |
7614 | schaersvoo | 5699 | ctx.beginPath();\ |
5700 | ctx.strokeStyle = stroke_color;\ |
||
5701 | ctx.lineWidth = 0.6*line_width;\ |
||
5702 | for(var p = zero_x ; p < xsize; p = p + x2step){\ |
||
5703 | ctx.moveTo(p,0);\ |
||
5704 | ctx.lineTo(p,ysize);\ |
||
5705 | };\ |
||
5706 | for(var p = zero_x ; p > 0; p = p - x2step){\ |
||
5707 | ctx.moveTo(p,0);\ |
||
5708 | ctx.lineTo(p,ysize);\ |
||
5709 | };\ |
||
5710 | for(var p = zero_y ; p < ysize; p = p + y2step){\ |
||
5711 | ctx.moveTo(0,p);\ |
||
5712 | ctx.lineTo(xsize,p);\ |
||
5713 | };\ |
||
5714 | for(var p = zero_y ; p > 0; p = p - y2step){\ |
||
5715 | ctx.moveTo(0,p);\ |
||
5716 | ctx.lineTo(xsize,p);\ |
||
5717 | };\ |
||
5718 | ctx.stroke();\ |
||
5719 | ctx.closePath();\ |
||
5720 | ctx.beginPath();\ |
||
5721 | ctx.lineWidth = 2*line_width;\ |
||
5722 | ctx.strokeStyle = axis_color;\ |
||
5723 | ctx.moveTo(0,zero_y);\ |
||
5724 | ctx.lineTo(xsize,zero_y);\ |
||
5725 | ctx.moveTo(zero_x,0);\ |
||
5726 | ctx.lineTo(zero_x,ysize);\ |
||
5727 | ctx.stroke();\ |
||
5728 | ctx.closePath();\ |
||
5729 | ctx.lineWidth = line_width+0.5;\ |
||
5730 | ctx.beginPath();\ |
||
5731 | for(var p = zero_x ; p < xsize; p = p + xstep){\ |
||
5732 | ctx.moveTo(p,zero_y-tics_length);\ |
||
5733 | ctx.lineTo(p,zero_y+tics_length);\ |
||
5734 | };\ |
||
5735 | for(var p = zero_x ; p > 0; p = p - xstep){\ |
||
5736 | ctx.moveTo(p,zero_y-tics_length);\ |
||
5737 | ctx.lineTo(p,zero_y+tics_length);\ |
||
5738 | };\ |
||
5739 | for(var p = zero_y ; p < ysize; p = p + ystep){\ |
||
5740 | ctx.moveTo(zero_x-tics_length,p);\ |
||
5741 | ctx.lineTo(zero_x+tics_length,p);\ |
||
5742 | };\ |
||
5743 | for(var p = zero_y ; p > 0; p = p - ystep){\ |
||
5744 | ctx.moveTo(zero_x-tics_length,p);\ |
||
5745 | ctx.lineTo(zero_x+tics_length,p);\ |
||
5746 | };\ |
||
5747 | for(var p = zero_x ; p < xsize; p = p + x2step){\ |
||
5748 | ctx.moveTo(p,zero_y-0.5*tics_length);\ |
||
5749 | ctx.lineTo(p,zero_y+0.5*tics_length);\ |
||
5750 | };\ |
||
5751 | for(var p = zero_x ; p > 0; p = p - x2step){\ |
||
5752 | ctx.moveTo(p,zero_y-0.5*tics_length);\ |
||
5753 | ctx.lineTo(p,zero_y+0.5*tics_length);\ |
||
5754 | };\ |
||
5755 | for(var p = zero_y ; p < ysize; p = p + y2step){\ |
||
5756 | ctx.moveTo(zero_x-0.5*tics_length,p);\ |
||
5757 | ctx.lineTo(zero_x+0.5*tics_length,p);\ |
||
5758 | };\ |
||
5759 | for(var p = zero_y ; p > 0; p = p - y2step){\ |
||
5760 | ctx.moveTo(zero_x-0.5*tics_length,p);\ |
||
5761 | ctx.lineTo(zero_x+0.5*tics_length,p);\ |
||
5762 | };\ |
||
5763 | ctx.stroke();\ |
||
5764 | ctx.closePath();\ |
||
7988 | schaersvoo | 5765 | ctx.restore();\ |
5766 | };\ |
||
5767 | if( use_axis_numbering == 1 ){\ |
||
5768 | ctx.save();\ |
||
5769 | ctx.fillColor = axis_color;\ |
||
8110 | schaersvoo | 5770 | ctx.strokeStyle = axis_color;\ |
5771 | ctx.lineWidth = 2*line_width;\ |
||
7988 | schaersvoo | 5772 | ctx.font = font_family;\ |
5773 | var shift = zero_y+2*font_size;var flip=0;var skip=0;var corr;var cnt;var disp_cnt;var prec;\ |
||
5774 | if( x_strings != null ){\ |
||
5775 | var len = x_strings.length;if((len/2+0.5)%%2 == 0){ alert(\"xaxis number unpaired: text missing ! \");return;};\ |
||
8110 | schaersvoo | 5776 | ctx.beginPath();\ |
7988 | schaersvoo | 5777 | for(var p = 0 ; p < len ; p = p+2){\ |
5778 | var x_nums = x2px(eval(x_strings[p]));\ |
||
5779 | var x_text = x_strings[p+1];\ |
||
5780 | corr = ctx.measureText(x_text).width;\ |
||
5781 | skip = 1.2*corr/xstep;\ |
||
5782 | if( zero_y+2*font_size > ysize ){shift = ysize - 2*font_size;};\ |
||
5783 | if( skip > 1 ){if(flip == 0 ){flip = 1; shift = shift + font_size;}else{flip = 0; shift = shift - font_size;}};\ |
||
5784 | ctx.fillText(x_text,parseInt(x_nums-0.5*corr),shift);\ |
||
8110 | schaersvoo | 5785 | ctx.moveTo(x_nums,zero_y - tics_length);\ |
5786 | ctx.lineTo(x_nums,zero_y + tics_length);\ |
||
7988 | schaersvoo | 5787 | };\ |
8110 | schaersvoo | 5788 | ctx.closePath();\ |
7988 | schaersvoo | 5789 | }\ |
5790 | else\ |
||
5791 | {\ |
||
5792 | skip = 1;cnt = px2x(zero_x);\ |
||
5793 | prec = Math.log(precision)/(Math.log(10));\ |
||
5794 | var y_basis;if(f_y == 1){ y_basis = ysize }else{ y_basis = zero_y + 1.4*font_size;};\ |
||
5795 | for( var p = zero_x ; p < xsize ; p = p+xstep){\ |
||
5796 | if(skip == 0 ){\ |
||
7990 | schaersvoo | 5797 | disp_cnt = cnt.toFixed(prec);\ |
7988 | schaersvoo | 5798 | corr = ctx.measureText(disp_cnt).width;\ |
5799 | skip = parseInt(1.2*corr/xstep);\ |
||
5800 | ctx.fillText(disp_cnt,p-0.5*corr,y_basis);\ |
||
7614 | schaersvoo | 5801 | }\ |
7988 | schaersvoo | 5802 | else\ |
5803 | {\ |
||
5804 | skip--;\ |
||
7614 | schaersvoo | 5805 | };\ |
7988 | schaersvoo | 5806 | cnt = cnt + xmajor;\ |
7614 | schaersvoo | 5807 | };\ |
7988 | schaersvoo | 5808 | cnt = px2x(zero_x);skip = 1;\ |
5809 | for( var p = zero_x ; p > 0 ; p = p-xstep){\ |
||
5810 | if(skip == 0 ){\ |
||
7990 | schaersvoo | 5811 | disp_cnt = cnt.toFixed(prec);\ |
7988 | schaersvoo | 5812 | corr = ctx.measureText(disp_cnt).width;\ |
5813 | skip = parseInt(1.2*corr/xstep);\ |
||
5814 | ctx.fillText(disp_cnt,p-0.5*corr,y_basis);\ |
||
5815 | }\ |
||
5816 | else\ |
||
5817 | {\ |
||
5818 | skip--;\ |
||
7614 | schaersvoo | 5819 | };\ |
7988 | schaersvoo | 5820 | cnt = cnt - xmajor;\ |
7614 | schaersvoo | 5821 | };\ |
5822 | };\ |
||
7988 | schaersvoo | 5823 | if( y_strings != null ){\ |
5824 | var len = y_strings.length;if((len/2+0.5)%%2 == 0){ alert(\"yaxis number unpaired: text missing ! \");return;};\ |
||
8110 | schaersvoo | 5825 | ctx.beginPath();\ |
7988 | schaersvoo | 5826 | for(var p = 0 ; p < len ; p = p+2){\ |
5827 | var y_nums = y2px(eval(y_strings[p]));\ |
||
5828 | var y_text = y_strings[p+1];\ |
||
5829 | corr = 2 + tics_length + ctx.measureText(y_text).width;\ |
||
5830 | if( corr > zero_x){corr = parseInt(zero_x+2); }\ |
||
8110 | schaersvoo | 5831 | ctx.fillText(y_text,zero_x - corr,y_nums + 0.5*font_size);\ |
5832 | ctx.moveTo(zero_x - tics_length,y_nums);\ |
||
5833 | ctx.lineTo(zero_x + tics_length,y_nums);\ |
||
7614 | schaersvoo | 5834 | };\ |
8110 | schaersvoo | 5835 | ctx.closePath();\ |
7988 | schaersvoo | 5836 | }\ |
5837 | else\ |
||
5838 | {\ |
||
7991 | schaersvoo | 5839 | if(f_x == 1){ corr = 1.5*tics_length; }\ |
7988 | schaersvoo | 5840 | cnt = px2y(zero_y);skip = 1;\ |
5841 | for( var p = zero_y ; p < ysize ; p = p+ystep){\ |
||
5842 | if(skip == 0 ){\ |
||
5843 | skip = parseInt(1.4*font_size/ystep);\ |
||
7990 | schaersvoo | 5844 | disp_cnt = cnt.toFixed(prec);\ |
7988 | schaersvoo | 5845 | if(f_x == -1 ){ corr = parseInt(zero_x - (2 + tics_length + ctx.measureText(disp_cnt).width));};\ |
5846 | ctx.fillText(disp_cnt,parseInt(corr),parseInt(p+(0.4*font_size)));\ |
||
5847 | }\ |
||
5848 | else\ |
||
5849 | {\ |
||
5850 | skip--;\ |
||
5851 | };\ |
||
5852 | cnt = cnt - ymajor;\ |
||
7614 | schaersvoo | 5853 | };\ |
7988 | schaersvoo | 5854 | corr = 0;cnt = px2y(zero_y);skip = 1;\ |
7991 | schaersvoo | 5855 | if(f_x == 1){ corr = 1.5*tics_length; }\ |
7988 | schaersvoo | 5856 | for( var p = zero_y ; p > 0 ; p = p-ystep){\ |
5857 | if(skip == 0 ){\ |
||
5858 | skip = parseInt(1.4*font_size/ystep);\ |
||
7990 | schaersvoo | 5859 | disp_cnt = cnt.toFixed(prec);\ |
7988 | schaersvoo | 5860 | if(f_x == -1 ){corr = parseInt(zero_x - (2 + tics_length + ctx.measureText(disp_cnt).width));};\ |
5861 | ctx.fillText(disp_cnt,parseInt(corr),parseInt(p+(0.4*font_size)));\ |
||
5862 | }\ |
||
5863 | else\ |
||
5864 | {\ |
||
5865 | skip--;\ |
||
5866 | };\ |
||
5867 | cnt = cnt + ymajor;\ |
||
7614 | schaersvoo | 5868 | };\ |
5869 | };\ |
||
7988 | schaersvoo | 5870 | ctx.stroke();\ |
7614 | schaersvoo | 5871 | ctx.restore();\ |
5872 | };\ |
||
7956 | schaersvoo | 5873 | if( typeof legend0 !== 'undefined' ){\ |
7988 | schaersvoo | 5874 | ctx.save();\ |
7614 | schaersvoo | 5875 | ctx.globalAlpha = 1.0;\ |
5876 | ctx.font = \"bold \"+font_size+\"px Ariel\";\ |
||
5877 | var y_offset = 2*font_size;\ |
||
5878 | var txt;var txt_size;\ |
||
5879 | var x_offset = xsize - 2*font_size;\ |
||
7956 | schaersvoo | 5880 | var l_length = legend0.length;\ |
5881 | if( typeof legendcolors0 !== 'undefined' ){\ |
||
7614 | schaersvoo | 5882 | for(var p = 0 ; p < l_length ; p++){\ |
7956 | schaersvoo | 5883 | barcolor[p] = legendcolors0[p];\ |
7614 | schaersvoo | 5884 | };\ |
7988 | schaersvoo | 5885 | }\ |
5886 | else\ |
||
5887 | {\ |
||
7614 | schaersvoo | 5888 | if( barcolor.length == 0 ){\ |
5889 | for(var p = 0 ; p < l_length ; p++){\ |
||
5890 | barcolor[p] = stroke_color;\ |
||
5891 | };\ |
||
5892 | };\ |
||
5893 | };\ |
||
5894 | for(var p = 0; p < l_length; p++){\ |
||
5895 | ctx.fillStyle = barcolor[p];\ |
||
7956 | schaersvoo | 5896 | txt = legend0[p];\ |
7614 | schaersvoo | 5897 | txt_size = ctx.measureText(txt).width;\ |
7956 | schaersvoo | 5898 | ctx.fillText(legend0[p],x_offset - txt_size, y_offset);\ |
7614 | schaersvoo | 5899 | y_offset = parseInt(y_offset + 1.5*font_size);\ |
5900 | };\ |
||
7988 | schaersvoo | 5901 | ctx.restore();\ |
7614 | schaersvoo | 5902 | };\ |
7991 | schaersvoo | 5903 | if( typeof barchart_0 !== 'undefined' ){\ |
5904 | ctx.save();\ |
||
5905 | var num_barcharts = 0;\ |
||
5906 | var bar_name = eval('barchart_0');\ |
||
5907 | while( typeof bar_name !== 'undefined' ){\ |
||
5908 | try{ bar_name = eval('barchart_'+num_barcharts);num_barcharts++;}catch(e){break;};\ |
||
5909 | };\ |
||
5910 | var bar_width = parseInt(0.8*xstep/(num_barcharts));\ |
||
5911 | for(var i=0 ; i< num_barcharts ; i++){\ |
||
5912 | bar_name = eval('barchart_'+i);\ |
||
5913 | var bar_x = new Array();\ |
||
5914 | var bar_y = new Array();\ |
||
5915 | var lb = bar_name.length;\ |
||
5916 | var idx = 0;\ |
||
5917 | var dx = parseInt(0.5*i*bar_width);\ |
||
5918 | for( var p = 0 ; p < lb ; p = p + 3 ){\ |
||
5919 | bar_x[idx] = x2px(bar_name[p]);\ |
||
5920 | bar_y[idx] = y2px(bar_name[p+1]);\ |
||
5921 | barcolor[idx] = bar_name[p+2];\ |
||
5922 | idx++;\ |
||
5923 | };\ |
||
5924 | ctx.globalAlpha = fill_opacity;\ |
||
5925 | ctx.beginPath();\ |
||
5926 | for( var p = 0; p < idx ; p++ ){\ |
||
5927 | ctx.strokeStyle = barcolor[p];\ |
||
5928 | ctx.fillStyle = barcolor[p];\ |
||
5929 | ctx.rect(bar_x[p]-0.4*xstep+dx,bar_y[p],bar_width,zero_y - bar_y[p]);\ |
||
5930 | };\ |
||
5931 | ctx.fill();\ |
||
5932 | ctx.stroke();\ |
||
5933 | ctx.closePath();\ |
||
5934 | };\ |
||
5935 | ctx.restore();\ |
||
5936 | };\ |
||
7996 | schaersvoo | 5937 | if( typeof linegraph_0 !== 'undefined' ){\ |
5938 | ctx.save();\ |
||
5939 | ctx.globalAlpha = 1.0;\ |
||
5940 | var i = 0;\ |
||
5941 | var line_name = eval('linegraph_'+i);\ |
||
5942 | while ( typeof line_name !== 'undefined' ){\ |
||
5943 | ctx.strokeStyle = 'rgba('+line_name[0]+','+stroke_opacity+')';\ |
||
5944 | ctx.lineWidth = parseInt(line_name[1]);\ |
||
5945 | if(line_name[2] == \"1\"){\ |
||
5946 | var d1 = parseInt(line_name[3]);\ |
||
5947 | var d2 = parseInt(line_name[4]);\ |
||
5948 | if(ctx.setLineDash){ ctx.setLineDash([d1,d2]); } else { ctx.mozDash = [d1,d2];};\ |
||
5949 | }\ |
||
5950 | else\ |
||
5951 | {\ |
||
5952 | if(ctx.setLineDash){ctx.setLineDash = null;}\ |
||
5953 | if(ctx.mozDash){ctx.mozDash = null;}\ |
||
5954 | };\ |
||
5955 | var data_x = new Array();\ |
||
5956 | var data_y = new Array();\ |
||
5957 | var lb = line_name.length;\ |
||
5958 | var idx = 0;\ |
||
5959 | for( var p = 5 ; p < lb ; p = p + 2 ){\ |
||
5960 | data_x[idx] = x2px(line_name[p]);\ |
||
5961 | data_y[idx] = y2px(line_name[p+1]);\ |
||
5962 | idx++;\ |
||
5963 | };\ |
||
5964 | for( var p = 0; p < idx ; p++){\ |
||
5965 | ctx.beginPath();\ |
||
5966 | ctx.moveTo(data_x[p],data_y[p]);\ |
||
5967 | ctx.lineTo(data_x[p+1],data_y[p+1]);\ |
||
5968 | ctx.stroke();\ |
||
5969 | ctx.closePath();\ |
||
5970 | };\ |
||
5971 | i++;\ |
||
5972 | try{ line_name = eval('linegraph_'+i); }catch(e){ break; }\ |
||
5973 | };\ |
||
5974 | ctx.restore();\ |
||
5975 | };\ |
||
7614 | schaersvoo | 5976 | return;\ |
7989 | schaersvoo | 5977 | };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 5978 | break; |
8224 | bpr | 5979 | |
7614 | schaersvoo | 5980 | case DRAW_PIECHART: |
7987 | schaersvoo | 5981 | fprintf(js_include_file,"\n<!-- draw piecharts -->\n\ |
7956 | schaersvoo | 5982 | function draw_piechart(canvas_type,x_center,y_center,radius, data_color_list,fill_opacity,legend_cnt,font_family){\ |
7614 | schaersvoo | 5983 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
5984 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
5985 | }\ |
||
5986 | else\ |
||
5987 | {\ |
||
5988 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
5989 | };\ |
||
5990 | var ld = data_color_list.length;\ |
||
5991 | var sum = 0;\ |
||
5992 | var idx = 0;\ |
||
7956 | schaersvoo | 5993 | var font_size = parseInt(font_family.replace(/[^0-9\\.]+/g, \"\"));\ |
7614 | schaersvoo | 5994 | var colors = new Array();\ |
5995 | var data = new Array();\ |
||
5996 | for(var p = 0;p < ld; p = p + 2){\ |
||
5997 | data[idx] = parseFloat(data_color_list[p]);\ |
||
5998 | sum = sum + data[idx];\ |
||
5999 | colors[idx] = data_color_list[p+1];\ |
||
6000 | idx++;\ |
||
6001 | };\ |
||
6002 | var ctx = obj.getContext(\"2d\");\ |
||
6003 | ctx.save();\ |
||
6004 | var angle;\ |
||
6005 | var angle_end = 0;\ |
||
6006 | var offset = Math.PI / 2;\ |
||
6007 | ctx.globalAlpha = fill_opacity;\ |
||
6008 | for(var p=0; p < idx; p++){\ |
||
6009 | ctx.beginPath();\ |
||
6010 | ctx.fillStyle = colors[p];\ |
||
6011 | ctx.moveTo(x_center,y_center);\ |
||
6012 | angle = Math.PI * (2 * data[p] / sum);\ |
||
6013 | ctx.arc(x_center,y_center, radius, angle_end - offset, angle_end + angle - offset, false);\ |
||
6014 | ctx.lineTo(x_center, y_center);\ |
||
6015 | ctx.fill();\ |
||
6016 | ctx.closePath();\ |
||
6017 | angle_end = angle_end + angle;\ |
||
6018 | };\ |
||
7956 | schaersvoo | 6019 | if(typeof legend0 !== 'undefined'){\ |
6020 | var legenda = eval(\"legend\"+legend_cnt);\ |
||
7614 | schaersvoo | 6021 | ctx.globalAlpha = 1.0;\ |
7956 | schaersvoo | 6022 | ctx.font = font_family;\ |
7614 | schaersvoo | 6023 | var y_offset = font_size; \ |
6024 | var x_offset = 0;\ |
||
6025 | var txt;var txt_size;\ |
||
6026 | for(var p = 0; p < idx; p++){\ |
||
6027 | ctx.fillStyle = colors[p];\ |
||
7956 | schaersvoo | 6028 | txt = legenda[p];\ |
7614 | schaersvoo | 6029 | txt_size = ctx.measureText(txt).width;\ |
6030 | if( x_center + radius + txt_size > xsize ){ x_offset = x_center + radius + txt_size - xsize;} else { x_offset = 0; };\ |
||
7956 | schaersvoo | 6031 | ctx.fillText(txt,x_center + radius - x_offset, y_center - radius + y_offset);\ |
7614 | schaersvoo | 6032 | y_offset = parseInt(y_offset + 1.5*font_size);\ |
6033 | };\ |
||
6034 | };\ |
||
6035 | ctx.restore();\ |
||
7956 | schaersvoo | 6036 | };",canvas_root_id,canvas_root_id,canvas_root_id); |
8224 | bpr | 6037 | |
7614 | schaersvoo | 6038 | break; |
6039 | case DRAW_ARCS: |
||
6040 | fprintf(js_include_file,"\n<!-- draw arcs -->\n\ |
||
8105 | schaersvoo | 6041 | var draw_arc = function(ctx,xc,yc,r,start,end,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_affine,affine_matrix){\ |
7614 | schaersvoo | 6042 | ctx.save();\ |
6043 | if( use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{if(ctx.mozDash){ ctx.mozDash = [dashtype0,dashtype1];};};};\ |
||
8071 | schaersvoo | 6044 | if( use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);};\ |
7614 | schaersvoo | 6045 | if( use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);};\ |
6046 | if(end < start){var tmp = end;end = start;start=tmp;};\ |
||
8071 | schaersvoo | 6047 | start = 360 - start;\ |
6048 | end = 360 - end;\ |
||
7614 | schaersvoo | 6049 | ctx.lineWidth = line_width;\ |
6050 | ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
8071 | schaersvoo | 6051 | ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\ |
6052 | ctx.beginPath();\ |
||
6053 | ctx.moveTo(xc,yc);\ |
||
6054 | ctx.arc(xc, yc, r, start*(Math.PI / 180), end*(Math.PI / 180),true);\ |
||
6055 | ctx.lineTo(xc,yc);\ |
||
6056 | ctx.closePath();\ |
||
7614 | schaersvoo | 6057 | if( use_filled == 1 ){\ |
6058 | ctx.fill();\ |
||
8071 | schaersvoo | 6059 | };\ |
6060 | ctx.stroke();\ |
||
7614 | schaersvoo | 6061 | ctx.restore();\ |
8071 | schaersvoo | 6062 | };"); |
8224 | bpr | 6063 | |
7614 | schaersvoo | 6064 | break; |
7983 | schaersvoo | 6065 | case DRAW_CENTERSTRING: |
6066 | fprintf(js_include_file,"\n<!-- draw centerstring -->\n\ |
||
8105 | schaersvoo | 6067 | var draw_centerstring = function(canvas_type,y,font_family,stroke_color,stroke_opacity,text){\ |
7983 | schaersvoo | 6068 | var obj;\ |
6069 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
6070 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
6071 | }\ |
||
6072 | else\ |
||
6073 | {\ |
||
6074 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
6075 | };\ |
||
6076 | var ctx = obj.getContext(\"2d\");\ |
||
6077 | ctx.save();\ |
||
6078 | ctx.font = font_family;\ |
||
6079 | ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
6080 | var stringwidth = ctx.measureText(text).width;\ |
||
6081 | var x = parseInt((xsize - stringwidth)/2);if( x < 0 ){x = 0;};\ |
||
6082 | ctx.fillText(text,x,y2px(y));\ |
||
6083 | return;\ |
||
6084 | };",canvas_root_id,canvas_root_id,canvas_root_id); |
||
6085 | break; |
||
7614 | schaersvoo | 6086 | case DRAW_TEXTS: |
6087 | fprintf(js_include_file,"\n<!-- draw text -->\n\ |
||
8105 | schaersvoo | 6088 | var draw_text = function(canvas_type,x,y,font_size,font_family,stroke_color,stroke_opacity,angle2,text,use_rotate,angle,use_affine,affine_matrix){\ |
7614 | schaersvoo | 6089 | var obj;\ |
6090 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
6091 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
6092 | }\ |
||
6093 | else\ |
||
6094 | {\ |
||
6095 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
6096 | };\ |
||
6097 | var ctx = obj.getContext(\"2d\");\ |
||
6098 | if(angle2 == 0 && angle != 0){\ |
||
6099 | ctx.save();\ |
||
8071 | schaersvoo | 6100 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 6101 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
6102 | };\ |
||
6103 | if( font_family.indexOf('px') != null ){\ |
||
6104 | ctx.font = font_family;\ |
||
6105 | }\ |
||
6106 | else\ |
||
6107 | {\ |
||
7956 | schaersvoo | 6108 | ctx.font = font_family;\ |
7614 | schaersvoo | 6109 | };\ |
6110 | ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
6111 | if(angle2 != 0){\ |
||
6112 | ctx.save();\ |
||
6113 | ctx.translate(x,y);\ |
||
6114 | ctx.rotate((360-angle2)*(Math.PI / 180));\ |
||
6115 | ctx.fillText(text,0,0);\ |
||
6116 | ctx.restore();\ |
||
6117 | }else{ctx.fillText(text,x,y);};\ |
||
6118 | ctx.restore();\ |
||
6119 | return;\ |
||
7653 | schaersvoo | 6120 | };",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 6121 | break; |
6122 | case DRAW_CURVE: |
||
6123 | fprintf(js_include_file,"\n<!-- draw curve -->\n\ |
||
8105 | schaersvoo | 6124 | var draw_curve = function(canvas_type,type,x_points,y_points,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,use_rotate,angle,use_affine,affine_matrix){\ |
7614 | schaersvoo | 6125 | var obj;\ |
6126 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
6127 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
6128 | }\ |
||
6129 | else\ |
||
6130 | {\ |
||
6131 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
6132 | };\ |
||
6133 | var ctx = obj.getContext(\"2d\");\ |
||
6134 | ctx.save();\ |
||
8071 | schaersvoo | 6135 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 6136 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
6137 | ctx.beginPath();ctx.lineWidth = line_width;\ |
||
6138 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
6139 | ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
6140 | ctx.moveTo(x2px(x_points[0]),y2px(y_points[0]));\ |
||
6141 | for(var p = 1 ; p < x_points.length ; p++){\ |
||
6142 | if( y2px(y_points[p]) > -5 && y2px(y_points[p]) < ysize+5 ){\ |
||
6143 | ctx.lineTo(x2px(x_points[p]),y2px(y_points[p]));\ |
||
6144 | }\ |
||
6145 | else\ |
||
6146 | {\ |
||
6147 | ctx.stroke();\ |
||
6148 | ctx.beginPath();\ |
||
6149 | p++;\ |
||
6150 | ctx.moveTo(x2px(x_points[p]),y2px(y_points[p]));\ |
||
6151 | };\ |
||
6152 | };\ |
||
6153 | ctx.stroke();\ |
||
6154 | ctx.restore();\ |
||
7653 | schaersvoo | 6155 | };",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 6156 | break; |
8224 | bpr | 6157 | |
7614 | schaersvoo | 6158 | case DRAW_INPUTS: |
6159 | fprintf(js_include_file,"\n<!-- draw input fields -->\n\ |
||
8105 | schaersvoo | 6160 | var draw_inputs = function(root_id,input_cnt,x,y,size,readonly,style,value){\ |
7614 | schaersvoo | 6161 | var canvas_div = document.getElementById(\"canvas_div\"+root_id);\ |
6162 | var input = document.createElement(\"input\");\ |
||
6163 | input.setAttribute(\"id\",\"canvas_input\"+input_cnt);\ |
||
6164 | input.setAttribute(\"style\",\"position:absolute;left:\"+x+\"px;top:\"+y+\"px;\"+style);\ |
||
6165 | input.setAttribute(\"size\",size);\ |
||
6166 | input.setAttribute(\"value\",value);\ |
||
7877 | schaersvoo | 6167 | if( readonly == 0 || wims_status == \"done\" ){ input.setAttribute(\"readonly\",\"readonly\");if( wims_status == \"done\" ){input.setAttribute(\"value\",\"\");};};\ |
7653 | schaersvoo | 6168 | canvas_div.appendChild(input);};"); |
7614 | schaersvoo | 6169 | break; |
8224 | bpr | 6170 | |
7614 | schaersvoo | 6171 | case DRAW_TEXTAREAS: |
6172 | fprintf(js_include_file,"\n<!-- draw text area inputfields -->\n\ |
||
8105 | schaersvoo | 6173 | var draw_textareas = function(root_id,input_cnt,x,y,cols,rows,readonly,style,value){\ |
7614 | schaersvoo | 6174 | var canvas_div = document.getElementById(\"canvas_div\"+root_id);\ |
6175 | var textarea = document.createElement(\"textarea\");\ |
||
6176 | textarea.setAttribute(\"id\",\"canvas_input\"+input_cnt);\ |
||
6177 | textarea.setAttribute(\"style\",\"position:absolute;left:\"+x+\"px;top:\"+y+\"px;\"+style);\ |
||
6178 | textarea.setAttribute(\"cols\",cols);\ |
||
6179 | textarea.setAttribute(\"rows\",rows);\ |
||
7877 | schaersvoo | 6180 | textarea.value = value;\ |
6181 | if( readonly == 0 || wims_status == \"done\" ){ textarea.setAttribute(\"readonly\",\"readonly\");if( wims_status == \"done\" ){textarea.value=\"\";};};\ |
||
7653 | schaersvoo | 6182 | canvas_div.appendChild(textarea);};"); |
7614 | schaersvoo | 6183 | break; |
8224 | bpr | 6184 | |
7614 | schaersvoo | 6185 | case DRAW_PIXELS: |
6186 | fprintf(js_include_file,"\n<!-- draw pixel -->\n\ |
||
8105 | schaersvoo | 6187 | var draw_setpixel = function(x,y,color,opacity,pixelsize){\ |
7614 | schaersvoo | 6188 | var canvas = create_canvas%d(10,xsize,ysize);\ |
6189 | var d = 0.5*pixelsize;\ |
||
6190 | var ctx = canvas.getContext(\"2d\");\ |
||
6191 | ctx.fillStyle = \"rgba(\"+color+\",\"+opacity+\")\";\ |
||
6192 | ctx.clearRect(0,0,xsize,ysize);\ |
||
6193 | for(var p=0; p<x.length;p++){\ |
||
6194 | ctx.fillRect( x2px(x[p]) - d, y2px(y[p]) - d , pixelsize, pixelsize );\ |
||
6195 | };\ |
||
6196 | ctx.fill();ctx.stroke();\ |
||
6197 | };",canvas_root_id); |
||
6198 | break; |
||
6199 | |||
6200 | case DRAW_CLOCK: |
||
6201 | fprintf(js_include_file,"\n<!-- begin command clock -->\n\ |
||
6202 | var clock_canvas = create_canvas%d(%d,xsize,ysize);\ |
||
6203 | var clock_ctx = clock_canvas.getContext(\"2d\");\ |
||
6204 | var clock = function(xc,yc,radius,H,M,S,type,interaction,h_color,m_color,s_color,bg_color,fg_color){\ |
||
8130 | schaersvoo | 6205 | clock_ctx.clearRect(xc - radius,yc - radius,2*radius,2*radius);\ |
7614 | schaersvoo | 6206 | clock_ctx.save();\ |
7997 | schaersvoo | 6207 | clock_ctx.globalAlpha = clock_bg_opacity;\ |
7614 | schaersvoo | 6208 | this.type = type || 0;\ |
6209 | this.interaction = interaction || 0;\ |
||
7862 | schaersvoo | 6210 | this.H = H;\ |
6211 | this.M = M;\ |
||
6212 | this.S = S;\ |
||
8000 | schaersvoo | 6213 | if(this.S == -1){this.S = 59;this.M = this.M - 1;};\ |
6214 | if(this.M == -1){this.M = 59;this.H = this.H - 1;};\ |
||
6215 | if(this.H == -1){this.H = 11;};\ |
||
7614 | schaersvoo | 6216 | this.xc = xc || xsize/2;\ |
6217 | this.yc = yc || ysize/2;\ |
||
6218 | this.radius = radius || xsize/4;\ |
||
6219 | var font_size = parseInt(0.2*this.radius);\ |
||
6220 | this.H_color = h_color || \"blue\";\ |
||
6221 | this.M_color = m_color || \"blue\";\ |
||
6222 | this.S_color = s_color || \"blue\";\ |
||
6223 | this.fg_color = fg_color || \"red\";\ |
||
6224 | this.bg_color = bg_color || \"white\";\ |
||
6225 | clock_ctx.translate(this.xc,this.yc);\ |
||
6226 | clock_ctx.beginPath();\ |
||
6227 | clock_ctx.arc(0,0,this.radius,0,2*Math.PI,false);\ |
||
6228 | clock_ctx.fillStyle = this.bg_color;\ |
||
6229 | clock_ctx.fill();\ |
||
6230 | clock_ctx.closePath();\ |
||
6231 | clock_ctx.beginPath();\ |
||
6232 | clock_ctx.font = font_size+\"px Arial\";\ |
||
6233 | clock_ctx.fillStyle = this.fg_color;\ |
||
6234 | clock_ctx.textAlign = \"center\";\ |
||
6235 | clock_ctx.textBaseline = 'middle';\ |
||
6236 | var angle;var x1,y1,x2,y2;\ |
||
6237 | var angle_cos;var angle_sin;\ |
||
7997 | schaersvoo | 6238 | clock_ctx.globalAlpha = clock_fg_opacity;\ |
7614 | schaersvoo | 6239 | switch(type){\ |
6240 | case 0:clock_ctx.beginPath();\ |
||
6241 | for(var p = 1; p <= 12 ; p++){\ |
||
6242 | angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 12));\ |
||
6243 | angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 12));\ |
||
6244 | x1 = 0.8*angle_cos;y1 = 0.8*angle_sin;x2 = angle_cos;y2 = angle_sin;\ |
||
6245 | clock_ctx.moveTo(x1,y1);\ |
||
6246 | clock_ctx.lineTo(x2,y2);\ |
||
6247 | };\ |
||
6248 | for(var p = 1; p <= 60 ; p++){\ |
||
6249 | angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 60));\ |
||
6250 | angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 60));\ |
||
6251 | x1 = 0.9*angle_cos;y1 = 0.9*angle_sin;x2 = angle_cos;y2 = angle_sin;\ |
||
6252 | clock_ctx.moveTo(x1,y1);\ |
||
6253 | clock_ctx.lineTo(x2,y2);\ |
||
6254 | };\ |
||
6255 | clock_ctx.closePath();\ |
||
6256 | clock_ctx.stroke();\ |
||
6257 | break;\ |
||
6258 | case 1:\ |
||
6259 | for(var p= 1; p <= 12 ; p++){ angle = (p - 3) * (Math.PI * 2) / 12;x1 = 0.9*this.radius*Math.cos(angle);y1 = 0.9*this.radius*Math.sin(angle);clock_ctx.fillText(p, x1, y1);};break;\ |
||
7862 | schaersvoo | 6260 | case 2:\ |
6261 | for(var p= 1; p <= 12 ; p++){ angle = (p - 3) * (Math.PI * 2) / 12;x1 = 0.8*this.radius*Math.cos(angle);y1 = 0.8*this.radius*Math.sin(angle);clock_ctx.fillText(p, x1, y1);};\ |
||
7614 | schaersvoo | 6262 | clock_ctx.beginPath();\ |
6263 | for(var p = 1; p <= 12 ; p++){\ |
||
6264 | angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 12));\ |
||
6265 | angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 12));\ |
||
6266 | x1 = 0.9*angle_cos;y1 = 0.9*angle_sin;x2 = angle_cos;y2 = angle_sin;\ |
||
6267 | clock_ctx.moveTo(x1,y1);\ |
||
6268 | clock_ctx.lineTo(x2,y2);\ |
||
6269 | };\ |
||
6270 | for(var p = 1; p <= 60 ; p++){\ |
||
6271 | angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 60));\ |
||
6272 | angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 60));\ |
||
6273 | x1 = 0.95*angle_cos;y1 = 0.95*angle_sin;x2 = angle_cos;y2 = angle_sin;\ |
||
6274 | clock_ctx.moveTo(x1,y1);\ |
||
6275 | clock_ctx.lineTo(x2,y2);\ |
||
6276 | };\ |
||
6277 | clock_ctx.closePath();\ |
||
6278 | clock_ctx.stroke();\ |
||
6279 | break;\ |
||
6280 | };\ |
||
6281 | angle = (this.H - 3 + this.M/60 ) * 2 * Math.PI / 12;\ |
||
6282 | clock_ctx.rotate(angle);\ |
||
6283 | clock_ctx.beginPath();\ |
||
6284 | clock_ctx.moveTo(-3, -2);\ |
||
6285 | clock_ctx.lineTo(-3, 2);\ |
||
6286 | clock_ctx.lineTo(this.radius * 0.7, 1);\ |
||
6287 | clock_ctx.lineTo(this.radius * 0.7, -1);\ |
||
6288 | clock_ctx.fillStyle = this.H_color;\ |
||
6289 | clock_ctx.fill();\ |
||
6290 | clock_ctx.rotate(-angle);\ |
||
6291 | angle = (this.M - 15 + this.S/60) * 2 * Math.PI / 60;\ |
||
6292 | clock_ctx.rotate(angle);\ |
||
6293 | clock_ctx.beginPath();\ |
||
6294 | clock_ctx.moveTo(-3, -2);\ |
||
6295 | clock_ctx.lineTo(-3, 2);\ |
||
6296 | clock_ctx.lineTo(this.radius * 0.8, 1);\ |
||
6297 | clock_ctx.lineTo(this.radius * 0.8, -1);\ |
||
6298 | clock_ctx.fillStyle = this.M_color;\ |
||
6299 | clock_ctx.fill();\ |
||
6300 | clock_ctx.rotate(-angle);\ |
||
6301 | angle = (this.S - 15) * 2 * Math.PI / 60;\ |
||
6302 | clock_ctx.rotate(angle);\ |
||
6303 | clock_ctx.beginPath();\ |
||
6304 | clock_ctx.moveTo(0,0);\ |
||
6305 | clock_ctx.lineTo(this.radius * 0.95, 0);\ |
||
6306 | clock_ctx.lineTo(this.radius * 0.9, -1);\ |
||
6307 | clock_ctx.strokeStyle = this.S_color;\ |
||
6308 | clock_ctx.stroke();\ |
||
6309 | clock_ctx.restore();\ |
||
7653 | schaersvoo | 6310 | };",canvas_root_id,CLOCK_CANVAS); |
7614 | schaersvoo | 6311 | break; |
6312 | |||
6313 | case DRAW_LATTICE: |
||
6314 | fprintf(js_include_file,"\n<!-- draw lattice -->\n\ |
||
8105 | schaersvoo | 6315 | var draw_lattice = function(canvas_type,line_width,x0,y0,dx1,dy1,dx2,dy2,n1,n2,fill_color,fill_opacity,stroke_color,stroke_opacity,use_rotate,angle,use_affine,affine_matrix){\ |
7614 | schaersvoo | 6316 | var obj;\ |
6317 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
6318 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
6319 | }\ |
||
6320 | else\ |
||
6321 | {\ |
||
6322 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
6323 | };\ |
||
6324 | var ctx = obj.getContext(\"2d\");\ |
||
6325 | ctx.save();\ |
||
8071 | schaersvoo | 6326 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 6327 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
6328 | ctx.fillStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
6329 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
6330 | var radius = line_width;\ |
||
6331 | var x = 0;\ |
||
6332 | var y = 0;\ |
||
6333 | var x_step_px = xsize/(xmax-xmin);\ |
||
6334 | var y_step_px = ysize/(ymax-ymin);\ |
||
6335 | var xv1 = dx1*x_step_px;\ |
||
6336 | var yv1 = dy1*y_step_px;\ |
||
6337 | var xv2 = dx2*x_step_px;\ |
||
6338 | var yv2 = dy2*y_step_px;\ |
||
6339 | for(var p = 0; p < n1 ;p++){\ |
||
6340 | x = p*xv1 + x0;\ |
||
6341 | y = p*yv1 + y0;\ |
||
6342 | for(var c = 0; c < n2 ; c++){\ |
||
6343 | ctx.beginPath();\ |
||
6344 | ctx.arc(x+c*xv2,y+c*yv2,radius,0,2*Math.PI,false);\ |
||
6345 | ctx.fill();\ |
||
6346 | ctx.stroke();\ |
||
6347 | ctx.closePath();\ |
||
6348 | };\ |
||
6349 | };\ |
||
6350 | ctx.restore();\ |
||
6351 | return;\ |
||
7653 | schaersvoo | 6352 | };",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 6353 | break; |
7735 | schaersvoo | 6354 | case DRAW_XYLOGSCALE: |
6355 | fprintf(js_include_file,"\n<!-- draw xylogscale -->\n\ |
||
8105 | schaersvoo | 6356 | var draw_grid%d = function(canvas_type,line_width,major_color,minor_color,major_opacity,minor_opacity,font_size,font_family,font_color,use_axis_numbering,precision){\ |
7956 | schaersvoo | 6357 | var obj;\ |
6358 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
6359 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
6360 | }\ |
||
6361 | else\ |
||
6362 | {\ |
||
6363 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
6364 | };\ |
||
6365 | var ctx = obj.getContext(\"2d\");\ |
||
7735 | schaersvoo | 6366 | ctx.clearRect(0,0,xsize,ysize);\ |
7956 | schaersvoo | 6367 | ctx.save();\ |
7739 | schaersvoo | 6368 | var xmarge;var ymarge;var x_e;var y_e;var num;var corr;var xtxt;var ytxt;\ |
7956 | schaersvoo | 6369 | var x_min = Math.log(xmin)/Math.log(xlogbase);\ |
6370 | var x_max = Math.log(xmax)/Math.log(xlogbase);\ |
||
6371 | var y_min = Math.log(ymin)/Math.log(ylogbase);\ |
||
6372 | var y_max = Math.log(ymax)/Math.log(ylogbase);\ |
||
7739 | schaersvoo | 6373 | if(use_axis_numbering == 1){\ |
7956 | schaersvoo | 6374 | ctx.font = font_family;\ |
6375 | xmarge = ctx.measureText(ylogbase+'^'+y_max.toFixed(0)+' ').width;\ |
||
6376 | ymarge = parseInt(1.5*font_size);\ |
||
6377 | ctx.save();\ |
||
6378 | ctx.fillStyle=\"rgba(255,215,0,0.2)\";\ |
||
6379 | ctx.rect(0,0,xmarge,ysize);\ |
||
6380 | ctx.rect(0,ysize-ymarge,xsize,ysize);\ |
||
6381 | ctx.fill();\ |
||
6382 | ctx.restore();\ |
||
6383 | }else{xmarge = 0;ymarge = 0;};\ |
||
7735 | schaersvoo | 6384 | if( typeof xaxislabel !== 'undefined' ){\ |
7956 | schaersvoo | 6385 | ctx.save();\ |
6386 | ctx.font = \"italic \"+font_size+\"px Ariel\";\ |
||
6387 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\ |
||
6388 | corr = ctx.measureText(xaxislabel).width;\ |
||
6389 | ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\ |
||
6390 | ctx.restore();\ |
||
6391 | };\ |
||
7735 | schaersvoo | 6392 | if( typeof yaxislabel !== 'undefined' ){\ |
7956 | schaersvoo | 6393 | ctx.save();\ |
6394 | ctx.font = \"italic \"+font_size+\"px Ariel\";\ |
||
6395 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\ |
||
6396 | corr = ctx.measureText(yaxislabel).width;\ |
||
6397 | ctx.translate(xmarge+font_size,corr+font_size);\ |
||
6398 | ctx.rotate(-0.5*Math.PI);\ |
||
6399 | ctx.fillText(yaxislabel,0,0);\ |
||
6400 | ctx.restore();\ |
||
6401 | };\ |
||
6402 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\ |
||
6403 | ctx.lineWidth = line_width;\ |
||
6404 | for(var p = x_min; p <= x_max ; p++){\ |
||
6405 | num = Math.pow(xlogbase,p);\ |
||
6406 | for(var i = 1 ; i < xlogbase ; i++){\ |
||
6407 | x_e = x2px(i*num);\ |
||
7735 | schaersvoo | 6408 | if( i == 1 ){\ |
7956 | schaersvoo | 6409 | ctx.lineWidth = line_width;\ |
6410 | ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\ |
||
7738 | schaersvoo | 6411 | if( use_axis_numbering == 1 && p > x_min){\ |
7956 | schaersvoo | 6412 | xtxt = xlogbase+'^'+p.toFixed(0);\ |
6413 | corr = 0.5*(ctx.measureText(xtxt).width);\ |
||
6414 | ctx.fillText(xtxt,x_e - corr,ysize - 4);\ |
||
6415 | };\ |
||
7735 | schaersvoo | 6416 | }else{\ |
7956 | schaersvoo | 6417 | ctx.lineWidth = 0.2*line_width;\ |
6418 | ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\ |
||
6419 | };\ |
||
7738 | schaersvoo | 6420 | if( x_e >= xmarge ){\ |
7956 | schaersvoo | 6421 | ctx.beginPath();\ |
6422 | ctx.moveTo(x_e,0);\ |
||
6423 | ctx.lineTo(x_e,ysize - ymarge);\ |
||
6424 | ctx.stroke();\ |
||
6425 | ctx.closePath();\ |
||
7738 | schaersvoo | 6426 | };\ |
7956 | schaersvoo | 6427 | };\ |
6428 | };\ |
||
6429 | for(var p = y_min; p <= y_max ; p++){\ |
||
6430 | num = Math.pow(ylogbase,p);\ |
||
6431 | for(var i = 1 ; i < ylogbase ; i++){\ |
||
6432 | y_e = y2px(i*num);\ |
||
6433 | if( i == 1 ){\ |
||
6434 | ctx.lineWidth = line_width;\ |
||
7735 | schaersvoo | 6435 | ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\ |
7956 | schaersvoo | 6436 | if( use_axis_numbering == 1 && p > y_min){\ |
6437 | ctx.fillText(ylogbase+'^'+p.toFixed(0),0,y_e);\ |
||
6438 | };\ |
||
6439 | }else{\ |
||
6440 | ctx.lineWidth = 0.2*line_width;\ |
||
6441 | ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\ |
||
6442 | };\ |
||
6443 | ctx.beginPath();\ |
||
6444 | ctx.moveTo(xmarge,y_e);\ |
||
6445 | ctx.lineTo(xsize,y_e);\ |
||
6446 | ctx.stroke();\ |
||
6447 | ctx.closePath();\ |
||
6448 | };\ |
||
6449 | };\ |
||
7735 | schaersvoo | 6450 | ctx.restore();\ |
6451 | };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id); |
||
6452 | break; |
||
7614 | schaersvoo | 6453 | |
7735 | schaersvoo | 6454 | case DRAW_XLOGSCALE: |
6455 | fprintf(js_include_file,"\n<!-- draw xlogscale -->\n\ |
||
8105 | schaersvoo | 6456 | var draw_grid%d = function(canvas_type,line_width,major_color,minor_color,major_opacity,minor_opacity,font_size,font_family,font_color,use_axis_numbering,ymajor,yminor,precision){\ |
7956 | schaersvoo | 6457 | var obj;\ |
6458 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
6459 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
6460 | }\ |
||
6461 | else\ |
||
6462 | {\ |
||
6463 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
6464 | };\ |
||
6465 | var ctx = obj.getContext(\"2d\");\ |
||
7735 | schaersvoo | 6466 | ctx.clearRect(0,0,xsize,ysize);\ |
7956 | schaersvoo | 6467 | ctx.save();\ |
6468 | ctx.lineWidth = line_width;\ |
||
7739 | schaersvoo | 6469 | var prec = Math.log(precision)/Math.log(10);\ |
7735 | schaersvoo | 6470 | var x_min = Math.log(xmin)/Math.log(xlogbase);\ |
6471 | var x_max = Math.log(xmax)/Math.log(xlogbase);\ |
||
6472 | var y_min = 0;var y_max = ysize;var x_e;var corr;\ |
||
7739 | schaersvoo | 6473 | var xtxt;var ytxt;var num;var xmarge;var ymarge;\ |
6474 | if(use_axis_numbering == 1){\ |
||
7956 | schaersvoo | 6475 | ctx.font = font_family;\ |
6476 | xmarge = ctx.measureText(ymax.toFixed(prec)+' ').width;\ |
||
6477 | ymarge = parseInt(1.5*font_size);\ |
||
6478 | ctx.save();\ |
||
6479 | ctx.fillStyle=\"rgba(255,215,0,0.2)\";\ |
||
6480 | ctx.rect(0,0,xmarge,ysize);\ |
||
6481 | ctx.rect(0,ysize-ymarge,xsize,ysize);\ |
||
6482 | ctx.fill();\ |
||
6483 | ctx.restore();\ |
||
6484 | }else{xmarge = 0;ymarge = 0;};\ |
||
7739 | schaersvoo | 6485 | if( typeof xaxislabel !== 'undefined' ){\ |
7956 | schaersvoo | 6486 | ctx.save();\ |
6487 | ctx.font = \"italic \"+font_size+\"px Ariel\";\ |
||
6488 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\ |
||
6489 | corr = ctx.measureText(xaxislabel).width;\ |
||
6490 | ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\ |
||
6491 | ctx.restore();\ |
||
6492 | };\ |
||
7739 | schaersvoo | 6493 | if( typeof yaxislabel !== 'undefined' ){\ |
7956 | schaersvoo | 6494 | ctx.save();\ |
6495 | ctx.font = \"italic \"+font_size+\"px Ariel\";\ |
||
6496 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\ |
||
6497 | corr = ctx.measureText(yaxislabel).width;\ |
||
6498 | ctx.translate(xmarge+font_size,corr+font_size);\ |
||
6499 | ctx.rotate(-0.5*Math.PI);\ |
||
6500 | ctx.fillText(yaxislabel,0,0);\ |
||
6501 | ctx.restore();\ |
||
6502 | };\ |
||
6503 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\ |
||
6504 | ctx.lineWidth = line_width;\ |
||
6505 | for(var p = x_min; p <= x_max ; p++){\ |
||
6506 | num = Math.pow(xlogbase,p);\ |
||
6507 | for(var i = 1 ; i < xlogbase ; i++){\ |
||
6508 | x_e = x2px(i*num);\ |
||
7735 | schaersvoo | 6509 | if( i == 1 ){\ |
7956 | schaersvoo | 6510 | ctx.lineWidth = line_width;\ |
7739 | schaersvoo | 6511 | ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\ |
6512 | if( use_axis_numbering == 1 && p > x_min ){\ |
||
7735 | schaersvoo | 6513 | xtxt = xlogbase+'^'+p.toFixed(0);\ |
6514 | corr = 0.5*(ctx.measureText(xtxt).width);\ |
||
6515 | ctx.fillText(xtxt,x_e - corr,ysize - 4);\ |
||
6516 | };\ |
||
6517 | }else{\ |
||
7956 | schaersvoo | 6518 | ctx.lineWidth = 0.2*line_width;\ |
7735 | schaersvoo | 6519 | ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\ |
6520 | };\ |
||
7739 | schaersvoo | 6521 | if( x_e >= xmarge ){\ |
7956 | schaersvoo | 6522 | ctx.beginPath();\ |
6523 | ctx.moveTo(x_e,0);\ |
||
6524 | ctx.lineTo(x_e,ysize - ymarge);\ |
||
6525 | ctx.stroke();\ |
||
6526 | ctx.closePath();\ |
||
7739 | schaersvoo | 6527 | };\ |
6528 | };\ |
||
7956 | schaersvoo | 6529 | };\ |
7735 | schaersvoo | 6530 | var stepy = Math.abs(y2px(ymajor) - y2px(0));\ |
6531 | var minor_step = stepy / yminor;\ |
||
7749 | schaersvoo | 6532 | for(var y = 0 ; y < ysize - stepy ; y = y + stepy){\ |
7735 | schaersvoo | 6533 | ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\ |
7956 | schaersvoo | 6534 | ctx.lineWidth = line_width;\ |
6535 | ctx.beginPath();\ |
||
6536 | ctx.moveTo(xmarge,y);\ |
||
6537 | ctx.lineTo(xsize,y);\ |
||
6538 | ctx.stroke();\ |
||
6539 | ctx.closePath();\ |
||
7735 | schaersvoo | 6540 | if( use_axis_numbering == 1){\ |
6541 | ytxt = (px2y(y)).toFixed(prec);\ |
||
6542 | ctx.fillText( ytxt,0 ,y + 0.5*font_size );\ |
||
6543 | };\ |
||
6544 | for(var dy = 1 ; dy < yminor ; dy++){\ |
||
6545 | ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\ |
||
7956 | schaersvoo | 6546 | ctx.lineWidth = 0.2*line_width;\ |
6547 | ctx.beginPath();\ |
||
7739 | schaersvoo | 6548 | ctx.moveTo(xmarge,y+dy*minor_step);\ |
7956 | schaersvoo | 6549 | ctx.lineTo(xsize,y+dy*minor_step);\ |
6550 | ctx.stroke();\ |
||
6551 | ctx.closePath();\ |
||
7735 | schaersvoo | 6552 | };\ |
6553 | };\ |
||
7956 | schaersvoo | 6554 | ctx.restore();\ |
6555 | };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id); |
||
7735 | schaersvoo | 6556 | break; |
7729 | schaersvoo | 6557 | case DRAW_YLOGSCALE: |
6558 | fprintf(js_include_file,"\n<!-- draw ylogscale -->\n\ |
||
8105 | schaersvoo | 6559 | var draw_grid%d = function(canvas_type,line_width,major_color,minor_color,major_opacity,minor_opacity,font_size,font_family,font_color,use_axis_numbering,xmajor,xminor,precision){\ |
7956 | schaersvoo | 6560 | var obj;\ |
6561 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
6562 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
6563 | }\ |
||
6564 | else\ |
||
6565 | {\ |
||
6566 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
6567 | };\ |
||
6568 | var ctx = obj.getContext(\"2d\");\ |
||
7729 | schaersvoo | 6569 | ctx.clearRect(0,0,xsize,ysize);\ |
7956 | schaersvoo | 6570 | ctx.save();\ |
6571 | ctx.lineWidth = line_width;\ |
||
7735 | schaersvoo | 6572 | var y_min = Math.log(ymin)/Math.log(ylogbase);\ |
6573 | var y_max = Math.log(ymax)/Math.log(ylogbase);\ |
||
8109 | schaersvoo | 6574 | var x_min = 0;var x_max = xsize;var y_s;var y_e;var num;var xmarge;var ymarge;\ |
7739 | schaersvoo | 6575 | if(use_axis_numbering == 1){\ |
7956 | schaersvoo | 6576 | ctx.font = font_family;\ |
6577 | xmarge = ctx.measureText(ylogbase+\"^\"+y_max.toFixed(0)+' ').width;\ |
||
6578 | ymarge = 2*font_size;\ |
||
6579 | ctx.save();\ |
||
6580 | ctx.fillStyle=\"rgba(255,215,0,0.2)\";\ |
||
6581 | ctx.rect(0,0,xmarge,ysize);\ |
||
6582 | ctx.rect(0,ysize-ymarge,xsize,ysize);\ |
||
6583 | ctx.fill();\ |
||
6584 | ctx.restore();\ |
||
6585 | }else{xmarge = 0;ymarge = 0;};\ |
||
7739 | schaersvoo | 6586 | if( typeof xaxislabel !== 'undefined' ){\ |
7956 | schaersvoo | 6587 | ctx.save();\ |
6588 | ctx.font = \"italic \"+font_size+\"px Ariel\";\ |
||
6589 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\ |
||
6590 | corr = ctx.measureText(xaxislabel).width;\ |
||
6591 | ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\ |
||
6592 | ctx.restore();\ |
||
6593 | };\ |
||
7739 | schaersvoo | 6594 | if( typeof yaxislabel !== 'undefined' ){\ |
7956 | schaersvoo | 6595 | ctx.save();\ |
6596 | ctx.font = \"italic \"+font_size+\"px Ariel\";\ |
||
6597 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\ |
||
6598 | corr = ctx.measureText(yaxislabel).width;\ |
||
6599 | ctx.translate(xmarge+font_size,corr+font_size);\ |
||
6600 | ctx.rotate(-0.5*Math.PI);\ |
||
6601 | ctx.fillText(yaxislabel,0,0);\ |
||
6602 | ctx.restore();\ |
||
6603 | };\ |
||
6604 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\ |
||
6605 | ctx.lineWidth = line_width;\ |
||
6606 | for(var p = y_min; p <= y_max ; p++){\ |
||
6607 | num = Math.pow(ylogbase,p);\ |
||
6608 | for(var i = 1 ; i < ylogbase ; i++){\ |
||
6609 | y_e = y2px(i*num);\ |
||
7729 | schaersvoo | 6610 | if( i == 1 ){\ |
7956 | schaersvoo | 6611 | ctx.lineWidth = line_width;\ |
7729 | schaersvoo | 6612 | ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\ |
7739 | schaersvoo | 6613 | if( use_axis_numbering == 1 && p > y_min){\ |
7735 | schaersvoo | 6614 | ctx.fillText(ylogbase+'^'+p.toFixed(0),0,y_e);\ |
7729 | schaersvoo | 6615 | };\ |
6616 | }else{\ |
||
7956 | schaersvoo | 6617 | ctx.lineWidth = 0.2*line_width;\ |
7729 | schaersvoo | 6618 | ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\ |
6619 | };\ |
||
7956 | schaersvoo | 6620 | ctx.beginPath();\ |
6621 | ctx.moveTo(xmarge,y_e);\ |
||
6622 | ctx.lineTo(xsize,y_e);\ |
||
6623 | ctx.stroke();\ |
||
6624 | ctx.closePath();\ |
||
6625 | };\ |
||
6626 | };\ |
||
7729 | schaersvoo | 6627 | var stepx = Math.abs(x2px(xmajor) - x2px(0));\ |
6628 | var minor_step = stepx / xminor;\ |
||
6629 | var prec = Math.log(precision)/Math.log(10);\ |
||
6630 | var xtxt;var corr;var flip = 0;\ |
||
7749 | schaersvoo | 6631 | for(var x = stepx ; x < xsize ; x = x + stepx){\ |
7729 | schaersvoo | 6632 | ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\ |
7956 | schaersvoo | 6633 | ctx.lineWidth = line_width;\ |
6634 | ctx.beginPath();\ |
||
6635 | ctx.moveTo(x,ysize-ymarge);\ |
||
6636 | ctx.lineTo(x,0);\ |
||
6637 | ctx.stroke();\ |
||
6638 | ctx.closePath();\ |
||
7729 | schaersvoo | 6639 | if( use_axis_numbering == 1){\ |
6640 | xtxt = (px2x(x)).toFixed(prec);\ |
||
6641 | corr = 0.5*(ctx.measureText(xtxt).width);\ |
||
6642 | if(flip == 0 ){flip = 1;ctx.fillText( xtxt,x - corr ,ysize - 0.2*font_size );}else{\ |
||
6643 | flip = 0;ctx.fillText( xtxt,x - corr ,ysize - 1.2*font_size );};\ |
||
6644 | };\ |
||
6645 | for(var dx = 1 ; dx < xminor ; dx++){\ |
||
6646 | ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\ |
||
7956 | schaersvoo | 6647 | ctx.lineWidth = 0.2*line_width;\ |
6648 | ctx.beginPath();\ |
||
7739 | schaersvoo | 6649 | ctx.moveTo(x+dx*minor_step,ysize - ymarge);\ |
7956 | schaersvoo | 6650 | ctx.lineTo(x+dx*minor_step,0);\ |
6651 | ctx.stroke();\ |
||
6652 | ctx.closePath();\ |
||
7735 | schaersvoo | 6653 | };\ |
6654 | };\ |
||
7956 | schaersvoo | 6655 | ctx.restore();\ |
6656 | };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id); |
||
7729 | schaersvoo | 6657 | break; |
7614 | schaersvoo | 6658 | default:break; |
6659 | } |
||
6660 | } |
||
6661 | } |
||
6662 | return; |
||
6663 | } |
||
6664 | |||
6665 | void check_string_length(int L){ |
||
6666 | if(L<1 || L > MAX_BUFFER-1){ |
||
6667 | canvas_error("problem with your arguments to command..."); |
||
6668 | } |
||
6669 | return; |
||
6670 | } |
||
6671 | |||
6672 | |||
6673 | int get_token(FILE *infile){ |
||
6674 | int c,i=0; |
||
6675 | char temp[MAX_INT], *input_type; |
||
6676 | char *line="line", |
||
6677 | *audio="audio", |
||
6678 | *blink="blink", |
||
6679 | *arrowhead="arrowhead", |
||
6680 | *crosshairsize="crosshairsize", |
||
6681 | *crosshair="crosshair", |
||
6682 | *crosshairs="crosshairs", |
||
6683 | *audioobject="audioobject", |
||
6684 | *style="style", |
||
6685 | *mouse="mouse", |
||
7991 | schaersvoo | 6686 | *mousex="mousex", |
6687 | *mousey="mousey", |
||
8071 | schaersvoo | 6688 | *mouse_display="display", |
6689 | *mouse_degree="mouse_degree", |
||
7614 | schaersvoo | 6690 | *userdraw="userdraw", |
6691 | *highlight="highlight", |
||
6692 | *http="http", |
||
6693 | *rays="rays", |
||
6694 | *dashtype="dashtype", |
||
6695 | *dashed="dashed", |
||
6696 | *filled="filled", |
||
6697 | *lattice="lattice", |
||
6698 | *parallel="parallel", |
||
6699 | *segment="segment", |
||
6700 | *dsegment="dsegment", |
||
6701 | *seg="seg", |
||
6702 | *bgimage="bgimage", |
||
6703 | *bgcolor="bgcolor", |
||
6704 | *strokecolor="strokecolor", |
||
6705 | *backgroundimage="backgroundimage", |
||
6706 | *text="text", |
||
6707 | *textup="textup", |
||
6708 | *mouseprecision="mouseprecision", |
||
6709 | *precision="precision", |
||
6710 | *plotsteps="plotsteps", |
||
6711 | *plotstep="plotstep", |
||
6712 | *tsteps="tsteps", |
||
6713 | *curve="curve", |
||
6714 | *dcurve="dcurve", |
||
6715 | *plot="plot", |
||
6716 | *dplot="dplot", |
||
7788 | schaersvoo | 6717 | *levelcurve="levelcurve", |
7614 | schaersvoo | 6718 | *fontsize="fontsize", |
6719 | *fontcolor="fontcolor", |
||
6720 | *axis="axis", |
||
6721 | *axisnumbering="axisnumbering", |
||
6722 | *axisnumbers="axisnumbers", |
||
6723 | *arrow="arrow", |
||
6724 | *darrow="darrow", |
||
6725 | *arrow2="arrow2", |
||
6726 | *darrow2="darrow2", |
||
6727 | *zoom="zoom", |
||
6728 | *grid="grid", |
||
6729 | *hline="hline", |
||
7786 | schaersvoo | 6730 | *dhline="dhline", |
7614 | schaersvoo | 6731 | *drag="drag", |
6732 | *horizontalline="horizontalline", |
||
6733 | *vline="vline", |
||
7786 | schaersvoo | 6734 | *dvline="dvline", |
7614 | schaersvoo | 6735 | *verticalline="verticalline", |
6736 | *triangle="triangle", |
||
6737 | *ftriangle="ftriangle", |
||
6738 | *mathml="mathml", |
||
6739 | *html="html", |
||
6740 | *input="input", |
||
8146 | schaersvoo | 6741 | *clearbutton="clearbutton", |
7614 | schaersvoo | 6742 | *inputstyle="inputstyle", |
6743 | *textarea="textarea", |
||
6744 | *trange="trange", |
||
6745 | *ranget="ranget", |
||
6746 | *xrange="xrange", |
||
6747 | *yrange="yrange", |
||
6748 | *rangex="rangex", |
||
6749 | *rangey="rangey", |
||
6750 | *polyline="polyline", |
||
6751 | *lines="lines", |
||
6752 | *poly="poly", |
||
6753 | *polygon="polygon", |
||
6754 | *fpolygon="fpolygon", |
||
6755 | *fpoly="fpoly", |
||
6756 | *filledpoly="filledpoly", |
||
6757 | *filledpolygon="filledpolygon", |
||
6758 | *rect="rect", |
||
6759 | *frect="frect", |
||
6760 | *rectangle="rectangle", |
||
6761 | *frectangle="frectangle", |
||
6762 | *square="square", |
||
6763 | *fsquare="fsquare", |
||
6764 | *dline="dline", |
||
6765 | *arc="arc", |
||
6766 | *filledarc="filledarc", |
||
6767 | *size="size", |
||
6768 | *string="string", |
||
6769 | *stringup="stringup", |
||
6770 | *copy="copy", |
||
6771 | *copyresized="copyresized", |
||
6772 | *opacity="opacity", |
||
6773 | *transparent="transparent", |
||
6774 | *fill="fill", |
||
6775 | *point="point", |
||
6776 | *points="points", |
||
6777 | *linewidth="linewidth", |
||
6778 | *circle="circle", |
||
6779 | *fcircle="fcircle", |
||
6780 | *disk="disk", |
||
6781 | *comment="#", |
||
6782 | *end="end", |
||
6783 | *ellipse="ellipse", |
||
6784 | *fellipse="fellipse", |
||
6785 | *rotate="rotate", |
||
7785 | schaersvoo | 6786 | *affine="affine", |
6787 | *killaffine="killaffine", |
||
7614 | schaersvoo | 6788 | *fontfamily="fontfamily", |
6789 | *fillcolor="fillcolor", |
||
6790 | *clicktile="clicktile", |
||
6791 | *clicktile_colors="clicktile_colors", |
||
6792 | *translation="translation", |
||
6793 | *translate="translate", |
||
6794 | *killtranslation="killtranslation", |
||
6795 | *killtranslate="killtranslate", |
||
6796 | *onclick="onclick", |
||
6797 | *roundrect="roundrect", |
||
6798 | *froundrect="froundrect", |
||
6799 | *roundrectangle="roundrectangle", |
||
6800 | *patternfill="patternfill", |
||
6801 | *hatchfill="hatchfill", |
||
6802 | *diafill="diafill", |
||
7647 | schaersvoo | 6803 | *diamondfill="diamondfill", |
7614 | schaersvoo | 6804 | *dotfill="dotfill", |
6805 | *gridfill="gridfill", |
||
6806 | *imagefill="imagefill", |
||
7735 | schaersvoo | 6807 | *xlogbase="xlogbase", |
6808 | *ylogbase="ylogbase", |
||
7614 | schaersvoo | 6809 | *xlogscale="xlogscale", |
6810 | *ylogscale="ylogscale", |
||
6811 | *xylogscale="xylogscale", |
||
6812 | *intooltip="intooltip", |
||
6813 | *replyformat="replyformat", |
||
6814 | *floodfill="floodfill", |
||
6815 | *filltoborder="filltoborder", |
||
6816 | *clickfill="clickfill", |
||
6817 | *setpixel="setpixel", |
||
6818 | *pixels="pixels", |
||
6819 | *pixelsize="pixelsize", |
||
6820 | *clickfillmarge="clickfillmarge", |
||
6821 | *xaxis="xaxis", |
||
6822 | *yaxis="yaxis", |
||
6823 | *xaxistext="xaxistext", |
||
6824 | *yaxistext="yaxistext", |
||
6825 | *piechart="piechart", |
||
6826 | *legend="legend", |
||
6827 | *legendcolors="legendcolors", |
||
6828 | *xlabel="xlabel", |
||
6829 | *ylabel="ylabel", |
||
6830 | *barchart="barchart", |
||
6831 | *linegraph="linegraph", |
||
6832 | *clock="clock", |
||
6833 | *animate="animate", |
||
6834 | *video="video", |
||
6835 | *status="status", |
||
7877 | schaersvoo | 6836 | *nostatus="nostatus", |
7652 | schaersvoo | 6837 | *snaptogrid="snaptogrid", |
7784 | schaersvoo | 6838 | *xsnaptogrid="xsnaptogrid", |
6839 | *ysnaptogrid="ysnaptogrid", |
||
7654 | schaersvoo | 6840 | *userinput_xy="userinput_xy", |
8193 | schaersvoo | 6841 | *userinput_function="userinput_function", |
7663 | schaersvoo | 6842 | *usertextarea_xy="usertextarea_xy", |
8222 | schaersvoo | 6843 | *userinput="userinput", |
7823 | schaersvoo | 6844 | *jsmath="jsmath", |
7858 | schaersvoo | 6845 | *trace_jscurve="trace_jscurve", |
7838 | schaersvoo | 6846 | *setlimits="setlimits", |
7858 | schaersvoo | 6847 | *jscurve="jscurve", |
6848 | *jsplot="jsplot", |
||
7983 | schaersvoo | 6849 | *sgraph="sgraph", |
7984 | schaersvoo | 6850 | *title="title", |
7996 | schaersvoo | 6851 | *centerstring="centerstring", |
6852 | *xunit="xunit", |
||
8071 | schaersvoo | 6853 | *yunit="yunit", |
8101 | schaersvoo | 6854 | *slider="slider", |
8105 | schaersvoo | 6855 | *killslider="killslider", |
8244 | schaersvoo | 6856 | *angle="angle", |
6857 | *halfline="halfline", |
||
8297 | schaersvoo | 6858 | *demiline="demiline", |
6859 | *functionlabel="functionlabel"; |
||
7614 | schaersvoo | 6860 | |
6861 | while(((c = getc(infile)) != EOF)&&(c!='\n')&&(c!=',')&&(c!='=')&&(c!='\r')){ |
||
6862 | if( i == 0 && (c == ' ' || c == '\t') ){ |
||
6863 | continue; /* white spaces or tabs allowed before first command identifier */ |
||
6864 | } |
||
6865 | else |
||
6866 | { |
||
6867 | if( c == ' ' || c == '\t' ){ |
||
6868 | break; |
||
6869 | } |
||
6870 | else |
||
6871 | { |
||
6872 | temp[i] = c; |
||
6873 | if(i > MAX_INT - 2){canvas_error("command string too long !");} |
||
6874 | i++; |
||
6875 | } |
||
6876 | } |
||
6877 | if(temp[0] == '#') break; |
||
6878 | } |
||
6879 | if (c == EOF) finished = 1; |
||
6880 | |||
6881 | if (c == '\n' || c == '\r') { |
||
6882 | line_number++; |
||
6883 | if (i == 0) { return EMPTY; } |
||
6884 | } else if (c == EOF) { |
||
6885 | return 0; |
||
6886 | } |
||
6887 | |||
6888 | temp[i]='\0'; |
||
6889 | input_type=(char*)my_newmem(strlen(temp)); |
||
6890 | snprintf(input_type,sizeof(temp),"%s",temp); |
||
6891 | |||
6892 | if( strcmp(input_type, size) == 0 ){ |
||
6893 | free(input_type); |
||
6894 | return SIZE; |
||
6895 | } |
||
6896 | if( strcmp(input_type, xrange) == 0 ){ |
||
6897 | free(input_type); |
||
6898 | return XRANGE; |
||
6899 | } |
||
6900 | if( strcmp(input_type, rangex) == 0 ){ |
||
6901 | free(input_type); |
||
6902 | return XRANGE; |
||
6903 | } |
||
6904 | if( strcmp(input_type, trange) == 0 ){ |
||
6905 | free(input_type); |
||
6906 | return TRANGE; |
||
6907 | } |
||
6908 | if( strcmp(input_type, ranget) == 0 ){ |
||
6909 | free(input_type); |
||
6910 | return TRANGE; |
||
6911 | } |
||
6912 | if( strcmp(input_type, yrange) == 0 ){ |
||
6913 | free(input_type); |
||
6914 | return YRANGE; |
||
6915 | } |
||
6916 | if( strcmp(input_type, rangey) == 0 ){ |
||
6917 | free(input_type); |
||
6918 | return YRANGE; |
||
6919 | } |
||
6920 | if( strcmp(input_type, linewidth) == 0 ){ |
||
6921 | free(input_type); |
||
6922 | return LINEWIDTH; |
||
6923 | } |
||
6924 | if( strcmp(input_type, dashed) == 0 ){ |
||
6925 | free(input_type); |
||
6926 | return DASHED; |
||
6927 | } |
||
6928 | if( strcmp(input_type, dashtype) == 0 ){ |
||
6929 | free(input_type); |
||
6930 | return DASHTYPE; |
||
6931 | } |
||
6932 | if( strcmp(input_type, axisnumbering) == 0 ){ |
||
6933 | free(input_type); |
||
6934 | return AXIS_NUMBERING; |
||
6935 | } |
||
6936 | if( strcmp(input_type, axisnumbers) == 0 ){ |
||
6937 | free(input_type); |
||
6938 | return AXIS_NUMBERING; |
||
6939 | } |
||
6940 | if( strcmp(input_type, axis) == 0 ){ |
||
6941 | free(input_type); |
||
6942 | return AXIS; |
||
6943 | } |
||
6944 | if( strcmp(input_type, grid) == 0 ){ |
||
6945 | free(input_type); |
||
6946 | return GRID; |
||
6947 | } |
||
6948 | if( strcmp(input_type, parallel) == 0 ){ |
||
6949 | free(input_type); |
||
6950 | return PARALLEL; |
||
6951 | } |
||
6952 | if( strcmp(input_type, hline) == 0 || strcmp(input_type, horizontalline) == 0 ){ |
||
6953 | free(input_type); |
||
6954 | return HLINE; |
||
6955 | } |
||
6956 | if( strcmp(input_type, vline) == 0 || strcmp(input_type, verticalline) == 0 ){ |
||
6957 | free(input_type); |
||
6958 | return VLINE; |
||
6959 | } |
||
6960 | if( strcmp(input_type, line) == 0 ){ |
||
6961 | free(input_type); |
||
6962 | return LINE; |
||
6963 | } |
||
6964 | if( strcmp(input_type, seg) == 0 || strcmp(input_type, segment) == 0 ){ |
||
6965 | free(input_type); |
||
6966 | return SEGMENT; |
||
6967 | } |
||
6968 | if( strcmp(input_type, dsegment) == 0 ){ |
||
6969 | free(input_type); |
||
6970 | use_dashed = TRUE; |
||
6971 | return SEGMENT; |
||
6972 | } |
||
6973 | if( strcmp(input_type, crosshairsize) == 0 ){ |
||
6974 | free(input_type); |
||
6975 | return CROSSHAIRSIZE; |
||
6976 | } |
||
6977 | if( strcmp(input_type, arrowhead) == 0 ){ |
||
6978 | free(input_type); |
||
6979 | return ARROWHEAD; |
||
6980 | } |
||
6981 | if( strcmp(input_type, crosshairs) == 0 ){ |
||
6982 | free(input_type); |
||
6983 | return CROSSHAIRS; |
||
6984 | } |
||
6985 | if( strcmp(input_type, crosshair) == 0 ){ |
||
6986 | free(input_type); |
||
6987 | return CROSSHAIR; |
||
6988 | } |
||
6989 | if( strcmp(input_type, onclick) == 0 ){ |
||
6990 | free(input_type); |
||
6991 | return ONCLICK; |
||
6992 | } |
||
6993 | if( strcmp(input_type, drag) == 0 ){ |
||
6994 | free(input_type); |
||
6995 | return DRAG; |
||
6996 | } |
||
6997 | if( strcmp(input_type, userdraw) == 0 ){ |
||
6998 | free(input_type); |
||
6999 | return USERDRAW; |
||
7000 | } |
||
7001 | if( strcmp(input_type, highlight) == 0 || strcmp(input_type, style) == 0 ){ |
||
7002 | free(input_type); |
||
7003 | return STYLE; |
||
7004 | } |
||
7005 | if( strcmp(input_type, fillcolor) == 0 ){ |
||
7006 | free(input_type); |
||
7007 | return FILLCOLOR; |
||
7008 | } |
||
7009 | if( strcmp(input_type, strokecolor) == 0 ){ |
||
7010 | free(input_type); |
||
7011 | return STROKECOLOR; |
||
7012 | } |
||
7013 | if( strcmp(input_type, filled) == 0 ){ |
||
7014 | free(input_type); |
||
7015 | return FILLED; |
||
7016 | } |
||
7017 | if( strcmp(input_type, http) == 0 ){ |
||
7018 | free(input_type); |
||
7019 | return HTTP; |
||
7020 | } |
||
7021 | if( strcmp(input_type, rays) == 0 ){ |
||
7022 | free(input_type); |
||
7023 | return RAYS; |
||
7024 | } |
||
7025 | if( strcmp(input_type, lattice) == 0 ){ |
||
7026 | free(input_type); |
||
7027 | return LATTICE; |
||
7028 | } |
||
7029 | if( strcmp(input_type, bgimage) == 0 ){ |
||
7030 | free(input_type); |
||
7031 | return BGIMAGE; |
||
7032 | } |
||
7033 | if( strcmp(input_type, bgcolor) == 0 ){ |
||
7034 | free(input_type); |
||
7035 | return BGCOLOR; |
||
7036 | } |
||
7037 | if( strcmp(input_type, backgroundimage) == 0 ){ |
||
7038 | free(input_type); |
||
7039 | return BGIMAGE; |
||
7040 | } |
||
7041 | if( strcmp(input_type, text) == 0 ){ |
||
7042 | free(input_type); |
||
7043 | return FLY_TEXT; |
||
7044 | } |
||
7045 | if( strcmp(input_type, textup) == 0 ){ |
||
7046 | free(input_type); |
||
7047 | return FLY_TEXTUP; |
||
7048 | } |
||
7049 | if( strcmp(input_type, mouse) == 0 ){ |
||
7050 | free(input_type); |
||
7051 | return MOUSE; |
||
7052 | } |
||
7991 | schaersvoo | 7053 | if( strcmp(input_type, mousex) == 0 ){ |
7054 | free(input_type); |
||
7055 | return MOUSEX; |
||
7056 | } |
||
7057 | if( strcmp(input_type, mousey) == 0 ){ |
||
7058 | free(input_type); |
||
7059 | return MOUSEY; |
||
7060 | } |
||
8071 | schaersvoo | 7061 | if( strcmp(input_type, mouse_degree) == 0 ){ |
7062 | free(input_type); |
||
7063 | return MOUSE_DEGREE; |
||
7064 | } |
||
7065 | if( strcmp(input_type, mouse_display) == 0 ){ |
||
7066 | free(input_type); |
||
7067 | return MOUSE_DISPLAY; |
||
7068 | } |
||
7614 | schaersvoo | 7069 | if( strcmp(input_type, mouseprecision) == 0 ){ |
7070 | free(input_type); |
||
7071 | return MOUSE_PRECISION; |
||
7072 | } |
||
7073 | if( strcmp(input_type, precision) == 0 ){ |
||
7074 | free(input_type); |
||
7075 | return MOUSE_PRECISION; |
||
7076 | } |
||
7077 | if( strcmp(input_type, curve) == 0 ){ |
||
7078 | free(input_type); |
||
7079 | return CURVE; |
||
7080 | } |
||
7081 | if( strcmp(input_type, dcurve) == 0 ){ |
||
7788 | schaersvoo | 7082 | use_dashed = TRUE; |
7614 | schaersvoo | 7083 | free(input_type); |
7084 | return CURVE; |
||
7085 | } |
||
7086 | if( strcmp(input_type, plot) == 0 ){ |
||
7087 | free(input_type); |
||
7088 | return CURVE; |
||
7089 | } |
||
7090 | if( strcmp(input_type, dplot) == 0 ){ |
||
7788 | schaersvoo | 7091 | use_dashed = TRUE; |
7614 | schaersvoo | 7092 | free(input_type); |
7093 | return CURVE; |
||
7094 | } |
||
7788 | schaersvoo | 7095 | if( strcmp(input_type, levelcurve) == 0 ){ |
7096 | free(input_type); |
||
7097 | return LEVELCURVE; |
||
7098 | } |
||
7614 | schaersvoo | 7099 | if( strcmp(input_type, plotsteps) == 0 ){ |
7100 | free(input_type); |
||
7101 | return PLOTSTEPS; |
||
7102 | } |
||
7103 | if( strcmp(input_type, plotstep) == 0 ){ |
||
7104 | free(input_type); |
||
7105 | return PLOTSTEPS; |
||
7106 | } |
||
7107 | if( strcmp(input_type, tsteps) == 0 ){ |
||
7108 | free(input_type); |
||
7109 | return PLOTSTEPS; |
||
7110 | } |
||
7111 | if( strcmp(input_type, fontsize) == 0 ){ |
||
7112 | free(input_type); |
||
7113 | return FONTSIZE; |
||
7114 | } |
||
7115 | if( strcmp(input_type, fontcolor) == 0 ){ |
||
7116 | free(input_type); |
||
7117 | return FONTCOLOR; |
||
7118 | } |
||
7119 | if( strcmp(input_type, arrow) == 0 ){ |
||
7120 | free(input_type); |
||
7121 | return ARROW; |
||
7122 | } |
||
7123 | if( strcmp(input_type, arrow2) == 0 ){ |
||
7124 | free(input_type); |
||
7125 | return ARROW2; |
||
7126 | } |
||
7127 | if( strcmp(input_type, darrow) == 0 ){ |
||
7128 | free(input_type); |
||
8071 | schaersvoo | 7129 | use_dashed = TRUE; |
7614 | schaersvoo | 7130 | return ARROW; |
7131 | } |
||
7132 | if( strcmp(input_type, darrow2) == 0 ){ |
||
7133 | free(input_type); |
||
7134 | use_dashed = TRUE; |
||
7135 | return ARROW2; |
||
7136 | } |
||
7137 | if( strcmp(input_type, zoom) == 0 ){ |
||
7138 | free(input_type); |
||
7139 | return ZOOM; |
||
7140 | } |
||
7141 | if( strcmp(input_type, triangle) == 0 ){ |
||
7142 | free(input_type); |
||
7143 | return TRIANGLE; |
||
7144 | } |
||
7145 | if( strcmp(input_type, ftriangle) == 0 ){ |
||
7146 | free(input_type); |
||
7147 | use_filled = TRUE; |
||
7148 | return TRIANGLE; |
||
7149 | } |
||
7150 | if( strcmp(input_type, input) == 0 ){ |
||
7151 | free(input_type); |
||
7152 | return INPUT; |
||
7153 | } |
||
7154 | if( strcmp(input_type, inputstyle) == 0 ){ |
||
7155 | free(input_type); |
||
7156 | return INPUTSTYLE; |
||
7157 | } |
||
7158 | if( strcmp(input_type, textarea) == 0 ){ |
||
7159 | free(input_type); |
||
7160 | return TEXTAREA; |
||
7161 | } |
||
7162 | if( strcmp(input_type, mathml) == 0 ){ |
||
7163 | free(input_type); |
||
7164 | return MATHML; |
||
7165 | } |
||
7166 | if( strcmp(input_type, html) == 0 ){ |
||
7167 | free(input_type); |
||
7168 | return MATHML; |
||
7169 | } |
||
7170 | if( strcmp(input_type, fontfamily) == 0 ){ |
||
7171 | free(input_type); |
||
7172 | return FONTFAMILY; |
||
7173 | } |
||
7174 | if( strcmp(input_type, lines) == 0 || strcmp(input_type, polyline) == 0 ){ |
||
7175 | free(input_type); |
||
7176 | return POLYLINE; |
||
7177 | } |
||
7178 | if( strcmp(input_type, rect) == 0 || strcmp(input_type, rectangle) == 0 ){ |
||
7179 | free(input_type); |
||
7180 | return RECT; |
||
7181 | } |
||
7182 | if( strcmp(input_type, roundrect) == 0 || strcmp(input_type, roundrectangle) == 0 ){ |
||
7183 | free(input_type); |
||
7184 | return ROUNDRECT; |
||
7185 | } |
||
7186 | if( strcmp(input_type, froundrect) == 0 ){ |
||
7187 | free(input_type); |
||
7188 | use_filled = TRUE; |
||
7189 | return ROUNDRECT; |
||
7190 | } |
||
7191 | if( strcmp(input_type, square) == 0 ){ |
||
7192 | free(input_type); |
||
7193 | return SQUARE; |
||
7194 | } |
||
7195 | if( strcmp(input_type, fsquare) == 0 ){ |
||
7196 | free(input_type); |
||
7197 | use_filled = TRUE; |
||
7198 | return SQUARE; |
||
7199 | } |
||
7200 | if( strcmp(input_type, dline) == 0 ){ |
||
7201 | use_dashed = TRUE; |
||
7202 | free(input_type); |
||
7203 | return LINE; |
||
7204 | } |
||
7786 | schaersvoo | 7205 | if( strcmp(input_type, dvline) == 0 ){ |
7206 | use_dashed = TRUE; |
||
7207 | free(input_type); |
||
7208 | return VLINE; |
||
7209 | } |
||
7210 | if( strcmp(input_type, dhline) == 0 ){ |
||
7211 | use_dashed = TRUE; |
||
7212 | free(input_type); |
||
7213 | return HLINE; |
||
7214 | } |
||
7614 | schaersvoo | 7215 | if( strcmp(input_type, frect) == 0 || strcmp(input_type, frectangle) == 0 ){ |
7216 | use_filled = TRUE; |
||
7217 | free(input_type); |
||
7218 | return RECT; |
||
7219 | } |
||
7220 | if( strcmp(input_type, fcircle) == 0 || strcmp(input_type, disk) == 0 ){ |
||
7221 | use_filled = TRUE; |
||
7222 | free(input_type); |
||
7223 | return CIRCLE; |
||
7224 | } |
||
7225 | if( strcmp(input_type, circle) == 0 ){ |
||
7226 | free(input_type); |
||
7227 | return CIRCLE; |
||
7228 | } |
||
7229 | if( strcmp(input_type, point) == 0 ){ |
||
7230 | free(input_type); |
||
7231 | return POINT; |
||
7232 | } |
||
7233 | if( strcmp(input_type, points) == 0 ){ |
||
7234 | free(input_type); |
||
7235 | return POINTS; |
||
7236 | } |
||
7237 | if( strcmp(input_type, filledarc) == 0 ){ |
||
7238 | use_filled = TRUE; |
||
7239 | free(input_type); |
||
7240 | return ARC; |
||
7241 | } |
||
7242 | if( strcmp(input_type, arc) == 0 ){ |
||
7243 | free(input_type); |
||
7244 | return ARC; |
||
7245 | } |
||
7246 | if( strcmp(input_type, poly) == 0 || strcmp(input_type, polygon) == 0 ){ |
||
7247 | free(input_type); |
||
7248 | return POLY; |
||
7249 | } |
||
7250 | if( strcmp(input_type, fpoly) == 0 || strcmp(input_type, filledpoly) == 0 || strcmp(input_type,filledpolygon) == 0 || strcmp(input_type,fpolygon) == 0 ){ |
||
7251 | use_filled = TRUE; |
||
7252 | free(input_type); |
||
7253 | return POLY; |
||
7254 | } |
||
7255 | if( strcmp(input_type, ellipse) == 0){ |
||
7256 | free(input_type); |
||
7257 | return ELLIPSE; |
||
7258 | } |
||
7259 | if( strcmp(input_type, fill) == 0 ){ |
||
7260 | free(input_type); |
||
7261 | return FLOODFILL; |
||
7262 | } |
||
7263 | if( strcmp(input_type, string) == 0 ){ |
||
7264 | free(input_type); |
||
7265 | return STRING; |
||
7266 | } |
||
7267 | if( strcmp(input_type, stringup) == 0 ){ |
||
7268 | free(input_type); |
||
7269 | return STRINGUP; |
||
7270 | } |
||
7271 | if( strcmp(input_type, opacity) == 0 ){ |
||
7272 | free(input_type); |
||
7273 | return OPACITY; |
||
7274 | } |
||
7275 | if( strcmp(input_type, comment) == 0){ |
||
7276 | free(input_type); |
||
7277 | return COMMENT; |
||
7278 | } |
||
7279 | if( strcmp(input_type, end) == 0){ |
||
7280 | free(input_type); |
||
7281 | return END; |
||
7282 | } |
||
7283 | if( strcmp(input_type, fellipse) == 0){ |
||
7284 | free(input_type); |
||
7285 | use_filled = TRUE; |
||
7286 | return ELLIPSE; |
||
8224 | bpr | 7287 | } |
7614 | schaersvoo | 7288 | if( strcmp(input_type, blink) == 0 ){ |
7289 | free(input_type); |
||
7290 | return BLINK; |
||
7291 | } |
||
8146 | schaersvoo | 7292 | if( strcmp(input_type, clearbutton) == 0){ |
7614 | schaersvoo | 7293 | free(input_type); |
8146 | schaersvoo | 7294 | return CLEARBUTTON; |
7614 | schaersvoo | 7295 | } |
7296 | if( strcmp(input_type, translation) == 0 || strcmp(input_type, translate) == 0 ){ |
||
7297 | free(input_type); |
||
7298 | return TRANSLATION; |
||
7299 | } |
||
7300 | if( strcmp(input_type, killtranslation) == 0 || strcmp(input_type, killtranslate) == 0){ |
||
7301 | free(input_type); |
||
7302 | return KILLTRANSLATION; |
||
7303 | } |
||
7304 | if( strcmp(input_type, rotate) == 0){ |
||
7305 | free(input_type); |
||
7306 | return ROTATE; |
||
7307 | } |
||
7785 | schaersvoo | 7308 | if( strcmp(input_type, affine) == 0){ |
7309 | free(input_type); |
||
7310 | return AFFINE; |
||
7311 | } |
||
7312 | if( strcmp(input_type, killaffine) == 0){ |
||
7313 | free(input_type); |
||
7314 | return KILLAFFINE; |
||
7315 | } |
||
7614 | schaersvoo | 7316 | if( strcmp(input_type, audio) == 0 ){ |
7317 | free(input_type); |
||
7318 | return AUDIO; |
||
7319 | } |
||
7320 | if( strcmp(input_type, audioobject) == 0 ){ |
||
7321 | free(input_type); |
||
7322 | return AUDIOOBJECT; |
||
7323 | } |
||
7324 | if( strcmp(input_type, slider) == 0 ){ |
||
7325 | free(input_type); |
||
7326 | return SLIDER; |
||
7327 | } |
||
8101 | schaersvoo | 7328 | if( strcmp(input_type, killslider) == 0 ){ |
7329 | free(input_type); |
||
7330 | return KILLSLIDER; |
||
7331 | } |
||
7614 | schaersvoo | 7332 | if( strcmp(input_type, copy) == 0 ){ |
7333 | free(input_type); |
||
7334 | return COPY; |
||
7335 | } |
||
7336 | if( strcmp(input_type, copyresized) == 0 ){ |
||
7337 | free(input_type); |
||
7338 | return COPYRESIZED; |
||
7339 | } |
||
7340 | if( strcmp(input_type, patternfill) == 0 ){ |
||
7341 | free(input_type); |
||
7342 | return PATTERNFILL; |
||
7343 | } |
||
7344 | if( strcmp(input_type, hatchfill) == 0 ){ |
||
7345 | free(input_type); |
||
7346 | return HATCHFILL; |
||
7347 | } |
||
7647 | schaersvoo | 7348 | if( strcmp(input_type, diafill) == 0 || strcmp(input_type, diamondfill) == 0 ){ |
7614 | schaersvoo | 7349 | free(input_type); |
7647 | schaersvoo | 7350 | return DIAMONDFILL; |
7614 | schaersvoo | 7351 | } |
7352 | if( strcmp(input_type, dotfill) == 0 ){ |
||
7353 | free(input_type); |
||
7354 | return DOTFILL; |
||
7355 | } |
||
7356 | if( strcmp(input_type, gridfill) == 0 ){ |
||
7357 | free(input_type); |
||
7358 | return GRIDFILL; |
||
7359 | } |
||
7360 | if( strcmp(input_type, imagefill) == 0 ){ |
||
7361 | free(input_type); |
||
7362 | return IMAGEFILL; |
||
7363 | } |
||
7364 | if( strcmp(input_type, clicktile_colors) == 0 ){ |
||
7365 | free(input_type); |
||
7366 | return CLICKTILE_COLORS; |
||
7367 | } |
||
7368 | if( strcmp(input_type, clicktile) == 0 ){ |
||
7369 | free(input_type); |
||
7370 | return CLICKTILE; |
||
7371 | } |
||
7372 | if( strcmp(input_type, xlogscale) == 0 ){ |
||
7373 | free(input_type); |
||
7374 | return XLOGSCALE; |
||
7375 | } |
||
7376 | if( strcmp(input_type, ylogscale) == 0 ){ |
||
7377 | free(input_type); |
||
7378 | return YLOGSCALE; |
||
7379 | } |
||
7380 | if( strcmp(input_type, xylogscale) == 0 ){ |
||
7381 | free(input_type); |
||
7382 | return XYLOGSCALE; |
||
7383 | } |
||
7384 | if( strcmp(input_type, ylogscale) == 0 ){ |
||
7385 | free(input_type); |
||
7386 | return YLOGSCALE; |
||
7387 | } |
||
7735 | schaersvoo | 7388 | if( strcmp(input_type, xlogbase) == 0 ){ |
7614 | schaersvoo | 7389 | free(input_type); |
7735 | schaersvoo | 7390 | return XLOGBASE; |
7614 | schaersvoo | 7391 | } |
7735 | schaersvoo | 7392 | if( strcmp(input_type, ylogbase) == 0 ){ |
7393 | free(input_type); |
||
7394 | return YLOGBASE; |
||
7395 | } |
||
7614 | schaersvoo | 7396 | if( strcmp(input_type, intooltip) == 0 ){ |
7397 | free(input_type); |
||
7398 | return INTOOLTIP; |
||
7399 | } |
||
7400 | if( strcmp(input_type,video) == 0 ){ |
||
7401 | free(input_type); |
||
7402 | return VIDEO; |
||
7403 | } |
||
7404 | if( strcmp(input_type,floodfill) == 0 || strcmp(input_type,fill) == 0 ){ |
||
7405 | free(input_type); |
||
7406 | return FLOODFILL; |
||
8224 | bpr | 7407 | } |
7614 | schaersvoo | 7408 | if( strcmp(input_type,filltoborder) == 0 ){ |
7409 | free(input_type); |
||
7410 | return FILLTOBORDER; |
||
8224 | bpr | 7411 | } |
7614 | schaersvoo | 7412 | if( strcmp(input_type,clickfill) == 0 ){ |
7413 | free(input_type); |
||
7414 | return CLICKFILL; |
||
8224 | bpr | 7415 | } |
7614 | schaersvoo | 7416 | if( strcmp(input_type, replyformat) == 0 ){ |
7417 | free(input_type); |
||
7418 | return REPLYFORMAT; |
||
7419 | } |
||
7420 | if( strcmp(input_type, pixelsize) == 0 ){ |
||
7421 | free(input_type); |
||
7422 | return PIXELSIZE; |
||
7423 | } |
||
7424 | if( strcmp(input_type, setpixel) == 0 ){ |
||
7425 | free(input_type); |
||
7426 | return SETPIXEL; |
||
7427 | } |
||
7428 | if( strcmp(input_type, pixels) == 0 ){ |
||
7429 | free(input_type); |
||
7430 | return PIXELS; |
||
7431 | } |
||
7432 | if( strcmp(input_type, clickfillmarge) == 0 ){ |
||
7433 | free(input_type); |
||
7434 | return CLICKFILLMARGE; |
||
7435 | } |
||
7436 | if( strcmp(input_type, xaxis) == 0 || strcmp(input_type, xaxistext) == 0 ){ |
||
7437 | free(input_type); |
||
7438 | return X_AXIS_STRINGS; |
||
7439 | } |
||
7440 | if( strcmp(input_type, yaxis) == 0 || strcmp(input_type, yaxistext) == 0 ){ |
||
7441 | free(input_type); |
||
7442 | return Y_AXIS_STRINGS; |
||
7443 | } |
||
7444 | if( strcmp(input_type, piechart) == 0 ){ |
||
7445 | free(input_type); |
||
7446 | return PIECHART; |
||
7447 | } |
||
7448 | if( strcmp(input_type, barchart) == 0 ){ |
||
7449 | free(input_type); |
||
7450 | return BARCHART; |
||
7451 | } |
||
7452 | if( strcmp(input_type, linegraph) == 0 ){ |
||
7453 | free(input_type); |
||
7454 | return LINEGRAPH; |
||
7455 | } |
||
7456 | if( strcmp(input_type, clock) == 0 ){ |
||
7457 | free(input_type); |
||
7458 | return CLOCK; |
||
7459 | } |
||
7460 | if( strcmp(input_type, legend) == 0 ){ |
||
7461 | free(input_type); |
||
7462 | return LEGEND; |
||
7463 | } |
||
7464 | if( strcmp(input_type, legendcolors) == 0 ){ |
||
7465 | free(input_type); |
||
7466 | return LEGENDCOLORS; |
||
7467 | } |
||
7468 | if( strcmp(input_type, xlabel) == 0 ){ |
||
7469 | free(input_type); |
||
7470 | return XLABEL; |
||
7471 | } |
||
7472 | if( strcmp(input_type, ylabel) == 0 ){ |
||
7473 | free(input_type); |
||
7474 | return YLABEL; |
||
7475 | } |
||
7476 | if( strcmp(input_type, animate) == 0 ){ |
||
7477 | free(input_type); |
||
7478 | return ANIMATE; |
||
7479 | } |
||
7480 | /* these are bitmap related flydraw commmands...must be removed. eventually */ |
||
7481 | if( strcmp(input_type, transparent) == 0 ){ |
||
7482 | free(input_type); |
||
7483 | return TRANSPARENT; |
||
7484 | } |
||
7877 | schaersvoo | 7485 | if( strcmp(input_type, status) == 0 || strcmp(input_type, nostatus) == 0 ){ |
7614 | schaersvoo | 7486 | free(input_type); |
7487 | return STATUS; |
||
7488 | } |
||
7489 | if( strcmp(input_type, snaptogrid) == 0 ){ |
||
7490 | free(input_type); |
||
7491 | return SNAPTOGRID; |
||
7492 | } |
||
7784 | schaersvoo | 7493 | if( strcmp(input_type, xsnaptogrid) == 0 ){ |
7494 | free(input_type); |
||
7495 | return XSNAPTOGRID; |
||
7496 | } |
||
7497 | if( strcmp(input_type, ysnaptogrid) == 0 ){ |
||
7498 | free(input_type); |
||
7499 | return YSNAPTOGRID; |
||
7500 | } |
||
7652 | schaersvoo | 7501 | if( strcmp(input_type, userinput_xy) == 0 ){ |
7614 | schaersvoo | 7502 | free(input_type); |
7652 | schaersvoo | 7503 | return USERINPUT_XY; |
7504 | } |
||
8193 | schaersvoo | 7505 | if( strcmp(input_type, userinput_function) == 0 ){ |
7506 | free(input_type); |
||
7507 | return USERINPUT_FUNCTION; |
||
7508 | } |
||
7663 | schaersvoo | 7509 | if( strcmp(input_type, usertextarea_xy) == 0 ){ |
7510 | free(input_type); |
||
7511 | return USERTEXTAREA_XY; |
||
7512 | } |
||
8222 | schaersvoo | 7513 | if( strcmp(input_type, userinput) == 0 ){ |
7514 | free(input_type); |
||
7515 | return USERINPUT; |
||
7516 | } |
||
7654 | schaersvoo | 7517 | if( strcmp(input_type, sgraph) == 0 ){ |
7652 | schaersvoo | 7518 | free(input_type); |
7654 | schaersvoo | 7519 | return SGRAPH; |
7520 | } |
||
7823 | schaersvoo | 7521 | if( strcmp(input_type, jsmath) == 0 ){ |
7654 | schaersvoo | 7522 | free(input_type); |
7823 | schaersvoo | 7523 | return JSMATH; |
7524 | } |
||
7858 | schaersvoo | 7525 | if( strcmp(input_type, trace_jscurve) == 0 ){ |
7823 | schaersvoo | 7526 | free(input_type); |
7858 | schaersvoo | 7527 | return TRACE_JSCURVE; |
7823 | schaersvoo | 7528 | } |
7858 | schaersvoo | 7529 | if( strcmp(input_type, jscurve) == 0 || strcmp(input_type, jsplot) == 0 ){ |
7530 | free(input_type); |
||
7531 | return JSCURVE; |
||
7532 | } |
||
7984 | schaersvoo | 7533 | if( strcmp(input_type, centerstring) == 0 || strcmp(input_type, title) == 0 ){ |
7983 | schaersvoo | 7534 | free(input_type); |
7535 | return CENTERSTRING; |
||
7536 | } |
||
7838 | schaersvoo | 7537 | if( strcmp(input_type, setlimits) == 0 ){ |
7823 | schaersvoo | 7538 | free(input_type); |
7838 | schaersvoo | 7539 | return SETLIMITS; |
7540 | } |
||
7996 | schaersvoo | 7541 | if( strcmp(input_type, xunit) == 0 ){ |
7838 | schaersvoo | 7542 | free(input_type); |
7996 | schaersvoo | 7543 | return XUNIT; |
7544 | } |
||
7545 | if( strcmp(input_type, yunit) == 0 ){ |
||
7546 | free(input_type); |
||
7547 | return YUNIT; |
||
7548 | } |
||
8105 | schaersvoo | 7549 | if( strcmp(input_type, angle) == 0 ){ |
7996 | schaersvoo | 7550 | free(input_type); |
8105 | schaersvoo | 7551 | return ANGLE; |
7552 | } |
||
8244 | schaersvoo | 7553 | if( strcmp(input_type, halfline) == 0 || strcmp(input_type, demiline) == 0 ){ |
8105 | schaersvoo | 7554 | free(input_type); |
8244 | schaersvoo | 7555 | return HALFLINE; |
7556 | } |
||
8297 | schaersvoo | 7557 | if( strcmp(input_type, functionlabel) == 0 ){ |
8244 | schaersvoo | 7558 | free(input_type); |
8297 | schaersvoo | 7559 | return FUNCTION_LABEL; |
7560 | } |
||
7561 | free(input_type); |
||
7614 | schaersvoo | 7562 | ungetc(c,infile); |
7563 | return 0; |
||
7564 | } |
||
7856 | schaersvoo | 7565 |