Rev 14957 | Rev 15111 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
8225 | bpr | 1 | #include "canvasdraw.h" |
2 | |||
3 | /* not used ?? */ |
||
4 | /* |
||
7614 | schaersvoo | 5 | char *data2js_array(int data[],int len); |
6 | char *xy2js_array(int xy[],int len); |
||
8225 | bpr | 7 | */ |
14038 | schaersvoo | 8 | |
9213 | schaersvoo | 9 | /* |
10 | |||
11 | just for the javascript switches(): |
||
12 | point = 0 points =1 |
||
13 | circle = 2 circles = 3 |
||
14 | line =4 lines = 5 |
||
15 | segment = 6 segments = 7 |
||
16 | arrow = 8 arrows = 9 |
||
17 | triangle = 10 triangles = 11 |
||
9338 | schaersvoo | 18 | polygon = 12 |
19 | text = 13 |
||
9372 | schaersvoo | 20 | rect = 14 |
21 | rects =15 |
||
11226 | schaersvoo | 22 | poly = 16 |
23 | polys = 17 |
||
24 | paralelogram = 18 |
||
14038 | schaersvoo | 25 | images = 20 |
9239 | schaersvoo | 26 | 28/6/2015: |
14948 | obado | 27 | the next js-code block (parsing/scanning the multidraw objects array) is -for now- generic, |
9239 | schaersvoo | 28 | e.g. not responsive to the actual draw_types used. |
29 | |||
30 | TODO: examine/parse the *draw_Types and make the js-code accordingly (e.g. specific and not generic) |
||
14038 | schaersvoo | 31 | |
14948 | obado | 32 | Firefox does not support drawing SVGimages to canvas unless the svg file |
14038 | schaersvoo | 33 | has width/height attributes on the root <svg> element and those width/height attributes are not percentages |
34 | |||
35 | container_div.addEventListener( 'mouseup' , mouseup, false);\ |
||
36 | container_div.addEventListener( 'mousemove' , mousemove,false);\ |
||
37 | container_div.addEventListener( 'mousedown' , mousedown,false);\ |
||
14949 | obado | 38 | container_div.addEventListener( 'touchstart' , function(e) { e.preventDefault(); mousedown(e.changedTouches[0]);},false);\ |
14038 | schaersvoo | 39 | container_div.addEventListener( 'touchmove' , function(e) { e.preventDefault(); mousemove(e.changedTouches[0]);},false);\ |
14948 | obado | 40 | container_div.addEventListener( 'touchend' , function(e) { e.preventDefault(); mouseup( e.changedTouches[0]);},false);\ |
14038 | schaersvoo | 41 | |
42 | replace: |
||
43 | var canvas_rect = canvas_userdraw.getBoundingClientRect();\ |
||
44 | var y = evt.clientY - canvas_rect.top;\ |
||
45 | var x = evt.clientX - canvas_rect.left;\ |
||
46 | by: |
||
47 | var mouse = dragstuff.getMouse(evt,canvas_userdraw);\ |
||
48 | var x = mouse.x;\ |
||
49 | var y = mouse.y;\ |
||
50 | |||
9250 | schaersvoo | 51 | */ |
9239 | schaersvoo | 52 | |
14038 | schaersvoo | 53 | void add_js_multidraw(FILE *js_include_file,int canvas_root_id,char *draw_types,char *button_style,int use_offset){ |
54 | fprintf(js_include_file,"\n/* begin multidraw */\n\ |
||
9262 | schaersvoo | 55 | var canvas_userdraw = create_canvas%d(999,xsize,ysize);\ |
56 | var context_userdraw = canvas_userdraw.getContext(\"2d\");\ |
||
14038 | schaersvoo | 57 | var multidraw_click_cnt = 0;\ |
9262 | schaersvoo | 58 | if(wims_status != \"done\"){\ |
14949 | obado | 59 | canvas_div.addEventListener('mousedown' , user_draw, false);\ |
60 | canvas_div.addEventListener('mousemove' , user_drag, false);\ |
||
61 | canvas_div.addEventListener('touchstart' , function(e) { e.preventDefault(); user_draw(e.changedTouches[0]);},false);\ |
||
62 | canvas_div.addEventListener('touchmove' , function(e) { e.preventDefault(); user_drag(e.changedTouches[0]);},false);\ |
||
9262 | schaersvoo | 63 | };\ |
64 | clear_draw_area%d = function(type,name){\ |
||
65 | switch(type){\ |
||
66 | case 0: context_points.clearRect(0,0,xsize,ysize);points_x = [];points_y = [];break;\ |
||
67 | case 1: points_x.pop();points_y.pop();draw_points();break;\ |
||
68 | case 2: context_circles.clearRect(0,0,xsize,ysize);circles_x = [];circles_y = []; multi_radius = [];break;\ |
||
69 | case 3: circles_x.pop();circles_y.pop(); multi_radius.pop();draw_circles();break;\ |
||
70 | case 4: context_lines.clearRect(0,0,xsize,ysize);lines_x = [];lines_y = [];break;\ |
||
71 | case 5: lines_x.pop();lines_y.pop();lines_x.pop();lines_y.pop();draw_lines();break;\ |
||
72 | case 6: context_segments.clearRect(0,0,xsize,ysize);segments_x = [];segments_y = [];break;\ |
||
73 | case 7: segments_x.pop();segments_y.pop();segments_x.pop();segments_y.pop();draw_segments();break;\ |
||
74 | case 8: context_arrows.clearRect(0,0,xsize,ysize);arrows_x = [];arrows_y = [];break;\ |
||
75 | case 9: arrows_x.pop();arrows_y.pop();arrows_x.pop();arrows_y.pop();draw_arrows();break;\ |
||
76 | case 10:context_triangles.clearRect(0,0,xsize,ysize); triangles_x = [];triangles_y = [];break;\ |
||
11226 | schaersvoo | 77 | case 11:for(var p=0;p<3;p++){triangles_x.pop();triangles_y.pop();};draw_triangles();break;\ |
9372 | schaersvoo | 78 | case 12:context_closedpoly.clearRect(0,0,xsize,ysize);closedpoly_x = [];closedpoly_y = [];break;\ |
79 | case 13:context_text.clearRect(0,0,xsize,ysize);text_x.pop();text_y.pop();text_abc.pop();draw_text();break;\ |
||
80 | case 14:context_rects.clearRect(0,0,xsize,ysize);rects_x = [];rects_y = [];break;\ |
||
11226 | schaersvoo | 81 | case 15:rects_x.pop();rects_y.pop();rects_x.pop();rects_y.pop();draw_rects();break;\ |
82 | case 16:context_polys.clearRect(0,0,xsize,ysize); polys_x = [];polys_y = [];break;\ |
||
83 | case 17:for(var p=0;p<polynum;p++){polys_x.pop();polys_y.pop();};draw_polys();break;\ |
||
11230 | schaersvoo | 84 | case 18:context_parallelogram.clearRect(0,0,xsize,ysize); parallelogram_x = [];parallelogram_y = [];break;\ |
85 | case 19:for(var p = 0; p < 4;p++){ parallelogram_x.pop();parallelogram_y.pop();};draw_parallelogram();break;\ |
||
14270 | schaersvoo | 86 | case 20:var len = images_id.length;if( len == 0 ){return;};var img = document.getElementById(images_id[len-1]);if( img.tagName == 'DIV' ){ img.innerHTML=null;};images_x.pop();images_y.pop();images_id.pop();draw_images();break;\ |
14038 | schaersvoo | 87 | case 21:context_curvedarrows.clearRect(0,0,xsize,ysize);curvedarrows_x = [];curvedarrows_y = [];break;\ |
14055 | schaersvoo | 88 | case 22:curvedarrows_x.pop();curvedarrows_y.pop();curvedarrows_x.pop();curvedarrows_y.pop();curvedarrows_x.pop();curvedarrows_y.pop();draw_curvedarrows();break;\ |
14038 | schaersvoo | 89 | case 23:context_curvedarrows2.clearRect(0,0,xsize,ysize);curvedarrows2_x = [];curvedarrows2_y = [];break;\ |
90 | case 24:curvedarrows2_x.pop();curvedarrows2_y.pop();curvedarrows2_x.pop();curvedarrows2_y.pop();curvedarrows2_x.pop();curvedarrows2_y.pop();draw_curvedarrows2();break;\ |
||
9213 | schaersvoo | 91 | default:break;\ |
92 | };\ |
||
9262 | schaersvoo | 93 | };\ |
94 | function user_draw(evt){\ |
||
14949 | obado | 95 | if(evt.button == 2){clear_draw_area%d(userdraw_primitive,0);return;};\ |
14038 | schaersvoo | 96 | var mouse = dragstuff.getMouse(evt,canvas_userdraw);\ |
97 | var x = mouse.x;\ |
||
98 | var y = mouse.y;\ |
||
9262 | schaersvoo | 99 | switch(userdraw_primitive){\ |
100 | case 0: points(x,y,0,0);break;\ |
||
101 | case 1: points(x,y,0,1);break;\ |
||
102 | case 2: circles(x,y,0,0);break;\ |
||
103 | case 3: circles(x,y,0,1);break;\ |
||
104 | case 4: lines(x,y,0,0);break;\ |
||
105 | case 5: lines(x,y,0,1);break;\ |
||
106 | case 6: segments(x,y,0,0);break;\ |
||
107 | case 7: segments(x,y,0,1);break;\ |
||
108 | case 8: arrows(x,y,0,0);break;\ |
||
109 | case 9: arrows(x,y,0,1);break;\ |
||
110 | case 10: triangles(x,y,0,0);break;\ |
||
111 | case 11: triangles(x,y,0,1);break;\ |
||
112 | case 12: closedpoly(x,y,0,0);break;\ |
||
9338 | schaersvoo | 113 | case 13: text(x,y,0,1);break;\ |
9372 | schaersvoo | 114 | case 14: rects(x,y,0,0);break;\ |
115 | case 15: rects(x,y,0,1);break;\ |
||
11226 | schaersvoo | 116 | case 16: polys(x,y,0,0);break;\ |
117 | case 17: polys(x,y,0,1);break;\ |
||
11230 | schaersvoo | 118 | case 18: parallelogram(x,y,0,0);break;\ |
119 | case 19: parallelogram(x,y,0,1);break;\ |
||
14038 | schaersvoo | 120 | case 20: images(x,y,0,1);break;\ |
121 | case 21: curvedarrows(x,y,0,0);break;\ |
||
122 | case 22: curvedarrows(x,y,0,1);break;\ |
||
123 | case 23: curvedarrows2(x,y,0,0);break;\ |
||
124 | case 24: curvedarrows2(x,y,0,1);break;\ |
||
9262 | schaersvoo | 125 | default:break;\ |
9213 | schaersvoo | 126 | };\ |
9262 | schaersvoo | 127 | };\ |
128 | function user_drag(evt){\ |
||
14038 | schaersvoo | 129 | var mouse = dragstuff.getMouse(evt,canvas_userdraw);\ |
130 | var x = mouse.x;\ |
||
131 | var y = mouse.y;\ |
||
9262 | schaersvoo | 132 | switch(userdraw_primitive){\ |
133 | case 0: break;\ |
||
134 | case 1: break;\ |
||
135 | case 2: circles(x,y,1,0);break;\ |
||
136 | case 3: circles(x,y,1,1);break;\ |
||
137 | case 4: lines(x,y,1,0);break;\ |
||
138 | case 5: lines(x,y,1,1);break;\ |
||
139 | case 6: segments(x,y,1,0);break;\ |
||
140 | case 7: segments(x,y,1,1);break;\ |
||
141 | case 8: arrows(x,y,1,0);break;\ |
||
142 | case 9: arrows(x,y,1,1);break;\ |
||
143 | case 10: triangles(x,y,1,0);break;\ |
||
144 | case 11: triangles(x,y,1,1);break;\ |
||
145 | case 12: closedpoly(x,y,1,0);break;\ |
||
9338 | schaersvoo | 146 | case 13: break;\ |
9372 | schaersvoo | 147 | case 14: rects(x,y,1,0);break;\ |
148 | case 15: rects(x,y,1,1);break;\ |
||
11226 | schaersvoo | 149 | case 16: polys(x,y,1,0);break;\ |
150 | case 17: polys(x,y,1,1);break;\ |
||
11230 | schaersvoo | 151 | case 18: parallelogram(x,y,1,0);break;\ |
152 | case 19: parallelogram(x,y,1,1);break;\ |
||
14038 | schaersvoo | 153 | case 20: images(x,y,1,1);break;\ |
154 | case 21: curvedarrows(x,y,1,0);break;\ |
||
155 | case 22: curvedarrows(x,y,1,1);break;\ |
||
156 | case 23: curvedarrows2(x,y,1,0);break;\ |
||
157 | case 24: curvedarrows2(x,y,1,1);break;\ |
||
9262 | schaersvoo | 158 | default:break;\ |
159 | };\ |
||
160 | };\ |
||
161 | var draw_things = [\"%s\"];\ |
||
162 | var tooltip_div = document.getElementById(\"tooltip_placeholder_div%d\");\ |
||
163 | var inner_html=\"\";\ |
||
164 | var button_style = \"%s\";\ |
||
165 | var id_x;\ |
||
166 | var id_y;\ |
||
167 | var id_r;\ |
||
14038 | schaersvoo | 168 | var curvedarrow_type_cnt=0;\ |
14053 | schaersvoo | 169 | var use_controls = 1;\ |
170 | var draw_things_length = draw_things.length;\ |
||
171 | if(multilabel[0] == 'NOCONTROLS'){use_controls = 0;}else{ if( typeof(multilabel[multilabel.length - 1 ]) === 'undefined' ){multilabel[multilabel.length - 1] = 'stop drawing';};};\ |
||
172 | for(var p = 0;p < draw_things_length;p++){\ |
||
9262 | schaersvoo | 173 | var desc;\ |
174 | id_r = 0;\ |
||
175 | if( multistrokeopacity[p] > 1 ){ multistrokeopacity[p] = (0.0039215*multistrokeopacity[p]).toFixed(2); };\ |
||
176 | if( multifillopacity[p] > 1 ){ multifillopacity[p] = (0.0039215*multifillopacity[p]).toFixed(2); };\ |
||
177 | if( draw_things[p] == 'point' || draw_things[p] == 'points' ){\ |
||
178 | var canvas_points = create_canvas%d(1000,xsize,ysize);\ |
||
179 | var context_points = canvas_points.getContext(\"2d\");\ |
||
180 | context_points.strokeStyle = \"rgba(\"+multistrokecolors[p]+\",\"+multistrokeopacity[p]+\")\";\ |
||
181 | context_points.fillStyle = context_points.strokeStyle;\ |
||
9406 | schaersvoo | 182 | context_points.lineWidth = multilinewidth[p];\ |
9462 | schaersvoo | 183 | if(multilinewidth[p]%%2 == 1){ context_points.translate(0.5,0.5);};\ |
9262 | schaersvoo | 184 | var points_x = new Array();var points_y = new Array();\ |
185 | var points_snap = multisnaptogrid[p];\ |
||
186 | if(draw_things[p] == 'point' ){desc = 0;}else{desc = 1;};\ |
||
187 | id_x = 'input_points_x';id_y = 'input_points_y';\ |
||
188 | }\ |
||
189 | else\ |
||
190 | {\ |
||
191 | if( draw_things[p] == 'circle' || draw_things[p] == 'circles' ){\ |
||
192 | var canvas_circles = create_canvas%d(1001,xsize,ysize);\ |
||
193 | var context_circles = canvas_circles.getContext(\"2d\");\ |
||
194 | context_circles.lineWidth = multilinewidth[p];\ |
||
9462 | schaersvoo | 195 | if(multilinewidth[p]%%2 == 1){ context_circles.translate(0.5,0.5);};\ |
9262 | schaersvoo | 196 | context_circles.strokeStyle = \"rgba(\"+multistrokecolors[p]+\",\"+multistrokeopacity[p]+\")\";\ |
197 | if(multifill[p] == '1' ){ context_circles.fillStyle = \"rgba(\"+multifillcolors[p]+\",\"+multifillopacity[p]+\")\";}else{context_circles.fillStyle = \"rgba( 255,255,255,0)\"; };\ |
||
198 | if(multidash[p] == '1' ){ if( context_circles.setLineDash ){context_circles.setLineDash([2,4]);}else{if(context_circles.mozDash){context_circles.mozDash = [2,4]};};};\ |
||
199 | var circles_x = new Array();var circles_y = new Array();var multi_radius = new Array();\ |
||
200 | var circles_snap = multisnaptogrid[p];\ |
||
201 | if( draw_things[p] == 'circle' ){desc = 2;}else{desc = 3;};\ |
||
202 | id_x = 'input_circles_x';id_y = 'input_circles_y';id_r = 'input_circles_r';\ |
||
9213 | schaersvoo | 203 | }\ |
204 | else\ |
||
205 | {\ |
||
9338 | schaersvoo | 206 | if( draw_things[p] == 'line' || draw_things[p] == 'lines' ){\ |
207 | var canvas_lines = create_canvas%d(1002,xsize,ysize);\ |
||
208 | var context_lines = canvas_lines.getContext(\"2d\");\ |
||
209 | context_lines.lineWidth = multilinewidth[p];\ |
||
9462 | schaersvoo | 210 | if(multilinewidth[p]%%2 == 1){ context_lines.translate(0.5,0.5);};\ |
9338 | schaersvoo | 211 | context_lines.strokeStyle = \"rgba(\"+multistrokecolors[p]+\",\"+multistrokeopacity[p]+\")\";\ |
212 | if(multidash[p] == '1' ){ if( context_lines.setLineDash ){context_lines.setLineDash([2,4]);}else{if(context_lines.mozDash){context_lines.mozDash = [2,4]};};};\ |
||
213 | var lines_x = new Array();var lines_y = new Array();\ |
||
214 | var lines_snap = multisnaptogrid[p];\ |
||
215 | if(draw_things[p] == 'line' ){desc = 4;}else{desc = 5;};\ |
||
216 | id_x = 'input_lines_x';id_y = 'input_lines_y';\ |
||
217 | }\ |
||
218 | else\ |
||
219 | {\ |
||
220 | if( draw_things[p] == 'segment' || draw_things[p] == 'segments' ){\ |
||
221 | var canvas_segments = create_canvas%d(1003,xsize,ysize);\ |
||
222 | var context_segments = canvas_segments.getContext(\"2d\");\ |
||
223 | context_segments.lineWidth = multilinewidth[p];\ |
||
9462 | schaersvoo | 224 | if(multilinewidth[p]%%2 == 1){ context_segments.translate(0.5,0.5);};\ |
9338 | schaersvoo | 225 | context_segments.strokeStyle = \"rgba(\"+multistrokecolors[p]+\",\"+multistrokeopacity[p]+\")\";\ |
226 | if(multidash[p] == '1' ){ if( context_segments.setLineDash ){context_segments.setLineDash([2,4]);}else{if(context_segments.mozDash){context_segments.mozDash = [2,4]};};};\ |
||
227 | var segments_x = new Array();var segments_y = new Array();\ |
||
228 | var segments_snap = multisnaptogrid[p];\ |
||
229 | if( draw_things[p] == 'segment' ){desc = 6;}else{ desc = 7;};\ |
||
9262 | schaersvoo | 230 | id_x = 'input_segments_x';id_y = 'input_segments_y';\ |
9213 | schaersvoo | 231 | }\ |
232 | else\ |
||
233 | {\ |
||
9262 | schaersvoo | 234 | if( draw_things[p] == 'arrow' || draw_things[p] == 'arrows' ){\ |
235 | var canvas_arrows = create_canvas%d(1004,xsize,ysize);\ |
||
236 | var context_arrows = canvas_arrows.getContext(\"2d\");\ |
||
237 | context_arrows.lineWidth = multilinewidth[p];\ |
||
9462 | schaersvoo | 238 | if(multilinewidth[p]%%2 == 1){ context_arrows.translate(0.5,0.5);};\ |
9262 | schaersvoo | 239 | context_arrows.lineCap = \"round\";\ |
240 | context_arrows.strokeStyle = \"rgba(\"+multistrokecolors[p]+\",\"+multistrokeopacity[p]+\")\";\ |
||
241 | context_arrows.fillStyle = context_arrows.strokeStyle;\ |
||
242 | if(multidash[p] == '1' ){ if( context_arrows.setLineDash ){context_arrows.setLineDash([2,4]);}else{if(context_arrows.mozDash){context_arrows.mozDash = [2,4]};};};\ |
||
243 | var arrows_x = new Array();var arrows_y = new Array();\ |
||
244 | var arrows_snap = multisnaptogrid[p];\ |
||
245 | if( draw_things[p] == 'arrow' ){desc = 8;}else{desc = 9;};\ |
||
246 | id_x = 'input_arrows_x';id_y = 'input_arrows_y';\ |
||
9213 | schaersvoo | 247 | }\ |
248 | else\ |
||
249 | {\ |
||
9372 | schaersvoo | 250 | if( draw_things[p] == 'rect' || draw_things[p] == 'rects' ){\ |
14032 | schaersvoo | 251 | var canvas_rects = create_canvas%d(1005,xsize,ysize);\ |
9372 | schaersvoo | 252 | var context_rects = canvas_rects.getContext(\"2d\");\ |
253 | context_rects.lineWidth = multilinewidth[p];\ |
||
9462 | schaersvoo | 254 | if(multilinewidth[p]%%2 == 1){ context_rects.translate(0.5,0.5);};\ |
9372 | schaersvoo | 255 | context_rects.strokeStyle = \"rgba(\"+multistrokecolors[p]+\",\"+multistrokeopacity[p]+\")\";\ |
256 | if(multidash[p] == '1' ){ if( context_rects.setlineDash ){context_rects.setlineDash([2,4]);}else{if(context_rects.mozDash){context_rects.mozDash = [2,4]};};};\ |
||
257 | if(multifill[p] == '1' ){ context_rects.fillStyle = \"rgba(\"+multifillcolors[p]+\",\"+multifillopacity[p]+\")\";}else{context_rects.fillStyle = \"rgba( 255,255,255,0)\"; };\ |
||
258 | var rects_x = new Array();var rects_y = new Array();\ |
||
259 | var rects_snap = multisnaptogrid[p];\ |
||
260 | if(draw_things[p] == 'rect' ){desc = 14;}else{desc = 15;};\ |
||
261 | id_x = 'input_rects_x';id_y = 'input_rects_y';\ |
||
9213 | schaersvoo | 262 | }\ |
263 | else\ |
||
264 | {\ |
||
9372 | schaersvoo | 265 | if( draw_things[p] == 'closedpoly'){\ |
266 | var canvas_closedpoly = create_canvas%d(1006,xsize,ysize);\ |
||
267 | var context_closedpoly = canvas_closedpoly.getContext(\"2d\");\ |
||
268 | context_closedpoly.lineCap = \"round\";\ |
||
269 | context_closedpoly.lineWidth = multilinewidth[p];\ |
||
9462 | schaersvoo | 270 | if(multilinewidth[p]%%2 == 1){ context_closedpoly.translate(0.5,0.5);};\ |
9372 | schaersvoo | 271 | context_closedpoly.lineCap = \"round\";\ |
272 | context_closedpoly.strokeStyle = \"rgba(\"+multistrokecolors[p]+\",\"+multistrokeopacity[p]+\")\";\ |
||
273 | if(multifill[p] == '1' ){ context_closedpoly.fillStyle = \"rgba(\"+multifillcolors[p]+\",\"+multifillopacity[p]+\")\";}else{context_closedpoly.fillStyle = \"rgba( 255,255,255,0)\"; };\ |
||
274 | if(multidash[p] == '1' ){ if( context_closedpoly.setLineDash ){context_closedpoly.setLineDash([2,4]);}else{if(context_closedpoly.mozDash){context_closedpoly.mozDash = [2,4]};};};\ |
||
275 | var closedpoly_x = new Array();var closedpoly_y = new Array();\ |
||
276 | var closedpoly_snap = multisnaptogrid[p];\ |
||
277 | desc = 12;\ |
||
278 | id_x = 'input_closedpoly_x';id_y = 'input_closedpoly_y';\ |
||
9338 | schaersvoo | 279 | }\ |
280 | else\ |
||
281 | {\ |
||
11230 | schaersvoo | 282 | if( draw_things[p] == 'triangle' || draw_things[p] == 'triangles' ){\ |
14032 | schaersvoo | 283 | var canvas_triangles = create_canvas%d(1007,xsize,ysize);\ |
9372 | schaersvoo | 284 | var context_triangles = canvas_triangles.getContext(\"2d\");\ |
285 | context_triangles.lineCap = \"round\";\ |
||
286 | context_triangles.lineWidth = multilinewidth[p];\ |
||
9462 | schaersvoo | 287 | if(multilinewidth[p]%%2 == 1){ context_triangles.translate(0.5,0.5);};\ |
9372 | schaersvoo | 288 | context_triangles.strokeStyle = \"rgba(\"+multistrokecolors[p]+\",\"+multistrokeopacity[p]+\")\";\ |
289 | if(multifill[p] == '1' ){ context_triangles.fillStyle = \"rgba(\"+multifillcolors[p]+\",\"+multifillopacity[p]+\")\";}else{context_triangles.fillStyle = \"rgba( 255,255,255,0)\"; };\ |
||
290 | if(multidash[p] == '1' ){ if( context_triangles.setLineDash ){context_triangles.setLineDash([2,4]);}else{if(context_triangles.mozDash){context_triangles.mozDash = [2,4]};};};\ |
||
291 | var triangles_x = new Array();var triangles_y = new Array();\ |
||
292 | var triangles_snap = multisnaptogrid[p];\ |
||
11226 | schaersvoo | 293 | if( draw_things[p] == 'triangle'){desc = 10;};\ |
294 | if( draw_things[p] == 'triangles'){desc = 11;};\ |
||
9372 | schaersvoo | 295 | id_x = 'input_triangles_x';id_y = 'input_triangles_y';id_r = 'input_triangles_r';\ |
296 | }\ |
||
297 | else\ |
||
298 | {\ |
||
14038 | schaersvoo | 299 | if( draw_things[p] == 'curvedarrow' || draw_things[p] == 'curvedarrows'){\ |
14032 | schaersvoo | 300 | var canvas_curvedarrows = create_canvas%d(1008,xsize,ysize);\ |
301 | var context_curvedarrows = canvas_curvedarrows.getContext(\"2d\");\ |
||
302 | context_curvedarrows.lineWidth = multilinewidth[p];\ |
||
303 | if(multilinewidth[p]%%2 == 1){ context_curvedarrows.translate(0.5,0.5);};\ |
||
304 | context_curvedarrows.lineCap = \"round\";\ |
||
305 | context_curvedarrows.strokeStyle = \"rgba(\"+multistrokecolors[p]+\",\"+multistrokeopacity[p]+\")\";\ |
||
306 | context_curvedarrows.fillStyle = context_curvedarrows.strokeStyle;\ |
||
307 | if(multidash[p] == '1' ){ if( context_curvedarrows.setLineDash ){context_curvedarrows.setLineDash([2,4]);}else{if(context_curvedarrows.mozDash){context_curvedarrows.mozDash = [2,4]};};};\ |
||
308 | var curvedarrows_x = new Array();var curvedarrows_y = new Array();\ |
||
309 | var curvedarrows_snap = multisnaptogrid[p];\ |
||
14038 | schaersvoo | 310 | if( draw_things[p] == 'curvedarrow' ){desc = 21;}else{desc = 22;};\ |
14390 | schaersvoo | 311 | id_x = 'input_curvedarrows_x';id_y = 'input_curvedarrows_y';;id_r = 'input_curvedarrows_r';\ |
11226 | schaersvoo | 312 | }\ |
313 | else\ |
||
314 | {\ |
||
14038 | schaersvoo | 315 | if( draw_things[p] == 'curvedarrow2' || draw_things[p] == 'curvedarrows2'){\ |
316 | if( draw_things[p] == 'curvedarrow2' ){desc = 23;}else{desc = 24;};\ |
||
317 | var canvas_curvedarrows2 = create_canvas%d(1009,xsize,ysize);\ |
||
318 | var context_curvedarrows2 = canvas_curvedarrows2.getContext(\"2d\");\ |
||
319 | context_curvedarrows2.lineWidth = multilinewidth[p];\ |
||
320 | if(multilinewidth[p]%%2 == 1){ context_curvedarrows2.translate(0.5,0.5);};\ |
||
321 | context_curvedarrows2.lineCap = \"round\";\ |
||
322 | context_curvedarrows2.strokeStyle = \"rgba(\"+multistrokecolors[p]+\",\"+multistrokeopacity[p]+\")\";\ |
||
323 | context_curvedarrows2.fillStyle = context_curvedarrows2.strokeStyle;\ |
||
324 | if(multidash[p] == '1' ){ if( context_curvedarrows2.setLineDash ){context_curvedarrows2.setLineDash([2,4]);}else{if(context_curvedarrows2.mozDash){context_curvedarrows2.mozDash = [2,4]};};};\ |
||
325 | var curvedarrows2_x = new Array();var curvedarrows2_y = new Array();\ |
||
326 | var curvedarrows2_snap = multisnaptogrid[p];\ |
||
14390 | schaersvoo | 327 | id_x = 'input_curvedarrows2_x';id_y = 'input_curvedarrows2_y';id_r = 'input_curvedarrows2_r';\ |
11230 | schaersvoo | 328 | }\ |
329 | else\ |
||
330 | {\ |
||
14038 | schaersvoo | 331 | if( draw_things[p].indexOf('para') != -1 ){\ |
332 | var canvas_parallelogram = create_canvas%d(1010,xsize,ysize);\ |
||
333 | var context_parallelogram = canvas_parallelogram.getContext(\"2d\");\ |
||
334 | context_parallelogram.lineCap = \"round\";\ |
||
335 | context_parallelogram.lineWidth = multilinewidth[p];\ |
||
336 | if(multilinewidth[p]%%2 == 1){ context_parallelogram.translate(0.5,0.5);};\ |
||
337 | context_parallelogram.strokeStyle = \"rgba(\"+multistrokecolors[p]+\",\"+multistrokeopacity[p]+\")\";\ |
||
338 | if(multifill[p] == '1' ){ context_parallelogram.fillStyle = \"rgba(\"+multifillcolors[p]+\",\"+multifillopacity[p]+\")\";}else{context_parallelogram.fillStyle = \"rgba( 255,255,255,0)\"; };\ |
||
339 | if(multidash[p] == '1' ){ if( context_parallelogram.setLineDash ){context_parallelogram.setLineDash([2,4]);}else{if(context_parallelogram.mozDash){context_parallelogram.mozDash = [2,4]};};};\ |
||
340 | var parallelogram_x = new Array();var parallelogram_y = new Array();\ |
||
341 | var parallelogram_snap = multisnaptogrid[p];\ |
||
342 | if( draw_things[p] == 'parallelogram'){multiuserinput[p] = 0;desc = 18;};\ |
||
343 | if( draw_things[p] == 'parallelograms'){multiuserinput[p] = 0;desc = 19;};\ |
||
344 | id_x = 'input_parallelogram_x';id_y = 'input_parallelogram_y';id_r = 'input_parallelogram_r';\ |
||
14032 | schaersvoo | 345 | }\ |
346 | else\ |
||
347 | {\ |
||
14038 | schaersvoo | 348 | if( draw_things[p].indexOf('poly') != -1 ){\ |
349 | var canvas_polys = create_canvas%d(1011,xsize,ysize);\ |
||
350 | var context_polys = canvas_polys.getContext(\"2d\");\ |
||
351 | context_polys.lineCap = \"round\";\ |
||
352 | context_polys.lineWidth = multilinewidth[p];\ |
||
353 | if(multilinewidth[p]%%2 == 1){ context_polys.translate(0.5,0.5);};\ |
||
354 | context_polys.strokeStyle = \"rgba(\"+multistrokecolors[p]+\",\"+multistrokeopacity[p]+\")\";\ |
||
355 | if(multifill[p] == '1' ){ context_polys.fillStyle = \"rgba(\"+multifillcolors[p]+\",\"+multifillopacity[p]+\")\";}else{context_polys.fillStyle = \"rgba( 255,255,255,0)\"; };\ |
||
356 | if(multidash[p] == '1' ){ if( context_polys.setLineDash ){context_polys.setLineDash([2,4]);}else{if(context_polys.mozDash){context_polys.mozDash = [2,4]};};};\ |
||
357 | var polys_x = new Array();var polys_y = new Array();\ |
||
358 | var polys_snap = multisnaptogrid[p];\ |
||
359 | if( draw_things[p].indexOf('polys') != -1){desc = 17;}else{desc = 16;}\ |
||
360 | multiuserinput[p] = 0;\ |
||
361 | id_x = 'input_polys_x';id_y = 'input_polys_y';id_r = 'input_polys_r';\ |
||
362 | }\ |
||
363 | else\ |
||
364 | {\ |
||
365 | if( draw_things[p] == 'images' ){\ |
||
366 | var canvas_images = create_canvas%d(1012,xsize,ysize);\ |
||
367 | var context_images = canvas_images.getContext(\"2d\");\ |
||
368 | context_images.font = multifont_family;\ |
||
369 | context_images.fillStyle = \"rgba(\"+multifont_color+\",\"+multistrokeopacity[p]+\")\";\ |
||
370 | var images_snap = multisnaptogrid[p];\ |
||
371 | var images_x = new Array();var images_y = new Array();\ |
||
372 | var images_id = new Array();\ |
||
373 | id_x = 'input_images_x';id_y = 'input_images_y';id_r = 'input_images_r';\ |
||
14044 | schaersvoo | 374 | if( typeof(imagepalette) === 'object' ){multiuserinput[p] = 1;};\ |
14038 | schaersvoo | 375 | desc = 20;\ |
376 | }\ |
||
377 | else\ |
||
378 | {\ |
||
379 | if( draw_things[p] == 'text' ){\ |
||
380 | var canvas_text = create_canvas%d(1013,xsize,ysize);\ |
||
381 | var context_text = canvas_text.getContext(\"2d\");\ |
||
382 | context_text.font = multifont_family;\ |
||
383 | context_text.fillStyle = \"rgba(\"+multifont_color+\",\"+multistrokeopacity[p]+\")\";\ |
||
384 | var text_snap = multisnaptogrid[p];\ |
||
385 | var text_x = new Array;var text_y = new Array; var text_abc = new Array();\ |
||
386 | id_x = 'input_text_x';id_y = 'input_text_y';id_r = 'input_text_r';\ |
||
387 | desc = 13;\ |
||
388 | };\ |
||
389 | };\ |
||
14032 | schaersvoo | 390 | };\ |
11230 | schaersvoo | 391 | };\ |
11226 | schaersvoo | 392 | };\ |
9372 | schaersvoo | 393 | };\ |
9262 | schaersvoo | 394 | };\ |
9213 | schaersvoo | 395 | };\ |
396 | };\ |
||
397 | };\ |
||
398 | };\ |
||
399 | };\ |
||
400 | };\ |
||
9262 | schaersvoo | 401 | };\ |
14053 | schaersvoo | 402 | if( use_controls == 1 ){\ |
403 | inner_html+=\"<tr style='background-color:rgba(\"+multistrokecolors[p]+\",0.4)'><td><input type='button' id='canvasdraw_\"+draw_things[p]+\"' style=\"+button_style+\" onclick='javascript:userdraw_primitive=\"+desc+\";multidraw_click_cnt = 0;' value='\"+multilabel[p]+\"' /></td><td><input type='button' style='\"+button_style+\"' onclick='javascript:clear_draw_area%d(\"+desc+\",\"+p+\");' value='delete' /></td>\";\ |
||
404 | if(multiuserinput[p] == '1'){ \ |
||
405 | if(desc == 0 || desc == 1 ){\ |
||
406 | inner_html+=\"<td><b>(</b><input type='text' size='5' value='' id='\"+id_x+\"' style='\"+button_style+\"' /><b>:</b> <input type='text' size='5' value='' id='\"+id_y+\"' style='\"+button_style+\"' /> <b>)</b></td>\";\ |
||
9338 | schaersvoo | 407 | }\ |
408 | else\ |
||
409 | {\ |
||
14053 | schaersvoo | 410 | if(desc == 2 || desc == 3){\ |
411 | inner_html+=\"<td><b>M : (<input type='text' size='5' value='' id='\"+id_x+\"' style='\"+button_style+\"' /> : <input type='text' size='5' value='' id='\"+id_y+\"' style='\"+button_style+\"' />) R</b> : <input type='text' size='3' value='' id='\"+id_r+\"' style='\"+button_style+\"' /></b></td>\";\ |
||
9338 | schaersvoo | 412 | }\ |
413 | else\ |
||
414 | {\ |
||
14053 | schaersvoo | 415 | if(desc >3 && desc <10 || desc == 14 || desc == 15){\ |
416 | inner_html+=\"<td><b>(</b><input type='text' size='5' value='x1 : y1' id='\"+id_x+\"' style='\"+button_style+\";text-align:center;' /><b>) --- (</b> <input type='text' size='5' value='x2 : y2' id='\"+id_y+\"' style='\"+button_style+\";text-align:center;' /> <b>)</b></td>\";\ |
||
9338 | schaersvoo | 417 | }\ |
418 | else\ |
||
419 | {\ |
||
14390 | schaersvoo | 420 | if( desc == 10 || desc == 11 || desc > 20){\ |
14053 | schaersvoo | 421 | inner_html+=\"<td><b>(<input type='text' size='5' value='x1 : y1' id='\"+id_x+\"' style='\"+button_style+\"' />) -- (<input type='text' size='5' value='x2 : y2' id='\"+id_y+\"' style='\"+button_style+\"' />) -- (<input type='text' size='5' value='x3 : y3' id='\"+id_r+\"' style='\"+button_style+\"' />)</b></td>\";\ |
9338 | schaersvoo | 422 | }\ |
423 | else\ |
||
424 | {\ |
||
14053 | schaersvoo | 425 | if( desc == 12 || desc == 16 || desc == 17 || desc == 18 || desc == 19){\ |
426 | inner_html+=\"<td><b>(<input type='text' size='8' value='x1,x2...x_n' id='\"+id_x+\"' style='\"+button_style+\"' /> ---- <input type='text' size='8' value='y1,y2...y_n' id='\"+id_y+\"' style='\"+button_style+\"' />)</b></td>\";\ |
||
14038 | schaersvoo | 427 | }\ |
428 | else\ |
||
429 | {\ |
||
14053 | schaersvoo | 430 | if( desc == 13 ){\ |
431 | inner_html+=\"<td><b>( <input type='text' size='2' value='' id='\"+id_x+\"' style='\"+button_style+\"' /> - <input type='text' size='2' value='' id='\"+id_y+\"' style='\"+button_style+\"' /> )</b><input type='text' size='4' value='' id='\"+id_r+\"' style='\"+button_style+\"' /></td>\";\ |
||
432 | }\ |
||
433 | else\ |
||
434 | {\ |
||
435 | if( desc == 20 ){\ |
||
436 | inner_html+=\"<td><table style ='\"+button_style+\"'><tr>\";\ |
||
437 | for(var im=0; im < imagepalette.length; im++){\ |
||
438 | if( im %% 4 == 0 ){ inner_html+=\"</tr><tr>\"};\ |
||
439 | inner_html+=\"<td><img onclick='javascript:place_image_on_canvas(this.id);' src='\"+imagepalette[im]+\"' id='imagepalette_\"+im+\"' alt='none'/></td>\";\ |
||
440 | };\ |
||
441 | inner_html+=\"</table></td>\";\ |
||
14038 | schaersvoo | 442 | };\ |
443 | };\ |
||
9338 | schaersvoo | 444 | };\ |
445 | };\ |
||
446 | };\ |
||
447 | };\ |
||
448 | };\ |
||
14053 | schaersvoo | 449 | if( desc != 20 ){inner_html+=\"<td><input type='button' id='canvasdraw_ok_button' style='\"+button_style+\"' onclick='javascript:update_draw_area%d(\"+desc+\",\"+id_x+\",\"+id_y+\",\"+id_r+\")' value='OK'/ ></td></tr>\";};\ |
11791 | schaersvoo | 450 | }\ |
451 | else\ |
||
452 | {\ |
||
14053 | schaersvoo | 453 | if( desc == 13 ){\ |
454 | inner_html+=\"<td><input type='text' size='4' value='' id='\"+id_r+\"' style='\"+button_style+\"' /></td><td></td><td></td></tr>\";\ |
||
455 | }\ |
||
456 | else\ |
||
457 | {\ |
||
458 | inner_html+\"<td> </td><td> </td><td> </td></tr>\";\ |
||
459 | };\ |
||
11791 | schaersvoo | 460 | };\ |
14053 | schaersvoo | 461 | if( wims_status != 'done' ){\ |
462 | tooltip_div.innerHTML = \"<table style='margin: 0 auto;'>\"+inner_html+\"<tr><td> </td><td><input type='button' id='canvasdraw_stop_drawing' style='\"+button_style+\"' value='\"+multilabel[multilabel.length - 1]+\"' onclick='javascript:userdraw_primitive=null;' /></td><td> </td></tr></table>\";\ |
||
463 | };\ |
||
9239 | schaersvoo | 464 | };\ |
14063 | schaersvoo | 465 | if( use_controls == 0 && draw_things_length == 1 ){userdraw_primitive= desc;};\ |
9262 | schaersvoo | 466 | };\ |
14038 | schaersvoo | 467 | function multi_snap_check(x,y,snap){\ |
468 | switch(snap){\ |
||
469 | case 1:return [snap_to_x(x),snap_to_y(y)];break;\ |
||
470 | case 2:return [snap_to_x(x),y];break;\ |
||
471 | case 3:return [x,snap_to_y(y)];break;\ |
||
472 | case 4:return snap_to_points(x,y);break;\ |
||
473 | default: return [x,y];break;\ |
||
9213 | schaersvoo | 474 | };\ |
9262 | schaersvoo | 475 | };\ |
14038 | schaersvoo | 476 | function coord_split(coord){if(coord.indexOf(':') > 0 ){return coord.split(':');}else{if(coord.indexOf(';') > 0 ){return coord.split(';');}else{if(coord.indexOf(',') > 0 ){return coord.split(',');}else{alert(coord+'-- X : Y ');return;};};};};\ |
9406 | schaersvoo | 477 | function scale_xy(type,xy){var tmp_xmin = xmin;var tmp_xmax = xmax;var tmp_ymin = ymin;var tmp_ymax = ymax;xmin=zoom_xy[0];xmax=zoom_xy[1];ymin=zoom_xy[2];ymax=zoom_xy[3];if(type == 1 ){for(var p=0;p<xy.length;p++){xy[p] = px2x(xy[p]);};}else{for(var p=0;p<xy.length;p++){xy[p] = px2y(xy[p]);};};xmin = tmp_xmin;ymin = tmp_ymin;xmax = tmp_xmax;ymax = tmp_ymax;if(type == 1){for(var p=0;p<xy.length;p++){xy[p] = x2px(xy[p]);}}else{for(var p=0;p<xy.length;p++){xy[p] = y2px(xy[p]);};};return xy;};\ |
478 | function scale_multi_radius(r){for(var p = 0 ; p < r.length;p++ ){r[p] = zoom_xy[0]/xmin*r[p];};return r;};\ |
||
479 | redraw_all%d = function(){\ |
||
14038 | schaersvoo | 480 | if( points_x && points_x.length > 0 ){points_x = scale_xy(1,points_x);points_y = scale_xy(1,points_y);draw_points();};\ |
481 | if( circles_x && circles_x.length > 0 ){circles_x = scale_xy(1,circles_x);circles_y = scale_xy(1,circles_y);multi_radius = scale_multi_radius(multi_radius);draw_circles();};\ |
||
482 | if( segments_x && segments_x.length > 0 ){segments_x = scale_xy(1,segments_x);segments_y = scale_xy(1,segments_y);draw_segments();};\ |
||
483 | if( arrows_x && arrows_x.length > 0 ){arrows_x = scale_xy(1,arrows_x);arrows_y = scale_xy(2,arrows_y);draw_arrows();};\ |
||
484 | if( lines_x && lines_x.length > 0 ){lines_x = scale_xy(1,lines_x);lines_y = scale_xy(2,lines_y);draw_lines();};\ |
||
485 | if( triangles_x && triangles_x.length > 0 ){triangles_x = scale_xy(1,triangles_x);triangles_y = scale_xy(2,triangles_y);draw_triangles();};\ |
||
486 | if( rects_x && rects_x.length > 0 ){rects_x = scale_xy(1,rects_x);rects_y = scale_xy(2,rects_y);draw_rects();};\ |
||
487 | if( closedpoly_x && closedpoly_x.length > 0 ){closedpoly_x = scale_xy(1,closedpoly_x);closedpoly_y = scale_xy(2,closedpoly_y);draw_closedpoly();};\ |
||
488 | if( text_x && text_x.length > 0 ){text_x = scale_xy(1,text_x);text_y = scale_xy(2,text_y);draw_text();};\ |
||
489 | if( polys_x && polys_x.length > 0 ){polys_x = scale_xy(1,polys_x);polys_y = scale_xy(2,polys_y);draw_polys();};\ |
||
490 | if( parallelogram_x && parallelogram_x.length > 0 ){parallelogram_x = scale_xy(1,parallelogram_x);parallelogram_y = scale_xy(2,parallelogram_y);draw_parallelogram();};\ |
||
491 | if( images_x && images_x.length > 0 ){images_x = scale_xy(1,images_x);images_y = scale_xy(2,images_y);draw_images();};\ |
||
492 | if( curvedarrows_x && curvedarrows_x.length > 0 ){curvedarrows_x = scale_xy(1,curvedarrows_x);curvedarrows_y = scale_xy(2,curvedarrows_y);draw_curvedarrows();};\ |
||
493 | if( curvedarrows2_x && curvedarrows2_x.length > 0 ){curvedarrows2_x = scale_xy(1,curvedarrows2_x);curvedarrows2_y = scale_xy(2,curvedarrows2_y);draw_curvedarrows2();};\ |
||
9406 | schaersvoo | 494 | return;\ |
495 | };\ |
||
9262 | schaersvoo | 496 | update_draw_area%d = function(desc,id_x,id_y,id_r){\ |
14038 | schaersvoo | 497 | if( desc == 20 ){ draw_images();return;};\ |
14390 | schaersvoo | 498 | var x1,x2,x3,y1,y2,y3,r,A,B,C;\ |
14038 | schaersvoo | 499 | x1 = document.getElementById(id_x.id).value;y1 = document.getElementById(id_y.id).value;\ |
500 | if(desc > 3 && desc < 12 || desc == 14 || desc == 15){A = coord_split(x1);B = coord_split(y1);if(A.length != 2 || B.length != 2){alert(' X : Y ');return;};x1 = x2px(safe_eval(A[0]));y1 = y2px(safe_eval(A[1]));x2 = x2px(safe_eval(B[0]));y2 = y2px(safe_eval(B[1]));\ |
||
501 | if(desc == 10 || desc == 11 ){r = document.getElementById(id_r.id).value;A = coord_split(r);x3 = x2px(safe_eval(A[0]));y3 = y2px(safe_eval(A[1]));};\ |
||
9262 | schaersvoo | 502 | }\ |
503 | else\ |
||
504 | {\ |
||
505 | if( desc < 4 ){\ |
||
9239 | schaersvoo | 506 | x1 = x2px(safe_eval(x1));y1 = y2px( safe_eval(y1));\ |
9213 | schaersvoo | 507 | };\ |
9262 | schaersvoo | 508 | };\ |
14390 | schaersvoo | 509 | if(desc > 20 ){\ |
510 | r = document.getElementById(id_r.id).value;\ |
||
511 | A = coord_split(x1);B = coord_split(y1);C = coord_split(r);\ |
||
512 | x1 = x2px(safe_eval(A[0]));y1 = y2px(safe_eval(A[1]));\ |
||
513 | x2 = x2px(safe_eval(B[0]));y2 = y2px(safe_eval(B[1]));\ |
||
514 | x3 = x2px(safe_eval(C[0]));y3 = y2px(safe_eval(C[1]));\ |
||
515 | };\ |
||
9262 | schaersvoo | 516 | switch(desc){\ |
517 | case 0: points(x1,y1,0,0);break;\ |
||
518 | case 1: points(x1,y1,0,1);break;\ |
||
519 | case 2: r = scale_x_radius(safe_eval(document.getElementById(id_r.id).value));multi_radius[0] = r;circles_x[0] = x1;circles_y[0] = y1;draw_circles();break;\ |
||
520 | case 3: r = scale_x_radius(safe_eval(document.getElementById(id_r.id).value));multi_radius.push(r);circles_x.push(x1);circles_y.push(y1);draw_circles();break;\ |
||
521 | case 4: lines_x[0] = x1;lines_x[1] = x2;lines_y[0] = y1;lines_y[1] = y2;calc_lines();draw_lines();break;\ |
||
522 | case 5: lines_x.push(x1);lines_x.push(x2);lines_y.push(y1);lines_y.push(y2);calc_lines();draw_lines();break;\ |
||
523 | case 6: segments_x[0] = x1;segments_x[1] = x2;segments_y[0] = y1;segments_y[1] = y2;draw_segments();break;\ |
||
524 | case 7: segments_x.push(x1);segments_x.push(x2);segments_y.push(y1);segments_y.push(y2);draw_segments();break;\ |
||
525 | case 8: arrows_x[0] = x1;arrows_x[1] = x2;arrows_y[0] = y1;arrows_y[1] = y2;draw_arrows();break;\ |
||
526 | case 9: arrows_x.push(x1);arrows_x.push(x2);arrows_y.push(y1);arrows_y.push(y2);draw_arrows();break;\ |
||
527 | case 10: triangles_x[0] = x1;triangles_x[1] = x2;triangles_x[2] = x3;triangles_y[0] = y1;triangles_y[1] = y2;triangles_y[2] = y3;draw_triangles();break;\ |
||
528 | case 11: triangles_x.push(x1);triangles_x.push(x2);triangles_x.push(x3);triangles_y.push(y1);triangles_y.push(y2);triangles_y.push(y3);draw_triangles();break;\ |
||
14038 | schaersvoo | 529 | case 12: A = coord_split(x1);B = coord_split(y1);var plus_len = A.length;if( plus_len != B.length){alert('mismatch between the number of x-values and y-values');return;};for(var p = 0 ; p < plus_len ; p++){x1 = x2px(safe_eval(A[p]));y1 = y2px(safe_eval(B[p]));closedpoly_x.push(x1);closedpoly_y.push(y1);};x1 = x2px(safe_eval(A[0]));y1 = y2px(safe_eval(B[0]));closedpoly_x.push(x1);closedpoly_y.push(y1);draw_closedpoly();break;\ |
11791 | schaersvoo | 530 | case 13: text_abc.push( document.getElementById(id_r.id).value);text(x2px(safe_eval(x1)),y2px(safe_eval(y1)),0,1);draw_text();break;\ |
9372 | schaersvoo | 531 | case 14: rects_x[0] = x1;rects_x[1] = x2;rects_y[0] = y1;rects_y[1] = y2;draw_rects();break;\ |
532 | case 15: rects_x.push(x1);rects_x.push(x2);rects_y.push(y1);rects_y.push(y2);draw_rects();break;\ |
||
11226 | schaersvoo | 533 | case 16: polys_x[0] = x1;polys_x[1] = x2;polys_x[2] = x3;polys_y[0] = y1;polys_y[1] = y2;polys_y[2] = y3;draw_polys();break;\ |
534 | case 17: polys_x.push(x1);polys_x.push(x2);polys_x.push(x3);polys_y.push(y1);polys_y.push(y2);polys_y.push(y3);draw_polys();break;\ |
||
11230 | schaersvoo | 535 | case 18: parallelogram_x[0] = x1;parallelogram_x[1] = x2;parallelogram_x[2] = x3;parallelogram_y[0] = y1;parallelogram_y[1] = y2;parallelogram_y[2] = y3;draw_parallelogram();break;\ |
536 | case 19: parallelogram_x.push(x1);parallelogram_x.push(x2);parallelogram_x.push(x3);parallelogram_y.push(y1);parallelogram_y.push(y2);parallelogram_y.push(y3);draw_parallelogram();break;\ |
||
14038 | schaersvoo | 537 | case 20: draw_images();break;\ |
538 | case 21: curvedarrows_x[0] = x1;curvedarrows_x[1] = x2;curvedarrows_x[2] = x3;curvedarrows_y[0] = y1;curvedarrows_y[1] = y2;curvedarrows_y[2] = y3;draw_curvedarrows();break;\ |
||
539 | case 22: curvedarrows_x.push(x1);curvedarrows_x.push(x2);curvedarrows_x.push(x3);curvedarrows_y.push(y1);curvedarrows_y.push(y2);curvedarrows_y.push(y3);draw_curvedarrows();break;\ |
||
540 | case 23: curvedarrows2_x[0] = x1;curvedarrows2_x[1] = x2;curvedarrows2_x[2] = x3;curvedarrows2_y[0] = y1;curvedarrows2_y[1] = y2;curvedarrows2_y[2] = y3;draw_curvedarrows2();break;\ |
||
541 | case 24: curvedarrows2_x.push(x1);curvedarrows2_x.push(x2);curvedarrows2_x.push(x3);curvedarrows2_y.push(y1);curvedarrows2_y.push(y2);curvedarrows2_y.push(y3);draw_curvedarrows2();break;\ |
||
11226 | schaersvoo | 542 | default:break;\ |
9244 | schaersvoo | 543 | };\ |
14063 | schaersvoo | 544 | };",canvas_root_id,canvas_root_id,canvas_root_id,draw_types,canvas_root_id,button_style, |
14038 | schaersvoo | 545 | canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id, |
14063 | schaersvoo | 546 | canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id); |
14038 | schaersvoo | 547 | |
14948 | obado | 548 | /* |
549 | now add specific draw functions according to draw_types |
||
9213 | schaersvoo | 550 | these will be somewhat simpler and less fancy-full than for the 'single object' userdraw command... |
551 | the 'switch function' in the mouselisteners will probably eat more CPU...so the rest needs to be faster: |
||
552 | we don't want to imitate these horribly slow js-libraries like JSXgraph |
||
9239 | schaersvoo | 553 | |
554 | 28/6/2015 |
||
555 | TODO: add a selection of the 'generic js-code' from above into these C-code selector parts ! |
||
9213 | schaersvoo | 556 | */ |
11808 | schaersvoo | 557 | |
558 | /* |
||
14948 | obado | 559 | 3/8/2017 : multidraw text is allways centered on click-coordinates ! |
14038 | schaersvoo | 560 | use_offset : 0=none; 1=yoffset; 2=xoffset; 3=xyoffset; 4=centered |
11808 | schaersvoo | 561 | */ |
14038 | schaersvoo | 562 | if( strstr(draw_types,"images") != 0){ |
14270 | schaersvoo | 563 | fprintf(js_include_file,"var current_id = null;var external_div_cnt=0;\ |
14038 | schaersvoo | 564 | function image_adjust(image,x,y){\ |
565 | var centered = %d;\ |
||
566 | var w = parseInt(image.width);var h = parseInt(image.height);\ |
||
567 | switch(centered){\ |
||
568 | case 0: return [x,y];break;\ |
||
569 | case 1: return [x,parseInt(y-0.5*h)];break;\ |
||
570 | case 2: return [parseInt(x+0.5*h),y];break;\ |
||
571 | case 3: return [parseInt(x+0.5*h),parseInt(y-0.5*h)];break;\ |
||
572 | case 4: return [parseInt(x-0.5*w),parseInt(y-0.5*h)];break;\ |
||
573 | default: return [x,y];break;\ |
||
574 | };\ |
||
575 | };\ |
||
576 | place_image_on_canvas = function(id){\ |
||
577 | var thing = document.getElementById(id);\ |
||
578 | var tag = thing.tagName;\ |
||
14270 | schaersvoo | 579 | if(tag == 'SVG'){draw_mathml_svg(thing,id);return;};\ |
14295 | schaersvoo | 580 | if(tag == 'DIV' || tag == 'SPAN' || tag == 'P'){draw_mathml_div(thing,id);return;};\ |
14038 | schaersvoo | 581 | var src = thing.src;\ |
582 | var image = new Image();\ |
||
583 | image.src = src;\ |
||
584 | image.id = 'placed_'+id;\ |
||
14296 | schaersvoo | 585 | image.width = thing.width;\ |
586 | image.height = thing.height;\ |
||
14038 | schaersvoo | 587 | image.onload = function(){ current_id = id; };\ |
14270 | schaersvoo | 588 | return;\ |
14038 | schaersvoo | 589 | };\ |
14270 | schaersvoo | 590 | function draw_mathml_div(thing,id){\ |
591 | var fix_div = document.createElement('DIV');\ |
||
592 | var new_id='placed_'+external_div_cnt+'_'+id;\ |
||
593 | fix_div.setAttribute('id',new_id);\ |
||
14295 | schaersvoo | 594 | var w = parseInt(thing.clientWidth);\ |
595 | var h = parseInt(thing.clientHeight);\ |
||
14270 | schaersvoo | 596 | fix_div.innerHTML = thing.innerHTML;\ |
14295 | schaersvoo | 597 | fix_div.setAttribute('style','display:none;position;absolute;width:'+w+'px;height:'+h+'px');\ |
598 | fix_div.width = w;fix_div.height = h;\ |
||
14270 | schaersvoo | 599 | canvas_div.appendChild(fix_div);\ |
600 | current_id = new_id;\ |
||
601 | external_div_cnt++;\ |
||
602 | return;\ |
||
603 | };\ |
||
14038 | schaersvoo | 604 | function draw_mathml_svg(thing,id){\ |
14270 | schaersvoo | 605 | var fix_div = document.createElement('DIV');\ |
14038 | schaersvoo | 606 | fix_div.setAttribute('style','display:none;position;relative');\ |
607 | canvas_div.appendChild(fix_div);\ |
||
608 | var image = new Image();\ |
||
609 | var svg_string = new XMLSerializer().serializeToString(thing);\ |
||
610 | var dom = self.URL || self.webkitURL || self;\ |
||
611 | var svg = new Blob([svg_string], {type: \"image/svg+xml;charset=utf-8\"});\ |
||
612 | var url = dom.createObjectURL(svg);\ |
||
613 | image.src= url;\ |
||
614 | image.id = 'placed_'+id;\ |
||
615 | image.onload = function(){\ |
||
616 | current_id = image.id;\ |
||
617 | fix_div.innerHTML='<img src='+image.src+' id='+image.id+' alt=\"this should not happen today...!\"/>';\ |
||
618 | };\ |
||
14270 | schaersvoo | 619 | return;\ |
14038 | schaersvoo | 620 | };\ |
621 | function images(x,y,event_which,num){\ |
||
622 | if(event_which == 1){ return;};\ |
||
623 | if(num == 1 && current_id){\ |
||
624 | var xy = multi_snap_check(x,y,images_snap);\ |
||
625 | images_x.push(xy[0]);\ |
||
626 | images_y.push(xy[1]);\ |
||
627 | images_id.push(current_id);\ |
||
628 | current_id = null;\ |
||
629 | };\ |
||
630 | draw_images();\ |
||
631 | };\ |
||
632 | function draw_images(){\ |
||
633 | context_images.clearRect(0,0,xsize,ysize);\ |
||
14270 | schaersvoo | 634 | var xy;var img;var tag;\ |
14038 | schaersvoo | 635 | for(var p = 0 ; p < images_x.length; p++){\ |
636 | if( images_id[p] ){\ |
||
637 | img = document.getElementById(images_id[p]);\ |
||
14270 | schaersvoo | 638 | tag = img.tagName;\ |
14038 | schaersvoo | 639 | xy = image_adjust(img,images_x[p],images_y[p]);\ |
14295 | schaersvoo | 640 | if( tag != 'IMG' ){\ |
641 | img.setAttribute('style','display:inline-block;position:absolute;top:'+xy[1]+'px;left:'+xy[0]+'px;');\ |
||
14270 | schaersvoo | 642 | }else{\ |
14296 | schaersvoo | 643 | context_images.drawImage(img,xy[0],xy[1],img.width,img.height);\ |
14270 | schaersvoo | 644 | };\ |
14038 | schaersvoo | 645 | };\ |
646 | };\ |
||
647 | };",use_offset); |
||
648 | } |
||
14948 | obado | 649 | |
9338 | schaersvoo | 650 | if( strstr(draw_types,"text") != 0){ |
651 | fprintf(js_include_file,"function text(x,y,event_which,num){\ |
||
652 | if(event_which == 1){ return; };\ |
||
14038 | schaersvoo | 653 | var xy = multi_snap_check(x,y,text_snap);\ |
9338 | schaersvoo | 654 | if( num == 0 ){\ |
14038 | schaersvoo | 655 | text_x[0] = xy[0];\ |
656 | text_y[0] =xy[1];\ |
||
9338 | schaersvoo | 657 | }else{\ |
14038 | schaersvoo | 658 | text_x.push(xy[0]);\ |
659 | text_y.push(xy[1]);\ |
||
9338 | schaersvoo | 660 | };\ |
661 | draw_text();\ |
||
662 | };\ |
||
14038 | schaersvoo | 663 | function conv_to_unicode(str){\ |
664 | return str.replace(/\\u[\\dA-F]{4}/gi,function(match){\ |
||
665 | return String.fromCharCode(parseInt(match.replace(/\\u/g,''), 16));});\ |
||
666 | };\ |
||
9338 | schaersvoo | 667 | function draw_text(){\ |
11808 | schaersvoo | 668 | var half = 0;\ |
14038 | schaersvoo | 669 | var height = 0.3 * (context_text.measureText('M').width);\ |
9338 | schaersvoo | 670 | context_text.clearRect(0,0,xsize,ysize);\ |
671 | for(var p = 0 ; p < text_x.length ; p++ ){\ |
||
14038 | schaersvoo | 672 | if( typeof(text_abc[p]) === 'undefined'){\ |
673 | var txt = conv_to_unicode(document.getElementById('input_text_r').value);\ |
||
674 | text_abc.push(txt);\ |
||
675 | };\ |
||
11808 | schaersvoo | 676 | half = 0.5*( context_text.measureText(text_abc[p]).width );\ |
14038 | schaersvoo | 677 | context_text.fillText(text_abc[p],text_x[p] - half,text_y[p] + height);\ |
9338 | schaersvoo | 678 | };\ |
679 | };"); |
||
680 | } |
||
681 | |||
9213 | schaersvoo | 682 | if( strstr(draw_types,"point") != 0){ |
683 | fprintf(js_include_file,"function points(x,y,event_which,num){\ |
||
684 | if(event_which == 1){ return; };\ |
||
14038 | schaersvoo | 685 | var xy = multi_snap_check(x,y,points_snap);\ |
9213 | schaersvoo | 686 | if( num == 0 ){\ |
14038 | schaersvoo | 687 | points_x[0] = xy[0];\ |
688 | points_y[0] = xy[1];\ |
||
9213 | schaersvoo | 689 | }else{\ |
14038 | schaersvoo | 690 | points_x.push(xy[0]);\ |
691 | points_y.push(xy[1]);\ |
||
9213 | schaersvoo | 692 | };\ |
693 | draw_points();\ |
||
694 | };\ |
||
695 | function draw_points(){\ |
||
9406 | schaersvoo | 696 | var radius = 2*(context_points.lineWidth);\ |
9213 | schaersvoo | 697 | context_points.clearRect(0,0,xsize,ysize);\ |
698 | for(var p = 0 ; p < points_x.length ; p++ ){\ |
||
699 | context_points.beginPath();\ |
||
700 | context_points.arc(points_x[p],points_y[p],radius,0,2*Math.PI,false);\ |
||
701 | context_points.closePath();\ |
||
702 | context_points.fill();\ |
||
703 | };\ |
||
704 | };"); |
||
705 | } |
||
14948 | obado | 706 | |
9213 | schaersvoo | 707 | if( strstr(draw_types,"circle") != 0){ |
708 | fprintf(js_include_file,"function circles(x,y,event_which,num){\ |
||
14038 | schaersvoo | 709 | var xy = multi_snap_check(x,y,circles_snap);\ |
9213 | schaersvoo | 710 | var last = circles_x.length - 1;\ |
711 | var xc = circles_x[last];\ |
||
712 | var yc = circles_y[last];\ |
||
713 | if(event_which == 0){\ |
||
14159 | schaersvoo | 714 | if( multidraw_click_cnt == 0 ){\ |
715 | if( num == 0 ){\ |
||
716 | circles_x[0]=xy[0];circles_y[0]=xy[1];multi_radius[0]=4;\ |
||
717 | }\ |
||
718 | else\ |
||
719 | {\ |
||
720 | circles_x.push(xy[0]);circles_y.push(xy[1]);multi_radius.push(4);\ |
||
721 | };\ |
||
722 | };\ |
||
14038 | schaersvoo | 723 | multidraw_click_cnt++;\ |
9213 | schaersvoo | 724 | }\ |
725 | else\ |
||
726 | {\ |
||
14038 | schaersvoo | 727 | if( multidraw_click_cnt == 1 ){\ |
14159 | schaersvoo | 728 | multi_radius[last] = parseInt(Math.sqrt( (xy[0] - xc)*(xy[0] - xc) + (xy[1] - yc)*(xy[1] - yc) ));\ |
9213 | schaersvoo | 729 | };\ |
730 | };\ |
||
14038 | schaersvoo | 731 | if( multidraw_click_cnt == 2 ){\ |
732 | multidraw_click_cnt = 0;\ |
||
9213 | schaersvoo | 733 | if( num == 0 ){\ |
14159 | schaersvoo | 734 | circles_x = [];circles_y = [];\ |
735 | circles_x[0] = xc;circles_y[0] = yc;\ |
||
9213 | schaersvoo | 736 | }\ |
737 | };\ |
||
738 | draw_circles();\ |
||
739 | };\ |
||
740 | function draw_circles(){\ |
||
741 | context_circles.clearRect(0,0,xsize,ysize);\ |
||
742 | for(var p = 0 ; p < circles_x.length ; p++ ){\ |
||
743 | context_circles.beginPath();\ |
||
744 | context_circles.arc(circles_x[p],circles_y[p],multi_radius[p],0,2*Math.PI,false);\ |
||
745 | context_circles.closePath();\ |
||
746 | context_circles.fill();\ |
||
747 | context_circles.stroke();\ |
||
748 | };\ |
||
749 | return;\ |
||
14948 | obado | 750 | };"); |
9213 | schaersvoo | 751 | } |
752 | |||
753 | if( strstr(draw_types,"segment") != 0){ |
||
754 | fprintf(js_include_file,"function segments(x,y,event_which,num){\ |
||
755 | var last = segments_x.length - 1;\ |
||
14038 | schaersvoo | 756 | var xy = multi_snap_check(x,y,segments_snap);\ |
9213 | schaersvoo | 757 | if(event_which == 0){\ |
758 | if(num == 0){\ |
||
14038 | schaersvoo | 759 | segments_x[0] = xy[0];segments_y[0] = xy[1];\ |
9213 | schaersvoo | 760 | }\ |
761 | else\ |
||
762 | {\ |
||
14038 | schaersvoo | 763 | segments_x.push(xy[0]);segments_y.push(xy[1]);\ |
9213 | schaersvoo | 764 | };\ |
14038 | schaersvoo | 765 | multidraw_click_cnt++;\ |
9213 | schaersvoo | 766 | }\ |
767 | else\ |
||
768 | {\ |
||
14038 | schaersvoo | 769 | if( multidraw_click_cnt == 1 ){\ |
770 | segments_x.push(xy[0]);segments_y.push(xy[1]);\ |
||
9213 | schaersvoo | 771 | draw_segments();\ |
772 | segments_x.pop();segments_y.pop();\ |
||
773 | };\ |
||
774 | };\ |
||
14038 | schaersvoo | 775 | if( multidraw_click_cnt == 2 ){\ |
776 | segments_x[last+num] = xy[0];segments_y[last+num] = xy[1];\ |
||
777 | multidraw_click_cnt = 0;\ |
||
9213 | schaersvoo | 778 | draw_segments();\ |
779 | };\ |
||
780 | };\ |
||
781 | function draw_segments(){\ |
||
782 | var len = segments_x.length;\ |
||
783 | if( len%%2 == 0 ){\ |
||
784 | context_segments.clearRect(0,0,xsize,ysize);\ |
||
785 | for(var p = 0 ; p < len ; p = p+2 ){\ |
||
786 | context_segments.beginPath();\ |
||
787 | context_segments.moveTo(segments_x[p],segments_y[p]);\ |
||
788 | context_segments.lineTo(segments_x[p+1],segments_y[p+1]);\ |
||
789 | context_segments.closePath();\ |
||
790 | context_segments.stroke();\ |
||
791 | };\ |
||
792 | };\ |
||
793 | return;\ |
||
794 | };"); |
||
795 | } |
||
14948 | obado | 796 | |
9213 | schaersvoo | 797 | if( strstr(draw_types,"arrow") != 0){ |
798 | fprintf(js_include_file,"function arrows(x,y,event_which,num){\ |
||
799 | var last = arrows_x.length - 1;\ |
||
14038 | schaersvoo | 800 | var xy = multi_snap_check(x,y,arrows_snap);\ |
9213 | schaersvoo | 801 | if(event_which == 0){\ |
802 | if(num == 0){\ |
||
14038 | schaersvoo | 803 | arrows_x[0] = xy[0];arrows_y[0] = xy[1];\ |
9213 | schaersvoo | 804 | }\ |
805 | else\ |
||
806 | {\ |
||
14038 | schaersvoo | 807 | arrows_x.push(xy[0]);arrows_y.push(xy[1]);\ |
9213 | schaersvoo | 808 | };\ |
14038 | schaersvoo | 809 | multidraw_click_cnt++;\ |
9213 | schaersvoo | 810 | }\ |
811 | else\ |
||
812 | {\ |
||
14038 | schaersvoo | 813 | if( multidraw_click_cnt == 1 ){\ |
814 | arrows_x.push(xy[0]);arrows_y.push(xy[1]);\ |
||
9213 | schaersvoo | 815 | draw_arrows();\ |
816 | arrows_x.pop();arrows_y.pop();\ |
||
817 | };\ |
||
818 | };\ |
||
14038 | schaersvoo | 819 | if( multidraw_click_cnt == 2 ){\ |
820 | arrows_x[last+num] = xy[0];arrows_y[last+num] = xy[1];\ |
||
821 | multidraw_click_cnt = 0;\ |
||
9213 | schaersvoo | 822 | draw_arrows();\ |
823 | };\ |
||
824 | };\ |
||
825 | function draw_arrows(){\ |
||
826 | var len = arrows_x.length;\ |
||
827 | var x1,y1,x2,y2,dx,dy,h;\ |
||
828 | if( len%%2 == 0 ){\ |
||
829 | context_arrows.clearRect(0,0,xsize,ysize);\ |
||
830 | for(var p = 0 ; p < len ; p = p+2 ){\ |
||
831 | context_arrows.save();\ |
||
832 | x1 = arrows_x[p];y1 = arrows_y[p];x2 = arrows_x[p+1];y2 = arrows_y[p+1];dx = x2 - x1;dy = y2 - y1;\ |
||
833 | h = Math.sqrt(dx*dx+dy*dy);\ |
||
834 | context_arrows.beginPath();\ |
||
835 | context_arrows.moveTo(x1,y1);\ |
||
836 | context_arrows.lineTo(x2,y2);\ |
||
837 | context_arrows.closePath();\ |
||
838 | context_arrows.stroke();\ |
||
839 | context_arrows.translate(x2,y2);\ |
||
840 | context_arrows.rotate(Math.atan2(dy,dx));\ |
||
841 | context_arrows.beginPath();\ |
||
842 | context_arrows.moveTo(0,0);\ |
||
843 | context_arrows.lineTo(-1*arrow_head,-0.5*arrow_head);\ |
||
844 | context_arrows.lineTo(-1*arrow_head, 0.5*arrow_head);\ |
||
845 | context_arrows.closePath();\ |
||
846 | context_arrows.fill();\ |
||
847 | context_arrows.stroke();\ |
||
848 | context_arrows.restore();\ |
||
849 | };\ |
||
850 | };\ |
||
851 | return;\ |
||
852 | };"); |
||
853 | } |
||
854 | |||
14038 | schaersvoo | 855 | if( strstr(draw_types,"curvedarrow") != 0 ){ |
856 | fprintf(js_include_file,"\ |
||
857 | function curvedarrows(x,y,event_which,num){\ |
||
858 | var xy = multi_snap_check(x,y,curvedarrows_snap);\ |
||
859 | if(event_which == 0){\ |
||
860 | if(num == 0 && multidraw_click_cnt == 0){curvedarrows_x = [];curvedarrows_y = [];curvedarrows_x[0] = xy[0];curvedarrows_y[0] = xy[1];}\ |
||
861 | else{curvedarrows_x.push(xy[0]);curvedarrows_y.push(xy[1]);};multidraw_click_cnt++;\ |
||
862 | }\ |
||
863 | else\ |
||
864 | {\ |
||
865 | if( multidraw_click_cnt < 3 ){curvedarrows_x.push(xy[0]);curvedarrows_y.push(xy[1]);draw_curvedarrows();curvedarrows_x.pop();curvedarrows_y.pop();};\ |
||
866 | if( multidraw_click_cnt == 3 ){curvedarrows_x.pop();curvedarrows_y.pop();curvedarrows_x.push(xy[0]);curvedarrows_y.push(xy[1]);multidraw_click_cnt = 0;draw_curvedarrows();};\ |
||
14032 | schaersvoo | 867 | };\ |
14038 | schaersvoo | 868 | };\ |
869 | function draw_curvedarrows(){\ |
||
870 | var len = curvedarrows_x.length;var x1,y1,x2,y2,x3,y3;\ |
||
871 | context_curvedarrows.clearRect(0,0,xsize,ysize);\ |
||
872 | for(var p = 0 ; p < len ; p = p+3){\ |
||
873 | x1 = curvedarrows_x[p];x2 = curvedarrows_x[p+1];x3 = curvedarrows_x[p+2];y1 = curvedarrows_y[p];y2 = curvedarrows_y[p+1];y3 = curvedarrows_y[p+2];\ |
||
14032 | schaersvoo | 874 | var angle1 = Math.atan2(x3 - x2,y3 - y2) + Math.PI;\ |
875 | context_curvedarrows.beginPath();\ |
||
876 | context_curvedarrows.moveTo(x1,y1);\ |
||
877 | context_curvedarrows.quadraticCurveTo(x3,y3,x2,y2);\ |
||
878 | context_curvedarrows.moveTo(x2 - (arrow_head * Math.sin(angle1 - Math.PI / 6)),y2 - (arrow_head * Math.cos(angle1 - Math.PI / 6)));\ |
||
879 | context_curvedarrows.lineTo(x2, y2);\ |
||
880 | context_curvedarrows.lineTo(x2 - (arrow_head * Math.sin(angle1 + Math.PI / 6)),y2 - (arrow_head * Math.cos(angle1 + Math.PI / 6)));\ |
||
881 | context_curvedarrows.stroke();\ |
||
882 | context_curvedarrows.closePath();\ |
||
883 | };\ |
||
884 | return;\ |
||
885 | };"); |
||
886 | } |
||
887 | |||
14038 | schaersvoo | 888 | if( strstr(draw_types,"curvedarrow2") != 0 || strstr(draw_types,"curvedarrows2") != 0 ){ |
889 | fprintf(js_include_file,"\ |
||
890 | function curvedarrows2(x,y,event_which,num){\ |
||
891 | var xy = multi_snap_check(x,y,curvedarrows2_snap);\ |
||
892 | if(event_which == 0){\ |
||
893 | if(num == 0 && multidraw_click_cnt == 0){curvedarrows2_x = [];curvedarrows2_y = [];curvedarrows2_x[0] = xy[0];curvedarrows2_y[0] = xy[1];}\ |
||
894 | else{curvedarrows2_x.push(xy[0]);curvedarrows2_y.push(xy[1]);};multidraw_click_cnt++;\ |
||
895 | }\ |
||
896 | else\ |
||
897 | {\ |
||
898 | if( multidraw_click_cnt < 3 ){curvedarrows2_x.push(xy[0]);curvedarrows2_y.push(xy[1]);draw_curvedarrows2();curvedarrows2_x.pop();curvedarrows2_y.pop();};\ |
||
899 | if( multidraw_click_cnt == 3 ){curvedarrows2_x.pop();curvedarrows2_y.pop();curvedarrows2_x.push(xy[0]);curvedarrows2_y.push(xy[1]);multidraw_click_cnt = 0;draw_curvedarrows2();};\ |
||
900 | };\ |
||
901 | };\ |
||
902 | function draw_curvedarrows2(){\ |
||
903 | var len = curvedarrows2_x.length;var x1,y1,x2,y2,x3,y3;\ |
||
904 | context_curvedarrows2.clearRect(0,0,xsize,ysize);\ |
||
905 | for(var p = 0 ; p < len ; p = p+3){\ |
||
906 | x1 = curvedarrows2_x[p];x2 = curvedarrows2_x[p+1];x3 = curvedarrows2_x[p+2];y1 = curvedarrows2_y[p];y2 = curvedarrows2_y[p+1];y3 = curvedarrows2_y[p+2];\ |
||
907 | var angle1 = Math.atan2(x3 - x2,y3 - y2) + Math.PI;\ |
||
908 | var angle2 = Math.atan2(x3 - x1,y3 - y1) + Math.PI;\ |
||
909 | context_curvedarrows2.beginPath();\ |
||
910 | context_curvedarrows2.moveTo(x1,y1);\ |
||
911 | context_curvedarrows2.moveTo(x1 - (arrow_head * Math.sin(angle2 - Math.PI / 6)),y1 - (arrow_head * Math.cos(angle2 - Math.PI / 6)));\ |
||
912 | context_curvedarrows2.lineTo(x1, y1);\ |
||
913 | context_curvedarrows2.lineTo(x1 - (arrow_head * Math.sin(angle2 + Math.PI / 6)),y1 - (arrow_head * Math.cos(angle2 + Math.PI / 6)));\ |
||
914 | context_curvedarrows2.moveTo(x1,y1);\ |
||
915 | context_curvedarrows2.quadraticCurveTo(x3,y3,x2,y2);\ |
||
916 | context_curvedarrows2.moveTo(x2 - (arrow_head * Math.sin(angle1 - Math.PI / 6)),y2 - (arrow_head * Math.cos(angle1 - Math.PI / 6)));\ |
||
917 | context_curvedarrows2.lineTo(x2, y2);\ |
||
918 | context_curvedarrows2.lineTo(x2 - (arrow_head * Math.sin(angle1 + Math.PI / 6)),y2 - (arrow_head * Math.cos(angle1 + Math.PI / 6)));\ |
||
919 | context_curvedarrows2.stroke();\ |
||
920 | context_curvedarrows2.closePath();\ |
||
921 | };\ |
||
922 | return;\ |
||
923 | };"); |
||
924 | } |
||
925 | |||
9213 | schaersvoo | 926 | if( strstr(draw_types,"line") != 0){ |
9214 | schaersvoo | 927 | fprintf(js_include_file,"function calc_lines(){\ |
928 | var marge = 2;var len = lines_x.length;\ |
||
9213 | schaersvoo | 929 | var x = lines_x;var y = lines_y;\ |
930 | lines_x = new Array(len);\ |
||
931 | lines_y = new Array(len);\ |
||
932 | var pp;\ |
||
933 | for(var p = 0 ; p< len ;p = p+2){\ |
||
934 | pp = p+1;\ |
||
935 | if(x[p] < x[pp]+marge && x[p] > x[pp]-marge){\ |
||
936 | lines_x[p] = x[p];lines_x[pp] = x[pp];\ |
||
937 | lines_y[p] = 0;lines_y[pp] = ysize;\ |
||
938 | }\ |
||
939 | else\ |
||
940 | {\ |
||
941 | if(y[p] < y[pp]+marge && y[p] > y[pp]-marge){\ |
||
942 | lines_x[p] = 0;lines_x[pp] = xsize;\ |
||
943 | lines_y[p] = y[p];lines_y[pp] = y[pp];\ |
||
944 | }\ |
||
945 | else\ |
||
946 | {\ |
||
947 | lines_x[p] = 0;lines_x[pp] = xsize;\ |
||
948 | lines_y[p] = y[p] - (x[p])*(y[pp] - y[p])/(x[pp] - x[p]);\ |
||
949 | lines_y[pp] = y[p] + (xsize - x[p])*(y[pp] - y[p])/(x[pp] - x[p]);\ |
||
950 | };\ |
||
951 | };\ |
||
952 | };\ |
||
953 | return;\ |
||
954 | }\ |
||
955 | function lines(x,y,event_which,num){\ |
||
14038 | schaersvoo | 956 | var xy = multi_snap_check(x,y,lines_snap);\ |
9213 | schaersvoo | 957 | if(event_which == 0){\ |
14038 | schaersvoo | 958 | if( num == 0 && multidraw_click_cnt == 0 ){lines_x = [];lines_y = [];};\ |
959 | lines_x.push(xy[0]);lines_y.push(xy[1]);\ |
||
960 | multidraw_click_cnt++;\ |
||
9213 | schaersvoo | 961 | }\ |
962 | else\ |
||
963 | {\ |
||
14038 | schaersvoo | 964 | if( multidraw_click_cnt == 1 ){\ |
965 | lines_x.push(xy[0]);lines_y.push(xy[1]);\ |
||
9213 | schaersvoo | 966 | draw_lines();\ |
967 | lines_x.pop();lines_y.pop();\ |
||
968 | };\ |
||
969 | };\ |
||
14038 | schaersvoo | 970 | if( multidraw_click_cnt == 2 ){\ |
971 | multidraw_click_cnt = 0;\ |
||
9214 | schaersvoo | 972 | calc_lines();\ |
9213 | schaersvoo | 973 | draw_lines();\ |
974 | };\ |
||
975 | };\ |
||
976 | function draw_lines(){\ |
||
977 | var len = lines_x.length;\ |
||
9214 | schaersvoo | 978 | if( len %%2 == 0 ){\ |
9213 | schaersvoo | 979 | context_lines.clearRect(0,0,xsize,ysize);\ |
980 | for(var p = 0 ; p < len ; p = p+2 ){\ |
||
981 | context_lines.beginPath();\ |
||
982 | context_lines.moveTo(lines_x[p],lines_y[p]);\ |
||
983 | context_lines.lineTo(lines_x[p+1],lines_y[p+1]);\ |
||
984 | context_lines.closePath();\ |
||
985 | context_lines.stroke();\ |
||
986 | };\ |
||
987 | };\ |
||
988 | return;\ |
||
989 | };"); |
||
990 | } |
||
991 | |||
9372 | schaersvoo | 992 | if( strstr(draw_types,"rect") != 0){ |
993 | fprintf(js_include_file,"\ |
||
994 | function rects(x,y,event_which,num){\ |
||
14038 | schaersvoo | 995 | var xy = multi_snap_check(x,y,rects_snap);\ |
9372 | schaersvoo | 996 | if(event_which == 0){\ |
14038 | schaersvoo | 997 | if( num == 0 && multidraw_click_cnt == 0 ){rects_x = [];rects_y = [];};\ |
998 | rects_x.push(xy[0]);rects_y.push(xy[1]);\ |
||
999 | multidraw_click_cnt++;\ |
||
9372 | schaersvoo | 1000 | }\ |
1001 | else\ |
||
1002 | {\ |
||
14038 | schaersvoo | 1003 | if( multidraw_click_cnt == 1 ){\ |
1004 | rects_x.push(xy[0]);rects_y.push(xy[1]);\ |
||
9372 | schaersvoo | 1005 | draw_rects();\ |
1006 | rects_x.pop();rects_y.pop();\ |
||
1007 | };\ |
||
1008 | };\ |
||
14038 | schaersvoo | 1009 | if( multidraw_click_cnt == 2 ){\ |
1010 | multidraw_click_cnt = 0;\ |
||
9372 | schaersvoo | 1011 | draw_rects();\ |
1012 | };\ |
||
1013 | };\ |
||
1014 | function draw_rects(){\ |
||
1015 | var len = rects_x.length;\ |
||
1016 | if( len %%2 == 0 ){\ |
||
1017 | context_rects.clearRect(0,0,xsize,ysize);\ |
||
1018 | for(var p = 0 ; p < len ; p = p+2 ){\ |
||
1019 | context_rects.beginPath();\ |
||
1020 | context_rects.rect(rects_x[p],rects_y[p],rects_x[p+1]-rects_x[p],rects_y[p+1]-rects_y[p]);\ |
||
1021 | context_rects.closePath();\ |
||
1022 | context_rects.fill();\ |
||
1023 | context_rects.stroke();\ |
||
1024 | };\ |
||
1025 | };\ |
||
1026 | return;\ |
||
1027 | };"); |
||
1028 | } |
||
1029 | |||
9250 | schaersvoo | 1030 | if( strstr(draw_types,"closedpoly") != 0 ){ |
1031 | fprintf(js_include_file,"\ |
||
9262 | schaersvoo | 1032 | function check_closed(x1,y1,X,Y){\ |
9250 | schaersvoo | 1033 | var marge=10;\ |
1034 | var len = X.length-1;\ |
||
9262 | schaersvoo | 1035 | for(var p = 0 ; p < len ; p++){\ |
1036 | if(x1 < X[p] + marge && x1 > X[p] - marge ){\ |
||
1037 | if(y1 < Y[p] + marge && y1 > Y[p] - marge ){\ |
||
9250 | schaersvoo | 1038 | return 1;\ |
1039 | };\ |
||
1040 | };\ |
||
1041 | };\ |
||
1042 | return 0;\ |
||
1043 | };\ |
||
9262 | schaersvoo | 1044 | function closedpoly(x,y,event_which,num){\ |
14038 | schaersvoo | 1045 | var xy = multi_snap_check(x,y,closedpoly_snap);\ |
9262 | schaersvoo | 1046 | if(event_which == 0){\ |
14038 | schaersvoo | 1047 | if(multidraw_click_cnt == 0){\ |
9250 | schaersvoo | 1048 | closedpoly_x = [];closedpoly_y = [];\ |
14038 | schaersvoo | 1049 | closedpoly_x[0] = xy[0];closedpoly_y[0] = xy[1];\ |
9262 | schaersvoo | 1050 | }\ |
1051 | else\ |
||
1052 | {\ |
||
14038 | schaersvoo | 1053 | closedpoly_x.push(xy[0]);closedpoly_y.push(xy[1]);\ |
9250 | schaersvoo | 1054 | };\ |
14038 | schaersvoo | 1055 | multidraw_click_cnt++;\ |
1056 | if( multidraw_click_cnt > 2 ){\ |
||
9262 | schaersvoo | 1057 | if( check_closed(x,y,closedpoly_x,closedpoly_y) == 1){\ |
9250 | schaersvoo | 1058 | draw_closedpoly();\ |
14038 | schaersvoo | 1059 | multidraw_click_cnt = 0;\ |
9250 | schaersvoo | 1060 | };\ |
9262 | schaersvoo | 1061 | }\ |
1062 | }\ |
||
1063 | else\ |
||
1064 | {\ |
||
14038 | schaersvoo | 1065 | if( multidraw_click_cnt > 0 ){\ |
1066 | closedpoly_x.push(xy[0]);closedpoly_y.push(xy[1]);\ |
||
9250 | schaersvoo | 1067 | draw_closedpoly();\ |
1068 | closedpoly_x.pop();closedpoly_y.pop();\ |
||
1069 | };\ |
||
1070 | };\ |
||
1071 | };\ |
||
9262 | schaersvoo | 1072 | function draw_closedpoly(){\ |
9250 | schaersvoo | 1073 | var len = closedpoly_x.length;\ |
1074 | context_closedpoly.clearRect(0,0,xsize,ysize);\ |
||
1075 | var p = 0;\ |
||
1076 | context_closedpoly.beginPath();\ |
||
1077 | context_closedpoly.moveTo(closedpoly_x[0],closedpoly_y[0]);\ |
||
9262 | schaersvoo | 1078 | for(var p = 1 ; p < len ; p++){\ |
9250 | schaersvoo | 1079 | context_closedpoly.lineTo(closedpoly_x[p],closedpoly_y[p]);\ |
1080 | };\ |
||
1081 | context_closedpoly.lineTo(closedpoly_x[0],closedpoly_y[0]);\ |
||
1082 | context_closedpoly.closePath();\ |
||
1083 | context_closedpoly.fill();\ |
||
1084 | context_closedpoly.stroke();\ |
||
1085 | return;\ |
||
1086 | };"); |
||
1087 | } |
||
1088 | /* the next : just one type allowed triangel;.poly[3-9],parallelogram */ |
||
1089 | if( strstr(draw_types,"triangle") != 0 ){ |
||
1090 | fprintf(js_include_file,"\ |
||
9213 | schaersvoo | 1091 | function triangles(x,y,event_which,num){\ |
14038 | schaersvoo | 1092 | var xy = multi_snap_check(x,y,triangles_snap);\ |
9213 | schaersvoo | 1093 | var last = triangles_x.length - 1;\ |
1094 | if(event_which == 0){\ |
||
14038 | schaersvoo | 1095 | if(num == 0 && multidraw_click_cnt == 0){\ |
9213 | schaersvoo | 1096 | triangles_x = [];triangles_y = [];\ |
14038 | schaersvoo | 1097 | triangles_x[0] = xy[0];triangles_y[0] = xy[1];\ |
9213 | schaersvoo | 1098 | }\ |
1099 | else\ |
||
1100 | {\ |
||
14038 | schaersvoo | 1101 | triangles_x.push(xy[0]);triangles_y.push(xy[1]);\ |
9213 | schaersvoo | 1102 | };\ |
14038 | schaersvoo | 1103 | multidraw_click_cnt++;\ |
9213 | schaersvoo | 1104 | }\ |
1105 | else\ |
||
1106 | {\ |
||
14038 | schaersvoo | 1107 | if( multidraw_click_cnt < 3 ){\ |
1108 | triangles_x.push(xy[0]);triangles_y.push(xy[1]);\ |
||
9213 | schaersvoo | 1109 | draw_triangles();\ |
1110 | triangles_x.pop();triangles_y.pop();\ |
||
1111 | };\ |
||
1112 | };\ |
||
14038 | schaersvoo | 1113 | if( multidraw_click_cnt == 3 ){\ |
9213 | schaersvoo | 1114 | triangles_x.pop();triangles_y.pop();\ |
14038 | schaersvoo | 1115 | triangles_x.push(xy[0]);triangles_y.push(xy[1]);\ |
1116 | multidraw_click_cnt = 0;\ |
||
9213 | schaersvoo | 1117 | draw_triangles();\ |
1118 | };\ |
||
1119 | };\ |
||
1120 | function draw_triangles(){\ |
||
1121 | var len = triangles_x.length - 1;\ |
||
1122 | context_triangles.clearRect(0,0,xsize,ysize);\ |
||
9250 | schaersvoo | 1123 | for(var p = 0 ; p < len ; p = p+3){\ |
9213 | schaersvoo | 1124 | context_triangles.beginPath();\ |
1125 | context_triangles.moveTo(triangles_x[p],triangles_y[p]);\ |
||
9250 | schaersvoo | 1126 | for( var m = p+1 ;m < p+3 ; m++){\ |
9213 | schaersvoo | 1127 | context_triangles.lineTo(triangles_x[m],triangles_y[m]);\ |
1128 | };\ |
||
1129 | context_triangles.lineTo(triangles_x[p],triangles_y[p]);\ |
||
1130 | context_triangles.closePath();\ |
||
1131 | context_triangles.fill();\ |
||
1132 | context_triangles.stroke();\ |
||
1133 | };\ |
||
1134 | return;\ |
||
9250 | schaersvoo | 1135 | };"); |
1136 | } |
||
1137 | /* need to rethink the parallelogram !!! 26/6/2015 */ |
||
11230 | schaersvoo | 1138 | if(strstr( draw_types,"parallelogram") != 0){ |
9250 | schaersvoo | 1139 | fprintf(js_include_file,"\ |
11230 | schaersvoo | 1140 | function parallelogram(x,y,event_which,num){\ |
1141 | var l2 = parallelogram_x.length;\ |
||
9250 | schaersvoo | 1142 | var l1 = l2 - 1;\ |
1143 | var l0 = l2 - 2;\ |
||
14038 | schaersvoo | 1144 | var xy = multi_snap_check(x,y,parallelogram_snap);\ |
9213 | schaersvoo | 1145 | if(event_which == 0){\ |
14038 | schaersvoo | 1146 | if(multidraw_click_cnt == 0){\ |
11230 | schaersvoo | 1147 | if(num == 0){parallelogram_x = [];parallelogram_y = [];};\ |
14038 | schaersvoo | 1148 | parallelogram_x.push(xy[0]);parallelogram_y.push(xy[1]);\ |
9213 | schaersvoo | 1149 | }\ |
1150 | else\ |
||
1151 | {\ |
||
14038 | schaersvoo | 1152 | parallelogram_x.push(xy[0]);parallelogram_y.push(xy[1]);\ |
1153 | if(multidraw_click_cnt == 2){\ |
||
1154 | var xy = multi_snap_check(parallelogram_x[l2] - parallelogram_x[l1] + parallelogram_x[l0],parallelogram_y[l2] - parallelogram_y[l1] + parallelogram_y[l0],parallelogram_snap);\ |
||
1155 | parallelogram_x.push(xy[0]);\ |
||
1156 | parallelogram_y.push(xy[1]);\ |
||
9213 | schaersvoo | 1157 | };\ |
1158 | };\ |
||
14038 | schaersvoo | 1159 | multidraw_click_cnt++;\ |
9213 | schaersvoo | 1160 | }\ |
1161 | else\ |
||
1162 | {\ |
||
14038 | schaersvoo | 1163 | if(multidraw_click_cnt == 1){\ |
1164 | var xxyy = multi_snap_check(parallelogram_x[l1],parallelogram_y[l1],parallelogram_snap);\ |
||
1165 | parallelogram_x.push(xxyy[0]);\ |
||
1166 | parallelogram_y.push(xxyy[1]);\ |
||
1167 | parallelogram_x.push(xy[0]);\ |
||
1168 | parallelogram_y.push(xy[1]);\ |
||
11230 | schaersvoo | 1169 | draw_parallelogram();\ |
1170 | parallelogram_x.pop();parallelogram_y.pop();\ |
||
1171 | parallelogram_x.pop();parallelogram_y.pop();\ |
||
1172 | }\ |
||
1173 | else\ |
||
1174 | {\ |
||
14038 | schaersvoo | 1175 | if(multidraw_click_cnt == 2){\ |
1176 | var xxyy = multi_snap_check(parallelogram_x[l2]-parallelogram_x[l1] + parallelogram_x[l0],parallelogram_y[l2]-parallelogram_y[l1] + parallelogram_y[l0],parallelogram_snap);\ |
||
1177 | parallelogram_x.push(xy[0]);parallelogram_y.push(xy[1]);\ |
||
1178 | parallelogram_x.push(xxyy[0]);\ |
||
1179 | parallelogram_y.push(xxyy[1]);\ |
||
11230 | schaersvoo | 1180 | draw_parallelogram();\ |
1181 | parallelogram_x.pop();parallelogram_y.pop();\ |
||
1182 | parallelogram_x.pop();parallelogram_y.pop();\ |
||
9213 | schaersvoo | 1183 | };\ |
11230 | schaersvoo | 1184 | };\ |
9213 | schaersvoo | 1185 | };\ |
14038 | schaersvoo | 1186 | if( multidraw_click_cnt == 3 ){\ |
11230 | schaersvoo | 1187 | parallelogram_x.pop();parallelogram_y.pop();\ |
14038 | schaersvoo | 1188 | var xxyy = multi_snap_check(parallelogram_x[l2]-parallelogram_x[l1] + parallelogram_x[l0],parallelogram_y[l2]-parallelogram_y[l1] + parallelogram_y[l0],parallelogram_snap);\ |
1189 | parallelogram_x.push(xxyy[0]);\ |
||
1190 | parallelogram_y.push(xxyy[1]);\ |
||
1191 | parallelogram_x.push(xy[0]);parallelogram_y.push(xy[1]);\ |
||
11230 | schaersvoo | 1192 | parallelogram_x.pop();parallelogram_y.pop();\ |
14038 | schaersvoo | 1193 | multidraw_click_cnt = 0;\ |
11230 | schaersvoo | 1194 | draw_parallelogram();\ |
9213 | schaersvoo | 1195 | };\ |
1196 | };\ |
||
11230 | schaersvoo | 1197 | function draw_parallelogram(){\ |
1198 | var len = parallelogram_x.length-1;\ |
||
1199 | context_parallelogram.clearRect(0,0,xsize,ysize);\ |
||
9250 | schaersvoo | 1200 | for(var p = 0 ; p < len ; p = p+4){\ |
11230 | schaersvoo | 1201 | context_parallelogram.beginPath();\ |
1202 | context_parallelogram.moveTo(parallelogram_x[p],parallelogram_y[p]);\ |
||
9250 | schaersvoo | 1203 | for( var m = p+1 ;m < p+4 ; m++){\ |
11230 | schaersvoo | 1204 | context_parallelogram.lineTo(parallelogram_x[m],parallelogram_y[m]);\ |
9213 | schaersvoo | 1205 | };\ |
11230 | schaersvoo | 1206 | context_parallelogram.lineTo(parallelogram_x[p],parallelogram_y[p]);\ |
1207 | context_parallelogram.closePath();\ |
||
1208 | context_parallelogram.fill();\ |
||
1209 | context_parallelogram.stroke();\ |
||
9213 | schaersvoo | 1210 | };\ |
1211 | return;\ |
||
1212 | };"); |
||
1213 | } |
||
14948 | obado | 1214 | |
9250 | schaersvoo | 1215 | if( strstr( draw_types,("poly")) != 0 ){ |
14038 | schaersvoo | 1216 | char *p = draw_types; int polynum=-1;while( *p ){ if( isdigit(*p) ){ polynum = atoi(p);break; } else { p++;} } |
9250 | schaersvoo | 1217 | if(polynum != -1 ){ |
1218 | fprintf(js_include_file,"var polynum = %d;\ |
||
11226 | schaersvoo | 1219 | function polys(x,y,event_which,num){\ |
1220 | var last = polys_x.length - 1;\ |
||
14038 | schaersvoo | 1221 | var xy = multi_snap_check(x,y,polys_snap);\ |
9250 | schaersvoo | 1222 | if(event_which == 0){\ |
14038 | schaersvoo | 1223 | if(num == 0 && multidraw_click_cnt == 0){\ |
11226 | schaersvoo | 1224 | polys_x = [];polys_y = [];\ |
14038 | schaersvoo | 1225 | polys_x[0] = xy[0];polys_y[0] = xy[1];\ |
9250 | schaersvoo | 1226 | }\ |
1227 | else\ |
||
1228 | {\ |
||
14038 | schaersvoo | 1229 | polys_x.push(xy[0]);polys_y.push(xy[1]);\ |
9250 | schaersvoo | 1230 | };\ |
14038 | schaersvoo | 1231 | multidraw_click_cnt++;\ |
9250 | schaersvoo | 1232 | }\ |
1233 | else\ |
||
1234 | {\ |
||
14038 | schaersvoo | 1235 | if( multidraw_click_cnt < polynum ){\ |
1236 | polys_x.push(xy[0]);polys_y.push(xy[1]);\ |
||
11226 | schaersvoo | 1237 | draw_polys();\ |
1238 | polys_x.pop();polys_y.pop();\ |
||
9250 | schaersvoo | 1239 | };\ |
1240 | };\ |
||
14038 | schaersvoo | 1241 | if( multidraw_click_cnt == polynum ){\ |
11226 | schaersvoo | 1242 | polys_x.pop();polys_y.pop();\ |
14038 | schaersvoo | 1243 | polys_x.push(xy[0]);polys_y.push(xy[1]);\ |
1244 | multidraw_click_cnt = 0;\ |
||
11226 | schaersvoo | 1245 | draw_polys();\ |
9250 | schaersvoo | 1246 | };\ |
1247 | };\ |
||
11226 | schaersvoo | 1248 | function draw_polys(){\ |
1249 | var len = polys_x.length - 1;\ |
||
1250 | context_polys.clearRect(0,0,xsize,ysize);\ |
||
9250 | schaersvoo | 1251 | for(var p = 0 ; p < len ; p = p+polynum){\ |
11226 | schaersvoo | 1252 | context_polys.beginPath();\ |
1253 | context_polys.moveTo(polys_x[p],polys_y[p]);\ |
||
9250 | schaersvoo | 1254 | for( var m = p+1 ;m < p+polynum ; m++){\ |
11226 | schaersvoo | 1255 | context_polys.lineTo(polys_x[m],polys_y[m]);\ |
9250 | schaersvoo | 1256 | };\ |
11226 | schaersvoo | 1257 | context_polys.lineTo(polys_x[p],polys_y[p]);\ |
1258 | context_polys.closePath();\ |
||
1259 | context_polys.fill();\ |
||
1260 | context_polys.stroke();\ |
||
9250 | schaersvoo | 1261 | };\ |
1262 | return;\ |
||
1263 | };",polynum); |
||
1264 | } |
||
1265 | } |
||
14948 | obado | 1266 | } |
14038 | schaersvoo | 1267 | /* end 'void add_js_multidraw()' */ |
9213 | schaersvoo | 1268 | |
14044 | schaersvoo | 1269 | void add_js_circles(FILE *js_include_file,int num,char *draw_type,int line_width, int radius ,char *stroke_color,double stroke_opacity,int use_filled,char *fill_color,double fill_opacity,int use_dashed,int dashtype0,int dashtype1,int use_snap){ |
14038 | schaersvoo | 1270 | fprintf(js_include_file,"\n/* begin userdraw \"%s\" on final canvas */\n\ |
7652 | schaersvoo | 1271 | var num = %d;\ |
14044 | schaersvoo | 1272 | var use_snap = %d;\ |
7652 | schaersvoo | 1273 | userdraw_radius[0] = %d;\ |
1274 | var line_width = %d;\ |
||
1275 | var stroke_color = \"%s\";\ |
||
1276 | var stroke_opacity = %f;\ |
||
1277 | var use_filled = %d;\ |
||
1278 | var fill_color = \"%s\";\ |
||
1279 | var fill_opacity = %f;\ |
||
1280 | var use_dashed = %d;\ |
||
1281 | var dashtype1 = %d;\ |
||
1282 | var dashtype0 = %d;\ |
||
1283 | var click_cnt = 0;\ |
||
1284 | var x0,y0,x1,y1;\ |
||
14958 | obado | 1285 | /* Draw circles */\ |
7652 | schaersvoo | 1286 | function user_draw(evt){\ |
14044 | schaersvoo | 1287 | var mouse = dragstuff.getMouse(evt,canvas_userdraw);\ |
1288 | var xy = multisnap_check(mouse.x,mouse.y,use_snap);\ |
||
1289 | x0 = xy[0];y0 = xy[1];\ |
||
7655 | schaersvoo | 1290 | if(y0 < ysize + 1){\ |
14949 | obado | 1291 | if(evt.button == 0 || typeof(evt.identifier) != 'undefined' ){\ |
7652 | schaersvoo | 1292 | if( click_cnt == 0 ){\ |
1293 | userdraw_x[xy_cnt] = x0;\ |
||
1294 | userdraw_y[xy_cnt] = y0;\ |
||
1295 | userdraw_radius[xy_cnt] = line_width;\ |
||
1296 | click_cnt = 1;\ |
||
1297 | draw_circles(context_userdraw,userdraw_x,userdraw_y,userdraw_radius,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,dashtype1);\ |
||
1298 | }\ |
||
1299 | else\ |
||
1300 | {\ |
||
1301 | click_cnt = 0;\ |
||
1302 | if( num != 1 ){ xy_cnt++; }\ |
||
1303 | }\ |
||
1304 | }\ |
||
1305 | else\ |
||
1306 | {\ |
||
1307 | canvas_remove(x0,y0);\ |
||
1308 | }\ |
||
1309 | }\ |
||
1310 | };\ |
||
1311 | function user_drag(evt){\ |
||
1312 | if( click_cnt == 1 ){\ |
||
14044 | schaersvoo | 1313 | var mouse = dragstuff.getMouse(evt,canvas_userdraw);\ |
1314 | var xy = multisnap_check(mouse.x,mouse.y,use_snap);\ |
||
1315 | x1 = xy[0];y1 = xy[1];\ |
||
8379 | schaersvoo | 1316 | userdraw_radius[xy_cnt] = parseInt(Math.sqrt( (x1-x0)*(x1-x0) + (y1-y0)*(y1-y0) ));\ |
1317 | userdraw_x[xy_cnt] = x0;\ |
||
1318 | userdraw_y[xy_cnt] = y0;\ |
||
1319 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
||
1320 | draw_circles(context_userdraw,userdraw_x,userdraw_y,userdraw_radius,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,dashtype1);\ |
||
1321 | };\ |
||
7652 | schaersvoo | 1322 | };\ |
1323 | function canvas_remove(x,y){\ |
||
1324 | var marge = 10*line_width;\ |
||
1325 | var diff1;var diff2;\ |
||
1326 | for(var p = 0;p < userdraw_x.length ; p++){\ |
||
1327 | diff1 = (x-userdraw_x[p])*(x - userdraw_x[p]) + (y - userdraw_y[p])*(y - userdraw_y[p]) - userdraw_radius[p]*userdraw_radius[p];\ |
||
1328 | diff2 = (x-userdraw_x[p])*(x - userdraw_x[p]) + (y - userdraw_y[p])*(y - userdraw_y[p]) - (userdraw_radius[p] - marge)*(userdraw_radius[p] - marge);\ |
||
1329 | if( diff1 < 0 && diff2 > 0 ){\ |
||
1330 | if(confirm(\"remove circle ?\")){\ |
||
7976 | schaersvoo | 1331 | if( num == 1 ){ userdraw_x = [];userdraw_y = []; userdraw_radius = [];xy_cnt = 0;context_userdraw.clearRect(0,0,xsize,ysize); return;}\ |
1332 | else\ |
||
1333 | {\ |
||
1334 | userdraw_x.splice(p,1);\ |
||
1335 | userdraw_y.splice(p,1);\ |
||
1336 | userdraw_radius.splice(p,1);\ |
||
1337 | xy_cnt--;\ |
||
1338 | context_userdraw = null;context_userdraw = canvas_userdraw.getContext(\"2d\");context_userdraw.clearRect(0,0,xsize,ysize);\ |
||
1339 | draw_circles(context_userdraw,userdraw_x,userdraw_y,userdraw_radius,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,dashtype1);\ |
||
1340 | };\ |
||
7652 | schaersvoo | 1341 | };\ |
1342 | return;\ |
||
1343 | }\ |
||
1344 | }\ |
||
14044 | schaersvoo | 1345 | };",draw_type,num,use_snap,radius,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,dashtype1); |
7652 | schaersvoo | 1346 | } |
7614 | schaersvoo | 1347 | |
14044 | schaersvoo | 1348 | void add_js_points(FILE *js_include_file,int num,char *draw_type,int line_width, int radius ,char *stroke_color,double stroke_opacity,int use_filled,char *fill_color,double fill_opacity,int use_dashed,int dashtype0,int dashtype1,int use_snap){ |
14038 | schaersvoo | 1349 | fprintf(js_include_file,"\n/* begin userdraw \"%s\" on final canvas */\n\ |
8448 | schaersvoo | 1350 | var num = %d;\ |
14044 | schaersvoo | 1351 | var use_snap = %d;\ |
8448 | schaersvoo | 1352 | userdraw_radius[0] = %d;\ |
1353 | var line_width = %d;\ |
||
1354 | var stroke_color = \"%s\";\ |
||
1355 | var stroke_opacity = %f;\ |
||
1356 | var use_filled = %d;\ |
||
1357 | var fill_color = \"%s\";\ |
||
1358 | var fill_opacity = %f;\ |
||
1359 | var use_dashed = %d;\ |
||
1360 | var dashtype1 = %d;\ |
||
1361 | var dashtype0 = %d;\ |
||
1362 | var x0,y0,x1,y1;\ |
||
1363 | var canvas_rect;\ |
||
1364 | function user_draw(evt){\ |
||
11002 | schaersvoo | 1365 | var mouse = dragstuff.getMouse(evt,canvas_userdraw);\ |
14044 | schaersvoo | 1366 | var xy = multisnap_check(mouse.x,mouse.y,use_snap);\ |
1367 | x0 = xy[0];y0 = xy[1];\ |
||
14949 | obado | 1368 | if(evt.button == 0 || typeof(evt.identifier) != 'undefined' ){\ |
11001 | schaersvoo | 1369 | userdraw_x[xy_cnt] = x0;\ |
1370 | userdraw_y[xy_cnt] = y0;\ |
||
1371 | userdraw_radius[xy_cnt] = line_width;\ |
||
1372 | if( num != 1 ){ xy_cnt++; }else{context_userdraw.clearRect(0,0,xsize,ysize);};\ |
||
1373 | draw_circles(context_userdraw,userdraw_x,userdraw_y,userdraw_radius,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,dashtype1);\ |
||
1374 | }\ |
||
1375 | else\ |
||
1376 | {\ |
||
1377 | canvas_remove(x0,y0);\ |
||
1378 | };\ |
||
8448 | schaersvoo | 1379 | };\ |
1380 | function user_drag(evt){ return;};\ |
||
1381 | function canvas_remove(x,y){\ |
||
1382 | var marge = 4*line_width;\ |
||
1383 | for(var p = 0;p < userdraw_x.length ; p++){\ |
||
1384 | if(userdraw_x[p] < x + marge && userdraw_x[p] > x - marge ){\ |
||
1385 | if(userdraw_y[p] < y + marge && userdraw_y[p] > y - marge ){\ |
||
1386 | userdraw_x.splice(p,1);userdraw_y.splice(p,1);\ |
||
1387 | context_userdraw = null;context_userdraw = canvas_userdraw.getContext(\"2d\");context_userdraw.clearRect(0,0,xsize,ysize);\ |
||
1388 | draw_circles(context_userdraw,userdraw_x,userdraw_y,userdraw_radius,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,dashtype1);\ |
||
11006 | schaersvoo | 1389 | xy_cnt--;\ |
8448 | schaersvoo | 1390 | return;\ |
1391 | };\ |
||
1392 | };\ |
||
1393 | };\ |
||
14044 | schaersvoo | 1394 | };",draw_type,num,use_snap,radius,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,dashtype1); |
8448 | schaersvoo | 1395 | } |
1396 | |||
14044 | schaersvoo | 1397 | void add_js_inputs(FILE *js_include_file,int canvas_root_id,int num,int input_cnt,char *input_style,int line_width,int use_offset,int use_snap){ |
14038 | schaersvoo | 1398 | fprintf(js_include_file,"\n/* user draw inputfields */\n\ |
1399 | var canvas_rect = canvas_userdraw.getBoundingClientRect();\ |
||
14044 | schaersvoo | 1400 | var use_snap = %d;\ |
8448 | schaersvoo | 1401 | var input_cnt = %d;\ |
1402 | var start_input_cnt = input_cnt;\ |
||
1403 | function user_drag(evt){return;}\ |
||
1404 | function user_draw(evt){\ |
||
14038 | schaersvoo | 1405 | var mouse = dragstuff.getMouse(evt,canvas_userdraw);\ |
14044 | schaersvoo | 1406 | var xy = multisnap_check(mouse.x,mouse.y,use_snap);\ |
1407 | var x = xy[0];\ |
||
1408 | var y = xy[1];\ |
||
8448 | schaersvoo | 1409 | var num = %d;var inputs;\ |
14949 | obado | 1410 | if(evt.button == 0){\ |
8448 | schaersvoo | 1411 | var inputs;var xi;var yi;var wi;var hi;\ |
1412 | var found = 0;\ |
||
1413 | if( start_input_cnt < input_cnt){\ |
||
1414 | for(var p = start_input_cnt ; p < input_cnt ; p++ ){\ |
||
1415 | inputs = document.getElementById(\"canvas_input\"+p);\ |
||
1416 | xi = findPosX(inputs) - canvas_rect.left;\ |
||
1417 | yi = findPosY(inputs) - canvas_rect.top;\ |
||
1418 | wi = 4 + inputs.clientWidth;\ |
||
1419 | hi = 4 + inputs.clientHeight;\ |
||
1420 | if( x > xi - wi && x < xi + wi && y > yi - hi && y < yi + hi ){\ |
||
1421 | found = 1;\ |
||
1422 | };\ |
||
1423 | };\ |
||
1424 | };\ |
||
1425 | if( found == 0 ){\ |
||
1426 | if( num == 1 ){\ |
||
1427 | inputs = document.getElementById(\"canvas_input\"+start_input_cnt);\ |
||
1428 | try{canvas_div.removeChild(inputs);}catch(e){};\ |
||
1429 | input_cnt = 0;\ |
||
1430 | };\ |
||
1431 | userdraw_x.push(x);userdraw_y.push(y);\ |
||
11803 | schaersvoo | 1432 | draw_inputs(%d,input_cnt,x,y,%d,1,\"%s\",\"?\",%d);\ |
8448 | schaersvoo | 1433 | input_cnt++;\ |
1434 | };\ |
||
1435 | }\ |
||
1436 | else\ |
||
1437 | {\ |
||
1438 | for(var p = start_input_cnt ; p < input_cnt; p++){\ |
||
1439 | inputs = document.getElementById(\"canvas_input\"+p);\ |
||
1440 | try{canvas_div.removeChild(inputs);}catch(e){};\ |
||
1441 | };\ |
||
1442 | userdraw_x = [];userdraw_y = [];\ |
||
1443 | input_cnt = start_input_cnt;\ |
||
1444 | };\ |
||
14044 | schaersvoo | 1445 | };",use_snap,input_cnt,num,canvas_root_id,line_width,input_style,use_offset); |
8448 | schaersvoo | 1446 | } |
1447 | |||
14038 | schaersvoo | 1448 | |
8448 | schaersvoo | 1449 | void add_zoom_buttons(FILE *js_include_file,int canvas_root_id,char *stroke_color,double stroke_opacity){ |
14038 | schaersvoo | 1450 | fprintf(js_include_file,"\n/* draw zoom buttons */\n\ |
8448 | schaersvoo | 1451 | var draw_zoom_buttons = function(){\ |
1452 | var obj;var canvas_type =%d;\ |
||
1453 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
1454 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
1455 | }\ |
||
1456 | else\ |
||
1457 | {\ |
||
1458 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
1459 | };\ |
||
1460 | var ctx = obj.getContext(\"2d\");\ |
||
14044 | schaersvoo | 1461 | ctx.font =\"22px Ariel\";\ |
8448 | schaersvoo | 1462 | ctx.textAlign = \"right\";\ |
9406 | schaersvoo | 1463 | ctx.fillStyle=\"rgba(%s,%f)\";\ |
8448 | schaersvoo | 1464 | ctx.fillText(\"+\",xsize,ysize);\ |
1465 | ctx.fillText(\"\\u2212\",xsize - 15,ysize);\ |
||
1466 | ctx.fillText(\"\\u2192\",xsize - 30,ysize-2);\ |
||
1467 | ctx.fillText(\"\\u2190\",xsize - 45,ysize-2);\ |
||
1468 | ctx.fillText(\"\\u2191\",xsize - 60,ysize-2);\ |
||
1469 | ctx.fillText(\"\\u2193\",xsize - 75,ysize-2);\ |
||
11002 | schaersvoo | 1470 | ctx.fillText(\"\\u00D7\",xsize - 90,ysize-2);\ |
8448 | schaersvoo | 1471 | ctx.stroke();\ |
1472 | };\ndraw_zoom_buttons();",BG_CANVAS,canvas_root_id,canvas_root_id,canvas_root_id,stroke_color,stroke_opacity); |
||
1473 | } |
||
1474 | |||
14044 | schaersvoo | 1475 | void add_js_crosshairs(FILE *js_include_file,int num,char *draw_type,int line_width, int crosshair_size ,char *stroke_color,double stroke_opacity,int use_snap){ |
14038 | schaersvoo | 1476 | fprintf(js_include_file,"\n/* begin userdraw \"%s\" on currect active canvas */\n\ |
7614 | schaersvoo | 1477 | var num = %d;\ |
14044 | schaersvoo | 1478 | var use_snap = %d;\ |
8347 | schaersvoo | 1479 | var crosshair_size = %d;\ |
7614 | schaersvoo | 1480 | var line_width = %d;\ |
1481 | var stroke_color = \"%s\";\ |
||
1482 | var stroke_opacity = %f;\ |
||
1483 | context_userdraw.lineWidth = line_width;\ |
||
1484 | context_userdraw.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
1485 | function user_drag(evt){return;}\ |
||
1486 | function user_draw(evt){\ |
||
11002 | schaersvoo | 1487 | var mouse = dragstuff.getMouse(evt,canvas_userdraw);\ |
14044 | schaersvoo | 1488 | var xy = multisnap_check(mouse.x,mouse.y,use_snap);\ |
1489 | var x = xy[0];var y = xy[1];var x1,y1,x2,y2;\ |
||
14949 | obado | 1490 | if(evt.button == 0 || typeof(evt.identifier) != 'undefined' ){\ |
7614 | schaersvoo | 1491 | userdraw_x[xy_cnt] = x;\ |
1492 | userdraw_y[xy_cnt] = y;\ |
||
1493 | x1 = x - crosshair_size;\ |
||
1494 | x2 = x + crosshair_size;\ |
||
1495 | y1 = y - crosshair_size;\ |
||
1496 | y2 = y + crosshair_size;\ |
||
1497 | if( num != 1 ){ xy_cnt++;\ |
||
1498 | for(var p = 0; p < xy_cnt - 1 ;p++){\ |
||
1499 | if(x1 < userdraw_x[p] && x2 > userdraw_x[p]){\ |
||
1500 | if(y1 < userdraw_y[p] && y2 > userdraw_y[p]){\ |
||
1501 | canvas_remove(x,y);\ |
||
1502 | context_userdraw = null;context_userdraw = canvas_userdraw.getContext(\"2d\");\ |
||
1503 | }\ |
||
1504 | }\ |
||
1505 | }\ |
||
1506 | };\ |
||
1507 | context_userdraw.beginPath();\ |
||
1508 | context_userdraw.moveTo(x1,y1);\ |
||
1509 | context_userdraw.lineTo(x2,y2);\ |
||
1510 | context_userdraw.closePath();\ |
||
1511 | context_userdraw.stroke();\ |
||
1512 | context_userdraw.beginPath();\ |
||
1513 | context_userdraw.moveTo(x2,y1);\ |
||
1514 | context_userdraw.lineTo(x1,y2);\ |
||
1515 | context_userdraw.closePath();\ |
||
1516 | context_userdraw.stroke();\ |
||
1517 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
||
1518 | draw_crosshairs(context_userdraw,userdraw_x,userdraw_y,line_width,crosshair_size,stroke_color,stroke_opacity,0,0,0,[0,0]);\ |
||
1519 | }\ |
||
1520 | else\ |
||
1521 | {\ |
||
1522 | canvas_remove(x,y);\ |
||
1523 | }\ |
||
1524 | }\ |
||
1525 | function canvas_remove(x,y){\ |
||
1526 | var marge = 2*crosshair_size;\ |
||
1527 | for(var p = 0;p < userdraw_x.length ; p++){\ |
||
1528 | if(userdraw_x[p] < x + marge && userdraw_x[p] > x - marge ){\ |
||
1529 | if(userdraw_y[p] < y + marge && userdraw_y[p] > y - marge ){\ |
||
1530 | userdraw_x.splice(p,1);userdraw_y.splice(p,1);\ |
||
11006 | schaersvoo | 1531 | context_userdraw = null;context_userdraw = canvas_userdraw.getContext(\"2d\");context_userdraw.clearRect(0,0,xsize,ysize);\ |
1532 | xy_cnt--;\ |
||
7614 | schaersvoo | 1533 | draw_crosshairs(context_userdraw,userdraw_x,userdraw_y,line_width,crosshair_size,stroke_color,stroke_opacity,0,0,0,[0,0]);\ |
1534 | return;\ |
||
1535 | }\ |
||
1536 | }\ |
||
1537 | }\ |
||
14044 | schaersvoo | 1538 | };",draw_type,num,use_snap,crosshair_size,line_width,stroke_color,stroke_opacity); |
7614 | schaersvoo | 1539 | } |
1540 | |||
12008 | schaersvoo | 1541 | /* need to rewrite not using clickcnt and xy_cnt */ |
14044 | schaersvoo | 1542 | void add_js_rect(FILE *js_include_file,int num,int roundrect,char *draw_type,int line_width,char *stroke_color,double stroke_opacity,int use_filled,char *fill_color,double fill_opacity,int use_dashed,int dashtype0,int dashtype1,int use_snap){ |
14038 | schaersvoo | 1543 | fprintf(js_include_file,"\n/* begin userdraw \"%s\" on currect active canvas */\n\ |
14044 | schaersvoo | 1544 | var use_snap = %d;\ |
7614 | schaersvoo | 1545 | var roundrect = %d;\ |
1546 | var line_width = %d;\ |
||
1547 | var stroke_color = \"%s\";\ |
||
1548 | var stroke_opacity = %f;\ |
||
1549 | var use_filled = %d;\ |
||
1550 | var fill_color = \"%s\";\ |
||
1551 | var fill_opacity = %f;\ |
||
1552 | var use_dashed = %d;\ |
||
1553 | var dashtype0 = %d;\ |
||
1554 | var dashtype1 = %d;\ |
||
1555 | var num = %d;\ |
||
1556 | var use_rotate = 0;\ |
||
1557 | var angle = 0;\ |
||
1558 | var closed_path = 1;\ |
||
1559 | var clickcnt = 0;\ |
||
1560 | xy_cnt = 0;\ |
||
1561 | var x0,y0,x1,y1;\ |
||
1562 | var marge = 10*line_width;\ |
||
1563 | function user_draw(evt){\ |
||
11002 | schaersvoo | 1564 | var mouse = dragstuff.getMouse(evt,canvas_userdraw);\ |
14044 | schaersvoo | 1565 | var xy = multisnap_check(mouse.x,mouse.y,use_snap);\ |
1566 | x0 = xy[0];\ |
||
1567 | y0 = xy[0];\ |
||
14949 | obado | 1568 | if( evt.button == 0 || typeof(evt.identifier) != 'undefined' ){\ |
11002 | schaersvoo | 1569 | if(clickcnt == 0 ){\ |
1570 | clickcnt = 1;\ |
||
1571 | userdraw_x[xy_cnt] = x0;userdraw_y[xy_cnt] = y0;xy_cnt++;\ |
||
1572 | }\ |
||
1573 | else\ |
||
1574 | {\ |
||
1575 | clickcnt = 0;\ |
||
12008 | schaersvoo | 1576 | var lu = userdraw_x.length - 1;\ |
1577 | if( userdraw_x[lu] == userdraw_x[lu-1] && userdraw_y[lu] == userdraw_y[lu-1]){userdraw_x.pop();userdraw_y.pop();clickcnt=1;return;};\ |
||
11002 | schaersvoo | 1578 | if(roundrect == 0 ){\ |
1579 | draw_rects(context_userdraw,userdraw_x,userdraw_y,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,0,[1,0,0,1,0,0]);\ |
||
7614 | schaersvoo | 1580 | }\ |
1581 | else\ |
||
1582 | {\ |
||
11002 | schaersvoo | 1583 | draw_roundrects(context_userdraw,userdraw_x,userdraw_y,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,0,[1,0,0,1,0,0]);\ |
7614 | schaersvoo | 1584 | }\ |
11002 | schaersvoo | 1585 | if( num != 1 ){ xy_cnt++; }else{xy_cnt--;}\ |
7614 | schaersvoo | 1586 | }\ |
11002 | schaersvoo | 1587 | }\ |
1588 | else\ |
||
1589 | {\ |
||
1590 | canvas_remove(x0,y0);\ |
||
7614 | schaersvoo | 1591 | };\ |
1592 | };\ |
||
1593 | function user_drag(evt){\ |
||
11002 | schaersvoo | 1594 | var mouse = dragstuff.getMouse(evt,canvas_userdraw);\ |
14044 | schaersvoo | 1595 | var xy = multisnap_check(mouse.x,mouse.y,use_snap);\ |
1596 | x1 = xy[0];\ |
||
1597 | y1 = xy[1];\ |
||
7614 | schaersvoo | 1598 | if( clickcnt == 1 ){\ |
1599 | userdraw_x[xy_cnt] = x1;\ |
||
1600 | userdraw_y[xy_cnt] = y1;\ |
||
1601 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
||
1602 | if( roundrect == 0 ){\ |
||
8071 | schaersvoo | 1603 | draw_rects(context_userdraw,userdraw_x,userdraw_y,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,0,[1,0,0,1,0,0]);\ |
7614 | schaersvoo | 1604 | }\ |
1605 | else\ |
||
1606 | {\ |
||
8071 | schaersvoo | 1607 | draw_roundrects(context_userdraw,userdraw_x,userdraw_y,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,0,[1,0,0,1,0,0]);\ |
7614 | schaersvoo | 1608 | };\ |
1609 | };\ |
||
1610 | };\ |
||
1611 | function canvas_remove(x,y){\ |
||
1612 | for(var p = 0;p < userdraw_x.length ; p++){\ |
||
1613 | if(userdraw_x[p] < x + marge && userdraw_x[p] > x - marge ){\ |
||
1614 | if(userdraw_y[p] < y + marge && userdraw_y[p] > y - marge ){\ |
||
1615 | if( confirm(\"remove rectangle ?\" )){\ |
||
1616 | if( p%%2 == 0 ){\ |
||
1617 | userdraw_x.splice(p,2);userdraw_y.splice(p,2);\ |
||
1618 | }\ |
||
1619 | else\ |
||
1620 | {\ |
||
1621 | userdraw_x.splice(p-1,2);userdraw_y.splice(p-1,2);\ |
||
1622 | }\ |
||
11006 | schaersvoo | 1623 | xy_cnt = xy_cnt - 2;\ |
7614 | schaersvoo | 1624 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
1625 | if(xy_cnt < 2){xy_cnt = 0;click_cnt = 0;userdraw_x = [];userdraw_y = [];return;};\ |
||
1626 | if( roundrect == 0 ){\ |
||
8071 | schaersvoo | 1627 | draw_rects(context_userdraw,userdraw_x,userdraw_y,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,0,[1,0,0,1,0,0]);\ |
7614 | schaersvoo | 1628 | }\ |
1629 | else\ |
||
1630 | {\ |
||
8071 | schaersvoo | 1631 | draw_roundrects(context_userdraw,userdraw_x,userdraw_y,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,0,[1,0,0,1,0,0]);\ |
7614 | schaersvoo | 1632 | }\ |
1633 | return;\ |
||
1634 | };\ |
||
1635 | };\ |
||
1636 | };\ |
||
1637 | };\ |
||
14044 | schaersvoo | 1638 | };",draw_type,use_snap,roundrect,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,dashtype1,num); |
7614 | schaersvoo | 1639 | } |
1640 | |||
14044 | schaersvoo | 1641 | void add_js_poly(FILE *js_include_file,int num,char *draw_type,int line_width,char *stroke_color,double stroke_opacity,int use_filled,char *fill_color,double fill_opacity,int use_dashed,int dashtype0,int dashtype1, int use_snap){ |
14038 | schaersvoo | 1642 | fprintf(js_include_file,"\n/* begin userdraw \"%s\" on currect active canvas */\n\ |
7614 | schaersvoo | 1643 | var num = %d;\ |
14044 | schaersvoo | 1644 | var use_snap = %d;\ |
7614 | schaersvoo | 1645 | var line_width = %d;\ |
1646 | var stroke_color = \"%s\";\ |
||
1647 | var stroke_opacity = %f;\ |
||
1648 | var use_filled = %d;\ |
||
1649 | var fill_color = \"%s\";\ |
||
1650 | var fill_opacity = %f;\ |
||
1651 | var use_dashed = %d;\ |
||
1652 | var dashtype0 = %d;\ |
||
1653 | var dashtype1 = %d;\ |
||
1654 | var use_rotate = 0;\ |
||
1655 | var angle = 0;\ |
||
1656 | var use_translate = 0;\ |
||
1657 | var vector=[0,0];\ |
||
1658 | var closed_path = 1;\ |
||
1659 | var done = 1;\ |
||
1660 | var x,y;\ |
||
1661 | var marge = 10*line_width;\ |
||
11002 | schaersvoo | 1662 | var canvas_rect;\ |
7614 | schaersvoo | 1663 | function user_draw(evt){\ |
11002 | schaersvoo | 1664 | var mouse = dragstuff.getMouse(evt,canvas_userdraw);\ |
14044 | schaersvoo | 1665 | var xy = multisnap_check(mouse.x,mouse.y,use_snap);\ |
1666 | x = xy[0];\ |
||
1667 | y = xy[1];\ |
||
14949 | obado | 1668 | if( evt.button == 0 || typeof(evt.identifier) != 'undefined' ){\ |
11002 | schaersvoo | 1669 | if( num == -1 && xy_cnt > 2 ){\ |
1670 | if( x - marge < userdraw_x[0] && x + marge > userdraw_x[0]){\ |
||
1671 | if( y - marge < userdraw_y[0] && y + marge > userdraw_y[0]){\ |
||
1672 | userdraw_x.splice(xy_cnt,1);userdraw_y.splice(xy_cnt,1);\ |
||
8071 | schaersvoo | 1673 | draw_paths(context_userdraw,userdraw_x,userdraw_y,line_width,closed_path,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,0,[1,0,0,1,0,0]);\ |
7614 | schaersvoo | 1674 | done = 1;return;\ |
1675 | };\ |
||
1676 | };\ |
||
1677 | }\ |
||
1678 | else\ |
||
1679 | {\ |
||
11002 | schaersvoo | 1680 | if( xy_cnt == num - 1){\ |
1681 | draw_paths(context_userdraw,userdraw_x,userdraw_y,line_width,closed_path,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,0,[1,0,0,1,0,0]);\ |
||
1682 | done = 1;return;\ |
||
1683 | };\ |
||
1684 | };\ |
||
1685 | done = 0;\ |
||
1686 | userdraw_x[xy_cnt] = x;userdraw_y[xy_cnt] = y;xy_cnt++;\ |
||
1687 | user_drag(evt);\ |
||
1688 | }\ |
||
1689 | else\ |
||
1690 | {\ |
||
1691 | canvas_remove(x,y);\ |
||
1692 | return;\ |
||
1693 | }\ |
||
7614 | schaersvoo | 1694 | };\ |
1695 | function user_drag(evt){\ |
||
1696 | if( done == 0 ){\ |
||
11002 | schaersvoo | 1697 | var mouse = dragstuff.getMouse(evt,canvas_userdraw);\ |
14044 | schaersvoo | 1698 | var xy = multisnap_check(mouse.x,mouse.y,use_snap);\ |
1699 | x = xy[0];\ |
||
1700 | y = xy[1];\ |
||
7614 | schaersvoo | 1701 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
1702 | userdraw_x[xy_cnt] = x;userdraw_y[xy_cnt] = y;\ |
||
8071 | schaersvoo | 1703 | draw_paths(context_userdraw,userdraw_x,userdraw_y,line_width,closed_path,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,0,[1,0,0,1,0,0]);\ |
7614 | schaersvoo | 1704 | }\ |
1705 | }\ |
||
1706 | function canvas_remove(x,y){\ |
||
1707 | for(var p = 0;p < userdraw_x.length ; p++){\ |
||
1708 | if(userdraw_x[p] < x + marge && userdraw_x[p] > x - marge ){\ |
||
1709 | if(userdraw_y[p] < y + marge && userdraw_y[p] > y - marge ){\ |
||
1710 | if( confirm(\"remove polygone ?\" )){\ |
||
1711 | context_userdraw = null;context_userdraw = canvas_userdraw.getContext(\"2d\");context_userdraw.clearRect(0,0,xsize,ysize);\ |
||
1712 | xy_cnt = 0;userdraw_x = [];userdraw_y = [];done = 1;\ |
||
1713 | }\ |
||
1714 | return;\ |
||
1715 | }\ |
||
1716 | }\ |
||
1717 | }\ |
||
14044 | schaersvoo | 1718 | };",draw_type,num,use_snap,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,dashtype1); |
7614 | schaersvoo | 1719 | } |
1720 | |||
11002 | schaersvoo | 1721 | /* |
1722 | canvas_rect = canvas_userdraw.getBoundingClientRect();\ |
||
1723 | var x = evt.clientX - canvas_rect.left;\ |
||
1724 | var y = evt.clientY - canvas_rect.top;\ |
||
1725 | */ |
||
14044 | schaersvoo | 1726 | void add_js_polyline(FILE *js_include_file,char *draw_type,int line_width, char *stroke_color,double stroke_opacity,int use_dashed,int dashtype0,int dashtype1,int use_snap){ |
14038 | schaersvoo | 1727 | fprintf(js_include_file,"\n/* begin userdraw \"%s\" on final canvas */\n\ |
14044 | schaersvoo | 1728 | var use_snap = %d;\ |
7663 | schaersvoo | 1729 | var cnt = 0;\ |
1730 | var line_width = %d;\ |
||
1731 | var stroke_color = \"%s\";\ |
||
1732 | var stroke_opacity = %f;\ |
||
1733 | var use_dashed = %d;\ |
||
1734 | var dashtype0 = %d;\ |
||
1735 | var dashtype1 = %d;\ |
||
11002 | schaersvoo | 1736 | var x,y;\ |
7663 | schaersvoo | 1737 | function user_draw(evt){\ |
11002 | schaersvoo | 1738 | var mouse = dragstuff.getMouse(evt,canvas_userdraw);\ |
14044 | schaersvoo | 1739 | var xy = multisnap_check(mouse.x,mouse.y,use_snap);\ |
1740 | x = xy[0];\ |
||
1741 | y = xy[1];\ |
||
7663 | schaersvoo | 1742 | var lu = userdraw_x.length;\ |
14949 | obado | 1743 | if( evt.button == 0 || typeof(evt.identifier) != 'undefined' ){\ |
7663 | schaersvoo | 1744 | userdraw_x[lu] = x;userdraw_y[lu] = y;\ |
1745 | if( cnt == 0 ){\ |
||
1746 | user_drag(evt);\ |
||
1747 | cnt = 1;\ |
||
1748 | }\ |
||
1749 | else\ |
||
1750 | {\ |
||
1751 | cnt = 0;\ |
||
1752 | draw_polyline(context_userdraw,userdraw_x,userdraw_y,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1);\ |
||
1753 | }\ |
||
1754 | }\ |
||
1755 | else\ |
||
1756 | {\ |
||
1757 | canvas_remove(x,y);\ |
||
1758 | }\ |
||
1759 | };\ |
||
1760 | function user_drag(evt){\ |
||
1761 | if( cnt == 0){\ |
||
11002 | schaersvoo | 1762 | var mouse = dragstuff.getMouse(evt,canvas_userdraw);\ |
14044 | schaersvoo | 1763 | var xy = multisnap_check(mouse.x,mouse.y,use_snap);\ |
1764 | x = xy[0];\ |
||
1765 | y = xy[1];\ |
||
7663 | schaersvoo | 1766 | var lu = userdraw_x.length;\ |
1767 | if( lu > 0 ){\ |
||
1768 | userdraw_x[lu - 1] = x; userdraw_y[lu - 1] = y;\ |
||
1769 | draw_polyline(context_userdraw,userdraw_x,userdraw_y,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1);\ |
||
1770 | };\ |
||
1771 | }\ |
||
1772 | };\ |
||
1773 | function canvas_remove(x,y){\ |
||
1774 | if( confirm(\"remove line ?\" )){\ |
||
1775 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
||
1776 | userdraw_x = [];userdraw_y = [];cnt = 1;\ |
||
11006 | schaersvoo | 1777 | xy_cnt=0;\ |
7663 | schaersvoo | 1778 | return;\ |
1779 | }\ |
||
14044 | schaersvoo | 1780 | };",draw_type,use_snap,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1); |
7663 | schaersvoo | 1781 | } |
7614 | schaersvoo | 1782 | |
14044 | schaersvoo | 1783 | void add_js_segments(FILE *js_include_file,int num,char *draw_type,int line_width, char *stroke_color,double stroke_opacity,int use_dashed,int dashtype0,int dashtype1,int use_snap){ |
14038 | schaersvoo | 1784 | fprintf(js_include_file,"\n/* begin userdraw \"%s\" on final canvas */\n\ |
7614 | schaersvoo | 1785 | var num = %d;\ |
14061 | schaersvoo | 1786 | var use_snap = %d;\ |
7614 | schaersvoo | 1787 | var line_width = %d;\ |
1788 | var stroke_color = \"%s\";\ |
||
1789 | var stroke_opacity = %f;\ |
||
1790 | var use_dashed = %d;\ |
||
1791 | var dashtype0 = %d;\ |
||
1792 | var dashtype1 = %d;\ |
||
1793 | var x0,y0;\ |
||
1794 | function user_draw(evt){\ |
||
7652 | schaersvoo | 1795 | var lu = userdraw_x.length;\ |
1796 | if( lu != 0 && lu%%2 == 0){\ |
||
7614 | schaersvoo | 1797 | draw_segments(context_userdraw,userdraw_x,userdraw_y,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1);\ |
1798 | }\ |
||
11002 | schaersvoo | 1799 | var mouse = dragstuff.getMouse(evt,canvas_userdraw);\ |
14044 | schaersvoo | 1800 | var xy = multisnap_check(mouse.x,mouse.y,use_snap);\ |
1801 | var x = xy[0];\ |
||
1802 | var y = xy[1];\ |
||
14949 | obado | 1803 | if( evt.button == 0 || typeof(evt.identifier) != 'undefined' ){\ |
11002 | schaersvoo | 1804 | if( lu%%2 == 0){\ |
1805 | x0 = x;y0 = y;\ |
||
1806 | if(num == 1){ userdraw_x = [];userdraw_y = [];userdraw_x[0] = x0;userdraw_y[0] = y0;} else {userdraw_x[lu] = x0;userdraw_y[lu] = y0;};\ |
||
1807 | draw_circles(context_userdraw,[x0],[y0],[line_width],line_width,stroke_color,stroke_opacity,1,stroke_color,stroke_opacity,0,1,1);\ |
||
1808 | user_drag(evt);\ |
||
7614 | schaersvoo | 1809 | }\ |
1810 | else\ |
||
1811 | {\ |
||
11002 | schaersvoo | 1812 | if( num == 1 ){ userdraw_x[1] = x;userdraw_y[1] = y;} else {userdraw_x[lu] = x;userdraw_y[lu] = y;};\ |
12008 | schaersvoo | 1813 | if( userdraw_x[lu] == userdraw_x[lu-1] && userdraw_y[lu] == userdraw_y[lu-1]){userdraw_x.splice(lu,2);userdraw_y.splice(lu,2);};\ |
11002 | schaersvoo | 1814 | draw_segments(context_userdraw,userdraw_x,userdraw_y,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1);\ |
7614 | schaersvoo | 1815 | }\ |
1816 | }\ |
||
11002 | schaersvoo | 1817 | else\ |
1818 | {\ |
||
1819 | canvas_remove(x,y);\ |
||
1820 | }\ |
||
7614 | schaersvoo | 1821 | };\ |
1822 | function user_drag(evt){\ |
||
11002 | schaersvoo | 1823 | var mouse = dragstuff.getMouse(evt,canvas_userdraw);\ |
14044 | schaersvoo | 1824 | var xy = multisnap_check(mouse.x,mouse.y,use_snap);\ |
1825 | var x = xy[0];\ |
||
1826 | var y = xy[1];\ |
||
7652 | schaersvoo | 1827 | var lu = userdraw_x.length;\ |
1828 | if( lu%%2 != 0 ){\ |
||
7614 | schaersvoo | 1829 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
1830 | draw_circles(context_userdraw,[x0],[y0],[line_width],line_width,stroke_color,stroke_opacity,1,stroke_color,stroke_opacity,0,1,1);\ |
||
1831 | draw_circles(context_userdraw,[x],[y],[line_width],line_width,stroke_color,stroke_opacity,1,stroke_color,stroke_opacity,0,1,1);\ |
||
1832 | draw_segments(context_userdraw,[x0,x],[y0,y],line_width,stroke_color,stroke_opacity);\ |
||
7652 | schaersvoo | 1833 | if( lu > 0){\ |
7614 | schaersvoo | 1834 | draw_segments(context_userdraw,userdraw_x,userdraw_y,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1);\ |
1835 | }\ |
||
1836 | }\ |
||
1837 | };\ |
||
1838 | function canvas_remove(x,y){\ |
||
1839 | var marge = 10*line_width;\ |
||
1840 | for(var p = 0;p < userdraw_x.length ; p++){\ |
||
1841 | if(userdraw_x[p] < x + marge && userdraw_x[p] > x - marge ){\ |
||
1842 | if(userdraw_y[p] < y + marge && userdraw_y[p] > y - marge ){\ |
||
1843 | if( confirm(\"remove line ?\" )){\ |
||
1844 | context_userdraw = null;context_userdraw = canvas_userdraw.getContext(\"2d\");context_userdraw.clearRect(0,0,xsize,ysize);\ |
||
1845 | if( p%%2 == 0 ){\ |
||
1846 | userdraw_x.splice(p,2);userdraw_y.splice(p,2);\ |
||
1847 | }\ |
||
1848 | else\ |
||
1849 | {\ |
||
1850 | userdraw_x.splice(p-1,2);userdraw_y.splice(p-1,2);\ |
||
1851 | }\ |
||
7652 | schaersvoo | 1852 | if(userdraw_x.length < 2){ userdraw_x = [];userdraw_y = [];return;};\ |
11006 | schaersvoo | 1853 | xy_cnt = xy_cnt - 2;\ |
7614 | schaersvoo | 1854 | draw_segments(context_userdraw,userdraw_x,userdraw_y,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1);\ |
1855 | }\ |
||
1856 | return;\ |
||
1857 | }\ |
||
1858 | }\ |
||
1859 | }\ |
||
14061 | schaersvoo | 1860 | };",draw_type,num,use_snap,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1); |
7614 | schaersvoo | 1861 | } |
1862 | |||
14044 | schaersvoo | 1863 | void add_js_demilines(FILE *js_include_file,int num,char *draw_type,int line_width, char *stroke_color,double stroke_opacity,int use_dashed,int dashtype0,int dashtype1,int use_snap){ |
14038 | schaersvoo | 1864 | fprintf(js_include_file,"\n/* begin userdraw \"%s\" on final canvas */\n\ |
8244 | schaersvoo | 1865 | var num = %d;\ |
14044 | schaersvoo | 1866 | var use_snap = %d;\ |
8244 | schaersvoo | 1867 | var line_width = %d;\ |
1868 | var stroke_color = \"%s\";\ |
||
1869 | var stroke_opacity = %f;\ |
||
1870 | var use_dashed = %d;\ |
||
1871 | var dashtype0 = %d;\ |
||
1872 | var dashtype1 = %d;\ |
||
1873 | var x0,y0;\ |
||
1874 | function user_draw(evt){\ |
||
1875 | var lu = userdraw_x.length;\ |
||
1876 | if( lu != 0 && lu%%2 == 0){\ |
||
1877 | draw_demilines(context_userdraw,userdraw_x,userdraw_y,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1);\ |
||
1878 | }\ |
||
11002 | schaersvoo | 1879 | var mouse = dragstuff.getMouse(evt,canvas_userdraw);\ |
14044 | schaersvoo | 1880 | var xy = multisnap_check(mouse.x,mouse.y,use_snap);\ |
1881 | var x = xy[0];\ |
||
1882 | var y = xy[1];\ |
||
14949 | obado | 1883 | if( evt.button == 0 || typeof(evt.identifier) != 'undefined' ){\ |
11002 | schaersvoo | 1884 | if( lu%%2 == 0){\ |
1885 | x0 = x;y0 = y;\ |
||
1886 | if(num == 1){ userdraw_x = [];userdraw_y = [];userdraw_x[0] = x0;userdraw_y[0] = y0;} else {userdraw_x[lu] = x0;userdraw_y[lu] = y0;}\ |
||
1887 | draw_circles(context_userdraw,[x0],[y0],[line_width],line_width,stroke_color,stroke_opacity,1,stroke_color,stroke_opacity,0,1,1);\ |
||
1888 | user_drag(evt);\ |
||
8244 | schaersvoo | 1889 | }\ |
1890 | else\ |
||
1891 | {\ |
||
11002 | schaersvoo | 1892 | if( num == 1 ){ userdraw_x[1] = x;userdraw_y[1] = y;} else {userdraw_x[lu] = x;userdraw_y[lu] = y;};\ |
12008 | schaersvoo | 1893 | if( userdraw_x[lu] == userdraw_x[lu-1] && userdraw_y[lu] == userdraw_y[lu-1]){userdraw_x.splice(lu,2);userdraw_y.splice(lu,2);};\ |
11002 | schaersvoo | 1894 | draw_demilines(context_userdraw,userdraw_x,userdraw_y,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1);\ |
8244 | schaersvoo | 1895 | }\ |
1896 | }\ |
||
11002 | schaersvoo | 1897 | else\ |
1898 | {\ |
||
1899 | canvas_remove(x,y);\ |
||
1900 | }\ |
||
8244 | schaersvoo | 1901 | };\ |
1902 | function user_drag(evt){\ |
||
11002 | schaersvoo | 1903 | var mouse = dragstuff.getMouse(evt,canvas_userdraw);\ |
14044 | schaersvoo | 1904 | var xy = multisnap_check(mouse.x,mouse.y,use_snap);\ |
1905 | var x = xy[0];\ |
||
1906 | var y = xy[1];\ |
||
8244 | schaersvoo | 1907 | var lu = userdraw_x.length;\ |
1908 | if( lu%%2 != 0 ){\ |
||
1909 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
||
1910 | draw_circles(context_userdraw,[x0],[y0],[line_width],line_width,stroke_color,stroke_opacity,1,stroke_color,stroke_opacity,0,1,1);\ |
||
1911 | draw_circles(context_userdraw,[x],[y],[line_width],line_width,stroke_color,stroke_opacity,1,stroke_color,stroke_opacity,0,1,1);\ |
||
1912 | draw_demilines(context_userdraw,[x0,x],[y0,y],line_width,stroke_color,stroke_opacity);\ |
||
1913 | if( lu > 0){\ |
||
1914 | draw_demilines(context_userdraw,userdraw_x,userdraw_y,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1);\ |
||
1915 | }\ |
||
1916 | }\ |
||
1917 | };\ |
||
1918 | function canvas_remove(x,y){\ |
||
1919 | var marge = 10*line_width;\ |
||
1920 | for(var p = 0;p < userdraw_x.length ; p++){\ |
||
1921 | if(userdraw_x[p] < x + marge && userdraw_x[p] > x - marge ){\ |
||
1922 | if(userdraw_y[p] < y + marge && userdraw_y[p] > y - marge ){\ |
||
1923 | if( confirm(\"remove line ?\" )){\ |
||
1924 | context_userdraw = null;context_userdraw = canvas_userdraw.getContext(\"2d\");context_userdraw.clearRect(0,0,xsize,ysize);\ |
||
1925 | if( p%%2 == 0 ){\ |
||
1926 | userdraw_x.splice(p,2);userdraw_y.splice(p,2);\ |
||
1927 | }\ |
||
1928 | else\ |
||
1929 | {\ |
||
1930 | userdraw_x.splice(p-1,2);userdraw_y.splice(p-1,2);\ |
||
1931 | }\ |
||
11006 | schaersvoo | 1932 | xy_cnt = xy_cnt - 2;\ |
8244 | schaersvoo | 1933 | if(userdraw_x.length < 2){ userdraw_x = [];userdraw_y = [];return;};\ |
1934 | draw_demilines(context_userdraw,userdraw_x,userdraw_y,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1);\ |
||
1935 | }\ |
||
1936 | return;\ |
||
1937 | }\ |
||
1938 | }\ |
||
1939 | }\ |
||
14044 | schaersvoo | 1940 | };",draw_type,num,use_snap,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1); |
8244 | schaersvoo | 1941 | } |
1942 | |||
1943 | |||
8224 | bpr | 1944 | /* |
1945 | num=1 single horizontal line |
||
7989 | schaersvoo | 1946 | num=2 multiple horizontal lines |
1947 | num=3 single vertical line |
||
1948 | num=4 multiple vertical lines |
||
1949 | */ |
||
14044 | schaersvoo | 1950 | void add_js_hlines(FILE *js_include_file,int num,char *draw_type,int line_width, char *stroke_color,double stroke_opacity,int use_dashed,int dashtype0,int dashtype1,int use_snap){ |
14038 | schaersvoo | 1951 | fprintf(js_include_file,"\n/* begin userdraw \"%s\" on final canvas */\n\ |
7989 | schaersvoo | 1952 | var num = %d;\ |
14044 | schaersvoo | 1953 | var use_snap = %d;\ |
7989 | schaersvoo | 1954 | var line_width = %d;\ |
1955 | var stroke_color = \"%s\";\ |
||
1956 | var stroke_opacity = %f;\ |
||
1957 | var use_dashed = %d;\ |
||
1958 | var dashtype0 = %d;\ |
||
1959 | var dashtype1 = %d;\ |
||
1960 | var x0,y0;\ |
||
1961 | function user_draw(evt){\ |
||
14949 | obado | 1962 | if( evt.button == 0 || typeof(evt.identifier) != 'undefined' ){\ |
11002 | schaersvoo | 1963 | var mouse = dragstuff.getMouse(evt,canvas_userdraw);\ |
14044 | schaersvoo | 1964 | var xy = multisnap_check(mouse.x,mouse.y,use_snap);\ |
1965 | var x = xy[0];\ |
||
1966 | var y = xy[1];\ |
||
7989 | schaersvoo | 1967 | var lu = userdraw_x.length;\ |
1968 | switch(num){\ |
||
1969 | case 1: userdraw_x[0] = x;userdraw_x[1] = xmax;userdraw_y[0] = y; userdraw_y[1] = y;break;\ |
||
1970 | case 2: userdraw_x[lu] = x;userdraw_x[lu+1] = xmax;userdraw_y[lu] = y;userdraw_y[lu+1] = y;break;\ |
||
1971 | case 3: userdraw_x[0] = x;userdraw_x[1] = x;userdraw_y[0] = y; userdraw_y[1] = ymax;break;\ |
||
1972 | case 4: userdraw_x[lu] = x;userdraw_x[lu+1] = x;userdraw_y[lu] = y;userdraw_y[lu+1] = ymax;break;\ |
||
1973 | };\ |
||
1974 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
||
1975 | draw_lines(context_userdraw,userdraw_x,userdraw_y,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1);\ |
||
1976 | }\ |
||
1977 | else\ |
||
1978 | {\ |
||
7990 | schaersvoo | 1979 | userdraw_x = [];userdraw_y = [];context_userdraw.clearRect(0,0,xsize,ysize);return;\ |
7989 | schaersvoo | 1980 | };\ |
1981 | };\ |
||
14044 | schaersvoo | 1982 | function user_drag(evt){ return evt; };",draw_type,num,use_snap,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1); |
7989 | schaersvoo | 1983 | } |
1984 | |||
1985 | |||
8244 | schaersvoo | 1986 | |
14044 | schaersvoo | 1987 | void add_js_lines(FILE *js_include_file,int num,char *draw_type,int line_width, char *stroke_color,double stroke_opacity,int use_dashed,int dashtype0,int dashtype1,int use_snap){ |
14038 | schaersvoo | 1988 | fprintf(js_include_file,"\n/* begin userdraw \"%s\" on final canvas */\n\ |
7614 | schaersvoo | 1989 | var num = %d;\ |
14060 | schaersvoo | 1990 | var use_snap =%d;\ |
7614 | schaersvoo | 1991 | var line_width = %d;\ |
1992 | var stroke_color = \"%s\";\ |
||
1993 | var stroke_opacity = %f;\ |
||
1994 | var use_dashed = %d;\ |
||
1995 | var dashtype0 = %d;\ |
||
1996 | var dashtype1 = %d;\ |
||
7746 | schaersvoo | 1997 | var x0,y0;\ |
7614 | schaersvoo | 1998 | function user_draw(evt){\ |
7746 | schaersvoo | 1999 | var lu = userdraw_x.length;\ |
2000 | if( lu != 0 && lu%%2 == 0){\ |
||
2001 | draw_lines(context_userdraw,userdraw_x,userdraw_y,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1);\ |
||
2002 | }\ |
||
11002 | schaersvoo | 2003 | var mouse = dragstuff.getMouse(evt,canvas_userdraw);\ |
14044 | schaersvoo | 2004 | var xy = multisnap_check(mouse.x,mouse.y,use_snap);\ |
2005 | var x = xy[0];\ |
||
2006 | var y = xy[1];\ |
||
14949 | obado | 2007 | if( evt.button == 0 || typeof(evt.identifier) != 'undefined' ){\ |
11002 | schaersvoo | 2008 | if( lu%%2 == 0){\ |
2009 | x0 = x;y0 = y;\ |
||
2010 | if(num == 1){ userdraw_x = [];userdraw_y = [];userdraw_x[0] = x0;userdraw_y[0] = y0;} else {userdraw_x[lu] = x0;userdraw_y[lu] = y0;}\ |
||
2011 | draw_circles(context_userdraw,[x0],[y0],[line_width],line_width,stroke_color,stroke_opacity,1,stroke_color,stroke_opacity,0,1,1);\ |
||
2012 | user_drag(evt);\ |
||
7614 | schaersvoo | 2013 | }\ |
2014 | else\ |
||
2015 | {\ |
||
11002 | schaersvoo | 2016 | if( num == 1 ){ userdraw_x[1] = x;userdraw_y[1] = y;} else {userdraw_x[lu] = x;userdraw_y[lu] = y;};\ |
12008 | schaersvoo | 2017 | if( userdraw_x[lu] == userdraw_x[lu-1] && userdraw_y[lu] == userdraw_y[lu-1]){userdraw_x.splice(lu,2);userdraw_y.splice(lu,2);};\ |
11002 | schaersvoo | 2018 | draw_lines(context_userdraw,userdraw_x,userdraw_y,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1);\ |
7989 | schaersvoo | 2019 | };\ |
11002 | schaersvoo | 2020 | }\ |
2021 | else\ |
||
2022 | {\ |
||
2023 | canvas_remove(x,y);\ |
||
7989 | schaersvoo | 2024 | };\ |
7614 | schaersvoo | 2025 | };\ |
2026 | function user_drag(evt){\ |
||
11002 | schaersvoo | 2027 | var mouse = dragstuff.getMouse(evt,canvas_userdraw);\ |
14044 | schaersvoo | 2028 | var xy = multisnap_check(mouse.x,mouse.y,use_snap);\ |
2029 | var x = xy[0];\ |
||
2030 | var y = xy[1];\ |
||
7746 | schaersvoo | 2031 | var lu = userdraw_x.length;\ |
2032 | if( lu%%2 != 0 ){\ |
||
7614 | schaersvoo | 2033 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
7746 | schaersvoo | 2034 | draw_circles(context_userdraw,[x0],[y0],[line_width],line_width,stroke_color,stroke_opacity,1,stroke_color,stroke_opacity,0,1,1);\ |
2035 | draw_circles(context_userdraw,[x],[y],[line_width],line_width,stroke_color,stroke_opacity,1,stroke_color,stroke_opacity,0,1,1);\ |
||
2036 | draw_lines(context_userdraw,[x0,x],[y0,y],line_width,stroke_color,stroke_opacity);\ |
||
2037 | if( lu > 0){\ |
||
2038 | draw_lines(context_userdraw,userdraw_x,userdraw_y,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1);\ |
||
2039 | }\ |
||
7614 | schaersvoo | 2040 | }\ |
2041 | };\ |
||
2042 | function canvas_remove(x,y){\ |
||
2043 | var marge = 10*line_width;\ |
||
2044 | for(var p = 0;p < userdraw_x.length ; p++){\ |
||
2045 | if(userdraw_x[p] < x + marge && userdraw_x[p] > x - marge ){\ |
||
2046 | if(userdraw_y[p] < y + marge && userdraw_y[p] > y - marge ){\ |
||
2047 | if( confirm(\"remove line ?\" )){\ |
||
2048 | context_userdraw = null;context_userdraw = canvas_userdraw.getContext(\"2d\");context_userdraw.clearRect(0,0,xsize,ysize);\ |
||
2049 | if( p%%2 == 0 ){\ |
||
2050 | userdraw_x.splice(p,2);userdraw_y.splice(p,2);\ |
||
2051 | }\ |
||
2052 | else\ |
||
2053 | {\ |
||
2054 | userdraw_x.splice(p-1,2);userdraw_y.splice(p-1,2);\ |
||
2055 | }\ |
||
11006 | schaersvoo | 2056 | xy_cnt--;\ |
7746 | schaersvoo | 2057 | if(userdraw_x.length < 2){ userdraw_x = [];userdraw_y = [];return;};\ |
7614 | schaersvoo | 2058 | draw_lines(context_userdraw,userdraw_x,userdraw_y,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1);\ |
2059 | }\ |
||
2060 | return;\ |
||
2061 | }\ |
||
2062 | }\ |
||
2063 | }\ |
||
14044 | schaersvoo | 2064 | };",draw_type,num,use_snap,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1); |
7614 | schaersvoo | 2065 | } |
2066 | |||
8244 | schaersvoo | 2067 | |
14044 | schaersvoo | 2068 | void add_js_arrows(FILE *js_include_file,int num,char *draw_type,int line_width,int type, char *stroke_color,double stroke_opacity,int use_dashed,int dashtype0,int dashtype1,int arrow_head,int use_snap){ |
8224 | bpr | 2069 | /* |
7875 | schaersvoo | 2070 | constants in draw_arrows() ... for this moment: ;var use_rotate = 0;var angle = 0;var use_translate = 0 ;var vector = [0,0];\ |
7654 | schaersvoo | 2071 | */ |
14038 | schaersvoo | 2072 | fprintf(js_include_file,"\n/* begin userdraw \"%s\" on final canvas */\n\ |
7614 | schaersvoo | 2073 | var num = %d;\ |
14044 | schaersvoo | 2074 | var use_snap = %d;\ |
7614 | schaersvoo | 2075 | var line_width = %d;\ |
2076 | var stroke_color = \"%s\";\ |
||
2077 | var stroke_opacity = %f;\ |
||
2078 | var use_dashed = %d;\ |
||
2079 | var dashtype0 = %d;\ |
||
2080 | var dashtype1 = %d;\ |
||
2081 | var arrow_head = %d;\ |
||
2082 | var x0,y0;\ |
||
7875 | schaersvoo | 2083 | var type = %d;\ |
2084 | var use_rotate = 0;var angle = 0;var use_translate = 0 ;var vector = [0,0];\ |
||
7614 | schaersvoo | 2085 | function user_draw(evt){\ |
7654 | schaersvoo | 2086 | var lu = userdraw_x.length;\ |
2087 | if( lu != 0 && lu%%2 == 0){\ |
||
8071 | schaersvoo | 2088 | draw_arrows(context_userdraw,userdraw_x,userdraw_y,arrow_head,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,type,use_rotate,angle,0,[1,0,0,1,0,0]);\ |
7614 | schaersvoo | 2089 | }\ |
11002 | schaersvoo | 2090 | var mouse = dragstuff.getMouse(evt,canvas_userdraw);\ |
14044 | schaersvoo | 2091 | var xy = multisnap_check(mouse.x,mouse.y,use_snap);\ |
2092 | var x = xy[0];\ |
||
2093 | var y = xy[1];\ |
||
14949 | obado | 2094 | if( evt.button == 0 || typeof(evt.identifier) != 'undefined' ){\ |
11002 | schaersvoo | 2095 | if( lu%%2 == 0){\ |
2096 | x0 = x;y0 = y;\ |
||
2097 | if(num == 1){ userdraw_x = [];userdraw_y = [];userdraw_x[0] = x0;userdraw_y[0] = y0;} else {userdraw_x[lu] = x0;userdraw_y[lu] = y0;}\ |
||
2098 | user_drag(evt);\ |
||
7614 | schaersvoo | 2099 | }\ |
2100 | else\ |
||
2101 | {\ |
||
11002 | schaersvoo | 2102 | if( num == 1 ){ userdraw_x[1] = x;userdraw_y[1] = y;} else {userdraw_x[lu] = x;userdraw_y[lu] = y;};\ |
12008 | schaersvoo | 2103 | if( userdraw_x[lu] == userdraw_x[lu-1] && userdraw_y[lu] == userdraw_y[lu-1]){userdraw_x.splice(lu,2);userdraw_y.splice(lu,2);};\ |
11002 | schaersvoo | 2104 | draw_arrows(context_userdraw,userdraw_x,userdraw_y,arrow_head,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,type,use_rotate,angle,0,[1,0,0,1,0,0]);\ |
2105 | };\ |
||
7614 | schaersvoo | 2106 | }\ |
11002 | schaersvoo | 2107 | else\ |
2108 | {\ |
||
2109 | canvas_remove(x,y);\ |
||
2110 | };\ |
||
7614 | schaersvoo | 2111 | };\ |
2112 | function user_drag(evt){\ |
||
11002 | schaersvoo | 2113 | var mouse = dragstuff.getMouse(evt,canvas_userdraw);\ |
14044 | schaersvoo | 2114 | var xy = multisnap_check(mouse.x,mouse.y,use_snap);\ |
2115 | var x = xy[0];\ |
||
2116 | var y = xy[1];\ |
||
7654 | schaersvoo | 2117 | var lu = userdraw_x.length;\ |
2118 | if( lu%%2 != 0 ){\ |
||
7614 | schaersvoo | 2119 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
8071 | schaersvoo | 2120 | draw_arrows(context_userdraw,[x0,x],[y0,y],arrow_head,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,type,use_rotate,angle,0,[1,0,0,1,0,0]);\ |
7654 | schaersvoo | 2121 | if( lu > 0){\ |
8071 | schaersvoo | 2122 | draw_arrows(context_userdraw,userdraw_x,userdraw_y,arrow_head,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,type,use_rotate,angle,0,[1,0,0,1,0,0]);\ |
7614 | schaersvoo | 2123 | }\ |
2124 | }\ |
||
2125 | };\ |
||
2126 | function canvas_remove(x,y){\ |
||
2127 | var marge = 10*line_width;\ |
||
2128 | for(var p = 0;p < userdraw_x.length ; p++){\ |
||
2129 | if(userdraw_x[p] < x + marge && userdraw_x[p] > x - marge ){\ |
||
2130 | if(userdraw_y[p] < y + marge && userdraw_y[p] > y - marge ){\ |
||
7654 | schaersvoo | 2131 | if( confirm(\"remove line ?\" )){\ |
7614 | schaersvoo | 2132 | context_userdraw = null;context_userdraw = canvas_userdraw.getContext(\"2d\");context_userdraw.clearRect(0,0,xsize,ysize);\ |
2133 | if( p%%2 == 0 ){\ |
||
2134 | userdraw_x.splice(p,2);userdraw_y.splice(p,2);\ |
||
2135 | }\ |
||
2136 | else\ |
||
2137 | {\ |
||
2138 | userdraw_x.splice(p-1,2);userdraw_y.splice(p-1,2);\ |
||
2139 | }\ |
||
11006 | schaersvoo | 2140 | xy_cnt = xy_cnt - 2;\ |
7654 | schaersvoo | 2141 | if(userdraw_x.length < 2){ userdraw_x = [];userdraw_y = [];return;};\ |
8071 | schaersvoo | 2142 | draw_arrows(context_userdraw,userdraw_x,userdraw_y,arrow_head,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,type,use_rotate,angle,0,[1,0,0,1,0,0],type,use_rotate,angle,0,[1,0,0,1,0,0]);\ |
7614 | schaersvoo | 2143 | }\ |
2144 | return;\ |
||
2145 | }\ |
||
2146 | }\ |
||
2147 | }\ |
||
14044 | schaersvoo | 2148 | };",draw_type,num,use_snap,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,arrow_head,type); |
7654 | schaersvoo | 2149 | |
7614 | schaersvoo | 2150 | } |
2151 | |||
14044 | schaersvoo | 2152 | void add_js_curvedarrow(FILE *js_include_file,int canvas_root_id,int num,int line_width,char *stroke_color,double stroke_opacity,int use_dashed,int arrow_head,int type,int use_snap){ |
2153 | fprintf(js_include_file,"\n<!-- begin userdraw \"curvedarrow\" on final canvas -->\n\ |
||
14038 | schaersvoo | 2154 | xy_cnt = 0;\ |
14044 | schaersvoo | 2155 | var use_snap = %d;\ |
14025 | schaersvoo | 2156 | function user_draw(evt){\ |
14949 | obado | 2157 | if(evt.button == 0 || typeof(evt.identifier) != 'undefined' ){\ |
14025 | schaersvoo | 2158 | var mouse = dragstuff.getMouse(evt,canvas_userdraw);\ |
14038 | schaersvoo | 2159 | var xy = multisnap_check(mouse.x,mouse.y,use_snap);\ |
2160 | if(1 == %d){if(xy_cnt == 3){xy_cnt = 0;userdraw_x = [];userdraw_y = [];context_userdraw.clearRect(0,0,xsize,ysize);};};\ |
||
2161 | userdraw_x[xy_cnt] = xy[0];userdraw_y[xy_cnt] = xy[1];\ |
||
2162 | xy_cnt++;\ |
||
14025 | schaersvoo | 2163 | };\ |
2164 | return;\ |
||
2165 | };\ |
||
2166 | function user_drag(evt){\ |
||
14949 | obado | 2167 | if(evt.button == 0 || typeof(evt.identifier) != 'undefined' ){\ |
14038 | schaersvoo | 2168 | var mouse = dragstuff.getMouse(evt,canvas_userdraw);\ |
2169 | var xy = multisnap_check(mouse.x,mouse.y,use_snap);\ |
||
2170 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
||
2171 | userdraw_x[xy_cnt] = xy[0];userdraw_y[xy_cnt] = xy[1];\ |
||
2172 | for(var p=0; p<xy_cnt;p=p+3){\ |
||
2173 | drawCurvedArrow(context_userdraw,userdraw_x[p],userdraw_y[p],userdraw_x[p+1],userdraw_y[p+1],userdraw_x[p+2],userdraw_y[p+2],%d,%d,'%s',%f,%d,%d);\ |
||
2174 | };\ |
||
2175 | userdraw_x.pop();userdraw_y.pop();\ |
||
14025 | schaersvoo | 2176 | };\ |
14038 | schaersvoo | 2177 | return;\ |
14025 | schaersvoo | 2178 | };\ |
14035 | schaersvoo | 2179 | function drawCurvedArrow(ctx,x1,y1,x2,y2,xm,ym,linewidth,arrowhead,color,opacity,use_dashed,type){\ |
14025 | schaersvoo | 2180 | if(use_dashed == 1 ){ if( ctx.setLineDash ){ctx.setLineDash([2,4]);}else{if(ctx.mozDash){context_circles.mozDash = [2,4]};};};\ |
2181 | ctx.save();\ |
||
2182 | ctx.strokeStyle = \"rgba(\"+color+\",\"+opacity+\")\";\ |
||
2183 | ctx.lineWidth = linewidth;\ |
||
14027 | schaersvoo | 2184 | var angle1 = Math.atan2(xm - x2,ym - y2) + Math.PI;\ |
14025 | schaersvoo | 2185 | ctx.beginPath();\ |
2186 | ctx.moveTo(x1,y1);\ |
||
14027 | schaersvoo | 2187 | if(type == 2){\ |
2188 | var angle2 = Math.atan2(xm - x1,ym - y1) + Math.PI;\ |
||
2189 | ctx.moveTo(x1 - (arrowhead * Math.sin(angle2 - Math.PI / 6)),y1 - (arrowhead * Math.cos(angle2 - Math.PI / 6)));\ |
||
2190 | ctx.lineTo(x1, y1);\ |
||
2191 | ctx.lineTo(x1 - (arrowhead * Math.sin(angle2 + Math.PI / 6)),y1 - (arrowhead * Math.cos(angle2 + Math.PI / 6)));\ |
||
2192 | };\ |
||
2193 | ctx.moveTo(x1,y1);\ |
||
14025 | schaersvoo | 2194 | ctx.quadraticCurveTo(xm,ym,x2,y2);\ |
14027 | schaersvoo | 2195 | ctx.moveTo(x2 - (arrowhead * Math.sin(angle1 - Math.PI / 6)),y2 - (arrowhead * Math.cos(angle1 - Math.PI / 6)));\ |
14025 | schaersvoo | 2196 | ctx.lineTo(x2, y2);\ |
14027 | schaersvoo | 2197 | ctx.lineTo(x2 - (arrowhead * Math.sin(angle1 + Math.PI / 6)),y2 - (arrowhead * Math.cos(angle1 + Math.PI / 6)));\ |
14025 | schaersvoo | 2198 | ctx.stroke();\ |
2199 | ctx.closePath();\ |
||
2200 | ctx.restore();\ |
||
14044 | schaersvoo | 2201 | };",use_snap,num,line_width,arrow_head,stroke_color,stroke_opacity,use_dashed,type); |
14025 | schaersvoo | 2202 | } |
2203 | |||
2204 | |||
14044 | schaersvoo | 2205 | void add_js_paths(FILE *js_include_file,int num,char *draw_type,int line_width, int closed_path,char *stroke_color,double stroke_opacity,int use_filled, char *fill_color,double fill_opacity,int use_dashed,int dashtype0,int dashtype1,int use_snap){ |
14038 | schaersvoo | 2206 | fprintf(js_include_file,"\n/* begin userdraw \"%s\" on final canvas */\n\ |
7614 | schaersvoo | 2207 | var path_cnt = 0;\ |
8227 | schaersvoo | 2208 | var temp_x = [];\ |
2209 | var temp_y = [];\ |
||
14044 | schaersvoo | 2210 | var use_snap = %d;\ |
7614 | schaersvoo | 2211 | var num = %d;\ |
2212 | xy_cnt=0;\ |
||
2213 | var line_width = %d;\ |
||
2214 | var stroke_color = \"%s\";\ |
||
2215 | var stroke_opacity = %f;\ |
||
2216 | var fill_color = \"%s\";\ |
||
2217 | var fill_opacity = %f;\ |
||
2218 | var use_filled = %d;\ |
||
2219 | var use_dashed = %d;\ |
||
2220 | var dashtype0 = %d;\ |
||
2221 | var dashtype1 = %d;\ |
||
2222 | var closed_path = 0;\ |
||
2223 | var click_cnt=0;\ |
||
2224 | function user_draw(evt){\ |
||
11002 | schaersvoo | 2225 | var mouse = dragstuff.getMouse(evt,canvas_userdraw);\ |
14044 | schaersvoo | 2226 | var xy = multisnap_check(mouse.x,mouse.y,use_snap);\ |
2227 | var x = xy[0];var y = xy[1];\ |
||
14949 | obado | 2228 | if(evt.button == 0 || typeof(evt.identifier) != 'undefined' ){\ |
7614 | schaersvoo | 2229 | if( click_cnt == 0 ){\ |
2230 | click_cnt = 1;\ |
||
2231 | user_drag(evt);\ |
||
2232 | }\ |
||
2233 | else\ |
||
2234 | {\ |
||
2235 | userdraw_x[path_cnt] = new Array();\ |
||
2236 | userdraw_y[path_cnt] = new Array();\ |
||
2237 | userdraw_x[path_cnt] = temp_x;\ |
||
2238 | userdraw_y[path_cnt] = temp_y;\ |
||
2239 | path_cnt++;\ |
||
2240 | temp_x = [];\ |
||
2241 | temp_y = [];\ |
||
2242 | click_cnt = 0;\ |
||
2243 | xy_cnt = 0;\ |
||
2244 | };\ |
||
2245 | }\ |
||
2246 | else\ |
||
2247 | {\ |
||
11002 | schaersvoo | 2248 | canvas_remove(x,y);\ |
7614 | schaersvoo | 2249 | };\ |
2250 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
||
2251 | for(var p=0; p < path_cnt; p++){\ |
||
2252 | if(userdraw_x[p] != null){\ |
||
2253 | draw_paths(context_userdraw,userdraw_x[p],userdraw_y[p],line_width,0,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,dashtype1);\ |
||
2254 | };\ |
||
2255 | };\ |
||
2256 | };\ |
||
2257 | function user_drag(evt){\ |
||
2258 | if(click_cnt == 1 ){\ |
||
11002 | schaersvoo | 2259 | var mouse = dragstuff.getMouse(evt,canvas_userdraw);\ |
14044 | schaersvoo | 2260 | var xy = multisnap_check(mouse.x,mouse.y,use_snap);\ |
2261 | temp_x[xy_cnt] = xy[0];temp_y[xy_cnt] = xy[1];\ |
||
11002 | schaersvoo | 2262 | xy_cnt++;\ |
2263 | draw_paths(context_userdraw,temp_x,temp_y,line_width,0,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,dashtype1);\ |
||
7614 | schaersvoo | 2264 | };\ |
2265 | };\ |
||
2266 | function canvas_remove(x,y){\ |
||
2267 | var marge = 4*line_width;\ |
||
2268 | var tmpx = [];\ |
||
2269 | var tmpy = [];\ |
||
2270 | for(var i = 0 ; i < path_cnt; i++){\ |
||
2271 | tmpx = userdraw_x[i];\ |
||
2272 | if(tmpx != null){\ |
||
2273 | tmpy = userdraw_y[i];\ |
||
2274 | for(var p = 0;p<tmpx.length;p++){\ |
||
2275 | if( x + marge > tmpx[p] && x - marge < tmpx[p] ){\ |
||
2276 | if( y + marge > tmpy[p] && y - marge < tmpy[p] ){\ |
||
2277 | if(confirm(\"Remove this drawing ?\")){\ |
||
2278 | userdraw_x[i] = null;\ |
||
2279 | userdraw_y[i] = null;\ |
||
2280 | xy_cnt = 0;click_cnt = 0;\ |
||
2281 | return;\ |
||
2282 | };\ |
||
2283 | };\ |
||
2284 | };\ |
||
2285 | };\ |
||
2286 | };\ |
||
2287 | };\ |
||
14044 | schaersvoo | 2288 | };",draw_type,use_snap,num,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype0,dashtype1); |
7614 | schaersvoo | 2289 | } |
11854 | schaersvoo | 2290 | void add_js_load_image(FILE *js_include_file,int canvas_root_id){ |
14038 | schaersvoo | 2291 | fprintf(js_include_file,"\n/* begin get_image_from_url */\n\ |
11854 | schaersvoo | 2292 | var image_cnt = 0;\ |
2293 | if( typeof(image_patterns) !== 'object'){var image_patterns = [];};\ |
||
2294 | var get_image_from_url = function(url){\ |
||
2295 | var idx = Math.ceil(1000*(Math.random()));\ |
||
2296 | var canvas = create_canvas%d(idx,xsize,ysize);\ |
||
2297 | canvas.style.visibility = 'hidden';\ |
||
2298 | var ctx = canvas.getContext(\"2d\");\ |
||
2299 | var img = new Image();\ |
||
2300 | img.src = url;\ |
||
2301 | img.onload = function(){\ |
||
2302 | var pat = ctx.createPattern(img,\"repeat\");\ |
||
2303 | image_patterns.push(pat);\ |
||
2304 | };\ |
||
2305 | };",canvas_root_id);} |
||
14038 | schaersvoo | 2306 | |
2307 | |||
2308 | /* almost the same as multidraw images !! */ |
||
2309 | void add_js_images(FILE *js_include_file,int canvas_root_id,int use_offset,int snap){ |
||
14270 | schaersvoo | 2310 | fprintf(js_include_file,"var current_id = null;var external_div_cnt=0;\ |
2311 | function image_adjust(image,x,y){\ |
||
2312 | var centered = %d;\ |
||
2313 | var w = parseInt(image.width);var h = parseInt(image.height);\ |
||
2314 | switch(centered){\ |
||
2315 | case 0: return [x,y];break;\ |
||
2316 | case 1: return [x,parseInt(y-0.5*h)];break;\ |
||
2317 | case 2: return [parseInt(x+0.5*h),y];break;\ |
||
2318 | case 3: return [parseInt(x+0.5*h),parseInt(y-0.5*h)];break;\ |
||
2319 | case 4: return [parseInt(x-0.5*w),parseInt(y-0.5*h)];break;\ |
||
2320 | default: return [x,y];break;\ |
||
2321 | };\ |
||
14038 | schaersvoo | 2322 | };\ |
14270 | schaersvoo | 2323 | place_image_on_canvas = function(id){\ |
2324 | var thing = document.getElementById(id);\ |
||
2325 | var tag = thing.tagName;\ |
||
2326 | if(tag == 'SVG'){draw_mathml_svg(thing,id);return;};\ |
||
14295 | schaersvoo | 2327 | if(tag == 'DIV'|| tag == 'SPAN' || tag == 'P'){draw_mathml_div(thing,id);return;};\ |
14270 | schaersvoo | 2328 | var src = thing.src;\ |
2329 | var image = new Image();\ |
||
2330 | image.src = src;\ |
||
2331 | image.id = 'placed_'+id;\ |
||
14296 | schaersvoo | 2332 | image.width = thing.width;\ |
2333 | image.height = thing.height;\ |
||
2334 | image.onload = function(){\ |
||
2335 | current_id = id;\ |
||
2336 | };\ |
||
14270 | schaersvoo | 2337 | return;\ |
2338 | };\ |
||
2339 | function draw_mathml_div(thing,id){\ |
||
2340 | var fix_div = document.createElement('DIV');\ |
||
2341 | var new_id='placed_'+external_div_cnt+'_'+id;\ |
||
2342 | fix_div.setAttribute('id',new_id);\ |
||
14295 | schaersvoo | 2343 | var w = parseInt(thing.clientWidth);\ |
2344 | var h = parseInt(thing.clientHeight);\ |
||
14270 | schaersvoo | 2345 | fix_div.innerHTML = thing.innerHTML;\ |
14295 | schaersvoo | 2346 | fix_div.setAttribute('style','display:none;position;absolute;width:'+w+'px;height:'+h+'px');\ |
2347 | fix_div.width = w;fix_div.height = h;\ |
||
14270 | schaersvoo | 2348 | canvas_div.appendChild(fix_div);\ |
2349 | current_id = new_id;\ |
||
2350 | external_div_cnt++;\ |
||
2351 | return;\ |
||
2352 | };\ |
||
2353 | function draw_mathml_svg(thing,id){\ |
||
2354 | var fix_div = document.createElement('DIV');\ |
||
2355 | fix_div.setAttribute('style','display:none;position;relative');\ |
||
2356 | canvas_div.appendChild(fix_div);\ |
||
2357 | var image = new Image();\ |
||
2358 | var svg_string = new XMLSerializer().serializeToString(thing);\ |
||
2359 | var dom = self.URL || self.webkitURL || self;\ |
||
2360 | var svg = new Blob([svg_string], {type: \"image/svg+xml;charset=utf-8\"});\ |
||
2361 | var url = dom.createObjectURL(svg);\ |
||
2362 | image.src= url;\ |
||
2363 | image.id = 'placed_'+id;\ |
||
2364 | image.onload = function(){\ |
||
2365 | current_id = image.id;\ |
||
2366 | fix_div.innerHTML='<img src='+image.src+' id='+image.id+' alt=\"this should not happen today...!\"/>';\ |
||
2367 | };\ |
||
2368 | return;\ |
||
2369 | };\ |
||
14296 | schaersvoo | 2370 | function remove_me(evt){\ |
2371 | var mouse = dragstuff.getMouse(evt,canvas_userdraw);\ |
||
2372 | var x = mouse.x;var y = mouse.y;var x1;var y1;\ |
||
2373 | var marge = 25;\ |
||
2374 | for(var p = 0 ; p < userdraw_x.length; p++){\ |
||
2375 | x1 = userdraw_x[p];y1 = userdraw_y[p];\ |
||
2376 | if( x > x1-marge && x < x1+marge ){\ |
||
2377 | if( y > y1-marge && y < y1+marge ){\ |
||
2378 | try{document.getElementById(userdraw_radius[p]).innerHTML = null;}catch(e){console.log(e);};\ |
||
2379 | userdraw_x.splice(p,1);userdraw_y.splice(p,1);userdraw_radius.splice(p,1);\ |
||
2380 | draw_images();\ |
||
2381 | };\ |
||
2382 | };\ |
||
2383 | };\ |
||
2384 | };\ |
||
2385 | function user_draw(evt){\ |
||
14949 | obado | 2386 | if( evt.button == 2 ){ remove_me(evt);return;};\ |
2387 | if( evt.button != 0 ){ return; };\ |
||
14270 | schaersvoo | 2388 | if(current_id != null){\ |
2389 | var centered = %d;\ |
||
2390 | var snap = %d;\ |
||
14296 | schaersvoo | 2391 | var mouse = dragstuff.getMouse(evt,canvas_userdraw);\ |
2392 | var img = document.getElementById(current_id);\ |
||
14270 | schaersvoo | 2393 | var xy = multisnap_check(mouse.x,mouse.y,snap);\ |
2394 | userdraw_x.push(xy[0]);userdraw_y.push(xy[1]);userdraw_radius.push(current_id);\ |
||
14296 | schaersvoo | 2395 | draw_images();\ |
2396 | };\ |
||
2397 | return;\ |
||
14270 | schaersvoo | 2398 | };\ |
2399 | function user_drag(evt){return;};\ |
||
2400 | function draw_images(){\ |
||
2401 | current_id = null;\ |
||
2402 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
||
2403 | var xy;var img;var tag;\ |
||
2404 | for(var p = 0 ; p < userdraw_x.length; p++){\ |
||
2405 | if( userdraw_radius[p] ){\ |
||
2406 | img = document.getElementById(userdraw_radius[p]);\ |
||
2407 | tag = img.tagName;\ |
||
2408 | xy = image_adjust(img,userdraw_x[p],userdraw_y[p]);\ |
||
14295 | schaersvoo | 2409 | if( tag != 'IMG' ){\ |
2410 | img.setAttribute('style','display:inline-block;position:absolute;top:'+xy[1]+'px;left:'+xy[0]+'px;');\ |
||
14270 | schaersvoo | 2411 | }else{\ |
14296 | schaersvoo | 2412 | context_userdraw.drawImage(img,xy[0],xy[1],img.width,img.height);\ |
14270 | schaersvoo | 2413 | };\ |
2414 | };\ |
||
2415 | };\ |
||
14296 | schaersvoo | 2416 | return;\ |
14270 | schaersvoo | 2417 | };",use_offset,use_offset,snap); |
14038 | schaersvoo | 2418 | } |
14948 | obado | 2419 | |
9329 | schaersvoo | 2420 | void add_js_popup(int canvas_root_id,int xsize,int ysize,char *getfile_cmd){ |
14094 | schaersvoo | 2421 | fprintf(stdout,"\n<!-- begin command popup %d -->\n\ |
9329 | schaersvoo | 2422 | <script type=\"text/javascript\">\n\ |
14038 | schaersvoo | 2423 | if( wims_status != 'done'){\ |
2424 | var popup = window.open('','','toolbar=no,scrollbars=yes,menubar=no,location=no,resizable=yes,top=4,left=4,status=no, width = %dpx, height = %dpx');\ |
||
2425 | var popupHTML =\"<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'>\\n<html><head></head>\\n<body><div style='width:%dpx;height:%dpx;position:relative' id='canvas_div%d'></div><div id='tooltip_placeholder_div%d' style='display:block;position:relative;margin-left:auto;margin-right:auto;margin-bottom:4px;'><span id='tooltip_placeholder%d' style='display:none;'></span></div></body></html>\";\ |
||
2426 | popup.document.write(popupHTML);\ |
||
2427 | var s0 = popup.document.createElement(\"script\");\ |
||
2428 | s0.text=\"var wims_status = window.opener.wims_status; var use_dragdrop_reply = window.opener.use_dragdrop_reply;window.opener.canvas_scripts.push('%d');\";\ |
||
2429 | popup.document.getElementsByTagName(\"HEAD\")[0].appendChild(s0);\ |
||
2430 | var s1 = popup.document.createElement(\"script\");\ |
||
2431 | s1.type = \"text/javascript\";\ |
||
2432 | s1.src = \"%s\";\ |
||
2433 | popup.document.getElementsByTagName(\"HEAD\")[0].appendChild(s1);\ |
||
2434 | popup.document.close();\ |
||
2435 | }else{\ |
||
2436 | var canvas_div = document.getElementById('canvas_div%d');\ |
||
2437 | canvas_div.style.display='block';\ |
||
2438 | };\ |
||
9331 | schaersvoo | 2439 | \n</script>\n\ |
14095 | schaersvoo | 2440 | <!-- end command popup %d -->\n", |
9329 | schaersvoo | 2441 | canvas_root_id, |
9333 | schaersvoo | 2442 | xsize+40,ysize+40, |
9329 | schaersvoo | 2443 | xsize,ysize, |
2444 | canvas_root_id, |
||
2445 | canvas_root_id, |
||
2446 | canvas_root_id, |
||
2447 | canvas_root_id, |
||
2448 | getfile_cmd, |
||
9331 | schaersvoo | 2449 | canvas_root_id, |
9329 | schaersvoo | 2450 | canvas_root_id); |
2451 | } |
||
2452 | |||
7614 | schaersvoo | 2453 | void add_js_tooltip(int canvas_root_id,char *tooltip_text,char *bgcolor,int xsize,int ysize){ |
14062 | schaersvoo | 2454 | fprintf(stdout,"\n<!-- begin command intooltip %d -->\n\ |
7614 | schaersvoo | 2455 | <script type=\"text/javascript\">\n\ |
2456 | var xsize = %d;\ |
||
2457 | var ysize = %d;\ |
||
2458 | var tooltip%d_obj_x = 0;\ |
||
2459 | var tooltip%d_obj_y = 0;\ |
||
2460 | var tooltip%d_flipflop = 0;\ |
||
2461 | var tooltip%d_obj = document.getElementById(\"canvas_div%d\");\ |
||
2462 | tooltip%d_obj.style.display=\"none\";\ |
||
2463 | tooltip%d_obj.style.position=\"absolute\";\ |
||
2464 | var tooltip%d_link = document.createElement(\"a\");\ |
||
2465 | tooltip%d_link.addEventListener(\"mousemove\",tooltip%d_drag,false);\ |
||
2466 | tooltip%d_link.setAttribute(\"onclick\",\"tooltip%d_show()\");\ |
||
2467 | tooltip%d_link.innerHTML = \"%s\";\ |
||
2468 | var tooltip_placeholder = document.getElementById(\"tooltip_placeholder%d\");\ |
||
2469 | tooltip_placeholder.style.display=\"block\";\ |
||
2470 | tooltip_placeholder.style.position=\"absolute\";\ |
||
2471 | tooltip_placeholder.style.backgroundColor=\"%s\";\ |
||
2472 | tooltip_placeholder.appendChild(tooltip%d_link);\ |
||
2473 | function tooltip%d_drag(action){\ |
||
14038 | schaersvoo | 2474 | if(!action){ action = event; };\ |
7614 | schaersvoo | 2475 | if(action.clientX){\ |
2476 | tooltip%d_obj.style.left = (tooltip%d_mouseX(action) + 10) +\"px\";\ |
||
2477 | var ytop = tooltip%d_mouseY(action);\ |
||
2478 | if(ytop + ysize < window.innerHeight){\ |
||
2479 | tooltip%d_obj.style.top = (ytop - 10) +\"px\";\ |
||
2480 | }\ |
||
2481 | else\ |
||
2482 | {\ |
||
2483 | tooltip%d_obj.style.top = parseInt(ytop - 0.8*ysize) +\"px\";\ |
||
14038 | schaersvoo | 2484 | };\ |
7614 | schaersvoo | 2485 | }\ |
2486 | else\ |
||
2487 | {\ |
||
2488 | return null;\ |
||
14038 | schaersvoo | 2489 | };\ |
2490 | };\ |
||
7614 | schaersvoo | 2491 | function tooltip%d_mouseX(action){\ |
2492 | if(action.pageX){\ |
||
2493 | return action.pageX;\ |
||
2494 | }\ |
||
2495 | else\ |
||
2496 | {\ |
||
2497 | if(action.clientX){\ |
||
2498 | return action.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);\ |
||
2499 | }\ |
||
2500 | else\ |
||
2501 | {\ |
||
2502 | return null;\ |
||
14038 | schaersvoo | 2503 | };\ |
2504 | };\ |
||
2505 | };\ |
||
7614 | schaersvoo | 2506 | function tooltip%d_mouseY(action){\ |
2507 | if(action.pageY){\ |
||
2508 | return action.pageY;\ |
||
2509 | }\ |
||
2510 | else\ |
||
2511 | {\ |
||
2512 | if(action.clientY){\ |
||
2513 | return action.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop :document.body.scrollTop);\ |
||
2514 | }\ |
||
2515 | else\ |
||
2516 | {\ |
||
2517 | return null;\ |
||
14038 | schaersvoo | 2518 | };\ |
2519 | };\ |
||
2520 | };\ |
||
7614 | schaersvoo | 2521 | function tooltip%d_show(){\ |
2522 | if(tooltip%d_flipflop == 0){\ |
||
2523 | tooltip%d_obj.style.display = \"block\";\ |
||
2524 | tooltip%d_flipflop = 1;\ |
||
2525 | }\ |
||
2526 | else\ |
||
2527 | {\ |
||
2528 | tooltip%d_flipflop = 0;\ |
||
2529 | tooltip%d_obj.style.display = \"none\";\ |
||
14038 | schaersvoo | 2530 | };\ |
14090 | schaersvoo | 2531 | };\n</script>\n<!-- end command intooltip %d -->\n",canvas_root_id,xsize,ysize,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,tooltip_text,canvas_root_id,bgcolor,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 2532 | |
8224 | bpr | 2533 | } |
14044 | schaersvoo | 2534 | void add_js_arc(FILE *js_include_file,int canvas_root_id,int num,int line_width,char *stroke_color,double stroke_opacity,char *fill_color,double fill_opacity,int use_dashed,int dashtype0,int dashtype1,int use_filled,int use_snap){ |
14038 | schaersvoo | 2535 | fprintf(js_include_file,"\n/* begin userdraw \"arc\" on final canvas */\n\ |
8270 | schaersvoo | 2536 | var canvas_rect;\ |
14044 | schaersvoo | 2537 | var use_filled = %d;\ |
8071 | schaersvoo | 2538 | function user_draw(evt){\ |
14044 | schaersvoo | 2539 | var use_snap = %d;\ |
8099 | schaersvoo | 2540 | var num = %d;\ |
2541 | var x,xc,x1,x2,y,yc,y1,y2;var lu = userdraw_x.length;\ |
||
2542 | if( num == 1 && lu == 3 ){ userdraw_x = [];userdraw_y = [];userdraw_radius = [];};\ |
||
14949 | obado | 2543 | if(evt.button == 0 || typeof(evt.identifier) != 'undefined' ){\ |
11002 | schaersvoo | 2544 | var mouse = dragstuff.getMouse(evt,canvas_userdraw);\ |
14044 | schaersvoo | 2545 | var xy = multisnap_check(mouse.x,mouse.y,use_snap);\ |
8099 | schaersvoo | 2546 | if(num == 1 && lu == 3){userdraw_x = [];userdraw_y = [];userdraw_radius = [];};\ |
14044 | schaersvoo | 2547 | lu = userdraw_x.push(xy[0]);userdraw_y.push(xy[1]);\ |
8071 | schaersvoo | 2548 | if( lu != 0 && lu%%3 == 0){\ |
2549 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
||
8083 | schaersvoo | 2550 | userdraw_radius = [];\ |
8071 | schaersvoo | 2551 | for(var p = 0 ; p < lu; p = p + 3){\ |
2552 | xc = userdraw_x[p];\ |
||
2553 | yc = userdraw_y[p];\ |
||
2554 | x1 = userdraw_x[p+1];\ |
||
2555 | x2 = userdraw_x[p+2];\ |
||
2556 | y1 = userdraw_y[p+1];\ |
||
2557 | y2 = userdraw_y[p+2];\ |
||
14044 | schaersvoo | 2558 | draw_userarc(context_userdraw,xc,yc,x1,y1,x2,y2,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,use_filled);\ |
8071 | schaersvoo | 2559 | };\ |
2560 | };\ |
||
2561 | }\ |
||
2562 | else\ |
||
2563 | {\ |
||
2564 | if( confirm(\"remove drawing ?\") ){\ |
||
8083 | schaersvoo | 2565 | context_userdraw.clearRect(0,0,xsize,ysize);userdraw_x = [];userdraw_y = [];userdraw_radius = [];return;\ |
8071 | schaersvoo | 2566 | };\ |
2567 | };\ |
||
2568 | };\ |
||
8097 | schaersvoo | 2569 | function user_drag(evt){ \ |
8099 | schaersvoo | 2570 | var lu = userdraw_x.length;\ |
2571 | if( (lu+1)%%3 == 0) {\ |
||
11002 | schaersvoo | 2572 | var mouse = dragstuff.getMouse(evt,canvas_userdraw);\ |
2573 | var x2 = mouse.x;\ |
||
2574 | var y2 = mouse.y;\ |
||
8099 | schaersvoo | 2575 | var xc = userdraw_x[lu-2];\ |
2576 | var yc = userdraw_y[lu-2];\ |
||
2577 | var x1 = userdraw_x[lu-1];\ |
||
2578 | var y1 = userdraw_y[lu-1];\ |
||
2579 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
||
14044 | schaersvoo | 2580 | draw_userarc(context_userdraw,xc,yc,x1,y1,x2,y2,1,\"255,0,0\",0.6,\"255,255,0\",0.4,0,2,2,use_filled);\ |
8099 | schaersvoo | 2581 | };\ |
8097 | schaersvoo | 2582 | return;\ |
2583 | };\ |
||
14044 | schaersvoo | 2584 | var draw_userarc = function(ctx,xc,yc,x1,y1,x2,y2,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_dashed,dashtype0,dashtype1,use_filled){\ |
8098 | schaersvoo | 2585 | ctx.save();\ |
2586 | if( use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{if(ctx.mozDash){ ctx.mozDash = [dashtype0,dashtype1];};};};\ |
||
2587 | ctx.lineWidth = line_width;\ |
||
2588 | ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
2589 | ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\ |
||
11017 | schaersvoo | 2590 | var alpha = find_angle(xc,yc,x2,y2);\ |
8083 | schaersvoo | 2591 | if( %d == 1 ){userdraw_radius[0] = alpha;ctx.clearRect(0,0,xsize,ysize);}else{userdraw_radius.push(alpha);};\ |
8098 | schaersvoo | 2592 | var r = Math.sqrt(Math.pow(xc-x2,2)+Math.pow(yc-y2,2));\ |
11017 | schaersvoo | 2593 | var start = find_angle(xc,yc,x1,y1);\ |
8098 | schaersvoo | 2594 | ctx.translate(xc,yc);\ |
2595 | ctx.rotate(start);\ |
||
2596 | ctx.beginPath();\ |
||
2597 | ctx.arc(0,0,r,0,alpha,false);\ |
||
2598 | ctx.lineTo(0,0);\ |
||
2599 | ctx.closePath();\ |
||
14044 | schaersvoo | 2600 | if(use_filled == 1){ ctx.fill();};\ |
8098 | schaersvoo | 2601 | ctx.stroke();\ |
2602 | ctx.restore();\ |
||
14044 | schaersvoo | 2603 | };",use_filled,use_snap,num,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_dashed,dashtype0,dashtype1,num); |
8071 | schaersvoo | 2604 | } |
7614 | schaersvoo | 2605 | |
14044 | schaersvoo | 2606 | void add_js_text(FILE *js_include_file,int canvas_root_id,int font_size,char *font_family,char *font_color,double stroke_opacity,int use_snap){ |
14038 | schaersvoo | 2607 | fprintf(js_include_file,"\n/* begin command userdraw text */\n\ |
11080 | schaersvoo | 2608 | canvas_div.addEventListener(\"keydown\",function(e){ e.preventDefault();user_text(e);},false);\ |
2609 | context_userdraw = canvas_userdraw.getContext(\"2d\");\ |
||
14044 | schaersvoo | 2610 | var use_snap = %d;\ |
7614 | schaersvoo | 2611 | var font_color = \"%s\";\ |
2612 | var font_opacity = %f;\ |
||
11080 | schaersvoo | 2613 | var mask_opacity = 0.5*font_opacity;\ |
7614 | schaersvoo | 2614 | var font_size = %d;\ |
2615 | var font_family = \"%s\";\ |
||
2616 | context_userdraw.fillStyle = \"rgba(\"+font_color+\",\"+font_opacity+\")\";\ |
||
2617 | context_userdraw.font = font_family;\ |
||
11080 | schaersvoo | 2618 | context_userdraw.save();\ |
11084 | schaersvoo | 2619 | var tmp_font_size = parseInt(context_userdraw.measureText(\"m\").width);\ |
2620 | if( font_size > tmp_font_size ){context_userdraw.font = font_size+\"px Ariel\";};\ |
||
7614 | schaersvoo | 2621 | var userdraw_text = new Array();\ |
11080 | schaersvoo | 2622 | var temp_userdraw_txt=\"\";\ |
7614 | schaersvoo | 2623 | var x_txt = 0;\ |
2624 | var y_txt = 0;\ |
||
2625 | function user_draw(evt){\ |
||
11002 | schaersvoo | 2626 | var mouse = dragstuff.getMouse(evt,canvas_userdraw);\ |
14044 | schaersvoo | 2627 | var xy = multisnap_check(mouse.x,mouse.y,use_snap);\ |
2628 | x_txt = xy[0];\ |
||
2629 | y_txt = xy[1];\ |
||
7614 | schaersvoo | 2630 | return;\ |
2631 | };\ |
||
11080 | schaersvoo | 2632 | function user_drag(evt){return;};\ |
2633 | function redraw_all_user_text(){\ |
||
2634 | var len = userdraw_x.length;\ |
||
2635 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
||
2636 | for(var p = 0 ; p < len ; p++){\ |
||
2637 | context_userdraw.fillText(userdraw_text[p],userdraw_x[p],userdraw_y[p]);\ |
||
2638 | };\ |
||
7614 | schaersvoo | 2639 | };\ |
2640 | function user_text(evt){\ |
||
11080 | schaersvoo | 2641 | var kc = evt.keyCode;\ |
7614 | schaersvoo | 2642 | if( kc== 8 || kc == 27 || kc == 46 ){\ |
11080 | schaersvoo | 2643 | var len = userdraw_x.length;\ |
2644 | for( var p=0 ; p < len ; p++){\ |
||
2645 | var tmp = userdraw_text[p];\ |
||
2646 | var w = context_userdraw.measureText(tmp).width;\ |
||
2647 | if( y_txt <= userdraw_y[p] && y_txt > userdraw_y[p] - font_size){\ |
||
2648 | if( x_txt < userdraw_x[p] + w && x_txt > userdraw_x[p] ){\ |
||
2649 | if (confirm(\"delete : \"+tmp+\"?\")){\ |
||
2650 | userdraw_text.splice(p,1);\ |
||
2651 | userdraw_x.splice(p,1);\ |
||
2652 | userdraw_y.splice(p,1);\ |
||
2653 | temp_userdraw_txt = \"\";\ |
||
2654 | redraw_all_user_text();\ |
||
2655 | return;\ |
||
7614 | schaersvoo | 2656 | };\ |
2657 | };\ |
||
2658 | };\ |
||
2659 | };\ |
||
2660 | }\ |
||
2661 | else\ |
||
2662 | {\ |
||
2663 | if( kc < 126 && kc > 40 ){\ |
||
11080 | schaersvoo | 2664 | temp_userdraw_txt=temp_userdraw_txt+String.fromCharCode(kc);\ |
7614 | schaersvoo | 2665 | context_userdraw.save();\ |
11080 | schaersvoo | 2666 | context_userdraw.fillStyle = \"rgba(\"+font_color+\",\"+mask_opacity+\")\";\ |
2667 | context_userdraw.fillText(temp_userdraw_txt,x_txt,y_txt);\ |
||
7614 | schaersvoo | 2668 | context_userdraw.restore();\ |
2669 | }\ |
||
2670 | else\ |
||
2671 | {\ |
||
2672 | if(kc == 13 ){\ |
||
11080 | schaersvoo | 2673 | w = context_userdraw.measureText(temp_userdraw_txt).width;\ |
2674 | if(w < 1){ return;};\ |
||
2675 | userdraw_x.push(x_txt);\ |
||
2676 | userdraw_y.push(y_txt);\ |
||
2677 | userdraw_text.push(temp_userdraw_txt);\ |
||
2678 | redraw_all_user_text();\ |
||
2679 | temp_userdraw_txt=\"\";\ |
||
7614 | schaersvoo | 2680 | return;\ |
2681 | };\ |
||
2682 | };\ |
||
2683 | };\ |
||
14044 | schaersvoo | 2684 | };",use_snap,font_color,stroke_opacity,font_size,font_family); |
7614 | schaersvoo | 2685 | |
2686 | } |
||
2687 | |||
8224 | bpr | 2688 | /* |
7614 | schaersvoo | 2689 | |
7991 | schaersvoo | 2690 | type = 0 : x-values only [command mousex] |
2691 | type = 1 : y-values only [command mousey] |
||
2692 | type = 2 : (x:y) [command mouse] |
||
11017 | schaersvoo | 2693 | type = 3 : degree [command mouse_degree] |
2694 | type = 4 : radian |
||
2695 | type = 5 : radius |
||
11040 | schaersvoo | 2696 | |
2697 | var mouse = dragstuff.getMouse(evt,canvas_div);\ |
||
2698 | var x = evt.clientX - mouse_canvas_rect.left;\ |
||
2699 | var y = evt.clientY - mouse_canvas_rect.top;\ |
||
2700 | |||
7991 | schaersvoo | 2701 | */ |
2702 | void add_js_mouse(FILE *js_include_file,int canvas_cnt,int canvas_root_id,int precision,char *stroke_color,int font_size,double stroke_opacity,int type){ |
||
14038 | schaersvoo | 2703 | fprintf(js_include_file,"\n/* begin command mouse on mouse canvas */\n\ |
7614 | schaersvoo | 2704 | function use_mouse_coordinates(){\ |
11041 | schaersvoo | 2705 | var display_type = %d;\ |
11006 | schaersvoo | 2706 | var canvas_type = %d;\ |
2707 | var mouse_canvas = create_canvas%d(canvas_type,xsize,ysize);\ |
||
11005 | schaersvoo | 2708 | var mouse_context = mouse_canvas.getContext(\"2d\");\ |
14949 | obado | 2709 | mouse_canvas.addEventListener(\"mousemove\", show_coordinate%d,false);\ |
11005 | schaersvoo | 2710 | mouse_canvas.addEventListener(\"touchmove\", function(e){ e.preventDefault();show_coordinate%d(e.changedTouches[0]);},false);\ |
7614 | schaersvoo | 2711 | var prec = Math.log(%d)/(Math.log(10));\ |
2712 | function show_coordinate%d(evt){\ |
||
11040 | schaersvoo | 2713 | var mouse = dragstuff.getMouse(evt,mouse_canvas);\ |
11002 | schaersvoo | 2714 | var x = mouse.x;\ |
2715 | var y = mouse.y;\ |
||
11041 | schaersvoo | 2716 | var m_data = \"\";\ |
2717 | switch(display_type){\ |
||
7996 | schaersvoo | 2718 | case 0: m_data = \" \"+(px2x(x)).toFixed(prec)+\" \"+unit_x;break;\ |
2719 | case 1: m_data = \" \"+(px2y(y)).toFixed(prec)+\" \"+unit_y;break;\ |
||
7991 | schaersvoo | 2720 | case 2: m_data = \"(\"+(px2x(x)).toFixed(prec)+\":\"+(px2y(y)).toFixed(prec)+\")\";break;\ |
11017 | schaersvoo | 2721 | case 3: if(userdraw_radius[0]){ m_data = \" \"+( ( userdraw_radius[0])/(Math.PI/180) ).toFixed(prec)+\" \\u00B0 \";};break;\ |
2722 | case 4: if(userdraw_radius[0]){ m_data = \" \"+(userdraw_radius[0]).toFixed(prec)+\" rad \";};break;\ |
||
12000 | schaersvoo | 2723 | case 5: if( userdraw_x.length > 0 ){var L = userdraw_x.length;m_data = \" R = \"+((xmax - xmin)*(distance(x,y,userdraw_x[L-1],userdraw_y[L-1]))/xsize).toFixed(prec)+\" \"+unit_x;};break;\ |
7991 | schaersvoo | 2724 | default:break;\ |
2725 | };\ |
||
7614 | schaersvoo | 2726 | var s = parseInt(0.8*%d*(m_data.toString()).length);\ |
11005 | schaersvoo | 2727 | mouse_context.font = \"%dpx Ariel\";\ |
2728 | mouse_context.fillStyle = \"rgba(%s,%f)\";\ |
||
2729 | mouse_context.clearRect(0,0,s,1.2*%d);\ |
||
2730 | mouse_context.fillText(m_data,0,%d);\ |
||
7614 | schaersvoo | 2731 | };\ |
11006 | schaersvoo | 2732 | };",type,MOUSE_CANVAS,canvas_root_id,canvas_root_id,canvas_root_id,precision,canvas_root_id,font_size,font_size,stroke_color,stroke_opacity,font_size,font_size); |
7856 | schaersvoo | 2733 | } |
7956 | schaersvoo | 2734 | /* to avoid easy js-code injection...but is it a real problem ? */ |
7856 | schaersvoo | 2735 | void add_safe_eval(FILE *js_include_file){ |
2736 | fprintf(js_include_file," \nfunction safe_eval(exp){\ |
||
9213 | schaersvoo | 2737 | exp = exp.replace(/pi/g,'3.14159');\ |
7856 | schaersvoo | 2738 | if(exp.indexOf('^') != -1){\ |
7956 | schaersvoo | 2739 | exp = exp.replace(/[a-zA-Z]/g,' ');\ |
2740 | exp = exp.replace(/\\*10\\^-/g,'e-');\ |
||
2741 | exp = exp.replace(/\\*10\\^/g,'e+');\ |
||
2742 | exp = exp.replace(/10\\^-/g,'1e-');exp = exp.replace(/10\\^/g,'1e+');\ |
||
2743 | exp = eval(exp);\ |
||
2744 | if(isNaN(exp)){alert(\"invalid input\\ntry just a real number \\ne.g. no calculations...\");return null;}\ |
||
2745 | return exp;\ |
||
7856 | schaersvoo | 2746 | };\ |
2747 | var reg = /(?:[a-z$_][a-z0-9$_]*)|(?:[;={}\\[\\]\"'!&<>^\\\\?:])/ig;\ |
||
2748 | var valid = true;\ |
||
2749 | exp = exp.replace(reg,function($0){\ |
||
2750 | if(Math.hasOwnProperty($0)){\ |
||
2751 | return \"Math.\"+$0;\ |
||
2752 | }\ |
||
2753 | else\ |
||
2754 | {\ |
||
2755 | valid = false;\ |
||
2756 | }\ |
||
2757 | }\ |
||
2758 | );\ |
||
2759 | if( !valid ){\ |
||
2760 | alert(\"hmmm \"+exp+\" ?\"); exp = null;\ |
||
2761 | }\ |
||
2762 | else\ |
||
2763 | {\ |
||
2764 | try{ exp = eval(exp); } catch(e){alert(\"Invalid arithmetic expression\"); exp = null;};\ |
||
2765 | };\ |
||
2766 | return exp;\ |
||
2767 | };"); |
||
2768 | } |
||
8112 | schaersvoo | 2769 | |
8224 | bpr | 2770 | /* |
14208 | schaersvoo | 2771 | Math.sin: angle in radians |
2772 | x1 = x*cos(a) - y*sin(a) |
||
2773 | y1 = y*cos(a) + x*sin(a) |
||
2774 | show_display = 0 nothing |
||
2775 | show_display = 1 delta X |
||
2776 | show_display = 2 delta Y |
||
2777 | show_display = 3 delta R radians |
||
2778 | show_display = 4 delta degrees |
||
2779 | show_display = 5 delta X:Y |
||
10952 | schaersvoo | 2780 | |
8112 | schaersvoo | 2781 | */ |
2782 | void add_slider_display(FILE *js_include_file,int canvas_root_id,int precision,int font_size,char *font_color,double stroke_opacity){ |
||
14038 | schaersvoo | 2783 | fprintf(js_include_file,"\n /* begin add_slider_display */ \n\ |
14208 | schaersvoo | 2784 | var slider_prec = Math.log(%d)/(Math.log(10));\ |
14038 | schaersvoo | 2785 | function show_slider_value(value,use_slider_display){\ |
8112 | schaersvoo | 2786 | var current_canvas = create_canvas%d(%d,xsize,ysize);\ |
2787 | var current_context = current_canvas.getContext(\"2d\");\ |
||
2788 | current_context.clearRect(0,0,xsize,ysize);\ |
||
2789 | var string;\ |
||
10952 | schaersvoo | 2790 | switch(use_slider_display){\ |
14208 | schaersvoo | 2791 | case 0: return;\ |
2792 | case 1: string = '\\u0394 x = '+value.toFixed(slider_prec)+' '+unit_x;break;\ |
||
2793 | case 2: string = '\\u0394 y = '+value.toFixed(slider_prec)+' '+unit_y;break;\ |
||
2794 | case 3: string = '\\u2221 = '+value.toFixed(slider_prec)+'\\u03C0 rad';break;\ |
||
2795 | case 4: string = '\\u2221 = '+(value*(180/Math.PI)).toFixed(slider_prec)+'\\u00B0';break;\ |
||
2796 | case 5: string = 'not implemented';break;\ |
||
2797 | default: string = '['+value+']';break;\ |
||
8112 | schaersvoo | 2798 | };\ |
2799 | var s = parseInt(1.2*%d*(string).length);\ |
||
14208 | schaersvoo | 2800 | current_context.font = '%dpx Ariel';\ |
2801 | current_context.strokeStyle = 'rgba(%s,%.2f)';\ |
||
8112 | schaersvoo | 2802 | current_context.clearRect(0,0,s,1.2*%d);\ |
14208 | schaersvoo | 2803 | current_context.fillText(string,0,%d);};",precision,canvas_root_id,MOUSE_CANVAS,font_size,font_size,font_color,stroke_opacity,font_size,font_size); |
8112 | schaersvoo | 2804 | } |
8071 | schaersvoo | 2805 | /* |
2806 | add slider |
||
14948 | obado | 2807 | P1 P2 Center |
14208 | schaersvoo | 2808 | |
2809 | min ----|-------------|-------------------- max (x/y/rad) |
||
2810 | |||
11002 | schaersvoo | 2811 | |
14208 | schaersvoo | 2812 | C: slider center (xcenter px) |
2813 | P1: x_px = P px |
||
2814 | P1: delta = d(PC) == C - P px == (C - P)/(width)*(max - min) in x/y/rad |
||
2815 | P1: delta = d(PC) == (xcenter - x_px)/width*(max - min); |
||
2816 | P2: increase P2-P1 |
||
2817 | P2: display C - P2 = d(CP2) == (xcenter - x_px)/width*(max - min); |
||
2818 | P2: displacement = P2 - P1 px |
||
8071 | schaersvoo | 2819 | */ |
14208 | schaersvoo | 2820 | void add_slider(FILE *js_include_file,int canvas_root_id){ |
2821 | fprintf(js_include_file,"\n/* begin add_slider */\n\ |
||
2822 | function array_uniq(array){\ |
||
2823 | var seen = {};\ |
||
2824 | var out = [];\ |
||
2825 | var len = array.length;\ |
||
2826 | var j = 0;\ |
||
2827 | for(var i = 0; i < len; i++){\ |
||
2828 | var item = array[i];\ |
||
2829 | if(seen[item] !== 1){\ |
||
2830 | seen[item] = 1;out[j++] = item;\ |
||
2831 | };\ |
||
2832 | };\ |
||
2833 | return out;\ |
||
2834 | };\ |
||
2835 | function contains(array, e){\ |
||
2836 | var len = array.length;\ |
||
2837 | for (var p = 0; p < len; p++){\ |
||
2838 | if (array[p] == e){\ |
||
2839 | return true;\ |
||
2840 | };\ |
||
2841 | };\ |
||
2842 | return false;\ |
||
2843 | };\ |
||
2844 | function translateX(obj,dx){\ |
||
2845 | var len = obj.x.length;\ |
||
2846 | for(var p=0;p<len;p++){\ |
||
2847 | obj.x[p]+=dx;\ |
||
2848 | };\ |
||
2849 | return obj;\ |
||
2850 | };\ |
||
2851 | function translateY(obj,dy){\ |
||
2852 | var len = obj.x.length;\ |
||
2853 | for(var p=0;p<len;p++){\ |
||
2854 | obj.y[p]-=dy;\ |
||
2855 | };\ |
||
2856 | return obj;\ |
||
2857 | };\ |
||
2858 | function rotateXY(obj,angle){\ |
||
2859 | if( typeof(angle) === 'undefined' ){console.log('rotateXY() angle undefined');return obj;};\ |
||
2860 | var len = obj.x.length;\ |
||
2861 | var cos = Math.cos(obj.angle-angle);\ |
||
2862 | var sin = Math.sin(obj.angle-angle);\ |
||
2863 | obj.angle = angle;\ |
||
2864 | var xc = obj.rotation_center[0];\ |
||
2865 | var yc = obj.rotation_center[1];\ |
||
2866 | var x,y;\ |
||
2867 | for(var p = 0 ; p < len ; p++ ){\ |
||
2868 | x = obj.x[p];\ |
||
2869 | y = obj.y[p];\ |
||
2870 | obj.x[p] = (cos * (x - xc)) + (sin * (y - yc)) + xc;\ |
||
2871 | obj.y[p] = (cos * (y - yc)) - (sin * (x - xc)) + yc ;\ |
||
2872 | };\ |
||
2873 | return obj;\ |
||
2874 | };\ |
||
2875 | function rotateARC(obj,angle){\ |
||
2876 | obj.h[0] = angle;\ |
||
2877 | obj.angle = -1*angle;\ |
||
2878 | return obj;\ |
||
2879 | };\ |
||
2880 | if( typeof(unit_x) === 'undefined' ){var unit_x = ' ';};\ |
||
2881 | if( typeof(unit_y) === 'undefined' ){var unit_y = ' ';};\ |
||
2882 | function slider(type,titletext,slider_id,width,height,linewidth,fillcolor,strokecolor,opacity,min,max,fun,fontfamily,show_display){\ |
||
8098 | schaersvoo | 2883 | if( wims_status == \"done\" ){return;};\ |
2884 | var tooltip_div = document.getElementById(\"tooltip_placeholder_div%d\");\ |
||
14208 | schaersvoo | 2885 | type = type || 'X';\ |
2886 | titletext = titletext || 'slider no.'+id;\ |
||
2887 | slider_id = slider_id || 0;\ |
||
2888 | width = width || xsize;\ |
||
2889 | height = height || parseInt(0.1*ysize);\ |
||
2890 | var xcenter = 0.5*width;\ |
||
2891 | var ycenter = 0.5*height;\ |
||
2892 | var previous_position = xcenter;\ |
||
2893 | var radius = 2*linewidth;\ |
||
2894 | opacity = opacity || [0.5,0.8];\ |
||
2895 | fillcolor = 'rgba('+fillcolor+','+opacity[0]+')' || 'rgba(200,200,0,0.2)';\ |
||
2896 | strokecolor = 'rgba('+strokecolor+','+opacity[1]+')' || 'rgba(0,0,0,0.8)';\ |
||
2897 | min = min || 0;\ |
||
2898 | max = max || 10;\ |
||
2899 | fun = fun || null;\ |
||
2900 | fontfamily = fontfamily || 'Italic 1.0em Courier';\ |
||
8098 | schaersvoo | 2901 | var span = document.createElement(\"span\");\ |
14208 | schaersvoo | 2902 | var button = document.createElement(\"a\");\ |
2903 | button.innerHTML = \"<span style='font-size:1.2em;color:red;'>⊗ </span>\";\ |
||
2904 | button.onclick = function(){dragstuff.slidergroup = [angle_object];reset_slider();};\ |
||
2905 | var style = 'font:'+fontfamily;\ |
||
2906 | span.setAttribute('style',style);\ |
||
2907 | var title = document.createTextNode(titletext);\ |
||
8098 | schaersvoo | 2908 | var br = document.createElement(\"br\");\ |
2909 | span.appendChild(title);\ |
||
2910 | span.appendChild(br);\ |
||
14208 | schaersvoo | 2911 | tooltip_div.appendChild(button);\ |
8098 | schaersvoo | 2912 | tooltip_div.appendChild(span);\ |
14208 | schaersvoo | 2913 | var slider_canvas = document.createElement('canvas');\ |
2914 | slider_canvas.id = 'canvas'+slider_id;\ |
||
8098 | schaersvoo | 2915 | tooltip_div.appendChild(slider_canvas);\ |
2916 | br = document.createElement(\"br\");\ |
||
2917 | tooltip_div.appendChild(br);\ |
||
14208 | schaersvoo | 2918 | var text_begin = 20;\ |
2919 | width = width+text_begin;\ |
||
2920 | slider_canvas.width = width;\ |
||
2921 | slider_canvas.height = height;\ |
||
8098 | schaersvoo | 2922 | var slider_ctx = slider_canvas.getContext(\"2d\");\ |
14208 | schaersvoo | 2923 | slider_ctx.font = fontfamily;\ |
2924 | slider_ctx.strokeStyle = strokecolor;\ |
||
2925 | slider_ctx.fillStyle = fillcolor;\ |
||
2926 | slider_ctx.lineWidth = linewidth;\ |
||
2927 | slider_ctx.save();\ |
||
8098 | schaersvoo | 2928 | slider_ctx.beginPath();\ |
14208 | schaersvoo | 2929 | slider_ctx.arc(xcenter,ycenter,radius,0,2*Math.PI,false);\ |
2930 | slider_ctx.rect(0,0,width,height);\ |
||
8098 | schaersvoo | 2931 | slider_ctx.closePath();\ |
2932 | slider_ctx.fill();\ |
||
2933 | slider_ctx.stroke();\ |
||
14949 | obado | 2934 | slider_canvas.addEventListener(\"mousedown\" , slider_on, false);\ |
2935 | slider_canvas.addEventListener(\"mouseup\" , slider_off, false);\ |
||
2936 | slider_canvas.addEventListener(\"mouseout\" , slider_off, false);\ |
||
2937 | slider_canvas.addEventListener(\"mousemove\" , slide_me, false);\ |
||
14208 | schaersvoo | 2938 | slider_canvas.addEventListener(\"touchmove\" , function(e){ e.preventDefault();slide_me(e.changedTouches[0]);},false);\ |
2939 | slider_canvas.addEventListener(\"touchstart\", function(e){ e.preventDefault();slider_on(e.changedTouches[0]);},false);\ |
||
14949 | obado | 2940 | slider_canvas.addEventListener(\"touchend\" , function(e){ e.preventDefault();slider_off(e.changedTouches[0]);},false);\ |
14208 | schaersvoo | 2941 | var slider_is_active = false;\ |
2942 | function slider_on(evt){\ |
||
2943 | slider_is_active = true;\ |
||
9244 | schaersvoo | 2944 | };\ |
14208 | schaersvoo | 2945 | function slider_off(evt){\ |
2946 | slider_is_active = false;\ |
||
9244 | schaersvoo | 2947 | };\ |
14208 | schaersvoo | 2948 | var my_slider_position;\ |
2949 | var scale_factor = (max - min)/(xmax - xmin);\ |
||
2950 | var display_factor = 1/width*(max - min);\ |
||
2951 | var angle_object = null;\ |
||
2952 | function reset_slider(){\ |
||
2953 | slider_ctx.beginPath();\ |
||
2954 | slider_ctx.arc(xcenter,ycenter,radius,0,2*Math.PI,false);\ |
||
2955 | slider_ctx.rect(0,0,width,height);\ |
||
2956 | slider_ctx.closePath();\ |
||
2957 | slider_ctx.fill();\ |
||
2958 | slider_ctx.stroke();\ |
||
2959 | slider_ctx.restore();\ |
||
2960 | previous_position = xcenter;\ |
||
2961 | };\ |
||
2962 | function slide_me(evt){\ |
||
2963 | if( ! slider_is_active ){return;};\ |
||
2964 | if( ! dragstuff.slidergroup){return;};\ |
||
2965 | var canvas_rect = slider_canvas.getBoundingClientRect();\ |
||
2966 | slider_ctx.clearRect(0,0,width,height);\ |
||
2967 | my_slider_position = parseInt(evt.clientX - canvas_rect.left);\ |
||
2968 | slider_ctx.beginPath();\ |
||
2969 | slider_ctx.arc(my_slider_position,ycenter,radius,0,2*Math.PI,false);\ |
||
2970 | slider_ctx.rect(0,0,width,height);\ |
||
2971 | slider_ctx.closePath();\ |
||
2972 | slider_ctx.fill();\ |
||
2973 | slider_ctx.stroke();\ |
||
2974 | slider_ctx.restore();\ |
||
2975 | var display_delta = (xcenter - my_slider_position)*display_factor;\ |
||
2976 | var delta = scale_factor*(my_slider_position - previous_position );\ |
||
2977 | previous_position = my_slider_position;\ |
||
2978 | if( show_display > 0 ){show_slider_value(display_delta,show_display);};\ |
||
2979 | dragstuff.slidergroup = array_uniq(dragstuff.slidergroup);\ |
||
2980 | var len = dragstuff.slidergroup.length;\ |
||
2981 | for(var i = 0;i<len;i++){\ |
||
2982 | var idx = dragstuff.slidergroup[i];\ |
||
2983 | if( idx > -1){\ |
||
2984 | var obj = dragstuff.shapes[idx];\ |
||
2985 | if( typeof(obj) === 'object' ){\ |
||
2986 | if(type == 'X' ){ obj = translateX(obj,delta);};\ |
||
2987 | if(type == 'Y' ){ obj = translateY(obj,delta);};\ |
||
2988 | if(type == 'R' ){ if(obj.type == 17 ){obj = rotateARC(obj,-1*display_delta);angle_object = idx;}else{obj = rotateXY(obj,display_delta);};};\ |
||
2989 | reply[obj.click_cnt] = obj;\ |
||
2990 | };\ |
||
2991 | };\ |
||
2992 | };\ |
||
2993 | dragstuff.valid = false;\ |
||
2994 | dragstuff.draw();\ |
||
2995 | return;\ |
||
2996 | };\ |
||
2997 | };\n",canvas_root_id); |
||
8071 | schaersvoo | 2998 | } |
7614 | schaersvoo | 2999 | |
14208 | schaersvoo | 3000 | /* |
8105 | schaersvoo | 3001 | |
14949 | obado | 3002 | if(evt.button == 0 || typeof(evt.identifier) != 'undefined'){dx=0;dy=Math.PI/4;};\ |
14208 | schaersvoo | 3003 | |
8097 | schaersvoo | 3004 | add xyslider |
8105 | schaersvoo | 3005 | return value is array : value[0] is the actual x-value between value_1 and value_2, value[1] is y-value between value_1 and value_2 |
8097 | schaersvoo | 3006 | */ |
14208 | schaersvoo | 3007 | void add_xyslider(FILE *js_include_file, int canvas_root_id,double v1,double v2,int width,int height,char *type,char *label,int slider_cnt,char *stroke_color,char *fill_color,int line_width,double opacity,char *font_family,char *font_color,int use_slider_display){ |
14038 | schaersvoo | 3008 | fprintf(js_include_file,"\n/* begin add_slider no. %d */\n\ |
8097 | schaersvoo | 3009 | function add_slider_%d(){\ |
8098 | schaersvoo | 3010 | if( wims_status == \"done\" ){return;};\ |
3011 | var tooltip_div = document.getElementById(\"tooltip_placeholder_div%d\");\ |
||
14208 | schaersvoo | 3012 | var slider_type = %s;\ |
8098 | schaersvoo | 3013 | var span = document.createElement(\"span\");\ |
11002 | schaersvoo | 3014 | span.setAttribute(\"style\",\"font:%s;color:%s\");\ |
8098 | schaersvoo | 3015 | var title = document.createTextNode(\" %s \");\ |
3016 | var br = document.createElement(\"br\");\ |
||
3017 | span.appendChild(title);\ |
||
3018 | span.appendChild(br);\ |
||
3019 | tooltip_div.appendChild(span);\ |
||
3020 | var slider_fillcolor = \"%s\";\ |
||
8106 | schaersvoo | 3021 | var slider_click = 0;\ |
8098 | schaersvoo | 3022 | var slider_strokecolor = \"%s\";\ |
3023 | var slider_linewidth = \"%d\";\ |
||
14208 | schaersvoo | 3024 | var this.canvas = document.createElement(\"canvas\");\ |
3025 | this.canvas.id = \"this.canvas%d\";\ |
||
3026 | tooltip_div.appendChild(this.canvas);\ |
||
8098 | schaersvoo | 3027 | br = document.createElement(\"br\");\ |
3028 | tooltip_div.appendChild(br);\ |
||
3029 | var slider_width = %d;\ |
||
3030 | var slider_height = %d;\ |
||
3031 | var slider_center = %d;\ |
||
3032 | var slider_radius = 4*slider_linewidth;\ |
||
3033 | var slider_opacity = %f;\ |
||
14208 | schaersvoo | 3034 | this.canvas.width = slider_width;\ |
3035 | this.canvas.height = slider_height;\ |
||
3036 | var slider_ctx = this.canvas.getContext(\"2d\");\ |
||
8098 | schaersvoo | 3037 | slider_ctx.font = \"%s\";\ |
3038 | slider_ctx.strokeStyle = \"rgba(\"+slider_strokecolor+\",\"+slider_opacity+\")\";\ |
||
3039 | slider_ctx.fillStyle = \"rgba(\"+slider_fillcolor+\",\"+slider_opacity+\")\";\ |
||
3040 | slider_ctx.lineWidth = slider_linewidth;\ |
||
3041 | slider_ctx.beginPath();\ |
||
3042 | slider_ctx.arc(10,slider_center,slider_radius,0,2*Math.PI,false);\ |
||
3043 | slider_ctx.fill();\ |
||
3044 | slider_ctx.closePath();\ |
||
3045 | slider_ctx.rect(0,0,slider_width,slider_height);\ |
||
3046 | slider_ctx.stroke();\ |
||
14949 | obado | 3047 | this.canvas.addEventListener(\"mousemove\", sliderdrag_%d,false);\ |
3048 | this.canvas.addEventListener(\"mousedown\", sliderclick_%d,false);\ |
||
3049 | this.canvas.addEventListener(\"touchmove\", function(e){ e.preventDefault();sliderdrag_%d(e.changedTouches[0]);},false);\ |
||
14208 | schaersvoo | 3050 | this.canvas.addEventListener(\"touchstart\", function(e){ e.preventDefault();sliderclick_%d(e.changedTouches[0]);},false);\ |
11094 | schaersvoo | 3051 | var canvas_rect = (slider_canvas).getBoundingClientRect();\ |
8106 | schaersvoo | 3052 | function sliderdrag_%d(evt){\ |
3053 | if(slider_click == 1){\ |
||
3054 | var value_1 = %f;\ |
||
3055 | var value_2 = %f;\ |
||
11094 | schaersvoo | 3056 | var canvas_rect = (slider_canvas).getBoundingClientRect();\ |
8106 | schaersvoo | 3057 | slider_ctx.clearRect(0,0,slider_width,slider_height);\ |
11094 | schaersvoo | 3058 | var x_px = evt.clientX - canvas_rect.left;\ |
3059 | var y_px = evt.clientY - canvas_rect.top;\ |
||
3060 | slider_ctx.clearRect(0,0,slider_width,slider_height);\ |
||
9213 | schaersvoo | 3061 | var x = x_px*(value_2 - value_1)/slider_width + value_1;\ |
3062 | var y = y_px*(value_2 - value_1)/slider_height + value_1;\ |
||
9244 | schaersvoo | 3063 | x = parseFloat(eval(slider_function%d.x));\ |
3064 | y = parseFloat(eval(slider_function%d.y));\ |
||
8106 | schaersvoo | 3065 | slider_ctx.beginPath();\ |
9213 | schaersvoo | 3066 | slider_ctx.arc(x_px,y_px,slider_radius,0,2*Math.PI,false);\ |
8106 | schaersvoo | 3067 | slider_ctx.fill();\ |
3068 | slider_ctx.rect(0,0,slider_width,slider_height);\ |
||
3069 | slider_ctx.closePath();\ |
||
3070 | slider_ctx.stroke();\ |
||
9213 | schaersvoo | 3071 | dragstuff.Slide( [x,y] , %d );\ |
3072 | if(%d != 0 ){show_slider_value([x,y],%d);}\ |
||
8098 | schaersvoo | 3073 | };\ |
3074 | };\ |
||
8106 | schaersvoo | 3075 | function sliderclick_%d(evt){\ |
3076 | if(slider_click == 1){slider_click = 0;}else{slider_click = 1;};\ |
||
3077 | };\ |
||
14038 | schaersvoo | 3078 | };add_slider_%d();",slider_cnt,slider_cnt,canvas_root_id,type,font_family,font_color,label,fill_color,stroke_color,line_width,canvas_root_id,width,height,(int)(0.5*height),opacity,font_family,slider_cnt,slider_cnt,slider_cnt,slider_cnt,slider_cnt,v1,v2,slider_cnt,slider_cnt,slider_cnt,use_slider_display,slider_cnt,slider_cnt,slider_cnt); |
8097 | schaersvoo | 3079 | } |
3080 | |||
3081 | |||
8224 | bpr | 3082 | /* |
7833 | schaersvoo | 3083 | adds inputfield for x-value: returns the js-calculated y-value after click on 'OK' button |
3084 | draws a non-configurable crosshair on this calculated location |
||
3085 | */ |
||
8815 | schaersvoo | 3086 | void add_calc_y(FILE *js_include_file,int canvas_root_id,char *jsmath,int font_size,char *input_style){ |
14038 | schaersvoo | 3087 | fprintf(js_include_file,"\n/* begin add_calc_y */\n\ |
7858 | schaersvoo | 3088 | use_jsmath=1;\ |
7856 | schaersvoo | 3089 | function add_calc_y(){\ |
11002 | schaersvoo | 3090 | if( wims_status == \"done\" ){return;};\ |
3091 | var fun = to_js_math(\"%s\");if(fun == null){return;};\ |
||
3092 | function eval_jsmath(x){return parseFloat(eval(fun));};\ |
||
3093 | var tooltip_div = document.getElementById(\"tooltip_placeholder_div%d\");\ |
||
3094 | var calc_div = document.createElement('div');\ |
||
3095 | calc_div.id = \"calc_div\";\ |
||
3096 | tooltip_div.appendChild(calc_div);\ |
||
3097 | var label_x = \"x\";var label_y = \"y\";\ |
||
11088 | schaersvoo | 3098 | if( typeof(xaxislabel) !== 'undefined' ){label_x = xaxislabel;}\ |
3099 | if( typeof(yaxislabel) !== 'undefined' ){label_y = yaxislabel;}\ |
||
11002 | schaersvoo | 3100 | calc_div.innerHTML=\"<br /><span style='font-style:italic;font-size:%dpx'>\"+label_x+\" : <input type='text' size='4' value='' id='calc_input_x' style='%s' /> \"+ label_y+\" : <input type='text' size='5' value='' id='calc_output_y' style='%s' readonly /><input id='calc_button' type='button' value='OK' onclick='' style='color:red;background-color:lightblue;' /></span> \";\ |
3101 | var calc_button = document.getElementById(\"calc_button\");\ |
||
14949 | obado | 3102 | calc_button.addEventListener(\"mousedown\", show_it,false);\ |
11002 | schaersvoo | 3103 | calc_button.addEventListener(\"touchstart\", function(e){ e.preventDefault();show_it(e.changedTouches[0]);},false);\ |
3104 | function show_it(){\ |
||
3105 | var x_value=document.getElementById(\"calc_input_x\").value;\ |
||
3106 | var y_value = eval_jsmath(x_value);\ |
||
3107 | document.getElementById(\"calc_output_y\").value = y_value;\ |
||
3108 | if(isNaN(y_value)){return;};\ |
||
3109 | var canvas = create_canvas%d(123,xsize,ysize);\ |
||
3110 | var ctx = canvas.getContext(\"2d\");\ |
||
3111 | draw_crosshairs(ctx,[x2px(x_value)],[y2px(y_value)],1,5,\"#000000\",1,0,0,0,[0,0]);return;\ |
||
3112 | };\ |
||
3113 | };\ |
||
3114 | ;add_calc_y();",jsmath,canvas_root_id,font_size,input_style,input_style,canvas_root_id); |
||
7833 | schaersvoo | 3115 | } |
3116 | /* |
||
3117 | x-value of the mouse will be used to calculate via javascript the corresponding y-value using the verbatim js-math function |
||
3118 | a configurable crosshair and vertical/horizontal crosshair lines will be drawn |
||
3119 | function is called "use_mouse_coordinates() and thus can not be combined with command 'mouse' |
||
3120 | */ |
||
8815 | schaersvoo | 3121 | void add_trace_js_mouse(FILE *js_include_file,int canvas_cnt,int canvas_root_id,char *stroke_color,char *jsmath,int font_size,double stroke_opacity,int line_width,int crosshair_size,char *input_style){ |
14038 | schaersvoo | 3122 | fprintf(js_include_file,"\n/* begin command add_trace_jsmath trace_canvas */\n\ |
7858 | schaersvoo | 3123 | use_jsmath=1;\ |
7839 | schaersvoo | 3124 | function use_trace_jsmath(){\ |
7956 | schaersvoo | 3125 | if( wims_status == \"done\" ){return;};\ |
7833 | schaersvoo | 3126 | var label_x = \"x\";var label_y = \"y\";\ |
11088 | schaersvoo | 3127 | if( typeof(xaxislabel) !== 'undefined' ){label_x = xaxislabel;}\ |
3128 | if( typeof(yaxislabel) !== 'undefined' ){label_y = yaxislabel;}\ |
||
7823 | schaersvoo | 3129 | var trace_canvas = create_canvas%d(%d,xsize,ysize);\ |
3130 | var trace_context = trace_canvas.getContext(\"2d\");\ |
||
7856 | schaersvoo | 3131 | var tooltip_div = document.getElementById(\"tooltip_placeholder_div%d\");\ |
7839 | schaersvoo | 3132 | var trace_div = document.createElement('div');\ |
3133 | trace_div.id = \"trace_div\";\ |
||
7856 | schaersvoo | 3134 | tooltip_div.appendChild(trace_div);\ |
9213 | schaersvoo | 3135 | trace_div.innerHTML = \"<br /><span style='font-style:italic;font-size:%dpx'>\"+label_x+\" : <input type='text' size='4' value='' id='trace_input_x' style='%s' />\"+label_y+\" : <input type='text' size='5' value='' id='trace_input_y' style='%s' readonly /></span> \";\ |
7858 | schaersvoo | 3136 | canvas_div.addEventListener(\"mousemove\",trace,false);\ |
11002 | schaersvoo | 3137 | canvas_div.addEventListener(\"touchmove\",function(e){ e.preventDefault();trace(e.changedTouches[0]);},false);\ |
7981 | schaersvoo | 3138 | var fun = to_js_math(\"%s\");if(fun == null){return;};\ |
7858 | schaersvoo | 3139 | function eval_jsmath(x){return parseFloat(eval(fun));};\ |
3140 | function trace(evt){\ |
||
11002 | schaersvoo | 3141 | var mouse = dragstuff.getMouse(evt,trace_canvas);\ |
3142 | var x_px = mouse.x;\ |
||
7834 | schaersvoo | 3143 | var x = px2x(x_px);\ |
7823 | schaersvoo | 3144 | var y = eval_jsmath(x);\ |
3145 | if(isNaN(y)){return;};\ |
||
7834 | schaersvoo | 3146 | var y_px = y2px(y);\ |
7823 | schaersvoo | 3147 | trace_context.clearRect(0,0,xsize,ysize);\ |
7834 | schaersvoo | 3148 | draw_crosshairs(trace_context,[x_px],[y_px],%d,%d,\"%s\",%f,0,0,0,[0,0]);\ |
7856 | schaersvoo | 3149 | document.getElementById(\"trace_input_x\").value = x;\ |
3150 | document.getElementById(\"trace_input_y\").value = y;\ |
||
7823 | schaersvoo | 3151 | };\ |
3152 | return;\ |
||
8815 | schaersvoo | 3153 | };use_trace_jsmath();",canvas_root_id,canvas_cnt,canvas_root_id,font_size,input_style,input_style,jsmath,line_width,crosshair_size,stroke_color,stroke_opacity); |
7823 | schaersvoo | 3154 | } |
7663 | schaersvoo | 3155 | |
8224 | bpr | 3156 | /* |
3157 | add a table with 2 textarea's labeled 'x' 'y' ( or 'xlabel' 'ylabel' if defined) |
||
7749 | schaersvoo | 3158 | add two buttons: OK and NOK (OK draws; NOK will delete last item pair from userdraw_x / userdraw_y array's |
3159 | */ |
||
8815 | schaersvoo | 3160 | void add_textarea_xy(FILE *js_include_file, int canvas_root_id, char *input_style){ |
14038 | schaersvoo | 3161 | fprintf(js_include_file,"\n/* begin add_textarea_xy */\n\ |
7856 | schaersvoo | 3162 | function add_textarea_xy(){\ |
7956 | schaersvoo | 3163 | if( wims_status == \"done\" ){return;};\ |
7856 | schaersvoo | 3164 | var tooltip_div = document.getElementById(\"tooltip_placeholder_div%d\");\ |
3165 | var textarea_div = document.createElement('div');\ |
||
3166 | textarea_div.id = \"textarea_div\";\ |
||
3167 | tooltip_div.appendChild(textarea_div);\ |
||
7663 | schaersvoo | 3168 | var label_x = \"x\";var label_y = \"y\";\ |
11088 | schaersvoo | 3169 | if( typeof(xaxislabel) !== 'undefined' ){label_x = xaxislabel;}\ |
3170 | if( typeof(yaxislabel) !== 'undefined' ){label_y = yaxislabel;}\ |
||
7856 | schaersvoo | 3171 | textarea_div.innerHTML=\"\ |
3172 | <table style=\'border:1px solid black;background-color:#ffffa0\' >\ |
||
3173 | <tr>\ |
||
3174 | <td><input id='textarea_ok_button' type='button' value='OK' onclick='' style='color:red;background-color:lightblue;'/></td>\ |
||
3175 | <td><input id='textarea_nok_button' type='button' value='NOK' onclick='' style='color:blue;background-color:red;'/></td>\ |
||
3176 | </tr>\ |
||
3177 | <tr>\ |
||
3178 | <td><em>\"+label_x+\"</em></td>\ |
||
3179 | <td><em>\"+label_y+\"</em></td>\ |
||
3180 | </tr>\ |
||
3181 | <tr>\ |
||
8815 | schaersvoo | 3182 | <td><textarea rows='5' cols='2' id='userinput_x' style='%s' ></textarea></td>\ |
3183 | <td><textarea rows='5' cols='2' id='userinput_y' style='%s' ></textarea></td>\ |
||
7856 | schaersvoo | 3184 | </tr>\ |
3185 | </table>\";\ |
||
3186 | var textarea_ok_button = document.getElementById(\"textarea_ok_button\");\ |
||
3187 | var textarea_nok_button = document.getElementById(\"textarea_nok_button\");\ |
||
3188 | textarea_ok_button.addEventListener(\"mousedown\",function(e){user_redraw(1);return;},false);\ |
||
3189 | textarea_nok_button.addEventListener(\"mousedown\",function(e){user_redraw(-1);return;},false);\ |
||
3190 | return;\ |
||
8815 | schaersvoo | 3191 | };add_textarea_xy();",canvas_root_id,input_style,input_style); |
7663 | schaersvoo | 3192 | } |
3193 | |||
7838 | schaersvoo | 3194 | /* |
7823 | schaersvoo | 3195 | |
7838 | schaersvoo | 3196 | */ |
8815 | schaersvoo | 3197 | void add_setlimits(FILE *js_include_file, int canvas_root_id,int font_size,char *input_style){ |
14038 | schaersvoo | 3198 | fprintf(js_include_file,"\n/* begin add_setlimits */\n\ |
8098 | schaersvoo | 3199 | use_pan_and_zoom = 1;\ |
7839 | schaersvoo | 3200 | function use_setlimits(){\ |
7956 | schaersvoo | 3201 | if( wims_status == \"done\" ){return;};\ |
7858 | schaersvoo | 3202 | var label_x = \"x\";var label_y = \"y\";\ |
11088 | schaersvoo | 3203 | if( typeof(xaxislabel) !== 'undefined' ){label_x = xaxislabel;}\ |
3204 | if( typeof(yaxislabel) !== 'undefined' ){label_y = yaxislabel;}\ |
||
7856 | schaersvoo | 3205 | var tooltip_div = document.getElementById(\"tooltip_placeholder_div%d\");\ |
7839 | schaersvoo | 3206 | var setlim_div = document.createElement('div');\ |
7856 | schaersvoo | 3207 | setlim_div.id = \"setlim_div\";\ |
3208 | tooltip_div.appendChild(setlim_div);\ |
||
8815 | schaersvoo | 3209 | setlim_div.innerHTML=\"<br /><span style='font-style:italic;font-size:%dpx'>\"+label_x+\"min = <input type='text' size='4' value='\"+xmin+\"' id='userinput_xmin' style='%s' /> \"+label_x+\"max = <input type='text' size='4' value='\"+xmax+\"' id='userinput_xmax' style='%s' /><br />\"+label_y+\"min = <input type='text' size='4' value='\"+ymin+\"' id='userinput_ymin' style='%s' /> \"+label_y+\"max = <input type='text' size='4' value='\"+ymax+\"' id='userinput_ymax' style='%s' /><br /><input id='set_limits' type='button' value='OK' onclick='' style='color:red;background-color:lightblue;' />\";\ |
7838 | schaersvoo | 3210 | var setlimit_button = document.getElementById(\"set_limits\");\ |
3211 | function set_limits(e){\ |
||
3212 | xmin = safe_eval(document.getElementById('userinput_xmin').value);\ |
||
3213 | xmax = safe_eval(document.getElementById('userinput_xmax').value);\ |
||
3214 | ymin = safe_eval(document.getElementById('userinput_ymin').value);\ |
||
3215 | ymax = safe_eval(document.getElementById('userinput_ymax').value);\ |
||
3216 | if(xmin > xmax || ymin > ymax){alert(\"your limits are not correct...\");return;}\ |
||
3217 | try{start_canvas%d(1234)}catch(e){};try{dragstuff.Zoom(xmin,xmax,ymin,ymax)}catch(e){};return;};\ |
||
7839 | schaersvoo | 3218 | setlimit_button.addEventListener(\"mousedown\",function(e){set_limits();},false);\ |
8815 | schaersvoo | 3219 | };use_setlimits();",canvas_root_id,font_size,input_style,input_style,input_style,input_style,canvas_root_id); |
7838 | schaersvoo | 3220 | } |
8193 | schaersvoo | 3221 | |
8297 | schaersvoo | 3222 | |
3223 | void add_rawmath(FILE *js_include_file){ |
||
14038 | schaersvoo | 3224 | fprintf(js_include_file,"\n/* begin add_rawmath() */\n\ |
8297 | schaersvoo | 3225 | function rawmath(i){\ |
3226 | i=i.toLowerCase();\ |
||
3227 | i=i.replace(/\\ /g,\"\");i=i.replace(/\\*\\*/g,\"^\");\ |
||
3228 | if(i.indexOf(\"e+\")!=-1){i=i.replace(\"e+\",\"*10^\");};\ |
||
3229 | if(i.indexOf(\"e-\")!=-1){i=i.replace(\"e-\",\"*10^-\");};\ |
||
3230 | i=i.replace(/\\*\\*/g,\"*\");\ |
||
3231 | if(i.charAt(0)==\"*\"){i=i.substring(1,i.length);};\ |
||
3232 | var fun=[\"asin\",\"acos\",\"atan\",\"sin\",\"cos\",\"tan\",\"log\",\"ln\",\"pi\",\"e\",\"x\",\"y\"];\ |
||
3233 | var cons=[\"pi\",\"e\",\"0\",\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\"];\ |
||
3234 | var cntl = 0;var cntr = 0;\ |
||
3235 | var len = i.length;\ |
||
3236 | for( var p = 0;p < len; p++){\ |
||
3237 | if(i.charAt(p) == '('){cntl++;}\ |
||
3238 | if(i.charAt(p) == ')'){cntr++;}\ |
||
3239 | };\ |
||
8299 | schaersvoo | 3240 | if(cntl != cntr){alert(\"unmatched parenthesis !!\");return null;};\ |
8297 | schaersvoo | 3241 | for(var p = 0; p < 12 ; p++){\ |
3242 | for(var d = 0; d < 12 ; d++){\ |
||
3243 | while(i.indexOf(cons[d]+\"\"+fun[p])!=-1){\ |
||
3244 | i = i.replace(cons[d]+\"\"+fun[p],cons[d]+\"*\"+fun[p]);\ |
||
3245 | };\ |
||
3246 | while(i.indexOf(fun[p]+\"\"+cons[d])!=-1){\ |
||
3247 | i = i.replace(fun[p]+\"\"+cons[d],fun[p]+\"*\"+cons[d]);\ |
||
3248 | };\ |
||
3249 | };\ |
||
3250 | };\ |
||
3251 | if(i.indexOf(\"(\")!=-1){\ |
||
3252 | for(var p = 0;p < 12; p++){\ |
||
3253 | if(i.indexOf(cons[p]+\"(\")!=-1){\ |
||
3254 | i = i.replace(cons[p]+\"(\",cons[p]+\"*(\");\ |
||
3255 | };\ |
||
3256 | if(i.indexOf(\")\"+cons[p])!=-1){\ |
||
3257 | i = i.replace(\")\"+cons[p],\")*\"+cons[p]);\ |
||
3258 | };\ |
||
3259 | };\ |
||
3260 | i = i.replace(/\\)\\(/g,\")*(\");\ |
||
3261 | };\ |
||
3262 | return i;\ |
||
3263 | }\n"); |
||
3264 | } |
||
8815 | schaersvoo | 3265 | void add_input_jsfunction(FILE *js_include_file, int canvas_root_id,char *input_style,char *input_label,int input_cnt,char *stroke_color,float stroke_opacity,int line_width,int use_dashed,int dashtype0,int dashtype1,int font_size){ |
14038 | schaersvoo | 3266 | fprintf(js_include_file,"\n/* begin add_input_jsfunction */\n\ |
8297 | schaersvoo | 3267 | function clear_jsfunction(canvas_plot_id,input_field){\ |
8193 | schaersvoo | 3268 | try{\ |
8297 | schaersvoo | 3269 | var canvas_plot = document.getElementById(\"wims_canvas%d\"+canvas_plot_id);\ |
3270 | var canvas_plot_ctx = canvas_plot.getContext(\"2d\");\ |
||
8193 | schaersvoo | 3271 | if( confirm(\"clear function plot?\") ){\ |
8297 | schaersvoo | 3272 | canvas_plot_ctx.clearRect(0,0,xsize,ysize);\ |
3273 | document.getElementById(input_field).value = \"\";\ |
||
3274 | };\ |
||
3275 | return;\ |
||
3276 | }catch(e){alert(e+\"nothing to remove...\");};\ |
||
9244 | schaersvoo | 3277 | return;\ |
3278 | };\ |
||
8297 | schaersvoo | 3279 | function add_input_jsfunction(input_cnt,input_style,input_label,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1){\ |
3280 | var canvas_plot_id = %d+input_cnt;\ |
||
3281 | var input_field = \"canvas_input\"+input_cnt;\ |
||
3282 | var update_button_id = \"update_button\"+input_cnt;\ |
||
3283 | var delete_button_id = \"delete_button\"+input_cnt;\ |
||
3284 | if( wims_status == \"done\" ){return;};\ |
||
3285 | var tooltip_div = document.getElementById(\"tooltip_placeholder_div%d\");\ |
||
3286 | var input_jsfunction_div = document.createElement('div');\ |
||
3287 | input_jsfunction_div.id = \"input_jsfunction_div\"+input_cnt;\ |
||
3288 | tooltip_div.appendChild(input_jsfunction_div);\ |
||
8815 | schaersvoo | 3289 | input_jsfunction_div.innerHTML=\"<br /><br /><span style='font-style:italic;font-size:%dpx;color:rgb(\"+stroke_color+\")'><b>\"+input_label+\" <input type='text' size='16' value='' id='\"+input_field+\"' style='\"+input_style+\"' /></b><input id='\"+update_button_id+\"' type='button' value='OK' onclick='' style='color:red;background-color:lightblue;'/><input id='\"+delete_button_id+\"' type='button' value='NOK' onclick='' style='color:blue;background-color:red;'/></span> \";\ |
8297 | schaersvoo | 3290 | var update_button = document.getElementById(update_button_id);\ |
3291 | var delete_button = document.getElementById(delete_button_id);\ |
||
11893 | schaersvoo | 3292 | update_button.addEventListener(\"mousedown\",function(e){jsplot(canvas_plot_id,[rawmath(document.getElementById(input_field).value)],[line_width],[stroke_color],[stroke_opacity],[use_dashed],dashtype0,dashtype1,0,0,300,0,0);return;},false);\ |
8297 | schaersvoo | 3293 | delete_button.addEventListener(\"mousedown\",function(e){clear_jsfunction(canvas_plot_id,input_field);return;},false);\ |
9244 | schaersvoo | 3294 | };\ |
8815 | schaersvoo | 3295 | add_input_jsfunction(%d,\"%s\",\"%s\",%d,\"%s\",%.2f,%d,%d,%d);\n",canvas_root_id,USERDRAW_JSPLOT,canvas_root_id,font_size,input_cnt,input_style,input_label,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1); |
8193 | schaersvoo | 3296 | } |
3297 | |||
3298 | |||
8224 | bpr | 3299 | /* |
3300 | adds 2 inputfields (x:y) and 'ok' | 'nok' button |
||
7668 | schaersvoo | 3301 | these are used for user drawing with inputfields... |
3302 | */ |
||
7823 | schaersvoo | 3303 | |
8815 | schaersvoo | 3304 | void add_input_xy(FILE *js_include_file, int canvas_root_id,int font_size,char *input_style){ |
14038 | schaersvoo | 3305 | fprintf(js_include_file,"\n/* begin add_input_xy */\n\ |
7856 | schaersvoo | 3306 | function add_input_xy(){\ |
7956 | schaersvoo | 3307 | if( wims_status == \"done\" ){return;};\ |
7856 | schaersvoo | 3308 | var tooltip_div = document.getElementById(\"tooltip_placeholder_div%d\");\ |
3309 | var input_xy_div = document.createElement('div');\ |
||
3310 | input_xy_div.id = \"input_xy_div\";\ |
||
3311 | tooltip_div.appendChild(input_xy_div);\ |
||
7663 | schaersvoo | 3312 | var label_x = \"x\";var label_y = \"y\";\ |
9213 | schaersvoo | 3313 | input_xy_div.innerHTML=\"<br /><span style='font-style:italic;font-size:%dpx'><b>( <input type='text' size='5' value='' id='userinput_x' style='%s' /> : <input type='text' size='5' value='' id='userinput_y' style='%s' /> )</b><input id='update_button' type='button' value='OK' onclick='' style='color:red;background-color:lightblue;'/><input id='delete_button' type='button' value='NOK' onclick='' style='color:blue;background-color:red;'/></span> \";\ |
7652 | schaersvoo | 3314 | var update_button = document.getElementById(\"update_button\");\ |
7668 | schaersvoo | 3315 | var delete_button = document.getElementById(\"delete_button\");\ |
3316 | update_button.addEventListener(\"mousedown\",function(e){user_redraw(1);return;},false);\ |
||
7856 | schaersvoo | 3317 | delete_button.addEventListener(\"mousedown\",function(e){user_redraw(-1);return;},false);\ |
8815 | schaersvoo | 3318 | };add_input_xy();",canvas_root_id,font_size,input_style,input_style); |
7652 | schaersvoo | 3319 | } |
3320 | |||
7668 | schaersvoo | 3321 | /* adds 4 inputfields (x1:y1) --- (x2:y2) and 'ok' + 'nok' button */ |
8815 | schaersvoo | 3322 | void add_input_x1y1x2y2(FILE *js_include_file, int canvas_root_id,int font_size,char *input_style){ |
14038 | schaersvoo | 3323 | fprintf(js_include_file,"\n/* begin add_input_x1y1x2y2 */\n\ |
7856 | schaersvoo | 3324 | function add_input_x1y1x2y2(){\ |
7956 | schaersvoo | 3325 | if( wims_status == \"done\" ){return;};\ |
7856 | schaersvoo | 3326 | var tooltip_div = document.getElementById(\"tooltip_placeholder_div%d\");\ |
3327 | var input_x1y1x2y2_div = document.createElement('div');\ |
||
3328 | input_x1y1x2y2_div.id = \"input_x1y1x2y2_div\";\ |
||
3329 | tooltip_div.appendChild(input_x1y1x2y2_div);\ |
||
9213 | schaersvoo | 3330 | input_x1y1x2y2_div.innerHTML=\"<br /><span style='font-size:%dpx'><b>( <input type='text' size='5' value='' id='userinput_x1' style='%s' /> : <input type='text' size='5' value='' id='userinput_y1' style='%s' /> ) ----- ( <input type='text' size='5' value='' id='userinput_x2' style='%s' /> : <input type='text' size='5' value='' id='userinput_y2' style='%s'/> )</b><input id='update_button' type='button' value='OK' onclick='' style='color:red;background-color:lightblue;'/><input id='delete_button' type='button' value='NOK' onclick='' style='color:blue;background-color:red;' /></span> \";\ |
7652 | schaersvoo | 3331 | var update_button = document.getElementById(\"update_button\");\ |
7668 | schaersvoo | 3332 | var delete_button = document.getElementById(\"delete_button\");\ |
3333 | update_button.addEventListener(\"mousedown\",function(e){user_redraw(1);return;},false);\ |
||
7856 | schaersvoo | 3334 | delete_button.addEventListener(\"mousedown\",function(e){user_redraw(-1);return;},false);\ |
8815 | schaersvoo | 3335 | };add_input_x1y1x2y2();",canvas_root_id,font_size,input_style,input_style,input_style,input_style); |
7652 | schaersvoo | 3336 | } |
3337 | |||
7668 | schaersvoo | 3338 | /* adds 3 inputfields Center (x:y) Radius r and 'ok'+'nok' buttons */ |
8815 | schaersvoo | 3339 | void add_input_xyr(FILE *js_include_file, int canvas_root_id,int font_size,char *input_style){ |
14038 | schaersvoo | 3340 | fprintf(js_include_file,"\n/* begin add_input_xyr */\n\ |
7856 | schaersvoo | 3341 | function add_input_xyr(){\ |
7956 | schaersvoo | 3342 | if( wims_status == \"done\" ){return;};\ |
7856 | schaersvoo | 3343 | var tooltip_div = document.getElementById(\"tooltip_placeholder_div%d\");\ |
3344 | var input_xyr_div = document.createElement('div');\ |
||
3345 | input_xyr_div.id = \"input_xyr_div\";\ |
||
3346 | tooltip_div.appendChild(input_xyr_div);\ |
||
9213 | schaersvoo | 3347 | input_xyr_div.innerHTML=\"<br /><span style='font-style:italic;font-size:%dpx'><b>Center : ( <input type='text' size='5' value='' id='userinput_x' style='%s' /> : <input type='text' size='5' value='' id='userinput_y' style='%s' /> ) Radius : <input type='text' size='5' value='' id='userinput_r' style='%s' /></b><input id='update_button' type='button' value='OK' onclick='' style='color:red;background-color:lightblue;'/><input id='delete_button' type='button' value='NOK' onclick='' style='color:blue;background-color:red;'/></span> \";\ |
7652 | schaersvoo | 3348 | var update_button = document.getElementById(\"update_button\");\ |
7668 | schaersvoo | 3349 | var delete_button = document.getElementById(\"delete_button\");\ |
3350 | update_button.addEventListener(\"mousedown\",function(e){user_redraw(1);return;},false);\ |
||
7856 | schaersvoo | 3351 | delete_button.addEventListener(\"mousedown\",function(e){user_redraw(-1);return;},false);\ |
8815 | schaersvoo | 3352 | };add_input_xyr();",canvas_root_id,font_size,input_style,input_style,input_style); |
7652 | schaersvoo | 3353 | } |
3354 | |||
7749 | schaersvoo | 3355 | /* THESE JS-FUNCTIONS COULD BE MADE LESS COPY & PASTE "PROGRAMMING" */ |
3356 | |||
7663 | schaersvoo | 3357 | /* draw circle(s) / point(s) via 3 inputfields */ |
7652 | schaersvoo | 3358 | void add_input_circle(FILE *js_include_file,int type,int num){ |
8224 | bpr | 3359 | /* |
3360 | type = 0 : a point ...radius is fixed |
||
7652 | schaersvoo | 3361 | type = 1 : a circle ... read inputfield userinput_r |
3362 | num = 1 : a single point / circle |
||
3363 | num = 2 : multiple points / circles |
||
3364 | */ |
||
14038 | schaersvoo | 3365 | fprintf(js_include_file,"\n/* begin add_input_circle */\n\ |
7668 | schaersvoo | 3366 | function user_redraw(t){\ |
3367 | var type = %d;\ |
||
3368 | var num = %d;\ |
||
7780 | schaersvoo | 3369 | var lu = userdraw_x.length;\ |
12006 | schaersvoo | 3370 | if( t == -1 && lu > 0){userdraw_x.splice(lu-1,1);userdraw_y.splice(lu-1,1);if(type == 1){userdraw_radius.splice(lu-1,1);};context_userdraw.clearRect(0,0,xsize,ysize);draw_circles(context_userdraw,userdraw_x,userdraw_y,userdraw_radius,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,dashtype1);xy_cnt = userdraw_x.length;return;};\ |
7749 | schaersvoo | 3371 | var add_x = safe_eval( document.getElementById(\"userinput_x\").value );\ |
3372 | var add_y = safe_eval( document.getElementById(\"userinput_y\").value );\ |
||
12006 | schaersvoo | 3373 | if( add_x != null && add_y != null ){if( type == 1 ){var add_r = safe_eval( document.getElementById(\"userinput_r\").value );if( add_r == null ){alert(\"illegal radius input \");return;};if( num == 1 ){userdraw_radius[0] = parseInt(Math.abs(xsize*(add_r)/(xmax - xmin)));}else{userdraw_radius.push( parseInt(Math.abs(xsize*(add_r)/(xmax - xmin))) );};}else{userdraw_radius[lu] = userdraw_radius[0];};if( num == 1 ){userdraw_x[0] = x2px(add_x);userdraw_y[0] = y2px(add_y);xy_cnt=1;}else{userdraw_x.push(x2px(add_x));userdraw_y.push(y2px(add_y));xy_cnt = userdraw_x.length;};context_userdraw.clearRect(0,0,xsize,ysize);draw_circles(context_userdraw,userdraw_x,userdraw_y,userdraw_radius,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,dashtype1);};\ |
7749 | schaersvoo | 3374 | return;\ |
3375 | };",type,num); |
||
7652 | schaersvoo | 3376 | } |
7663 | schaersvoo | 3377 | /* draw crosshairs via inputfields x/y */ |
7654 | schaersvoo | 3378 | void add_input_crosshair(FILE *js_include_file,int num){ |
14038 | schaersvoo | 3379 | fprintf(js_include_file,"\n/* begin add_input_crosshair */\n\ |
7668 | schaersvoo | 3380 | function user_redraw(t){\ |
7780 | schaersvoo | 3381 | var lu = userdraw_x.length;\ |
3382 | if( t == -1 && lu > 0){\ |
||
3383 | userdraw_x.splice(lu-1,1);\ |
||
3384 | userdraw_y.splice(lu-1,1);\ |
||
7749 | schaersvoo | 3385 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
3386 | draw_crosshairs(context_userdraw,userdraw_x,userdraw_y,line_width,crosshair_size,stroke_color,stroke_opacity,0,0,0,[0,0]);\ |
||
3387 | return;\ |
||
3388 | };\ |
||
3389 | var add_x = safe_eval( document.getElementById(\"userinput_x\").value );\ |
||
3390 | var add_y = safe_eval( document.getElementById(\"userinput_y\").value );\ |
||
3391 | if( add_x != null && add_y != null ){\ |
||
7654 | schaersvoo | 3392 | if( %d == 1 ){\ |
3393 | userdraw_x[0] = x2px(add_x);\ |
||
3394 | userdraw_y[0] = y2px(add_y);\ |
||
3395 | }\ |
||
3396 | else\ |
||
3397 | {\ |
||
3398 | userdraw_x[lu] = x2px(add_x);\ |
||
3399 | userdraw_y[lu] = y2px(add_y);\ |
||
3400 | xy_cnt++;\ |
||
3401 | };\ |
||
3402 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
||
3403 | draw_crosshairs(context_userdraw,userdraw_x,userdraw_y,line_width,crosshair_size,stroke_color,stroke_opacity,0,0,0,[0,0]);\ |
||
3404 | };\ |
||
7749 | schaersvoo | 3405 | return;\ |
7654 | schaersvoo | 3406 | };",num); |
3407 | } |
||
3408 | |||
7663 | schaersvoo | 3409 | /* draw arrows via inputfields x/y */ |
3410 | void add_input_arrow(FILE *js_include_file,int num){ |
||
14038 | schaersvoo | 3411 | fprintf(js_include_file,"\n/* begin add_input_arrow */\n\ |
7668 | schaersvoo | 3412 | function user_redraw(t){\ |
7780 | schaersvoo | 3413 | var lu = userdraw_x.length;\ |
3414 | if( t == -1 && lu > 1 ){\ |
||
3415 | userdraw_x.splice(lu-2,2);\ |
||
3416 | userdraw_y.splice(lu-2,2);\ |
||
7747 | schaersvoo | 3417 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
8071 | schaersvoo | 3418 | draw_arrows(context_userdraw,userdraw_x,userdraw_y,arrow_head,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,type,use_rotate,angle,0,[1,0,0,1,0,0]);\ |
7747 | schaersvoo | 3419 | return;\ |
3420 | };\ |
||
7749 | schaersvoo | 3421 | var add_x1 = safe_eval( document.getElementById(\"userinput_x1\").value );\ |
3422 | var add_y1 = safe_eval( document.getElementById(\"userinput_y1\").value );\ |
||
3423 | var add_x2 = safe_eval( document.getElementById(\"userinput_x2\").value );\ |
||
3424 | var add_y2 = safe_eval( document.getElementById(\"userinput_y2\").value );\ |
||
3425 | if( add_x1 != null && add_y1 != null && add_x2 != null && add_y2 != null ){\ |
||
7654 | schaersvoo | 3426 | if( %d == 2 ){\ |
3427 | var s = userdraw_x.length;\ |
||
7780 | schaersvoo | 3428 | userdraw_x[lu] = x2px(add_x1);\ |
3429 | userdraw_y[lu] = y2px(add_y1);\ |
||
3430 | userdraw_x[lu+1] = x2px(add_x2);\ |
||
3431 | userdraw_y[lu+1] = y2px(add_y2);\ |
||
7654 | schaersvoo | 3432 | }\ |
3433 | else\ |
||
3434 | {\ |
||
3435 | userdraw_x[0] = x2px(add_x1);\ |
||
3436 | userdraw_y[0] = y2px(add_y1);\ |
||
3437 | userdraw_x[1] = x2px(add_x2);\ |
||
3438 | userdraw_y[1] = y2px(add_y2);\ |
||
3439 | };\ |
||
3440 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
||
8071 | schaersvoo | 3441 | draw_arrows(context_userdraw,userdraw_x,userdraw_y,arrow_head,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,type,use_rotate,angle,0,[1,0,0,1,0,0]);\ |
7654 | schaersvoo | 3442 | };\ |
7749 | schaersvoo | 3443 | return;\ |
7654 | schaersvoo | 3444 | };",num); |
3445 | } |
||
3446 | |||
7746 | schaersvoo | 3447 | /* draw line via inputfields x/y */ |
7780 | schaersvoo | 3448 | void add_input_line(FILE *js_include_file,int num){ |
14038 | schaersvoo | 3449 | fprintf(js_include_file,"\n/* begin line via inputfields */\n\ |
7746 | schaersvoo | 3450 | function user_redraw(t){\ |
7780 | schaersvoo | 3451 | var lu = userdraw_x.length;\ |
3452 | if( t == -1 && lu > 1){\ |
||
3453 | userdraw_x.splice(lu-2,2);\ |
||
3454 | userdraw_y.splice(lu-2,2);\ |
||
7746 | schaersvoo | 3455 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
3456 | draw_lines(context_userdraw,userdraw_x,userdraw_y,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,1,0,0);\ |
||
3457 | return;\ |
||
3458 | };\ |
||
7749 | schaersvoo | 3459 | var add_x1 = safe_eval( document.getElementById(\"userinput_x1\").value );\ |
3460 | var add_y1 = safe_eval( document.getElementById(\"userinput_y1\").value );\ |
||
3461 | var add_x2 = safe_eval( document.getElementById(\"userinput_x2\").value );\ |
||
3462 | var add_y2 = safe_eval( document.getElementById(\"userinput_y2\").value );\ |
||
3463 | if( add_x1 != null && add_y1 != null && add_x2 != null && add_y2 != null ){\ |
||
7746 | schaersvoo | 3464 | if( %d == 2 ){\ |
7780 | schaersvoo | 3465 | userdraw_x[lu] = x2px(add_x1);\ |
3466 | userdraw_y[lu] = y2px(add_y1);\ |
||
3467 | userdraw_x[lu+1] = x2px(add_x2);\ |
||
3468 | userdraw_y[lu+1] = y2px(add_y2);\ |
||
7746 | schaersvoo | 3469 | }\ |
3470 | else\ |
||
3471 | {\ |
||
3472 | userdraw_x[0] = x2px(add_x1);\ |
||
3473 | userdraw_y[0] = y2px(add_y1);\ |
||
3474 | userdraw_x[1] = x2px(add_x2);\ |
||
3475 | userdraw_y[1] = y2px(add_y2);\ |
||
3476 | };\ |
||
3477 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
||
3478 | draw_lines(context_userdraw,userdraw_x,userdraw_y,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,1,0,0);\ |
||
3479 | };\ |
||
7749 | schaersvoo | 3480 | return;\ |
7746 | schaersvoo | 3481 | };",num); |
3482 | } |
||
3483 | |||
3484 | |||
7663 | schaersvoo | 3485 | /* draw polyline via inputfields x/y */ |
7780 | schaersvoo | 3486 | void add_input_polyline(FILE *js_include_file){ |
14038 | schaersvoo | 3487 | fprintf(js_include_file,"\n/* begin polyline_segment via inputfields */\n\ |
7668 | schaersvoo | 3488 | function user_redraw(t){\ |
8071 | schaersvoo | 3489 | var lu = userdraw_x.length;\ |
7962 | schaersvoo | 3490 | cnt = 1;\ |
7780 | schaersvoo | 3491 | if( t == -1 && lu > 0){\ |
8071 | schaersvoo | 3492 | userdraw_x.splice(lu-1,1);\ |
3493 | userdraw_y.splice(lu-1,1);\ |
||
3494 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
||
3495 | draw_polyline(context_userdraw,userdraw_x,userdraw_y,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1);\ |
||
3496 | return;\ |
||
3497 | };\ |
||
3498 | var add_x = safe_eval( document.getElementById(\"userinput_x\").value );\ |
||
3499 | var add_y = safe_eval( document.getElementById(\"userinput_y\").value );\ |
||
7749 | schaersvoo | 3500 | if(add_x != null && add_y != null ){\ |
8071 | schaersvoo | 3501 | userdraw_x.push(x2px(add_x));\ |
3502 | userdraw_y.push(y2px(add_y));\ |
||
3503 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
||
3504 | draw_polyline(context_userdraw,userdraw_x,userdraw_y,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1);\ |
||
3505 | };\ |
||
3506 | return;\ |
||
7663 | schaersvoo | 3507 | };"); |
3508 | } |
||
3509 | /* draw segment(s) via inputfields x/y */ |
||
3510 | void add_input_segment(FILE *js_include_file,int num){ |
||
14038 | schaersvoo | 3511 | fprintf(js_include_file,"\n/* begin add_input_segment */\n\ |
7668 | schaersvoo | 3512 | function user_redraw(t){\ |
7780 | schaersvoo | 3513 | var lu = userdraw_x.length;\ |
3514 | if( t == -1 && lu > 1){\ |
||
3515 | userdraw_x.splice(lu-2,2);\ |
||
3516 | userdraw_y.splice(lu-2,2);\ |
||
7746 | schaersvoo | 3517 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
7668 | schaersvoo | 3518 | draw_segments(context_userdraw,userdraw_x,userdraw_y,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1);\ |
3519 | return;\ |
||
3520 | };\ |
||
7749 | schaersvoo | 3521 | var add_x1 = safe_eval( document.getElementById(\"userinput_x1\").value );\ |
3522 | var add_y1 = safe_eval( document.getElementById(\"userinput_y1\").value );\ |
||
3523 | var add_x2 = safe_eval( document.getElementById(\"userinput_x2\").value );\ |
||
3524 | var add_y2 = safe_eval( document.getElementById(\"userinput_y2\").value );\ |
||
3525 | if( add_x1 != null && add_y1 != null && add_x2 != null && add_y2 != null ){\ |
||
7652 | schaersvoo | 3526 | if( %d == 2 ){\ |
3527 | var s = userdraw_x.length;\ |
||
3528 | userdraw_x[s] = x2px(add_x1);\ |
||
3529 | userdraw_y[s] = y2px(add_y1);\ |
||
3530 | userdraw_x[s+1] = x2px(add_x2);\ |
||
3531 | userdraw_y[s+1] = y2px(add_y2);\ |
||
3532 | }\ |
||
3533 | else\ |
||
3534 | {\ |
||
3535 | userdraw_x[0] = x2px(add_x1);\ |
||
3536 | userdraw_y[0] = y2px(add_y1);\ |
||
3537 | userdraw_x[1] = x2px(add_x2);\ |
||
3538 | userdraw_y[1] = y2px(add_y2);\ |
||
3539 | };\ |
||
3540 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
||
3541 | draw_segments(context_userdraw,userdraw_x,userdraw_y,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1);\ |
||
7668 | schaersvoo | 3542 | };\ |
7749 | schaersvoo | 3543 | return;\ |
7652 | schaersvoo | 3544 | };",num); |
3545 | } |
||
7663 | schaersvoo | 3546 | |
8244 | schaersvoo | 3547 | /* draw demilines(s) via inputfields x/y */ |
3548 | void add_input_demiline(FILE *js_include_file,int num){ |
||
14038 | schaersvoo | 3549 | fprintf(js_include_file,"\n/* begin add_input_segment */\n\ |
8244 | schaersvoo | 3550 | function user_redraw(t){\ |
3551 | var lu = userdraw_x.length;\ |
||
3552 | if( t == -1 && lu > 1){\ |
||
3553 | userdraw_x.splice(lu-2,2);\ |
||
3554 | userdraw_y.splice(lu-2,2);\ |
||
3555 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
||
3556 | draw_demilines(context_userdraw,userdraw_x,userdraw_y,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1);\ |
||
3557 | return;\ |
||
3558 | };\ |
||
3559 | var add_x1 = safe_eval( document.getElementById(\"userinput_x1\").value );\ |
||
3560 | var add_y1 = safe_eval( document.getElementById(\"userinput_y1\").value );\ |
||
3561 | var add_x2 = safe_eval( document.getElementById(\"userinput_x2\").value );\ |
||
3562 | var add_y2 = safe_eval( document.getElementById(\"userinput_y2\").value );\ |
||
3563 | if( add_x1 != null && add_y1 != null && add_x2 != null && add_y2 != null ){\ |
||
3564 | if( %d == 2 ){\ |
||
3565 | var s = userdraw_x.length;\ |
||
3566 | userdraw_x[s] = x2px(add_x1);\ |
||
3567 | userdraw_y[s] = y2px(add_y1);\ |
||
3568 | userdraw_x[s+1] = x2px(add_x2);\ |
||
3569 | userdraw_y[s+1] = y2px(add_y2);\ |
||
3570 | }\ |
||
3571 | else\ |
||
3572 | {\ |
||
3573 | userdraw_x[0] = x2px(add_x1);\ |
||
3574 | userdraw_y[0] = y2px(add_y1);\ |
||
3575 | userdraw_x[1] = x2px(add_x2);\ |
||
3576 | userdraw_y[1] = y2px(add_y2);\ |
||
3577 | };\ |
||
3578 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
||
3579 | draw_demilines(context_userdraw,userdraw_x,userdraw_y,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1);\ |
||
3580 | };\ |
||
3581 | return;\ |
||
3582 | };",num); |
||
3583 | } |
||
3584 | |||
7749 | schaersvoo | 3585 | /* draw polygon via 2 textarea's x/y : split into lines ! */ |
3586 | void add_textarea_polygon(FILE *js_include_file){ |
||
14038 | schaersvoo | 3587 | fprintf(js_include_file,"\n/* begin polygon via 2 textareas x / y */\n\ |
7749 | schaersvoo | 3588 | function user_redraw(t){\ |
7780 | schaersvoo | 3589 | var lu = userdraw_x.length;\ |
3590 | if( t == -1 && lu > 0){\ |
||
7856 | schaersvoo | 3591 | if( lu < 3 ){\ |
3592 | userdraw_x = [];\ |
||
3593 | userdraw_y = [];\ |
||
3594 | }\ |
||
3595 | else\ |
||
3596 | {\ |
||
7780 | schaersvoo | 3597 | userdraw_x.splice(lu-1,1);\ |
3598 | userdraw_y.splice(lu-1,1);\ |
||
7856 | schaersvoo | 3599 | };\ |
7749 | schaersvoo | 3600 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
8071 | schaersvoo | 3601 | draw_paths(context_userdraw,userdraw_x,userdraw_y,line_width,closed_path,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,use_rotate,angle,0,[1,0,0,1,0,0]);\ |
7749 | schaersvoo | 3602 | cnt = 1; return;\ |
3603 | };\ |
||
7780 | schaersvoo | 3604 | var add_x_values = (document.getElementById(\"userinput_x\").value).split('\\n');\ |
3605 | var add_y_values = (document.getElementById(\"userinput_y\").value).split('\\n');\ |
||
3606 | var lx = add_x_values.length;\ |
||
3607 | var ly = add_y_values.length;\ |
||
3608 | if( lx != ly){ if(lx > ly){alert(\'x/y mismatch\\ntoo few y-values\');return}else{alert(\'x/y mismatch\\ntoo many y-values\');return}};\ |
||
3609 | var add_x;var add_y;\ |
||
3610 | for(var p = 0 ; p < lx ; p++){\ |
||
3611 | add_x = safe_eval( add_x_values[p] );\ |
||
3612 | add_y = safe_eval( add_y_values[p] );\ |
||
3613 | if( add_x == null || add_y == null ){return;};\ |
||
3614 | userdraw_x[lu+p] = x2px(add_x);\ |
||
3615 | userdraw_y[lu+p] = y2px(add_y);\ |
||
3616 | if(p>100){alert(\"hmmmm\");return;};\ |
||
7749 | schaersvoo | 3617 | };\ |
8071 | schaersvoo | 3618 | draw_paths(context_userdraw,userdraw_x,userdraw_y,line_width,closed_path,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,use_rotate,angle,0,[1,0,0,1,0,0]);\ |
7780 | schaersvoo | 3619 | cnt = 1;\ |
7749 | schaersvoo | 3620 | return;\ |
3621 | };"); |
||
3622 | } |
||
3623 | |||
7858 | schaersvoo | 3624 | void add_jsplot(FILE *js_include_file,int canvas_root_id){ |
14038 | schaersvoo | 3625 | fprintf(js_include_file,"\n/* begin jsplot() */\n\ |
13512 | schaersvoo | 3626 | var x_anim_points;var y_anim_points;var animation_steps;var animation_funs;\ |
11893 | schaersvoo | 3627 | var jsplot = function(canvas_type,funs,linewidth,color,opacity,use_dashed,dashtype0,dashtype1,trange,plotsteps,use_parametric,use_animate){\ |
11093 | schaersvoo | 3628 | var obj = create_canvas%d(canvas_type,xsize,ysize);\ |
3629 | var ctx = obj.getContext(\"2d\");\ |
||
3630 | ctx.clearRect(0,0,xsize,ysize);\ |
||
13512 | schaersvoo | 3631 | animation_funs = funs.length;\ |
11093 | schaersvoo | 3632 | function eval_jsmath(x,func){return parseFloat(eval(func));};\ |
3633 | if( typeof(multilinewidth) !== 'undefined' && multilinewidth != null ){ linewidth = multilinewidth;};\ |
||
3634 | if( typeof(multistrokecolors) !== 'undefined' && multistrokecolors != null){ color = multistrokecolors;};\ |
||
3635 | if( typeof(multistrokeopacity) !== 'undefined' && multistrokeopacity != null ){ opacity = multistrokeopacity;};\ |
||
3636 | if( typeof(multidash) !== 'undefined' && multidash != null ){use_dashed = multidash;};\ |
||
11893 | schaersvoo | 3637 | x_anim_points = [];y_anim_points = [];var idx=0;\ |
3638 | if( use_parametric == 1){\n\ |
||
13512 | schaersvoo | 3639 | for(var i = 0 ; i < animation_funs; i=i+2){\ |
11893 | schaersvoo | 3640 | var fun_x = to_js_math(funs[i]);\ |
3641 | var fun_y = to_js_math(funs[i+1]);\ |
||
3642 | if(fun_x == null || fun_y == null){alert(\"Syntax Error...\\nAttention : try use very precise notation !\\nlike :\\n6*(0.25)^(1.23)\\n1/(sin(5*x))\\n(3*x+4)/(x^(2*pi)) \");return;};\ |
||
3643 | try{ parseFloat( eval_jsmath( px2x(0),fun_x ) );}catch(e){alert(\"\\nSyntax Error...\\nAttention : try use very precise notation !\\nlike :\\n6*(0.25)^(1.23)\\n1/(sin(5*x))\\n(3*x+4)/(x^(2*pi))\");return;};\ |
||
13512 | schaersvoo | 3644 | ctx.lineWidth = linewidth[i] || linewidth;\ |
3645 | ctx.strokeStyle='rgba('+color[i] || color +','+opacity[i] || opacity +')';\ |
||
3646 | if(use_dashed[i] == \"1\" || use_dashed == \"1\"){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash =[dashtype0,dashtype1];}};\ |
||
11893 | schaersvoo | 3647 | var y1;var x1;var y2;var x2;\ |
3648 | ctx.beginPath();\ |
||
3649 | var tmin = trange[0];var tmax = trange[1];\ |
||
3650 | var step = parseFloat((tmax - tmin)/plotsteps);\ |
||
3651 | for(var p = tmin ; p < tmax; p = p+step ){\ |
||
3652 | x1 = x2px(parseFloat(eval_jsmath(p,fun_x)));\ |
||
3653 | y1 = y2px(parseFloat(eval_jsmath(p,fun_y)));\ |
||
3654 | x2 = x2px(parseFloat(eval_jsmath(p+step,fun_x)));\ |
||
3655 | y2 = y2px(parseFloat(eval_jsmath(p+step,fun_y)));\ |
||
3656 | x_anim_points[idx] = x1;y_anim_points[idx] = y1;idx++;\ |
||
3657 | ctx.moveTo(x1,y1);\ |
||
3658 | ctx.lineTo(x2,y2);\ |
||
3659 | ctx.moveTo(x1,y1);\ |
||
3660 | ctx.lineTo(x2,y2);\ |
||
11093 | schaersvoo | 3661 | };\ |
11893 | schaersvoo | 3662 | ctx.closePath();\ |
3663 | ctx.stroke();\ |
||
11093 | schaersvoo | 3664 | };\ |
13512 | schaersvoo | 3665 | animation_funs = 0.5*animation_funs;\ |
11893 | schaersvoo | 3666 | }else{\ |
13512 | schaersvoo | 3667 | for(var i = 0 ; i < animation_funs; i++){\ |
11893 | schaersvoo | 3668 | var fun = to_js_math(funs[i]);\ |
3669 | if(fun == null){alert(\"Syntax Error...\\nAttention : try use very precise notation !\\nlike :\\n6*(0.25)^(1.23)\\n1/(sin(5*x))\\n(3*x+4)/(x^(2*pi)) \");return;};\ |
||
3670 | try{ parseFloat( eval_jsmath( px2x(0),fun ) );}catch(e){alert(\"\\nSyntax Error...\\nAttention : try use very precise notation !\\nlike :\\n6*(0.25)^(1.23)\\n1/(sin(5*x))\\n(3*x+4)/(x^(2*pi))\");return;};\ |
||
13512 | schaersvoo | 3671 | if(use_dashed[i] == \"1\" || use_dashed == \"1\"){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash =[dashtype0,dashtype1];}};\ |
3672 | ctx.lineWidth = linewidth[i] || linewidth;\ |
||
3673 | ctx.strokeStyle='rgba('+color[i] || color +','+opacity[i] || opacity +')';\ |
||
11893 | schaersvoo | 3674 | var y1;var x1;var y2;var x2;\ |
3675 | ctx.beginPath();\ |
||
3676 | for(var p = 0 ; p<xsize;p++){\ |
||
3677 | x1 = px2x(p);\ |
||
3678 | y1 = y2px(parseFloat(eval_jsmath(x1,fun)));\ |
||
3679 | x2 = px2x(p+1);\ |
||
3680 | y2 = y2px(parseFloat(eval_jsmath(x2,fun)));\ |
||
12006 | schaersvoo | 3681 | x_anim_points[idx] = p;y_anim_points[idx] = y1;idx++;\ |
11893 | schaersvoo | 3682 | if(Math.abs(y2-y1) < ysize ){\ |
3683 | ctx.moveTo(p,y1);\ |
||
3684 | ctx.lineTo(p+1,y2);\ |
||
3685 | };\ |
||
3686 | };\ |
||
3687 | ctx.closePath();\ |
||
3688 | ctx.stroke();\ |
||
3689 | };\ |
||
11093 | schaersvoo | 3690 | };\ |
11893 | schaersvoo | 3691 | if( use_animate == 1 ){animation_steps = idx;animate_this();}\ |
11006 | schaersvoo | 3692 | };",canvas_root_id); |
7858 | schaersvoo | 3693 | } |
3694 | |||
3695 | void add_to_js_math(FILE *js_include_file){ |
||
14038 | schaersvoo | 3696 | fprintf(js_include_file,"\n/* begin to_js_math() */\n\ |
7858 | schaersvoo | 3697 | var to_js_math = function(math_fun){\ |
8299 | schaersvoo | 3698 | if(math_fun == null){return;};\ |
7858 | schaersvoo | 3699 | var infun=[\"sqrt\",\"^\",\"asin\",\"acos\",\"atan\",\"log\",\"pi\",\"abs\",\"sin\",\"cos\",\"tan\",\"e\"];\ |
7981 | schaersvoo | 3700 | var outfun=[\"Math.sqrt\",\"Math.pow\",\"Math.asin\",\"Math.acos\",\"Math.atan\",\"Math.log\",\"(3.14159265358979)\",\"Math.abs\",\"Math.sin\",\"Math.cos\",\"Math.tan\",\"(2.718281828459045)\"];\ |
3701 | var len = infun.length;var in_fun;var In_Fun;var out_fun;var w_cnt;\ |
||
7858 | schaersvoo | 3702 | for(var p=0 ; p < len ; p++){\ |
7981 | schaersvoo | 3703 | in_fun = infun[p];In_Fun = in_fun.toUpperCase();out_fun = outfun[p];w_cnt=0;\ |
3704 | if(math_fun.indexOf(in_fun) != -1){\ |
||
7858 | schaersvoo | 3705 | if(in_fun == \"^\"){\ |
3706 | var tab = [];var small_trick = \"___small_trick___\";\ |
||
7981 | schaersvoo | 3707 | while (math_fun.indexOf(\"(\") != -1){\ |
7858 | schaersvoo | 3708 | math_fun = math_fun.replace(/(\\([^\\(\\)]*\\))/g, function(m, t){tab.push(t);return (small_trick + (tab.length - 1));});\ |
7981 | schaersvoo | 3709 | w_cnt++;if(w_cnt>1000){alert(\"hmmm \"+math_fun+\" ?\\nUse command plot for more complex math functions...\");return null;};\ |
7858 | schaersvoo | 3710 | };\ |
7981 | schaersvoo | 3711 | tab.push(math_fun);w_cnt = 0;math_fun = small_trick + (tab.length - 1);\ |
3712 | while (math_fun.indexOf(small_trick) != -1){\ |
||
7858 | schaersvoo | 3713 | math_fun = math_fun.replace(new RegExp(small_trick + \"(\\\\d+)\", \"g\"), function(m, d){return tab[d].replace(/(\\w*)\\^(\\w*)/g, out_fun+\"($1,$2)\");});\ |
7981 | schaersvoo | 3714 | w_cnt++;if(w_cnt>1000){alert(\"hmmm \"+math_fun+\" ?\\nUse command plot for more complex math functions...\");return null;};\ |
7858 | schaersvoo | 3715 | };\ |
3716 | }\ |
||
3717 | else\ |
||
3718 | {\ |
||
7981 | schaersvoo | 3719 | while( math_fun.indexOf(in_fun) != -1 ){\ |
7858 | schaersvoo | 3720 | math_fun = math_fun.replace(in_fun,out_fun);\ |
3721 | math_fun = math_fun.replace(in_fun,In_Fun);\ |
||
7981 | schaersvoo | 3722 | w_cnt++;if(w_cnt>1000){alert(\"hmmm \"+math_fun+\" ?\\nUse command plot for more complex math functions...\");return null;};\ |
7858 | schaersvoo | 3723 | };\ |
3724 | };\ |
||
3725 | };\ |
||
8071 | schaersvoo | 3726 | };\ |
3727 | for(var p=0 ; p < len ; p++){\ |
||
3728 | in_fun = infun[p];In_Fun = in_fun.toUpperCase();w_cnt = 0;\ |
||
3729 | if(math_fun.indexOf(In_Fun) != -1 ){\ |
||
3730 | while(math_fun.indexOf(In_Fun) != -1){\ |
||
3731 | math_fun = math_fun.replace(In_Fun,in_fun);\ |
||
3732 | w_cnt++;if(w_cnt>1000){alert(\"hmmm \"+math_fun+\" ?\\nUse command plot for more complex math functions...\");return null;};\ |
||
3733 | };\ |
||
3734 | };\ |
||
3735 | };\ |
||
3736 | return math_fun;\ |
||
7981 | schaersvoo | 3737 | };\n"); |
7858 | schaersvoo | 3738 | } |
3739 | |||
8146 | schaersvoo | 3740 | void add_clear_button(FILE *js_include_file,int canvas_root_id,char *input_style,char *button_text){ |
11001 | schaersvoo | 3741 | /* 25/11/2014 added clearing of reply array |
8448 | schaersvoo | 3742 | all members will be set to 0 eg reply[0] = 0 , reply[1] = 0 ... |
14948 | obado | 3743 | hope this does not interfere with existing work... |
8448 | schaersvoo | 3744 | */ |
11001 | schaersvoo | 3745 | /* |
14948 | obado | 3746 | 5/2016 changed to 'setAttribute()' because of trouble on Chromium/Safari/IE |
11080 | schaersvoo | 3747 | 10/2016 corrected contex-reset-flaw when using "userdraw text,color" and added inputs to the things we can remove |
11764 | schaersvoo | 3748 | 7/2017 added 'userdraw clickfill,color' to removable things...one user_filling per click |
11001 | schaersvoo | 3749 | */ |
14038 | schaersvoo | 3750 | fprintf(js_include_file,"<!-- add clear button */\n\ |
8349 | schaersvoo | 3751 | clear_draw_area%d = function(){\ |
11763 | schaersvoo | 3752 | if(typeof(fill_canvas_no) === 'object'){\ |
3753 | var len = fill_canvas_no.length;\ |
||
3754 | for(var p = len; p >= 0; p = p - 1){\ |
||
3755 | var chk = document.getElementById('wims_canvas%d'+fill_canvas_no[p]);\ |
||
3756 | if( chk ){\ |
||
3757 | var fill_ctx = chk.getContext(\"2d\");\ |
||
3758 | fill_ctx.clearRect(0,0,xsize,ysize);\ |
||
3759 | fill_canvas_no.splice(p,1);\ |
||
3760 | userdraw_x.splice(p,1);\ |
||
3761 | userdraw_y.splice(p,1);\ |
||
11764 | schaersvoo | 3762 | userdraw_radius.splice(p,1);\ |
3763 | return;\ |
||
11763 | schaersvoo | 3764 | };\ |
3765 | };\ |
||
3766 | return;\ |
||
3767 | };\ |
||
11088 | schaersvoo | 3768 | if( typeof(context_userdraw) === 'object' ){\ |
14270 | schaersvoo | 3769 | while( document.getElementById(canvas_div.lastChild.id).tagName == 'DIV'){\ |
3770 | document.getElementById(canvas_div.lastChild.id).innerHTML = null;\ |
||
3771 | canvas_div.removeChild(document.getElementById(canvas_div.lastChild.id));\ |
||
3772 | };\ |
||
11001 | schaersvoo | 3773 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
11088 | schaersvoo | 3774 | if( typeof(userdraw_text) != 'undefined'){ userdraw_text = []; };\ |
11080 | schaersvoo | 3775 | if( document.getElementById(\"canvas_input0\") ){\ |
3776 | var p = 0;var inp;\ |
||
3777 | while( document.getElementById(\"canvas_input\"+p) ){\ |
||
3778 | inp = document.getElementById(\"canvas_input\"+p);\ |
||
3779 | canvas_div.removeChild(inp);\ |
||
3780 | p++;\ |
||
3781 | };\ |
||
3782 | input_cnt = 0;start_input_cnt = 0; \ |
||
3783 | };\ |
||
14958 | obado | 3784 | userdraw_x = [];userdraw_y = [];userdraw_radius = [];xy_cnt = 0;click_cnt = 0;\ |
11001 | schaersvoo | 3785 | for(var p = 0;p < reply.length; p++){\ |
3786 | reply[p] = 0;\ |
||
3787 | };\ |
||
11080 | schaersvoo | 3788 | };\ |
14270 | schaersvoo | 3789 | if( typeof(external_ctx) === 'object'){\ |
14038 | schaersvoo | 3790 | external_ctx.clearRect(0,0,xsize,ysize);\ |
3791 | for(var p = 0 ; p < userdraw_x.length; p++){\ |
||
3792 | userdraw_x[p] = null;userdraw_y[p] = null;\ |
||
3793 | };\ |
||
3794 | };\ |
||
11080 | schaersvoo | 3795 | return;\ |
8350 | schaersvoo | 3796 | };\ |
3797 | function add_clear_button(){\ |
||
8146 | schaersvoo | 3798 | var tooltip_placeholder_div = document.getElementById(\"tooltip_placeholder_div%d\");\ |
8350 | schaersvoo | 3799 | var button = document.createElement('input');\ |
9858 | schaersvoo | 3800 | button.setAttribute(\"type\" , \"button\");\ |
11024 | schaersvoo | 3801 | button.setAttribute(\"id\" , \"clearbutton%d\");\ |
9858 | schaersvoo | 3802 | button.setAttribute(\"style\" , \"%s\");\ |
3803 | button.setAttribute(\"value\" , \"%s\");\ |
||
8350 | schaersvoo | 3804 | button.setAttribute(\"onclick\",\"clear_draw_area%d()\");\ |
3805 | tooltip_placeholder_div.appendChild(button);\ |
||
8146 | schaersvoo | 3806 | };\ |
9244 | schaersvoo | 3807 | add_clear_button();\ |
11763 | schaersvoo | 3808 | ",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,input_style,button_text,canvas_root_id); |
8146 | schaersvoo | 3809 | } |
7858 | schaersvoo | 3810 | |
11767 | schaersvoo | 3811 | void add_color_palette(FILE *js_include_file,int canvas_root_id,char *input_style){ |
14038 | schaersvoo | 3812 | fprintf(js_include_file,"<!-- add color palette */\n\ |
11767 | schaersvoo | 3813 | function add_color_palette(){\ |
3814 | var tooltip_placeholder_div = document.getElementById(\"tooltip_placeholder_div%d\");\ |
||
12006 | schaersvoo | 3815 | var clen = palettecolors.length;\ |
14038 | schaersvoo | 3816 | for( var p = 0 ; p < clen ; p++ ){\ |
12006 | schaersvoo | 3817 | var button = document.createElement('input');\ |
3818 | button.setAttribute('type', 'button');\ |
||
3819 | button.setAttribute('value', ' ');\ |
||
3820 | button.setAttribute('id',palettecolors[p]);\ |
||
3821 | button.setAttribute('style', \"%s\");\ |
||
3822 | button.setAttribute('style','background-color:rgb('+palettecolors[p]+')');\ |
||
3823 | button.setAttribute(\"backgroundColor\",palettecolors[p]);\ |
||
3824 | button.addEventListener('mousedown',function(e){var id = this.getAttribute('id');multifillcolors[0]=id;multifillcolors[1]=id;multifillcolors[2]=id;},false);\ |
||
3825 | tooltip_placeholder_div.appendChild(button);\ |
||
3826 | };\ |
||
3827 | };\ |
||
3828 | add_color_palette();\ |
||
11767 | schaersvoo | 3829 | ",canvas_root_id,input_style); |
3830 | } |
||
8146 | schaersvoo | 3831 | |
14230 | schaersvoo | 3832 | |
3833 | char *getMML(char *tex){ |
||
3834 | int my_pipe[2];pid_t pid; |
||
3835 | if(pipe(my_pipe)){canvas_error("mathml(): pipe() failure.\n");} |
||
3836 | pid = fork(); |
||
3837 | if (pid == (pid_t) 0){ |
||
3838 | char mml_buffer[MAX_BUFFER+1]; |
||
3839 | char *argv[]={"wims_mathml","--use-zoom","0","--tex-size 100%","--max-mml-size","1024","--tex-string",tex,NULL}; |
||
3840 | close(my_pipe[0]);dup2(my_pipe[1], 1);dup2(my_pipe[1], 2);close(my_pipe[1]); |
||
14594 | schaersvoo | 3841 | execv("../bin/wims_mathml",argv);canvas_error("could not execute wims_mathml\n"); |
14230 | schaersvoo | 3842 | } |
3843 | else |
||
14948 | obado | 3844 | { |
14230 | schaersvoo | 3845 | if (pid < (pid_t) 0){ |
14948 | obado | 3846 | close(my_pipe[0]);close(my_pipe[1]);canvas_error("mathml(): fork() failure.\n"); |
14230 | schaersvoo | 3847 | } |
3848 | int status;FILE *stream;close(my_pipe[1]);stream = fdopen (my_pipe[0], "r"); |
||
3849 | char buffer[MAX_BUFFER+1];memset(buffer,'\0',MAX_BUFFER); |
||
3850 | fgets(buffer, MAX_BUFFER, stream); |
||
3851 | int L0 = 1 + snprintf(NULL,0,"%s", buffer); |
||
3852 | tex = my_newmem(L0);memset(tex,'\0',L0); |
||
3853 | snprintf(tex,L0,"%s",buffer); |
||
14948 | obado | 3854 | fclose (stream);close(my_pipe[0]);waitpid(pid, &status, 0); |
14230 | schaersvoo | 3855 | } |
3856 | return tex; |
||
3857 | } |
||
3858 | |||
7858 | schaersvoo | 3859 | /* GNU libmatheval library for evaluating mathematical functions. */ |
3860 | char *eval(int xsize,int ysize,char *fun,double xmin,double xmax,double ymin,double ymax,int plotsteps,int precision){ |
||
3861 | void *f; |
||
3862 | double x; |
||
3863 | double y; |
||
3864 | int xv; |
||
3865 | int i = 0; |
||
3866 | int xstep =(int)(xsize/plotsteps); |
||
3867 | if( xstep == 0 ){xstep = 1;} |
||
3868 | double a = (xmax - xmin)/xsize; |
||
3869 | f = eval_create(fun); |
||
3870 | assert (f); |
||
3871 | if( f == NULL ){canvas_error("I'm having trouble parsing your \"expression\" ") ;} |
||
3872 | /* we supply the true x/y values...draw_curve() will convert these (x:y) to pixels : used for pan/scale */ |
||
3873 | double xydata[MAX_BUFFER+1];/* hmmm */ |
||
8813 | schaersvoo | 3874 | int lim_ymin =(int)( ymin - 4*fabs(ymin));/* 19-4-2015 replacing "abs" by "fabs"*/ |
3875 | int lim_ymax =(int)( ymax + 4*fabs(ymax));/* 19-4-2015 replacing "abs" by "fabs"*/ |
||
7858 | schaersvoo | 3876 | for ( xv = 0 ;xv < xsize ; xv = xv+xstep ){ |
3877 | x = (double) (xv*a + xmin); |
||
3878 | if( i < MAX_BUFFER - 2){ |
||
3879 | y = eval_x(f, x); |
||
3880 | if(y < lim_ymax && y > lim_ymin ){ |
||
3881 | xydata[i++] = x; |
||
3882 | xydata[i++] = y; |
||
3883 | } |
||
3884 | } |
||
3885 | else |
||
3886 | { |
||
3887 | canvas_error("\nYour curve plotting produces too many data \n Use less plotsteps or some other means to reduce the amount of data... "); |
||
3888 | } |
||
3889 | } |
||
3890 | eval_destroy(f); |
||
3891 | return double_xy2js_array(xydata,i,find_number_of_digits(precision)); |
||
3892 | } |
||
3893 | /* plot a very primitive (!) levelcurve : not to be compared with "flydraw levelcurve" */ |
||
3894 | char *eval_levelcurve(int xsize,int ysize,char *fun,double xmin,double xmax,double ymin,double ymax,int plotsteps,int precision,double level){ |
||
3895 | void *f = eval_create(fun); |
||
3896 | assert (f); |
||
3897 | if( f == NULL ){canvas_error("I'm having trouble parsing your \"expression\" ") ;} |
||
3898 | double a = (double)((xmax - xmin)/plotsteps); |
||
3899 | double b = (double)((ymax - ymin)/plotsteps); |
||
3900 | double x;double y;double diff; |
||
3901 | double xydata[MAX_BUFFER+1]; |
||
3902 | int i = 0; |
||
3903 | ymin = ymin - 1; |
||
3904 | xmin = xmin - 1; |
||
3905 | ymax = ymax + 1; |
||
3906 | xmax = xmax + 1; |
||
3907 | for( x = xmin ;x < xmax ; x = x + a ){ |
||
3908 | for ( y = ymin ;y < ymax ; y = y + b ){ |
||
3909 | if( i < MAX_BUFFER - 2){ |
||
3910 | diff = level - eval_x_y(f, x,y); |
||
3911 | if(diff < 0.1 && diff > -0.1){ |
||
3912 | xydata[i++] = x; |
||
3913 | xydata[i++] = y; |
||
3914 | } |
||
3915 | } |
||
3916 | else |
||
3917 | { |
||
3918 | canvas_error("\nYour curve plotting produces too many data \n Use less plotsteps, decrease image size...\nor some other means to reduce the amount of data... "); |
||
3919 | } |
||
3920 | } |
||
3921 | } |
||
3922 | eval_destroy(f); |
||
3923 | return double_xy2js_array(xydata,i,find_number_of_digits(precision)); |
||
3924 | } |
||
3925 | |||
3926 | /* plot parametric function */ |
||
8224 | bpr | 3927 | char *eval_parametric(int xsize,int ysize,char *fun1,char* fun2,double xmin,double xmax,double ymin,double ymax, |
7858 | schaersvoo | 3928 | double tmin,double tmax,int plotsteps,int precision){ |
3929 | void *fx; |
||
3930 | void *fy; |
||
3931 | double t; |
||
3932 | int i = 0; |
||
3933 | double tstep = (tmax-tmin)/plotsteps; |
||
3934 | if( tstep == 0 ){canvas_error("zero step for t variable : reduce plotsteps or inrease trange");} |
||
3935 | fx = eval_create(fun1); |
||
3936 | fy = eval_create(fun2); |
||
3937 | assert(fx); |
||
3938 | assert(fy); |
||
3939 | if( fx == NULL || fy == NULL ){canvas_error("I'm having trouble parsing your \"expression\" ") ;} |
||
3940 | /* we supply the true x/y values...draw_curve() will convert these (x:y) to pixels : used for pan/scale */ |
||
3941 | double xydata[MAX_BUFFER+1];/* hmmm */ |
||
3942 | double x; /* real x-values */ |
||
3943 | double y; /* real y-values */ |
||
8813 | schaersvoo | 3944 | int lim_ymin =(int)( ymin - 4*fabs(ymin));/* 19-4-2015 replacing "abs" by "fabs"*/ |
3945 | int lim_ymax =(int)( ymax + 4*fabs(ymax));/* 19-4-2015 replacing "abs" by "fabs"*/ |
||
7858 | schaersvoo | 3946 | for( t = tmin ;t <= tmax ; t = t + tstep ){ |
3947 | if( i < MAX_BUFFER - 2 ){ |
||
3948 | y = eval_t(fy, t); |
||
3949 | if(y > lim_ymin && y < lim_ymax){ |
||
3950 | x = eval_t(fx, t); |
||
3951 | xydata[i++] = x; |
||
3952 | xydata[i++] = y; |
||
3953 | } |
||
3954 | } |
||
3955 | else |
||
3956 | { |
||
3957 | canvas_error("\nYour curve plotting produces too many data \n Use less plotsteps or some other means to reduce the amount of data... "); |
||
3958 | } |
||
3959 | } |
||
3960 | eval_destroy(fx); |
||
3961 | eval_destroy(fy); |
||
3962 | return double_xy2js_array(xydata,i,find_number_of_digits(precision)); |
||
3963 | } |
||
3964 | |||
3965 | char *double_xy2js_array(double xy[],int len,int decimals){ |
||
8224 | bpr | 3966 | /* |
3967 | 1,2,3,4,5,6,7,8 --> [1,3,5,7],[2,4,6,8] |
||
3968 | int xy[] is already checked for errors or overflow in "get_real()" |
||
3969 | just to be sure we double check the size of "temp" |
||
7858 | schaersvoo | 3970 | */ |
3971 | char temp[2*MAX_BUFFER], *string; |
||
3972 | char *tmp = my_newmem(16);/* <= 9999999999999999 */ |
||
3973 | memset(temp,'\0',2*MAX_BUFFER);/* clear memory */ |
||
3974 | int i;int space_left; |
||
3975 | temp[0] = '[';/* start js-array */ |
||
3976 | for(i = 0; i < len;i = i + 2){ /* x_points[] */ |
||
3977 | if(i == len - 2){sprintf(tmp, "%.*f",decimals, xy[i]);}else{sprintf(tmp, "%.*f,",decimals,xy[i]);} |
||
3978 | space_left = (int) (sizeof(temp) - strlen(temp) - strlen(tmp) - 1); |
||
3979 | if( space_left > 0 ){ strncat(temp,tmp,space_left - 1);}else{canvas_error("can not parse integer to js-array:\nYour curve plotting produces too many data \nreduce your image size or plotsteps ");} |
||
3980 | } |
||
13949 | schaersvoo | 3981 | strncat(temp,"],[",4); /* close js x_values array and start new */ |
7858 | schaersvoo | 3982 | for(i = 1; i < len;i = i + 2){ /* y_points */ |
3983 | if(i == len - 1){ sprintf(tmp, "%.*f",decimals,xy[i]);}else{sprintf(tmp, "%.*f,",decimals,xy[i]);} |
||
3984 | space_left = (int) (sizeof(temp) - strlen(temp) - strlen(tmp) - 1); |
||
3985 | if( space_left > 0 ){ strncat(temp,tmp,space_left - 1);}else{canvas_error("can not parse integer to js-array:\nYour curve plotting produces too many data \nreduce your image size or plotsteps");} |
||
3986 | } |
||
13949 | schaersvoo | 3987 | strncat(temp,"]",2); |
7858 | schaersvoo | 3988 | string=(char *)my_newmem(sizeof(temp)); |
3989 | snprintf(string,sizeof(temp),"%s",temp); |
||
3990 | return string; |
||
3991 | } |
||
3992 | |||
3993 | char *xy2js_array(int xy[],int len){ |
||
8224 | bpr | 3994 | /* |
3995 | 1,2,3,4,5,6,7,8 --> [1,3,5,7],[2,4,6,8] |
||
3996 | int xy[] is already checked for errors or overflow in "get_real()" |
||
3997 | just to be sure we double check the size of "temp" |
||
7858 | schaersvoo | 3998 | */ |
3999 | char temp[MAX_BUFFER], *string; |
||
4000 | char *tmp = my_newmem(16);/* <= 9999999999999999 */ |
||
4001 | memset(temp,'\0',MAX_BUFFER);/* clear memory */ |
||
4002 | int i;int space_left; |
||
4003 | temp[0] = '[';/* start js-array */ |
||
4004 | for(i = 0; i < len;i = i + 2){ /* x_points[] */ |
||
4005 | if(i == len - 2){sprintf(tmp, "%d", xy[i]);}else{sprintf(tmp, "%d,", xy[i]);} |
||
4006 | space_left = (int) (sizeof(temp) - strlen(temp) - strlen(tmp) - 1); |
||
4007 | if( space_left > 0 ){ strncat(temp,tmp,space_left - 1);}else{canvas_error("can not parse integer to js-array:\nYour curve plotting produces too many data \nreduce image size or plotsteps ");} |
||
4008 | } |
||
13949 | schaersvoo | 4009 | strncat(temp,"],[",4); /* close js x_values array and start new */ |
7858 | schaersvoo | 4010 | for(i = 1; i < len;i = i + 2){ /* y_points */ |
4011 | if(i == len - 1){ sprintf(tmp, "%d", xy[i]);}else{sprintf(tmp, "%d,", xy[i]);} |
||
4012 | space_left = (int) (sizeof(temp) - strlen(temp) - strlen(tmp) - 1); |
||
4013 | if( space_left > 0 ){ strncat(temp,tmp,space_left - 1);}else{canvas_error("can not parse integer to js-array:\nYour curve plotting produces too many data\nreduce image size or plotsteps \n");} |
||
4014 | } |
||
13949 | schaersvoo | 4015 | strncat(temp,"]",2); |
7858 | schaersvoo | 4016 | string=(char *)my_newmem(sizeof(temp)); |
4017 | snprintf(string,sizeof(temp),"%s",temp); |
||
4018 | return string; |
||
4019 | } |
||
4020 | |||
4021 | char *data2js_array(int data[],int len){ |
||
8224 | bpr | 4022 | /* |
4023 | 1,2,3,4,5,6,7,8 --> [1,2,3,4,5,6,7,8] |
||
4024 | int data[] is already checked for errors or overflow in "get_real()" |
||
4025 | just to be sure we double check the size of "temp" |
||
7858 | schaersvoo | 4026 | */ |
4027 | char temp[MAX_BUFFER], *string; |
||
4028 | char *tmp = my_newmem(16);/* <= 9999999999999999 */ |
||
4029 | memset(temp,'\0',MAX_BUFFER);/* clear memory */ |
||
4030 | int i;int space_left; |
||
4031 | temp[0] = '[';/* start js-array */ |
||
8224 | bpr | 4032 | for(i = 0; i < len; i++){ |
7858 | schaersvoo | 4033 | if(i == len - 1){sprintf(tmp, "%d", data[i]);}else{sprintf(tmp, "%d,", data[i]);} |
4034 | space_left = (int) (sizeof(temp) - strlen(temp) - strlen(tmp) - 1); |
||
4035 | if( space_left > 0 ){ strncat(temp,tmp,space_left - 1);}else{canvas_error("can not parse integer to js-array:\nYour curve plotting produces too many data \nreduce image size or plotsteps ");} |
||
4036 | } |
||
13949 | schaersvoo | 4037 | strncat(temp,"]",2); |
7858 | schaersvoo | 4038 | string=(char *)my_newmem(sizeof(temp)); |
4039 | snprintf(string,sizeof(temp),"%s",temp); |
||
4040 | return string; |
||
4041 | } |
||
4042 | |||
4043 | |||
7614 | schaersvoo | 4044 | void *my_newmem(size_t size){ |
4045 | void *p; |
||
4046 | if ((p = malloc(size +1)) == NULL){canvas_error("canvasdraw: ran out of memory\n");} |
||
4047 | return p; |
||
4048 | } |
||
4049 | |||
4050 | int find_number_of_digits(int i){ |
||
4051 | if(i < 0 ){ i = -1*i;} |
||
4052 | int digits = 0; |
||
4053 | while ( i > 0){ |
||
4054 | digits++; |
||
4055 | i = i/10; |
||
4056 | } |
||
4057 | return digits; |
||
4058 | } |
||
8225 | bpr | 4059 | |
4060 | struct colors colors[]={ |
||
7614 | schaersvoo | 4061 | {"#FF0000","red","255,0,0"}, |
4062 | {"#00FF00","lime","0,255,0"}, |
||
4063 | {"#0000FF","blue","0,0,255"}, |
||
4064 | {"#FFA500","orange","255,165,0"}, |
||
4065 | {"#E9967A","darksalmon","233,150,122"}, |
||
4066 | {"#F0FFFF","azure","240,255,255"}, |
||
4067 | {"#CD5C5C","indianred","205,92,92"}, |
||
4068 | {"#E0FFFF","lightcyan","224,255,255"}, |
||
4069 | {"#FFE4E1","mistyrose","255,228,225"}, |
||
4070 | {"#DC143C","crimson","220,20,60"}, |
||
4071 | {"#FFC0CB","pink","255,192,203"}, |
||
4072 | {"#FFD700","gold","255,215,0"}, |
||
4073 | {"#E6E6FA","lavender","230,230,250"}, |
||
4074 | {"#808080","gray","128,128,128"}, |
||
4075 | {"#F0F8FF","aliceblue","240,248,255"}, |
||
4076 | {"#C71585","mediumvioletred","199,21,133"}, |
||
4077 | {"#FFF0F5","lavenderblush","255,240,245"}, |
||
4078 | {"#DAA520","goldenrod","218,165,32"}, |
||
4079 | {"#FFB6C1","lightpink","255,182,193"}, |
||
4080 | {"#00FFFF","aqua","0,255,255"}, |
||
4081 | {"#FF69B4","hotpink","255,105,180"}, |
||
4082 | {"#00FFFF","cyan","0,255,255"}, |
||
4083 | {"#FF1493","deeppink","255,20,147"}, |
||
4084 | {"#7FFFD4","aquamarine","127,255,212"}, |
||
4085 | {"#FA8072","salmon","250,128,114"}, |
||
4086 | {"#DEB887","burlywood","222,184,135"}, |
||
4087 | {"#DB7093","palevioletred","219,112,147"}, |
||
4088 | {"#D2B48C","tan","210,180,140"}, |
||
4089 | {"#BDB76B","darkkhaki","189,183,107"}, |
||
4090 | {"#B22222","firebrick","178,34,34"}, |
||
4091 | {"#FF4500","orangered","255,69,0"}, |
||
4092 | {"#8B4513","saddlebrown","139,69,19"}, |
||
4093 | {"#FF8C00","darkorange","255,140,0"}, |
||
4094 | {"#FFFFE0","lightyellow","255,255,224"}, |
||
4095 | {"#FFFF00","yellow","255,255,0"}, |
||
4096 | {"#FFFACD","lemonchiffon","255,250,205"}, |
||
4097 | {"#F5F5DC","beige","245,245,220"}, |
||
4098 | {"#FFEFD5","papayawhip","255,239,213"}, |
||
4099 | {"#FAFAD2","lightgoldenrodyellow","250,250,210"}, |
||
4100 | {"#FFE4B5","moccasin","255,228,181"}, |
||
4101 | {"#B8860B","darkgoldenrod","184,134,11"}, |
||
4102 | {"#FFF8DC","cornsilk","255,248,220"}, |
||
4103 | {"#FFEBCD","blanchedalmond","255,235,205"}, |
||
4104 | {"#FFE4C4","bisque","255,228,196"}, |
||
4105 | {"#FFDEAD","navajowhite","255,222,173"}, |
||
4106 | {"#F5DEB3","wheat","245,222,179"}, |
||
4107 | {"#CD853F","peru","205,133,63"}, |
||
4108 | {"#D2691E","chocolate","210,105,30"}, |
||
4109 | {"#A0522D","sienna","160,82,45"}, |
||
4110 | {"#A52A2A","brown","165,42,42"}, |
||
4111 | {"#BC8F8F","rosybrown","188,143,143"}, |
||
4112 | {"#F08080","lightcoral","240,128,128"}, |
||
4113 | {"#FFA07A","lightsalmon","255,160,122"}, |
||
4114 | {"#8B0000","darkred","139,0,0"}, |
||
4115 | {"#800000","maroon","128,0,0"}, |
||
4116 | {"#FAA460","sandybrown","250,164,96"}, |
||
4117 | {"#FF7F50","coral","255,127,80"}, |
||
4118 | {"#FF6347","tomato","255,99,71"}, |
||
4119 | {"#FFDAB9","peachpuff","255,218,185"}, |
||
4120 | {"#EEE8AA","palegoldenrod","238,232,170"}, |
||
4121 | {"#F0E68C","khaki","240,230,140"}, |
||
4122 | {"#D8BFD8","thistle","216,191,216"}, |
||
4123 | {"#DDA0DD","plum","221,160,221"}, |
||
4124 | {"#FF00FF","fuchsia","255,0,255"}, |
||
4125 | {"#FF00FF","magenta","255,0,255"}, |
||
4126 | {"#EE82EE","violet","238,130,238"}, |
||
4127 | {"#DA70D6","orchid","218,112,214"}, |
||
4128 | {"#BA55D3","mediumorchid","186,85,211"}, |
||
4129 | {"#9370DB","mediumpurple","147,112,219"}, |
||
4130 | {"#8A2BE2","blueviolet","138,43,226"}, |
||
4131 | {"#9400D3","darkviolet","148,0,211"}, |
||
4132 | {"#9932CC","darkorchid","153,50,204"}, |
||
4133 | {"#8B008B","darkmagenta","139,0,139"}, |
||
4134 | {"#800080","purple","128,0,128"}, |
||
4135 | {"#4B0082","indigo","75,0,130"}, |
||
4136 | {"#483D8B","darkslateblue","72,61,139"}, |
||
4137 | {"#6A5ACD","slateblue","106,90,205"}, |
||
4138 | {"#7B68EE","mediumslateblue","123,104,238"}, |
||
4139 | {"#98FB98","palegreen","152,251,152"}, |
||
4140 | {"#ADFF2F","greenyellow","173,255,47"}, |
||
4141 | {"#7FFF00","chartreuse","127,255,0"}, |
||
4142 | {"#7CFC00","lawngreen","124,252,0"}, |
||
4143 | {"#00FF7F","springgreen","0,255,127"}, |
||
4144 | {"#00FA9A","mediumspringgreen","0,250,154"}, |
||
4145 | {"#90EE90","lightgreen","144,238,144"}, |
||
4146 | {"#32CD32","limegreen","50,205,50"}, |
||
4147 | {"#3CB371","mediumseagreen","60,179,113"}, |
||
4148 | {"#2E8B57","seagreen","46,139,87"}, |
||
4149 | {"#228B22","forestgreen","34,139,34"}, |
||
4150 | {"#008000","green","0,128,0"}, |
||
4151 | {"#006400","darkgreen","0,100,0"}, |
||
4152 | {"#9ACD32","yellowgreen","154,205,50"}, |
||
4153 | {"#6B8E23","olivedrab","107,142,35"}, |
||
4154 | {"#808000","olive","128,128,0"}, |
||
4155 | {"#556B2F","darkolivegreen","85,107,47"}, |
||
4156 | {"#8FBC8F","darkseagreen","143,188,143"}, |
||
4157 | {"#66CDAA","mediumaquamarine","102,205,170"}, |
||
4158 | {"#20B2AA","lightseagreen","32,178,170"}, |
||
4159 | {"#008B8B","darkcyan","0,139,139"}, |
||
4160 | {"#008080","teal","0,128,128"}, |
||
4161 | {"#AFEEEE","paleturquoise","175,238,238"}, |
||
4162 | {"#40E0D0","turquoise","64,224,208"}, |
||
4163 | {"#48D1CC","mediumturquoise","72,209,204"}, |
||
4164 | {"#00CED1","darkturquoise","0,206,209"}, |
||
4165 | {"#5F9EA0","cadetblue","95,158,160"}, |
||
4166 | {"#4682B4","steelblue","70,130,180"}, |
||
4167 | {"#B0C4DE","lightsteelblue","176,196,222"}, |
||
4168 | {"#B0E0E6","powderblue","176,224,230"}, |
||
4169 | {"#ADD8E6","lightblue","173,216,230"}, |
||
4170 | {"#87CEEB","skyblue","135,206,235"}, |
||
4171 | {"#87CEFA","lightskyblue","135,206,250"}, |
||
4172 | {"#00BFFF","deepskyblue","0,191,255"}, |
||
4173 | {"#1E90FF","dodgerblue","30,144,255"}, |
||
4174 | {"#6495ED","cornflowerblue","100,149,237"}, |
||
4175 | {"#4169E1","royalblue","65,105,225"}, |
||
4176 | {"#0000CD","mediumblue","0,0,205"}, |
||
4177 | {"#00008B","darkblue","0,0,139"}, |
||
4178 | {"#000080","navy","0,0,128"}, |
||
4179 | {"#191970","midnightblue","25,25,112"}, |
||
4180 | {"#DCDCDC","gainsboro","220,220,220"}, |
||
4181 | {"#D3D3D3","lightgrey","211,211,211"}, |
||
4182 | {"#808080","grey","128,128,128"}, |
||
4183 | {"#C0C0C0","silver","192,192,192"}, |
||
4184 | {"#A9A9A9","darkgray","169,169,169"}, |
||
4185 | {"#778899","lightslategray","119,136,153"}, |
||
4186 | {"#708090","slategray","112,128,144"}, |
||
4187 | {"#696969","dimgray","105,105,105"}, |
||
4188 | {"#2F4F4F","darkslategray","47,79,79"}, |
||
11877 | schaersvoo | 4189 | {"#0a0a0a","black","10,10,10"}, |
7614 | schaersvoo | 4190 | {"#F5FFFA","mintcream","245,255,250"}, |
4191 | {"#FFFFFF","white","255,255,255"}, |
||
4192 | {"#F0FFF0","honeydew","240,255,240"}, |
||
4193 | {"#F5F5F5","whitesmoke","245,245,245"}, |
||
4194 | {"#F8F8FF","ghostwhite","248,248,255"}, |
||
4195 | {"#FFFFF0","ivory","255,255,240"}, |
||
4196 | {"#FFFAFA","snow","255,250,250"}, |
||
4197 | {"#FFFAF0","floralwhite","255,250,240"}, |
||
4198 | {"#FFF5EE","seashell","255,245,238"}, |
||
4199 | {"#FDF5E6","oldlace","253,245,230"}, |
||
4200 | {"#FAF0E6","linen","250,240,230"}, |
||
4201 | {"#FAEBD7","antiquewhite","250,235,215"}, |
||
4202 | }; |
||
8225 | bpr | 4203 | int NUMBER_OF_COLORNAMES=(sizeof(colors)/sizeof(colors[0])); |
7858 | schaersvoo | 4204 | |
8257 | schaersvoo | 4205 | void add_drag_code(FILE *js_include_file,int canvas_cnt,int canvas_root_id ){ |
7875 | schaersvoo | 4206 | /* in drag& drop / onclick library: |
8363 | schaersvoo | 4207 | obj_type = 1 == rect / rects |
7875 | schaersvoo | 4208 | obj_type = 2 == point / points (do not scale with zoom) |
8224 | bpr | 4209 | obj_type = 3 == ellipse |
8304 | schaersvoo | 4210 | obj_type = 4 == polyline / segment / segments /line / vline / hline |
7875 | schaersvoo | 4211 | obj_type = 5 == closed path (polygon) |
8370 | schaersvoo | 4212 | obj_type = 6 == roundrect /roundrects |
7875 | schaersvoo | 4213 | obj_type = 7 == crosshair / crosshairs |
8304 | schaersvoo | 4214 | obj_type = 8 == arrow / arrows |
7875 | schaersvoo | 4215 | obj_type = 9 == curve |
8349 | schaersvoo | 4216 | obj_type = 10== arrow2 / arrows2 |
8224 | bpr | 4217 | obj_type = 11== parallel (no drag or onclick) |
8105 | schaersvoo | 4218 | obj_type = 12== arc : radius is in pixels , so no zooming in/out |
8304 | schaersvoo | 4219 | obj_type = 13== circle / circles (will scale on zoom) |
7875 | schaersvoo | 4220 | obj_type = 14== text (will not scale or pan on zoom) |
4221 | obj_type = 15== animated point on curve |
||
4222 | obj_type = 16== pixels |
||
8105 | schaersvoo | 4223 | obj_type = 17== new arc [command angle] :radius in x-range, so will scale on zooming in/out |
8244 | schaersvoo | 4224 | obj_type = 18== halfline |
9427 | schaersvoo | 4225 | obj_type = 19== yerrorbars |
4226 | obj_type = 20== xerrorbars |
||
14029 | schaersvoo | 4227 | obj_type = 21== curvedarrow |
14948 | obado | 4228 | |
8448 | schaersvoo | 4229 | arc |
14948 | obado | 4230 | x[0] = x[1] = xc = double_data[0] |
4231 | y[0] = y[1] = yc = double_data[1] |
||
4232 | w[0] = width = int_data[0] |
||
4233 | w[1] = height = int_data[1] |
||
4234 | h[0] = start_angle = double_data[2] |
||
4235 | h[1] = end_angle = double_data[3] |
||
8448 | schaersvoo | 4236 | myState.selection.line_width = org_line_width;myState.selection.font_family = org_font_family;break;\ |
4237 | |||
12063 | schaersvoo | 4238 | use_offset only for text shape objects... |
4239 | 0=none; |
||
4240 | 1=yoffset |
||
4241 | 2=xoffset |
||
4242 | 3=xyoffset |
||
4243 | 4=centered |
||
14044 | schaersvoo | 4244 | |
14948 | obado | 4245 | int onclick = 0; 0 = noninteractive ; 1 = onclick ; 2 = draggable |
4246 | type= object type |
||
14044 | schaersvoo | 4247 | |
4248 | verwijderd: direction : dragging in xy=0 , in x=1 in y=2 vervangen dooor use_snap en multisnap_check(x,y,use_snap) |
||
14948 | obado | 4249 | use_snap: 0 = none 1=grid : 2=x-grid : 3=y-grid : 4=snap to points |
14208 | schaersvoo | 4250 | |
4251 | obj.angle == RADIANS! |
||
7875 | schaersvoo | 4252 | */ |
14038 | schaersvoo | 4253 | fprintf(js_include_file,"\n/* begin drag_drop_onclick shape library */\n\ |
11088 | schaersvoo | 4254 | if( typeof(dragdrop_precision) == 'undefined' ){var dragdrop_precision = 100;};\ |
14208 | schaersvoo | 4255 | function Shape(drag_type,click_cnt,onclick,use_snap,type,x,y,w,h,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype0,dashtype1,use_rotate,angle,text,font_size,font_family,use_affine,affine_matrix,use_slider,rotation_center,use_offset,use_pattern){\ |
14045 | schaersvoo | 4256 | this.drag_type = drag_type || 0;\ |
11837 | schaersvoo | 4257 | this.stroke_opacity = stroke_opacity || 1.0;\ |
4258 | this.stroke_color = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\" || '#FF0000';\ |
||
4259 | this.fill_opacity = fill_opacity || 1.0;\ |
||
4260 | this.fill_color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\" || '#FF0000';\ |
||
4261 | this.use_pattern = use_pattern || 0;\ |
||
11854 | schaersvoo | 4262 | if( use_pattern > 0 ){ this.pattern = create_Pattern(x,y,this.use_pattern,this.fill_color); }else{ this.pattern = 0; }\ |
14208 | schaersvoo | 4263 | this.use_slider = use_slider || -1;\ |
7875 | schaersvoo | 4264 | this.text = text || 0;\ |
4265 | this.font_size = font_size || 12;\ |
||
12063 | schaersvoo | 4266 | this.font_family = font_family || this.font_size+'px Ariel';\ |
14542 | schaersvoo | 4267 | this.org_font_family = this.font_family;\ |
4268 | this.textwidth = 0;\ |
||
4269 | this.textheight = 0;\ |
||
7875 | schaersvoo | 4270 | this.use_rotate = use_rotate || 0;\ |
4271 | this.angle = angle*(Math.PI/180) || 0;\ |
||
4272 | this.use_affine = use_affine || 0;\ |
||
4273 | this.affine_matrix = affine_matrix || [1,0,0,1,0,0];\ |
||
8448 | schaersvoo | 4274 | this.click_cnt = click_cnt || 0;\ |
7875 | schaersvoo | 4275 | this.onclick = onclick || 0;\ |
8448 | schaersvoo | 4276 | if(this.onclick == 1 ){reply[click_cnt] = 0;};\ |
14044 | schaersvoo | 4277 | this.use_snap = use_snap || 0;\ |
7875 | schaersvoo | 4278 | this.type = type || 1;\ |
14208 | schaersvoo | 4279 | if( type == 17 || type == 12 ){dragstuff.slidergroup.push(click_cnt);};\ |
7875 | schaersvoo | 4280 | this.xorg = x;\ |
4281 | this.yorg = y;\ |
||
11805 | schaersvoo | 4282 | this.use_once = true;\ |
7875 | schaersvoo | 4283 | this.x = [x.length];\ |
4284 | this.y = [x.length];\ |
||
4285 | this.w = [x.length];\ |
||
4286 | this.h = [x.length];\ |
||
4287 | for(var p=0;p<x.length;p++){\ |
||
7976 | schaersvoo | 4288 | this.x[p] = x2px(x[p]-xstart);\ |
4289 | this.y[p] = y2px(y[p]-ystart);\ |
||
7875 | schaersvoo | 4290 | if( p > w.length){\ |
4291 | this.w[p] = w[0];\ |
||
4292 | this.h[p] = h[0];\ |
||
4293 | }\ |
||
4294 | else\ |
||
4295 | {\ |
||
4296 | this.w[p] = w[p];\ |
||
4297 | this.h[p] = h[p];\ |
||
4298 | }\ |
||
4299 | };\ |
||
9907 | schaersvoo | 4300 | if( rotation_center != null ){\ |
14174 | schaersvoo | 4301 | this.use_rotation_center = 1;\ |
9907 | schaersvoo | 4302 | this.rotation_center = [x2px(rotation_center[0]),y2px(rotation_center[1])];\ |
14174 | schaersvoo | 4303 | }else{this.use_rotation_center = 0;this.rotation_center = [this.x[0],this.y[0]];};\ |
7875 | schaersvoo | 4304 | this.line_width = line_width || 30;\ |
8448 | schaersvoo | 4305 | this.org_line_width = line_width || 30;\ |
7875 | schaersvoo | 4306 | this.use_filled = use_filled || 0;\ |
4307 | this.use_dashed = use_dashed || 0;\ |
||
4308 | this.dashtype0 = dashtype0 || 4;\ |
||
4309 | this.dashtype1 = dashtype1 || 4;\ |
||
11802 | schaersvoo | 4310 | this.use_offset = use_offset || 0;\ |
11854 | schaersvoo | 4311 | };\ |
4312 | var create_Pattern = function(x0,y0,type,color){\ |
||
4313 | document.body.style.cursor = 'wait';\ |
||
11837 | schaersvoo | 4314 | var idx = Math.ceil(1000*(Math.random()));\ |
4315 | var canvas = create_canvas%d(idx,xsize,ysize);\ |
||
4316 | canvas.style.visibility = 'hidden';\ |
||
4317 | var ctx = canvas.getContext(\"2d\");\ |
||
4318 | var x;var y;var dx = 6;var dy = 6;\ |
||
4319 | ctx.lineWidth = 1;\ |
||
4320 | ctx.strokeStyle = color;\ |
||
4321 | ctx.fillStyle = color;\ |
||
11854 | schaersvoo | 4322 | var pat;\ |
11837 | schaersvoo | 4323 | switch(type){\ |
11854 | schaersvoo | 4324 | case 2: for( x = 0 ; x < xsize ; x = x + dx ){ctx.beginPath();ctx.moveTo(x,0);ctx.lineTo(x,ysize);ctx.closePath();ctx.stroke();};for( y = 0 ; y < ysize; y = y + dy ){ctx.beginPath();ctx.moveTo(0,y);ctx.lineTo(xsize,y);ctx.closePath();ctx.stroke();}; pat = ctx.createPattern(canvas,\"no-repeat\");break;\ |
4325 | case 3: y = ysize;ctx.beginPath();for( x = 0 ; x < xsize ; x = x + dx ){ctx.moveTo(x,0);ctx.lineTo(xsize,y);y = y - dy;};y = 0;for( x = xsize ; x > 0 ; x = x - dx){ctx.moveTo(x,ysize);ctx.lineTo(0,y); y = y + dy;};ctx.closePath();ctx.stroke(); pat = ctx.createPattern(canvas,\"no-repeat\");break;\ |
||
4326 | case 4: y = ysize;ctx.beginPath();for( x = 0 ; x < xsize ; x = x + dx ){ctx.moveTo(x,0); ctx.lineTo(xsize,y); y = y - dy;};y = 0;for( x = xsize ; x > 0 ; x = x - dx){ctx.moveTo(x,ysize);ctx.lineTo(0,y);y = y + dy;};y = 0;for( x = 0 ; x < xsize ; x = x + dx ){ctx.moveTo(x,0); ctx.lineTo(0,y); y = y + dy;};y = 0;for( x = 0 ; x < xsize ; x = x + dx ){ctx.moveTo(xsize,y);ctx.lineTo(x,ysize);y = y + dy;};ctx.closePath(); ctx.stroke(); pat = ctx.createPattern(canvas,\"no-repeat\");break;\ |
||
4327 | case 5: for( x = 0 ; x < xsize ; x = x + dx ){for( y = 0 ; y < ysize ; y = y + dy ){ctx.beginPath();ctx.arc(x,y,1,0,2*Math.PI,false);ctx.closePath();ctx.fill();};}; pat = ctx.createPattern(canvas,\"no-repeat\");break;\ |
||
11874 | schaersvoo | 4328 | case 6: alert('wait for image '+(image_cnt+1)+'...');pat = image_patterns[image_cnt];image_cnt++;break;\ |
4329 | default: break;\ |
||
11854 | schaersvoo | 4330 | };\ |
4331 | document.body.style.cursor = 'default';\ |
||
11837 | schaersvoo | 4332 | return pat;\ |
7875 | schaersvoo | 4333 | };\ |
4334 | Shape.prototype.draw = function(ctx)\ |
||
4335 | {\ |
||
4336 | ctx.lineWidth = this.line_width;\ |
||
4337 | ctx.strokeStyle = this.stroke_color;\ |
||
11837 | schaersvoo | 4338 | if( this.use_pattern > 0 ){ ctx.fillStyle = this.pattern; }else{ ctx.fillStyle = this.fill_color; };\ |
7875 | schaersvoo | 4339 | ctx.lineJoin = \"round\";\ |
4340 | ctx.save();\ |
||
4341 | if(this.use_rotate == 1){\ |
||
9907 | schaersvoo | 4342 | ctx.translate(this.rotation_center[0],this.rotation_center[1]);\ |
4343 | ctx.rotate(this.angle);\ |
||
4344 | ctx.translate(-1*(this.rotation_center[0]),-1*(this.rotation_center[1]));\ |
||
8105 | schaersvoo | 4345 | };\ |
7875 | schaersvoo | 4346 | if( this.use_affine == 1 ){\ |
4347 | ctx.setTransform(this.affine_matrix[0],this.affine_matrix[1],this.affine_matrix[2],this.affine_matrix[3],this.affine_matrix[4],this.affine_matrix[5]);\ |
||
4348 | };\ |
||
14032 | schaersvoo | 4349 | function drawCurvedArrow(x1,y1,x3,y3,x2,y2,arrowhead,type){ctx.save();var angle1 = Math.atan2(x3 - x2,y3 - y2) + Math.PI;ctx.beginPath();if(type == 2){var angle2 =Math.atan2(x3 - x1,y3 - y1) + Math.PI;ctx.moveTo(x1,y1);ctx.moveTo(x1 - (arrowhead * Math.sin(angle2 - Math.PI / 6)),y1 - (arrowhead * Math.cos(angle2 - Math.PI / 6)));ctx.lineTo(x1, y1);ctx.lineTo(x1 - (arrowhead * Math.sin(angle2 + Math.PI / 6)),y1 - (arrowhead * Math.cos(angle2 + Math.PI / 6)));};ctx.moveTo(x1,y1);ctx.quadraticCurveTo(x3,y3,x2,y2);ctx.moveTo(x2 - (arrowhead * Math.sin(angle1 - Math.PI / 6)),y2 - (arrowhead * Math.cos(angle1 - Math.PI / 6)));ctx.lineTo(x2, y2);ctx.lineTo(x2 - (arrowhead * Math.sin(angle1 + Math.PI / 6)),y2 - (arrowhead * Math.cos(angle1 + Math.PI / 6)));ctx.stroke();ctx.closePath();ctx.restore();};\ |
14038 | schaersvoo | 4350 | ctx.beginPath();\ |
9462 | schaersvoo | 4351 | switch(this.type){\ |
8370 | schaersvoo | 4352 | case 1: for(var p = 0 ; p < this.x.length;p = p+4){ctx.rect(this.x[p], this.y[p], this.x[p+1]-this.x[p], this.y[p+2] - this.y[p]);};break;\ |
8448 | schaersvoo | 4353 | case 2: ctx.arc(this.x[0],this.y[0],0.5*this.w[0],0,2*Math.PI,false);break;\ |
8071 | schaersvoo | 4354 | case 3: ctx.save();var w = 0.5*(scale_x_radius(this.w[0]));var h = 0.5*(scale_y_radius(this.h[0]));ctx.scale(1,h/w);ctx.beginPath();ctx.arc(this.x[0], w/h*this.y[0], w, 0, 2 * Math.PI);if(this.use_filled == 1){ ctx.fillStyle = this.fill_color; ctx.fill(); };ctx.closePath();ctx.stroke();ctx.restore();break;\ |
7875 | schaersvoo | 4355 | case 4: for(var p = 0; p < this.x.length - 1;p++){ctx.moveTo(this.x[p], this.y[p]);ctx.lineTo(this.x[p+1],this.y[p+1]);};break;\ |
9462 | schaersvoo | 4356 | case 5: ctx.moveTo(this.x[0],this.y[0]);for(var p = 1; p < this.x.length;p++){ctx.lineTo(this.x[p],this.y[p]);};ctx.lineTo(this.x[0],this.y[0]);break;\ |
7875 | schaersvoo | 4357 | case 6: var w = this.x[1] - this.x[0];var h = this.y[1] - this.y[0];var r = this.w[0];ctx.beginPath();ctx.moveTo(this.x[0] + r, this.y[0]);ctx.lineTo(this.x[0] + w - r, this.y[0]);ctx.quadraticCurveTo(this.x[0] + w, this.y[0], this.x[0] + w, this.y[0] + r);ctx.lineTo(this.x[0] + w, this.y[0] + h - r);ctx.quadraticCurveTo(this.x[0] + w, this.y[0] + h, this.x[0] + w - r, this.y[0] + h);ctx.lineTo(this.x[0] + r, this.y[0] + h);ctx.quadraticCurveTo(this.x[0], this.y[0] + h, this.x[0], this.y[0] + h - r);ctx.lineTo(this.x[0], this.y[0] + r);ctx.quadraticCurveTo(this.x[0], this.y[0], this.x[0] + r, this.y[0]);ctx.closePath();break;\ |
4358 | case 7: ctx.moveTo(this.x[0]-this.w[0],this.y[0]-this.h[0]);ctx.lineTo(this.x[0]+this.w[0],this.y[0]+this.h[0]);ctx.moveTo(this.x[0]-this.w[0],this.y[0]+this.h[0]);ctx.lineTo(this.x[0]+this.w[0],this.y[0]-this.h[0]);break;\ |
||
8814 | schaersvoo | 4359 | case 8: var dx;var dy;var len;var arrow_head = this.w[0];for(var p = 0; p < this.x.length - 1;p++){ctx.save();if(this.use_dashed == 1 ){if( ctx.setLineDash ){ ctx.setLineDash([this.dashtype0,this.dashtype1]);}else{ ctx.mozDash = [this.dashtype0,this.dashtype1];};};dx = this.x[p+1] - this.x[p];dy = this.y[p+1] - this.y[p];len = Math.sqrt(dx*dx+dy*dy);ctx.translate(this.x[p+1],this.y[p+1]);ctx.rotate(Math.atan2(dy,dx));ctx.lineCap = \"round\";ctx.beginPath();ctx.moveTo(0,0);ctx.lineTo(-len,0);ctx.closePath();ctx.stroke();ctx.beginPath();ctx.moveTo(0,0);ctx.lineTo(-1*arrow_head,-0.5*arrow_head);ctx.lineTo(-1*arrow_head, 0.5*arrow_head);ctx.closePath();ctx.fill();ctx.restore();};break;\ |
7875 | schaersvoo | 4360 | case 9: ctx.moveTo(this.x[0], this.y[0]);for(var p = 1; p < this.x.length - 1;p++){if( Math.abs(this.y[p] - this.y[p-1]) < ysize && Math.abs(this.y[p+1] - this.y[p]) < ysize ){ctx.lineTo(this.x[p],this.y[p]);}else{ctx.moveTo(this.x[p],this.y[p]);};};break;\ |
8349 | schaersvoo | 4361 | case 10: var dx;var dy;var len;ctx.save();if(this.use_dashed == 1 ){if( ctx.setLineDash ){ ctx.setLineDash([this.dashtype0,this.dashtype1]);}else{ ctx.mozDash = [this.dashtype0,this.dashtype1];};};dx = this.x[1] - this.x[0];dy = this.y[1] - this.y[0];len = Math.sqrt(dx*dx+dy*dy);ctx.translate(this.x[1],this.y[1]);ctx.rotate(Math.atan2(dy,dx));ctx.beginPath();ctx.moveTo(0,0);ctx.lineTo(-len,0);ctx.closePath();ctx.stroke();ctx.beginPath();ctx.moveTo(0,0);ctx.lineTo(-1*this.w[0],0.5*this.w[0]);ctx.lineTo(-1*this.w[0],-0.5*this.w[0]);ctx.closePath();ctx.lineCap = \"round\";ctx.fill();ctx.restore();ctx.save();ctx.translate(this.x[0],this.y[0]);ctx.rotate(Math.atan2(dy,dx));ctx.beginPath();ctx.moveTo(0,0);ctx.lineTo(this.w[0],0.4*this.w[0]);ctx.lineTo(this.w[0],-0.4*this.w[0]);ctx.closePath();ctx.lineCap = \"round\";ctx.fill(); break;\ |
7875 | schaersvoo | 4362 | case 11: var x1 = this.x[0];var y1 = this.y[0];var x2 = this.x[1];var y2 = this.y[1];var dx = this.x[2];var dy = this.y[2];var n = this.w[0];for(var p = 0 ; p < n ; p++ ){ctx.beginPath();ctx.moveTo(x1,y1);ctx.lineTo(x2,y2);ctx.stroke();x1 = x1 + dx;y1 = y1 + dy;x2 = x2 + dx;y2 = y2 + dy;ctx.closePath();};break;\ |
14782 | schaersvoo | 4363 | case 12: ctx.save();var start;var end;if(this.h[0] < this.h[1]){start = this.h[0];end = this.h[1]}else{start = this.h[1];end = this.h[0];};start=(360-start)*Math.PI/180;end=(360-end)*Math.PI/180;var w = 0.5*(scale_x_radius(this.w[0]));var wh = 0.5*(scale_y_radius(this.w[1]));ctx.scale(1,wh/w);ctx.arc(this.x[0], w/(wh)*this.y[0], w,start,end,true);ctx.stroke();if(this.use_filled == 1){ ctx.fillStyle = this.fill_color; ctx.lineTo(this.x[0],this.y[0]);ctx.fill(); };ctx.restore();break;\ |
8304 | schaersvoo | 4364 | case 13: for(var p = 0; p < this.x.length; p++){ ctx.arc(this.x[p],this.y[p],scale_x_radius(this.w[p]),0,2*Math.PI,false);};break;\ |
14545 | schaersvoo | 4365 | case 14: if( this.font_family == null ){ ctx.font = this.font_size+\"px Ariel\";}else{ctx.font = this.font_family ;};if( this.use_once == true ){this.marge = 2*this.line_width;this.textwidth = ctx.measureText(this.text).width;this.textheight = ctx.measureText('MI').width;};if( this.use_offset > 0 && this.use_once == true ){this.use_once = false;if(this.use_offset == 1){this.y[0] = this.y[0] - this.marge;}else{if(this.use_offset == 2){this.x[0] = this.x[0] + this.marge;}else{if(this.use_offset == 3){this.y[0] = this.y[0] - this.marge;this.x[0] = this.x[0] + this.marge;}else{if(this.use_offset == 4){this.y[0] = parseInt(this.y[0] + 0.25*(this.textheight));this.x[0] = parseInt(this.x[0] - 0.5*(this.textwidth));};};};};};ctx.fillText(this.text,this.x[0],this.y[0]);break;\ |
8108 | schaersvoo | 4366 | case 15: break;\ |
7875 | schaersvoo | 4367 | case 16: for(var p = 0; p < this.x.length;p++){ctx.fillRect( this.x[p], this.y[p],this.line_width,this.line_width );};break;\ |
14208 | schaersvoo | 4368 | case 17: ctx.save();var start;var end;if(this.h[0] < this.h[1]){start = this.h[0];end = this.h[1]}else{start = this.h[1];end = this.h[0];};start=2*Math.PI-start;end=2*Math.PI-end;var r = scale_x_radius(this.w[0]);ctx.arc(this.x[0], this.y[0], r,start,end,true);if(this.use_filled){ctx.lineTo(this.x[0],this.y[0]);ctx.fill();};ctx.restore();break;\ |
8370 | schaersvoo | 4369 | case 18: for(var p=0 ; p < this.x.length ;p=p+2){ctx.moveTo(this.x[p], this.y[p]);ctx.lineTo(this.x[p+1],this.y[p+1]);};break;\ |
9427 | schaersvoo | 4370 | case 19: ctx.arc(this.x[0],this.y[0],this.line_width,0,2*Math.PI,false);var E1 = y2px(px2y(this.y[0]) - this.h[0]);var E2 = y2px(px2y(this.y[0]) + this.w[0]);ctx.moveTo(this.x[0],E1);ctx.lineTo(this.x[0],E2);ctx.moveTo(this.x[0] - 2*(this.line_width),E1);ctx.lineTo(this.x[0] + 2*(this.line_width),E1);ctx.moveTo(this.x[0] - 2*(this.line_width),E2);ctx.lineTo(this.x[0] + 2*(this.line_width),E2);break;\ |
4371 | case 20: ctx.arc(this.x[0],this.y[0],this.line_width,0,2*Math.PI,false);var E1 = x2px(px2x(this.x[0]) - this.w[0]);var E2 = x2px(px2x(this.x[0]) + this.h[0]);ctx.moveTo(E1,this.y[0]);ctx.lineTo(E2,this.y[0]);ctx.moveTo(E1,this.y[0]-2*(this.line_width));ctx.lineTo(E1,this.y[0]+2*(this.line_width));ctx.moveTo(E2,this.y[0]-2*(this.line_width));ctx.lineTo(E2,this.y[0]+2*(this.line_width));break;\ |
||
14038 | schaersvoo | 4372 | case 21: drawCurvedArrow(this.x[0],this.y[0],this.x[1],this.y[1],this.x[2],this.y[2],this.h[0],this.h[1]);break;\ |
7875 | schaersvoo | 4373 | default: alert(\"draw primitive unknown\");break;\ |
4374 | };\ |
||
4375 | if(this.use_filled == 1){ ctx.fill();}\ |
||
4376 | if(this.use_dashed == 1 ){if( ctx.setLineDash ){ ctx.setLineDash([this.dashtype0,this.dashtype1]);}else{ ctx.mozDash = [this.dashtype0,this.dashtype1];};};\ |
||
4377 | ctx.stroke();\ |
||
4378 | ctx.restore();\ |
||
4379 | };\ |
||
4380 | Shape.prototype.contains = function(mx, my){\ |
||
14546 | schaersvoo | 4381 | if( this.angle != 0 ){ var m_rot = rotate_mouse(mx,my,this);mx = m_rot.x;my = m_rot.y;};\ |
14548 | schaersvoo | 4382 | if( this.use_affine != 0 ){ var m_trans = transform_mouse(mx,my,this);mx = m_trans.x;my = m_trans.y;};\ |
7875 | schaersvoo | 4383 | var marge = 2*this.line_width;\ |
4384 | switch(this.type){\ |
||
4385 | case 1: for(var p = 0 ; p < this.x.length; p++ ){if( mx < this.x[p] + marge && mx > this.x[p] - marge ){if( my < this.y[p]+marge && my > this.y[p] - marge ){return p;};};};break;\ |
||
9270 | schaersvoo | 4386 | case 2: for(var p = 0 ; p < this.x.length; p++ ){if( Math.abs(distance(this.x[p],this.y[p],mx,my) ) < this.w[p] + 4*marge ){return p;break;};};break;\ |
7875 | schaersvoo | 4387 | case 3: for(var p = 0 ; p < this.x.length; p++ ){if( Math.abs(distance(this.x[p],this.y[p],mx,my) ) < scale_x_radius(this.w[p]) + marge ){return p;break;};};break;\ |
4388 | case 4: var diff;var q;var r;for(var p = 0 ; p < this.x.length-1; p = p+2 ){if( ((this.x[p+1] - this.x[p]) != 0) && ((this.y[p+1]-this.y[p]) != 0) ){r = (this.y[p+1]-this.y[p])/(this.x[p+1]-this.x[p]);q = this.y[p] - (r)*(this.x[p]);diff = distance_to_line(r,q,mx,my);}else{if( (this.y[p+1]-this.y[p]) != 0 ){diff = Math.abs(this.x[p] - mx);}else{diff = Math.abs(this.y[p] - my);};};if( diff < marge ){ return p;};}; break;\ |
||
8379 | schaersvoo | 4389 | case 5: marge = 2*marge;for(var p = 0 ; p < this.x.length; p++ ){if( mx < this.x[p] + marge && mx > this.x[p] - marge ){if( my < this.y[p]+marge && my > this.y[p] - marge ){return p;};};};break;\ |
8370 | schaersvoo | 4390 | case 6: marge = 0.5*this.w[0];for(var p = 0 ; p < this.x.length; p++ ){if( mx < this.x[p] + marge && mx > this.x[p] - marge ){if( my < this.y[p]+marge && my > this.y[p] - marge ){return p;};};};break;\ |
7875 | schaersvoo | 4391 | case 7: for(var p = 0 ; p < this.x.length; p++ ){if( (this.x[p] - this.w[p] <= mx) && (this.x[p] + this.w[p] >= mx) && (this.y[p] - this.h[p] <= my) && (this.y[p] + this.h[p] >= my) ){return p;};};break;\ |
4392 | case 8: var diff;var q;var r;for(var p = 0 ; p < this.x.length-1; p = p+2 ){if( ((this.x[p+1] - this.x[p]) != 0) && ((this.y[p+1]-this.y[p]) != 0) ){r = (this.y[p+1]-this.y[p])/(this.x[p+1]-this.x[p]);q = this.y[p] - (r)*(this.x[p]);diff = distance_to_line(r,q,mx,my);}else{if( (this.y[p+1]-this.y[p]) != 0 ){diff = Math.abs(this.x[p] - mx);}else{diff = Math.abs(this.y[p] - my);};};if( diff < marge ){ return p;};}; break;\ |
||
4393 | case 9: for(var p = 0 ; p < this.x.length; p++ ){if( (this.x[p] - this.line_width <= mx) && (this.x[p] + this.w[p] + this.line_width >= mx) && (this.y[p] - this.line_width <= my) && (this.y[p] + this.h[p] +this.line_width >= my) ){return p;};};break;\ |
||
8347 | schaersvoo | 4394 | case 10: var diff;var q;var r;for(var p = 0 ; p < this.x.length-1; p = p+2 ){if( ((this.x[p+1] - this.x[p]) != 0) && ((this.y[p+1]-this.y[p]) != 0) ){r = (this.y[p+1]-this.y[p])/(this.x[p+1]-this.x[p]);q = this.y[p] - (r)*(this.x[p]);diff = distance_to_line(r,q,mx,my);}else{if( (this.y[p+1]-this.y[p]) != 0 ){diff = Math.abs(this.x[p] - mx);}else{diff = Math.abs(this.y[p] - my);};};if( diff < marge ){ return p;};}; break;\ |
7875 | schaersvoo | 4395 | case 11: break;\ |
4396 | case 12: break;\ |
||
4397 | case 13: for(var p = 0 ; p < this.x.length; p++ ){if( Math.abs(distance(this.x[p],this.y[p],mx,my) ) < scale_x_radius(this.w[p]) + marge ){return p;break;};};break;\ |
||
14542 | schaersvoo | 4398 | case 14: for(var p = 0 ; p < this.x.length; p++ ){if( my < this.y[p] && my > this.y[p] - this.textheight ){if( mx < this.x[p] + this.textwidth && mx > this.x[p] ){ return p;break;};};};break;\ |
8244 | schaersvoo | 4399 | case 15: break;\ |
4400 | case 16: break;\ |
||
4401 | case 17: break;\ |
||
4402 | case 18: var diff;var q;var r;if(((this.x[1] - this.x[0]) != 0) && ((this.y[1]-this.y[0]) != 0)){r = (this.y[1]-this.y[0])/(this.x[1]-this.x[0]);q = this.y[0] - (r)*(this.x[0]);diff = distance_to_line(r,q,mx,my);}else{if((this.y[1]-this.y[0])!= 0){diff = Math.abs(this.x[0] - mx);}else{diff = Math.abs(this.y[0] - my);};};if( diff < marge ){ return 0;};break;\ |
||
14029 | schaersvoo | 4403 | case 19: marge = 2*marge;for(var p = 0 ; p < this.x.length; p++ ){if( mx < this.x[p] + marge && mx > this.x[p] - marge ){if( my < this.y[p]+marge && my > this.y[p] - marge ){return p;};};};break;\ |
4404 | case 21: marge = 2*marge;for(var p = 0 ; p < this.x.length; p++ ){if( mx < this.x[p] + marge && mx > this.x[p] - marge ){if( my < this.y[p]+marge && my > this.y[p] - marge ){return p;};};};break;\ |
||
7875 | schaersvoo | 4405 | default: for(var p = 0 ; p < this.x.length; p++ ){if( (this.x[p] - this.line_width <= mx) && (this.x[p] + this.w[p] + this.line_width >= mx) && (this.y[p] - this.line_width <= my) && (this.y[p] + this.h[p] +this.line_width >= my) ){return p;};};break;\ |
4406 | };\ |
||
4407 | return -1;\ |
||
4408 | };\ |
||
4409 | var reply = [];\ |
||
14208 | schaersvoo | 4410 | var slidergroup = [];\ |
14948 | obado | 4411 | function CanvasState(canvas, container_div){\ |
7895 | schaersvoo | 4412 | this.canvas = canvas;\ |
4413 | this.width = canvas.width;\ |
||
4414 | this.height = canvas.height;\ |
||
4415 | var ctx = canvas.getContext(\"2d\");\ |
||
4416 | this.ctx = ctx;\ |
||
4417 | this.valid = false;\ |
||
4418 | this.shapes = [];\ |
||
4419 | this.moved = [];\ |
||
4420 | this.dragging = false;\ |
||
4421 | this.selection = null;\ |
||
14208 | schaersvoo | 4422 | this.slidergroup = [];\ |
7895 | schaersvoo | 4423 | var myState = this;\ |
11001 | schaersvoo | 4424 | container_div.addEventListener( 'mouseup' , mouseup, false);\ |
7895 | schaersvoo | 4425 | container_div.addEventListener( 'mousemove' , mousemove,false);\ |
4426 | container_div.addEventListener( 'mousedown' , mousedown,false);\ |
||
14949 | obado | 4427 | container_div.addEventListener( 'touchstart' , function(e) { e.preventDefault(); mousedown(e.changedTouches[0]);},false);\ |
11001 | schaersvoo | 4428 | container_div.addEventListener( 'touchmove' , function(e) { e.preventDefault(); mousemove(e.changedTouches[0]);},false);\ |
4429 | container_div.addEventListener( 'touchend' , function(e) { e.preventDefault(); mouseup( e.changedTouches[0]);},false);\ |
||
7875 | schaersvoo | 4430 | function mousedown(e){\ |
11002 | schaersvoo | 4431 | var mouse = myState.getMouse(e,canvas);\ |
7895 | schaersvoo | 4432 | var mx = mouse.x;\ |
4433 | var my = mouse.y;\ |
||
7875 | schaersvoo | 4434 | if( use_pan_and_zoom == 1 && my > ysize - 15){\ |
7895 | schaersvoo | 4435 | check_zoom_or_pan(mx);\ |
7875 | schaersvoo | 4436 | }\ |
4437 | else\ |
||
4438 | {\ |
||
8555 | schaersvoo | 4439 | if( wims_status == \"done\"){return null;};\ |
7895 | schaersvoo | 4440 | var shapes = myState.shapes;\ |
4441 | var l = shapes.length;\ |
||
4442 | var chk = -1;\ |
||
7875 | schaersvoo | 4443 | for(var i=0;i<l;i++){\ |
7895 | schaersvoo | 4444 | chk = shapes[i].contains(mx, my);\ |
7875 | schaersvoo | 4445 | if ( chk != -1 ){\ |
14208 | schaersvoo | 4446 | if( myState.shapes[i].use_slider != -1 ){ myState.slidergroup.push(i);};\ |
7875 | schaersvoo | 4447 | if( myState.moved[shapes[i].click_cnt] != 1){\ |
7895 | schaersvoo | 4448 | myState.moved[shapes[i].click_cnt] = 1;\ |
4449 | myState.x_start = shapes[i].x[chk];\ |
||
4450 | myState.y_start = shapes[i].y[chk];\ |
||
4451 | };\ |
||
4452 | myState.chk = chk;\ |
||
4453 | myState.selection = shapes[i];\ |
||
4454 | myState.valid = false;\ |
||
7875 | schaersvoo | 4455 | switch(shapes[i].onclick){\ |
7895 | schaersvoo | 4456 | case 0: myState.dragging = false;break;\ |
14542 | schaersvoo | 4457 | case 1: if( reply[myState.selection.click_cnt] == 0 ){myState.selection.line_width = 3*(myState.selection.org_line_width);myState.selection.font_family = parseInt(myState.selection.font_size+10)+\"px Courier\";reply[myState.selection.click_cnt] = 1;}else{ reply[myState.selection.click_cnt] = 0;myState.selection.font_family = myState.selection.org_font_family;myState.selection.line_width = myState.selection.org_line_width;};myState.dragging = false;myState.draw();break;\ |
7895 | schaersvoo | 4458 | case 2: myState.dragging = true;break;\ |
4459 | default:break;\ |
||
4460 | };\ |
||
4461 | return;\ |
||
4462 | };\ |
||
4463 | };\ |
||
4464 | };\ |
||
4465 | myState.selection = null;\ |
||
4466 | myState.valid = true;\ |
||
4467 | return;\ |
||
4468 | };\ |
||
4469 | function mouseup(e){;\ |
||
4470 | if(myState.selection != null ){\ |
||
4471 | if(myState.selection.onclick == 2 ){\ |
||
14045 | schaersvoo | 4472 | var dx,dy;\ |
14044 | schaersvoo | 4473 | var mouse = myState.getMouse(e,canvas);\ |
4474 | var xy = multisnap_check(mouse.x,mouse.y,myState.selection.use_snap);\ |
||
14045 | schaersvoo | 4475 | switch(myState.selection.drag_type){\ |
4476 | case 0: dx = xy[0] - myState.selection.x[myState.chk];dy = xy[1] - myState.selection.y[myState.chk];break;\ |
||
4477 | case 1: dx = xy[0] - myState.selection.x[myState.chk];dy = 0;break;\ |
||
4478 | case 2: dx = 0;dy = xy[1] - myState.selection.y[myState.chk];break;\ |
||
4479 | default:break;\ |
||
4480 | };\ |
||
14044 | schaersvoo | 4481 | myState.selection = move(myState.selection,dx,dy);\ |
14208 | schaersvoo | 4482 | reply[myState.selection.click_cnt] = myState.selection;\ |
8448 | schaersvoo | 4483 | myState.valid = false;\ |
4484 | myState.draw();\ |
||
4485 | myState.valid = true;\ |
||
7875 | schaersvoo | 4486 | };\ |
4487 | };\ |
||
7895 | schaersvoo | 4488 | myState.dragging = false;\ |
4489 | };\ |
||
4490 | function mousemove(e){\ |
||
14957 | obado | 4491 | if(myState.dragging && (e.button == 0 || typeof(e.identifier) != 'undefined') ){\ |
14045 | schaersvoo | 4492 | var dx,dy;\ |
11002 | schaersvoo | 4493 | var mouse = myState.getMouse(e,canvas);\ |
14044 | schaersvoo | 4494 | var xy = multisnap_check(mouse.x,mouse.y,myState.selection.use_snap);\ |
14045 | schaersvoo | 4495 | switch(myState.selection.drag_type){\ |
4496 | case 0: dx = xy[0] - myState.selection.x[myState.chk];dy = xy[1] - myState.selection.y[myState.chk];break;\ |
||
4497 | case 1: dx = xy[0] - myState.selection.x[myState.chk];dy = 0;break;\ |
||
4498 | case 2: dx = 0;dy = xy[1] - myState.selection.y[myState.chk];break;\ |
||
4499 | default:break;\ |
||
4500 | };\ |
||
14044 | schaersvoo | 4501 | myState.selection = move(myState.selection,dx,dy);\ |
14208 | schaersvoo | 4502 | };\ |
4503 | myState.valid = false;\ |
||
7875 | schaersvoo | 4504 | };\ |
4505 | function check_zoom_or_pan(x){\ |
||
7895 | schaersvoo | 4506 | var key = -1;\ |
8109 | schaersvoo | 4507 | for(var p = 15 ; p < 106 ; p = p+15){\ |
7895 | schaersvoo | 4508 | key++;\ |
7875 | schaersvoo | 4509 | if(x > xsize - p){start_canvas%d(key);return;}\ |
4510 | }\ |
||
7895 | schaersvoo | 4511 | return;\ |
4512 | };\ |
||
4513 | this.interval = 30;\ |
||
4514 | setInterval(function() { myState.draw(); }, myState.interval);\ |
||
4515 | };\ |
||
7875 | schaersvoo | 4516 | CanvasState.prototype.addShape = function(shape){\ |
7895 | schaersvoo | 4517 | this.shapes.push(shape);\ |
4518 | this.valid = false;\ |
||
4519 | };\ |
||
7875 | schaersvoo | 4520 | CanvasState.prototype.clear = function(){\ |
7895 | schaersvoo | 4521 | this.ctx.clearRect(0, 0, this.width, this.height);\ |
4522 | };\ |
||
7875 | schaersvoo | 4523 | CanvasState.prototype.draw = function(){\ |
4524 | if(this.valid == false ){\ |
||
7895 | schaersvoo | 4525 | var shapes = this.shapes;\ |
4526 | this.clear();\ |
||
4527 | var l = shapes.length;var shape;\ |
||
7875 | schaersvoo | 4528 | for(var i = 0; i < l; i++){\ |
7895 | schaersvoo | 4529 | shape = shapes[i];\ |
4530 | shape.draw(this.ctx);\ |
||
4531 | };\ |
||
4532 | this.valid = true;\ |
||
14208 | schaersvoo | 4533 | };\ |
9244 | schaersvoo | 4534 | };\ |
14208 | schaersvoo | 4535 | CanvasState.prototype.read_dragdrop = function(){\ |
4536 | if( wims_status == \"done\" || use_dragdrop_reply == -1 ){return null;};\ |
||
14543 | schaersvoo | 4537 | function set_precision(val){val = (Math.round(dragdrop_precision*val))/dragdrop_precision;if( Number.isNaN(val) ){return 'null';}else{return val;};};\ |
14208 | schaersvoo | 4538 | var x,y,a;\ |
14543 | schaersvoo | 4539 | var len = reply.length;\ |
4540 | var total = new Array(len);\ |
||
4541 | for(var p = 0 ; p < len ; p++){\ |
||
14208 | schaersvoo | 4542 | var obj = reply[p];\ |
4543 | if( typeof(obj) === 'object' ){\ |
||
4544 | x = obj.x || null;\ |
||
4545 | if(x != null){\ |
||
4546 | x = set_precision(px2x(obj.x[0]));\ |
||
4547 | y = set_precision(px2y(obj.y[0]));\ |
||
4548 | a = set_precision(obj.angle*180/Math.PI);\ |
||
14543 | schaersvoo | 4549 | total[p] = obj.xorg[0]+':'+obj.yorg[0]+':'+x+':'+y+':'+a;\ |
4550 | }\ |
||
4551 | }else{\ |
||
4552 | if( obj == null ){total[p] = 'not_moved';}else{ total[p] = obj;};\ |
||
9244 | schaersvoo | 4553 | };\ |
4554 | };\ |
||
14543 | schaersvoo | 4555 | return total;\ |
9244 | schaersvoo | 4556 | };\ |
7875 | schaersvoo | 4557 | CanvasState.prototype.Zoom = function(xmin,xmax,ymin,ymax){\ |
7895 | schaersvoo | 4558 | (this.ctx).clearRect(0,0,this.width,this.height);\ |
8098 | schaersvoo | 4559 | var len = this.shapes.length;var shape;\ |
8097 | schaersvoo | 4560 | for(var i = 0; i < len ; i++){\ |
8098 | schaersvoo | 4561 | shape = this.shapes[i];\ |
8097 | schaersvoo | 4562 | for(var p = 0 ; p < shape.x.length;p++){\ |
4563 | shape.x[p] = x2px(shape.xorg[p]);\ |
||
4564 | shape.y[p] = y2px(shape.yorg[p]);\ |
||
7875 | schaersvoo | 4565 | }\ |
7895 | schaersvoo | 4566 | this.valid = false;\ |
8097 | schaersvoo | 4567 | shape.draw(this.ctx);\ |
7895 | schaersvoo | 4568 | };\ |
4569 | };\ |
||
11002 | schaersvoo | 4570 | CanvasState.prototype.getMouse = function(e,element){\ |
11041 | schaersvoo | 4571 | var mx,my;var offsetX = 0,offsetY = 0;\ |
11002 | schaersvoo | 4572 | while( ( element = element.offsetParent) ){\ |
4573 | offsetX += element.offsetLeft;\ |
||
4574 | offsetY += element.offsetTop;\ |
||
4575 | };\ |
||
4576 | if(isTouch){\ |
||
4577 | mx = e.pageX - offsetX;\ |
||
4578 | my = e.pageY - offsetY;\ |
||
4579 | }\ |
||
4580 | else\ |
||
4581 | {\ |
||
4582 | mx = e.clientX - offsetX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);\ |
||
4583 | my = e.clientY - offsetY + (document.documentElement.scrollTop ? document.documentElement.scrollTop :document.body.scrollTop);\ |
||
11001 | schaersvoo | 4584 | };\ |
7895 | schaersvoo | 4585 | return {x: mx, y: my};\ |
4586 | };\ |
||
7875 | schaersvoo | 4587 | var obj = create_canvas%d(%d,xsize,ysize);\ |
4588 | var container_div = document.getElementById(\"canvas_div%d\");\ |
||
8108 | schaersvoo | 4589 | var dragstuff = new CanvasState(obj,container_div);\ |
11837 | schaersvoo | 4590 | read_dragdrop%d = dragstuff.read_dragdrop;\n",canvas_root_id,canvas_root_id,canvas_root_id,DRAG_CANVAS,canvas_root_id,canvas_root_id); |
7875 | schaersvoo | 4591 | } |
7895 | schaersvoo | 4592 | |
14546 | schaersvoo | 4593 | |
7895 | schaersvoo | 4594 | /* |
4595 | #define BG_CANVAS 0 may be used for floodfill |
||
4596 | #define STATIC_CANVAS 1 may be used for floodfill |
||
4597 | #define MOUSE_CANVAS 2 xx |
||
4598 | #define GRID_CANVAS 3 may be used for floodfill |
||
4599 | #define DRAG_CANVAS 4 default for floodfill |
||
4600 | #define DRAW_CANVAS 5 may be used for floodfill |
||
4601 | |||
4602 | */ |
||
14044 | schaersvoo | 4603 | void add_js_clickfill(FILE *js_include_file,int canvas_root_id,char *clickcolor,int opacity,int use_snap){ |
14038 | schaersvoo | 4604 | fprintf(js_include_file,"\n/* begin command clickfill */\n\ |
11005 | schaersvoo | 4605 | function user_drag(evt){return;};\ |
11818 | schaersvoo | 4606 | if( typeof(fill_canvas_no) != 'object' ){ var fill_canvas_no = []; };\ |
11764 | schaersvoo | 4607 | fill_canvas_no.push(%d);\ |
14044 | schaersvoo | 4608 | var use_snap = %d;\ |
11005 | schaersvoo | 4609 | function user_draw(evt){\ |
11006 | schaersvoo | 4610 | var mouse = dragstuff.getMouse(evt,canvas_userdraw);\ |
14044 | schaersvoo | 4611 | var xy = multisnap_check(mouse.x,mouse.y,use_snap);\ |
4612 | var x = xy[0];\ |
||
4613 | var y = xy[1];\ |
||
11763 | schaersvoo | 4614 | var len = fill_canvas_no.length;\ |
4615 | var last = fill_canvas_no[len - 1];\ |
||
11764 | schaersvoo | 4616 | var color = [ %s,%d ];\ |
4617 | if( typeof(multifillcolors) === 'object'){\ |
||
11767 | schaersvoo | 4618 | var numx = userdraw_x.length;var numc = multifillcolors.length-1;var num = numx%%numc;\ |
11764 | schaersvoo | 4619 | var tc = (multifillcolors[num]).split(',');\ |
4620 | color = [ tc[0],tc[1],tc[2],%d ];\ |
||
11767 | schaersvoo | 4621 | if( typeof( palettecolors ) === 'object'){\ |
4622 | var idx = palettecolors.indexOf( multifillcolors[num]);\ |
||
4623 | userdraw_radius.push(idx);\ |
||
4624 | }else{ userdraw_radius.push(num);};\ |
||
4625 | }\ |
||
4626 | else\ |
||
4627 | {\ |
||
11824 | schaersvoo | 4628 | userdraw_radius.push(0);\ |
11767 | schaersvoo | 4629 | };\ |
11820 | schaersvoo | 4630 | document.body.style.cursor = 'wait';\ |
11823 | schaersvoo | 4631 | var special_ctx;\ |
4632 | var use_special = false;\ |
||
4633 | if( typeof(grid_fill_pattern) != 'undefined' ){\ |
||
4634 | special_ctx = grid_fill_pattern;\ |
||
4635 | use_special = true;\ |
||
4636 | };\ |
||
4637 | if( typeof(diamond_fill_pattern) != 'undefined' ){\ |
||
4638 | special_ctx = diamond_fill_pattern;\ |
||
4639 | use_special = true;\ |
||
4640 | };\ |
||
4641 | if( typeof(hatch_fill_pattern) != 'undefined' ){\ |
||
4642 | special_ctx = hatch_fill_pattern;\ |
||
4643 | use_special = true;\ |
||
4644 | };\ |
||
4645 | if( typeof(dot_fill_pattern) != 'undefined' ){\ |
||
4646 | special_ctx = dot_fill_pattern;\ |
||
4647 | use_special = true;\ |
||
4648 | };\ |
||
11830 | schaersvoo | 4649 | if( typeof(text_fill_pattern) != 'undefined' ){\ |
4650 | special_ctx = text_fill_pattern;\ |
||
4651 | use_special = true;\ |
||
4652 | };\ |
||
11823 | schaersvoo | 4653 | if( use_special ){\ |
4654 | setTimeout(function(){ filltoborder( px2x(mouse.x),px2y(mouse.y),color,color,last,true,special_ctx);},500);\ |
||
11818 | schaersvoo | 4655 | }\ |
4656 | else\ |
||
4657 | {\ |
||
4658 | setTimeout(function(){ filltoborder( px2x(mouse.x),px2y(mouse.y),color,color,last,false,null);},500);\ |
||
4659 | };\ |
||
11763 | schaersvoo | 4660 | fill_canvas_no.push(last+1);\ |
11767 | schaersvoo | 4661 | userdraw_x.push(x);\ |
4662 | userdraw_y.push(y);\ |
||
11820 | schaersvoo | 4663 | document.body.style.cursor = 'default';\ |
11771 | schaersvoo | 4664 | return;\ |
14044 | schaersvoo | 4665 | };",CLICKFILL_CANVAS,use_snap,clickcolor,opacity,opacity); |
7895 | schaersvoo | 4666 | } |
4667 | |||
11005 | schaersvoo | 4668 | /* 10/2016 does not react to border color !! just any border will stop the filling */ |
11006 | schaersvoo | 4669 | void add_js_filltoborder(FILE *js_include_file,int canvas_root_id,int canvas_type){ |
14038 | schaersvoo | 4670 | fprintf(js_include_file,"\n/* begin command filltoborder */\n\ |
11818 | schaersvoo | 4671 | var filltoborder = function(xs,ys,bordercolor,color,fill_canvas_no,use_special_filling,fill_ctx){\ |
11820 | schaersvoo | 4672 | document.body.style.cursor = 'wait';\ |
8199 | schaersvoo | 4673 | var canvas = document.getElementById(\"wims_canvas%d%d\");\ |
4674 | if( ! canvas ){ return; };\ |
||
11817 | schaersvoo | 4675 | document.body.style.cursor = 'wait';\ |
8199 | schaersvoo | 4676 | var ctx = canvas.getContext(\"2d\");\ |
4677 | ctx.save();\ |
||
4678 | xs = x2px(xs);\ |
||
4679 | ys = y2px(ys);\ |
||
11817 | schaersvoo | 4680 | if( xs < 0 || xs > xsize || ys < 0 || ys > ysize ){ document.body.style.cursor = 'default';return; };\ |
8098 | schaersvoo | 4681 | var image = ctx.getImageData(0, 0, xsize, ysize);\ |
4682 | var imageData = image.data;\ |
||
4683 | var pixelStack = [[xs, ys]];\ |
||
4684 | var px1;\ |
||
4685 | var newPos;\ |
||
4686 | var pixelPos;\ |
||
4687 | var found_left_border;\ |
||
4688 | var found_right_border;\ |
||
4689 | function _getPixel(pixelPos){\ |
||
4690 | return {r:imageData[pixelPos], g:imageData[pixelPos+1], b:imageData[pixelPos+2], a:imageData[pixelPos+3]};\ |
||
11820 | schaersvoo | 4691 | };\ |
4692 | var _setPixel;\ |
||
4693 | if( use_special_filling ){\ |
||
11818 | schaersvoo | 4694 | var fill_image = fill_ctx.getImageData(0, 0, xsize, ysize);\ |
4695 | var fill_data = fill_image.data;\ |
||
11817 | schaersvoo | 4696 | _setPixel = function(pixelPos){\ |
11820 | schaersvoo | 4697 | var n;var o;\ |
4698 | for(var p = 0;p < 3; p++){\ |
||
4699 | n = fill_data[pixelPos+p];\ |
||
4700 | o = imageData[pixelPos+p];\ |
||
4701 | if( n != o ){ imageData[pixelPos+p] = n; } else { if( o == 255 ){ o = 253;} imageData[pixelPos+p] = o+1;};\ |
||
4702 | };\ |
||
4703 | imageData[pixelPos+3] = 255;\ |
||
4704 | };\ |
||
4705 | }\ |
||
4706 | else\ |
||
4707 | {\ |
||
4708 | _setPixel = function(pixelPos){\ |
||
11817 | schaersvoo | 4709 | imageData[pixelPos] = color.r;\ |
4710 | imageData[pixelPos+1] = color.g;\ |
||
4711 | imageData[pixelPos+2] = color.b;\ |
||
4712 | imageData[pixelPos+3] = color.a;\ |
||
11820 | schaersvoo | 4713 | };\ |
4714 | };\ |
||
8098 | schaersvoo | 4715 | function _comparePixel(px2){\ |
11023 | schaersvoo | 4716 | if(px2.r === px1.r && px2.g === px1.g && px2.b === px1.b ){ return true;};\ |
4717 | return false;\ |
||
8098 | schaersvoo | 4718 | };\ |
4719 | px1 = _getPixel(((ys * xsize) + xs) * 4);\ |
||
8199 | schaersvoo | 4720 | color = {\ |
4721 | r: parseInt(color[0], 10),\ |
||
4722 | g: parseInt(color[1], 10),\ |
||
4723 | b: parseInt(color[2], 10),\ |
||
4724 | a: parseInt(color[3] || 255, 10)\ |
||
4725 | };\ |
||
8098 | schaersvoo | 4726 | bordercolor = {\ |
8074 | schaersvoo | 4727 | r: parseInt(bordercolor[0], 10),\ |
4728 | g: parseInt(bordercolor[1], 10),\ |
||
4729 | b: parseInt(bordercolor[2], 10),\ |
||
4730 | a: parseInt(bordercolor[3] || 255, 10)\ |
||
8098 | schaersvoo | 4731 | };\ |
4732 | if( _comparePixel(color) ) { return true; }\ |
||
4733 | while (pixelStack.length) {\ |
||
4734 | newPos = pixelStack.pop();\ |
||
4735 | xs = newPos[0];ys = newPos[1];\ |
||
4736 | pixelPos = (ys*xsize + xs) * 4;\ |
||
11023 | schaersvoo | 4737 | while(ys >= 0 && _comparePixel(_getPixel(pixelPos))){\ |
4738 | ys -= 1;\ |
||
8098 | schaersvoo | 4739 | pixelPos -= xsize * 4;\ |
4740 | }\ |
||
4741 | pixelPos += xsize * 4;\ |
||
11023 | schaersvoo | 4742 | ys += 1;\ |
8098 | schaersvoo | 4743 | found_left_border = false;\ |
4744 | found_right_border = false;\ |
||
11023 | schaersvoo | 4745 | while( ys <= ysize-1 && _comparePixel(_getPixel(pixelPos)) ){\ |
4746 | ys += 1;\ |
||
8098 | schaersvoo | 4747 | _setPixel(pixelPos);\ |
11005 | schaersvoo | 4748 | if( xs > 1 ){\ |
8098 | schaersvoo | 4749 | if( _comparePixel(_getPixel(pixelPos - 4)) ){\ |
4750 | if( !found_left_border ){\ |
||
4751 | pixelStack.push( [xs - 1, ys] );\ |
||
4752 | found_left_border = true;\ |
||
11023 | schaersvoo | 4753 | };\ |
8098 | schaersvoo | 4754 | }\ |
4755 | else if( found_left_border ){\ |
||
4756 | found_left_border = false;\ |
||
4757 | }\ |
||
4758 | }\ |
||
11005 | schaersvoo | 4759 | if( xs < xsize - 1 ){\ |
8098 | schaersvoo | 4760 | if( _comparePixel(_getPixel(pixelPos + 4)) ){\ |
4761 | if( !found_right_border){\ |
||
4762 | pixelStack.push( [xs + 1, ys] );\ |
||
4763 | found_right_border = true;\ |
||
4764 | }\ |
||
4765 | }\ |
||
4766 | else if(found_right_border){\ |
||
4767 | found_right_border = false;\ |
||
4768 | }\ |
||
4769 | }\ |
||
4770 | pixelPos += xsize * 4;\ |
||
4771 | }\ |
||
11820 | schaersvoo | 4772 | };\ |
4773 | var fill_canvas = create_canvas%d(fill_canvas_no,xsize,ysize);\ |
||
4774 | var fill_canvas_ctx = fill_canvas.getContext(\"2d\");\ |
||
4775 | fill_canvas_ctx.clearRect(0,0,xsize,ysize);\ |
||
4776 | fill_canvas_ctx.putImageData(image, 0, 0);\ |
||
4777 | document.body.style.cursor = 'default';};",canvas_root_id,canvas_type,canvas_root_id); |
||
8074 | schaersvoo | 4778 | } |
8083 | schaersvoo | 4779 | |
9289 | schaersvoo | 4780 | void add_js_ruler(FILE *js_include_file, |
4781 | int canvas_root_id,double x,double y,double sizex,double sizey,char *font, |
||
4782 | char *stroke_color,double stroke_opacity,char *fill_color,double fill_opacity, |
||
14057 | schaersvoo | 4783 | int line_width,int dynamic,int use_snap){ |
14038 | schaersvoo | 4784 | fprintf(js_include_file,"\n/* begin command ruler */\n\ |
9289 | schaersvoo | 4785 | var ruler_data = new Array(3);\ |
4786 | var ruler%d = function(){\ |
||
14057 | schaersvoo | 4787 | var use_snap = %d;\ |
9289 | schaersvoo | 4788 | var full = 2*Math.PI;\ |
4789 | var once = true;\ |
||
4790 | var canvas = create_canvas%d(3000,xsize,ysize);\ |
||
4791 | var ctx = canvas.getContext(\"2d\");\ |
||
4792 | var canvas_temp = document.createElement(\"canvas\");\ |
||
4793 | var size_x = xsize*(%f)/(xmax - xmin);\ |
||
4794 | var size_y = ysize*(%f)/(ymax - ymin);\ |
||
4795 | var dx = xsize/(xmax - xmin);\ |
||
4796 | var dy = 0.8*ysize/(ymax - ymin);\ |
||
4797 | canvas_temp.width = xsize;\ |
||
4798 | canvas_temp.height = ysize;\ |
||
4799 | var ctx_temp = canvas_temp.getContext(\"2d\");\ |
||
4800 | var xcenter = x2px(%f);\ |
||
4801 | var ycenter = y2px(%f);\ |
||
4802 | var ruler_x = xcenter;\ |
||
4803 | var ruler_y = ycenter;\ |
||
4804 | ctx_temp.font = \"%s\";\ |
||
4805 | ctx_temp.strokeStyle = \"rgba(%s,%f)\";\ |
||
4806 | ctx_temp.fillStyle = \"rgba(%s,%f)\";\ |
||
4807 | ctx_temp.lineWidth = %d;\ |
||
4808 | ctx_temp.save();\ |
||
4809 | if(once){\ |
||
4810 | ctx_temp.beginPath();\ |
||
4811 | ctx_temp.moveTo(ruler_x,ruler_y);\ |
||
4812 | ctx_temp.lineTo(ruler_x+size_x,ruler_y);\ |
||
4813 | ctx_temp.lineTo(ruler_x+size_x,ruler_y-size_y);\ |
||
4814 | ctx_temp.lineTo(ruler_x,ruler_y-size_y);\ |
||
4815 | ctx_temp.lineTo(ruler_x,ruler_y);\ |
||
4816 | ctx_temp.closePath();\ |
||
4817 | ctx_temp.fill();\ |
||
4818 | ctx_temp.stroke();\ |
||
4819 | ctx_temp.fillStyle = ctx_temp.strokeStyle;\ |
||
4820 | var txtsize;\ |
||
4821 | var num = 1;\ |
||
4822 | for(var p = dx ; p < size_x ; p = p+dx){\ |
||
4823 | txtsize = 0.5*(ctx_temp.measureText(num).width);\ |
||
4824 | ctx_temp.fillText(num,ruler_x + p -txtsize,ruler_y - 0.9*dy);\ |
||
4825 | num++;\ |
||
4826 | };\ |
||
4827 | ctx_temp.strokeStyle = \"rgba(0,0,255,0.6)\";\ |
||
4828 | ctx_temp.lineWidth = 2;\ |
||
4829 | for(var p = 0; p < size_x ; p = p+dx){\ |
||
4830 | ctx_temp.beginPath();\ |
||
4831 | ctx_temp.moveTo(ruler_x+p,ruler_y);\ |
||
4832 | ctx_temp.lineTo(ruler_x+p,ruler_y-0.8*dy);\ |
||
4833 | ctx_temp.closePath();\ |
||
4834 | ctx_temp.stroke();\ |
||
4835 | };\ |
||
4836 | ctx_temp.strokeStyle = \"rgba(0,0,255,0.6)\";\ |
||
4837 | ctx_temp.lineWidth = 1;\ |
||
4838 | for(var p = 0; p < size_x ; p = p+0.5*dx){\ |
||
4839 | ctx_temp.beginPath();\ |
||
4840 | ctx_temp.moveTo(ruler_x+p,ruler_y);\ |
||
4841 | ctx_temp.lineTo(ruler_x+p,ruler_y-0.6*dy);\ |
||
4842 | ctx_temp.closePath();\ |
||
4843 | ctx_temp.stroke();\ |
||
4844 | };\ |
||
4845 | ctx_temp.strokeStyle = \"rgba(255,0,0,0.6)\";\ |
||
4846 | ctx_temp.lineWidth = 0.5;\ |
||
4847 | for(var p = 0; p < size_x ; p = p+0.1*dx){\ |
||
4848 | ctx_temp.beginPath();\ |
||
4849 | ctx_temp.moveTo(ruler_x+p,ruler_y);\ |
||
4850 | ctx_temp.lineTo(ruler_x+p,ruler_y-0.4*dy);\ |
||
4851 | ctx_temp.closePath();\ |
||
4852 | ctx_temp.stroke();\ |
||
4853 | };\ |
||
4854 | ctx_temp.drawImage(canvas,ruler_x,ruler_y);\ |
||
4855 | once = false;\ |
||
14057 | schaersvoo | 4856 | }",canvas_root_id,use_snap,canvas_root_id,sizex,sizey,x,y,font,stroke_color,stroke_opacity,fill_color,fill_opacity,line_width); |
14948 | obado | 4857 | |
9289 | schaersvoo | 4858 | if( dynamic == -1 ){ |
4859 | fprintf(js_include_file,"\ |
||
4860 | ctx.drawImage(canvas_temp,0,0);\ |
||
4861 | if(wims_status != \"done\"){\ |
||
4862 | canvas_div.addEventListener( 'mouseup' , ruler_stop,false);\ |
||
4863 | canvas_div.addEventListener( 'mousedown' , ruler_start,false);\ |
||
4864 | canvas_div.addEventListener( 'mousemove' , ruler_move,false);\ |
||
11002 | schaersvoo | 4865 | canvas_div.addEventListener( 'touchstart', function(e){ e.preventDefault();ruler_start(e.changedTouches[0]);},false);\ |
4866 | canvas_div.addEventListener( 'touchmove', function(e){ e.preventDefault();ruler_move(e.changedTouches[0]);},false);\ |
||
4867 | canvas_div.addEventListener( 'touchend', function(e){ e.preventDefault();ruler_stop(e.changedTouches[0]);},false);\ |
||
9289 | schaersvoo | 4868 | };\ |
4869 | function ruler_stop(evt){\ |
||
4870 | ruler_data[0] = ruler_x;\ |
||
4871 | ruler_data[1] = ruler_y;\ |
||
4872 | ruler_data[2] = angle;\ |
||
4873 | return;\ |
||
4874 | };\ |
||
4875 | var ruler_click_cnt = 0;\ |
||
4876 | function ruler_start(evt){\ |
||
11002 | schaersvoo | 4877 | var mouse = dragstuff.getMouse(evt,canvas);\ |
4878 | var mouse_y = mouse.y;\ |
||
4879 | if( mouse_y > ysize - 20 ){return;};\ |
||
4880 | var mouse_x = mouse.x;\ |
||
4881 | if( mouse_x > ruler_x - 50 && mouse_x < ruler_x + size_x + 50){\ |
||
4882 | if( mouse_y > ruler_y - 50 && mouse_y < ruler_y + size_y + 50){\ |
||
4883 | ruler_click_cnt++;\ |
||
4884 | ruler_move(evt);\ |
||
4885 | return;\ |
||
4886 | };\ |
||
4887 | }else{ruler_click_cnt = 0; return;};\ |
||
9289 | schaersvoo | 4888 | };\ |
4889 | var angle = 0;\ |
||
4890 | function ruler_move(evt){\ |
||
11002 | schaersvoo | 4891 | var mouse = dragstuff.getMouse(evt,canvas);\ |
9289 | schaersvoo | 4892 | switch(ruler_click_cnt){\ |
4893 | case 1:\ |
||
4894 | angle = 0;\ |
||
14057 | schaersvoo | 4895 | var xy = multisnap_check(mouse.x,mouse.y,use_snap);\ |
4896 | ruler_y = xy[1];\ |
||
9289 | schaersvoo | 4897 | if( ruler_y > ysize - 20 ){ruler_y = 0.5*ysize;ruler_x = 0.5*xsize;return;};\ |
14057 | schaersvoo | 4898 | ruler_x = xy[0];\ |
9289 | schaersvoo | 4899 | ctx.clearRect(0,0,xsize,ysize);\ |
4900 | ctx.save();\ |
||
4901 | ctx.translate(ruler_x - xcenter,ruler_y - ycenter);\ |
||
4902 | ctx.drawImage(canvas_temp,0,0);\ |
||
4903 | ctx.restore();\ |
||
4904 | break;\ |
||
4905 | case 2:\ |
||
11017 | schaersvoo | 4906 | angle = find_angle(ruler_x,ruler_y,mouse.x,mouse.y);\ |
9289 | schaersvoo | 4907 | ctx.clearRect(0,0,xsize,ysize);\ |
4908 | ctx.save();\ |
||
4909 | ctx.translate(ruler_x,ruler_y);\ |
||
4910 | ctx.rotate(angle);\ |
||
4911 | ctx.translate( -1*xcenter, -1*ycenter );\ |
||
4912 | ctx.drawImage( canvas_temp,0,0 );\ |
||
4913 | ctx.restore();\ |
||
11017 | schaersvoo | 4914 | userdraw_radius[0] = 2*Math.PI - angle;\ |
9289 | schaersvoo | 4915 | break;\ |
4916 | case 3:ruler_click_cnt = 0;break;\ |
||
4917 | default:ruler_stop(evt);break;\ |
||
4918 | };\ |
||
4919 | };\ |
||
4920 | };\ |
||
4921 | ruler%d();\n",canvas_root_id); |
||
4922 | } |
||
4923 | else |
||
4924 | { |
||
4925 | fprintf(js_include_file,"\ |
||
4926 | ctx.clearRect(0,0,xsize,ysize);\ |
||
4927 | ctx.save();\ |
||
4928 | ctx.translate(ruler_x,ruler_y);\ |
||
4929 | ctx.rotate(%d*Math.PI/180);\ |
||
4930 | ctx.translate( -1*xcenter, -1*ycenter );\ |
||
4931 | ctx.drawImage( canvas_temp,0,0 );\ |
||
4932 | ctx.restore();\ |
||
4933 | };\ |
||
4934 | ruler%d();",dynamic,canvas_root_id); |
||
4935 | } |
||
4936 | } |
||
4937 | |||
14057 | schaersvoo | 4938 | void add_js_protractor(FILE *js_include_file,int canvas_root_id,int type,double xcenter,double ycenter,int size,char *font,char *stroke_color,double stroke_opacity,char *fill_color,double fill_opacity,int line_width,int use_scale,int dynamic,int use_snap){ |
9289 | schaersvoo | 4939 | |
4940 | /* |
||
4941 | use_slider_display = 2 : angle in degrees |
||
4942 | use_slider_display = 3 : angle in radians |
||
4943 | void add_slider_display(FILE *js_include_file,int canvas_root_id,int precision,int font_size,char *font_color,double stroke_opacity){ |
||
4944 | */ |
||
4945 | |||
4946 | if( type == 1 ){ /* geodriehoek */ |
||
14038 | schaersvoo | 4947 | fprintf(js_include_file,"\n/* begin command protractor type 1 */\n\ |
9289 | schaersvoo | 4948 | var protractor_data = new Array(3);\ |
4949 | var protractor%d = function(){\ |
||
4950 | var once = true;\ |
||
14057 | schaersvoo | 4951 | var use_snap = %d;\ |
9289 | schaersvoo | 4952 | var full = 2*Math.PI;\ |
4953 | var canvas = create_canvas%d(2000,xsize,ysize);\ |
||
4954 | var ctx = canvas.getContext(\"2d\");\ |
||
4955 | var canvas_temp = document.createElement(\"canvas\");\ |
||
4956 | var size = parseInt(xsize*(%d)/(xmax - xmin));\ |
||
4957 | canvas_temp.width = xsize;\ |
||
4958 | canvas_temp.height = ysize;\ |
||
4959 | var ctx_temp = canvas_temp.getContext(\"2d\");\ |
||
4960 | var type = %d;\ |
||
4961 | var xcenter = x2px(%f);\ |
||
4962 | var ycenter = y2px(%f);\ |
||
4963 | var half = 0.5*size;\ |
||
4964 | var radius1 = 0.6*half;\ |
||
4965 | var radius2 = 0.65*half;\ |
||
4966 | var radius3 = 0.7*half;\ |
||
4967 | ctx_temp.font = \"%s\";\ |
||
4968 | ctx_temp.strokeStyle = \"rgba(%s,%f)\";\ |
||
4969 | ctx_temp.fillStyle = \"rgba(%s,%f)\";\ |
||
4970 | ctx_temp.lineWidth =%d;\ |
||
4971 | var use_scale = %d;\ |
||
4972 | if( once ){\ |
||
4973 | ctx_temp.clearRect(0,0,canvas_temp.width,canvas_temp.height);\ |
||
4974 | ctx_temp.beginPath();\ |
||
4975 | ctx_temp.moveTo(xcenter-half,ycenter );\ |
||
4976 | ctx_temp.lineTo(xcenter,ycenter-half);\ |
||
4977 | ctx_temp.lineTo(xcenter+half,ycenter);\ |
||
4978 | ctx_temp.lineTo(xcenter-half,ycenter);\ |
||
4979 | ctx_temp.moveTo(xcenter,ycenter );\ |
||
4980 | ctx_temp.lineTo(xcenter+0.5*half,ycenter-0.5*half);\ |
||
4981 | ctx_temp.moveTo(xcenter,ycenter );\ |
||
4982 | ctx_temp.lineTo(xcenter-0.5*half,ycenter-0.5*half);\ |
||
4983 | ctx_temp.moveTo(xcenter,ycenter );\ |
||
4984 | ctx_temp.lineTo(xcenter,ycenter-half);\ |
||
4985 | ctx_temp.closePath();\ |
||
4986 | ctx_temp.fill();\ |
||
4987 | ctx_temp.stroke();\ |
||
4988 | ctx_temp.beginPath();\ |
||
4989 | ctx_temp.arc(xcenter,ycenter,radius1,0,Math.PI,false);\ |
||
4990 | ctx_temp.closePath();\ |
||
4991 | if( use_scale == 1 ){\ |
||
4992 | ctx_temp.fillStyle = ctx_temp.strokeStyle;\ |
||
4993 | var txtsize;\ |
||
4994 | for(var p = 45 ; p < 180;p = p+45){\ |
||
4995 | txtsize = 0.5*(ctx_temp.measureText(p).width);\ |
||
4996 | ctx_temp.fillText(p,xcenter+0.5*half*Math.cos(p*Math.PI/180) - txtsize,ycenter-0.5*half*Math.sin(p*Math.PI/180));\ |
||
4997 | };\ |
||
4998 | };\ |
||
4999 | for(var p = 10 ; p < 180;p = p+10){\ |
||
5000 | ctx_temp.beginPath();\ |
||
5001 | ctx_temp.moveTo(xcenter+radius1*Math.cos(p*Math.PI/180),ycenter-radius1*Math.sin(p*Math.PI/180));\ |
||
5002 | ctx_temp.lineTo(xcenter+radius3*Math.cos(p*Math.PI/180),ycenter-radius3*Math.sin(p*Math.PI/180));\ |
||
5003 | ctx_temp.closePath();\ |
||
5004 | ctx_temp.stroke();\ |
||
5005 | };\ |
||
5006 | for(var p = 0 ; p < 180;p=p+2){\ |
||
5007 | if(p%%10 != 0){\ |
||
5008 | ctx_temp.beginPath();\ |
||
5009 | ctx_temp.moveTo(xcenter+radius1*Math.cos(p*Math.PI/180),ycenter-radius1*Math.sin(p*Math.PI/180));\ |
||
5010 | ctx_temp.lineTo(xcenter+radius2*Math.cos(p*Math.PI/180),ycenter-radius2*Math.sin(p*Math.PI/180));\ |
||
5011 | ctx_temp.closePath();\ |
||
5012 | ctx_temp.stroke();\ |
||
5013 | };\ |
||
5014 | };\ |
||
5015 | ctx_temp.drawImage(canvas,xcenter,ycenter);\ |
||
5016 | ctx_temp.save();\ |
||
5017 | once = false;\ |
||
5018 | };\ |
||
14057 | schaersvoo | 5019 | ",canvas_root_id,use_snap,canvas_root_id,size,type,xcenter,ycenter,font,stroke_color,stroke_opacity,fill_color,fill_opacity,line_width,use_scale); |
9289 | schaersvoo | 5020 | } |
5021 | |||
11002 | schaersvoo | 5022 | if( type != 1 ){ |
14038 | schaersvoo | 5023 | fprintf(js_include_file,"\n/* begin command protractor type 0 */\n\ |
9289 | schaersvoo | 5024 | var protractor_data = new Array(3);\ |
5025 | var protractor%d = function(){\ |
||
5026 | var once = true;\ |
||
14057 | schaersvoo | 5027 | var use_snap = %d;\ |
9289 | schaersvoo | 5028 | var full = 2*Math.PI;\ |
5029 | var canvas = create_canvas%d(2000,xsize,ysize);\ |
||
5030 | var ctx = canvas.getContext(\"2d\");\ |
||
5031 | var canvas_temp = document.createElement(\"canvas\");\ |
||
5032 | var size = parseInt(xsize*(%d)/(xmax - xmin));\ |
||
5033 | canvas_temp.width = xsize;\ |
||
5034 | canvas_temp.height = ysize;\ |
||
5035 | var ctx_temp = canvas_temp.getContext(\"2d\");\ |
||
5036 | var type = %d;\ |
||
5037 | var xcenter = x2px(%f);\ |
||
5038 | var ycenter = y2px(%f);\ |
||
5039 | var half = 0.5*size;\ |
||
5040 | var radius1 = 0.8*half;\ |
||
5041 | var radius2 = 0.9*half;\ |
||
5042 | var radius3 = half;\ |
||
5043 | ctx_temp.font = \"%s\";\ |
||
5044 | ctx_temp.strokeStyle = \"rgba(%s,%f)\";\ |
||
5045 | ctx_temp.fillStyle = \"rgba(%s,%f)\";\ |
||
5046 | ctx_temp.lineWidth =%d;\ |
||
5047 | var use_scale = %d;\ |
||
5048 | if( once ){\ |
||
5049 | ctx_temp.clearRect(0,0,xsize,ysize);\ |
||
5050 | ctx_temp.arc(xcenter,ycenter,radius1,0,2*Math.PI,false);\ |
||
5051 | ctx_temp.arc(xcenter,ycenter,radius2,0,2*Math.PI,false);\ |
||
5052 | ctx_temp.arc(xcenter,ycenter,radius3,0,2*Math.PI,false);\ |
||
5053 | ctx_temp.fill();\ |
||
5054 | ctx_temp.stroke();\ |
||
5055 | if( use_scale == 1 ){\ |
||
5056 | ctx_temp.fillStyle = ctx_temp.strokeStyle;\ |
||
5057 | var txtsize;\ |
||
5058 | for(var p = 0 ; p < 360;p = p+45){\ |
||
5059 | txtsize = 0.5*(ctx_temp.measureText(p).width);\ |
||
5060 | ctx_temp.fillText(p,xcenter+0.6*half*Math.cos(p*Math.PI/180) - txtsize,ycenter-0.6*half*Math.sin(p*Math.PI/180));\ |
||
5061 | };\ |
||
5062 | };\ |
||
5063 | ctx_temp.strokeStyle = \"rgba(255,0,0,0.4)\";\ |
||
5064 | for(var p = 0 ; p < 360;p = p+10){\ |
||
5065 | ctx_temp.beginPath();\ |
||
5066 | ctx_temp.moveTo(xcenter+radius1*Math.cos(p*Math.PI/180),ycenter-radius1*Math.sin(p*Math.PI/180));\ |
||
5067 | ctx_temp.lineTo(xcenter+radius3*Math.cos(p*Math.PI/180),ycenter-radius3*Math.sin(p*Math.PI/180));\ |
||
5068 | ctx_temp.closePath();\ |
||
5069 | ctx_temp.stroke();\ |
||
5070 | };\ |
||
5071 | ctx_temp.strokeStyle = \"rgba(0,0,255,0.4)\";\ |
||
5072 | for(var p = 0 ; p < 360;p=p+2){\ |
||
5073 | ctx_temp.beginPath();\ |
||
5074 | ctx_temp.moveTo(xcenter+radius2*Math.cos(p*Math.PI/180),ycenter-radius2*Math.sin(p*Math.PI/180));\ |
||
5075 | ctx_temp.lineTo(xcenter+radius3*Math.cos(p*Math.PI/180),ycenter-radius3*Math.sin(p*Math.PI/180));\ |
||
5076 | ctx_temp.closePath();\ |
||
5077 | ctx_temp.stroke();\ |
||
5078 | };\ |
||
5079 | ctx_temp.strokeStyle = \"rgba(0,0,0,0.6)\";\ |
||
5080 | for(var p = 0 ; p < 360;p=p+45){\ |
||
5081 | ctx_temp.beginPath();\ |
||
5082 | ctx_temp.moveTo(xcenter,ycenter);\ |
||
5083 | ctx_temp.lineTo(xcenter+radius3*Math.cos(p*Math.PI/180),ycenter-radius3*Math.sin(p*Math.PI/180));\ |
||
5084 | ctx_temp.closePath();\ |
||
5085 | ctx_temp.stroke();\ |
||
5086 | };\ |
||
5087 | ctx_temp.drawImage(canvas,0,0);\ |
||
5088 | ctx_temp.save();\ |
||
5089 | once = false;\ |
||
14057 | schaersvoo | 5090 | };\n",canvas_root_id,use_snap,canvas_root_id,size,type,xcenter,ycenter,font,stroke_color,stroke_opacity,fill_color,fill_opacity,line_width,use_scale); |
11017 | schaersvoo | 5091 | } |
5092 | if( dynamic == -1 ){ /* rotate the protractors */ |
||
9289 | schaersvoo | 5093 | fprintf(js_include_file,"\ |
5094 | var protractor_x = xcenter;\ |
||
5095 | var protractor_y = ycenter;\ |
||
5096 | ctx.drawImage(canvas_temp,0,0);\ |
||
11017 | schaersvoo | 5097 | var angle = 0;\ |
9289 | schaersvoo | 5098 | if(wims_status != \"done\"){\ |
5099 | canvas_div.addEventListener( 'mouseup' , protractor_stop,false);\ |
||
5100 | canvas_div.addEventListener( 'mousedown' , protractor_start,false);\ |
||
5101 | canvas_div.addEventListener( 'mousemove' , protractor_move,false);\ |
||
11002 | schaersvoo | 5102 | canvas_div.addEventListener( 'touchstart', function(e){ e.preventDefault();protractor_start(e.changedTouches[0]);},false);\ |
5103 | canvas_div.addEventListener( 'touchmove', function(e){ e.preventDefault();protractor_move(e.changedTouches[0]);},false);\ |
||
5104 | canvas_div.addEventListener( 'touchend', function(e){ e.preventDefault();protractor_stop(e.changedTouches[0]);},false);\ |
||
9289 | schaersvoo | 5105 | };\ |
5106 | function protractor_stop(evt){\ |
||
5107 | protractor_data[0] = protractor_x;\ |
||
5108 | protractor_data[1] = protractor_y;\ |
||
5109 | protractor_data[2] = angle;\ |
||
5110 | return;\ |
||
5111 | };\ |
||
5112 | var protractor_click_cnt = 0;\ |
||
5113 | function protractor_start(evt){\ |
||
11002 | schaersvoo | 5114 | var mouse = dragstuff.getMouse(evt,canvas);\ |
5115 | var mouse_y = mouse.y;\ |
||
5116 | if( mouse_y > ysize - 20 ){return;};\ |
||
5117 | var mouse_x = mouse.x;\ |
||
5118 | if( mouse_x > protractor_x - half && mouse_x < protractor_x + half ){\ |
||
5119 | if( mouse_y > protractor_y - half && mouse_y < protractor_y + half ){\ |
||
5120 | protractor_click_cnt++;\ |
||
5121 | protractor_move(evt);\ |
||
5122 | return;\ |
||
5123 | };\ |
||
5124 | }else{protractor_click_cnt = 0; return;};\ |
||
9289 | schaersvoo | 5125 | };\ |
5126 | function protractor_move(evt){\ |
||
11002 | schaersvoo | 5127 | var mouse = dragstuff.getMouse(evt,canvas);\ |
9289 | schaersvoo | 5128 | switch(protractor_click_cnt){\ |
5129 | case 1:\ |
||
14057 | schaersvoo | 5130 | var xy = multisnap_check(mouse.x,mouse.y,use_snap);\ |
5131 | mouse.x = xy[0];\ |
||
5132 | mouse.y = xy[1];\ |
||
9289 | schaersvoo | 5133 | angle = 0;\ |
14057 | schaersvoo | 5134 | protractor_x = mouse.x;\ |
11002 | schaersvoo | 5135 | protractor_y = mouse.y;\ |
9289 | schaersvoo | 5136 | if( protractor_y > ysize - 20 ){protractor_y = 0.5*ysize;protractor_x = 0.5*xsize;return;};\ |
5137 | ctx.clearRect(0,0,xsize,ysize);\ |
||
5138 | ctx.save();\ |
||
5139 | ctx.translate(protractor_x - xcenter,protractor_y - ycenter);\ |
||
5140 | ctx.drawImage(canvas_temp,0,0);\ |
||
5141 | ctx.restore();\ |
||
5142 | break;\ |
||
5143 | case 2:\ |
||
11017 | schaersvoo | 5144 | angle = find_angle(protractor_x,protractor_y,mouse.x,mouse.y);\ |
9289 | schaersvoo | 5145 | ctx.clearRect(0,0,xsize,ysize);\ |
5146 | ctx.save();\ |
||
5147 | ctx.translate(protractor_x,protractor_y);\ |
||
5148 | ctx.rotate(angle);\ |
||
5149 | ctx.translate( -1*xcenter, -1*ycenter );\ |
||
5150 | ctx.drawImage( canvas_temp,0,0 );\ |
||
5151 | ctx.restore();\ |
||
11017 | schaersvoo | 5152 | userdraw_radius[0] =2*Math.PI- angle;\ |
9289 | schaersvoo | 5153 | break;\ |
5154 | case 3:protractor_click_cnt = 0;break;\ |
||
5155 | default:protractor_stop(evt);\ |
||
5156 | };\ |
||
5157 | };\ |
||
5158 | };\ |
||
5159 | protractor%d();\n\ |
||
5160 | ",canvas_root_id); |
||
5161 | } |
||
5162 | else |
||
5163 | { |
||
5164 | fprintf(js_include_file,"\ |
||
5165 | ctx.save();\ |
||
5166 | ctx.translate(xcenter,ycenter);\ |
||
5167 | ctx.rotate(%d*Math.PI/180);\ |
||
5168 | ctx.translate( -1*xcenter, -1*ycenter );\ |
||
5169 | ctx.drawImage( canvas_temp,0,0 );\ |
||
5170 | ctx.restore();\ |
||
5171 | };\ |
||
5172 | protractor%d();\ |
||
5173 | ",dynamic,canvas_root_id); |
||
5174 | } /* end dynamic == -1*/ |
||
5175 | |||
5176 | } |
||
9329 | schaersvoo | 5177 | |
14038 | schaersvoo | 5178 | |
5179 | |||
14044 | schaersvoo | 5180 |