Rev 16834 | Rev 16845 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
15111 | schaersvoo | 1 | /*27/7/2013 version 0.01 |
7614 | schaersvoo | 2 | "Inspired" by FLY program: http://martin.gleeson.com/fly |
3 | ********************************************************************************* |
||
4 | * J.M. Evers 7/2013 * |
||
5 | * This is all just amateur scriblings... So no copyrights. * |
||
6 | * This source code file, and compiled objects derived from it, * |
||
7 | * can be used and distributed without restriction, including for commercial use * |
||
15111 | schaersvoo | 8 | * No warrenty whatsoever * |
7614 | schaersvoo | 9 | ********************************************************************************* |
10 | */ |
||
15734 | schaersvoo | 11 | #define VERSION "0.5" |
7848 | bpr | 12 | #include "canvasdraw.h" |
15348 | bpr | 13 | void *tmp_buffer; |
14 | FILE *js_include_file; |
||
7614 | schaersvoo | 15 | /****************************************************************************** |
16 | ** Internal Functions |
||
17 | ******************************************************************************/ |
||
18 | void add_to_buffer(char *tmp); /* add tmp_buffer to the buffer */ |
||
19 | void sync_input(FILE *infile);/* proceed with inputfile */ |
||
14078 | bpr | 20 | void reset();/* reset some global variables like "use_filled", "use_dashed" */ |
7614 | schaersvoo | 21 | int get_token(FILE *infile); /* read next char until EOL*/ |
8225 | bpr | 22 | /* |
7614 | schaersvoo | 23 | int x2px(double x); |
24 | int y2px(double y); |
||
8225 | bpr | 25 | */ |
15111 | schaersvoo | 26 | double px2x(int x); |
27 | double px2y(int y); |
||
7906 | schaersvoo | 28 | double get_real(FILE *infile,int last); /* read a value; calculation and symbols allowed */ |
7614 | schaersvoo | 29 | char *str_replace ( const char *word, const char *sub_word, const char *rep_word ); |
15111 | schaersvoo | 30 | char *get_color(FILE *infile,int last); /* read hex-color or colorname -> hex */ |
7906 | schaersvoo | 31 | char *get_string(FILE *infile,int last); /* get the string at the end of a command */ |
7614 | schaersvoo | 32 | char *get_string_argument(FILE *infile,int last); /* the same, but with "comma" as separator */ |
15111 | schaersvoo | 33 | char *convert_hex2rgb(char *hexcolor); |
7614 | schaersvoo | 34 | void make_js_include(int canvas_root_id); |
35 | void check_string_length(int length);/* checks if the length of string argument of command is correct */ |
||
15111 | schaersvoo | 36 | FILE *js_include_file; |
7614 | schaersvoo | 37 | FILE *get_file(int *line_number, char **filename); |
15111 | schaersvoo | 38 | FILE *infile; /* will be stdin */ |
7614 | schaersvoo | 39 | /****************************************************************************** |
40 | ** global |
||
41 | ******************************************************************************/ |
||
42 | int finished = FALSE;/* main variable for signalling the end of the fly-script ; if finished = 1 ; write to stdout or canvasz */ |
||
43 | int line_number = 1;/* used in canvas_error() ; keep track of line number in canvasdraw/fly - script */ |
||
44 | /* set some variables to avoid trouble (NaN) in case of syntax and other usage errors */ |
||
45 | int xsize = 320; |
||
46 | int ysize = 320; |
||
47 | double xmin = 0.0; |
||
48 | double xmax = 320.0; |
||
49 | double ymin = 0.0; |
||
50 | double ymax = 320.0; |
||
11893 | schaersvoo | 51 | double tmax = 0; |
52 | double tmin = 0; |
||
7614 | schaersvoo | 53 | /* flag to indicate parsing of line status */ |
8224 | bpr | 54 | int done = FALSE; |
7614 | schaersvoo | 55 | int type; /* eg command number */ |
15111 | schaersvoo | 56 | int onclick = 0; |
57 | /* |
||
15116 | bpr | 58 | |
59 | 1 = onclick ; |
||
60 | 2 = draggable ; |
||
61 | 3 = click+slideable ; |
||
62 | 4 = slideable without click |
||
15111 | schaersvoo | 63 | 5 = draggable + slideable |
64 | */ |
||
14208 | schaersvoo | 65 | char *slider_type="0"; |
15111 | schaersvoo | 66 | char *my_sliders = "[-1]"; |
67 | int use_slider = -1; |
||
68 | int last_slider = 0; |
||
69 | double double_data[MAX_INT+1]; |
||
70 | int int_data[MAX_INT+1]; |
||
71 | int dragstuff[MAX_DRAGSTUFF]; |
||
72 | int js_function[MAX_JS_FUNCTIONS]; /* javascript functions include objects on demand basis: only once per object type */ |
||
73 | double affine_matrix[] = {1,0,0,1,0,0}; |
||
7785 | schaersvoo | 74 | int use_affine = FALSE; |
7614 | schaersvoo | 75 | int use_rotate = FALSE; |
14078 | bpr | 76 | int use_filled = 0; /* 0:no fill, 1:fill,2=grid?,3=hatch?,4=diamond?,5=dot?,6=image? */ |
77 | int use_dashed = FALSE; /* dashing not natively supported in firefox, for now... */ |
||
15111 | schaersvoo | 78 | double angle = 0.0; |
7614 | schaersvoo | 79 | char buffer[MAX_BUFFER];/* contains js-functions with arguments ... all other basic code is directly printed into js-include file */ |
9329 | schaersvoo | 80 | char *getfile_cmd = ""; |
15111 | schaersvoo | 81 | int reply_format = 0; |
82 | unsigned int canvas_root_id; |
||
83 | char *css_class; |
||
84 | int font_size; |
||
85 | char *draw_type; |
||
86 | int jsplot_cnt = -1; /* keepint track on the curve identity */ |
||
87 | int input_cnt = 0; |
||
88 | int dashtype[2] = { 4 , 4 }; /* just line_px and space_px: may have more arguments...if needed in future */ |
||
89 | char *function_label = "[\"f(x)=\",\"g(x)=\",\"h(x)=\"]"; |
||
90 | int drag_type = -1;/* 0,1,2: xy,x,y */ |
||
91 | int use_offset = 0;/* use_offset only for text shape objects... 0=none;1=yoffset;2=xoffset;3=xyoffset;4=centered*/ |
||
92 | int linegraph_cnt = 0; /* identifier for command 'linegraph' ; multiple line graphs may be plotted in a single plot*/ |
||
93 | int barchart_cnt = 0; /* identifier for command 'barchart' ; multiple charts may be plotted in a single plot*/ |
||
94 | int legend_cnt = -1; /* to allow multiple legends to be used, for multiple piecharts etc */ |
||
95 | int use_axis = FALSE; |
||
96 | int use_axis_numbering = -1; |
||
97 | int no_reset = FALSE; |
||
98 | |||
7614 | schaersvoo | 99 | /****************************************************************************** |
100 | ** Main Program |
||
101 | ******************************************************************************/ |
||
102 | int main(int argc, char *argv[]){ |
||
14066 | bpr | 103 | /* need unique id for every call to canvasdraw: rand(); is too slow...will result in many identical id's */ |
12104 | schaersvoo | 104 | struct timeval tv;struct timezone tz;gettimeofday(&tv, &tz); |
15111 | schaersvoo | 105 | canvas_root_id = (unsigned int) tv.tv_usec; |
7614 | schaersvoo | 106 | infile = stdin;/* read flyscript via stdin */ |
107 | int i,c; |
||
15111 | schaersvoo | 108 | for(i=0;i<MAX_DRAGSTUFF;i++){dragstuff[i] = 0;} |
7614 | schaersvoo | 109 | for(i=0;i<MAX_INT;i++){int_data[i]=0;double_data[i]=0;} |
14066 | bpr | 110 | int use_snap = 0; /* 0 = none 1=grid: 2=x-grid: 3=y-grid: 4=snap to points */ |
8448 | schaersvoo | 111 | int print_drag_params_only_once = FALSE;/* avoid multiple useless identical lines about javascript precision and use_dragdrop */ |
7614 | schaersvoo | 112 | int line_width = 1; |
113 | int decimals = 2; |
||
15111 | schaersvoo | 114 | int use_dragstuff = 0; |
8365 | schaersvoo | 115 | int precision = 100; /* 10 = 1;100=2;1000=3 decimal display for mouse coordinates or grid coordinate.May be redefined before every object */ |
15111 | schaersvoo | 116 | int use_userdraw = 0; /* 0=none,1=userdraw,2=multidraw flag to indicate user interaction */ |
9329 | schaersvoo | 117 | int use_tooltip = -1; /* 1= tooltip 2= popup window*/ |
15601 | schaersvoo | 118 | int use_parametric = FALSE;/* will be reset after parametric plotting */ |
7614 | schaersvoo | 119 | char *tooltip_text = "Click here"; |
120 | char *temp = ""; /* */ |
||
121 | char *bgcolor = "";/* used for background of canvas_div ; default is tranparent */ |
||
122 | char *stroke_color = "255,0,0"; |
||
14208 | schaersvoo | 123 | char *fill_color = "255,255,255"; |
15313 | schaersvoo | 124 | char *font_family = "12px Arial"; /* commands xaxistext,yaxistext,legend,text/textup/string/stringup may us this */ |
7614 | schaersvoo | 125 | char *font_color = "#00000"; |
15111 | schaersvoo | 126 | draw_type = "points"; |
7614 | schaersvoo | 127 | char *fly_font = "normal"; |
15111 | schaersvoo | 128 | css_class = "none"; |
7614 | schaersvoo | 129 | char *flytext = ""; |
11006 | schaersvoo | 130 | int canvas_type = DRAG_CANVAS; /* to use a specific canvas for filling etc */ |
7614 | schaersvoo | 131 | int pixelsize = 1; |
11763 | schaersvoo | 132 | int fill_cnt = 0; |
15111 | schaersvoo | 133 | int use_zoom = 0; |
15313 | schaersvoo | 134 | font_size = 12;/* this may lead to problems when using something like <code>fontfamily Italic 24px Arial</code> the ''fontsize`` value is not substituted into fontfamily !! */ |
8388 | schaersvoo | 135 | int fly_font_size = 12; /*fly_font_size is relative to this... */ |
7614 | schaersvoo | 136 | for(i=0;i<MAX_JS_FUNCTIONS;i++){js_function[i]=0;} |
8365 | schaersvoo | 137 | int arrow_head = 8; /* size in px needed for arrow based userdraw: "userdraw arrow,color" */ |
7833 | schaersvoo | 138 | int crosshair_size = 5; /* size in px*/ |
8365 | schaersvoo | 139 | int plot_steps = 250;/* the js-arrays with x_data_points and y_data_points will have size 250 each: use with care !!! use jscurve when precise plots are required */ |
14066 | bpr | 140 | int found_size_command = 0; /* 1 = found size ; 2 = found xrange; 3 = found yrange: just to flag an error message */ |
15111 | schaersvoo | 141 | int object_cnt = 0; /*counter to identify the "onclick" ojects ; 0 is first object set onclick: reply[object_cnt]=1 when clicked ; otherwise reply[object_cnt]=0 ; object_cnt is only increased when another object is set again */ |
7614 | schaersvoo | 142 | int clock_cnt = 0; /* counts the amount of clocks used -> unique object clock%d */ |
9433 | schaersvoo | 143 | int boxplot_cnt = 0; |
15111 | schaersvoo | 144 | int drawxml_cnt = 0; |
11890 | schaersvoo | 145 | int numberline_cnt = 0; |
8074 | schaersvoo | 146 | int reply_precision = 100; /* used for precision of student answers / drawings */ |
15111 | schaersvoo | 147 | char *rotation_center = "null";/* needs to be removed... but is used for canvas CTX based rotation*/ |
148 | double rotationcenter[] = {0,0}; /* use for recalculating x/y values on rotation() */ |
||
11893 | schaersvoo | 149 | int use_animate = 0; /* used for jscurve / js parametric */ |
7823 | schaersvoo | 150 | int use_input_xy = 0; /* 1= input fields 2= textarea 3=calc y value*/ |
8365 | schaersvoo | 151 | size_t string_length = 0; /* measure the size of the user input fly-string */ |
152 | double stroke_opacity = 0.8; /* use some opacity as default */ |
||
14208 | schaersvoo | 153 | double fill_opacity = 0.5;/* use some opacity as default */ |
7614 | schaersvoo | 154 | char *URL = "http://localhost/images"; |
155 | memset(buffer,'\0',MAX_BUFFER); |
||
156 | void *tmp_buffer = ""; |
||
157 | /* default writing a unzipped js-include file into wims getfile directory */ |
||
158 | char *w_wims_session = getenv("w_wims_session"); |
||
12104 | schaersvoo | 159 | if( w_wims_session == NULL || *w_wims_session == 0 ){canvas_error("Hmmm, your wims environment does not exist...\nCanvasdraw should be used within wims.");} |
7614 | schaersvoo | 160 | int L0=strlen(w_wims_session) + 21; |
161 | char *getfile_dir = my_newmem(L0); /* create memory to fit string precisely */ |
||
162 | snprintf(getfile_dir,L0, "../sessions/%s/getfile",w_wims_session);/* string will fit precisely */ |
||
163 | mode_t process_mask = umask(0); /* check if file exists */ |
||
164 | int result = mkdir(getfile_dir, S_IRWXU | S_IRWXG | S_IRWXO); |
||
165 | if( result == 0 || errno == EEXIST ){ |
||
166 | umask(process_mask); /* be sure to set correct permission */ |
||
8224 | bpr | 167 | char *w_session = getenv("w_session"); |
7614 | schaersvoo | 168 | int L1 = (int) (strlen(w_session)) + find_number_of_digits(canvas_root_id) + 48; |
12104 | schaersvoo | 169 | getfile_cmd = my_newmem(L1); /* create memory to fit string precisely */ |
8224 | bpr | 170 | snprintf(getfile_cmd,L1,"wims.cgi?session=%s&cmd=getfile&special_parm=%d.js",w_session,canvas_root_id);/* extension ".gz" is MANDATORY for webserver */ |
13306 | obado | 171 | /* write the include tag to html page:<script src="wims.cgi?session=%s&cmd=getfile&special_parm=11223344_js"></script> */ |
7614 | schaersvoo | 172 | /* now write file into getfile dir*/ |
14066 | bpr | 173 | char *w_wims_home = getenv("w_wims_home"); /* "/home/users/wims": we need absolute path for location */ |
7614 | schaersvoo | 174 | int L2 = (int) (strlen(w_wims_home)) + (int) (strlen(w_wims_session)) + find_number_of_digits(canvas_root_id) + 23; |
175 | char *location = my_newmem(L2); /* create memory to fit string precisely */ |
||
176 | snprintf(location,L2,"%s/sessions/%s/getfile/%d.js",w_wims_home,w_wims_session,canvas_root_id);/*absolute path */ |
||
177 | js_include_file = fopen(location,"w");/* open the file location for writing */ |
||
14066 | bpr | 178 | /* check on opening...if nogood: mount readonly? disk full? permissions not set correctly? */ |
179 | if(js_include_file == NULL){ canvas_error("SHOULD NOT HAPPEN: could not write to javascript include file...check your system logfiles !" );} |
||
7614 | schaersvoo | 180 | |
181 | /* ----------------------------------------------------- */ |
||
11997 | schaersvoo | 182 | |
7614 | schaersvoo | 183 | /* while more lines to process */ |
184 | |||
185 | while(!finished){ |
||
9329 | schaersvoo | 186 | if(line_number>1 && found_size_command == 0 && use_tooltip != 2 ){canvas_error("command \"size xsize,ysize\" needs to come first ! ");} |
7614 | schaersvoo | 187 | type = get_token(infile); |
188 | done = FALSE; |
||
189 | /* |
||
9385 | schaersvoo | 190 | @ canvasdraw |
15116 | bpr | 191 | @ Canvasdraw will try use the same basic syntax structure as flydraw |
16844 | bpr | 192 | @ General syntax <ul><li>The transparency of all objects can be controlled by command <a href="#opacity">opacity [0-255],[0,255]</a></li><li>line width of any object can be controlled by command <a href="#linewidth">linewidth int</a></li><li>any may be dashed by using keyword <a href="#dashed">dashed</a> before the object command.<br /> the dashing type can be controled by command <a href="#dashtype">dashtype int,int</a>please note: dashing may have different spacing depending on the angle of the line<br />see https://wimsedu.info/?topic=dashed-arrows-not-dashed-in-canvasdraw</li><li>a fillable object can be set fillable by starting the object command with an ''f`` (like ''frect``,''fcircle``,''ftriangle`` ...) or by using the keyword <a href="#filled">filled</a> before the object command.<br />The fill colour of ''non_userdraw`` objects will be the stroke colour...(flydraw harmonization 19/10/2013)<br /> non-solid filling (grid,hatch,diamond,dot,text) is provided using command <a href="#fillpattern">fillpattern a_pattern</a><br />note: do not use a <b>f</b> with this non-solid pattern filling !<br />for <a href="#filltoborder">filltoborder x0,y0,color</a> or <a href="#filltoborder">fill x0,y0,color</a> type filling (eg fill a region around x0,y0 with color until a border is encountered),<br />there are non-solid pattern fill analogues:<ul><li><a href="#gridfill">gridfill x,y,dx,dy,color</a></li><li><a href="#hatchfill">hatchfill x,y,dx,dy,color</a></li><li><a href="#diamondfill">diamondfill x,y,dx,dy,color</a></li><li><a href="#dotfill">dotfill x,y,dx,dy,color</a></li><li><a href="#textfill">textfill x,y,color,sometext_or_char</a></li></ul></li><li>all draggable objects may have a <a href="#slider">slider</a> for translation / rotation; several objects may be translated / rotated by a single slider</li> <li> a draggable object can be set draggable by a preceding command <a href="#drag">drag x/y/xy</a><br />The translation can be read by javascript:read_dragdrop();The replyformat is: object_number : x-orig : y-orig : x-drag : y-drag<br />The x-orig/y-orig will be returned in maximum precision (javascript float)...<br />the x-drag/y-drag will be returned in defined ''precision`` number of decimals<br />Multiple objects may be set draggable / clickable (no limit)<br />not all flydraw objects may be dragged / clicked<br />Only draggable / clickable objects will be scaled on <a href="#zoom">zoom</a> and will be translated in case of panning.</li><li> a ''onclick object`` can be set ''clickable`` by the preceding keyword <a href="#onclick">onclick</a><br />not all flydraw objects can be set clickable</li><li><b>remarks using a '';`` as command separator</b>. Commands with only numeric or colour arguments may be using a '';`` as command separator (instead of a new line). Commands with a string argument may not use a '';`` as command separator !<br />these exceptions are not really straight forward... so keep this in mind.</li><li>almost every <a href="#userdraw">userdraw object,color</a> or <a href="#multidraw">multidraw</a> command ''family`` may be combined with keywords <a href="#snaptogrid">"snaptogrid | xsnaptogrid | ysnaptogrid | snaptofunction</a> or command <code>snaptopoints x1,y1,x2,y2,...</code></li><li>every draggable | onclick object may be combined with keywords <a href="#snaptogrid">snaptogrid | xsnaptogrid | ysnaptogrid | snaptofunction</a> or command <code>snaptopoints x1,y1,x2,y2,...</code></li><li>almost every command for a single object has a multiple objects counterpart:<br /><ul>general syntax rule:<li><code>object x1,y1,...,color</code></li><li><code>objects color,x1,y1,...</code></li></ul><li>All inputfields or textareas generated, can be styled individually using command <a href="#css">css some_css</a><br/>the fontsize used for labeling these elements can be controlled by command <a href="#fontsize">fontsize int</a> <br />command <code>fontfamily</code> is <b>not</b> active for these elements</li></ul> |
193 | @ If needed multiple interactive scripts (*) may be used in a single webpage.<br />A function <code>read_canvas()</code> and / or <code>read_dragdrop()</code> can read all interactive userdata from these images.<br />The global array <code>canvas_scripts</code>will contain all unique random "canvas_root_id" of the included scripts.<br />The included local javascript "read" functions ''read_canvas%d()`` and ''read_dragdrop%d()`` will have this ''%d = canvas_root_id``<br />e.g. canvas_scripts[0] will be the random id of the first script in the page and will thus provide a function<br /><code>fun = eval("read_canvas"+canvas_scripts[0])</code> to read user based drawings / inputfield in this first image.<br />The read_dragdrop is analogue.<br />If the default reply formatting is not suitable, use command <a href='#replyformat'>replyformat</a> to format the replies for an individual canvas script,<br />To read all user interactions from all included canvas scripts, use something like:<br /><code>function read_all_canvas_images(){<br /> var script_len = canvas_scripts.length;<br /> var draw_reply = "";<br /> var found_result = false;<br /> for(var p = 0 ; p < script_len ; p++){<br /> var fun = eval("read_canvas"+canvas_scripts[p]);<br /> if( typeof fun === 'function'){<br /> var result = fun();<br /> if( result && result.length != 0){<br /> if(script_len == 1 ){.return result;};<br /> found_result = true;<br /> draw_reply = draw_reply + result + "newline";<br /> };<br /> };<br /> };<br /> if( found_result ){return draw_reply;}else{return null;};<br />};</code> <br />(*) Note: the speed advantage over <em>canvas-do-it-all</em> libraries is reduced to zero, when multiple canvasdraw scripts are present in a single page...<br />For example a typical canvasdraw script is between 5 and 40 kB...a large library like JSXgraph is approx 600 kB<br />In these cases it would be much faster to load a static general HTML5 canvas javascript draw library and parse it multiple raw fly instructions !<br /> |
||
194 | @ Canvasdraw can be used to paint a html5 bitmap image<br />by generating a tailor-made javascript include file: providing only the js-functionality needed to perform the job.<br />thus ensuring a minimal strain on the client browser <br />(unlike some popular ''canvas-do-it-all`` libraries, who have proven to be not suitable for low-end computers found in schools...) |
||
15111 | schaersvoo | 195 | @ You can check the javascript reply format in the wims tool <a href="http://localhost/wims/wims.cgi?lang=en&module=tool/directexec">direct exec</a> |
196 | @ For usage within OEF (without anstype ''draw``), something like this (a popup function plotter) will work:<br /><code>\\text{popup_grapher=wims(exec canvasdraw <br />popup<br />size 400,400<br />xrange -10,10<br />yrange -10,10<br />axis<br />axisnumbering<br />opacity 100,100<br />grid 2,2,grey,2,2,6,black<br />snaptogrid<br />linewidth 2<br />jsplot red,5*sin(1/x)<br />strokecolor green<br />functionlabel f(x)=<br />userinput function<br />mouse blue,22<br />)<br />}<br />\\statement{<br />\\popup_grapher<br />}</code>. |
||
14379 | bpr | 197 | @ Be aware that older browsers will probably not work correctly<br />no effort has been undertaken to add glue code for older browsers !! <br />in any case it is not wise to use older browsers...not just for canvasdraw. |
15111 | schaersvoo | 198 | @ Be aware that combining several different objects and interactivity may lead to problems. |
14379 | bpr | 199 | @ If you find flaws, errors or other incompatibilities -not those mentioned in this document- send <a href='mailto:jm.evers-at-schaersvoorde.nl'>me</a> an email with screenshots and the generated javascript include file. |
15633 | bpr | 200 | @ There is limited support for touch devices: touchstart, touchmove and touchend in commands <a href="#userdraw">userdraw primitives </a>, <a href="#multidraw">multidraw primitives </a>, <a href="#protractor">protractor</a>, <a href="#ruler">ruler</a> and probably a few others... <br />Only single finger gestures are supported (for now).<br />The use of a special pen is advised for interactive drawing on touch devices.<br />For more accurate user-interaction (numeric, eg keyboard driven drawings) with canvasdraw on touch devices: use the command family <a href="#userinput_xy">userinput</a>. |
7614 | schaersvoo | 201 | */ |
202 | switch(type){ |
||
15111 | schaersvoo | 203 | case END:finished = 1;done = TRUE;break; |
204 | case 0:sync_input(infile);break; |
||
11806 | schaersvoo | 205 | case AFFINE: |
7614 | schaersvoo | 206 | /* |
11806 | schaersvoo | 207 | @ affine a,b,c,d,tx,ty |
208 | @ defines a transformation matrix for subsequent objects |
||
14066 | bpr | 209 | @ use keyword <a href='#killaffine'>killaffine</a> to end the transformation...the next objects will be drawn in the original x/y-range |
210 | @ a: Scales the drawings horizontally |
||
211 | @ b: Skews the drawings horizontally |
||
212 | @ c: Skews the drawings vertically |
||
213 | @ d: Scales the drawings vertically |
||
11806 | schaersvoo | 214 | @ tx: Moves the drawings horizontally in xrange coordinate system |
215 | @ ty: Moves the drawings vertically in yrange coordinate system |
||
14078 | bpr | 216 | @ the data precision may be set by preceding command ''precision int`` |
15541 | schaersvoo | 217 | @ <b>note</b>: not all affine operations on canvasdraw objects will be identical to flydraw's behaviour. Make sure to check ! |
15111 | schaersvoo | 218 | @%affine%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%#use larger linewith to improve selecting a draggable object !%linewidth 4%drag xy%frect 0,5,3,3,red%affine cos(pi/4),sin(pi/4),-cos(pi/2),sin(pi/2),-5,-5%drag xy%frect 0,5,3,3,red |
15313 | schaersvoo | 219 | @%affine+latex%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%strokecolor blue%fontfamily 42px Arial%centered%drag xy%latex 5,5,\\frac{123}{\\pi^{234}}%affine cos(pi/4),sin(pi/4),-cos(pi/2),sin(pi/2),-5,-5%drag xy%latex 5,5,\\frac{123}{\\pi^{234}} |
7614 | schaersvoo | 220 | */ |
11806 | schaersvoo | 221 | for(i = 0 ; i<6;i++){ |
7614 | schaersvoo | 222 | switch(i){ |
15111 | schaersvoo | 223 | case 0: affine_matrix[0] = get_real(infile,0);break; |
224 | case 1: affine_matrix[1] = get_real(infile,0);break; |
||
225 | case 2: affine_matrix[2] = get_real(infile,0);break; |
||
226 | case 3: affine_matrix[3] = get_real(infile,0);break; |
||
227 | case 4: affine_matrix[4] = get_real(infile,0);break; |
||
228 | case 5: affine_matrix[5] = get_real(infile,1); |
||
11806 | schaersvoo | 229 | use_affine = TRUE; |
230 | break; |
||
7614 | schaersvoo | 231 | default: break; |
232 | } |
||
233 | } |
||
11806 | schaersvoo | 234 | break; |
14394 | schaersvoo | 235 | case ALLOW_DUPLICATES: |
236 | /* |
||
14393 | schaersvoo | 237 | @ duplicates || allowdups |
238 | @ keyword (no arguments) |
||
15645 | bpr | 239 | @ only useful in case of a <a href="#multidraw">multidraw</a> student reply. |
240 | @ only useful in default <a href="#replyformat">replyformat</a> (eg in case of a not specified replyformat). |
||
14396 | bpr | 241 | @ if set, duplicate (x:y) coordinates will not be removed from the student reply. |
15645 | bpr | 242 | @ technical: a javascript variable "allow_duplicate_answer = 1;" is declared. |
243 | @ default for command multidraw is: removal of duplicates. |
||
14393 | schaersvoo | 244 | */ |
15111 | schaersvoo | 245 | fprintf(js_include_file,"var allow_duplicate_answers = 1;"); |
14393 | schaersvoo | 246 | break; |
11806 | schaersvoo | 247 | case ANGLE: |
7614 | schaersvoo | 248 | /* |
11806 | schaersvoo | 249 | @ angle xc,yc,width,start_angle,end_angle,color |
250 | @ width is in x-range |
||
14208 | schaersvoo | 251 | @ angles are in degrees |
252 | @ not compatible with ''flydraw`` |
||
11806 | schaersvoo | 253 | @ will zoom in/out |
15690 | schaersvoo | 254 | @ may be set onclick or drag&drop |
14208 | schaersvoo | 255 | @ if angle size is controlled by command <a href='#slider'>slider</a>, use radians to set limits of slider |
15111 | schaersvoo | 256 | @ ''angle`` and <a href="#arc">arc</a> are exceptions in case of sliders...they are always active (e.g. not click-activated) |
12110 | schaersvoo | 257 | @%angle%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor orange%angle 0,0,4,10,135,blue |
15111 | schaersvoo | 258 | @%angle_slider%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 3%strokecolor blue%slider -2*pi,2*pi,260,28,angle active degree,blue arrow%arrow 0,0,8,0,8,blue%fillpattern diamond%angle 0,0,2,0,0,blue%killslider%strokecolor red%slider -2*pi,2*pi,260,28,angle active radian,red arrow%arrow 0,1,8,1,8,red%fillpattern dot%angle 0,1,2,0,0,red |
7614 | schaersvoo | 259 | */ |
11806 | schaersvoo | 260 | for(i=0;i<7;i++){ |
7614 | schaersvoo | 261 | switch(i){ |
11806 | schaersvoo | 262 | case 0:double_data[0] = get_real(infile,0);break; /* x-values */ |
15111 | schaersvoo | 263 | case 1:double_data[1] = get_real(infile,0); |
264 | if(use_rotate == TRUE ){rotate(2,angle,rotationcenter,2);} |
||
15116 | bpr | 265 | if(use_affine == TRUE ){ transform(2,2);} |
15111 | schaersvoo | 266 | break; /* y-values */ |
14208 | schaersvoo | 267 | case 2:double_data[2] = get_real(infile,0);break; /* width x-range ! */ |
15111 | schaersvoo | 268 | case 3:double_data[3] = 0.0174532925*(get_real(infile,0) - angle);break; /* start angle in degrees -> radians */ |
269 | case 4:double_data[4] = 0.0174532925*(get_real(infile,0) - angle);break; /* end angle in degrees -> radians */ |
||
11806 | schaersvoo | 270 | case 5:stroke_color = get_color(infile,1);/* name or hex color */ |
15111 | schaersvoo | 271 | if( use_slider != -1 ){ onclick = 3; }/* always active in case of slider */ |
272 | decimals = find_number_of_digits(precision); |
||
273 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,17,[%.*f,%.*f],[%.*f,%.*f],[%.*f,%.*f],[%.*f,%.*f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[0],decimals,double_data[1],decimals,double_data[1],decimals,double_data[2],decimals,double_data[2],decimals,double_data[3],decimals,double_data[4],line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
274 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
275 | snprintf(tmp_buffer,string_length, "dragstuff.addShape(new Shape(%d,%d,%d,%d,17,[%.*f,%.*f],[%.*f,%.*f],[%.*f,%.*f],[%.*f,%.*f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[0],decimals,double_data[1],decimals,double_data[1],decimals,double_data[2],decimals,double_data[2],decimals,double_data[3],decimals,double_data[4],line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
276 | add_to_buffer(tmp_buffer); |
||
277 | dragstuff[17] = 1; |
||
278 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
279 | if(onclick != 0){object_cnt++;}/* object_cnt++;*/ |
||
11806 | schaersvoo | 280 | break; |
7614 | schaersvoo | 281 | } |
282 | } |
||
283 | break; |
||
8386 | schaersvoo | 284 | |
11806 | schaersvoo | 285 | case ANIMATE: |
7614 | schaersvoo | 286 | /* |
11930 | schaersvoo | 287 | @ animate |
11893 | schaersvoo | 288 | @ keyword |
15111 | schaersvoo | 289 | @ if set, it will animate a point on a curve |
290 | @ all other canvas object or group of objects (like lines,circles,rects,points...images,svg,latex,mathml etc)<br />may be animated using command <a href='#slider'>slider</a> with keyword 'anim' |
||
14071 | bpr | 291 | @ the animated point is a filled rectangle ; adjust colour with command <code>fillcolor colorname/hexnumber</code> |
11893 | schaersvoo | 292 | @ use linewidth to adjust size of the points |
14078 | bpr | 293 | @ will animate a point on -only- the next <a href='#jsplot'>jsplot/jscurve command</a>. Only a single call to <code>animate</code> is allowed...in case of multiple <code>animate</code> keywords, only the last one is valid |
15111 | schaersvoo | 294 | @ only usable in combination with command <a href='#jsplot'>jsplot</a> (normal functions or parametric) |
13957 | schaersvoo | 295 | @ moves repeatedly from <a href='#xrange'>xmin to xmax</a> or in case of a parametric function from <a href='#trange'>tmin to tmax</a> |
15650 | reyssat | 296 | @ use commands <a href='#multilinewidth'>multilinewidth</a>, <a href='#multistrokecolor'>multistrokecolor</a> etc in case of multiple animated functions.<br />use multiple functions as argument in a single call to <a href='#jsplot'>jsplot color,fun1,fun2,fun3...fun_n</a> |
13939 | bpr | 297 | @%animate_1%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%precision 1%grid 2,2,grey,2,2,5,grey%precision 100%linewidth 4%fillcolor red%animate%trange -2*pi,2*pi%linewidth 1%opacity 255,50%canvastype 100%fill 1.2,1.2,red%canvastype 101%fill -1.2,-1.2,blue%jsplot blue,7*cos(x),5*sin(2*x) |
298 | @%animate_2%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%precision 1%grid 2,2,grey,2,2,5,grey%precision 100%linewidth 4%fillcolor red%animate%trange -2*pi,2*pi%linewidth 1%opacity 255,50%canvastype 100%fill 1.2,1.2,red%canvastype 101%fill -1.2,-1.2,blue%multistrokecolors blue,blue,green,green,orange,orange%multilinewidth 2,2,3,3,1,1%jsplot blue,7*cos(x),5*sin(2*x),9*sin(x),5*cos(x),x^2,x |
||
7614 | schaersvoo | 299 | */ |
13512 | schaersvoo | 300 | use_animate++; |
301 | if( use_animate == 1 ){ |
||
302 | fprintf(js_include_file,"\nvar trace_canvas = create_canvas%d(%d,xsize,ysize);\ |
||
303 | var trace_ctx = trace_canvas.getContext('2d');\ |
||
304 | trace_ctx.fillStyle = 'rgba(%s,%f)';\ |
||
305 | trace_ctx.strokeStyle = 'rgba(%s,%f)';\ |
||
306 | trace_ctx.lineWidth = %d;var anim_pos = 0;\n\ |
||
307 | function animate_this(){\ |
||
308 | var sync;\ |
||
309 | var synchrone = Math.floor(animation_steps/animation_funs);\ |
||
310 | trace_ctx.clearRect(0,0,xsize,ysize);\ |
||
311 | for(var p=0; p<animation_funs;p++){\ |
||
312 | sync = p*synchrone;\ |
||
313 | trace_ctx.fillRect(x_anim_points[sync+anim_pos]-%d, y_anim_points[sync+anim_pos]-%d,%d,%d);\ |
||
314 | };\ |
||
315 | setTimeout(function(){\ |
||
316 | requestAnimationFrame(animate_this); anim_pos++;}, 50\ |
||
317 | );\ |
||
318 | if(anim_pos >= animation_steps){anim_pos = 0;};\ |
||
319 | };",canvas_root_id,ANIMATE_CANVAS,fill_color,fill_opacity,stroke_color,stroke_opacity,line_width,line_width,line_width,2*line_width,2*line_width); |
||
320 | } |
||
321 | else |
||
322 | { |
||
13514 | schaersvoo | 323 | canvas_error("animate can only be used once<br />multiple curves may be animated using something like:<br />jsplot red,sin(x),cos(x),x^2,sin(2*x)"); |
13512 | schaersvoo | 324 | } |
7614 | schaersvoo | 325 | break; |
8386 | schaersvoo | 326 | |
11806 | schaersvoo | 327 | case ARC: |
7614 | schaersvoo | 328 | /* |
11997 | schaersvoo | 329 | @ arc xc,yc,x-width,y-height,start_angle,end_angle,color |
15690 | schaersvoo | 330 | @ may be set ''onclick`` or ''drag xy`` |
14208 | schaersvoo | 331 | @ compatible with ''flydraw`` |
332 | @ attention: width & height in x/y-range |
||
16832 | bpr | 333 | @ for arrow hats on an arc, see command <a href='#arcarrow'>arcarrow or arrowarc</a> |
14208 | schaersvoo | 334 | @ better use command <a href='#angle'>angle</a> for use with a <a href='#slider'>slider</a> |
15111 | schaersvoo | 335 | @%arc%size 400,400%xrange -10,10%yrange -10,10%arc 0,0,4,4,10,135,red |
13961 | schaersvoo | 336 | @%arc_filled%size 400,400%xrange -10,10%yrange -10,10%opacity 255,60%filled%fillcolor green%arc 0,0,4,4,10,135,red |
7614 | schaersvoo | 337 | */ |
11806 | schaersvoo | 338 | for(i=0;i<7;i++){ |
339 | switch(i){ |
||
340 | case 0:double_data[0] = get_real(infile,0);break; /* x-values */ |
||
15111 | schaersvoo | 341 | case 1:double_data[1] = get_real(infile,0); |
342 | if(use_rotate == TRUE ){rotate(2,angle,rotationcenter,2);} |
||
343 | if(use_affine == TRUE ){ transform(4,2);} |
||
344 | break; /* y-values */ |
||
11806 | schaersvoo | 345 | case 2:double_data[2] = get_real(infile,0);break; /* width x-range no pixels ! */ |
15111 | schaersvoo | 346 | case 3:double_data[3] = get_real(infile,0); |
347 | break; /* height y-range no pixels ! */ |
||
348 | case 4:double_data[4] = get_real(infile,0) - angle ;break; /* start angle in degrees */ |
||
349 | case 5:double_data[5] = get_real(infile,0) - angle;break; /* end angle in degrees */ |
||
11806 | schaersvoo | 350 | case 6:stroke_color = get_color(infile,1);/* name or hex color */ |
351 | /* in Shape library: |
||
352 | x[0] = x[1] = xc = double_data[0] |
||
353 | y[0] = y[1] = yc = double_data[1] |
||
354 | w[0] = width = double_data[2] |
||
355 | w[1] = height = double_data[3] |
||
356 | h[0] = start_angle = double_data[4] |
||
357 | h[1] = end_angle = double_data[5] |
||
358 | */ |
||
15111 | schaersvoo | 359 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
11806 | schaersvoo | 360 | decimals = find_number_of_digits(precision); |
15111 | schaersvoo | 361 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,12,[%.*f,%.*f],[%.*f,%.*f],[%.*f,%.*f],[%.*f,%.*f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[0],decimals,double_data[1],decimals,double_data[1],decimals,double_data[2],decimals,double_data[3],decimals,double_data[4],decimals,double_data[5],line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
362 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
363 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,12,[%.*f,%.*f],[%.*f,%.*f],[%.*f,%.*f],[%.*f,%.*f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[0],decimals,double_data[1],decimals,double_data[1],decimals,double_data[2],decimals,double_data[3],decimals,double_data[4],decimals,double_data[5],line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
364 | add_to_buffer(tmp_buffer);reset(); |
||
365 | dragstuff[12] = 1; |
||
366 | if(onclick != 0){object_cnt++;} |
||
367 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
11806 | schaersvoo | 368 | break; |
369 | } |
||
370 | } |
||
7614 | schaersvoo | 371 | break; |
15690 | schaersvoo | 372 | case ARCARROW: |
373 | /* |
||
374 | @ arrowarc xc,yc,x-width,y-height,start_angle,end_angle,color,type |
||
15715 | schaersvoo | 375 | @ alternative: arcarrow |
15690 | schaersvoo | 376 | @ uses same syntax as <a href='#arc'>arc</a> |
377 | @ for arrow hat: type = 1 : right<br />type = 2 : left<br />type = 3 : left&right |
||
378 | @ if the default arrow hat/head is not satisfactory , the size of the arrow may be set with command <a href='#arrowhead'>arrowhead</a> |
||
379 | @ no other arrow types are implemented...yet |
||
380 | @ may be set draggable or onclick |
||
381 | @ attention: when width ad height are very different, the arrow hat is not drawn correctly. This is a flaw and not a feature...(for now: too much calculations to correct) |
||
382 | @%arcarrow%size 400,400%xrange -10,10%yrange -10,10%noreset%onclick%arcarrow 0,0,7,7,50,275,blue,3%arcarrow 0,0,8,8,50,275,red,2%arcarrow 0,0,9,9,50,275,green,1 |
||
383 | */ |
||
384 | for(i=0;i<8;i++){ |
||
385 | switch(i){ |
||
386 | case 0:double_data[0] = get_real(infile,0);break; /* x-values */ |
||
387 | case 1:double_data[1] = get_real(infile,0); |
||
388 | if(use_rotate == TRUE ){rotate(2,angle,rotationcenter,2);} |
||
389 | if(use_affine == TRUE ){ transform(4,2);} |
||
390 | break; /* y-values */ |
||
391 | case 2:double_data[2] = get_real(infile,0);break; /* width x-range no pixels ! */ |
||
392 | case 3:double_data[3] = get_real(infile,0); |
||
393 | break; /* height y-range no pixels ! */ |
||
394 | case 4:double_data[4] = get_real(infile,0) - angle ;break; /* start angle in degrees */ |
||
395 | case 5:double_data[5] = get_real(infile,0) - angle;break; /* end angle in degrees */ |
||
396 | case 6:stroke_color = get_color(infile,0);/* name or hex color */ |
||
397 | break; |
||
398 | case 7:int_data[0] = (int) get_real(infile,1); |
||
399 | switch(int_data[0]){ |
||
400 | case 1: int_data[1] = 24;break; /* right */ |
||
401 | case 2: int_data[1] = 25;break; /* left */ |
||
402 | case 3: int_data[1] = 26;break; /* left&right */ |
||
403 | default:int_data[1] = 24;break; |
||
404 | } |
||
405 | if(int_data[0] == 1 ){int_data[1] = 24;} |
||
406 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
407 | decimals = find_number_of_digits(precision); |
||
408 | string_length = 1 + snprintf(NULL,0,"var arrow_head = %d;dragstuff.addShape(new Shape(%d,%d,%d,%d,%d,[%.*f,%.*f],[%.*f,%.*f],[%.*f,%.*f],[%.*f,%.*f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",arrow_head,drag_type,object_cnt,onclick,use_snap,int_data[1],decimals,double_data[0],decimals,double_data[0],decimals,double_data[1],decimals,double_data[1],decimals,double_data[2],decimals,double_data[3],decimals,double_data[4],decimals,double_data[5],line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
409 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
410 | snprintf(tmp_buffer,string_length,"var arrow_head = %d;dragstuff.addShape(new Shape(%d,%d,%d,%d,%d,[%.*f,%.*f],[%.*f,%.*f],[%.*f,%.*f],[%.*f,%.*f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",arrow_head,drag_type,object_cnt,onclick,use_snap,int_data[1],decimals,double_data[0],decimals,double_data[0],decimals,double_data[1],decimals,double_data[1],decimals,double_data[2],decimals,double_data[3],decimals,double_data[4],decimals,double_data[5],line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
411 | add_to_buffer(tmp_buffer); |
||
412 | dragstuff[int_data[1]] = 1; |
||
413 | if(onclick != 0){object_cnt++;} |
||
414 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
415 | js_function[JS_ARROWHEAD] = 1; |
||
416 | reset(); |
||
417 | } |
||
418 | } |
||
419 | break; |
||
11806 | schaersvoo | 420 | case ARROW: |
7614 | schaersvoo | 421 | /* |
11806 | schaersvoo | 422 | @ arrow x1,y1,x2,y2,h,color |
15715 | schaersvoo | 423 | @ alternative: vector |
14379 | bpr | 424 | @ draw a single headed arrow / vector from (x1:y1) to (x2:y2)<br />with arrowhead size h in px and in color ''color`` |
14077 | bpr | 425 | @ use command <code>linewidth int</code> to adjust thickness of the arrow |
9406 | schaersvoo | 426 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
13957 | schaersvoo | 427 | @%arrow_drag%size 400,400%xrange -10,10%yrange -10,10%cursor move%linewidth 2%drag xy%arrow 0,0,4,3,8,blue%drag xy%arrow 0,0,-4,3,8,green%drag xy%arrow 0,0,4,-3,8,orange%drag xy%arrow 0,0,-4,-3,8,cyan |
428 | @%arrow_click%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%%onclick%arrow 0,0,4,4,8,blue%onclick%arrow 0,0,-4,5,8,green%onclick%arrow 0,0,4,-6,8,orange%onclick%arrow 0,0,-4,-2,8,cyan |
||
7614 | schaersvoo | 429 | */ |
11806 | schaersvoo | 430 | for(i=0;i<6;i++){ |
7614 | schaersvoo | 431 | switch(i){ |
432 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
433 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
11806 | schaersvoo | 434 | case 2: double_data[2] = get_real(infile,0);break; /* x */ |
435 | case 3: double_data[3] = get_real(infile,0);break; /* y */ |
||
436 | case 4: arrow_head = (int) get_real(infile,0);break;/* h */ |
||
437 | case 5: stroke_color = get_color(infile,1);/* name or hex color */ |
||
15111 | schaersvoo | 438 | if(use_rotate == TRUE ){rotate(4,angle,rotationcenter,2);} |
439 | if(use_affine == TRUE ){ transform(4,2);} |
||
440 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
441 | decimals = find_number_of_digits(precision); |
||
442 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,8,[%.*f,%.*f],[%.*f,%.*f],[%d,%d],[%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[2],decimals,double_data[1],decimals,double_data[3],arrow_head,arrow_head,arrow_head,arrow_head,line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
443 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
444 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,8,[%.*f,%.*f],[%.*f,%.*f],[%d,%d],[%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[2],decimals,double_data[1],decimals,double_data[3],arrow_head,arrow_head,arrow_head,arrow_head,line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
445 | if(onclick != 0){object_cnt++;} |
||
446 | /* object_cnt++;*/ |
||
447 | add_to_buffer(tmp_buffer);reset(); |
||
448 | dragstuff[8] = 1; |
||
449 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
450 | break; |
||
11806 | schaersvoo | 451 | } |
452 | } |
||
453 | break; |
||
8386 | schaersvoo | 454 | |
11806 | schaersvoo | 455 | case ARROWS: |
7614 | schaersvoo | 456 | /* |
11806 | schaersvoo | 457 | @ arrows color,head (px),x1,y1,x2,y2...x_n,y_n |
15715 | schaersvoo | 458 | @ alternative: vectors |
15111 | schaersvoo | 459 | @ draw single headed arrows / vectors from (x1:y1) to (x2:y2) ... (x3:y3) to (x4:y4) etc ... in color 'color' |
14071 | bpr | 460 | @ use command <code>linewidth int</code> to adjust thickness of the arrow |
11806 | schaersvoo | 461 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually |
13957 | schaersvoo | 462 | @%arrows_click%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%onclick%arrows red,8,0,0,4,3,0,0,2,4,0,0,-2,4,0,0,-3,-4,0,0,3,-2% |
463 | @%arrows_drag%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%drag xy%arrows red,8,0,0,4,3,0,0,2,4,0,0,-2,4,0,0,-3,-4,0,0,3,-2% |
||
14208 | schaersvoo | 464 | @%arrows_drag_slider%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%drag xy%# Click arrow(s) to activate %slider 0,2*pi,300,30,angle degrees,Rotate%slider -5,5*pi,300,30,x display,move in x-direction%slider -10,10*pi,300,30,y display,move in y-direction%arrows red,8,0,0,4,3,0,0,2,4,0,0,-2,4,0,0,-3,-4,0,0,3,-2% |
7614 | schaersvoo | 465 | */ |
466 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
467 | fill_color = stroke_color; |
||
11806 | schaersvoo | 468 | arrow_head = (int) get_real(infile,0);/* h */ |
7614 | schaersvoo | 469 | i=0; |
470 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 471 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
7614 | schaersvoo | 472 | if(i%2 == 0 ){ |
473 | double_data[i] = get_real(infile,0); /* x */ |
||
474 | } |
||
475 | else |
||
476 | { |
||
477 | double_data[i] = get_real(infile,1); /* y */ |
||
478 | } |
||
479 | i++; |
||
480 | } |
||
15111 | schaersvoo | 481 | if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);} |
482 | if( use_affine == TRUE ){ transform(i-1,2);} |
||
483 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
7614 | schaersvoo | 484 | decimals = find_number_of_digits(precision); |
11806 | schaersvoo | 485 | for(c = 0 ; c < i-1 ; c = c+4){ |
15111 | schaersvoo | 486 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,8,[%.*f,%.*f],[%.*f,%.*f],[%d,%d],[%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[c],decimals,double_data[c+2],decimals,double_data[c+1],decimals,double_data[c+3],arrow_head,arrow_head,arrow_head,arrow_head,line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
487 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
488 | snprintf(tmp_buffer,string_length, "dragstuff.addShape(new Shape(%d,%d,%d,%d,8,[%.*f,%.*f],[%.*f,%.*f],[%d,%d],[%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[c],decimals,double_data[c+2],decimals,double_data[c+1],decimals,double_data[c+3],arrow_head,arrow_head,arrow_head,arrow_head,line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
489 | add_to_buffer(tmp_buffer); |
||
490 | if(onclick != 0){object_cnt++;}/* object_cnt++; */ |
||
7614 | schaersvoo | 491 | } |
15111 | schaersvoo | 492 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
493 | dragstuff[8] = 1; |
||
7614 | schaersvoo | 494 | reset(); |
495 | break; |
||
8386 | schaersvoo | 496 | |
11806 | schaersvoo | 497 | case ARROW2: |
7614 | schaersvoo | 498 | /* |
11806 | schaersvoo | 499 | @ arrow2 x1,y1,x2,y2,h,color |
14071 | bpr | 500 | @ draw a double headed arrow/vector from (x1:y1) to (x2:y2)<br />with arrowhead size h in px and in color ''color`` |
501 | @ use command <code>arrowhead int</code> to adjust the arrow head size |
||
502 | @ use command <code>linewidth int</code> to adjust thickness of the arrow |
||
9406 | schaersvoo | 503 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
12107 | schaersvoo | 504 | @%arrow2%size 400,400%xrange -10,10%yrange -10,10%drag xy%arrow2 0,0,4,3,8,blue% |
7614 | schaersvoo | 505 | */ |
11806 | schaersvoo | 506 | for(i=0;i<6;i++){ |
7614 | schaersvoo | 507 | switch(i){ |
508 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
509 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
11806 | schaersvoo | 510 | case 2: double_data[2] = get_real(infile,0);break; /* x */ |
511 | case 3: double_data[3] = get_real(infile,0);break; /* y */ |
||
512 | case 4: arrow_head = (int) get_real(infile,0);break;/* h */ |
||
513 | case 5: stroke_color = get_color(infile,1);/* name or hex color */ |
||
15111 | schaersvoo | 514 | if(use_rotate == TRUE ){rotate(4,angle,rotationcenter,2);} |
515 | if( use_affine == 1 ){ transform(4,2);} |
||
516 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
11806 | schaersvoo | 517 | decimals = find_number_of_digits(precision); |
15111 | schaersvoo | 518 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,10,[%.*f,%.*f],[%.*f,%.*f],[%d,%d],[%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[2],decimals,double_data[1],decimals,double_data[3],arrow_head,arrow_head,arrow_head,arrow_head,line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
519 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
520 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,10,[%.*f,%.*f],[%.*f,%.*f],[%d,%d],[%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[2],decimals,double_data[1],decimals,double_data[3],arrow_head,arrow_head,arrow_head,arrow_head,line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
521 | add_to_buffer(tmp_buffer); |
||
522 | if(onclick != 0){object_cnt++;}/* object_cnt++;*/ |
||
523 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
524 | dragstuff[10] = 1; |
||
11806 | schaersvoo | 525 | reset(); |
526 | break; |
||
527 | } |
||
528 | } |
||
529 | break; |
||
8386 | schaersvoo | 530 | |
11806 | schaersvoo | 531 | case ARROWS2: |
7614 | schaersvoo | 532 | /* |
11806 | schaersvoo | 533 | @ arrows2 color,head (px),x1,y1,x2,y2...x_n,y_n |
14071 | bpr | 534 | @ draw double headed arrows / vectors from (x1:y1) to (x2:y2) ... (x3:y3) to (x4:y4) etc ... in color ''color`` |
535 | @ use command <code>linewidth int</code> to adjust thickness of the arrows |
||
11806 | schaersvoo | 536 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually |
12107 | schaersvoo | 537 | @%arrows2%size 400,400%xrange -10,10%yrange -10,10%onclick%arrows2 red,8,0,0,4,3,1,1,2,4,2,2,-2,4,3,3,-3,-4,0,0,3,-2% |
7614 | schaersvoo | 538 | */ |
539 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
540 | fill_color = stroke_color; |
||
11806 | schaersvoo | 541 | arrow_head = (int) get_real(infile,0);/* h */ |
7614 | schaersvoo | 542 | i=0; |
543 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 544 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
7614 | schaersvoo | 545 | if(i%2 == 0 ){ |
546 | double_data[i] = get_real(infile,0); /* x */ |
||
547 | } |
||
548 | else |
||
549 | { |
||
550 | double_data[i] = get_real(infile,1); /* y */ |
||
551 | } |
||
552 | i++; |
||
553 | } |
||
15111 | schaersvoo | 554 | if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);} |
555 | if( use_affine == 1 ){ transform(i-1,2);} |
||
556 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
557 | |||
8224 | bpr | 558 | decimals = find_number_of_digits(precision); |
11806 | schaersvoo | 559 | for(c = 0 ; c < i-1 ; c = c+4){ |
15111 | schaersvoo | 560 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,10,[%.*f,%.*f],[%.*f,%.*f],[%d,%d],[%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[c],decimals,double_data[c+2],decimals,double_data[c+1],decimals,double_data[c+3],arrow_head,arrow_head,arrow_head,arrow_head,line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
561 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
562 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,10,[%.*f,%.*f],[%.*f,%.*f],[%d,%d],[%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[c],decimals,double_data[c+2],decimals,double_data[c+1],decimals,double_data[c+3],arrow_head,arrow_head,arrow_head,arrow_head,line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
563 | add_to_buffer(tmp_buffer); |
||
564 | if(onclick != 0){object_cnt++;}/* object_cnt++; */ |
||
7614 | schaersvoo | 565 | } |
15111 | schaersvoo | 566 | dragstuff[10] = 1; |
567 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
7614 | schaersvoo | 568 | reset(); |
569 | break; |
||
11806 | schaersvoo | 570 | case ARROWHEAD: |
9427 | schaersvoo | 571 | /* |
11806 | schaersvoo | 572 | @ arrowhead int |
573 | @ default 8 (pixels) |
||
9427 | schaersvoo | 574 | */ |
11806 | schaersvoo | 575 | arrow_head = (int) (get_real(infile,1)); |
576 | break; |
||
577 | |||
578 | case AUDIO: |
||
579 | /* |
||
580 | @ audio x,y,w,h,loop,visible,audiofile location |
||
14066 | bpr | 581 | @ x,y: left top corner of audio element (in xrange / yrange) |
582 | @ w,y: width and height in pixels |
||
583 | @ loop: 0 or 1 ( 1 = loop audio fragment) |
||
584 | @ visible: 0 or 1 (1 = show controls) |
||
11806 | schaersvoo | 585 | @ audio format may be in *.mp3 or *.ogg |
14066 | bpr | 586 | @ If you are using *.mp3: be aware that FireFox will not (never) play this ! (Pattented format) |
587 | @ if you are using *.ogg: be aware that Microsoft based systems not support it natively |
||
11806 | schaersvoo | 588 | @ To avoid problems supply both types (mp3 and ogg) of audiofiles.<br />the program will use both as source tag |
589 | */ |
||
15111 | schaersvoo | 590 | js_function[DRAW_AUDIO] = 1; |
11806 | schaersvoo | 591 | for(i=0;i<7;i++){ |
592 | switch(i){ |
||
593 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */ |
||
594 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system -> pixel */ |
||
595 | case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */ |
||
596 | case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */ |
||
597 | case 4: int_data[4] = (int) (get_real(infile,0)); if(int_data[4] != TRUE){int_data[4] = FALSE;} break; /* loop boolean */ |
||
598 | case 5: int_data[5] = (int) (get_real(infile,0)); if(int_data[5] != TRUE){int_data[5] = FALSE;} break; /* visible boolean */ |
||
599 | case 6: |
||
600 | temp = get_string(infile,1); |
||
601 | if( strstr(temp,".mp3") != 0 ){ temp = str_replace(temp,".mp3","");} |
||
602 | if( strstr(temp,".ogg") != 0 ){ temp = str_replace(temp,".ogg","");} |
||
14208 | schaersvoo | 603 | string_length = 1 + snprintf(NULL,0, "draw_audio(%d,%d,%d,%d,%d,%d,%d,\"%s.ogg\",\"%s.mp3\");\n",canvas_root_id,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],temp,temp); |
604 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11806 | schaersvoo | 605 | snprintf(tmp_buffer,string_length,"draw_audio(%d,%d,%d,%d,%d,%d,%d,\"%s.ogg\",\"%s.mp3\");\n",canvas_root_id,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],temp,temp); |
606 | add_to_buffer(tmp_buffer); |
||
607 | break; |
||
608 | default:break; |
||
9427 | schaersvoo | 609 | } |
11806 | schaersvoo | 610 | } |
611 | reset(); |
||
612 | break; |
||
613 | |||
614 | |||
615 | case AXIS_NUMBERING: |
||
616 | /* |
||
617 | @ axisnumbering |
||
618 | @ keyword (no arguments required) |
||
14246 | bpr | 619 | @ for special numbering of x-axis or y-axis see grid related commands <a href="#axis">axis</a> <a href="#xaxis">xaxis</a>, <a href="#xaxisup">xaxisup</a>, <a href="#noxaxis">noxaxis</a>, <a href="#yaxis">yaxis</a>, <a href="#yaxisup">yaxisup</a>, <a href="#noyaxis">noyaxis</a> |
11806 | schaersvoo | 620 | @ to be used before command grid (see <a href="#grid">command grid</a>) |
621 | */ |
||
11891 | schaersvoo | 622 | use_axis_numbering++; |
11806 | schaersvoo | 623 | break; |
624 | case AXIS: |
||
625 | /* |
||
626 | @ axis |
||
627 | @ keyword (no arguments required) |
||
628 | @ to be used before command grid (see <a href="#grid">command grid</a>) |
||
629 | |||
630 | */ |
||
631 | use_axis = TRUE; |
||
632 | break; |
||
633 | |||
634 | case BARCHART: |
||
635 | /* |
||
636 | @ barchart x_1:y_1:color_1:x_2:y_2:color_2:...x_n:y_n:color_n |
||
14066 | bpr | 637 | @ may <b>only</b> to be used together with command <a href='#grid'>grid</a> |
638 | @ can be used together with freestyle x-axis/y-axis texts: see commands <a href='#xaxis'>xaxis</a>,<a href='#xaxisup'>xaxisup</a> and <a href='#yaxis'>yaxis</a> |
||
639 | @ use command <a href='#legend'>legend</a> to provide an optional legend in right-top-corner |
||
11806 | schaersvoo | 640 | @ multiple barchart command may be used in a single script |
14066 | bpr | 641 | @ also see command <a href='#piechart'>piechart</a> |
642 | @ note: your arguments are not checked by canvasdraw: use your javascript console in case of trouble... |
||
15313 | schaersvoo | 643 | @%barchart%size 400,400%xrange -1,10%yrange -2,14%legend legend Z:legend A:this is B:C:D:E:F:G:H:X%legendcolors green:red:orange:lightblue:cyan:gold:purple:darkred:yellow:lightgreen%xaxis 0:Z:1:A:2:B:3:C:4:D:5:E:6:F:7:G:8:H:9:X%noyaxis%precision 1%fontfamily bold 15px Arial%grid 1,1,white%barchart 0:5.5:green:2:5.5:red:4:6.5:orange:6:8:lightblue:8:11:cyan:1:5.5:gold:3:9:purple:5:4:darkred:7:7:yellow:9:1:lightgreen%mouse red,14 |
11806 | schaersvoo | 644 | */ |
645 | temp = get_string(infile,1); |
||
646 | if( strstr( temp,":" ) != 0 ){ temp = str_replace(temp,":","\",\""); } |
||
647 | fprintf(js_include_file,"var barchart_%d = [\"%s\"];",barchart_cnt,temp); |
||
648 | barchart_cnt++; |
||
649 | reset(); |
||
650 | break; |
||
651 | |||
652 | case BEZIER: |
||
653 | /* |
||
654 | @ bezier color,x_start,y_start,x_first,y_first,x_second,y_second,x_end,y_end |
||
655 | @ draw a bezier curve between points, starting from (x_start:y_start) |
||
656 | @ can <b>not</b> be dragged or set onclick |
||
657 | */ |
||
15111 | schaersvoo | 658 | js_function[DRAW_BEZIER] = 1; |
11806 | schaersvoo | 659 | decimals = find_number_of_digits(precision); |
660 | for(i = 0 ; i < 9; i++){ |
||
661 | switch(i){ |
||
662 | case 0: stroke_color = get_color(infile,0);break; |
||
663 | case 1: double_data[0] = get_real(infile,0);break;/* start x */ |
||
664 | case 2: double_data[1] = get_real(infile,0);break;/* start y */ |
||
665 | case 3: double_data[2] = get_real(infile,0);break;/*The x-coordinate of the first Bézier control point */ |
||
666 | case 4: double_data[3] = get_real(infile,0);break;/*The y-coordinate of the first Bézier control point */ |
||
667 | case 5: double_data[4] = get_real(infile,0);break;/*The x-coordinate of the second Bézier control point */ |
||
668 | case 6: double_data[5] = get_real(infile,0);break;/*The y-coordinate of the second Bézier control point */ |
||
669 | case 7: double_data[6] = get_real(infile,0);break;/*The x-coordinate of the Bézier end point */ |
||
670 | case 8: double_data[7] = get_real(infile,1);/*The y-coordinate of the Bézier end point */ |
||
15111 | schaersvoo | 671 | if(use_rotate == TRUE ){rotate(8,angle,rotationcenter,2);} |
672 | if(use_affine == TRUE ){ transform(2,5);} |
||
673 | string_length = 1 + snprintf(NULL,0,"draw_bezier(%d,%d,[%f,%f,%f,%f,%f,%f,%f,%f],\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.2f);",STATIC_CANVAS,line_width,double_data[0],double_data[1],double_data[2],double_data[3],double_data[4],double_data[5],double_data[6],double_data[7],fill_color,fill_opacity,stroke_color,stroke_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle); |
||
14208 | schaersvoo | 674 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
15111 | schaersvoo | 675 | snprintf(tmp_buffer,string_length,"draw_bezier(%d,%d,[%f,%f,%f,%f,%f,%f,%f,%f],\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.2f);",STATIC_CANVAS,line_width,double_data[0],double_data[1],double_data[2],double_data[3],double_data[4],double_data[5],double_data[6],double_data[7],fill_color,fill_opacity,stroke_color,stroke_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle); |
11806 | schaersvoo | 676 | add_to_buffer(tmp_buffer); |
677 | break; |
||
678 | default: break; |
||
9427 | schaersvoo | 679 | } |
680 | } |
||
681 | reset(); |
||
682 | break; |
||
11806 | schaersvoo | 683 | |
684 | |||
685 | case BGCOLOR: |
||
9427 | schaersvoo | 686 | /* |
11806 | schaersvoo | 687 | @ bgcolor colorname or #hex |
688 | @ use this color as background of the "div" containing the canvas(es) |
||
12110 | schaersvoo | 689 | @%bgcolor%size 400,400%xrange -10,10%yrange -10,10%bgcolor lightblue |
9427 | schaersvoo | 690 | */ |
11806 | schaersvoo | 691 | /* [255,255,255]*/ |
692 | bgcolor = get_string(infile,1); |
||
693 | if(strstr(bgcolor,"#") == NULL){ /* convert colorname -> #ff00ff */ |
||
694 | int found = 0; |
||
695 | for( i = 0; i < NUMBER_OF_COLORNAMES ; i++ ){ |
||
696 | if( strcmp( colors[i].name , bgcolor ) == 0 ){ |
||
697 | bgcolor = colors[i].hex; |
||
698 | found = 1; |
||
699 | break; |
||
700 | } |
||
9427 | schaersvoo | 701 | } |
14066 | bpr | 702 | if(found == 0){canvas_error("your bgcolor is not in my rgb.txt data list: use hexcolor...something like #a0ffc4");} |
11806 | schaersvoo | 703 | } |
13970 | obado | 704 | fprintf(js_include_file,"/* set background color of canvas div */\ncanvas_div.style.backgroundColor = \"%s\";canvas_div.style.opacity = %f;\n",bgcolor,fill_opacity); |
11806 | schaersvoo | 705 | break; |
706 | |||
707 | case BGIMAGE: |
||
708 | /* |
||
709 | @ bgimage image_location |
||
14071 | bpr | 710 | @ use an image as background; technical: we use the background of ''canvas_div`` |
11806 | schaersvoo | 711 | @ the background image will be resized to match "width = xsize" and "height = ysize" |
12110 | schaersvoo | 712 | @%bgimage%size 400,400%xrange -10,10%yrange -10,10%bgimage https://wims.unice.fr/wims/gifs/en.gif |
11806 | schaersvoo | 713 | */ |
714 | URL = get_string(infile,1); |
||
13970 | obado | 715 | fprintf(js_include_file,"/* set background image to canvas div */\ncanvas_div.style.backgroundImage = \"url(%s)\";canvas_div.style.backgroundSize = \"%dpx %dpx\";\n",URL,xsize,ysize); |
11806 | schaersvoo | 716 | break; |
717 | |||
718 | case BLINK: |
||
719 | /* |
||
720 | @ blink time(seconds) |
||
721 | @ NOT IMPLEMETED -YET |
||
722 | */ |
||
723 | break; |
||
724 | |||
725 | case BOXPLOT: |
||
726 | /* |
||
727 | @ boxplot x_or_y,box-height_or_box-width,position,min,Q1,median,Q3,max |
||
14066 | bpr | 728 | @ example:<br /><code>xrange 0,300<br />yrange 0,10<br />boxplot x,4,8,120,160,170,220,245</code><br />meaning: create a boxplot in x-direction, with height 4 (in yrange) and centered around line y=8 |
729 | @ example:<br /><code>xrange 0,10<br />yrange 0,300<br />boxplot y,4,8,120,160,170,220,245</code><br />meaning: create a boxplot in y-direction, with width 4 (in xrange) and centered around line x=8 |
||
730 | @ use command <a href='#filled'>filled</a> to fill the box<br /><b>note:</b> the strokecolor is used for filling Q1, the fillcolor is used for filling Q3 |
||
731 | @ use command <a href='#fillpattern'>fillpattern some_pattern</a> to use a (diamond for Q1, hatch for Q3) pattern. |
||
732 | @ use command <a href='#opacity'>opacity</a> to adjust fill_opacity of stroke and fill colours |
||
14379 | bpr | 733 | @ use command <a href='#legend'>legend</a> to automatically create a legend <br />unicode allowed in legend<br />use command <a href='#fontfamily'>fontfamily</a> to set the font of the legend. |
11806 | schaersvoo | 734 | @ there is no limit to the number of boxplots used. |
14078 | bpr | 735 | @ can <b>not</b> be set draggable and <a href='#onclick'>onclick</a> is not ready yet |
14066 | bpr | 736 | @ use keyword <a href="#userboxplot">userboxplot</a> before command boxplot, if a pupil must draw a boxplot (using his own min,Q1,median,Q3,max data) |
737 | @ use keyword <a href="#userboxplotdata">userboxplotdata</a> before command boxplot, if a pupil must generate the data by some means. |
||
738 | @ use command <a href="#boxplotdata">boxplotdata</a> when the boxplot should be drawn from wims-generated raw statistical date |
||
12110 | schaersvoo | 739 | @%boxplot_1%size 400,400%xrange 0,300%yrange 0,10%opacity 120,50%filled%fillcolor orange%strokecolor blue%linewidth 2%boxplot x,4,8,120,160,170,220,245 |
740 | @%boxplot_2%size 400,400%xrange 0,10%yrange 0,300%opacity 120,50%filled%fillcolor orange%strokecolor blue%linewidth 2%boxplot y,4,8,120,160,170,220,245 |
||
13958 | schaersvoo | 741 | @%boxplot_3%size 400,400%xrange 0,100%yrange 0,10%fillpattern hatch%linewidth 3%fillcolor red%strokecolor green%boxplot x,1,2,4,14,27,39,66%strokecolor blue%boxplot x,1,4,15,45,50,66,87%strokecolor red%boxplot x,1,6,45,70,80,90,100%strokecolor orange%boxplot x,1,8,28,38,48,56,77%mouse red,16 |
11806 | schaersvoo | 742 | */ |
15111 | schaersvoo | 743 | js_function[DRAW_BOXPLOT] = 1; |
11806 | schaersvoo | 744 | for(i=0;i<8;i++){ |
745 | switch(i){ |
||
746 | case 0: temp = get_string_argument(infile,0); |
||
747 | if( strstr(temp,"x") != 0){int_data[0] = 1;}else{int_data[0] = 0;} break; /* x or y */ |
||
748 | case 1: double_data[0] = get_real(infile,0);break;/* height | width */ |
||
749 | case 2: |
||
750 | if( js_function[DRAW_JSBOXPLOT] == 0 ){ |
||
751 | double_data[1] = get_real(infile,0); |
||
752 | fprintf(js_include_file,"var boxplot_source = 0;\n");/* we use given min,Q1,median,Q3,max */ |
||
753 | } |
||
754 | else |
||
755 | { |
||
756 | double_data[1] = get_real(infile,1); |
||
757 | double_data[2] = 1; |
||
758 | double_data[3] = 1; |
||
759 | double_data[4] = 1; |
||
760 | double_data[5] = 1; |
||
761 | double_data[6] = 1; |
||
762 | double_data[7] = 1; |
||
763 | i=8; |
||
764 | } |
||
765 | break;/* center value x or y */ |
||
766 | case 3: double_data[2] = get_real(infile,0); break;/* min */ |
||
767 | case 4: double_data[3] = get_real(infile,0); break;/* Q1 */ |
||
768 | case 5: double_data[4] = get_real(infile,0); break;/* median */ |
||
769 | case 6: double_data[5] = get_real(infile,0); break;/* Q3 */ |
||
770 | case 7: double_data[6] = get_real(infile,1); break;/* max */ |
||
771 | default:break; |
||
9427 | schaersvoo | 772 | } |
773 | } |
||
774 | decimals = find_number_of_digits(precision); |
||
11806 | schaersvoo | 775 | /*function draw_boxplot(canvas_type,xy,hw,cxy,data,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype0,dashtype1)*/ |
14208 | schaersvoo | 776 | string_length = 1 + snprintf(NULL,0, "draw_boxplot(%d,%d,%.*f,%.*f,[%.*f,%.*f,%.*f,%.*f,%.*f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d);\n",BOXPLOT_CANVAS+boxplot_cnt,int_data[0],decimals,double_data[0],decimals,double_data[1],decimals,double_data[2],decimals,double_data[3],decimals,double_data[4],decimals,double_data[5],decimals,double_data[6],line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1]); |
11806 | schaersvoo | 777 | check_string_length(string_length); |
14208 | schaersvoo | 778 | tmp_buffer = my_newmem(string_length); |
11806 | schaersvoo | 779 | snprintf(tmp_buffer,string_length, "draw_boxplot(%d,%d,%.*f,%.*f,[%.*f,%.*f,%.*f,%.*f,%.*f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d);\n",BOXPLOT_CANVAS+boxplot_cnt,int_data[0],decimals,double_data[0],decimals,double_data[1],decimals,double_data[2],decimals,double_data[3],decimals,double_data[4],decimals,double_data[5],decimals,double_data[6],line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1]); |
780 | add_to_buffer(tmp_buffer); |
||
781 | boxplot_cnt++; |
||
782 | reset(); |
||
783 | break; |
||
784 | case BOXPLOTDATA: |
||
785 | /* |
||
786 | @ boxplotdata some_data |
||
15111 | schaersvoo | 787 | @ 'some_data' are a list of numbers separated by a comma "," (items) |
14071 | bpr | 788 | @ only be used before command <code>boxplot</code>: the command <a href="#boxplot">boxplot</a> will provide the boxplot drawing of the data. |
11806 | schaersvoo | 789 | @ xrange 0,100<br />yrange 0,10<br />boxplotdata 11,22,13,15,23,43,12,12,14,2,45,32,44,13,21,24,13,19,35,21,24,23<br />boxplot x,4,5 |
790 | @ note: wims will not check your data input | format. use js-error console to debug any problems. |
||
14071 | bpr | 791 | @ a javascript function <code>statistics()</code> will parse the data and calculate the values [min,Q1,median,Q3,max] and hand them to the boxplot draw function. |
792 | @ only a single call to <code>boxplotdata</code> can be made. If multiple boxplots should be present in a single canvas, then use multiple calls to command <a href='#boxplot'>boxplot</a> |
||
13959 | bpr | 793 | @%boxplotdata%size 400,400%xrange 0,100%yrange 0,10%strokecolor orange%fillpattern hatch%linewidth 3%strokecolor green%boxplotdata 11,22,13,15,23,43,12,12,14,2,45,32,44,13,21,24,13,19,35,21,24,23%boxplot x,2,2%mouse red,16 |
11806 | schaersvoo | 794 | */ |
15111 | schaersvoo | 795 | js_function[DRAW_JSBOXPLOT] = 1; |
796 | js_function[DRAW_BOXPLOT] = 1; |
||
11806 | schaersvoo | 797 | fprintf(js_include_file,"var boxplot_source = 1;var jsboxplot_data = [%s];\n",get_string(infile,1)); |
798 | |||
799 | break; |
||
800 | |||
801 | case CANVASTYPE: |
||
802 | canvas_type = (int) (get_real(infile,1)); |
||
803 | /* |
||
804 | @ canvastype TYPE |
||
14246 | bpr | 805 | @ for now only useful before commands filltoborder / floodfill / clickfill etc operations<br />Only the images of this TYPE will be scanned and filled |
11806 | schaersvoo | 806 | @ default value of TYPE is DRAG_CANVAS e.g. 5 (all clickable / draggable object are in this canvas) |
807 | @ use another TYPE, if you know what you are doing... |
||
15309 | schaersvoo | 808 | @ other possible canvasses (e.g. transparent PNG pictures, xsize × ysize on top of each other)<ul><li> EXTERNAL_IMAGE_CANVAS 0</li><li> BG_CANVAS 1</li><li> STATIC_CANVAS 2</li><li> MOUSE_CANVAS 3</li><li> GRID_CANVAS 4</li><li> DRAG_CANVAS 5</li><li> DRAW_CANVAS 6</li><li> TEXT_CANVAS 7</li><li> CLOCK_CANVAS 8</li><li> ANIMATE_CANVAS 9</li><li> TRACE_CANVAS 10</li><li>BOXPLOT_CANVAS 11</li><li> JSPLOT_CANVAS 100, will increase with every call</li><li> FILL_CANVAS 200, will increase with every call</li><li> USERDRAW_JSPLOT 300, will increase with every call</li><li>CLICKFILL_CANVAS 400, will increase with every call/click</li><li>BOXPLOT_CANVAS 500, will increase with every call</li></ul> |
11806 | schaersvoo | 809 | */ |
810 | break; |
||
811 | |||
15111 | schaersvoo | 812 | case CENTERED: |
813 | use_offset = 4; |
||
814 | /* |
||
815 | @ centered |
||
816 | @ keyword ; to place the text centered (in width and height) on the text coordinates(x:y) |
||
817 | @ may be used for text exactly centered on its (x;y) |
||
818 | @ use <a href="#fontfamily">fontfamily</a> for setting the font |
||
819 | @ may be active for commands <a href="#text">text</a> and <a href="#string">string</a> (e.g. objects in the ''drag/drop/onclick-library``) |
||
15313 | schaersvoo | 820 | @%centered%size 400,400%xrange -10,10%yrange -10,10%fontfamily 12pt Arial%string blue,-9,-9,no offset%point -9,-9,red%centered%string blue,-6,-6,centered%point -6,-6,red%xoffset%string blue,-3,-3,xoffset%point -3,-3,red%yoffset%string blue,0,0,yoffset%point 0,0,red%xyoffset%string blue,3,3,xyoffset%point 3,3,red%resetoffset%string blue,6,6,resetoffset%point 6,6,red |
15111 | schaersvoo | 821 | */ |
822 | break; |
||
823 | |||
11806 | schaersvoo | 824 | case CENTERSTRING: |
825 | /* |
||
826 | @ centerstring color,y-value,the text string |
||
827 | @ title color,y-value,the text string |
||
828 | @ draw a string centered on the canvas at y = y-value |
||
14071 | bpr | 829 | @ can not be set ''onclick`` or ''drag xy`` (...) |
14162 | bpr | 830 | @ unicode supported: <code>centerstring red,5,\\u2232</code> |
15313 | schaersvoo | 831 | @ use a command like <code>fontfamily italic 24pt Arial</code> to set fonts on browser that support font change |
12110 | schaersvoo | 832 | @%centerstring%size 400,400%xrange -10,10%yrange -10,10%bgcolor lightblue%fontfamily italic 22pt Courier%centerstring blue,7,the center |
11806 | schaersvoo | 833 | */ |
15111 | schaersvoo | 834 | js_function[DRAW_CENTERSTRING] = 1; |
11806 | schaersvoo | 835 | for(i=0;i<3;i++){ |
836 | switch(i){ |
||
837 | case 0: stroke_color = get_color(infile,0);break;/* name or hex color */ |
||
838 | case 1: double_data[0] = get_real(infile,0);break; /* y in xrange*/ |
||
839 | case 2: temp = get_string_argument(infile,1); |
||
840 | /* draw_text = function(canvas_type,y,font_family,stroke_color,stroke_opacity,text) */ |
||
841 | decimals = find_number_of_digits(precision); |
||
15111 | schaersvoo | 842 | string_length = 1 + snprintf(NULL,0,"draw_centerstring(%d,%.*f,\"%s\",\"%s\",%.2f,\"%s\");\n",canvas_root_id,decimals,double_data[0],font_family,stroke_color,stroke_opacity,temp); |
14208 | schaersvoo | 843 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
11806 | schaersvoo | 844 | snprintf(tmp_buffer,string_length,"draw_centerstring(%d,%.*f,\"%s\",\"%s\",%.2f,\"%s\");\n",canvas_root_id,decimals,double_data[0],font_family,stroke_color,stroke_opacity,temp); |
845 | add_to_buffer(tmp_buffer); |
||
846 | break; |
||
847 | default:break; |
||
848 | } |
||
9427 | schaersvoo | 849 | } |
850 | break; |
||
15111 | schaersvoo | 851 | case CHEMTEX: |
852 | /* |
||
15116 | bpr | 853 | chemtex |
854 | keyword...needs to be the first command in the script (even before the ''size`` command) |
||
855 | only for KaTeX enabled typesetting ! |
||
856 | will include 80kB large js-library for chemisty typesetting |
||
857 | using <a href="http://85.148.206.56/wims/download/katex.for.wims.tar.gz">KaTeX</a> : <code>katex x,y,\\ce{ chemistry tex code} like : \\ce{ Hg^2+ ->[I-] HgI2 ->[I-] [Hg^{II}I4]^2- }</code> |
||
858 | using MathJaX : <code>latex x,y,\\ce{ chemistry tex code} like : \\ce{ Hg^2+ ->[I-] HgI2 ->[I-] [Hg^{II}I4]^2- }</code> |
||
859 | see https://mhchem.github.io/MathJax-mhchem/ |
||
15313 | schaersvoo | 860 | %chemtex_katex_mathjax%chemtex%size 400,400%xrange -10,10%yrange -10,10%snaptogrid%fontfamily 22px Arial%strokecolor red%drag xy%centered%latex 0,8,\\ce{Hg^2+}%drag xy%centered%latex 0,4,\\ce{\\xrightarrow{\\text{I}^{-}}}%drag xy%centered%latex 0,0,\\ce{HgI2}%centered%drag xy%latex 0,-4,\\ce{\\xrightarrow{\\text{I}^{-}}}%drag xy%centered%latex 0,-8,\\ce{[Hg^{II}I4]^2-} |
15111 | schaersvoo | 861 | */ |
862 | found_size_command = 1; |
||
863 | fprintf(stdout,"\n<script src=\"scripts/js/KaTeX/mhchem.js\" defer></script>\n"); |
||
864 | break; |
||
8386 | schaersvoo | 865 | |
866 | case CIRCLE: |
||
8299 | schaersvoo | 867 | /* |
8386 | schaersvoo | 868 | @ circle xc,yc,width (2*r in pixels),color |
15111 | schaersvoo | 869 | @ use command <code>fcircle xc,yc,d,color</code> |
15715 | schaersvoo | 870 | @ alternative: disk |
15111 | schaersvoo | 871 | @ use command <code>fillcolor color</code> to set the fillcolor |
14071 | bpr | 872 | @ may be set <a href='#drag'>draggable</a> / <a href='#onclick'>onclick</a> |
15111 | schaersvoo | 873 | @ will shrink / expand on zoom out / zoom in |
12110 | schaersvoo | 874 | @%circle%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor lightblue%opacity 255,50%drag xy%circle 0,0,60,red%zoom red |
8299 | schaersvoo | 875 | */ |
8386 | schaersvoo | 876 | for(i=0;i<4;i++){ |
877 | switch(i){ |
||
878 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
879 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
14066 | bpr | 880 | case 2: double_data[2] = px2x((get_real(infile,0))/2) - px2x(0);break; /* for zoom in/out: radius in 'dx' xrange*/ |
8386 | schaersvoo | 881 | case 3: stroke_color = get_color(infile,1);/* name or hex color */ |
15111 | schaersvoo | 882 | if(use_rotate == TRUE ){rotate(2,angle,rotationcenter,2);} |
883 | if(use_affine == TRUE ){ transform(2,2);} |
||
884 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
8386 | schaersvoo | 885 | decimals = find_number_of_digits(precision); |
15111 | schaersvoo | 886 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,13,[%.*f],[%.*f],[%.3f],[%.3f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[1],double_data[2],double_data[2],line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
887 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
888 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,13,[%.*f],[%.*f],[%.3f],[%.3f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[1],double_data[2],double_data[2],line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
889 | add_to_buffer(tmp_buffer); |
||
890 | if(onclick != 0){object_cnt++;}/* object_cnt++;*/ |
||
891 | dragstuff[13] = 1; |
||
892 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
8386 | schaersvoo | 893 | reset(); |
894 | break; |
||
895 | default : break; |
||
896 | } |
||
897 | } |
||
898 | break; |
||
899 | |||
900 | case CIRCLES: |
||
901 | /* |
||
902 | @ circles color,xc1,yc1,r1,xc2,yc2,r2...xc_n,yc_n,r_n |
||
9383 | schaersvoo | 903 | @ <b>attention</b> r = radius in x-range (!) |
14071 | bpr | 904 | @ use keyword <code>filled</code> or command <code>fcircles</code> to produce solid circles |
15715 | schaersvoo | 905 | @ alternative: disks |
14071 | bpr | 906 | @ use command <code>fillcolor color</code> to set the fillcolor |
907 | @ may be set <a href='#drag'>draggable</a> / <a href='#onclick'>onclick</a> (individually) |
||
8386 | schaersvoo | 908 | @ will shrink / expand on zoom out / zoom in |
14208 | schaersvoo | 909 | @%circles_drag%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor lightblue%opacity 255,50%drag xy%circles blue,0,0,2,2,2,3,-3,-3,3,3,3,4,3,-4,2%zoom red |
910 | @%circles_onclick%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor lightblue%opacity 255,50%onclick%circles blue,0,0,2,2,2,3,-3,-3,3,3,3,4,3,-4,2%zoom red |
||
911 | @%circles_drag_slider%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%drag xy%# Click circles(s) to activate%opacity 200,50%fillcolor orange%rotationcenter 2,3%slider 0,2*pi,300,30,angle degrees,Rotate%slider -5,5*pi,300,30,x display,move in x-direction%slider -10,10*pi,300,30,y display,move in y-direction%fcircles blue,0,0,0.5,2,2,1,-3,-3,1.5,3,3,0.5,3,-4,0.5 |
||
8386 | schaersvoo | 912 | */ |
8299 | schaersvoo | 913 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
914 | fill_color = stroke_color; |
||
8386 | schaersvoo | 915 | i=1; |
8299 | schaersvoo | 916 | while( ! done ){ /* get next item until EOL*/ |
11997 | schaersvoo | 917 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
8386 | schaersvoo | 918 | switch (i%3){ |
919 | case 1:double_data[i-1] = get_real(infile,0);break; /* x */ |
||
920 | case 2:double_data[i-1] = get_real(infile,0);break; /* y */ |
||
921 | case 0:double_data[i-1] = get_real(infile,1);break; /* r */ |
||
8299 | schaersvoo | 922 | } |
923 | i++; |
||
924 | } |
||
15111 | schaersvoo | 925 | if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,3);} |
926 | if(use_affine == TRUE ){ transform(i-1,3);} |
||
927 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
928 | |||
8299 | schaersvoo | 929 | decimals = find_number_of_digits(precision); |
8386 | schaersvoo | 930 | for(c = 0 ; c < i-1 ; c = c+3){ |
15111 | schaersvoo | 931 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,13,[%.*f],[%.*f],[%.3f],[%.3f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[c],decimals,double_data[c+1],double_data[c+2],double_data[c+2],line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
932 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
933 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,13,[%.*f],[%.*f],[%.3f],[%.3f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[c],decimals,double_data[c+1],double_data[c+2],double_data[c+2],line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
934 | add_to_buffer(tmp_buffer); |
||
935 | if(onclick != 0){object_cnt++;}/* object_cnt++; */ |
||
8299 | schaersvoo | 936 | } |
937 | reset(); |
||
15111 | schaersvoo | 938 | dragstuff[13] = 1; |
939 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
8299 | schaersvoo | 940 | break; |
11806 | schaersvoo | 941 | case CLEARBUTTON: |
942 | /* |
||
943 | @ clearbutton value |
||
15715 | schaersvoo | 944 | @ alternative: delete |
945 | @ alternative: erase |
||
15111 | schaersvoo | 946 | @ adds a button to clear the <a href="#userdraw">userdraw</a> canvas with text ''value`` |
947 | @ <b>attention</b> command <code>clearbutton</code> is incompatible with <a href="#multidraw">multidraw</a> based drawings<br/>(in <code>multidraw</code> there is always a remove_object_button for every draw primitive) |
||
948 | @ normally <a href="#userdraw">userdraw</a> primitives have the option to use middle/right mouse button on<br /> a point of the object to remove this specific object...this clear button will remove all drawings |
||
14071 | bpr | 949 | @ uses the tooltip placeholder div element: may not be used with command <code>intooltip</code> |
15111 | schaersvoo | 950 | @ use command <a href="#css">css</a> to style the button... |
951 | @ the clearbutton will have id="canvas_scripts[%d]" ; starting with %d=0 for the first script<br />to change the style of all ''clearbutton`` of all included canvasdraw scripts, use something like<br /><code>if(document.getElementById("clearbutton"+canvas_scripts[0])){<br /> var p = 0;<br /> while(document.getElementById("clearbutton"+canvas_scripts[p])){<br /> document.getElementById("clearbutton"+canvas_scripts[p]).className="some_class_name";<br /> <!−−</code> or <code>document.getElementById("clearbutton"+canvas_scripts[p]).setAttribute("style","some_style"); −−><br /> p++;<br /> };<br />};</code> |
||
13935 | bpr | 952 | @%clearbutton%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor lightblue%opacity 255,50%userdraw circles,red%clearbutton Remove All |
11806 | schaersvoo | 953 | */ |
954 | if(reply_format == 29){/* eg multidraw is selected */ |
||
14054 | schaersvoo | 955 | // canvas_error("command clearbutton incompatible with multidraw...only suitable for userdraw"); |
11806 | schaersvoo | 956 | } |
15111 | schaersvoo | 957 | add_clear_button(css_class,get_string(infile,1)); |
11806 | schaersvoo | 958 | break; |
8386 | schaersvoo | 959 | |
11806 | schaersvoo | 960 | case CLOCK: |
7614 | schaersvoo | 961 | /* |
11806 | schaersvoo | 962 | @ clock x,y,r(px),H,M,S,type hourglass,interactive [ ,H_color,M_color,S_color,background_color,foreground_color ] |
14071 | bpr | 963 | @ use command <code>opacity stroke-opacity,fill-opacity</code> to adjust foreground (stroke) and background (fill) transparency |
14066 | bpr | 964 | @ type hourglass:<br />type = 0: only segments<br />type = 1: only numbers<br />type = 2: numbers and segments |
11806 | schaersvoo | 965 | @ colors are optional: if not defined, default values will be used<br />default colours: clock 0,0,60,4,35,45,1,2<br />custom colours: clock 0,0,60,4,35,45,1,2,,,,yellow,red<br />custom colours: clock 0,0,60,4,35,45,1,2,white,green,blue,black,yellow |
966 | @ if you don't want a seconds hand (or minutes...), just make it invisible by using the background color of the hourglass... |
||
14162 | bpr | 967 | @ interactive <ul><li>0: not interactive, just clock(s)</li><li>1: function read_canvas() will read all active clocks in H:M:S format<br />The active clock(s) can be adjusted by pupils</li><li>2: function read_canvas() will return the clicked clock <br />(like multiplechoice; first clock in script in nr. 0 )</li><li>3: no prefab buttons...create your own buttons (or other means) to make the clock(s) adjustable by javascript function set_clock(num,type,diff)<br />wherein: num = clock id (starts with 0) ; type = 1 (hours) ; type = 2 (minutes) ; type = 3 (seconds) <br />and diff = the increment of 'type' (positive or negative)</li></ul> |
11806 | schaersvoo | 968 | @ canvasdraw will not check validity of colornames...the javascript console is your best friend |
969 | @ no combinations with other reply_types allowed, for now |
||
14077 | bpr | 970 | @ if interactive is set to ''1``, 6 buttons per clock will be displayed for adjusting a clock (H+ M+ S+ H- M- S-)<br /> set_clock(clock_id,type,incr) <br />first clock has clock_id=0 ; type: H=1,M=2,S=3 ; incr: increment integer |
971 | @ note: if you need multiple -interactive- clocks on a webpage, use multiple ''clock`` commands in a single script !<br />and <i>not multiple canvas scripts</i> in a single page |
||
14066 | bpr | 972 | @ note: clocks will not zoom or pan, when using command <a href='#zoom'>zoom</a> |
12110 | schaersvoo | 973 | @%clock_1%size 400,400%xrange -10,10%yrange -10,10%clock 0,0,120,4,35,45,0,0,red,green,blue,lightgrey,black |
974 | @%clock_2%size 400,400%xrange -10,10%yrange -10,10%clock 0,0,120,4,35,45,1,1,red,green,blue,lightgrey,black |
||
975 | @%clock_3%size 400,400%xrange -10,10%yrange -10,10%clock -5,0,80,4,35,45,2,2,red,green,blue,lightgrey,black%clock 5,0,80,3,15,65,2,2,red,green,blue,lightgrey,black |
||
976 | @%clock_4%size 400,400%xrange -10,10%yrange -10,10%clock 0,0,120,4,35,45,0,0,red,green,blue,lightgrey,black |
||
977 | @%clock_5%size 400,400%xrange -10,10%yrange -10,10%clock 0,0,120,4,35,45,1,1,red,green,blue,lightgrey,black |
||
978 | @%clock_6%size 400,400%xrange -10,10%yrange -10,10%clock -5,0,80,4,35,45,2,2,red,green,blue,lightgrey,black%clock 5,0,80,8,55,15,2,2,red,green,blue,lightgrey,black |
||
979 | @%clock_7%size 400,400%xrange -10,10%yrange -10,10%clock 0,0,120,4,35,45,2,0,red,green,blue,lightgrey,black |
||
7614 | schaersvoo | 980 | */ |
15111 | schaersvoo | 981 | js_function[DRAW_CLOCK] = 1; |
982 | js_function[INTERACTIVE] = 1; |
||
11806 | schaersvoo | 983 | |
984 | /* var clock = function(xc,yc,radius,H,M,S,h_color,m_color,s_color,bg_color,fg_color) */ |
||
985 | for(i=0;i<9;i++){ |
||
986 | switch(i){ |
||
987 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* xc */ |
||
988 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* yc */ |
||
989 | case 2: int_data[2] = get_real(infile,0);break;/* radius in px */ |
||
990 | case 3: int_data[3] = get_real(infile,0);break;/* hours */ |
||
991 | case 4: int_data[4] = get_real(infile,0);break;/* minutes */ |
||
992 | case 5: int_data[5] = get_real(infile,0);break;/* seconds */ |
||
993 | case 6: int_data[6] = get_real(infile,0);if(int_data[6] < 0 || int_data[6] > 2){canvas_error("hourglass can be 0,1 or 2");}break;/* type hourglass */ |
||
994 | case 7: int_data[7] = (int)(get_real(infile,1));/* interactive 0,1,2*/ |
||
995 | switch(int_data[7]){ |
||
996 | case 0:break; |
||
997 | case 1:if(clock_cnt == 0){ |
||
998 | if( reply_format == 0 ){ |
||
999 | reply_format = 18; /* user sets clock */ |
||
14208 | schaersvoo | 1000 | /* string_length = 1 + snprintf(NULL,0,"set_clock = function(num,type,diff){var name = eval(\"clocks\"+num);switch(type){case 1:name.H = parseInt(name.H+diff);break;case 2:name.M = parseInt(name.M+diff);break;case 3:name.S = parseInt(name.S+diff);break;default: break;};name = clock(name.xc,name.yc,name.radius,name.H,name.M,name.S,name.type,name.interaction,name.H_color,name.M_color,name.S_color,name.bg_color,name.fg_color);};\n"); |
1001 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11806 | schaersvoo | 1002 | snprintf(tmp_buffer,string_length,"set_clock = function(num,type,diff){var name = eval(\"clocks\"+num);switch(type){case 1:name.H = parseInt(name.H+diff);break;case 2:name.M = parseInt(name.M+diff);break;case 3:name.S = parseInt(name.S+diff);break;default: break;};name = clock(name.xc,name.yc,name.radius,name.H,name.M,name.S,name.type,name.interaction,name.H_color,name.M_color,name.S_color,name.bg_color,name.fg_color);};\n"); |
1003 | add_to_buffer(tmp_buffer); |
||
1004 | */ |
||
1005 | fprintf(js_include_file,"set_clock = function(num,type,diff){if(wims_status == \"done\"){return;};var name = eval(\"clocks\"+num);switch(type){case 1:name.H = parseInt(name.H+diff);break;case 2:name.M = parseInt(name.M+diff);break;case 3:name.S = parseInt(name.S+diff);break;default: break;};name = new clock(name.xc,name.yc,name.radius,name.H,name.M,name.S,name.type,name.interaction,name.H_color,name.M_color,name.S_color,name.bg_color,name.fg_color);};\n"); |
||
1006 | } |
||
1007 | else |
||
1008 | { |
||
1009 | canvas_error("interactive clock may not be used together with other reply_types..."); |
||
1010 | } |
||
1011 | } |
||
15111 | schaersvoo | 1012 | fprintf(stdout,"<p style=\"text-align:center\"><input class=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,1,1)\" value=\"H+\" /><input class=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,2,1)\" value=\"M+\" /><input class=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,3,1)\" value=\"S+\" /><br /><input class=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,1,-1)\" value=\"H−\" /><input class=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,2,-1)\" value=\"M−\" /><input class=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,3,-1)\" value=\"S−\" /></p>",css_class,clock_cnt,css_class,clock_cnt,css_class,clock_cnt,css_class,clock_cnt,css_class,clock_cnt,css_class,clock_cnt); |
11806 | schaersvoo | 1013 | break; |
1014 | case 3:if(clock_cnt == 0){ |
||
1015 | if( reply_format == 0 ){ |
||
1016 | reply_format = 18; /* user sets clock */ |
||
1017 | fprintf(js_include_file,"set_clock = function(num,type,diff){if(wims_status == \"done\"){return;};var name = eval(\"clocks\"+num);switch(type){case 1:name.H = parseInt(name.H+diff);break;case 2:name.M = parseInt(name.M+diff);break;case 3:name.S = parseInt(name.S+diff);break;default: break;};name = new clock(name.xc,name.yc,name.radius,name.H,name.M,name.S,name.type,1,name.H_color,name.M_color,name.S_color,name.bg_color,name.fg_color);};\n"); |
||
1018 | } |
||
1019 | else |
||
1020 | { |
||
1021 | canvas_error("interactive clock may not be used together with other reply_types..."); |
||
1022 | } |
||
1023 | } |
||
1024 | /* |
||
15111 | schaersvoo | 1025 | fprintf(stdout,"<p style=\"text-align:center\"><input class=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,1,1)\" value=\"H+\" /><input class=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,2,1)\" value=\"M+\" /><input class=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,3,1)\" value=\"S+\" /><br /><input class=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,1,-1)\" value=\"H−\" /><input class=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,2,-1)\" value=\"M−\" /><input class=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,3,-1)\" value=\"S−\" /></p>",css_class,clock_cnt,css_class,clock_cnt,css_class,clock_cnt,css_class,clock_cnt,css_class,clock_cnt,css_class,clock_cnt); |
11806 | schaersvoo | 1026 | */ |
1027 | break; |
||
1028 | case 2:if( reply_format == 0 ){ |
||
1029 | reply_format = 19; /* "onclick */ |
||
15111 | schaersvoo | 1030 | js_function[INTERACTIVE] = 1; |
1031 | fprintf(js_include_file,"\n/* begin onclick handler for clocks */\nvar reply = new Array();canvas_div.addEventListener( 'mousedown', user_click,false);\n\nfunction user_click(evt){if(evt.button == 1){var canvas_rect = clock_canvas.getBoundingClientRect();var x = evt.clientX - canvas_rect.left;var y = evt.clientY - canvas_rect.top;var p = 0;var name;var t = true;while(t){try{name = eval('clocks'+p);if( x < name.xc + name.radius && x > name.xc - name.radius ){if( y < name.yc + name.radius && y > name.yc - name.radius ){reply[0] = p;name = new clock(name.xc,name.yc,name.radius,name.H,name.M,name.S,name.type,name.interaction,name.H_color,name.M_color,name.S_color,\"lightblue\",name.fg_color);};}else{clock_ctx.clearRect(name.xc-name.radius,name.yc-name.radius,name.xc+name.radius,name.yc+name.radius);name = new clock(name.xc,name.yc,name.radius,name.H,name.M,name.S,name.type,name.interaction,name.H_color,name.M_color,name.S_color,name.bg_color,name.fg_color);};p++;}catch(e){t=false;};};};};\n"); |
||
11806 | schaersvoo | 1032 | } |
1033 | else |
||
1034 | { |
||
1035 | if( reply_format != 19){ |
||
1036 | canvas_error("clickable clock(s) may not be used together with other reply_types..."); |
||
1037 | } |
||
1038 | } |
||
1039 | break; |
||
1040 | default: canvas_error("interactive must be set 0,1 or 2");break; |
||
1041 | } |
||
1042 | break; |
||
1043 | case 8: |
||
14078 | bpr | 1044 | if(clock_cnt == 0 ){ /* set opacity's just once .... it should be a argument to clock(), for now it's OK */ |
11806 | schaersvoo | 1045 | fprintf(js_include_file,"var clock_bg_opacity = %.2f;var clock_fg_opacity = %.2f;",fill_opacity,stroke_opacity); |
1046 | } |
||
1047 | temp = get_string(infile,3);/* optional colors, like: ,,red,,blue*/ |
||
1048 | if( strstr( temp,",") != 0 ){ temp = str_replace(temp,",","\",\""); } |
||
1049 | else{ |
||
1050 | /* h_color,m_color,s_color,bg_color,fg_color */ |
||
11991 | schaersvoo | 1051 | temp = ",black\",\"black\",\"black\",\"white\",\"black";} |
14208 | schaersvoo | 1052 | string_length = 1 + snprintf(NULL,0,"clocks%d = new clock(%d,%d,%d,%d,%d,%d,%d,%d,\"%s\");\n",clock_cnt,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],temp); |
1053 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11806 | schaersvoo | 1054 | snprintf(tmp_buffer,string_length,"clocks%d = new clock(%d,%d,%d,%d,%d,%d,%d,%d,\"%s\");\n",clock_cnt,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],temp); |
1055 | add_to_buffer(tmp_buffer); |
||
1056 | fprintf(js_include_file,"var clocks%d;",clock_cnt); |
||
1057 | clock_cnt++; |
||
1058 | break; |
||
1059 | default:break; |
||
1060 | } |
||
1061 | } |
||
1062 | break; |
||
1063 | |||
1064 | |||
1065 | case COLORPALETTE: |
||
1066 | /* |
||
1067 | @ colorpalette color_name_1,color_name_2,...,color_name_8 |
||
1068 | @ opacity will be the same for all colors and is set by command <a href="#opacity">opacity [0-255],[0-255]</a> |
||
14066 | bpr | 1069 | @ can be used with command <a href='#userdraw'>userdraw clickfill,color</a> when more than one fillcolor is wanted.<br />in that case use for example <a href='#replyformat'>replyformat 10</a> ... reply=x1:y1:color1,x2:y2:color2...<br />the pupil can choose from the given colors by clicking small coloured buttons.<br /> the click coordinates and corresponding fillcolor will be stored in read_canvas()...when using the appropriate replyformat.<br />the first color of the palette is color=0 |
14077 | bpr | 1070 | @ make sure to include the ''remove button`` by using command <a href='#clearbutton'>clearbutton some_text</a> |
11806 | schaersvoo | 1071 | */ |
1072 | if( use_tooltip == 1 ){canvas_error("command 'colorpalette' is incompatible with command 'intooltip tip_text'");} |
||
1073 | fprintf(js_include_file,"var multifillcolors = [];var palettecolors = ["); |
||
1074 | while( ! done ){ |
||
1075 | temp = get_color(infile,1); |
||
1076 | fprintf(js_include_file,"\"%s\",",temp); |
||
1077 | } |
||
1078 | fprintf(js_include_file,"];");/* add black to avoid trouble with dangling comma... */ |
||
15111 | schaersvoo | 1079 | add_color_palette(css_class); |
11806 | schaersvoo | 1080 | break; |
13829 | bpr | 1081 | |
15111 | schaersvoo | 1082 | case COMMENT: |
1083 | sync_input(infile); |
||
1084 | break; |
||
1085 | |||
1086 | |||
11806 | schaersvoo | 1087 | case COPY: |
1088 | /* |
||
1089 | @ copy x,y,x1,y1,x2,y2,[filename URL] |
||
1090 | @ The image may be "bitmap" or "SVG" |
||
1091 | @ Insert the region from (x1,y1) to (x2,y2) (in pixels) of [filename] to (x,y) in x/y-range |
||
1092 | @ If x1=y1=x2=y2=-1, the whole [filename URL] is copied. |
||
1093 | @ [filename] is the URL of the image |
||
15111 | schaersvoo | 1094 | @ <em>TODO:move special image functions to generic 'dragstuff' library</em> |
1095 | @ URL is normal URL of network reachable image file location |
||
1096 | @ if command <a href="#drag">drag x/y/xy</a> is set before command ''copy``, the images will be draggable<br />javascript function read_canvas(); will return the x/y coordinate data in xrange/yrange of all -including non draggable- images<br />the command drag is only valid for the next image<br />draggable / non-draggable images may be mixed<br />may be used together with preceding keywords ''snaptogrid``, ''xsnaptogrid``, ''ysnaptogrid`` or <code>snaptopoints x1,y1,x2,y2...</code>. |
||
1097 | @ if keyword <a href="#onclick">onclick</a> is set before command ''copy`` the image(s) is clickable (marked with a green rectangle around the image)<br />use 'read_dragdrop' to get the number of the clicked image(s)<br />use command 'clearbutton some_text' to reset the reply/click array.<br />example: 4 images; student clicked on image 2 and 3: reply = 0,1,1,0<br />after clicking the clear button: reply = 0,0,0,0<br />May be mixed with commands ''drag x|y|xy`` (use javascript read_canvas to get the new coordinates |
||
1098 | @ ''onclick`` for external images may be mixed with canvas generated stuff (like lines,curves, embeded XML etc) |
||
11806 | schaersvoo | 1099 | @ you may draw / userdraw / drag other stuff on top of an "imported" image |
15633 | bpr | 1100 | @ the use of a slider is not possible: if needed, use command <a href='#html'>html x,y,<img src=my_image.svg /> </a> |
14077 | bpr | 1101 | @ use keyword <a href='#centered'>centered</a> before command ''copy`` to place image center at given coordinates. |
13967 | schaersvoo | 1102 | @%copy_onclick%size 400,400%xrange -10,10%yrange -10,10%onclick%copy -5,5,-1,-1,-1,-1,gifs/fr.gif%onclick%copy 5,5,-1,-1,-1,-1,gifs/en.gif%onclick%copy 5,-5,-1,-1,-1,-1,gifs/it.gif%onclick%copy -5,-5,-1,-1,-1,-1,gifs/cn.gif |
14066 | bpr | 1103 | @%copy_drag_xy%size 400,400%xrange -10,10%yrange -10,10%# attention: left mouse click on the image will activate dragging...%# keep left mouse button pressed while moving the image !%drag xy%copy -5,5,-1,-1,-1,-1,gifs/fr.gif%drag xy%copy 5,5,-1,-1,-1,-1,gifs/en.gif%drag xy%copy 5,-5,-1,-1,-1,-1,gifs/it.gif%drag xy%copy -5,-5,-1,-1,-1,-1,gifs/cn.gif |
1104 | @%copy_drag_xy_snaptogrid%size 400,400%xrange -10,10%yrange -10,10%grid 2,2,grey%# attention: left mouse click on the image will activate dragging...%# keep left mouse button pressed while moving the image !%drag xy%# a function read_canvas_images() %copy -6,6,-1,-1,-1,-1,gifs/fr.gif%snaptogrid%drag xy%copy 6,6,-1,-1,-1,-1,gifs/en.gif%snaptogrid%drag xy%copy 6,-6,-1,-1,-1,-1,gifs/it.gif%snaptogrid%drag xy%copy -6,-6,-1,-1,-1,-1,gifs/cn.gif |
||
11806 | schaersvoo | 1105 | */ |
1106 | for(i = 0 ; i<7;i++){ |
||
7614 | schaersvoo | 1107 | switch(i){ |
15111 | schaersvoo | 1108 | case 0: double_data[0]=get_real(infile,0);break; /* x left top corner in x/y range */ |
1109 | case 1: double_data[1]=get_real(infile,0);break; /* y left top corner in x/y range */ |
||
11806 | schaersvoo | 1110 | case 2: int_data[2]=(int)(get_real(infile,0));break;/* x1 in px of external image */ |
1111 | case 3: int_data[3]=(int)(get_real(infile,0));break;/* y1 in px of external image */ |
||
1112 | case 4: int_data[4]=(int)(get_real(infile,0));break;/* x2 --> width */ |
||
1113 | case 5: int_data[5]=(int)(get_real(infile,0)) ;break;/* y2 --> height */ |
||
1114 | case 6: URL = get_string(infile,1); |
||
15111 | schaersvoo | 1115 | if(use_rotate == TRUE ){rotate(2,angle,rotationcenter,2);} |
1116 | if(use_affine == TRUE ){transform(2,2);} |
||
1117 | int_data[0] = x2px(double_data[0]); |
||
1118 | int_data[1] = y2px(double_data[1]); |
||
11806 | schaersvoo | 1119 | int_data[6] = int_data[4] - int_data[2];/* swidth & width (if not scaling )*/ |
1120 | int_data[7] = int_data[5] - int_data[3];/* sheight & height (if not scaling )*/ |
||
15111 | schaersvoo | 1121 | if( onclick == 0 ){ /* no mouse needed static image copy */ |
1122 | if(js_function[DRAW_EXTERNAL_IMAGE] == 0){/* create canvas just once */ |
||
1123 | fprintf(js_include_file,"var image_copy_canvas = create_canvas%d(%d,xsize,ysize);",canvas_root_id,STATIC_IMAGE_CANVAS); |
||
1124 | js_function[DRAW_EXTERNAL_IMAGE] = 1; |
||
1125 | } |
||
1126 | string_length = 1 + snprintf(NULL,0, "draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,%d);\n",URL,int_data[2],int_data[3],int_data[6],int_data[7],int_data[0],int_data[1],int_data[6],int_data[7],use_offset,int_data[10]); |
||
1127 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
1128 | snprintf(tmp_buffer,string_length, "draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,%d);\n",URL,int_data[2],int_data[3],int_data[6],int_data[7],int_data[0],int_data[1],int_data[6],int_data[7],use_offset,int_data[10]); |
||
11806 | schaersvoo | 1129 | } |
15111 | schaersvoo | 1130 | else /* onclick or drag & drop external copy images */ |
11806 | schaersvoo | 1131 | { |
15111 | schaersvoo | 1132 | js_function[DRAG_EXTERNAL_IMAGE] = 1; |
1133 | string_length = 1 + snprintf(NULL,0, "drag_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d);\n",URL,int_data[2],int_data[3],int_data[6],int_data[7],int_data[0],int_data[1],int_data[6],int_data[7],onclick,object_cnt,use_offset,use_snap,int_data[10]); |
||
1134 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
15116 | bpr | 1135 | snprintf(tmp_buffer,string_length, "drag_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d);\n",URL,int_data[2],int_data[3],int_data[6],int_data[7],int_data[0],int_data[1],int_data[6],int_data[7],onclick,object_cnt,use_offset,use_snap,int_data[10]); |
11806 | schaersvoo | 1136 | } |
14038 | schaersvoo | 1137 | add_to_buffer(tmp_buffer); |
11806 | schaersvoo | 1138 | break; |
7614 | schaersvoo | 1139 | default: break; |
1140 | } |
||
1141 | } |
||
15111 | schaersvoo | 1142 | reset(); |
7614 | schaersvoo | 1143 | break; |
11806 | schaersvoo | 1144 | /* |
1145 | HTML5 specs: |
||
1146 | context.drawImage(img,sx,sy,swidth,sheight,x,y,width,height); |
||
1147 | img Specifies the image, canvas, or video element to use |
||
14066 | bpr | 1148 | sx The x coordinate where to start clipping: x1 = int_data[0] |
1149 | sy The y coordinate where to start clipping: x2 = int_data[1] |
||
1150 | swidth The width of the clipped image: int_data[2] - int_data[0] |
||
1151 | sheight The height of the clipped image: int_data[3] - int_data[1] |
||
1152 | x The x coordinate where to place the image on the canvas: dx1 = int_data[4] |
||
1153 | y The y coordinate where to place the image on the canvas: dy1 = int_data[5] |
||
1154 | width The width of the image to use (stretch or reduce the image): dx2 - dx1 = int_data[6] |
||
1155 | height The height of the image to use (stretch or reduce the image): dy2 - dy1 = int_data[7] |
||
11806 | schaersvoo | 1156 | */ |
1157 | case COPYRESIZED: |
||
1158 | /* |
||
15111 | schaersvoo | 1159 | @ copyresized x1,y2,x2,y2,dx1,dy1,dx2,dy2,image_file_url |
11806 | schaersvoo | 1160 | @ The image may be any "bitmap" or "SVG" |
1161 | @ Insert the region from (x1,y1) to (x2,y2) (in pixels) of [ filename], <br />possibly resized,<br />to the region of (dx1,dy1) to (dx2,dy2) in x/y-range |
||
14066 | bpr | 1162 | @ (dx1:dy1) must be left top corner; (dx2:dy2) must be right bottom corner of inserted image |
11806 | schaersvoo | 1163 | @ If x1=y1=x2=y2=-1, the whole [filename / URL ] is copied and resized. |
15111 | schaersvoo | 1164 | @ URL is normal URL of network reachable image file location<br />(as seen from public_html-root or network reachable 'http://some_server/my_images/test.gif'<br />(eg no special wims paths are searched !!) |
1165 | @ if command <a href="#drag">drag x/y/xy</a> is set before command ''copy``, the images will be draggable<br />javascript function read_canvas(); will return the x/y coordinate data in xrange/yrange of all -including non draggable- images<br />the command drag is only valid for the next image<br />draggable / non-draggable images may be mixed<br />may be used together with preceding keywords ''snaptogrid``,''xsnaptogrid``,''ysnaptogrid`` or <code>snaptopoints x1,y1,x2,y2...</code> |
||
1166 | @ if keyword <a href="#onclick">onclick</a> is set before command ''copy`` the image(s) is clickable (marked with a green rectangle around the image)<br />use ''read_dragdrop`` to get the number of the clicked image(s)<br />use command 'clearbutton some_text' to reset the reply/click array.<br />example: 4 images; student clicked on image 2 and 3: reply = 0,1,1,0<br />after clicking the clear button: reply = 0,0,0,0<br />May be mixed with commands ''drag x|y|xy`` (use javascript read_canvas to get the new coordinates |
||
1167 | @ ''onclick`` for external images may be mixed with canvas generated stuff (like lines,curves etc) |
||
1168 | @ you may draw / userdraw / drag stuff on top of an "imported" image |
||
1169 | @ when set draggable, there will be special function 'read_canvas_images()'<br />now dragging external images may be combined with 'read_canvas()' from <a href='#userdraw'>userdraw</a> or <a href='#multidraw'>multidraw</a><br />set command <a href='#precision'>precision</a> before command ''copy`` |
||
1170 | @ use keyword <a href='#centered'>centered</a> before command 'copyresized' to place image center at given coordinates. |
||
1171 | @ <em>TODO:move special image functions to generic 'dragstuff' library</em> |
||
11806 | schaersvoo | 1172 | */ |
1173 | for(i = 0 ; i<9;i++){ |
||
1174 | switch(i){ |
||
1175 | case 0: int_data[0] = (int)(get_real(infile,0));break; /* x1 */ |
||
1176 | case 1: int_data[1] = (int)(get_real(infile,0));break; /* y1 */ |
||
1177 | case 2: int_data[2] = (int)(get_real(infile,0));break;/* x2 */ |
||
1178 | case 3: int_data[3] = (int)(get_real(infile,0));break;/* y2 */ |
||
1179 | case 4: int_data[4] = x2px(get_real(infile,0));break;/* dx1 */ |
||
1180 | case 5: int_data[5] = y2px(get_real(infile,0));break;/* dy1 */ |
||
1181 | case 6: int_data[6] = x2px(get_real(infile,0));break;/* dx2 */ |
||
1182 | case 7: int_data[7] = y2px(get_real(infile,0));break;/* dy2 */ |
||
1183 | case 8: URL = get_string(infile,1); |
||
15111 | schaersvoo | 1184 | if( int_data[1] == -1 ){ int_data[10] = 1; }else{int_data[10] = 0; }/* resized / not resized */ |
11806 | schaersvoo | 1185 | /* flag error when wrong diagonal: copyresized -1,-1,-1,-1,0,0,7,7,testfig.gif */ |
1186 | if( int_data[7] < int_data[5] || int_data[6] < int_data[4]){ |
||
15633 | bpr | 1187 | canvas_error("in copyresized, use:<br />left top corner (dx1:dy1) and right bottom corner (dx2:dy2) ! "); |
11806 | schaersvoo | 1188 | } |
1189 | int_data[2] = abs(int_data[2] - int_data[0]);/* swidth */ |
||
1190 | int_data[3] = abs(int_data[3] - int_data[1]);/* sheight */ |
||
1191 | int_data[6] = abs(int_data[6] - int_data[4]);/* width */ |
||
1192 | int_data[7] = abs(int_data[7] - int_data[5]);/* height */ |
||
15111 | schaersvoo | 1193 | if( onclick == 0 ){ /* no mouse needed static image copy */ |
1194 | if(js_function[DRAW_EXTERNAL_IMAGE] == 0){ |
||
1195 | fprintf(js_include_file,"var image_copy_canvas = create_canvas%d(%d,xsize,ysize);",canvas_root_id,STATIC_IMAGE_CANVAS); |
||
1196 | js_function[DRAW_EXTERNAL_IMAGE] = 1; |
||
1197 | } |
||
1198 | string_length = 1 + snprintf(NULL,0, "draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,%d);\n",URL,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],use_offset,int_data[10]); |
||
1199 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
1200 | snprintf(tmp_buffer,string_length, "draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,%d);\n",URL,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],use_offset,int_data[10]); |
||
11806 | schaersvoo | 1201 | } |
15111 | schaersvoo | 1202 | else /* onclick or drag & drop external copy images */ |
11806 | schaersvoo | 1203 | { |
15111 | schaersvoo | 1204 | js_function[DRAG_EXTERNAL_IMAGE] = 1; |
1205 | string_length = 1 + snprintf(NULL,0, "drag_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d);\n",URL,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],onclick,object_cnt,use_offset,use_snap,int_data[10]); |
||
1206 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
15116 | bpr | 1207 | snprintf(tmp_buffer,string_length, "drag_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d);\n",URL,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],onclick,object_cnt,use_offset,use_snap,int_data[10]); |
15111 | schaersvoo | 1208 | object_cnt++; |
11806 | schaersvoo | 1209 | } |
14038 | schaersvoo | 1210 | add_to_buffer(tmp_buffer); |
11806 | schaersvoo | 1211 | break; |
1212 | default: break; |
||
1213 | } |
||
1214 | } |
||
14038 | schaersvoo | 1215 | reset(); |
11806 | schaersvoo | 1216 | break; |
8386 | schaersvoo | 1217 | |
11806 | schaersvoo | 1218 | case CROSSHAIR: |
8386 | schaersvoo | 1219 | /* |
11806 | schaersvoo | 1220 | @ crosshair x,y,color |
14379 | bpr | 1221 | @ draw a single crosshair point at (x;y) in color ''color`` |
1222 | @ use command <code>crosshairsize int</code> and / or <code>linewidth int</code> to adjust |
||
11806 | schaersvoo | 1223 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
12107 | schaersvoo | 1224 | @%crosshair%size 400,400%xrange -10,10%yrange -10,10%opacity 255,255%linewidth 2%onclick%crosshair 0,0,red%linewidth 1%onclick%crosshair 1,1,blue%linewidth 3%onclick%crosshair 3,3,green%linewidth 4%xrosshair 4,4,orange |
11806 | schaersvoo | 1225 | */ |
1226 | for(i=0;i<3;i++){ |
||
1227 | switch(i){ |
||
1228 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
1229 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
1230 | case 2: stroke_color = get_color(infile,1);/* name or hex color */ |
||
15111 | schaersvoo | 1231 | if(use_rotate == TRUE ){rotate(2,angle,rotationcenter,2);} |
1232 | if(use_affine == TRUE ){ transform(2,2);} |
||
1233 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
11806 | schaersvoo | 1234 | decimals = find_number_of_digits(precision); |
15111 | schaersvoo | 1235 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,7,[%.*f],[%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[1],crosshair_size,crosshair_size,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,0,0,0,use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
1236 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
1237 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,7,[%.*f],[%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[1],crosshair_size,crosshair_size,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,0,0,0,use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
1238 | add_to_buffer(tmp_buffer); |
||
1239 | if(onclick != 0){object_cnt++;} |
||
1240 | /* object_cnt++ */ |
||
11806 | schaersvoo | 1241 | reset(); |
15111 | schaersvoo | 1242 | dragstuff[7] = 1; |
11806 | schaersvoo | 1243 | break; |
1244 | default:break; |
||
1245 | } |
||
1246 | } |
||
15111 | schaersvoo | 1247 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
11806 | schaersvoo | 1248 | break; |
1249 | |||
1250 | case CROSSHAIRS: |
||
1251 | /* |
||
1252 | @ crosshairs color,x1,y1,x2,y2,...,x_n,y_n |
||
14077 | bpr | 1253 | @ draw multiple crosshair points at given coordinates in color ''color`` |
14246 | bpr | 1254 | @ use command <code>crosshairsize int</code> and / or <code>linewidth int</code> to adjust |
9406 | schaersvoo | 1255 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!) |
12107 | schaersvoo | 1256 | @%crosshairs_1%size 400,400%xrange -10,10%yrange -10,10%opacity 255,255%snaptogrid%linewidth 2%drag xy%crosshairs red,0,0,1,1,2,2,3,3%drag x%crosshairs blue,0,1,1,2,2,3,3,4 |
1257 | @%crosshairs_2%size 400,400%xrange -10,10%yrange -10,10%opacity 255,255%linewidth 2%onclick%crosshairs red,0,0,1,1,2,2,3,3%onclick%crosshairs blue,0,1,1,2,2,3,3,4 |
||
1258 | */ |
||
8386 | schaersvoo | 1259 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
1260 | fill_color = stroke_color; |
||
1261 | i=0; |
||
1262 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 1263 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
8386 | schaersvoo | 1264 | if(i%2 == 0 ){ |
1265 | double_data[i] = get_real(infile,0); /* x */ |
||
1266 | } |
||
1267 | else |
||
1268 | { |
||
1269 | double_data[i] = get_real(infile,1); /* y */ |
||
1270 | } |
||
1271 | i++; |
||
1272 | } |
||
15111 | schaersvoo | 1273 | if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);} |
1274 | if(use_affine == TRUE ){ transform(i-1,2);} |
||
1275 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
8386 | schaersvoo | 1276 | decimals = find_number_of_digits(precision); |
11806 | schaersvoo | 1277 | for(c=0 ; c < i-1 ; c = c+2){ |
15111 | schaersvoo | 1278 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,7,[%.*f],[%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[c],decimals,double_data[c+1],crosshair_size,crosshair_size,line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,1,0,0,0,use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
1279 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
1280 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,7,[%.*f],[%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[c],decimals,double_data[c+1],crosshair_size,crosshair_size,line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,1,0,0,0,use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
1281 | add_to_buffer(tmp_buffer); |
||
1282 | if(onclick != 0){object_cnt++;}/* object_cnt++; */ |
||
8386 | schaersvoo | 1283 | } |
15111 | schaersvoo | 1284 | dragstuff[7] = 1; |
1285 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
8386 | schaersvoo | 1286 | reset(); |
1287 | break; |
||
1288 | |||
11806 | schaersvoo | 1289 | case CROSSHAIRSIZE: |
7614 | schaersvoo | 1290 | /* |
11806 | schaersvoo | 1291 | @ crosshairsize int |
1292 | @ default 8 (px) |
||
7614 | schaersvoo | 1293 | */ |
11806 | schaersvoo | 1294 | crosshair_size = (int) (get_real(infile,1)); |
1295 | break; |
||
15111 | schaersvoo | 1296 | case CSS: |
1297 | /* |
||
1298 | @ css css_class |
||
1299 | @ may be used before any ''style-able`` html object (like inputfields or buttons) or some html objects that are generated by some canvasdraw commands |
||
1300 | @ in case of <a href="#multidraw">multidraw</a> this command must be a table css class, for example "wimstable" |
||
1301 | @%css%size 400,400%xrange -10,10%yrange -10,10%css wims_button_help%input 0,0,10,1,Hello |
||
1302 | */ |
||
1303 | css_class = get_string(infile,1); |
||
1304 | break; |
||
11806 | schaersvoo | 1305 | |
1306 | case CURSOR: |
||
1307 | /* |
||
14086 | bpr | 1308 | @ cursor some CSS cursor_style |
15715 | schaersvoo | 1309 | @ alternative: pointer |
13956 | schaersvoo | 1310 | @ style can be any valid CSS property value |
1311 | @ choose from these types:<br />alias,all-scroll,auto,cell,context-menu,col-resize,copy,crosshair,default,e-resize,<br />ew-resize,grab,grabbing,help,move,n-resize,ne-resize,nesw-resize,ns-resize,nw-resize,<br />nwse-resize,no-drop,none,not-allowed,pointer,progress,row-resize,s-resize,se-resize,<br />sw-resize,text,url(myBall.cur),auto,vertical-text,w-resize,wait,zoom-in,zoom-out,initial |
||
1312 | @ note: wims will not check the validity of your cursor declaration |
||
1313 | @%cursor_css%size 400,400%xrange -10,10%yrange -10,10%cursor move%linewidth 3%drag xy%opacity 200,75%fcircles blue,-5,5,3,-4,-2,6,0,0,5,3,4,2,4,-5,4 |
||
11806 | schaersvoo | 1314 | */ |
1315 | fprintf(js_include_file,"canvas_div%d.style.cursor = \"%s\";",canvas_root_id,get_string(infile,1)); |
||
1316 | break; |
||
1317 | |||
1318 | case CURVE: |
||
1319 | /* |
||
1320 | @ curve color,formula(x) |
||
15715 | schaersvoo | 1321 | @ alternative: plot |
15601 | schaersvoo | 1322 | @ use command <a href="#trange">trange</a> in parametric functions before <b>every</b> command curve / plot <code>trange -pi,pi<br />curve color,formula1(t),formula2(t)</code><br />A next parametric curve will only be correctly plot when trange is set again !<br/>this is a design flaw and not a feature... |
14086 | bpr | 1323 | @ use command <a href="#precision">precision</a> to increase the number of digits of the plotted points |
14066 | bpr | 1324 | @ use command <a href="#plotsteps">plotsteps</a> to increase / decrease the amount of plotted points (default 150) |
11806 | schaersvoo | 1325 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
14379 | bpr | 1326 | @ if you need a plot beyond xrange / yrange, use <a href="#jsplot">jsplot</a> (command ''curve`` will only calculate points within the xrange) |
12107 | schaersvoo | 1327 | @%curve%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%xlabel x-axis%ylabel y-axis%precision 1%grid 2,2,grey,2,2,6,grey%precision 1000%curve red,4*sqrt(x)%curve green,2*sqrt(abs(x)%curve blue,3*1/sqrt(x)%curve orange,4*sin(4/x)%dashed%curve red,4*cos(x) |
11806 | schaersvoo | 1328 | */ |
15111 | schaersvoo | 1329 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
1330 | |||
11806 | schaersvoo | 1331 | if( use_parametric == TRUE ){ /* parametric color,fun1(t),fun2(t)*/ |
1332 | use_parametric = FALSE; |
||
1333 | stroke_color = get_color(infile,0); |
||
1334 | char *fun1 = get_string_argument(infile,0); |
||
1335 | char *fun2 = get_string_argument(infile,1); |
||
1336 | if( strlen(fun1) == 0 || strlen(fun2) == 0 ){canvas_error("parametric functions are NOT OK !");} |
||
15601 | schaersvoo | 1337 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,9,%s,[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,eval_parametric(xsize,ysize,fun1,fun2,xmin,xmax,ymin,ymax,tmin,tmax,plot_steps,precision,rotationcenter),2*line_width,2*line_width,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
15116 | bpr | 1338 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
15601 | schaersvoo | 1339 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,9,%s,[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,eval_parametric(xsize,ysize,fun1,fun2,xmin,xmax,ymin,ymax,tmin,tmax,plot_steps,precision,rotationcenter),2*line_width,2*line_width,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
15111 | schaersvoo | 1340 | add_to_buffer(tmp_buffer); |
11806 | schaersvoo | 1341 | } |
1342 | else |
||
1343 | { |
||
1344 | stroke_color = get_color(infile,0); |
||
1345 | char *fun1 = get_string_argument(infile,1); |
||
1346 | if( strlen(fun1) == 0 ){canvas_error("function is NOT OK !");} |
||
15601 | schaersvoo | 1347 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,9,%s,[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,eval(xsize,ysize,fun1,xmin,xmax,ymin,ymax,plot_steps,precision,rotationcenter),line_width,line_width,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
15116 | bpr | 1348 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
15601 | schaersvoo | 1349 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,9,%s,[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,eval(xsize,ysize,fun1,xmin,xmax,ymin,ymax,plot_steps,precision,rotationcenter),line_width,line_width,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
15111 | schaersvoo | 1350 | add_to_buffer(tmp_buffer); |
11806 | schaersvoo | 1351 | } |
15111 | schaersvoo | 1352 | if(onclick != 0){object_cnt++;}/* object_cnt++; */ |
1353 | dragstuff[9] = 1; |
||
1354 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
11806 | schaersvoo | 1355 | reset(); |
1356 | break; |
||
15116 | bpr | 1357 | |
14038 | schaersvoo | 1358 | case CURVEDARROW: |
1359 | /* |
||
1360 | @ curvedarrow x1,y1,xc,yc,x2,y2,color |
||
15111 | schaersvoo | 1361 | @ draw a single headed curved arrow from (x1:y1) in direction of (xc:yc) to point (x2:y2)<br /> note: the curve will <b>not go through</b> point (xc:yc) |
14038 | schaersvoo | 1362 | @ use command <a href='#arrowhead'>arrowhead</a> to set the size of the arrow head. |
15111 | schaersvoo | 1363 | @ use command <code>linewidth int</code> to adjust thickness of the arrow |
1364 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
||
14038 | schaersvoo | 1365 | @%curvedarrow_drag%size 400,400%xrange -10,10%yrange -10,10%cursor move%linewidth 2%drag xy%curvedarrow -5,0,0,10,5,0,blue |
1366 | @%curvedarrow_click%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%%onclick%curvedarrow -5,0,0,-10,5,0,blue%onclick%curvedarrow -8,0,0,5,8,3,green |
||
11806 | schaersvoo | 1367 | |
14029 | schaersvoo | 1368 | h[0] = arrowhead |
14066 | bpr | 1369 | h[1] = type: 1 = single 2=double arrow |
15111 | schaersvoo | 1370 | function Shape(object_cnt,onclick,direction,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_slider,rotation_center,use_offset) |
14038 | schaersvoo | 1371 | */ |
15111 | schaersvoo | 1372 | for(i=0;i<7;i++){ |
14038 | schaersvoo | 1373 | switch(i){ |
1374 | case 0: double_data[0] = get_real(infile,0);break; /* x1 */ |
||
1375 | case 1: double_data[1] = get_real(infile,0);break; /* y1 */ |
||
1376 | case 2: double_data[2] = get_real(infile,0);break; /* xc */ |
||
1377 | case 3: double_data[3] = get_real(infile,0);break; /* yc */ |
||
1378 | case 4: double_data[4] = get_real(infile,0);break; /* y3 */ |
||
1379 | case 5: double_data[5] = get_real(infile,0);break; /* y3 */ |
||
1380 | case 6: stroke_color = get_color(infile,1);/* name or hex color */ |
||
15111 | schaersvoo | 1381 | if(use_rotate == TRUE ){rotate(6,angle,rotationcenter,2);} |
1382 | if(use_affine == TRUE ){ transform(6,2);} |
||
1383 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
14038 | schaersvoo | 1384 | decimals = find_number_of_digits(precision); |
15111 | schaersvoo | 1385 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,21,[%.*f,%.*f,%.*f],[%.*f,%.*f,%.*f],[%d,%d],[%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[2],decimals,double_data[4],decimals,double_data[1],decimals,double_data[3],decimals,double_data[5],arrow_head,arrow_head,arrow_head,1,line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
1386 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
1387 | snprintf(tmp_buffer,string_length, "dragstuff.addShape(new Shape(%d,%d,%d,%d,21,[%.*f,%.*f,%.*f],[%.*f,%.*f,%.*f],[%d,%d],[%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[2],decimals,double_data[4],decimals,double_data[1],decimals,double_data[3],decimals,double_data[5],arrow_head,arrow_head,arrow_head,1,line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
1388 | add_to_buffer(tmp_buffer); |
||
1389 | if(onclick != 0){object_cnt++;}/* object_cnt++;*/ |
||
1390 | reset(); |
||
14038 | schaersvoo | 1391 | break; |
1392 | } |
||
15111 | schaersvoo | 1393 | } |
1394 | dragstuff[21] = 1; |
||
1395 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
1396 | break; |
||
14029 | schaersvoo | 1397 | |
14038 | schaersvoo | 1398 | case CURVEDARROW2: |
1399 | /* |
||
1400 | @ curvedarrow2 x1,y1,xc,yc,x2,y2,color |
||
14248 | bpr | 1401 | @ draw a double headed curved arrow from (x1:y1) in direction of (xc:yc) to point (x2:y2)<br /> note: the curve will <b>not go through</b> point (xc:yc) |
14038 | schaersvoo | 1402 | @ use command <a href='#arrowhead'>arrowhead</a> to set the size of the arrow head. |
14077 | bpr | 1403 | @ use command <code>linewidth int</code> to adjust thickness of the arrow |
14038 | schaersvoo | 1404 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
1405 | @%curvedarrow_drag%size 400,400%xrange -10,10%yrange -10,10%cursor move%linewidth 2%drag xy%curvedarrow2 -5,0,0,10,5,0,blue |
||
1406 | @%curvedarrow_click%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%%onclick%cuvedarrow2 -5,0,0,-10,5,0,blue%onclick%curvedarrow -8,0,0,5,8,3,green |
||
14029 | schaersvoo | 1407 | |
1408 | h[0] = arrowhead |
||
14066 | bpr | 1409 | h[1] = type: 1 = single 2=double arrow |
15111 | schaersvoo | 1410 | function Shape(object_cnt,onclick,direction,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_slider,rotation_center,use_offset) |
14038 | schaersvoo | 1411 | */ |
15111 | schaersvoo | 1412 | for(i=0;i<7;i++){ |
14038 | schaersvoo | 1413 | switch(i){ |
1414 | case 0: double_data[0] = get_real(infile,0);break; /* x1 */ |
||
1415 | case 1: double_data[1] = get_real(infile,0);break; /* y1 */ |
||
1416 | case 2: double_data[2] = get_real(infile,0);break; /* xc */ |
||
1417 | case 3: double_data[3] = get_real(infile,0);break; /* yc */ |
||
1418 | case 4: double_data[4] = get_real(infile,0);break; /* y3 */ |
||
1419 | case 5: double_data[5] = get_real(infile,0);break; /* y3 */ |
||
1420 | case 6: stroke_color = get_color(infile,1);/* name or hex color */ |
||
15111 | schaersvoo | 1421 | if(use_rotate == TRUE ){rotate(6,angle,rotationcenter,2);} |
1422 | if(use_affine == TRUE ){ transform(6,2);} |
||
1423 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
14038 | schaersvoo | 1424 | decimals = find_number_of_digits(precision); |
15111 | schaersvoo | 1425 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,21,[%.*f,%.*f,%.*f],[%.*f,%.*f,%.*f],[%d,%d],[%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[2],decimals,double_data[4],decimals,double_data[1],decimals,double_data[3],decimals,double_data[5],arrow_head,arrow_head,arrow_head,2,line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
1426 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
1427 | snprintf(tmp_buffer,string_length, "dragstuff.addShape(new Shape(%d,%d,%d,%d,21,[%.*f,%.*f,%.*f],[%.*f,%.*f,%.*f],[%d,%d],[%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[2],decimals,double_data[4],decimals,double_data[1],decimals,double_data[3],decimals,double_data[5],arrow_head,arrow_head,arrow_head,2,line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
1428 | add_to_buffer(tmp_buffer); |
||
1429 | if(onclick != 0){object_cnt++;}/* object_cnt++;*/ |
||
1430 | dragstuff[21] = 1; |
||
1431 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
1432 | reset(); |
||
1433 | break; |
||
14038 | schaersvoo | 1434 | } |
15111 | schaersvoo | 1435 | } |
1436 | break; |
||
14038 | schaersvoo | 1437 | case CURVEDARROWS: |
1438 | /* |
||
14248 | bpr | 1439 | @ curvedarrows color,x1,y1,xc,yc,x2,y2,...,x_(n-1),y_(n-1),xc,yc,x_n,y_n |
1440 | @ draw curved arrows from (x1:y1) in direction of (xc:yc) to point (x2:y2), etc<br /> note: the curve will <b>not go through</b> point (xc:yc) |
||
14038 | schaersvoo | 1441 | @ use command <a href='#arrowhead'>arrowhead</a> to set the size of the arrow head. |
14077 | bpr | 1442 | @ use command <code>linewidth int</code> to adjust thickness of the arrow |
14038 | schaersvoo | 1443 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
1444 | @%curvedarrows_drag%size 400,400%xrange -10,10%yrange -10,10%cursor move%linewidth 2%drag xy%curvedarrows red,-8,0,0,8,8,0,-5,5,0,-10,6,3 |
||
1445 | @%curvedarrows_click%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%%onclick%curvedarrows red,-8,0,0,8,8,0,-5,5,0,-10,6,3 |
||
14029 | schaersvoo | 1446 | |
14030 | schaersvoo | 1447 | h[0] = arrowhead |
14066 | bpr | 1448 | h[1] = type: 1 = single 2=double arrow |
15111 | schaersvoo | 1449 | function Shape(object_cnt,onclick,direction,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_slider,rotation_center,use_offset) |
14038 | schaersvoo | 1450 | */ |
1451 | stroke_color = get_color(infile,0);/* name or hex color */ |
||
1452 | i = 0; |
||
1453 | decimals = find_number_of_digits(precision); |
||
15111 | schaersvoo | 1454 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
14038 | schaersvoo | 1455 | while( ! done ){ |
15111 | schaersvoo | 1456 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
1457 | double_data[0] = get_real(infile,0); /* x1 */ |
||
1458 | double_data[1] = get_real(infile,0); /* y1 */ |
||
1459 | double_data[2] = get_real(infile,0); /* xc */ |
||
1460 | double_data[3] = get_real(infile,0); /* yc */ |
||
1461 | double_data[4] = get_real(infile,0); /* x3 */ |
||
1462 | double_data[5] = get_real(infile,1); /* y3 */ |
||
1463 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,21,[%.*f,%.*f,%.*f],[%.*f,%.*f,%.*f],[%d,%d],[%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[2],decimals,double_data[4],decimals,double_data[1],decimals,double_data[3],decimals,double_data[5],arrow_head,arrow_head,arrow_head,1,line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
1464 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
1465 | snprintf(tmp_buffer,string_length, "dragstuff.addShape(new Shape(%d,%d,%d,%d,21,[%.*f,%.*f,%.*f],[%.*f,%.*f,%.*f],[%d,%d],[%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[2],decimals,double_data[4],decimals,double_data[1],decimals,double_data[3],decimals,double_data[5],arrow_head,arrow_head,arrow_head,1,line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
1466 | add_to_buffer(tmp_buffer); |
||
1467 | if(onclick != 0){object_cnt++;} |
||
1468 | i = i + 6; |
||
1469 | } |
||
1470 | if(use_rotate == TRUE ){rotate(i-6,angle,rotationcenter,2);} |
||
1471 | if(use_affine == TRUE ){ transform(i-6,2);} |
||
1472 | dragstuff[21] = 1; |
||
1473 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
1474 | reset(); |
||
1475 | break; |
||
14030 | schaersvoo | 1476 | |
14038 | schaersvoo | 1477 | case CURVEDARROWS2: |
1478 | /* |
||
1479 | @ curvedarrows2 color,x1,y1,xc,yc,x2,y2,...x_(n-1),y_(n-1),xc,yc,x_n,y_n |
||
14248 | bpr | 1480 | @ draw double headed curved arrows from (x1:y1) in direction of (xc:yc) to point (x2:y2), etc. <br /> note: the curve will <b>not go through</b> point (xc:yc) |
14038 | schaersvoo | 1481 | @ use command <a href='#arrowhead'>arrowhead</a> to set the size of the arrow head. |
14077 | bpr | 1482 | @ use command <code>linewidth int</code> to adjust thickness of the arrow |
14038 | schaersvoo | 1483 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
1484 | @%curvedarrows2_drag%size 400,400%xrange -10,10%yrange -10,10%cursor move%linewidth 2%drag xy%curvedarrows2 red,-8,0,0,8,8,0,-5,5,0,-10,6,3 |
||
1485 | @%curvedarrows2_click%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%%onclick%curvedarrow -5,0,0,-10,5,0,blue%onclick%curvedarrows2 red,-8,0,0,8,8,0,-5,5,0,-10,6,3 |
||
14030 | schaersvoo | 1486 | |
1487 | h[0] = arrowhead |
||
14066 | bpr | 1488 | h[1] = type: 1 = single 2=double arrow |
15111 | schaersvoo | 1489 | function Shape(object_cnt,onclick,direction,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_slider,rotation_center,use_offset) |
14038 | schaersvoo | 1490 | */ |
1491 | stroke_color = get_color(infile,0);/* name or hex color */ |
||
1492 | i = 0; |
||
1493 | decimals = find_number_of_digits(precision); |
||
15111 | schaersvoo | 1494 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
14038 | schaersvoo | 1495 | while( ! done ){ |
15111 | schaersvoo | 1496 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
1497 | double_data[0] = get_real(infile,0); /* x1 */ |
||
1498 | double_data[1] = get_real(infile,0); /* y1 */ |
||
1499 | double_data[2] = get_real(infile,0); /* xc */ |
||
1500 | double_data[3] = get_real(infile,0); /* yc */ |
||
1501 | double_data[4] = get_real(infile,0); /* x3 */ |
||
1502 | double_data[5] = get_real(infile,1); /* y3 */ |
||
1503 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,21,[%.*f,%.*f,%.*f],[%.*f,%.*f,%.*f],[%d,%d],[%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[2],decimals,double_data[4],decimals,double_data[1],decimals,double_data[3],decimals,double_data[5],arrow_head,arrow_head,arrow_head,2,line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
1504 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
1505 | snprintf(tmp_buffer,string_length, "dragstuff.addShape(new Shape(%d,%d,%d,%d,21,[%.*f,%.*f,%.*f],[%.*f,%.*f,%.*f],[%d,%d],[%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[2],decimals,double_data[4],decimals,double_data[1],decimals,double_data[3],decimals,double_data[5],arrow_head,arrow_head,arrow_head,2,line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
1506 | add_to_buffer(tmp_buffer); |
||
1507 | if(onclick != 0){object_cnt++;} |
||
1508 | i = i + 6; |
||
1509 | } |
||
1510 | if(use_rotate == TRUE ){rotate(i-6,angle,rotationcenter,2);} |
||
1511 | if(use_affine == TRUE ){ transform(i-6,2);} |
||
1512 | dragstuff[21] = 1; |
||
1513 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
1514 | reset(); |
||
1515 | break; |
||
15116 | bpr | 1516 | |
11806 | schaersvoo | 1517 | case DASHED: |
1518 | /* |
||
1519 | @ dashed |
||
1520 | @ keyword (no arguments required) |
||
1521 | @ next object will be drawn with a dashed line |
||
1522 | @ change dashing scheme by using command <a href="#dashtype">dashtype</a> |
||
12107 | schaersvoo | 1523 | @%dashed%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%line -5,-5,-5,5,red%dashtype 1,1%dline -4,-5,-4,5,green%dashtype 2,2%dline -3,-5,-3,5,blue%dashtype 3,3%dline 0,-5,0,5,orange%dashtype 4,4%dline 3,-5,3,5,brown |
11806 | schaersvoo | 1524 | */ |
1525 | use_dashed = TRUE; |
||
1526 | break; |
||
1527 | |||
1528 | case DASHTYPE: |
||
1529 | /* |
||
1530 | @ dashtype line_width_px,space_width_px |
||
1531 | @ every indiviual object may have its own dashtype, if needed... |
||
1532 | @ When keyword <a href='#dashed'>dashed</a> is set, the objects will be drawn with this dashtype |
||
14086 | bpr | 1533 | @ default value <code>dashtype 2,2</code> e.g. 2px line and 2px space |
13957 | schaersvoo | 1534 | @ HTML5 canvas specification supports more arguments (dashing schemes) ... but not all modern browsers are yet capable |
13949 | schaersvoo | 1535 | @%dashtype%size 400,400%xrange -10,10%yrange -10,10%dashtype 1,1%dhline 0,9,red%dashtype 2,2%dhline 0,8,red%dashtype 4,4%dhline 0,7,red%dashtype 6,6%dhline 0,6,red%dashtype 8,8%dhline 0,5,red%dashtype 10,10%dhline 0,4,red%dashtype 1,2%dhline 0,3,red%dashtype 2,4%dhline 0,2,red%dashtype 3,6%dhline 0,1,red%dashtype 4,8%dhline 0,0,red%linewidth 2%dashtype 1,1%dhline 0,-9,red%dashtype 2,2%dhline 0,-8,red%dashtype 4,4%dhline 0,-7,red%dashtype 6,6%dhline 0,-6,red%dashtype 8,8%dhline 0,-5,red%dashtype 10,10%dhline 0,-4,red%dashtype 1,2%dhline 0,-3,red%dashtype 2,4%dhline 0,-2,red%dashtype 4,8%dhline 0,-1,red |
11806 | schaersvoo | 1536 | */ |
1537 | for(i=0;i<2;i++){ |
||
1538 | switch(i){ |
||
1539 | case 0 : dashtype[0] = (int) line_width*( get_real(infile,0)) ; break; |
||
1540 | case 1 : dashtype[1] = (int) line_width*( get_real(infile,1)) ; break; |
||
1541 | } |
||
1542 | } |
||
1543 | break; |
||
1544 | |||
1545 | case DIAMONDFILL: |
||
1546 | /* |
||
1547 | @ diamondfill x0,y0,dx,dy,color |
||
1548 | @ x0,y0 in xrange / yrange |
||
1549 | @ distances dx,dy in pixels |
||
13936 | bpr | 1550 | @ there is also a command <a href="#userdraw">userdraw diamondfill,color</a> |
12110 | schaersvoo | 1551 | @%diamondfill%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%circles red,-4,0,6,4,0,6%linewidth 1%diamondfill 0,0,5,8,blue%diamondfill 0,7,8,8,lightgreen |
11806 | schaersvoo | 1552 | */ |
15111 | schaersvoo | 1553 | js_function[DRAW_DIAMONDFILL] = 1; |
11820 | schaersvoo | 1554 | if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */ |
1555 | js_function[DRAW_FILLTOBORDER] = 1; |
||
15111 | schaersvoo | 1556 | add_js_filltoborder(canvas_type); |
11820 | schaersvoo | 1557 | } |
1558 | decimals = find_number_of_digits(precision); |
||
7614 | schaersvoo | 1559 | for(i=0;i<5;i++){ |
1560 | switch(i){ |
||
11820 | schaersvoo | 1561 | case 0: double_data[0] = get_real(infile,0); break; /* x */ |
14032 | schaersvoo | 1562 | case 1: double_data[1] = get_real(infile,0); break; /* y */ |
11820 | schaersvoo | 1563 | case 2: int_data[0] = (int) (get_real(infile,0)); break; /* dx pixel */ |
1564 | case 3: int_data[1] = (int) (get_real(infile,0)); break; /* dy pixel*/ |
||
11806 | schaersvoo | 1565 | case 4: stroke_color = get_color(infile,1); |
15111 | schaersvoo | 1566 | if(use_rotate == TRUE ){rotate(2,angle,rotationcenter,2);} |
1567 | if(use_affine == TRUE ){ transform(2,2);} |
||
11806 | schaersvoo | 1568 | /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */ |
14208 | schaersvoo | 1569 | string_length = 1 + snprintf(NULL,0, "draw_diamondfill(%d,%.*f,%.*f,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS+fill_cnt,decimals,double_data[0],decimals,double_data[1],int_data[0],int_data[1],line_width,stroke_color,stroke_opacity,xsize,ysize); |
1570 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11820 | schaersvoo | 1571 | snprintf(tmp_buffer,string_length,"draw_diamondfill(%d,%.*f,%.*f,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS+fill_cnt,decimals,double_data[0],decimals,double_data[1],int_data[0],int_data[1],line_width,stroke_color,stroke_opacity,xsize,ysize); |
11806 | schaersvoo | 1572 | add_to_buffer(tmp_buffer); |
11820 | schaersvoo | 1573 | fill_cnt++; |
15111 | schaersvoo | 1574 | reset(); |
11806 | schaersvoo | 1575 | break; |
1576 | default:break; |
||
1577 | } |
||
1578 | } |
||
1579 | break; |
||
8224 | bpr | 1580 | |
11806 | schaersvoo | 1581 | case DOTFILL: |
1582 | /* |
||
1583 | @ dotfill x0,y0,dx,dy,color |
||
1584 | @ x0,y0 in xrange / yrange |
||
1585 | @ distances dx,dy in pixels |
||
1586 | @ radius of dots is linewidth |
||
13936 | bpr | 1587 | @ there is also a command <a href="#userdraw">userdraw dotfill,color</a> |
12110 | schaersvoo | 1588 | @%dotfill%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%circles red,-4,0,6,4,0,6%dotfill 0,0,5,8,blue%dotfill 0,7,8,8,lightgreen |
11806 | schaersvoo | 1589 | */ |
15111 | schaersvoo | 1590 | js_function[DRAW_DOTFILL] = 1; |
11817 | schaersvoo | 1591 | if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */ |
1592 | js_function[DRAW_FILLTOBORDER] = 1; |
||
15111 | schaersvoo | 1593 | add_js_filltoborder(canvas_type); |
11817 | schaersvoo | 1594 | } |
1595 | decimals = find_number_of_digits(precision); |
||
11806 | schaersvoo | 1596 | for(i=0;i<5;i++){ |
1597 | switch(i){ |
||
11817 | schaersvoo | 1598 | case 0: double_data[0] = get_real(infile,0); break; /* x in px */ |
1599 | case 1: double_data[1] = get_real(infile,0); break; /* y in py */ |
||
1600 | case 2: int_data[0] = (int) (get_real(infile,0)); break; /* dx pixel */ |
||
1601 | case 3: int_data[1] = (int) (get_real(infile,0)); break; /* dy pixel*/ |
||
11806 | schaersvoo | 1602 | case 4: stroke_color = get_color(infile,1); |
15111 | schaersvoo | 1603 | if(use_rotate == TRUE ){rotate(2,angle,rotationcenter,2);} |
1604 | if(use_affine == TRUE ){ transform(2,2);} |
||
11806 | schaersvoo | 1605 | /* draw_dotfill(ctx,x0,y0,dx,dy,radius,color,opacity,xsize,ysize) */ |
14208 | schaersvoo | 1606 | string_length = 1 + snprintf(NULL,0, "draw_dotfill(%d,%.*f,%.*f,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",FILL_CANVAS+fill_cnt,decimals,double_data[0],decimals,double_data[1],int_data[0],int_data[1],line_width,stroke_color,stroke_opacity,xsize,ysize); |
1607 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11817 | schaersvoo | 1608 | snprintf(tmp_buffer,string_length,"draw_dotfill(%d,%.*f,%.*f,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",FILL_CANVAS+fill_cnt,decimals,double_data[0],decimals,double_data[1],int_data[0],int_data[1],line_width,stroke_color,stroke_opacity,xsize,ysize); |
11806 | schaersvoo | 1609 | add_to_buffer(tmp_buffer); |
11817 | schaersvoo | 1610 | fill_cnt++; |
15111 | schaersvoo | 1611 | reset(); |
7614 | schaersvoo | 1612 | break; |
11806 | schaersvoo | 1613 | default:break; |
7614 | schaersvoo | 1614 | } |
1615 | } |
||
11806 | schaersvoo | 1616 | break; |
1617 | |||
1618 | case DRAG: |
||
1619 | /* |
||
1620 | @ drag [x][y][xy] |
||
1621 | @ the next object will be draggable in x / y / xy direction |
||
14077 | bpr | 1622 | @ the displacement can be read by <code>javascript:read_dragdrop();</code> |
15111 | schaersvoo | 1623 | @ the precision (default 2 decimals) in the student reply may be set with command <a href="#precision">precision</a>.<br />Use this 'precision' command before this command 'drag x|y|xy' ! |
14078 | bpr | 1624 | @ <a href='#onclick'>onclick</a> and ''drag x|y|xy`` may be combined (for different objects: a single object can either be onclick or drag, not both ) |
14077 | bpr | 1625 | @ ''multi_objects`` will be numbered in the given x/y-sequence (example: points red,0,0,1,1,2,2,3,3: point (0:0) is object_number 1) |
15313 | schaersvoo | 1626 | @ <b>attention</b>: static objects and ''onclick/drag`` objects of the same type (like point,circle,etc) with the same coordinates (e.g. objects that overlap) will give problems in the ''recognition algorithm``) in this example<br /> <code>linewidth 4<br />point 0,0,red<br />drag xy<br />point 0,0,blue</code><br />the red point will not be recognised as draggable ! in the example<br /><code>linewidth 4<br />drag xy<br />point 0,0,red<br />drag xy<br />point 0,0,blue</code><br />both points will be recognised |
14066 | bpr | 1627 | @ the answer is: drag_or_onclick_object_number : Xorg : Yorg : Xnew : Ynew<br />wherein object_number is the sequence number of the draggable & onclick objects in your script.<br />Only draggable & onclick objects will have an object_number (e.g things like point,crosshair,line,segment,circle,rect,triangle...etc) |
15650 | reyssat | 1628 | @ use keyword <a href='#snaptogrid'>snaptogrid</a>, <a href='#xsnaptogrid'>xsnaptogrid</a>, <a href='#ysnaptogrid'>ysnaptogrid</a> or command <a href='#snaptopoints'>snaptopoints x1,y1,x2,y2,...</a> to switch from free to discrete movement |
11806 | schaersvoo | 1629 | @ in case of external images (commands copy / copyresized) the external image can be set draggable ; always xy. <br />The function javascript;read_canvas() will return the xy-coordinates of all images. |
13829 | bpr | 1630 | @%drag_x%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor lightblue%opacity 200,40%drag x%linewidth 2%circles blue,-5,0,3,0,0,2,5,0,4,0,4,3,0,-3,4 |
1631 | @%drag_y%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor lightblue%opacity 200,40%drag y%linewidth 2%circles blue,-5,0,3,0,0,2,5,0,4,0,4,3,0,-3,4 |
||
1632 | @%drag_xy%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor lightblue%opacity 200,40%drag xy%linewidth 2%circles blue,-5,0,3,0,0,2,5,0,4,0,4,3,0,-3,4 |
||
11806 | schaersvoo | 1633 | */ |
1634 | temp = get_string(infile,1); |
||
1635 | if(strstr(temp,"xy") != NULL ){ |
||
1636 | drag_type = 0; |
||
1637 | } |
||
1638 | else |
||
1639 | { |
||
1640 | if(strstr(temp,"x") != NULL ){ |
||
1641 | drag_type = 1; |
||
1642 | } |
||
1643 | else |
||
1644 | { |
||
1645 | drag_type = 2; |
||
1646 | } |
||
1647 | } |
||
1648 | /* assuming all drag&drop coordinates the same precision: so set only once */ |
||
1649 | if( print_drag_params_only_once == FALSE ){ |
||
15111 | schaersvoo | 1650 | fprintf(js_include_file,"dragdrop_precision = %d;use_dragdrop_reply = true;",precision); |
11806 | schaersvoo | 1651 | print_drag_params_only_once = TRUE; |
1652 | } |
||
1653 | onclick = 2; |
||
1654 | /* if(use_userdraw == TRUE ){canvas_error("\"drag & drop\" may not be combined with \"userdraw\" or \"pan and zoom\" \n");} */ |
||
15111 | schaersvoo | 1655 | use_dragstuff = 2; |
1656 | js_function[INTERACTIVE] = 1; |
||
7614 | schaersvoo | 1657 | break; |
8386 | schaersvoo | 1658 | |
11806 | schaersvoo | 1659 | case ELLIPSE: |
8351 | schaersvoo | 1660 | /* |
11806 | schaersvoo | 1661 | @ ellipse xc,yc,radius_x,radius_y,color |
15111 | schaersvoo | 1662 | @ ellipses with center xc/yc and radius in x/y-range etc (this differs from flydraw syntax!) |
11806 | schaersvoo | 1663 | @ radius_x and radius_y are in pixels |
9406 | schaersvoo | 1664 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
11806 | schaersvoo | 1665 | @ will shrink / expand on zoom out / zoom in |
13949 | schaersvoo | 1666 | @%ellipse%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor orange%opacity 200,40%linewidth 3%drag xy%ellipse 0,0,6,4,green%zoom blue |
8351 | schaersvoo | 1667 | */ |
11806 | schaersvoo | 1668 | for(i=0;i<5;i++){ |
1669 | switch(i){ |
||
1670 | case 0:double_data[0] = get_real(infile,0);break; /* x-values */ |
||
1671 | case 1:double_data[1] = get_real(infile,0);break; /* y-values */ |
||
14066 | bpr | 1672 | case 2:double_data[2] = get_real(infile,0);break; /* rx -> px */ |
1673 | case 3:double_data[3] = get_real(infile,0);break; /* ry -> px */ |
||
11806 | schaersvoo | 1674 | case 4:stroke_color = get_color(infile,1);/* name or hex color */ |
15111 | schaersvoo | 1675 | if(use_rotate == TRUE ){rotate(2,angle,rotationcenter,4);} |
1676 | if(use_affine == TRUE ){ transform(2,4);} |
||
1677 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
11806 | schaersvoo | 1678 | decimals = find_number_of_digits(precision); |
15111 | schaersvoo | 1679 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,3,[%.*f],[%.*f],[%.*f],[%.*f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[1],decimals,double_data[2],decimals,double_data[3],line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
1680 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
1681 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,3,[%.*f],[%.*f],[%.*f],[%.*f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[1],decimals,double_data[2],decimals,double_data[3],line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
1682 | add_to_buffer(tmp_buffer); |
||
1683 | if(onclick != 0){object_cnt++;}/* object_cnt++; */ |
||
1684 | dragstuff[3] = 1; |
||
1685 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
11806 | schaersvoo | 1686 | reset(); |
1687 | break; |
||
1688 | } |
||
1689 | } |
||
1690 | break; |
||
13829 | bpr | 1691 | |
12110 | schaersvoo | 1692 | case ELLIPSES: |
1693 | /* |
||
1694 | @ ellipses color,xc1,yc1,radius_x1,radius_y1,xc2,yc2,radius_x2,radius_y2,xc3,yc3,radius_x3,radius_y3,... |
||
15111 | schaersvoo | 1695 | @ ellipses with center and radius in x/y-range etc (this differs from flydraw syntax!) |
12110 | schaersvoo | 1696 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
1697 | @ will shrink / expand on zoom out / zoom in |
||
13949 | schaersvoo | 1698 | @%ellipses%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor orange%opacity 200,40%linewidth 3%onclick%ellipses red,-3,0,2,4,0,0,4,2,3,0,6,2 |
12110 | schaersvoo | 1699 | */ |
13829 | bpr | 1700 | |
15111 | schaersvoo | 1701 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
12110 | schaersvoo | 1702 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
1703 | fill_color = stroke_color; |
||
1704 | i=1; |
||
1705 | while( ! done ){ /* get next item until EOL*/ |
||
1706 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
||
1707 | switch (i%4){ |
||
1708 | case 1:double_data[i-1] = get_real(infile,0);break; /* x */ |
||
1709 | case 2:double_data[i-1] = get_real(infile,0);break; /* y */ |
||
1710 | case 3:double_data[i-1] = get_real(infile,0);break; /* rx */ |
||
1711 | case 0:double_data[i-1] = get_real(infile,1);break; /* ry */ |
||
1712 | default: break; |
||
1713 | } |
||
1714 | i++; |
||
1715 | } |
||
15111 | schaersvoo | 1716 | if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,4);} |
1717 | if(use_affine == TRUE ){ transform(i-1,4);} |
||
12110 | schaersvoo | 1718 | decimals = find_number_of_digits(precision); |
1719 | for(c = 0 ; c < i-1 ; c = c+4){ |
||
15111 | schaersvoo | 1720 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,3,[%.*f],[%.*f],[%.*f],[%.*f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[c],decimals,double_data[c+1],decimals,double_data[c+2],decimals,double_data[c+3],line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
1721 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
1722 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,3,[%.*f],[%.*f],[%.*f],[%.*f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[c],decimals,double_data[c+1],decimals,double_data[c+2],decimals,double_data[c+3],line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
1723 | add_to_buffer(tmp_buffer); |
||
1724 | if(onclick != 0){object_cnt++;} /* object_cnt++; */ |
||
12110 | schaersvoo | 1725 | } |
1726 | reset(); |
||
15111 | schaersvoo | 1727 | dragstuff[3] = 1; |
1728 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
12110 | schaersvoo | 1729 | break; |
1730 | |||
11806 | schaersvoo | 1731 | case FILLALL: |
1732 | /* |
||
1733 | @ fillall color,x1,y1,x2,y2...x_n,y_n |
||
15111 | schaersvoo | 1734 | @ fill all region containing points (x1:y1),(x2:y2)...(x_n:y_n) with color 'color' |
15650 | reyssat | 1735 | @ any other colors (objects) in the <a href="#canvastype">canvastype</a> will act as border to the bucket fill |
14246 | bpr | 1736 | @ use this command after all boundary objects are declared. |
15111 | schaersvoo | 1737 | @ Use command 'userdraw clickfill,color' for user click driven flood fill. |
1738 | @ use command <a href="#canvastype">canvastype </a> to fill another canvas (default should be fine: DRAG_CANVAS = 5) |
||
14071 | bpr | 1739 | @ note: the fill-family of commands are very (client) cpu intensive operations!<br />filling is done pixel by pixel e.g. image size of 400x400 uses 160000 pixels: each pixel contains 4 data (R,G,B,Opacity) = 640000 data.<br />on every data a few operations / comparisons are done...<br />So have pity on your students CPU.. |
12110 | schaersvoo | 1740 | @%fillall%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%vlines black,-5,0,-5,0,-4,0,-4,0,3,0,3,0%hlines black,-5,0,-5,0,-5,4,-5,4,-5,-2,-5,-2%circles green,0,0,2,3,3,5,-5,-5,3%opacity 240,50%fillall blue,1,1,8,8,-8,-8 |
11806 | schaersvoo | 1741 | */ |
1742 | decimals = find_number_of_digits(precision); |
||
1743 | fill_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
8351 | schaersvoo | 1744 | i=0; |
11806 | schaersvoo | 1745 | if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */ |
1746 | js_function[DRAW_FILLTOBORDER] = 1; |
||
15111 | schaersvoo | 1747 | add_js_filltoborder(canvas_type); |
11806 | schaersvoo | 1748 | } |
8351 | schaersvoo | 1749 | while( ! done ){ /* get next item until EOL*/ |
11997 | schaersvoo | 1750 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
8351 | schaersvoo | 1751 | if(i%2 == 0 ){ |
1752 | double_data[i] = get_real(infile,0); /* x */ |
||
1753 | } |
||
1754 | else |
||
1755 | { |
||
1756 | double_data[i] = get_real(infile,1); /* y */ |
||
14208 | schaersvoo | 1757 | string_length = 1 + snprintf(NULL,0, "setTimeout(function(){filltoborder(%.*f,%.*f,[%s,%d],[%s,%d],%d,false,null);},1000);\n",decimals,double_data[i-1],decimals,double_data[i],fill_color,(int) (fill_opacity/0.0039215),fill_color,(int) (fill_opacity/0.0039215),FILL_CANVAS+fill_cnt); |
1758 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11818 | schaersvoo | 1759 | snprintf(tmp_buffer,string_length,"setTimeout(function(){filltoborder(%.*f,%.*f,[%s,%d],[%s,%d],%d,false,null);},1000);\n",decimals,double_data[i-1],decimals,double_data[i],fill_color,(int) (fill_opacity/0.0039215),fill_color,(int) (fill_opacity/0.0039215),FILL_CANVAS+fill_cnt); |
11806 | schaersvoo | 1760 | add_to_buffer(tmp_buffer); |
1761 | fill_cnt++; |
||
8351 | schaersvoo | 1762 | } |
1763 | i++; |
||
1764 | } |
||
11806 | schaersvoo | 1765 | break; |
1766 | |||
1767 | case FILLED: |
||
1768 | /* |
||
1769 | @ filled |
||
1770 | @ keyword (no arguments required) |
||
14077 | bpr | 1771 | @ the next ''fillable`` object (only the next !) will be filled |
14066 | bpr | 1772 | @ use command <a href="#fillcolor">fillcolor color</a> to set fillcolor |
11839 | schaersvoo | 1773 | @ use <a href="#fillpattern">fillpattern</a> for non-solid color filling. |
14086 | bpr | 1774 | @ use command <code>opacity 0-255,0-255</code> to set stroke and fill-opacity |
14066 | bpr | 1775 | @ use command <a href='#fill'>fill x,y,color</a> or <a href="#floodfill">floodfill x,y,color</a> to fill the space around (x;y) with color <br />pixel operation implemented in javascript: use with care ! |
11806 | schaersvoo | 1776 | */ |
11839 | schaersvoo | 1777 | use_filled = 1; |
11806 | schaersvoo | 1778 | break; |
1779 | |||
1780 | case FILLCOLOR: |
||
1781 | /* |
||
1782 | @ fillcolor colorname or #hex |
||
15111 | schaersvoo | 1783 | @ set the color: mainly used for command 'userdraw obj,stroke_color' |
11806 | schaersvoo | 1784 | @ all fillable massive objects will have a fillcolor == strokecolor (just to be compatible with flydraw...) |
11839 | schaersvoo | 1785 | @ see <a href="#fillpattern">fillpattern</a> for non-solid color filling. |
11806 | schaersvoo | 1786 | */ |
1787 | fill_color = get_color(infile,1); |
||
1788 | break; |
||
1789 | |||
11837 | schaersvoo | 1790 | case FILLPATTERN: |
1791 | /* |
||
15601 | schaersvoo | 1792 | @ fillpattern grid | hatch | diamond | dot | image_url |
15715 | schaersvoo | 1793 | @ alternative: settile image_url |
11837 | schaersvoo | 1794 | @ use a pattern as fillstyle |
14066 | bpr | 1795 | @ suitable for all fillable object including the <a href="#userdraw">userdraw objects' family</a> |
15601 | schaersvoo | 1796 | @ note: do not use the ''f`` for a fillable object : this is used exclusively for solid colour filling. |
14066 | bpr | 1797 | @ the fillcolor is set by the object command, for example:<br /><code>size 370,370<br />xrange -5,5<br />yrange -5,5<br />opacity 165,150<br />fillpattern grid<br />fcircle -6,3,160,blue<br />fillpattern dot<br />fcircle -3,-3,160,red<br />fillpattern hatch<br />fcircle 0,3,160,green<br />filpattern diamond<br />fcircle 3,-3,160,cyan<br />userdraw dotfill,blue<br />zoom red</code> |
14078 | bpr | 1798 | @ the pattern dimensions are hardcoded (linewidth, radius,dx,dy are fixed) |
11837 | schaersvoo | 1799 | @ the pattern color is set by command <a href='#fillcolor'>fillcolor</a> and <a href='#opacity'>opacity</a> |
11839 | schaersvoo | 1800 | @ see <a href="#fillcolor">fillcolor</a> for solid color filling. |
15111 | schaersvoo | 1801 | @ when using an image-url, make sure it contains an ''/`` in the filename...''fillpattern $module_dir/gifs/test.jpg`` will fill the next fillable object with this image.|<br />the argument to html5 canvas routine 'createPattern(img,argument)' is set to ''repeat`` e.g. if the image is smaller then the canvas, multiple copies will be used to fill the area ( e.g. ctx.fillStyle() = pattern)<br />for example:<br /><code>size 150,150<br />xrange -5,5<br />yrange -5,5<br />drag xy<br />fillpattern gifs/en.gif<br />fcircle 0,0,100,red<br />fillpattern gifs/nl.gif<br />drag xy<br />fcircle -3,2,100,green<br />fillpattern gifs/cn.gif<br />drag xy<br />fcircle 3,2,100,green</code> |
1802 | @ fillpattern is also active for <a href="#userdraw">userdraw object,color</a>...<br />the userdraw family a has also ''clickfill type`` (e.g. an object gets filled between boundaries, when clicked) commands like:<br />'userdraw dotfill,color'<br />'userdraw hatchfill,color' etc |
||
1803 | @%fillpattern_1%size 400,400%xrange -5,5%yrange -5,5%opacity 165,150%fillpattern grid%circle -6,3,160,blue%fillpattern dot%circle -3,-3,160,red%fillpattern hatch%circle 0,3,160,green%filpattern diamond%circle 3,-3,160,cyan%zoom red |
||
1804 | @%fillpattern_2%size 400,400%xrange -10,10%yrange -10,10%linewidth 3%fillcolor green%fillpattern hatch%#fillpattern dot,diamond,grid,imageurl%userdraw circle,red |
||
11837 | schaersvoo | 1805 | */ |
1806 | temp = get_string(infile,1); |
||
15111 | schaersvoo | 1807 | use_filled = 0; |
1808 | js_function[DRAW_FILL_PATTERN] = 1; |
||
15116 | bpr | 1809 | if( strstr(temp,"grid") != 0 ){ use_filled = 2;} |
15111 | schaersvoo | 1810 | else{ |
1811 | if( strstr(temp,"hatch") != 0 ){ use_filled = 3;} |
||
1812 | else{ |
||
1813 | if( strstr(temp,"diamond") != 0 ){ use_filled = 4;} |
||
1814 | else{ |
||
1815 | if( strstr(temp,"dot") != 0 ){ use_filled = 5;} |
||
1816 | else{ |
||
15600 | schaersvoo | 1817 | if( strstr(temp,"/") != 0 ){ /* get_image_from_url() needs to be called after function definition...*/ |
1818 | use_filled = 6;js_function[JS_LOAD_IMAGE] = 1; |
||
1819 | string_length = 1 + snprintf(NULL,0,"get_image_from_url(\"%s\");",temp); |
||
1820 | check_string_length(string_length); |
||
1821 | tmp_buffer = my_newmem(string_length); |
||
1822 | snprintf(tmp_buffer,string_length,"get_image_from_url(\"%s\");",temp); |
||
1823 | add_to_buffer(tmp_buffer); |
||
1824 | } |
||
15111 | schaersvoo | 1825 | } |
1826 | } |
||
1827 | } |
||
1828 | } |
||
1829 | if( use_filled == 0 ){canvas_error("fillpattern unknown or typo...choose grid,hatch,diamond of dot...");} |
||
11837 | schaersvoo | 1830 | break; |
11806 | schaersvoo | 1831 | case FILLTOBORDER: |
1832 | /* |
||
1833 | @ filltoborder x,y,bordercolor,color |
||
15111 | schaersvoo | 1834 | @ fill the region of point (x:y) with color 'color' |
11806 | schaersvoo | 1835 | @ any other color will not act as border to the bucket fill |
14246 | bpr | 1836 | @ use this command after all boundary objects are declared. |
11806 | schaersvoo | 1837 | @ use command <a href="#canvastype">canvastype </a> to fill another canvas (default should be fine: DRAG_CANVAS = 5) |
14071 | bpr | 1838 | @ note: filltoborder is a very (client) cpu intensive operation!<br />filling is done pixel by pixel e.g. image size of 400x400 uses 160000 pixels: each pixel contains 4 data (R,G,B,Opacity) = 640000 data.<br />on every data a few operations / comparisons are done...<br />So have pity on your students CPU.. |
11806 | schaersvoo | 1839 | @ maybe used together with command <a href="#userdraw">userdraw clickfill,color</a> |
12110 | schaersvoo | 1840 | @%filltoborder%size 400,400%xrange -10,10%yrange -10,10%canvastype 100%linewidth 2%precision 1000%jsplot blue,5*sin(x)%opacity 200,50%filltoborder 6,6,blue,blue%filltoborder 6,-6,blue,red |
11806 | schaersvoo | 1841 | */ |
1842 | for(i=0 ;i < 4 ; i++){ |
||
1843 | switch(i){ |
||
1844 | case 0:double_data[0] = get_real(infile,0);break; |
||
1845 | case 1:double_data[1] = get_real(infile,0);break; |
||
1846 | case 2:bgcolor = get_color(infile,0);break; |
||
1847 | case 3:fill_color = get_color(infile,1); |
||
1848 | if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */ |
||
15111 | schaersvoo | 1849 | js_function[DRAW_FILLTOBORDER] = 1; |
1850 | add_js_filltoborder(canvas_type); |
||
11806 | schaersvoo | 1851 | } |
1852 | decimals = find_number_of_digits(precision); |
||
1853 | /* we need to set a timeout: the canvas is not yet draw in memory? when floodfill is called directly... */ |
||
14208 | schaersvoo | 1854 | string_length = 1 + snprintf(NULL,0, "setTimeout(function(){filltoborder(%.*f,%.*f,[%s,%d],[%s,%d],%d,false,null);},1000);\n",decimals,double_data[0],decimals,double_data[1],bgcolor,(int) (fill_opacity/0.0039215),fill_color,(int) (fill_opacity/0.0039215),FILL_CANVAS+fill_cnt); |
1855 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11818 | schaersvoo | 1856 | snprintf(tmp_buffer,string_length,"setTimeout(function(){filltoborder(%.*f,%.*f,[%s,%d],[%s,%d],%d,false,null);},1000);\n",decimals,double_data[0],decimals,double_data[1],bgcolor,(int) (fill_opacity/0.0039215),fill_color,(int) (fill_opacity/0.0039215),FILL_CANVAS+fill_cnt); |
11806 | schaersvoo | 1857 | add_to_buffer(tmp_buffer); |
1858 | fill_cnt++; |
||
15111 | schaersvoo | 1859 | reset(); |
11806 | schaersvoo | 1860 | break; |
1861 | default:break; |
||
8351 | schaersvoo | 1862 | } |
11806 | schaersvoo | 1863 | } |
1864 | break; |
||
1865 | case FLOODFILL: |
||
1866 | /* |
||
1867 | @ floodfill x,y,color |
||
15715 | schaersvoo | 1868 | @ alternative: fill |
15111 | schaersvoo | 1869 | @ fill the region of point (x:y) with color 'color' |
11806 | schaersvoo | 1870 | @ any other color or size of picture (borders of picture) will act as border to the bucket fill |
14246 | bpr | 1871 | @ use this command after all boundary objects are declared. |
14077 | bpr | 1872 | @ Use command <code>userdraw clickfill,color</code> for user click driven flood fill. |
11806 | schaersvoo | 1873 | @ use command <a href="#canvastype">canvastype </a> to fill another canvas (default should be fine: DRAG_CANVAS = 5) |
14071 | bpr | 1874 | @ note: floodfill is a very (client) cpu intensive operation!<br />filling is done pixel by pixel e.g. image size of 400x400 uses 160000 pixels: each pixel contains 4 data (R,G,B,Opacity) = 640000 data.<br />on every data a few operations / comparisons are done...<br />So have pity on your students CPU.. |
12110 | schaersvoo | 1875 | @%floodfill%size 400,400%xrange -10,10%yrange -10,10%canvastype 100%linewidth 2%precision 1000%jsplot blue,5*sin(x)%opacity 200,50%floodfill 6,6,blue%floodfill 6,-6,red |
11806 | schaersvoo | 1876 | */ |
1877 | for(i=0 ;i < 4 ; i++){ |
||
1878 | switch(i){ |
||
1879 | case 0:double_data[0] = get_real(infile,0);break; |
||
1880 | case 1:double_data[1] = get_real(infile,0);break; |
||
1881 | case 2:fill_color = get_color(infile,1); |
||
1882 | if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */ |
||
15111 | schaersvoo | 1883 | js_function[DRAW_FILLTOBORDER] = 1; |
1884 | add_js_filltoborder(canvas_type); |
||
11806 | schaersvoo | 1885 | } |
1886 | decimals = find_number_of_digits(precision); |
||
1887 | /* we need to set a timeout: the canvas is not yet draw in memory? when floodfill is called directly... */ |
||
14208 | schaersvoo | 1888 | string_length = 1 + snprintf(NULL,0, "setTimeout(function(){filltoborder(%.*f,%.*f,[%s,%d],[%s,%d],%d,false,null);},1000);\n",decimals,double_data[0],decimals,double_data[1],fill_color,(int) (fill_opacity/0.0039215),fill_color,(int) (fill_opacity/0.0039215),FILL_CANVAS+fill_cnt); |
1889 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11818 | schaersvoo | 1890 | snprintf(tmp_buffer,string_length,"setTimeout(function(){filltoborder(%.*f,%.*f,[%s,%d],[%s,%d],%d,false,null);},1000);\n",decimals,double_data[0],decimals,double_data[1],fill_color,(int) (fill_opacity/0.0039215),fill_color,(int) (fill_opacity/0.0039215),FILL_CANVAS+fill_cnt); |
11806 | schaersvoo | 1891 | add_to_buffer(tmp_buffer); |
1892 | fill_cnt++; |
||
1893 | break; |
||
1894 | default:break; |
||
1895 | } |
||
1896 | } |
||
1897 | reset(); |
||
1898 | break; |
||
1899 | |||
1900 | case FONTCOLOR: |
||
1901 | /* |
||
1902 | @ fontcolor color |
||
1903 | @ color: hexcolor or colorname |
||
1904 | @ default: black |
||
15650 | reyssat | 1905 | @ use command <a href="#fontfamily">fontfamily</a> to deviate from default font type |
13956 | schaersvoo | 1906 | @%fontcolor%size 400,400%xrange -10,10%yrange -10,10%fontcolor red%#note: use command fontfamily to change size and shape%axis%axisnumbering%grid 2,2,grey,2,2,4,grey |
11806 | schaersvoo | 1907 | */ |
1908 | font_color = get_color(infile,1); |
||
1909 | break; |
||
1910 | |||
1911 | case FONTFAMILY: |
||
1912 | /* |
||
1913 | @ fontfamily font_description |
||
1914 | @ set the font family; for browsers that support it |
||
15313 | schaersvoo | 1915 | @ font_description: Arial, Courier, Helvetica etc |
1916 | @ in case commands <code>string color,x,y,the string</code>, <code>stringup color,x,y,rotation,the string</code>, ''fontfamily`` can be something like:<code>fontfamily italic 34pt Arial</code>. Use correct syntax: ''font style``, ''font size pt``, ''fontfamily`` |
||
1917 | @%fontfamily%size 400,400%xrange -10,10%yrange -10,10 %fontfamily Bold 10pt Arial%string blue,-9,9,10 pt Arial%fontfamily Italic 20pt Arial%string blue,0,9,20 pt Arial%fontfamily Bold 10pt Helvetica%string blue,-9,5,10 pt Helvetica%fontfamily Italic 20pt Helvetica%string blue,0,5,20 pt Helvetica %fontfamily Bold 10pt Courier%string blue,-9,0,10 pt Courier%fontfamily Italic 20pt Courier%string blue,0,0,20 pt Courier%fontfamily Bold 10pt Fixed%string blue,-9,-5,10 pt Fixed%fontfamily Italic 20pt Fixed%string blue,0,-5,20 pt Fixed %fontfamily Bold 10pt Times%string blue,-9,-9,10 pt Times%fontfamily Italic 20pt Times%string blue,0,-9,20 pt Times |
||
13959 | bpr | 1918 | |
11806 | schaersvoo | 1919 | */ |
1920 | font_family = get_string(infile,1); |
||
1921 | break; |
||
1922 | |||
1923 | case FONTSIZE: |
||
1924 | /* |
||
1925 | @ fontsize font_size |
||
1926 | @ default value 12 |
||
15111 | schaersvoo | 1927 | @ note: for some macros (like ''grid | legend | xaxistext | xlabel`` etc) sometimes command <a href="#fontfamily">fontfamily</a> can be used for some specific font-setting<br />this is however not always very straight forward... so just try and see what happens |
11806 | schaersvoo | 1928 | */ |
1929 | font_size = (int) (get_real(infile,1)); |
||
1930 | break; |
||
1931 | |||
1932 | case FUNCTION_LABEL: |
||
1933 | /* |
||
15313 | schaersvoo | 1934 | @ functionlabel label_1:label_2:label_3... |
15512 | bpr | 1935 | @ alternative: functionlabels |
15111 | schaersvoo | 1936 | @ default value ''f(x)=:g(x)=:h(x)=:i(x)=:j(x)=:k(x)=:m(x)=:n(x)=`` |
11806 | schaersvoo | 1937 | @ no mathml allowed (just ascii string) |
13956 | schaersvoo | 1938 | @ use command <a href='#fontsize'>fontsize int</a> to adjust the size |
1939 | @ use command <a href='#strokecolor'>strokecolor colorname</a> to adjust the labels (individually, if needed) |
||
14066 | bpr | 1940 | @ if needed, use before every command <a href='#userinput'>userinput function | inputfield | textarea</a> |
15111 | schaersvoo | 1941 | @ no limit in amount of inputfields for userbased function plotting |
15313 | schaersvoo | 1942 | @%function_label%size 400,400%xrange -5,5%yrange -5,5%precision 0%axis%axisnumbering%opacity 100,190%grid 1,1,grey,2,2,5,black%linewidth 3%linewidth 1%precision 1000%functionlabels F(x)=:H(x)=:Yield(x)=%strokecolor green%userinput function%strokecolor red%userinput function%strokecolor blue%userinput function |
11806 | schaersvoo | 1943 | */ |
15111 | schaersvoo | 1944 | temp = get_string_argument(infile,1); |
1945 | function_label = list2js_array(temp,":"); |
||
15116 | bpr | 1946 | |
11806 | schaersvoo | 1947 | break; |
1948 | |||
14078 | bpr | 1949 | case GRID:/* xmajor,ymajor,gridcolor [,xminor,yminor,tick length (px), axis/tickscolor]*/ |
11806 | schaersvoo | 1950 | /* |
1951 | @ grid step_x,step_y,gridcolor |
||
14177 | bpr | 1952 | @ if keywords <a href="#axis">axis</a> or <a href="#axisnumbering">axisnumbering</a> are set, use: <code>grid step_x,step_y,major_color,minor_x,minor_y,tics height in px,axis_color</code> minor x step = step_x / minor_x |
15313 | schaersvoo | 1953 | @ in that case, use command <a href="#fontcolor">fontcolor</a>, <a href="#fontsize">fontsize</a> and / or <a href="#fontfamily">fontfamily</a> to adjust font; defaults: black,12,Arial |
14071 | bpr | 1954 | @ if xmin > 0 and/or ymin > 0 and zooming / panning is not active: be aware that the x/y-axis numbering and x/y major/minor tic marks will not be visual as they are placed under the x-axis and left to the y-axis (in Quadrant II and IV) |
14066 | bpr | 1955 | @ can <b>not</b> be set <a href="#onclick">onclick</a> or <a href="#drag">drag xy</a> |
15313 | schaersvoo | 1956 | @ use commands <a href="#xlabel">xlabel some_string</a> and/or <a href="#ylabel">ylabel some_string</a> to label axis; use command ''fontsize`` to adjust size: the font family is non-configurable 'italic your_fontsize px Arial' ! |
1957 | @ see commands <a href="#xaxis">xaxis or xaxistext</a>, <a href="#yaxis">yaxis or yaxistext</a> to set tailormade values on axis (the used font is set by command <a href="#fontfamily">fontfamily</a>; default '12px Arial') |
||
1958 | @ see command <a href="#legend">legend</a> to set a legend for the graph; use command <a href="#fontsize">fontsize</a> to adjust size (the font family is non-configurable 'bold your_fontsize px Arial') |
||
12110 | schaersvoo | 1959 | @%grid%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%zoom red |
1960 | @%grid_axis%size 400,400%xrange -10,10%yrange -10,10%axis%grid 1,1,grey,2,2,6,black%zoom red |
||
15111 | schaersvoo | 1961 | @%grid_axis_axisnumbering%size 400,400%xrange -10,10%yrange -10,10%fontfamily Italic 14px Courier%axis%axisnumbering%precision 0%grid 1,1,grey,2,2,6,black%zoom red |
11806 | schaersvoo | 1962 | */ |
1963 | if( js_function[DRAW_YLOGSCALE] == 1 ){canvas_error("only one grid type is allowed...");} |
||
15111 | schaersvoo | 1964 | js_function[DRAW_GRID] = 1; |
11806 | schaersvoo | 1965 | for(i=0;i<4;i++){ |
1966 | switch(i){ |
||
1967 | case 0:double_data[0] = get_real(infile,0);break;/* xmajor */ |
||
1968 | case 1:double_data[1] = get_real(infile,0);break;/* ymajor */ |
||
1969 | case 2: |
||
1970 | if( use_axis == TRUE ){ |
||
1971 | stroke_color = get_color(infile,0); |
||
1972 | done = FALSE; |
||
1973 | int_data[0] = (int) (get_real(infile,0));/* xminor */ |
||
1974 | int_data[1] = (int) (get_real(infile,0));/* yminor */ |
||
1975 | int_data[2] = (int) (get_real(infile,0));/* tic_length */ |
||
1976 | fill_color = get_color(infile,1); /* used as axis_color*/ |
||
8351 | schaersvoo | 1977 | } |
1978 | else |
||
1979 | { |
||
11806 | schaersvoo | 1980 | int_data[0] = 1; |
1981 | int_data[1] = 1; |
||
1982 | stroke_color = get_color(infile,1); |
||
1983 | fill_color = stroke_color; |
||
8351 | schaersvoo | 1984 | } |
11806 | schaersvoo | 1985 | if( double_data[0] <= 0 || double_data[1] <= 0 || int_data[0] <= 0 || int_data[1] <= 0 ){canvas_error("major or minor ticks must be positive !");} |
1986 | /* set snap_x snap_y values in pixels */ |
||
1987 | fprintf(js_include_file,"snap_x = %f;snap_y = %f;",double_data[0] / int_data[0],double_data[1] / int_data[1]); |
||
15111 | schaersvoo | 1988 | fprintf(js_include_file,"\n/* add grid */function redraw_grid(){draw_grid%d(%d,%d,%.2f,%.*f,%.*f,%d,%d,%d,%d,\"%s\",\"%s\",%d,\"%s\",%d,%d,%d,%d,%d,\"%s\",%.2f);return;};",canvas_root_id,GRID_CANVAS,precision,stroke_opacity,decimals,double_data[0],decimals,double_data[1],int_data[0],int_data[1],int_data[2],line_width,stroke_color,fill_color,font_size,font_family,use_axis,use_axis_numbering,use_dashed,dashtype[0],dashtype[1],font_color,fill_opacity); |
1989 | string_length = 1 + snprintf(NULL,0, "redraw_grid();\n"); |
||
14208 | schaersvoo | 1990 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
15111 | schaersvoo | 1991 | snprintf(tmp_buffer,string_length, "redraw_grid();\n"); |
11806 | schaersvoo | 1992 | add_to_buffer(tmp_buffer); |
1993 | break; |
||
8351 | schaersvoo | 1994 | } |
1995 | } |
||
1996 | reset(); |
||
1997 | break; |
||
11806 | schaersvoo | 1998 | case GRIDFILL: |
1999 | /* |
||
2000 | @ gridfill x0,y0,dx,dy,color |
||
2001 | @ x0,y0 in xrange / yrange |
||
2002 | @ distances dx,dy in pixels |
||
13936 | bpr | 2003 | @ there is also a command <a href="#userdraw">userdraw gridfill,color</a> |
12110 | schaersvoo | 2004 | @%gridfill%size 400,400%xrange -10,10%yrange -10,10%canvastype 100%linewidth 2%precision 1000%jsplot blue,5*sin(x)%opacity 200,50%gridfill 6,6,10,10,blue%gridfill 6,-6,6,6,red |
2005 | |||
11806 | schaersvoo | 2006 | */ |
15111 | schaersvoo | 2007 | js_function[DRAW_GRIDFILL] = 1; |
11820 | schaersvoo | 2008 | decimals = find_number_of_digits(precision); |
2009 | if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */ |
||
2010 | js_function[DRAW_FILLTOBORDER] = 1; |
||
15111 | schaersvoo | 2011 | add_js_filltoborder(canvas_type); |
11820 | schaersvoo | 2012 | } |
11806 | schaersvoo | 2013 | for(i=0;i<5;i++){ |
2014 | switch(i){ |
||
11820 | schaersvoo | 2015 | case 0: double_data[0] = get_real(infile,0); break; /* x */ |
2016 | case 1: double_data[1] = get_real(infile,0); break; /* y */ |
||
2017 | case 2: int_data[0] = (int) (get_real(infile,0)); break; /* dx pixel */ |
||
2018 | case 3: int_data[1] = (int) (get_real(infile,0)); break; /* dy pixel*/ |
||
11806 | schaersvoo | 2019 | case 4: stroke_color = get_color(infile,1); |
14208 | schaersvoo | 2020 | string_length = 1 + snprintf(NULL,0, "draw_gridfill(%d,%.*f,%.*f,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS+fill_cnt,decimals,double_data[0],decimals,double_data[1],int_data[0],int_data[1],line_width,stroke_color,stroke_opacity,xsize,ysize); |
2021 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11820 | schaersvoo | 2022 | snprintf(tmp_buffer,string_length,"draw_gridfill(%d,%.*f,%.*f,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS+fill_cnt,decimals,double_data[0],decimals,double_data[1],int_data[0],int_data[1],line_width,stroke_color,stroke_opacity,xsize,ysize); |
11806 | schaersvoo | 2023 | add_to_buffer(tmp_buffer); |
11820 | schaersvoo | 2024 | fill_cnt++; |
15111 | schaersvoo | 2025 | reset(); |
11806 | schaersvoo | 2026 | break; |
2027 | default:break; |
||
2028 | } |
||
2029 | } |
||
2030 | break; |
||
8386 | schaersvoo | 2031 | |
8244 | schaersvoo | 2032 | case HALFLINE: |
2033 | /* |
||
2034 | @ demiline x1,y1,x2,y2,color |
||
15715 | schaersvoo | 2035 | @ alternative: halfline |
15111 | schaersvoo | 2036 | @ draws a halfline starting in (x1:y1) and through (x2:y2) in color 'color' (colorname or hex) |
9406 | schaersvoo | 2037 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
12110 | schaersvoo | 2038 | @%halfline%size 400,400%xrange -10,10%yrange -10,10%halfline -5,5,0,0,red%halfline -5,-5,0,0,blue |
8244 | schaersvoo | 2039 | */ |
2040 | for(i=0;i<5;i++){ |
||
2041 | switch(i){ |
||
2042 | case 0: double_data[0]= get_real(infile,0);break; /* x-values */ |
||
2043 | case 1: double_data[1]= get_real(infile,0);break; /* y-values */ |
||
2044 | case 2: double_data[10]= get_real(infile,0);break; /* x-values */ |
||
2045 | case 3: double_data[11]= get_real(infile,0);break; /* y-values */ |
||
2046 | case 4: stroke_color=get_color(infile,1);/* name or hex color */ |
||
2047 | if(double_data[0] == double_data[10]){ /* vertical halfline */ |
||
2048 | if(double_data[1] < double_data[11]){ |
||
2049 | double_data[3] = ymax + 1000; |
||
2050 | } |
||
2051 | else |
||
2052 | { |
||
2053 | double_data[3] = ymin - 1000; |
||
2054 | } |
||
10953 | bpr | 2055 | double_data[2] = double_data[0]; |
8244 | schaersvoo | 2056 | } |
2057 | else |
||
2058 | { /* horizontal halfline*/ |
||
2059 | if( double_data[1] == double_data[11] ){ |
||
2060 | if( double_data[0] < double_data[10] ){ |
||
2061 | double_data[2] = xmax + 1000; /* halfline to the right */ |
||
2062 | } |
||
2063 | else |
||
2064 | { |
||
2065 | double_data[2] = xmin - 1000; /* halfline to the left */ |
||
2066 | } |
||
2067 | double_data[3] = double_data[1]; |
||
2068 | } |
||
2069 | else |
||
2070 | { |
||
2071 | /* any other halfline */ |
||
2072 | /* slope */ |
||
2073 | double_data[12] = (double_data[11] - double_data[1])/(double_data[10] - double_data[0]); |
||
2074 | /* const */ |
||
2075 | double_data[13] = double_data[1] - double_data[12]*double_data[0]; |
||
2076 | if( double_data[0] < double_data[10] ){ |
||
2077 | double_data[2] = double_data[2] + 1000; |
||
2078 | } |
||
2079 | else |
||
2080 | { |
||
2081 | double_data[2] = double_data[2] - 1000; |
||
2082 | } |
||
2083 | double_data[3] = double_data[12]*double_data[2] + double_data[13]; |
||
2084 | } |
||
10953 | bpr | 2085 | } |
15111 | schaersvoo | 2086 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
2087 | if(use_rotate == TRUE ){rotate(4,angle,rotationcenter,2);} |
||
2088 | if(use_affine == TRUE ){ transform(4,2);} |
||
2089 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,18,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[2],decimals,double_data[1],decimals,double_data[3],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
2090 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
2091 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,18,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[2],decimals,double_data[1],decimals,double_data[3],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
2092 | add_to_buffer(tmp_buffer); |
||
2093 | if(onclick != 0){object_cnt++;} |
||
2094 | /* object_cnt++; */ |
||
8379 | schaersvoo | 2095 | reset(); |
8244 | schaersvoo | 2096 | break; |
2097 | } |
||
2098 | } |
||
15111 | schaersvoo | 2099 | dragstuff[18] = 1; |
2100 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
8244 | schaersvoo | 2101 | break; |
8386 | schaersvoo | 2102 | |
8365 | schaersvoo | 2103 | case HALFLINES: |
2104 | /* |
||
2105 | @ demilines color,x1,y1,x2,y2,.... |
||
15715 | schaersvoo | 2106 | @ alternative: halflines |
15111 | schaersvoo | 2107 | @ draws halflines starting in (x1:y1) and through (x2:y2) in color 'color' (colorname or hex) etc |
9406 | schaersvoo | 2108 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> indiviually |
12110 | schaersvoo | 2109 | @%halflines%size 400,400%xrange -10,10%yrange -10,10%halflines red,-5,5,0,0,-5,-5,0,0 |
8365 | schaersvoo | 2110 | */ |
2111 | stroke_color=get_color(infile,0); |
||
2112 | fill_color = stroke_color; |
||
2113 | i=0; |
||
2114 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 2115 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
8365 | schaersvoo | 2116 | if(i%2 == 0 ){ |
2117 | double_data[i] = get_real(infile,0); /* x */ |
||
2118 | } |
||
2119 | else |
||
2120 | { |
||
2121 | double_data[i] = get_real(infile,1); /* y */ |
||
2122 | } |
||
2123 | i++; |
||
2124 | } |
||
15111 | schaersvoo | 2125 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
8365 | schaersvoo | 2126 | decimals = find_number_of_digits(precision); |
2127 | for(c = 0 ; c < i-1 ; c = c+4){ |
||
2128 | if( double_data[c] == double_data[c+2] ){ /* vertical line*/ |
||
2129 | if(double_data[c+1] < double_data[c+3]){ /* upright halfline */ |
||
2130 | double_data[c+3] = ymax + 1000; |
||
2131 | } |
||
2132 | else |
||
2133 | { |
||
2134 | double_data[c+3] = ymin - 1000;/* descending halfline */ |
||
2135 | } |
||
2136 | } |
||
2137 | else |
||
2138 | { |
||
2139 | if( double_data[c+1] == double_data[c+3] ){ /* horizontal line */ |
||
2140 | if(double_data[c] < double_data[c+2] ){ /* halfline to the right */ |
||
2141 | double_data[c+2] = xmax+100; |
||
2142 | } |
||
2143 | else |
||
2144 | { |
||
2145 | double_data[c+2] = xmin-1000; /* halfline to the right */ |
||
2146 | } |
||
2147 | } |
||
2148 | else |
||
2149 | { |
||
2150 | /* m */ |
||
2151 | double m = (double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]); |
||
2152 | /* q */ |
||
2153 | double q = double_data[c+1] - ((double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]))*double_data[c]; |
||
2154 | if(double_data[c] < double_data[c+2]){ /* to the right */ |
||
14071 | bpr | 2155 | double_data[c+2] = xmax+1000; /* 1000 is needed for dragging...otherwise it is just segment */ |
8365 | schaersvoo | 2156 | double_data[c+3] = (m)*(double_data[c+2])+(q); |
2157 | } |
||
2158 | else |
||
2159 | { /* to the left */ |
||
2160 | double_data[c+2] = xmin - 1000; |
||
2161 | double_data[c+3] = (m)*(double_data[c+2])+(q); |
||
2162 | } |
||
2163 | } |
||
2164 | } |
||
15111 | schaersvoo | 2165 | if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);} |
2166 | if(use_affine == TRUE ){ transform(i-1,2);} |
||
2167 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,18,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[c],decimals,double_data[c+2],decimals,double_data[c+1],decimals,double_data[c+3],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
2168 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
2169 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,18,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[c],decimals,double_data[c+2],decimals,double_data[c+1],decimals,double_data[c+3],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
2170 | add_to_buffer(tmp_buffer); |
||
2171 | if(onclick != 0){object_cnt++;}/* object_cnt++; */ |
||
8365 | schaersvoo | 2172 | } |
2173 | reset(); |
||
15111 | schaersvoo | 2174 | dragstuff[18] = 1; |
2175 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
8365 | schaersvoo | 2176 | break; |
11806 | schaersvoo | 2177 | case HATCHFILL: |
2178 | /* |
||
2179 | @ hatchfill x0,y0,dx,dy,color |
||
2180 | @ x0,y0 in xrange / yrange |
||
2181 | @ distances dx,dy in pixels |
||
13936 | bpr | 2182 | @ there is also a command <a href="#userdraw">userdraw hatchfill,color</a> |
12110 | schaersvoo | 2183 | @%hatchfill%size 400,400%xrange -10,10%yrange -10,10%canvastype 100%linewidth 2%precision 1000%jsplot blue,5*sin(x)%opacity 200,50%hatchfill 6,6,10,10,blue%hatchfill 6,-6,6,6,red |
11806 | schaersvoo | 2184 | */ |
15111 | schaersvoo | 2185 | js_function[DRAW_HATCHFILL] = 1; |
11820 | schaersvoo | 2186 | if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */ |
2187 | js_function[DRAW_FILLTOBORDER] = 1; |
||
15111 | schaersvoo | 2188 | add_js_filltoborder(canvas_type); |
11820 | schaersvoo | 2189 | } |
2190 | decimals = find_number_of_digits(precision); |
||
11806 | schaersvoo | 2191 | for(i=0;i<5;i++){ |
2192 | switch(i){ |
||
11820 | schaersvoo | 2193 | case 0: double_data[0] = get_real(infile,0); break; /* x */ |
2194 | case 1: double_data[1] = get_real(infile,0); break; /* y */ |
||
2195 | case 2: int_data[0] = (int) (get_real(infile,0)); break; /* dx pixel */ |
||
2196 | case 3: int_data[1] = (int) (get_real(infile,0)); break; /* dy pixel*/ |
||
11806 | schaersvoo | 2197 | case 4: stroke_color = get_color(infile,1); |
15111 | schaersvoo | 2198 | if(use_rotate == TRUE ){rotate(2,angle,rotationcenter,2);} |
2199 | if(use_affine == TRUE ){ transform(2,2);} |
||
11806 | schaersvoo | 2200 | /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */ |
14208 | schaersvoo | 2201 | string_length = 1 + snprintf(NULL,0, "draw_hatchfill(%d,%.*f,%.*f,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS+fill_cnt,decimals,double_data[0],decimals,double_data[1],int_data[0],int_data[1],line_width,stroke_color,stroke_opacity,xsize,ysize); |
2202 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11820 | schaersvoo | 2203 | snprintf(tmp_buffer,string_length,"draw_hatchfill(%d,%.*f,%.*f,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS+fill_cnt,decimals,double_data[0],decimals,double_data[1],int_data[0],int_data[1],line_width,stroke_color,stroke_opacity,xsize,ysize); |
11806 | schaersvoo | 2204 | add_to_buffer(tmp_buffer); |
11820 | schaersvoo | 2205 | fill_cnt++; |
15111 | schaersvoo | 2206 | reset(); |
11806 | schaersvoo | 2207 | break; |
2208 | default:break; |
||
2209 | } |
||
2210 | } |
||
2211 | break; |
||
8386 | schaersvoo | 2212 | |
8224 | bpr | 2213 | case HLINE: |
7614 | schaersvoo | 2214 | /* |
2215 | @ hline x,y,color |
||
15715 | schaersvoo | 2216 | @ alternative: horizontalline |
15111 | schaersvoo | 2217 | @ draw a horizontal line through point (x:y) in color 'color' |
2218 | @ or use command <a href='#curve'>curve color,formula</a> to draw the line (uses more points to draw the line; is however better draggable) |
||
9406 | schaersvoo | 2219 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
12110 | schaersvoo | 2220 | @%hline%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%hline 0,0,red%dhline 0,5,blue |
7614 | schaersvoo | 2221 | */ |
2222 | for(i=0;i<3;i++) { |
||
2223 | switch(i){ |
||
2224 | case 0: double_data[0] = get_real(infile,0);break; /* x-values */ |
||
2225 | case 1: double_data[1] = get_real(infile,0);break; /* y-values */ |
||
2226 | case 2: stroke_color = get_color(infile,1);/* name or hex color */ |
||
2227 | double_data[3] = double_data[1]; |
||
15111 | schaersvoo | 2228 | if(use_rotate == TRUE ){rotate(2,angle,rotationcenter,2);} |
2229 | if(use_affine == TRUE ){ transform(2,2);} |
||
2230 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
7614 | schaersvoo | 2231 | decimals = find_number_of_digits(precision); |
15111 | schaersvoo | 2232 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,100*xmin,decimals,100*xmax,decimals,double_data[1],decimals,double_data[3],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
2233 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
2234 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,100*xmin,decimals,100*xmax,decimals,double_data[1],decimals,double_data[3],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
2235 | add_to_buffer(tmp_buffer); |
||
2236 | if(onclick != 0){object_cnt++;}/* object_cnt++; */ |
||
2237 | dragstuff[4] = 1; |
||
2238 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
8379 | schaersvoo | 2239 | reset(); |
7614 | schaersvoo | 2240 | break; |
2241 | } |
||
2242 | } |
||
2243 | break; |
||
8366 | schaersvoo | 2244 | |
2245 | case HLINES: |
||
2246 | /* |
||
2247 | @ hlines color,x1,y1,x2,y2,... |
||
15715 | schaersvoo | 2248 | @ alternative: horizontallines |
15111 | schaersvoo | 2249 | @ draw horizontal lines through points (x1:y1)...(xn:yn) in color 'color' |
9406 | schaersvoo | 2250 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually |
12110 | schaersvoo | 2251 | @%hlines%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%hlines red,0,0,0,5,0,-5 |
8366 | schaersvoo | 2252 | */ |
2253 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
2254 | fill_color = stroke_color; |
||
2255 | i=0; |
||
2256 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 2257 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
8366 | schaersvoo | 2258 | if(i%2 == 0 ){ |
2259 | double_data[i] = get_real(infile,0); /* x */ |
||
2260 | } |
||
2261 | else |
||
2262 | { |
||
2263 | double_data[i] = get_real(infile,1); /* y */ |
||
2264 | } |
||
2265 | i++; |
||
2266 | } |
||
15111 | schaersvoo | 2267 | if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);} |
2268 | if(use_affine == TRUE ){ transform(i-1,2);} |
||
2269 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
2270 | |||
8366 | schaersvoo | 2271 | decimals = find_number_of_digits(precision); |
2272 | for(c = 0 ; c < i-1 ; c = c+2){ |
||
15111 | schaersvoo | 2273 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,xmin,decimals,xmax,decimals,double_data[c+1],decimals,double_data[c+1],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
2274 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
2275 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,xmin,decimals,xmax,decimals,double_data[c+1],decimals,double_data[c+1],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
2276 | add_to_buffer(tmp_buffer); |
||
2277 | if(onclick != 0){object_cnt++;}/* object_cnt++; */ |
||
8366 | schaersvoo | 2278 | } |
2279 | reset(); |
||
15111 | schaersvoo | 2280 | dragstuff[4] = 1; |
2281 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
8366 | schaersvoo | 2282 | break; |
11806 | schaersvoo | 2283 | case HTTP: |
7614 | schaersvoo | 2284 | /* |
11806 | schaersvoo | 2285 | @ http x1,y1,x2,y2,http://some_adress.com |
14078 | bpr | 2286 | @ an active html-page will be displayed in an "iframe" rectangle left top (x1:y1), right bottom (x2:y2) |
11806 | schaersvoo | 2287 | @ do not use interactivity (or mouse) if the mouse needs to be active in the iframe |
14071 | bpr | 2288 | @ can <b>not</b> be ''set onclick`` or ''drag xy`` |
12110 | schaersvoo | 2289 | @%http%size 400,400%xrange -10,10%yrange -10,10%http 0,10,10,0,http://wims.unice.fr%opacity 200,50%drag xy%fcircle 0,0,100,green |
7614 | schaersvoo | 2290 | */ |
15111 | schaersvoo | 2291 | js_function[DRAW_HTTP] = 1; |
11806 | schaersvoo | 2292 | for(i=0;i<5;i++){ |
7614 | schaersvoo | 2293 | switch(i){ |
11806 | schaersvoo | 2294 | case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */ |
14032 | schaersvoo | 2295 | case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system -> pixel height */ |
11806 | schaersvoo | 2296 | case 2: int_data[2]=x2px(get_real(infile,0)) - int_data[0];break; /* width in x/y-range coord system -> pixel width */ |
2297 | case 3: int_data[3]=y2px(get_real(infile,0)) - int_data[1];break; /* height in x/y-range coord system -> pixel height */ |
||
2298 | case 4: decimals = find_number_of_digits(precision); |
||
2299 | temp = get_string(infile,1); |
||
2300 | if(strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'");} |
||
14208 | schaersvoo | 2301 | string_length = 1 + snprintf(NULL,0,"draw_http(%d,%d,%d,%d,%d,\"%s\");\n",canvas_root_id,int_data[0],int_data[1],int_data[2],int_data[3],temp); |
11806 | schaersvoo | 2302 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+2); |
2303 | snprintf(tmp_buffer,string_length,"draw_http(%d,%d,%d,%d,%d,\"%s\");\n",canvas_root_id,int_data[0],int_data[1],int_data[2],int_data[3],temp); |
||
2304 | add_to_buffer(tmp_buffer); |
||
7614 | schaersvoo | 2305 | break; |
2306 | } |
||
2307 | } |
||
11806 | schaersvoo | 2308 | reset(); |
7614 | schaersvoo | 2309 | break; |
11806 | schaersvoo | 2310 | case HTML: |
8366 | schaersvoo | 2311 | /* |
15111 | schaersvoo | 2312 | @ html x1,y1,html_string |
14071 | bpr | 2313 | @ all tags are allowed, html code using inputfields could be read using your own javascript code. Do not use ids like 'canvas_input0' etc. |
15111 | schaersvoo | 2314 | @ can be set <a href='#onclick'>onclick</a> and <a href='#drag'>drag&drop</a> |
2315 | @ command <a href='#affine'>affine</a> will produce CSS3 matrix transformations |
||
2316 | @ command <a href='#rotate'>rotate</a> will rotate the object |
||
14038 | schaersvoo | 2317 | @ use keyword <a href='#centered'>centered</a> to center the html object on (x1:y1) |
15111 | schaersvoo | 2318 | @ note: using drag&drop for all external P,SPAN,DIV,IMG,SVG-images onto a canvasdraw element, use ''onclick=javascript:place_image_on_canvas(this.id)`` |
16707 | schaersvoo | 2319 | @ note: sub & sup are supported in command family <a href='#string'>string</a>, e.g. real internal canvas objects ! |
15629 | bpr | 2320 | @%html-text%size 500,500%xrange -10,10%yrange -10,10%drag xy%centered%fillcolor lightblue%html 2,2,<h1 style='color:red'>DRAG ME</h1> %opacity 200,50%drag xy%fcircle 0,0,100,green |
15111 | schaersvoo | 2321 | @%html-image-slider%size 500,500%xrange -10,10%yrange -10,10%fontsize 42%rotationcenter 0,0%centered%html 0,0,<img src="http://85.148.206.56/gifs/can1.gif" />%slider 0,pi,400,40,angle active degree, %centered%html 0,0,<img src="http://85.148.206.56/gifs/can2.gif" /> |
8366 | schaersvoo | 2322 | */ |
15111 | schaersvoo | 2323 | js_function[DRAW_XML] = 1; |
11806 | schaersvoo | 2324 | for(i=0;i<5;i++){ |
2325 | switch(i){ |
||
15111 | schaersvoo | 2326 | case 0: double_data[0] = get_real(infile,0);break; |
2327 | case 1: double_data[1] = get_real(infile,0);break; |
||
11806 | schaersvoo | 2328 | case 4: decimals = find_number_of_digits(precision); |
15111 | schaersvoo | 2329 | if(use_affine == TRUE ){ transform(2,2);}/* needs double_data[] */ |
2330 | if( use_offset != 0 || drag_type != -1 ){int_data[2] = 1;}else{int_data[2] = 0;} /* only centered or not-centered */ |
||
2331 | int_data[0] = x2px(double_data[0]);/* needs px */ |
||
2332 | int_data[1] = y2px(double_data[1]); |
||
2333 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
15116 | bpr | 2334 | if( use_slider != -1 && drag_type != -1){ onclick = 5; } |
11806 | schaersvoo | 2335 | temp = get_string(infile,1); |
15111 | schaersvoo | 2336 | if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","\\\""); } |
2337 | if( strstr(temp,"<img ")!= 0){URL="image";}else{URL="html";} |
||
2338 | string_length = 1 + snprintf(NULL,0,"var draw_xml%d = {id:%d,type:'%s',x:[%d],y:[%d],mathml:\"%s\",drag_type:%d,onclick:%d,object_cnt:%d,stroke_color:\"%s\",stroke_opacity:%.2f,fill_color:\"%s\",fill_opacity:%.2f,use_center:%d,use_snap:%d,angle:%f,fontfamily:\"%s\",transform:%s,use_affine:%d,offset:[0,0],use_slider:%s,rotation_center:%s,once:true};slidergroup[%d] = null;draw_xml(draw_xml%d);\n",drawxml_cnt,drawxml_cnt,URL,int_data[0],int_data[1],temp,drag_type,onclick,object_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,int_data[2],use_snap,angle,font_family,doubledata2js_array(affine_matrix,6,decimals),use_affine,my_sliders,rotation_center,object_cnt,drawxml_cnt); |
||
14208 | schaersvoo | 2339 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
15111 | schaersvoo | 2340 | snprintf(tmp_buffer,string_length, "var draw_xml%d = {id:%d,type:'%s',x:[%d],y:[%d],mathml:\"%s\",drag_type:%d,onclick:%d,object_cnt:%d,stroke_color:\"%s\",stroke_opacity:%.2f,fill_color:\"%s\",fill_opacity:%.2f,use_center:%d,use_snap:%d,angle:%f,fontfamily:\"%s\",transform:%s,use_affine:%d,offset:[0,0],use_slider:%s,rotation_center:%s,once:true};slidergroup[%d] = null;draw_xml(draw_xml%d);\n",drawxml_cnt,drawxml_cnt,URL,int_data[0],int_data[1],temp,drag_type,onclick,object_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,int_data[2],use_snap,angle,font_family,doubledata2js_array(affine_matrix,6,decimals),use_affine,my_sliders,rotation_center,object_cnt,drawxml_cnt); |
11806 | schaersvoo | 2341 | add_to_buffer(tmp_buffer); |
15111 | schaersvoo | 2342 | if(onclick != 0 ){object_cnt++;} |
2343 | drawxml_cnt++;/* keeps track on imported img,div,p,span,mathml,svg */ |
||
11806 | schaersvoo | 2344 | break; |
2345 | default:break; |
||
8366 | schaersvoo | 2346 | } |
2347 | } |
||
15111 | schaersvoo | 2348 | reset(); |
8366 | schaersvoo | 2349 | break; |
8386 | schaersvoo | 2350 | |
11806 | schaersvoo | 2351 | case IMAGEFILL: |
7614 | schaersvoo | 2352 | /* |
11996 | schaersvoo | 2353 | @ imagefill x,y,scaling to xsize × ysize?,image_url |
11874 | schaersvoo | 2354 | @ The next suitable <b>filled object</b> will be filled with "image_url" tiled |
2355 | @ scaling to xsize × ysize ? ... 1 = yes 0 = no |
||
14078 | bpr | 2356 | @ After pattern filling, the fill-color should be reset ! |
14066 | bpr | 2357 | @ wims getins / image from class directory: imagefill 80,80,my_image.gif |
15111 | schaersvoo | 2358 | @ normal url: imagefill 80,80,0,$module_dir/gifs/my_image.gif |
14066 | bpr | 2359 | @ normal url: imagefill 80,80,1,http://adres/a/b/c/my_image.jpg |
11874 | schaersvoo | 2360 | @ if dx,dy is larger than the image, the whole image will be background to the next object. |
13967 | schaersvoo | 2361 | @%imagefill_tile%size 400,400%xrange -10,10%yrange -10,10%linewidth 3%circles blue,0,0,5,3,2,5%imagefill 1.5,1.5,0,gifs/en.gif%imagefill -5,5,0,gifs/logo/wimsedu.png |
2362 | @%imagefill_scale%size 400,400%xrange -10,10%yrange -10,10%linewidth 3%circles blue,0,0,5,3,2,5%imagefill 1.5,1.5,1,gifs/en.gif%imagefill -5,5,1,gifs/logo/wimsedu.png |
||
7614 | schaersvoo | 2363 | */ |
15111 | schaersvoo | 2364 | js_function[DRAW_IMAGEFILL] = 1; |
11854 | schaersvoo | 2365 | if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */ |
2366 | js_function[DRAW_FILLTOBORDER] = 1; |
||
15111 | schaersvoo | 2367 | add_js_filltoborder(canvas_type); |
11854 | schaersvoo | 2368 | } |
11874 | schaersvoo | 2369 | for(i=0 ;i < 4 ; i++){ |
7614 | schaersvoo | 2370 | switch(i){ |
11806 | schaersvoo | 2371 | case 0:int_data[0] = (int) (get_real(infile,0));break; |
2372 | case 1:int_data[1] = (int) (get_real(infile,0));break; |
||
11874 | schaersvoo | 2373 | case 2:int_data[2] = (int) (get_real(infile,0));break; /* 0 | 1 */ |
2374 | case 3: URL = get_string_argument(infile,1); |
||
14208 | schaersvoo | 2375 | string_length = 1 + snprintf(NULL,0, "draw_imagefill(%d,%d,%d,\"%s\",%d,%d,%d,%d);\n",STATIC_CANVAS+fill_cnt,int_data[0],int_data[1],URL,xsize,ysize,use_userdraw,int_data[2]); |
2376 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11874 | schaersvoo | 2377 | snprintf(tmp_buffer,string_length,"draw_imagefill(%d,%d,%d,\"%s\",%d,%d,%d,%d);\n",STATIC_CANVAS+fill_cnt,int_data[0],int_data[1],URL,xsize,ysize,use_userdraw,int_data[2]); |
11806 | schaersvoo | 2378 | add_to_buffer(tmp_buffer); |
11874 | schaersvoo | 2379 | fill_cnt++; |
11806 | schaersvoo | 2380 | break; |
7614 | schaersvoo | 2381 | } |
2382 | } |
||
11806 | schaersvoo | 2383 | reset(); |
2384 | break; |
||
14066 | bpr | 2385 | |
14038 | schaersvoo | 2386 | case IMAGEPALETTE: |
2387 | /* |
||
2388 | @ imagepalette image1,image2,image3,... |
||
14379 | bpr | 2389 | @ if used before and together with command <a href='#multidraw'>multidraw images,..,..., etc</a> the image will be presented in a small table in the ''control panel``. |
15313 | schaersvoo | 2390 | @%imagepalette%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%copy 0,0,-1,-1,-1,-1,gifs/images/skull_and_crossbones50.png%fontcolor green%fontfamily Bold 42pt Arial%imagepalette gifs/ca.gif,gifs/en.gif,gifs/nl.gif,gifs/fr.gif,gifs/cn.gif,gifs/de.gif,gifs/kh.gif,gifs/it.gif%multiuserinput 0,0,1%css color:blue;%multisnaptogrid 1,1,1%multilinewidth 0,4,0%# attention: use unicode text input without the slash %# \u222D ---> u222D at least will sometimes work%# otherwise cut&past unicode symbols into inputfield...%multilabel TEXT,REACTION ARROW,FLAGS,STOP DRAWING%multidraw text,arrow,images |
14038 | schaersvoo | 2391 | */ |
2392 | temp = get_string(infile,1); |
||
2393 | temp = str_replace(temp,",","\",\""); |
||
2394 | if( use_tooltip == 1 ){canvas_error("command 'imagepalette' is incompatible with command 'intooltip tip_text',as they use the same div-element ");} |
||
2395 | fprintf(js_include_file,"\nvar current_id;var imagepalette = [\" %s \"];\n",temp); |
||
2396 | break; |
||
14066 | bpr | 2397 | |
11806 | schaersvoo | 2398 | case INPUT: |
2399 | /* |
||
2400 | @ input x,y,size,editable,value |
||
2401 | @ to set inputfield "readonly", use editable = 0 |
||
15111 | schaersvoo | 2402 | @ if no preset 'value' is needed...use a 'space' as last item argument |
11806 | schaersvoo | 2403 | @ only active inputfields (editable = 1) will be read with read_canvas(); |
15111 | schaersvoo | 2404 | @ if ''$status=done`` (e.g. in answer.phtml) the inputfield will be cleared and set readonly<br />override this by keyword <a href="#status">status</a> |
2405 | @ may be further controlled by <a href="#css">css</a> |
||
11806 | schaersvoo | 2406 | @ if mathml inputfields are present and / or some userdraw is performed, these data will <b>not</b> be send as well (javascript:read_canvas();) |
2407 | @ use keyword <a href='#xoffset'>xoffset | centered</a> if the inputfield should be centered on (x:y)<br /> default is the left top corner is (x:y) |
||
13953 | schaersvoo | 2408 | @ if the student must place an inputfield(s) somewhere on the canvas, use command <a href="#userdraw">userdraw input,color</a> or make use of a command like <a href="#userdraw">userdraw text,color</a> |
2409 | @%input%size 400,400%xrange -10,10%yrange -10,10%linewidth 6%point 1,2,red%input 1,2,5,1, ?%point -5,5,red%input -5,5,5,1, ?%point 6,-5,red%input 6,-5,5,1, ?%point -5,-8,red%input -5,-8,5,1, ? |
||
11806 | schaersvoo | 2410 | */ |
15111 | schaersvoo | 2411 | js_function[DRAW_INPUTS] = 1; |
11806 | schaersvoo | 2412 | for(i = 0 ; i<5;i++){ |
2413 | switch(i){ |
||
2414 | case 0: int_data[0]=x2px(get_real(infile,0));break;/* x in px */ |
||
2415 | case 1: int_data[1]=y2px(get_real(infile,0));break;/* y in px */ |
||
2416 | case 2: int_data[2]=abs( (int)(get_real(infile,0)));break; /* size */ |
||
2417 | case 3: if( get_real(infile,1) >0){int_data[3] = 1;}else{int_data[3] = 0;};break; /* readonly */ |
||
15260 | schaersvoo | 2418 | case 4: temp = get_string(infile,3); |
15111 | schaersvoo | 2419 | string_length = 1 + snprintf(NULL,0, "draw_static_inputs(%d,%d,%d,%d,%d,%d,\"%s\",\"%s\",%d);\n",canvas_root_id,input_cnt,int_data[0],int_data[1],int_data[2],int_data[3],css_class,temp,use_offset); |
14208 | schaersvoo | 2420 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
15111 | schaersvoo | 2421 | snprintf(tmp_buffer,string_length,"draw_static_inputs(%d,%d,%d,%d,%d,%d,\"%s\",\"%s\",%d);\n",canvas_root_id,input_cnt,int_data[0],int_data[1],int_data[2],int_data[3],css_class,temp,use_offset); |
11806 | schaersvoo | 2422 | add_to_buffer(tmp_buffer); |
2423 | input_cnt++;break; |
||
2424 | default: break; |
||
2425 | } |
||
2426 | } |
||
2427 | if(reply_format == 0 ){reply_format = 15;} |
||
2428 | reset(); |
||
2429 | break; |
||
8386 | schaersvoo | 2430 | |
11806 | schaersvoo | 2431 | case INTOOLTIP: |
2432 | /* |
||
2433 | @ intooltip link_text |
||
2434 | @ link_text is a single line (span-element) |
||
15111 | schaersvoo | 2435 | @ link_text may also be an image URL ''http://some_server/images/my_image.png`` or ''$module_dir/gifs/my_image.jpg`` |
11806 | schaersvoo | 2436 | @ link_text may contain HTML markup |
14071 | bpr | 2437 | @ the canvas will be displayed in a tooltip on ''link_text`` |
15111 | schaersvoo | 2438 | @ the canvas is default transparent: use command <a href="#bgcolor">bgcolor color</a> to adjust background-color, the link text will also be shown with this 'bgcolor'. |
14071 | bpr | 2439 | @ many ''userinput stuff`` will use the tooltip_placeholder_div element...only one is defined in the wims-page<br />and are therefore these commands are mutually exclusive.<br />keep this in mind... |
14246 | bpr | 2440 | @%intooltip%size 400,400%xrange -10,10%yrange -10,10%fontfamily Bold 42pt Courier%string black,0,0,Hello World%intooltip <span style="background-color:black;color:white;font-style:bold;font-size:48pt;">CLICK <br />HERE</span> |
11806 | schaersvoo | 2441 | */ |
2442 | if(use_input_xy != FALSE ){canvas_error("intooltip can not be combined with userinput_xy or other commands using the tooltip-div...see documentation");} |
||
2443 | if( use_tooltip == 1 ){ canvas_error("command 'intooltip' cannot be combined with command 'popup'...");} |
||
2444 | tooltip_text = get_string(infile,1); |
||
2445 | if(strstr(tooltip_text,"\"") != 0 ){ tooltip_text = str_replace(tooltip_text,"\"","'"); } |
||
2446 | use_tooltip = 1; |
||
2447 | break; |
||
2448 | |||
2449 | case JSCURVE: |
||
7614 | schaersvoo | 2450 | /* |
11893 | schaersvoo | 2451 | @ jscurve color,formula1(x),formula2(x),formula3(x),... |
15715 | schaersvoo | 2452 | @ alternative: jsplot |
11893 | schaersvoo | 2453 | @ your function will be plotted by the javascript engine of the client browser |
2454 | @ if <a href='trange'>trange</a> is defined, the two functions will be plotted parametric<br /><b>note</b>: use <i>x</i> as variable...and not <i>t</i>. Use keyword <a href='#animate'>animate</a> to animate a point on the curve |
||
14071 | bpr | 2455 | @ use only basic math in your curve: <code>sqrt,^,asin,acos,atan,log,pi,abs,sin,cos,tan,e</code> |
2456 | @ use parenthesis and rawmath: use 2*x instead of 2x ; use 2^(sin(x))...etc etc (use error console to debug any errors...) |
||
2457 | @ <b>attention</b>: last ''precision`` command in the canvasdraw script determines the calculation precision of the javascript curve plot ! |
||
11806 | schaersvoo | 2458 | @ no validity check is done by wims. |
15111 | schaersvoo | 2459 | @ zooming & panning are implemented:<br />use command ''zoom color`` for mouse driven zooming<br />or use keyword 'setlimits' for inputfields setting xmin/xmax, ymin/ymax |
11806 | schaersvoo | 2460 | @ zooming & panning is better than for curves produced by command <a href="#curve">curve color,formula</a> because for avery change in x/y-range the curve is recalculated in javascript |
15116 | bpr | 2461 | @ zooming & panning in case of userbased functionplot: reclick the OK button to re-plot curve onto the resized grid |
11893 | schaersvoo | 2462 | @ use keyword <a href='animate'>animate</a> for animating a point on the curve |
14071 | bpr | 2463 | @ use command ''trace_jscurve formula(x)`` for tracing |
14246 | bpr | 2464 | @ use command ''jsmath formula(x)`` for calculating and displaying indiviual points on the curve |
11806 | schaersvoo | 2465 | @ can <b>not</b> be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> (yet) |
14071 | bpr | 2466 | @ commands plotjump / plotstep are not active for ''jscurve`` |
11806 | schaersvoo | 2467 | @ every command jscurve will produce a new canvas (canvastype 111,112,113...) for this one curve. |
14071 | bpr | 2468 | @ plotting multiple js-curves on the same canvas (for example if you want to use 'userdraw clickfill,color' on <a href="#canvastype">canvastype</a> number 111, use:<br/> <code>jscurve red,fun1(x),fun2(x)...fun_n(x)</code>, you must specify individual multistrokecolors & multistrokeopacity & multilinewidth for these multiple js-curves to use different colors. Otherwise all curves will be the same color... Use commands like: <a href="#multistrokecolors">multistrokecolors</a>, <a href="#multilinewidth">multilinewidth</a>, <a href="#multidash">multidash</a>, <a href="#multistrokeopacity">multistroke</a>, <b>color</b> given for the command <code>jscurve color,formulas(x)</code> will not be used in that case... but the color argument must still be given in any case (otherwise syntax error...) |
14622 | schaersvoo | 2469 | @%jscurve%size 400,400%xrange -10,10%yrange -10,10%multistrokecolors red,green,blue,orange%multilinewidth 1,2,3%multistrokeopacity 0.5,0.8,1.0%jscurve red,sin(x),1/sin(x),sin(x^2) |
11806 | schaersvoo | 2470 | */ |
15111 | schaersvoo | 2471 | jsplot_cnt++;/* -1 --> 0 */ |
11806 | schaersvoo | 2472 | stroke_color = get_color(infile,0); |
15111 | schaersvoo | 2473 | js_function[JS_MATH] = 1; |
2474 | js_function[JS_PLOT] = 1; |
||
2475 | if( tmin != 0 && tmax !=0){use_parametric = TRUE;} |
||
11806 | schaersvoo | 2476 | temp = get_string(infile,1); |
2477 | temp = str_replace(temp,",","\",\""); |
||
15111 | schaersvoo | 2478 | string_length = 1 + snprintf(NULL,0, "var js_plot%d = function(){jsplot(%d,[\"%s\"],[%d],[\"%s\"],[%.2f],[%d],%d,%d,[%f,%f],%d,%d,%d,0);};js_plot%d();",jsplot_cnt,JSPLOT_CANVAS+jsplot_cnt,temp,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],tmin,tmax,plot_steps,use_parametric,use_animate,jsplot_cnt); |
14208 | schaersvoo | 2479 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
15111 | schaersvoo | 2480 | snprintf(tmp_buffer,string_length, "var js_plot%d = function(){jsplot(%d,[\"%s\"],[%d],[\"%s\"],[%.2f],[%d],%d,%d,[%f,%f],%d,%d,%d,0);};js_plot%d();",jsplot_cnt,JSPLOT_CANVAS+jsplot_cnt,temp,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],tmin,tmax,plot_steps,use_parametric,use_animate,jsplot_cnt); |
11806 | schaersvoo | 2481 | add_to_buffer(tmp_buffer); |
15111 | schaersvoo | 2482 | fprintf(js_include_file,"if(typeof(all_jsplots) !== 'number'){var all_jsplots;};all_jsplots = %d;",jsplot_cnt); |
2483 | |||
11806 | schaersvoo | 2484 | /* we need to create multiple canvasses, so we may zoom and pan ?? */ |
2485 | break; |
||
2486 | |||
2487 | case JSMATH: |
||
2488 | /* |
||
2489 | @ jsmath some_math_function |
||
2490 | @ will calculate an y-value from a userinput x-value and draws a crosshair on these coordinates. |
||
14246 | bpr | 2491 | @ default labels ''x`` and ''y``; the commands ''xlabel some_x_axis_name`` and ''ylabel some_y_axis_name`` will set the label for the input fields |
15111 | schaersvoo | 2492 | @ use command 'css some_css' for styling the display fields. Use command 'fontsize int' to size the labels ''x`` and ''y`` |
14066 | bpr | 2493 | @ the client browser will convert your math function to javascript math.<br />use parenthesis and rawmath: use 2*x instead of 2x etc etc<br />no check is done on the validity of your function and/or syntax<br />use error console to debug any errors... |
11806 | schaersvoo | 2494 | @ be aware that the formula's of the plotted function(s) can be found in the page javascript source |
12111 | schaersvoo | 2495 | @%jsmath%size 400,400%xrange -10,10%yrange -10,10%jsplot blue,sin(x^2)%jsmath sin(x^2) |
11806 | schaersvoo | 2496 | */ |
15111 | schaersvoo | 2497 | js_function[DRAW_CROSSHAIRS] = 1; |
2498 | js_function[JS_MATH] = 1; |
||
2499 | add_calc_y(get_string(infile,1),font_size,css_class); |
||
2500 | break; |
||
15716 | schaersvoo | 2501 | case KILL: |
2502 | /* |
||
2503 | @ kill arguments |
||
2504 | @ arguments may be: affine linear translation rotation slider offset reset |
||
2505 | @ for documentation see: killaffine,killlinear,killtranslation... |
||
2506 | @ multiple arguments are allowed (although not checked for validity...) |
||
2507 | */ |
||
2508 | temp = get_string(infile,1); |
||
2509 | if(strstr(temp,"affine") != 0 ){use_affine = FALSE;affine_matrix[0] = 1.0;affine_matrix[1] = 0.0;affine_matrix[2] = 0.0;affine_matrix[3] = 1.0;affine_matrix[4] = 0.0;affine_matrix[5] = 0.0;} |
||
2510 | if(strstr(temp,"linear") != 0 ){affine_matrix[0] = 1.0;affine_matrix[1] = 0.0;affine_matrix[2] = 0.0;affine_matrix[3] = 1.0;} |
||
2511 | if(strstr(temp,"translation") != 0 || strstr(temp,"translate") != 0 ){affine_matrix[4] = 0.0;affine_matrix[5] = 0.0;} |
||
2512 | if(strstr(temp,"rotation") != 0 || strstr(temp,"rotate") != 0 ){use_rotate = FALSE;angle = 0.0;rotation_center="null";} |
||
2513 | if(strstr(temp,"slider") != 0 ){slider_type = "0";my_sliders = "[-1]";last_slider = use_slider+1;} |
||
2514 | if(strstr(temp,"reset") != 0 ){if(no_reset == FALSE){no_reset = TRUE;}else{no_reset = FALSE;reset();}} |
||
2515 | if(strstr(temp,"offset") != 0 ){use_offset = 0;} |
||
2516 | break; |
||
11806 | schaersvoo | 2517 | case KILLAFFINE: |
2518 | /* |
||
2519 | @ killaffine |
||
14066 | bpr | 2520 | @ keyword: resets the transformation matrix to 1,0,0,1,0,0 |
15633 | bpr | 2521 | @ note: any active linear transformation will also be reset: tx=0, ty=0 |
11806 | schaersvoo | 2522 | */ |
15111 | schaersvoo | 2523 | use_affine = FALSE; |
2524 | affine_matrix[0] = 1.0; |
||
2525 | affine_matrix[1] = 0.0; |
||
2526 | affine_matrix[2] = 0.0; |
||
2527 | affine_matrix[3] = 1.0; |
||
2528 | affine_matrix[4] = 0.0; |
||
2529 | affine_matrix[5] = 0.0; |
||
11806 | schaersvoo | 2530 | break; |
15111 | schaersvoo | 2531 | case KILLLINEAR: |
2532 | /* |
||
2533 | @ killlinear |
||
2534 | @ keyword: resets the transformation matrix to 1,0,0,1,tx,ty |
||
2535 | @ note:any active transformation or rotation will not be killed (tx,ty remain active) |
||
2536 | */ |
||
2537 | affine_matrix[0] = 1.0; |
||
2538 | affine_matrix[1] = 0.0; |
||
2539 | affine_matrix[2] = 0.0; |
||
2540 | affine_matrix[3] = 1.0; |
||
2541 | break; |
||
11806 | schaersvoo | 2542 | |
15111 | schaersvoo | 2543 | |
11806 | schaersvoo | 2544 | case KILLROTATE: |
2545 | /* |
||
14071 | bpr | 2546 | @ killrotate |
15111 | schaersvoo | 2547 | @ will set the rotation angle to 0. |
2548 | @ will also reset the command <a href="#rotationcenter">rotationcenter</a> to the first (x;y) of the next rotatable/slidable object(s) <br/>eg a following rotate command will have the first object point as rotation center |
||
11806 | schaersvoo | 2549 | @ if not set, the rotation center will remain unchanged |
15111 | schaersvoo | 2550 | @ note:any active transformation or linear will not be killed (e.g an active transformation matrix remains active) |
15116 | bpr | 2551 | @%killrotate%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%rotationcenter 0,0%# slider is active for all following objects until 'killslider'%slider -10,10,300,40,angle degree,Rotate%drag xy%# after dragging the object must be clicked to re-activate the slider%linewidth 4%arrow 0,0,6,0,9,blue%%# reset rotation center to the first (x,y) of the next object/arrow...%killrotate%drag xy%# after dragging the object must be clicked to re-activate the slider%arrow 0,0,6,1,9,red |
11806 | schaersvoo | 2552 | */ |
15111 | schaersvoo | 2553 | use_rotate = FALSE; |
14549 | schaersvoo | 2554 | angle = 0.0; |
15111 | schaersvoo | 2555 | rotation_center="null"; |
11806 | schaersvoo | 2556 | break; |
2557 | |||
2558 | case KILLSLIDER: |
||
2559 | /* |
||
2560 | @ killslider |
||
2561 | @ keyword (no arguments required) |
||
2562 | @ ends grouping of object under a previously defined slider |
||
2563 | */ |
||
14208 | schaersvoo | 2564 | slider_type = "0"; |
15111 | schaersvoo | 2565 | my_sliders = "[-1]"; |
2566 | last_slider = use_slider+1; |
||
11806 | schaersvoo | 2567 | break; |
2568 | |||
2569 | case KILLTRANSLATION: |
||
2570 | /* |
||
15116 | bpr | 2571 | @ killtranslation |
15715 | schaersvoo | 2572 | @ alternative: killtranslate |
15111 | schaersvoo | 2573 | @ note: a active linear or affine transformation will not be 100% reset...only tx=0,ty=0 |
2574 | @ resets the translation matrix a,b,c,d,tx,ty to a,b,c,d,0,0 |
||
11806 | schaersvoo | 2575 | */ |
15111 | schaersvoo | 2576 | affine_matrix[4] = 0.0; |
2577 | affine_matrix[5] = 0.0; |
||
11806 | schaersvoo | 2578 | break; |
15757 | schaersvoo | 2579 | |
14225 | schaersvoo | 2580 | case LATEX: |
2581 | /* |
||
15111 | schaersvoo | 2582 | @ latex x,y,tex string |
15715 | schaersvoo | 2583 | @ alternative: math |
16706 | schaersvoo | 2584 | @ note: <b>for a single greek letter</b> ,please be smart and use a command like <a href='#string'>string</a> along with <b>unicode</b> !! <br />possibly together with command <a href="#xyoffset">xoffset, yoffset or xyoffset</a><br/> See <a target='new' href='https://en.wikipedia.org/wiki/Mathematical_operators_and_symbols_in_Unicode'>https://en.wikipedia.org/wiki/Mathematical_operators_and_symbols_in_Unicode</a><br/> See <a target='new' href='https://en.wikipedia.org/wiki/Greek_script_in_Unicode'>https://en.wikipedia.org/wiki/Greek_script_in_Unicode</a> |
15111 | schaersvoo | 2585 | @ you may also use command <a href="#mathml">mathml</a> for xml strings generated with wims commmand ''mathmlmath`` (will not work on KaTeX enabled WIMS) |
15633 | bpr | 2586 | @ transformation commands <a href='#affine'>affine</a>, <a href='#translation'>translation</a> and <a href='#rotate'>rotate</a> are supported.(onclick and drag will work) |
15111 | schaersvoo | 2587 | @ can be set onclick: <code>javascript:read_dragdrop();</code> will return click numbers of mathml-objects<br />if 4 clickable object are drawn, the reply could be 1,0,1,0 ... meaning clicked on the first and third object |
2588 | @ can be set draggable:<code>javascript:read_dragdrop();</code> will return all coordinates in the same order as the canvas script: unmoved object will have their original coordinates... |
||
2589 | @ can be moved/rotated with command <a href='#slider'>slider</a> |
||
2590 | @ snaptogrid is supported |
||
2591 | @ when clicked, the colour of the 'div background' of the 'mathobject' will be determined by the <a href="#fillcolor">fillcolor</a> and <a href="#opacity">opacity</a> settings |
||
2592 | @ userdraw may be combined with 'latex' ; the js-function 'read_canvas()' will contain the coordinates of the drawing. |
||
2593 | @ userdraw may be combined; the read_canvas() will contain the drawing. |
||
2594 | @ draggable or onclick 'external images' from command <a href='#copyresized'>copy or copyresized</a> and all objects from commands <a href='#html'>html</a> or <a href='#obabel'>obabel</a> can be combined with drag and/or onclick mathml |
||
14230 | schaersvoo | 2595 | @ other drag objects (circles/rects etc) are supported, but read_dragdrop() will probably be difficult to interpret... |
14379 | bpr | 2596 | @ if inputfields are incorporated in mathml (with id's: id='mathml0',id='mathml1',...id='mathml_n')<br />the user_input values will be read by <code>javascript:read_mathml();</code>. <b>attention</b>: if after this mathml-input object other user-interactions are included, these will read mathml too using "read_canvas();" |
2597 | @ If other inputfields (command input / command textarea) or userdraw are performed, the function read_canvas() will not read mathml. Use some generic function to read it.... |
||
15116 | bpr | 2598 | @ use keyword <a href='#centered'>centered</a> to center the katex div object on (x1:y1) <br />this may not work as expected for MathJaX [TO BE TESTED] |
15274 | bpr | 2599 | @ note: if you want to include external TeX via drag&drop onto a canvasdraw element, use \\mmlid{integer} in the tex-command:''!insmath \\mmlid{1}\\frac{1}{\pi}``<br /> (if your wims_mathml does not support it...use <a href="http://85.148.206.56/wims/download/Mathml.tar.gz">this version...</a>) |
15111 | schaersvoo | 2600 | @ note: the same is true for all external P,SPAN,DIV,IMG,SVG-images via drag&drop onto a canvasdraw element, use ''onclick=javascript:place_image_on_canvas(this.id)`` |
2601 | @%latex_drag%size 400,400%xrange -10,10%yrange -10,10%grid 2,2,grey%strokecolor red%drag xy%centered%latex -6,5,\\frac{1}{2}+ \\frac{\\pi}{2}%strokecolor blue%drag xy%centered%latex -3,5,\\frac{1}{3}+ \\frac{\\pi}{3}%strokecolor green%drag xy%centered%latex 0,5,\\frac{1}{4}+ \\frac{\\pi}{4}%strokecolor orange%drag xy%fontfamily 26px Times%centered%latex 3,5,\\frac{1}{5}+ \\frac{\\pi}{6} |
||
15313 | schaersvoo | 2602 | @%latex%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 3%vline 0,0,green%hline 0,0,green%fontfamily 16px Arial%fillcolor orange%strokecolor blue%linewidth 2%slider 0,4*pi,400,40,angle degree active, %centered%latex 0,0,\\frac{12345}{23456} \\times \\frac{12345}{23456}%translate 4,4%centered%rotate 180%drag xy%html 0,0,<table><tr><th>HTML TABLE</th></tr><tr><th><a href="https://wimsedu.info/">WIMS EDU </a> </th></tr><tr><td><img src="gifs/en.gif" /></tr><tr><td><img src="gifs/nl.gif" /></tr><tr><td><img src="gifs/fr.gif" /></tr><tr><td><img src="gifs/cn.gif" /></tr><tr><td><img src="gifs/it.gif" /></tr></table>%userdraw arrow2,red |
14225 | schaersvoo | 2603 | */ |
15111 | schaersvoo | 2604 | js_function[DRAW_XML] = 1; |
15757 | schaersvoo | 2605 | for(i=0;i<3;i++){ |
14225 | schaersvoo | 2606 | switch(i){ |
15111 | schaersvoo | 2607 | case 0: double_data[0]=get_real(infile,0);break; /* x in x/y-range coord system -> pixel width */ |
2608 | case 1: double_data[1]=get_real(infile,0);break; /* y in x/y-range coord system -> pixel height */ |
||
14225 | schaersvoo | 2609 | case 2: decimals = find_number_of_digits(precision); |
15757 | schaersvoo | 2610 | temp = get_string(infile,1); |
2611 | if(use_affine == TRUE ){ transform(2,2);}/* slider will use css-rotate transformation */ |
||
15111 | schaersvoo | 2612 | if( use_offset != 0 || drag_type != -1 ){int_data[2] = 1;}else{int_data[2] = 0;} /* only centered or not-centered */ |
2613 | int_data[0] = x2px(double_data[0]); |
||
2614 | int_data[1] = y2px(double_data[1]); |
||
2615 | if( use_slider != -1 && onclick == 0 ){ onclick = 3;}/* no drag&onclick but slideable */ |
||
15116 | bpr | 2616 | if( use_slider != -1 && drag_type != -1){ onclick = 5; } |
15757 | schaersvoo | 2617 | #ifdef KATEX_INSTALLED |
2618 | if( strstr(temp,"\\") != 0 ){ temp = str_replace(temp,"\\","\\\\"); } |
||
16613 | schaersvoo | 2619 | if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'"); } |
15757 | schaersvoo | 2620 | string_length = 1 + snprintf(NULL,0,"var draw_xml%d = {id:%d,type:'katex',x:[%d],y:[%d],mathml:\"%s\",drag_type:%d,onclick:%d,object_cnt:%d,stroke_color:\"%s\",stroke_opacity:%.2f,fill_color:\"%s\",fill_opacity:%.2f,use_center:%d,use_snap:%d,angle:%f,fontfamily:\"%s\",transform:%s,use_affine:%d,offset:[0,0],use_slider:%s,rotation_center:%s,once:true};slidergroup[%d] = null;draw_xml(draw_xml%d);\n",drawxml_cnt,drawxml_cnt,int_data[0],int_data[1],temp,drag_type,onclick,object_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,int_data[2],use_snap,angle,font_family,doubledata2js_array(affine_matrix,6,decimals),use_affine,my_sliders,rotation_center,object_cnt,drawxml_cnt); |
2621 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
2622 | snprintf(tmp_buffer,string_length, "var draw_xml%d = {id:%d,type:'katex',x:[%d],y:[%d],mathml:\"%s\",drag_type:%d,onclick:%d,object_cnt:%d,stroke_color:\"%s\",stroke_opacity:%.2f,fill_color:\"%s\",fill_opacity:%.2f,use_center:%d,use_snap:%d,angle:%f,fontfamily:\"%s\",transform:%s,use_affine:%d,offset:[0,0],use_slider:%s,rotation_center:%s,once:true};slidergroup[%d] = null;draw_xml(draw_xml%d);\n",drawxml_cnt,drawxml_cnt,int_data[0],int_data[1],temp,drag_type,onclick,object_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,int_data[2],use_snap,angle,font_family,doubledata2js_array(affine_matrix,6,decimals),use_affine,my_sliders,rotation_center,object_cnt,drawxml_cnt); |
||
2623 | #else |
||
15111 | schaersvoo | 2624 | temp = getMML(temp);/* generate MathML for Firefox or MathJaX */ |
2625 | if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'"); } |
||
2626 | string_length = 1 + snprintf(NULL,0,"var draw_xml%d = {id:%d,type:'mathml',x:[%d],y:[%d],mathml:\"%s\",drag_type:%d,onclick:%d,object_cnt:%d,stroke_color:\"%s\",stroke_opacity:%.2f,fill_color:\"%s\",fill_opacity:%.2f,use_center:%d,use_snap:%d,angle:%f,fontfamily:\"%s\",transform:%s,use_affine:%d,offset:[0,0],use_slider:%s,rotation_center:%s,once:true};slidergroup[%d] = null;draw_xml(draw_xml%d);\n",drawxml_cnt,drawxml_cnt,int_data[0],int_data[1],temp,drag_type,onclick,object_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,int_data[2],use_snap,angle,font_family,doubledata2js_array(affine_matrix,6,decimals),use_affine,my_sliders,rotation_center,object_cnt,drawxml_cnt); |
||
2627 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
2628 | snprintf(tmp_buffer,string_length, "var draw_xml%d = {id:%d,type:'mathml',x:[%d],y:[%d],mathml:\"%s\",drag_type:%d,onclick:%d,object_cnt:%d,stroke_color:\"%s\",stroke_opacity:%.2f,fill_color:\"%s\",fill_opacity:%.2f,use_center:%d,use_snap:%d,angle:%f,fontfamily:\"%s\",transform:%s,use_affine:%d,offset:[0,0],use_slider:%s,rotation_center:%s,once:true};slidergroup[%d] = null;draw_xml(draw_xml%d);\n",drawxml_cnt,drawxml_cnt,int_data[0],int_data[1],temp,drag_type,onclick,object_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,int_data[2],use_snap,angle,font_family,doubledata2js_array(affine_matrix,6,decimals),use_affine,my_sliders,rotation_center,object_cnt,drawxml_cnt); |
||
15757 | schaersvoo | 2629 | #endif |
15111 | schaersvoo | 2630 | add_to_buffer(tmp_buffer); |
2631 | if(onclick != 0 ){object_cnt++;} |
||
2632 | drawxml_cnt++;/* keeps track on imported img,div,p,span,mathml,svg */ |
||
2633 | break; |
||
14225 | schaersvoo | 2634 | default:break; |
2635 | } |
||
2636 | } |
||
15111 | schaersvoo | 2637 | reset(); |
14225 | schaersvoo | 2638 | break; |
14230 | schaersvoo | 2639 | case LATTICE: |
2640 | /* |
||
2641 | @ lattice x0,y0,xv1,yv1,xv2,yv2,n1,n2,color |
||
2642 | @ can <b>not</b> be set ''onclick`` or ''drag xy`` |
||
2643 | @%lattice%size 400,400%xrange -10,10%yrange -10,10%fillcolor red%linewidth 2%lattice -10,-10,0,1,1,1,10,10,red%fillcolor blue%lattice 10,-10,0,1,-1,1,10,10,blue |
||
2644 | */ |
||
15111 | schaersvoo | 2645 | js_function[DRAW_LATTICE] = 1; |
14230 | schaersvoo | 2646 | for( i = 0; i<9; i++){ |
2647 | switch(i){ |
||
2648 | case 0: int_data[0] = x2px(get_real(infile,0));break; /* x0-values -> x-pixels*/ |
||
2649 | case 1: int_data[1] = y2px(get_real(infile,0));break; /* y0-values -> y-pixels*/ |
||
2650 | case 2: int_data[2] = (int) (get_real(infile,0));break; /* x1-values -> x-pixels*/ |
||
2651 | case 3: int_data[3] = (int) -1*(get_real(infile,0));break; /* y1-values -> y-pixels*/ |
||
2652 | case 4: int_data[4] = (int) (get_real(infile,0));break; /* x2-values -> x-pixels*/ |
||
2653 | case 5: int_data[5] = (int) -1*(get_real(infile,0));break; /* y2-values -> y-pixels*/ |
||
2654 | case 6: int_data[6] = (int) (get_real(infile,0));break; /* n1-values */ |
||
2655 | case 7: int_data[7] = (int) (get_real(infile,0));break; /* n2-values */ |
||
2656 | case 8: stroke_color=get_color(infile,1); |
||
2657 | decimals = find_number_of_digits(precision); |
||
15111 | schaersvoo | 2658 | string_length = 1 + snprintf(NULL,0,"draw_lattice(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%.2f,%d); ",STATIC_CANVAS,line_width,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],fill_color,fill_opacity,stroke_color,stroke_opacity,use_rotate,angle,use_filled); |
14230 | schaersvoo | 2659 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
15111 | schaersvoo | 2660 | snprintf(tmp_buffer,string_length,"draw_lattice(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%.2f,%d); ",STATIC_CANVAS,line_width,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],fill_color,fill_opacity,stroke_color,stroke_opacity,use_rotate,angle,use_filled); |
14230 | schaersvoo | 2661 | add_to_buffer(tmp_buffer);break; |
2662 | default:break; |
||
2663 | } |
||
2664 | } |
||
2665 | reset(); |
||
2666 | break; |
||
15111 | schaersvoo | 2667 | case LINEAR: |
2668 | /* |
||
2669 | @ linear a,b,c,d |
||
2670 | @ defines a transformation matrix for subsequent objects |
||
2671 | @ use keyword <a href='#killlinear'>killlinear</a> to end the transformation...the next objects will be drawn in the original x/y-range |
||
2672 | @ a: Scales the drawings horizontally |
||
2673 | @ b: Skews the drawings horizontally |
||
2674 | @ c: Skews the drawings vertically |
||
2675 | @ d: Scales the drawings vertically |
||
2676 | @ the data precision may be set by preceding command ''precision int`` |
||
2677 | @ note: any active translation (tx,ty) is not changed |
||
15309 | schaersvoo | 2678 | @%linear%size 400,400%xrange -10,10%yrange -10,10%opacity 255,255%fcircle 5,5,40,blue%linear 0.2,0,0,0.2%fcircle 5,5,40,green |
15111 | schaersvoo | 2679 | */ |
2680 | for(i = 0 ; i<4;i++){ |
||
2681 | switch(i){ |
||
2682 | case 0: affine_matrix[0] = get_real(infile,0);break; |
||
2683 | case 1: affine_matrix[1] = get_real(infile,0);break; |
||
2684 | case 2: affine_matrix[2] = get_real(infile,0);break; |
||
2685 | case 3: affine_matrix[3] = get_real(infile,1); |
||
2686 | affine_matrix[4] = 0;affine_matrix[5] = 0; |
||
2687 | use_affine = TRUE; |
||
2688 | break; |
||
2689 | default: break; |
||
2690 | } |
||
2691 | } |
||
2692 | reset(); |
||
2693 | break; |
||
14230 | schaersvoo | 2694 | |
11806 | schaersvoo | 2695 | case LINE: |
2696 | /* |
||
2697 | @ line x1,y1,x2,y2,color |
||
14379 | bpr | 2698 | @ draw a line through points (x1:y1)--(x2:y2) in color ''color`` |
15111 | schaersvoo | 2699 | @ or use command ''curve color,formula`` to draw the line (uses more points to draw the line; is however better draggable) |
9406 | schaersvoo | 2700 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
12107 | schaersvoo | 2701 | @%line%size 400,400%xrange -10,10%yrange -10,10%line 0,1,2,-1,green |
7614 | schaersvoo | 2702 | */ |
8386 | schaersvoo | 2703 | for(i=0;i<5;i++){ |
7614 | schaersvoo | 2704 | switch(i){ |
11806 | schaersvoo | 2705 | case 0: double_data[10]= get_real(infile,0);break; /* x-values */ |
2706 | case 1: double_data[11]= get_real(infile,0);break; /* y-values */ |
||
2707 | case 2: double_data[12]= get_real(infile,0);break; /* x-values */ |
||
2708 | case 3: double_data[13]= get_real(infile,0);break; /* y-values */ |
||
2709 | case 4: stroke_color=get_color(infile,1);/* name or hex color */ |
||
2710 | if( double_data[10] == double_data[12] ){ /* vertical line*/ |
||
2711 | double_data[1] = xmin; |
||
2712 | double_data[3] = ymax; |
||
2713 | double_data[0] = double_data[10]; |
||
2714 | double_data[2] = double_data[10]; |
||
2715 | } |
||
2716 | else |
||
2717 | { |
||
2718 | if( double_data[11] == double_data[13] ){ /* horizontal line */ |
||
2719 | double_data[1] = double_data[11]; |
||
2720 | double_data[3] = double_data[11]; |
||
2721 | double_data[0] = ymin; |
||
2722 | double_data[2] = xmax; |
||
2723 | } |
||
2724 | else |
||
2725 | { |
||
2726 | /* m */ |
||
2727 | double_data[5] = (double_data[13] - double_data[11]) /(double_data[12] - double_data[10]); |
||
2728 | /* q */ |
||
2729 | double_data[6] = double_data[11] - ((double_data[13] - double_data[11]) /(double_data[12] - double_data[10]))*double_data[10]; |
||
2730 | |||
2731 | /*xmin,m*xmin+q,xmax,m*xmax+q*/ |
||
2732 | |||
2733 | double_data[1] = (double_data[5])*(xmin)+(double_data[6]); |
||
2734 | double_data[3] = (double_data[5])*(xmax)+(double_data[6]); |
||
2735 | double_data[0] = xmin; |
||
2736 | double_data[2] = xmax; |
||
2737 | } |
||
2738 | } |
||
15111 | schaersvoo | 2739 | if(use_rotate == TRUE ){rotate(4,angle,rotationcenter,2);} |
2740 | if(use_affine == TRUE ){ transform(4,2);} |
||
2741 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
2742 | |||
11806 | schaersvoo | 2743 | decimals = find_number_of_digits(precision); |
15111 | schaersvoo | 2744 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[2],decimals,double_data[1],decimals,double_data[3],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
2745 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
2746 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[2],decimals,double_data[1],decimals,double_data[3],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
2747 | add_to_buffer(tmp_buffer); |
||
2748 | if(onclick != 0){object_cnt++;} |
||
2749 | /* object_cnt++;*/ |
||
11806 | schaersvoo | 2750 | reset(); |
2751 | break; |
||
7614 | schaersvoo | 2752 | } |
2753 | } |
||
15111 | schaersvoo | 2754 | dragstuff[4] = 1; |
2755 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
7614 | schaersvoo | 2756 | break; |
8386 | schaersvoo | 2757 | |
11806 | schaersvoo | 2758 | case LINES: |
8370 | schaersvoo | 2759 | /* |
11806 | schaersvoo | 2760 | @ lines color,x1,y1,x2,y2...x_n-1,y_n-1,x_n,y_n |
15111 | schaersvoo | 2761 | @ draw multiple lines through points (x1:y1)--(x2:y2) ...(x_n-1:y_n-1)--(x_n:y_n) in color 'color' |
2762 | @ or use multiple commands ''curve color,formula`` or ''jscurve color,formule`` to draw the line <br />(uses more points to draw the line; is however better draggable) |
||
11806 | schaersvoo | 2763 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
14071 | bpr | 2764 | @ <b>attention</b>: the flydraw command ''lines`` is equivalent to canvasdraw command <a href="#polyline">polyline</a> |
12107 | schaersvoo | 2765 | @%lines%size 400,400%xrange -10,10%yrange -10,10%lines green,0,1,1,3,0,0,1,3,0,0,-2,1 |
8370 | schaersvoo | 2766 | */ |
2767 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
2768 | fill_color = stroke_color; |
||
2769 | i=0; |
||
2770 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 2771 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
8370 | schaersvoo | 2772 | if(i%2 == 0 ){ |
2773 | double_data[i] = get_real(infile,0); /* x */ |
||
2774 | } |
||
2775 | else |
||
2776 | { |
||
2777 | double_data[i] = get_real(infile,1); /* y */ |
||
2778 | } |
||
2779 | i++; |
||
2780 | } |
||
2781 | decimals = find_number_of_digits(precision); |
||
15111 | schaersvoo | 2782 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
8370 | schaersvoo | 2783 | for(c = 0 ; c < i-1 ; c = c+4){ |
11806 | schaersvoo | 2784 | if( double_data[c] == double_data[c+2] ){ /* vertical line*/ |
2785 | double_data[c+1] = xmin; |
||
2786 | double_data[c+3] = ymax; |
||
2787 | double_data[c+2] = double_data[c]; |
||
2788 | } |
||
2789 | else |
||
2790 | { |
||
2791 | if( double_data[c+1] == double_data[c+3] ){ /* horizontal line */ |
||
2792 | double_data[c+3] = double_data[c+1]; |
||
2793 | double_data[c] = ymin; |
||
2794 | double_data[c+2] = xmax; |
||
2795 | } |
||
2796 | else |
||
2797 | { |
||
2798 | /* m */ |
||
2799 | double m = (double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]); |
||
2800 | /* q */ |
||
2801 | double q = double_data[c+1] - ((double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]))*double_data[c]; |
||
2802 | /*xmin,m*xmin+q,xmax,m*xmax+q*/ |
||
2803 | double_data[c+1] = (m)*(xmin)+(q); |
||
2804 | double_data[c+3] = (m)*(xmax)+(q); |
||
2805 | double_data[c] = xmin; |
||
2806 | double_data[c+2] = xmax; |
||
2807 | } |
||
2808 | } |
||
15111 | schaersvoo | 2809 | if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);} |
2810 | if(use_affine == TRUE ){ transform(i-1,2);} |
||
2811 | |||
2812 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[c],decimals,double_data[c+2],decimals,double_data[c+1],decimals,double_data[c+3],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
2813 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
2814 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[c],decimals,double_data[c+2],decimals,double_data[c+1],decimals,double_data[c+3],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
2815 | add_to_buffer(tmp_buffer); |
||
2816 | if(onclick != 0){object_cnt++;} |
||
2817 | /* object_cnt++; */ |
||
8370 | schaersvoo | 2818 | } |
15111 | schaersvoo | 2819 | dragstuff[4] = 1; |
2820 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
8370 | schaersvoo | 2821 | reset(); |
2822 | break; |
||
8386 | schaersvoo | 2823 | |
11806 | schaersvoo | 2824 | |
2825 | case LINEWIDTH: |
||
7614 | schaersvoo | 2826 | /* |
11806 | schaersvoo | 2827 | @ linewidth int |
2828 | @ default 1 |
||
12107 | schaersvoo | 2829 | @%linewidth%size 400,400%xrange -10,10%yrange -10,10%linewidth 1%line -5,-5,-5,5,red%linewidth 2%line -4,-5,-4,5,green%linewidth 3%line -3,-5,-3,5,blue%linewidth 4%line -2,-5,-2,5,orange%linewidth 1%line -1,-5,-1,5,brown%linewidth 5%line 1,-5,1,5,cyan%linewidth 6%line 3,-5,3,5,purple%linewidth 7%line 5,-5,5,5,black |
7614 | schaersvoo | 2830 | */ |
11806 | schaersvoo | 2831 | line_width = (int) (get_real(infile,1)); |
2832 | break; |
||
2833 | |||
2834 | case LEVELCURVE: |
||
8363 | schaersvoo | 2835 | /* |
11806 | schaersvoo | 2836 | @ levelcurve color,expression in x/y,l1,l2,... |
15111 | schaersvoo | 2837 | @ draws very primitive level curves for expression, with levels l1,l2,l3,...,l_n |
2838 | @ the quality is <b>not to be compared</b> with the Flydraw levelcurve. <br />(choose flydraw if you want quality...) |
||
2839 | @ every individual level curve may be set 'onclick / drag xy' <br />e.g. every single level curve (l1,l2,l3...l_n) has a unique identifier |
||
2840 | @ note: the arrays for holding the javascript data are limited in size |
||
2841 | @ note: reduce image size if javascript data arrays get overloaded<br />(command 'plotsteps int' will not control the data size of the plot...) |
||
12107 | schaersvoo | 2842 | @%levelcurve%size 400,400%xrange -10,10%yrange -10,10%levelcurve red,x*y,1,2,3,4 |
8363 | schaersvoo | 2843 | */ |
11806 | schaersvoo | 2844 | fill_color = get_color(infile,0); |
2845 | char *fun1 = get_string_argument(infile,0); |
||
2846 | if( strlen(fun1) == 0 ){canvas_error("function is NOT OK !");} |
||
2847 | i = 0; |
||
2848 | done = FALSE; |
||
2849 | while( !done ){ |
||
2850 | double_data[i] = get_real(infile,1); |
||
2851 | i++; |
||
2852 | } |
||
15111 | schaersvoo | 2853 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
2854 | |||
11806 | schaersvoo | 2855 | for(c = 0 ; c < i; c++){ |
15111 | schaersvoo | 2856 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,16,%s,[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,eval_levelcurve(xsize,ysize,fun1,xmin,xmax,ymin,ymax,plot_steps,precision,double_data[c]),line_width,line_width,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
2857 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
2858 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,16,%s,[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,eval_levelcurve(xsize,ysize,fun1,xmin,xmax,ymin,ymax,plot_steps,precision,double_data[c]),line_width,line_width,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
2859 | add_to_buffer(tmp_buffer); |
||
2860 | if(onclick != 0){object_cnt++;} |
||
2861 | /* object_cnt++; */ |
||
11806 | schaersvoo | 2862 | } |
15111 | schaersvoo | 2863 | dragstuff[16] = 1; |
2864 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
11806 | schaersvoo | 2865 | reset(); |
2866 | break; |
||
8386 | schaersvoo | 2867 | |
11806 | schaersvoo | 2868 | case LEGEND: |
2869 | /* |
||
2870 | @ legend string1:string2:string3....string_n |
||
2871 | @ will be used to create a legend for a graph |
||
14066 | bpr | 2872 | @ also see command <a href='#piechart'>piechart</a> |
14071 | bpr | 2873 | @ will use the same colors per default as used in the graphs; use command <a href='#legendcolors'>legendcolors</a> to override the default |
15111 | schaersvoo | 2874 | @ use command <a href="#fontsize">fontsize</a> to adjust. (command ''fontfamily`` is not active for command ''legend``) |
14066 | bpr | 2875 | @%legend%size 400,400%xrange -10,10%yrange -10,10%bgcolor white%fontsize 16%legend legend 1:legend 2:legend 3:legend 4:this is legend 5:legend 6:another legend abc%legendcolors red:green:blue%grid 1,1,white%# note: command "grid" is mandatory%# just set grid invisible if not wanted |
11806 | schaersvoo | 2876 | */ |
2877 | temp = get_string(infile,1); |
||
2878 | if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); } |
||
14066 | bpr | 2879 | legend_cnt++; /* attention: starts with -1: it will be used in piechart etc */ |
11806 | schaersvoo | 2880 | fprintf(js_include_file,"var legend%d = [\"%s\"];",legend_cnt,temp); |
2881 | break; |
||
2882 | |||
2883 | case LEGENDCOLORS: |
||
2884 | /* |
||
2885 | @ legendcolors color1:color2:color3:...:color_n |
||
14379 | bpr | 2886 | @ will be used to color a legend: use this command after the legend command ! e.g. <code>legend test1:test2:test3<br />legendcolors blue:red:orange</code>. |
2887 | @ make sure the number of colors match the number of legend items |
||
15111 | schaersvoo | 2888 | @ command ''legend`` in case of ''piechart`` and ''barchart`` will use these colours per default (no need to specify ''legendcolors``) |
13960 | bpr | 2889 | @%legendcolors%size 400,400%xrange -10,10%yrange -10,10%fontsize 18%legend legend 1:legend 2:legend 3%legendcolors red:green:blue%grid 1,1,grey |
11806 | schaersvoo | 2890 | */ |
2891 | if(legend_cnt == -1){canvas_error("use command \"legend\" before command \"legendcolors\" ! ");} |
||
2892 | temp = get_string(infile,1); |
||
2893 | if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); } |
||
2894 | fprintf(js_include_file,"var legendcolors%d = [\"%s\"];",legend_cnt,temp); |
||
2895 | break; |
||
2896 | |||
14078 | bpr | 2897 | case LINEGRAPH: /* scheme: var linegraph_0 = [ 'stroke_color','line_width','use_dashed', 'dashtype0','dashtype1','x1','y1',...,'x_n','y_n'];*/ |
11806 | schaersvoo | 2898 | /* |
2899 | @ linegraph x1:y1:x2:y2...x_n:y_n |
||
2900 | @ will plot your data in a graph |
||
14066 | bpr | 2901 | @ may <b>only</b> to be used together with command <a href='#grid'>grid</a> |
2902 | @ can be used together with freestyle x-axis/y-axis texts: see commands <a href='#xaxis'>xaxis</a>,<a href='#xaxisup'>xaxisup</a> and <a href='#yaxis'>yaxis</a> |
||
2903 | @ use command <a href='#legend'>legend</a> to provide an optional legend in right-top-corner |
||
2904 | @ also see command <a href='#piechart'>piechart</a> |
||
11806 | schaersvoo | 2905 | @ multiple linegraphs may be used in a single plot |
14066 | bpr | 2906 | @ note: your arguments are not checked by canvasdraw: use your javascript console in case of trouble... |
14379 | bpr | 2907 | @ <ul><li>use command <a href='#strokecolor'>strokecolor</a> before a command ''linegraph`` to set the color of this graph</li><li>use command <a href='#linewidth'>linewidth</a> before command ''linegraph`` to set linewidth of this graph</li><li>use keyword <a href='#dashed'>dashed</a> before command ''linegraph`` to set dashing of the graph</li><li>if dashing is set, use command <a href='#dashtype'>dashtype</a> before command ''linegraph`` to set the type of dashing of the (individual) graph</li></ul> |
12107 | schaersvoo | 2908 | @%linegraph%size 400,400%xrange -10,10%yrange -10,10%strokecolor red%linegraph -10:1:-5:-1:3:3:10:-5%strokecolor blue%linegraph -10:-1:-5:1:3:-3:10:5%dashed%strokecolor green%linegraph -10:2:-5:-2:3:4:10:2%grid 1,1,grey |
11806 | schaersvoo | 2909 | */ |
2910 | temp = get_string(infile,1); |
||
2911 | if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); } |
||
2912 | fprintf(js_include_file,"var linegraph_%d = [\"%s\",\"%d\",\"%d\",\"%d\",\"%d\",\"%s\"];",linegraph_cnt,stroke_color,line_width,use_dashed,dashtype[0],dashtype[1],temp); |
||
2913 | linegraph_cnt++; |
||
2914 | reset(); |
||
2915 | break; |
||
2916 | |||
2917 | case MATHML: |
||
2918 | /* |
||
15111 | schaersvoo | 2919 | @ mathml x1,y1,mathml_string |
14230 | schaersvoo | 2920 | @ this command is special for GECKO browsers, and it makes use of Native Mathml |
15313 | schaersvoo | 2921 | @ For general use with all browsers, use command <a href='#latex'>latex</a> |
2922 | @ can be set <a href='onclick'>onclick</a> and <a href='drag'>drag&drop</a> <br />Note: dragging is fairly primitive dragging of the div-element, and is not done using the <em>dragstuff library</em> |
||
15111 | schaersvoo | 2923 | @ command <a href='#affine'>affine</a> will produce CSS3 matrix transformations |
2924 | @ command <a href='#rotate'>rotate</a> will rotate the object |
||
15315 | bpr | 2925 | @ the mathml object is centered at (x1:y1) |
14379 | bpr | 2926 | @ the ''mathml_string`` can be produced using WIMS commands like ''texmath`` followed by ''mathmlmath``... or write correct TeX and use only ''mathmlmath`` |
15313 | schaersvoo | 2927 | @ mathml will be displayed in a rectangle left top (x1:y1) |
14247 | bpr | 2928 | @ can be set onclick <code>javascript:read_dragdrop();</code> will return click numbers of mathml-objects; if 4 clickable object are drawn, the reply could be 1,0,1,0 ... meaning clicked on the first and third object |
14379 | bpr | 2929 | @ can be set draggable: <code>javascript:read_dragdrop()</code> will return all coordinates in same order as the canvas script: unmoved objects will have their original coordinates... |
14247 | bpr | 2930 | @ snaptogrid is supported...snaptopoints will work, but use with care... due to the primitive dragging. Technically: the dragstuff library is not used... the mathml is embedded in a new div element and not in the html5-canvas. |
2931 | @ when clicked, the mathml object will be drawn in red color; the div background color will be determined by the <a href="#fillcolor">fillcolor</a> and <a href="#opacity">opacity</a> settings. |
||
15111 | schaersvoo | 2932 | @ userdraw may be combined with 'mathml' ; the read_canvas() will contain the drawing. |
2933 | @ draggable or onclick 'external images' from command <a href='#copyresized'>copy or copyresized</a> can be combined with drag and/or onclick mathml |
||
14078 | bpr | 2934 | @ other drag objects (circles/rects etc) are supported, but read_dragdrop() will probably be difficult to interpret... |
14066 | bpr | 2935 | @ if inputfields are incorporated in mathml (with id's: id='mathml0',id='mathml1',...id='mathml_n')<br />the user_input values will be read by javascript:read_mathml();<br /><b>attention</b>: if after this mathml-input object other user-interactions are included, these will read mathml too using "read_canvas();" |
11806 | schaersvoo | 2936 | @ If other inputfields (command input / command textarea) or userdraw is performed, the function read_canvas() will not read mathml. Use some generic function to read it.... |
14038 | schaersvoo | 2937 | @ use keyword <a href='#centered'>centered</a> to center the mathml/xml object on (x1:y1) |
15313 | schaersvoo | 2938 | @%mathml_onclick%size 400,400%xrange -10,10%yrange -10,10%onclick%strokecolor red%mathml -5,5,<span style="font-size:1em;"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mstyle id="wims_mathml366290"><mrow><mo stretchy="true">[</mo><mtable rowspacing="0.5ex" columnalign=" left " columnlines=" none " rowlines=" none " ><mtr><mtd><mi>f</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><mstyle displaystyle="true"><mfrac><mn>1</mn><mn>2</mn></mfrac></mstyle><mo>⋅</mo><msup><mi>x</mi> <mn>2</mn></msup></mtd></mtr> <mtr><mtd><mi>g</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><msqrt><mstyle displaystyle="true"><mfrac><mn>1</mn><mrow><msup><mi>x</mi> <mn>2</mn></msup></mrow></mfrac></mstyle></msqrt></mtd></mtr></mtable><mo stretchy="true">]</mo></mrow></mstyle></math></span>%onclick%strokecolor blue%mathml 5,5,<span style="font-size:1em;"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mstyle id="wims_mathml580175" ><mrow><mo stretchy="true">[</mo><mtable rowspacing="0.5ex" columnalign=" left " columnlines=" none " rowlines="none"><mtr><mtd><mi>f</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><mstyle displaystyle="true"><mfrac><mn>1</mn><mrow><mi>sin</mi><mrow><mo stretchy="true">(</mo><msup><mi>x</mi> <mn>2</mn></msup><mo stretchy="true">)</mo></mrow></mrow></mfrac></mstyle></mtd></mtr> <mtr><mtd><mi>g</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><msqrt><mrow><mi>sin</mi><mrow><mo stretchy="true">(</mo><msup><mi>x</mi> <mn>2</mn></msup><mo stretchy="true">)</mo></mrow></mrow></msqrt></mtd></mtr></mtable><mo stretchy="true">]</mo></mrow></mstyle></math></span> |
2939 | @%mathml_drag%size 400,400%xrange -10,10%yrange -10,10%drag xy%strokecolor red%mathml -5,5,<span style="font-size:1em;"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mstyle id="wims_mathml366290"><mrow><mo stretchy="true">[</mo><mtable rowspacing="0.5ex" columnalign=" left " columnlines=" none " rowlines=" none "><mtr><mtd><mi>f</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><mstyle displaystyle="true"><mfrac><mn>1</mn><mn>2</mn></mfrac></mstyle><mo>⋅</mo><msup><mi>x</mi> <mn>2</mn></msup></mtd></mtr> <mtr><mtd><mi>g</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><msqrt><mstyle displaystyle="true"><mfrac><mn>1</mn><mrow><msup><mi>x</mi> <mn>2</mn></msup></mrow></mfrac></mstyle></msqrt></mtd></mtr></mtable><mo stretchy="true">]</mo></mrow></mstyle></math></span>%drag xy%strokecolor blue%mathml 5,5,<span style="font-size:1em;"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mstyle id="wims_mathml580175" ><mrow><mo stretchy="true">[</mo><mtable rowspacing="0.5ex" columnalign=" left " columnlines=" none " rowlines=" none "><mtr><mtd><mi>f</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><mstyle displaystyle="true"><mfrac><mn>1</mn><mrow><mi>sin</mi><mrow><mo stretchy="true">(</mo><msup><mi>x</mi> <mn>2</mn></msup><mo stretchy="true">)</mo></mrow></mrow></mfrac></mstyle></mtd></mtr> <mtr><mtd><mi>g</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><msqrt><mrow><mi>sin</mi><mrow><mo stretchy="true">(</mo><msup><mi>x</mi> <mn>2</mn></msup><mo stretchy="true">)</mo></mrow></mrow></msqrt></mtd></mtr></mtable><mo stretchy="true">]</mo></mrow></mstyle></math></span>%#click left top corner...then drag... |
||
11806 | schaersvoo | 2940 | */ |
15111 | schaersvoo | 2941 | js_function[DRAW_XML] = 1; |
2942 | for(i=0;i<3;i++){ |
||
11806 | schaersvoo | 2943 | switch(i){ |
15111 | schaersvoo | 2944 | case 0: double_data[0]=get_real(infile,0);break; /* x in x/y-range coord system -> pixel width */ |
2945 | case 1: double_data[1]=get_real(infile,0);break; /* y in x/y-range coord system -> pixel height */ |
||
2946 | case 2: decimals = find_number_of_digits(precision); |
||
2947 | |||
2948 | if(use_affine == TRUE ){ transform(2,2);}/* needs double_data[] */ |
||
2949 | if( use_offset != 0 || drag_type != -1 ){int_data[2] = 1;}else{int_data[2] = 0;} /* only centered or not-centered */ |
||
2950 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
2951 | int_data[0] = x2px(double_data[0]);/* needs px */ |
||
2952 | int_data[1] = y2px(double_data[1]); |
||
2953 | if( use_slider != -1 && onclick == 0 ){ onclick = 3;}/* no drag&onclick but slideable */ |
||
15116 | bpr | 2954 | if( use_slider != -1 && drag_type != -1){ onclick = 5; } |
11806 | schaersvoo | 2955 | temp = get_string(infile,1); |
2956 | if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'"); } |
||
15111 | schaersvoo | 2957 | string_length = 1 + snprintf(NULL,0,"var draw_xml%d = {id:%d,type:'mathml',x:[%d],y:[%d],mathml:\"%s\",drag_type:%d,onclick:%d,object_cnt:%d,stroke_color:\"%s\",stroke_opacity:%.2f,fill_color:\"%s\",fill_opacity:%.2f,use_center:%d,use_snap:%d,angle:%f,fontfamily:\"%s\",transform:%s,use_affine:%d,offset:[0,0],use_slider:%d,rotation_center:%s,once:true};draw_xml(draw_xml%d);slidergroup[%d] = null;\n",drawxml_cnt,drawxml_cnt,int_data[0],int_data[1],temp,drag_type,onclick,object_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,int_data[2],use_snap,angle,font_family,doubledata2js_array(affine_matrix,6,decimals),use_affine,use_slider,rotation_center,drawxml_cnt,object_cnt); |
14208 | schaersvoo | 2958 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
15111 | schaersvoo | 2959 | snprintf(tmp_buffer,string_length, "var draw_xml%d = {id:%d,type:'mathml',x:[%d],y:[%d],mathml:\"%s\",drag_type:%d,onclick:%d,object_cnt:%d,stroke_color:\"%s\",stroke_opacity:%.2f,fill_color:\"%s\",fill_opacity:%.2f,use_center:%d,use_snap:%d,angle:%f,fontfamily:\"%s\",transform:%s,use_affine:%d,offset:[0,0],use_slider:%d,rotation_center:%s,once:true};draw_xml(draw_xml%d);slidergroup[%d] = null;\n",drawxml_cnt,drawxml_cnt,int_data[0],int_data[1],temp,drag_type,onclick,object_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,int_data[2],use_snap,angle,font_family,doubledata2js_array(affine_matrix,6,decimals),use_affine,use_slider,rotation_center,drawxml_cnt,object_cnt); |
11806 | schaersvoo | 2960 | add_to_buffer(tmp_buffer); |
15111 | schaersvoo | 2961 | if(onclick != 0 ){object_cnt++;} |
2962 | drawxml_cnt++;/* keeps track on imported img,div,p,span,mathml,svg */ |
||
11806 | schaersvoo | 2963 | /* |
15111 | schaersvoo | 2964 | in case inputs are present, trigger adding the read_mathml() |
2965 | if no other reply_format is defined |
||
2966 | note: all other reply types will include a reading of elements with id='mathml'+p) |
||
2967 | */ |
||
2968 | if(strstr(temp,"mathml0") != NULL){ if(reply_format == 0 ){reply_format = 16;}} /* no other reply type is defined */ |
||
11806 | schaersvoo | 2969 | break; |
15116 | bpr | 2970 | default:break; |
11806 | schaersvoo | 2971 | } |
2972 | } |
||
15111 | schaersvoo | 2973 | reset(); |
11806 | schaersvoo | 2974 | break; |
2975 | |||
2976 | case MOUSE: |
||
2977 | /* |
||
2978 | @ mouse color,fontsize |
||
15313 | schaersvoo | 2979 | @ will display the cursor (x:y) coordinates in ''color`` and ''fontsize`` using default fontfamily Arial |
14379 | bpr | 2980 | @ note: use command ''mouse`` at the end of your script code (the same is true for command ''zoom``) |
12107 | schaersvoo | 2981 | @%mouse%size 400,400%xrange -10,10%yrange -10,10%mouse red,22 |
11806 | schaersvoo | 2982 | */ |
2983 | stroke_color = get_color(infile,0); |
||
2984 | font_size = (int) (get_real(infile,1)); |
||
2985 | tmp_buffer = my_newmem(26); |
||
13371 | schaersvoo | 2986 | snprintf(tmp_buffer,26,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer); |
15111 | schaersvoo | 2987 | add_js_mouse(MOUSE_CANVAS,precision,stroke_color,font_size,stroke_opacity,2); |
2988 | js_function[INTERACTIVE] = 1; |
||
11806 | schaersvoo | 2989 | break; |
2990 | |||
2991 | |||
2992 | case MOUSE_DEGREE: |
||
2993 | /* |
||
2994 | @ mouse_degree color,fontsize |
||
15313 | schaersvoo | 2995 | @ will display the angle in degrees between x-axis, (0:0) and the cursor (x:y) in 'color' and 'font size'<br /> using a fontfamily Arial |
11806 | schaersvoo | 2996 | @ The angle is positive in QI and QIII and the angle value is negative in QII and QIV |
15111 | schaersvoo | 2997 | @ note: use command 'mouse' at the end of your script code (the same is true for command 'zoom') |
12107 | schaersvoo | 2998 | @%mouse_degree%size 400,400%xrange -10,10%yrange -10,10%userdraw arc,blue%precision 100000%mouse_degree red,22 |
11806 | schaersvoo | 2999 | */ |
3000 | stroke_color = get_color(infile,0); |
||
3001 | font_size = (int) (get_real(infile,1)); |
||
3002 | tmp_buffer = my_newmem(26); |
||
13371 | schaersvoo | 3003 | snprintf(tmp_buffer,26,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer); |
15111 | schaersvoo | 3004 | add_js_mouse(MOUSE_CANVAS,precision,stroke_color,font_size,stroke_opacity,3); |
11806 | schaersvoo | 3005 | js_function[JS_FIND_ANGLE] = 1; |
15111 | schaersvoo | 3006 | js_function[INTERACTIVE] = 1; |
11806 | schaersvoo | 3007 | break; |
3008 | case MOUSE_DISPLAY: |
||
3009 | /* |
||
3010 | @ display TYPE,color,fontsize |
||
15111 | schaersvoo | 3011 | @ TYPE may be x | y | xy | degree | radian | radius |
3012 | @ will display the mouse cursor coordinates as x-only,y-only,(x:y), the radius of a circle (this only in case 'userdraw circle(s),color') or the angle in degrees or radians for commands <code>userdraw arc,color</code> or protractor, ruler (if set dynamic). |
||
15650 | reyssat | 3013 | @ use commands ''xunit`` and / or ''yunit`` to add the units to the mouse values. The ''degree | radian`` will always have the appropriate symbol). |
14077 | bpr | 3014 | @ just like commands ''mouse``, ''mousex``, ''mousey``, ''mouse_degree``... only other name |
12111 | schaersvoo | 3015 | @%display_x%size 400,400%xrange -10,10%yrange -10,10%xunit \\u212B%display x,red,22 |
12107 | schaersvoo | 3016 | @%display_y%size 400,400%xrange -10,10%yrange -10,10%yunit seconds%display y,red,22 |
13936 | bpr | 3017 | @%display_xy%size 400,400%xrange -10,10%yrange -10,10%xunit centimetre%yunit seconds%display xy,red,22%userdraw segments,blue |
12107 | schaersvoo | 3018 | @%display_deg%size 400,400%xrange -10,10%yrange -10,10%display degree,red,22%fillcolor orange%opacity 200,50%userdraw arc,blue |
3019 | @%display_rad%size 400,400%xrange -10,10%yrange -10,10%display radian,red,22%fillcolor orange%opacity 200,50%userdraw arc,blue |
||
12111 | schaersvoo | 3020 | @%display_radius%size 400,400%xrange -10,10%yrange -10,10%xunit cm%xunit \\u212b%display radius,red,22%userdraw circle,blue |
11806 | schaersvoo | 3021 | */ |
3022 | temp = get_string_argument(infile,0); |
||
3023 | if( strstr(temp,"xy") != NULL ){ |
||
3024 | int_data[0] = 2; |
||
3025 | }else{ |
||
3026 | if( strstr(temp,"y") != NULL ){ |
||
3027 | int_data[0] = 1; |
||
3028 | }else{ |
||
3029 | if( strstr(temp,"x") != NULL ){ |
||
3030 | int_data[0] = 0; |
||
3031 | }else{ |
||
3032 | if(strstr(temp,"degree") != NULL){ |
||
3033 | int_data[0] = 3; |
||
3034 | js_function[JS_FIND_ANGLE] = 1; |
||
3035 | }else{ |
||
3036 | if(strstr(temp,"radian") != NULL){ |
||
3037 | int_data[0] = 4; |
||
3038 | js_function[JS_FIND_ANGLE] = 1; |
||
3039 | }else{ |
||
3040 | if(strstr(temp,"radius") != NULL){ |
||
3041 | int_data[0] = 5; |
||
3042 | }else{ |
||
3043 | int_data[0] = 2; |
||
3044 | } |
||
3045 | } |
||
3046 | } |
||
3047 | } |
||
3048 | } |
||
3049 | } |
||
3050 | stroke_color = get_color(infile,0); |
||
3051 | font_size = (int) (get_real(infile,1)); |
||
3052 | tmp_buffer = my_newmem(26); |
||
13371 | schaersvoo | 3053 | snprintf(tmp_buffer,26,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer); |
15111 | schaersvoo | 3054 | add_js_mouse(MOUSE_CANVAS,precision,stroke_color,font_size,stroke_opacity,int_data[0]); |
3055 | js_function[INTERACTIVE] = 1; |
||
11806 | schaersvoo | 3056 | break; |
3057 | |||
3058 | case MOUSE_PRECISION: |
||
3059 | /* |
||
3060 | @ precision int |
||
3061 | @ 1 = no decimals ; 10 = 1 decimal ; 100 = 2 decimals etc |
||
3062 | @ may be used / changed before every object |
||
15111 | schaersvoo | 3063 | @ In case of user interaction (like ''userdraw`` or ''multidraw``), this value will be used to determine the amount of decimals in the reply / answer |
13936 | bpr | 3064 | @%precision%size 400,400%xrange -10,10%yrange -10,10%precision 1%userdraw segment,red |
11806 | schaersvoo | 3065 | */ |
3066 | precision = (int) (get_real(infile,1)); |
||
3067 | if(precision < 1 ){precision = 1;}; |
||
3068 | break; |
||
3069 | |||
3070 | case MOUSEX: |
||
3071 | /* |
||
3072 | @ mousex color,fontsize |
||
15313 | schaersvoo | 3073 | @ will display the cursor x-coordinate in ''color`` and ''font size`` using the fontfamily Arial. |
14247 | bpr | 3074 | @ note: use command ''mouse`` at the end of your script code (the same is true for command ''zoom``). |
11806 | schaersvoo | 3075 | |
3076 | */ |
||
3077 | stroke_color = get_color(infile,0); |
||
3078 | font_size = (int) (get_real(infile,1)); |
||
3079 | tmp_buffer = my_newmem(26); |
||
13371 | schaersvoo | 3080 | snprintf(tmp_buffer,26,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer); |
15111 | schaersvoo | 3081 | add_js_mouse(MOUSE_CANVAS,precision,stroke_color,font_size,stroke_opacity,0); |
3082 | js_function[INTERACTIVE] = 1; |
||
11806 | schaersvoo | 3083 | break; |
3084 | case MOUSEY: |
||
3085 | /* |
||
3086 | @ mousey color,fontsize |
||
15313 | schaersvoo | 3087 | @ will display the cursor y-coordinate in ''color`` and ''font size`` using default fontfamily Arial. |
14247 | bpr | 3088 | @ note: use command ''mouse`` at the end of your script code (the same is true for command ''zoom``). |
11806 | schaersvoo | 3089 | |
3090 | */ |
||
3091 | stroke_color = get_color(infile,0); |
||
3092 | font_size = (int) (get_real(infile,1)); |
||
3093 | tmp_buffer = my_newmem(26); |
||
13371 | schaersvoo | 3094 | snprintf(tmp_buffer,26,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer); |
15111 | schaersvoo | 3095 | add_js_mouse(MOUSE_CANVAS,precision,stroke_color,font_size,stroke_opacity,1); |
3096 | js_function[INTERACTIVE] = 1; |
||
11806 | schaersvoo | 3097 | break; |
3098 | |||
3099 | case MULTIDASH: |
||
3100 | /* |
||
3101 | @ multidash 0,1,1 |
||
14071 | bpr | 3102 | @ meaning draw objects no. 2 (circle) and 3 (segments), in the list of command like <code>multifill points,circle,segments</code>, are dashed |
14066 | bpr | 3103 | @ use before command <a href='#multidraw'>multidraw</a> |
14247 | bpr | 3104 | @ if not set all objects will be set ''not dashed``... unless a generic keyword ''dashed`` was given before command ''multidraw`` |
15111 | schaersvoo | 3105 | @ the dash-type is not -yet- adjustable <br />(e.g. command <code>dashtype line_px,space_px</code> will give no control over multidraw objects) |
11806 | schaersvoo | 3106 | @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives... |
14077 | bpr | 3107 | @ always use the same sequence as is used for ''multidraw`` |
11806 | schaersvoo | 3108 | */ |
3109 | if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
||
3110 | temp = get_string(infile,1); |
||
3111 | temp = str_replace(temp,",","\",\""); |
||
3112 | fprintf(js_include_file,"var multidash = [\"%s\"];",temp); |
||
3113 | reset();/* if command 'dashed' was given...reset to not-dashed */ |
||
3114 | break; |
||
3115 | |||
3116 | case MULTIDRAW: |
||
3117 | /* |
||
3118 | @ multidraw obj_type_1,obj_type_2...obj_type_11 |
||
14066 | bpr | 3119 | @ for simple single object user drawings you could also use command <a href="#userdraw">userdraw</a> |
16828 | schaersvoo | 3120 | @ implemented obj_types:<ul><li>point | points</li><li>circle | circles</li><li>line | lines</li><li>segment | segments</li><li>arrow | arrows (use command 'arrowhead int' for size (default value 8 pixels))</li><li>curvedarrow | curvedarrows</li><li>rect | rects</li><li>closedpoly<br /><b>only one</b> closedpolygon may be drawn.The number of ''corner points`` is not preset (e.g. not limited, freestyle), the polygon is closed when clicking on the first point again..(+/- 10px)</li><li>triangle | triangles</li><li>parallelogram | parallelograms</li><li>poly[3-9] | polys[3-9] draw 3...9 point polygone(s): polys3 is of course triangles</li><li>images</li><li>crosshair | crosshairs</li><li>function <br/>for more function user input fields, use it multiple times<br />for 4 inputfields use : multidraw function,function,function,function</li></ul> |
15111 | schaersvoo | 3121 | @ additionally objects may be user labelled, using obj_type ''text``...<br />in this case allways a text input field and if <a href='#multiuserinput'> multiuserinput=1 </a> also (x:y) inputfields will be added to the page.<br />use commands ''fontfamily`` and ''fontcolor`` to adjust (command ''multistrokeopacity`` may be set to adjust text opacity)<br />note: text is always centered on the mouse-click or user-input coordinates !<br />note: no keyboard listeners are used |
3122 | @ it makes no sense using something like ''multidraw point,points`` ... <br />something like "multidraw polys4,polys7" will only result in drawing a ''4 point polygone`` and not a ''7 point polygone``: this is a design flaw and not a feature... |
||
3123 | @ note: mouselisteners are only active if "$status != done " (eg only drawing in an active/non-finished exercise) <br /> to overrule use command/keyword "status" (no arguments required) |
||
3124 | @ buttons for changing the obj_type (and in case of ''multiuserinput``, some inputfields and buttons) <br />will be present in the reserved div ''tooltip_div`` and can be styled using command 'css some_css' |
||
3125 | @ the button label will be default the ''object primitive name`` (like ''point``, ''circles``).<br />If you want a different label (e.g. an other language), use command ''multilabel``<br />for example in dutch: <br /><code>multilabel cirkel,lijnstuk,punten,STOP<br />multidraw circle,segment,points</code><br />(see command <a href='#multilabel'>multilabel</a> for more details) |
||
14063 | schaersvoo | 3126 | @ a right mouse button click will remove the last drawn object of the selected drawing type. All other type of objects are not removed |
15111 | schaersvoo | 3127 | @ multidraw is incompatible with command ''tooltip`` (the reserved div_area is used for the multidraw control buttons) |
3128 | @ all ''multidraw`` drawings will scale on zooming.<br />this in contrast to the command <a href="#userdraw">userdraw</a>. |
||
3129 | @ wims will <b>not</b> check the amount or validity of your command arguments ! <br />( use javascript console to debug any typo's ) |
||
16844 | bpr | 3130 | @ a local function <code>read_canvas%d</code> will read all userbased drawings.<br />The output is always a 16 lines string with fixed sequence.<br/>line 1 = points_x+";"+points_y+"\\n"<br/>line 2 = circles_x+";"+circles_y+";"+multi_radius+"\\n"<br/>line 3 = segments_x+";"+segments_y+"\\n"<br/>line 4 = arrows_x+";"+arrows_y+"\\n"<br/>line 5 = lines_x+";"+lines_y+"\\n"<br/>line 6 = triangles_x+";"+triangles_y+"\\n"<br/>line 7 = polys[3-9]_x+";"+polys[3-9]_y+"\\n"<br/>line 8 = rects_x +";"+rects_y+"\\n"<br />line 9 = closedpoly_x+";"+closedpoly_y+"\\n"<br/>line 10 = parallelogram_x+";"+parallelogram_y"\\n"<br/>line 11 = text_x+";"+text_y+";"+text"\\n"<br />line 12 = image_x+";"+image_y+";"+image_id<br />line 13 = curvedarrows_x +";"+ curvedarrows_y +"\\n"<br />line 14 = curvedarrows2_x +";"+ curvedarrows2_y +"\\n"<br />line 15 = crosshairs_x +";"+ crosshairs_y +"\\n"<br />line 16 = userdraw_x +";"+userdraw_y + "\\n" note: this is for single ''userdraw object,color`` and ''replyformat 29``<br/>line 17 = userdraw_x +";"+userdraw_y +";"+userdraw_radius + "\\n" note: this is for single ''userdraw object,color`` and ''replyformat 29``<br/>The x/y-data are in x/y-coordinate system and display precision may be set by a previous command ''precision 0 | 10 | 100 | 1000...``<br />In case of circles the radius is -for the time being- rounded to pixels<br /><b>use the wims "direct exec" tool to see the format of the reply</b> |
15111 | schaersvoo | 3131 | @ It is best to prepare / format the student reply in clientside javascript.<br />However in ''wims`` language you could use something like this<br />for example you are interested in the polys5 drawings of a pupil (the pupil may draw multiple poly5 objects...)<br />note: the reply for 2 poly5's is: x11,x12,x13,x14,x15,x21,x22,x23,x24,x25 ; y11,y12,y13,y14,y15,y21,y22,y23,y24,y25<br />rep = !line 7 of reply <br />rep = !translate ';' to '\\n' in $rep <br />pts = 5 # 5 points for polygon <br />x_rep = !line 1 of $rep <br />y_rep = !line 2 of $rep <br />tot = !itemcnt $x_rep <br />num_poly = $[$tot/$pts] <br />idx = 0 <br />!for p=1 to $num_poly <br /> !for s=1 to $pts <br /> !increase idx <br /> X = !item $idx of $x_rep <br /> Y = !item $idx of $y_rep <br /> # do some checking <br /> !next s <br />!next p <br /> |
14379 | bpr | 3132 | @ <b>attention</b>: for command argument ''closedpoly``, only one polygone can be drawn. The last point (e.g. the point clicked near the first point) of the array is removed. |
15111 | schaersvoo | 3133 | @ technical: all 10 ''draw primitives`` + ''text`` will have their own -transparent- PNG bitmap canvas. <br />So for example there can be a points_canvas entirely separated from a line_canvas.<br />This to avoid the need for a complete redraw when something is drawn to the canvas...(eg only the object_type_canvas is redrawn), this in contrast too many very slow do-it-all HTML5 canvas javascript libraries.<br />The mouselisteners are attached to the canvas-div element. |
3134 | @ a special object type is ''images``.<br />if used together with <a href='#imagepalette'>imagepalette</a> a image table will be integrated in the 'control section' of multidraw (set <code>multiuserinput 1</code> for ''images``) if not used with <a href='#imagepalette'>imagepalette</a>, provide the images or div's (<img> tag with bitmap or SVG or anything in a div element) somewhere on the html exercise page, with an onclick handler like:<br /><code><img src='gifs/images/dog.svg' onclick='javascript:place_image_on_canvas(this.id);' id="ext_image_1" /><br /><img src='gifs/fish.png' onclick='javascript:place_image_on_canvas(this.id);' id="another" /></code><br />etc ... when activating the multidraw ''image`` button, the images can be selected<br /> (left mouse button/onclick) and placed on the canvas...left mouse click.<br />using div's will enable you -amongst other content- to add math typesetting from the exercise page onto the canvas. |
||
3135 | @ When you are not content with the default ''multidraw control panel``, you can create your own interface, using a few javascript functions to call the drawprimitives, delete things and ''stop drawing`` in case you also want to drag&drop stuff...</br>To activate this feature, use <a href='#multilabel'>multilabel NOCONTROLS</a><br />The object types are internally represented by the following numbers (making typos will render your exercise null and void)<br/>point = 0<br />points =1<br />circle = 2<br />circles = 3<br />line = 4<br />lines = 5<br />segment = 6<br />segments = 7<br />arrow = 8<br />arrows = 9<br />triangle = 10<br />triangles = 11<br />closedspoly = 12<br />text = 13<br />rect = 14<br />rects = 15<br />poly[3-9] = 16<br />polys[3-9] = 17<br />parallelogram = 18<br />parallelograms = 19<br />images = 20<br />curvedarrow = 21<br />curvedarrows = 22<br />curvedarrow2 = 23<br />curvedarrows2 = 24<br />crosshair = 25<br />crosshairs = 26 <br />controls for example:<br /><code><input type='button' onclick='javascript:userdraw_primitive=null' value='STOP DRAWING' /><br /><input type='button' onclick='javascript:userdraw_primitive=24;multidraw_object_cnt = 0;' value='start drawing curvedarrows2' /> <br /><input type='button' onclick='javascript:var fun=eval("clear_draw_area"+canvas_scripts[0]);fun(24,0);' value='REMOVE LAST CURVEDARROW ' /> </code><br/> If using multiple canvas scripts in a single page, loop through the canvas_scripts[n] <br />note: if using NOCONTROLS and just a single draw primitive (for example, just: 'multidraw circles'), the object may be drawn directly. (analogue to 'userdraw circles,color')<br />And since a right mouse button click will always remove the last drawn object of the current object type, there is no need for a special "remove button" |
||
16828 | schaersvoo | 3136 | @%multidraw_function%size 400,400%xrange -10,10%yrange -10,10%fontfamily Italic 22px Helvetica%axis%axisnumbering%precision 0%grid 2,2,grey,1,1,5,black%multicolors red,green,blue%fontcolor orange%multilinewidth 1,2,3%multidraw text,function,function,function,line |
12107 | schaersvoo | 3137 | @%multidraw%size 400,400%xrange -10,10%yrange -10,10%multidash 1,0%multilinewidth 1,2%multistrokecolors red,blue%multisnaptogrid 1,1%multilabel LINES,CIRCLES,STOP DRAWING%multidraw lines,circles |
15313 | schaersvoo | 3138 | @%multidraw_images%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%drag xy%# use special function to read the drag coordinates%copy 0,0,-1,-1,-1,-1,gifs/images/skull_and_crossbones50.png%fontcolor green%fontfamily Bold 42pt Arial%imagepalette gifs/ca.gif,gifs/en.gif,gifs/nl.gif,gifs/fr.gif,gifs/cn.gif,gifs/de.gif,gifs/kh.gif,gifs/it.gif%multiuserinput 0,0,1%css color:blue;%multisnaptogrid 1,1,1%multilinewidth 0,4,0%# attention: use unicode text input without the slash %# \u222D ---> u222D at least will sometimes work%# otherwise cut&past unicode symbols into inputfield...%multilabel TEXT,REACTION ARROW,FLAGS,STOP DRAWING%multidraw text,arrow,images |
3139 | @%multidraw_demo%size 800,800%xrange -10,10%yrange -10,10%axis%axisnumbering%precision 1%grid 2,2,grey,2,2,5,grey%css color:blue;%fontfamily Italic 42pt Arial%precision 1%opacity 200,50%snaptogrid%linewidth 3%filled%multistrokecolors red,green,blue,orange,yellow,purple,black,cyan,red,green,blue,orange,green,purple,black,cyan%multifillcolors red,green,blue,orange,yellow,purple,black,cyan,red,green,blue,orange,brown,purple%imagepalette gifs/ca.gif,gifs/en.gif,gifs/nl.gif,gifs/fr.gif,gifs/cn.gif,gifs/de.gif,gifs/kh.gif,gifs/it.gif%multidraw closedpoly,segments,rect,parallelogram,triangles,poly5,points,lines,arrows,circles,text,curvedarrows,curvedarrows2,images |
||
16827 | schaersvoo | 3140 | @%multidraw_NOCONTROLS%size 400,400%xrange -10,10%yrange -10,10%grid 2,2,grey%linewidth 3%strokecolor green%fillcolor blue%filled%opacity 255,60%multilabel NOCONTROLS%multidraw circles%# RIGHT MOUSE CLICK REMOVES LAST OBJECT |
11806 | schaersvoo | 3141 | */ |
15111 | schaersvoo | 3142 | js_function[INTERACTIVE] = 1; |
15633 | bpr | 3143 | if(js_function[JS_ZOOM] == 1){use_zoom = 1;} /* use noisy zoom_code, when command zoom is given before command 'multidraw' */ |
14038 | schaersvoo | 3144 | if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
15111 | schaersvoo | 3145 | if( use_userdraw == 1 ){canvas_error("Only one userdraw primitive may be used in command 'userdraw' use command 'multidraw' for this...");} |
3146 | use_userdraw = 2; |
||
11806 | schaersvoo | 3147 | temp = get_string(infile,1); |
3148 | fprintf(js_include_file,"\ |
||
15111 | schaersvoo | 3149 | var MMP = %d;\ |
3150 | if( typeof(multisnaptogrid) == 'undefined' && multisnaptogrid == null){var multisnaptogrid = new Array(MMP);for(var i=0;i<MMP;i++){multisnaptogrid[i] = %d;};};\ |
||
3151 | if( typeof(multistrokecolors) === 'undefined' && multistrokecolors == null){ var multistrokecolors = new Array(MMP);for(var i=0;i<MMP;i++){multistrokecolors[i] = '%s';};};\ |
||
3152 | if( typeof(multifillcolors) === 'undefined' && multifillcolors == null ){var multifillcolors = new Array(MMP);for(var i=0;i<MMP;i++){multifillcolors[i] = '%s';};};\ |
||
3153 | if( typeof(multistrokeopacity) === 'undefined' && multistrokeopacity == null){var multistrokeopacity = new Array(MMP);for(var i=0;i<MMP;i++){multistrokeopacity[i] = %.2f;};};\ |
||
3154 | if( typeof(multifillopacity) === 'undefined' && multifillopacity == null){var multifillopacity = new Array(MMP);for(var i=0;i<MMP;i++){multifillopacity[i] = %.2f;};};\ |
||
3155 | if( typeof(multilinewidth) === 'undefined' && multilinewidth == null){var multilinewidth = new Array(MMP);for(var i=0;i<MMP;i++){multilinewidth[i] = %d;};};\ |
||
3156 | if( typeof(multifill) === 'undefined' && multifill == null){var multifill = new Array(MMP);for(var i=0;i<MMP;i++){multifill[i] = %d;};};\ |
||
3157 | if( typeof(multidash) === 'undefined' && multidash == null){var multidash = new Array(MMP);for(var i=0;i<MMP;i++){multidash[i] = %d;};};\ |
||
3158 | if( typeof(multilabel) === 'undefined' && multilabel == null){var multilabel = [\"%s\",\"stop drawing\"];};\ |
||
3159 | if( typeof(multiuserinput) === 'undefined' && multiuserinput == null){var multiuserinput = new Array(MMP);for(var i=0;i<MMP;i++){multiuserinput[i] = '0';};};\ |
||
3160 | var arrow_head = %d;var multifont_color = '%s';var multifont_family = '%s';var forbidden_zone = [xsize+2,ysize+2];", |
||
3161 | MAX_MULTI_PRIMITIVES, |
||
3162 | use_snap, |
||
3163 | stroke_color, |
||
3164 | fill_color, |
||
3165 | stroke_opacity, |
||
3166 | fill_opacity, |
||
3167 | line_width, |
||
3168 | use_filled, |
||
3169 | use_dashed, |
||
3170 | str_replace(temp,",","\",\""), |
||
3171 | arrow_head,font_color,font_family); |
||
16827 | schaersvoo | 3172 | add_js_multidraw(temp,css_class,use_offset,int_data[MAX_MULTI_PRIMITIVES+1],crosshair_size,use_zoom); |
3173 | /* no_controls == int_data[MAX_MULTI_PRIMITIVES+1] */ |
||
3174 | reply_precision = precision; |
||
11806 | schaersvoo | 3175 | if(strstr(temp,"text") != NULL){ |
15111 | schaersvoo | 3176 | js_function[JS_SAFE_EVAL] = 1; |
16722 | schaersvoo | 3177 | js_function[DRAW_SUBSUP] = 1; |
11806 | schaersvoo | 3178 | } |
16827 | schaersvoo | 3179 | if(strstr(temp,"function") != NULL){ |
16832 | bpr | 3180 | int pp, funs = count_substring(temp, "function"); |
16827 | schaersvoo | 3181 | js_function[JS_SAFE_EVAL] = 1; |
3182 | js_function[JS_RAWMATH] = 1; |
||
3183 | js_function[DRAW_JSFUNCTION] = 1; |
||
3184 | js_function[JS_MATH] = 1; |
||
3185 | js_function[JS_PLOT] = 1; |
||
16832 | bpr | 3186 | for(pp = 0 ; pp< funs ;pp++){ |
16827 | schaersvoo | 3187 | add_input_jsfunction(css_class,function_label,input_cnt,stroke_color,stroke_opacity,line_width,use_dashed,dashtype[0],dashtype[1],font_size); |
3188 | input_cnt++; |
||
3189 | jsplot_cnt++; |
||
3190 | } |
||
3191 | fprintf(js_include_file,"if(typeof(all_jsplots) !== 'number'){var all_jsplots;};all_jsplots = %d;function redraw_userdraw(){redraw_jsplot();return;};",jsplot_cnt); |
||
3192 | } |
||
11806 | schaersvoo | 3193 | /* the canvasses range from 1000 ... 1008 */ |
3194 | if( reply_format == 0){reply_format = 29;} |
||
3195 | reset();/* if command 'filled' / 'dashed' was given...reset all */ |
||
3196 | break; |
||
3197 | case MULTILABEL: |
||
3198 | /* |
||
3199 | @ multilabel button_label_1,button_label_2,...,button_label_8,'stop drawing text' |
||
14066 | bpr | 3200 | @ use before command <a href='#multidraw'>multidraw</a> |
15111 | schaersvoo | 3201 | @ if not set all labels (e.g. the value of input type 'button') will be set by the english names for the draw_primitives (like 'point','circle'...) |
14071 | bpr | 3202 | @ the ''stop drawing`` button text <b>must</b> be the last item on the ''multilabel`` -list <br />for example:<br /><code>multilabel punten,lijnen,Stop met Tekenen<br />multidraw points,lines</code> |
15111 | schaersvoo | 3203 | @ all buttons can be ''styled`` by using command <code>css</code><br /><b>note:</b>If you want to add some CSS style to the buttons...<br />the id's of the ''draw buttons`` are their english command argument<br />(e.g. id="canvasdraw_points" for the draw points button).<br />the id of the ''stop drawing`` button is "canvasdraw_stop_drawing".<br />the id of the "OK" button is ''canvasdraw_ok_button`` |
3204 | @ wims will not check the amount or validity of your input |
||
3205 | @ always use the same sequence as is used for ''multidraw`` |
||
3206 | @ if you don't want the controls, and want to write your own interface, set <code>multilabel NOCONTROLS</code> |
||
11806 | schaersvoo | 3207 | */ |
3208 | if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
||
3209 | temp = get_string(infile,1); |
||
15116 | bpr | 3210 | if( strcasestr(temp,"NOCONTROLS") ){ |
15111 | schaersvoo | 3211 | int_data[MAX_MULTI_PRIMITIVES+1] = 1; /*int_data[25] = 1 --> 'no_controls = 1' in canvasmacro.c */ |
3212 | fprintf(js_include_file,"var multilabel = null;"); |
||
3213 | } |
||
3214 | else |
||
3215 | { |
||
3216 | int_data[MAX_MULTI_PRIMITIVES+1] = 0; /* so DO use control buttons etc */ |
||
3217 | temp = str_replace(temp,",","\",\""); |
||
3218 | fprintf(js_include_file,"var multilabel = [\"%s\"];",temp); |
||
3219 | } |
||
11806 | schaersvoo | 3220 | break; |
3221 | case MULTILINEWIDTH: |
||
3222 | /* |
||
3223 | @ multilinewidth linewidth_1,linewidth_2,...,linewidth_8 |
||
14066 | bpr | 3224 | @ use before command <a href='#multidraw'>multidraw</a> |
14071 | bpr | 3225 | @ if not set all line widths will be set by a previous command ''linewidth int`` |
3226 | @ use these up to 7 different line widths for the draw primitives used by command <code>multidraw obj_type_1,obj_type_2...obj_type_7</code> |
||
11806 | schaersvoo | 3227 | @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives... |
14071 | bpr | 3228 | @ always use the same sequence as is used for ''multidraw`` |
11806 | schaersvoo | 3229 | */ |
3230 | if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
||
3231 | temp = get_string(infile,1); |
||
3232 | temp = str_replace(temp,",","\",\""); |
||
3233 | fprintf(js_include_file,"var multilinewidth = [\"%s\"];",temp); |
||
3234 | break; |
||
3235 | case MULTIFILL: |
||
3236 | /* |
||
3237 | @ multifill 0,0,1,0,1,0,0 |
||
14071 | bpr | 3238 | @ meaning draw objects no. 3 and 5, in the list of command ''multifill``, are filled (if the object is fillable...and not a line,segment,arrow or point...) |
15111 | schaersvoo | 3239 | @ using a fillpattern: multifill 0,1,2,5,3,4<br />meaning: first object is not filled...second object is solid color filled...2=grid | 3=hatch | 4=diamond | 5=dot |
14066 | bpr | 3240 | @ use before command <a href='#multidraw'>multidraw</a> |
14246 | bpr | 3241 | @ if not set all objects -except point|points- will be set ''not filled``... unless a command <code>filled</code> was given before command <code>multifill</code> |
15651 | reyssat | 3242 | @ only suitable for draw_primitives like ''circle | circles``, ''triangle | triangles``, ''rect | rects``, ''poly[3-9] | polys[3-9]`` and ''polygon`` |
11806 | schaersvoo | 3243 | @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives... |
14071 | bpr | 3244 | @ always use the same sequence as is used for ''multidraw`` |
11806 | schaersvoo | 3245 | */ |
3246 | if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
||
15111 | schaersvoo | 3247 | i=0; |
3248 | while( ! done ){ /* get next item until EOL*/ |
||
3249 | if(i > MAX_MULTI_PRIMITIVES){canvas_error("too many multidraw primitives...read the documentation...");} |
||
3250 | int_data[i] = (int)(get_real(infile,1)); /* 0,1,2,3,4,5 */ |
||
3251 | if(int_data[i] < 0 || int_data[i] > 5 ){canvas_error("the only possible multifill arguments are: 0,1,2,3,4,5 ");} |
||
3252 | if(int_data[i] > 1 ){use_filled = 2;js_function[DRAW_FILL_PATTERN] = 1;}/* switch to trigger pattern filling */ |
||
15116 | bpr | 3253 | i++; |
15111 | schaersvoo | 3254 | } |
3255 | fprintf(js_include_file,"var multifill = %s ;",data2js_array(int_data,i-1)); |
||
11806 | schaersvoo | 3256 | break; |
3257 | |||
3258 | case MULTIFILLCOLORS: |
||
3259 | /* |
||
3260 | @ multifillcolors color_name_1,color_name_2,...,color_name_8 |
||
14066 | bpr | 3261 | @ use before command <a href='#multidraw'>multidraw</a> |
14078 | bpr | 3262 | @ if not set all fillcolors (for circle | triangle | poly[3-9] | closedpoly ) will be ''stroke_color``, ''fill_opacity`` |
14071 | bpr | 3263 | @ use these up to 6 colors for the draw primitives used by command <code>multidraw obj_type_1,obj_type_2...obj_type_n</code> |
11806 | schaersvoo | 3264 | @ wims will <b>not</b> check if the number of colours matches the amount of draw primitives... |
14379 | bpr | 3265 | @ always use the same sequence as is used for ''multidraw`` |
15111 | schaersvoo | 3266 | @ can also be used with command <a href='#userdraw'>userdraw clickfill,color</a> when more than one fillcolor is wanted.<br />in that case use for example <a href='#replyformat'>replyformat 10</a> ... reply=x1:y1:color1,x2:y2:color2...<br />the colors will restart at the first color, when there are more fill-clicks than multi-fill-colors<br />if more control over the used colours is wanted, see command <a href='#colorpalette'>colorpalette color1,color2...</a> |
11806 | schaersvoo | 3267 | */ |
3268 | if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
||
3269 | fprintf(js_include_file,"var multifillcolors = ["); |
||
3270 | while( ! done ){ |
||
3271 | temp = get_color(infile,1); |
||
3272 | fprintf(js_include_file,"\"%s\",",temp); |
||
3273 | } |
||
3274 | fprintf(js_include_file,"\"0,0,0\"];");/* add black to avoid trouble with dangling comma... */ |
||
3275 | break; |
||
3276 | |||
3277 | case MULTIFILLOPACITY: |
||
3278 | /* |
||
3279 | @ multifillopacity fill_opacity_1,fill_opacity_2,...,fill_opacity_8 |
||
3280 | @ float values 0 - 1 or integer values 0 - 255 |
||
14066 | bpr | 3281 | @ use before command <a href='#multidraw'>multidraw</a> |
14071 | bpr | 3282 | @ if not set all fill opacity_ will be set by previous command <code>opacity int,int</code> and keyword ''filled`` |
3283 | @ use these up to 7 different stroke opacities for the draw primitives used by command <code>multidraw obj_type_1,obj_type_2...obj_type_y</code> |
||
11806 | schaersvoo | 3284 | @ wims will not check the amount or validity of your input |
14071 | bpr | 3285 | @ always use the same sequence as is used for ''multidraw`` |
11806 | schaersvoo | 3286 | */ |
3287 | if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
||
3288 | temp = get_string(infile,1); |
||
3289 | temp = str_replace(temp,",","\",\""); |
||
3290 | fprintf(js_include_file,"var multifillopacity = [\"%s\"];",temp); |
||
3291 | break; |
||
3292 | case MULTISNAPTOGRID: |
||
3293 | /* |
||
3294 | @ multisnaptogrid 0,1,1 |
||
15715 | schaersvoo | 3295 | @ alternative: multisnap |
14071 | bpr | 3296 | @ meaning draw objects no. 2 (circle) and 3 (segments), in the list of command like <code>multifill points,circle,segments</code>, will snap to the xy-grid (default 1 in x/y-coordinate system: see command <a href='#snaptogrid'>snaptogrid</a>) |
3297 | @ freehand drawing...specify precision for reply: all objects snap to grid <code>multisnaptogrid 1,1,1,...</code> |
||
14246 | bpr | 3298 | @ only the xy-values snap_to_grid: all objects snap to grid <code>multisnaptogrid 1,1,1,...</code> |
14071 | bpr | 3299 | @ only the x-values snap_to_grid: all objects snap to x-grid <code>multisnaptogrid 2,2,2,...</code> |
3300 | @ only the y-values snap_to_grid: all objects snap to y-grid <code>multisnaptogrid 3,3,3,...</code> |
||
3301 | @ if <a href='#snaptopoints'>snaptopoints</a> is defined: all objects snap to points <code>multisnaptogrid 4,4,4,...</code> <br /><b>make sure to define the points to snap on...</b> use command <a href='#snaptopoints'>snaptopoints</a> |
||
3302 | @ <code>multisnaptogrid 0,1,2,3,4<br />multidraw text,arrow,line,circle,image</code><br />''text`` is free hand, ''arrow`` is snap to grid, ''line`` is snap to x-grid, ''circle`` is snap to y-grid, ''image`` is snap to points defined by command <a href='#snaptopoints'>snaptopoints</a> |
||
15111 | schaersvoo | 3303 | @ use before command <a href='#multidraw'>multidraw</a> |
3304 | @ attention: if not set all objects will be set ''no snap``... unless a generic command ''snaptogrid`` was given before command ''multidraw`` |
||
3305 | @ commands <a href='#xsnaptogrid'>xsnaptogrid</a>, <a href='#ysnaptogrid'>ysnaptogrid</a>, <a href='#snaptofunction'>snaptofunction</a> are <b>not</b> supported amd only functional for command <a href='#userdraw'>userdraw</a> |
||
14071 | bpr | 3306 | @ always use the same sequence as is used for ''multidraw`` |
11806 | schaersvoo | 3307 | @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives... |
3308 | */ |
||
3309 | if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
||
3310 | temp = get_string(infile,1); |
||
14038 | schaersvoo | 3311 | fprintf(js_include_file,"var multisnaptogrid = [%s];",temp); |
15111 | schaersvoo | 3312 | reset();/* if command 'dashed' was given...reset to not-dashed */ |
11806 | schaersvoo | 3313 | break; |
3314 | case MULTISTROKECOLORS: |
||
3315 | /* |
||
3316 | @ multistrokecolors color_name_1,color_name_2,...,color_name_8 |
||
14066 | bpr | 3317 | @ use before command <a href='#multidraw'>multidraw</a> |
14071 | bpr | 3318 | @ if not set all colors will be ''stroke_color``, ''stroke_opacity`` |
3319 | @ use these up to 6 colors for the draw primitives used by command <code>multidraw obj_type_1,obj_type_2...obj_type_7</code> |
||
11806 | schaersvoo | 3320 | @ wims will <b>not</b> check if the number of colours matches the amount of draw primitives... |
14071 | bpr | 3321 | @ always use the same sequence as is used for ''multidraw`` |
11806 | schaersvoo | 3322 | */ |
3323 | if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
||
3324 | fprintf(js_include_file,"var multistrokecolors = ["); |
||
3325 | while( ! done ){ |
||
3326 | temp = get_color(infile,1); |
||
3327 | fprintf(js_include_file,"\"%s\",",temp); |
||
3328 | } |
||
3329 | fprintf(js_include_file,"\"0,0,0\"];");/* add black to avoid trouble with dangling comma... */ |
||
3330 | break; |
||
3331 | case MULTISTROKEOPACITY: |
||
3332 | /* |
||
3333 | @ multistrokeopacity stroke_opacity_1,stroke_opacity_2,...,stroke_opacity_7 |
||
3334 | @ float values 0 - 1 or integer values 0 - 255 |
||
14066 | bpr | 3335 | @ use before command <a href='#multidraw'>multidraw</a> |
14071 | bpr | 3336 | @ if not set all stroke opacity_ will be set by previous command <code>opacity int,int</code> |
15111 | schaersvoo | 3337 | @ use these up to 7 different stroke opacities for the draw primitives used by command <code>multidraw obj_type_1,obj_type_2...obj_type_7</code> |
11806 | schaersvoo | 3338 | @ wims will not check the amount or validity of your input |
14071 | bpr | 3339 | @ always use the same sequence as is used for ''multidraw`` |
11806 | schaersvoo | 3340 | */ |
3341 | if( use_tooltip == 1){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
||
3342 | temp = get_string(infile,1); |
||
3343 | temp = str_replace(temp,",","\",\""); |
||
3344 | fprintf(js_include_file,"var multistrokeopacity = [\"%s\"];",temp); |
||
3345 | break; |
||
3346 | |||
3347 | case MULTIUSERINPUT: |
||
3348 | /* |
||
3349 | @ multiuserinput 0,1,1,0 |
||
15715 | schaersvoo | 3350 | @ alternative: multiinput |
15111 | schaersvoo | 3351 | @ meaning, when the command ''multidraw`` is used <code>multidraw circles,points,lines,triangles</code><br />objects ''points`` and ''lines`` may additionally be ''drawn`` by direct input (inputfields)<br/>all other objects must be drawn with a mouse |
3352 | @ in case of circle | circles a third inputfield for Radius (R) is added. The radius must be in the x/y coordinate system (x-range) and <b>not</b> in pixels...students don't think in pixels.<br />note: R-values will not snap-to-grid |
||
15651 | reyssat | 3353 | @ in case of line(s) | segment(s) | arrow(s) the user should write <b>x1:y1</b> in the first inputfield and <b>x2:y2</b> in the second.<br />These ''hints`` are pre-filled into the input field.<br />Other coordinate delimiters are '';`` and '',`` e.g. <b>x1;y1</b> or <b>x1,y1</b>.<br />An error message (alert box) will popup when things are not correctly... |
15111 | schaersvoo | 3354 | @ in case of a triangle | poly3, three inputfields are provided. |
15651 | reyssat | 3355 | @ in case of ''text`` and ''multiuserinput=1, 3`` inputfields will be shown: ''x,y,text`` |
3356 | @ in case of ''text`` and ''multiuserinput=0, 1`` inputfield will be shown: text ... a mouse click will place the text on the canvas. |
||
15111 | schaersvoo | 3357 | @ may be styled using command <a href="#css">css</a> |
3358 | @ an additional button ''stop drawing`` may be used to combine userbased drawings with ''drag∧drop`` or ''onclick`` elements |
||
3359 | @ when exercise if finished (status=done) the buttons will not be shown.<br />To override this default behaviour use command / keyword ''status`` |
||
3360 | @ use before command <a href='#multidraw'>multidraw</a> |
||
3361 | @ always use the same sequence as is used for ''multidraw`` |
||
11806 | schaersvoo | 3362 | */ |
3363 | /* simple rawmath and input check */ |
||
15111 | schaersvoo | 3364 | js_function[JS_SAFE_EVAL] = 1; |
11806 | schaersvoo | 3365 | temp = get_string(infile,1); |
3366 | temp = str_replace(temp,",","\",\""); |
||
3367 | fprintf(js_include_file,"var multiuserinput = [\"%s\"];",temp); |
||
3368 | break; |
||
15111 | schaersvoo | 3369 | case NORESET: |
3370 | /* |
||
15715 | schaersvoo | 3371 | @ noreset |
3372 | @ alternative: killreset |
||
15111 | schaersvoo | 3373 | @ keyword |
3374 | @ may come in handy if canvas script code is generated using loops |
||
3375 | @ if used the following properties will remain to be valid<br /><ul><li>filled</li><li>dash settings</li><li>onclick or drag settings</li><li>centering or offset</li></ul> |
||
3376 | @ if used again, these properies will be reset to the default values and normal behaviour is continued (e.g. the above properties will be reset after 'use' on a canvas object) |
||
3377 | @ etc etc |
||
15633 | bpr | 3378 | @ commands <a href='#slider'>slider</a>, <a href='#linear'>linear</a>, <a href='#rotate'>rotate</a>, <a href='#translate'>translate</a>, <a href='#affine'>affine</a> are always active until the 'kill' commands are given: <br /><a href='#killlinear'>killlinear</a>, <a href='#killrotate'>killrotate</a>, <a href='#killtranslate'>killtranslate</a> and <a href='#killaffine'>killaffine</a> |
3379 | @ commands like 'opacity', 'linewidth', 'fontsize', 'fontfamily' are only changed when redefined again |
||
15111 | schaersvoo | 3380 | @%noreset%size 400,400%xrange -10,10%yrange -10,10%noreset%drag xy%linewidth 4%filled%rect -4,4,-2,2,blue%triangle -3,-3,0,0,1,-5,green%circle 0,0,50,orange%noreset%rect 2,4,4,2,blue |
15758 | schaersvoo | 3381 | @%noreset_oefgraduation%size 800,100%xrange 0,11%yrange -1,1%hline 0,0,black%parallel 0,0,0,0.5,1,0,11,blue%noreset%onclick%centered%text black,1,0.6,large,20%text black,2,0.6,large,30%text black,3,0.6,large,40%text black,4,0.6,large,50%text black,5,0.6,large,60%text black,6,0.6,large,70%text black,7,0.6,large,80%text black,8,0.6,large,90%text black,9,0.6,large,100%text black,10,0.6,large,110 |
15111 | schaersvoo | 3382 | */ |
3383 | if(no_reset == FALSE){no_reset = TRUE;}else{no_reset = FALSE;reset();} |
||
3384 | break; |
||
11806 | schaersvoo | 3385 | case NOXAXIS: |
3386 | /* |
||
14252 | bpr | 3387 | @ noxaxis |
11806 | schaersvoo | 3388 | @ keyword |
3389 | @ if set, the automatic x-axis numbering will be ignored |
||
14252 | bpr | 3390 | @ use command <a href="#axis">axis</a> to have a visual x/y-axis lines (see command <a href="#grid">grid</a>) |
11806 | schaersvoo | 3391 | @ to be used before command grid (see <a href="#grid">command grid</a>) |
3392 | */ |
||
11891 | schaersvoo | 3393 | fprintf(js_include_file,"x_strings = {};x_strings_up = [];\n"); |
3394 | use_axis_numbering = -1; |
||
11806 | schaersvoo | 3395 | break; |
3396 | case NOYAXIS: |
||
3397 | /* |
||
14251 | bpr | 3398 | @ noyaxis |
11806 | schaersvoo | 3399 | @ keyword |
3400 | @ if set, the automatic y-axis numbering will be ignored |
||
14252 | bpr | 3401 | @ use command <a href="#axis">axis</a> to have a visual x/y-axis lines (see command <a href="#grid">grid</a>) |
11806 | schaersvoo | 3402 | @ to be used before command grid (see <a href="#grid">command grid</a>) |
3403 | */ |
||
11891 | schaersvoo | 3404 | fprintf(js_include_file,"y_strings = {};\n"); |
11806 | schaersvoo | 3405 | break; |
11890 | schaersvoo | 3406 | case NUMBERLINE: |
3407 | /* |
||
3408 | @ numberline x0,x1,xmajor,xminor,y0,y1 |
||
3409 | @ numberline is using xrange/yrange system for all dimensions |
||
11996 | schaersvoo | 3410 | @ multiple numberlines are allowed ; combinations with command <a href='#grid'>grid</a> is allowed; multiple commands <a href='#xaxis'>xaxis numbering</a> are allowed |
11890 | schaersvoo | 3411 | @ x0 is start x-value in xrange |
3412 | @ x1 is end x-value in xrange |
||
3413 | @ xmajor is step for major division |
||
14071 | bpr | 3414 | @ xminor is divisor of xmajor; using small (30% of major tick) tick marks: this behaviour is ''hardcoded`` |
3415 | @ is xminor is an even divisor, an extra tickmark (60% of major tick) is added to the numberline: this behaviour is ''hardcoded`` |
||
11890 | schaersvoo | 3416 | @ y0 is bottom of numberline; y1 endpoint of major tics |
13829 | bpr | 3417 | @ use command <a href="#linewidth">linewidth</a> to control appearance |
11890 | schaersvoo | 3418 | @ use <a href="#strokecolor">strokecolor</a> and <a href="#opacity">opacity</a> to controle measure line |
3419 | @ for all ticks linewidth and color / opacity are identical. |
||
3420 | @ if command <a href="#xaxis">xaxis</a> or <a href="#xaxisup">xaxisup</a> is not defined, the labeling will be on major ticks: x0...x1 |
||
13829 | bpr | 3421 | @ use <a href="#fontfamily">fontfamily</a> and <a href="#fontcolor">fontcolor</a> to control fonts settings |
14078 | bpr | 3422 | @ may be used together with <a href="#userdraw">userdraw</a>, <a href="#multidraw">multidraw</a> and <a href="#drag">user drag</a> command family for the extra object drawn onto the numberline |
11890 | schaersvoo | 3423 | @ <a href="#snaptogrid">snaptogrid, snaptopoints etc</a> and <a href="#zoom">zooming and panning</a> is supported |
3424 | @ onclick and dragging of the numberline are not -yet- supported |
||
14071 | bpr | 3425 | @ note: in case of multiple numberlines, make sure the numberline without special x-axis numbering (e.g. ranging from xmin to xmax) comes first ! |
13829 | bpr | 3426 | @%numberline%size 400,400%xrange -10,10%yrange -10,10%precision 1%strokecolor black%numberline -8,8,1,6,-4,-3.5%strokecolor red%xaxis -4:AA:-2:BB:2:CC:4:DD%numberline -8,8,1,2,4,4.5%strokecolor green%xaxisup -4:AAA:-2:BBB:2:CCC:4:DDD%numberline -8,8,1,3,2,2.5%strokecolor blue%xaxis -4:AAAA:-2:BBBB:2:CCCC:4:DDDD%numberline -8,8,1,4,0,0.5%strokecolor brown%xaxis -4:AAAAA:-2:BBBBB:2:CCCCC:4:DDDDD%numberline -8,8,1,5,-2,-1.5%zoom red |
11890 | schaersvoo | 3427 | */ |
15111 | schaersvoo | 3428 | js_function[DRAW_NUMBERLINE] = 1; |
11890 | schaersvoo | 3429 | for(i=0;i<6;i++){ |
3430 | switch(i){ |
||
3431 | case 0: double_data[0] = get_real(infile,0);break;/* xmin */ |
||
3432 | case 1: double_data[1] = get_real(infile,0);break;/* xmax */ |
||
3433 | case 2: double_data[2] = get_real(infile,0);break;/* xmajor */ |
||
3434 | case 3: double_data[3] = get_real(infile,0);break;/* xminor */ |
||
3435 | case 4: double_data[4] = get_real(infile,0);break;/* ymin */ |
||
3436 | case 5: double_data[5] = get_real(infile,1);/* ymax */ |
||
3437 | /* |
||
3438 | var draw_numberline%d = function(canvas_type,xmin,xmax,xmajor,xminor,ymin,ymax,linewidth,strokecolor,strokeopacity,fontfamily,fontcolor); |
||
3439 | */ |
||
3440 | fprintf(js_include_file,"snap_x = %f;snap_y = %f;",double_data[2] / double_data[3],double_data[5] - double_data[4] ); |
||
14208 | schaersvoo | 3441 | string_length = 1 + snprintf(NULL,0,"\ndraw_numberline(%d,%d,%f,%f,%f,%f,%f,%f,%d,\"%s\",%f,\"%s\",\"%s\",%d); ",NUMBERLINE_CANVAS+numberline_cnt,use_axis_numbering,double_data[0],double_data[1],double_data[2],double_data[3],double_data[4],double_data[5],line_width,stroke_color,stroke_opacity,font_family,font_color,precision); |
3442 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11996 | schaersvoo | 3443 | snprintf(tmp_buffer,string_length,"\ndraw_numberline(%d,%d,%f,%f,%f,%f,%f,%f,%d,\"%s\",%f,\"%s\",\"%s\",%d); ",NUMBERLINE_CANVAS+numberline_cnt,use_axis_numbering,double_data[0],double_data[1],double_data[2],double_data[3],double_data[4],double_data[5],line_width,stroke_color,stroke_opacity,font_family,font_color,precision); |
11890 | schaersvoo | 3444 | add_to_buffer(tmp_buffer); |
3445 | numberline_cnt++; |
||
3446 | break; |
||
3447 | default:break; |
||
3448 | } |
||
3449 | } |
||
3450 | reset(); |
||
3451 | break; |
||
3452 | |||
15541 | schaersvoo | 3453 | case OBABEL: |
3454 | |||
3455 | /* |
||
3456 | @ obabel x,y,type input,molecule smiles-code or file location, extra arguments,extra arguments,... |
||
15633 | bpr | 3457 | @ will call the ''obabel`` program, if installed. |
15541 | schaersvoo | 3458 | @ output will be an svg file |
15686 | reyssat | 3459 | @ see documentation of obabel for special keys |
15541 | schaersvoo | 3460 | @ command <a href='#affine'>affine</a> will produce CSS3 matrix transformations |
3461 | @ command <a href='#rotate'>rotate</a> will rotate the object |
||
3462 | @ can be set onclick: <code>javascript:read_dragdrop();</code> will return click numbers of mathml-objects<br />if 4 clickable object are drawn, the reply could be 1,0,1,0 ... meaning clicked on the first and third object |
||
3463 | @ can be set draggable: <code>javascript:read_dragdrop();</code> will return all coordinates in the same order as the canvas script: unmoved object will have their original coordinates... |
||
3464 | @ snaptogrid is supported...snaptopoints will work, but use with care...due to the primitive dragging<br />technically: the dragstuff library is not used...the mathml is embedded in a new div element and not in the html5-canvas |
||
3465 | @ external files may be loaded if they are present on the server or in the modules <br />for example:<br /> obabel 0,0,mol,$module_dir/caffeine.mol,-P100,-xb none |
||
3466 | @%obabel_smi%size 400,400%xrange -10,10%yrange -10,10%fillcolor green%drag xy%centered%obabel 0,0,smi,-:c1cFccc1cc,-xb none,-xB blue,-xi,-xt,-xa,-xX,-xP180,-h |
||
3467 | */ |
||
3468 | js_function[DRAW_XML] = 1; |
||
3469 | for(i=0;i<4;i++){ |
||
3470 | switch(i){ |
||
3471 | case 0: double_data[0]=get_real(infile,0);break; /* x in x/y-range coord system -> pixel width */ |
||
3472 | case 1: double_data[1]=get_real(infile,0);break; /* y in x/y-range coord system -> pixel height */ |
||
3473 | case 2: URL = get_string_argument(infile,0);break; |
||
3474 | case 3: |
||
3475 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
3476 | temp = getSVGMOL(URL,get_string(infile,1)); |
||
3477 | decimals = find_number_of_digits(precision); |
||
3478 | if(use_affine == TRUE ){ transform(2,2);} |
||
3479 | if( use_offset != 0 || drag_type != -1 ){int_data[2] = 1;}else{int_data[2] = 0;} /* only centered or not-centered */ |
||
3480 | int_data[0] = x2px(double_data[0]); |
||
3481 | int_data[1] = y2px(double_data[1]); |
||
3482 | if( use_slider != -1 && onclick == 0 ){ onclick = 3;}/* no drag&onclick but slideable */ |
||
3483 | if( use_slider != -1 && drag_type > 0 ){ onclick = 5;}/* slider+drag*/ |
||
3484 | if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'"); } |
||
3485 | string_length = 1 + snprintf(NULL,0,"var draw_xml%d = {id:%d,type:'svg',x:[%d],y:[%d],mathml:\"%s\",drag_type:%d,onclick:%d,object_cnt:%d,stroke_color:\"%s\",stroke_opacity:%.2f,fill_color:\"%s\",fill_opacity:%.2f,use_center:%d,use_snap:%d,angle:%f,fontfamily:\"%s\",transform:%s,use_affine:%d,offset:[0,0],use_slider:%s,rotation_center:%s,once:true};slidergroup[%d] = null;draw_xml(draw_xml%d);\n",drawxml_cnt,drawxml_cnt,int_data[0],int_data[1],temp,drag_type,onclick,object_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,int_data[2],use_snap,angle,font_family,doubledata2js_array(affine_matrix,6,decimals),use_affine,my_sliders,rotation_center,object_cnt,drawxml_cnt); |
||
3486 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
3487 | snprintf(tmp_buffer,string_length, "var draw_xml%d = {id:%d,type:'svg',x:[%d],y:[%d],mathml:\"%s\",drag_type:%d,onclick:%d,object_cnt:%d,stroke_color:\"%s\",stroke_opacity:%.2f,fill_color:\"%s\",fill_opacity:%.2f,use_center:%d,use_snap:%d,angle:%f,fontfamily:\"%s\",transform:%s,use_affine:%d,offset:[0,0],use_slider:%s,rotation_center:%s,once:true};slidergroup[%d] = null;draw_xml(draw_xml%d);\n",drawxml_cnt,drawxml_cnt,int_data[0],int_data[1],temp,drag_type,onclick,object_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,int_data[2],use_snap,angle,font_family,doubledata2js_array(affine_matrix,6,decimals),use_affine,my_sliders,rotation_center,object_cnt,drawxml_cnt); |
||
3488 | add_to_buffer(tmp_buffer); |
||
3489 | if(onclick != 0 ){object_cnt++;} |
||
3490 | drawxml_cnt++;/* keeps track on imported img,div,p,span,mathml,svg */ |
||
3491 | break; |
||
3492 | default:break; |
||
3493 | } |
||
3494 | } |
||
3495 | reset(); |
||
3496 | break; |
||
3497 | |||
11806 | schaersvoo | 3498 | case OPACITY: |
3499 | /* |
||
13951 | schaersvoo | 3500 | @ opacity [0-255],[0-255] |
3501 | @ opacity [0.0 - 1.0],[0.0 - 1.0] |
||
15715 | schaersvoo | 3502 | @ alternative: transparent |
11806 | schaersvoo | 3503 | @ first item is stroke opacity, second is fill opacity |
13951 | schaersvoo | 3504 | @%opacity%size 400,400%xrange -10,10%yrange -10,10%opacity 255,0%fcircle -10,0,100,blue%opacity 250,50%fcircle -5,0,100,blue%opacity 200,100%fcircle 0,0,100,blue%opacity 150,150%fcircle 5,0,100,blue%opacity 100,200%fcircle 10,0,100,blue |
11806 | schaersvoo | 3505 | */ |
3506 | for(i = 0 ; i<2;i++){ |
||
3507 | switch(i){ |
||
3508 | case 0: double_data[0]= get_real(infile,0);break; |
||
3509 | case 1: double_data[1]= get_real(infile,1);break; |
||
3510 | default: break; |
||
3511 | } |
||
3512 | } |
||
15633 | bpr | 3513 | if( double_data[0] > 255 || double_data[1] > 255 || double_data[0] < 0 || double_data[1] < 0 ){ canvas_error("opacity [0 - 255], [0 - 255] ");}/* typo or non-RGB ? */ |
11997 | schaersvoo | 3514 | if( double_data[0] > 1 ){ stroke_opacity = (double) (0.0039215*double_data[0]); }else{ stroke_opacity = 0.0;} /* 0.0 - 1.0 */ |
3515 | if( double_data[1] > 1 ){ fill_opacity = (double) (0.0039215*double_data[1]); }else{ fill_opacity = 0.0;} /* 0.0 - 1.0 */ |
||
11806 | schaersvoo | 3516 | break; |
3517 | |||
3518 | case ONCLICK: |
||
3519 | /* |
||
3520 | @ onclick |
||
3521 | @ keyword (no arguments required) |
||
15111 | schaersvoo | 3522 | @ if the next object is clicked, its ''object onclick_or_drag sequence number`` in fly script is returned by <code>javascript:read_canvas();</code> |
14086 | bpr | 3523 | @ onclick seqeuence numbering starts at ''0``, e.g. if there are 6 objects set onclick, the first onclick object will have id-number ''0``, the last id-number ''5`` |
15111 | schaersvoo | 3524 | @ line based objects will show an increase in line width<br />font based objects will show the text in ''bold`` when clicked. |
14562 | bpr | 3525 | @ the click zone (accuracy) is determined by 2× the line width of the object |
14071 | bpr | 3526 | @ onclick and <a href="#drag">drag x|y|xy</a> may be combined in a single flyscript (although a single object can <b>not</b> be onclick and draggable at the same time...) |
11806 | schaersvoo | 3527 | @ note: not all objects may be set onclick |
12107 | schaersvoo | 3528 | @%onclick%size 400,400%xrange -10,10%yrange -10,10%opacity 255,60%linewidth 3%onclick%fcircles blue,-3,3,1,1,2,2,3,1,1%onclick%ftriangles red,-4,-4,-4,0,-3,-2,0,0,4,0,2,-4%onclick%frects green,-4,4,-2,2,1,-1,3,-4 |
11806 | schaersvoo | 3529 | */ |
15111 | schaersvoo | 3530 | fprintf(js_include_file,"use_dragdrop_reply = true;"); |
11806 | schaersvoo | 3531 | onclick = 1; |
15111 | schaersvoo | 3532 | use_dragstuff=2; |
3533 | js_function[INTERACTIVE] = 1; |
||
11806 | schaersvoo | 3534 | |
3535 | break; |
||
3536 | |||
3537 | case PARALLEL: |
||
3538 | /* |
||
3539 | @ parallel x1,y1,x2,y2,dx,dy,n,[colorname or #hexcolor] |
||
15611 | schaersvoo | 3540 | @ affine transformations should be identical to flydraw |
15613 | schaersvoo | 3541 | @ in case of <a href='#rotate'>rotation</a> or <a href='#affine'>affine transformation </a>, command parallel will produce <em>n</em> individual segments, and these may be set ''onclick`` or ''drag xy`` individually. |
3542 | @ in case of <em>no rotation or transformations</em> the lines can not be set ''onclick`` or ''drag xy``. |
||
15629 | bpr | 3543 | @ note: a large number of parallel lines (large <em>n</em>) may result in a canvasdraw error (...simplify your script...it produces too many lines...) |
15611 | schaersvoo | 3544 | @%parallel_click%size 400,400%xrange -10,10%yrange -10,10%parallel -5,5,-4,-5,0.25,0,40,red%rotate 45%onclick%parallel -5,5,-4,-5,0.25,0,40,blue |
3545 | @%parallel%size 400,400%xrange -10,10%yrange -10,10%parallel -5,5,-4,-5,0.25,0,40,red |
||
3546 | */ |
||
15613 | schaersvoo | 3547 | decimals = find_number_of_digits(precision); |
15611 | schaersvoo | 3548 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
3549 | |||
15613 | schaersvoo | 3550 | if( use_rotate == TRUE || use_affine == TRUE ){ |
3551 | for( i = 0;i < 8; i++ ){ |
||
3552 | switch(i){ |
||
3553 | case 0: double_data[0] = get_real(infile,0);break; /* x1-values */ |
||
3554 | case 1: double_data[1] = get_real(infile,0);break; /* y1-values */ |
||
3555 | case 2: double_data[2] = get_real(infile,0);break; /* x2-values */ |
||
3556 | case 3: double_data[3] = get_real(infile,0);break; /* y2-values */ |
||
3557 | case 4: double_data[4] = get_real(infile,0);break; /* xv */ |
||
3558 | case 5: double_data[5] = get_real(infile,0);break; /* yv */ |
||
3559 | case 6: int_data[0] = (int) (get_real(infile,0));break; /* n */ |
||
3560 | case 7: stroke_color=get_color(infile,1);break;/* name or hex color */ |
||
3561 | default: break; |
||
3562 | } |
||
11806 | schaersvoo | 3563 | } |
15613 | schaersvoo | 3564 | double_data[6] = double_data[0]; /* x1 */ |
15629 | bpr | 3565 | double_data[7] = double_data[1]; /* y1 */ |
15613 | schaersvoo | 3566 | double_data[8] = double_data[2]; /* x2 */ |
15629 | bpr | 3567 | double_data[9] = double_data[3]; /* y2 */ |
15613 | schaersvoo | 3568 | for(i = 0 ; i < int_data[0] ; i++){ |
15629 | bpr | 3569 | double_data[0] = double_data[6] + i*double_data[4]; |
3570 | double_data[1] = double_data[7] + i*double_data[5]; |
||
3571 | double_data[2] = double_data[8] + i*double_data[4]; |
||
3572 | double_data[3] = double_data[9] + i*double_data[5]; |
||
15613 | schaersvoo | 3573 | if(use_rotate == TRUE ){ rotate(4,angle,rotationcenter,2);} |
3574 | if(use_affine == TRUE ){ transform(4,2);} |
||
3575 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[2],decimals,double_data[1],decimals,double_data[3],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
3576 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
3577 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[2],decimals,double_data[1],decimals,double_data[3],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
3578 | add_to_buffer(tmp_buffer); |
||
3579 | if(onclick != 0){object_cnt++;} |
||
3580 | } |
||
3581 | dragstuff[4] = 1; |
||
11806 | schaersvoo | 3582 | } |
15613 | schaersvoo | 3583 | else /* use the old parallel version: calculations in javascript */ |
3584 | { |
||
3585 | for( i = 0;i < 8; i++ ){ |
||
3586 | switch(i){ |
||
3587 | case 0: double_data[0] = get_real(infile,0);break; /* x1-values */ |
||
3588 | case 1: double_data[1] = get_real(infile,0);break; /* y1-values */ |
||
3589 | case 2: double_data[2] = get_real(infile,0);break; /* x2-values */ |
||
3590 | case 3: double_data[3] = get_real(infile,0);break; /* y2-values */ |
||
3591 | case 4: double_data[4] = xmin + get_real(infile,0);break; /* xv */ |
||
3592 | case 5: double_data[5] = ymax + get_real(infile,0);break; /* yv */ |
||
3593 | case 6: int_data[0] = (int) (get_real(infile,0));break; /* n */ |
||
3594 | case 7: stroke_color=get_color(infile,1);/* name or hex color */ |
||
3595 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,11,[%.*f,%.*f,%.*f],[%.*f,%.*f,%.*f],[%d,%d,%d],[%d,%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[2],decimals,double_data[4],decimals,double_data[1],decimals,double_data[3],decimals,double_data[5],int_data[0],int_data[0],int_data[0],int_data[0],int_data[0],int_data[0],line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
3596 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
3597 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,11,[%.*f,%.*f,%.*f],[%.*f,%.*f,%.*f],[%d,%d,%d],[%d,%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[2],decimals,double_data[4],decimals,double_data[1],decimals,double_data[3],decimals,double_data[5],int_data[0],int_data[0],int_data[0],int_data[0],int_data[0],int_data[0],line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
3598 | add_to_buffer(tmp_buffer); |
||
3599 | if(onclick != 0){object_cnt++;} |
||
3600 | break; |
||
3601 | default: break; |
||
3602 | } |
||
3603 | dragstuff[11] = 1; |
||
3604 | } |
||
3605 | } |
||
15111 | schaersvoo | 3606 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
15613 | schaersvoo | 3607 | reset(); |
11806 | schaersvoo | 3608 | break; |
15629 | bpr | 3609 | |
11806 | schaersvoo | 3610 | case PLOTSTEPS: |
3611 | /* |
||
3612 | @ plotsteps a_number |
||
3613 | @ default 150 |
||
14066 | bpr | 3614 | @ only used for commands <a href="#curve">curve / plot</a> and <a href="#levelcurve">levelcurve</a> |
11806 | schaersvoo | 3615 | @ use with care ! |
3616 | */ |
||
3617 | plot_steps = (int) (get_real(infile,1)); |
||
3618 | break; |
||
13829 | bpr | 3619 | |
11806 | schaersvoo | 3620 | case POINT: |
3621 | /* |
||
3622 | @ point x,y,color |
||
15111 | schaersvoo | 3623 | @ draw a single point at (x;y) in color 'color' |
14246 | bpr | 3624 | @ use command <code>linewidth int</code> to adjust size |
11806 | schaersvoo | 3625 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
14071 | bpr | 3626 | @ will not resize on zooming (command <code>circle x,y,r,color</code> will resize on zooming) |
14066 | bpr | 3627 | @ attention: in case of command <a href="#rotate">rotate angle</a> a point has rotation center (0:0) in x/y-range |
12107 | schaersvoo | 3628 | @%point%size 400,400%xrange -10,10%yrange -10,10%opacity 255,255%linewidth 1%onclick%point 0,0,red%linewidth 2%onclick%point 1,1,blue%linewidth 3%onclick%point 3,3,green%linewidth 4%point 4,4,orange |
11806 | schaersvoo | 3629 | */ |
3630 | for(i=0;i<3;i++){ |
||
3631 | switch(i){ |
||
3632 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
3633 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
3634 | case 2: stroke_color = get_color(infile,1);/* name or hex color */ |
||
15111 | schaersvoo | 3635 | if(use_rotate == TRUE ){rotate(2,angle,rotationcenter,2);} |
3636 | if(use_affine == TRUE ){ transform(2,2);} |
||
3637 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
3638 | |||
11806 | schaersvoo | 3639 | decimals = find_number_of_digits(precision); |
15111 | schaersvoo | 3640 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,2,[%.*f],[%.*f],[%.2f],[%d],%.2f,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[1],1.5*line_width,line_width,1.5*line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,1,0,0,0,use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
3641 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
3642 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,2,[%.*f],[%.*f],[%.2f],[%d],%.2f,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[1],1.5*line_width,line_width,1.5*line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,1,0,0,0,use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
3643 | add_to_buffer(tmp_buffer); |
||
3644 | /* object_cnt++; */ |
||
3645 | if(onclick != 0){object_cnt++;} |
||
11806 | schaersvoo | 3646 | break; |
3647 | default: break; |
||
3648 | } |
||
3649 | } |
||
15111 | schaersvoo | 3650 | dragstuff[2] = 1; |
3651 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
11806 | schaersvoo | 3652 | reset(); |
3653 | break; |
||
3654 | |||
3655 | case POINTS: |
||
3656 | /* |
||
3657 | @ points color,x1,y1,x2,y2,...,x_n,y_n |
||
15111 | schaersvoo | 3658 | @ draw multiple points at given coordinates in color 'color' |
14246 | bpr | 3659 | @ use command <code>linewidth int</code> to adjust size |
11806 | schaersvoo | 3660 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!) |
14066 | bpr | 3661 | @ attention: in case of command <a href="#rotate">rotate angle</a> the points have rotation center (0:0) in x/y-range |
12107 | schaersvoo | 3662 | @%points_1%size 400,400%xrange -10,10%yrange -10,10%opacity 255,255%snaptogrid%linewidth 1%drag xy%points red,0,0,1,1,2,2,3,3%drag x%points blue,0,1,1,2,2,3,3,4 |
3663 | @%points_2%size 400,400%xrange -10,10%yrange -10,10%opacity 255,255%linewidth 1%onclick%points red,0,0,1,1,2,2,3,3%onclick%points blue,0,1,1,2,2,3,3,4 |
||
11806 | schaersvoo | 3664 | */ |
8363 | schaersvoo | 3665 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
3666 | fill_color = stroke_color; |
||
3667 | i=0; |
||
3668 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 3669 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
8363 | schaersvoo | 3670 | if(i%2 == 0 ){ |
3671 | double_data[i] = get_real(infile,0); /* x */ |
||
3672 | } |
||
3673 | else |
||
3674 | { |
||
3675 | double_data[i] = get_real(infile,1); /* y */ |
||
3676 | } |
||
3677 | i++; |
||
3678 | } |
||
15111 | schaersvoo | 3679 | if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);} |
3680 | if(use_affine == TRUE ){ transform(i-1,2);} |
||
3681 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
8363 | schaersvoo | 3682 | decimals = find_number_of_digits(precision); |
11806 | schaersvoo | 3683 | for(c = 0 ; c < i-1 ; c = c+2){ |
15111 | schaersvoo | 3684 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,2,[%.*f],[%.*f],[%.2f],[%d],%.2f,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[c],decimals,double_data[c+1],1.5*line_width,line_width,1.5*line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,1,0,0,0,use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
3685 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
3686 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,2,[%.*f],[%.*f],[%.2f],[%d],%.2f,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[c],decimals,double_data[c+1],1.5*line_width,line_width,1.5*line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,1,0,0,0,use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
3687 | add_to_buffer(tmp_buffer); |
||
3688 | /* object_cnt++; */ |
||
3689 | if(onclick != 0){object_cnt++;} |
||
8363 | schaersvoo | 3690 | } |
15111 | schaersvoo | 3691 | dragstuff[2] = 1; |
3692 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
8363 | schaersvoo | 3693 | reset(); |
3694 | break; |
||
11806 | schaersvoo | 3695 | |
3696 | case POLY: |
||
3697 | /* |
||
3698 | @ poly color,x1,y1,x2,y2...x_n,y_n |
||
3699 | @ polygon color,x1,y1,x2,y2...x_n,y_n |
||
3700 | @ draw closed polygon |
||
14071 | bpr | 3701 | @ use command ''fpoly`` to fill it or use keyword <a href='#filled'>filled</a> |
11806 | schaersvoo | 3702 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
12107 | schaersvoo | 3703 | @%polygon_1%size 400,400%xrange -10,10%yrange -10,10%opacity 255,25%fillcolor orange%filled%linewidth 2%drag xy%snaptogrid%poly blue,0,0,1,3,3,1,2,4,-1,3 |
3704 | @%polygon_2%size 400,400%xrange -10,10%yrange -10,10%opacity 255,25%fillcolor orange%filled%linewidth 1%onclick%poly green,0,0,1,3,3,1,2,4,-1,3 |
||
11806 | schaersvoo | 3705 | */ |
3706 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
3707 | i=0; |
||
3708 | c=0; |
||
3709 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 3710 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
11806 | schaersvoo | 3711 | for( c = 0 ; c < 2; c++){ |
3712 | if(c == 0 ){ |
||
3713 | double_data[i] = get_real(infile,0); |
||
3714 | i++; |
||
3715 | } |
||
3716 | else |
||
3717 | { |
||
3718 | double_data[i] = get_real(infile,1); |
||
3719 | i++; |
||
3720 | } |
||
3721 | } |
||
3722 | } |
||
15111 | schaersvoo | 3723 | if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);} |
3724 | if(use_affine == TRUE ){ transform(i-1,2);} |
||
3725 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
3726 | |||
14066 | bpr | 3727 | /* draw path: closed & optional filled */ |
15111 | schaersvoo | 3728 | decimals = find_number_of_digits(precision); |
3729 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,5,%s,[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,double_xy2js_array(double_data,i,decimals),line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
3730 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
3731 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,5,%s,[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,double_xy2js_array(double_data,i,decimals),line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
3732 | add_to_buffer(tmp_buffer); |
||
3733 | if(onclick != 0){object_cnt++;} |
||
3734 | reset(); |
||
3735 | dragstuff[5] = 1; |
||
3736 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
11806 | schaersvoo | 3737 | break; |
3738 | |||
7614 | schaersvoo | 3739 | case POLYLINE: |
3740 | /* |
||
3741 | @ polyline color,x1,y1,x2,y2...x_n,y_n |
||
10975 | schaersvoo | 3742 | @ brokenline color,x1,y1,x2,y2...x_n,y_n |
3743 | @ path color,x1,y1,x2,y2...x_n,y_n |
||
14086 | bpr | 3744 | @ remark: there is <b>no</b> command polylines | brokenlines | paths ... just use multiple commands <code>polyline, x1,y1,x2,y2...x_n,y_n</code> |
3745 | @ remark: there are commands <code>userdraw path(s),color</code> and <code>userdraw polyline,color</code>... these are two entirely different things ! the path(s) userdraw commands may be used for freehand drawing(s)<br />the polyline userdraw command is analogue to this polyline|brokenline command |
||
10975 | schaersvoo | 3746 | @ the command interconnects the points in the given order with a line (canvasdraw will not close the drawing: use command <a href="#poly">polygon</a> for this) |
14071 | bpr | 3747 | @ use command <a href='#segments'>segments</a> for a series of segments. These may be clicked/dragged individually |
9406 | schaersvoo | 3748 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
12107 | schaersvoo | 3749 | @%polyline_1%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%drag xy%snaptogrid%polyline blue,0,0,1,3,3,1,2,4,-1,3 |
3750 | @%polyline_2%size 400,400%xrange -10,10%yrange -10,10%linewidth 1%onclick%polyline green,0,0,1,3,3,1,2,4,-1,3 |
||
7614 | schaersvoo | 3751 | */ |
13829 | bpr | 3752 | |
7614 | schaersvoo | 3753 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
3754 | i=0; |
||
3755 | c=0; |
||
3756 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 3757 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
7614 | schaersvoo | 3758 | for( c = 0 ; c < 2; c++){ |
3759 | if(c == 0 ){ |
||
3760 | double_data[i] = get_real(infile,0); |
||
3761 | i++; |
||
3762 | } |
||
3763 | else |
||
3764 | { |
||
3765 | double_data[i] = get_real(infile,1); |
||
3766 | i++; |
||
3767 | } |
||
3768 | } |
||
3769 | } |
||
15111 | schaersvoo | 3770 | |
3771 | if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);} |
||
3772 | if(use_affine == TRUE ){ transform(i-1,2);} |
||
3773 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
3774 | |||
14066 | bpr | 3775 | /* draw path: not closed & not filled */ |
7614 | schaersvoo | 3776 | decimals = find_number_of_digits(precision); |
15111 | schaersvoo | 3777 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,4,%s,[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,double_xy2js_array(double_data,i,decimals),line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
3778 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
3779 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,4,%s,[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,double_xy2js_array(double_data,i,decimals),line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
3780 | add_to_buffer(tmp_buffer); |
||
3781 | if(onclick != 0){object_cnt++;} |
||
3782 | /* object_cnt++;*/ |
||
8379 | schaersvoo | 3783 | reset(); |
15111 | schaersvoo | 3784 | dragstuff[4] = 1; |
3785 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
7614 | schaersvoo | 3786 | break; |
11806 | schaersvoo | 3787 | |
3788 | case POPUP: |
||
3789 | /* |
||
3790 | @ popup |
||
3791 | @ keyword (no arguments) |
||
14086 | bpr | 3792 | @ if fly-script starts with keyword ''popup``, the canvas image will be exclusively in a popup window (xsize px × ysize px) |
14071 | bpr | 3793 | @ if keyword ''popup`` is used after command <code>size xsize,ysize</code> the canvas will also be displayed in a popup window with size ''xsize × ysize`` |
15309 | schaersvoo | 3794 | @ the popup window will be embedded into the page as a normal image, when ''status=done``; override with keyword <a href="#status">nostatus</a> |
16844 | bpr | 3795 | @ to access the read_canvas and read_dragdrop functions in a popup window, use:<br /> <code> function read_all(){<br /> if( typeof popup !== 'undefined' ){<br /> var fun1 = popup['read_dragdrop'+canvas_scripts[0]];<br />var fun2 = popup['read_canvas'+canvas_scripts[0]];<br /> popup.close();<br /> return "dragdrop="+fun1()+"\\ncanvas="+fun2();<br /> };</code> |
14071 | bpr | 3796 | @ to set a canvasdraw produced <a href="#clock">clock</a> or multiple clocks...use something like: <code>popup.set_clock(clock_id,type,diff);</code> as js-function for a button (or something else) in your document page.<br />where in <b>clock_id</b> starts with 0 for the first clock<br /><b>type</b> is 1 for Hours,2 for Minutes and 3 for Seconds<br /><b>diff</b> is the increment (positive or negative) per click |
15313 | schaersvoo | 3797 | @%popup%popup%size 400,400%xrange -2*pi,2*pi%yrange -5,5%precision 0%axis%axisnumbering%opacity 100,190%grid 1,1,grey,2,2,5,black%linewidth 4%fillcolor blue%trange -pi,pi%animate%linewidth 1%precision 1000%jsplot red,4*cos(2*x),2*sin(3*x-pi/6)%strokecolor green%functionlabel H(x)=%userinput function |
11806 | schaersvoo | 3798 | */ |
3799 | use_tooltip = 2; |
||
3800 | break; |
||
3801 | |||
3802 | case PROTRACTOR: |
||
7614 | schaersvoo | 3803 | /* |
11806 | schaersvoo | 3804 | @ protractor x,y,x_width,type,mode,use_a_scale |
3805 | @ x,y are the initial location |
||
14066 | bpr | 3806 | @ x_width: give the width in x-coordinate system (e.g. not in pixels !) |
14246 | bpr | 3807 | @ type = 1: a triangle range 0 - 180<br />type = 2: a circle shape 0 - 360 |
14066 | bpr | 3808 | @ mode: use -1 to set the protractor interactive (mouse movement of protractor)<br />use mode = '0° - 360°' to set the protractor with a static angle of some value |
11806 | schaersvoo | 3809 | @ if the value of the user_rotation angle is to be shown...use command <a href='#display'>display degree,color,fontsize</a><a href='#display'>display radian,color,fontsize</a> |
14066 | bpr | 3810 | @ use_scale = 1: the protractor will have some scale values printed; use_scale=0 to disable |
11806 | schaersvoo | 3811 | @ the rotating direction of the mouse around the protractor determines the clockwise/ counter clockwise rotation of the protractor... |
14071 | bpr | 3812 | @ commands ''stroke_color | fill_color | linewidth | opacity | font_family`` will determine the looks of the protractor. |
3813 | @ default replyformat: reply[0] = x;reply[1] = y;reply[2] = angle_in_radians<br />use command ''precision`` to set the reply precision. |
||
11806 | schaersvoo | 3814 | @ if combined with a ruler, use replyformat = 32 |
14071 | bpr | 3815 | @ command <code>snap_to_grid</code> may be used to assist the pupil at placing the protractor |
3816 | @ when using command ''zoom``, pay <b>attention</b> to the size and symmetry of your canvas<br />...to avoid a partial image, locate the start position near the center of the visual canvas<br />technical: the actual ''protractor`` is just a static generated image in a new canvas-memory<br />This image is only generated once, and a copy of its bitmap is translated & rotated onto the visible canvas.<br />That is the reason for the ''high-speed dragging and rotating``.<br />I've limited its size to xsize × ysize e.g. the same size as the visual canvas... |
||
11806 | schaersvoo | 3817 | @ only one protractor allowed (for the time being) |
15111 | schaersvoo | 3818 | @ usage: first left click on the protractor will activate dragging;<br />a second left click will activate rotating (just move mouse around)<br />a third click will freeze this position and the x/y-coordinate and angle in radians will be stored in reply(3)<br />a next click will restart this sequence... |
15313 | schaersvoo | 3819 | @%protractor%size 400,400%xrange -5,10%yrange -5,10%hline 0,0,black%vline 0,0,black%fillcolor orange%opacity 255,40%protractor 2,-2,6,0,-1,1,1%mouse red,22 |
7614 | schaersvoo | 3820 | */ |
11806 | schaersvoo | 3821 | for( i = 0;i < 6; i++ ){ |
3822 | switch(i){ |
||
3823 | case 0: double_data[0] = get_real(infile,0);break; /* x-center */ |
||
3824 | case 1: double_data[1] = get_real(infile,0);break; /* y-center */ |
||
3825 | case 2: double_data[2] = get_real(infile,0);break; /* x-width */ |
||
3826 | case 3: int_data[0] = (int)(get_real(infile,0));break; /* type: 1==triangle 2 == circle */ |
||
3827 | case 4: int_data[1] = (int)(get_real(infile,0));break; /* passive mode == 0; active mode == -1 */ |
||
3828 | case 5: int_data[2] = (int)(get_real(infile,1)); /* use scale */ |
||
3829 | decimals = find_number_of_digits(precision); |
||
11821 | schaersvoo | 3830 | if( int_data[1] < 0 ){ js_function[JS_FIND_ANGLE] = 1;} |
15111 | schaersvoo | 3831 | add_js_protractor(int_data[0],double_data[0],double_data[1],double_data[2],font_family,stroke_color,stroke_opacity,fill_color,fill_opacity,line_width,int_data[2],int_data[1],use_snap); |
11806 | schaersvoo | 3832 | |
14208 | schaersvoo | 3833 | string_length = 1 + snprintf(NULL,0,";protractor%d(); ",canvas_root_id); |
3834 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11806 | schaersvoo | 3835 | snprintf(tmp_buffer,string_length,";protractor%d(); ",canvas_root_id); |
3836 | add_to_buffer(tmp_buffer); |
||
3837 | reply_precision = precision; |
||
3838 | /* no reply from protractor if non-interactive */ |
||
3839 | if( reply_format == 0 && int_data[1] == -1 ){reply_format = 30;} |
||
15111 | schaersvoo | 3840 | js_function[INTERACTIVE] = 1; |
11806 | schaersvoo | 3841 | break; |
3842 | default: break; |
||
3843 | } |
||
3844 | } |
||
3845 | break; |
||
3846 | |||
3847 | case PIXELS: |
||
3848 | /* |
||
3849 | @ pixels color,x1,y1,x2,y2,x3,y3... |
||
3850 | @ draw rectangular "points" with diameter 1 pixel |
||
3851 | @ pixels can <b>not</b> be dragged or clicked |
||
14086 | bpr | 3852 | @ "pixelsize = 1" may be changed by command <code>pixelsize int</code> |
12111 | schaersvoo | 3853 | @%pixels%size 400,400%opacity 255,255%pixelsize 5%pixels red,1,1,2,2,3,3,4,4,5,5,10,10,20,20,30,30,40,40,50,50,60,60,70,70,80,80,90,90,100,100,120,120,140,140,160,160,180,180,200,200,240,240,280,280,320,320,360,360,400,400%#NOTE pixelsize=5...otherwise you will not see them clearly... |
11806 | schaersvoo | 3854 | */ |
15111 | schaersvoo | 3855 | js_function[DRAW_PIXELS] = 1; |
11806 | schaersvoo | 3856 | stroke_color=get_color(infile,0); |
7614 | schaersvoo | 3857 | i=0; |
3858 | c=0; |
||
3859 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 3860 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
7614 | schaersvoo | 3861 | for( c = 0 ; c < 2; c++){ |
3862 | if(c == 0 ){ |
||
3863 | double_data[i] = get_real(infile,0); |
||
3864 | i++; |
||
3865 | } |
||
3866 | else |
||
3867 | { |
||
3868 | double_data[i] = get_real(infile,1); |
||
3869 | } |
||
3870 | } |
||
3871 | } |
||
15111 | schaersvoo | 3872 | if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);} |
3873 | if(use_affine == TRUE ){ transform(i-1,2);} |
||
11806 | schaersvoo | 3874 | decimals = find_number_of_digits(precision); |
3875 | /* *double_xy2js_array(double xy[],int len,int decimals) */ |
||
14208 | schaersvoo | 3876 | string_length = 1 + snprintf(NULL,0, "draw_setpixel(%s,\"%s\",%.2f,%d);\n",double_xy2js_array(double_data,i,decimals),stroke_color,stroke_opacity,pixelsize); |
3877 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11806 | schaersvoo | 3878 | snprintf(tmp_buffer,string_length,"draw_setpixel(%s,\"%s\",%.2f,%d);\n",double_xy2js_array(double_data,i,decimals),stroke_color,stroke_opacity,pixelsize); |
3879 | add_to_buffer(tmp_buffer); |
||
3880 | reset(); |
||
7614 | schaersvoo | 3881 | break; |
11806 | schaersvoo | 3882 | |
3883 | case PIXELSIZE: |
||
7614 | schaersvoo | 3884 | /* |
11806 | schaersvoo | 3885 | @ pixelsize int |
3886 | @ in case you want to deviate from default pixelsize = 1(...) |
||
12111 | schaersvoo | 3887 | @ pixelsize 100 is of course a filled rectangle 100px × 100px |
7614 | schaersvoo | 3888 | */ |
11806 | schaersvoo | 3889 | pixelsize = (int) get_real(infile,1); |
3890 | break; |
||
8105 | schaersvoo | 3891 | |
11806 | schaersvoo | 3892 | case PIECHART: |
7614 | schaersvoo | 3893 | /* |
11806 | schaersvoo | 3894 | @ piechart xc,yc,radius,'data+colorlist' |
14066 | bpr | 3895 | @ (xc: yc) center of circle diagram in xrange/yrange |
11806 | schaersvoo | 3896 | @ radius in pixels |
3897 | @ data+color list: a colon separated list of raw data and corresponding colours<br />canvasdraw will not check validity of colornames...<br />in case of trouble look into javascript debugging of your browser |
||
14066 | bpr | 3898 | @ example data+colorlist: 32:red:65:green:23:black:43:orange:43:yellow:14:white |
11806 | schaersvoo | 3899 | @ the number of colors must match the number of data. |
14066 | bpr | 3900 | @ if defined <a href='#fillpattern'>fillpattern some_pattern</a> then the pie pieces will be filled with the respective color and a fill pattern...<br />the pattern is cycled from the 4 pattern primitives: grid,hatch,diamond,dot,grid,hatch,diamond,dot,... |
14086 | bpr | 3901 | @ use command <a href='#opacity'>opacity</a> to adjust fill_opacity of colours |
3902 | @ use command <a href='#legend'>legend</a> to automatically create a legend using the same colours as pie segments; unicode allowed in legend; expect javascript trouble if the amount of ''pie-slices``, ''pie-colors``, ''pie-legend-titles`` do not match, a javascript console is your best friend...<br />use command ''fontfamily`` to set the font of the legend. |
||
14066 | bpr | 3903 | @ use command <a href='centered'>centered</a> to place <a href='#legend'>legend</a> text inside the piechart. The text is using the same color as the pie segment: use (fill) opacity to enhance visibility. |
12538 | schaersvoo | 3904 | @%piechart_1%size 300,200%xrange -10,10%yrange -10,10%legend cars:motorcycles:bicycles:trikes%opacity 255,120%piechart -5,0,75,22:red:8:blue:63:green:7:purple% |
15313 | schaersvoo | 3905 | @%piechart_2%size 200,200%xrange -10,10%yrange -10,10%fontfamily 16px Arial%centered%legend cars:motorcycles:bicycles:trikes%opacity 255,60%piechart 0,0,100,22:red:8:blue:63:green:7:purple |
7614 | schaersvoo | 3906 | */ |
15111 | schaersvoo | 3907 | js_function[DRAW_PIECHART] = 1; |
7614 | schaersvoo | 3908 | for(i=0;i<5;i++){ |
3909 | switch(i){ |
||
11806 | schaersvoo | 3910 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */ |
14032 | schaersvoo | 3911 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y */ |
11806 | schaersvoo | 3912 | case 2: int_data[2] = (int)(get_real(infile,1));break;/* radius*/ |
3913 | case 3: temp = get_string(infile,1); |
||
3914 | if( strstr( temp, ":" ) != 0 ){ temp = str_replace(temp,":","\",\"");} |
||
14208 | schaersvoo | 3915 | string_length = 1 + snprintf(NULL,0,"draw_piechart(%d,%d,%d,%d,[\"%s\"],%.2f,%d,\"%s\",%d,%d);\n",PIECHART,int_data[0],int_data[1],int_data[2],temp,fill_opacity,legend_cnt,font_family,use_filled,use_offset); |
3916 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
12538 | schaersvoo | 3917 | snprintf(tmp_buffer,string_length,"draw_piechart(%d,%d,%d,%d,[\"%s\"],%.2f,%d,\"%s\",%d,%d);\n",PIECHART,int_data[0],int_data[1],int_data[2],temp,fill_opacity,legend_cnt,font_family,use_filled,use_offset); |
11806 | schaersvoo | 3918 | add_to_buffer(tmp_buffer); |
3919 | break; |
||
3920 | default:break; |
||
7614 | schaersvoo | 3921 | } |
3922 | } |
||
11806 | schaersvoo | 3923 | reset(); |
7614 | schaersvoo | 3924 | break; |
16832 | bpr | 3925 | |
15773 | schaersvoo | 3926 | case RANGE: |
3927 | /* |
||
3928 | @ range xmin,xmax,ymin,ymax |
||
3929 | @ if not given: 0,xsize,0,ysize (eg in pixels) |
||
3930 | */ |
||
3931 | for(i = 0 ; i<4; i++){ |
||
3932 | switch(i){ |
||
3933 | case 0: xmin = get_real(infile,0);break; |
||
3934 | case 1: xmax = get_real(infile,1);break; |
||
3935 | case 2: ymin = get_real(infile,0);break; |
||
3936 | case 3: ymax = get_real(infile,1);break; |
||
3937 | default: break; |
||
3938 | } |
||
3939 | } |
||
3940 | if(xmin >= xmax){canvas_error(" xrange is not OK: xmin < xmax !");} |
||
3941 | if(ymin >= ymax){canvas_error(" yrange is not OK: ymin < ymax !");} |
||
3942 | fprintf(js_include_file,"var xmin = %f;var xmax = %f;var ymin = %f;var ymax = %f;",xmin,xmax,ymin,ymax); |
||
3943 | found_size_command = found_size_command+2; |
||
3944 | break; |
||
8304 | schaersvoo | 3945 | |
15773 | schaersvoo | 3946 | |
7614 | schaersvoo | 3947 | case RAYS: |
3948 | /* |
||
3949 | @ rays color,xc,yc,x1,y1,x2,y2,x3,y3...x_n,y_n |
||
15111 | schaersvoo | 3950 | @ draw rays in color 'color' and center (xc:yc) |
7786 | schaersvoo | 3951 | @ may be set draggable or onclick (every individual ray) |
12111 | schaersvoo | 3952 | @%rays_onclick%size 400,400%xrange -10,10%yrange -10,10%onclick%rays blue,0,0,3,9,-3,5,-4,0,4,-9,7,9,-8,1,-1,-9 |
3953 | @%rays_drag_xy%size 400,400%xrange -10,10%yrange -10,10%drag xy%rays blue,0,0,3,9,-3,5,-4,0,4,-9,7,9,-8,1,-1,-9 |
||
7614 | schaersvoo | 3954 | */ |
3955 | stroke_color=get_color(infile,0); |
||
7786 | schaersvoo | 3956 | fill_color = stroke_color; |
3957 | double_data[0] = get_real(infile,0);/* xc */ |
||
3958 | double_data[1] = get_real(infile,0);/* yc */ |
||
3959 | i=2; |
||
3960 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 3961 | if(i > MAX_INT - 1){canvas_error("in command rays too many points / rays in argument: repeat command multiple times to fit");} |
7786 | schaersvoo | 3962 | if(i%2 == 0 ){ |
3963 | double_data[i] = get_real(infile,0); /* x */ |
||
7614 | schaersvoo | 3964 | } |
7786 | schaersvoo | 3965 | else |
3966 | { |
||
3967 | double_data[i] = get_real(infile,1); /* y */ |
||
7614 | schaersvoo | 3968 | } |
7786 | schaersvoo | 3969 | fprintf(js_include_file,"/* double_data[%d] = %f */\n",i,double_data[i]); |
3970 | i++; |
||
7614 | schaersvoo | 3971 | } |
15111 | schaersvoo | 3972 | if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);} |
3973 | if(use_affine == TRUE ){ transform(i-1,2);} |
||
8224 | bpr | 3974 | if( i%2 != 0 ){canvas_error("in command rays: unpaired x or y value");} |
3975 | decimals = find_number_of_digits(precision); |
||
15111 | schaersvoo | 3976 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
7786 | schaersvoo | 3977 | for(c=2; c<i;c = c+2){ |
15111 | schaersvoo | 3978 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[c],decimals,double_data[1],decimals,double_data[c+1],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
3979 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
3980 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[c],decimals,double_data[1],decimals,double_data[c+1],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
3981 | add_to_buffer(tmp_buffer); |
||
3982 | /* object_cnt++; */ |
||
3983 | if(onclick != 0){object_cnt++;} |
||
7614 | schaersvoo | 3984 | } |
3985 | reset(); |
||
15111 | schaersvoo | 3986 | dragstuff[4] = 1; |
3987 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
7614 | schaersvoo | 3988 | break; |
8304 | schaersvoo | 3989 | |
11806 | schaersvoo | 3990 | case RECT: |
8386 | schaersvoo | 3991 | /* |
11806 | schaersvoo | 3992 | @ rect x1,y1,x2,y2,color |
14071 | bpr | 3993 | @ use command <code>frect x1,y1,x2,y2,color</code> for a filled rectangle |
14246 | bpr | 3994 | @ use command/keyword <a href='#filled'>filled</a> before command <code>rect x1,y1,x2,y2,color</code> |
9406 | schaersvoo | 3995 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
15541 | schaersvoo | 3996 | @ note: internally a rect is defined with 4 points. So when performing some affine transformation, other than translation, it will result in some morphing of the rectangle !<br/>this is a deviation of flydraw's rect&affine |
12111 | schaersvoo | 3997 | @%rect%size 400,400%xrange -10,10%yrange -10,10%rect 0,0,4,-4,green%rect 0,5,4,1,red |
8386 | schaersvoo | 3998 | */ |
11806 | schaersvoo | 3999 | for(i=0;i<5;i++){ |
4000 | switch(i){ |
||
4001 | case 0:double_data[0] = get_real(infile,0);break; /* x-values */ |
||
4002 | case 1:double_data[1] = get_real(infile,0);break; /* y-values */ |
||
15111 | schaersvoo | 4003 | case 2:double_data[4] = get_real(infile,0);break; /* x-values */ |
4004 | case 3:double_data[5] = get_real(infile,0);break; /* y-values */ |
||
11806 | schaersvoo | 4005 | case 4:stroke_color = get_color(infile,1);/* name or hex color */ |
8386 | schaersvoo | 4006 | decimals = find_number_of_digits(precision); |
15111 | schaersvoo | 4007 | double_data[2] = double_data[4]; |
4008 | double_data[3] = double_data[1]; |
||
4009 | double_data[6] = double_data[0]; |
||
4010 | double_data[7] = double_data[5]; |
||
4011 | /* using closed PATH (type=5) in stead of ctx.rect (type=1)!!! |
||
4012 | 0,1 2,3 |
||
4013 | 6,7 4,5 |
||
4014 | x = [0,2,4,6] |
||
4015 | y = [1,3,5,7] |
||
4016 | */ |
||
4017 | if(use_rotate == TRUE ){rotate(8,angle,rotationcenter,2);} |
||
4018 | if(use_affine == TRUE ){ transform(8,2);} |
||
4019 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
4020 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,5,[%.*f,%.*f,%.*f,%.*f],[%.*f,%.*f,%.*f,%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[2],decimals,double_data[4],decimals,double_data[6],decimals,double_data[1],decimals,double_data[3],decimals,double_data[5],decimals,double_data[7],line_width,line_width,line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
4021 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
4022 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,5,[%.*f,%.*f,%.*f,%.*f],[%.*f,%.*f,%.*f,%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[2],decimals,double_data[4],decimals,double_data[6],decimals,double_data[1],decimals,double_data[3],decimals,double_data[5],decimals,double_data[7],line_width,line_width,line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
4023 | add_to_buffer(tmp_buffer); |
||
4024 | if(onclick != 0){object_cnt++;} |
||
4025 | /* object_cnt++; */ |
||
8386 | schaersvoo | 4026 | reset(); |
4027 | break; |
||
11806 | schaersvoo | 4028 | } |
4029 | } |
||
15111 | schaersvoo | 4030 | dragstuff[5] = 1; |
4031 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
11806 | schaersvoo | 4032 | break; |
8386 | schaersvoo | 4033 | |
11806 | schaersvoo | 4034 | case RECTS: |
8304 | schaersvoo | 4035 | /* |
11806 | schaersvoo | 4036 | @ rects color,x1,y1,x2,y2,..... |
14071 | bpr | 4037 | @ use command <code>frect color,x1,y1,x2,y2,.....</code> for a filled rectangle |
14246 | bpr | 4038 | @ use command/keyword <a href='#filled'>filled</a> before command <code>rects color,x1,y1,x2,y2,....</code> |
14071 | bpr | 4039 | @ use command <code>fillcolor color</code> before ''frects`` to set the fill colour. |
9406 | schaersvoo | 4040 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually |
12111 | schaersvoo | 4041 | @%rects%size 400,400%xrange -10,10%yrange -10,10%rects red,0,0,4,-4,0,5,4,1 |
8304 | schaersvoo | 4042 | */ |
15111 | schaersvoo | 4043 | /* using closed PATH (type=5) in stead of ctx.rect (type=1)!!! |
4044 | 0,1 2,3 .....8,9 10,11..... |
||
4045 | 6,7 4,5 .....14,15 12,13..... |
||
4046 | x = [0,2,4,6,8,10,12,14...] |
||
4047 | y = [1,3,5,7,9,11,13,15...] |
||
4048 | */ |
||
8304 | schaersvoo | 4049 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
4050 | fill_color = stroke_color; |
||
4051 | i=0; |
||
4052 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 4053 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
8304 | schaersvoo | 4054 | if(i%2 == 0 ){ |
4055 | double_data[i] = get_real(infile,0); /* x */ |
||
4056 | } |
||
4057 | else |
||
4058 | { |
||
4059 | double_data[i] = get_real(infile,1); /* y */ |
||
4060 | } |
||
4061 | i++; |
||
4062 | } |
||
15111 | schaersvoo | 4063 | if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);} |
4064 | if(use_affine == TRUE ){ transform(i-1,2);} |
||
4065 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
15116 | bpr | 4066 | |
8304 | schaersvoo | 4067 | decimals = find_number_of_digits(precision); |
4068 | for(c = 0 ; c < i-1 ; c = c+4){ |
||
15111 | schaersvoo | 4069 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,5,[%.*f,%.*f,%.*f,%.*f],[%.*f,%.*f,%.*f,%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[c],decimals,double_data[c+2],decimals,double_data[c+2],decimals,double_data[c],decimals,double_data[c+1],decimals,double_data[c+1],decimals,double_data[c+3],decimals,double_data[c+3],line_width,line_width,line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
4070 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
4071 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,5,[%.*f,%.*f,%.*f,%.*f],[%.*f,%.*f,%.*f,%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[c],decimals,double_data[c+2],decimals,double_data[c+2],decimals,double_data[c],decimals,double_data[c+1],decimals,double_data[c+1],decimals,double_data[c+3],decimals,double_data[c+3],line_width,line_width,line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
4072 | add_to_buffer(tmp_buffer); |
||
4073 | if(onclick != 0){object_cnt++;} |
||
4074 | /* object_cnt++; */ |
||
8304 | schaersvoo | 4075 | } |
15111 | schaersvoo | 4076 | dragstuff[5] = 1; |
4077 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
4078 | if(use_rotate == TRUE ){ |
||
4079 | rotate(i-1,angle,rotationcenter,2); |
||
4080 | } |
||
8304 | schaersvoo | 4081 | reset(); |
4082 | break; |
||
8386 | schaersvoo | 4083 | |
11806 | schaersvoo | 4084 | case REPLYFORMAT: |
7614 | schaersvoo | 4085 | /* |
11806 | schaersvoo | 4086 | @ replyformat number |
4087 | @ use number=-1 to deactivate the js-functions read_canvas() and read_dragdrop() |
||
4088 | @ default values should be fine ! |
||
14071 | bpr | 4089 | @ use command <code>precision [0,1,10,100,1000,10000...]</code> before command ''replyformat`` to set the desired number of decimals in the student reply / drawing |
14246 | bpr | 4090 | @ the last value for ''precision int`` will be used to calculate the reply coordinates, if needed (read_canvas();) |
15651 | reyssat | 4091 | @ choose<ul><li>replyformat 1: <code>x1,x2,x3,x4....x_n<br />y1,y2,y3,y4....y_n</code> x/y in pixels</li><li>replyformat 2: <code> x1,x2,x3,x4....x_n<br /> y1,y2,y3,y4....y_n</code> x/y in xrange / yrange coordinate system</li><li>replyformat 3: <code> x1,x2,x3,x4....x_n<br /> y1,y2,y3,y4....y_n<br /> r1,r2,r3,r4....r_n</code> x/y in pixels, r in pixels</li><li>replyformat 4: <code> x1,x2,x3,x4....x_n<br /> y1,y2,y3,y4....y_n<br /> r1,r2,r3,r4....r_n</code> x/y in xrange / yrange coordinate system, r in pixels</li><li>replyformat 5: <code> Ax1,Ax2,Ax3,Ax4....Ax_n<br /> Ay1,Ay2,Ay3,Ay4....Ay_n<br /> Bx1,Bx2,Bx3,Bx4....Bx_n<br /> By1,By2,By3,By4....By_n<br /> Cx1,Cx2,Cx3,Cx4....Cx_n<br /> Cy1,Cy2,Cy3,Cy4....Cy_n<br /> ....<br /> Zx1,Zx2,Zx3,Zx4....Zx_n<br /> Zy1,Zy2,Zy3,Zy4....Zy_n</code> x/y in pixels</li><li>replyformat 6: <code> Ax1,Ax2,Ax3,Ax4....Ax_n<br /> Ay1,Ay2,Ay3,Ay4....Ay_n<br /> Bx1,Bx2,Bx3,Bx4....Bx_n<br /> By1,By2,By3,By4....By_n<br /> Cx1,Cx2,Cx3,Cx4....Cx_n<br /> Cy1,Cy2,Cy3,Cy4....Cy_n<br /> ....<br /> Zx1,Zx2,Zx3,Zx4....Zx_n<br /> Zy1,Zy2,Zy3,Zy4....Zy_n</code> x/y in xrange / yrange coordinate system</li><li>replyformat 7: <code> x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n</code> x/y in pixels</li><li>replyformat 8: <code> x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n</code> x/y in xrange / yrange coordinate system</li><li>replyformat 9: <code> x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n</code> x/y in pixels</li><li>replyformat 10: <code> x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n</code> x/y in xrange / yrange coordinate system</li><li>replyformat 11: <code> Ax1,Ay1,Ax2,Ay2<br />Bx1,By1,Bx2,By2<br /> Cx1,Cy1,Cx2,Cy2<br /> Dx1,Dy1,Dx2,Dy2<br /> ......<br /> Zx1,Zy1,Zx2,Zy2</code> x/y in xrange / yrange coordinate system</li><li>replyformat 12: <code> Ax1,Ay1,Ax2,Ay2<br /> Bx1,By1,Bx2,By2<br />Cx1,Cy1,Cx2,Cy2<br /> Dx1,Dy1,Dx2,Dy2<br /> ......<br /> Zx1,Zy1,Zx2,Zy2</code> x/y in pixels</li><li>replyformat 13: <code> Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2,Cx1:Cy1:Cx2:Cy2,Dx1:Dy1:Dx2:Dy2, ... ,Zx1:Zy1:Zx2:Zy2</code> x/y in xrange / yrange coordinate system</li><li>replyformat 14: <code> Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2....Zx1:Zy1:Zx2:Zy2</code> x/y in pixels</li><li>replyformat 15: reply from inputfields,textareas <code>reply1,reply2,reply3,...,reply_n</code></li><li>replyformat 16: mathml input fields</li><li>replyformat 17: read ''userdraw text,color`` only <code>x1,y1,text1 \\n x2,y2,text2...\\n...x_n,y_n,text_n </code> x/y-values are in xrange/yrange</li><li>replyformat 18: read_canvas() will read all interactive clocks in <code>H1:M1:S1,H2:M2:S2...Hn:Mn:Sn</code></li><li>replyformat 19: read_canvas() will return the object number of marked / clicked object (clock), analogue to (shape library) onclick command</li><li>replyformat 20: read_canvas() will reply "object_number:x:y" of external images: object_number of the first draggable external image in the fly-script starts with 0, e.g. expect something like 0:-5:4,1:6:2,2:-2:-5, the first image position is (-5:4), the second image position is (6:2) and the third image position is (-2:-5) <li>replyformat 21: <code> (x1:y1) (x2:y2) ... (x_n:y_n)</code> verbatim coordinate return</li><li>replyformat 22: returns an array .... <code>reply[0]=x1 reply[1]=y1 reply[2]=x2 reply[3]=y2 ... reply[n-1]=x_n reply[n]=y_n</code> x/y in xrange / yrange coordinate system</li><li>replyformat 23: can only be used for drawtype ''polyline``. A typical click sequence in drawtype polyline is x1,y1,x2,y2,x2,y2,x3,y3,x3,y3.....,x(n-1),y(n-1),x(n-1),y(n-1),xn,yn --replyformat 23 gives <code>x1,y1,x2,y2,x3,y3,.....x(n-1),y(n-1),xn,yn</code>; multiple occurences will be filtered out. The reply will be in x-y-range (xreply \\n yreply)</li><li>replyformat 24: read all inputfield values: even those set ''readonly``</li><li>replyformat 25: <code> angle1,angle2;...;angle_n</code> will return the radius (one or many) of the user drawn circle segment in degrees</li><li>replyformat 26: <code> rad1,rad2,...rad_n</code> will return the radius (one or many) of the user drawn circle segment in radians</li><li>replyformat 27: return (only) userdraw inputfields <code>x1,y1,text1<br /> x2,y2,text2...<br />...x_n,y_n,textn</code></li><li>replyformat 28: <code> x1,y1,r1,x2,y2,r2...x_n,y_n,r_n</code> x / y / r in xrange / yrange coordinate system: may be used to reinput into command <code>circles color,x1,y1,r1,x2,y2,r2...x_n,y_n,r_n</code> will not return anything else (e.g. no inputfields, text etc)</li><li>replyformat 34: a special for OEF and dragging external images -included via commands <a href='#copy'>copy</a> or <a href='#copyresized'>copyresized</a> there will be an extra function <code>read_canvas_images()</code> for reading the coordinates of the images.<br />for now this is a unique function, e.g. there is no ''canvas id`` linked to it. (TO DO !!! 18/5/2019)</li></ul> |
16718 | schaersvoo | 4092 | @ special replyformat = 100 ; will access to the raw javascript object data...use: read_dragdrop([property,property,...])<br />for example properies like 'clicked','text', 'angle' , 'x' |
11806 | schaersvoo | 4093 | */ |
4094 | reply_format = (int) get_real(infile,1); |
||
4095 | reply_precision = precision; |
||
4096 | break; |
||
4097 | |||
4098 | case ROUNDRECT: |
||
4099 | /* |
||
4100 | @ roundrect x1,y1,x2,y2,radius in px,color |
||
14071 | bpr | 4101 | @ use command <code>froundrect x1,y1,x2,y2,radius,color</code> for a filled rectangle |
4102 | @ use command/keyword <a href='#filled'>filled</a> before command <code>roundrect x1,y1,x2,y2,radius,color</code> |
||
4103 | @ fillcolor will be identical to ''color`` |
||
9406 | schaersvoo | 4104 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
12111 | schaersvoo | 4105 | @%roundrect%size 400,400%xrange -10,10%yrange -10,10%roundrect 0,0,4,-4,20,green%roundrect 0,5,4,1,10,red |
7614 | schaersvoo | 4106 | */ |
11806 | schaersvoo | 4107 | for(i=0;i<6;i++){ |
4108 | switch(i){ |
||
4109 | case 0:double_data[0] = get_real(infile,0);break; /* x-values */ |
||
4110 | case 1:double_data[1] = get_real(infile,0);break; /* y-values */ |
||
4111 | case 2:double_data[2] = get_real(infile,0);break; /* x-values */ |
||
4112 | case 3:double_data[3] = get_real(infile,0);break; /* y-values */ |
||
4113 | case 4:int_data[0] = (int) (get_real(infile,0));break; /* radius value in pixels */ |
||
4114 | case 5:stroke_color = get_color(infile,1);/* name or hex color */ |
||
15111 | schaersvoo | 4115 | if(use_rotate == TRUE ){rotate(4,angle,rotationcenter,2);} |
4116 | if(use_affine == TRUE ){ transform(2,4);} |
||
4117 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
11806 | schaersvoo | 4118 | /* ensure no inverted roundrect is produced... */ |
4119 | if( double_data[0] > double_data[2] ){double_data[4] = double_data[0];double_data[0] = double_data[2];double_data[2] = double_data[4];} |
||
4120 | if( double_data[3] > double_data[1] ){double_data[4] = double_data[1];double_data[1] = double_data[3];double_data[3] = double_data[4];} |
||
7614 | schaersvoo | 4121 | decimals = find_number_of_digits(precision); |
15111 | schaersvoo | 4122 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,6,[%.*f,%.*f],[%.*f,%.*f],[%d,%d],[%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[2],decimals,double_data[1],decimals,double_data[3],int_data[0],int_data[0],int_data[0],int_data[0],line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
4123 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
4124 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,6,[%.*f,%.*f],[%.*f,%.*f],[%d,%d],[%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[2],decimals,double_data[1],decimals,double_data[3],int_data[0],int_data[0],int_data[0],int_data[0],line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
4125 | add_to_buffer(tmp_buffer); |
||
4126 | if(onclick != 0){object_cnt++;} |
||
4127 | /* object_cnt++;*/ |
||
8379 | schaersvoo | 4128 | reset(); |
11806 | schaersvoo | 4129 | break; |
4130 | } |
||
4131 | } |
||
15111 | schaersvoo | 4132 | dragstuff[6] = 1; |
4133 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
11806 | schaersvoo | 4134 | break; |
8386 | schaersvoo | 4135 | |
11806 | schaersvoo | 4136 | case ROUNDRECTS: |
8347 | schaersvoo | 4137 | /* |
11806 | schaersvoo | 4138 | @ roundrects color,radius in px,x1,y1,x2,y2,x3,y3,x4,y4,.... |
14066 | bpr | 4139 | @ for filled roundrects use command/keyword <a href='#filled'>filled</a> before command |
9406 | schaersvoo | 4140 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually |
13935 | bpr | 4141 | @%roundrects%size 400,400%xrange -10,10%yrange -10,10%roundrects blue,5,0,0,4,-4,5,4,1,2 |
8347 | schaersvoo | 4142 | */ |
11806 | schaersvoo | 4143 | |
8347 | schaersvoo | 4144 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
11806 | schaersvoo | 4145 | int_data[0] = (int) (get_real(infile,0)); /* radius value in pixels */ |
8347 | schaersvoo | 4146 | fill_color = stroke_color; |
4147 | i=0; |
||
4148 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 4149 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
8347 | schaersvoo | 4150 | if(i%2 == 0 ){ |
4151 | double_data[i] = get_real(infile,0); /* x */ |
||
4152 | } |
||
4153 | else |
||
4154 | { |
||
4155 | double_data[i] = get_real(infile,1); /* y */ |
||
4156 | } |
||
4157 | i++; |
||
4158 | } |
||
15111 | schaersvoo | 4159 | if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);} |
4160 | if(use_affine == TRUE ){ transform(i-1,2);} |
||
4161 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
8347 | schaersvoo | 4162 | decimals = find_number_of_digits(precision); |
4163 | for(c = 0 ; c < i-1 ; c = c+4){ |
||
11806 | schaersvoo | 4164 | /* ensure no inverted roundrect is produced... */ |
4165 | if( double_data[c] > double_data[c+2] ){double_data[c+4] = double_data[c];double_data[c] = double_data[c+2];double_data[c+2] = double_data[c+4];} |
||
4166 | if( double_data[c+3] > double_data[c+1] ){double_data[c+4] = double_data[c+1];double_data[c+1] = double_data[c+3];double_data[c+3] = double_data[c+4];} |
||
15111 | schaersvoo | 4167 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,6,[%.*f,%.*f],[%.*f,%.*f],[%d,%d],[%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[c],decimals,double_data[c+2],decimals,double_data[c+1],decimals,double_data[c+3],int_data[0],int_data[0],int_data[0],int_data[0],line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
4168 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
4169 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,6,[%.*f,%.*f],[%.*f,%.*f],[%d,%d],[%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[c],decimals,double_data[c+2],decimals,double_data[c+1],decimals,double_data[c+3],int_data[0],int_data[0],int_data[0],int_data[0],line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
4170 | add_to_buffer(tmp_buffer); |
||
4171 | if(onclick != 0){object_cnt++;} |
||
4172 | /* object_cnt++; */ |
||
8347 | schaersvoo | 4173 | } |
15111 | schaersvoo | 4174 | dragstuff[6] = 1; |
4175 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
8347 | schaersvoo | 4176 | reset(); |
4177 | break; |
||
8386 | schaersvoo | 4178 | |
11806 | schaersvoo | 4179 | case RULER: |
7614 | schaersvoo | 4180 | /* |
14078 | bpr | 4181 | @ ruler x,y,x-width,y-height,mode |
11806 | schaersvoo | 4182 | @ x,y are the initial location |
14078 | bpr | 4183 | @ x-width, y-height are the ruler dimensions width & height in xy-coordinate system |
14071 | bpr | 4184 | @ the ruler scale is by definition the x-scale, set by command ''xrange``. For example: a ruler x-width of 6 will have a scale ranging from 0 to 6 |
14066 | bpr | 4185 | @ mode: use -1 to set the ruler interactive (eg mouse movement of ruler; drag & rotate)<br />use mode = '0° - 360°' to set the ruler with a static angle of some value |
11806 | schaersvoo | 4186 | @ if combined with a protractor, use replyformat = 32 |
4187 | @ only one ruler allowed (for the time being) |
||
15651 | reyssat | 4188 | @ when using command ''zoom``, pay <b>attention</b> to the size and symmetry of your canvas to avoid a partial image, locate the start position near the center of the visual canvas; technical: the actual ''ruler`` is just a static generated image in a new canvas-memory. This image is only generated once, and a copy of its bitmap is translated & rotated onto the visible canvas. That is the reason for the ''high-speed dragging and rotating``. I have limited its size to xsize × ysize e.g. the same size as the visual canvas... |
14247 | bpr | 4189 | @ usage: first left click on the ruler will activate dragging; a second left click will activate rotating (just move mouse around), a third click will freeze this position and the x/y-coordinate and angle in radians will be stored in reply(3), a next click will restart this sequence... |
15313 | schaersvoo | 4190 | @%ruler_interactive%size 800,400%xrange -10,10%yrange -10,10%strokecolor blue%opacity 200,50%filled%fillcolor lightgrey%ruler -9,0,10,2,-1%display degree,blue,22 |
4191 | @%ruler_set_degree_45%size 800,400%xrange -10,10%yrange -10,10%strokecolor blue%opacity 200,50%filled%fillcolor lightgrey%ruler 0,0,10,2,45 |
||
4192 | @%ruler_set_degree_125%size 800,400%xrange -10,10%yrange -10,10%strokecolor blue%opacity 200,50%filled%fillcolor lightgrey%ruler 0,0,10,2,125 |
||
7614 | schaersvoo | 4193 | */ |
11806 | schaersvoo | 4194 | for( i = 0;i < 5; i++ ){ |
7614 | schaersvoo | 4195 | switch(i){ |
11806 | schaersvoo | 4196 | case 0: double_data[0] = get_real(infile,0);break; /* x-center */ |
4197 | case 1: double_data[1] = get_real(infile,0);break; /* y-center */ |
||
4198 | case 2: double_data[2] = get_real(infile,0);break; /* x-width */ |
||
4199 | case 3: double_data[3] = get_real(infile,0);break; /* y-width */ |
||
4200 | case 4: int_data[0] = (int)(get_real(infile,1)); /* passive mode */ |
||
4201 | decimals = find_number_of_digits(precision); |
||
4202 | if( int_data[0] < 0 ){ |
||
15116 | bpr | 4203 | js_function[JS_FIND_ANGLE] = 1; |
11806 | schaersvoo | 4204 | } |
15111 | schaersvoo | 4205 | add_js_ruler(double_data[0],double_data[1],double_data[2],double_data[3],font_family,stroke_color,stroke_opacity,fill_color,fill_opacity,line_width,int_data[0],use_snap); |
14208 | schaersvoo | 4206 | string_length = 1 + snprintf(NULL,0,";ruler%d(); ",canvas_root_id); |
4207 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11806 | schaersvoo | 4208 | snprintf(tmp_buffer,string_length,";ruler%d(); ",canvas_root_id); |
4209 | add_to_buffer(tmp_buffer); |
||
4210 | reply_precision = precision; |
||
4211 | /* no reply from ruler if non-interactive */ |
||
4212 | if( reply_format == 0 && int_data[0] == -1 ){reply_format = 31;} |
||
7614 | schaersvoo | 4213 | break; |
4214 | default: break; |
||
4215 | } |
||
4216 | } |
||
4217 | break; |
||
8386 | schaersvoo | 4218 | |
15111 | schaersvoo | 4219 | case RESETOFFSET: |
4220 | /* |
||
4221 | @ resetoffset |
||
4222 | @ keyword ; use to restore text placement on the canvas to the real (x;y) coordinates of the left bottom corner of the text |
||
4223 | @ may be active for commands <a href="#text">text</a> and <a href="#string">string</a> (e.g. objects in the drag/drop/onclick-librariy |
||
4224 | */ |
||
4225 | use_offset = 0; |
||
4226 | break; |
||
11806 | schaersvoo | 4227 | |
15111 | schaersvoo | 4228 | case ROTATE: |
4229 | /* |
||
4230 | @ rotate rotation_angle |
||
4231 | @ angle in degrees |
||
4232 | @ (only) the next object will be rotated is given angle |
||
4233 | @ positive values rotate counter clockwise |
||
4234 | @ attention: all objects will be rotated around their first point...<br /><code>rotate 45<br />triangle 1,1,5,1,3,4,red</code><br />will rotate 45 degrees around point (1:1) |
||
4235 | @ if another rotation center is needed, use command <a href="#rotationcenter">rotationcenter xc,yc</a>.<br />to reset this rotationcenter, use keyword <a href="#killrotate">killrotate</a> |
||
4236 | @ attention: rotate will mess up the interactivity of the rotated object <br />e.g. if combined with command <a href="#drag">drag xy</a> or keyword <a href="#onclick">onclick</a>: the mouse recognises the original -unrotated- coordinates of the object |
||
4237 | @%rotate_1%size 400,400%xrange -10,10%yrange -10,10%fpoly yellow,0,0,4,3,2,5%rotate 45%fpoly violet,0,0,4,3,2,5%killrotate%rotate 90%fpoly violet,0,0,4,3,2,5% |
||
4238 | */ |
||
4239 | use_rotate = TRUE; |
||
4240 | angle = -1*(get_real(infile,1));/* -1: to be compatible with Flydraw... */ |
||
4241 | break; |
||
4242 | case ROTATION_CENTER: |
||
4243 | /* |
||
4244 | @ rotationcenter x_center,y_center |
||
4245 | @ define an rotation center in your x/y-coordinate system |
||
4246 | @ wims will not check the validity of your input; use javascript console to debug any erors |
||
4247 | @ if not defined a rotation will be around the first point of an object |
||
4248 | @ to be used before command <a href="#rotate">rotate</a> |
||
4249 | @ use <a href="#killrotate">killrotate</a> to reset to 'null' <br/>(eg. the rotationcenter of the next object(s) will be the first (x;y) coordinate of the object(s)) |
||
4250 | @ all other commands will use this rotation center, unless a <a href="#killrotation">killrotation</a> is given |
||
4251 | @%rotationcenter%size 400,400%xrange -5,10%yrange -5,10%circles green,3,3,4.25%rotationcenter 3,3%opacity 255,80%fpoly yellow,0,0,4,3,2,5%rotate 45%fpoly violet,0,0,4,3,2,5%rotate 90%fpoly lightblue,0,0,4,3,2,5%rotate 135%fpoly blue,0,0,4,3,2,5%rotate 180%fpoly orange,0,0,4,3,2,5%rotate 225%fpoly green,0,0,4,3,2,5%rotate 270%fpoly cyan,0,0,4,3,2,5%rotate 315%fpoly purple,0,0,4,3,2,5%linewidth 3%point 3,3,red%mouse red,22 |
||
15633 | bpr | 4252 | @%rotationcenter_slider%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%fillcolor black%strokecolor yellow%rotationcenter 0,0%fontsize 28%slider 0,2*pi,400,30,angle degrees active, rotate...%plot red,5*sin(x)%filled%linewidth 1%opacity 150,50%fillcolor orange%angle 0,0,pi,0,0,blue |
15111 | schaersvoo | 4253 | */ |
4254 | for( i = 0;i < 2; i++ ){ |
||
4255 | switch(i){ |
||
4256 | case 0: rotationcenter[0] = get_real(infile,0);break; /* x-center */ |
||
4257 | case 1: rotationcenter[1] = get_real(infile,1);break; /* y-center */ |
||
4258 | } |
||
4259 | string_length = 1 + snprintf(NULL,0,"[%f,%f ]",rotationcenter[0],rotationcenter[1]); |
||
4260 | check_string_length(string_length); |
||
4261 | rotation_center = my_newmem(string_length); |
||
4262 | snprintf(rotation_center,string_length,"[%f,%f]",rotationcenter[0],rotationcenter[1]); |
||
4263 | } |
||
4264 | break; |
||
11806 | schaersvoo | 4265 | |
4266 | case SIZE: |
||
4267 | /* |
||
4268 | @ size width,height |
||
4269 | @ set canvas size in pixels |
||
14066 | bpr | 4270 | @ mandatory first command (can only be preceded by keyword <a href="#popup">popup</a>) |
14162 | bpr | 4271 | @ if xrange and/or yrange is not given the range will be set to pixels:<br />xrange 0,xsize yrange 0,ysize<br />note: lower left corner is origin (0:0) !!! this in contrast to flydraw |
11806 | schaersvoo | 4272 | */ |
4273 | found_size_command = 1; |
||
14066 | bpr | 4274 | /* using fabs: however "xsize == int": so "xsize = abs( (int) get_real(infile,0))" would be the idea... */ |
11806 | schaersvoo | 4275 | xsize = (int)(fabs(round(get_real(infile,0)))); /* just to be sure that sizes > 0 */ |
4276 | ysize = (int)(fabs(round(get_real(infile,1)))); |
||
4277 | /* sometimes we want xrange / yrange to be in pixels...without telling x/y-range */ |
||
4278 | xmin = 0;xmax = xsize; |
||
4279 | ymin = 0;ymax = ysize; |
||
4280 | |||
4281 | /* |
||
4282 | The sequence in which stuff is finally printed is important !! |
||
4283 | */ |
||
4284 | fprintf(stdout,"\n\ |
||
13970 | obado | 4285 | <script>\n\ |
11806 | schaersvoo | 4286 | /*<![CDATA[*/\n\ |
4287 | if( typeof(wims_status) === 'undefined' ){ var wims_status = \"$status\";};\ |
||
4288 | if( typeof(use_dragdrop_reply) === 'undefined' ){ var use_dragdrop_reply = false;};\ |
||
4289 | if( typeof(canvas_scripts) === 'undefined' ){ var canvas_scripts = new Array();};\ |
||
4290 | canvas_scripts.push(\"%d\");\n/*]]>*/\n</script>\n\ |
||
4291 | ",canvas_root_id); |
||
4292 | |||
4293 | /* style=\"display:block;position:relative;margin-left:auto;margin-right:auto;margin-bottom:4px;\" */ |
||
4294 | if( use_tooltip != 2){ |
||
16844 | bpr | 4295 | fprintf(stdout,"<!-- canvasdraw div -->\n\ |
11806 | schaersvoo | 4296 | <div tabindex=\"0\" id=\"canvas_div%d\" style=\"position:relative;width:%dpx;height:%dpx;margin-left:auto;margin-right:auto;\" oncontextmenu=\"return false;\"></div>\n\ |
4297 | <!-- tooltip and input placeholder -->\n\ |
||
4298 | <div id=\"tooltip_placeholder_div%d\" style=\"text-align:center\"><span id=\"tooltip_placeholder%d\" style=\"display:none;\"></span></div>\ |
||
4299 | <!-- include actual object code via include file -->\n\ |
||
15111 | schaersvoo | 4300 | <script id=\"canvas_script%d\" src=\"%s\" defer></script>\n",canvas_root_id,xsize,ysize,canvas_root_id,canvas_root_id,canvas_root_id,getfile_cmd); |
11806 | schaersvoo | 4301 | } |
4302 | else |
||
4303 | { |
||
4304 | /* |
||
14066 | bpr | 4305 | set canvas_div invisible and do not include placeholder in main html page: |
15111 | schaersvoo | 4306 | the js-include will also be in a popup window...to be shown when wims $status = done |
11806 | schaersvoo | 4307 | */ |
16844 | bpr | 4308 | fprintf(stdout,"<!-- canvasdraw div invisible -->\n\ |
11806 | schaersvoo | 4309 | <div tabindex=\"0\" id=\"canvas_div%d\" style=\"display:none;position:relative;width:%dpx;height:%dpx;margin-left:auto;margin-right:auto;\" ></div>\n\ |
4310 | <div id=\"tooltip_placeholder_div%d\" style=\"display:none;position:relative;margin-left:auto;margin-right:auto;margin-bottom:4px;\"><span id=\"tooltip_placeholder%d\" style=\"display:none;\"></span></div>\ |
||
4311 | <!-- include actual object code via include file -->\n\ |
||
13970 | obado | 4312 | <script id=\"canvas_script%d\" src=\"%s\"></script>\n",canvas_root_id,xsize,ysize,canvas_root_id,canvas_root_id,canvas_root_id,getfile_cmd); |
11806 | schaersvoo | 4313 | } |
4314 | |||
14071 | bpr | 4315 | /* these must be global...it is all really very poor javascript:( */ |
15734 | schaersvoo | 4316 | fprintf(js_include_file,"\n/* begin generated javascript include for canvasdraw version %s */\n\ |
11806 | schaersvoo | 4317 | \"use strict\";\n\ |
15111 | schaersvoo | 4318 | /* these variables and functions must be global */\ |
11806 | schaersvoo | 4319 | var read_dragdrop%d;\ |
14038 | schaersvoo | 4320 | var read_canvas_images;\ |
11806 | schaersvoo | 4321 | var read_canvas%d;\ |
4322 | var set_clock;\ |
||
4323 | var clear_draw_area%d;\ |
||
4324 | var update_draw_area%d;\ |
||
14038 | schaersvoo | 4325 | var place_image_on_canvas;\ |
11806 | schaersvoo | 4326 | var draw_boxplot;\ |
4327 | var redraw_all%d;\ |
||
15111 | schaersvoo | 4328 | var userdraw_primitive;\ |
4329 | var wims_canvas_function%d = function(){\n/* common used stuff */\ |
||
4330 | var userdraw_x = [];var userdraw_y = [];var userdraw_radius = [];\ |
||
11806 | schaersvoo | 4331 | var xsize = %d;\ |
4332 | var ysize = %d;\ |
||
4333 | var precision = 100;\ |
||
4334 | var canvas_div = document.getElementById(\"canvas_div%d\");\ |
||
4335 | var create_canvas%d = function(canvas_type,size_x,size_y){var cnv;if(document.getElementById(\"wims_canvas%d\"+canvas_type)){ cnv = document.getElementById(\"wims_canvas%d\"+canvas_type);}else{try{ cnv = document.createElement(\"canvas\"); }catch(e){alert(\"Your browser does not support HTML5 CANVAS:GET FIREFOX !\");return;};canvas_div.appendChild(cnv);};cnv.width = size_x;cnv.height = size_y;cnv.style.top = 0;cnv.style.left = 0;cnv.style.position = \"absolute\";cnv.id = \"wims_canvas%d\"+canvas_type;return cnv;};\ |
||
4336 | function findPosX(i){ var obj = i;var curleft = 0;if(obj.offsetParent){while(1){curleft += obj.offsetLeft;if(!obj.offsetParent){break;};obj = obj.offsetParent;};}else{if(obj.x){curleft += obj.x;};};return curleft;};function findPosY(i){var obj = i;var curtop = 0;if(obj.offsetParent){while(1){curtop += obj.offsetTop;if(!obj.offsetParent){break;};obj = obj.offsetParent;};}else{if(obj.y){curtop += obj.y;};};return curtop;};\ |
||
15111 | schaersvoo | 4337 | function x2px(x){if(use_xlogscale == 0 ){return parseFloat((x)*xsize/(xmax - xmin) - xsize*xmin/(xmax - xmin));}else{var x_max = Math.log(xmax)/Math.log(xlogbase);var x_min = Math.log(xmin)/Math.log(xlogbase);var x_in = Math.log(x)/Math.log(xlogbase);return x_in*xsize/(x_max - x_min) - xsize*x_min/(x_max - x_min);};};\ |
11806 | schaersvoo | 4338 | function px2x(px){if(use_xlogscale == 0 ){return parseFloat(px*(xmax - xmin)/xsize + xmin);}else{var x_max = Math.log(xmax)/Math.log(xlogbase);var x_min = Math.log(xmin)/Math.log(xlogbase);var x_out = x_min +px*(x_max - x_min)/(xsize);return Math.pow(xlogbase,x_out);};};\ |
4339 | function px2y(py){if(use_ylogscale == 0 ){return parseFloat(ymax - py*(ymax - ymin)/ysize);}else{var y_max = Math.log(ymax)/Math.log(ylogbase);var y_min = Math.log(ymin)/Math.log(ylogbase);var y_out = y_max +py*(y_min - y_max)/(ysize);return Math.pow(ylogbase,y_out);};};\ |
||
15111 | schaersvoo | 4340 | function y2px(y){if(use_ylogscale == 0){return parseFloat(-1*(y)*ysize/(ymax - ymin) + ymax*ysize/(ymax - ymin));}else{var y_max = Math.log(ymax)/Math.log(ylogbase);var y_min = Math.log(ymin)/Math.log(ylogbase);var y_in = Math.log(y)/Math.log(ylogbase);return (y_max - y_in)*ysize/(y_max - y_min);};};\ |
11806 | schaersvoo | 4341 | function scale_x_radius(rx){return rx*xsize/(xmax - xmin);};\ |
4342 | function scale_y_radius(ry){return ry*ysize/(ymax - ymin);};\ |
||
4343 | function distance(x1,y1,x2,y2){return Math.sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) );};\ |
||
4344 | function distance_to_line (r,q,x,y){var c = (y) - (-1/r)*(x);var xs = r*(c - q)/(r*r+1);var ys = (r)*(xs)+(q);return parseInt(Math.sqrt( (xs-x)*(xs-x) + (ys-y)*(ys-y) ));};\ |
||
4345 | function move(obj,dx,dy){for(var p = 0 ; p < obj.x.length; p++){obj.x[p] = obj.x[p] + dx;obj.y[p] = obj.y[p] + dy;};return obj;};\ |
||
15111 | schaersvoo | 4346 | var snap_x = 1;var snap_y = 1;\ |
11806 | schaersvoo | 4347 | function snap_to_x(x){return x2px(snap_x*(Math.round((px2x(x))/snap_x)));};\ |
11890 | schaersvoo | 4348 | function snap_to_y(y){return y2px(snap_y*(Math.round((px2y(y))/snap_y)));};\ |
15111 | schaersvoo | 4349 | function multisnap_check(x,y,snap){switch(snap){case 1:return [snap_to_x(x),snap_to_y(y)];break;case 2:return [snap_to_x(x),y];break;case 3:return [x,snap_to_y(y)];break;case 4:return snap_to_points(x,y);break;case 5: return snap_to_fun(x,y);break;default: return [x,y];break;};};\ |
11806 | schaersvoo | 4350 | var xlogbase = 10;\ |
4351 | var ylogbase = 10;\ |
||
4352 | var use_xlogscale = 0;\ |
||
4353 | var use_ylogscale = 0;\ |
||
11891 | schaersvoo | 4354 | var x_strings = {};var x_strings_up = [];\ |
11806 | schaersvoo | 4355 | var y_strings = null;\ |
4356 | var use_jsmath = 0;\ |
||
4357 | var xstart = 0;\ |
||
4358 | var ystart = 0;\ |
||
4359 | var unit_x=\" \";\ |
||
4360 | var unit_y=\" \";\ |
||
15111 | schaersvoo | 4361 | var dragdrop_reply = [];\ |
15734 | schaersvoo | 4362 | var external_canvas = create_canvas%d(%d,xsize,ysize);",VERSION,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,xsize,ysize,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,EXTERNAL_IMAGE_CANVAS); |
15111 | schaersvoo | 4363 | /* var xstart,ystart are normally 0 : in case of sgraph they have the 'jump' in the graph */ |
11806 | schaersvoo | 4364 | break; |
4365 | |||
4366 | |||
4367 | case SEGMENT: |
||
7614 | schaersvoo | 4368 | /* |
11806 | schaersvoo | 4369 | @ segment x1,y1,x2,y2,color |
15715 | schaersvoo | 4370 | @ alternative: seg |
14071 | bpr | 4371 | @ draw a line segment between points (x1:y1)--(x2:y2) in color ''color`` |
11806 | schaersvoo | 4372 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
14061 | schaersvoo | 4373 | @%segment_onclick%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%onclick%segment 1,1,-9,3,green |
4374 | @%segment_drag_y%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%drag y%segment 1,1,-9,3,green |
||
7614 | schaersvoo | 4375 | */ |
11806 | schaersvoo | 4376 | for(i=0;i<5;i++) { |
7614 | schaersvoo | 4377 | switch(i){ |
11806 | schaersvoo | 4378 | case 0: double_data[0]= get_real(infile,0);break; /* x1-values */ |
4379 | case 1: double_data[1]= get_real(infile,0);break; /* y1-values */ |
||
4380 | case 2: double_data[2]= get_real(infile,0);break; /* x2-values */ |
||
4381 | case 3: double_data[3]= get_real(infile,0);break; /* y2-values */ |
||
4382 | case 4: stroke_color=get_color(infile,1);/* name or hex color */ |
||
15111 | schaersvoo | 4383 | if(use_rotate == TRUE ){rotate(4,angle,rotationcenter,2);} |
4384 | if(use_affine == TRUE ){ transform(4,2);} |
||
4385 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
11806 | schaersvoo | 4386 | decimals = find_number_of_digits(precision); |
15111 | schaersvoo | 4387 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[2],decimals,double_data[1],decimals,double_data[3],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
4388 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
4389 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[2],decimals,double_data[1],decimals,double_data[3],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
4390 | add_to_buffer(tmp_buffer); |
||
4391 | if(onclick != 0){object_cnt++;} |
||
4392 | /* object_cnt++; */ |
||
11806 | schaersvoo | 4393 | reset(); |
4394 | break; |
||
4395 | default: break; |
||
7614 | schaersvoo | 4396 | } |
4397 | } |
||
15111 | schaersvoo | 4398 | dragstuff[4] = 1; |
4399 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
7614 | schaersvoo | 4400 | break; |
10953 | bpr | 4401 | |
11806 | schaersvoo | 4402 | case SEGMENTS: |
9213 | schaersvoo | 4403 | /* |
11806 | schaersvoo | 4404 | @ segments color,x1,y1,x2,y2,...,x_n,y_n |
15715 | schaersvoo | 4405 | @ alternative: segs |
14071 | bpr | 4406 | @ draw multiple segments between points (x1:y1)--(x2:y2).....and... (x_n-1:y_n-1)--(x_n:y_n) in color ''color`` |
15318 | bpr | 4407 | @ use command ''linewidth int`` to adjust size |
11806 | schaersvoo | 4408 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!) |
12111 | schaersvoo | 4409 | @%segments_onclick%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%onclick%segments green,1,1,3,3,0,0,-3,3,1,1,4,-1,-5,5,-3,-1 |
4410 | @%segments_drag_y%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%drag y%segments green,1,1,3,3,0,0,-3,3,1,1,4,-1,-5,5,-3,-1 |
||
9213 | schaersvoo | 4411 | */ |
11806 | schaersvoo | 4412 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
4413 | fill_color = stroke_color; |
||
4414 | i=0; |
||
4415 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 4416 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
11806 | schaersvoo | 4417 | if(i%2 == 0 ){ |
4418 | double_data[i] = get_real(infile,0); /* x */ |
||
4419 | } |
||
4420 | else |
||
4421 | { |
||
4422 | double_data[i] = get_real(infile,1); /* y */ |
||
4423 | } |
||
4424 | i++; |
||
4425 | } |
||
15111 | schaersvoo | 4426 | if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);} |
4427 | if(use_affine == TRUE ){ transform(i-1,2);} |
||
4428 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
11806 | schaersvoo | 4429 | decimals = find_number_of_digits(precision); |
4430 | for(c = 0 ; c < i-1 ; c = c+4){ |
||
15111 | schaersvoo | 4431 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[c],decimals,double_data[c+2],decimals,double_data[c+1],decimals,double_data[c+3],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
4432 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
4433 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[c],decimals,double_data[c+2],decimals,double_data[c+1],decimals,double_data[c+3],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
4434 | add_to_buffer(tmp_buffer); |
||
4435 | if(onclick != 0){object_cnt++;} |
||
4436 | /* object_cnt++;*/ |
||
11806 | schaersvoo | 4437 | } |
4438 | reset(); |
||
15111 | schaersvoo | 4439 | dragstuff[4] = 1; |
4440 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
9213 | schaersvoo | 4441 | break; |
11806 | schaersvoo | 4442 | |
4443 | case SETLIMITS: |
||
9213 | schaersvoo | 4444 | /* |
11806 | schaersvoo | 4445 | @ setlimits |
14071 | bpr | 4446 | @ keyword: if set, it will produce 4 inputfields for ''xmin,xmax,ymin,ymax`` and an ''ok`` button |
11806 | schaersvoo | 4447 | @ may be used for inputfield based zooming / panning |
15111 | schaersvoo | 4448 | @ may be styled using command <a href="#css">css</a> |
14071 | bpr | 4449 | @ use commands <a href="#xlabel">xlabel / ylabel</a> to change text from xmin to ''xlabel`` etc |
14247 | bpr | 4450 | @ note: the input value will not be checked on validity |
12107 | schaersvoo | 4451 | @%setlimits%size 400,400%xrange -10,10%yrange -10,10%precision 1%xlabel T%ylabel H%axis%axisnumbering%grid 2,2,grey,2,2,5,grey%precision 100%multistrokecolors red,green,blue,orange%multilinewidth 1,1,2,2%multistrokeopacity 0.6,0.7,0.8,0.9%jsplot red,1/x,-1,x,1/(x-3),1/(x+3)%setlimits |
9213 | schaersvoo | 4452 | */ |
15111 | schaersvoo | 4453 | js_function[JS_SAFE_EVAL] = 1; |
4454 | js_function[JSPLOT_AND_ZOOM] = 1; |
||
4455 | add_setlimits(font_size,css_class); |
||
11806 | schaersvoo | 4456 | done = TRUE; |
9213 | schaersvoo | 4457 | break; |
11806 | schaersvoo | 4458 | |
4459 | case SETPIXEL: |
||
9213 | schaersvoo | 4460 | /* |
11806 | schaersvoo | 4461 | @ setpixel x,y,color |
4462 | @ A rectangular "point" with diameter 1 pixel centered at (x:y) in xrange / yrange |
||
4463 | @ pixels can <b>not</b> be dragged or clicked |
||
14086 | bpr | 4464 | @ "pixelsize = 1" may be changed by command <code>pixelsize int</code> |
12107 | schaersvoo | 4465 | @%setpixel%size 400,400%xrange -10,10%yrange -10,10%setpixel 1,1,red%pixelsize 2%setpixel 2,2,green%pixelsize 3%setpixel 3,3,blue% |
9213 | schaersvoo | 4466 | */ |
15111 | schaersvoo | 4467 | js_function[DRAW_PIXELS] = 1; |
11806 | schaersvoo | 4468 | for(i=0;i<3;i++){ |
4469 | switch(i){ |
||
4470 | case 0: double_data[0] = get_real(infile,0); break; /* x */ |
||
14162 | bpr | 4471 | case 1: double_data[1] = get_real(infile,0); break; /* y */ |
11806 | schaersvoo | 4472 | case 2: stroke_color = get_color(infile,1); |
14208 | schaersvoo | 4473 | string_length = 1 + snprintf(NULL,0,"draw_setpixel([%f],[%f],\"%s\",%.2f,%d);\n",double_data[0],double_data[1],stroke_color,stroke_opacity,pixelsize); |
4474 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11806 | schaersvoo | 4475 | snprintf(tmp_buffer,string_length,"draw_setpixel([%f],[%f],\"%s\",%.2f,%d);\n",double_data[0],double_data[1],stroke_color,stroke_opacity,pixelsize); |
4476 | add_to_buffer(tmp_buffer); |
||
4477 | break; |
||
4478 | default:break; |
||
4479 | } |
||
4480 | } |
||
4481 | reset(); |
||
4482 | break; |
||
4483 | case SLIDER: |
||
9213 | schaersvoo | 4484 | /* |
14071 | bpr | 4485 | @ slider start_value,end_value,width px,height px,type,label |
15655 | schaersvoo | 4486 | @ type may be: ''x,y,angle`` |
4487 | @ if a slider value display is desired, use for argument ''type``: ''x display``, ''y display``, ''angle radian``, ''angle degree`` |
||
15651 | reyssat | 4488 | @ is the slider is used for animation, add keyword ''anim`` or ''animate`` to ''type``; for now only one animated slider may be used... |
4489 | @ default behaviour is: click on an object to use its slider(s)<br/>to use sliders without clicking on an object, use for ''type`` keyword ''active``<br />eg: <code>slider -2*pi,2*pi,300,30,angle degree active,Rotate</code> |
||
14071 | bpr | 4490 | @ if a unit (or something like that...) for x/y-value display is needed, use commands ''xunit`` and / or ''yunit`` |
15655 | schaersvoo | 4491 | @ if the translation should be performed using a function, use for type: ''x function``, ''y function``<br />use commands ''sliderfunction_x`` and/or ''sliderfunction_y`` before the slider command to define the functions. Example:<code>sliderfunction_x x^2<br />sliderfunction_y y^2<br />slider -5,5,100,100,xy function,Some_Text<br />...some stuff to slide<br />killslider<br />sliderfunction_x x^2-2<br />slider -15,15,100,10,x function,Some_Other_Text<br />...more stuff to slide<br />killslider... etc</code> |
14071 | bpr | 4492 | @ use command ''slider`` before draggable/clickable objects. |
15633 | bpr | 4493 | @ drag and drop may be combined with rotation slider<br />for example an arrow rotated by a slider may be placed anywhere (drag&drop)<br /><code>size 300,300<br />xrange -5,5<br />yrange -5,5<br />grid 1,1,grey<br />linewidth 3<br />drag xy<br />fillcolor orange<br />strokecolor blue<br />slider 0,2*pi,250,30,angle degrees,Rotate arrow<br />arrow 2,2,5,5,8,red</code><br />note: except a combination 'drag' and 'slider' for command 'latex, katex, mathml, html, obabel' |
14071 | bpr | 4494 | @ no slider for a math function, these can be traced using command ''trace_jscurve some_function_in_x`` |
4495 | @ a slider will affect all draggable objects after the ''slider`` command...<br />and can be used to group translate / rotate several objects...<br />until a next ''slider`` or keyword ''killslider`` |
||
11806 | schaersvoo | 4496 | @ amount of sliders is not limited. |
14208 | schaersvoo | 4497 | @ a slider can not be set ''snaptogrid`` or other ''snapto*`` : you may always use 'drag xy' in combination with the slider objects |
14071 | bpr | 4498 | @ <code>javascript:read_dragdrop();</code> will return an array with ''object_number:slider_value`` |
11806 | schaersvoo | 4499 | @ every draggable object may have its own slider (no limit in amount of sliders) |
15657 | schaersvoo | 4500 | @ label: some slider text. <br />Note: on <a target='new' href='https://katex.org'>KaTeX</a> enabled wims, TeX produced by wims command ''mathmlmath``, is allowed. |
15111 | schaersvoo | 4501 | @ use fillcolor for slider controlkey |
11806 | schaersvoo | 4502 | @ use strokecolor for slider bar |
4503 | @ use fontfamily / fontcolor to set used fonts |
||
4504 | @ use opacity (only fill opacity will be used) to set transparency |
||
14071 | bpr | 4505 | @ the slider canvas will be added to the ''tooltip div``: so incompatible with command tooltip ; setlimits etc |
15655 | schaersvoo | 4506 | @%slider_x_y_angle%%size 300,300%xrange -5,5%yrange -5,5%grid 1,1,grey%linewidth 3%fillcolor orange%strokecolor blue%slider 0,2*pi,300,30,angle active degrees,Rotate arrow%arrow 0,0,4.5,0,8,red%killslider%opacity 200,100%slider -2,2,300,30,x active,move blue rectangle%frect -4,4,1,-1,blue%killslider%linewidth 2%slider -2,2,300,30,y,move green rectangle%frect -4,4,1,-1,green |
15633 | bpr | 4507 | @%slider_click%%size 300,300%xrange -6,6%yrange -6,6%grid 1,1,grey%linewidth 2%slider 0,2*pi,300,28,angle degree, name%fillcolor lightgreen%#CLICK ON THE OBJECTS TO ACTIVATE%opacity 255,30%ftriangle 2,2,-2,2,0,0,red%ftriangle -2,2,-2,-2,0,0,blue%ftriangle -2,-2,2,-2,0,0,green%ftriangle 2,-2,2,2,0,0,orange%rotationcenter 0,0%frect -2,2,2,-2,black |
4508 | @%slider_active%%size 300,300%xrange -6,6%yrange -6,6%grid 1,1,grey%linewidth 1%slider 0,2*pi,300,28,angle degree active, name%fillcolor lightgreen%opacity 255,30%ftriangle 2,2,-2,2,0,0,red%ftriangle -2,2,-2,-2,0,0,blue%ftriangle -2,-2,2,-2,0,0,green%ftriangle 2,-2,2,2,0,0,orange%rotationcenter 0,0%frect -2,2,2,-2,black |
||
4509 | @%slider_animate%%size 300,300%xrange -6,6%yrange -6,6%grid 1,1,grey%linewidth 1%slider 0,2*pi,300,28,angle anim active, name%fillcolor lightgreen%opacity 255,30%ftriangle 2,2,-2,2,0,0,red%ftriangle -2,2,-2,-2,0,0,blue%ftriangle -2,-2,2,-2,0,0,green%ftriangle 2,-2,2,2,0,0,orange%rotationcenter 0,0%frect -2,2,2,-2,black |
||
15654 | bpr | 4510 | @%slider_html_image%%size 400,400%xrange -6,6%yrange -6,6%bgcolor white%grid 1,1,grey%linewidth 1%slider 0,2*pi,300,28,angle active degree,%centered%html 0,0,<img src="gifs/domains/sciences/flasks.svg" width="100px" height="100px" /> |
9213 | schaersvoo | 4511 | */ |
16832 | bpr | 4512 | js_function[INTERACTIVE] = 1; |
14208 | schaersvoo | 4513 | int_data[2] = 0; /* --> show_display = 0; */ |
11806 | schaersvoo | 4514 | for(i=0; i<6 ; i++){ |
4515 | switch(i){ |
||
4516 | case 0: double_data[0] = get_real(infile,0);break; /* start value */ |
||
4517 | case 1: double_data[1] = get_real(infile,0);break; /* end value */ |
||
4518 | case 2: int_data[0] = (int)(get_real(infile,0));break; /* width */ |
||
4519 | case 3: int_data[1] = (int)(get_real(infile,0));break; /* height */ |
||
15655 | schaersvoo | 4520 | case 4: temp = get_string_argument(infile,0); /* type: x,y,angle */ |
15111 | schaersvoo | 4521 | if( strstr(temp,"displ")!=0 || strstr(temp,"deg")!=0 || strstr(temp,"rad")!=0 ){int_data[5] = 1; }else{int_data[5] = 0;} |
4522 | if(strstr(temp,"anim")!= 0){int_data[3] = 1;}else{int_data[3] = 0;} |
||
4523 | if(strstr(temp,"active")!= 0){onclick = 4;}else{onclick=0;} |
||
14208 | schaersvoo | 4524 | if(strstr(temp,"angle")!= 0){slider_type="R";if( strstr(temp,"rad")!= 0){int_data[2] = 3;}if( strstr(temp,"deg")!= 0){int_data[2] = 4;}} |
11806 | schaersvoo | 4525 | else |
14208 | schaersvoo | 4526 | if(strstr(temp,"xy") != 0){slider_type = "XY";if( strstr(temp,"disp")!= 0){int_data[2] = 5;}} |
11806 | schaersvoo | 4527 | else |
14208 | schaersvoo | 4528 | if(strstr(temp,"x") != 0){slider_type = "X";if( strstr(temp,"disp")!= 0){int_data[2] = 1;}} |
4529 | else |
||
4530 | if(strstr(temp,"y") != 0){slider_type = "Y";if( strstr(temp,"disp")!= 0){int_data[2] = 2;}} |
||
4531 | else |
||
15655 | schaersvoo | 4532 | canvas_error("slider can be of type: x,y,angle,fun_x:fun_y"); |
14208 | schaersvoo | 4533 | break; |
15655 | schaersvoo | 4534 | case 5: temp = get_string_argument(infile,1); if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\""," ");} |
16832 | bpr | 4535 | /* slider label : in case of latex/mathmlmath we need to remove the extra " */ |
15655 | schaersvoo | 4536 | break; |
11806 | schaersvoo | 4537 | } |
4538 | } |
||
15111 | schaersvoo | 4539 | |
4540 | if(use_slider == -1 ){ /* add once */ |
||
4541 | add_slider(int_data[3]); |
||
4542 | if(int_data[5] == 1 ){add_slider_display(precision,font_size,font_color,stroke_opacity);} |
||
14208 | schaersvoo | 4543 | } |
15111 | schaersvoo | 4544 | use_slider++; |
4545 | if(int_data[3] == 0){\ |
||
4546 | string_length = 1 + snprintf(NULL,0,"slider%d = new slider(\"%s\",\"%s\",%d,%d,%d,%d,\"%s\",\"%s\",[%f,%f],%f,%f,'%s',%d);\n",use_slider,slider_type,temp,use_slider,int_data[0],int_data[1],line_width,fill_color,stroke_color,fill_opacity,stroke_opacity,double_data[0],double_data[1],font_family,int_data[2]); |
||
4547 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
4548 | snprintf(tmp_buffer,string_length ,"slider%d = new slider(\"%s\",\"%s\",%d,%d,%d,%d,\"%s\",\"%s\",[%f,%f],%f,%f,'%s',%d);\n",use_slider,slider_type,temp,use_slider,int_data[0],int_data[1],line_width,fill_color,stroke_color,fill_opacity,stroke_opacity,double_data[0],double_data[1],font_family,int_data[2]); |
||
4549 | }else{ |
||
4550 | string_length = 1 + snprintf(NULL,0,"slider%d = new animslider(\"%s\",\"%s\",%d,%d,%d,%d,\"%s\",\"%s\",[%f,%f],%f,%f,'%s',%d);\n",use_slider,slider_type,temp,use_slider,int_data[0],int_data[1],line_width,fill_color,stroke_color,fill_opacity,stroke_opacity,double_data[0],double_data[1],font_family,int_data[2]); |
||
4551 | add_slider(int_data[3]);/* use only once !! */ |
||
4552 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
4553 | snprintf(tmp_buffer,string_length ,"slider%d = new animslider(\"%s\",\"%s\",%d,%d,%d,%d,\"%s\",\"%s\",[%f,%f],%f,%f,'%s',%d);\n",use_slider,slider_type,temp,use_slider,int_data[0],int_data[1],line_width,fill_color,stroke_color,fill_opacity,stroke_opacity,double_data[0],double_data[1],font_family,int_data[2]); |
||
4554 | } |
||
14208 | schaersvoo | 4555 | add_to_buffer(tmp_buffer); |
15111 | schaersvoo | 4556 | fprintf(js_include_file,"var slider%d;",use_slider); |
4557 | use_dragstuff = 2; |
||
4558 | // dragstuff[22] = 1; /* dragstuff switch no 22 is a slider...*/ |
||
4559 | if(onclick != 4 ){ js_function[INTERACTIVE] = 1; }/* no need to click on object to use slider... */ |
||
4560 | //js_function[JS_ROTATE_MOUSE] = 1; |
||
4561 | c = 0; |
||
4562 | for(i=last_slider;i<=use_slider;i++){ |
||
4563 | int_data[c] = i; c++; |
||
4564 | } |
||
4565 | my_sliders = data2js_array(int_data,use_slider - last_slider+1); |
||
14208 | schaersvoo | 4566 | break; |
4567 | |||
14246 | bpr | 4568 | case SLIDER_X: |
15731 | obado | 4569 | /* TEMPORARILY REMOVED |
15732 | obado | 4570 | # sliderfunction_x some_function_in_x |
4571 | # default value "x" |
||
4572 | # the x-value of the slider object will be calculated with this function. |
||
4573 | # default is the x-slider value itself |
||
4574 | # only used by command ''slider`` |
||
4575 | # define before a slider command ! |
||
9213 | schaersvoo | 4576 | */ |
15111 | schaersvoo | 4577 | /* slider_function_x = get_string(infile,1);*/ |
11806 | schaersvoo | 4578 | break; |
4579 | case SLIDER_Y: |
||
15111 | schaersvoo | 4580 | /*slider_function_y = get_string(infile,1);*/ |
15731 | obado | 4581 | /* TEMPORARILY REMOVED |
15732 | obado | 4582 | # sliderfunction_y some_function_in_y |
4583 | # default value "y" |
||
4584 | # the y-value of the slider object(s) will be calculated with this function. |
||
4585 | # only used by command ''slider`` |
||
4586 | # define before a slider command ! |
||
11806 | schaersvoo | 4587 | */ |
4588 | break; |
||
4589 | case SGRAPH: |
||
4590 | /* |
||
4591 | @ sgraph xstart,ystart,xmajor,ymajor,xminor,yminor,majorgrid_color,minorgrid_color |
||
14071 | bpr | 4592 | @ primitive implementation of a ''broken scale`` graph... |
4593 | @ not very versatile: only usable in combination with userdraw <br />eg no other objects will obey this "coordinate system"<br />if you want to place an object into this coordinate system, be aware that 10% or 20% of xsize and/or ysize is ''lost``.<br />Use these "formulas" to recalculate the virtual coordinates:<br />factor=0.8 in case xstart != xmin (or ystart != ymin)<br />factor=0.9 in case xstart = xmin (or ystart = ymin)<br />px_x_point = ((factor*xsize)/(xmax - xstart))*(x_point - xmax)+xsize<br />x_recalculated = px*(xmax - xmin)/xsize + $xmin<br />px_y_point = -1*factor*y_point*ysize/(ymax - ystart) + ymax*factor*ysize/(ymax - ystart)<br />y_recalculated = ymax - py*(ymax - ymin)/ysize<br /> |
||
12111 | schaersvoo | 4594 | @%sgraph%size 400,400%xrange 0,10000%yrange 0,100%sgraph 9000,50,100,10,4,4,grey,blue%userinput_xy%linewidth 2%userdraw segments,red%precision 0%mouse blue,22 |
11806 | schaersvoo | 4595 | */ |
15111 | schaersvoo | 4596 | js_function[DRAW_SGRAPH] = 1; |
11806 | schaersvoo | 4597 | for(i = 0 ; i < 8 ;i++){ |
4598 | switch(i){ |
||
4599 | case 0:double_data[0] = get_real(infile,0);break; |
||
4600 | case 1:double_data[1] = get_real(infile,0);break; |
||
4601 | case 2:double_data[2] = get_real(infile,0);break; |
||
4602 | case 3:double_data[3] = get_real(infile,0);break; |
||
4603 | case 4:int_data[0] = (int)(get_real(infile,0));break; |
||
4604 | case 5:int_data[1] = (int)(get_real(infile,0));break; |
||
4605 | case 6:stroke_color = get_color(infile,0);break; |
||
4606 | case 7:font_color = get_color(infile,1); |
||
14208 | schaersvoo | 4607 | string_length = 1 + snprintf(NULL,0,"xstart = %f;\nystart = %f;\ndraw_sgraph(%d,%d,%f,%f,%d,%d,\"%s\",\"%s\",\"%s\",%f,%d);\n",double_data[0],double_data[1],GRID_CANVAS,precision,double_data[2],double_data[3],int_data[0],int_data[1],stroke_color,font_color,font_family,stroke_opacity,font_size); |
4608 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11806 | schaersvoo | 4609 | snprintf(tmp_buffer,string_length,"xstart = %f;\nystart = %f;\ndraw_sgraph(%d,%d,%f,%f,%d,%d,\"%s\",\"%s\",\"%s\",%f,%d);\n",double_data[0],double_data[1],GRID_CANVAS,precision,double_data[2],double_data[3],int_data[0],int_data[1],stroke_color,font_color,font_family,stroke_opacity,font_size); |
4610 | add_to_buffer(tmp_buffer); |
||
4611 | break; |
||
4612 | default:break; |
||
4613 | } |
||
4614 | } |
||
4615 | /* sgraph(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily,opacity)*/ |
||
9213 | schaersvoo | 4616 | break; |
11806 | schaersvoo | 4617 | case SNAPTOFUNCTION: |
9213 | schaersvoo | 4618 | /* |
11806 | schaersvoo | 4619 | @ snaptofunction some_function_in_x,some_funtion_in_y |
15715 | schaersvoo | 4620 | @ alternative: snaptofun |
11806 | schaersvoo | 4621 | @ the next object will snap to the calculated values |
14071 | bpr | 4622 | @ note: snaptofun is probably not really useful feature... |
14066 | bpr | 4623 | @ if you want only modification of y-values,just use: <code>snaptofunction x,5*sin(1/y)</code> |
4624 | @ if you want only modification of x-values,just use: <code>snaptofunction 5*sin(1/x),y</code> |
||
14071 | bpr | 4625 | @ for now only one instance of ''snaptofunction`` is allowed |
11806 | schaersvoo | 4626 | @ use rawmath on your functions: no validity checking is done by wims ! |
14071 | bpr | 4627 | @ note: switching x and y coordinates? <code>snaptofunction y,x</code> |
13960 | bpr | 4628 | @%snaptofunction_1%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%precision 1%grid 2,2,grey,2,2,5,grey%precision 100%snaptofunction x,5*sin(x)%linewidth 3%crosshairsize 6%userdraw crosshairs,red%linewidth 2%curve blue,5*sin(x)%xunit = x-value%display x,blue,22 |
4629 | @%snaptofunction_2%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%precision 1%grid 2,2,grey,2,2,5,grey%precision 100%snaptofunction y^2-9,y%#snaptofunction y^2-9,abs(y)%linewidth 3%crosshairsize 6%userdraw crosshairs,red%linewidth 2%curve blue,sqrt(x+9)%curve blue,-1*sqrt(x+9)%yunit = y-value%display y,blue,22 |
||
9213 | schaersvoo | 4630 | */ |
11806 | schaersvoo | 4631 | temp = get_string_argument(infile,0); |
14038 | schaersvoo | 4632 | use_snap = 2; |
15111 | schaersvoo | 4633 | use_snap = 5; |
4634 | js_function[JS_MATH] = 1; |
||
11806 | schaersvoo | 4635 | fprintf(js_include_file,"var snap_fun = {x:to_js_math('%s'),y:to_js_math('%s')};function snap_to_fun(px,py){ var x = px2x(px); var y = px2y(py); return [ x2px(eval(snap_fun.x)) , y2px(eval(snap_fun.y)) ];};",temp,get_string(infile,1)); |
4636 | break; |
||
4637 | case SNAPTOPOINTS: |
||
4638 | /* |
||
4639 | @ snaptopoints x1,y1,x2,y2,x3,y3.... |
||
4640 | @ a userdraw object will snap to these points. |
||
14071 | bpr | 4641 | @ the array size (e.g. the number of points) of command ''snaptopoints`` is limited by constant MAX_INT (canvasdraw.h) |
14162 | bpr | 4642 | @ a draggable object (use command ''drag x|y|xy``) will snap to the closed of these points when dragged (mouseup) |
14078 | bpr | 4643 | @ other options: use keyword ''snaptogrid``, ''xsnaptogrid`` or ''ysnaptogrid`` |
13950 | schaersvoo | 4644 | @%snaptopoints%size 400,400%xrange -5,5%yrange -5,5%snaptopoints -1,-3,-1,-2,-1,0,-1,1,-1,2,-1,3,1,-3,1,-2,1,-1,1,0,1,1,1,2,1,3%linewidth 2%points red,-1,-3,-1,-2,-1,0,-1,1,-1,2,-1,3,1,-3,1,-2,1,-1,1,0,1,1,1,2,1,3%userdraw arrows,red |
11806 | schaersvoo | 4645 | */ |
4646 | i = 0; |
||
14038 | schaersvoo | 4647 | use_snap = 4; |
11806 | schaersvoo | 4648 | while( ! done ){ /* get next item until EOL*/ |
11997 | schaersvoo | 4649 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
11806 | schaersvoo | 4650 | if(i%2 == 0 ){ |
4651 | double_data[i] = get_real(infile,0); /* x */ |
||
4652 | } |
||
4653 | else |
||
4654 | { |
||
4655 | double_data[i] = get_real(infile,1); /* y */ |
||
4656 | } |
||
4657 | i++; |
||
4658 | } |
||
4659 | decimals = find_number_of_digits(precision); |
||
14044 | schaersvoo | 4660 | fprintf(js_include_file,"function find_min_diff(x,y,X,Y){var diff = 100000000;var chk;var idx = 0;for(var p = 0 ; p < %d ; p++){chk = distance(x,y,X[p],Y[p]);if( chk < diff ){ diff = chk; idx = p;};};return idx;};function snap_to_points(x,y){x = px2x(x); y = px2y(y);var points = [%s];var xpoints = points[0];var ypoints = points[1];var idx = find_min_diff(x,y,xpoints,ypoints);x = xpoints[idx];y = ypoints[idx];return [x2px(x),y2px(y)];};",(int) (0.5*i),double_xy2js_array(double_data,i,decimals)); |
11806 | schaersvoo | 4661 | break; |
4662 | |||
4663 | case SNAPTOGRID: |
||
4664 | /* |
||
4665 | @ snaptogrid |
||
4666 | @ keyword (no arguments required) |
||
14162 | bpr | 4667 | @ a draggable object (use command ''drag x|y|xy``) will snap to the given grid when dragged (mouseup) |
11806 | schaersvoo | 4668 | @ in case of userdraw the drawn points will snap to xmajor / ymajor grid |
14078 | bpr | 4669 | @ if no grid is defined, points will snap to every integer xrange/yrange value. (eg snap_x=1,snap_y=1) |
14071 | bpr | 4670 | @ if you do not want a visible grid, but you only want a ''snaptogrid`` with some value...define this grid with opacity 0. |
14162 | bpr | 4671 | @ if xminor / yminor is defined,(use keyword ''axis`` to activate the minor steps) the drawing will snap to xminor and yminor<br />use only even dividers in x/y-minor...for example <code>snaptogrid<br />axis<br />grid 2,1,grey,4,4,7,red</code> will snap on x=0, x=0.5, x=1, x=1.5 .... will snap on y=0, y=0.25 y=0.5 y=0.75 ... |
12311 | schaersvoo | 4672 | @%snaptogrid_1%size 400,400%xrange -5,5%yrange -5,5%axis%axisnumbering%precision 1%grid 1,1,grey,2,2,6,grey%linewidth 2%snaptogrid%userdraw crosshairs,blue%mouse red,22 |
4673 | @%snaptogrid_2%size 400,400%xrange -5,5%yrange -5,5%axis%axisnumbering%precision 1%grid 1,1,grey,4,1,6,grey%linewidth 1%snaptogrid%userdraw crosshairs,blue%mouse red,22 |
||
11806 | schaersvoo | 4674 | */ |
14038 | schaersvoo | 4675 | use_snap = 1; |
11806 | schaersvoo | 4676 | break; |
4677 | |||
4678 | case SQUARE: |
||
4679 | /* |
||
14078 | bpr | 4680 | @ square x,y,side (px),color |
15111 | schaersvoo | 4681 | @ draw a square with left top corner (x:y) with side ''side`` in color 'color' |
14071 | bpr | 4682 | @ use command <code>fsquare x,y,side,color</code> for a filled square |
14162 | bpr | 4683 | @ use command/keyword <a href='#filled'>filled</a> before command <code>square x,y,side,color</code> |
11806 | schaersvoo | 4684 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
12107 | schaersvoo | 4685 | @%square%size 400,400%xrange -10,10%yrange -10,10%linewidth 3%filled%fillcolor blue%square 0,0,120,green |
11806 | schaersvoo | 4686 | */ |
11991 | schaersvoo | 4687 | for(i=0;i<4;i++){ |
11806 | schaersvoo | 4688 | switch(i){ |
4689 | case 0:double_data[0] = get_real(infile,0);break; /* x1-values */ |
||
4690 | case 1:double_data[1] = get_real(infile,0);break; /* y1-values */ |
||
11991 | schaersvoo | 4691 | case 2:double_data[2] = get_real(infile,0);break; /* width in px */ |
4692 | case 3:stroke_color = get_color(infile,1);/* name or hex color */ |
||
4693 | decimals = find_number_of_digits(precision); |
||
4694 | double_data[3] = double_data[0] + (xmax - xmin)*double_data[2]/xsize; |
||
4695 | double_data[4] = double_data[1] + -1*(ymax - ymin)*double_data[2]/ysize; |
||
15111 | schaersvoo | 4696 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
4697 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,1,[%.*f,%.*f,%.*f,%.*f],[%.*f,%.*f,%.*f,%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[3],decimals,double_data[3],decimals,double_data[0],decimals,double_data[1],decimals,double_data[1],decimals,double_data[4],decimals,double_data[4],line_width,line_width,line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
4698 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
4699 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,1,[%.*f,%.*f,%.*f,%.*f],[%.*f,%.*f,%.*f,%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[3],decimals,double_data[3],decimals,double_data[0],decimals,double_data[1],decimals,double_data[1],decimals,double_data[4],decimals,double_data[4],line_width,line_width,line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
4700 | add_to_buffer(tmp_buffer); |
||
4701 | if(onclick != 0){object_cnt++;}/* object_cnt++; */ |
||
11991 | schaersvoo | 4702 | reset();break; |
4703 | default: break; |
||
11806 | schaersvoo | 4704 | } |
4705 | } |
||
15111 | schaersvoo | 4706 | dragstuff[1] = 1; |
4707 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
9213 | schaersvoo | 4708 | break; |
13829 | bpr | 4709 | |
11806 | schaersvoo | 4710 | case STATUS: |
9213 | schaersvoo | 4711 | /* |
11806 | schaersvoo | 4712 | @ status |
4713 | @ keyword |
||
14066 | bpr | 4714 | @ alernative: nostatus |
14078 | bpr | 4715 | @ used to override the effects of ''status=done`` in wims (answer.phtml) |
14071 | bpr | 4716 | @ affects ''readonly`` in inputfields / textareas in canvasimage and all userdraw based commands |
4717 | @ e.g.: if keyword ''status`` is set, the pupil will be able to modify the canvas when the ''wims $status variable`` is set to ''done`` |
||
9213 | schaersvoo | 4718 | */ |
11806 | schaersvoo | 4719 | |
4720 | fprintf(js_include_file,"\nwims_status=\"waiting\";\n"); |
||
9213 | schaersvoo | 4721 | break; |
11806 | schaersvoo | 4722 | |
4723 | case STRING: |
||
9213 | schaersvoo | 4724 | /* |
11806 | schaersvoo | 4725 | @ string color,x,y,the text string |
15111 | schaersvoo | 4726 | @ may be set ''onclick`` or ''drag xy`` |
15633 | bpr | 4727 | @ note: when set ''onclick``, use an extra command ''fontsize`` (default: fontsize=12) to adjust the size of the clicked text-string<br />note: a clicked text string will be hardcoded : fontsize+10 in the font family courier |
16706 | schaersvoo | 4728 | @ unicode supported: <code>string red,0,0,\\u2232</code><br/> See <a target='new' href='https://en.wikipedia.org/wiki/Mathematical_operators_and_symbols_in_Unicode'>https://en.wikipedia.org/wiki/Mathematical_operators_and_symbols_in_Unicode</a><br/> See <a target='new' href='https://en.wikipedia.org/wiki/Greek_script_in_Unicode'>https://en.wikipedia.org/wiki/Greek_script_in_Unicode</a> |
15313 | schaersvoo | 4729 | @ use a command like <code>fontfamily italic 24px Arial</code> to set fonts on browser that support font change |
16713 | schaersvoo | 4730 | @ super / sub script is supported, using '<b>_</b>' and '<b>^</b>' <br />The font family for the sub/sup string will be Helvetica e.g. your font family settings will be ignored <br />to end the subscript/supscript, use an extra space...see example: |
16705 | schaersvoo | 4731 | @%string_sup_sub%size 400,400%xrange -6,6%yrange -6,6%fontfamily 22px Arial%# use single space for separation in formula...%# use double space to create new word%string red,-5,0,H_3 O^+ + OH^\\u2212 \\u2192 2H_2 O% |
15313 | schaersvoo | 4732 | @%string%size 400,400%xrange -10,10%yrange -10,10%fontfamily 14px Arial%crosshair -3,-3,red%crosshair 3,3,blue%string red,-3,-3,Hello World%fontfamily Italic 18px Arial%string red,3,3,Hello World%fontfamily 22pt STIX%string black,-10,8,\\u03B1 \\u03B2 \\u03B3 \\u03B4 \\u03B5 \\u03B6 \\u03B7 \\u03B8 \\u03B9 \\u03BA \\u03BB \\u03BC \\u03BD \\u03BE \\u03BF |
9213 | schaersvoo | 4733 | */ |
15111 | schaersvoo | 4734 | if( use_rotate == TRUE ){js_function[JS_ROTATE_MOUSE] = 1; } |
4735 | dragstuff[14] = 1; |
||
4736 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
11806 | schaersvoo | 4737 | for(i=0;i<5;i++){ |
4738 | switch(i){ |
||
4739 | case 0: stroke_color = get_color(infile,0);break;/* name or hex color */ |
||
4740 | case 1: double_data[0] = get_real(infile,0);break; /* x in xrange*/ |
||
4741 | case 2: double_data[1] = get_real(infile,0);break; /* y in yrange*/ |
||
4742 | case 3: decimals = find_number_of_digits(precision); |
||
15111 | schaersvoo | 4743 | if(use_affine == TRUE ){ transform(2,2);} |
4744 | /* rotate is done by HTML5/CANVAS context rotation */ |
||
11806 | schaersvoo | 4745 | temp = get_string_argument(infile,1); |
16700 | schaersvoo | 4746 | if(strstr(temp,"_") != NULL || strstr(temp,"^") != NULL){js_function[DRAW_SUBSUP] = 1;} |
11806 | schaersvoo | 4747 | decimals = find_number_of_digits(precision); |
15111 | schaersvoo | 4748 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
4749 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,14,[%.*f],[%.*f],[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[1],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,0,0,0,use_rotate,angle,temp,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
4750 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
4751 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,14,[%.*f],[%.*f],[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[1],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,0,0,0,use_rotate,angle,temp,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
4752 | add_to_buffer(tmp_buffer); |
||
4753 | if(onclick != 0){object_cnt++;} |
||
15758 | schaersvoo | 4754 | //onclick = 0; |
4755 | //use_offset = 0; |
||
15111 | schaersvoo | 4756 | reset(); |
11806 | schaersvoo | 4757 | break; |
4758 | default:break; |
||
4759 | } |
||
9213 | schaersvoo | 4760 | } |
4761 | break; |
||
11806 | schaersvoo | 4762 | |
4763 | case STRINGUP: |
||
9213 | schaersvoo | 4764 | /* |
11806 | schaersvoo | 4765 | @ stringup color,x,y,rotation_degrees,the text string |
15111 | schaersvoo | 4766 | @ may be set ''onclick`` or ''drag xy`` |
15633 | bpr | 4767 | @ note: when set ''onclick``, use an extra command ''fontsize`` (default: fontsize=12) to adjust the size of the clicked text-string<br />note: a clicked text string will be hardcoded : fontsize+10 in the font family courier |
15111 | schaersvoo | 4768 | @ unicode supported: <code>stringup red,0,0,45,\\u2232</code> |
4769 | @ use a command like <code>fontfamily bold 34px Courier</code> to set fonts on browser that support font change |
||
4770 | @ you could use keyword <a href='#yoffset'>yoffset</a> to -sometimes- do a small correction of text placement under/above a point (e.g. text & point have thesame coordinates) |
||
14634 | bpr | 4771 | @ note: no need to ''killrotate`` after ''stringup``<br /><code>onclick<br />rotate 45<br />string red,0,0,AAAAAA<br/>killrotate<br />string red,4,4,BBBBBB</code><br />is identical with:<br /><code>onclick<br />stringup red,0,0,45,AAAAAA<br />string red,4,4,BBBBBB</code> |
16706 | schaersvoo | 4772 | @ super / sub script is supported, using '<b>_</b>' and '<b>^</b>' <br />to end the subscript/supscript, use an extra space...see example: |
16705 | schaersvoo | 4773 | @%stringup_sub_sup%size 400,400%xrange -6,6%yrange -6,6%fontfamily 22px Arial%# use single space for separation in formula...%# use double space to create new word%stringup red,-5,0,45,H_3 O^+ + OH^\\u2212 \\u2192 2H_2 O% |
15313 | schaersvoo | 4774 | @%stringup%size 400,400%xrange -10,10%yrange -10,10%fontsize 24%fontfamily 14px Arial%crosshair -3,0,red%crosshair 3,0,blue%onclick%stringup red,-3,0,-90,Hello World%drag xy%stringup red,-3,0,-45,Hello World%stringup red,-3,0,45,Hello World%stringup red,-3,0,90,Hello World%stringup blue,3,0,-90,Hello World%stringup blue,3,0,-45,Hello World%stringup blue,3,0,45,Hello World%stringup blue,3,0,90,Hello World |
11806 | schaersvoo | 4775 | |
14634 | bpr | 4776 | */ |
15111 | schaersvoo | 4777 | /* html5 canvas rotation is only used for text objects */ |
4778 | use_rotate = TRUE ; |
||
4779 | dragstuff[14] = 1; |
||
4780 | js_function[JS_ROTATE_MOUSE] = 1; |
||
4781 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
15116 | bpr | 4782 | |
15111 | schaersvoo | 4783 | for(i=0;i<6;i++){ |
11806 | schaersvoo | 4784 | switch(i){ |
14596 | schaersvoo | 4785 | case 0: stroke_color = get_color(infile,0);break;/* name or hex color */ |
4786 | case 1: double_data[0] = get_real(infile,0);break; /* x */ |
||
4787 | case 2: double_data[1] = get_real(infile,0);break; /* y */ |
||
15111 | schaersvoo | 4788 | case 3: angle = get_real(infile,0);break;/* rotation */ |
11806 | schaersvoo | 4789 | case 4: decimals = find_number_of_digits(precision); |
14596 | schaersvoo | 4790 | temp = get_string_argument(infile,1); |
16700 | schaersvoo | 4791 | if(strstr(temp,"_") != NULL || strstr(temp,"^") != NULL){js_function[DRAW_SUBSUP] = 1;} |
14596 | schaersvoo | 4792 | decimals = find_number_of_digits(precision); |
15111 | schaersvoo | 4793 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
4794 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,14,[%.*f],[%.*f],[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[1],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,0,0,0,use_rotate,angle,temp,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
4795 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
4796 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,14,[%.*f],[%.*f],[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[1],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,0,0,0,use_rotate,angle,temp,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
4797 | add_to_buffer(tmp_buffer); |
||
4798 | if(onclick != 0){object_cnt++;} |
||
15758 | schaersvoo | 4799 | //onclick = 0; |
4800 | //use_offset = 0; |
||
14596 | schaersvoo | 4801 | reset(); |
4802 | break; |
||
11806 | schaersvoo | 4803 | default:break; |
4804 | } |
||
9213 | schaersvoo | 4805 | } |
14596 | schaersvoo | 4806 | use_rotate = FALSE; |
9213 | schaersvoo | 4807 | break; |
11767 | schaersvoo | 4808 | |
11806 | schaersvoo | 4809 | case STYLE: |
11767 | schaersvoo | 4810 | /* |
11806 | schaersvoo | 4811 | @ highlight color,opacity,linewidth |
4812 | @ NOT IMPLEMENTED |
||
14071 | bpr | 4813 | @ use command ''onclick``: when the object receives a userclick it will increase its linewidth |
11767 | schaersvoo | 4814 | */ |
4815 | break; |
||
11806 | schaersvoo | 4816 | |
4817 | |||
4818 | case STROKECOLOR: |
||
9213 | schaersvoo | 4819 | /* |
11806 | schaersvoo | 4820 | @ strokecolor colorname or #hex |
14071 | bpr | 4821 | @ to be used for commands that do not supply a color argument (like command ''linegraph``) |
9213 | schaersvoo | 4822 | */ |
11806 | schaersvoo | 4823 | stroke_color = get_color(infile,1); |
9213 | schaersvoo | 4824 | break; |
11806 | schaersvoo | 4825 | |
4826 | case FLY_TEXT: |
||
9213 | schaersvoo | 4827 | /* |
11806 | schaersvoo | 4828 | @ text fontcolor,x,y,font,text_string |
14066 | bpr | 4829 | @ font may be described by keywords: giant,huge,normal,small,tiny |
15111 | schaersvoo | 4830 | @ use command ''fontsize`` to increase base fontsize for these keywords |
4831 | @ may be set ''onclick`` or ''drag xy`` |
||
11806 | schaersvoo | 4832 | @ backwards compatible with flydraw |
4833 | @ unicode supported: text red,0,0,huge,\\u2232 |
||
16700 | schaersvoo | 4834 | @ special: use '_' and '^' to imitate html sup/sub, like H_3O^+ + OH^\\u22i2 \\u2192 2H_2 O |
16706 | schaersvoo | 4835 | @ much better to use command <a href='#string'>string</a> combined with <a href='#fontfamily'>fontfamily</a> for a more fine grained control over html5 canvas text element |
4836 | @ super / sub script is supported, using '<b>_</b>' and '<b>^</b>' <br />to end the subscript/supscript, use an extra space...see <a href='#string'>string </a> command |
||
15313 | schaersvoo | 4837 | @ Avoid mixing old flydraw commands ''text``, ''textup`` with new canvasdraw commands ''string``, ''stringup``. If the fontfamily was set completely like <code>fontfamily italic 24px Arial</code>. In that case reset ''fontfamily`` to something lke ''fontfamily Arial`` before the old flydraw commands. |
12311 | schaersvoo | 4838 | @%text%size 400,400%xrange -10,10%yrange -10,10%fontsize 14%onclick%drag xy%text green,-4,-4,small,Hello World%drag xy%text red,-4,-2,large,Hello World%drag xy%text blue,-4,0,huge,Hello World%drag xy%text green,-4,3,giant,Hello World%drag xy |
9213 | schaersvoo | 4839 | */ |
11806 | schaersvoo | 4840 | for(i = 0; i < 5 ;i++){ |
4841 | switch(i){ |
||
4842 | case 0: stroke_color = get_color(infile,0);break;/* font_color == stroke_color name or hex color */ |
||
4843 | case 1: double_data[0] = get_real(infile,0);break; /* x */ |
||
4844 | case 2: double_data[1] = get_real(infile,0);break; /* y */ |
||
4845 | case 3: fly_font = get_string_argument(infile,0); |
||
4846 | if(strcmp(fly_font,"giant") == 0){ |
||
4847 | fly_font_size = (int)(font_size + 24); |
||
4848 | } |
||
4849 | else |
||
4850 | { |
||
4851 | if(strcmp(fly_font,"huge") == 0){ |
||
4852 | fly_font_size = (int)(font_size + 14); |
||
4853 | } |
||
4854 | else |
||
4855 | { |
||
4856 | if(strcmp(fly_font,"large") == 0){ |
||
4857 | fly_font_size = (int)(font_size + 6); |
||
4858 | } |
||
4859 | else |
||
4860 | { |
||
4861 | if(strcmp(fly_font,"small") == 0){ |
||
4862 | fly_font_size = (int)(font_size - 4); |
||
4863 | if(fly_font_size<0){fly_font_size = 8;} |
||
4864 | } |
||
4865 | } |
||
4866 | } |
||
4867 | } |
||
4868 | break; |
||
4869 | case 4: |
||
4870 | temp = get_string_argument(infile,1); |
||
16700 | schaersvoo | 4871 | if(strstr(temp,"_") != NULL || strstr(temp,"^") != NULL){js_function[DRAW_SUBSUP] = 1;} |
11806 | schaersvoo | 4872 | decimals = find_number_of_digits(precision); |
15111 | schaersvoo | 4873 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
15646 | schaersvoo | 4874 | if(use_affine == TRUE ){ transform(2,2);} |
15111 | schaersvoo | 4875 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,14,[%.*f],[%.*f],[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%f,\"%s\",%d,%s,%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[1],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,0,0,0,use_rotate,angle,temp,fly_font_size,"null",my_sliders,rotation_center,use_offset); |
4876 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
4877 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,14,[%.*f],[%.*f],[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%f,\"%s\",%d,%s,%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[1],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,0,0,0,use_rotate,angle,temp,fly_font_size,"null",my_sliders,rotation_center,use_offset); |
||
4878 | add_to_buffer(tmp_buffer); |
||
4879 | if(onclick != 0){object_cnt++;} |
||
11806 | schaersvoo | 4880 | reset(); |
4881 | break; |
||
4882 | default:break; |
||
4883 | } |
||
10953 | bpr | 4884 | } |
15111 | schaersvoo | 4885 | dragstuff[14] = 1; |
4886 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
9213 | schaersvoo | 4887 | break; |
11806 | schaersvoo | 4888 | case TEXTAREA: |
9289 | schaersvoo | 4889 | /* |
11806 | schaersvoo | 4890 | @ textarea x,y,cols,rows,readonly,value |
15111 | schaersvoo | 4891 | @ may be further controlled by <a href="#css">css</a> |
14162 | bpr | 4892 | @ if ''$status=done`` (e.g. in answer.phtml) the inputfield will be cleared and set readonly. Override this by keyword <a href="#status">status</a>. |
14066 | bpr | 4893 | @ if mathml inputfields are present and / or some userdraw is performed, these data will <b>not</b> be send as well (<code>javascript:read_canvas();</code>) |
14071 | bpr | 4894 | @ keyword ''xoffset | centered`` is not active for command ''textarea`` |
15111 | schaersvoo | 4895 | @%textarea%size 400,400%xrange -10,10%yrange -10,10%css color:red;background-color:lightblue;font-size:14px;text-align:center%textarea -3,-2,6,3,1,?%css color:blue;background-color:yellow;font-size:14px;text-align:center%textarea 0,-2,8,2,1,? |
9289 | schaersvoo | 4896 | */ |
15111 | schaersvoo | 4897 | js_function[DRAW_TEXTAREAS] = 1; |
11806 | schaersvoo | 4898 | for(i = 0 ; i<6;i++){ |
9289 | schaersvoo | 4899 | switch(i){ |
11806 | schaersvoo | 4900 | case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in px */ |
4901 | case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in px */ |
||
4902 | case 2: int_data[2]=abs( (int)(get_real(infile,0)));break;/* cols */ |
||
4903 | case 3: int_data[3]=abs( (int)(get_real(infile,0)));break;/* rows */ |
||
4904 | case 4: if( get_real(infile,1) >0){int_data[4] = 1;}else{int_data[3] = 0;};break; /* readonly */ |
||
4905 | case 5: temp = get_string_argument(infile,1); |
||
15111 | schaersvoo | 4906 | string_length = 1 + snprintf(NULL,0, "draw_textareas(%d,%d,%d,%d,%d,%d,%d,\"%s\",\"%s\");\n",canvas_root_id,input_cnt,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],css_class,temp); |
14208 | schaersvoo | 4907 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
15111 | schaersvoo | 4908 | snprintf(tmp_buffer,string_length,"draw_textareas(%d,%d,%d,%d,%d,%d,%d,\"%s\",\"%s\");\n",canvas_root_id,input_cnt,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],css_class,temp); |
11806 | schaersvoo | 4909 | add_to_buffer(tmp_buffer); |
4910 | input_cnt++;break; |
||
9289 | schaersvoo | 4911 | default: break; |
4912 | } |
||
4913 | } |
||
11806 | schaersvoo | 4914 | if(reply_format == 0 ){reply_format = 15;} |
4915 | reset(); |
||
9289 | schaersvoo | 4916 | break; |
11806 | schaersvoo | 4917 | |
11830 | schaersvoo | 4918 | case TEXTFILL: |
4919 | /* |
||
4920 | @ textfill x0,y0,color,some_text |
||
4921 | @ x0,y0 in xrange / yrange |
||
4922 | @ color will be used for the font color |
||
4923 | @ use command <a href="#fontfamily">fontfamily</a> to set font type and size |
||
13829 | bpr | 4924 | @ there is also a command <a href="#userdraw">userdraw textfill,color,some_text</a> |
15313 | schaersvoo | 4925 | @%textfill%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%fontfamily 24pt Arial%circles red,0,0,3,3,3,6%textfill 4,4,blue,HELLO WORLD |
11830 | schaersvoo | 4926 | */ |
4927 | |||
4928 | js_function[DRAW_TEXTFILL] = 1; |
||
4929 | if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */ |
||
4930 | js_function[DRAW_FILLTOBORDER] = 1; |
||
15111 | schaersvoo | 4931 | add_js_filltoborder(canvas_type); |
11830 | schaersvoo | 4932 | } |
4933 | decimals = find_number_of_digits(precision); |
||
4934 | for(i=0;i<4;i++){ |
||
4935 | switch(i){ |
||
4936 | case 0: double_data[0] = get_real(infile,0); break; /* x in px */ |
||
4937 | case 1: double_data[1] = get_real(infile,0); break; /* y in py */ |
||
13829 | bpr | 4938 | case 2: font_color = get_color(infile,0); break; |
11830 | schaersvoo | 4939 | case 3: temp = get_string(infile,1); |
14208 | schaersvoo | 4940 | string_length = 1 + snprintf(NULL,0,"draw_textfill(%d,%*.f,%*.f,'%s','%s',%d,%d,'%s',false); ",FILL_CANVAS+fill_cnt,decimals,double_data[0],decimals,double_data[1],font_color,font_family,xsize,ysize,temp); |
4941 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11830 | schaersvoo | 4942 | snprintf(tmp_buffer,string_length,"draw_textfill(%d,%*.f,%*.f,'%s','%s',%d,%d,'%s',false); ",FILL_CANVAS+fill_cnt,decimals,double_data[0],decimals,double_data[1],font_color,font_family,xsize,ysize,temp); |
4943 | add_to_buffer(tmp_buffer); |
||
4944 | fill_cnt++; |
||
4945 | break; |
||
4946 | default:break; |
||
4947 | } |
||
4948 | } |
||
4949 | reset(); |
||
4950 | break; |
||
4951 | |||
4952 | |||
11806 | schaersvoo | 4953 | case FLY_TEXTUP: |
9289 | schaersvoo | 4954 | /* |
11806 | schaersvoo | 4955 | @ textup fontcolor,x,y,font,text_string |
14078 | bpr | 4956 | @ can <b>not</b> be set ''onclick`` or ''drag xy`` (because of translaton matrix...mouse incompatible) |
14066 | bpr | 4957 | @ font may be described by keywords: giant,huge,normal,small,tiny |
14071 | bpr | 4958 | @ use command ''fontsize`` to increase base fontsize for the keywords |
11806 | schaersvoo | 4959 | @ backwards compatible with flydraw |
4960 | @ unicode supported: textup red,0,0,huge,\\u2232 |
||
14071 | bpr | 4961 | @ use command ''stringup`` and ''fontfamily`` for a more fine grained control over html5 canvas text element |
15313 | schaersvoo | 4962 | @ Avoid mixing old flydraw commands ''text``, ''textup`` with new canvasdraw commands ''string``; ''stringup``. If the fontfamily was set completely like <code>fontfamily italic 24px Arial</code>. In that case reset ''fontfamily`` to something like ''fontfamily Arial`` before the old flydraw commands. |
9289 | schaersvoo | 4963 | */ |
15111 | schaersvoo | 4964 | js_function[DRAW_TEXTS] = 1; |
11806 | schaersvoo | 4965 | for(i = 0; i<5 ;i++){ |
9289 | schaersvoo | 4966 | switch(i){ |
11806 | schaersvoo | 4967 | case 0: font_color = get_color(infile,0);break;/* name or hex color */ |
4968 | case 1: int_data[0] = x2px(get_real(infile,0));break; /* x */ |
||
4969 | case 2: int_data[1] = y2px(get_real(infile,0));break; /* y */ |
||
4970 | case 3: fly_font = get_string_argument(infile,0); |
||
4971 | if(strcmp(fly_font,"giant") == 0){ |
||
4972 | fly_font_size = (int)(font_size + 24); |
||
4973 | } |
||
4974 | else |
||
4975 | { |
||
4976 | if(strcmp(fly_font,"huge") == 0){ |
||
4977 | fly_font_size = (int)(font_size + 14); |
||
4978 | } |
||
4979 | else |
||
4980 | { |
||
4981 | if(strcmp(fly_font,"large") == 0){ |
||
4982 | fly_font_size = (int)(font_size + 6); |
||
4983 | } |
||
4984 | else |
||
4985 | { |
||
4986 | if(strcmp(fly_font,"small") == 0){ |
||
4987 | fly_font_size = (int)(font_size - 4); |
||
4988 | if(fly_font_size<0){fly_font_size = 8;} |
||
4989 | } |
||
4990 | } |
||
4991 | } |
||
4992 | } |
||
4993 | break; |
||
4994 | case 4: |
||
9289 | schaersvoo | 4995 | decimals = find_number_of_digits(precision); |
11806 | schaersvoo | 4996 | temp = get_string_argument(infile,1); |
15111 | schaersvoo | 4997 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
4998 | string_length = 1 + snprintf(NULL,0,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,90,\"%s\",%d,%.2f,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],fly_font_size,"null",font_color,stroke_opacity,temp,use_rotate,angle,use_offset); |
||
14208 | schaersvoo | 4999 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
15111 | schaersvoo | 5000 | snprintf(tmp_buffer,string_length,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,90,\"%s\",%d,%.2f,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],fly_font_size,"null",font_color,stroke_opacity,temp,use_rotate,angle,use_offset); |
9289 | schaersvoo | 5001 | add_to_buffer(tmp_buffer); |
15758 | schaersvoo | 5002 | reset(); |
5003 | //use_offset = 0; |
||
9289 | schaersvoo | 5004 | break; |
11806 | schaersvoo | 5005 | default:break; |
5006 | } |
||
5007 | } |
||
5008 | break; |
||
5009 | |||
5010 | |||
5011 | case TRACE_JSCURVE: |
||
5012 | /* |
||
5013 | @ trace_jscurve some_math_function |
||
5014 | @ will use a crosshair to trace the jsmath curve |
||
5015 | @ two inputfields will display the current x/y-values (numerical evaluation by javascript) |
||
14071 | bpr | 5016 | @ default labels ''x`` and ''y``; use commands ''xlabel some_x_axis_name`` and ''ylabel some_y_axis_name`` to customize the labels for the input fields |
15111 | schaersvoo | 5017 | @ use commands fontsize and css to format the fonts for labels and inputfields. |
14071 | bpr | 5018 | @ use commands ''linewidth, strokecolor, crosshairsize`` to adjust the corsshair. |
5019 | @ the client browser will convert your math function to javascript math.<br />use parenthesis and rawmath: use 2*x instead of 2x etc etc no check is done on the validity of your function and/or syntax (use error console to debug any errors...) |
||
5020 | @ be aware that the formulas of the plotted function(s) can be found in the page javascript source |
||
15111 | schaersvoo | 5021 | @%trace_jscurve%size 400,400%xrange -10,10%yrange -10,10%precision 0%axis%axisnumbering%grid 2,2,grey,2,2,5,gray%recision 100%css color:blue;%linewidth 4%crosshairsize 8%trace_jscurve 5*sin(0.1*x^2)%linewidth 1%jsplot red,5*sin(0.1*x^2)%#only one curve can be traced |
11806 | schaersvoo | 5022 | */ |
15111 | schaersvoo | 5023 | js_function[INTERACTIVE] = 1; |
5024 | js_function[DRAW_CROSSHAIRS] = 1; |
||
5025 | js_function[DRAW_LINES] = 1; |
||
5026 | js_function[JS_MATH] = 1; |
||
5027 | add_trace_js_mouse(TRACE_CANVAS,stroke_color,get_string(infile,1),font_size,stroke_opacity,line_width,crosshair_size,css_class); |
||
11806 | schaersvoo | 5028 | break; |
5029 | |||
5030 | |||
5031 | case TRANGE: |
||
5032 | /* |
||
5033 | @ trange tmin,tmax |
||
15715 | schaersvoo | 5034 | @ alternative: ranget |
11806 | schaersvoo | 5035 | @ default -2,2 |
5036 | */ |
||
5037 | use_parametric = TRUE; |
||
5038 | for(i = 0 ; i<2; i++){ |
||
5039 | switch(i){ |
||
5040 | case 0: tmin = get_real(infile,0);break; |
||
5041 | case 1: tmax = get_real(infile,1);break; |
||
9289 | schaersvoo | 5042 | default: break; |
5043 | } |
||
5044 | } |
||
14066 | bpr | 5045 | if(tmin >= tmax ){canvas_error(" trange is not OK: tmin < tmax!\n");} |
9289 | schaersvoo | 5046 | break; |
11806 | schaersvoo | 5047 | case TRANSLATION: |
5048 | /* |
||
5049 | @ translation tx,ty |
||
15715 | schaersvoo | 5050 | @ alternative: translate |
11806 | schaersvoo | 5051 | @ will translate the next objects tx in xrange and ty in yrange |
14071 | bpr | 5052 | @ use command ''killtranstation`` to end the command |
13958 | schaersvoo | 5053 | @%translation%size 400,400%xrange -10,10%yrange -10,10%linewidth 1%fillpattern grid%ftriangle -6,6,8,6,5,1,blue%translation 2,2%ftriangle -6,6,8,6,5,1,red |
11806 | schaersvoo | 5054 | */ |
5055 | for(i = 0 ; i<2;i++){ |
||
5056 | switch(i){ |
||
15111 | schaersvoo | 5057 | case 0: affine_matrix[4] = get_real(infile,0);break; |
5058 | case 1: affine_matrix[5] = get_real(infile,1); |
||
11806 | schaersvoo | 5059 | use_affine = TRUE; |
15111 | schaersvoo | 5060 | /* the other values affine_matrix[0..3] remain untouched*/ |
11806 | schaersvoo | 5061 | break; |
5062 | default: break; |
||
5063 | } |
||
5064 | } |
||
5065 | break; |
||
5066 | |||
5067 | case TRIANGLE: |
||
5068 | /* |
||
5069 | @ triangle x1,y1,x2,y2,x3,y3,color |
||
14066 | bpr | 5070 | @ use ftriangle or keyword <a href='#filled'>filled</a> for a solid triangle |
11806 | schaersvoo | 5071 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
13948 | schaersvoo | 5072 | @%triangle%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%opacity 250,150%drag xy%triangle 0,0,-4,4,6,8,red%drag xy%ftriangle 0,0,-4,-4,6,-8,red%fillpattern grid%drag xy%ftriangle -6,6,8,6,5,1,blue |
11806 | schaersvoo | 5073 | */ |
5074 | for(i=0;i<7;i++){ |
||
5075 | switch(i){ |
||
5076 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
5077 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
5078 | case 2: double_data[2] = get_real(infile,0);break; /* x */ |
||
5079 | case 3: double_data[3] = get_real(infile,0);break; /* y */ |
||
5080 | case 4: double_data[4] = get_real(infile,0);break; /* x */ |
||
5081 | case 5: double_data[5] = get_real(infile,0);break; /* y */ |
||
5082 | case 6: stroke_color = get_color(infile,1);/* name or hex color */ |
||
5083 | decimals = find_number_of_digits(precision); |
||
15111 | schaersvoo | 5084 | if( use_rotate == TRUE ){ rotate(6,angle,rotationcenter,2);} |
5085 | if( use_affine == TRUE ){ transform(6,2);} |
||
5086 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
||
5087 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,5,%s,[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,double_xy2js_array(double_data,6,decimals),line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
5088 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
5089 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,5,%s,[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,double_xy2js_array(double_data,6,decimals),line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
5090 | add_to_buffer(tmp_buffer); |
||
5091 | if(onclick != 0){object_cnt++;} |
||
5092 | /* object_cnt++;*/ |
||
11806 | schaersvoo | 5093 | reset(); |
5094 | break; |
||
5095 | default: break; |
||
5096 | } |
||
5097 | } |
||
15111 | schaersvoo | 5098 | dragstuff[5] = 1; |
5099 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
11806 | schaersvoo | 5100 | break; |
5101 | case TRIANGLES: |
||
5102 | /* |
||
5103 | @ triangles color,x1,y1,x2,y2,x3,y3,... |
||
14066 | bpr | 5104 | @ use ftriangles or keyword <a href='#filled'>filled</a> for solid triangles |
11806 | schaersvoo | 5105 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!) |
13948 | schaersvoo | 5106 | @%triangles%size 400,400%xrange -10,10%yrange -10,10%linewidth 3%onclick%triangles red,0,0,-4,4,6,8,0,0,-4,-4,6,-8,-6,6,8,6,5,1%# the same as 3 calls to command triangle |
11806 | schaersvoo | 5107 | */ |
5108 | stroke_color = get_color(infile,0);/* name or hex color */ |
||
5109 | i = 0; |
||
5110 | decimals = find_number_of_digits(precision); |
||
15111 | schaersvoo | 5111 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
15116 | bpr | 5112 | |
11806 | schaersvoo | 5113 | while( ! done ){ |
11997 | schaersvoo | 5114 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
11806 | schaersvoo | 5115 | double_data[0] = get_real(infile,0); /* x1 */ |
5116 | double_data[1] = get_real(infile,0); /* y1 */ |
||
5117 | double_data[2] = get_real(infile,0); /* x2 */ |
||
5118 | double_data[3] = get_real(infile,0); /* y2 */ |
||
5119 | double_data[4] = get_real(infile,0); /* x3 */ |
||
5120 | double_data[5] = get_real(infile,1); /* y3 */ |
||
15111 | schaersvoo | 5121 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,5,%s,[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,double_xy2js_array(double_data,6,decimals),line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
5122 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
5123 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,5,%s,[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,double_xy2js_array(double_data,6,decimals),line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
5124 | add_to_buffer(tmp_buffer); |
||
5125 | if(onclick != 0){object_cnt++;} |
||
11806 | schaersvoo | 5126 | i = i + 6; |
5127 | } |
||
5128 | reset(); |
||
15111 | schaersvoo | 5129 | dragstuff[5] = 1; |
5130 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
11806 | schaersvoo | 5131 | break; |
5132 | case USERBOXPLOT: |
||
5133 | /* |
||
5134 | @ userboxplot |
||
5135 | @ keyword, no arguments |
||
14066 | bpr | 5136 | @ use before command <a href="#boxplot">boxplot x_or_y,box-height_or_box-width,x_or_y-position</a> |
14071 | bpr | 5137 | @ if set, the student will have to calculate "min,Q1,median,Q3,max" and feed these data into the ''draw_boxplot`` function |
5138 | @ for example: put the canvas-script into a html element with id='boxplot' and set style='display:none'<br />define a variable called ''student_boxplot`` and fill it with the 5 student-data (from inputfields or something)<br /><code>var student_boxplot = new Array(5)<br />function show_boxplot(){<br />student_boxplot[0] = min;<br />student_boxplot[1] = Q1;<br />student_boxplot[2] = median;<br />student_boxplot[3] = Q3;<br />student_boxplot[4] = max;<br />document.getElementById('boxplot').style.display = "block";<br />draw_boxplot(12345,1,2.00,5.00,[0,0,0,0,0],4,"0,0,255",0.78,"255,165,0",0.60,1,0,1,1);<br />};</code><br />In the canvas-script the function draw_boxplot has the following arguments:<br />draw_boxplot=function(canvas_type,xy,hw,cxy,data,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype0,dashtype1) |
||
11806 | schaersvoo | 5139 | */ |
15111 | schaersvoo | 5140 | js_function[DRAW_BOXPLOT] = 1; |
11806 | schaersvoo | 5141 | fprintf(js_include_file,"var boxplot_source = 3;\n"); |
5142 | js_function[DRAW_JSBOXPLOT] = 2; |
||
5143 | break; |
||
5144 | |||
5145 | case USERBOXPLOTDATA: |
||
5146 | /* |
||
5147 | @ userboxplotdata |
||
5148 | @ keyword, no arguments |
||
14066 | bpr | 5149 | @ use before command <a href="#boxplot">boxplot x_or_y,box-height_or_box-width,x_or_y-position</a> |
14071 | bpr | 5150 | @ if set, the student will have to generate some statistical data. These data should be put in a named array ''student_boxplot_data`` |
15111 | schaersvoo | 5151 | @ ''min,Q1,median,Q3,max`` are calculated by a js-function and the 'draw_boxplot' function will draw a boxplot. |
14066 | bpr | 5152 | @ see command <a href="#userboxplot">userboxplot</a> for calling 'draw_boxplot()' |
11806 | schaersvoo | 5153 | */ |
15111 | schaersvoo | 5154 | js_function[DRAW_BOXPLOT] = 1; |
11806 | schaersvoo | 5155 | fprintf(js_include_file,"var boxplot_source = 2;\n"); |
5156 | js_function[DRAW_JSBOXPLOT] = 1; |
||
5157 | |||
5158 | break; |
||
5159 | |||
7614 | schaersvoo | 5160 | case USERDRAW: |
5161 | /* |
||
5162 | @ userdraw object_type,color |
||
9213 | schaersvoo | 5163 | @ only a single object_type is allowed. |
15111 | schaersvoo | 5164 | @ right mouse click will remove last drawn object. |
5165 | @ for multiple different 'userdraw' objects in an exercise, use command <a href="#multidraw">multidraw</a> |
||
5166 | @ implemented object_type: <ul><li>point</li><li>points</li><li>crosshair</li><li>crosshairs</li><li>line</li><li>lines</li><li>vline</li><li>vlines</li><li>hline</li><li>hlines</li><li>demiline</li><li>demilines</li><li>segment</li><li>segments</li><li>polyline | brokenline</li><li>circle</li><li>circles</li><li>arrow</li><li>arrow2 (double arrow)</li><li>arrows</li><li>arrows2 (double arrows)</li><li>curvedarrow</li><li>curvedarrows</li><li>curvedarrow2</li><li>curvedarrows2</li><li>triangle</li><li>polygon</li><li>poly[3-9] (e.g poly3 ... poly7...poly9</li><li>rect</li><li>roundrect</li><li>rects</li><li>roundrects</li><li>freehandline | path</li><li>freehandlines | paths</li><li>clickfill: fill the clicked area with color<br />multiple areas may be selected <br />multiple colors may be provided using commands <a href='#colorpalette'>colorpalette color1,color2,color3,...</a> use <a href='#replyformat'>replyformat 10</a> for checking the user click color ... reply=x1:y1:color1,x2:y2:color2...<br/>attention: this will <b>not</b> work for pattern filling, because the pattern image is only generated once and after creation can not be changed !<br />the opacity of this image on a separate canvas is set to 0.01 and not 0 (!!)...in the ''fill algorithm`` the opacity of the matching pixels is set to 1</li><li>dotfill: fill the clicked area with a dot pattern; use command linewidth to change dot size</li><li>diamondfill: fill the clicked area with a diamond pattern</li><li>hatchfill: fill the clicked area with a hatch pattern</li><li>gridfill: fill the clicked area with a grid pattern</li><li>textfill: fill the clicked area with a repeating string<br />userdraw textfill,blue,some_text<br />use command <a href="#fontfamily">fontfamily</a> to adjust text style and size</li><li>''clickfill | pattern filling`` in general:<br />the clicks may be set <a href="#snaptogrid">snaptogrid</a><br />can be used together with command <a href="#floodfill">floodfill or fill</a><br /><b>always</b> use together with command <a href="#clearbutton">clearbutton some_text</a> for removal of all click_colored areas<br />the function read_canvas() will return the click coordinates in the sequence of the user clicks<br />use command <a href="#canvastype">canvastype</a> to fill another canvas (default should be fine: DRAG_CANVAS = 5)</li><li>text <br />an inputfield is provided, unicode allowed. The text is drawn a the mouse click, or if used with command ''userinput inputfield`` also at the given x/y-coordonates</li><li>arc</li><li>arcs</li><li>image<br/>only a single "image" of every supported type(*) may be added to canvas window from the surrounding html page.<br />the image should have an 'id' and an onclick handler.<br />(*) supported types are ''svg``,''bitmap``,''p-element``,''div-element`` and ''mathml/tex-code`` with ''\\mmlid{int}``.</li><li>images</li><li>input<br/>place a single inputfield on ''canvas`` <br />use commands 'css' for css styling: use command ''linewidth`` for adjusting the input field size (default 1)</li><li>inputs<br/>place multiple inputfield: placing inputfields on top of each other is not possible</li><li>function : identical to <a href="#userinput">userinput function</a></li></ul> |
||
14078 | bpr | 5167 | @ note: mouselisteners are only active if ''$status != done`` (eg only drawing in an active/non-finished exercise) <br /> to overrule use command/keyword ''status`` (no arguments required) |
15111 | schaersvoo | 5168 | @ note: object_type text: Any string or multiple strings may be placed anywhere on the canvas.<br />Use command ''fontfamily`` to set font |
11088 | schaersvoo | 5169 | @ note: object_type polygone: Will be finished (the object is closed) when clicked on the first point of the polygone again. |
15111 | schaersvoo | 5170 | @ note: all objects will be removed -after a javascript confirm box- when clicked on an object point with middle or right mouse button (e.g. event.button != 1: all buttons but left) |
5171 | @ use a prefix <a href='#filled'>filled</a> or ''f`` to set fillable objects filled. (fcircles,filledcircles etc)<br/> in case of ''fillpattern`` do not use the ''f`` prefix ! |
||
11839 | schaersvoo | 5172 | @ for non solid filling, use command <a href="#fillpattern">fillpattern grid,hatch,diamond,dot</a> |
14071 | bpr | 5173 | @ use <a href='#opacity'>opacity int,int</a> and <a href='#fillcolor'>fillcolor color</a> to trigger coloured filling of fillable objects |
14078 | bpr | 5174 | @ use command ''dashed`` and/or ''dashtype int,int`` to trigger dashing |
5175 | @ use command ''replyformat int`` to control / adjust output formatting of javascript function read_canvas(); (the defaults should be fine...) |
||
14071 | bpr | 5176 | @ may be combined with onclick or drag xy of other components of flyscript objects (although not very useful...) |
14066 | bpr | 5177 | @ may be combined with keyword <a href='#userinput_xy'>userinput_xy</a> |
5178 | @ may be combined width the <a href='#snaptogrid'>snaptogrid snaptopoints </a> etc, to simplify the checking of the student reply |
||
13956 | schaersvoo | 5179 | @ the cursor may be appropriately styled using command <a href='cursor'>cursor</a> |
15111 | schaersvoo | 5180 | @ note: when zooming / panning after a drawing, the drawing will NOT be zoomed / panned...this is a "design" flaw and not a feature <br />To avoid trouble do not use zooming / panning together width userdraw.!<br />use command <a href="#multidraw">multidraw</a> is this is a problem for you... |
14247 | bpr | 5181 | @ note: the default replyformat for ''userdraw input(s),color`` used format x1;y1;text1 \n x2;y2;test2 \n x_n;y_n;text_n (e.g. it is not a comma separated array...use ''direct exec`` to test) |
15111 | schaersvoo | 5182 | @ note: a special case is ''userdraw image,boguscolor``. Images (bitmap or svg or div) present in the exercise page and the img/svg/div-tag with an unique 'id' and <code>onclick='javascript:place_image_on_canvas(this.id)'</code> can be placed onto the canvas.<br />The ''id`` and (x;y) coordinates will be returned using read_canvas();<br /> native MathML, MathJax or KaTeX typesetting may be included in div's.(experiments; wims_modules svn version only!) |
15527 | bpr | 5183 | @ note: command <br /><code>userdraw function,color</code> is identical to acombination of <code>strokecolor color</code> and <code>userinput function</code><br /> |
15313 | schaersvoo | 5184 | @ note: commands :<br /><code>multicolors red,green,blue<br />multilabel f(x)=:g(x)=:h(x)=<br />userdraw functions3,color</code><br />is identical to commands :<br /><code>functionlabel f(x)=:p(x)=:w(x)=<br/>strokecolor red<br />userinput function <br />strokecolor green<br />userinput function <br />strokecolor blue<br />userinput function</code> |
16613 | schaersvoo | 5185 | @%userdraw_canvastype_a%size 400,400%xrange -10,10%yrange -10,10%linewidth 3%grid 2,2,grey%replyformat 10%colorpalette orange,yellow,red,green,lightgreen,blue,lightblue,cyan%canvastype 4%userdraw clickfill,blue%clearbutton REMOVE LAST RECTANGLE |
12107 | schaersvoo | 5186 | @%userdraw_canvastype_b%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%canvastype 4%snaptogrid%replyformat 10%userdraw dotfill,blue%clearbutton REMOVE LAST RECTANGLE |
5187 | @%userdraw_rect%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw rect,green |
||
5188 | @%userdraw_rects%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw rects,green |
||
5189 | @%userdraw_frect%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw frect,green |
||
5190 | @%userdraw_frects%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw frects,green |
||
5191 | @%userdraw_roundrect%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw roundrect,green |
||
5192 | @%userdraw_roundrects%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw roundrects,green |
||
5193 | @%userdraw_froundrect%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw froundrect,green |
||
5194 | @%userdraw_froundrects%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw froundrects,green |
||
5195 | @%userdraw_line%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw line,green |
||
5196 | @%userdraw_lines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw lines,green |
||
5197 | @%userdraw_vline%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw vline,green |
||
5198 | @%userdraw_vlines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw vlines,green |
||
5199 | @%userdraw_hline%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw hline,green |
||
5200 | @%userdraw_hlines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw hlines,green |
||
5201 | @%userdraw_demiline%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw demiline,green |
||
5202 | @%userdraw_demilines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw demilines,green |
||
5203 | @%userdraw_arc%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw arc,green |
||
5204 | @%userdraw_arcs%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw arcs,green |
||
5205 | @%userdraw_point%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw point,green |
||
5206 | @%userdraw_points%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw points,green |
||
5207 | @%userdraw_arrow%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw arrow,green |
||
5208 | @%userdraw_arrows%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw arrows,green |
||
5209 | @%userdraw_arrow2%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw arrow2,green |
||
5210 | @%userdraw_arrows2%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw arrows2,green |
||
14025 | schaersvoo | 5211 | @%userdraw_curvedarrow%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%precision 1%grid 2,2,grey,2,2,5,grey%precision 1%linewidth 3%userdraw curvedarrow,red%clearbutton REMOVE ALL ARROWS |
5212 | @%userdraw_curvedarrows%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%precision 1%grid 2,2,grey,2,2,5,grey%precision 1%linewidth 3%userdraw curvedarrows,red%clearbutton REMOVE ALL ARROWS |
||
14270 | schaersvoo | 5213 | @%userdraw_curvedarrow2%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%precision 1%grid 2,2,grey,2,2,5,grey%precision 1%linewidth 3%userdraw curvedarrow2,red%clearbutton REMOVE ALL ARROWS |
5214 | @%userdraw_curvedarrows2%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%precision 1%grid 2,2,grey,2,2,5,grey%precision 1%linewidth 3%userdraw curvedarrows2,red%clearbutton REMOVE ALL ARROWS |
||
12107 | schaersvoo | 5215 | @%userdraw_crosshair%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw crosshair,green |
5216 | @%userdraw_crosshairs%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw crosshairs,green |
||
5217 | @%userdraw_circle%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw circle,green |
||
5218 | @%userdraw_circles%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw circles,green |
||
5219 | @%userdraw_segment%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw segment,green |
||
5220 | @%userdraw_segments%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw segments,green |
||
5221 | @%userdraw_line%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw line,green |
||
5222 | @%userdraw_lines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw lines,green |
||
5223 | @%userdraw_triangle%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw triangle,green |
||
5224 | @%userdraw_poly5%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw poly5,green |
||
5225 | @%userdraw_filled_poly5%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%filled%userdraw poly5,green |
||
5226 | @%userdraw_poly7%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw poly7,green |
||
5227 | @%userdraw_filled_poly7%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%filled%userdraw poly7,green |
||
5228 | @%userdraw_polyline%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw polyline,green |
||
5229 | @%userdraw_freehandline%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw freehandline,green |
||
5230 | @%userdraw_filled_freehandline%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%filled%userdraw freehandline,green |
||
5231 | @%userdraw_freehandlines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw freehandlines,green |
||
5232 | @%userdraw_input%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%userdraw input,green |
||
5233 | @%userdraw_inputs%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%userdraw inputs,green |
||
5234 | @%userdraw_text%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%fontfamily 42px Courier%userdraw text,green |
||
15111 | schaersvoo | 5235 | @%userdraw_function%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%precision 1%grid 2,2,grey,2,2,5,grey%multicolors orange,red,green,blue,cyan%precision 1000%userdraw functions3,red%jscurve blue,x^2,-x^2,5*cos(x)%precision 1%mouse red,22 |
14044 | schaersvoo | 5236 | @%userdraw_clickfill_colorpalette%size 400,400%xrange -10,10%yrange -10,10%linewidth 3%circles blue,0,0,4,1,1,6,3,3,3,-3,-3,5%opacity 255,120%colorpalette red,green,yellow,blue%userdraw clickfill,green |
13948 | schaersvoo | 5237 | @%userdraw_clickfill_1%size 400,400%xrange -10,10%yrange -10,10%linewidth 3%circles blue,0,0,4,1,1,6,3,3,3,-3,-3,5%opacity 255,120%userdraw clickfill,green |
5238 | @%userdraw_clickfill_2%size 400,400%xrange -10,10%yrange -10,10%linewidth 1%circles blue,0,0,2,1,1,5,5,5,4,-5,5,6,5,-5,6%userdraw hatchfill,red%#userdraw dotfill,red%#userdraw diamonefill,red%#userdraw gridfill,red |
||
14071 | bpr | 5239 | @%userdraw_clickfill_2%size 400,400%xrange -10,10%yrange -10,10%bgcolor white%# to get nice click coordinates take invisible ''grid`` and use ''snaptogrid`` %grid 1,1,white%snaptogrid%circles blue,0,0,2,1,1,5,5,5,4,-5,5,6,5,-5,6%userdraw gridfill,red |
7614 | schaersvoo | 5240 | */ |
15111 | schaersvoo | 5241 | if( use_userdraw != 0 ){ /* only one object type may be drawn*/ |
14038 | schaersvoo | 5242 | canvas_error("Only one userdraw primitive may be used in command 'userdraw' use command 'multidraw' for this..."); |
7614 | schaersvoo | 5243 | } |
15111 | schaersvoo | 5244 | js_function[INTERACTIVE] = 1; |
7614 | schaersvoo | 5245 | draw_type = get_string_argument(infile,0); |
15111 | schaersvoo | 5246 | if( strcmp(draw_type,"textfill") == 0){ |
5247 | fprintf(js_include_file,"var userdraw_text_string = \"%s\";", get_string(infile,1)); |
||
7614 | schaersvoo | 5248 | } |
5249 | else |
||
15111 | schaersvoo | 5250 | { |
5251 | if( strcmp(draw_type,"imagefill") == 0){ |
||
5252 | fprintf(js_include_file,"var userdraw_image_url = \"%s\";", get_string(infile,1)); |
||
5253 | } |
||
5254 | else |
||
5255 | { |
||
5256 | stroke_color = get_color(infile,1); |
||
5257 | } |
||
7614 | schaersvoo | 5258 | } |
15116 | bpr | 5259 | |
15111 | schaersvoo | 5260 | if( strcmp(draw_type,"clickfill") == 0){use_filled = 1;fill_color = stroke_color;} |
5261 | reply_precision = precision; |
||
5262 | use_userdraw = 1; |
||
5263 | fprintf(js_include_file,"\n\ |
||
5264 | /* begin userdraw */\ |
||
5265 | userdraw_x = new Array();userdraw_y = new Array();userdraw_radius = new Array();\ |
||
5266 | var forbidden_zone=[xsize+1,ysize+1];var xy_cnt = 0;\ |
||
5267 | var canvas_userdraw = create_canvas%d(%d,xsize,ysize);\ |
||
5268 | var context_userdraw = canvas_userdraw.getContext(\"2d\");\ |
||
5269 | var use_dashed = %d;\ |
||
5270 | var use_snap = %d;if(use_dashed == 1){if( context_userdraw.setLineDash ){context_userdraw.setLineDash([%d,%d]);}else{if(context_userdraw.mozDash){context_userdraw.mozDash = [%d,%d];};};};\ |
||
5271 | context_userdraw.lineWidth = %d;var use_filled = %d;\ |
||
5272 | context_userdraw.strokeStyle = \"rgba(%s,%.2f)\";\ |
||
5273 | context_userdraw.font = \"%s\";\ |
||
15128 | schaersvoo | 5274 | var user_is_dragging = false;\ |
15111 | schaersvoo | 5275 | if(wims_status != \"done\"){\ |
5276 | canvas_div.addEventListener(\"mousedown\" ,user_draw,false);\ |
||
5277 | canvas_div.addEventListener(\"mousemove\" ,user_drag,false);\ |
||
5278 | canvas_div.addEventListener(\"touchstart\",function(e){ e.preventDefault();user_draw(e.changedTouches[0]);},false);\ |
||
5279 | canvas_div.addEventListener(\"touchmove\" ,function(e){ e.preventDefault();user_drag(e.changedTouches[0]);},false);\ |
||
15128 | schaersvoo | 5280 | canvas_div.addEventListener(\"touchend\" ,function(e){ e.preventDefault();user_drawstop(e.changedTouches[0]);},false);\ |
15111 | schaersvoo | 5281 | };",canvas_root_id,DRAW_CANVAS,use_dashed,use_snap,dashtype[0],dashtype[1],dashtype[0],dashtype[1],line_width,use_filled,stroke_color,stroke_opacity,font_family); |
5282 | |||
5283 | if( use_filled == 0 ){ |
||
5284 | fprintf(js_include_file,"context_userdraw.fillStyle = \"rgba(255,255,255.0)\";"); |
||
7614 | schaersvoo | 5285 | } |
5286 | else |
||
5287 | { |
||
15111 | schaersvoo | 5288 | if( use_filled == 1 ){ |
5289 | fprintf(js_include_file,"context_userdraw.fillStyle = \"rgba(%s,%.2f)\";",fill_color,fill_opacity); |
||
5290 | } |
||
5291 | else |
||
5292 | { |
||
5293 | js_function[DRAW_FILL_PATTERN] = 1; |
||
5294 | fprintf(js_include_file,"context_userdraw.fillStyle = create_Pattern(0,0,%d,[%s]);\n",use_filled,fill_color); |
||
5295 | } |
||
7614 | schaersvoo | 5296 | } |
15111 | schaersvoo | 5297 | add_js_userdraw(draw_type,stroke_color,stroke_opacity,crosshair_size,arrow_head,use_offset,css_class,use_snap,canvas_type,use_filled,fill_color,fill_opacity,line_width,font_family); |
7614 | schaersvoo | 5298 | reset(); |
5299 | break; |
||
8386 | schaersvoo | 5300 | |
5301 | case USERINPUT: |
||
5302 | /* |
||
13955 | schaersvoo | 5303 | @ userinput function inputfield |
15715 | schaersvoo | 5304 | @ alternative: userinput_function |
5305 | @ alternative: userinput_xy |
||
15111 | schaersvoo | 5306 | @ ''inputfield`` is only usable in combination with some ''userdraw draw_type`` |
5307 | @ note: the input fields are not cleared after the object is drawn...be aware of multiple idential drawings (many clicks on the ''ok`` button) |
||
5308 | @ ''userinput function`` may be used any time (e.g. without userdraw) |
||
14071 | bpr | 5309 | @ multiple ''userinput function`` commands may be used. |
5310 | @ use command <code>functionlabel some_string</code> to define the inputfield text: default value "f(x)=" |
||
5311 | @ use command <code>strokecolor some_color</code> to adjust the plot / functionlabel color |
||
15111 | schaersvoo | 5312 | @ use command <code>css some_css</code> to adjust the inputfields |
14071 | bpr | 5313 | @ use command <code>fontsize int</code> to adjust the label fonts. (default 12px) |
5314 | @ the user input for the function will be corrected by a simple ''rawmath`` implementation...<br />an error message will be shown if javascript can not interpret the user input |
||
15111 | schaersvoo | 5315 | @%userinput_function%size 400,400%xrange -10,10%yrange -10,10%functionlabel your function g(x)=%axis%axisnumbering%xlabel x-axis%ylabel y-axis%grid 2,2,grey,3,3,5,grey%css color:blue;text-align:center%userinput function%# note: number of function inputs not limited |
13955 | schaersvoo | 5316 | @%userinput_points%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%# adding 2 inputfields for x and y%userinput inputfield%userdraw points,blue |
5317 | @%userinput_arrows%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%#adding 4 inputfields for (x1;y1)---(x2;y2)%userinput inputfieldd%userdraw arrows,blue |
||
15111 | schaersvoo | 5318 | @%userinput_combined%size 400,400%xrange -10,10%yrange -10,10%functionlabel your function g(x)=%axis%axisnumbering%xlabel x-axis%ylabel y-axis%precision 0%grid 2,2,grey,3,3,5,grey%css color:blue;text-align:center%precision 1000%strokecolor red%opacity 255,255%userinput function%# note: number of function inputs not limited%userdraw line,blue |
8386 | schaersvoo | 5319 | */ |
5320 | temp = get_string_argument(infile,1); |
||
5321 | if(strstr(temp,"function") != 0 || strstr(temp,"curve") != 0 || strstr(temp,"plot") != 0 ){ |
||
5322 | if( js_function[DRAW_JSFUNCTION] != 1 ){ |
||
15111 | schaersvoo | 5323 | js_function[JS_RAWMATH] = 1; |
8386 | schaersvoo | 5324 | js_function[DRAW_JSFUNCTION] = 1; |
5325 | if(reply_format == 0){reply_format = 24;}/* read canvas_input values */ |
||
15111 | schaersvoo | 5326 | add_input_jsfunction(css_class,function_label,input_cnt,stroke_color,stroke_opacity,line_width,use_dashed,dashtype[0],dashtype[1],font_size); |
8386 | schaersvoo | 5327 | input_cnt++; |
5328 | } |
||
10953 | bpr | 5329 | else |
8386 | schaersvoo | 5330 | { |
14078 | bpr | 5331 | /* no need to add DRAW_JSFUNCTION, just call it with the parameters */ |
15111 | schaersvoo | 5332 | fprintf(js_include_file,"add_input_jsfunction(%d,\"%s\",%s,%d,\"%s\",\"%.2f\",%d,%d,%d,%d);\n",input_cnt,css_class,function_label,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],font_size); |
8386 | schaersvoo | 5333 | input_cnt++; |
5334 | } |
||
15111 | schaersvoo | 5335 | js_function[JS_MATH] = 1; |
5336 | js_function[JS_PLOT] = 1; |
||
8386 | schaersvoo | 5337 | } |
5338 | else |
||
5339 | { |
||
5340 | if(strstr(temp,"inputfield") != 0 ){ |
||
15111 | schaersvoo | 5341 | js_function[JS_SAFE_EVAL] = 1; |
5342 | js_function[ADD_USER_INPUTS] = 1; |
||
8386 | schaersvoo | 5343 | } |
5344 | else |
||
5345 | { |
||
15111 | schaersvoo | 5346 | canvas_error("userinput argument may be \"function\" or \"inputfield\""); |
8386 | schaersvoo | 5347 | } |
5348 | } |
||
5349 | break; |
||
5350 | case USERINPUT_XY: |
||
5351 | /* |
||
5352 | @ userinput_xy |
||
9372 | schaersvoo | 5353 | @ keyword (no arguments required) |
8386 | schaersvoo | 5354 | @ to be used in combination with command "userdraw object_type,color" |
14078 | bpr | 5355 | @ if set two (or three) input fields are added to the document<br />(one for x-values, one for y-values and in case of drawing circle one for radius-values) |
8386 | schaersvoo | 5356 | @ the student may use this as correction for (x:y) on a drawing (or to draw without mouse, using just the coordinates) |
14071 | bpr | 5357 | @ math input is allowed (e.g something like: 1+3,2*6,1/3,sqrt(3), sin(pi/4),10^-2,log(2)...)<br />eval function is ''protected`` against code injection. |
14086 | bpr | 5358 | @ can <b>not</b> be combined with command ''intooltip tiptext`` <br />note: the ''tooltip div element`` is used for placing inputfields |
8386 | schaersvoo | 5359 | @ user drawings will not zoom on zooming (or pan on panning) |
15651 | reyssat | 5360 | @ use command ''css some_css`` to adjust the inputarea. |
14071 | bpr | 5361 | @ use command ''fontsize int`` to adjust the text labels (if needed) |
13950 | schaersvoo | 5362 | @%userinput_xy%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%precision 0%grid 2,2,grey,3,3,6,black%# provides inputfields for (x1:y1)---(x2:y2)%userinput_xy%linewidth 2%precision 1000%userdraw lines,blue |
8386 | schaersvoo | 5363 | */ |
5364 | /* add simple eval check to avoid code injection with unprotected eval(string) */ |
||
15111 | schaersvoo | 5365 | js_function[JS_SAFE_EVAL] = 1; |
5366 | js_function[ADD_USER_INPUTS] = 1; |
||
8386 | schaersvoo | 5367 | break; |
5368 | |||
5369 | case USERINPUT_FUNCTION: |
||
5370 | /* |
||
5371 | @ userinput_function |
||
15715 | schaersvoo | 5372 | @ alternative: userinput |
9372 | schaersvoo | 5373 | @ keyword (no arguments required) |
14078 | bpr | 5374 | @ if set, a inputfield will be added to the page |
8386 | schaersvoo | 5375 | @ repeat keyword for more function input fields |
5376 | @ the userinput value will be plotted in the canvas |
||
14071 | bpr | 5377 | @ this value may be read with <code>read_canvas()</code>. <br />for do it yourself js-scripters: If this is the first inputfield in the script, its id is canvas_input0 |
15111 | schaersvoo | 5378 | @ use before this command ''userinput_function``,<br />commands like ''css some_css``, ''xlabel some_description``, ''opacity int,int``, ''linewidth int``, ''dashed`` and ''dashtype int,int`` to modify |
14071 | bpr | 5379 | @ fontsize can be set using command ''fontsize int`` |
5380 | @ incompatible with command ''intooltip link_text_or_image``: it uses the tooltip div for adding the inputfield |
||
15313 | schaersvoo | 5381 | @%userinput_function%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%xlabel x-axis%ylabel y-axis%precision 0%grid 2,2,grey,2,2,5,grey%precision 1000%linewidth 2%# first inputfield%css color:blue;text-align:center;font-family:Italic;%strokecolor blue%functionlabel g(x)=:p(x)=:k(x)=%userinput function%# second inputfield%css color:green;text-align:center;font-family:Italic;%strokecolor green%userinput function%# third inputfield%css color:purple;text-align:center;font-family:Italic;%strokecolor purple%userinput function%# no limit in number of function inputfields |
8386 | schaersvoo | 5382 | */ |
5383 | if( js_function[DRAW_JSFUNCTION] != 1 ){ |
||
5384 | js_function[DRAW_JSFUNCTION] = 1; |
||
15111 | schaersvoo | 5385 | js_function[JS_RAWMATH] = 1; |
8386 | schaersvoo | 5386 | if(reply_format == 0){reply_format = 24;}/* read canvas_input values */ |
15111 | schaersvoo | 5387 | add_input_jsfunction(css_class,function_label,input_cnt,stroke_color,stroke_opacity,line_width,use_dashed,dashtype[0],dashtype[1],font_size); |
8386 | schaersvoo | 5388 | input_cnt++; |
5389 | } |
||
10953 | bpr | 5390 | else |
8386 | schaersvoo | 5391 | { |
14078 | bpr | 5392 | /* no need to add DRAW_JSFUNCTION, just call it with the parameters */ |
15111 | schaersvoo | 5393 | fprintf(js_include_file,"add_input_jsfunction(%d,\"%s\",%s,%d,\"%s\",\"%.2f\",%d,%d,%d,%d);\n",input_cnt,css_class,function_label,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],font_size); |
8386 | schaersvoo | 5394 | input_cnt++; |
5395 | } |
||
15111 | schaersvoo | 5396 | js_function[JS_MATH] = 1; |
5397 | js_function[JS_PLOT] = 1; |
||
8386 | schaersvoo | 5398 | break; |
5399 | |||
11806 | schaersvoo | 5400 | case VLINE: |
8386 | schaersvoo | 5401 | /* |
11806 | schaersvoo | 5402 | @ vline x,y,color |
15715 | schaersvoo | 5403 | @ alternative: verticalline |
15111 | schaersvoo | 5404 | @ draw a vertical line through point (x:y) in color 'color' |
11806 | schaersvoo | 5405 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
12107 | schaersvoo | 5406 | @%vline%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%onclick%vline 0,0,red%onclick%vline 1,0,orange%onclick%vline 2,0,blue%onclick%vline 3,0,green |
8386 | schaersvoo | 5407 | */ |
11806 | schaersvoo | 5408 | for(i=0;i<3;i++) { |
7614 | schaersvoo | 5409 | switch(i){ |
11806 | schaersvoo | 5410 | case 0: double_data[0] = get_real(infile,0);break; /* x-values */ |
5411 | case 1: double_data[1] = get_real(infile,0);break; /* y-values */ |
||
5412 | case 2: stroke_color=get_color(infile,1);/* name or hex color */ |
||
5413 | double_data[2] = double_data[0]; |
||
7614 | schaersvoo | 5414 | decimals = find_number_of_digits(precision); |
15111 | schaersvoo | 5415 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
5416 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[2],decimals,100*ymin,decimals,100*ymax,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
5417 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
5418 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[2],decimals,100*ymin,decimals,100*ymax,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
5419 | add_to_buffer(tmp_buffer); |
||
5420 | if(onclick != 0){object_cnt++;} |
||
5421 | /* object_cnt++; */ |
||
8379 | schaersvoo | 5422 | reset(); |
7614 | schaersvoo | 5423 | break; |
5424 | } |
||
5425 | } |
||
15111 | schaersvoo | 5426 | dragstuff[4] = 1; |
5427 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
7614 | schaersvoo | 5428 | break; |
5429 | |||
11806 | schaersvoo | 5430 | case VLINES: |
11802 | schaersvoo | 5431 | /* |
11806 | schaersvoo | 5432 | @ vlines color,x1,y1,x2,y2.... |
15715 | schaersvoo | 5433 | @ alternative: verticallines |
15111 | schaersvoo | 5434 | @ draw vertical lines through points (x1:y1),(x2:y2)... in color 'color' |
11806 | schaersvoo | 5435 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually |
13939 | bpr | 5436 | @%vlines%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%onclick%vlines red,1,0,2,0,3,0,4,0 |
11802 | schaersvoo | 5437 | */ |
11806 | schaersvoo | 5438 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
5439 | fill_color = stroke_color; |
||
5440 | i=0; |
||
5441 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 5442 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
11806 | schaersvoo | 5443 | if(i%2 == 0 ){ |
5444 | double_data[i] = get_real(infile,0); /* x */ |
||
7614 | schaersvoo | 5445 | } |
11806 | schaersvoo | 5446 | else |
5447 | { |
||
5448 | double_data[i] = get_real(infile,1); /* y */ |
||
7983 | schaersvoo | 5449 | } |
11806 | schaersvoo | 5450 | i++; |
7983 | schaersvoo | 5451 | } |
11806 | schaersvoo | 5452 | decimals = find_number_of_digits(precision); |
15111 | schaersvoo | 5453 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
11806 | schaersvoo | 5454 | for(c = 0 ; c < i-1 ; c = c+2){ |
15111 | schaersvoo | 5455 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[c],decimals,double_data[c],decimals,ymin,decimals,ymax,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
5456 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
5457 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[c],decimals,double_data[c],decimals,ymin,decimals,ymax,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
5458 | add_to_buffer(tmp_buffer); |
||
5459 | if(onclick != 0){object_cnt++;} |
||
5460 | /* object_cnt++; */ |
||
11806 | schaersvoo | 5461 | } |
5462 | reset(); |
||
15111 | schaersvoo | 5463 | dragstuff[4] = 1; |
5464 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
7983 | schaersvoo | 5465 | break; |
11806 | schaersvoo | 5466 | |
5467 | case VIDEO: |
||
7614 | schaersvoo | 5468 | /* |
11806 | schaersvoo | 5469 | @ video x,y,w,h,videofile location |
14066 | bpr | 5470 | @ x,y: left top corner of audio element (in xrange / yrange) |
5471 | @ w,y: width and height in pixels |
||
5472 | @ video format may be in *.mp4 (todo: other formats) |
||
13950 | schaersvoo | 5473 | @%video%size 400,400%xrange -10,10%yrange -10,10%opacity 200,100%frect -9,9,6,-6,green%video -5,5,200,200,http://techslides.com/demos/sample-videos/small.mp4 |
7614 | schaersvoo | 5474 | */ |
15111 | schaersvoo | 5475 | js_function[DRAW_VIDEO] = 1; |
7614 | schaersvoo | 5476 | for(i=0;i<5;i++){ |
5477 | switch(i){ |
||
11806 | schaersvoo | 5478 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */ |
14162 | bpr | 5479 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system -> pixel */ |
11806 | schaersvoo | 5480 | case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */ |
5481 | case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */ |
||
5482 | case 4: temp = get_string(infile,1); |
||
14208 | schaersvoo | 5483 | string_length = 1 + snprintf(NULL,0, "draw_video(%d,%d,%d,%d,%d,\"%s\");\n",canvas_root_id,int_data[0],int_data[1],int_data[2],int_data[3],temp); |
5484 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
11806 | schaersvoo | 5485 | snprintf(tmp_buffer,string_length,"draw_video(%d,%d,%d,%d,%d,\"%s\");\n",canvas_root_id,int_data[0],int_data[1],int_data[2],int_data[3],temp); |
7614 | schaersvoo | 5486 | add_to_buffer(tmp_buffer); |
5487 | break; |
||
5488 | default:break; |
||
5489 | } |
||
5490 | } |
||
5491 | reset(); |
||
5492 | break; |
||
11806 | schaersvoo | 5493 | |
7614 | schaersvoo | 5494 | case X_AXIS_STRINGS: |
5495 | /* |
||
5496 | @ xaxis num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n |
||
16832 | bpr | 5497 | @ alternative: xaxistext |
13936 | bpr | 5498 | @ usable for commands <a href="#numberline">numberline</a> and <a href="#grid">grid</a> or combinations thereof |
9346 | schaersvoo | 5499 | @ use these x-axis num1...num_n values instead of default xmin...xmax |
14071 | bpr | 5500 | @ in case of command ''grid``. there is no need to use keyword <a href="#axisnumbering">axisnumbering</a> |
13936 | bpr | 5501 | @ use command <a href="#axis">axis</a> to have visual x/y-axis lines (see command <a href="#grid">grid</a> |
15313 | schaersvoo | 5502 | @ use command ''fontcolor``, ''fontfamily`` to adjust font <br />defaults: black,12,Arial<br />note: command ''fontsize`` is not active for this command.(''fontsize`` can be used for the <a href="#legend">legend</a> in a <a href="#grid">grid</a>) |
9346 | schaersvoo | 5503 | @ a javascript error message will flag non-matching value:name pairs |
14071 | bpr | 5504 | @ if the ''x-axis words`` are too big and will overlap, a simple alternating offset will be applied |
11044 | schaersvoo | 5505 | @ to be used before command grid (see <a href="#grid">command grid</a>) |
14078 | bpr | 5506 | @ ''xmajor`` steps should be synchronised with numbers eg. ''1`` in the next example <code>grid 1,100,grey,1,4,6,grey</code> |
13937 | schaersvoo | 5507 | @%xaxistext%size 800,200%xrange -1,13%yrange -5,10%axis%xaxistext 1:january:2:february:3:march:4:april:5:may:6:june:7:july:8:august:9:september:10:october:11:november:12:december%grid 1,4,grey,1,2,10,red |
7614 | schaersvoo | 5508 | */ |
11891 | schaersvoo | 5509 | use_axis_numbering++; |
7614 | schaersvoo | 5510 | temp = get_string(infile,1); |
5511 | if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");} |
||
5512 | if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/ |
||
11891 | schaersvoo | 5513 | fprintf(js_include_file,"x_strings[%d] = [\"%s\"];x_strings_up[%d] = null;",use_axis_numbering,temp,use_axis_numbering); |
7614 | schaersvoo | 5514 | break; |
9341 | schaersvoo | 5515 | case X_AXIS_STRINGS_UP: |
5516 | /* |
||
5517 | @ xaxisup num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n |
||
15715 | schaersvoo | 5518 | @ alternative: xaxistextup |
9341 | schaersvoo | 5519 | @ the text will be rotated 90° up |
11044 | schaersvoo | 5520 | @ no need to use keyword <a href="#axisnumbering">axisnumbering</a> |
13936 | bpr | 5521 | @ use command <a href="#axis">axis</a> to have visual x/y-axis lines (see command <a href="#grid">grid</a> |
9346 | schaersvoo | 5522 | @ use these x-axis num1...num_n values instead of default xmin...xmax |
15313 | schaersvoo | 5523 | @ use command ''fontcolor``, <a href="#fontfamily">fontfamily</a> to adjust font <br />defaults: black,12,Arial<br />note: command ''fontsize`` is not active for this command.(''fontsize`` can be used for the <a href="#legend">legend</a> in a <a href="#grid">grid</a>) |
9346 | schaersvoo | 5524 | @ a javascript error message will flag non-matching value:name pairs |
14071 | bpr | 5525 | @ if the ''x-axis words`` are too big, they will overlap the graph<br /> (in this case the text will start from ysize upwards) |
11044 | schaersvoo | 5526 | @ to be used before command grid (see <a href="#grid">command grid</a>) |
14086 | bpr | 5527 | @''xmajor`` steps should be synchronised with numbers eg. "1" in the next example <code>grid 1,100,grey,1,4,6,grey</code> |
13937 | schaersvoo | 5528 | @%xaxistextup%size 800,300%xrange -1,13%yrange -10,10%fontfamily Italic 18pt Courier%axis%xaxistextup 1:january:2:february:3:march:4:april:5:may:6:june:7:july:8:august:9:september:10:october:11:november:12:december%grid 1,4,grey,1,2,10,red |
9341 | schaersvoo | 5529 | */ |
11891 | schaersvoo | 5530 | use_axis_numbering++; |
9341 | schaersvoo | 5531 | temp = get_string(infile,1); |
5532 | if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");} |
||
5533 | if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/ |
||
11891 | schaersvoo | 5534 | fprintf(js_include_file,"x_strings_up[%d] = 1;x_strings[%d] = [\"%s\"];",use_axis_numbering,use_axis_numbering,temp); |
9341 | schaersvoo | 5535 | break; |
8224 | bpr | 5536 | |
11806 | schaersvoo | 5537 | case XERRORBARS: |
7614 | schaersvoo | 5538 | /* |
11806 | schaersvoo | 5539 | @ xerrorbars color,E1,E2,x1,y1,x2,y2,...,x_n,y_n |
15111 | schaersvoo | 5540 | @ draw multiple points with x-errorbars E1 (error value left from point) and E2 (error value right from point) at given coordinates in color 'color' |
11806 | schaersvoo | 5541 | @ the errors E1 and E2 values are in xrange. |
14071 | bpr | 5542 | @ use command ''linewidth int`` to adust size |
11806 | schaersvoo | 5543 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!) |
12107 | schaersvoo | 5544 | @%xerrorbars%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%drag xy%xerrorbars red,0.8,1.3,0,0,1,1,2,3,3,2,4,5,5,2,6,1,-1,-2,-2,0,-3,2,-4,4,-5,-1 |
12006 | schaersvoo | 5545 | |
7614 | schaersvoo | 5546 | */ |
11806 | schaersvoo | 5547 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
5548 | fill_color = stroke_color; |
||
5549 | i=0; |
||
5550 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 5551 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
11806 | schaersvoo | 5552 | if(i%2 == 0 ){ |
5553 | double_data[i] = get_real(infile,0); /* x */ |
||
8071 | schaersvoo | 5554 | } |
11806 | schaersvoo | 5555 | else |
5556 | { |
||
5557 | double_data[i] = get_real(infile,1); /* y */ |
||
7614 | schaersvoo | 5558 | } |
11806 | schaersvoo | 5559 | i++; |
7614 | schaersvoo | 5560 | } |
11806 | schaersvoo | 5561 | decimals = find_number_of_digits(precision); |
15111 | schaersvoo | 5562 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
11806 | schaersvoo | 5563 | for(c = 2 ; c < i-1 ; c = c+2){ |
15111 | schaersvoo | 5564 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,20,[%.*f],[%.*f],[%.2f],[%.2f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[c],decimals,double_data[c+1],double_data[0],double_data[1],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,1,0,0,0,use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
5565 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
5566 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,20,[%.*f],[%.*f],[%.2f],[%.2f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[c],decimals,double_data[c+1],double_data[0],double_data[1],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,1,0,0,0,use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
5567 | add_to_buffer(tmp_buffer); |
||
5568 | /* object_cnt++; */ |
||
5569 | if(onclick != 0){object_cnt++;} |
||
11806 | schaersvoo | 5570 | } |
7614 | schaersvoo | 5571 | reset(); |
15111 | schaersvoo | 5572 | dragstuff[20] = 1; |
5573 | if(use_dragstuff == 0 ){ use_dragstuff = 1; } |
||
7614 | schaersvoo | 5574 | break; |
11806 | schaersvoo | 5575 | |
5576 | case XRANGE: |
||
7614 | schaersvoo | 5577 | /* |
11806 | schaersvoo | 5578 | @ xrange xmin,xmax |
15715 | schaersvoo | 5579 | @ alternative: rangex |
11806 | schaersvoo | 5580 | @ if not given: 0,xsize (eg in pixels) |
7614 | schaersvoo | 5581 | */ |
11806 | schaersvoo | 5582 | for(i = 0 ; i<2; i++){ |
7614 | schaersvoo | 5583 | switch(i){ |
11806 | schaersvoo | 5584 | case 0: xmin = get_real(infile,0);break; |
5585 | case 1: xmax = get_real(infile,1);break; |
||
7614 | schaersvoo | 5586 | default: break; |
5587 | } |
||
5588 | } |
||
15111 | schaersvoo | 5589 | if(xmin >= xmax){canvas_error(" xrange is not OK: xmin < xmax !");} |
5590 | fprintf(js_include_file,"var xmin = %f;var xmax = %f;",xmin,xmax); |
||
11806 | schaersvoo | 5591 | found_size_command++; |
7614 | schaersvoo | 5592 | break; |
8386 | schaersvoo | 5593 | |
11806 | schaersvoo | 5594 | case XSNAPTOGRID: |
7614 | schaersvoo | 5595 | /* |
11806 | schaersvoo | 5596 | @ xsnaptogrid |
5597 | @ keyword (no arguments required) |
||
15111 | schaersvoo | 5598 | @ a draggable object (use command ''drag x|y|xy``) will snap to the given x-grid values when dragged (mouseup) |
5599 | @ in case of userdraw the drawn points will snap to xmajor grid |
||
14078 | bpr | 5600 | @ if no grid is defined, points will snap to every integer xrange value. (eg snap_x=1) |
14071 | bpr | 5601 | @ if you do not want a visible grid, but you only want a ''snaptogrid`` with some value...define this grid with opacity 0. |
15111 | schaersvoo | 5602 | @ if xminor is defined (use keyword ''axis`` to activate xminor), the drawing will snap to xminor <br />use only even dividers in x-minor...for example<br /><code>xsnaptogrid<br />axis<br />grid 2,1,grey,4,4,7,red</code><br /> will snap on x=0, x=0.5, x=1, x=1.5 ....<br /> will snap on y=0, y=0.25 y=0.5 y=0.75 ...<br /> |
13939 | bpr | 5603 | @%xsnaptogrid_1%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%xsnaptogrid%userdraw segments,red%precision 1%display x,red,12 |
5604 | @%xsnaptogrid_2%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 3%drag x%points red,0,0,0,0,0,0,0,0,0,0 |
||
12007 | schaersvoo | 5605 | |
7614 | schaersvoo | 5606 | */ |
14038 | schaersvoo | 5607 | use_snap = 2; |
11806 | schaersvoo | 5608 | break; |
8386 | schaersvoo | 5609 | |
11806 | schaersvoo | 5610 | case XOFFSET: |
7614 | schaersvoo | 5611 | /* |
12063 | schaersvoo | 5612 | @ xoffset |
13829 | bpr | 5613 | @ keyword ; to place the text centered above the text coordinates(x:y) ... |
5614 | @ may be used for points or other things requiring centered labels |
||
12063 | schaersvoo | 5615 | @ use <a href="#fontfamily">fontfamily</a> for setting the font |
11811 | schaersvoo | 5616 | @ may be active for commands <a href="#text">text</a> and <a href="#string">string</a> (e.g. objects in the drag/drop/onclick-library) |
15313 | schaersvoo | 5617 | @%xoffset%size 400,400%xrange -10,10%yrange -10,10%fontfamily 12pt Arial%string blue,-9,-9,no offset%point -9,-9,red%centered%string blue,-6,-6,centered%point -6,-6,red%xoffset%string blue,-3,-3,xoffset%point -3,-3,red%yoffset%string blue,0,0,yoffset%point 0,0,red%xyoffset%string blue,3,3,xyoffset%point 3,3,red%resetoffset%string blue,6,6,resetoffset%point 6,6,red |
7614 | schaersvoo | 5618 | */ |
12063 | schaersvoo | 5619 | use_offset = 2; |
11806 | schaersvoo | 5620 | break; |
8386 | schaersvoo | 5621 | |
11806 | schaersvoo | 5622 | case XYOFFSET: |
7614 | schaersvoo | 5623 | /* |
11806 | schaersvoo | 5624 | @ xyoffset |
5625 | @ keyword ; to place the text (x:y) to (x+dx:y+dy)... dx/dy are dependent on fontsize/fontfamily |
||
13829 | bpr | 5626 | @ may be used for points or other things requiring labels |
12063 | schaersvoo | 5627 | @ use <a href="#fontfamily">fontfamily</a> for setting the font |
11806 | schaersvoo | 5628 | @ only active for commands <a href="#text">text</a> and <a href="#string">string</a> (e.g. objects in the drag/drop/onclick-librariy |
15651 | reyssat | 5629 | @ in case of inputfields the inputfield will be centered x and y on its coordinates.<br />for example:<br />inputs 1,1,10,? <br />point 1,1,red <br /> the point will be completely invisible<br />note: keyword ''xyoffset`` will also provide centering if used with <a href='#userdraw'>input(s),color</a> |
15313 | schaersvoo | 5630 | @%xyoffset%size 400,400%xrange -10,10%yrange -10,10%fontfamily 12pt Arial%string blue,-9,-9,no offset%point -9,-9,red%centered%string blue,-6,-6,centered%point -6,-6,red%xoffset%string blue,-3,-3,xoffset%point -3,-3,red%yoffset%string blue,0,0,yoffset%point 0,0,red%xyoffset%string blue,3,3,xyoffset%point 3,3,red%resetoffset%string blue,6,6,resetoffset%point 6,6,red |
7614 | schaersvoo | 5631 | */ |
12063 | schaersvoo | 5632 | use_offset = 3; |
11806 | schaersvoo | 5633 | break; |
8386 | schaersvoo | 5634 | |
7996 | schaersvoo | 5635 | case XUNIT: |
5636 | /* |
||
5637 | @ xunit some_unit_for_x-values |
||
5638 | @ unicode allowed (no html code) |
||
15309 | schaersvoo | 5639 | @ use together with command <a href="#display">display or mouse</a> |
14071 | bpr | 5640 | @ will display the cursor x-coordinate in ''unit`` |
12107 | schaersvoo | 5641 | @%xunit%size 400,400%xrange -10,10%yrange -10,10%xunit cm \\u00B2%grid 2,2,grey%linewidth 2%userdraw segments,blue%display x,blue,18 |
7996 | schaersvoo | 5642 | */ |
5643 | fprintf(js_include_file,"unit_x = \"%s\";",get_string(infile,1)); |
||
5644 | break; |
||
11806 | schaersvoo | 5645 | |
5646 | case XLABEL: |
||
7996 | schaersvoo | 5647 | /* |
11806 | schaersvoo | 5648 | @ xlabel some_string |
15111 | schaersvoo | 5649 | @ will be used to create a label for the x-axis (label is in quadrant I) |
5650 | @ can only be used together with command ''grid``<br />not depending on keywords ''axis`` and ''axisnumbering`` |
||
5651 | @ font setting: italic Courier, fontsize will be slightly larger (fontsize + 4)<br />use command ''fontsize`` to adjust.<br />(command ''fontfamily`` is not active for this command) |
||
15309 | schaersvoo | 5652 | @ use <a href="#ylabel">ylabel</a> |
5653 | @%xlabel%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%xlabel cm\\u00B2 %ylabel v\\u00B2 %precision 1%grid 2,2,grey,2,2,5,grey |
||
7996 | schaersvoo | 5654 | */ |
11806 | schaersvoo | 5655 | temp = get_string(infile,1); |
5656 | fprintf(js_include_file,"var xaxislabel = \"%s\";",temp); |
||
7996 | schaersvoo | 5657 | break; |
8071 | schaersvoo | 5658 | |
11806 | schaersvoo | 5659 | case XLOGBASE: |
7991 | schaersvoo | 5660 | /* |
11806 | schaersvoo | 5661 | @ xlogbase number |
5662 | @ sets the logbase number for the x-axis |
||
5663 | @ default value 10 |
||
5664 | @ use together with commands xlogscale / xylogscale |
||
7991 | schaersvoo | 5665 | */ |
11806 | schaersvoo | 5666 | fprintf(js_include_file,"xlogbase=%d;",(int)(get_real(infile,1))); |
7991 | schaersvoo | 5667 | break; |
5668 | |||
11806 | schaersvoo | 5669 | case XLOGSCALE: |
7614 | schaersvoo | 5670 | /* |
11806 | schaersvoo | 5671 | @ xlogscale ymajor,yminor,majorcolor,minorcolor |
14071 | bpr | 5672 | @ the x/y-range are set using commands <code>xrange xmin,xmax</code> and <code>yrange ymin,ymax</code> |
11806 | schaersvoo | 5673 | @ ymajor is the major step on the y-axis; yminor is the divisor for the y-step |
14071 | bpr | 5674 | @ the linewidth is set using command ''linewidth int`` |
14066 | bpr | 5675 | @ the opacity of major / minor grid lines is set by command <a href='#opacity'>opacity</a> |
14379 | bpr | 5676 | @ default logbase number = 10 ... when needed, set the logbase number with command ''xlogbase number`` |
14071 | bpr | 5677 | @ the x/y- axis numbering is triggered by keyword ''axisnumbering``<ul><li>use command ''precision`` before ''xlogscale`` command to set the precision (decimals) of the axis numbering</li><li>use commands ''xlabel some_text`` and/or ''ylabel some_text`` for text on axis: use command ''fontsize int`` to set the fontsize (default 12px)</li><li>use command ''fontfamily fnt_family_string`` to set the fonts for axis-numbering</li><li>use command ''fontcolor`` to set the colour</li></ul> |
5678 | @ note: the complete canvas will be used for the ''log paper`` |
||
11806 | schaersvoo | 5679 | @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values |
14071 | bpr | 5680 | @ note: command ''mouse color,fontsize`` will show the real values in the logpaper.<br />\ |
5681 | @ note: when using something like ''xrange 0.0001,0.01``...combined with commands <a href='#mouse'>mouse</a> and/or <a href='#userdraw'>userdraw</a>...<br /> make sure the <a href='#precision'>precision</a> is set accordingly |
||
14078 | bpr | 5682 | @ note: in case of userdraw, the use of keyword <a href='#userinput_xy'>userinput_xy</a> may be handy ! |
14071 | bpr | 5683 | @ <b>attention</b>: keyword ''snaptogrid`` may not lead to the desired result... |
15111 | schaersvoo | 5684 | @ <b>attention</b>: do not use command ''zoom`` |
12107 | schaersvoo | 5685 | @%xlogscale%size 400,400%xrange 10,50000%yrange -5,5%xlabel x-axis%ylabel y-axis%xlogscale 10,1,black,grey%display x,red,22 |
7614 | schaersvoo | 5686 | */ |
11972 | schaersvoo | 5687 | use_axis_numbering++;if(use_axis_numbering > 1){use_axis_numbering = 1;} |
11806 | schaersvoo | 5688 | if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");} |
15111 | schaersvoo | 5689 | js_function[DRAW_XLOGSCALE] = 1; |
11806 | schaersvoo | 5690 | for(i=0;i<4;i++){ |
7614 | schaersvoo | 5691 | switch(i){ |
11806 | schaersvoo | 5692 | case 0: double_data[0] = get_real(infile,0);break; /* xmajor */ |
5693 | case 1: int_data[0] = (int) (get_real(infile,0));break; /* xminor */ |
||
5694 | case 2: stroke_color = get_color(infile,0); break; |
||
5695 | case 3: fill_color = get_color(infile,1); |
||
14208 | schaersvoo | 5696 | string_length = 1 + snprintf(NULL,0,"draw_grid%d(%d,%d,\"%s\",\"%s\",%.2f,%.2f,%d,\"%s\",\"%s\",%d,%f,%d,%d); ",canvas_root_id,GRID_CANVAS,line_width,stroke_color,fill_color,stroke_opacity,fill_opacity,font_size,font_family,font_color,use_axis_numbering,double_data[0],int_data[0],precision); |
5697 | tmp_buffer = my_newmem(string_length); |
||
11806 | schaersvoo | 5698 | snprintf(tmp_buffer,string_length,"draw_grid%d(%d,%d,\"%s\",\"%s\",%.2f,%.2f,%d,\"%s\",\"%s\",%d,%f,%d,%d); ",canvas_root_id,GRID_CANVAS,line_width,stroke_color,fill_color,stroke_opacity,fill_opacity,font_size,font_family,font_color,use_axis_numbering,double_data[0],int_data[0],precision); |
5699 | fprintf(js_include_file,"use_xlogscale=1;snap_y = %f;snap_x = xlogbase;",double_data[0]/int_data[0]); |
||
5700 | add_to_buffer(tmp_buffer); |
||
5701 | break; |
||
7614 | schaersvoo | 5702 | default:break; |
5703 | } |
||
5704 | } |
||
5705 | break; |
||
11806 | schaersvoo | 5706 | |
5707 | case XYLOGSCALE: |
||
7614 | schaersvoo | 5708 | /* |
11806 | schaersvoo | 5709 | @ xylogscale majorcolor,minorcolor |
14071 | bpr | 5710 | @ the x/y-range are set using commands ''xrange xmin,xmax`` and ''yrange ymin,ymax`` |
5711 | @ the linewidth is set using command ''linewidth int`` |
||
5712 | @ the opacity of major / minor grid lines is set by command ''opacity [0-255],[0-255]`` |
||
14078 | bpr | 5713 | @ default logbase number = 10 ... when needed, set the logbase number with command ''xlogbase number`` and/or ''ylogbase number`` |
14071 | bpr | 5714 | @ the x/y- axis numbering is triggered by keyword ''axisnumbering``<ul><li>use commands ''xlabel some_text`` and/or ''ylabel some_text`` for text on axis: use command ''fontsize int`` to set the fontsize (default 12px)</li><li>use command ''fontfamily fnt_family_string`` to set the fonts for axis-numbering</li><li>use command ''fontcolor`` to set the colour</li></ul> |
5715 | @ note: the complete canvas will be used for the ''log paper`` |
||
11806 | schaersvoo | 5716 | @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values |
14071 | bpr | 5717 | @ note: command ''mouse color,fontsize`` will show the real values in the logpaper.<br />\ |
5718 | @ note: when using something like ''yrange 0.0001,0.01``...combined with commands ''mouse color,fontsize`` and/or ''userdraw type,color``...<br /> make sure the precision is set accordingly (eg command ''precision 10000``) |
||
14078 | bpr | 5719 | @ note: in case of userdraw, the use of keyword ''userinput_xy`` may be handy ! |
14071 | bpr | 5720 | @ <b>attention</b>: keyword ''snaptogrid`` may not lead to the desired result... |
15111 | schaersvoo | 5721 | @ <b>attention</b>: do not use command ''zoom`` |
13829 | bpr | 5722 | @%xylogscale%size 400,400%xrange 10,50000%yrange 10,50000%xlabel x-axis%ylabel y-axis%xylogscale black,grey%display xy,red,22 |
7614 | schaersvoo | 5723 | */ |
11972 | schaersvoo | 5724 | use_axis_numbering++;if(use_axis_numbering > 1){use_axis_numbering = 1;} |
11806 | schaersvoo | 5725 | if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");} |
15111 | schaersvoo | 5726 | js_function[DRAW_XYLOGSCALE] = 1; |
11806 | schaersvoo | 5727 | for(i=0;i<2;i++){ |
7614 | schaersvoo | 5728 | switch(i){ |
11806 | schaersvoo | 5729 | case 0: stroke_color = get_color(infile,0); break; |
5730 | case 1: fill_color = get_color(infile,1); |
||
14208 | schaersvoo | 5731 | string_length = 1 + snprintf(NULL,0,"draw_grid%d(%d,%d,\"%s\",\"%s\",%.2f,%.2f,%d,\"%s\",\"%s\",%d,%d); ",canvas_root_id,GRID_CANVAS,line_width,stroke_color,fill_color,stroke_opacity,fill_opacity,font_size,font_family,font_color,use_axis_numbering,precision); |
5732 | tmp_buffer = my_newmem(string_length); |
||
11806 | schaersvoo | 5733 | snprintf(tmp_buffer,string_length,"draw_grid%d(%d,%d,\"%s\",\"%s\",%.2f,%.2f,%d,\"%s\",\"%s\",%d,%d); ",canvas_root_id,GRID_CANVAS,line_width,stroke_color,fill_color,stroke_opacity,fill_opacity,font_size,font_family,font_color,use_axis_numbering,precision); |
5734 | fprintf(js_include_file,"use_xlogscale=1;use_ylogscale=1;snap_x = xlogbase;snap_y = ylogbase;"); |
||
5735 | add_to_buffer(tmp_buffer); |
||
5736 | break; |
||
7614 | schaersvoo | 5737 | default:break; |
5738 | } |
||
5739 | } |
||
5740 | break; |
||
11806 | schaersvoo | 5741 | |
5742 | |||
5743 | case Y_AXIS_STRINGS: |
||
7647 | schaersvoo | 5744 | /* |
11806 | schaersvoo | 5745 | @ yaxis num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n |
15715 | schaersvoo | 5746 | @ alternative: yaxistext |
15313 | schaersvoo | 5747 | @ use command ''fontcolor``, ''fontfamily`` to adjust font <br />defaults: black,12,Arial<br /> note: command ''fontsize`` is not active for this command.(''fontsize`` can be used for the <a href="#legend">legend</a> in a <a href="#grid">grid</a>) |
11806 | schaersvoo | 5748 | @ no need to use keyword <a href="#axisnumbering">axisnumbering</a> |
13936 | bpr | 5749 | @ use command <a href="#axis">axis</a> to have visual x/y-axis lines (see command <a href="#grid">grid</a> |
14071 | bpr | 5750 | @ use these y-axis num1...num_n values instead of default ymin...ymax |
11806 | schaersvoo | 5751 | @ a javascript error message will flag non-matching value:name pairs |
5752 | @ to be used before command grid (see <a href="#grid">command grid</a>) |
||
12107 | schaersvoo | 5753 | @%yaxistext%size 400,400%yrange 0,13%xrange -100,500%axis%yaxis 1:january:2:february:3:march:5:may:6:june:7:july:8:august:9:september:10:october:11:november:12:december%#'ymajor' steps should be synchronised with numbers eg. "1" in this example%grid 100,1,grey,4,1,6,grey |
7647 | schaersvoo | 5754 | */ |
11806 | schaersvoo | 5755 | temp = get_string(infile,1); |
5756 | if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");} |
||
5757 | if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/ |
||
5758 | fprintf(js_include_file,"y_strings = [\"%s\"];\n ",temp); |
||
11891 | schaersvoo | 5759 | use_axis_numbering++; |
11806 | schaersvoo | 5760 | break; |
5761 | |||
5762 | |||
5763 | case YERRORBARS: |
||
7614 | schaersvoo | 5764 | /* |
11806 | schaersvoo | 5765 | @ yerrorbars color,E1,E2,x1,y1,x2,y2,...,x_n,y_n |
15111 | schaersvoo | 5766 | @ draw multiple points with y-errorbars E1 (error value under point) and E2 (error value above point) at given coordinates in color 'color' |
11806 | schaersvoo | 5767 | @ the errors E1 and E2 values are in yrange. |
14071 | bpr | 5768 | @ use command ''linewidth int`` to adust size |
11806 | schaersvoo | 5769 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!) |
12107 | schaersvoo | 5770 | @%yerrorbars%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%onclick%yerrorbars red,0.8,1.3,0,0,1,1,2,3,3,2,4,5,5,2,6,1,-1,-2,-2,0,-3,2,-4,4,-5,-1 |
7614 | schaersvoo | 5771 | */ |
11806 | schaersvoo | 5772 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
5773 | fill_color = stroke_color; |
||
11772 | schaersvoo | 5774 | i=0; |
5775 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 5776 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
11772 | schaersvoo | 5777 | if(i%2 == 0 ){ |
5778 | double_data[i] = get_real(infile,0); /* x */ |
||
5779 | } |
||
5780 | else |
||
5781 | { |
||
5782 | double_data[i] = get_real(infile,1); /* y */ |
||
5783 | } |
||
5784 | i++; |
||
5785 | } |
||
15111 | schaersvoo | 5786 | if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */ |
11806 | schaersvoo | 5787 | for(c = 2 ; c < i-1 ; c = c+2){ |
15111 | schaersvoo | 5788 | string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,19,[%.*f],[%.*f],[%.2f],[%.2f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[c],decimals,double_data[c+1],double_data[0],double_data[1],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,1,0,0,0,use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
5789 | check_string_length(string_length);tmp_buffer = my_newmem(string_length); |
||
5790 | snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,19,[%.*f],[%.*f],[%.2f],[%.2f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[c],decimals,double_data[c+1],double_data[0],double_data[1],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,1,0,0,0,use_rotate,angle,flytext,font_size,font_family,my_sliders,rotation_center,use_offset); |
||
5791 | add_to_buffer(tmp_buffer); |
||
5792 | /* object_cnt++; */ |
||
5793 | if(onclick != 0){object_cnt++;} |
||
8083 | schaersvoo | 5794 | } |
11806 | schaersvoo | 5795 | decimals = find_number_of_digits(precision); |
8083 | schaersvoo | 5796 | reset(); |
15111 | schaersvoo | 5797 | dragstuff[19] = 1; |
5798 | if(use_dragstuff == 0 ){ use_dragstuff = 1;} |
||
11806 | schaersvoo | 5799 | break; |
11811 | schaersvoo | 5800 | case YOFFSET: |
5801 | /* |
||
5802 | @ yoffset |
||
14162 | bpr | 5803 | @ keyword; to place the text centered above the text coordinates(x:y) ... |
13829 | bpr | 5804 | @ may be used for points or other things requiring centered labels |
12063 | schaersvoo | 5805 | @ use <a href="#fontfamily">fontfamily</a> for setting the font |
5806 | @ may be active for commands <a href="#text">text</a> and <a href="#string">string</a> (e.g. objects in the drag/drop/onclick-library) |
||
15313 | schaersvoo | 5807 | @%yoffset%size 400,400%xrange -10,10%yrange -10,10%fontfamily 12pt Arial%string blue,-9,-9,no offset%point -9,-9,red%centered%string blue,-6,-6,centered%point -6,-6,red%xoffset%string blue,-3,-3,xoffset%point -3,-3,red%yoffset%string blue,0,0,yoffset%point 0,0,red%xyoffset%string blue,3,3,xyoffset%point 3,3,red%resetoffset%string blue,6,6,resetoffset%point 6,6,red |
11811 | schaersvoo | 5808 | */ |
12063 | schaersvoo | 5809 | use_offset = 1; |
11811 | schaersvoo | 5810 | break; |
5811 | |||
11806 | schaersvoo | 5812 | case YRANGE: |
7614 | schaersvoo | 5813 | /* |
11806 | schaersvoo | 5814 | @ yrange ymin,ymax |
15715 | schaersvoo | 5815 | @ alternative: rangey |
11806 | schaersvoo | 5816 | @ if not given 0,ysize (eg in pixels) |
7614 | schaersvoo | 5817 | */ |
11806 | schaersvoo | 5818 | for(i = 0 ; i<2; i++){ |
7614 | schaersvoo | 5819 | switch(i){ |
11806 | schaersvoo | 5820 | case 0: ymin = get_real(infile,0);break; |
5821 | case 1: ymax = get_real(infile,1);break; |
||
5822 | default: break; |
||
7614 | schaersvoo | 5823 | } |
5824 | } |
||
15111 | schaersvoo | 5825 | if(ymin >= ymax){canvas_error(" yrange is not OK: ymin < ymax !<br />");} |
5826 | fprintf(js_include_file,"var ymin = %f;var ymax = %f;",ymin,ymax); |
||
11806 | schaersvoo | 5827 | found_size_command++; |
5828 | break; |
||
5829 | |||
5830 | case YSNAPTOGRID: |
||
7614 | schaersvoo | 5831 | /* |
11806 | schaersvoo | 5832 | @ ysnaptogrid |
5833 | @ keyword (no arguments required) |
||
14162 | bpr | 5834 | @ a draggable object (use command ''drag x|y|xy``) will snap to the given y-grid values when dragged (mouseup) |
11806 | schaersvoo | 5835 | @ in case of userdraw the drawn points will snap to ymajor grid |
14078 | bpr | 5836 | @ if no grid is defined, points will snap to every integer yrange value. (eg snap_y=1) |
14071 | bpr | 5837 | @ if you do not want a visible grid, but you only want a ''snaptogrid`` with some value...define this grid with opacity 0. |
5838 | @ if yminor is defined (use keyword ''axis`` to activate yminor), the drawing will snap to yminor <br />use only even dividers in y-minor...for example<br /><code>ysnaptogrid<br />axis<br />grid 2,1,grey,4,4,7,red</code><br /> will snap on x=0, x=0.5, x=1, x=1.5 ....<br /> will snap on y=0, y=0.25 y=0.5 y=0.75 ...<br /> |
||
15111 | schaersvoo | 5839 | @%ysnaptogrid_1%size 400,400%xrange -10,10%yrange -10,10%ysnaptogrid%grid 1,1,grey%linewidth 2%userdraw crosshairs,blue%css font-size:8px;color:blue%clearbutton delete all crosshairs |
13959 | bpr | 5840 | @%ysnaptogrid_2%size 400,400%xrange -10,10%yrange -10,10%ysnaptogrid%grid 1,1,grey%linewidth 3%drag y%points red,0,0,0,0,0,0,0,0,0,0 |
7614 | schaersvoo | 5841 | */ |
14038 | schaersvoo | 5842 | use_snap = 3; |
7614 | schaersvoo | 5843 | break; |
11080 | schaersvoo | 5844 | |
7614 | schaersvoo | 5845 | case YLABEL: |
5846 | /* |
||
5847 | @ ylabel some_string |
||
8224 | bpr | 5848 | @ will be used to create a (vertical) label for the y-axis (label is in quadrant I) |
14071 | bpr | 5849 | @ can only be used together with command <a href="#grid">grid</a><br />not depending on keywords ''axis`` and ''axisnumbering`` |
14086 | bpr | 5850 | @ font setting: italic Courier, fontsize will be slightly larger (fontsize + 4)<br />use command ''fontsize`` to adjust (command ''fontsize`` is not active for this command) |
15309 | schaersvoo | 5851 | @ use <a href="#xlabel">xlabel</a> |
12107 | schaersvoo | 5852 | @%ylabel%size 400,400%xrange -10,10%yrange -10,10%fontsize 8%axis%axisnumbering%precision 1%xlabel x-axis%ylabel y-axis%grid 1,1,grey,2,2,2,red |
7614 | schaersvoo | 5853 | */ |
5854 | temp = get_string(infile,1); |
||
7653 | schaersvoo | 5855 | fprintf(js_include_file,"var yaxislabel = \"%s\";",temp); |
7614 | schaersvoo | 5856 | break; |
7735 | schaersvoo | 5857 | case YLOGBASE: |
5858 | /* |
||
5859 | @ ylogbase number |
||
5860 | @ sets the logbase number for the y-axis |
||
5861 | @ default value 10 |
||
5862 | @ use together with commands ylogscale / xylogscale |
||
5863 | */ |
||
5864 | fprintf(js_include_file,"ylogbase=%d;",(int)(get_real(infile,1))); |
||
5865 | break; |
||
7614 | schaersvoo | 5866 | case YLOGSCALE: |
7729 | schaersvoo | 5867 | /* |
5868 | @ ylogscale xmajor,xminor,majorcolor,minorcolor |
||
14071 | bpr | 5869 | @ the x/y-range are set using commands ''xrange xmin,xmax`` and ''yrange ymin,ymax`` |
7729 | schaersvoo | 5870 | @ xmajor is the major step on the x-axis; xminor is the divisor for the x-step |
14071 | bpr | 5871 | @ the linewidth is set using command ''linewidth int`` |
5872 | @ the opacity of major / minor grid lines is set by command ''opacity [0-255],[0-255]`` |
||
14078 | bpr | 5873 | @ default logbase number = 10 ... when needed, set the logbase number with command ''ylogbase number`` |
14071 | bpr | 5874 | @ the x/y- axis numbering is triggered by keyword ''axisnumbering``<ul><li>use command ''precision`` before ''ylogscale`` command to set the precision (decimals) of the axis numbering</li><li>use commands ''xlabel some_text`` and/or ''ylabel some_text`` for text on axis: use command ''fontsize int`` to set the fontsize (default 12px)</li><li>use command ''fontfamily fnt_family_string`` to set the fonts for axis-numbering</li><li>use command ''fontcolor`` to set the color</li></ul> |
5875 | @ note: the complete canvas will be used for the ''log paper`` |
||
11088 | schaersvoo | 5876 | @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values |
14071 | bpr | 5877 | @ note: command ''mouse color,fontsize`` will show the real values in the logpaper.<br />\ |
5878 | @ note: when using something like ''yrange 0.0001,0.01``...combined with commands ''mouse color,fontsize`` and/or ''userdraw type,color``...<br /> make sure the precision is set accordingly (eg command ''precision 10000``) |
||
14078 | bpr | 5879 | @ note: in case of userdraw, the use of keyword ''userinput_xy`` may be handy ! |
15111 | schaersvoo | 5880 | @ <b>attention</b>: do not use command ''zoom`` |
14071 | bpr | 5881 | @ <b>attention</b>: keyword ''snaptogrid`` may not lead to the desired result... |
7729 | schaersvoo | 5882 | */ |
11972 | schaersvoo | 5883 | use_axis_numbering++;if(use_axis_numbering > 1){use_axis_numbering = 1;} |
7729 | schaersvoo | 5884 | if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");} |
15111 | schaersvoo | 5885 | js_function[DRAW_YLOGSCALE] = 1; |
7729 | schaersvoo | 5886 | for(i=0;i<4;i++){ |
5887 | switch(i){ |
||
5888 | case 0: double_data[0] = get_real(infile,0);break; /* xmajor */ |
||
5889 | case 1: int_data[0] = (int) (get_real(infile,0));break; /* xminor */ |
||
5890 | case 2: stroke_color = get_color(infile,0); break; |
||
8224 | bpr | 5891 | case 3: fill_color = get_color(infile,1); |
14208 | schaersvoo | 5892 | string_length = 1 + snprintf(NULL,0,"draw_grid%d(%d,%d,\"%s\",\"%s\",%.2f,%.2f,%d,\"%s\",\"%s\",%d,%f,%d,%d); ",canvas_root_id,GRID_CANVAS,line_width,stroke_color,fill_color,stroke_opacity,fill_opacity,font_size,font_family,font_color,use_axis_numbering,double_data[0],int_data[0],precision); |
5893 | tmp_buffer = my_newmem(string_length); |
||
7779 | schaersvoo | 5894 | snprintf(tmp_buffer,string_length,"draw_grid%d(%d,%d,\"%s\",\"%s\",%.2f,%.2f,%d,\"%s\",\"%s\",%d,%f,%d,%d); ",canvas_root_id,GRID_CANVAS,line_width,stroke_color,fill_color,stroke_opacity,fill_opacity,font_size,font_family,font_color,use_axis_numbering,double_data[0],int_data[0],precision); |
7735 | schaersvoo | 5895 | fprintf(js_include_file,"use_ylogscale=1;snap_x = %f;snap_y = ylogbase;",double_data[0]/int_data[0]); |
7729 | schaersvoo | 5896 | add_to_buffer(tmp_buffer); |
5897 | break; |
||
5898 | default:break; |
||
5899 | } |
||
5900 | } |
||
7614 | schaersvoo | 5901 | break; |
11806 | schaersvoo | 5902 | |
5903 | case YUNIT: |
||
7735 | schaersvoo | 5904 | /* |
11806 | schaersvoo | 5905 | @ yunit some_unit_for_y-values |
5906 | @ unicode allowed (no html code) |
||
5907 | @ use together with command mousey |
||
14071 | bpr | 5908 | @ will display the cursor y-coordinate in ''unit`` |
7735 | schaersvoo | 5909 | */ |
11806 | schaersvoo | 5910 | fprintf(js_include_file,"unit_y = \"%s\";",get_string(infile,1)); |
5911 | break; |
||
5912 | |||
5913 | case ZOOM: |
||
5914 | /* |
||
5915 | @ zoom button_color |
||
15313 | schaersvoo | 5916 | @ introduce a very small ''controlpanel`` at the lower right corner (font size of the panel is fixed to: 22px Arial) |
15111 | schaersvoo | 5917 | @ giving six 15×15px ''active`` rectangle areas<br />(''×,↓,↑,←,→,−,+``) for zooming and/or panning of the image |
5918 | @ a mouse wheel is active for in/out zooming. Drag panning is not supported (this will conflict with many ''userdraw`` or ''multidraw`` primitives) |
||
5919 | @ the ''controlpanel`` is not active for a ''userdraw`` mousedown (but it can interfere with some ''userdraw`` types) |
||
5920 | @ the ''×`` symbol will reset to your original xmax/xmin ymax/ymin values. |
||
5921 | @ choose an appropriate color, so the small ''×,↓,↑,←,→,−,+`` are clearly visible |
||
14071 | bpr | 5922 | @ command ''opacity`` may be used to set stroke_opacity of buttons |
15111 | schaersvoo | 5923 | @ note: on zooming, text will not increase / decrease the font size (todo??) |
15116 | bpr | 5924 | @ note: adding ''zooming`` will increase the size of the javascript include with approx. 11 kb |
11806 | schaersvoo | 5925 | */ |
15111 | schaersvoo | 5926 | js_function[INTERACTIVE] = 1; |
5927 | js_function[JS_ZOOM] = 1; |
||
5928 | if( use_userdraw == 1 ){ |
||
5929 | js_function[USERDRAW_AND_ZOOM] = 1; |
||
5930 | fprintf(js_include_file,"forbidden_zone = [%d,%d];",xsize-115,ysize - 20); |
||
5931 | } |
||
5932 | if(jsplot_cnt != -1){ js_function[JSPLOT_AND_ZOOM] = 1;} |
||
11806 | schaersvoo | 5933 | stroke_color = get_color(infile,1); |
5934 | /* we use BG_CANVAS (0) */ |
||
15111 | schaersvoo | 5935 | add_js_zoom_buttons(stroke_color,stroke_opacity); |
11806 | schaersvoo | 5936 | done = TRUE; |
5937 | break; |
||
5938 | |||
5939 | /* ready */ |
||
7614 | schaersvoo | 5940 | default:sync_input(infile); |
5941 | break; |
||
5942 | } |
||
8224 | bpr | 5943 | } |
7614 | schaersvoo | 5944 | /* we are done parsing script file */ |
15111 | schaersvoo | 5945 | if(use_dragstuff != 0){ |
5946 | /* add the 20kb drag code: nearly always used ... use_dragstuff==1: no-mouse ! */ |
||
5947 | add_drag_code(DRAG_CANVAS,use_dragstuff,dragstuff,reply_format); |
||
5948 | if(js_function[JS_ZOOM] == 1){ |
||
5949 | js_function[DRAG_AND_ZOOM] = 1; |
||
5950 | } |
||
5951 | } |
||
15116 | bpr | 5952 | |
14066 | bpr | 5953 | /* check if xrange / yrange was set explicit ... or use xmin=0 xmax=xsize ymin=0 ymax=ysize: Quadrant I */ |
7983 | schaersvoo | 5954 | if( found_size_command == 1 ){ |
5955 | fprintf(js_include_file,"var xmin = 0;var xmax = %d;var ymin = 0;var ymax = %d",xsize,ysize); |
||
5956 | } |
||
5957 | else |
||
5958 | { |
||
5959 | if( found_size_command != 3 ){ |
||
15111 | schaersvoo | 5960 | canvas_error("Please specify size first and then both xrange and yrange ..."); |
7983 | schaersvoo | 5961 | } |
5962 | } |
||
8257 | schaersvoo | 5963 | |
14066 | bpr | 5964 | /* if needed, add generic draw functions (grid / xml etc) to buffer: these are no draggable/clickable shapes / objects ! */ |
15111 | schaersvoo | 5965 | add_javascript_function(); |
7614 | schaersvoo | 5966 | /* add read_canvas() etc functions if needed */ |
15111 | schaersvoo | 5967 | if( reply_format > 0 ){ add_read_canvas(reply_format,reply_precision);} |
7797 | schaersvoo | 5968 | /* no zoom, just add buffer */ |
15111 | schaersvoo | 5969 | fprintf(js_include_file,"\n/* add buffer */\n%s};\n/* end wims_canvas_function */\nwims_canvas_function%d();\n",buffer,canvas_root_id); |
7614 | schaersvoo | 5970 | /* done writing the javascript include file */ |
5971 | fclose(js_include_file); |
||
5972 | } |
||
5973 | |||
5974 | /* if using a tooltip, this should always be printed to the *.phtml file, so stdout */ |
||
9329 | schaersvoo | 5975 | if( use_tooltip > 0 ){ |
5976 | if( use_tooltip == 1 ){ |
||
15111 | schaersvoo | 5977 | add_js_tooltip(tooltip_text,bgcolor); |
9329 | schaersvoo | 5978 | } |
5979 | else |
||
5980 | { |
||
5981 | if( use_tooltip == 2 ){ |
||
15111 | schaersvoo | 5982 | add_js_popup(getfile_cmd); |
9329 | schaersvoo | 5983 | } |
5984 | } |
||
5985 | } |
||
7614 | schaersvoo | 5986 | exit(EXIT_SUCCESS); |
5987 | } |
||
5988 | /* end main() */ |
||
5989 | |||
15111 | schaersvoo | 5990 | |
7614 | schaersvoo | 5991 | /****************************************************************************** |
5992 | ** |
||
5993 | ** sync_input |
||
5994 | ** |
||
5995 | ** synchronises input line - reads to end of line, leaving file pointer |
||
5996 | ** at first character of next line. |
||
5997 | ** |
||
5998 | ** Used by: |
||
5999 | ** main program - error handling. |
||
6000 | ** |
||
6001 | ******************************************************************************/ |
||
6002 | void sync_input(FILE *infile) |
||
6003 | { |
||
6004 | int c = 0; |
||
6005 | |||
7658 | schaersvoo | 6006 | if( c == '\n' || c == ';' ) return; |
6007 | while( ( (c=getc(infile)) != EOF ) && (c != '\n') && (c != '\r') && (c != ';')) ; |
||
7614 | schaersvoo | 6008 | if( c == EOF ) finished = 1; |
7658 | schaersvoo | 6009 | if( c == '\n' || c == '\r' || c == ';') line_number++; |
7614 | schaersvoo | 6010 | return; |
6011 | } |
||
6012 | |||
6013 | /******************************************************************************/ |
||
6014 | |||
15111 | schaersvoo | 6015 | |
6016 | void transform(int num,int incr){ |
||
6017 | /*. |
||
6018 | only "double_data[]" is used for transformations !! |
||
6019 | */ |
||
6020 | int i;int ii;double x,y; |
||
6021 | for(i=0;i<num;i = i+incr){ |
||
6022 | ii = i+1; |
||
6023 | x = double_data[i]*affine_matrix[0] + double_data[ii]*affine_matrix[1]+affine_matrix[4]; |
||
6024 | y = double_data[i]*affine_matrix[2] + double_data[ii]*affine_matrix[3]+affine_matrix[5]; |
||
15601 | schaersvoo | 6025 | /* |
6026 | printf("(%f:%f) → (%f:%f)<br />",double_data[i],double_data[ii],x,y); |
||
6027 | */ |
||
15111 | schaersvoo | 6028 | double_data[i] = x; |
6029 | double_data[ii] = y; |
||
6030 | } |
||
6031 | } |
||
6032 | |||
6033 | void rotate(int num,double angle,double center[],int incr){ |
||
6034 | int i;int ii;double rad = angle * 0.0174532925199; |
||
6035 | double c = cos(rad); |
||
6036 | double s = sin(rad); |
||
6037 | double x,y; |
||
6038 | for(i=0;i<num;i = i+incr){ |
||
6039 | ii = i+1; |
||
6040 | x = c*(double_data[i]-center[0]) + s*(double_data[ii] - center[1] ) + center[0]; |
||
6041 | y = c*(double_data[ii]-center[1]) - s*(double_data[i] - center[0] ) + center[1]; |
||
6042 | double_data[i] = x; |
||
6043 | double_data[ii] = y; |
||
15116 | bpr | 6044 | // printf("(x:y) - (%f:%f)<br />",x,y); |
15111 | schaersvoo | 6045 | } |
6046 | } |
||
6047 | /* not used: see transform() |
||
6048 | void translate(int num){ |
||
6049 | int i;int ii; |
||
6050 | double x,y; |
||
6051 | for(i=0;i<num;i = i+2){ |
||
6052 | ii = i+1; |
||
6053 | x = double_data[i] + affine_matrix[4]; |
||
6054 | y = double_data[ii] + affine_matrix[5]; |
||
6055 | double_data[i] = x; |
||
6056 | double_data[ii] = y; |
||
6057 | } |
||
6058 | } |
||
6059 | */ |
||
7614 | schaersvoo | 6060 | char *str_replace(const char *str, const char *old, const char *new){ |
6061 | if(strlen(str) > MAX_BUFFER){canvas_error("string argument too big");} |
||
6062 | char *ret, *r; |
||
6063 | const char *p, *q; |
||
6064 | size_t oldlen = strlen(old); |
||
6065 | size_t count = 0; |
||
6066 | size_t retlen = 0; |
||
6067 | size_t newlen = strlen(new); |
||
6068 | if (oldlen != newlen){ |
||
6069 | for (count = 0, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen){ |
||
6070 | count++; |
||
6071 | retlen = p - str + strlen(p) + count * (newlen - oldlen); |
||
6072 | } |
||
8224 | bpr | 6073 | } |
7614 | schaersvoo | 6074 | else |
6075 | { |
||
6076 | retlen = strlen(str); |
||
6077 | } |
||
8224 | bpr | 6078 | |
7614 | schaersvoo | 6079 | if ((ret = malloc(retlen + 1)) == NULL){ |
6080 | ret = NULL; |
||
6081 | canvas_error("string argument is NULL"); |
||
6082 | } |
||
6083 | else |
||
6084 | { |
||
6085 | for (r = ret, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen) { |
||
6086 | size_t l = q - p; |
||
6087 | memcpy(r, p, l); |
||
6088 | r += l; |
||
6089 | memcpy(r, new, newlen); |
||
6090 | r += newlen; |
||
6091 | } |
||
6092 | strcpy(r, p); |
||
6093 | } |
||
6094 | return ret; |
||
6095 | } |
||
6096 | |||
6097 | /******************************************************************************/ |
||
7848 | bpr | 6098 | |
7614 | schaersvoo | 6099 | char *get_color(FILE *infile , int last){ |
6100 | int c,i = 0,is_hex = 0; |
||
6101 | char temp[MAX_COLOR_STRING], *string; |
||
8305 | schaersvoo | 6102 | const char *not_allowed = "0123456789"; |
10891 | schaersvoo | 6103 | while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != ',' ) && ( c != ';' ) && ( c != '\t' ) ){ |
7614 | schaersvoo | 6104 | if( i > MAX_COLOR_STRING ){ canvas_error("colour string is too big ... ? ");} |
6105 | if( c == '#' ){ |
||
6106 | is_hex = 1; |
||
6107 | } |
||
6108 | if( c != ' '){ |
||
8304 | schaersvoo | 6109 | if( is_hex == 0 ){if(strchr(not_allowed,c) != 0){canvas_error("found something like a number...but is should have been a colour or #hex color number...<br />Do not use R,G,B !!! ");}} |
7614 | schaersvoo | 6110 | temp[i]=tolower(c); |
6111 | i++; |
||
6112 | } |
||
6113 | } |
||
10891 | schaersvoo | 6114 | if( ( c == '\n' || c == EOF || c == ';' || c == '\t' ) && last == 0){canvas_error("expecting more arguments in command");} |
6115 | if( c == '\n' || c == ';' || c == '\t' ){ done = TRUE; line_number++; } |
||
7614 | schaersvoo | 6116 | if( c == EOF ){finished = 1;} |
6117 | if( finished == 1 && last != 1 ){ canvas_error("expected more arguments");} |
||
6118 | temp[i]='\0'; |
||
6119 | if( strlen(temp) == 0 ){ canvas_error("expected a colorname or hexnumber, but found nothing !!");} |
||
6120 | if( is_hex == 1 ){ |
||
6121 | char red[3], green[3], blue[3]; |
||
6122 | red[0] = toupper(temp[1]); red[1] = toupper(temp[2]); red[2] = '\0'; |
||
6123 | green[0] = toupper(temp[3]); green[1] = toupper(temp[4]); green[2] = '\0'; |
||
6124 | blue[0] = toupper(temp[5]); blue[1] = toupper(temp[6]); blue[2] = '\0'; |
||
6125 | int r = (int) strtol(red, NULL, 16); |
||
6126 | int g = (int) strtol(green, NULL, 16); |
||
6127 | int b = (int) strtol(blue, NULL, 16); |
||
14408 | schaersvoo | 6128 | int L0 = 1+snprintf(NULL,0,"%d,%d,%d",r,g,b); |
6129 | string = my_newmem(L0); |
||
6130 | snprintf(string,L0,"%d,%d,%d",r,g,b); |
||
7614 | schaersvoo | 6131 | return string; |
6132 | } |
||
6133 | else |
||
6134 | { |
||
6135 | string = (char *)my_newmem(sizeof(temp)); |
||
6136 | snprintf(string,sizeof(temp),"%s",temp); |
||
8304 | schaersvoo | 6137 | for( i = 0; i < NUMBER_OF_COLORNAMES ; i++ ){ |
7614 | schaersvoo | 6138 | if( strcmp( colors[i].name , string ) == 0 ){ |
6139 | return colors[i].rgb; |
||
6140 | } |
||
6141 | } |
||
8304 | schaersvoo | 6142 | canvas_error("I was expecting a color name or hexnumber...but found nothing."); |
7614 | schaersvoo | 6143 | } |
8304 | schaersvoo | 6144 | return "0,0,255"; |
7614 | schaersvoo | 6145 | } |
6146 | |||
14066 | bpr | 6147 | char *get_string(FILE *infile,int last){ /* last = 0: more arguments ; last=1 final argument */ |
7614 | schaersvoo | 6148 | int c,i=0; |
6149 | char temp[MAX_BUFFER], *string; |
||
10891 | schaersvoo | 6150 | while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != '\t') ){ |
7614 | schaersvoo | 6151 | temp[i]=c; |
6152 | i++; |
||
6153 | if(i > MAX_BUFFER){ canvas_error("string size too big...repeat command to fit string");break;} |
||
6154 | } |
||
10891 | schaersvoo | 6155 | if( ( c == '\n' || c == '\t' || c == EOF ) && last == 0){canvas_error("expecting more arguments in command");} |
6156 | if( c == '\n' || c == '\t') { done = TRUE; line_number++; } |
||
11022 | schaersvoo | 6157 | if( c == EOF ) {finished = 1;} |
7614 | schaersvoo | 6158 | temp[i]='\0'; |
15722 | obado | 6159 | if( strlen(temp) == 0 && last != 3 ){ canvas_error("expected a word or string, but found nothing!");} |
7614 | schaersvoo | 6160 | string=(char *)my_newmem(strlen(temp)); |
6161 | snprintf(string,sizeof(temp),"%s",temp); |
||
6162 | return string; |
||
6163 | } |
||
6164 | |||
14066 | bpr | 6165 | char *get_string_argument(FILE *infile,int last){ /* last = 0: more arguments ; last=1 final argument */ |
7614 | schaersvoo | 6166 | int c,i=0; |
6167 | char temp[MAX_BUFFER], *string; |
||
10891 | schaersvoo | 6168 | while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != '\t') && ( c != ',')){ |
7614 | schaersvoo | 6169 | temp[i]=c; |
6170 | i++; |
||
6171 | if(i > MAX_BUFFER){ canvas_error("string size too big...will cut it off");break;} |
||
6172 | } |
||
8224 | bpr | 6173 | if( ( c == '\n' || c == EOF) && last == 0){canvas_error("expecting more arguments in command");} |
10891 | schaersvoo | 6174 | if( c == '\n' || c == '\t' ) { line_number++; } |
7614 | schaersvoo | 6175 | if( c == EOF ) {finished = 1;} |
9478 | schaersvoo | 6176 | if( finished == 1 && last == 0 ){ canvas_error("expected more arguments");} |
7614 | schaersvoo | 6177 | temp[i]='\0'; |
10953 | bpr | 6178 | /* |
8322 | schaersvoo | 6179 | 17.10.2014 removed (question Perrin) |
6180 | may cause some unwanted effects... |
||
14078 | bpr | 6181 | if( strlen(temp) == 0 ){ canvas_error("expected a word or string (without comma), but found nothing !!");} |
8322 | schaersvoo | 6182 | */ |
7614 | schaersvoo | 6183 | string=(char *)my_newmem(sizeof(temp)); |
6184 | snprintf(string,sizeof(temp),"%s",temp); |
||
6185 | done = TRUE; |
||
6186 | return string; |
||
6187 | } |
||
6188 | |||
14066 | bpr | 6189 | double get_real(FILE *infile, int last){ /* accept anything that looks like an number ? last = 0: more arguments ; last=1 final argument */ |
7614 | schaersvoo | 6190 | int c,i=0,found_calc = 0; |
6191 | double y; |
||
6192 | char tmp[MAX_INT]; |
||
10953 | bpr | 6193 | /* |
14066 | bpr | 6194 | these things are 'allowed functions': *,^,+,-,/,(,),e,arc,cos,tan,pi,log,ln,sqrt,abs |
8383 | schaersvoo | 6195 | but there should be a better way to avoid segfaults ! |
8348 | schaersvoo | 6196 | */ |
6197 | const char *allowed = "earcostanpilogqb*+-/^()";/* assuming these are allowed stuff in a 'number'*/ |
||
6198 | const char *not_allowed = "#dfhjkmuvwxyz{}[]%&~!$";/* avoid segmentation faults in a "atof()" and "wims eval" */ |
||
10891 | schaersvoo | 6199 | while(( (c=getc(infile)) != EOF ) && ( c != ',') && (c != '\n') && (c != '\t') && ( c != ';')){ |
7614 | schaersvoo | 6200 | if( c != ' ' ){ |
8224 | bpr | 6201 | if( i == 0 && c == '+' ){ |
7614 | schaersvoo | 6202 | continue; |
8224 | bpr | 6203 | } |
7614 | schaersvoo | 6204 | else |
6205 | { |
||
8304 | schaersvoo | 6206 | c = tolower(c); |
6207 | if( strchr(not_allowed,c) != 0 ){canvas_error("found a character not associated with a number...");} |
||
6208 | if( strchr(allowed,c) != 0 ){found_calc = 1;}/* hand the string over to wims eval() */ |
||
7614 | schaersvoo | 6209 | tmp[i] = c; |
6210 | i++; |
||
6211 | } |
||
6212 | } |
||
6213 | if( i > MAX_INT - 1){canvas_error("number too large");} |
||
6214 | } |
||
10891 | schaersvoo | 6215 | if( ( c == '\n' || c == EOF || c == ';' || c == '\t' ) && last == 0){canvas_error("expecting more arguments in command");} |
6216 | if( c == '\n' || c == ';' || c == '\t' ){ done = TRUE; line_number++; } |
||
7614 | schaersvoo | 6217 | if( c == EOF ){done = TRUE ; finished = 1;} |
6218 | tmp[i]='\0'; |
||
15633 | bpr | 6219 | if( strlen(tmp) == 0 ){canvas_error("expected a number, but found nothing !!");} |
8304 | schaersvoo | 6220 | if( found_calc == 1 ){ /* use wims eval to calculate 2*pi/3 */ |
7848 | bpr | 6221 | void *f = eval_create(tmp); |
7614 | schaersvoo | 6222 | assert(f);if( f == NULL ){canvas_error("I'm having trouble parsing your \"expression\" ") ;} |
7848 | bpr | 6223 | y = eval_x(f, 1); |
14066 | bpr | 6224 | /* if function is bogus; y = 1: so no core dumps */ |
7848 | bpr | 6225 | eval_destroy(f); |
7614 | schaersvoo | 6226 | } |
6227 | else |
||
6228 | { |
||
6229 | y = atof(tmp); |
||
6230 | } |
||
6231 | return y; |
||
6232 | } |
||
8304 | schaersvoo | 6233 | |
13829 | bpr | 6234 | |
7614 | schaersvoo | 6235 | void canvas_error(char *msg){ |
15722 | obado | 6236 | fprintf(stdout,"\n</script><hr /><span style=\"color:red\">FATAL syntax error: line %d: %s</span><hr />",line_number,msg); |
7614 | schaersvoo | 6237 | finished = 1; |
6238 | exit(EXIT_SUCCESS); |
||
6239 | } |
||
6240 | |||
6241 | |||
6242 | /* convert x/y coordinates to pixel */ |
||
6243 | int x2px(double x){ |
||
6244 | return x*xsize/(xmax - xmin) - xsize*xmin/(xmax - xmin); |
||
6245 | } |
||
6246 | |||
6247 | int y2px(double y){ |
||
6248 | return -1*y*ysize/(ymax - ymin) + ymax*ysize/(ymax - ymin); |
||
6249 | } |
||
6250 | |||
6251 | double px2x(int x){ |
||
6252 | return (x*(xmax - xmin)/xsize + xmin); |
||
6253 | } |
||
6254 | double px2y(int y){ |
||
6255 | return (y*(ymax - ymin)/ysize + ymin); |
||
6256 | } |
||
6257 | |||
6258 | void add_to_buffer(char *tmp){ |
||
15111 | schaersvoo | 6259 | //fprintf(stdout,"tmp = %s<br />buffer = %s<br />",tmp,buffer); |
7614 | schaersvoo | 6260 | if( tmp == NULL || tmp == 0 ){ canvas_error("nothing to add_to_buffer()...");} |
6261 | /* do we have enough space left in buffer[MAX_BUFFER] ? */ |
||
6262 | int space_left = (int) (sizeof(buffer) - strlen(buffer)); |
||
6263 | if( space_left > strlen(tmp)){ |
||
6264 | strncat(buffer,tmp,space_left - 1);/* add safely "tmp" to the string buffer */ |
||
6265 | } |
||
6266 | else |
||
6267 | { |
||
15111 | schaersvoo | 6268 | canvas_error("your memory buffer is too big<br />simplify your script...it produces too many lines "); |
7614 | schaersvoo | 6269 | } |
6270 | tmp = NULL;free(tmp); |
||
6271 | return; |
||
6272 | } |
||
6273 | |||
6274 | void reset(){ |
||
15111 | schaersvoo | 6275 | if(no_reset == FALSE){ /* 8/5/2020 */ |
6276 | use_filled = FALSE; |
||
6277 | use_dashed = FALSE; |
||
6278 | if(onclick != 4 ){onclick = 0;} /* slider param 'active'... onclick=4 */ |
||
6279 | drag_type = -1; |
||
6280 | use_offset = 0; |
||
15601 | schaersvoo | 6281 | } |
7614 | schaersvoo | 6282 | } |
6283 | |||
15111 | schaersvoo | 6284 | char *getMML(char *tex){ |
6285 | int my_pipe[2];pid_t pid; |
||
6286 | if(pipe(my_pipe)){canvas_error("mathml(): pipe() failure.\n");} |
||
6287 | pid = fork(); |
||
6288 | if (pid == (pid_t) 0){ |
||
6289 | char *argv[]={"wims_mathml","--use-zoom","0","--tex-size 100%","--max-mml-size","1024","--tex-string",tex,NULL}; |
||
6290 | close(my_pipe[0]);dup2(my_pipe[1], 1);dup2(my_pipe[1], 2);close(my_pipe[1]); |
||
6291 | execv("../bin/wims_mathml",argv);canvas_error("could not execute wims_mathml\n"); |
||
6292 | } |
||
6293 | else |
||
15116 | bpr | 6294 | { |
15111 | schaersvoo | 6295 | if (pid < (pid_t) 0){ |
15116 | bpr | 6296 | close(my_pipe[0]);close(my_pipe[1]);canvas_error("mathml(): fork() failure.\n"); |
15111 | schaersvoo | 6297 | } |
6298 | int status;FILE *stream;close(my_pipe[1]);stream = fdopen (my_pipe[0], "r"); |
||
6299 | char buffer[MAX_BUFFER+1];memset(buffer,'\0',MAX_BUFFER); |
||
6300 | fgets(buffer, MAX_BUFFER, stream); |
||
6301 | int L0 = 1 + snprintf(NULL,0,"%s", buffer); |
||
6302 | tex = my_newmem(L0);memset(tex,'\0',L0); |
||
6303 | snprintf(tex,L0,"%s",buffer); |
||
15116 | bpr | 6304 | fclose (stream);close(my_pipe[0]);waitpid(pid, &status, 0); |
15111 | schaersvoo | 6305 | } |
6306 | return tex; |
||
6307 | } |
||
7614 | schaersvoo | 6308 | |
15111 | schaersvoo | 6309 | char *getSVGMOL(char *inputtype,char *keys){ |
6310 | int idx; |
||
6311 | char *forbidden[] = {"-O","-H","-z","-L","-o","-m"}; |
||
6312 | char *argv[1+strlen(keys)]; |
||
6313 | argv[0] = "obabel"; argv[1] = "-i"; argv[2] = inputtype; |
||
6314 | idx = 3;int i; |
||
6315 | char *ptr = strtok(keys,","); |
||
6316 | while(ptr != NULL ){ |
||
6317 | for(i = 0 ; i < 6; i++ ){if( strncmp(ptr,forbidden[i],2) == 0 ){return "NOT ALLOWED ARGUMENT";}} |
||
6318 | argv[idx] = ptr; idx++; |
||
6319 | if(idx > 18){canvas_error("too many arguments for obabel....see docs<br />");} |
||
6320 | ptr = strtok(NULL,","); |
||
6321 | } |
||
6322 | /* last arguments; no 'javascript', only 'svg to STDOUT' and 'NULL' */ |
||
6323 | argv[idx] = "-xj";argv[idx+1] = "-o"; argv[idx+2] = "svg";argv[idx+3] = NULL; |
||
6324 | int link[2]; |
||
6325 | pid_t pid; |
||
6326 | char buffer[MAX_BUFFER+1]; |
||
6327 | memset(buffer,'\0',MAX_BUFFER); |
||
6328 | if (pipe(link)==-1){canvas_error("pipe");} |
||
6329 | if ((pid = fork()) == -1){canvas_error("fork");} |
||
15116 | bpr | 6330 | |
15111 | schaersvoo | 6331 | char *svgmol = "error"; |
6332 | int string_length = 0; |
||
15116 | bpr | 6333 | |
15111 | schaersvoo | 6334 | if(pid == 0) { |
6335 | dup2 (link[1], STDOUT_FILENO); |
||
6336 | dup2(link[0], STDERR_FILENO);/* remove annoying messages '1 molecule converted' */ |
||
6337 | close(link[0]); |
||
6338 | close(link[1]); |
||
6339 | execvp("obabel",argv); |
||
6340 | } else { |
||
6341 | close(link[1]); |
||
6342 | read(link[0],buffer, 1+sizeof(buffer)); |
||
6343 | close(link[0]); |
||
6344 | /* need to remover newline from svg-string on freebsd */ |
||
6345 | char *pch = strstr(buffer, "\n"); |
||
6346 | while(pch != NULL){ |
||
6347 | strncpy(pch, " ", 1); |
||
6348 | pch = strstr(buffer, "\n"); |
||
6349 | } |
||
6350 | string_length = 1 + snprintf(NULL,0,"%s",buffer); |
||
6351 | svgmol= my_newmem(string_length); |
||
6352 | snprintf(svgmol,string_length,"%s",buffer); |
||
6353 | wait(NULL); |
||
6354 | } |
||
6355 | return svgmol; |
||
6356 | } |
||
7614 | schaersvoo | 6357 | |
6358 | |||
15111 | schaersvoo | 6359 | /* GNU libmatheval library for evaluating mathematical functions. */ |
15601 | schaersvoo | 6360 | char *eval(int xsize,int ysize,char *fun,double xmin,double xmax,double ymin,double ymax,int plotsteps,int precision,double rotationcenter[]){ |
15111 | schaersvoo | 6361 | void *f; |
6362 | double x; |
||
6363 | double y; |
||
15601 | schaersvoo | 6364 | double xorg; |
15111 | schaersvoo | 6365 | int xv; |
6366 | int i = 0; |
||
6367 | int xstep =(int)(xsize/plotsteps); |
||
6368 | if( xstep == 0 ){xstep = 1;} |
||
6369 | double a = (xmax - xmin)/xsize; |
||
6370 | f = eval_create(fun); |
||
6371 | assert (f); |
||
6372 | if( f == NULL ){canvas_error("I'm having trouble parsing your \"expression\" ") ;} |
||
6373 | /* we supply the true x/y values...draw_curve() will convert these (x:y) to pixels : used for pan/scale */ |
||
6374 | double xydata[MAX_BUFFER+1];/* hmmm */ |
||
6375 | int lim_ymin =(int)( ymin - 4*fabs(ymin));/* 19-4-2015 replacing "abs" by "fabs"*/ |
||
6376 | int lim_ymax =(int)( ymax + 4*fabs(ymax));/* 19-4-2015 replacing "abs" by "fabs"*/ |
||
15669 | schaersvoo | 6377 | double c = 1.0;double s = 1.0; |
15601 | schaersvoo | 6378 | if( use_rotate == TRUE ){s = sin(angle*0.0174533);c = cos(angle*0.0174533);} |
15111 | schaersvoo | 6379 | for ( xv = 0 ;xv < xsize ; xv = xv+xstep ){ |
6380 | x = (double) (xv*a + xmin); |
||
15601 | schaersvoo | 6381 | xorg = x; |
15111 | schaersvoo | 6382 | if( i < MAX_BUFFER - 2){ |
6383 | y = eval_x(f, x); |
||
6384 | if(y < lim_ymax && y > lim_ymin ){ |
||
15540 | schaersvoo | 6385 | if( use_affine == TRUE ){ |
6386 | x = x*affine_matrix[0] + y*affine_matrix[1]+affine_matrix[4]; |
||
15601 | schaersvoo | 6387 | y = xorg*affine_matrix[2] + y*affine_matrix[3]+affine_matrix[5]; |
15540 | schaersvoo | 6388 | } |
15601 | schaersvoo | 6389 | if( use_rotate == TRUE){ |
6390 | x = (c * (x - rotationcenter[0])) + (s * (y - rotationcenter[1])) + rotationcenter[0]; |
||
6391 | y = (c * (y - rotationcenter[1])) - (s * (xorg - rotationcenter[0])) + rotationcenter[1]; |
||
6392 | } |
||
15111 | schaersvoo | 6393 | xydata[i++] = x; |
6394 | xydata[i++] = y; |
||
6395 | } |
||
6396 | } |
||
6397 | else |
||
6398 | { |
||
6399 | canvas_error("\nYour curve plotting produces too many data \n Use less plotsteps or some other means to reduce the amount of data... "); |
||
6400 | } |
||
6401 | } |
||
6402 | eval_destroy(f); |
||
6403 | return double_xy2js_array(xydata,i,find_number_of_digits(precision)); |
||
6404 | } |
||
6405 | /* plot a very primitive (!) levelcurve : not to be compared with "flydraw levelcurve" */ |
||
6406 | char *eval_levelcurve(int xsize,int ysize,char *fun,double xmin,double xmax,double ymin,double ymax,int plotsteps,int precision,double level){ |
||
6407 | void *f = eval_create(fun); |
||
6408 | assert (f); |
||
6409 | if( f == NULL ){canvas_error("I'm having trouble parsing your \"expression\" ") ;} |
||
6410 | double a = (double)((xmax - xmin)/plotsteps); |
||
6411 | double b = (double)((ymax - ymin)/plotsteps); |
||
15669 | schaersvoo | 6412 | double x;double y;double diff; |
15111 | schaersvoo | 6413 | double xydata[MAX_BUFFER+1]; |
6414 | int i = 0; |
||
6415 | ymin = ymin - 1; |
||
6416 | xmin = xmin - 1; |
||
6417 | ymax = ymax + 1; |
||
6418 | xmax = xmax + 1; |
||
6419 | for( x = xmin ;x < xmax ; x = x + a ){ |
||
6420 | for ( y = ymin ;y < ymax ; y = y + b ){ |
||
6421 | if( i < MAX_BUFFER - 2){ |
||
6422 | diff = level - eval_x_y(f, x,y); |
||
6423 | if(diff < 0.1 && diff > -0.1){ |
||
6424 | xydata[i++] = x; |
||
6425 | xydata[i++] = y; |
||
6426 | } |
||
6427 | } |
||
6428 | else |
||
6429 | { |
||
6430 | 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... "); |
||
6431 | } |
||
6432 | } |
||
6433 | } |
||
6434 | eval_destroy(f); |
||
6435 | return double_xy2js_array(xydata,i,find_number_of_digits(precision)); |
||
6436 | } |
||
7614 | schaersvoo | 6437 | |
15111 | schaersvoo | 6438 | /* plot parametric function */ |
6439 | char *eval_parametric(int xsize,int ysize,char *fun1,char* fun2,double xmin,double xmax,double ymin,double ymax, |
||
15601 | schaersvoo | 6440 | double tmin,double tmax,int plotsteps,int precision,double rotationcenter[]){ |
15111 | schaersvoo | 6441 | void *fx; |
6442 | void *fy; |
||
6443 | double t; |
||
6444 | int i = 0; |
||
6445 | double tstep = (tmax-tmin)/plotsteps; |
||
6446 | if( tstep == 0 ){canvas_error("zero step for t variable : reduce plotsteps or inrease trange");} |
||
6447 | fx = eval_create(fun1); |
||
6448 | fy = eval_create(fun2); |
||
6449 | assert(fx); |
||
6450 | assert(fy); |
||
6451 | if( fx == NULL || fy == NULL ){canvas_error("I'm having trouble parsing your \"expression\" ") ;} |
||
6452 | /* we supply the true x/y values...draw_curve() will convert these (x:y) to pixels : used for pan/scale */ |
||
6453 | double xydata[MAX_BUFFER+1];/* hmmm */ |
||
6454 | double x; /* real x-values */ |
||
6455 | double y; /* real y-values */ |
||
15601 | schaersvoo | 6456 | double xorg; |
15623 | schaersvoo | 6457 | /* |
6458 | 29/12/2020 |
||
15633 | bpr | 6459 | disabled to try and synchronise curve+affine behaviour in complex scripts produced by "elec, tool circuit" (BPR) |
15623 | schaersvoo | 6460 | int lim_ymin =(int)( ymin - 4*fabs(ymin)); |
6461 | int lim_ymax =(int)( ymax + 4*fabs(ymax)); |
||
6462 | */ |
||
15669 | schaersvoo | 6463 | double c = 1.0;double s = 1.0;if( use_rotate == TRUE ){s = sin(angle*0.0174533);c = cos(angle*0.0174533);} |
15111 | schaersvoo | 6464 | for( t = tmin ;t <= tmax ; t = t + tstep ){ |
6465 | if( i < MAX_BUFFER - 2 ){ |
||
6466 | y = eval_t(fy, t); |
||
15623 | schaersvoo | 6467 | /* if(y > lim_ymin && y < lim_ymax){*/ |
15111 | schaersvoo | 6468 | x = eval_t(fx, t); |
15628 | schaersvoo | 6469 | if( x == x){ /* no NaN */ |
6470 | xorg = x; |
||
6471 | if( use_affine == TRUE ){ |
||
6472 | x = x*affine_matrix[0] + y*affine_matrix[1]+affine_matrix[4]; |
||
6473 | y = xorg*affine_matrix[2] + y*affine_matrix[3]+affine_matrix[5]; |
||
6474 | } |
||
6475 | if( use_rotate == TRUE){ |
||
6476 | x = (c * (x - rotationcenter[0])) + (s * (y - rotationcenter[1])) + rotationcenter[0]; |
||
6477 | y = (c * (y - rotationcenter[1])) - (s * (xorg - rotationcenter[0])) + rotationcenter[1]; |
||
6478 | } |
||
6479 | xydata[i++] = x; |
||
6480 | xydata[i++] = y; |
||
15540 | schaersvoo | 6481 | } |
15629 | bpr | 6482 | |
15623 | schaersvoo | 6483 | /* } */ |
15111 | schaersvoo | 6484 | } |
6485 | else |
||
6486 | { |
||
6487 | canvas_error("\nYour curve plotting produces too many data \n Use less plotsteps or some other means to reduce the amount of data... "); |
||
6488 | } |
||
6489 | } |
||
6490 | eval_destroy(fx); |
||
6491 | eval_destroy(fy); |
||
6492 | return double_xy2js_array(xydata,i,find_number_of_digits(precision)); |
||
6493 | } |
||
7614 | schaersvoo | 6494 | |
15111 | schaersvoo | 6495 | char *double_xy2js_array(double xy[],int len,int decimals){ |
6496 | /* |
||
6497 | 1,2,3,4,5,6,7,8 --> [1,3,5,7],[2,4,6,8] |
||
6498 | int xy[] is already checked for errors or overflow in "get_real()" |
||
6499 | just to be sure we double check the size of "temp" |
||
7614 | schaersvoo | 6500 | */ |
15111 | schaersvoo | 6501 | char temp[2*MAX_BUFFER], *string; |
6502 | char *tmp = my_newmem(16);/* <= 9999999999999999 */ |
||
6503 | memset(temp,'\0',2*MAX_BUFFER);/* clear memory */ |
||
6504 | int i;int space_left; |
||
6505 | temp[0] = '[';/* start js-array */ |
||
6506 | for(i = 0; i < len;i = i + 2){ /* x_points[] */ |
||
6507 | if(i == len - 2){sprintf(tmp, "%.*f",decimals, xy[i]);}else{sprintf(tmp, "%.*f,",decimals,xy[i]);} |
||
6508 | space_left = (int) (sizeof(temp) - strlen(temp) - strlen(tmp) - 1); |
||
6509 | 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 ");} |
||
6510 | } |
||
6511 | strncat(temp,"],[",4); /* close js x_values array and start new */ |
||
6512 | for(i = 1; i < len;i = i + 2){ /* y_points */ |
||
6513 | if(i == len - 1){ sprintf(tmp, "%.*f",decimals,xy[i]);}else{sprintf(tmp, "%.*f,",decimals,xy[i]);} |
||
6514 | space_left = (int) (sizeof(temp) - strlen(temp) - strlen(tmp) - 1); |
||
6515 | 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");} |
||
6516 | } |
||
6517 | strncat(temp,"]",2); |
||
6518 | string=(char *)my_newmem(sizeof(temp)); |
||
6519 | snprintf(string,sizeof(temp),"%s",temp); |
||
6520 | return string; |
||
6521 | } |
||
7614 | schaersvoo | 6522 | |
15111 | schaersvoo | 6523 | char *list2js_array(char *list, char *s){/* abc:defg:hjiuy:qwer --> ["abc","defg","hjiuy","qwer"] */ |
6524 | #define MAX_ARG 128 |
||
15116 | bpr | 6525 | if( strlen(list)> MAX_ARG - 1){canvas_error("argument is too large (> 128)");} |
15111 | schaersvoo | 6526 | char tmp[MAX_ARG]; |
6527 | size_t p = 0; |
||
6528 | tmp[0] = '['; |
||
6529 | tmp[1] = '\"'; |
||
6530 | size_t t = 2; |
||
6531 | while(list[p] != '\0'){ |
||
6532 | if( list[p] == s[0] ){ |
||
6533 | tmp[t++]='\"';tmp[t++]=',';tmp[t++]='\"'; |
||
6534 | } |
||
6535 | else |
||
6536 | { |
||
6537 | tmp[t++] = list[p]; |
||
6538 | } |
||
6539 | p++; |
||
6540 | } |
||
6541 | tmp[t++]='\"';tmp[t++]=']';tmp[t++]= '\0'; |
||
6542 | char *js_array = (char *)my_newmem(sizeof(tmp)); |
||
6543 | snprintf(js_array,sizeof(tmp),"%s",tmp); |
||
6544 | return js_array; |
||
6545 | } |
||
7963 | schaersvoo | 6546 | |
15111 | schaersvoo | 6547 | char *xy2js_array(int xy[],int len){ |
6548 | /* |
||
6549 | 1,2,3,4,5,6,7,8 --> [1,3,5,7],[2,4,6,8] |
||
6550 | int xy[] is already checked for errors or overflow in "get_real()" |
||
6551 | just to be sure we double check the size of "temp" |
||
7614 | schaersvoo | 6552 | */ |
15111 | schaersvoo | 6553 | char temp[MAX_BUFFER], *string; |
6554 | char *tmp = my_newmem(16);/* <= 9999999999999999 */ |
||
6555 | memset(temp,'\0',MAX_BUFFER);/* clear memory */ |
||
6556 | int i;int space_left; |
||
6557 | temp[0] = '[';/* start js-array */ |
||
6558 | for(i = 0; i < len;i = i + 2){ /* x_points[] */ |
||
6559 | if(i == len - 2){sprintf(tmp, "%d", xy[i]);}else{sprintf(tmp, "%d,", xy[i]);} |
||
6560 | space_left = (int) (sizeof(temp) - strlen(temp) - strlen(tmp) - 1); |
||
6561 | 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 ");} |
||
6562 | } |
||
6563 | strncat(temp,"],[",4); /* close js x_values array and start new */ |
||
6564 | for(i = 1; i < len;i = i + 2){ /* y_points */ |
||
6565 | if(i == len - 1){ sprintf(tmp, "%d", xy[i]);}else{sprintf(tmp, "%d,", xy[i]);} |
||
6566 | space_left = (int) (sizeof(temp) - strlen(temp) - strlen(tmp) - 1); |
||
6567 | 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");} |
||
6568 | } |
||
6569 | strncat(temp,"]",2); |
||
6570 | string=(char *)my_newmem(sizeof(temp)); |
||
6571 | snprintf(string,sizeof(temp),"%s",temp); |
||
6572 | return string; |
||
7614 | schaersvoo | 6573 | } |
6574 | |||
15111 | schaersvoo | 6575 | char *data2js_array(int data[],int len){ |
6576 | /* |
||
6577 | 1,2,3,4,5,6,7,8 --> [1,2,3,4,5,6,7,8] |
||
6578 | int data[] is already checked for errors or overflow in "get_real()" |
||
6579 | just to be sure we double check the size of "temp" |
||
7614 | schaersvoo | 6580 | */ |
15111 | schaersvoo | 6581 | char temp[MAX_BUFFER], *string; |
6582 | char *tmp = my_newmem(16);/* <= 9999999999999999 */ |
||
6583 | memset(temp,'\0',MAX_BUFFER);/* clear memory */ |
||
6584 | int i;int space_left; |
||
6585 | temp[0] = '[';/* start js-array */ |
||
6586 | for(i = 0; i < len; i++){ |
||
6587 | if(i == len - 1){sprintf(tmp, "%d", data[i]);}else{sprintf(tmp, "%d,", data[i]);} |
||
6588 | space_left = (int) (sizeof(temp) - strlen(temp) - strlen(tmp) - 1); |
||
6589 | 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 ");} |
||
6590 | } |
||
6591 | strncat(temp,"]",2); |
||
6592 | string=(char *)my_newmem(sizeof(temp)); |
||
6593 | snprintf(string,sizeof(temp),"%s",temp); |
||
6594 | return string; |
||
6595 | } |
||
7614 | schaersvoo | 6596 | |
15111 | schaersvoo | 6597 | char *doubledata2js_array(double data[],int len, int decimals){ |
6598 | /* |
||
15116 | bpr | 6599 | 1.4355,2.345353,3.3455 --> [1.44,2.35,3.35] |
15111 | schaersvoo | 6600 | double data[] is already checked for errors or overflow in "get_real()" |
6601 | just to be sure we double check the size of "temp" |
||
8448 | schaersvoo | 6602 | */ |
15111 | schaersvoo | 6603 | char temp[MAX_BUFFER], *string; |
6604 | char *tmp = my_newmem(16);/* <= 9999999999999999 */ |
||
6605 | memset(temp,'\0',MAX_BUFFER);/* clear memory */ |
||
6606 | int i;int space_left; |
||
6607 | temp[0] = '[';/* start js-array */ |
||
6608 | for(i = 0; i < len; i++){ |
||
6609 | if(i == len - 1){sprintf(tmp, "%.*f",decimals,data[i]);}else{sprintf(tmp, "%.*f,",decimals,data[i]);} |
||
6610 | space_left = (int) (sizeof(temp) - strlen(temp) - strlen(tmp) - 1); |
||
6611 | 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 ");} |
||
6612 | } |
||
6613 | strncat(temp,"]",2); |
||
6614 | string=(char *)my_newmem(sizeof(temp)); |
||
6615 | snprintf(string,sizeof(temp),"%s",temp); |
||
6616 | return string; |
||
6617 | } |
||
13829 | bpr | 6618 | |
8224 | bpr | 6619 | |
15111 | schaersvoo | 6620 | void *my_newmem(size_t size){ |
6621 | void *p; |
||
6622 | if((p = malloc(size +1)) == NULL){canvas_error("canvasdraw: ran out of memory\n");} |
||
6623 | return p; |
||
6624 | } |
||
8224 | bpr | 6625 | |
15111 | schaersvoo | 6626 | int find_number_of_digits(int i){ |
6627 | if(i < 0 ){ i = -1*i;} |
||
6628 | int digits = 0; |
||
6629 | while ( i > 0){ |
||
6630 | digits++; |
||
6631 | i = i/10; |
||
6632 | } |
||
6633 | return digits; |
||
6634 | } |
||
7645 | schaersvoo | 6635 | |
16828 | schaersvoo | 6636 | int count_substring(char* string, char* substring) { |
6637 | int i, j, l1, l2; |
||
6638 | int count = 0; |
||
6639 | l1 = strlen(string); |
||
6640 | l2 = strlen(substring); |
||
6641 | for(i = 0; i < l1 - l2 + 1; i++) { |
||
6642 | if(strstr(string + i, substring) == string + i) { |
||
6643 | count++; |
||
6644 | i = i + l2 -1; |
||
6645 | } |
||
6646 | } |
||
6647 | return count; |
||
6648 | } |
||
11830 | schaersvoo | 6649 | |
8224 | bpr | 6650 | |
6651 | |||
7614 | schaersvoo | 6652 | void check_string_length(int L){ |
9466 | schaersvoo | 6653 | if( L > MAX_BUFFER-1){ |
7614 | schaersvoo | 6654 | canvas_error("problem with your arguments to command..."); |
6655 | } |
||
6656 | return; |
||
6657 | } |
||
6658 | |||
6659 | int get_token(FILE *infile){ |
||
6660 | int c,i=0; |
||
6661 | char temp[MAX_INT], *input_type; |
||
6662 | char *line="line", |
||
6663 | *audio="audio", |
||
6664 | *blink="blink", |
||
6665 | *arrowhead="arrowhead", |
||
6666 | *crosshairsize="crosshairsize", |
||
6667 | *crosshair="crosshair", |
||
6668 | *crosshairs="crosshairs", |
||
6669 | *audioobject="audioobject", |
||
6670 | *style="style", |
||
6671 | *mouse="mouse", |
||
7991 | schaersvoo | 6672 | *mousex="mousex", |
6673 | *mousey="mousey", |
||
8071 | schaersvoo | 6674 | *mouse_display="display", |
6675 | *mouse_degree="mouse_degree", |
||
7614 | schaersvoo | 6676 | *userdraw="userdraw", |
6677 | *highlight="highlight", |
||
6678 | *http="http", |
||
6679 | *rays="rays", |
||
6680 | *dashtype="dashtype", |
||
6681 | *dashed="dashed", |
||
6682 | *filled="filled", |
||
6683 | *lattice="lattice", |
||
6684 | *parallel="parallel", |
||
6685 | *segment="segment", |
||
8299 | schaersvoo | 6686 | *segments="segments", |
7614 | schaersvoo | 6687 | *dsegment="dsegment", |
9374 | schaersvoo | 6688 | *dsegments="dsegments", |
7614 | schaersvoo | 6689 | *seg="seg", |
9383 | schaersvoo | 6690 | *segs="segs", |
7614 | schaersvoo | 6691 | *bgimage="bgimage", |
6692 | *bgcolor="bgcolor", |
||
6693 | *strokecolor="strokecolor", |
||
6694 | *backgroundimage="backgroundimage", |
||
6695 | *text="text", |
||
6696 | *textup="textup", |
||
6697 | *mouseprecision="mouseprecision", |
||
6698 | *precision="precision", |
||
6699 | *plotsteps="plotsteps", |
||
6700 | *plotstep="plotstep", |
||
6701 | *tsteps="tsteps", |
||
6702 | *curve="curve", |
||
6703 | *dcurve="dcurve", |
||
14038 | schaersvoo | 6704 | *curvedarrow="curvedarrow", |
6705 | *curvedarrows="curvedarrows", |
||
6706 | *curvedarrow2="curvedarrow2", |
||
6707 | *curvedarrows2="curvedarrows2", |
||
7614 | schaersvoo | 6708 | *plot="plot", |
6709 | *dplot="dplot", |
||
7788 | schaersvoo | 6710 | *levelcurve="levelcurve", |
7614 | schaersvoo | 6711 | *fontsize="fontsize", |
6712 | *fontcolor="fontcolor", |
||
6713 | *axis="axis", |
||
6714 | *axisnumbering="axisnumbering", |
||
6715 | *axisnumbers="axisnumbers", |
||
6716 | *arrow="arrow", |
||
9382 | schaersvoo | 6717 | *vector="vector", |
6718 | *vectors="vectors", |
||
7614 | schaersvoo | 6719 | *darrow="darrow", |
6720 | *arrow2="arrow2", |
||
6721 | *darrow2="darrow2", |
||
8304 | schaersvoo | 6722 | *arrows="arrows", |
8347 | schaersvoo | 6723 | *arrows2="arrows2", |
7614 | schaersvoo | 6724 | *zoom="zoom", |
6725 | *grid="grid", |
||
6726 | *hline="hline", |
||
7786 | schaersvoo | 6727 | *dhline="dhline", |
7614 | schaersvoo | 6728 | *drag="drag", |
6729 | *horizontalline="horizontalline", |
||
9383 | schaersvoo | 6730 | *horizontallines="horizontallines", |
7614 | schaersvoo | 6731 | *vline="vline", |
7786 | schaersvoo | 6732 | *dvline="dvline", |
7614 | schaersvoo | 6733 | *verticalline="verticalline", |
9383 | schaersvoo | 6734 | *verticallines="verticallines", |
7614 | schaersvoo | 6735 | *triangle="triangle", |
9306 | schaersvoo | 6736 | *triangles="triangles", |
7614 | schaersvoo | 6737 | *ftriangle="ftriangle", |
9374 | schaersvoo | 6738 | *ftriangles="ftriangles", |
7614 | schaersvoo | 6739 | *mathml="mathml", |
6740 | *html="html", |
||
6741 | *input="input", |
||
8146 | schaersvoo | 6742 | *clearbutton="clearbutton", |
9386 | schaersvoo | 6743 | *erase="erase", |
6744 | *delete="delete", |
||
15111 | schaersvoo | 6745 | *css="css", |
7614 | schaersvoo | 6746 | *textarea="textarea", |
15773 | schaersvoo | 6747 | *range="range", |
7614 | schaersvoo | 6748 | *trange="trange", |
6749 | *ranget="ranget", |
||
6750 | *xrange="xrange", |
||
6751 | *yrange="yrange", |
||
6752 | *rangex="rangex", |
||
6753 | *rangey="rangey", |
||
8370 | schaersvoo | 6754 | *path="path", |
7614 | schaersvoo | 6755 | *polyline="polyline", |
8351 | schaersvoo | 6756 | *brokenline="brokenline", |
7614 | schaersvoo | 6757 | *lines="lines", |
6758 | *poly="poly", |
||
6759 | *polygon="polygon", |
||
6760 | *fpolygon="fpolygon", |
||
6761 | *fpoly="fpoly", |
||
6762 | *filledpoly="filledpoly", |
||
6763 | *filledpolygon="filledpolygon", |
||
6764 | *rect="rect", |
||
6765 | *frect="frect", |
||
6766 | *rectangle="rectangle", |
||
6767 | *frectangle="frectangle", |
||
6768 | *square="square", |
||
6769 | *fsquare="fsquare", |
||
9374 | schaersvoo | 6770 | *fsquares="fsquares", |
8363 | schaersvoo | 6771 | *rects="rects", |
6772 | *frects="frects", |
||
7614 | schaersvoo | 6773 | *dline="dline", |
6774 | *arc="arc", |
||
6775 | *filledarc="filledarc", |
||
9374 | schaersvoo | 6776 | *farc="farc", |
7614 | schaersvoo | 6777 | *size="size", |
6778 | *string="string", |
||
6779 | *stringup="stringup", |
||
6780 | *copy="copy", |
||
6781 | *copyresized="copyresized", |
||
6782 | *opacity="opacity", |
||
6783 | *transparent="transparent", |
||
6784 | *fill="fill", |
||
6785 | *point="point", |
||
6786 | *points="points", |
||
6787 | *linewidth="linewidth", |
||
6788 | *circle="circle", |
||
8304 | schaersvoo | 6789 | *circles="circles", |
7614 | schaersvoo | 6790 | *fcircle="fcircle", |
9374 | schaersvoo | 6791 | *fcircles="fcircles", |
7614 | schaersvoo | 6792 | *disk="disk", |
9374 | schaersvoo | 6793 | *disks="disks", |
7614 | schaersvoo | 6794 | *comment="#", |
6795 | *end="end", |
||
6796 | *ellipse="ellipse", |
||
12110 | schaersvoo | 6797 | *ellipses="ellipses", |
7614 | schaersvoo | 6798 | *fellipse="fellipse", |
6799 | *rotate="rotate", |
||
7785 | schaersvoo | 6800 | *affine="affine", |
9907 | schaersvoo | 6801 | *rotationcenter="rotationcenter", |
15716 | schaersvoo | 6802 | *kill="kill", |
9907 | schaersvoo | 6803 | *killrotate="killrotate", |
7785 | schaersvoo | 6804 | *killaffine="killaffine", |
15111 | schaersvoo | 6805 | *killlinear="killlinear", |
6806 | *killinear="killinear", |
||
7614 | schaersvoo | 6807 | *fontfamily="fontfamily", |
6808 | *fillcolor="fillcolor", |
||
6809 | *clicktile="clicktile", |
||
6810 | *clicktile_colors="clicktile_colors", |
||
6811 | *translation="translation", |
||
6812 | *translate="translate", |
||
6813 | *killtranslation="killtranslation", |
||
6814 | *killtranslate="killtranslate", |
||
6815 | *onclick="onclick", |
||
8370 | schaersvoo | 6816 | *roundrects="roundrects", |
7614 | schaersvoo | 6817 | *roundrect="roundrect", |
6818 | *froundrect="froundrect", |
||
9374 | schaersvoo | 6819 | *froundrects="froundrects", |
7614 | schaersvoo | 6820 | *roundrectangle="roundrectangle", |
6821 | *patternfill="patternfill", |
||
6822 | *hatchfill="hatchfill", |
||
6823 | *diafill="diafill", |
||
7647 | schaersvoo | 6824 | *diamondfill="diamondfill", |
7614 | schaersvoo | 6825 | *dotfill="dotfill", |
11830 | schaersvoo | 6826 | *textfill="textfill", |
7614 | schaersvoo | 6827 | *gridfill="gridfill", |
6828 | *imagefill="imagefill", |
||
7735 | schaersvoo | 6829 | *xlogbase="xlogbase", |
6830 | *ylogbase="ylogbase", |
||
7614 | schaersvoo | 6831 | *xlogscale="xlogscale", |
6832 | *ylogscale="ylogscale", |
||
6833 | *xylogscale="xylogscale", |
||
6834 | *intooltip="intooltip", |
||
9329 | schaersvoo | 6835 | *popup="popup", |
7614 | schaersvoo | 6836 | *replyformat="replyformat", |
6837 | *floodfill="floodfill", |
||
11772 | schaersvoo | 6838 | *fillall="fillall", |
7614 | schaersvoo | 6839 | *filltoborder="filltoborder", |
6840 | *setpixel="setpixel", |
||
6841 | *pixels="pixels", |
||
6842 | *pixelsize="pixelsize", |
||
6843 | *xaxis="xaxis", |
||
9341 | schaersvoo | 6844 | *xaxisup="xaxisup", |
7614 | schaersvoo | 6845 | *yaxis="yaxis", |
6846 | *xaxistext="xaxistext", |
||
9341 | schaersvoo | 6847 | *xaxistextup="xaxistextup", |
7614 | schaersvoo | 6848 | *yaxistext="yaxistext", |
6849 | *piechart="piechart", |
||
9433 | schaersvoo | 6850 | *boxplot="boxplot", |
9465 | schaersvoo | 6851 | *boxplotdata="boxplotdata", |
6852 | *userboxplot="userboxplot", |
||
6853 | *userboxplotdata="userboxplotdata", |
||
7614 | schaersvoo | 6854 | *legend="legend", |
6855 | *legendcolors="legendcolors", |
||
6856 | *xlabel="xlabel", |
||
6857 | *ylabel="ylabel", |
||
6858 | *barchart="barchart", |
||
6859 | *linegraph="linegraph", |
||
6860 | *clock="clock", |
||
6861 | *animate="animate", |
||
6862 | *video="video", |
||
6863 | *status="status", |
||
7877 | schaersvoo | 6864 | *nostatus="nostatus", |
7652 | schaersvoo | 6865 | *snaptogrid="snaptogrid", |
7784 | schaersvoo | 6866 | *xsnaptogrid="xsnaptogrid", |
6867 | *ysnaptogrid="ysnaptogrid", |
||
8379 | schaersvoo | 6868 | *snaptopoints="snaptopoints", |
9213 | schaersvoo | 6869 | *snaptofunction="snaptofunction", |
6870 | *snaptofun="snaptofun", |
||
7654 | schaersvoo | 6871 | *userinput_xy="userinput_xy", |
8193 | schaersvoo | 6872 | *userinput_function="userinput_function", |
8222 | schaersvoo | 6873 | *userinput="userinput", |
7823 | schaersvoo | 6874 | *jsmath="jsmath", |
7858 | schaersvoo | 6875 | *trace_jscurve="trace_jscurve", |
7838 | schaersvoo | 6876 | *setlimits="setlimits", |
7858 | schaersvoo | 6877 | *jscurve="jscurve", |
6878 | *jsplot="jsplot", |
||
7983 | schaersvoo | 6879 | *sgraph="sgraph", |
7984 | schaersvoo | 6880 | *title="title", |
7996 | schaersvoo | 6881 | *centerstring="centerstring", |
6882 | *xunit="xunit", |
||
8071 | schaersvoo | 6883 | *yunit="yunit", |
8101 | schaersvoo | 6884 | *slider="slider", |
8105 | schaersvoo | 6885 | *killslider="killslider", |
8244 | schaersvoo | 6886 | *angle="angle", |
8365 | schaersvoo | 6887 | *halflines="halflines", |
6888 | *demilines="demilines", |
||
8244 | schaersvoo | 6889 | *halfline="halfline", |
8297 | schaersvoo | 6890 | *demiline="demiline", |
8366 | schaersvoo | 6891 | *hlines="hlines", |
6892 | *vlines="vlines", |
||
8370 | schaersvoo | 6893 | *bezier="bezier", |
9213 | schaersvoo | 6894 | *functionlabel="functionlabel", |
15313 | schaersvoo | 6895 | *functionlabels="functionlabels", |
9213 | schaersvoo | 6896 | *sliderfunction_x="sliderfunction_x", |
6897 | *sliderfunction_y="sliderfunction_y", |
||
6898 | *multidraw="multidraw", |
||
15111 | schaersvoo | 6899 | *multilinewidth="multilinewidth", |
14622 | schaersvoo | 6900 | *linewidths="linewidths", |
9213 | schaersvoo | 6901 | *multistrokecolors="multistrokecolors", |
15111 | schaersvoo | 6902 | *multicolors="multicolors", |
6903 | *strokecolors="strokecolors", |
||
14622 | schaersvoo | 6904 | *colors="colors", |
9213 | schaersvoo | 6905 | *multifillcolors="multifillcolors", |
14622 | schaersvoo | 6906 | *fillcolors="fillcolors", |
9213 | schaersvoo | 6907 | *multistrokeopacity="multistrokeopacity", |
6908 | *multifillopacity="multifillopacity", |
||
6909 | *multifill="multifill", |
||
6910 | *multidash="multidash", |
||
6911 | *multilabel="multilabel", |
||
6912 | *multiuserinput="multiuserinput", |
||
14038 | schaersvoo | 6913 | *multiinput="multiinput", |
9289 | schaersvoo | 6914 | *multisnaptogrid="multisnaptogrid", |
14038 | schaersvoo | 6915 | *multisnap="multisnap", |
9289 | schaersvoo | 6916 | *protractor="protractor", |
9386 | schaersvoo | 6917 | *ruler="ruler", |
6918 | *cursor="cursor", |
||
9427 | schaersvoo | 6919 | *pointer="pointer", |
6920 | *yerrorbars="yerrorbars", |
||
11006 | schaersvoo | 6921 | *xerrorbars="xerrorbars", |
11044 | schaersvoo | 6922 | *noxaxis="noxaxis", |
6923 | *noyaxis="noyaxis", |
||
11767 | schaersvoo | 6924 | *colorpalette="colorpalette", |
14038 | schaersvoo | 6925 | *imagepalette="imagepalette", |
12063 | schaersvoo | 6926 | *yoffset="yoffset", |
11802 | schaersvoo | 6927 | *xoffset="xoffset", |
14225 | schaersvoo | 6928 | *latex="latex", |
15111 | schaersvoo | 6929 | *katex="katex", |
6930 | *math="math", |
||
11802 | schaersvoo | 6931 | *centered="centered", |
6932 | *xyoffset="xyoffset", |
||
6933 | *resetoffset="resetoffset", |
||
11837 | schaersvoo | 6934 | *fillpattern="fillpattern", |
15601 | schaersvoo | 6935 | *settile="settile", |
11890 | schaersvoo | 6936 | *numberline="numberline", |
14393 | schaersvoo | 6937 | *duplicates="duplicates", |
6938 | *allowdups="allowdups", |
||
15111 | schaersvoo | 6939 | *linear="linear", |
6940 | *obabel="obabel", |
||
6941 | *chemtex="chemtex", |
||
6942 | *noreset="noreset", |
||
6943 | *killreset="killreset", |
||
15690 | schaersvoo | 6944 | *arrowarc="arrowarc", |
6945 | *arcarrow="arcarrow", |
||
11006 | schaersvoo | 6946 | *canvastype="canvastype"; |
7614 | schaersvoo | 6947 | |
10891 | schaersvoo | 6948 | while(((c = getc(infile)) != EOF)&&(c!='\n')&&(c!=',')&&(c!='=')&&(c!='\r')&&(c!='\t')){ |
6949 | if( i == 0 && (c == ' ') ){ continue; /* white spaces or tabs allowed before first command identifier */ |
||
6950 | }else{ |
||
6951 | if( c == ' ' ){ |
||
7614 | schaersvoo | 6952 | break; |
10891 | schaersvoo | 6953 | }else{ |
6954 | temp[i] = c; |
||
6955 | if(i > MAX_INT - 2){canvas_error("command string too long !");} |
||
6956 | i++; |
||
6957 | } |
||
6958 | } |
||
6959 | if(temp[0] == '#'){ break; } |
||
7614 | schaersvoo | 6960 | } |
10891 | schaersvoo | 6961 | if (c == '\n' || c == '\r' || c == '\t' ){ line_number++; } |
6962 | if (c == EOF) {finished=1;return 0;} |
||
7614 | schaersvoo | 6963 | |
6964 | temp[i]='\0'; |
||
6965 | input_type=(char*)my_newmem(strlen(temp)); |
||
6966 | snprintf(input_type,sizeof(temp),"%s",temp); |
||
10891 | schaersvoo | 6967 | /* fprintf(stdout,"temp = %s <br/>",input_type); */ |
7614 | schaersvoo | 6968 | if( strcmp(input_type, size) == 0 ){ |
6969 | free(input_type); |
||
6970 | return SIZE; |
||
6971 | } |
||
15773 | schaersvoo | 6972 | if( strcmp(input_type, range) == 0 ){ |
6973 | free(input_type); |
||
6974 | return RANGE; |
||
6975 | } |
||
7614 | schaersvoo | 6976 | if( strcmp(input_type, xrange) == 0 ){ |
6977 | free(input_type); |
||
6978 | return XRANGE; |
||
6979 | } |
||
6980 | if( strcmp(input_type, rangex) == 0 ){ |
||
6981 | free(input_type); |
||
6982 | return XRANGE; |
||
6983 | } |
||
6984 | if( strcmp(input_type, trange) == 0 ){ |
||
6985 | free(input_type); |
||
6986 | return TRANGE; |
||
6987 | } |
||
6988 | if( strcmp(input_type, ranget) == 0 ){ |
||
6989 | free(input_type); |
||
6990 | return TRANGE; |
||
6991 | } |
||
6992 | if( strcmp(input_type, yrange) == 0 ){ |
||
6993 | free(input_type); |
||
6994 | return YRANGE; |
||
6995 | } |
||
6996 | if( strcmp(input_type, rangey) == 0 ){ |
||
6997 | free(input_type); |
||
6998 | return YRANGE; |
||
6999 | } |
||
7000 | if( strcmp(input_type, linewidth) == 0 ){ |
||
7001 | free(input_type); |
||
7002 | return LINEWIDTH; |
||
7003 | } |
||
7004 | if( strcmp(input_type, dashed) == 0 ){ |
||
7005 | free(input_type); |
||
7006 | return DASHED; |
||
7007 | } |
||
7008 | if( strcmp(input_type, dashtype) == 0 ){ |
||
7009 | free(input_type); |
||
7010 | return DASHTYPE; |
||
7011 | } |
||
7012 | if( strcmp(input_type, axisnumbering) == 0 ){ |
||
7013 | free(input_type); |
||
7014 | return AXIS_NUMBERING; |
||
7015 | } |
||
7016 | if( strcmp(input_type, axisnumbers) == 0 ){ |
||
7017 | free(input_type); |
||
7018 | return AXIS_NUMBERING; |
||
7019 | } |
||
7020 | if( strcmp(input_type, axis) == 0 ){ |
||
7021 | free(input_type); |
||
7022 | return AXIS; |
||
7023 | } |
||
7024 | if( strcmp(input_type, grid) == 0 ){ |
||
7025 | free(input_type); |
||
7026 | return GRID; |
||
7027 | } |
||
9383 | schaersvoo | 7028 | if( strcmp(input_type, hlines) == 0 || strcmp(input_type, horizontallines) == 0 ){ |
8366 | schaersvoo | 7029 | free(input_type); |
7030 | return HLINES; |
||
7031 | } |
||
9383 | schaersvoo | 7032 | if( strcmp(input_type, vlines) == 0 || strcmp(input_type, verticallines) == 0 ){ |
8366 | schaersvoo | 7033 | free(input_type); |
7034 | return VLINES; |
||
7035 | } |
||
9383 | schaersvoo | 7036 | if( strcmp(input_type, hline) == 0 || strcmp(input_type, horizontalline) == 0 ){ |
7614 | schaersvoo | 7037 | free(input_type); |
7038 | return HLINE; |
||
7039 | } |
||
7040 | if( strcmp(input_type, vline) == 0 || strcmp(input_type, verticalline) == 0 ){ |
||
7041 | free(input_type); |
||
7042 | return VLINE; |
||
7043 | } |
||
7044 | if( strcmp(input_type, line) == 0 ){ |
||
7045 | free(input_type); |
||
7046 | return LINE; |
||
7047 | } |
||
9383 | schaersvoo | 7048 | if( strcmp(input_type, segments) == 0 || strcmp(input_type, segs) == 0 ){ |
8299 | schaersvoo | 7049 | free(input_type); |
7050 | return SEGMENTS; |
||
7051 | } |
||
7614 | schaersvoo | 7052 | if( strcmp(input_type, seg) == 0 || strcmp(input_type, segment) == 0 ){ |
7053 | free(input_type); |
||
7054 | return SEGMENT; |
||
7055 | } |
||
9374 | schaersvoo | 7056 | if( strcmp(input_type, dsegments) == 0 ){ |
7057 | free(input_type); |
||
7058 | use_dashed = TRUE; |
||
7059 | return SEGMENTS; |
||
7060 | } |
||
7614 | schaersvoo | 7061 | if( strcmp(input_type, dsegment) == 0 ){ |
7062 | free(input_type); |
||
7063 | use_dashed = TRUE; |
||
7064 | return SEGMENT; |
||
7065 | } |
||
7066 | if( strcmp(input_type, crosshairsize) == 0 ){ |
||
7067 | free(input_type); |
||
7068 | return CROSSHAIRSIZE; |
||
7069 | } |
||
7070 | if( strcmp(input_type, arrowhead) == 0 ){ |
||
7071 | free(input_type); |
||
7072 | return ARROWHEAD; |
||
7073 | } |
||
7074 | if( strcmp(input_type, crosshairs) == 0 ){ |
||
7075 | free(input_type); |
||
7076 | return CROSSHAIRS; |
||
7077 | } |
||
7078 | if( strcmp(input_type, crosshair) == 0 ){ |
||
7079 | free(input_type); |
||
7080 | return CROSSHAIR; |
||
7081 | } |
||
7082 | if( strcmp(input_type, onclick) == 0 ){ |
||
7083 | free(input_type); |
||
7084 | return ONCLICK; |
||
7085 | } |
||
7086 | if( strcmp(input_type, drag) == 0 ){ |
||
7087 | free(input_type); |
||
7088 | return DRAG; |
||
7089 | } |
||
7090 | if( strcmp(input_type, userdraw) == 0 ){ |
||
7091 | free(input_type); |
||
7092 | return USERDRAW; |
||
7093 | } |
||
7094 | if( strcmp(input_type, highlight) == 0 || strcmp(input_type, style) == 0 ){ |
||
7095 | free(input_type); |
||
7096 | return STYLE; |
||
7097 | } |
||
7098 | if( strcmp(input_type, fillcolor) == 0 ){ |
||
7099 | free(input_type); |
||
7100 | return FILLCOLOR; |
||
7101 | } |
||
7102 | if( strcmp(input_type, strokecolor) == 0 ){ |
||
7103 | free(input_type); |
||
7104 | return STROKECOLOR; |
||
7105 | } |
||
15111 | schaersvoo | 7106 | if( strcmp(input_type, filled) == 0 ){ |
7614 | schaersvoo | 7107 | free(input_type); |
7108 | return FILLED; |
||
7109 | } |
||
7110 | if( strcmp(input_type, http) == 0 ){ |
||
7111 | free(input_type); |
||
7112 | return HTTP; |
||
7113 | } |
||
7114 | if( strcmp(input_type, rays) == 0 ){ |
||
7115 | free(input_type); |
||
7116 | return RAYS; |
||
7117 | } |
||
7118 | if( strcmp(input_type, lattice) == 0 ){ |
||
7119 | free(input_type); |
||
7120 | return LATTICE; |
||
7121 | } |
||
7122 | if( strcmp(input_type, bgimage) == 0 ){ |
||
7123 | free(input_type); |
||
7124 | return BGIMAGE; |
||
7125 | } |
||
7126 | if( strcmp(input_type, bgcolor) == 0 ){ |
||
7127 | free(input_type); |
||
7128 | return BGCOLOR; |
||
7129 | } |
||
7130 | if( strcmp(input_type, backgroundimage) == 0 ){ |
||
7131 | free(input_type); |
||
7132 | return BGIMAGE; |
||
7133 | } |
||
7134 | if( strcmp(input_type, text) == 0 ){ |
||
7135 | free(input_type); |
||
7136 | return FLY_TEXT; |
||
7137 | } |
||
7138 | if( strcmp(input_type, textup) == 0 ){ |
||
7139 | free(input_type); |
||
7140 | return FLY_TEXTUP; |
||
7141 | } |
||
7142 | if( strcmp(input_type, mouse) == 0 ){ |
||
7143 | free(input_type); |
||
7144 | return MOUSE; |
||
7145 | } |
||
7991 | schaersvoo | 7146 | if( strcmp(input_type, mousex) == 0 ){ |
7147 | free(input_type); |
||
7148 | return MOUSEX; |
||
7149 | } |
||
7150 | if( strcmp(input_type, mousey) == 0 ){ |
||
7151 | free(input_type); |
||
7152 | return MOUSEY; |
||
7153 | } |
||
8071 | schaersvoo | 7154 | if( strcmp(input_type, mouse_degree) == 0 ){ |
7155 | free(input_type); |
||
7156 | return MOUSE_DEGREE; |
||
7157 | } |
||
7158 | if( strcmp(input_type, mouse_display) == 0 ){ |
||
7159 | free(input_type); |
||
7160 | return MOUSE_DISPLAY; |
||
7161 | } |
||
7614 | schaersvoo | 7162 | if( strcmp(input_type, mouseprecision) == 0 ){ |
7163 | free(input_type); |
||
7164 | return MOUSE_PRECISION; |
||
7165 | } |
||
7166 | if( strcmp(input_type, precision) == 0 ){ |
||
7167 | free(input_type); |
||
7168 | return MOUSE_PRECISION; |
||
7169 | } |
||
7170 | if( strcmp(input_type, curve) == 0 ){ |
||
7171 | free(input_type); |
||
7172 | return CURVE; |
||
7173 | } |
||
7174 | if( strcmp(input_type, dcurve) == 0 ){ |
||
7788 | schaersvoo | 7175 | use_dashed = TRUE; |
7614 | schaersvoo | 7176 | free(input_type); |
7177 | return CURVE; |
||
7178 | } |
||
7179 | if( strcmp(input_type, plot) == 0 ){ |
||
7180 | free(input_type); |
||
7181 | return CURVE; |
||
7182 | } |
||
7183 | if( strcmp(input_type, dplot) == 0 ){ |
||
7788 | schaersvoo | 7184 | use_dashed = TRUE; |
7614 | schaersvoo | 7185 | free(input_type); |
7186 | return CURVE; |
||
7187 | } |
||
7788 | schaersvoo | 7188 | if( strcmp(input_type, levelcurve) == 0 ){ |
7189 | free(input_type); |
||
7190 | return LEVELCURVE; |
||
7191 | } |
||
7614 | schaersvoo | 7192 | if( strcmp(input_type, plotsteps) == 0 ){ |
7193 | free(input_type); |
||
7194 | return PLOTSTEPS; |
||
7195 | } |
||
7196 | if( strcmp(input_type, plotstep) == 0 ){ |
||
7197 | free(input_type); |
||
7198 | return PLOTSTEPS; |
||
7199 | } |
||
7200 | if( strcmp(input_type, tsteps) == 0 ){ |
||
7201 | free(input_type); |
||
7202 | return PLOTSTEPS; |
||
7203 | } |
||
7204 | if( strcmp(input_type, fontsize) == 0 ){ |
||
7205 | free(input_type); |
||
7206 | return FONTSIZE; |
||
7207 | } |
||
7208 | if( strcmp(input_type, fontcolor) == 0 ){ |
||
7209 | free(input_type); |
||
7210 | return FONTCOLOR; |
||
7211 | } |
||
7212 | if( strcmp(input_type, arrow2) == 0 ){ |
||
7213 | free(input_type); |
||
7214 | return ARROW2; |
||
7215 | } |
||
7216 | if( strcmp(input_type, darrow) == 0 ){ |
||
7217 | free(input_type); |
||
8071 | schaersvoo | 7218 | use_dashed = TRUE; |
7614 | schaersvoo | 7219 | return ARROW; |
7220 | } |
||
7221 | if( strcmp(input_type, darrow2) == 0 ){ |
||
7222 | free(input_type); |
||
7223 | use_dashed = TRUE; |
||
7224 | return ARROW2; |
||
7225 | } |
||
8347 | schaersvoo | 7226 | if( strcmp(input_type, arrows2) == 0 ){ |
7227 | free(input_type); |
||
7228 | return ARROWS2; |
||
7229 | } |
||
9382 | schaersvoo | 7230 | if( strcmp(input_type, arrows) == 0 || strcmp(input_type, vectors) == 0 ){ |
8304 | schaersvoo | 7231 | free(input_type); |
7232 | return ARROWS; |
||
7233 | } |
||
9382 | schaersvoo | 7234 | if( strcmp(input_type, arrow) == 0 || strcmp(input_type, vector) == 0 ){ |
8304 | schaersvoo | 7235 | free(input_type); |
7236 | return ARROW; |
||
7237 | } |
||
7614 | schaersvoo | 7238 | if( strcmp(input_type, zoom) == 0 ){ |
7239 | free(input_type); |
||
7240 | return ZOOM; |
||
7241 | } |
||
7242 | if( strcmp(input_type, triangle) == 0 ){ |
||
7243 | free(input_type); |
||
7244 | return TRIANGLE; |
||
7245 | } |
||
9306 | schaersvoo | 7246 | if( strcmp(input_type, triangles) == 0 ){ |
7247 | free(input_type); |
||
7248 | return TRIANGLES; |
||
7249 | } |
||
9374 | schaersvoo | 7250 | if( strcmp(input_type, ftriangles) == 0 ){ |
7251 | free(input_type); |
||
7252 | use_filled = TRUE; |
||
7253 | return TRIANGLES; |
||
7254 | } |
||
7614 | schaersvoo | 7255 | if( strcmp(input_type, ftriangle) == 0 ){ |
7256 | free(input_type); |
||
7257 | use_filled = TRUE; |
||
7258 | return TRIANGLE; |
||
7259 | } |
||
7260 | if( strcmp(input_type, input) == 0 ){ |
||
7261 | free(input_type); |
||
7262 | return INPUT; |
||
7263 | } |
||
15111 | schaersvoo | 7264 | if( strcmp(input_type, css) == 0 ){ |
7614 | schaersvoo | 7265 | free(input_type); |
15111 | schaersvoo | 7266 | return CSS; |
7614 | schaersvoo | 7267 | } |
7268 | if( strcmp(input_type, textarea) == 0 ){ |
||
7269 | free(input_type); |
||
7270 | return TEXTAREA; |
||
7271 | } |
||
7272 | if( strcmp(input_type, mathml) == 0 ){ |
||
7273 | free(input_type); |
||
7274 | return MATHML; |
||
7275 | } |
||
7276 | if( strcmp(input_type, html) == 0 ){ |
||
7277 | free(input_type); |
||
15111 | schaersvoo | 7278 | return HTML; |
7614 | schaersvoo | 7279 | } |
7280 | if( strcmp(input_type, fontfamily) == 0 ){ |
||
7281 | free(input_type); |
||
7282 | return FONTFAMILY; |
||
7283 | } |
||
10975 | schaersvoo | 7284 | if( strcmp(input_type, polyline) == 0 || strcmp(input_type, path) == 0 || strcmp(input_type, brokenline) == 0 ){ |
7614 | schaersvoo | 7285 | free(input_type); |
7286 | return POLYLINE; |
||
7287 | } |
||
8351 | schaersvoo | 7288 | if( strcmp(input_type, lines) == 0 ){ |
7289 | free(input_type); |
||
7290 | return LINES; |
||
7291 | } |
||
9374 | schaersvoo | 7292 | if( strcmp(input_type, rects) == 0){ |
8363 | schaersvoo | 7293 | free(input_type); |
7294 | return RECTS; |
||
7295 | } |
||
9383 | schaersvoo | 7296 | if( strcmp(input_type, frects) == 0 ){ |
8363 | schaersvoo | 7297 | free(input_type); |
9374 | schaersvoo | 7298 | use_filled = TRUE; |
8363 | schaersvoo | 7299 | return RECTS; |
7300 | } |
||
7614 | schaersvoo | 7301 | if( strcmp(input_type, rect) == 0 || strcmp(input_type, rectangle) == 0 ){ |
7302 | free(input_type); |
||
7303 | return RECT; |
||
7304 | } |
||
9374 | schaersvoo | 7305 | if( strcmp(input_type, square) == 0 ){ |
7306 | free(input_type); |
||
11991 | schaersvoo | 7307 | return SQUARE; |
9374 | schaersvoo | 7308 | } |
7309 | if( strcmp(input_type, fsquare) == 0 ){ |
||
7310 | free(input_type); |
||
7311 | use_filled = TRUE; |
||
7312 | return SQUARE; |
||
7313 | } |
||
7314 | if( strcmp(input_type, fsquares) == 0 ){ |
||
7315 | free(input_type); |
||
7316 | use_filled = TRUE; |
||
7317 | return RECTS; |
||
7318 | } |
||
8370 | schaersvoo | 7319 | if( strcmp(input_type, roundrects) == 0 ){ |
7320 | free(input_type); |
||
7321 | return ROUNDRECTS; |
||
7322 | } |
||
7614 | schaersvoo | 7323 | if( strcmp(input_type, roundrect) == 0 || strcmp(input_type, roundrectangle) == 0 ){ |
7324 | free(input_type); |
||
7325 | return ROUNDRECT; |
||
7326 | } |
||
9374 | schaersvoo | 7327 | if( strcmp(input_type, froundrects) == 0 ){ |
7614 | schaersvoo | 7328 | free(input_type); |
7329 | use_filled = TRUE; |
||
9374 | schaersvoo | 7330 | return ROUNDRECTS; |
7614 | schaersvoo | 7331 | } |
9374 | schaersvoo | 7332 | if( strcmp(input_type, froundrect) == 0 ){ |
7614 | schaersvoo | 7333 | free(input_type); |
7334 | use_filled = TRUE; |
||
9374 | schaersvoo | 7335 | return ROUNDRECT; |
7614 | schaersvoo | 7336 | } |
7337 | if( strcmp(input_type, dline) == 0 ){ |
||
7338 | use_dashed = TRUE; |
||
7339 | free(input_type); |
||
7340 | return LINE; |
||
7341 | } |
||
7786 | schaersvoo | 7342 | if( strcmp(input_type, dvline) == 0 ){ |
7343 | use_dashed = TRUE; |
||
7344 | free(input_type); |
||
7345 | return VLINE; |
||
7346 | } |
||
7347 | if( strcmp(input_type, dhline) == 0 ){ |
||
7348 | use_dashed = TRUE; |
||
7349 | free(input_type); |
||
7350 | return HLINE; |
||
7351 | } |
||
15111 | schaersvoo | 7352 | if( strcmp(input_type, halflines) == 0 || strcmp(input_type, demilines) == 0 ){ |
9386 | schaersvoo | 7353 | free(input_type); |
7354 | return HALFLINES; |
||
7355 | } |
||
15111 | schaersvoo | 7356 | if( strcmp(input_type, halfline) == 0 || strcmp(input_type, demiline) == 0 ){ |
9386 | schaersvoo | 7357 | free(input_type); |
7358 | return HALFLINE; |
||
7359 | } |
||
7614 | schaersvoo | 7360 | if( strcmp(input_type, frect) == 0 || strcmp(input_type, frectangle) == 0 ){ |
7361 | use_filled = TRUE; |
||
7362 | free(input_type); |
||
7363 | return RECT; |
||
7364 | } |
||
8304 | schaersvoo | 7365 | if( strcmp(input_type, circles) == 0 ){ |
7366 | free(input_type); |
||
7367 | return CIRCLES; |
||
7368 | } |
||
7614 | schaersvoo | 7369 | if( strcmp(input_type, fcircle) == 0 || strcmp(input_type, disk) == 0 ){ |
7370 | use_filled = TRUE; |
||
7371 | free(input_type); |
||
7372 | return CIRCLE; |
||
7373 | } |
||
9374 | schaersvoo | 7374 | if( strcmp(input_type, fcircles) == 0 || strcmp(input_type, disks) == 0 ){ |
7375 | use_filled = TRUE; |
||
7376 | free(input_type); |
||
7377 | return CIRCLES; |
||
7378 | } |
||
7614 | schaersvoo | 7379 | if( strcmp(input_type, circle) == 0 ){ |
7380 | free(input_type); |
||
7381 | return CIRCLE; |
||
7382 | } |
||
7383 | if( strcmp(input_type, point) == 0 ){ |
||
7384 | free(input_type); |
||
7385 | return POINT; |
||
7386 | } |
||
7387 | if( strcmp(input_type, points) == 0 ){ |
||
7388 | free(input_type); |
||
7389 | return POINTS; |
||
7390 | } |
||
9374 | schaersvoo | 7391 | if( strcmp(input_type, filledarc) == 0 || strcmp(input_type, farc) == 0 ){ |
7614 | schaersvoo | 7392 | use_filled = TRUE; |
7393 | free(input_type); |
||
7394 | return ARC; |
||
7395 | } |
||
7396 | if( strcmp(input_type, arc) == 0 ){ |
||
7397 | free(input_type); |
||
7398 | return ARC; |
||
7399 | } |
||
7400 | if( strcmp(input_type, poly) == 0 || strcmp(input_type, polygon) == 0 ){ |
||
7401 | free(input_type); |
||
7402 | return POLY; |
||
7403 | } |
||
7404 | if( strcmp(input_type, fpoly) == 0 || strcmp(input_type, filledpoly) == 0 || strcmp(input_type,filledpolygon) == 0 || strcmp(input_type,fpolygon) == 0 ){ |
||
7405 | use_filled = TRUE; |
||
7406 | free(input_type); |
||
7407 | return POLY; |
||
7408 | } |
||
7409 | if( strcmp(input_type, ellipse) == 0){ |
||
7410 | free(input_type); |
||
7411 | return ELLIPSE; |
||
7412 | } |
||
12110 | schaersvoo | 7413 | if( strcmp(input_type, ellipses) == 0){ |
7414 | free(input_type); |
||
7415 | return ELLIPSES; |
||
7416 | } |
||
7614 | schaersvoo | 7417 | if( strcmp(input_type, string) == 0 ){ |
7418 | free(input_type); |
||
7419 | return STRING; |
||
7420 | } |
||
7421 | if( strcmp(input_type, stringup) == 0 ){ |
||
7422 | free(input_type); |
||
7423 | return STRINGUP; |
||
7424 | } |
||
9385 | schaersvoo | 7425 | if( strcmp(input_type, opacity) == 0 || strcmp(input_type, transparent) == 0 ){ |
7614 | schaersvoo | 7426 | free(input_type); |
7427 | return OPACITY; |
||
7428 | } |
||
7429 | if( strcmp(input_type, comment) == 0){ |
||
7430 | free(input_type); |
||
7431 | return COMMENT; |
||
7432 | } |
||
7433 | if( strcmp(input_type, fellipse) == 0){ |
||
7434 | free(input_type); |
||
7435 | use_filled = TRUE; |
||
7436 | return ELLIPSE; |
||
8224 | bpr | 7437 | } |
9386 | schaersvoo | 7438 | if( strcmp(input_type, clearbutton) == 0 || strcmp(input_type, erase) == 0 || strcmp(input_type, delete) == 0){ |
7614 | schaersvoo | 7439 | free(input_type); |
8146 | schaersvoo | 7440 | return CLEARBUTTON; |
7614 | schaersvoo | 7441 | } |
15111 | schaersvoo | 7442 | if( strcmp(input_type, translation) == 0 || strcmp(input_type, translate) == 0 ){ |
7614 | schaersvoo | 7443 | free(input_type); |
7444 | return TRANSLATION; |
||
7445 | } |
||
15716 | schaersvoo | 7446 | if( strcmp(input_type, kill) == 0 ){ |
7447 | free(input_type); |
||
7448 | return KILL; |
||
7449 | } |
||
7614 | schaersvoo | 7450 | if( strcmp(input_type, killtranslation) == 0 || strcmp(input_type, killtranslate) == 0){ |
7451 | free(input_type); |
||
7452 | return KILLTRANSLATION; |
||
7453 | } |
||
7454 | if( strcmp(input_type, rotate) == 0){ |
||
7455 | free(input_type); |
||
7456 | return ROTATE; |
||
7457 | } |
||
9907 | schaersvoo | 7458 | if( strcmp(input_type, killrotate) == 0){ |
7459 | free(input_type); |
||
7460 | return KILLROTATE; |
||
7461 | } |
||
7462 | if( strcmp(input_type, rotationcenter) == 0){ |
||
7463 | free(input_type); |
||
7464 | return ROTATION_CENTER; |
||
7465 | } |
||
7785 | schaersvoo | 7466 | if( strcmp(input_type, affine) == 0){ |
7467 | free(input_type); |
||
7468 | return AFFINE; |
||
7469 | } |
||
15111 | schaersvoo | 7470 | if( strcmp(input_type, linear) == 0){ |
7471 | free(input_type); |
||
7472 | return LINEAR; |
||
7473 | } |
||
7785 | schaersvoo | 7474 | if( strcmp(input_type, killaffine) == 0){ |
7475 | free(input_type); |
||
7476 | return KILLAFFINE; |
||
7477 | } |
||
15111 | schaersvoo | 7478 | if( strcmp(input_type, killlinear) == 0 || strcmp(input_type, killinear) == 0 ){ |
7479 | free(input_type); |
||
7480 | return KILLLINEAR; |
||
7481 | } |
||
7614 | schaersvoo | 7482 | if( strcmp(input_type, slider) == 0 ){ |
7483 | free(input_type); |
||
7484 | return SLIDER; |
||
7485 | } |
||
8101 | schaersvoo | 7486 | if( strcmp(input_type, killslider) == 0 ){ |
7487 | free(input_type); |
||
7488 | return KILLSLIDER; |
||
7489 | } |
||
7614 | schaersvoo | 7490 | if( strcmp(input_type, copy) == 0 ){ |
7491 | free(input_type); |
||
7492 | return COPY; |
||
7493 | } |
||
7494 | if( strcmp(input_type, copyresized) == 0 ){ |
||
7495 | free(input_type); |
||
7496 | return COPYRESIZED; |
||
7497 | } |
||
7498 | if( strcmp(input_type, xlogscale) == 0 ){ |
||
7499 | free(input_type); |
||
7500 | return XLOGSCALE; |
||
7501 | } |
||
7502 | if( strcmp(input_type, ylogscale) == 0 ){ |
||
7503 | free(input_type); |
||
7504 | return YLOGSCALE; |
||
7505 | } |
||
7506 | if( strcmp(input_type, xylogscale) == 0 ){ |
||
7507 | free(input_type); |
||
7508 | return XYLOGSCALE; |
||
7509 | } |
||
7510 | if( strcmp(input_type, ylogscale) == 0 ){ |
||
7511 | free(input_type); |
||
7512 | return YLOGSCALE; |
||
7513 | } |
||
7735 | schaersvoo | 7514 | if( strcmp(input_type, xlogbase) == 0 ){ |
7614 | schaersvoo | 7515 | free(input_type); |
7735 | schaersvoo | 7516 | return XLOGBASE; |
7614 | schaersvoo | 7517 | } |
7735 | schaersvoo | 7518 | if( strcmp(input_type, ylogbase) == 0 ){ |
7519 | free(input_type); |
||
7520 | return YLOGBASE; |
||
7521 | } |
||
7614 | schaersvoo | 7522 | if( strcmp(input_type, intooltip) == 0 ){ |
7523 | free(input_type); |
||
7524 | return INTOOLTIP; |
||
7525 | } |
||
9329 | schaersvoo | 7526 | if( strcmp(input_type, popup) == 0 ){ |
7527 | free(input_type); |
||
7528 | return POPUP; |
||
7529 | } |
||
7614 | schaersvoo | 7530 | if( strcmp(input_type,video) == 0 ){ |
7531 | free(input_type); |
||
7532 | return VIDEO; |
||
7533 | } |
||
15111 | schaersvoo | 7534 | if( strcmp(input_type,math) == 0 || strcmp(input_type,latex) == 0 || strcmp(input_type,katex) == 0 ){ |
14225 | schaersvoo | 7535 | free(input_type); |
7536 | return LATEX; |
||
7537 | } |
||
11772 | schaersvoo | 7538 | if( strcmp(input_type,fillall) == 0 ){ |
7539 | free(input_type); |
||
7540 | return FILLALL; |
||
7541 | } |
||
7614 | schaersvoo | 7542 | if( strcmp(input_type,floodfill) == 0 || strcmp(input_type,fill) == 0 ){ |
7543 | free(input_type); |
||
7544 | return FLOODFILL; |
||
8224 | bpr | 7545 | } |
7614 | schaersvoo | 7546 | if( strcmp(input_type,filltoborder) == 0 ){ |
7547 | free(input_type); |
||
7548 | return FILLTOBORDER; |
||
8224 | bpr | 7549 | } |
14038 | schaersvoo | 7550 | if( strcmp(input_type, curvedarrow2) == 0 ){ |
7551 | free(input_type); |
||
7552 | return CURVEDARROW2; |
||
7553 | } |
||
7554 | if( strcmp(input_type, curvedarrow) == 0 ){ |
||
7555 | free(input_type); |
||
7556 | return CURVEDARROW; |
||
7557 | } |
||
7558 | if( strcmp(input_type, curvedarrows) == 0 ){ |
||
7559 | free(input_type); |
||
7560 | return CURVEDARROWS; |
||
7561 | } |
||
7562 | if( strcmp(input_type, curvedarrows2) == 0 ){ |
||
7563 | free(input_type); |
||
7564 | return CURVEDARROWS2; |
||
7565 | } |
||
7614 | schaersvoo | 7566 | if( strcmp(input_type, replyformat) == 0 ){ |
7567 | free(input_type); |
||
7568 | return REPLYFORMAT; |
||
7569 | } |
||
7570 | if( strcmp(input_type, pixelsize) == 0 ){ |
||
7571 | free(input_type); |
||
7572 | return PIXELSIZE; |
||
7573 | } |
||
7574 | if( strcmp(input_type, setpixel) == 0 ){ |
||
7575 | free(input_type); |
||
7576 | return SETPIXEL; |
||
7577 | } |
||
7578 | if( strcmp(input_type, pixels) == 0 ){ |
||
7579 | free(input_type); |
||
7580 | return PIXELS; |
||
7581 | } |
||
7582 | if( strcmp(input_type, xaxis) == 0 || strcmp(input_type, xaxistext) == 0 ){ |
||
7583 | free(input_type); |
||
7584 | return X_AXIS_STRINGS; |
||
7585 | } |
||
9341 | schaersvoo | 7586 | if( strcmp(input_type, xaxisup) == 0 || strcmp(input_type, xaxistextup) == 0 ){ |
7587 | free(input_type); |
||
7588 | return X_AXIS_STRINGS_UP; |
||
7589 | } |
||
7614 | schaersvoo | 7590 | if( strcmp(input_type, yaxis) == 0 || strcmp(input_type, yaxistext) == 0 ){ |
7591 | free(input_type); |
||
7592 | return Y_AXIS_STRINGS; |
||
7593 | } |
||
15111 | schaersvoo | 7594 | if( strcmp(input_type, legend) == 0 ){ |
7614 | schaersvoo | 7595 | free(input_type); |
7596 | return LEGEND; |
||
7597 | } |
||
15111 | schaersvoo | 7598 | if( strcmp(input_type, legendcolors) == 0 ){ |
7614 | schaersvoo | 7599 | free(input_type); |
7600 | return LEGENDCOLORS; |
||
7601 | } |
||
15111 | schaersvoo | 7602 | if( strcmp(input_type, xlabel) == 0 ){ |
7614 | schaersvoo | 7603 | free(input_type); |
7604 | return XLABEL; |
||
7605 | } |
||
15111 | schaersvoo | 7606 | if( strcmp(input_type, ylabel) == 0 ){ |
7614 | schaersvoo | 7607 | free(input_type); |
7608 | return YLABEL; |
||
7609 | } |
||
15111 | schaersvoo | 7610 | if( strcmp(input_type, bezier) == 0 ){ |
8370 | schaersvoo | 7611 | free(input_type); |
7612 | return BEZIER; |
||
7613 | } |
||
15111 | schaersvoo | 7614 | if( strcmp(input_type, animate) == 0 ){ |
7614 | schaersvoo | 7615 | free(input_type); |
7616 | return ANIMATE; |
||
7617 | } |
||
9354 | schaersvoo | 7618 | /* these are bitmap related flydraw commands...must be removed. eventually */ |
7614 | schaersvoo | 7619 | if( strcmp(input_type, transparent) == 0 ){ |
7620 | free(input_type); |
||
7621 | return TRANSPARENT; |
||
7622 | } |
||
7877 | schaersvoo | 7623 | if( strcmp(input_type, status) == 0 || strcmp(input_type, nostatus) == 0 ){ |
7614 | schaersvoo | 7624 | free(input_type); |
7625 | return STATUS; |
||
7626 | } |
||
7784 | schaersvoo | 7627 | if( strcmp(input_type, xsnaptogrid) == 0 ){ |
7628 | free(input_type); |
||
7629 | return XSNAPTOGRID; |
||
7630 | } |
||
7631 | if( strcmp(input_type, ysnaptogrid) == 0 ){ |
||
7632 | free(input_type); |
||
7633 | return YSNAPTOGRID; |
||
7634 | } |
||
8379 | schaersvoo | 7635 | if( strcmp(input_type, snaptogrid) == 0 ){ |
7636 | free(input_type); |
||
7637 | return SNAPTOGRID; |
||
7638 | } |
||
7639 | if( strcmp(input_type, snaptopoints) == 0 ){ |
||
7640 | free(input_type); |
||
7641 | return SNAPTOPOINTS; |
||
7642 | } |
||
9213 | schaersvoo | 7643 | if( strcmp(input_type, snaptofunction) == 0 || strcmp(input_type, snaptofun) == 0 ){ |
7644 | free(input_type); |
||
7645 | return SNAPTOFUNCTION; |
||
7646 | } |
||
7652 | schaersvoo | 7647 | if( strcmp(input_type, userinput_xy) == 0 ){ |
7614 | schaersvoo | 7648 | free(input_type); |
7652 | schaersvoo | 7649 | return USERINPUT_XY; |
7650 | } |
||
8193 | schaersvoo | 7651 | if( strcmp(input_type, userinput_function) == 0 ){ |
7652 | free(input_type); |
||
7653 | return USERINPUT_FUNCTION; |
||
7654 | } |
||
8222 | schaersvoo | 7655 | if( strcmp(input_type, userinput) == 0 ){ |
7656 | free(input_type); |
||
7657 | return USERINPUT; |
||
7658 | } |
||
8105 | schaersvoo | 7659 | if( strcmp(input_type, angle) == 0 ){ |
7996 | schaersvoo | 7660 | free(input_type); |
8105 | schaersvoo | 7661 | return ANGLE; |
7662 | } |
||
15315 | bpr | 7663 | if( strcmp(input_type, functionlabel) == 0 || strcmp(input_type, functionlabels) == 0 ){ |
8244 | schaersvoo | 7664 | free(input_type); |
8297 | schaersvoo | 7665 | return FUNCTION_LABEL; |
7666 | } |
||
9213 | schaersvoo | 7667 | if( strcmp(input_type, sliderfunction_x) == 0 ){ |
8297 | schaersvoo | 7668 | free(input_type); |
9213 | schaersvoo | 7669 | return SLIDER_X; |
7670 | } |
||
7671 | if( strcmp(input_type, sliderfunction_y) == 0 ){ |
||
7672 | free(input_type); |
||
7673 | return SLIDER_Y; |
||
7674 | } |
||
7675 | if( strcmp(input_type, multidraw) == 0 ){ |
||
7676 | free(input_type); |
||
7677 | return MULTIDRAW; |
||
7678 | } |
||
7679 | if( strcmp(input_type, multistrokeopacity) == 0 ){ |
||
7680 | free(input_type); |
||
7681 | return MULTISTROKEOPACITY; |
||
7682 | } |
||
7683 | if( strcmp(input_type, multifillopacity) == 0 ){ |
||
7684 | free(input_type); |
||
7685 | return MULTIFILLOPACITY; |
||
7686 | } |
||
15111 | schaersvoo | 7687 | if( strcmp(input_type, multilinewidth) == 0 || strcmp(input_type, linewidths) == 0 ){ |
9213 | schaersvoo | 7688 | free(input_type); |
7689 | return MULTILINEWIDTH; |
||
7690 | } |
||
15111 | schaersvoo | 7691 | if( strcmp(input_type, multistrokecolors) == 0 || strcmp(input_type,multicolors) == 0 || strcmp(input_type,strokecolors) == 0 || strcmp(input_type,colors) == 0 ){ |
9213 | schaersvoo | 7692 | free(input_type); |
7693 | return MULTISTROKECOLORS; |
||
7694 | } |
||
7695 | if( strcmp(input_type, multifill) == 0 ){ |
||
7696 | free(input_type); |
||
7697 | return MULTIFILL; |
||
7698 | } |
||
15111 | schaersvoo | 7699 | if( strcmp(input_type, multifillcolors) == 0 || strcmp(input_type, fillcolors) == 0 ){ |
9213 | schaersvoo | 7700 | free(input_type); |
7701 | return MULTIFILLCOLORS; |
||
7702 | } |
||
7703 | if( strcmp(input_type, multilabel) == 0 ){ |
||
7704 | free(input_type); |
||
7705 | return MULTILABEL; |
||
7706 | } |
||
7707 | if( strcmp(input_type, multidash) == 0 ){ |
||
7708 | free(input_type); |
||
7709 | return MULTIDASH; |
||
7710 | } |
||
14038 | schaersvoo | 7711 | if( strcmp(input_type, multisnaptogrid) == 0 || strcmp(input_type, multisnap) == 0 ){ |
9213 | schaersvoo | 7712 | free(input_type); |
7713 | return MULTISNAPTOGRID; |
||
7714 | } |
||
15111 | schaersvoo | 7715 | if( strcmp(input_type, multiuserinput) == 0 || strcmp(input_type, multiinput) == 0 ){ |
9213 | schaersvoo | 7716 | free(input_type); |
7717 | return MULTIUSERINPUT; |
||
7718 | } |
||
9386 | schaersvoo | 7719 | if( strcmp(input_type, parallel) == 0 ){ |
7720 | free(input_type); |
||
7721 | return PARALLEL; |
||
7722 | } |
||
9289 | schaersvoo | 7723 | if( strcmp(input_type, protractor) == 0 ){ |
7724 | free(input_type); |
||
7725 | return PROTRACTOR; |
||
7726 | } |
||
7727 | if( strcmp(input_type, ruler) == 0 ){ |
||
7728 | free(input_type); |
||
7729 | return RULER; |
||
7730 | } |
||
9386 | schaersvoo | 7731 | if( strcmp(input_type, cursor) == 0 || strcmp(input_type, pointer) == 0 ){ |
9213 | schaersvoo | 7732 | free(input_type); |
9386 | schaersvoo | 7733 | return CURSOR; |
7734 | } |
||
7735 | if( strcmp(input_type, sgraph) == 0 ){ |
||
7736 | free(input_type); |
||
7737 | return SGRAPH; |
||
7738 | } |
||
7739 | if( strcmp(input_type, jsmath) == 0 ){ |
||
7740 | free(input_type); |
||
7741 | return JSMATH; |
||
7742 | } |
||
7743 | if( strcmp(input_type, trace_jscurve) == 0 ){ |
||
7744 | free(input_type); |
||
7745 | return TRACE_JSCURVE; |
||
7746 | } |
||
7747 | if( strcmp(input_type, jscurve) == 0 || strcmp(input_type, jsplot) == 0 ){ |
||
7748 | free(input_type); |
||
7749 | return JSCURVE; |
||
7750 | } |
||
7751 | if( strcmp(input_type, centerstring) == 0 || strcmp(input_type, title) == 0 ){ |
||
7752 | free(input_type); |
||
7753 | return CENTERSTRING; |
||
7754 | } |
||
7755 | if( strcmp(input_type, setlimits) == 0 ){ |
||
7756 | free(input_type); |
||
7757 | return SETLIMITS; |
||
7758 | } |
||
7759 | if( strcmp(input_type, xunit) == 0 ){ |
||
7760 | free(input_type); |
||
7761 | return XUNIT; |
||
7762 | } |
||
7763 | if( strcmp(input_type, yunit) == 0 ){ |
||
7764 | free(input_type); |
||
7765 | return YUNIT; |
||
7766 | } |
||
7767 | if( strcmp(input_type, fill) == 0 ){ |
||
7768 | free(input_type); |
||
7769 | return FLOODFILL; |
||
7770 | } |
||
7771 | if( strcmp(input_type, end) == 0){ |
||
7772 | free(input_type); |
||
7773 | return END; |
||
7774 | } |
||
7775 | if( strcmp(input_type, blink) == 0 ){ |
||
7776 | free(input_type); |
||
7777 | return BLINK; |
||
7778 | } |
||
7779 | if( strcmp(input_type, audio) == 0 ){ |
||
7780 | free(input_type); |
||
7781 | return AUDIO; |
||
7782 | } |
||
7783 | if( strcmp(input_type, audioobject) == 0 ){ |
||
7784 | free(input_type); |
||
7785 | return AUDIOOBJECT; |
||
7786 | } |
||
7787 | if( strcmp(input_type, patternfill) == 0 ){ |
||
7788 | free(input_type); |
||
7789 | return PATTERNFILL; |
||
7790 | } |
||
7791 | if( strcmp(input_type, hatchfill) == 0 ){ |
||
7792 | free(input_type); |
||
7793 | return HATCHFILL; |
||
7794 | } |
||
15111 | schaersvoo | 7795 | if( strcmp(input_type, diafill) == 0 || strcmp(input_type, diamondfill) == 0 ){ |
9386 | schaersvoo | 7796 | free(input_type); |
7797 | return DIAMONDFILL; |
||
7798 | } |
||
7799 | if( strcmp(input_type, dotfill) == 0 ){ |
||
7800 | free(input_type); |
||
7801 | return DOTFILL; |
||
7802 | } |
||
11830 | schaersvoo | 7803 | if( strcmp(input_type, textfill) == 0 ){ |
7804 | free(input_type); |
||
7805 | return TEXTFILL; |
||
7806 | } |
||
9386 | schaersvoo | 7807 | if( strcmp(input_type, gridfill) == 0 ){ |
7808 | free(input_type); |
||
7809 | return GRIDFILL; |
||
7810 | } |
||
7811 | if( strcmp(input_type, imagefill) == 0 ){ |
||
7812 | free(input_type); |
||
7813 | return IMAGEFILL; |
||
7814 | } |
||
7815 | if( strcmp(input_type, clicktile_colors) == 0 ){ |
||
7816 | free(input_type); |
||
7817 | return CLICKTILE_COLORS; |
||
7818 | } |
||
7819 | if( strcmp(input_type, clicktile) == 0 ){ |
||
7820 | free(input_type); |
||
7821 | return CLICKTILE; |
||
7822 | } |
||
15111 | schaersvoo | 7823 | if( strcmp(input_type, piechart) == 0 ){ |
9386 | schaersvoo | 7824 | free(input_type); |
7825 | return PIECHART; |
||
7826 | } |
||
15111 | schaersvoo | 7827 | if( strcmp(input_type, boxplot) == 0 ){ |
9433 | schaersvoo | 7828 | free(input_type); |
7829 | return BOXPLOT; |
||
7830 | } |
||
15111 | schaersvoo | 7831 | if( strcmp(input_type, boxplotdata) == 0 ){ |
9433 | schaersvoo | 7832 | free(input_type); |
9465 | schaersvoo | 7833 | return BOXPLOTDATA; |
9433 | schaersvoo | 7834 | } |
15111 | schaersvoo | 7835 | if( strcmp(input_type, userboxplot) == 0 ){ |
9465 | schaersvoo | 7836 | free(input_type); |
7837 | return USERBOXPLOT; |
||
7838 | } |
||
15111 | schaersvoo | 7839 | if( strcmp(input_type, userboxplotdata) == 0 ){ |
9465 | schaersvoo | 7840 | free(input_type); |
7841 | return USERBOXPLOT; |
||
7842 | } |
||
15111 | schaersvoo | 7843 | if( strcmp(input_type, barchart) == 0 ){ |
9386 | schaersvoo | 7844 | free(input_type); |
7845 | return BARCHART; |
||
7846 | } |
||
15111 | schaersvoo | 7847 | if( strcmp(input_type, linegraph) == 0 ){ |
9386 | schaersvoo | 7848 | free(input_type); |
7849 | return LINEGRAPH; |
||
7850 | } |
||
15111 | schaersvoo | 7851 | if( strcmp(input_type, clock) == 0 ){ |
9386 | schaersvoo | 7852 | free(input_type); |
7853 | return CLOCK; |
||
7854 | } |
||
15111 | schaersvoo | 7855 | if( strcmp(input_type, yerrorbars) == 0 ){ |
9386 | schaersvoo | 7856 | free(input_type); |
9427 | schaersvoo | 7857 | return YERRORBARS; |
7858 | } |
||
15111 | schaersvoo | 7859 | if( strcmp(input_type, xerrorbars) == 0 ){ |
9427 | schaersvoo | 7860 | free(input_type); |
7861 | return XERRORBARS; |
||
7862 | } |
||
15111 | schaersvoo | 7863 | if( strcmp(input_type, canvastype) == 0 ){ |
9427 | schaersvoo | 7864 | free(input_type); |
11006 | schaersvoo | 7865 | return CANVASTYPE; |
7866 | } |
||
15111 | schaersvoo | 7867 | if( strcmp(input_type, noyaxis) == 0 ){ |
11006 | schaersvoo | 7868 | free(input_type); |
11044 | schaersvoo | 7869 | return NOYAXIS; |
7870 | } |
||
15111 | schaersvoo | 7871 | if( strcmp(input_type, noxaxis) == 0 ){ |
11044 | schaersvoo | 7872 | free(input_type); |
7873 | return NOXAXIS; |
||
7874 | } |
||
15111 | schaersvoo | 7875 | if( strcmp(input_type, colorpalette) == 0 ){ |
11044 | schaersvoo | 7876 | free(input_type); |
11767 | schaersvoo | 7877 | return COLORPALETTE; |
7878 | } |
||
15111 | schaersvoo | 7879 | if( strcmp(input_type, imagepalette) == 0 ){ |
14038 | schaersvoo | 7880 | free(input_type); |
7881 | return IMAGEPALETTE; |
||
7882 | } |
||
15111 | schaersvoo | 7883 | if( strcmp(input_type, resetoffset) == 0 ){ |
11767 | schaersvoo | 7884 | free(input_type); |
11802 | schaersvoo | 7885 | return RESETOFFSET; |
7886 | } |
||
15111 | schaersvoo | 7887 | if( strcmp(input_type, xyoffset) == 0 ){ |
11802 | schaersvoo | 7888 | free(input_type); |
7889 | return XYOFFSET; |
||
7890 | } |
||
12063 | schaersvoo | 7891 | if( strcmp(input_type, centered) == 0 ){ |
11802 | schaersvoo | 7892 | free(input_type); |
12063 | schaersvoo | 7893 | return CENTERED; |
11802 | schaersvoo | 7894 | } |
15111 | schaersvoo | 7895 | if( strcmp(input_type, yoffset) == 0 ){ |
11802 | schaersvoo | 7896 | free(input_type); |
11811 | schaersvoo | 7897 | return YOFFSET; |
7898 | } |
||
15111 | schaersvoo | 7899 | if( strcmp(input_type, xoffset) == 0 ){ |
12063 | schaersvoo | 7900 | free(input_type); |
7901 | return XOFFSET; |
||
7902 | } |
||
15601 | schaersvoo | 7903 | if( strcmp(input_type, fillpattern) == 0 || strcmp(input_type, settile) == 0 ){ |
11811 | schaersvoo | 7904 | free(input_type); |
11837 | schaersvoo | 7905 | return FILLPATTERN; |
7906 | } |
||
11890 | schaersvoo | 7907 | if( strcmp(input_type, numberline) == 0 ){ |
11837 | schaersvoo | 7908 | free(input_type); |
11890 | schaersvoo | 7909 | return NUMBERLINE; |
7910 | } |
||
15111 | schaersvoo | 7911 | if( strcmp(input_type, obabel) == 0 ){ |
7912 | free(input_type); |
||
7913 | return OBABEL; |
||
7914 | } |
||
7915 | if( strcmp(input_type, chemtex) == 0 ){ |
||
7916 | free(input_type); |
||
7917 | return CHEMTEX; |
||
7918 | } |
||
7919 | if( strcmp(input_type, noreset) == 0 || strcmp(input_type, killreset) == 0 ){ |
||
7920 | return NORESET; |
||
7921 | } |
||
14393 | schaersvoo | 7922 | if( strcmp(input_type, duplicates) == 0 || strcmp(input_type, allowdups) == 0 ){ |
11890 | schaersvoo | 7923 | free(input_type); |
14393 | schaersvoo | 7924 | return ALLOW_DUPLICATES; |
7925 | } |
||
15690 | schaersvoo | 7926 | if( strcmp(input_type, arrowarc) == 0 || strcmp(input_type, arcarrow) == 0 ){ |
14393 | schaersvoo | 7927 | free(input_type); |
15690 | schaersvoo | 7928 | return ARCARROW; |
7929 | } |
||
7930 | free(input_type); |
||
7614 | schaersvoo | 7931 | ungetc(c,infile); |
7932 | return 0; |
||
7933 | } |
||
15611 | schaersvoo | 7934 | |
15613 | schaersvoo | 7935 | |
7936 |