Subversion Repositories wimsdev

Compare Revisions

Ignore whitespace Rev 14947 → Rev 14948

/trunk/wims/src/Misc/canvasdraw/canvasmacro.c
24,12 → 24,12
paralelogram = 18
images = 20
28/6/2015:
the next js-code block (parsing/scanning the multidraw objects array) is -for now- generic,
the next js-code block (parsing/scanning the multidraw objects array) is -for now- generic,
e.g. not responsive to the actual draw_types used.
 
TODO: examine/parse the *draw_Types and make the js-code accordingly (e.g. specific and not generic)
 
Firefox does not support drawing SVGimages to canvas unless the svg file
Firefox does not support drawing SVGimages to canvas unless the svg file
has width/height attributes on the root <svg> element and those width/height attributes are not percentages
 
container_div.addEventListener( 'mouseup' , mouseup, false);\
37,7 → 37,7
container_div.addEventListener( 'mousedown' , mousedown,false);\
container_div.addEventListener('touchstart' , function(e) { e.preventDefault(); mousedown(e.changedTouches[0]);},false);\
container_div.addEventListener( 'touchmove' , function(e) { e.preventDefault(); mousemove(e.changedTouches[0]);},false);\
container_div.addEventListener( 'touchend' , function(e) { e.preventDefault(); mouseup( e.changedTouches[0]);},false);\
container_div.addEventListener( 'touchend' , function(e) { e.preventDefault(); mouseup( e.changedTouches[0]);},false);\
 
replace:
var canvas_rect = canvas_userdraw.getBoundingClientRect();\
545,8 → 545,8
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,canvas_root_id,canvas_root_id);
 
/*
now add specific draw functions according to draw_types
/*
now add specific draw functions according to draw_types
these will be somewhat simpler and less fancy-full than for the 'single object' userdraw command...
the 'switch function' in the mouselisteners will probably eat more CPU...so the rest needs to be faster:
we don't want to imitate these horribly slow js-libraries like JSXgraph
556,7 → 556,7
*/
 
/*
3/8/2017 : multidraw text is allways centered on click-coordinates !
3/8/2017 : multidraw text is allways centered on click-coordinates !
use_offset : 0=none; 1=yoffset; 2=xoffset; 3=xyoffset; 4=centered
*/
if( strstr(draw_types,"images") != 0){
646,7 → 646,7
};\
};",use_offset);
}
 
if( strstr(draw_types,"text") != 0){
fprintf(js_include_file,"function text(x,y,event_which,num){\
if(event_which == 1){ return; };\
703,7 → 703,7
};\
};");
}
 
if( strstr(draw_types,"circle") != 0){
fprintf(js_include_file,"function circles(x,y,event_which,num){\
var xy = multi_snap_check(x,y,circles_snap);\
747,7 → 747,7
context_circles.stroke();\
};\
return;\
};");
};");
}
 
if( strstr(draw_types,"segment") != 0){
793,7 → 793,7
return;\
};");
}
 
if( strstr(draw_types,"arrow") != 0){
fprintf(js_include_file,"function arrows(x,y,event_which,num){\
var last = arrows_x.length - 1;\
1211,7 → 1211,7
return;\
};");
}
 
