Rev 18644 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
15111 | schaersvoo | 1 | #include "canvasdraw.h" |
2 | |||
3 | void add_js_userdraw(char *draw_type,char *stroke_color,double stroke_opacity,int crosshair_size,int arrow_head,int use_offset, char *css_class,int use_snap,int canvas_type,int use_filled,char * fill_color,double fill_opacity,int line_width,char *font_family){ |
||
4 | |||
5 | #define MAX_USERDRAW_PRIMITIVES 59 |
||
15126 | bpr | 6 | static char userdraw_primitives[MAX_USERDRAW_PRIMITIVES][32] = { |
15111 | schaersvoo | 7 | "point","points", /* 0,1 */ |
8 | "crosshair","crosshairs",/* 2,3 */ |
||
9 | "circle","circles",/* 4,5 */ |
||
10 | "segment","segments", /* 6,7 */ |
||
11 | "demiline","halfline","demilines","halflines", /* 8,9,10,11 */ |
||
12 | "line","lines", /* 12,13 */ |
||
13 | "hline","hlines", /* 14,15 */ |
||
14 | "vline","vlines", /* 16,17 */ |
||
15 | "arrow","arrows", /* 18,19 */ |
||
16 | "arrow2","arrows2", /* 20,21 */ |
||
17 | "curvedarrow","curvedarrows",/* 22,23 */ |
||
18 | "curvedarrow2","curvedarrows2", /* 24,25 */ |
||
19 | "freehandline","path","freehandlines","paths", /* 26,27,28,29 */ |
||
20 | "poly","polys",/*poly[3]...polys[9] */ /* 30,31 */ |
||
21 | "polygon","polygons", /* 32,33 */ |
||
22 | "polyline","polylines", /* 34,35 */ |
||
23 | "triangle","triangles", /* 36,37 */ |
||
24 | "rect","rects",/* 38,39 */ |
||
25 | "roundrect","roundrects", /* 40,41*/ |
||
26 | "arc","arcs", /* 42,43 */ |
||
27 | "text", /* 44 */ |
||
28 | "image","images", /* 45 46*/ |
||
29 | "input","inputs", /* 47,48*/ |
||
30 | "clickfill","gridfill","diamondfill","dotfill","hatchfill","textfill",/* 49,50,51,52,53,54 */ |
||
31 | "parallelogram","parallelograms",/* 55,56 */ |
||
32 | "function","functions" /* 57,58 is the same as command "userinput function"*/ |
||
33 | }; |
||
34 | |||
35 | /*1+strlen() of words "point","points",... == 6,7,..*/ |
||
36 | //static int userdraw_primitives_length[MAX_USERDRAW_PRIMITIVES] = {6,7,10,11,7,8,8,9,9,9,10,10,5,6,6,7,6,7,6,7,7,8,12,13,13,14,13,5,14,6,5,6,8,9,9,10,9,10,5,6,10,11,4,5,5,6,7,6,7,19,12,8,10,9,14,15}; |
||
37 | |||
38 | static int userdraw_primitives_length[MAX_USERDRAW_PRIMITIVES] = {6,7,10,11,7,8,8,9,9,9,10,10,5,6,6,7,6,7,6,7,7,8,12,13,13,14,13,5,14,6,5,6,8,9,9,10,9,10,5,6,10,11,4,5,5,6,7,6,7,10,9,12,8,10,9,14,15,9,10}; |
||
15126 | bpr | 39 | int p,n; |
15111 | schaersvoo | 40 | int found = 0; |
41 | int draw_num = -1; |
||
42 | int equal = -1;; |
||
43 | int polynum = -1; |
||
44 | |||
45 | |||
15126 | bpr | 46 | if(strncmp(draw_type,"functions",9) == 0){ |
18553 | bpr | 47 | draw_num = 58; polynum = (int) (draw_type[9]-'0');found = 1; |
17351 | bpr | 48 | // fprintf(stdout,"found polys%d<br>",polynum); |
15111 | schaersvoo | 49 | } |
18553 | bpr | 50 | else { |
51 | if(strncmp(draw_type,"polys",5) == 0){ |
||
52 | draw_num = 31; polynum = (int) (draw_type[5]-'0');found = 1; |
||
17351 | bpr | 53 | // fprintf(stdout,"found polys%d<br>",polynum); |
18553 | bpr | 54 | } |
55 | else { |
||
56 | if( strncmp(draw_type,"poly",4) == 0 && ( strstr(draw_type,"polygon") == NULL && strstr(draw_type,"polyline") == NULL ) ){ |
||
57 | draw_num = 30; polynum = (int) (draw_type[4]-'0');found = 1; |
||
17351 | bpr | 58 | // fprintf(stdout,"found poly%d<br>",polynum); |
18553 | bpr | 59 | } |
60 | else { |
||
61 | for( p = 0; p < MAX_USERDRAW_PRIMITIVES ; p++ ){ |
||
62 | equal = strncmp(userdraw_primitives[p],draw_type,userdraw_primitives_length[p]); |
||
15111 | schaersvoo | 63 | /* remake array: static int userdraw_primitives_length[MAX_USERDRAW_PRIMITIVES]*/ |
64 | /* fprintf(stdout,"%d,",1+strlen(userdraw_primitives[p]));*/ |
||
18553 | bpr | 65 | if( equal == 0 ){ |
17351 | bpr | 66 | /* fprintf(stdout,"found %s p=%d<br>",userdraw_primitives[p],p);*/ |
18553 | bpr | 67 | draw_num= p;found=1; break; |
68 | } |
||
69 | } |
||
70 | } |
||
15111 | schaersvoo | 71 | } |
72 | } |
||
73 | if( found == 0 ){canvas_error("unknown userdraw primitive found...typo?");} |
||
74 | |||
75 | /* begin user_draw() */ |
||
15136 | schaersvoo | 76 | |
15128 | schaersvoo | 77 | /* touchend routine for touch devices */ |
78 | fprintf(js_include_file,"\ |
||
79 | function user_drawstop(evt){\ |
||
80 | if(!user_is_dragging){user_drag(evt);return;};\ |
||
81 | if(user_is_dragging){user_draw(evt);return;};\ |
||
82 | };"); |
||
83 | |||
15111 | schaersvoo | 84 | fprintf(js_include_file,"function user_draw(evt){\ |
85 | if(evt.button == 2){remove_last();return;};\ |
||
86 | var mouse = getMouse(evt,canvas_userdraw);\ |
||
87 | var xy = multisnap_check(mouse.x,mouse.y,use_snap);\ |
||
15128 | schaersvoo | 88 | user_is_dragging = false;\ |
15111 | schaersvoo | 89 | var x = xy[0];var y = xy[1];\ |
90 | if(x>forbidden_zone[0] && y>forbidden_zone[1]){console.log('drawing in zoom area...');return;};\ |
||
91 | "); |
||
92 | int temp_reply_format = 22; |
||
93 | switch( draw_num ){ |
||
18553 | bpr | 94 | default: break; |
95 | case 0:temp_reply_format = 8;fprintf(js_include_file,"points(x,y,0,0);");break; |
||
96 | case 1:temp_reply_format = 8;fprintf(js_include_file,"points(x,y,0,1);");break; |
||
97 | case 2:temp_reply_format = 8;fprintf(js_include_file,"crosshairs(x,y,0,0);");break; |
||
98 | case 3:temp_reply_format = 8;fprintf(js_include_file,"crosshairs(x,y,0,1);");break; |
||
99 | case 4:temp_reply_format = 10;fprintf(js_include_file,"circles(x,y,0,0);");break; |
||
100 | case 5:temp_reply_format = 10;fprintf(js_include_file,"circles(x,y,0,1);");break; |
||
101 | case 6:temp_reply_format = 11;fprintf(js_include_file,"segments(x,y,0,0);");break; |
||
102 | case 7:temp_reply_format = 11;fprintf(js_include_file,"segments(x,y,0,1);");break; |
||
103 | case 8 ... 9:temp_reply_format = 11;fprintf(js_include_file,"demilines(x,y,0,0);");break; |
||
104 | case 10 ... 11:temp_reply_format = 11;fprintf(js_include_file,"demilines(x,y,0,1);");break; |
||
105 | case 12:temp_reply_format = 11;fprintf(js_include_file,"lines(x,y,0,0);");break; |
||
106 | case 13:temp_reply_format = 11;fprintf(js_include_file,"lines(x,y,0,1);");break; |
||
107 | case 14:temp_reply_format = 11;fprintf(js_include_file,"hlines(x,y,0,0);");break; |
||
108 | case 15:temp_reply_format = 11;fprintf(js_include_file,"hlines(x,y,0,1);");break; |
||
109 | case 16:temp_reply_format = 11;fprintf(js_include_file,"vlines(x,y,0,0);");break; |
||
110 | case 17:temp_reply_format = 11;fprintf(js_include_file,"vlines(x,y,0,1);");break; |
||
111 | case 18:temp_reply_format = 11;fprintf(js_include_file,"arrows(x,y,0,0);");break; |
||
112 | case 19:temp_reply_format = 11;fprintf(js_include_file,"arrows(x,y,0,1);");break; |
||
113 | case 20:temp_reply_format = 11;fprintf(js_include_file,"arrows2(x,y,0,0);");break; |
||
114 | case 21:temp_reply_format = 11;fprintf(js_include_file,"arrows2(x,y,0,1);");break; |
||
115 | case 22:temp_reply_format = 2;fprintf(js_include_file,"curvedarrows(x,y,0,0);");break; |
||
116 | case 23:temp_reply_format = 2;fprintf(js_include_file,"curvedarrows(x,y,0,1);");break; |
||
117 | case 24:temp_reply_format = 2;fprintf(js_include_file,"curvedarrows2(x,y,0,0);");break; |
||
118 | case 25:temp_reply_format = 2;fprintf(js_include_file,"curvedarrows2(x,y,0,1);");break; |
||
119 | case 26 ... 27:temp_reply_format = 6;fprintf(js_include_file,"paths(x,y,0,0);");break; |
||
120 | case 28 ... 29:temp_reply_format = 6;fprintf(js_include_file,"paths(x,y,0,0);");break; |
||
121 | case 30:temp_reply_format = 2;fprintf(js_include_file,"polys(x,y,0,0);");break; |
||
122 | case 31:temp_reply_format = 2;fprintf(js_include_file,"polys(x,y,0,1);");break; |
||
123 | case 32:temp_reply_format = 2;fprintf(js_include_file,"polygon(x,y,0,0);");break; |
||
124 | case 33:temp_reply_format = 2;fprintf(js_include_file,"polygon(x,y,0,1);");break; |
||
125 | case 34:temp_reply_format = 23;fprintf(js_include_file,"polylines(x,y,0,1);");break; |
||
126 | case 35:temp_reply_format = 23;fprintf(js_include_file,"polylines(x,y,0,1);");break; |
||
127 | case 36:temp_reply_format = 2;fprintf(js_include_file,"triangles(x,y,0,0);");break; |
||
128 | case 37:temp_reply_format = 2;fprintf(js_include_file,"triangles(x,y,0,1);");break; |
||
129 | case 38:temp_reply_format = 2;fprintf(js_include_file,"rects(x,y,0,0);");break; |
||
130 | case 39:temp_reply_format = 2;fprintf(js_include_file,"rects(x,y,0,1);");break; |
||
131 | case 40:temp_reply_format = 2;fprintf(js_include_file,"roundrects(x,y,0,0);");break; |
||
132 | case 41:temp_reply_format = 2;fprintf(js_include_file,"roundrects(x,y,0,1);");break; |
||
133 | case 42:temp_reply_format = 25;js_function[JS_FIND_ANGLE] = 1; fprintf(js_include_file,"arcs(x,y,0,0);");break; |
||
134 | case 43:temp_reply_format = 25;js_function[JS_FIND_ANGLE] = 1; fprintf(js_include_file,"arcs(x,y,0,1);");break; |
||
135 | case 44:temp_reply_format = 17;js_function[DRAW_SUBSUP] = 1;fprintf(js_include_file,"text(x,y,0,1);");break; |
||
136 | case 45:temp_reply_format = 17;fprintf(js_include_file,"images(x,y,0,0);");break; |
||
137 | case 46:temp_reply_format = 17;fprintf(js_include_file,"images(x,y,0,1);");break; |
||
138 | case 47:temp_reply_format = 27;fprintf(js_include_file,"inputs(x,y,0,0);");break; |
||
139 | case 48:temp_reply_format = 27;fprintf(js_include_file,"inputs(x,y,0,1);");break; |
||
140 | case 49 ... 54 : |
||
15111 | schaersvoo | 141 | /* |
15126 | bpr | 142 | "clickfill 49","gridfill 50","diamondfill 51","dotfill 52","hatchfill 53","textfill 54", 49,50,51,52,53,54 |
143 | use_filled ... 0:no fill, 1:fill,2=grid?,3=hatch?,4=diamond?,5=dot?,6=image ? |
||
15111 | schaersvoo | 144 | */ |
18553 | bpr | 145 | temp_reply_format = 10; |
15111 | schaersvoo | 146 | fprintf(js_include_file,"clickfill(x,y,0,1);"); |
147 | if( draw_num == 49 ){ use_filled = 1;} |
||
148 | else{ |
||
149 | if( draw_num == 50 ){js_function[DRAW_GRIDFILL] = 1;use_filled = 2;} |
||
150 | else{ |
||
151 | if( draw_num == 51 ){js_function[DRAW_DIAMONDFILL] = 1;use_filled = 4;} |
||
152 | else{ |
||
153 | if( draw_num == 52 ){js_function[DRAW_DOTFILL] = 1;use_filled = 5;} |
||
154 | else{ |
||
155 | if( draw_num == 53 ){js_function[DRAW_HATCHFILL] = 1;use_filled = 3;} |
||
156 | else{ |
||
157 | if( draw_num == 54 ){js_function[DRAW_TEXTFILL] = 1;use_filled = 7;}}}}}} |
||
15126 | bpr | 158 | break; |
159 | |||
15111 | schaersvoo | 160 | case 55:temp_reply_format = 2;fprintf(js_include_file,"parallelograms(x,y,0,0);");break; |
161 | case 56:temp_reply_format = 2;fprintf(js_include_file,"parallelograms(x,y,0,1);");break; |
||
162 | case 57 ... 58: |
||
18635 | bpr | 163 | // fprintf(stdout,"functions num = %d;",(int) (draw_type[9]-'0'));*/ /* functions4 == 9 |
15111 | schaersvoo | 164 | if(reply_format == 0 || reply_format != -1){reply_format = 24;} |
165 | break; |
||
166 | |||
167 | } |
||
168 | fprintf(js_include_file," return;};"); |
||
169 | |||
170 | if( reply_format == 0 ){reply_format = temp_reply_format;} |
||
171 | |||
172 | /* begin user_drag() */ |
||
173 | fprintf(js_include_file,"function user_drag(evt){\ |
||
174 | var mouse = getMouse(evt,canvas_userdraw);\ |
||
15121 | schaersvoo | 175 | if(isTouch){var xy = multisnap_check(mouse.x,mouse.y,use_snap);};\ |
15128 | schaersvoo | 176 | var x = mouse.x;var y = mouse.y;\ |
177 | user_is_dragging = true;\ |
||
178 | if(x>forbidden_zone[0] && y>forbidden_zone[1]){return;};"); |
||
15111 | schaersvoo | 179 | switch( draw_num ){ |
18553 | bpr | 180 | case 0:fprintf(js_include_file,"return;");break; |
181 | case 1:fprintf(js_include_file,"return;");break; |
||
182 | case 2:fprintf(js_include_file,"return;");break; |
||
183 | case 3:fprintf(js_include_file,"return;");break; |
||
184 | case 4:fprintf(js_include_file,"circles(x,y,1,0);return;");break; |
||
185 | case 5:fprintf(js_include_file,"circles(x,y,1,1);return;");break; |
||
186 | case 6:fprintf(js_include_file,"segments(x,y,1,0);");break; |
||
187 | case 7:fprintf(js_include_file,"segments(x,y,1,1);return;");break; |
||
188 | case 8 ... 9:fprintf(js_include_file,"demilines(x,y,1,0);return;");break; |
||
189 | case 10 ... 11:fprintf(js_include_file,"demilines(x,y,1,1);return;");break; |
||
190 | case 12:fprintf(js_include_file,"lines(x,y,1,0);return;");break; |
||
191 | case 13:fprintf(js_include_file,"lines(x,y,1,1);return;");break; |
||
192 | case 14:fprintf(js_include_file,"hlines(x,y,1,0);return;");break; |
||
193 | case 15:fprintf(js_include_file,"hlines(x,y,1,1);return;");break; |
||
194 | case 16:fprintf(js_include_file,"vlines(x,y,1,0);return;");break; |
||
195 | case 17:fprintf(js_include_file,"vlines(x,y,1,1);return;");break; |
||
196 | case 18:fprintf(js_include_file,"arrows(x,y,1,0);return;");break; |
||
197 | case 19:fprintf(js_include_file,"arrows(x,y,1,1);return;");break; |
||
198 | case 20:fprintf(js_include_file,"arrows2(x,y,1,0);return;");break; |
||
199 | case 21:fprintf(js_include_file,"arrows2(x,y,1,1);return;");break; |
||
200 | case 22:fprintf(js_include_file,"curvedarrows(x,y,1,0);return;");break; |
||
201 | case 23:fprintf(js_include_file,"curvedarrows(x,y,1,1);return;");break; |
||
202 | case 24:fprintf(js_include_file,"curvedarrows2(x,y,1,0);return;");break; |
||
203 | case 25:fprintf(js_include_file,"curvedarrows2(x,y,1,1);return;");break; |
||
204 | case 26 ... 27:fprintf(js_include_file,"paths(x,y,1,0);return;");break; |
||
205 | case 28 ... 29:fprintf(js_include_file,"paths(x,y,1,0);return;");break; |
||
206 | case 30:fprintf(js_include_file,"polys(x,y,1,0);return;");break; |
||
207 | case 31:fprintf(js_include_file,"polys(x,y,1,1);return;");break; |
||
208 | case 32:fprintf(js_include_file,"polygon(x,y,1,0);return;");break; |
||
209 | case 33:fprintf(js_include_file,"polygon(x,y,1,1);return;");break; |
||
210 | case 34:fprintf(js_include_file,"polylines(x,y,1,1);return;");break; |
||
211 | case 35:fprintf(js_include_file,"polylines(x,y,1,1);return;");break; |
||
212 | case 36:fprintf(js_include_file,"triangles(x,y,1,0);return;");break; |
||
213 | case 37:fprintf(js_include_file,"triangles(x,y,1,1);return;");break; |
||
214 | case 38:fprintf(js_include_file,"rects(x,y,1,0);return;");break; |
||
215 | case 39:fprintf(js_include_file,"rects(x,y,1,1);return;");break; |
||
216 | case 40:fprintf(js_include_file,"roundrects(x,y,1,0);return;");break; |
||
217 | case 41:fprintf(js_include_file,"roundrects(x,y,1,1);return;");break; |
||
218 | case 42:fprintf(js_include_file,"arcs(x,y,1,0);return;");break; |
||
219 | case 43:fprintf(js_include_file,"arcs(x,y,1,1);return;");break; |
||
220 | case 44:fprintf(js_include_file,"return;");break; |
||
221 | case 45:fprintf(js_include_file,"return;");break; |
||
222 | case 46:fprintf(js_include_file,"return;");break; |
||
223 | case 47:fprintf(js_include_file,"return;");break; |
||
224 | case 48:fprintf(js_include_file,"return;");break; |
||
225 | case 49:fprintf(js_include_file,"return;");break; |
||
226 | case 50:fprintf(js_include_file,"return;");break; |
||
227 | case 51:fprintf(js_include_file,"return;");break; |
||
228 | case 52:fprintf(js_include_file,"return;");break; |
||
229 | case 53:fprintf(js_include_file,"return;");break; |
||
230 | case 54:fprintf(js_include_file,"return;");break; |
||
231 | case 55:fprintf(js_include_file,"parallelograms(x,y,1,0);return;");break; |
||
232 | case 56:fprintf(js_include_file,"parallelograms(x,y,1,1);return;");break; |
||
233 | case 57 ... 58: break; |
||
15111 | schaersvoo | 234 | } |
235 | |||
236 | fprintf(js_include_file,"};"); |
||
237 | |||
238 | /* add all stuff needed to draw the selected primitives... */ |
||
239 | switch( draw_num ){ |
||
240 | /* point/points */ |
||
18553 | bpr | 241 | case -1 : break; |
242 | case 0 ... 1: |
||
243 | fprintf(js_include_file,"\ |
||
15111 | schaersvoo | 244 | context_userdraw.fillStyle = \"rgba(%s,%.2f)\";\ |
245 | function redraw_userdraw(){draw_points();}\ |
||
246 | function remove_last(){if( userdraw_x.length > 0 ){userdraw_x.pop();userdraw_y.pop();draw_points();};return;};\ |
||
247 | function points(x,y,event_which,num){\ |
||
248 | if(event_which == 1){ return; };\ |
||
249 | if( num == 0 ){\ |
||
250 | userdraw_x[0] = x;\ |
||
251 | userdraw_y[0] = y;\ |
||
252 | }else{\ |
||
253 | userdraw_x.push(x);\ |
||
254 | userdraw_y.push(y);\ |
||
255 | };\ |
||
256 | draw_points();\ |
||
257 | };\ |
||
258 | function draw_points(){\ |
||
259 | var len = userdraw_x.length;\ |
||
260 | var radius = 2*(context_userdraw.lineWidth);\ |
||
261 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
||
262 | var r = 2*Math.PI;\ |
||
263 | for(var p = 0 ; p < len ; p++ ){\ |
||
264 | context_userdraw.beginPath();\ |
||
265 | context_userdraw.arc(userdraw_x[p],userdraw_y[p],radius,0,r,false);\ |
||
266 | context_userdraw.closePath();context_userdraw.fill();\ |
||
267 | };\ |
||
268 | };",stroke_color,stroke_opacity); |
||
18553 | bpr | 269 | break; |
15111 | schaersvoo | 270 | /* crosshair /crosshairs */ |
18553 | bpr | 271 | case 2 ... 3: |
272 | fprintf(js_include_file,"\ |
||
15111 | schaersvoo | 273 | function redraw_userdraw(){draw_crosshairs();};\ |
274 | function remove_last(){if( userdraw_x.length > 0 ){userdraw_x.pop();userdraw_y.pop();draw_crosshairs();};return;};\ |
||
275 | function crosshairs(x,y,event_which,num){\ |
||
276 | if(event_which == 1){ return; };\ |
||
277 | if( num == 0 ){\ |
||
278 | userdraw_x[0] = x;\ |
||
279 | userdraw_y[0] = y;\ |
||
280 | }else{\ |
||
281 | userdraw_x.push(x);\ |
||
282 | userdraw_y.push(y);\ |
||
283 | };\ |
||
284 | draw_crosshairs();\ |
||
285 | };\ |
||
286 | function draw_crosshairs(){\ |
||
287 | var crosshair_size = %d;\ |
||
288 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
||
289 | var x1,x2,y1,y2;\ |
||
290 | var len = userdraw_x.length;\ |
||
291 | for(var p = 0 ; p < len ; p++ ){\ |
||
292 | x1 = userdraw_x[p] - crosshair_size;\ |
||
293 | x2 = userdraw_x[p] + crosshair_size;\ |
||
294 | y1 = userdraw_y[p] - crosshair_size;\ |
||
295 | y2 = userdraw_y[p] + crosshair_size;\ |
||
296 | context_userdraw.beginPath();\ |
||
297 | context_userdraw.moveTo(x1,y1);\ |
||
298 | context_userdraw.lineTo(x2,y2);\ |
||
299 | context_userdraw.closePath();\ |
||
300 | context_userdraw.stroke();\ |
||
301 | context_userdraw.beginPath();\ |
||
302 | context_userdraw.moveTo(x2,y1);\ |
||
303 | context_userdraw.lineTo(x1,y2);\ |
||
304 | context_userdraw.closePath();\ |
||
305 | context_userdraw.stroke();\ |
||
306 | };\ |
||
307 | };",crosshair_size); |
||
18553 | bpr | 308 | break; |
15111 | schaersvoo | 309 | /* circle/circles */ |
18553 | bpr | 310 | case 4 ... 5 : |
311 | fprintf(js_include_file,"\ |
||
15111 | schaersvoo | 312 | function redraw_userdraw(){draw_circles();};\ |
313 | function remove_last(){if( userdraw_x.length > 0 ){userdraw_x.pop();userdraw_y.pop();userdraw_radius.pop();draw_circles();};return;};\ |
||
314 | function circles(x,y,event_which,num){\ |
||
315 | var last = userdraw_x.length - 1;\ |
||
316 | var xc = userdraw_x[last];\ |
||
317 | var yc = userdraw_y[last];\ |
||
318 | if(event_which == 0){\ |
||
319 | if( xy_cnt == 0 ){\ |
||
320 | if( num == 0 ){\ |
||
321 | userdraw_x[0]=x;userdraw_y[0]=y;userdraw_radius[0]=4;\ |
||
322 | }\ |
||
323 | else\ |
||
324 | {\ |
||
325 | userdraw_x.push(x);userdraw_y.push(y);userdraw_radius.push(4);\ |
||
326 | };\ |
||
327 | };\ |
||
328 | xy_cnt++;\ |
||
329 | }\ |
||
330 | else\ |
||
331 | {\ |
||
332 | if( xy_cnt == 1 ){\ |
||
333 | userdraw_radius[last] = parseInt(Math.sqrt( (x - xc)*(x - xc) + (y - yc)*(y - yc) ));\ |
||
334 | };\ |
||
335 | };\ |
||
336 | if( xy_cnt == 2 ){\ |
||
337 | xy_cnt = 0;\ |
||
338 | if( num == 0 ){\ |
||
339 | userdraw_x = [];userdraw_y = [];\ |
||
340 | userdraw_x[0] = xc;userdraw_y[0] = yc;\ |
||
341 | };\ |
||
342 | };\ |
||
343 | draw_circles();\ |
||
344 | };\ |
||
345 | function draw_circles(){\ |
||
346 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
||
347 | var len = userdraw_x.length;\ |
||
348 | var r = 2*Math.PI;\ |
||
349 | for(var p = 0 ; p < len ; p++ ){\ |
||
350 | context_userdraw.beginPath();\ |
||
351 | context_userdraw.arc(userdraw_x[p],userdraw_y[p],userdraw_radius[p],0,r,false);\ |
||
352 | context_userdraw.closePath();\ |
||
353 | if(use_filled!=0){context_userdraw.fill();};\ |
||
354 | context_userdraw.stroke();\ |
||
355 | };\ |
||
356 | return;\ |
||
357 | };"); |
||
18553 | bpr | 358 | break; |
15111 | schaersvoo | 359 | |
360 | /* segment/segments */ |
||
18553 | bpr | 361 | case 6 ... 7 : |
362 | fprintf(js_include_file,"\ |
||
15111 | schaersvoo | 363 | function redraw_userdraw(){draw_segments();};\ |
364 | function remove_last(){if( userdraw_x.length > 0 ){for(var p=0;p<2;p++){userdraw_x.pop();userdraw_y.pop();};draw_segments();};return;};\ |
||
365 | function segments(x,y,event_which,num){\ |
||
366 | if(event_which == 0){\ |
||
367 | if( num == 0 && xy_cnt == 0 ){userdraw_x = [];userdraw_y = [];};\ |
||
368 | userdraw_x.push(x);userdraw_y.push(y);\ |
||
369 | xy_cnt++;\ |
||
370 | }\ |
||
371 | else\ |
||
372 | {\ |
||
373 | if( xy_cnt == 1 ){\ |
||
374 | userdraw_x.push(x);userdraw_y.push(y);\ |
||
375 | draw_segments();\ |
||
376 | userdraw_x.pop();userdraw_y.pop();\ |
||
377 | };\ |
||
378 | };\ |
||
379 | if( xy_cnt == 2 ){\ |
||
380 | xy_cnt = 0;\ |
||
381 | draw_segments();\ |
||
382 | };\ |
||
383 | };\ |
||
384 | function draw_segments(){\ |
||
385 | var len = userdraw_x.length;\ |
||
386 | if( len%%2 == 0 ){\ |
||
387 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
||
388 | for(var p = 0 ; p < len ; p = p+2 ){\ |
||
389 | context_userdraw.beginPath();\ |
||
390 | context_userdraw.moveTo(userdraw_x[p],userdraw_y[p]);\ |
||
391 | context_userdraw.lineTo(userdraw_x[p+1],userdraw_y[p+1]);\ |
||
392 | context_userdraw.closePath();\ |
||
393 | context_userdraw.stroke();\ |
||
394 | };\ |
||
395 | };\ |
||
396 | return;\ |
||
397 | };"); |
||
15126 | bpr | 398 | |
15111 | schaersvoo | 399 | /* "demiline","demilines","halfline","halflines" 8,9,10,11 */ |
18553 | bpr | 400 | case 8 ... 11 : |
401 | fprintf(js_include_file,"\ |
||
15111 | schaersvoo | 402 | function redraw_userdraw(){draw_demilines();};\ |
403 | function find_inf_point(x1,y1,x2,y2){\ |
||
404 | if(x1<x2+2 && x1>x2-2){if(y1<y2){return [x1,y1,x1,ysize];}else{return [x1,0,x1,y1];};};\ |
||
405 | var rc = (y2 - y1)/(x2 - x1);var q = y1 - (x1)*rc;\ |
||
406 | if( x1 < x2 ){ return [x1,y1,xsize,rc*xsize+q];}else{return [x1,y1,0,q];};\ |
||
407 | };\ |
||
408 | function calc_lines(){\ |
||
409 | var len = userdraw_x.length;\ |
||
410 | var points = find_inf_point(userdraw_x[len-2],userdraw_y[len-2],userdraw_x[len-1],userdraw_y[len-1]);\ |
||
411 | userdraw_x[len-2] = points[0];\ |
||
412 | userdraw_y[len-2] = points[1];\ |
||
413 | userdraw_x[len-1] = points[2];\ |
||
414 | userdraw_y[len-1] = points[3];\ |
||
415 | };\ |
||
416 | function remove_last(){if( userdraw_x.length > 0 ){for(var p=0;p<2;p++){userdraw_x.pop();userdraw_y.pop();};draw_demilines();};return;};\ |
||
417 | function demilines(x,y,event_which,num){\ |
||
418 | if(event_which == 0){\ |
||
419 | if( num == 0 && xy_cnt == 0 ){userdraw_x = [];userdraw_y = [];};\ |
||
420 | userdraw_x.push(x);userdraw_y.push(y);\ |
||
421 | xy_cnt++;\ |
||
422 | }\ |
||
423 | else\ |
||
424 | {\ |
||
425 | if( xy_cnt == 1 ){\ |
||
426 | userdraw_x.push(x);userdraw_y.push(y);\ |
||
427 | draw_demilines();\ |
||
428 | userdraw_x.pop();userdraw_y.pop();\ |
||
429 | };\ |
||
430 | };\ |
||
431 | if( xy_cnt == 2 ){\ |
||
432 | xy_cnt = 0;\ |
||
433 | calc_lines();\ |
||
434 | draw_demilines();\ |
||
435 | };\ |
||
436 | };\ |
||
437 | function draw_demilines(){\ |
||
438 | var len = userdraw_x.length;\ |
||
439 | if( len %%2 == 0 ){\ |
||
440 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
||
441 | for(var p = 0 ; p < len ; p = p+2 ){\ |
||
442 | context_userdraw.beginPath();\ |
||
443 | context_userdraw.moveTo(userdraw_x[p],userdraw_y[p]);\ |
||
444 | context_userdraw.lineTo(userdraw_x[p+1],userdraw_y[p+1]);\ |
||
445 | context_userdraw.closePath();\ |
||
446 | context_userdraw.stroke();\ |
||
447 | };\ |
||
448 | };\ |
||
449 | return;\ |
||
450 | };"); |
||
18553 | bpr | 451 | break; |
15111 | schaersvoo | 452 | /* line/lines */ |
18553 | bpr | 453 | case 12 ... 13 : |
15111 | schaersvoo | 454 | fprintf(js_include_file,"\ |
455 | function redraw_userdraw(){calc_lines();draw_lines();};\ |
||
456 | function calc_lines(){\ |
||
457 | var marge = 2;var len = userdraw_x.length;\ |
||
15118 | schaersvoo | 458 | var tmp_x = new Array(len);\ |
459 | var tmp_y = new Array(len);\ |
||
15111 | schaersvoo | 460 | var pp;\ |
461 | for(var p = 0 ; p < len ;p = p+2){\ |
||
462 | pp = p+1;\ |
||
15118 | schaersvoo | 463 | if(userdraw_x[p] < userdraw_x[pp]+marge && userdraw_x[p] > userdraw_x[pp]-marge){\ |
464 | tmp_x[p] = userdraw_x[p];tmp_x[pp] = userdraw_x[pp];\ |
||
465 | tmp_y[p] = 0;tmp_y[pp] = ysize;\ |
||
15111 | schaersvoo | 466 | }\ |
467 | else\ |
||
468 | {\ |
||
15118 | schaersvoo | 469 | if(userdraw_y[p] < userdraw_y[pp]+marge && userdraw_y[p] > userdraw_y[pp]-marge){\ |
470 | tmp_x[p] = 0;tmp_x[pp] = xsize;\ |
||
471 | tmp_y[p] = userdraw_y[p];tmp_y[pp] = userdraw_y[pp];\ |
||
15111 | schaersvoo | 472 | }\ |
473 | else\ |
||
474 | {\ |
||
15118 | schaersvoo | 475 | tmp_x[p] = 0;tmp_x[pp] = xsize;\ |
476 | tmp_y[p] = userdraw_y[p] - (userdraw_x[p])*(userdraw_y[pp] - userdraw_y[p])/(userdraw_x[pp] - userdraw_x[p]);\ |
||
477 | tmp_y[pp] = userdraw_y[p] + (xsize - userdraw_x[p])*(userdraw_y[pp] - userdraw_y[p])/(userdraw_x[pp] - userdraw_x[p]);\ |
||
15111 | schaersvoo | 478 | };\ |
479 | };\ |
||
480 | };\ |
||
15118 | schaersvoo | 481 | return {x:tmp_x,y:tmp_y};\ |
15111 | schaersvoo | 482 | };\ |
483 | function remove_last(){if( userdraw_x.length > 0 ){for(var p=0;p<2;p++){userdraw_x.pop();userdraw_y.pop();};draw_lines();};return;};\ |
||
484 | function lines(x,y,event_which,num){\ |
||
485 | if(event_which == 0){\ |
||
486 | if( num == 0 && xy_cnt == 0 ){userdraw_x = [];userdraw_y = [];};\ |
||
487 | userdraw_x.push(x);userdraw_y.push(y);\ |
||
488 | xy_cnt++;\ |
||
489 | }\ |
||
490 | else\ |
||
491 | {\ |
||
492 | if( xy_cnt == 1 ){\ |
||
493 | userdraw_x.push(x);userdraw_y.push(y);\ |
||
494 | draw_lines();\ |
||
495 | userdraw_x.pop();userdraw_y.pop();\ |
||
496 | };\ |
||
497 | };\ |
||
498 | if( xy_cnt == 2 ){\ |
||
499 | xy_cnt = 0;\ |
||
500 | draw_lines();\ |
||
501 | };\ |
||
502 | };\ |
||
503 | function draw_lines(){\ |
||
504 | var len = userdraw_x.length;\ |
||
505 | if( len %%2 == 0 ){\ |
||
15118 | schaersvoo | 506 | var xy = calc_lines();\ |
15111 | schaersvoo | 507 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
508 | for(var p = 0 ; p < len ; p = p+2 ){\ |
||
509 | context_userdraw.beginPath();\ |
||
15118 | schaersvoo | 510 | context_userdraw.moveTo(xy.x[p],xy.y[p]);\ |
511 | context_userdraw.lineTo(xy.x[p+1],xy.y[p+1]);\ |
||
15111 | schaersvoo | 512 | context_userdraw.closePath();\ |
513 | context_userdraw.stroke();\ |
||
514 | };\ |
||
515 | };\ |
||
516 | return;\ |
||
517 | };"); |
||
18553 | bpr | 518 | break; |
15111 | schaersvoo | 519 | /* hline/hlines 14,15 */ |
18553 | bpr | 520 | case 14 ... 15: |
521 | fprintf(js_include_file,"\ |
||
15111 | schaersvoo | 522 | function redraw_userdraw(){draw_hlines();};\ |
523 | function remove_last(){if( userdraw_x.length > 0 ){for(var p=0;p<2;p++){userdraw_x.pop();userdraw_y.pop();};draw_hlines();};return;};\ |
||
524 | function hlines(x,y,event_which,num){\ |
||
525 | if(event_which == 0){\ |
||
526 | if( num == 0 ){userdraw_x = [];userdraw_y = [];};\ |
||
527 | userdraw_x.push(0);userdraw_y.push(y);\ |
||
528 | userdraw_x.push(xsize);userdraw_y.push(y);\ |
||
529 | draw_hlines();\ |
||
530 | };\ |
||
531 | };\ |
||
532 | function draw_hlines(){\ |
||
533 | var len = userdraw_x.length;\ |
||
534 | if( len %%2 == 0 ){\ |
||
535 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
||
536 | for(var p = 0 ; p < len ; p = p+2 ){\ |
||
537 | context_userdraw.beginPath();\ |
||
538 | context_userdraw.moveTo(userdraw_x[p],userdraw_y[p]);\ |
||
539 | context_userdraw.lineTo(userdraw_x[p+1],userdraw_y[p+1]);\ |
||
540 | context_userdraw.closePath();\ |
||
541 | context_userdraw.stroke();\ |
||
542 | };\ |
||
543 | };\ |
||
544 | return;\ |
||
545 | };"); |
||
546 | |||
18553 | bpr | 547 | break; |
15111 | schaersvoo | 548 | /* vline,vlines 16,17 */ |
18553 | bpr | 549 | case 16 ... 17: |
550 | fprintf(js_include_file,"\ |
||
15111 | schaersvoo | 551 | function redraw_userdraw(){draw_vlines();};\ |
552 | function remove_last(){if( userdraw_x.length > 0 ){for(var p=0;p<2;p++){userdraw_x.pop();userdraw_y.pop();};draw_vlines();};return;};\ |
||
553 | function vlines(x,y,event_which,num){\ |
||
554 | if(event_which == 0){\ |
||
555 | if( num == 0 ){userdraw_x = [];userdraw_y = [];};\ |
||
556 | userdraw_x.push(x);userdraw_y.push(0);\ |
||
557 | userdraw_x.push(x);userdraw_y.push(ysize);\ |
||
558 | draw_vlines();\ |
||
559 | };\ |
||
560 | };\ |
||
561 | function draw_vlines(){\ |
||
562 | var len = userdraw_x.length;\ |
||
563 | if( len %%2 == 0 ){\ |
||
564 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
||
565 | for(var p = 0 ; p < len ; p = p+2 ){\ |
||
566 | context_userdraw.beginPath();\ |
||
567 | context_userdraw.moveTo(userdraw_x[p],userdraw_y[p]);\ |
||
568 | context_userdraw.lineTo(userdraw_x[p+1],userdraw_y[p+1]);\ |
||
569 | context_userdraw.closePath();\ |
||
570 | context_userdraw.stroke();\ |
||
571 | };\ |
||
572 | };\ |
||
573 | return;};"); |
||
574 | |||
18553 | bpr | 575 | break; |
15111 | schaersvoo | 576 | /* arrow/arrows */ |
18553 | bpr | 577 | case 18 ... 19 : |
15111 | schaersvoo | 578 | fprintf(js_include_file,"\ |
579 | function redraw_userdraw(){draw_arrows();};\ |
||
580 | context_userdraw.fillStyle = \"rgba(%s,%.2f)\";\ |
||
581 | function remove_last(){if( userdraw_x.length > 0 ){for(var p=0;p<2;p++){userdraw_x.pop();userdraw_y.pop();};draw_arrows();};return;};\ |
||
582 | function arrows(x,y,event_which,num){\ |
||
583 | if(event_which == 0){\ |
||
584 | if( num == 0 && xy_cnt == 0 ){userdraw_x = [];userdraw_y = [];};\ |
||
585 | userdraw_x.push(x);userdraw_y.push(y);\ |
||
586 | xy_cnt++;\ |
||
587 | }\ |
||
588 | else\ |
||
589 | {\ |
||
590 | if( xy_cnt == 1 ){\ |
||
591 | userdraw_x.push(x);userdraw_y.push(y);\ |
||
592 | draw_arrows();\ |
||
593 | userdraw_x.pop();userdraw_y.pop();\ |
||
594 | };\ |
||
595 | };\ |
||
596 | if( xy_cnt == 2 ){\ |
||
597 | xy_cnt = 0;\ |
||
598 | draw_arrows();\ |
||
599 | };\ |
||
600 | };\ |
||
601 | function draw_arrows(){\ |
||
602 | var arrow_head = %d;\ |
||
603 | var len = userdraw_x.length;\ |
||
604 | var x1,y1,x2,y2,dx,dy,h;\ |
||
605 | if( len%%2 == 0 ){\ |
||
606 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
||
607 | for(var p = 0 ; p < len ; p = p+2 ){\ |
||
15711 | schaersvoo | 608 | x1 = userdraw_x[p];y1 = userdraw_y[p];x2 = userdraw_x[p+1];y2 = userdraw_y[p+1];dx = x2 - x1;dy = y2 - y1;\ |
15111 | schaersvoo | 609 | context_userdraw.save();\ |
15711 | schaersvoo | 610 | context_userdraw.setLineDash([]);\ |
15111 | schaersvoo | 611 | context_userdraw.translate(x2,y2);\ |
612 | context_userdraw.rotate(Math.atan2(dy,dx));\ |
||
613 | context_userdraw.beginPath();\ |
||
614 | context_userdraw.moveTo(0,0);\ |
||
615 | context_userdraw.lineTo(-1*arrow_head,-0.5*arrow_head);\ |
||
616 | context_userdraw.lineTo(-1*arrow_head, 0.5*arrow_head);\ |
||
617 | context_userdraw.closePath();\ |
||
618 | context_userdraw.fill();\ |
||
619 | context_userdraw.stroke();\ |
||
620 | context_userdraw.restore();\ |
||
15711 | schaersvoo | 621 | context_userdraw.beginPath();\ |
622 | context_userdraw.moveTo(x1,y1);\ |
||
623 | context_userdraw.lineTo(x2,y2);\ |
||
624 | context_userdraw.closePath();\ |
||
625 | context_userdraw.stroke();\ |
||
15111 | schaersvoo | 626 | };\ |
627 | };\ |
||
628 | return;\ |
||
629 | };",stroke_color,stroke_opacity,arrow_head); |
||
18553 | bpr | 630 | break; |
15111 | schaersvoo | 631 | /* arrow/arrows */ |
18553 | bpr | 632 | case 20 ... 21 : |
15111 | schaersvoo | 633 | fprintf(js_include_file,"\ |
634 | function redraw_userdraw(){draw_arrows2();};\ |
||
635 | context_userdraw.fillStyle = \"rgba(%s,%.2f)\";\ |
||
636 | function remove_last(){if( userdraw_x.length > 0 ){for(var p=0;p<2;p++){userdraw_x.pop();userdraw_y.pop();};draw_arrows();};return;};\ |
||
637 | function arrows2(x,y,event_which,num){\ |
||
638 | if(event_which == 0){\ |
||
639 | if( num == 0 && xy_cnt == 0 ){userdraw_x = [];userdraw_y = [];};\ |
||
640 | userdraw_x.push(x);userdraw_y.push(y);\ |
||
641 | xy_cnt++;\ |
||
642 | }\ |
||
643 | else\ |
||
644 | {\ |
||
645 | if( xy_cnt == 1 ){\ |
||
646 | userdraw_x.push(x);userdraw_y.push(y);\ |
||
647 | draw_arrows2();\ |
||
648 | userdraw_x.pop();userdraw_y.pop();\ |
||
649 | };\ |
||
650 | };\ |
||
651 | if( xy_cnt == 2 ){\ |
||
652 | xy_cnt = 0;\ |
||
653 | draw_arrows2();\ |
||
654 | };\ |
||
655 | };\ |
||
656 | function draw_arrows2(){\ |
||
657 | var arrow_head = %d;\ |
||
658 | var len = userdraw_x.length;\ |
||
659 | var x1,y1,x2,y2,dx,dy,h;\ |
||
660 | if( len%%2 == 0 ){\ |
||
661 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
||
662 | for(var p = 0 ; p < len ; p = p+2 ){\ |
||
663 | context_userdraw.save();\ |
||
664 | x1 = userdraw_x[p];y1 = userdraw_y[p];x2 = userdraw_x[p+1];y2 = userdraw_y[p+1];dx = x2 - x1;dy = y2 - y1;\ |
||
665 | context_userdraw.save();\ |
||
666 | context_userdraw.beginPath();\ |
||
667 | context_userdraw.moveTo(x1,y1);\ |
||
668 | context_userdraw.lineTo(x2,y2);\ |
||
669 | context_userdraw.closePath();\ |
||
670 | context_userdraw.stroke();\ |
||
671 | context_userdraw.translate(x2,y2);\ |
||
672 | context_userdraw.rotate(Math.atan2(dy,dx));\ |
||
673 | context_userdraw.beginPath();\ |
||
674 | context_userdraw.moveTo(0,0);\ |
||
675 | context_userdraw.lineTo(-1*arrow_head,-0.5*arrow_head);\ |
||
676 | context_userdraw.lineTo(-1*arrow_head, 0.5*arrow_head);\ |
||
677 | context_userdraw.closePath();\ |
||
678 | context_userdraw.fill();\ |
||
679 | context_userdraw.stroke();\ |
||
680 | context_userdraw.restore();\ |
||
681 | context_userdraw.translate(x1,y1);\ |
||
682 | context_userdraw.rotate(Math.atan2(-dy,-dx));\ |
||
683 | context_userdraw.beginPath();\ |
||
684 | context_userdraw.moveTo(0,0);\ |
||
685 | context_userdraw.lineTo(-1*arrow_head,-0.5*arrow_head);\ |
||
686 | context_userdraw.lineTo(-1*arrow_head, 0.5*arrow_head);\ |
||
687 | context_userdraw.closePath();\ |
||
688 | context_userdraw.fill();\ |
||
689 | context_userdraw.stroke();\ |
||
690 | context_userdraw.restore();\ |
||
691 | };\ |
||
692 | };\ |
||
693 | return;\ |
||
694 | };",stroke_color,stroke_opacity,arrow_head); |
||
18553 | bpr | 695 | break; |
15111 | schaersvoo | 696 | /* curvedarrow/curvedarrows */ |
18553 | bpr | 697 | case 22 ... 23: |
15111 | schaersvoo | 698 | fprintf(js_include_file,"\ |
699 | function redraw_userdraw(){draw_curvedarrows();};\ |
||
700 | function remove_last(){if( userdraw_x.length > 0 ){for(var p=0;p<3;p++){userdraw_x.pop();userdraw_y.pop();};draw_curvedarrows();};return;};\ |
||
701 | function curvedarrows(x,y,event_which,num){\ |
||
702 | if(event_which == 0){\ |
||
703 | if(num == 0 && xy_cnt == 0){\ |
||
704 | userdraw_x = [];userdraw_y = [];userdraw_x[0] = x;userdraw_y[0] = y;\ |
||
705 | }\ |
||
706 | else\ |
||
707 | {\ |
||
708 | userdraw_x.push(x);userdraw_y.push(y);\ |
||
709 | };\ |
||
710 | xy_cnt++;\ |
||
711 | }\ |
||
712 | else\ |
||
713 | {\ |
||
714 | if( xy_cnt < 3 ){userdraw_x.push(x);userdraw_y.push(y);draw_curvedarrows();userdraw_x.pop();userdraw_y.pop();};\ |
||
715 | if( xy_cnt == 3 ){userdraw_x.pop();userdraw_y.pop();userdraw_x.push(x);userdraw_y.push(y);xy_cnt = 0;draw_curvedarrows();};\ |
||
716 | };\ |
||
717 | };\ |
||
718 | var arrow_head = %d;\ |
||
719 | function draw_curvedarrows(){\ |
||
720 | var len = userdraw_x.length;var x1,y1,x2,y2,x3,y3;\ |
||
721 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
||
722 | for(var p = 0 ; p < len ; p = p+3){\ |
||
723 | x1 = userdraw_x[p];x2 = userdraw_x[p+1];x3 = userdraw_x[p+2];y1 = userdraw_y[p];y2 = userdraw_y[p+1];y3 = userdraw_y[p+2];\ |
||
724 | var angle1 = Math.atan2(x3 - x2,y3 - y2) + Math.PI;\ |
||
725 | context_userdraw.beginPath();\ |
||
726 | context_userdraw.moveTo(x1,y1);\ |
||
727 | context_userdraw.quadraticCurveTo(x3,y3,x2,y2);\ |
||
728 | context_userdraw.moveTo(x2 - (arrow_head * Math.sin(angle1 - Math.PI / 6)),y2 - (arrow_head * Math.cos(angle1 - Math.PI / 6)));\ |
||
729 | context_userdraw.lineTo(x2, y2);\ |
||
730 | context_userdraw.lineTo(x2 - (arrow_head * Math.sin(angle1 + Math.PI / 6)),y2 - (arrow_head * Math.cos(angle1 + Math.PI / 6)));\ |
||
731 | context_userdraw.stroke();\ |
||
732 | context_userdraw.closePath();\ |
||
733 | };\ |
||
734 | return;};",arrow_head); |
||
18553 | bpr | 735 | break; |
15111 | schaersvoo | 736 | /* curvedarrow2/curvedarrows2 */ |
18553 | bpr | 737 | case 24 ... 25: |
738 | fprintf(js_include_file,"\ |
||
15111 | schaersvoo | 739 | function redraw_userdraw(){draw_curvedarrows2();};\ |
740 | function remove_last(){if( userdraw_x.length > 0 ){for(var p=0;p<3;p++){userdraw_x.pop();userdraw_y.pop();};draw_curvedarrows2();};return;};\ |
||
741 | function curvedarrows2(x,y,event_which,num){\ |
||
742 | if(event_which == 0){\ |
||
743 | if(num == 0 && xy_cnt == 0){userdraw_x = [];userdraw_y = [];userdraw_x[0] = x;userdraw_y[0] = y;}else{userdraw_x.push(x);userdraw_y.push(y);};xy_cnt++;\ |
||
744 | }\ |
||
745 | else\ |
||
746 | {\ |
||
747 | if( xy_cnt < 3 ){userdraw_x.push(x);userdraw_y.push(y);draw_curvedarrows2();userdraw_x.pop();userdraw_y.pop();};\ |
||
748 | if( xy_cnt == 3 ){userdraw_x.pop();userdraw_y.pop();userdraw_x.push(x);userdraw_y.push(y);xy_cnt = 0;draw_curvedarrows2();};\ |
||
749 | };\ |
||
750 | };\ |
||
751 | var arrow_head = %d;\ |
||
752 | function draw_curvedarrows2(){\ |
||
753 | var len = userdraw_x.length;var x1,y1,x2,y2,x3,y3;\ |
||
754 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
||
755 | for(var p = 0 ; p < len ; p = p+3){\ |
||
756 | x1 = userdraw_x[p];x2 = userdraw_x[p+1];x3 = userdraw_x[p+2];y1 = userdraw_y[p];y2 = userdraw_y[p+1];y3 = userdraw_y[p+2];\ |
||
757 | var angle1 = Math.atan2(x3 - x2,y3 - y2) + Math.PI;\ |
||
758 | var angle2 = Math.atan2(x3 - x1,y3 - y1) + Math.PI;\ |
||
759 | context_userdraw.beginPath();\ |
||
760 | context_userdraw.moveTo(x1,y1);\ |
||
761 | context_userdraw.moveTo(x1 - (arrow_head * Math.sin(angle2 - Math.PI / 6)),y1 - (arrow_head * Math.cos(angle2 - Math.PI / 6)));\ |
||
762 | context_userdraw.lineTo(x1, y1);\ |
||
763 | context_userdraw.lineTo(x1 - (arrow_head * Math.sin(angle2 + Math.PI / 6)),y1 - (arrow_head * Math.cos(angle2 + Math.PI / 6)));\ |
||
764 | context_userdraw.moveTo(x1,y1);\ |
||
765 | context_userdraw.quadraticCurveTo(x3,y3,x2,y2);\ |
||
766 | context_userdraw.moveTo(x2 - (arrow_head * Math.sin(angle1 - Math.PI / 6)),y2 - (arrow_head * Math.cos(angle1 - Math.PI / 6)));\ |
||
767 | context_userdraw.lineTo(x2, y2);\ |
||
768 | context_userdraw.lineTo(x2 - (arrow_head * Math.sin(angle1 + Math.PI / 6)),y2 - (arrow_head * Math.cos(angle1 + Math.PI / 6)));\ |
||
769 | context_userdraw.stroke();\ |
||
770 | context_userdraw.closePath();\ |
||
771 | };\ |
||
772 | return;\ |
||
773 | };",arrow_head); |
||
18553 | bpr | 774 | break; |
15126 | bpr | 775 | |
15111 | schaersvoo | 776 | /* freehandline/freehandlines/path/paths 0,1 26,27,28,29 */ |
18553 | bpr | 777 | case 26 ... 29: |
778 | fprintf(js_include_file,"\ |
||
15111 | schaersvoo | 779 | var stop = 1;\ |
780 | function remove_last(){userdraw_x = [];userdraw_y = []; context_userdraw.clearRect(0,0,xsize,ysize);return;};\ |
||
781 | function paths(x,y,event_which,num){\ |
||
782 | if(event_which == 0 && stop == 0 ){stop = 1;return;};\ |
||
783 | if(event_which == 1 && stop == 1 ){return;}; \ |
||
784 | if(event_which == 0 && stop == 1 ){\ |
||
785 | stop = 0;userdraw_x = [];userdraw_y = [];return;};\ |
||
786 | userdraw_x.push(x);userdraw_y.push(y);\ |
||
787 | draw_paths();\ |
||
788 | };\ |
||
789 | function draw_paths(){\ |
||
790 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
||
791 | var len = userdraw_x.length ;\ |
||
792 | context_userdraw.beginPath();\ |
||
793 | context_userdraw.moveTo(userdraw_x[0],userdraw_y[0]);\ |
||
794 | for(var p = 1 ; p < len ; p++ ){\ |
||
795 | context_userdraw.lineTo(userdraw_x[p],userdraw_y[p]);\ |
||
796 | };\ |
||
797 | if(use_filled!=0){context_userdraw.fill();};\ |
||
798 | context_userdraw.stroke();\ |
||
799 | return;\ |
||
800 | };"); |
||
15126 | bpr | 801 | |
18553 | bpr | 802 | break; |
15126 | bpr | 803 | |
15111 | schaersvoo | 804 | /* poly/polys poly[3]...polys[9] 30,31 */ |
18553 | bpr | 805 | case 30 ... 31: |
806 | fprintf(js_include_file,"\ |
||
15111 | schaersvoo | 807 | var polynum = %d;\ |
808 | function redraw_userdraw(){draw_polys();};\ |
||
809 | function remove_last(){if( userdraw_x.length > 0 ){for(var p=0;p<polynum;p++){userdraw_x.pop();userdraw_y.pop();};draw_polys();};return;};\ |
||
810 | function polys(x,y,event_which,num){\ |
||
811 | if(event_which == 0){\ |
||
812 | if(num == 0 && xy_cnt == 0){\ |
||
813 | userdraw_x = [];userdraw_y = [];\ |
||
814 | userdraw_x[0] = x;userdraw_y[0] = y;\ |
||
815 | }\ |
||
816 | else\ |
||
817 | {\ |
||
818 | userdraw_x.push(x);userdraw_y.push(y);\ |
||
819 | };\ |
||
820 | xy_cnt++;\ |
||
821 | }\ |
||
822 | else\ |
||
823 | {\ |
||
824 | if( xy_cnt < polynum ){\ |
||
825 | userdraw_x.push(x);userdraw_y.push(y);\ |
||
826 | draw_polys();\ |
||
827 | userdraw_x.pop();userdraw_y.pop();\ |
||
828 | };\ |
||
829 | };\ |
||
830 | if( xy_cnt == polynum ){\ |
||
831 | userdraw_x.pop();userdraw_y.pop();\ |
||
832 | userdraw_x.push(x);userdraw_y.push(y);\ |
||
833 | xy_cnt = 0;\ |
||
834 | draw_polys();\ |
||
835 | };\ |
||
836 | };\ |
||
837 | function draw_polys(){\ |
||
15121 | schaersvoo | 838 | var len = userdraw_x.length;\ |
15111 | schaersvoo | 839 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
840 | for(var p = 0 ; p < len ; p = p+polynum){\ |
||
841 | context_userdraw.beginPath();\ |
||
842 | context_userdraw.moveTo(userdraw_x[p],userdraw_y[p]);\ |
||
15121 | schaersvoo | 843 | for( var m = p+1 ;m < p+polynum ; m++){\ |
844 | if(typeof(userdraw_x[m]) !== 'undefined' ){context_userdraw.lineTo(userdraw_x[m],userdraw_y[m]);};};\ |
||
15111 | schaersvoo | 845 | context_userdraw.lineTo(userdraw_x[p],userdraw_y[p]);\ |
15121 | schaersvoo | 846 | context_userdraw.stroke();\ |
15111 | schaersvoo | 847 | context_userdraw.closePath();\ |
848 | if(use_filled!=0){context_userdraw.fill();};\ |
||
849 | };\ |
||
850 | return;\ |
||
851 | };",polynum); |
||
18553 | bpr | 852 | break; |
853 | case 32 ... 33: |
||
15111 | schaersvoo | 854 | /* polygon/polygon 32,33 */ |
855 | /* multiple polygons are now working as expected : no problems with duplicated/closing points*/ |
||
856 | fprintf(js_include_file,"\ |
||
857 | var poly_closed = [];\ |
||
858 | var do_not_pop = 0;\ |
||
859 | function redraw_userdraw(){do_not_pop = 1;draw_polygon();};\ |
||
860 | function remove_last(){var len = poly_closed.length;if(len > 1 ){var last = poly_closed[len-1]-poly_closed[len-2];for(var p=0;p<last-1;p++){userdraw_x.pop();userdraw_y.pop();};poly_closed.pop();}else{poly_closed = [];userdraw_x = [];userdraw_y = [];};draw_polygon();return;};\ |
||
861 | function check_closed(x1,y1,X,Y){\ |
||
862 | var marge=10;\ |
||
863 | var len = X.length-1;\ |
||
864 | for(var p = 0 ; p < len ; p++){\ |
||
865 | if(x1 < X[p] + marge && x1 > X[p] - marge ){\ |
||
866 | if(y1 < Y[p] + marge && y1 > Y[p] - marge ){\ |
||
867 | return 1;\ |
||
868 | };\ |
||
869 | };\ |
||
870 | };\ |
||
871 | return 0;\ |
||
872 | };\ |
||
873 | \ |
||
874 | function polygon(x,y,event_which,num){\ |
||
875 | do_not_pop = 0;\ |
||
876 | if(event_which == 0){\ |
||
877 | if(num == 0 && xy_cnt == 0){\ |
||
878 | userdraw_x = [];userdraw_y = [];\ |
||
879 | userdraw_x[0] = x;userdraw_y[0] = y;\ |
||
880 | }\ |
||
881 | else\ |
||
882 | {\ |
||
883 | userdraw_x.push(x);userdraw_y.push(y);\ |
||
884 | };\ |
||
885 | xy_cnt++;\ |
||
886 | if( xy_cnt > 2 ){\ |
||
887 | if( check_closed(x,y,userdraw_x,userdraw_y) == 1){\ |
||
888 | poly_closed.push(userdraw_x.length - 1);\ |
||
889 | draw_polygon();\ |
||
890 | xy_cnt = 0;\ |
||
891 | };\ |
||
892 | };\ |
||
893 | }\ |
||
894 | else\ |
||
895 | {\ |
||
896 | if( xy_cnt > 0 ){\ |
||
897 | userdraw_x.push(x);userdraw_y.push(y);\ |
||
898 | draw_polygon();\ |
||
899 | };\ |
||
900 | };\ |
||
901 | };\ |
||
902 | function draw_polygon(){\ |
||
903 | var len = userdraw_x.length;\ |
||
904 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
||
905 | context_userdraw.beginPath();\ |
||
906 | var begin = 0;\ |
||
907 | context_userdraw.moveTo(userdraw_x[0],userdraw_y[0]);\ |
||
908 | for( var p = 0 ; p < len ; p++){\ |
||
909 | if( poly_closed.indexOf(p) != -1 ){\ |
||
910 | context_userdraw.lineTo(userdraw_x[begin],userdraw_y[begin]);\ |
||
911 | begin = p;\ |
||
912 | context_userdraw.closePath();\ |
||
913 | if(use_filled!=0){context_userdraw.fill();};\ |
||
914 | context_userdraw.stroke();\ |
||
915 | context_userdraw.beginPath();\ |
||
916 | }else{ context_userdraw.lineTo(userdraw_x[p],userdraw_y[p]);};\ |
||
917 | };\ |
||
918 | context_userdraw.lineTo(userdraw_x[begin],userdraw_y[begin]);\ |
||
919 | context_userdraw.closePath();\ |
||
920 | if(use_filled!=0){context_userdraw.fill();};\ |
||
921 | context_userdraw.stroke();\ |
||
922 | if(do_not_pop == 0){ userdraw_x.pop();userdraw_y.pop();};\ |
||
923 | return;\ |
||
924 | };"); |
||
18553 | bpr | 925 | break; |
15126 | bpr | 926 | |
927 | /* |
||
928 | polyline/brokenline 34,35 |
||
15111 | schaersvoo | 929 | there is just a single polyline/brokenline possible ! |
930 | */ |
||
18553 | bpr | 931 | case 34 ... 35: |
932 | fprintf(js_include_file,"\ |
||
15111 | schaersvoo | 933 | function redraw_userdraw(){draw_polylines();};\ |
934 | function remove_last(){if( userdraw_x.length > 0 ){userdraw_x.pop();userdraw_y.pop();draw_polylines();};return;};\ |
||
935 | function polylines(x,y,event_which,num){\ |
||
936 | if(event_which == 0){\ |
||
937 | if(num == 0 && xy_cnt == 0 ){ userdraw_x = [];userdraw_y = [];};\ |
||
938 | userdraw_x.push(x);userdraw_y.push(y);\ |
||
939 | xy_cnt++;\ |
||
940 | }\ |
||
941 | else\ |
||
942 | {\ |
||
943 | if( xy_cnt == 1 ){\ |
||
944 | userdraw_x.push(x);userdraw_y.push(y);\ |
||
945 | userdraw_x.pop();userdraw_y.pop();\ |
||
946 | };\ |
||
947 | };\ |
||
948 | if( xy_cnt == 2 ){xy_cnt = 0;};\ |
||
949 | draw_polylines();\ |
||
950 | };\ |
||
951 | var full_circle = 2*Math.PI;\ |
||
952 | function draw_polylines(){\ |
||
953 | var len = userdraw_x.length;\ |
||
954 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
||
955 | context_userdraw.beginPath();\ |
||
956 | context_userdraw.moveTo(userdraw_x[0],userdraw_y[0]);\ |
||
957 | for( var p = 0 ; p < len ; p++){\ |
||
958 | context_userdraw.lineTo(userdraw_x[p],userdraw_y[p]);\ |
||
959 | context_userdraw.arc(userdraw_x[p],userdraw_y[p],2,0,full_circle,false);\ |
||
960 | };\ |
||
961 | context_userdraw.stroke();\ |
||
962 | context_userdraw.closePath();\ |
||
963 | if(use_filled != 0 ){if(use_filled!=0){context_userdraw.fill();};};\ |
||
964 | return;\ |
||
965 | };"); |
||
18553 | bpr | 966 | break; |
15111 | schaersvoo | 967 | |
968 | /* triangle/triangles 36,37 */ |
||
18553 | bpr | 969 | case 36 ... 37: |
970 | fprintf(js_include_file,"\ |
||
15111 | schaersvoo | 971 | function redraw_userdraw(){draw_triangles();};\ |
972 | function remove_last(){if( userdraw_x.length > 0 ){for(var p=0;p<3;p++){userdraw_x.pop();userdraw_y.pop();};draw_triangles();};return;};\ |
||
973 | function triangles(x,y,event_which,num){\ |
||
974 | var last = userdraw_x.length - 1;\ |
||
975 | if(event_which == 0){\ |
||
976 | if(num == 0 && xy_cnt == 0){\ |
||
977 | userdraw_x = [];userdraw_y = [];userdraw_x[0] = x;userdraw_y[0] = y;\ |
||
978 | }\ |
||
979 | else\ |
||
980 | {\ |
||
981 | userdraw_x.push(x);userdraw_y.push(y);\ |
||
982 | };\ |
||
983 | xy_cnt++;\ |
||
984 | }\ |
||
985 | else\ |
||
986 | {\ |
||
987 | if( xy_cnt < 3 ){\ |
||
988 | userdraw_x.push(x);userdraw_y.push(y);\ |
||
989 | draw_triangles();\ |
||
990 | userdraw_x.pop();userdraw_y.pop();\ |
||
991 | return;\ |
||
992 | };\ |
||
993 | };\ |
||
994 | if( xy_cnt == 3 ){\ |
||
995 | userdraw_x.pop();userdraw_y.pop();\ |
||
996 | userdraw_x.push(x);userdraw_y.push(y);\ |
||
997 | xy_cnt = 0;\ |
||
998 | draw_triangles();\ |
||
999 | };\ |
||
1000 | };\ |
||
1001 | function draw_triangles(){\ |
||
1002 | var len = userdraw_x.length - 1;\ |
||
1003 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
||
1004 | for(var p = 0 ; p < len ; p = p+3){\ |
||
1005 | context_userdraw.beginPath();\ |
||
1006 | context_userdraw.moveTo(userdraw_x[p],userdraw_y[p]);\ |
||
1007 | for( var m = p+1 ;m < p+3 ; m++){\ |
||
1008 | context_userdraw.lineTo(userdraw_x[m],userdraw_y[m]);\ |
||
1009 | };\ |
||
1010 | context_userdraw.lineTo(userdraw_x[p],userdraw_y[p]);\ |
||
1011 | context_userdraw.closePath();\ |
||
1012 | if(use_filled!=0){context_userdraw.fill();};\ |
||
1013 | context_userdraw.stroke();\ |
||
1014 | };\ |
||
1015 | return;\ |
||
1016 | };"); |
||
18553 | bpr | 1017 | break; |
15111 | schaersvoo | 1018 | |
1019 | /* rect/rects 38,39 : NOT USING A PATH !!*/ |
||
18553 | bpr | 1020 | case 38 ... 39 : |
1021 | fprintf(js_include_file,"\ |
||
15111 | schaersvoo | 1022 | function redraw_userdraw(){draw_rects();};\ |
1023 | function remove_last(){if( userdraw_x.length > 0 ){for(var p=0;p<2;p++){userdraw_x.pop();userdraw_y.pop();};draw_rects();};return;};\ |
||
1024 | function rects(x,y,event_which,num){\ |
||
1025 | if(event_which == 0){\ |
||
1026 | if( num == 0 && xy_cnt == 0 ){userdraw_x = [];userdraw_y = [];};\ |
||
1027 | userdraw_x.push(x);userdraw_y.push(y);\ |
||
1028 | xy_cnt++;\ |
||
1029 | }\ |
||
1030 | else\ |
||
1031 | {\ |
||
1032 | if( xy_cnt == 1 ){\ |
||
1033 | userdraw_x.push(x);userdraw_y.push(y);\ |
||
1034 | draw_rects();\ |
||
1035 | userdraw_x.pop();userdraw_y.pop();\ |
||
1036 | };\ |
||
1037 | };\ |
||
1038 | if( xy_cnt == 2 ){\ |
||
1039 | xy_cnt = 0;\ |
||
1040 | draw_rects();\ |
||
1041 | };\ |
||
1042 | };\ |
||
1043 | function draw_rects(){\ |
||
1044 | var len = userdraw_x.length;\ |
||
1045 | if( len %%2 == 0 ){\ |
||
1046 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
||
1047 | for(var p = 0 ; p < len ; p = p+2 ){\ |
||
1048 | context_userdraw.beginPath();\ |
||
1049 | context_userdraw.rect(userdraw_x[p],userdraw_y[p],userdraw_x[p+1]-userdraw_x[p],userdraw_y[p+1]-userdraw_y[p]);\ |
||
1050 | context_userdraw.closePath();\ |
||
1051 | if(use_filled!=0){context_userdraw.fill();};\ |
||
1052 | context_userdraw.stroke();\ |
||
1053 | };\ |
||
1054 | };\ |
||
1055 | return;\ |
||
1056 | };"); |
||
18553 | bpr | 1057 | break; |
15111 | schaersvoo | 1058 | /* roundrect/roundrects 40,41 : NOT USING A PATH !!*/ |
18553 | bpr | 1059 | case 40 ... 41: |
15111 | schaersvoo | 1060 | fprintf(js_include_file,"\ |
1061 | function redraw_userdraw(){draw_roundrects();};\ |
||
1062 | function remove_last(){if( userdraw_x.length > 0 ){for(var p=0;p<2;p++){userdraw_x.pop();userdraw_y.pop();};draw_roundrects();};return;};\ |
||
1063 | function roundrects(x,y,event_which,num){\ |
||
1064 | if(event_which == 0){\ |
||
1065 | if( num == 0 && xy_cnt == 0 ){userdraw_x = [];userdraw_y = [];};\ |
||
1066 | userdraw_x.push(x);userdraw_y.push(y);\ |
||
1067 | xy_cnt++;\ |
||
1068 | }\ |
||
1069 | else\ |
||
1070 | {\ |
||
1071 | if( xy_cnt == 1 ){\ |
||
1072 | userdraw_x.push(x);userdraw_y.push(y);\ |
||
1073 | draw_roundrects();\ |
||
1074 | userdraw_x.pop();userdraw_y.pop();\ |
||
1075 | };\ |
||
1076 | };\ |
||
1077 | if( xy_cnt == 2 ){\ |
||
1078 | xy_cnt = 0;\ |
||
1079 | draw_roundrects();\ |
||
1080 | };\ |
||
1081 | };\ |
||
1082 | function draw_roundrects(){\ |
||
1083 | var len = userdraw_x.length;\ |
||
1084 | if( len %%2 == 0 ){\ |
||
1085 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
||
1086 | var x,y,w,h,r;\ |
||
1087 | for(var p = 0; p < len; p = p+2){\ |
||
1088 | x = userdraw_x[p];y = userdraw_y[p];w = userdraw_x[p+1] - x;h = userdraw_y[p+1] - y;r = parseInt(0.1*w);\ |
||
1089 | context_userdraw.beginPath();\ |
||
1090 | context_userdraw.moveTo(x + r, y);\ |
||
1091 | context_userdraw.lineTo(x + w - r, y);\ |
||
1092 | context_userdraw.quadraticCurveTo(x + w, y, x + w, y + r);\ |
||
1093 | context_userdraw.lineTo(x + w, y + h - r);\ |
||
1094 | context_userdraw.quadraticCurveTo(x + w, y + h, x + w - r, y + h);\ |
||
1095 | context_userdraw.lineTo(x + r, y + h);\ |
||
1096 | context_userdraw.quadraticCurveTo(x, y + h, x, y + h - r);\ |
||
1097 | context_userdraw.lineTo(x, y + r);\ |
||
1098 | context_userdraw.quadraticCurveTo(x, y, x + r, y);\ |
||
1099 | context_userdraw.closePath();\ |
||
1100 | if(use_filled!=0){context_userdraw.fill();};\ |
||
1101 | context_userdraw.stroke();\ |
||
1102 | };\ |
||
1103 | };\ |
||
1104 | return;\ |
||
1105 | };"); |
||
18553 | bpr | 1106 | break; |
15111 | schaersvoo | 1107 | /* arc/arcs 42,43 */ |
18553 | bpr | 1108 | case 42 ... 43: |
15111 | schaersvoo | 1109 | fprintf(js_include_file,"\ |
1110 | function redraw_userdraw(){draw_arcs();};\ |
||
1111 | var temp_point_x = new Array(3);\ |
||
1112 | var temp_point_y = new Array(3);\ |
||
1113 | context_userdraw.fillStyle = context_userdraw.strokeStyle;\ |
||
1114 | function remove_last(){if( userdraw_x.length > 0 ){for(var p=0;p<3;p++){userdraw_x.pop();userdraw_y.pop();userdraw_radius.pop();temp_point_x = [];temp_point_y = [];};draw_arcs();};return;};\ |
||
1115 | function arcs(x,y,event_which,num){\ |
||
1116 | var last = userdraw_x.length - 1;\ |
||
1117 | var xc = userdraw_x[last];\ |
||
1118 | var yc = userdraw_y[last];\ |
||
1119 | if(event_which == 0){\ |
||
1120 | if(num == 0 && xy_cnt == 3 ){xy_cnt = 0;userdraw_x = [];userdraw_y = [];};\ |
||
1121 | userdraw_x.push(x);userdraw_y.push(y);\ |
||
1122 | temp_point_x.push(x);\ |
||
1123 | temp_point_y.push(y);\ |
||
1124 | draw_points();\ |
||
1125 | xy_cnt++;\ |
||
1126 | };\ |
||
1127 | if( xy_cnt%%3 == 0 ){ draw_arcs();temp_point_x = [];temp_point_y = [];};\ |
||
1128 | return;\ |
||
1129 | };\ |
||
1130 | function draw_points(){\ |
||
1131 | var len = temp_point_x.length;\ |
||
1132 | var radius = 4*(context_userdraw.lineWidth);\ |
||
1133 | var r = 2*Math.PI;\ |
||
1134 | for(var p = 0 ; p < len ; p++ ){\ |
||
1135 | context_userdraw.beginPath();\ |
||
1136 | context_userdraw.arc(temp_point_x[p],temp_point_y[p],radius,0,r,false);\ |
||
1137 | context_userdraw.closePath();\ |
||
1138 | context_userdraw.fill();\ |
||
1139 | };\ |
||
1140 | return;\ |
||
1141 | };\ |
||
1142 | function draw_arcs(){\ |
||
1143 | var xc,x1,x2,yc,y1,y2,radius,end,start,direction,p1,p2;\ |
||
1144 | var len = userdraw_x.length;\ |
||
1145 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
||
1146 | var idx = 0;\ |
||
1147 | for(var p=0; p< len;p = p+3){\ |
||
1148 | p1=p+1;p2=p+2;\ |
||
1149 | xc = userdraw_x[p1];x1 = userdraw_x[p];x2 = userdraw_x[p2];yc = userdraw_y[p1];y1 = userdraw_y[p];y2 = userdraw_y[p2];\ |
||
1150 | radius = distance(x1,y1,xc,yc);\ |
||
1151 | start = Math.atan2(y1-yc, x1-xc);\ |
||
1152 | end = Math.atan2(y2-yc, x2-xc);\ |
||
1153 | direction = ( start > end);\ |
||
1154 | userdraw_radius[idx] = Math.abs( end - start );idx++;\ |
||
1155 | context_userdraw.beginPath();\ |
||
1156 | context_userdraw.moveTo(xc,yc);\ |
||
1157 | context_userdraw.arc(xc, yc,radius,start,end,direction);\ |
||
1158 | context_userdraw.closePath();\ |
||
1159 | context_userdraw.stroke();\ |
||
1160 | if(use_filled!=0){context_userdraw.fill();};\ |
||
1161 | };\ |
||
1162 | return;\ |
||
1163 | };"); |
||
18553 | bpr | 1164 | break; |
15111 | schaersvoo | 1165 | /* text : 44 always uses user input field !! */ |
18553 | bpr | 1166 | case 44: |
15111 | schaersvoo | 1167 | fprintf(js_include_file,"\ |
1168 | function redraw_userdraw(){draw_text();};\ |
||
1169 | var userdraw_text = new Array();\ |
||
1170 | var tooltip_div = document.getElementById(\"tooltip_placeholder_div%d\");\ |
||
1171 | var inner_html = tooltip_div.innerHTML;\ |
||
18572 | bpr | 1172 | tooltip_div.innerHTML = inner_html + \"<input class='%s' type='text' size='4' value='' id='userdraw_text_abc'>\";\ |
15111 | schaersvoo | 1173 | context_userdraw.fillStyle = \"rgba(%s,%f)\";\ |
1174 | var userdraw_textheight = 0.3 * (context_userdraw.measureText('M').width);\ |
||
1175 | function remove_last(){if(userdraw_x.length > 0 ){userdraw_x.pop();userdraw_y.pop();userdraw_text.pop();draw_text();return;};};\ |
||
1176 | function text(x,y,event_which,num){\ |
||
1177 | if(event_which == 1){ return; };\ |
||
1178 | if( num == 0 ){\ |
||
1179 | userdraw_x[0] = x;\ |
||
1180 | userdraw_y[0] = y;\ |
||
1181 | }else{\ |
||
1182 | userdraw_x.push(x);\ |
||
1183 | userdraw_y.push(y);\ |
||
1184 | };\ |
||
1185 | var txt = document.getElementById('userdraw_text_abc').value;\ |
||
1186 | if( ! txt ){userdraw_x.pop();userdraw_y.pop();userdraw_text.pop();return;};\ |
||
1187 | txt = conv_to_unicode(txt);userdraw_text.push(txt.replace(/\\\\/g,' '));\ |
||
1188 | draw_text();\ |
||
1189 | };\ |
||
1190 | function conv_to_unicode(str){return str.replace(/\\u[\\dA-F]{4}/gi,function(match){return String.fromCharCode(parseInt(match.replace(/\\u/g,''), 16));});};\ |
||
1191 | function draw_text(){\ |
||
1192 | var len = userdraw_x.length;\ |
||
1193 | var half = 0;\ |
||
16722 | schaersvoo | 1194 | var txt;\ |
15111 | schaersvoo | 1195 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
1196 | for(var p = 0 ; p < len ; p++ ){\ |
||
16722 | schaersvoo | 1197 | txt = userdraw_text[p];\ |
1198 | if(txt.indexOf('_') > 0 || txt.indexOf('^') > 0 ){draw_subsup(context_userdraw,userdraw_x[p],userdraw_y[p],txt,4);}else{half = 0.5*( context_userdraw.measureText(txt).width );context_userdraw.fillText(txt,userdraw_x[p] - half,userdraw_y[p] + userdraw_textheight);};\ |
||
15111 | schaersvoo | 1199 | };\ |
1200 | };",canvas_root_id,css_class,stroke_color,stroke_opacity); |
||
18553 | bpr | 1201 | break; |
15111 | schaersvoo | 1202 | /* images 45,46 replyformat is same as 'userdraw text,color' e.g. 17 === x,y,image_id */ |
18553 | bpr | 1203 | case 45 ... 46: |
1204 | fprintf(js_include_file,"\ |
||
15111 | schaersvoo | 1205 | function redraw_userdraw(){draw_images(0);};\ |
1206 | var userdraw_text = new Array();\ |
||
1207 | var current_id = null;var external_div_cnt=0;\ |
||
1208 | function remove_last(){draw_images(1);return;};\ |
||
1209 | function image_adjust(image,x,y){\ |
||
1210 | var centered = %d;\ |
||
1211 | var w = parseInt(image.width);var h = parseInt(image.height);\ |
||
1212 | switch(centered){\ |
||
1213 | case 0: return [x,y];break;\ |
||
1214 | case 1: return [x,parseInt(y-0.5*h)];break;\ |
||
1215 | case 2: return [parseInt(x+0.5*h),y];break;\ |
||
1216 | case 3: return [parseInt(x+0.5*h),parseInt(y-0.5*h)];break;\ |
||
1217 | case 4: return [parseInt(x-0.5*w),parseInt(y-0.5*h)];break;\ |
||
1218 | default: return [x,y];break;\ |
||
1219 | };\ |
||
1220 | };\ |
||
1221 | place_image_on_canvas = function(id){\ |
||
1222 | var thing = document.getElementById(id);\ |
||
1223 | var tag = thing.tagName;\ |
||
1224 | if(tag == 'SVG'){draw_mathml_svg(thing,id);return;};\ |
||
1225 | if(tag == 'DIV' || tag == 'SPAN' || tag == 'P' || tag == 'TD' || tag == 'TH' ){draw_mathml_div(thing,id);return;};\ |
||
1226 | var src = thing.src;\ |
||
1227 | var image = new Image();\ |
||
1228 | image.src = src;\ |
||
1229 | image.id = 'placed_'+id;\ |
||
1230 | image.width = thing.width;\ |
||
1231 | image.height = thing.height;\ |
||
1232 | image.onload = function(){ current_id = id; };\ |
||
1233 | return;\ |
||
1234 | };\ |
||
1235 | function draw_mathml_div(thing,id){\ |
||
1236 | var fix_div = document.createElement('DIV');\ |
||
1237 | var new_id='placed_'+external_div_cnt+'_'+id;\ |
||
1238 | fix_div.setAttribute('id',new_id);\ |
||
1239 | var w = parseInt(thing.clientWidth);\ |
||
1240 | var h = parseInt(thing.clientHeight);\ |
||
1241 | fix_div.innerHTML = thing.innerHTML;\ |
||
1242 | fix_div.setAttribute('style','display:none;position;absolute;width:'+w+'px;height:'+h+'px');\ |
||
1243 | fix_div.width = w;fix_div.height = h;\ |
||
1244 | canvas_div.appendChild(fix_div);\ |
||
1245 | current_id = new_id;\ |
||
1246 | external_div_cnt++;\ |
||
1247 | return;\ |
||
1248 | };\ |
||
1249 | function draw_mathml_svg(thing,id){\ |
||
1250 | var fix_div = document.createElement('DIV');\ |
||
1251 | fix_div.setAttribute('style','display:none;position;relative');\ |
||
1252 | canvas_div.appendChild(fix_div);\ |
||
1253 | var image = new Image();\ |
||
1254 | var svg_string = new XMLSerializer().serializeToString(thing);\ |
||
1255 | var dom = self.URL || self.webkitURL || self;\ |
||
1256 | var svg = new Blob([svg_string], {type: \"image/svg+xml;charset=utf-8\"});\ |
||
1257 | var url = dom.createObjectURL(svg);\ |
||
1258 | image.src= url;\ |
||
1259 | image.id = 'placed_'+id;\ |
||
1260 | image.onload = function(){\ |
||
1261 | current_id = image.id;\ |
||
18572 | bpr | 1262 | fix_div.innerHTML='<img src='+image.src+' id='+image.id+' alt=\"this should not happen today...!\">';\ |
15111 | schaersvoo | 1263 | };\ |
1264 | return;\ |
||
1265 | };\ |
||
1266 | function images(x,y,event_which,num){\ |
||
1267 | if(event_which == 1){ return;};\ |
||
1268 | if( current_id ){\ |
||
1269 | if(num == 0 ){ \ |
||
1270 | userdraw_x[0] = x;\ |
||
1271 | userdraw_y[0] = y;\ |
||
1272 | userdraw_text[0] = current_id;\ |
||
1273 | external_div_cnt = 0;\ |
||
1274 | }else{\ |
||
1275 | userdraw_x.push(x);\ |
||
1276 | userdraw_y.push(y);\ |
||
1277 | userdraw_text.push(current_id);\ |
||
1278 | };\ |
||
1279 | current_id = null;\ |
||
1280 | draw_images(0);\ |
||
1281 | };\ |
||
1282 | };\ |
||
1283 | function draw_images(remove){\ |
||
1284 | var last = userdraw_x.length - 1;\ |
||
1285 | if(last < 0 ){return;};\ |
||
1286 | var x = userdraw_x[last];\ |
||
1287 | var y = userdraw_y[last];\ |
||
1288 | var id = userdraw_text[last];\ |
||
1289 | var img = document.getElementById(id);\ |
||
1290 | var tag = img.tagName;\ |
||
1291 | var xy = image_adjust(img,x,y);\ |
||
1292 | if( tag == 'DIV' || tag == 'SPAN' || tag == 'P' || tag == 'TD' || tag == 'TH'){\ |
||
1293 | if( remove == 1 ){\ |
||
1294 | img.setAttribute('style','display:none');\ |
||
1295 | userdraw_x.pop();userdraw_y.pop();userdraw_text.pop();external_div_cnt--;\ |
||
1296 | }\ |
||
1297 | else\ |
||
1298 | {\ |
||
1299 | img.setAttribute('style','display:inline-block;position:absolute;top:'+xy[1]+'px;left:'+xy[0]+'px;');\ |
||
1300 | };\ |
||
1301 | return;\ |
||
1302 | }else{\ |
||
1303 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
||
1304 | if(remove == 1){\ |
||
1305 | userdraw_x.pop();userdraw_y.pop();userdraw_text.pop();\ |
||
1306 | };\ |
||
1307 | var len = userdraw_x.length;\ |
||
1308 | for(var p = 0 ; p < len; p++){\ |
||
1309 | if( userdraw_text[p] ){\ |
||
1310 | img = document.getElementById(userdraw_text[p]);\ |
||
1311 | tag = img.tagName;\ |
||
1312 | xy = image_adjust(img,userdraw_x[p],userdraw_y[p]);\ |
||
1313 | if( tag == 'IMG' || tag == 'SVG' ){\ |
||
1314 | context_userdraw.drawImage(img,xy[0],xy[1],img.width,img.height);\ |
||
1315 | };\ |
||
1316 | };\ |
||
1317 | };\ |
||
1318 | };\ |
||
1319 | };",use_offset); |
||
18553 | bpr | 1320 | break; |
15111 | schaersvoo | 1321 | /* input/inputs" 46,47 |
1322 | if(use_offset != 0 ){ center_input('canvas_input'+input_cnt,x,y,style);};\ |
||
1323 | inp.addEventListener(\"touchstart\", function(e){this.focus();},false);\ |
||
1324 | if( wims_status == \"done\" ){ inp.setAttribute(\"readonly\",\"readonly\");}; |
||
1325 | */ |
||
18553 | bpr | 1326 | case 47 ... 48: |
15126 | bpr | 1327 | /* |
15111 | schaersvoo | 1328 | input_cnt keeps track of all inputfields INCLUDING static inputfields |
1329 | xy_cnt keeps track of the dynamically added userdraw inputfields |
||
1330 | */ |
||
18553 | bpr | 1331 | fprintf(js_include_file,"\ |
15111 | schaersvoo | 1332 | var current_id = null;\ |
1333 | var current_obj = null;\ |
||
1334 | var inputs_width = 16;\ |
||
1335 | var inputs_height = 8;\ |
||
1336 | function redraw_userdraw(){console.log('userdraw inputs not zooming...');};\ |
||
1337 | if(typeof(input_cnt) !== 'undefined'){var input_cnt = 0;};\ |
||
1338 | function remove_last(){console.log('input_cnt ='+input_cnt);\ |
||
1339 | var input = document.getElementById('canvas_input'+input_cnt);try{ canvas_div.removeChild(input);userdraw_x.pop();userdraw_y.pop();xy_cnt--;input_cnt--;}catch(e){console.log('removal failed...'+e);};};\ |
||
1340 | function check_overlap(x,y,obj){\ |
||
1341 | var inputs;var xi,yi;\ |
||
1342 | for(var p = 0 ; p < xy_cnt ; p++ ){\ |
||
1343 | xi = userdraw_x[p];yi = userdraw_y[p];\ |
||
1344 | if( x > xi - 5 && x < xi + inputs_width && y > yi-5 && y < yi + inputs_height){\ |
||
1345 | try{canvas_div.removeChild(obj);\ |
||
1346 | current_obj = null;userdraw_x.pop();userdraw_y.pop();xy_cnt--;input_cnt--;\ |
||
1347 | }catch(e){console.log('failed removing overlap: '+e);};\ |
||
1348 | return;\ |
||
1349 | };\ |
||
1350 | };\ |
||
1351 | return;\ |
||
1352 | };\ |
||
1353 | function inputs(x,y,event_which,num){\ |
||
1354 | if( document.getElementById('canvas_input0')){\ |
||
1355 | var inputs = document.getElementById('canvas_input0');\ |
||
1356 | inputs_width = 5+parseInt(inputs.clientWidth);\ |
||
1357 | inputs_height = 5+ parseInt(inputs.clientHeight);\ |
||
1358 | };\ |
||
1359 | if(event_which == 0){\ |
||
1360 | if(num == 0 && xy_cnt == 1 ){try{ canvas_div.removeChild(document.getElementById('canvas_input0'));\ |
||
1361 | userdraw_x = [];userdraw_y = [];xy_cnt=0;}catch(e){console.log('removal first input failed...'+e);};};\ |
||
1362 | userdraw_x.push(x);userdraw_y.push(y);\ |
||
1363 | current_id = 'canvas_input'+input_cnt;\ |
||
1364 | current_obj = document.getElementById(current_id);\ |
||
1365 | draw_inputs(x,y);\ |
||
1366 | if(input_cnt > 0){check_overlap(x,y,current_obj);};\ |
||
1367 | input_cnt++;\ |
||
1368 | xy_cnt++;\ |
||
1369 | if(isTouch){current_obj.addEventListener(\"touchstart\", function(e){this.focus();},false);}else{\ |
||
1370 | current_obj.autofocus = true;};\ |
||
1371 | };\ |
||
1372 | return;\ |
||
1373 | };\ |
||
1374 | function draw_inputs(x,y){\ |
||
1375 | var input_size = parseInt(context_userdraw.lineWidth);\ |
||
1376 | current_obj = document.createElement(\"input\");\ |
||
1377 | current_obj.setAttribute(\"id\",current_id);\ |
||
1378 | current_obj.setAttribute(\"size\",input_size);\ |
||
1379 | var xx = x - 0.5*inputs_width;\ |
||
1380 | var yy = y - 0.5*inputs_height;\ |
||
1381 | current_obj.setAttribute(\"style\",\"position:absolute;left:\"+xx+\"px;top:\"+yy+\"px;\");\ |
||
1382 | canvas_div.appendChild(current_obj);\ |
||
1383 | return;\ |
||
1384 | };"); |
||
18553 | bpr | 1385 | break; |
15111 | schaersvoo | 1386 | // current_obj.setAttribute(\"class\",\"%s\"); |
1387 | |||
1388 | // input.setAttribute(\"style\",\"position:absolute;left:\"+userdraw_x[p]+\"px;top:\"+userdraw_y[p]+\"px;%s\"); |
||
15126 | bpr | 1389 | /* gridfill/diamondfill/dotfill/hatchfill/textfill 48,49,50,51,52 |
1390 | 0:no fill, 1:fill,2=grid?,3=hatch?,4=diamond?,5=dot?,6=image? |
||
15111 | schaersvoo | 1391 | if( draw_num == 50 ){js_function[DRAW_GRIDFILL] = 1;use_filled = 2;} |
1392 | else{ |
||
1393 | if( draw_num == 51 ){js_function[DRAW_DIAMONDFILL] = 1;use_filled = 4;} |
||
1394 | else{ |
||
1395 | if( draw_num == 52 ){js_function[DRAW_DOTFILL] = 1;use_filled = 5;} |
||
1396 | else{ |
||
1397 | if( draw_num == 53 ){js_function[DRAW_HATCHFILL] = 1;use_filled = 3;} |
||
1398 | else{ |
||
1399 | if( draw_num == 54 ){js_function[DRAW_TEXTFILL] = 1;use_filled = 7;} |
||
1400 | else{ use_filled = 1;}}}}} |
||
1401 | */ |
||
18553 | bpr | 1402 | case 49 ... 54: |
18559 | bpr | 1403 | /* handling rare case of clickfill using a pattern instead of a single color...*/ |
18553 | bpr | 1404 | add_js_filltoborder(canvas_type); |
17351 | bpr | 1405 | /*fprintf(stdout,"USE_FILLED = %d<br>",use_filled);*/ |
18645 | czzmrn | 1406 | tmp_buffer = my_newmem(MAX_BUFFER); |
18553 | bpr | 1407 | switch(use_filled){ |
1408 | case 1: |
||
18563 | bpr | 1409 | check_string_length(snprintf(tmp_buffer,MAX_BUFFER,"var use_pattern_ctx = false;")); |
18553 | bpr | 1410 | break; |
1411 | case 2: |
||
18586 | bpr | 1412 | check_string_length(snprintf(tmp_buffer,MAX_BUFFER,"draw_gridfill(%d,0,0,%d,%d,%d,'%s',%d,xsize,ysize,1);var use_pattern_ctx = true;var pattern_ctx = grid_fill_pattern;",CLICKFILL_CANVAS,5*line_width,5*line_width,line_width,stroke_color,(int) (fill_opacity/0.0039215))); |
18553 | bpr | 1413 | break; |
1414 | case 3: |
||
18586 | bpr | 1415 | check_string_length(snprintf(tmp_buffer,MAX_BUFFER,"draw_hatchfill(%d,0,0,%d,%d,%d,'%s',%d,xsize,ysize,1);var use_pattern_ctx = true;var pattern_ctx = hatch_fill_pattern;",CLICKFILL_CANVAS,5*line_width,5*line_width,line_width,stroke_color,(int) (fill_opacity/0.0039215))); |
18553 | bpr | 1416 | break; |
1417 | case 4: |
||
18586 | bpr | 1418 | check_string_length(snprintf(tmp_buffer,MAX_BUFFER,"draw_diamondfill(%d,0,0,%d,%d,%d,'%s',%d,xsize,ysize,1);var use_pattern_ctx = true;var pattern_ctx = diamond_fill_pattern;",CLICKFILL_CANVAS,5*line_width,5*line_width,line_width,stroke_color,(int) (fill_opacity/0.0039215))); |
18553 | bpr | 1419 | break; |
1420 | case 5: |
||
18586 | bpr | 1421 | check_string_length(snprintf(tmp_buffer,MAX_BUFFER,"draw_dotfill(%d,0,0,%d,%d,%d,'%s',%d,xsize,ysize,1);var use_pattern_ctx = true;var pattern_ctx = dot_fill_pattern;",CLICKFILL_CANVAS,5*line_width,5*line_width,line_width,stroke_color,(int) (fill_opacity/0.0039215))); |
18553 | bpr | 1422 | break; |
1423 | case 6: |
||
18586 | bpr | 1424 | check_string_length(snprintf(tmp_buffer,MAX_BUFFER,"draw_imagefill(%d,0,0,%d,%d,%d,'%s',%d,xsize,ysize,1);var use_pattern_ctx = true;var pattern_ctx = image_fill_pattern;",CLICKFILL_CANVAS,5*line_width,5*line_width,line_width,stroke_color,(int) (fill_opacity/0.0039215))); |
18553 | bpr | 1425 | break; |
1426 | case 7: |
||
15111 | schaersvoo | 1427 | /*var draw_textfill = function(canvas_type,x0,y0,color,fontfamily,xsize,ysize,txt,use_userdraw)*/ |
18563 | bpr | 1428 | check_string_length(snprintf(tmp_buffer,MAX_BUFFER,"draw_textfill(%d,0,0,'%s','%s',xsize,ysize,userdraw_text_string,1);var use_pattern_ctx = true;var pattern_ctx = text_fill_pattern;",CLICKFILL_CANVAS,stroke_color,font_family)); |
18553 | bpr | 1429 | break; |
1430 | } |
||
1431 | add_to_buffer(tmp_buffer); |
||
15111 | schaersvoo | 1432 | |
18553 | bpr | 1433 | fprintf(js_include_file,"function redraw_userdraw(){console.log('userdraw fill not zooming...');return;};\ |
15111 | schaersvoo | 1434 | function remove_last(){var last = fill_canvas_no;\ |
1435 | console.log('last = '+last);\ |
||
1436 | if(last > %d){\ |
||
1437 | var last_canvas = document.getElementById('wims_canvas%d'+last);\ |
||
1438 | if( last_canvas == null ){fill_canvas_no--;return;};\ |
||
1439 | var last_ctx = last_canvas.getContext('2d');\ |
||
1440 | last_ctx.clearRect(0,0,xsize,ysize);\ |
||
1441 | canvas_div.removeChild(last_canvas);\ |
||
1442 | userdraw_x.pop();userdraw_y.pop();\ |
||
1443 | fill_canvas_no--;\ |
||
1444 | };return;};\ |
||
1445 | if( typeof(fill_canvas_no) === 'undefined' ){ var fill_canvas_no = %d; };\ |
||
1446 | function clickfill(x,y,event_which,num){\ |
||
18642 | schaersvoo | 1447 | var opacity = %d;\ |
18644 | schaersvoo | 1448 | var color = [%s,opacity];\ |
15111 | schaersvoo | 1449 | if( typeof(multifillcolors) === 'object'){\ |
1450 | var numx = userdraw_x.length;\ |
||
1451 | var numc = multifillcolors.length-1;var num = numx%%numc;\ |
||
1452 | if( ! multifillcolors[num] ){alert('first select a colour...');return;};\ |
||
1453 | var tc = (multifillcolors[num]).split(',');\ |
||
18642 | schaersvoo | 1454 | color = [ tc[0],tc[1],tc[2],opacity ];\ |
15111 | schaersvoo | 1455 | if( typeof( palettecolors ) === 'object'){\ |
1456 | var idx = palettecolors.indexOf( multifillcolors[num]);\ |
||
1457 | userdraw_radius.push(idx);\ |
||
1458 | }else{ userdraw_radius.push(num);};\ |
||
1459 | }\ |
||
1460 | else\ |
||
1461 | {\ |
||
1462 | userdraw_radius.push(0);\ |
||
1463 | };\ |
||
1464 | document.body.style.cursor = 'wait';\ |
||
1465 | if( use_pattern_ctx ){\ |
||
18609 | bpr | 1466 | setTimeout(function(){ filltoborder( px2x(x),px2y(y),false,color,fill_canvas_no,true,pattern_ctx);},500);\ |
15111 | schaersvoo | 1467 | }\ |
1468 | else\ |
||
1469 | {\ |
||
18609 | bpr | 1470 | setTimeout(function(){ filltoborder(px2x(x),px2y(y),false,color,fill_canvas_no,false,null);},500);\ |
15111 | schaersvoo | 1471 | };\ |
1472 | userdraw_x.push(x);\ |
||
1473 | userdraw_y.push(y);\ |
||
1474 | fill_canvas_no++;\ |
||
1475 | document.body.style.cursor = 'default';\ |
||
1476 | return;\ |
||
18642 | schaersvoo | 1477 | };",CLICKFILL_CANVAS,canvas_root_id,CLICKFILL_CANVAS,(int)(255*fill_opacity),stroke_color); |
15111 | schaersvoo | 1478 | /*(int) (stroke_opacity/0.0039215),(int) (stroke_opacity/0.0039215) */ |
18553 | bpr | 1479 | break; |
15111 | schaersvoo | 1480 | /* parallelogram/parallelograms */ |
18553 | bpr | 1481 | case 55 ... 56: |
1482 | fprintf(js_include_file,"\ |
||
15111 | schaersvoo | 1483 | function redraw_userdraw(){draw_parallelograms();};\ |
1484 | function remove_last(){if( userdraw_x.length > 0 ){for(var p=0;p<4;p++){userdraw_x.pop();userdraw_y.pop();};draw_parallelograms();};return;};\ |
||
1485 | function parallelograms(x,y,event_which,num){\ |
||
1486 | var l2 = userdraw_x.length;\ |
||
1487 | var l1 = l2 - 1;var l0 = l2 - 2;\ |
||
1488 | var xxyy;\ |
||
1489 | if(event_which == 0){\ |
||
1490 | if(xy_cnt == 0){\ |
||
1491 | if(num == 0){userdraw_x = [];userdraw_y = [];};\ |
||
1492 | userdraw_x.push(x);userdraw_y.push(y);\ |
||
1493 | }\ |
||
1494 | else\ |
||
1495 | {\ |
||
1496 | userdraw_x.push(x);userdraw_y.push(y);\ |
||
1497 | if(xy_cnt == 2){\ |
||
1498 | var xy = multisnap_check(userdraw_x[l2] - userdraw_x[l1] + userdraw_x[l0],userdraw_y[l2] - userdraw_y[l1] + userdraw_y[l0],use_snap);\ |
||
1499 | userdraw_x.push(xy[0]);\ |
||
1500 | userdraw_y.push(xy[1]);\ |
||
1501 | };\ |
||
1502 | };\ |
||
1503 | xy_cnt++;\ |
||
1504 | }\ |
||
1505 | else\ |
||
1506 | {\ |
||
1507 | if(xy_cnt == 1){\ |
||
1508 | var xxyy = multisnap_check(userdraw_x[l1],userdraw_y[l1],use_snap);\ |
||
1509 | userdraw_x.push(xxyy[0]);\ |
||
1510 | userdraw_y.push(xxyy[1]);\ |
||
1511 | userdraw_x.push(x);\ |
||
1512 | userdraw_y.push(y);\ |
||
1513 | draw_parallelograms();\ |
||
1514 | userdraw_x.pop();userdraw_y.pop();\ |
||
1515 | userdraw_x.pop();userdraw_y.pop();\ |
||
1516 | }\ |
||
1517 | else\ |
||
1518 | {\ |
||
1519 | if(xy_cnt == 2){\ |
||
1520 | xxyy = multisnap_check(userdraw_x[l2]-userdraw_x[l1] + userdraw_x[l0],userdraw_y[l2]-userdraw_y[l1] + userdraw_y[l0],use_snap);\ |
||
1521 | userdraw_x.push(x);userdraw_y.push(y);\ |
||
1522 | userdraw_x.push(xxyy[0]);\ |
||
1523 | userdraw_y.push(xxyy[1]);\ |
||
1524 | draw_parallelograms();\ |
||
1525 | userdraw_x.pop();userdraw_y.pop();\ |
||
1526 | userdraw_x.pop();userdraw_y.pop();\ |
||
1527 | };\ |
||
1528 | };\ |
||
1529 | };\ |
||
1530 | if( xy_cnt == 3 ){\ |
||
1531 | userdraw_x.pop();userdraw_y.pop();\ |
||
1532 | xxyy = multisnap_check(userdraw_x[l2]-userdraw_x[l1] + userdraw_x[l0],userdraw_y[l2]-userdraw_y[l1] + userdraw_y[l0],use_snap);\ |
||
1533 | userdraw_x.push(xxyy[0]);userdraw_y.push(xxyy[1]);\ |
||
1534 | userdraw_x.push(x);userdraw_y.push(y);\ |
||
1535 | userdraw_x.pop();userdraw_y.pop();\ |
||
1536 | xy_cnt = 0;\ |
||
1537 | draw_parallelograms();\ |
||
1538 | };\ |
||
1539 | };\ |
||
1540 | function draw_parallelograms(){\ |
||
1541 | var len = userdraw_x.length-1;\ |
||
1542 | context_userdraw.clearRect(0,0,xsize,ysize);\ |
||
1543 | for(var p = 0 ; p < len ; p = p+4){\ |
||
1544 | context_userdraw.beginPath();\ |
||
1545 | context_userdraw.moveTo(userdraw_x[p],userdraw_y[p]);\ |
||
1546 | for( var m = p+1 ;m < p+4 ; m++){\ |
||
1547 | context_userdraw.lineTo(userdraw_x[m],userdraw_y[m]);\ |
||
1548 | };\ |
||
1549 | context_userdraw.lineTo(userdraw_x[p],userdraw_y[p]);\ |
||
1550 | context_userdraw.closePath();\ |
||
1551 | if(use_filled!=0){context_userdraw.fill();};\ |
||
1552 | context_userdraw.stroke();\ |
||
1553 | };\ |
||
1554 | return;};"); |
||
18553 | bpr | 1555 | break; |
15126 | bpr | 1556 | |
15111 | schaersvoo | 1557 | case 57 ... 58: |
18556 | bpr | 1558 | if(js_function[DRAW_JSFUNCTION] != 1 ){ |
18553 | bpr | 1559 | js_function[JS_RAWMATH] = 1;js_function[DRAW_JSFUNCTION] = 1; |
1560 | js_function[JS_MATH] = 1;js_function[JS_PLOT] = 1; |
||
1561 | if(reply_format == 0 || reply_format != -1){reply_format = 24;}/* read canvas_input values */ |
||
1562 | if(polynum == -1 ){polynum = 1; } /* functions5 --> polynum = 5 */ |
||
1563 | for(n=0;n<polynum;n++){ |
||
1564 | add_input_jsfunction(css_class,function_label,input_cnt,stroke_color,stroke_opacity, |
||
1565 | line_width,use_dashed,dashtype[0],dashtype[1],font_size); |
||
1566 | input_cnt++; |
||
1567 | jsplot_cnt++; |
||
1568 | } |
||
15111 | schaersvoo | 1569 | } |
18553 | bpr | 1570 | fprintf(js_include_file,"if(typeof(all_jsplots) !== 'number'){var all_jsplots;};all_jsplots = %d;function redraw_userdraw(){redraw_jsplot();return;};",jsplot_cnt); |
1571 | break; |
||
15111 | schaersvoo | 1572 | |
18553 | bpr | 1573 | default:canvas_error("unknown drawtype?? this should not happen...");break; |
1574 | }/* einde switch */ |
||
15111 | schaersvoo | 1575 | |
1576 | }/* einde add_js_userdraw */ |