if( strstr( draw_types,("poly")) != 0 ){
char *p = draw_types; int polynum=-1;while( *p ){ if( isdigit(*p) ){ polynum = atoi(p);break; } else { p++;} }
if(polynum != -1 ){
1263,7 → 1263,7
};",polynum);
}
}
}
}
/* end 'void add_js_multidraw()' */
 
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){
1287,7 → 1287,7
var xy = multisnap_check(mouse.x,mouse.y,use_snap);\
x0 = xy[0];y0 = xy[1];\
if(y0 < ysize + 1){\
if(evt.which == 1 || evt.identifier == 0){\
if(evt.button == 0 || evt.identifier >= 0){\
if( click_cnt == 0 ){\
userdraw_x[xy_cnt] = x0;\
userdraw_y[xy_cnt] = y0;\
1364,7 → 1364,7
var mouse = dragstuff.getMouse(evt,canvas_userdraw);\
var xy = multisnap_check(mouse.x,mouse.y,use_snap);\
x0 = xy[0];y0 = xy[1];\
if(evt.which == 1 || evt.identifier == 0){\
if(evt.button == 0 || evt.identifier >= 0){\
userdraw_x[xy_cnt] = x0;\
userdraw_y[xy_cnt] = y0;\
userdraw_radius[xy_cnt] = line_width;\
1486,7 → 1486,7
var mouse = dragstuff.getMouse(evt,canvas_userdraw);\
var xy = multisnap_check(mouse.x,mouse.y,use_snap);\
var x = xy[0];var y = xy[1];var x1,y1,x2,y2;\
if(evt.which == 1 || evt.identifier == 0 ){\
if(evt.button == 0 || evt.identifier >= 0 ){\
userdraw_x[xy_cnt] = x;\
userdraw_y[xy_cnt] = y;\
x1 = x - crosshair_size;\
1564,7 → 1564,7
var xy = multisnap_check(mouse.x,mouse.y,use_snap);\
x0 = xy[0];\
y0 = xy[0];\
if( evt.which == 1 || evt.identifier == 0 ){\
if( evt.button == 0 || evt.identifier >= 0 ){\
if(clickcnt == 0 ){\
clickcnt = 1;\
userdraw_x[xy_cnt] = x0;userdraw_y[xy_cnt] = y0;xy_cnt++;\
1664,7 → 1664,7
var xy = multisnap_check(mouse.x,mouse.y,use_snap);\
x = xy[0];\
y = xy[1];\
if( evt.which == 1 || evt.identifier == 0 ){\
if( evt.button == 0 || evt.identifier >= 0 ){\
if( num == -1 && xy_cnt > 2 ){\
if( x - marge < userdraw_x[0] && x + marge > userdraw_x[0]){\
if( y - marge < userdraw_y[0] && y + marge > userdraw_y[0]){\
1739,7 → 1739,7
x = xy[0];\
y = xy[1];\
var lu = userdraw_x.length;\
if( evt.which == 1 || evt.identifier == 0 ){\
if( evt.button == 0 || evt.identifier >= 0 ){\
userdraw_x[lu] = x;userdraw_y[lu] = y;\
if( cnt == 0 ){\
user_drag(evt);\
1799,7 → 1799,7
var xy = multisnap_check(mouse.x,mouse.y,use_snap);\
var x = xy[0];\
var y = xy[1];\
if( evt.which == 1 || evt.identifier == 0){\
if( evt.button == 0 || evt.identifier >= 0){\
if( lu%%2 == 0){\
x0 = x;y0 = y;\
if(num == 1){ userdraw_x = [];userdraw_y = [];userdraw_x[0] = x0;userdraw_y[0] = y0;} else {userdraw_x[lu] = x0;userdraw_y[lu] = y0;};\
1879,7 → 1879,7
var xy = multisnap_check(mouse.x,mouse.y,use_snap);\
var x = xy[0];\
var y = xy[1];\
if( evt.which == 1 || evt.identifier == 0 ){\
if( evt.button == 0 || evt.identifier >= 0 ){\
if( lu%%2 == 0){\
x0 = x;y0 = y;\
if(num == 1){ userdraw_x = [];userdraw_y = [];userdraw_x[0] = x0;userdraw_y[0] = y0;} else {userdraw_x[lu] = x0;userdraw_y[lu] = y0;}\
1958,7 → 1958,7
var dashtype1 = %d;\
var x0,y0;\
function user_draw(evt){\
if( evt.which == 1 || evt.identifier == 0){\
if( evt.button == 0 || evt.identifier >= 0){\
var mouse = dragstuff.getMouse(evt,canvas_userdraw);\
var xy = multisnap_check(mouse.x,mouse.y,use_snap);\
var x = xy[0];\
2003,7 → 2003,7
var xy = multisnap_check(mouse.x,mouse.y,use_snap);\
var x = xy[0];\
var y = xy[1];\
if( evt.which == 1 || evt.identifier == 0 ){\
if( evt.button == 0 || evt.identifier >= 0 ){\
if( lu%%2 == 0){\
x0 = x;y0 = y;\
if(num == 1){ userdraw_x = [];userdraw_y = [];userdraw_x[0] = x0;userdraw_y[0] = y0;} else {userdraw_x[lu] = x0;userdraw_y[lu] = y0;}\
2090,7 → 2090,7
var xy = multisnap_check(mouse.x,mouse.y,use_snap);\
var x = xy[0];\
var y = xy[1];\
if( evt.which == 1 || evt.identifier == 0 ){\
if( evt.button == 0 || evt.identifier >= 0 ){\
if( lu%%2 == 0){\
x0 = x;y0 = y;\
if(num == 1){ userdraw_x = [];userdraw_y = [];userdraw_x[0] = x0;userdraw_y[0] = y0;} else {userdraw_x[lu] = x0;userdraw_y[lu] = y0;}\
2153,7 → 2153,7
xy_cnt = 0;\
var use_snap = %d;\
function user_draw(evt){\
if(evt.which == 1 || evt.identifier == 0){\
if(evt.button == 0 || evt.identifier >= 0){\
var mouse = dragstuff.getMouse(evt,canvas_userdraw);\
var xy = multisnap_check(mouse.x,mouse.y,use_snap);\
if(1 == %d){if(xy_cnt == 3){xy_cnt = 0;userdraw_x = [];userdraw_y = [];context_userdraw.clearRect(0,0,xsize,ysize);};};\
2163,7 → 2163,7
return;\
};\
function user_drag(evt){\
if(evt.which == 1 || evt.identifier == 0){\
if(evt.button == 0 || evt.identifier >= 0){\
var mouse = dragstuff.getMouse(evt,canvas_userdraw);\
var xy = multisnap_check(mouse.x,mouse.y,use_snap);\
context_userdraw.clearRect(0,0,xsize,ysize);\
2224,7 → 2224,7
var mouse = dragstuff.getMouse(evt,canvas_userdraw);\
var xy = multisnap_check(mouse.x,mouse.y,use_snap);\
var x = xy[0];var y = xy[1];\
if(evt.which == 1 || evt.identifier == 0){\
if(evt.button == 0 || evt.identifier >= 0){\
if( click_cnt == 0 ){\
click_cnt = 1;\
user_drag(evt);\
2415,7 → 2415,7
return;\
};",use_offset,use_offset,snap);
}
 
void add_js_popup(int canvas_root_id,int xsize,int ysize,char *getfile_cmd){
fprintf(stdout,"\n<!-- begin command popup %d -->\n\
<script type=\"text/javascript\">\n\
2539,7 → 2539,7
var num = %d;\
var x,xc,x1,x2,y,yc,y1,y2;var lu = userdraw_x.length;\
if( num == 1 && lu == 3 ){ userdraw_x = [];userdraw_y = [];userdraw_radius = [];};\
if(evt.which == 1 || evt.identifier == 0 ){\
if(evt.button == 0 || evt.identifier >= 0 ){\
var mouse = dragstuff.getMouse(evt,canvas_userdraw);\
var xy = multisnap_check(mouse.x,mouse.y,use_snap);\
if(num == 1 && lu == 3){userdraw_x = [];userdraw_y = [];userdraw_radius = [];};\
2803,7 → 2803,7
}
/*
add slider
P1 P2 Center
P1 P2 Center
0 px ----|-------------|-------------------- width px
min ----|-------------|-------------------- max (x/y/rad)
0 px ----|----|--------|-------------------- width px
2998,7 → 2998,7
 
/*
 
if(evt.which == 1 || evt.identifier == 0){dx=0;dy=Math.PI/4;};\
if(evt.button == 0 || evt.identifier >= 0){dx=0;dy=Math.PI/4;};\
 
add xyslider
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
3739,10 → 3739,10
void add_clear_button(FILE *js_include_file,int canvas_root_id,char *input_style,char *button_text){
/* 25/11/2014 added clearing of reply array
all members will be set to 0 eg reply[0] = 0 , reply[1] = 0 ...
hope this does not interfere with existing work...
hope this does not interfere with existing work...
*/
/*
5/2016 changed to 'setAttribute()' because of trouble on Chromium/Safari/IE
5/2016 changed to 'setAttribute()' because of trouble on Chromium/Safari/IE
10/2016 corrected contex-reset-flaw when using "userdraw text,color" and added inputs to the things we can remove
7/2017 added 'userdraw clickfill,color' to removable things...one user_filling per click
*/
3840,9 → 3840,9
execv("../bin/wims_mathml",argv);canvas_error("could not execute wims_mathml\n");
}
else
{
{
if (pid < (pid_t) 0){
close(my_pipe[0]);close(my_pipe[1]);canvas_error("mathml(): fork() failure.\n");
close(my_pipe[0]);close(my_pipe[1]);canvas_error("mathml(): fork() failure.\n");
}
int status;FILE *stream;close(my_pipe[1]);stream = fdopen (my_pipe[0], "r");
char buffer[MAX_BUFFER+1];memset(buffer,'\0',MAX_BUFFER);
3850,7 → 3850,7
int L0 = 1 + snprintf(NULL,0,"%s", buffer);
tex = my_newmem(L0);memset(tex,'\0',L0);
snprintf(tex,L0,"%s",buffer);
fclose (stream);close(my_pipe[0]);waitpid(pid, &status, 0);
fclose (stream);close(my_pipe[0]);waitpid(pid, &status, 0);
}
return tex;
}
4224,14 → 4224,14
obj_type = 19== yerrorbars
obj_type = 20== xerrorbars
obj_type = 21== curvedarrow
 
arc
x[0] = x[1] = xc = double_data[0]
y[0] = y[1] = yc = double_data[1]
w[0] = width = int_data[0]
w[1] = height = int_data[1]
h[0] = start_angle = double_data[2]
h[1] = end_angle = double_data[3]
x[0] = x[1] = xc = double_data[0]
y[0] = y[1] = yc = double_data[1]
w[0] = width = int_data[0]
w[1] = height = int_data[1]
h[0] = start_angle = double_data[2]
h[1] = end_angle = double_data[3]
myState.selection.line_width = org_line_width;myState.selection.font_family = org_font_family;break;\
 
use_offset only for text shape objects...
4241,11 → 4241,11
3=xyoffset
4=centered
 
int onclick = 0; 0 = noninteractive ; 1 = onclick ; 2 = draggable
type= object type
int onclick = 0; 0 = noninteractive ; 1 = onclick ; 2 = draggable
type= object type
 
verwijderd: direction : dragging in xy=0 , in x=1 in y=2 vervangen dooor use_snap en multisnap_check(x,y,use_snap)
use_snap: 0 = none 1=grid : 2=x-grid : 3=y-grid : 4=snap to points
use_snap: 0 = none 1=grid : 2=x-grid : 3=y-grid : 4=snap to points
 
obj.angle == RADIANS!
*/
4407,7 → 4407,7
};\
var reply = [];\
var slidergroup = [];\
function CanvasState(canvas,container_div){\
function CanvasState(canvas, container_div){\
this.canvas = canvas;\
this.width = canvas.width;\
this.height = canvas.height;\
4853,7 → 4853,7
ctx_temp.drawImage(canvas,ruler_x,ruler_y);\
once = false;\
}",canvas_root_id,use_snap,canvas_root_id,sizex,sizey,x,y,font,stroke_color,stroke_opacity,fill_color,fill_opacity,line_width);
 
if( dynamic == -1 ){
fprintf(js_include_file,"\
ctx.drawImage(canvas_temp,0,0);\