Rev 14078 | Rev 14092 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
8299 | 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 * |
||
8 | * No warrenty whatsoever * |
||
9 | ********************************************************************************* |
||
10 | */ |
||
7848 | bpr | 11 | #include "canvasdraw.h" |
7614 | schaersvoo | 12 | |
13 | /****************************************************************************** |
||
14 | ** Internal Functions |
||
15 | ******************************************************************************/ |
||
16 | void add_to_buffer(char *tmp); /* add tmp_buffer to the buffer */ |
||
17 | void sync_input(FILE *infile);/* proceed with inputfile */ |
||
11021 | schaersvoo | 18 | void add_javascript_function(int js_function[], int canvas_root_id); |
14078 | bpr | 19 | void reset();/* reset some global variables like "use_filled", "use_dashed" */ |
7614 | schaersvoo | 20 | int get_token(FILE *infile); /* read next char until EOL*/ |
8225 | bpr | 21 | /* |
7614 | schaersvoo | 22 | int x2px(double x); |
23 | int y2px(double y); |
||
8225 | bpr | 24 | */ |
7614 | schaersvoo | 25 | double px2x(int x); |
26 | double px2y(int y); |
||
7906 | schaersvoo | 27 | double get_real(FILE *infile,int last); /* read a value; calculation and symbols allowed */ |
7614 | schaersvoo | 28 | char *str_replace ( const char *word, const char *sub_word, const char *rep_word ); |
29 | char *get_color(FILE *infile,int last); /* read hex-color or colorname -> hex */ |
||
7906 | schaersvoo | 30 | char *get_string(FILE *infile,int last); /* get the string at the end of a command */ |
7614 | schaersvoo | 31 | char *get_string_argument(FILE *infile,int last); /* the same, but with "comma" as separator */ |
32 | char *convert_hex2rgb(char *hexcolor); |
||
8257 | schaersvoo | 33 | void add_read_canvas(int canvas_root_id,int reply_format,int reply_precision); |
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 */ |
||
8224 | bpr | 36 | FILE *js_include_file; |
7614 | schaersvoo | 37 | FILE *get_file(int *line_number, char **filename); |
38 | FILE *infile; /* will be stdin */ |
||
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 */ |
56 | int onclick = 0;/* 0 = noninteractive ; 1 = onclick ; 2 = draggable*/ |
||
14066 | bpr | 57 | int slider = 0;/* slider=1: x-values ; slider=2: y-values;slider=3 angle values */ |
7785 | schaersvoo | 58 | int use_affine = FALSE; |
7614 | schaersvoo | 59 | int use_rotate = FALSE; |
14078 | bpr | 60 | int use_filled = 0; /* 0:no fill, 1:fill,2=grid?,3=hatch?,4=diamond?,5=dot?,6=image? */ |
61 | int use_dashed = FALSE; /* dashing not natively supported in firefox, for now... */ |
||
8097 | schaersvoo | 62 | |
7614 | schaersvoo | 63 | char buffer[MAX_BUFFER];/* contains js-functions with arguments ... all other basic code is directly printed into js-include file */ |
9329 | schaersvoo | 64 | char *getfile_cmd = ""; |
7614 | schaersvoo | 65 | /****************************************************************************** |
66 | ** Main Program |
||
67 | ******************************************************************************/ |
||
68 | int main(int argc, char *argv[]){ |
||
14066 | bpr | 69 | /* need unique id for every call to canvasdraw: rand(); is too slow...will result in many identical id's */ |
12104 | schaersvoo | 70 | struct timeval tv;struct timezone tz;gettimeofday(&tv, &tz); |
71 | unsigned int canvas_root_id = (unsigned int) tv.tv_usec; |
||
7614 | schaersvoo | 72 | infile = stdin;/* read flyscript via stdin */ |
73 | int i,c; |
||
74 | double double_data[MAX_INT+1]; |
||
75 | int int_data[MAX_INT+1]; |
||
76 | for(i=0;i<MAX_INT;i++){int_data[i]=0;double_data[i]=0;} |
||
77 | int use_parametric = FALSE;/* will be reset after parametric plotting */ |
||
78 | int use_axis = FALSE; |
||
11891 | schaersvoo | 79 | int use_axis_numbering = -1; |
14066 | bpr | 80 | int use_snap = 0; /* 0 = none 1=grid: 2=x-grid: 3=y-grid: 4=snap to points */ |
14038 | schaersvoo | 81 | int use_offset = 0;/* use_offset only for text shape objects... 0=none;1=yoffset;2=xoffset;3=xyoffset;4=centered*/ |
7797 | schaersvoo | 82 | int use_pan_and_zoom = FALSE; |
14066 | bpr | 83 | int use_safe_eval = FALSE; /* if true, add just once: js function to evaluate userinput values for plotting etc */ |
7858 | schaersvoo | 84 | int use_js_math = FALSE; /* if true add js-function to convert math_function --> javascript math_function */ |
14078 | bpr | 85 | int use_js_plot = FALSE; /* if true, let js-engine plot the curve */ |
11006 | schaersvoo | 86 | int jsplot_cnt = 0; /* keepint track on the curve identity */ |
8448 | schaersvoo | 87 | int print_drag_params_only_once = FALSE;/* avoid multiple useless identical lines about javascript precision and use_dragdrop */ |
14038 | schaersvoo | 88 | int include_special_OEF_reply = FALSE; /* used for including extra read_canvas_images();*/ |
7614 | schaersvoo | 89 | int line_width = 1; |
90 | int decimals = 2; |
||
8365 | schaersvoo | 91 | int precision = 100; /* 10 = 1;100=2;1000=3 decimal display for mouse coordinates or grid coordinate.May be redefined before every object */ |
92 | int use_userdraw = FALSE; /* flag to indicate user interaction */ |
||
14066 | bpr | 93 | int drag_type = -1;/* 0,1,2: xy,x,y */ |
9329 | schaersvoo | 94 | int use_tooltip = -1; /* 1= tooltip 2= popup window*/ |
7614 | schaersvoo | 95 | char *tooltip_text = "Click here"; |
96 | char *temp = ""; /* */ |
||
97 | char *bgcolor = "";/* used for background of canvas_div ; default is tranparent */ |
||
98 | char *stroke_color = "255,0,0"; |
||
99 | char *fill_color = "0,255,0"; |
||
100 | char *font_family = "12px Ariel"; /* commands xaxistext,yaxistext,legend,text/textup/string/stringup may us this */ |
||
101 | char *font_color = "#00000"; |
||
102 | char *draw_type = "points"; |
||
103 | char *fly_font = "normal"; |
||
8815 | schaersvoo | 104 | char *input_style = "font-family:Ariel;text-align:center;color:blue;font-size:12px;background-color:orange;"; |
7614 | schaersvoo | 105 | char *flytext = ""; |
7785 | schaersvoo | 106 | char *affine_matrix = "[1,0,0,1,0,0]"; |
8297 | schaersvoo | 107 | char *function_label = "f(x)="; |
14066 | bpr | 108 | int use_pattern = 0; /* used in drag&drop library: grid=2,hatch=3,diamond=4,dot=5*/ |
11006 | schaersvoo | 109 | int canvas_type = DRAG_CANVAS; /* to use a specific canvas for filling etc */ |
7614 | schaersvoo | 110 | int pixelsize = 1; |
111 | int reply_format = 0; |
||
112 | int input_cnt = 0; |
||
113 | int ext_img_cnt = 0; |
||
8071 | schaersvoo | 114 | int slider_cnt = 0; |
11763 | schaersvoo | 115 | int fill_cnt = 0; |
14086 | bpr | 116 | int font_size = 12;/* this may lead to problems when using something like <code>fontfamily Italic 24px Ariel</code> the ''fontsize`` value is not substituted into fontfamily !! */ |
8388 | schaersvoo | 117 | int fly_font_size = 12; /*fly_font_size is relative to this... */ |
14066 | bpr | 118 | int dashtype[2] = { 4 , 4 }; /* just line_px and space_px: may have more arguments...if needed in future */ |
119 | int js_function[MAX_JS_FUNCTIONS]; /* javascript functions include objects on demand basis: only once per object type */ |
||
7614 | schaersvoo | 120 | for(i=0;i<MAX_JS_FUNCTIONS;i++){js_function[i]=0;} |
8365 | schaersvoo | 121 | int arrow_head = 8; /* size in px needed for arrow based userdraw: "userdraw arrow,color" */ |
7833 | schaersvoo | 122 | int crosshair_size = 5; /* size in px*/ |
8365 | schaersvoo | 123 | 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 | 124 | int found_size_command = 0; /* 1 = found size ; 2 = found xrange; 3 = found yrange: just to flag an error message */ |
8448 | schaersvoo | 125 | int click_cnt = 0; /*counter to identify the "onclick" ojects ; 0 is first object set onclick: reply[click_cnt]=1 when clicked ; otherwise reply[click_cnt]=0 ; click_cnt is only increased when another object is set again */ |
7614 | schaersvoo | 126 | int clock_cnt = 0; /* counts the amount of clocks used -> unique object clock%d */ |
127 | int linegraph_cnt = 0; /* identifier for command 'linegraph' ; multiple line graphs may be plotted in a single plot*/ |
||
7989 | schaersvoo | 128 | int barchart_cnt = 0; /* identifier for command 'barchart' ; multiple charts may be plotted in a single plot*/ |
9433 | schaersvoo | 129 | int boxplot_cnt = 0; |
11890 | schaersvoo | 130 | int numberline_cnt = 0; |
7956 | schaersvoo | 131 | int legend_cnt = -1; /* to allow multiple legends to be used, for multiple piecharts etc */ |
8074 | schaersvoo | 132 | int reply_precision = 100; /* used for precision of student answers / drawings */ |
7614 | schaersvoo | 133 | double angle = 0.0; |
10953 | bpr | 134 | char *rotation_center = "null"; |
11893 | schaersvoo | 135 | int use_animate = 0; /* used for jscurve / js parametric */ |
7823 | schaersvoo | 136 | int use_input_xy = 0; /* 1= input fields 2= textarea 3=calc y value*/ |
10953 | bpr | 137 | int use_slider_display = 0; /* in case of a slider, should we display its value ?*/ |
8365 | schaersvoo | 138 | size_t string_length = 0; /* measure the size of the user input fly-string */ |
139 | double stroke_opacity = 0.8; /* use some opacity as default */ |
||
140 | double fill_opacity = 0.8;/* use some opacity as default */ |
||
7614 | schaersvoo | 141 | char *URL = "http://localhost/images"; |
9213 | schaersvoo | 142 | char *slider_function_x = "x"; |
143 | char *slider_function_y = "y"; |
||
7614 | schaersvoo | 144 | memset(buffer,'\0',MAX_BUFFER); |
145 | void *tmp_buffer = ""; |
||
146 | /* default writing a unzipped js-include file into wims getfile directory */ |
||
147 | char *w_wims_session = getenv("w_wims_session"); |
||
12104 | schaersvoo | 148 | 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 | 149 | int L0=strlen(w_wims_session) + 21; |
150 | char *getfile_dir = my_newmem(L0); /* create memory to fit string precisely */ |
||
151 | snprintf(getfile_dir,L0, "../sessions/%s/getfile",w_wims_session);/* string will fit precisely */ |
||
152 | mode_t process_mask = umask(0); /* check if file exists */ |
||
153 | int result = mkdir(getfile_dir, S_IRWXU | S_IRWXG | S_IRWXO); |
||
154 | if( result == 0 || errno == EEXIST ){ |
||
155 | umask(process_mask); /* be sure to set correct permission */ |
||
8224 | bpr | 156 | char *w_session = getenv("w_session"); |
7614 | schaersvoo | 157 | int L1 = (int) (strlen(w_session)) + find_number_of_digits(canvas_root_id) + 48; |
12104 | schaersvoo | 158 | getfile_cmd = my_newmem(L1); /* create memory to fit string precisely */ |
8224 | bpr | 159 | 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 | 160 | /* write the include tag to html page:<script src="wims.cgi?session=%s&cmd=getfile&special_parm=11223344_js"></script> */ |
7614 | schaersvoo | 161 | /* now write file into getfile dir*/ |
14066 | bpr | 162 | char *w_wims_home = getenv("w_wims_home"); /* "/home/users/wims": we need absolute path for location */ |
7614 | schaersvoo | 163 | int L2 = (int) (strlen(w_wims_home)) + (int) (strlen(w_wims_session)) + find_number_of_digits(canvas_root_id) + 23; |
164 | char *location = my_newmem(L2); /* create memory to fit string precisely */ |
||
165 | snprintf(location,L2,"%s/sessions/%s/getfile/%d.js",w_wims_home,w_wims_session,canvas_root_id);/*absolute path */ |
||
166 | js_include_file = fopen(location,"w");/* open the file location for writing */ |
||
14066 | bpr | 167 | /* check on opening...if nogood: mount readonly? disk full? permissions not set correctly? */ |
168 | if(js_include_file == NULL){ canvas_error("SHOULD NOT HAPPEN: could not write to javascript include file...check your system logfiles !" );} |
||
7614 | schaersvoo | 169 | |
170 | /* ----------------------------------------------------- */ |
||
11997 | schaersvoo | 171 | |
7614 | schaersvoo | 172 | /* while more lines to process */ |
173 | |||
174 | while(!finished){ |
||
9329 | schaersvoo | 175 | if(line_number>1 && found_size_command == 0 && use_tooltip != 2 ){canvas_error("command \"size xsize,ysize\" needs to come first ! ");} |
7614 | schaersvoo | 176 | type = get_token(infile); |
177 | done = FALSE; |
||
178 | /* |
||
9385 | schaersvoo | 179 | @ canvasdraw |
14078 | bpr | 180 | @ will try use the same syntax as@ general syntax <ul><li>The transparency of all objects can be controlled by command <a href="#opacity">opacity [0-255],[0,255]</a></il><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></li><li>a fillable object can be set fillable by starting the object command with an ''f`` (like frect,fcircle,ftriangle...)<br />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 />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><br />commands with only numeric or colour arguments may be using a '';`` as command separator (instead of a new line)<br />commands with a string argument may not use a '';`` as command separator !<br />these exceptions are not really straight forward... so keep this in mind.</li><li>almost every <a href="#userdraw">userdraw object,color</a> or <a href="#multidraw">multidraw</a> command <code>family</code> 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>single_object x1,y1,...,color</code></li><li><code>multi_object color,x1,y1,...</code></li></ul><li>All inputfields or textareas generated, can be styled individually using command <a href="#inputstyle">inputstyle 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> |
181 | @ 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 + "\\n" flydraw or svgdraw to paint a html5 bitmap image<br />by generating a tailor-made javascript include file: providing only the js-functionality needed to perform the job.<br />thus ensuring a minimal strain on the client browser <br />(unlike some popular ''canvas-do-it-all`` libraries, who have proven to be not suitable for low-end computers found in schools...) ;<br /> };<br /> };<br /> };<br /> if( found_result ){return draw_reply;}else{return null;};<br />};</code> |
||
11006 | schaersvoo | 182 | @ 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> |
14078 | bpr | 183 | @ 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> |
14071 | bpr | 184 | @ 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 |
10827 | schaersvoo | 185 | @ 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. |
14066 | bpr | 186 | @ there is limited support for touch devices: touchstart,touchmove and touchend in commands <a href="#userdraw">userdraw primitives </a>, <a href="#protractor">protractor</a> and <a href="#ruler">ruler</a><br />only single finger gestures are supported (for now)<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 | 187 | */ |
188 | switch(type){ |
||
189 | case END: |
||
190 | finished = 1; |
||
191 | done = TRUE; |
||
192 | break; |
||
193 | case 0: |
||
194 | sync_input(infile); |
||
195 | break; |
||
12063 | schaersvoo | 196 | |
197 | case CENTERED: |
||
198 | use_offset = 4; |
||
199 | /* |
||
200 | @ centered |
||
201 | @ keyword ; to place the text centered (in width and height) on the text coordinates(x:y) |
||
14071 | bpr | 202 | @ may be used for text exactly centered on its (x;y) |
12063 | schaersvoo | 203 | @ use <a href="#fontfamily">fontfamily</a> for setting the font |
14071 | bpr | 204 | @ 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``) |
12107 | schaersvoo | 205 | @%centered%size 400,400%xrange -10,10%yrange -10,10%fontfamily 12pt Ariel%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 |
12063 | schaersvoo | 206 | */ |
207 | break; |
||
208 | |||
7614 | schaersvoo | 209 | case COMMENT: |
210 | sync_input(infile); |
||
211 | break; |
||
11806 | schaersvoo | 212 | case AFFINE: |
7614 | schaersvoo | 213 | /* |
11806 | schaersvoo | 214 | @ affine a,b,c,d,tx,ty |
215 | @ defines a transformation matrix for subsequent objects |
||
13957 | schaersvoo | 216 | @ follows the HTML5 / Canvas transformation standards<br />note: images drawn by setting skew params a & d will thus be very different from Flydraw's "affine a,b,c,d,e,tx,ty" !! |
14066 | bpr | 217 | @ use keyword <a href='#killaffine'>killaffine</a> to end the transformation...the next objects will be drawn in the original x/y-range |
14071 | bpr | 218 | @ note 1: only ''draggable`` / ''onclick`` type of objects (e.g. objects in the ''drag/drop/onclick-library``) can be transformed. |
219 | @ note 2: do not use <code>onclick</code> or <code>drag xy</code> with tranformation / rotation objects: the mouse coordinates do not get transformed (yet) |
||
11806 | schaersvoo | 220 | @ note 3: no matrix operations on the transformation matrix implemented (yet) |
14066 | bpr | 221 | @ a: Scales the drawings horizontally |
222 | @ b: Skews the drawings horizontally |
||
223 | @ c: Skews the drawings vertically |
||
224 | @ d: Scales the drawings vertically |
||
11806 | schaersvoo | 225 | @ tx: Moves the drawings horizontally in xrange coordinate system |
226 | @ ty: Moves the drawings vertically in yrange coordinate system |
||
14078 | bpr | 227 | @ the data precision may be set by preceding command ''precision int`` |
12107 | schaersvoo | 228 | @%affine%size 400,400%xrange -10,10%yrange -10,10%opacity 255,255%fcircle 5,5,40,blue%affine 1,0,0,1,-10,-10%fcircle 5,5,40,green |
7614 | schaersvoo | 229 | */ |
11806 | schaersvoo | 230 | for(i = 0 ; i<6;i++){ |
7614 | schaersvoo | 231 | switch(i){ |
11806 | schaersvoo | 232 | case 0: double_data[0] = get_real(infile,0);break; |
233 | case 1: double_data[1] = get_real(infile,0);break; |
||
234 | case 2: double_data[2] = get_real(infile,0);break; |
||
235 | case 3: double_data[3] = get_real(infile,0);break; |
||
236 | case 4: double_data[4] = get_real(infile,0);break; |
||
237 | case 5: double_data[5] = get_real(infile,1); |
||
238 | use_affine = TRUE; |
||
239 | decimals = find_number_of_digits(precision); |
||
240 | string_length = snprintf(NULL,0, "[%.*f,%.*f,%.*f,%.*f,%.*f,%.*f] ",decimals,double_data[0],decimals,double_data[1],decimals,double_data[2],decimals,double_data[3],decimals,double_data[4]*xsize/(xmax - xmin),decimals,-1*double_data[5]*ysize/(ymax - ymin)); |
||
241 | check_string_length(string_length);affine_matrix = my_newmem(string_length+1); |
||
242 | snprintf(affine_matrix,string_length,"[%.*f,%.*f,%.*f,%.*f,%.*f,%.*f] ",decimals,double_data[0],decimals,double_data[1],decimals,double_data[2],decimals,double_data[3],decimals,double_data[4]*xsize/(xmax - xmin),decimals,-1*double_data[5]*ysize/(ymax - ymin)); |
||
243 | break; |
||
7614 | schaersvoo | 244 | default: break; |
245 | } |
||
246 | } |
||
11806 | schaersvoo | 247 | break; |
8386 | schaersvoo | 248 | |
11806 | schaersvoo | 249 | case ANGLE: |
7614 | schaersvoo | 250 | /* |
11806 | schaersvoo | 251 | @ angle xc,yc,width,start_angle,end_angle,color |
252 | @ width is in x-range |
||
253 | @ will zoom in/out |
||
14078 | bpr | 254 | @ if size is controlled by command <a href='#slider'>slider</a>, use radians to set limits of slider. |
12110 | schaersvoo | 255 | @%angle%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor orange%angle 0,0,4,10,135,blue |
13961 | schaersvoo | 256 | @%angle_slider%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 3%fillcolor black%strokecolor yellow%slider 0,2*pi,400,30,angle degrees,Rotate arrow%arrow 0,0,8,0,8,red%filled%fillcolor orange%angle 0,0,4,0,0,red |
7614 | schaersvoo | 257 | */ |
11806 | schaersvoo | 258 | for(i=0;i<7;i++){ |
7614 | schaersvoo | 259 | switch(i){ |
11806 | schaersvoo | 260 | case 0:double_data[0] = get_real(infile,0);break; /* x-values */ |
261 | case 1:double_data[1] = get_real(infile,0);break; /* y-values */ |
||
262 | case 2:double_data[2] = get_real(infile,0);break; /* width in pixels ! */ |
||
263 | case 3:double_data[3] = get_real(infile,0);break; /* start angle in degrees */ |
||
264 | case 4:double_data[4] = get_real(infile,0);break; /* end angle in degrees */ |
||
265 | case 5:stroke_color = get_color(infile,1);/* name or hex color */ |
||
266 | decimals = find_number_of_digits(precision); |
||
14045 | schaersvoo | 267 | fprintf(js_include_file,"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\",%d,%s,%d,%d,%s,%d,%d));\n",drag_type,click_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,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern); |
11806 | schaersvoo | 268 | reset(); |
269 | break; |
||
7614 | schaersvoo | 270 | } |
271 | } |
||
272 | break; |
||
8386 | schaersvoo | 273 | |
11806 | schaersvoo | 274 | case ANIMATE: |
7614 | schaersvoo | 275 | /* |
11930 | schaersvoo | 276 | @ animate |
11893 | schaersvoo | 277 | @ keyword |
14071 | bpr | 278 | @ the animated point is a filled rectangle ; adjust colour with command <code>fillcolor colorname/hexnumber</code> |
11893 | schaersvoo | 279 | @ use linewidth to adjust size of the points |
14078 | bpr | 280 | @ 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 |
13957 | schaersvoo | 281 | @ only usable for command jsplot (normal functions or parametric)<br />no other object/thing can be animated -for now |
282 | @ 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> |
||
283 | @ 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 | 284 | @%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) |
285 | @%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 | 286 | */ |
13512 | schaersvoo | 287 | use_animate++; |
288 | if( use_animate == 1 ){ |
||
289 | fprintf(js_include_file,"\nvar trace_canvas = create_canvas%d(%d,xsize,ysize);\ |
||
290 | var trace_ctx = trace_canvas.getContext('2d');\ |
||
291 | trace_ctx.fillStyle = 'rgba(%s,%f)';\ |
||
292 | trace_ctx.strokeStyle = 'rgba(%s,%f)';\ |
||
293 | trace_ctx.lineWidth = %d;var anim_pos = 0;\n\ |
||
294 | function animate_this(){\ |
||
295 | var sync;\ |
||
296 | var synchrone = Math.floor(animation_steps/animation_funs);\ |
||
297 | trace_ctx.clearRect(0,0,xsize,ysize);\ |
||
298 | for(var p=0; p<animation_funs;p++){\ |
||
299 | sync = p*synchrone;\ |
||
300 | trace_ctx.fillRect(x_anim_points[sync+anim_pos]-%d, y_anim_points[sync+anim_pos]-%d,%d,%d);\ |
||
301 | };\ |
||
302 | setTimeout(function(){\ |
||
303 | requestAnimationFrame(animate_this); anim_pos++;}, 50\ |
||
304 | );\ |
||
305 | if(anim_pos >= animation_steps){anim_pos = 0;};\ |
||
306 | };",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); |
||
307 | } |
||
308 | else |
||
309 | { |
||
13514 | schaersvoo | 310 | 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 | 311 | } |
7614 | schaersvoo | 312 | break; |
8386 | schaersvoo | 313 | |
11806 | schaersvoo | 314 | case ARC: |
7614 | schaersvoo | 315 | /* |
11997 | schaersvoo | 316 | @ arc xc,yc,x-width,y-height,start_angle,end_angle,color |
14071 | bpr | 317 | @ can <b>not</b> be set ''onclick`` or ''drag xy`` |
11806 | schaersvoo | 318 | @ <b>attention</b>: width in height in x/y-range |
12110 | schaersvoo | 319 | @%arc%size 400,400%xrange -10,10%yrange -10,10%arc 0,0,4,4,10,135,red%zoom blue |
13961 | schaersvoo | 320 | @%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 |
321 | @%arc_slider%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 3%fillcolor black%strokecolor yellow%slider 0,2*pi,400,30,angle degree,Rotate arrow%arrow 0,0,8,0,8,red%filled%fillcolor orange%fillpatter hatch%opacity 255,80%arc 0,0,8,8,0,0,red |
||
7614 | schaersvoo | 322 | */ |
11806 | schaersvoo | 323 | for(i=0;i<7;i++){ |
324 | switch(i){ |
||
325 | case 0:double_data[0] = get_real(infile,0);break; /* x-values */ |
||
326 | case 1:double_data[1] = get_real(infile,0);break; /* y-values */ |
||
327 | case 2:double_data[2] = get_real(infile,0);break; /* width x-range no pixels ! */ |
||
328 | case 3:double_data[3] = get_real(infile,0);break; /* height y-range no pixels ! */ |
||
329 | case 4:double_data[4] = get_real(infile,0);break; /* start angle in degrees */ |
||
330 | case 5:double_data[5] = get_real(infile,0);break; /* end angle in degrees */ |
||
331 | case 6:stroke_color = get_color(infile,1);/* name or hex color */ |
||
332 | /* in Shape library: |
||
333 | x[0] = x[1] = xc = double_data[0] |
||
334 | y[0] = y[1] = yc = double_data[1] |
||
335 | w[0] = width = double_data[2] |
||
336 | w[1] = height = double_data[3] |
||
337 | h[0] = start_angle = double_data[4] |
||
338 | h[1] = end_angle = double_data[5] |
||
339 | */ |
||
340 | decimals = find_number_of_digits(precision); |
||
14045 | schaersvoo | 341 | fprintf(js_include_file,"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\",%d,%s,%d,%d,%s,%d,%d));\n",drag_type,click_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,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern); |
11806 | schaersvoo | 342 | reset(); |
343 | break; |
||
344 | } |
||
345 | } |
||
7614 | schaersvoo | 346 | break; |
11806 | schaersvoo | 347 | case ARROW: |
7614 | schaersvoo | 348 | /* |
11806 | schaersvoo | 349 | @ arrow x1,y1,x2,y2,h,color |
14071 | bpr | 350 | @ alternative: <code>vector</code> |
11806 | schaersvoo | 351 | @ 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 | 352 | @ use command <code>linewidth int</code> to adjust thickness of the arrow |
9406 | schaersvoo | 353 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
13957 | schaersvoo | 354 | @%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 |
355 | @%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 | 356 | */ |
11806 | schaersvoo | 357 | for(i=0;i<6;i++){ |
7614 | schaersvoo | 358 | switch(i){ |
359 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
360 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
11806 | schaersvoo | 361 | case 2: double_data[2] = get_real(infile,0);break; /* x */ |
362 | case 3: double_data[3] = get_real(infile,0);break; /* y */ |
||
363 | case 4: arrow_head = (int) get_real(infile,0);break;/* h */ |
||
364 | case 5: stroke_color = get_color(infile,1);/* name or hex color */ |
||
7614 | schaersvoo | 365 | decimals = find_number_of_digits(precision); |
14045 | schaersvoo | 366 | fprintf(js_include_file,"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\",%d,%s,%d,%d,%s,%d,%d));\n",drag_type,click_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,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern); |
11806 | schaersvoo | 367 | if(onclick > 0){click_cnt++;} |
368 | /* click_cnt++;*/ |
||
369 | reset(); |
||
370 | break; |
||
371 | } |
||
372 | } |
||
373 | break; |
||
8386 | schaersvoo | 374 | |
11806 | schaersvoo | 375 | case ARROWS: |
7614 | schaersvoo | 376 | /* |
11806 | schaersvoo | 377 | @ arrows color,head (px),x1,y1,x2,y2...x_n,y_n |
14071 | bpr | 378 | @ alternative: <code>vectors</code> |
11806 | schaersvoo | 379 | @ draw single headed arrows / vectors from (x1:y1) to (x2:y2) ... (x3:y3) to (x4:y4) etc ... in color 'color' |
14071 | bpr | 380 | @ use command <code>linewidth int</code> to adjust thickness of the arrow |
11806 | schaersvoo | 381 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually |
13957 | schaersvoo | 382 | @%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% |
383 | @%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% |
||
7614 | schaersvoo | 384 | */ |
385 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
386 | fill_color = stroke_color; |
||
11806 | schaersvoo | 387 | arrow_head = (int) get_real(infile,0);/* h */ |
7614 | schaersvoo | 388 | i=0; |
389 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 390 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
7614 | schaersvoo | 391 | if(i%2 == 0 ){ |
392 | double_data[i] = get_real(infile,0); /* x */ |
||
393 | } |
||
394 | else |
||
395 | { |
||
396 | double_data[i] = get_real(infile,1); /* y */ |
||
397 | } |
||
398 | i++; |
||
399 | } |
||
400 | decimals = find_number_of_digits(precision); |
||
11806 | schaersvoo | 401 | for(c = 0 ; c < i-1 ; c = c+4){ |
14045 | schaersvoo | 402 | fprintf(js_include_file,"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\",%d,%s,%d,%d,%s,%d,%d));\n",drag_type,click_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,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern); |
11806 | schaersvoo | 403 | if(onclick > 0){click_cnt++;} |
8379 | schaersvoo | 404 | /* click_cnt++; */ |
7614 | schaersvoo | 405 | } |
406 | reset(); |
||
407 | break; |
||
8386 | schaersvoo | 408 | |
11806 | schaersvoo | 409 | case ARROW2: |
7614 | schaersvoo | 410 | /* |
11806 | schaersvoo | 411 | @ arrow2 x1,y1,x2,y2,h,color |
14071 | bpr | 412 | @ draw a double headed arrow/vector from (x1:y1) to (x2:y2)<br />with arrowhead size h in px and in color ''color`` |
413 | @ use command <code>arrowhead int</code> to adjust the arrow head size |
||
414 | @ use command <code>linewidth int</code> to adjust thickness of the arrow |
||
9406 | schaersvoo | 415 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
12107 | schaersvoo | 416 | @%arrow2%size 400,400%xrange -10,10%yrange -10,10%drag xy%arrow2 0,0,4,3,8,blue% |
7614 | schaersvoo | 417 | */ |
11806 | schaersvoo | 418 | for(i=0;i<6;i++){ |
7614 | schaersvoo | 419 | switch(i){ |
420 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
421 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
11806 | schaersvoo | 422 | case 2: double_data[2] = get_real(infile,0);break; /* x */ |
423 | case 3: double_data[3] = get_real(infile,0);break; /* y */ |
||
424 | case 4: arrow_head = (int) get_real(infile,0);break;/* h */ |
||
425 | case 5: stroke_color = get_color(infile,1);/* name or hex color */ |
||
426 | decimals = find_number_of_digits(precision); |
||
14045 | schaersvoo | 427 | fprintf(js_include_file,"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\",%d,%s,%d,%d,%s,%d,%d));\n",drag_type,click_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,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern); |
11806 | schaersvoo | 428 | if(onclick > 0){click_cnt++;} |
429 | /* click_cnt++;*/ |
||
430 | reset(); |
||
431 | break; |
||
432 | } |
||
433 | } |
||
434 | break; |
||
8386 | schaersvoo | 435 | |
11806 | schaersvoo | 436 | case ARROWS2: |
7614 | schaersvoo | 437 | /* |
11806 | schaersvoo | 438 | @ arrows2 color,head (px),x1,y1,x2,y2...x_n,y_n |
14071 | bpr | 439 | @ draw double headed arrows / vectors from (x1:y1) to (x2:y2) ... (x3:y3) to (x4:y4) etc ... in color ''color`` |
440 | @ use command <code>linewidth int</code> to adjust thickness of the arrows |
||
11806 | schaersvoo | 441 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually |
12107 | schaersvoo | 442 | @%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 | 443 | */ |
444 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
445 | fill_color = stroke_color; |
||
11806 | schaersvoo | 446 | arrow_head = (int) get_real(infile,0);/* h */ |
7614 | schaersvoo | 447 | i=0; |
448 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 449 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
7614 | schaersvoo | 450 | if(i%2 == 0 ){ |
451 | double_data[i] = get_real(infile,0); /* x */ |
||
452 | } |
||
453 | else |
||
454 | { |
||
455 | double_data[i] = get_real(infile,1); /* y */ |
||
456 | } |
||
457 | i++; |
||
458 | } |
||
8224 | bpr | 459 | decimals = find_number_of_digits(precision); |
11806 | schaersvoo | 460 | for(c = 0 ; c < i-1 ; c = c+4){ |
14045 | schaersvoo | 461 | fprintf(js_include_file,"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\",%d,%s,%d,%d,%s,%d,%d));\n",drag_type,click_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,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern); |
11806 | schaersvoo | 462 | if(onclick > 0){click_cnt++;} |
8379 | schaersvoo | 463 | /* click_cnt++; */ |
11806 | schaersvoo | 464 | |
7614 | schaersvoo | 465 | } |
466 | reset(); |
||
467 | break; |
||
11806 | schaersvoo | 468 | case ARROWHEAD: |
9427 | schaersvoo | 469 | /* |
11806 | schaersvoo | 470 | @ arrowhead int |
471 | @ default 8 (pixels) |
||
9427 | schaersvoo | 472 | */ |
11806 | schaersvoo | 473 | arrow_head = (int) (get_real(infile,1)); |
474 | break; |
||
475 | |||
476 | case AUDIO: |
||
477 | /* |
||
478 | @ audio x,y,w,h,loop,visible,audiofile location |
||
14066 | bpr | 479 | @ x,y: left top corner of audio element (in xrange / yrange) |
480 | @ w,y: width and height in pixels |
||
481 | @ loop: 0 or 1 ( 1 = loop audio fragment) |
||
482 | @ visible: 0 or 1 (1 = show controls) |
||
11806 | schaersvoo | 483 | @ audio format may be in *.mp3 or *.ogg |
14066 | bpr | 484 | @ If you are using *.mp3: be aware that FireFox will not (never) play this ! (Pattented format) |
485 | @ if you are using *.ogg: be aware that Microsoft based systems not support it natively |
||
11806 | schaersvoo | 486 | @ To avoid problems supply both types (mp3 and ogg) of audiofiles.<br />the program will use both as source tag |
487 | */ |
||
488 | if( js_function[DRAW_AUDIO] != 1 ){ js_function[DRAW_AUDIO] = 1;} |
||
489 | for(i=0;i<7;i++){ |
||
490 | switch(i){ |
||
491 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */ |
||
492 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system -> pixel */ |
||
493 | case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */ |
||
494 | case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */ |
||
495 | case 4: int_data[4] = (int) (get_real(infile,0)); if(int_data[4] != TRUE){int_data[4] = FALSE;} break; /* loop boolean */ |
||
496 | case 5: int_data[5] = (int) (get_real(infile,0)); if(int_data[5] != TRUE){int_data[5] = FALSE;} break; /* visible boolean */ |
||
497 | case 6: |
||
498 | temp = get_string(infile,1); |
||
499 | if( strstr(temp,".mp3") != 0 ){ temp = str_replace(temp,".mp3","");} |
||
500 | if( strstr(temp,".ogg") != 0 ){ temp = str_replace(temp,".ogg","");} |
||
501 | string_length = snprintf(NULL,0, "draw_audio(%d,%d,%d,%d,%d,%d,%d,\"%s.ogg\",\"%s.mp3\");\n",canvas_root_id,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],temp,temp); |
||
502 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
503 | 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); |
||
504 | add_to_buffer(tmp_buffer); |
||
505 | break; |
||
506 | default:break; |
||
9427 | schaersvoo | 507 | } |
11806 | schaersvoo | 508 | } |
509 | reset(); |
||
510 | break; |
||
511 | |||
512 | |||
513 | case AXIS_NUMBERING: |
||
514 | /* |
||
515 | @ axisnumbering |
||
516 | @ keyword (no arguments required) |
||
14078 | bpr | 517 | @ 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 | 518 | @ to be used before command grid (see <a href="#grid">command grid</a>) |
519 | */ |
||
11891 | schaersvoo | 520 | use_axis_numbering++; |
11806 | schaersvoo | 521 | break; |
522 | case AXIS: |
||
523 | /* |
||
524 | @ axis |
||
525 | @ keyword (no arguments required) |
||
526 | @ to be used before command grid (see <a href="#grid">command grid</a>) |
||
527 | |||
528 | */ |
||
529 | use_axis = TRUE; |
||
530 | break; |
||
531 | |||
532 | case BARCHART: |
||
533 | /* |
||
534 | @ barchart x_1:y_1:color_1:x_2:y_2:color_2:...x_n:y_n:color_n |
||
14066 | bpr | 535 | @ may <b>only</b> to be used together with command <a href='#grid'>grid</a> |
536 | @ 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> |
||
537 | @ use command <a href='#legend'>legend</a> to provide an optional legend in right-top-corner |
||
11806 | schaersvoo | 538 | @ multiple barchart command may be used in a single script |
14066 | bpr | 539 | @ also see command <a href='#piechart'>piechart</a> |
540 | @ note: your arguments are not checked by canvasdraw: use your javascript console in case of trouble... |
||
12107 | schaersvoo | 541 | @%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 Ariel%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 | 542 | */ |
543 | temp = get_string(infile,1); |
||
544 | if( strstr( temp,":" ) != 0 ){ temp = str_replace(temp,":","\",\""); } |
||
545 | fprintf(js_include_file,"var barchart_%d = [\"%s\"];",barchart_cnt,temp); |
||
546 | barchart_cnt++; |
||
547 | reset(); |
||
548 | break; |
||
549 | |||
550 | case BEZIER: |
||
551 | /* |
||
552 | @ bezier color,x_start,y_start,x_first,y_first,x_second,y_second,x_end,y_end |
||
553 | @ draw a bezier curve between points, starting from (x_start:y_start) |
||
554 | @ can <b>not</b> be dragged or set onclick |
||
555 | */ |
||
556 | if( js_function[DRAW_BEZIER] != 1 ){ js_function[DRAW_BEZIER] = 1;} |
||
557 | decimals = find_number_of_digits(precision); |
||
558 | for(i = 0 ; i < 9; i++){ |
||
559 | switch(i){ |
||
560 | case 0: stroke_color = get_color(infile,0);break; |
||
561 | case 1: double_data[0] = get_real(infile,0);break;/* start x */ |
||
562 | case 2: double_data[1] = get_real(infile,0);break;/* start y */ |
||
563 | case 3: double_data[2] = get_real(infile,0);break;/*The x-coordinate of the first Bézier control point */ |
||
564 | case 4: double_data[3] = get_real(infile,0);break;/*The y-coordinate of the first Bézier control point */ |
||
565 | case 5: double_data[4] = get_real(infile,0);break;/*The x-coordinate of the second Bézier control point */ |
||
566 | case 6: double_data[5] = get_real(infile,0);break;/*The y-coordinate of the second Bézier control point */ |
||
567 | case 7: double_data[6] = get_real(infile,0);break;/*The x-coordinate of the Bézier end point */ |
||
568 | case 8: double_data[7] = get_real(infile,1);/*The y-coordinate of the Bézier end point */ |
||
569 | string_length = 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,%d,%s);",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,use_affine,affine_matrix); |
||
570 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
571 | 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,%d,%s);",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,use_affine,affine_matrix); |
||
572 | add_to_buffer(tmp_buffer); |
||
573 | break; |
||
574 | default: break; |
||
9427 | schaersvoo | 575 | } |
576 | } |
||
577 | reset(); |
||
578 | break; |
||
11806 | schaersvoo | 579 | |
580 | |||
581 | case BGCOLOR: |
||
9427 | schaersvoo | 582 | /* |
11806 | schaersvoo | 583 | @ bgcolor colorname or #hex |
584 | @ use this color as background of the "div" containing the canvas(es) |
||
12110 | schaersvoo | 585 | @%bgcolor%size 400,400%xrange -10,10%yrange -10,10%bgcolor lightblue |
9427 | schaersvoo | 586 | */ |
11806 | schaersvoo | 587 | /* [255,255,255]*/ |
588 | bgcolor = get_string(infile,1); |
||
589 | if(strstr(bgcolor,"#") == NULL){ /* convert colorname -> #ff00ff */ |
||
590 | int found = 0; |
||
591 | for( i = 0; i < NUMBER_OF_COLORNAMES ; i++ ){ |
||
592 | if( strcmp( colors[i].name , bgcolor ) == 0 ){ |
||
593 | bgcolor = colors[i].hex; |
||
594 | found = 1; |
||
595 | break; |
||
596 | } |
||
9427 | schaersvoo | 597 | } |
14066 | bpr | 598 | if(found == 0){canvas_error("your bgcolor is not in my rgb.txt data list: use hexcolor...something like #a0ffc4");} |
11806 | schaersvoo | 599 | } |
13970 | obado | 600 | 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 | 601 | break; |
602 | |||
603 | case BGIMAGE: |
||
604 | /* |
||
605 | @ bgimage image_location |
||
14071 | bpr | 606 | @ use an image as background; technical: we use the background of ''canvas_div`` |
11806 | schaersvoo | 607 | @ the background image will be resized to match "width = xsize" and "height = ysize" |
12110 | schaersvoo | 608 | @%bgimage%size 400,400%xrange -10,10%yrange -10,10%bgimage https://wims.unice.fr/wims/gifs/en.gif |
11806 | schaersvoo | 609 | */ |
610 | URL = get_string(infile,1); |
||
13970 | obado | 611 | 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 | 612 | break; |
613 | |||
614 | case BLINK: |
||
615 | /* |
||
616 | @ blink time(seconds) |
||
617 | @ NOT IMPLEMETED -YET |
||
618 | */ |
||
619 | break; |
||
620 | |||
621 | case BOXPLOT: |
||
622 | /* |
||
623 | @ boxplot x_or_y,box-height_or_box-width,position,min,Q1,median,Q3,max |
||
14066 | bpr | 624 | @ 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 |
625 | @ 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 |
||
626 | @ 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 |
||
627 | @ use command <a href='#fillpattern'>fillpattern some_pattern</a> to use a (diamond for Q1, hatch for Q3) pattern. |
||
628 | @ use command <a href='#opacity'>opacity</a> to adjust fill_opacity of stroke and fill colours |
||
14071 | bpr | 629 | @ use command <a href='#legend'>legend</a> to automatically create a legend <br />unicode allowed in legend<br />use command <code>fontfamily</code> to set the font of the legend. |
11806 | schaersvoo | 630 | @ there is no limit to the number of boxplots used. |
14078 | bpr | 631 | @ can <b>not</b> be set draggable and <a href='#onclick'>onclick</a> is not ready yet |
14066 | bpr | 632 | @ 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) |
633 | @ use keyword <a href="#userboxplotdata">userboxplotdata</a> before command boxplot, if a pupil must generate the data by some means. |
||
634 | @ use command <a href="#boxplotdata">boxplotdata</a> when the boxplot should be drawn from wims-generated raw statistical date |
||
12110 | schaersvoo | 635 | @%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 |
636 | @%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 | 637 | @%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 | 638 | */ |
639 | if( js_function[DRAW_BOXPLOT] != 1 ){ js_function[DRAW_BOXPLOT] = 1;} |
||
640 | for(i=0;i<8;i++){ |
||
641 | switch(i){ |
||
642 | case 0: temp = get_string_argument(infile,0); |
||
643 | if( strstr(temp,"x") != 0){int_data[0] = 1;}else{int_data[0] = 0;} break; /* x or y */ |
||
644 | case 1: double_data[0] = get_real(infile,0);break;/* height | width */ |
||
645 | case 2: |
||
646 | if( js_function[DRAW_JSBOXPLOT] == 0 ){ |
||
647 | double_data[1] = get_real(infile,0); |
||
648 | fprintf(js_include_file,"var boxplot_source = 0;\n");/* we use given min,Q1,median,Q3,max */ |
||
649 | } |
||
650 | else |
||
651 | { |
||
652 | double_data[1] = get_real(infile,1); |
||
653 | double_data[2] = 1; |
||
654 | double_data[3] = 1; |
||
655 | double_data[4] = 1; |
||
656 | double_data[5] = 1; |
||
657 | double_data[6] = 1; |
||
658 | double_data[7] = 1; |
||
659 | i=8; |
||
660 | } |
||
661 | break;/* center value x or y */ |
||
662 | case 3: double_data[2] = get_real(infile,0); break;/* min */ |
||
663 | case 4: double_data[3] = get_real(infile,0); break;/* Q1 */ |
||
664 | case 5: double_data[4] = get_real(infile,0); break;/* median */ |
||
665 | case 6: double_data[5] = get_real(infile,0); break;/* Q3 */ |
||
666 | case 7: double_data[6] = get_real(infile,1); break;/* max */ |
||
667 | default:break; |
||
9427 | schaersvoo | 668 | } |
669 | } |
||
670 | decimals = find_number_of_digits(precision); |
||
11806 | schaersvoo | 671 | /*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)*/ |
672 | string_length = 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]); |
||
673 | check_string_length(string_length); |
||
674 | tmp_buffer = my_newmem(string_length+1); |
||
675 | 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]); |
||
676 | add_to_buffer(tmp_buffer); |
||
677 | boxplot_cnt++; |
||
678 | reset(); |
||
679 | break; |
||
680 | case BOXPLOTDATA: |
||
681 | /* |
||
682 | @ boxplotdata some_data |
||
683 | @ 'some_data' are a list of numbers separated by a comma "," (items) |
||
14071 | bpr | 684 | @ 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 | 685 | @ 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 |
686 | @ note: wims will not check your data input | format. use js-error console to debug any problems. |
||
14071 | bpr | 687 | @ 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. |
688 | @ 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 | 689 | @%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 | 690 | */ |
691 | if( js_function[DRAW_JSBOXPLOT] != 1 ){ js_function[DRAW_JSBOXPLOT] = 1;} |
||
692 | if( js_function[DRAW_BOXPLOT] != 1 ){ js_function[DRAW_BOXPLOT] = 1;} |
||
693 | fprintf(js_include_file,"var boxplot_source = 1;var jsboxplot_data = [%s];\n",get_string(infile,1)); |
||
694 | |||
695 | break; |
||
696 | |||
697 | case CANVASTYPE: |
||
698 | canvas_type = (int) (get_real(infile,1)); |
||
699 | /* |
||
700 | @ canvastype TYPE |
||
13987 | bpr | 701 | @ 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 | 702 | @ default value of TYPE is DRAG_CANVAS e.g. 5 (all clickable / draggable object are in this canvas) |
703 | @ use another TYPE, if you know what you are doing... |
||
14078 | bpr | 704 | @ other possible canvasses (transparent PNG pictures xsize x 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 | 705 | */ |
706 | break; |
||
707 | |||
708 | case CENTERSTRING: |
||
709 | /* |
||
710 | @ centerstring color,y-value,the text string |
||
711 | @ title color,y-value,the text string |
||
712 | @ draw a string centered on the canvas at y = y-value |
||
14071 | bpr | 713 | @ can not be set ''onclick`` or ''drag xy`` (...) |
11806 | schaersvoo | 714 | @ unicode supported: centerstring red,5,\\u2232 |
14071 | bpr | 715 | @ use a command like <code>fontfamily italic 24pt Ariel</code> to set fonts on browser that support font change |
12110 | schaersvoo | 716 | @%centerstring%size 400,400%xrange -10,10%yrange -10,10%bgcolor lightblue%fontfamily italic 22pt Courier%centerstring blue,7,the center |
11806 | schaersvoo | 717 | */ |
718 | if( js_function[DRAW_CENTERSTRING] != 1 ){ js_function[DRAW_CENTERSTRING] = 1;} |
||
719 | for(i=0;i<3;i++){ |
||
720 | switch(i){ |
||
721 | case 0: stroke_color = get_color(infile,0);break;/* name or hex color */ |
||
722 | case 1: double_data[0] = get_real(infile,0);break; /* y in xrange*/ |
||
723 | case 2: temp = get_string_argument(infile,1); |
||
724 | /* draw_text = function(canvas_type,y,font_family,stroke_color,stroke_opacity,text) */ |
||
725 | decimals = find_number_of_digits(precision); |
||
726 | string_length = snprintf(NULL,0, |
||
727 | "draw_centerstring(%d,%.*f,\"%s\",\"%s\",%.2f,\"%s\");\n",canvas_root_id,decimals,double_data[0],font_family,stroke_color,stroke_opacity,temp); |
||
728 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
729 | 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); |
||
730 | add_to_buffer(tmp_buffer); |
||
731 | break; |
||
732 | default:break; |
||
733 | } |
||
9427 | schaersvoo | 734 | } |
735 | break; |
||
8386 | schaersvoo | 736 | |
11806 | schaersvoo | 737 | |
8386 | schaersvoo | 738 | case CIRCLE: |
8299 | schaersvoo | 739 | /* |
8386 | schaersvoo | 740 | @ circle xc,yc,width (2*r in pixels),color |
14071 | bpr | 741 | @ use command <code>fcircle xc,yc,d,color</code> |
9383 | schaersvoo | 742 | @ alternative: disk for a filled circle |
14071 | bpr | 743 | @ use command <code>fillcolor color</code> to set the fillcolor |
744 | @ may be set <a href='#drag'>draggable</a> / <a href='#onclick'>onclick</a> |
||
8386 | schaersvoo | 745 | @ will shrink / expand on zoom out / zoom in |
12110 | schaersvoo | 746 | @%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 | 747 | */ |
8386 | schaersvoo | 748 | for(i=0;i<4;i++){ |
749 | switch(i){ |
||
750 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
751 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
14066 | bpr | 752 | case 2: double_data[2] = px2x((get_real(infile,0))/2) - px2x(0);break; /* for zoom in/out: radius in 'dx' xrange*/ |
8386 | schaersvoo | 753 | case 3: stroke_color = get_color(infile,1);/* name or hex color */ |
754 | decimals = find_number_of_digits(precision); |
||
14045 | schaersvoo | 755 | fprintf(js_include_file,"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\",%d,%s,%d,%d,%s,%d,%d));\n",drag_type,click_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,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern); |
8386 | schaersvoo | 756 | if(onclick > 0){click_cnt++;} |
757 | /* click_cnt++;*/ |
||
758 | reset(); |
||
759 | break; |
||
760 | default : break; |
||
761 | } |
||
762 | } |
||
763 | break; |
||
764 | |||
765 | case CIRCLES: |
||
766 | /* |
||
767 | @ circles color,xc1,yc1,r1,xc2,yc2,r2...xc_n,yc_n,r_n |
||
9383 | schaersvoo | 768 | @ <b>attention</b> r = radius in x-range (!) |
14071 | bpr | 769 | @ use keyword <code>filled</code> or command <code>fcircles</code> to produce solid circles |
14066 | bpr | 770 | @ alternative: disks for filled circles |
14071 | bpr | 771 | @ use command <code>fillcolor color</code> to set the fillcolor |
772 | @ may be set <a href='#drag'>draggable</a> / <a href='#onclick'>onclick</a> (individually) |
||
8386 | schaersvoo | 773 | @ will shrink / expand on zoom out / zoom in |
12110 | schaersvoo | 774 | @%circles%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 |
8386 | schaersvoo | 775 | */ |
8299 | schaersvoo | 776 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
777 | fill_color = stroke_color; |
||
8386 | schaersvoo | 778 | i=1; |
8299 | schaersvoo | 779 | while( ! done ){ /* get next item until EOL*/ |
11997 | schaersvoo | 780 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
8386 | schaersvoo | 781 | switch (i%3){ |
782 | case 1:double_data[i-1] = get_real(infile,0);break; /* x */ |
||
783 | case 2:double_data[i-1] = get_real(infile,0);break; /* y */ |
||
784 | case 0:double_data[i-1] = get_real(infile,1);break; /* r */ |
||
8299 | schaersvoo | 785 | } |
786 | i++; |
||
787 | } |
||
788 | decimals = find_number_of_digits(precision); |
||
8386 | schaersvoo | 789 | for(c = 0 ; c < i-1 ; c = c+3){ |
14045 | schaersvoo | 790 | fprintf(js_include_file,"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\",%d,%s,%d,%d,%s,%d,%d));\n",drag_type,click_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,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern); |
8379 | schaersvoo | 791 | if(onclick > 0){click_cnt++;} |
8386 | schaersvoo | 792 | /* click_cnt++; */ |
8299 | schaersvoo | 793 | } |
794 | reset(); |
||
795 | break; |
||
11806 | schaersvoo | 796 | case CLEARBUTTON: |
797 | /* |
||
798 | @ clearbutton value |
||
14071 | bpr | 799 | @ alternative: <code>delete</code> |
800 | @ alternative: <code>erase</code> |
||
14078 | bpr | 801 | @ adds a button to clear the <a href="#userdraw">userdraw</a> canvas with text ''value`` |
14071 | bpr | 802 | @ <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 drawprimitive) |
11806 | schaersvoo | 803 | @ 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 | 804 | @ uses the tooltip placeholder div element: may not be used with command <code>intooltip</code> |
14066 | bpr | 805 | @ use command <a href="#inputstyle">inputstyle</a> to style the button... |
14071 | bpr | 806 | @ 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 | 807 | @%clearbutton%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor lightblue%opacity 255,50%userdraw circles,red%clearbutton Remove All |
11806 | schaersvoo | 808 | */ |
809 | if(reply_format == 29){/* eg multidraw is selected */ |
||
14054 | schaersvoo | 810 | // canvas_error("command clearbutton incompatible with multidraw...only suitable for userdraw"); |
11806 | schaersvoo | 811 | } |
812 | add_clear_button(js_include_file,canvas_root_id,input_style,get_string(infile,1)); |
||
813 | break; |
||
8386 | schaersvoo | 814 | |
11806 | schaersvoo | 815 | case CLOCK: |
7614 | schaersvoo | 816 | /* |
11806 | schaersvoo | 817 | @ clock x,y,r(px),H,M,S,type hourglass,interactive [ ,H_color,M_color,S_color,background_color,foreground_color ] |
14071 | bpr | 818 | @ use command <code>opacity stroke-opacity,fill-opacity</code> to adjust foreground (stroke) and background (fill) transparency |
14066 | bpr | 819 | @ type hourglass:<br />type = 0: only segments<br />type = 1: only numbers<br />type = 2: numbers and segments |
11806 | schaersvoo | 820 | @ 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 |
821 | @ if you don't want a seconds hand (or minutes...), just make it invisible by using the background color of the hourglass... |
||
14066 | bpr | 822 | @ 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 | 823 | @ canvasdraw will not check validity of colornames...the javascript console is your best friend |
824 | @ no combinations with other reply_types allowed, for now |
||
14077 | bpr | 825 | @ 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 |
826 | @ 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 | 827 | @ note: clocks will not zoom or pan, when using command <a href='#zoom'>zoom</a> |
12110 | schaersvoo | 828 | @%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 |
829 | @%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 |
||
830 | @%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 |
||
831 | @%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 |
||
832 | @%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 |
||
833 | @%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 |
||
834 | @%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 | 835 | */ |
11806 | schaersvoo | 836 | if( js_function[DRAW_CLOCK] != 1 ){ js_function[DRAW_CLOCK] = 1;} |
837 | |||
838 | /* var clock = function(xc,yc,radius,H,M,S,h_color,m_color,s_color,bg_color,fg_color) */ |
||
839 | for(i=0;i<9;i++){ |
||
840 | switch(i){ |
||
841 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* xc */ |
||
842 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* yc */ |
||
843 | case 2: int_data[2] = get_real(infile,0);break;/* radius in px */ |
||
844 | case 3: int_data[3] = get_real(infile,0);break;/* hours */ |
||
845 | case 4: int_data[4] = get_real(infile,0);break;/* minutes */ |
||
846 | case 5: int_data[5] = get_real(infile,0);break;/* seconds */ |
||
847 | 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 */ |
||
848 | case 7: int_data[7] = (int)(get_real(infile,1));/* interactive 0,1,2*/ |
||
849 | switch(int_data[7]){ |
||
850 | case 0:break; |
||
851 | case 1:if(clock_cnt == 0){ |
||
852 | if( reply_format == 0 ){ |
||
853 | reply_format = 18; /* user sets clock */ |
||
854 | /* string_length = snprintf(NULL,0,"set_clock = function(num,type,diff){var name = eval(\"clocks\"+num);switch(type){case 1:name.H = parseInt(name.H+diff);break;case 2:name.M = parseInt(name.M+diff);break;case 3:name.S = parseInt(name.S+diff);break;default: break;};name = clock(name.xc,name.yc,name.radius,name.H,name.M,name.S,name.type,name.interaction,name.H_color,name.M_color,name.S_color,name.bg_color,name.fg_color);};\n"); |
||
855 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
856 | 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"); |
||
857 | add_to_buffer(tmp_buffer); |
||
858 | */ |
||
859 | 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"); |
||
860 | } |
||
861 | else |
||
862 | { |
||
863 | canvas_error("interactive clock may not be used together with other reply_types..."); |
||
864 | } |
||
865 | } |
||
866 | fprintf(stdout,"<p style=\"text-align:center\"><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,1,1)\" value=\"H+\" /><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,2,1)\" value=\"M+\" /><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,3,1)\" value=\"S+\" /><br /><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,1,-1)\" value=\"H−\" /><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,2,-1)\" value=\"M−\" /><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,3,-1)\" value=\"S−\" /></p>",input_style,clock_cnt,input_style,clock_cnt,input_style,clock_cnt,input_style,clock_cnt,input_style,clock_cnt,input_style,clock_cnt); |
||
867 | break; |
||
868 | case 3:if(clock_cnt == 0){ |
||
869 | if( reply_format == 0 ){ |
||
870 | reply_format = 18; /* user sets clock */ |
||
871 | 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"); |
||
872 | } |
||
873 | else |
||
874 | { |
||
875 | canvas_error("interactive clock may not be used together with other reply_types..."); |
||
876 | } |
||
877 | } |
||
878 | /* |
||
879 | fprintf(stdout,"<p style=\"text-align:center\"><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,1,1)\" value=\"H+\" /><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,2,1)\" value=\"M+\" /><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,3,1)\" value=\"S+\" /><br /><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,1,-1)\" value=\"H−\" /><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,2,-1)\" value=\"M−\" /><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,3,-1)\" value=\"S−\" /></p>",input_style,clock_cnt,input_style,clock_cnt,input_style,clock_cnt,input_style,clock_cnt,input_style,clock_cnt,input_style,clock_cnt); |
||
880 | */ |
||
881 | break; |
||
882 | case 2:if( reply_format == 0 ){ |
||
883 | reply_format = 19; /* "onclick */ |
||
13970 | obado | 884 | 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.which == 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 | 885 | } |
886 | else |
||
887 | { |
||
888 | if( reply_format != 19){ |
||
889 | canvas_error("clickable clock(s) may not be used together with other reply_types..."); |
||
890 | } |
||
891 | } |
||
892 | break; |
||
893 | default: canvas_error("interactive must be set 0,1 or 2");break; |
||
894 | } |
||
895 | break; |
||
896 | case 8: |
||
14078 | bpr | 897 | if(clock_cnt == 0 ){ /* set opacity's just once .... it should be a argument to clock(), for now it's OK */ |
11806 | schaersvoo | 898 | fprintf(js_include_file,"var clock_bg_opacity = %.2f;var clock_fg_opacity = %.2f;",fill_opacity,stroke_opacity); |
899 | } |
||
900 | temp = get_string(infile,3);/* optional colors, like: ,,red,,blue*/ |
||
901 | if( strstr( temp,",") != 0 ){ temp = str_replace(temp,",","\",\""); } |
||
902 | else{ |
||
903 | /* h_color,m_color,s_color,bg_color,fg_color */ |
||
11991 | schaersvoo | 904 | temp = ",black\",\"black\",\"black\",\"white\",\"black";} |
11806 | schaersvoo | 905 | string_length = 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); |
906 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
907 | 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); |
||
908 | add_to_buffer(tmp_buffer); |
||
909 | fprintf(js_include_file,"var clocks%d;",clock_cnt); |
||
910 | clock_cnt++; |
||
911 | break; |
||
912 | default:break; |
||
913 | } |
||
914 | } |
||
915 | break; |
||
916 | |||
917 | |||
918 | case COLORPALETTE: |
||
919 | /* |
||
920 | @ colorpalette color_name_1,color_name_2,...,color_name_8 |
||
921 | @ opacity will be the same for all colors and is set by command <a href="#opacity">opacity [0-255],[0-255]</a> |
||
14066 | bpr | 922 | @ 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 | 923 | @ make sure to include the ''remove button`` by using command <a href='#clearbutton'>clearbutton some_text</a> |
11806 | schaersvoo | 924 | */ |
925 | if( use_tooltip == 1 ){canvas_error("command 'colorpalette' is incompatible with command 'intooltip tip_text'");} |
||
926 | fprintf(js_include_file,"var multifillcolors = [];var palettecolors = ["); |
||
927 | while( ! done ){ |
||
928 | temp = get_color(infile,1); |
||
929 | fprintf(js_include_file,"\"%s\",",temp); |
||
930 | } |
||
931 | fprintf(js_include_file,"];");/* add black to avoid trouble with dangling comma... */ |
||
932 | add_color_palette(js_include_file,canvas_root_id,input_style); |
||
933 | break; |
||
13829 | bpr | 934 | |
11806 | schaersvoo | 935 | case COPY: |
936 | /* |
||
937 | @ copy x,y,x1,y1,x2,y2,[filename URL] |
||
938 | @ The image may be "bitmap" or "SVG" |
||
939 | @ Insert the region from (x1,y1) to (x2,y2) (in pixels) of [filename] to (x,y) in x/y-range |
||
940 | @ If x1=y1=x2=y2=-1, the whole [filename URL] is copied. |
||
941 | @ [filename] is the URL of the image |
||
14077 | bpr | 942 | @ URL is normal URL of network reachable image file location<br />(eg special url for ''classexo`` not -yet- implemented) |
943 | @ 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>. |
||
944 | @ 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 |
||
945 | @ ''onclick`` for external images may be mixed with canvas generated stuff (like lines,curves etc) |
||
11806 | schaersvoo | 946 | @ you may draw / userdraw / drag other stuff on top of an "imported" image |
14077 | bpr | 947 | @ 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``<br />note: when dragging the image anchor is the center of the picture, this can not be changed (it's a feature and not a flaw!) |
948 | @ use keyword <a href='#centered'>centered</a> before command ''copy`` to place image center at given coordinates. |
||
13967 | schaersvoo | 949 | @%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 | 950 | @%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 |
951 | @%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 | 952 | */ |
953 | for(i = 0 ; i<7;i++){ |
||
7614 | schaersvoo | 954 | switch(i){ |
11806 | schaersvoo | 955 | case 0: int_data[0]=x2px(get_real(infile,0));break; /* x left top corner in x/y range */ |
956 | case 1: int_data[1]=y2px(get_real(infile,0));break; /* y left top corner in x/y range */ |
||
957 | case 2: int_data[2]=(int)(get_real(infile,0));break;/* x1 in px of external image */ |
||
958 | case 3: int_data[3]=(int)(get_real(infile,0));break;/* y1 in px of external image */ |
||
959 | case 4: int_data[4]=(int)(get_real(infile,0));break;/* x2 --> width */ |
||
960 | case 5: int_data[5]=(int)(get_real(infile,0)) ;break;/* y2 --> height */ |
||
961 | case 6: URL = get_string(infile,1); |
||
962 | int_data[6] = int_data[4] - int_data[2];/* swidth & width (if not scaling )*/ |
||
963 | int_data[7] = int_data[5] - int_data[3];/* sheight & height (if not scaling )*/ |
||
964 | if( js_function[DRAW_EXTERNAL_IMAGE] != 1 ){ js_function[DRAW_EXTERNAL_IMAGE] = 1;} |
||
965 | int_data[9] = click_cnt; |
||
966 | if( drag_type > -1 ){/* e.g. we are dragging images x/y/xy */ |
||
14038 | schaersvoo | 967 | //if( reply_format == 0 ){ reply_format = 20; } |
11806 | schaersvoo | 968 | int_data[8] = 2;/* drag & drop */ |
14044 | schaersvoo | 969 | if(use_offset == 0 ){use_offset = 4;} /* mouse is attached to the center of the image !! */ |
11806 | schaersvoo | 970 | } |
971 | else |
||
972 | { |
||
973 | if( onclick == 1 ){ |
||
14038 | schaersvoo | 974 | // reply_format = 20; |
11806 | schaersvoo | 975 | int_data[8] = 1; /* onclick will be reset using 'void reset()'*/ |
976 | click_cnt++; /* will also be used in dragstuff ! */ |
||
977 | } |
||
978 | else |
||
979 | { |
||
980 | int_data[8] = 0; /* just static image */ |
||
981 | } |
||
982 | } |
||
14038 | schaersvoo | 983 | if( include_special_OEF_reply == FALSE){ |
984 | if( int_data[8] == 1 || int_data[8] == 2 ){ |
||
985 | include_special_OEF_reply = TRUE; |
||
986 | fprintf(js_include_file,"\ |
||
987 | \n/* begin special OEF function (replyformat 34) read_canvas_images() \\n note: only suitable for reading a single canvas in exercise page */\n\ |
||
988 | read_canvas_images = function(){\ |
||
989 | var prec = %d;\ |
||
990 | var len = ext_drag_images.length;\ |
||
991 | var reply = new Array(len);\ |
||
992 | for(var p = 0 ; p < len ; p++){\ |
||
993 | var img = ext_drag_images[p];\ |
||
994 | reply[p] = p+\":\"+(Math.round(prec*(px2x(img[6]))))/prec+\":\"+(Math.round(prec*(px2y(img[7]))))/prec;\ |
||
995 | };\ |
||
996 | return reply;\ |
||
997 | };\n\ |
||
14062 | schaersvoo | 998 | /* end function 34 read_canvas_images() */",reply_precision); |
14038 | schaersvoo | 999 | } |
1000 | } |
||
11806 | schaersvoo | 1001 | /* |
14062 | schaersvoo | 1002 | function draw_external_image(URL,sx,sy,swidth,sheight,x0,y0,width,height,idx,resizable,draggable,click_cnt,centered,use_snap){\ |
11806 | schaersvoo | 1003 | */ |
14044 | schaersvoo | 1004 | string_length = snprintf(NULL,0, "draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,0,%d,%d,%d,%d);\n",URL,int_data[2],int_data[3],int_data[6],int_data[7],int_data[0],int_data[1],int_data[6],int_data[7],ext_img_cnt,int_data[8],int_data[9],use_offset,use_snap); |
11806 | schaersvoo | 1005 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
14044 | schaersvoo | 1006 | snprintf(tmp_buffer,string_length,"draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,0,%d,%d,%d,%d);\n",URL,int_data[2],int_data[3],int_data[6],int_data[7],int_data[0],int_data[1],int_data[6],int_data[7],ext_img_cnt,int_data[8],int_data[9],use_offset,use_snap); |
14038 | schaersvoo | 1007 | add_to_buffer(tmp_buffer); |
11806 | schaersvoo | 1008 | drag_type = -1; /* reset the drag_type indicator */ |
1009 | ext_img_cnt++; |
||
1010 | onclick=0; |
||
14038 | schaersvoo | 1011 | use_offset=0; |
1012 | reset(); |
||
11806 | schaersvoo | 1013 | break; |
7614 | schaersvoo | 1014 | default: break; |
1015 | } |
||
1016 | } |
||
1017 | break; |
||
11806 | schaersvoo | 1018 | /* |
1019 | HTML5 specs: |
||
1020 | context.drawImage(img,sx,sy,swidth,sheight,x,y,width,height); |
||
1021 | img Specifies the image, canvas, or video element to use |
||
14066 | bpr | 1022 | sx The x coordinate where to start clipping: x1 = int_data[0] |
1023 | sy The y coordinate where to start clipping: x2 = int_data[1] |
||
1024 | swidth The width of the clipped image: int_data[2] - int_data[0] |
||
1025 | sheight The height of the clipped image: int_data[3] - int_data[1] |
||
1026 | x The x coordinate where to place the image on the canvas: dx1 = int_data[4] |
||
1027 | y The y coordinate where to place the image on the canvas: dy1 = int_data[5] |
||
1028 | width The width of the image to use (stretch or reduce the image): dx2 - dx1 = int_data[6] |
||
1029 | height The height of the image to use (stretch or reduce the image): dy2 - dy1 = int_data[7] |
||
11806 | schaersvoo | 1030 | */ |
1031 | case COPYRESIZED: |
||
1032 | /* |
||
1033 | @ copyresized x1,y2,x2,y2,dx1,dy1,dx2,dy2,image_file_url |
||
1034 | @ The image may be any "bitmap" or "SVG" |
||
1035 | @ 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 | 1036 | @ (dx1:dy1) must be left top corner; (dx2:dy2) must be right bottom corner of inserted image |
11806 | schaersvoo | 1037 | @ If x1=y1=x2=y2=-1, the whole [filename / URL ] is copied and resized. |
1038 | @ 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 !!) |
||
14077 | bpr | 1039 | @ 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> |
1040 | @ 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 |
||
1041 | @ ''onclick`` for external images may be mixed with canvas generated stuff (like lines,curves etc) |
||
11806 | schaersvoo | 1042 | @ you may draw / userdraw / drag stuff on top of an "imported" image |
14077 | bpr | 1043 | @ 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`` |
14038 | schaersvoo | 1044 | @ use keyword <a href='#centered'>centered</a> before command 'copyresized' to place image center at given coordinates. |
11806 | schaersvoo | 1045 | */ |
1046 | for(i = 0 ; i<9;i++){ |
||
1047 | switch(i){ |
||
1048 | case 0: int_data[0] = (int)(get_real(infile,0));break; /* x1 */ |
||
1049 | case 1: int_data[1] = (int)(get_real(infile,0));break; /* y1 */ |
||
1050 | case 2: int_data[2] = (int)(get_real(infile,0));break;/* x2 */ |
||
1051 | case 3: int_data[3] = (int)(get_real(infile,0));break;/* y2 */ |
||
1052 | case 4: int_data[4] = x2px(get_real(infile,0));break;/* dx1 */ |
||
1053 | case 5: int_data[5] = y2px(get_real(infile,0));break;/* dy1 */ |
||
1054 | case 6: int_data[6] = x2px(get_real(infile,0));break;/* dx2 */ |
||
1055 | case 7: int_data[7] = y2px(get_real(infile,0));break;/* dy2 */ |
||
1056 | case 8: URL = get_string(infile,1); |
||
1057 | /* flag error when wrong diagonal: copyresized -1,-1,-1,-1,0,0,7,7,testfig.gif */ |
||
1058 | if( int_data[7] < int_data[5] || int_data[6] < int_data[4]){ |
||
1059 | canvas_error("in copyresized , use:<br />left top corner (dx1:dy1) and right bottom corner (dx2:dy2) ! "); |
||
1060 | } |
||
1061 | int_data[2] = abs(int_data[2] - int_data[0]);/* swidth */ |
||
1062 | int_data[3] = abs(int_data[3] - int_data[1]);/* sheight */ |
||
1063 | int_data[6] = abs(int_data[6] - int_data[4]);/* width */ |
||
1064 | int_data[7] = abs(int_data[7] - int_data[5]);/* height */ |
||
1065 | if( js_function[DRAW_EXTERNAL_IMAGE] != 1 ){ js_function[DRAW_EXTERNAL_IMAGE] = 1;} |
||
1066 | int_data[9] = click_cnt; |
||
1067 | if( drag_type > -1 ){/* e.g. we are dragging images x/y/xy */ |
||
14038 | schaersvoo | 1068 | // if( reply_format == 0 ){ reply_format = 20; } |
11806 | schaersvoo | 1069 | int_data[8] = 2;/* drag & drop */ |
1070 | } |
||
1071 | else |
||
1072 | { |
||
1073 | if( onclick == 1 ){ |
||
14038 | schaersvoo | 1074 | // reply_format = 20; |
11806 | schaersvoo | 1075 | int_data[8] = 1; /* onclick will be reset using 'void reset()'*/ |
1076 | click_cnt++; /* will also be used in dragstuff ! */ |
||
1077 | } |
||
1078 | else |
||
1079 | { |
||
1080 | int_data[8] = 0; /* just static image */ |
||
1081 | } |
||
1082 | } |
||
14038 | schaersvoo | 1083 | if( include_special_OEF_reply == FALSE){ |
1084 | if( int_data[8] == 1 || int_data[8] == 2 ){ |
||
1085 | include_special_OEF_reply = TRUE; |
||
1086 | fprintf(js_include_file,"\ |
||
1087 | \n/* begin special OEF function (replyformat 34) read_canvas_images() \\n note: only suitable for reading a single canvas in exercise page */\n\ |
||
1088 | read_canvas_images = function(){\ |
||
1089 | var prec = %d;\ |
||
1090 | var len = ext_drag_images.length;\ |
||
1091 | var reply = new Array(len);\ |
||
1092 | for(var p = 0 ; p < len ; p++){\ |
||
1093 | var img = ext_drag_images[p];\ |
||
1094 | reply[p] = p+\":\"+(Math.round(prec*(px2x(img[6]))))/prec+\":\"+(Math.round(prec*(px2y(img[7]))))/prec;\ |
||
1095 | };\ |
||
1096 | return reply;\ |
||
1097 | };\n\ |
||
14062 | schaersvoo | 1098 | /* end function 34 read_canvas_images() */",reply_precision); |
14038 | schaersvoo | 1099 | } |
1100 | } |
||
1101 | |||
11806 | schaersvoo | 1102 | /* |
1103 | (URL,sx,sy,swidth,sheight,x0,y0,width,height,idx,resizable,draggable,click_cnt) |
||
1104 | URL,[2],[3],[6], [7], [4],[5],[6],[7],ext_img_cnt,1, [8], [9] |
||
1105 | */ |
||
14044 | schaersvoo | 1106 | string_length = snprintf(NULL,0, "draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,1,%d,%d,%d,%d);\n",URL,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],ext_img_cnt,int_data[8],int_data[9],use_offset,use_snap); |
11806 | schaersvoo | 1107 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
14044 | schaersvoo | 1108 | snprintf(tmp_buffer,string_length,"draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,1,%d,%d,%d,%d);\n",URL,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],ext_img_cnt,int_data[8],int_data[9],use_offset,use_snap); |
14038 | schaersvoo | 1109 | add_to_buffer(tmp_buffer); |
11806 | schaersvoo | 1110 | drag_type = -1; /* reset the drag_type indicator */ |
1111 | ext_img_cnt++; |
||
1112 | onclick=0; |
||
14038 | schaersvoo | 1113 | use_offset=0; |
1114 | reset(); |
||
11806 | schaersvoo | 1115 | break; |
1116 | default: break; |
||
1117 | } |
||
1118 | } |
||
14038 | schaersvoo | 1119 | reset(); |
11806 | schaersvoo | 1120 | break; |
8386 | schaersvoo | 1121 | |
11806 | schaersvoo | 1122 | case CROSSHAIR: |
8386 | schaersvoo | 1123 | /* |
11806 | schaersvoo | 1124 | @ crosshair x,y,color |
1125 | @ draw a single crosshair point at (x;y) in color 'color' |
||
1126 | @ use command 'crosshairsize int' and / or 'linewidth int' to adust |
||
1127 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
||
12107 | schaersvoo | 1128 | @%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 | 1129 | */ |
1130 | for(i=0;i<3;i++){ |
||
1131 | switch(i){ |
||
1132 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
1133 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
1134 | case 2: stroke_color = get_color(infile,1);/* name or hex color */ |
||
1135 | decimals = find_number_of_digits(precision); |
||
14045 | schaersvoo | 1136 | fprintf(js_include_file,"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\",%d,%s,%d,%d,%s,%d,%d));\n",drag_type,click_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,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern); |
11806 | schaersvoo | 1137 | if(onclick > 0){click_cnt++;} |
1138 | /* click_cnt++ */ |
||
1139 | reset(); |
||
1140 | break; |
||
1141 | default:break; |
||
1142 | } |
||
1143 | } |
||
1144 | break; |
||
1145 | |||
1146 | case CROSSHAIRS: |
||
1147 | /* |
||
1148 | @ crosshairs color,x1,y1,x2,y2,...,x_n,y_n |
||
14077 | bpr | 1149 | @ draw multiple crosshair points at given coordinates in color ''color`` |
1150 | @ use command <code>crosshairsize int</code> and / or <code>linewidth int</code> to adust |
||
9406 | schaersvoo | 1151 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!) |
12107 | schaersvoo | 1152 | @%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 |
1153 | @%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 |
||
1154 | */ |
||
8386 | schaersvoo | 1155 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
1156 | fill_color = stroke_color; |
||
1157 | i=0; |
||
1158 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 1159 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
8386 | schaersvoo | 1160 | if(i%2 == 0 ){ |
1161 | double_data[i] = get_real(infile,0); /* x */ |
||
1162 | } |
||
1163 | else |
||
1164 | { |
||
1165 | double_data[i] = get_real(infile,1); /* y */ |
||
1166 | } |
||
1167 | i++; |
||
1168 | } |
||
1169 | decimals = find_number_of_digits(precision); |
||
11806 | schaersvoo | 1170 | for(c=0 ; c < i-1 ; c = c+2){ |
14045 | schaersvoo | 1171 | fprintf(js_include_file,"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\",%d,%s,%d,%d,%s,%d,%d));\n",drag_type,click_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,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern); |
8386 | schaersvoo | 1172 | if(onclick > 0){click_cnt++;} |
11806 | schaersvoo | 1173 | /* click_cnt++; */ |
8386 | schaersvoo | 1174 | } |
1175 | reset(); |
||
1176 | break; |
||
1177 | |||
11806 | schaersvoo | 1178 | case CROSSHAIRSIZE: |
7614 | schaersvoo | 1179 | /* |
11806 | schaersvoo | 1180 | @ crosshairsize int |
1181 | @ default 8 (px) |
||
7614 | schaersvoo | 1182 | */ |
11806 | schaersvoo | 1183 | crosshair_size = (int) (get_real(infile,1)); |
1184 | break; |
||
1185 | |||
1186 | case CURSOR: |
||
1187 | /* |
||
14086 | bpr | 1188 | @ cursor some CSS cursor_style |
14071 | bpr | 1189 | @ alternative: <code>pointer</code> |
13956 | schaersvoo | 1190 | @ style can be any valid CSS property value |
1191 | @ 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 |
||
1192 | @ note: wims will not check the validity of your cursor declaration |
||
1193 | @%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 | 1194 | */ |
1195 | fprintf(js_include_file,"canvas_div%d.style.cursor = \"%s\";",canvas_root_id,get_string(infile,1)); |
||
1196 | break; |
||
1197 | |||
1198 | case CURVE: |
||
1199 | /* |
||
1200 | @ curve color,formula(x) |
||
14066 | bpr | 1201 | @ alernative: plot color,formula(x) |
14071 | bpr | 1202 | @ use command <a href="#trange">trange</a> in parametric functions before command curve / plot <code>trange -pi,pi<br />curve color,formula1(t),formula2(t)</code> |
14086 | bpr | 1203 | @ use command <a href="#precision">precision</a> to increase the number of digits of the plotted points |
14066 | bpr | 1204 | @ use command <a href="#plotsteps">plotsteps</a> to increase / decrease the amount of plotted points (default 150) |
11806 | schaersvoo | 1205 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
14071 | bpr | 1206 | @ if you need a plot beyond xrange / yrange, use <a href="#jsplot">jsplot</a><br />(command ''curve`` will only calculate points within the xrange) |
12107 | schaersvoo | 1207 | @%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 | 1208 | */ |
1209 | if( use_parametric == TRUE ){ /* parametric color,fun1(t),fun2(t)*/ |
||
1210 | use_parametric = FALSE; |
||
1211 | stroke_color = get_color(infile,0); |
||
1212 | char *fun1 = get_string_argument(infile,0); |
||
1213 | char *fun2 = get_string_argument(infile,1); |
||
1214 | if( strlen(fun1) == 0 || strlen(fun2) == 0 ){canvas_error("parametric functions are NOT OK !");} |
||
14045 | schaersvoo | 1215 | fprintf(js_include_file,"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\",%d,%s,%d,%d,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,eval_parametric(xsize,ysize,fun1,fun2,xmin,xmax,ymin,ymax,tmin,tmax,plot_steps,precision),2*line_width,2*line_width,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern); |
11806 | schaersvoo | 1216 | } |
1217 | else |
||
1218 | { |
||
1219 | stroke_color = get_color(infile,0); |
||
1220 | char *fun1 = get_string_argument(infile,1); |
||
1221 | if( strlen(fun1) == 0 ){canvas_error("function is NOT OK !");} |
||
14045 | schaersvoo | 1222 | fprintf(js_include_file,"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\",%d,%s,%d,%d,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,eval(xsize,ysize,fun1,xmin,xmax,ymin,ymax,plot_steps,precision),line_width,line_width,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern); |
11806 | schaersvoo | 1223 | } |
1224 | if(onclick > 0){click_cnt++;} |
||
1225 | /* click_cnt++; */ |
||
1226 | reset(); |
||
1227 | break; |
||
14038 | schaersvoo | 1228 | case CURVEDARROW: |
1229 | /* |
||
1230 | @ curvedarrow x1,y1,xc,yc,x2,y2,color |
||
14066 | bpr | 1231 | @ draw a single headed curved arrow from (x1:y1) in direction of (xc:yc) to point (x3:y3)<br /> note: the curve will <b>not go through</b> point (xc:yc) |
14038 | schaersvoo | 1232 | @ use command <a href='#arrowhead'>arrowhead</a> to set the size of the arrow head. |
14077 | bpr | 1233 | @ use command <code>linewidth int</code> to adjust thickness of the arrow |
14038 | schaersvoo | 1234 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
1235 | @%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 |
||
1236 | @%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 | 1237 | |
14029 | schaersvoo | 1238 | h[0] = arrowhead |
14066 | bpr | 1239 | h[1] = type: 1 = single 2=double arrow |
14029 | schaersvoo | 1240 | function Shape(click_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_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern) |
14038 | schaersvoo | 1241 | */ |
1242 | for(i=0;i<7;i++){ |
||
1243 | switch(i){ |
||
1244 | case 0: double_data[0] = get_real(infile,0);break; /* x1 */ |
||
1245 | case 1: double_data[1] = get_real(infile,0);break; /* y1 */ |
||
1246 | case 2: double_data[2] = get_real(infile,0);break; /* xc */ |
||
1247 | case 3: double_data[3] = get_real(infile,0);break; /* yc */ |
||
1248 | case 4: double_data[4] = get_real(infile,0);break; /* y3 */ |
||
1249 | case 5: double_data[5] = get_real(infile,0);break; /* y3 */ |
||
1250 | case 6: stroke_color = get_color(infile,1);/* name or hex color */ |
||
1251 | decimals = find_number_of_digits(precision); |
||
14045 | schaersvoo | 1252 | fprintf(js_include_file,"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\",%d,%s,%d,%d,%s,%d,%d));\n",drag_type,click_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,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern); |
14038 | schaersvoo | 1253 | if(onclick > 0){click_cnt++;} |
1254 | /* click_cnt++;*/ |
||
1255 | reset(); |
||
1256 | break; |
||
1257 | } |
||
1258 | } |
||
1259 | break; |
||
14029 | schaersvoo | 1260 | |
14038 | schaersvoo | 1261 | case CURVEDARROW2: |
1262 | /* |
||
1263 | @ curvedarrow2 x1,y1,xc,yc,x2,y2,color |
||
14066 | bpr | 1264 | @ draw a double headed curved arrow from (x1:y1) in direction of (xc:yc) to point (x3:y3)<br /> note: the curve will <b>not go through</b> point (xc:yc) |
14038 | schaersvoo | 1265 | @ use command <a href='#arrowhead'>arrowhead</a> to set the size of the arrow head. |
14077 | bpr | 1266 | @ use command <code>linewidth int</code> to adjust thickness of the arrow |
14038 | schaersvoo | 1267 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
1268 | @%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 |
||
1269 | @%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 | 1270 | |
1271 | h[0] = arrowhead |
||
14066 | bpr | 1272 | h[1] = type: 1 = single 2=double arrow |
14029 | schaersvoo | 1273 | function Shape(click_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_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern) |
14038 | schaersvoo | 1274 | */ |
1275 | for(i=0;i<7;i++){ |
||
1276 | switch(i){ |
||
1277 | case 0: double_data[0] = get_real(infile,0);break; /* x1 */ |
||
1278 | case 1: double_data[1] = get_real(infile,0);break; /* y1 */ |
||
1279 | case 2: double_data[2] = get_real(infile,0);break; /* xc */ |
||
1280 | case 3: double_data[3] = get_real(infile,0);break; /* yc */ |
||
1281 | case 4: double_data[4] = get_real(infile,0);break; /* y3 */ |
||
1282 | case 5: double_data[5] = get_real(infile,0);break; /* y3 */ |
||
1283 | case 6: stroke_color = get_color(infile,1);/* name or hex color */ |
||
1284 | decimals = find_number_of_digits(precision); |
||
14045 | schaersvoo | 1285 | fprintf(js_include_file,"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\",%d,%s,%d,%d,%s,%d,%d));\n",drag_type,click_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,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern); |
14038 | schaersvoo | 1286 | if(onclick > 0){click_cnt++;} |
1287 | /* click_cnt++;*/ |
||
1288 | reset(); |
||
1289 | break; |
||
1290 | } |
||
1291 | } |
||
1292 | break; |
||
1293 | case CURVEDARROWS: |
||
1294 | /* |
||
1295 | @ curvedarrow color,x1,y1,xc,yc,x2,y2,...x_(n-1),y_(n-1),xc,yc,x_n,y_n |
||
14066 | bpr | 1296 | @ draw a single headed curved arrows from (x1:y1) in direction of (xc:yc) to point (x3:y3)<br /> note: the curve will <b>not go through</b> point (xc:yc) |
14038 | schaersvoo | 1297 | @ use command <a href='#arrowhead'>arrowhead</a> to set the size of the arrow head. |
14077 | bpr | 1298 | @ use command <code>linewidth int</code> to adjust thickness of the arrow |
14038 | schaersvoo | 1299 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
1300 | @%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 |
||
1301 | @%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 | 1302 | |
14030 | schaersvoo | 1303 | h[0] = arrowhead |
14066 | bpr | 1304 | h[1] = type: 1 = single 2=double arrow |
14030 | schaersvoo | 1305 | function Shape(click_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_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern) |
14038 | schaersvoo | 1306 | */ |
1307 | stroke_color = get_color(infile,0);/* name or hex color */ |
||
1308 | i = 0; |
||
1309 | decimals = find_number_of_digits(precision); |
||
1310 | while( ! done ){ |
||
1311 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
||
1312 | double_data[0] = get_real(infile,0); /* x1 */ |
||
1313 | double_data[1] = get_real(infile,0); /* y1 */ |
||
1314 | double_data[2] = get_real(infile,0); /* xc */ |
||
1315 | double_data[3] = get_real(infile,0); /* yc */ |
||
1316 | double_data[4] = get_real(infile,0); /* x3 */ |
||
1317 | double_data[5] = get_real(infile,1); /* y3 */ |
||
14045 | schaersvoo | 1318 | fprintf(js_include_file,"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\",%d,%s,%d,%d,%s,%d,%d));\n",drag_type,click_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,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern); |
14038 | schaersvoo | 1319 | if(onclick > 0){click_cnt++;} |
1320 | i = i + 6; |
||
1321 | } |
||
1322 | reset(); |
||
1323 | break; |
||
14030 | schaersvoo | 1324 | |
14038 | schaersvoo | 1325 | case CURVEDARROWS2: |
1326 | /* |
||
1327 | @ curvedarrows2 color,x1,y1,xc,yc,x2,y2,...x_(n-1),y_(n-1),xc,yc,x_n,y_n |
||
14066 | bpr | 1328 | @ draw a double headed curved arrows from (x1:y1) in direction of (xc:yc) to point (x3:y3)<br /> note: the curve will <b>not go through</b> point (xc:yc) |
14038 | schaersvoo | 1329 | @ use command <a href='#arrowhead'>arrowhead</a> to set the size of the arrow head. |
14077 | bpr | 1330 | @ use command <code>linewidth int</code> to adjust thickness of the arrow |
14038 | schaersvoo | 1331 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
1332 | @%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 |
||
1333 | @%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 | 1334 | |
1335 | h[0] = arrowhead |
||
14066 | bpr | 1336 | h[1] = type: 1 = single 2=double arrow |
14030 | schaersvoo | 1337 | function Shape(click_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_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern) |
14038 | schaersvoo | 1338 | */ |
1339 | stroke_color = get_color(infile,0);/* name or hex color */ |
||
1340 | i = 0; |
||
1341 | decimals = find_number_of_digits(precision); |
||
1342 | while( ! done ){ |
||
1343 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
||
1344 | double_data[0] = get_real(infile,0); /* x1 */ |
||
1345 | double_data[1] = get_real(infile,0); /* y1 */ |
||
1346 | double_data[2] = get_real(infile,0); /* xc */ |
||
1347 | double_data[3] = get_real(infile,0); /* yc */ |
||
1348 | double_data[4] = get_real(infile,0); /* x3 */ |
||
1349 | double_data[5] = get_real(infile,1); /* y3 */ |
||
14045 | schaersvoo | 1350 | fprintf(js_include_file,"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\",%d,%s,%d,%d,%s,%d,%d));\n",drag_type,click_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,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern); |
14038 | schaersvoo | 1351 | if(onclick > 0){click_cnt++;} |
1352 | i = i + 6; |
||
1353 | } |
||
1354 | reset(); |
||
1355 | break; |
||
11806 | schaersvoo | 1356 | case DASHED: |
1357 | /* |
||
1358 | @ dashed |
||
1359 | @ keyword (no arguments required) |
||
1360 | @ next object will be drawn with a dashed line |
||
1361 | @ change dashing scheme by using command <a href="#dashtype">dashtype</a> |
||
12107 | schaersvoo | 1362 | @%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 | 1363 | */ |
1364 | use_dashed = TRUE; |
||
1365 | break; |
||
1366 | |||
1367 | case DASHTYPE: |
||
1368 | /* |
||
1369 | @ dashtype line_width_px,space_width_px |
||
1370 | @ every indiviual object may have its own dashtype, if needed... |
||
1371 | @ When keyword <a href='#dashed'>dashed</a> is set, the objects will be drawn with this dashtype |
||
14086 | bpr | 1372 | @ default value <code>dashtype 2,2</code> e.g. 2px line and 2px space |
13957 | schaersvoo | 1373 | @ HTML5 canvas specification supports more arguments (dashing schemes) ... but not all modern browsers are yet capable |
13949 | schaersvoo | 1374 | @%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 | 1375 | */ |
1376 | for(i=0;i<2;i++){ |
||
1377 | switch(i){ |
||
1378 | case 0 : dashtype[0] = (int) line_width*( get_real(infile,0)) ; break; |
||
1379 | case 1 : dashtype[1] = (int) line_width*( get_real(infile,1)) ; break; |
||
1380 | } |
||
1381 | } |
||
1382 | break; |
||
1383 | |||
1384 | case DIAMONDFILL: |
||
1385 | /* |
||
1386 | @ diamondfill x0,y0,dx,dy,color |
||
1387 | @ x0,y0 in xrange / yrange |
||
1388 | @ distances dx,dy in pixels |
||
13936 | bpr | 1389 | @ there is also a command <a href="#userdraw">userdraw diamondfill,color</a> |
12110 | schaersvoo | 1390 | @%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 | 1391 | */ |
1392 | if( js_function[DRAW_DIAMONDFILL] != 1 ){ js_function[DRAW_DIAMONDFILL] = 1;} |
||
11820 | schaersvoo | 1393 | if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */ |
1394 | js_function[DRAW_FILLTOBORDER] = 1; |
||
1395 | add_js_filltoborder(js_include_file,canvas_root_id,canvas_type); |
||
1396 | } |
||
1397 | decimals = find_number_of_digits(precision); |
||
7614 | schaersvoo | 1398 | for(i=0;i<5;i++){ |
1399 | switch(i){ |
||
11820 | schaersvoo | 1400 | case 0: double_data[0] = get_real(infile,0); break; /* x */ |
14032 | schaersvoo | 1401 | case 1: double_data[1] = get_real(infile,0); break; /* y */ |
11820 | schaersvoo | 1402 | case 2: int_data[0] = (int) (get_real(infile,0)); break; /* dx pixel */ |
1403 | case 3: int_data[1] = (int) (get_real(infile,0)); break; /* dy pixel*/ |
||
11806 | schaersvoo | 1404 | case 4: stroke_color = get_color(infile,1); |
1405 | /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */ |
||
14032 | schaersvoo | 1406 | string_length = 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); |
11806 | schaersvoo | 1407 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
11820 | schaersvoo | 1408 | 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 | 1409 | add_to_buffer(tmp_buffer); |
11820 | schaersvoo | 1410 | fill_cnt++; |
11806 | schaersvoo | 1411 | break; |
1412 | default:break; |
||
1413 | } |
||
1414 | } |
||
1415 | reset(); |
||
1416 | break; |
||
8224 | bpr | 1417 | |
11806 | schaersvoo | 1418 | case DOTFILL: |
1419 | /* |
||
1420 | @ dotfill x0,y0,dx,dy,color |
||
1421 | @ x0,y0 in xrange / yrange |
||
1422 | @ distances dx,dy in pixels |
||
1423 | @ radius of dots is linewidth |
||
13936 | bpr | 1424 | @ there is also a command <a href="#userdraw">userdraw dotfill,color</a> |
12110 | schaersvoo | 1425 | @%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 | 1426 | */ |
1427 | if( js_function[DRAW_DOTFILL] != 1 ){ js_function[DRAW_DOTFILL] = 1;} |
||
11817 | schaersvoo | 1428 | if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */ |
1429 | js_function[DRAW_FILLTOBORDER] = 1; |
||
1430 | add_js_filltoborder(js_include_file,canvas_root_id,canvas_type); |
||
1431 | } |
||
1432 | decimals = find_number_of_digits(precision); |
||
11806 | schaersvoo | 1433 | for(i=0;i<5;i++){ |
1434 | switch(i){ |
||
11817 | schaersvoo | 1435 | case 0: double_data[0] = get_real(infile,0); break; /* x in px */ |
1436 | case 1: double_data[1] = get_real(infile,0); break; /* y in py */ |
||
1437 | case 2: int_data[0] = (int) (get_real(infile,0)); break; /* dx pixel */ |
||
1438 | case 3: int_data[1] = (int) (get_real(infile,0)); break; /* dy pixel*/ |
||
11806 | schaersvoo | 1439 | case 4: stroke_color = get_color(infile,1); |
1440 | /* draw_dotfill(ctx,x0,y0,dx,dy,radius,color,opacity,xsize,ysize) */ |
||
14032 | schaersvoo | 1441 | string_length = 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); |
11806 | schaersvoo | 1442 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
11817 | schaersvoo | 1443 | 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 | 1444 | add_to_buffer(tmp_buffer); |
11817 | schaersvoo | 1445 | fill_cnt++; |
7614 | schaersvoo | 1446 | break; |
11806 | schaersvoo | 1447 | default:break; |
7614 | schaersvoo | 1448 | } |
1449 | } |
||
11806 | schaersvoo | 1450 | reset(); |
1451 | break; |
||
1452 | |||
1453 | case DRAG: |
||
1454 | /* |
||
1455 | @ drag [x][y][xy] |
||
1456 | @ the next object will be draggable in x / y / xy direction |
||
14077 | bpr | 1457 | @ the displacement can be read by <code>javascript:read_dragdrop();</code> |
14066 | bpr | 1458 | @ 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 | 1459 | @ <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 | 1460 | @ ''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) |
1461 | @ <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``)<br />in this example<br /><code>linewidth 4<br />point 0,0,red<br />drag xy<br />point 0,0,blue</code><br />the blue point will not be recognised as draggable !<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 | 1462 | @ 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) |
14078 | bpr | 1463 | @ 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 | 1464 | @ 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. |
14078 | bpr | 1465 | @ note: in case an object is dragged, zooming or panning will cause the coordinates to be reset to the original position: <br />e.g. dragging / panning will get lost. (array with ''drag data`` is erased)<br />This is a design flaw and not a feature !! |
13829 | bpr | 1466 | @%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 |
1467 | @%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 |
||
1468 | @%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 | 1469 | */ |
1470 | temp = get_string(infile,1); |
||
1471 | if(strstr(temp,"xy") != NULL ){ |
||
1472 | drag_type = 0; |
||
1473 | } |
||
1474 | else |
||
1475 | { |
||
1476 | if(strstr(temp,"x") != NULL ){ |
||
1477 | drag_type = 1; |
||
1478 | } |
||
1479 | else |
||
1480 | { |
||
1481 | drag_type = 2; |
||
1482 | } |
||
1483 | } |
||
1484 | /* assuming all drag&drop coordinates the same precision: so set only once */ |
||
1485 | if( print_drag_params_only_once == FALSE ){ |
||
1486 | fprintf(js_include_file,"dragdrop_precision = %d;use_dragdrop_reply = true;\n",precision); |
||
1487 | print_drag_params_only_once = TRUE; |
||
1488 | } |
||
1489 | onclick = 2; |
||
1490 | /* if(use_userdraw == TRUE ){canvas_error("\"drag & drop\" may not be combined with \"userdraw\" or \"pan and zoom\" \n");} */ |
||
7614 | schaersvoo | 1491 | break; |
8386 | schaersvoo | 1492 | |
11806 | schaersvoo | 1493 | case ELLIPSE: |
8351 | schaersvoo | 1494 | /* |
11806 | schaersvoo | 1495 | @ ellipse xc,yc,radius_x,radius_y,color |
1496 | @ a ellipse with center xc/yc in x/y-range |
||
1497 | @ radius_x and radius_y are in pixels |
||
9406 | schaersvoo | 1498 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
11806 | schaersvoo | 1499 | @ will shrink / expand on zoom out / zoom in |
13949 | schaersvoo | 1500 | @%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 | 1501 | */ |
11806 | schaersvoo | 1502 | for(i=0;i<5;i++){ |
1503 | switch(i){ |
||
1504 | case 0:double_data[0] = get_real(infile,0);break; /* x-values */ |
||
1505 | case 1:double_data[1] = get_real(infile,0);break; /* y-values */ |
||
14066 | bpr | 1506 | case 2:double_data[2] = get_real(infile,0);break; /* rx -> px */ |
1507 | case 3:double_data[3] = get_real(infile,0);break; /* ry -> px */ |
||
11806 | schaersvoo | 1508 | case 4:stroke_color = get_color(infile,1);/* name or hex color */ |
1509 | decimals = find_number_of_digits(precision); |
||
14045 | schaersvoo | 1510 | fprintf(js_include_file,"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\",%d,%s,%d,%d,%s,%d,%d));\n",drag_type,click_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,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern); |
11806 | schaersvoo | 1511 | if(onclick > 0){click_cnt++;} |
1512 | /* click_cnt++; */ |
||
1513 | reset(); |
||
1514 | break; |
||
1515 | } |
||
1516 | } |
||
1517 | break; |
||
13829 | bpr | 1518 | |
12110 | schaersvoo | 1519 | case ELLIPSES: |
1520 | /* |
||
1521 | @ ellipses color,xc1,yc1,radius_x1,radius_y1,xc2,yc2,radius_x2,radius_y2,xc3,yc3,radius_x3,radius_y3,... |
||
1522 | @ a ellipses with center xc/yc in x/y-range |
||
1523 | @ radius_x and radius_y are in pixels |
||
1524 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
||
1525 | @ will shrink / expand on zoom out / zoom in |
||
13949 | schaersvoo | 1526 | @%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 | 1527 | */ |
13829 | bpr | 1528 | |
12110 | schaersvoo | 1529 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
1530 | fill_color = stroke_color; |
||
1531 | i=1; |
||
1532 | while( ! done ){ /* get next item until EOL*/ |
||
1533 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
||
1534 | switch (i%4){ |
||
1535 | case 1:double_data[i-1] = get_real(infile,0);break; /* x */ |
||
1536 | case 2:double_data[i-1] = get_real(infile,0);break; /* y */ |
||
1537 | case 3:double_data[i-1] = get_real(infile,0);break; /* rx */ |
||
1538 | case 0:double_data[i-1] = get_real(infile,1);break; /* ry */ |
||
1539 | default: break; |
||
1540 | } |
||
1541 | i++; |
||
1542 | } |
||
1543 | decimals = find_number_of_digits(precision); |
||
1544 | for(c = 0 ; c < i-1 ; c = c+4){ |
||
14045 | schaersvoo | 1545 | fprintf(js_include_file,"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\",%d,%s,%d,%d,%s,%d,%d));\n", drag_type,click_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,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern); |
12110 | schaersvoo | 1546 | if(onclick > 0){click_cnt++;} /* click_cnt++; */ |
1547 | } |
||
1548 | reset(); |
||
1549 | break; |
||
1550 | |||
11806 | schaersvoo | 1551 | case FILLALL: |
1552 | /* |
||
1553 | @ fillall color,x1,y1,x2,y2...x_n,y_n |
||
1554 | @ fill all region containing points (x1:y1),(x2:y2)...(x_n:y_n) with color 'color' |
||
1555 | @ any other colors (objects) in the <a href="#canvastype>canvastype</a> will act as border to the bucket fill |
||
14032 | schaersvoo | 1556 | @ use this command after all boundary objects are declared. |
11806 | schaersvoo | 1557 | @ Use command 'userdraw clickfill,color' for user click driven flood fill. |
1558 | @ use command <a href="#canvastype">canvastype </a> to fill another canvas (default should be fine: DRAG_CANVAS = 5) |
||
14071 | bpr | 1559 | @ 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 | 1560 | @%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 | 1561 | */ |
1562 | decimals = find_number_of_digits(precision); |
||
1563 | fill_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
8351 | schaersvoo | 1564 | i=0; |
11806 | schaersvoo | 1565 | if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */ |
1566 | js_function[DRAW_FILLTOBORDER] = 1; |
||
1567 | add_js_filltoborder(js_include_file,canvas_root_id,canvas_type); |
||
1568 | } |
||
8351 | schaersvoo | 1569 | while( ! done ){ /* get next item until EOL*/ |
11997 | schaersvoo | 1570 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
8351 | schaersvoo | 1571 | if(i%2 == 0 ){ |
1572 | double_data[i] = get_real(infile,0); /* x */ |
||
1573 | } |
||
1574 | else |
||
1575 | { |
||
1576 | double_data[i] = get_real(infile,1); /* y */ |
||
14032 | schaersvoo | 1577 | string_length = 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); |
11806 | schaersvoo | 1578 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
11818 | schaersvoo | 1579 | 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 | 1580 | add_to_buffer(tmp_buffer); |
1581 | fill_cnt++; |
||
8351 | schaersvoo | 1582 | } |
1583 | i++; |
||
1584 | } |
||
11806 | schaersvoo | 1585 | break; |
1586 | |||
1587 | case FILLED: |
||
1588 | /* |
||
1589 | @ filled |
||
1590 | @ keyword (no arguments required) |
||
14077 | bpr | 1591 | @ the next ''fillable`` object (only the next !) will be filled |
14066 | bpr | 1592 | @ use command <a href="#fillcolor">fillcolor color</a> to set fillcolor |
11839 | schaersvoo | 1593 | @ use <a href="#fillpattern">fillpattern</a> for non-solid color filling. |
14086 | bpr | 1594 | @ use command <code>opacity 0-255,0-255</code> to set stroke and fill-opacity |
14066 | bpr | 1595 | @ 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 | 1596 | */ |
11839 | schaersvoo | 1597 | use_filled = 1; |
11859 | schaersvoo | 1598 | use_pattern = 0; |
11806 | schaersvoo | 1599 | break; |
1600 | |||
1601 | case FILLCOLOR: |
||
1602 | /* |
||
1603 | @ fillcolor colorname or #hex |
||
14066 | bpr | 1604 | @ set the color: mainly used for command 'userdraw obj,stroke_color' |
11806 | schaersvoo | 1605 | @ all fillable massive objects will have a fillcolor == strokecolor (just to be compatible with flydraw...) |
11839 | schaersvoo | 1606 | @ see <a href="#fillpattern">fillpattern</a> for non-solid color filling. |
11806 | schaersvoo | 1607 | */ |
1608 | fill_color = get_color(infile,1); |
||
11874 | schaersvoo | 1609 | use_pattern = 0; |
11806 | schaersvoo | 1610 | break; |
1611 | |||
11837 | schaersvoo | 1612 | case FILLPATTERN: |
1613 | /* |
||
11854 | schaersvoo | 1614 | @ fillpattern grid | hatch | diamond | dot | image-url |
11837 | schaersvoo | 1615 | @ use a pattern as fillstyle |
14066 | bpr | 1616 | @ suitable for all fillable object including the <a href="#userdraw">userdraw objects' family</a> |
14077 | bpr | 1617 | @ not -yet- implemented in the <a href="#multidraw">multidraw objects family</a>...(will probably be too complex) |
14066 | bpr | 1618 | @ 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 | 1619 | @ the pattern dimensions are hardcoded (linewidth, radius,dx,dy are fixed) |
11837 | schaersvoo | 1620 | @ the pattern color is set by command <a href='#fillcolor'>fillcolor</a> and <a href='#opacity'>opacity</a> |
11839 | schaersvoo | 1621 | @ see <a href="#fillcolor">fillcolor</a> for solid color filling. |
14086 | bpr | 1622 | @ 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> |
1623 | @ 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 |
||
13948 | schaersvoo | 1624 | @%fillpattern_1%size 400,400%xrange -5,5%yrange -5,5%opacity 165,150%fillpattern grid%fcircle -6,3,160,blue%fillpattern dot%fcircle -3,-3,160,red%fillpattern hatch%fcircle 0,3,160,green%filpattern diamond%fcircle 3,-3,160,cyan%zoom red |
1625 | @%fillpattern_2%size 400,400%xrange -10,10%yrange -10,10%linewidth 3%fillcolor green%fillpattern hatch%#fillpattern dot,diamond,grid,imageurl%userdraw fcircle,red |
||
11837 | schaersvoo | 1626 | */ |
1627 | temp = get_string(infile,1); |
||
11875 | schaersvoo | 1628 | if( strstr(temp,"grid") != 0 ){ use_pattern = 2;use_filled = 2;} /* use_pattern is used in dragstuff library */ |
11837 | schaersvoo | 1629 | else |
11875 | schaersvoo | 1630 | if( strstr(temp,"hatch") != 0 ){ use_pattern = 3;use_filled = 3;} |
11837 | schaersvoo | 1631 | else |
11875 | schaersvoo | 1632 | if( strstr(temp,"diamond") != 0 ){ use_pattern = 4;use_filled = 4;} |
11837 | schaersvoo | 1633 | else |
11875 | schaersvoo | 1634 | if( strstr(temp,"dot") != 0 ){ use_pattern = 5;use_filled = 5;} |
11837 | schaersvoo | 1635 | else |
11875 | schaersvoo | 1636 | if( strstr(temp,"/") != 0 ){ use_pattern = 6;use_filled = 0;if( js_function[ADD_LOAD_IMAGE] != 1 ){ js_function[ADD_LOAD_IMAGE] = 1; add_js_load_image(js_include_file,canvas_root_id);} fprintf(js_include_file,"get_image_from_url(\"%s\"); ",temp); } |
11854 | schaersvoo | 1637 | else |
13829 | bpr | 1638 | canvas_error("fillpattern unknown or typo...choose grid,hatch,diamond of dot..."); |
11837 | schaersvoo | 1639 | break; |
11806 | schaersvoo | 1640 | case FILLTOBORDER: |
1641 | /* |
||
1642 | @ filltoborder x,y,bordercolor,color |
||
14032 | schaersvoo | 1643 | @ fill the region of point (x:y) with color 'color' |
11806 | schaersvoo | 1644 | @ any other color will not act as border to the bucket fill |
14032 | schaersvoo | 1645 | @ use this command after all boundary objects are declared. |
11806 | schaersvoo | 1646 | @ use command <a href="#canvastype">canvastype </a> to fill another canvas (default should be fine: DRAG_CANVAS = 5) |
14071 | bpr | 1647 | @ 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 | 1648 | @ maybe used together with command <a href="#userdraw">userdraw clickfill,color</a> |
12110 | schaersvoo | 1649 | @%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 | 1650 | */ |
1651 | for(i=0 ;i < 4 ; i++){ |
||
1652 | switch(i){ |
||
1653 | case 0:double_data[0] = get_real(infile,0);break; |
||
1654 | case 1:double_data[1] = get_real(infile,0);break; |
||
1655 | case 2:bgcolor = get_color(infile,0);break; |
||
1656 | case 3:fill_color = get_color(infile,1); |
||
1657 | if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */ |
||
1658 | js_function[DRAW_FILLTOBORDER] = 1; |
||
1659 | add_js_filltoborder(js_include_file,canvas_root_id,canvas_type); |
||
1660 | } |
||
1661 | decimals = find_number_of_digits(precision); |
||
1662 | /* we need to set a timeout: the canvas is not yet draw in memory? when floodfill is called directly... */ |
||
11818 | schaersvoo | 1663 | string_length = 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); |
11806 | schaersvoo | 1664 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
11818 | schaersvoo | 1665 | 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 | 1666 | add_to_buffer(tmp_buffer); |
1667 | fill_cnt++; |
||
1668 | break; |
||
1669 | default:break; |
||
8351 | schaersvoo | 1670 | } |
11806 | schaersvoo | 1671 | } |
1672 | reset(); |
||
1673 | break; |
||
1674 | case FLOODFILL: |
||
1675 | /* |
||
1676 | @ floodfill x,y,color |
||
14071 | bpr | 1677 | @ alternative: <code>fill x,y,color</code> |
11806 | schaersvoo | 1678 | @ fill the region of point (x:y) with color 'color' |
1679 | @ any other color or size of picture (borders of picture) will act as border to the bucket fill |
||
14032 | schaersvoo | 1680 | @ use this command after all boundary objects are declared. |
14077 | bpr | 1681 | @ Use command <code>userdraw clickfill,color</code> for user click driven flood fill. |
11806 | schaersvoo | 1682 | @ use command <a href="#canvastype">canvastype </a> to fill another canvas (default should be fine: DRAG_CANVAS = 5) |
14071 | bpr | 1683 | @ 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 | 1684 | @%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 | 1685 | */ |
1686 | for(i=0 ;i < 4 ; i++){ |
||
1687 | switch(i){ |
||
1688 | case 0:double_data[0] = get_real(infile,0);break; |
||
1689 | case 1:double_data[1] = get_real(infile,0);break; |
||
1690 | case 2:fill_color = get_color(infile,1); |
||
1691 | if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */ |
||
1692 | js_function[DRAW_FILLTOBORDER] = 1; |
||
1693 | add_js_filltoborder(js_include_file,canvas_root_id,canvas_type); |
||
1694 | } |
||
1695 | decimals = find_number_of_digits(precision); |
||
1696 | /* we need to set a timeout: the canvas is not yet draw in memory? when floodfill is called directly... */ |
||
11818 | schaersvoo | 1697 | string_length = 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); |
11806 | schaersvoo | 1698 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
11818 | schaersvoo | 1699 | 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 | 1700 | add_to_buffer(tmp_buffer); |
1701 | fill_cnt++; |
||
1702 | break; |
||
1703 | default:break; |
||
1704 | } |
||
1705 | } |
||
1706 | reset(); |
||
1707 | break; |
||
1708 | |||
1709 | case FONTCOLOR: |
||
1710 | /* |
||
1711 | @ fontcolor color |
||
1712 | @ color: hexcolor or colorname |
||
1713 | @ default: black |
||
13956 | schaersvoo | 1714 | @ use command <a href="#fontfamily'>fontfamily</a> to deviate from default font type |
1715 | @%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 | 1716 | */ |
1717 | font_color = get_color(infile,1); |
||
1718 | break; |
||
1719 | |||
1720 | case FONTFAMILY: |
||
1721 | /* |
||
1722 | @ fontfamily font_description |
||
1723 | @ set the font family; for browsers that support it |
||
14078 | bpr | 1724 | @ font_description: Ariel, Courier, Helvetica etc |
14071 | bpr | 1725 | @ 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:<br />italic 34pt Ariel |
1726 | @ use correct syntax: ''font style``, ''font size pt``, ''fontfamily`` |
||
13959 | bpr | 1727 | @%fontfamily%size 400,400%xrange -10,10%yrange -10,10 %fontfamily Bold 10pt Ariel%string blue,-9,9,10 pt Ariel%fontfamily Italic 20pt Ariel%string blue,0,9,20 pt Ariel%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 |
1728 | |||
11806 | schaersvoo | 1729 | */ |
1730 | font_family = get_string(infile,1); |
||
1731 | break; |
||
1732 | |||
1733 | case FONTSIZE: |
||
1734 | /* |
||
1735 | @ fontsize font_size |
||
1736 | @ default value 12 |
||
14071 | bpr | 1737 | @ 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 | 1738 | */ |
1739 | font_size = (int) (get_real(infile,1)); |
||
1740 | break; |
||
1741 | |||
1742 | case FUNCTION_LABEL: |
||
1743 | /* |
||
14071 | bpr | 1744 | @ functionlabel some string |
14086 | bpr | 1745 | @ default value ''f(x)=`` |
11806 | schaersvoo | 1746 | @ no mathml allowed (just ascii string) |
13956 | schaersvoo | 1747 | @ use command <a href='#fontsize'>fontsize int</a> to adjust the size |
1748 | @ use command <a href='#strokecolor'>strokecolor colorname</a> to adjust the labels (individually, if needed) |
||
14066 | bpr | 1749 | @ if needed, use before every command <a href='#userinput'>userinput function | inputfield | textarea</a> |
13956 | schaersvoo | 1750 | @ no limit in amount of inputfields for userbased function plotting |
11806 | schaersvoo | 1751 | */ |
1752 | function_label = get_string_argument(infile,1); |
||
1753 | break; |
||
1754 | |||
14078 | bpr | 1755 | case GRID:/* xmajor,ymajor,gridcolor [,xminor,yminor,tick length (px), axis/tickscolor]*/ |
11806 | schaersvoo | 1756 | /* |
1757 | @ grid step_x,step_y,gridcolor |
||
14068 | bpr | 1758 | @ 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><br />minor x step = step_x / minor_x |
14066 | bpr | 1759 | @ 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 <br />defaults: black,12,Ariel |
14071 | bpr | 1760 | @ 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 | 1761 | @ can <b>not</b> be set <a href="#onclick">onclick</a> or <a href="#drag">drag xy</a> |
14086 | bpr | 1762 | @ use commands <a href="#xlabel">xlabel some_string</a> and/or <a href="#ylabel">ylabel some_string</a> to label axis;<br />use command ''fontsize`` to adjust size: the font family is non-configurable 'italic your_fontsize px Ariel' ! |
14066 | bpr | 1763 | @ 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 <a href="#fontfamily">command fontfamily</a>; default '12px Ariel') |
1764 | @ see command <a href="#legend">legend</a>to set a legend for the graph ;<br />use command <a href="#fontsize">fontsize</a> to adjust size (the font family is non-configurable 'bold your_fontsize px Ariel') |
||
12110 | schaersvoo | 1765 | @%grid%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%zoom red |
1766 | @%grid_axis%size 400,400%xrange -10,10%yrange -10,10%axis%grid 1,1,grey,2,2,6,black%zoom red |
||
1767 | @%grid_axisnumbering%size 400,400%xrange -10,10%yrange -10,10%axisnumbering%precision 0%grid 1,1,grey,2,2,6,black%zoom red |
||
1768 | @%grid_axis_axisnumbering%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%precision 0%grid 1,1,grey,2,2,6,black%zoom red |
||
11806 | schaersvoo | 1769 | */ |
1770 | if( js_function[DRAW_YLOGSCALE] == 1 ){canvas_error("only one grid type is allowed...");} |
||
1771 | if( js_function[DRAW_GRID] != 1 ){ js_function[DRAW_GRID] = 1;} |
||
1772 | for(i=0;i<4;i++){ |
||
1773 | switch(i){ |
||
1774 | case 0:double_data[0] = get_real(infile,0);break;/* xmajor */ |
||
1775 | case 1:double_data[1] = get_real(infile,0);break;/* ymajor */ |
||
1776 | case 2: |
||
1777 | if( use_axis == TRUE ){ |
||
1778 | stroke_color = get_color(infile,0); |
||
1779 | done = FALSE; |
||
1780 | int_data[0] = (int) (get_real(infile,0));/* xminor */ |
||
1781 | int_data[1] = (int) (get_real(infile,0));/* yminor */ |
||
1782 | int_data[2] = (int) (get_real(infile,0));/* tic_length */ |
||
1783 | fill_color = get_color(infile,1); /* used as axis_color*/ |
||
8351 | schaersvoo | 1784 | } |
1785 | else |
||
1786 | { |
||
11806 | schaersvoo | 1787 | int_data[0] = 1; |
1788 | int_data[1] = 1; |
||
1789 | stroke_color = get_color(infile,1); |
||
1790 | fill_color = stroke_color; |
||
8351 | schaersvoo | 1791 | } |
11806 | schaersvoo | 1792 | 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 !");} |
1793 | /* set snap_x snap_y values in pixels */ |
||
1794 | fprintf(js_include_file,"snap_x = %f;snap_y = %f;",double_data[0] / int_data[0],double_data[1] / int_data[1]); |
||
1795 | string_length = snprintf(NULL,0, ";draw_grid%d(%d,%d,%.2f,%.*f,%.*f,%d,%d,%d,%d,\"%s\",\"%s\",%d,\"%s\",%d,%d,%d,%.2f,%d,%s,%d,%d,%d,\"%s\",%.2f);\n ",canvas_root_id,GRID_CANVAS,precision,stroke_opacity,decimals,double_data[0],decimals,double_data[1],int_data[0],int_data[1],int_data[2],line_width,stroke_color,fill_color,font_size,font_family,use_axis,use_axis_numbering,use_rotate,angle,use_affine,affine_matrix,use_dashed,dashtype[0],dashtype[1],font_color,fill_opacity); |
||
1796 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
1797 | snprintf(tmp_buffer,string_length,";draw_grid%d(%d,%d,%.2f,%.*f,%.*f,%d,%d,%d,%d,\"%s\",\"%s\",%d,\"%s\",%d,%d,%d,%.2f,%d,%s,%d,%d,%d,\"%s\",%.2f);\n ",canvas_root_id,GRID_CANVAS,precision,stroke_opacity,decimals,double_data[0],decimals,double_data[1],int_data[0],int_data[1],int_data[2],line_width,stroke_color,fill_color,font_size,font_family,use_axis,use_axis_numbering,use_rotate,angle,use_affine,affine_matrix,use_dashed,dashtype[0],dashtype[1],font_color,fill_opacity); |
||
1798 | add_to_buffer(tmp_buffer); |
||
1799 | break; |
||
8351 | schaersvoo | 1800 | } |
1801 | } |
||
1802 | reset(); |
||
1803 | break; |
||
11806 | schaersvoo | 1804 | case GRIDFILL: |
1805 | /* |
||
1806 | @ gridfill x0,y0,dx,dy,color |
||
1807 | @ x0,y0 in xrange / yrange |
||
1808 | @ distances dx,dy in pixels |
||
13936 | bpr | 1809 | @ there is also a command <a href="#userdraw">userdraw gridfill,color</a> |
12110 | schaersvoo | 1810 | @%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 |
1811 | |||
11806 | schaersvoo | 1812 | */ |
1813 | if( js_function[DRAW_GRIDFILL] != 1 ){ js_function[DRAW_GRIDFILL] = 1;} |
||
11820 | schaersvoo | 1814 | decimals = find_number_of_digits(precision); |
1815 | if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */ |
||
1816 | js_function[DRAW_FILLTOBORDER] = 1; |
||
1817 | add_js_filltoborder(js_include_file,canvas_root_id,canvas_type); |
||
1818 | } |
||
11806 | schaersvoo | 1819 | for(i=0;i<5;i++){ |
1820 | switch(i){ |
||
11820 | schaersvoo | 1821 | case 0: double_data[0] = get_real(infile,0); break; /* x */ |
1822 | case 1: double_data[1] = get_real(infile,0); break; /* y */ |
||
1823 | case 2: int_data[0] = (int) (get_real(infile,0)); break; /* dx pixel */ |
||
1824 | case 3: int_data[1] = (int) (get_real(infile,0)); break; /* dy pixel*/ |
||
11806 | schaersvoo | 1825 | case 4: stroke_color = get_color(infile,1); |
11820 | schaersvoo | 1826 | string_length = 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); |
11806 | schaersvoo | 1827 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
11820 | schaersvoo | 1828 | 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 | 1829 | add_to_buffer(tmp_buffer); |
11820 | schaersvoo | 1830 | fill_cnt++; |
11806 | schaersvoo | 1831 | break; |
1832 | default:break; |
||
1833 | } |
||
1834 | } |
||
1835 | reset(); |
||
1836 | break; |
||
8386 | schaersvoo | 1837 | |
8244 | schaersvoo | 1838 | case HALFLINE: |
1839 | /* |
||
1840 | @ demiline x1,y1,x2,y2,color |
||
14071 | bpr | 1841 | @ alternative: <code>halfline</code> |
8244 | schaersvoo | 1842 | @ draws a halfline starting in (x1:y1) and through (x2:y2) in color 'color' (colorname or hex) |
9406 | schaersvoo | 1843 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
12110 | schaersvoo | 1844 | @%halfline%size 400,400%xrange -10,10%yrange -10,10%halfline -5,5,0,0,red%halfline -5,-5,0,0,blue |
8244 | schaersvoo | 1845 | */ |
1846 | for(i=0;i<5;i++){ |
||
1847 | switch(i){ |
||
1848 | case 0: double_data[0]= get_real(infile,0);break; /* x-values */ |
||
1849 | case 1: double_data[1]= get_real(infile,0);break; /* y-values */ |
||
1850 | case 2: double_data[10]= get_real(infile,0);break; /* x-values */ |
||
1851 | case 3: double_data[11]= get_real(infile,0);break; /* y-values */ |
||
1852 | case 4: stroke_color=get_color(infile,1);/* name or hex color */ |
||
1853 | if(double_data[0] == double_data[10]){ /* vertical halfline */ |
||
1854 | if(double_data[1] < double_data[11]){ |
||
1855 | double_data[3] = ymax + 1000; |
||
1856 | } |
||
1857 | else |
||
1858 | { |
||
1859 | double_data[3] = ymin - 1000; |
||
1860 | } |
||
10953 | bpr | 1861 | double_data[2] = double_data[0]; |
8244 | schaersvoo | 1862 | } |
1863 | else |
||
1864 | { /* horizontal halfline*/ |
||
1865 | if( double_data[1] == double_data[11] ){ |
||
1866 | if( double_data[0] < double_data[10] ){ |
||
1867 | double_data[2] = xmax + 1000; /* halfline to the right */ |
||
1868 | } |
||
1869 | else |
||
1870 | { |
||
1871 | double_data[2] = xmin - 1000; /* halfline to the left */ |
||
1872 | } |
||
1873 | double_data[3] = double_data[1]; |
||
1874 | } |
||
1875 | else |
||
1876 | { |
||
1877 | /* any other halfline */ |
||
1878 | /* slope */ |
||
1879 | double_data[12] = (double_data[11] - double_data[1])/(double_data[10] - double_data[0]); |
||
1880 | /* const */ |
||
1881 | double_data[13] = double_data[1] - double_data[12]*double_data[0]; |
||
1882 | if( double_data[0] < double_data[10] ){ |
||
1883 | double_data[2] = double_data[2] + 1000; |
||
1884 | } |
||
1885 | else |
||
1886 | { |
||
1887 | double_data[2] = double_data[2] - 1000; |
||
1888 | } |
||
1889 | double_data[3] = double_data[12]*double_data[2] + double_data[13]; |
||
1890 | } |
||
10953 | bpr | 1891 | } |
14045 | schaersvoo | 1892 | fprintf(js_include_file,"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\",%d,%s,%d,%d,%s,%d,%d));\n",drag_type,click_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,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern); |
8379 | schaersvoo | 1893 | if(onclick > 0){click_cnt++;} |
1894 | /* click_cnt++; */ |
||
1895 | reset(); |
||
8244 | schaersvoo | 1896 | break; |
1897 | } |
||
1898 | } |
||
1899 | break; |
||
8386 | schaersvoo | 1900 | |
8365 | schaersvoo | 1901 | case HALFLINES: |
1902 | /* |
||
1903 | @ demilines color,x1,y1,x2,y2,.... |
||
14071 | bpr | 1904 | @ alternative: <code>halflines</code> |
8365 | schaersvoo | 1905 | @ draws halflines starting in (x1:y1) and through (x2:y2) in color 'color' (colorname or hex) etc etc |
9406 | schaersvoo | 1906 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> indiviually |
12110 | schaersvoo | 1907 | @%halflines%size 400,400%xrange -10,10%yrange -10,10%halflines red,-5,5,0,0,-5,-5,0,0 |
8365 | schaersvoo | 1908 | */ |
1909 | stroke_color=get_color(infile,0); |
||
1910 | fill_color = stroke_color; |
||
1911 | i=0; |
||
1912 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 1913 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
8365 | schaersvoo | 1914 | if(i%2 == 0 ){ |
1915 | double_data[i] = get_real(infile,0); /* x */ |
||
1916 | } |
||
1917 | else |
||
1918 | { |
||
1919 | double_data[i] = get_real(infile,1); /* y */ |
||
1920 | } |
||
1921 | i++; |
||
1922 | } |
||
1923 | decimals = find_number_of_digits(precision); |
||
1924 | for(c = 0 ; c < i-1 ; c = c+4){ |
||
1925 | if( double_data[c] == double_data[c+2] ){ /* vertical line*/ |
||
1926 | if(double_data[c+1] < double_data[c+3]){ /* upright halfline */ |
||
1927 | double_data[c+3] = ymax + 1000; |
||
1928 | } |
||
1929 | else |
||
1930 | { |
||
1931 | double_data[c+3] = ymin - 1000;/* descending halfline */ |
||
1932 | } |
||
1933 | } |
||
1934 | else |
||
1935 | { |
||
1936 | if( double_data[c+1] == double_data[c+3] ){ /* horizontal line */ |
||
1937 | if(double_data[c] < double_data[c+2] ){ /* halfline to the right */ |
||
1938 | double_data[c+2] = xmax+100; |
||
1939 | } |
||
1940 | else |
||
1941 | { |
||
1942 | double_data[c+2] = xmin-1000; /* halfline to the right */ |
||
1943 | } |
||
1944 | } |
||
1945 | else |
||
1946 | { |
||
1947 | /* m */ |
||
1948 | double m = (double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]); |
||
1949 | /* q */ |
||
1950 | double q = double_data[c+1] - ((double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]))*double_data[c]; |
||
1951 | if(double_data[c] < double_data[c+2]){ /* to the right */ |
||
14071 | bpr | 1952 | double_data[c+2] = xmax+1000; /* 1000 is needed for dragging...otherwise it is just segment */ |
8365 | schaersvoo | 1953 | double_data[c+3] = (m)*(double_data[c+2])+(q); |
1954 | } |
||
1955 | else |
||
1956 | { /* to the left */ |
||
1957 | double_data[c+2] = xmin - 1000; |
||
1958 | double_data[c+3] = (m)*(double_data[c+2])+(q); |
||
1959 | } |
||
1960 | } |
||
1961 | } |
||
14045 | schaersvoo | 1962 | fprintf(js_include_file,"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\",%d,%s,%d,%d,%s,%d,%d));\n",drag_type,click_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,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern); |
8379 | schaersvoo | 1963 | if(onclick > 0){click_cnt++;} |
1964 | /* click_cnt++; */ |
||
8365 | schaersvoo | 1965 | } |
1966 | reset(); |
||
1967 | break; |
||
11806 | schaersvoo | 1968 | case HATCHFILL: |
1969 | /* |
||
1970 | @ hatchfill x0,y0,dx,dy,color |
||
1971 | @ x0,y0 in xrange / yrange |
||
1972 | @ distances dx,dy in pixels |
||
13936 | bpr | 1973 | @ there is also a command <a href="#userdraw">userdraw hatchfill,color</a> |
12110 | schaersvoo | 1974 | @%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 | 1975 | */ |
1976 | if( js_function[DRAW_HATCHFILL] != 1 ){ js_function[DRAW_HATCHFILL] = 1;} |
||
11820 | schaersvoo | 1977 | if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */ |
1978 | js_function[DRAW_FILLTOBORDER] = 1; |
||
1979 | add_js_filltoborder(js_include_file,canvas_root_id,canvas_type); |
||
1980 | } |
||
1981 | decimals = find_number_of_digits(precision); |
||
11806 | schaersvoo | 1982 | for(i=0;i<5;i++){ |
1983 | switch(i){ |
||
11820 | schaersvoo | 1984 | case 0: double_data[0] = get_real(infile,0); break; /* x */ |
1985 | case 1: double_data[1] = get_real(infile,0); break; /* y */ |
||
1986 | case 2: int_data[0] = (int) (get_real(infile,0)); break; /* dx pixel */ |
||
1987 | case 3: int_data[1] = (int) (get_real(infile,0)); break; /* dy pixel*/ |
||
11806 | schaersvoo | 1988 | case 4: stroke_color = get_color(infile,1); |
1989 | /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */ |
||
11820 | schaersvoo | 1990 | string_length = 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); |
11806 | schaersvoo | 1991 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
11820 | schaersvoo | 1992 | 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 | 1993 | add_to_buffer(tmp_buffer); |
11820 | schaersvoo | 1994 | fill_cnt++; |
11806 | schaersvoo | 1995 | break; |
1996 | default:break; |
||
1997 | } |
||
1998 | } |
||
1999 | reset(); |
||
2000 | break; |
||
8386 | schaersvoo | 2001 | |
8224 | bpr | 2002 | case HLINE: |
7614 | schaersvoo | 2003 | /* |
2004 | @ hline x,y,color |
||
14071 | bpr | 2005 | @ alternative: <code>horizontalline</code> |
7614 | schaersvoo | 2006 | @ draw a horizontal line through point (x:y) in color 'color' |
14066 | bpr | 2007 | @ 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 | 2008 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
12110 | schaersvoo | 2009 | @%hline%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%hline 0,0,red%dhline 0,5,blue |
7614 | schaersvoo | 2010 | */ |
2011 | for(i=0;i<3;i++) { |
||
2012 | switch(i){ |
||
2013 | case 0: double_data[0] = get_real(infile,0);break; /* x-values */ |
||
2014 | case 1: double_data[1] = get_real(infile,0);break; /* y-values */ |
||
2015 | case 2: stroke_color = get_color(infile,1);/* name or hex color */ |
||
2016 | double_data[3] = double_data[1]; |
||
2017 | decimals = find_number_of_digits(precision); |
||
14045 | schaersvoo | 2018 | fprintf(js_include_file,"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\",%d,%s,%d,%d,%s,%d,%d));\n",drag_type,click_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,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern); |
8379 | schaersvoo | 2019 | if(onclick > 0){click_cnt++;} |
2020 | /* click_cnt++; */ |
||
2021 | reset(); |
||
7614 | schaersvoo | 2022 | break; |
2023 | } |
||
2024 | } |
||
2025 | break; |
||
8366 | schaersvoo | 2026 | |
2027 | case HLINES: |
||
2028 | /* |
||
2029 | @ hlines color,x1,y1,x2,y2,... |
||
14071 | bpr | 2030 | @ alternative: <code>horizontallines</code> |
8366 | schaersvoo | 2031 | @ draw horizontal lines through points (x1:y1)...(xn:yn) in color 'color' |
9406 | schaersvoo | 2032 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually |
12110 | schaersvoo | 2033 | @%hlines%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%hlines red,0,0,0,5,0,-5 |
8366 | schaersvoo | 2034 | */ |
2035 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
2036 | fill_color = stroke_color; |
||
2037 | i=0; |
||
2038 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 2039 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
8366 | schaersvoo | 2040 | if(i%2 == 0 ){ |
2041 | double_data[i] = get_real(infile,0); /* x */ |
||
2042 | } |
||
2043 | else |
||
2044 | { |
||
2045 | double_data[i] = get_real(infile,1); /* y */ |
||
2046 | } |
||
2047 | i++; |
||
2048 | } |
||
2049 | decimals = find_number_of_digits(precision); |
||
2050 | for(c = 0 ; c < i-1 ; c = c+2){ |
||
14045 | schaersvoo | 2051 | fprintf(js_include_file,"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\",%d,%s,%d,%d,%s,%d,%d));\n",drag_type,click_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,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern); |
8379 | schaersvoo | 2052 | if(onclick > 0){click_cnt++;} |
2053 | /* click_cnt++; */ |
||
8366 | schaersvoo | 2054 | } |
2055 | reset(); |
||
2056 | break; |
||
11806 | schaersvoo | 2057 | case HTTP: |
7614 | schaersvoo | 2058 | /* |
11806 | schaersvoo | 2059 | @ http x1,y1,x2,y2,http://some_adress.com |
14078 | bpr | 2060 | @ an active html-page will be displayed in an "iframe" rectangle left top (x1:y1), right bottom (x2:y2) |
11806 | schaersvoo | 2061 | @ do not use interactivity (or mouse) if the mouse needs to be active in the iframe |
14071 | bpr | 2062 | @ can <b>not</b> be ''set onclick`` or ''drag xy`` |
12110 | schaersvoo | 2063 | @%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 | 2064 | */ |
11806 | schaersvoo | 2065 | if( js_function[DRAW_HTTP] != 1 ){ js_function[DRAW_HTTP] = 1;} |
2066 | for(i=0;i<5;i++){ |
||
7614 | schaersvoo | 2067 | switch(i){ |
11806 | schaersvoo | 2068 | case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */ |
14032 | schaersvoo | 2069 | case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system -> pixel height */ |
11806 | schaersvoo | 2070 | case 2: int_data[2]=x2px(get_real(infile,0)) - int_data[0];break; /* width in x/y-range coord system -> pixel width */ |
2071 | case 3: int_data[3]=y2px(get_real(infile,0)) - int_data[1];break; /* height in x/y-range coord system -> pixel height */ |
||
2072 | case 4: decimals = find_number_of_digits(precision); |
||
2073 | temp = get_string(infile,1); |
||
2074 | if(strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'");} |
||
2075 | string_length = snprintf(NULL,0,"draw_http(%d,%d,%d,%d,%d,\"%s\");\n",canvas_root_id,int_data[0],int_data[1],int_data[2],int_data[3],temp); |
||
2076 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+2); |
||
2077 | 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); |
||
2078 | add_to_buffer(tmp_buffer); |
||
7614 | schaersvoo | 2079 | break; |
2080 | } |
||
2081 | } |
||
11806 | schaersvoo | 2082 | reset(); |
7614 | schaersvoo | 2083 | break; |
11806 | schaersvoo | 2084 | case HTML: |
8366 | schaersvoo | 2085 | /* |
11806 | schaersvoo | 2086 | @ html x1,y1,x2,y2,html_string |
14071 | bpr | 2087 | @ all tags are allowed, html code using inputfields could be read using your own javascript code. Do not use ids like 'canvas_input0' etc. |
2088 | @ can be set onclick (however dragging not supported) |
||
14038 | schaersvoo | 2089 | @ use keyword <a href='#centered'>centered</a> to center the html object on (x1:y1) |
12110 | schaersvoo | 2090 | @%html%size 400,400%xrange -10,10%yrange -10,10%html 0,10,10,0,<table style="border:solid 2px;background-color:yellow"><tr><th>qwerty</th><th>qwerty</th></tr><tr><td>qwerty</td><td>qwerty</td></tr><tr><td>qwerty</td><td>qwerty</td></tr><tr><td>qwerty</td><td>qwerty</td></tr><tr><td>qwerty</td><td>qwerty</td></tr></table> %opacity 200,50%drag xy%fcircle 0,0,100,green |
8366 | schaersvoo | 2091 | */ |
11806 | schaersvoo | 2092 | if( js_function[DRAW_XML] != 1 ){ js_function[DRAW_XML] = 1;} |
2093 | for(i=0;i<5;i++){ |
||
2094 | switch(i){ |
||
2095 | case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */ |
||
14032 | schaersvoo | 2096 | case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system -> pixel height */ |
14066 | bpr | 2097 | case 2: int_data[2]=x2px(get_real(infile,0));break;/* no more width needed: overflow */ |
2098 | case 3: int_data[3]=y2px(get_real(infile,0));break;/* no more height needed: overflow */ |
||
11806 | schaersvoo | 2099 | case 4: decimals = find_number_of_digits(precision); |
2100 | temp = get_string(infile,1); |
||
2101 | if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'"); } |
||
14044 | schaersvoo | 2102 | string_length = snprintf(NULL,0,"draw_xml(%d,%d,%d,\"%s\",%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d);\n",canvas_root_id,int_data[0],int_data[1],temp,drag_type,onclick,click_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,use_offset,use_snap); |
11806 | schaersvoo | 2103 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
14044 | schaersvoo | 2104 | snprintf(tmp_buffer,string_length,"draw_xml(%d,%d,%d,\"%s\",%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d);\n",canvas_root_id,int_data[0],int_data[1],temp,drag_type,onclick,click_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,use_offset,use_snap); |
11806 | schaersvoo | 2105 | add_to_buffer(tmp_buffer); |
2106 | if(onclick == 1 || onclick == 2 ){click_cnt++;} |
||
14038 | schaersvoo | 2107 | use_offset = 0; |
11806 | schaersvoo | 2108 | break; |
2109 | default:break; |
||
8366 | schaersvoo | 2110 | } |
2111 | } |
||
2112 | break; |
||
8386 | schaersvoo | 2113 | |
11806 | schaersvoo | 2114 | case IMAGEFILL: |
7614 | schaersvoo | 2115 | /* |
11996 | schaersvoo | 2116 | @ imagefill x,y,scaling to xsize × ysize?,image_url |
11874 | schaersvoo | 2117 | @ The next suitable <b>filled object</b> will be filled with "image_url" tiled |
2118 | @ scaling to xsize × ysize ? ... 1 = yes 0 = no |
||
14078 | bpr | 2119 | @ After pattern filling, the fill-color should be reset ! |
14066 | bpr | 2120 | @ wims getins / image from class directory: imagefill 80,80,my_image.gif |
2121 | @ normal url: imagefill 80,80,0,$module_dir/gifs/my_image.gif |
||
2122 | @ normal url: imagefill 80,80,1,http://adres/a/b/c/my_image.jpg |
||
11874 | schaersvoo | 2123 | @ if dx,dy is larger than the image, the whole image will be background to the next object. |
13967 | schaersvoo | 2124 | @%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 |
2125 | @%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 | 2126 | */ |
11806 | schaersvoo | 2127 | if( js_function[DRAW_IMAGEFILL] != 1 ){ js_function[DRAW_IMAGEFILL] = 1;} |
11854 | schaersvoo | 2128 | if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */ |
2129 | js_function[DRAW_FILLTOBORDER] = 1; |
||
2130 | add_js_filltoborder(js_include_file,canvas_root_id,canvas_type); |
||
2131 | } |
||
11874 | schaersvoo | 2132 | for(i=0 ;i < 4 ; i++){ |
7614 | schaersvoo | 2133 | switch(i){ |
11806 | schaersvoo | 2134 | case 0:int_data[0] = (int) (get_real(infile,0));break; |
2135 | case 1:int_data[1] = (int) (get_real(infile,0));break; |
||
11874 | schaersvoo | 2136 | case 2:int_data[2] = (int) (get_real(infile,0));break; /* 0 | 1 */ |
2137 | case 3: URL = get_string_argument(infile,1); |
||
2138 | string_length = 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]); |
||
11806 | schaersvoo | 2139 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
11874 | schaersvoo | 2140 | 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 | 2141 | add_to_buffer(tmp_buffer); |
11874 | schaersvoo | 2142 | fill_cnt++; |
11806 | schaersvoo | 2143 | break; |
7614 | schaersvoo | 2144 | } |
2145 | } |
||
11806 | schaersvoo | 2146 | reset(); |
2147 | break; |
||
14066 | bpr | 2148 | |
14038 | schaersvoo | 2149 | case IMAGEPALETTE: |
2150 | /* |
||
2151 | @ imagepalette image1,image2,image3,... |
||
14071 | bpr | 2152 | @ if used before & together with command <a href='#multidraw'>multidraw images,..,...,etc</a> the imag as will be presented in a small table in the 'control panel' |
14038 | schaersvoo | 2153 | @%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 Ariel%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%inputstyle 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 |
2154 | */ |
||
2155 | temp = get_string(infile,1); |
||
2156 | temp = str_replace(temp,",","\",\""); |
||
2157 | if( use_tooltip == 1 ){canvas_error("command 'imagepalette' is incompatible with command 'intooltip tip_text',as they use the same div-element ");} |
||
2158 | fprintf(js_include_file,"\nvar current_id;var imagepalette = [\" %s \"];\n",temp); |
||
2159 | break; |
||
14066 | bpr | 2160 | |
11806 | schaersvoo | 2161 | case INPUTSTYLE: |
2162 | /* |
||
2163 | @ inputstyle style_description |
||
14071 | bpr | 2164 | @ may be used before any ''style-able`` html object (like inputfields or buttons) or any html objects that are generated by some canvasdraw commands |
12107 | schaersvoo | 2165 | @%inputstyle%size 400,400%xrange -10,10%yrange -10,10%inputstyle color:blue;font-weight:bold;font-style:italic;font-size:16pt;text-align:center%input 0,0,10,1,Hello |
11806 | schaersvoo | 2166 | */ |
2167 | input_style = get_string(infile,1); |
||
7614 | schaersvoo | 2168 | break; |
11806 | schaersvoo | 2169 | case INPUT: |
2170 | /* |
||
2171 | @ input x,y,size,editable,value |
||
2172 | @ to set inputfield "readonly", use editable = 0 |
||
2173 | @ only active inputfields (editable = 1) will be read with read_canvas(); |
||
14086 | bpr | 2174 | @ 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> |
14066 | bpr | 2175 | @ may be further controlled by <a href="#inputstyle">inputstyle</a> (inputcss is not yet implemented...) |
11806 | schaersvoo | 2176 | @ if mathml inputfields are present and / or some userdraw is performed, these data will <b>not</b> be send as well (javascript:read_canvas();) |
2177 | @ 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 | 2178 | @ 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> |
2179 | @%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 | 2180 | */ |
2181 | if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;} |
||
2182 | for(i = 0 ; i<5;i++){ |
||
2183 | switch(i){ |
||
2184 | case 0: int_data[0]=x2px(get_real(infile,0));break;/* x in px */ |
||
2185 | case 1: int_data[1]=y2px(get_real(infile,0));break;/* y in px */ |
||
2186 | case 2: int_data[2]=abs( (int)(get_real(infile,0)));break; /* size */ |
||
2187 | case 3: if( get_real(infile,1) >0){int_data[3] = 1;}else{int_data[3] = 0;};break; /* readonly */ |
||
2188 | case 4: |
||
2189 | temp = get_string_argument(infile,1); |
||
2190 | string_length = snprintf(NULL,0, "draw_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],input_style,temp,use_offset); |
||
2191 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
2192 | snprintf(tmp_buffer,string_length,"draw_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],input_style,temp,use_offset); |
||
2193 | add_to_buffer(tmp_buffer); |
||
2194 | input_cnt++;break; |
||
2195 | default: break; |
||
2196 | } |
||
2197 | } |
||
2198 | if(reply_format == 0 ){reply_format = 15;} |
||
2199 | reset(); |
||
2200 | break; |
||
8386 | schaersvoo | 2201 | |
11806 | schaersvoo | 2202 | case INTOOLTIP: |
2203 | /* |
||
2204 | @ intooltip link_text |
||
2205 | @ link_text is a single line (span-element) |
||
14071 | bpr | 2206 | @ link_text may also be an image URL ''http://some_server/images/my_image.png`` or ''$module_dir/gifs/my_image.jpg`` |
11806 | schaersvoo | 2207 | @ link_text may contain HTML markup |
14071 | bpr | 2208 | @ the canvas will be displayed in a tooltip on ''link_text`` |
2209 | @ 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'. |
||
2210 | @ 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... |
||
13953 | schaersvoo | 2211 | @%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 | 2212 | */ |
2213 | if(use_input_xy != FALSE ){canvas_error("intooltip can not be combined with userinput_xy or other commands using the tooltip-div...see documentation");} |
||
2214 | if( use_tooltip == 1 ){ canvas_error("command 'intooltip' cannot be combined with command 'popup'...");} |
||
2215 | tooltip_text = get_string(infile,1); |
||
2216 | if(strstr(tooltip_text,"\"") != 0 ){ tooltip_text = str_replace(tooltip_text,"\"","'"); } |
||
2217 | use_tooltip = 1; |
||
2218 | break; |
||
2219 | |||
2220 | case JSCURVE: |
||
7614 | schaersvoo | 2221 | /* |
11893 | schaersvoo | 2222 | @ jscurve color,formula1(x),formula2(x),formula3(x),... |
14071 | bpr | 2223 | @ alternative: <code>jsplot color,formula(x)</code> |
11893 | schaersvoo | 2224 | @ your function will be plotted by the javascript engine of the client browser |
2225 | @ 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 | 2226 | @ use only basic math in your curve: <code>sqrt,^,asin,acos,atan,log,pi,abs,sin,cos,tan,e</code> |
2227 | @ use parenthesis and rawmath: use 2*x instead of 2x ; use 2^(sin(x))...etc etc (use error console to debug any errors...) |
||
2228 | @ <b>attention</b>: last ''precision`` command in the canvasdraw script determines the calculation precision of the javascript curve plot ! |
||
11806 | schaersvoo | 2229 | @ no validity check is done by wims. |
14071 | bpr | 2230 | @ 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 | 2231 | @ 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 |
11893 | schaersvoo | 2232 | @ use keyword <a href='animate'>animate</a> for animating a point on the curve |
14071 | bpr | 2233 | @ use command ''trace_jscurve formula(x)`` for tracing |
2234 | @ use command ''jsmath formula(x)`` for calculating and displaying indiviual points on the curve |
||
11806 | schaersvoo | 2235 | @ can <b>not</b> be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> (yet) |
14071 | bpr | 2236 | @ commands plotjump / plotstep are not active for ''jscurve`` |
11806 | schaersvoo | 2237 | @ every command jscurve will produce a new canvas (canvastype 111,112,113...) for this one curve. |
14071 | bpr | 2238 | @ 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...) |
12107 | schaersvoo | 2239 | @%jscurve%size 400,400%xrange -10,10%yrange -10,10%multicolors red,green,blue,orange%multilinewidth 1,1,1%multistrokeopacity 0.5,0.8,1.0%jscurve red,sin(x),1/sin(x),sin(x^2) |
11806 | schaersvoo | 2240 | */ |
2241 | stroke_color = get_color(infile,0); |
||
2242 | if( use_js_math == FALSE){/* add this stuff only once...*/ |
||
2243 | add_to_js_math(js_include_file); |
||
2244 | use_js_math = TRUE; |
||
2245 | } |
||
2246 | if( use_js_plot == FALSE){ |
||
2247 | use_js_plot = TRUE; |
||
2248 | add_jsplot(js_include_file,canvas_root_id); /* this plots the function on JSPLOT_CANVAS */ |
||
2249 | } |
||
11893 | schaersvoo | 2250 | int use_paramteric = 0; |
2251 | if( tmin != 0 && tmax !=0){use_parametric = 1;} |
||
11806 | schaersvoo | 2252 | temp = get_string(infile,1); |
2253 | temp = str_replace(temp,",","\",\""); |
||
14032 | schaersvoo | 2254 | string_length = snprintf(NULL,0, "jsplot(%d,[\"%s\"],[%d],[\"%s\"],[%.2f],[%d],%d,%d,[%f,%f],%d,%d,%d); ",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); |
11806 | schaersvoo | 2255 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
11893 | schaersvoo | 2256 | snprintf(tmp_buffer,string_length,"jsplot(%d,[\"%s\"],[%d],[\"%s\"],[%.2f],[%d],%d,%d,[%f,%f],%d,%d,%d); ",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); |
11806 | schaersvoo | 2257 | add_to_buffer(tmp_buffer); |
2258 | jsplot_cnt++; |
||
2259 | /* we need to create multiple canvasses, so we may zoom and pan ?? */ |
||
2260 | break; |
||
2261 | |||
2262 | case JSMATH: |
||
2263 | /* |
||
2264 | @ jsmath some_math_function |
||
2265 | @ will calculate an y-value from a userinput x-value and draws a crosshair on these coordinates. |
||
14077 | bpr | 2266 | @ 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 |
2267 | @ use command 'inputstyle some_css' for styling the display fields. Use command 'fontsize int' to size the labels ''x`` and ''y`` |
||
14066 | bpr | 2268 | @ 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 | 2269 | @ be aware that the formula's of the plotted function(s) can be found in the page javascript source |
12111 | schaersvoo | 2270 | @%jsmath%size 400,400%xrange -10,10%yrange -10,10%jsplot blue,sin(x^2)%jsmath sin(x^2) |
11806 | schaersvoo | 2271 | */ |
2272 | if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;} |
||
2273 | if( use_js_math == FALSE){ |
||
2274 | add_to_js_math(js_include_file); |
||
2275 | use_js_math = TRUE; |
||
2276 | } |
||
2277 | add_calc_y(js_include_file,canvas_root_id,get_string(infile,1),font_size,input_style); |
||
2278 | break; |
||
2279 | case KILLAFFINE: |
||
2280 | /* |
||
2281 | @ killaffine |
||
14066 | bpr | 2282 | @ keyword: resets the transformation matrix to 1,0,0,1,0,0 |
11806 | schaersvoo | 2283 | */ |
2284 | use_affine = FALSE; |
||
2285 | snprintf(affine_matrix,14,"[1,0,0,1,0,0]"); |
||
2286 | break; |
||
2287 | |||
2288 | case KILLROTATE: |
||
2289 | /* |
||
14071 | bpr | 2290 | @ killrotate |
2291 | @ will reset the command <a href="#rotationcenter">rotationcenter xc,yc</a> |
||
11806 | schaersvoo | 2292 | @ a following rotate command will have the first object point as rotation center |
2293 | @ if not set, the rotation center will remain unchanged |
||
2294 | */ |
||
2295 | rotation_center= my_newmem(6); |
||
2296 | snprintf(rotation_center,5,"null"); |
||
2297 | break; |
||
2298 | |||
2299 | case KILLSLIDER: |
||
2300 | /* |
||
2301 | @ killslider |
||
2302 | @ keyword (no arguments required) |
||
2303 | @ ends grouping of object under a previously defined slider |
||
2304 | */ |
||
2305 | slider = 0; |
||
2306 | break; |
||
2307 | |||
2308 | case KILLTRANSLATION: |
||
2309 | /* |
||
2310 | @ killtranslation |
||
14071 | bpr | 2311 | @ alternative: <code>killtranslate</code> |
11806 | schaersvoo | 2312 | @ resets the translation matrix to 1,0,0,1,0,0 |
2313 | */ |
||
2314 | use_affine = FALSE; |
||
2315 | snprintf(affine_matrix,14,"[1,0,0,1,0,0]"); |
||
2316 | break; |
||
2317 | |||
2318 | case LINE: |
||
2319 | /* |
||
2320 | @ line x1,y1,x2,y2,color |
||
2321 | @ draw a line through points (x1:y1)--(x2:y2) in color 'color' |
||
14071 | bpr | 2322 | @ or use command ''curve color,formula`` to draw the line <br />(uses more points to draw the line; is however better draggable) |
9406 | schaersvoo | 2323 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
12107 | schaersvoo | 2324 | @%line%size 400,400%xrange -10,10%yrange -10,10%line 0,1,2,-1,green |
7614 | schaersvoo | 2325 | */ |
8386 | schaersvoo | 2326 | for(i=0;i<5;i++){ |
7614 | schaersvoo | 2327 | switch(i){ |
11806 | schaersvoo | 2328 | case 0: double_data[10]= get_real(infile,0);break; /* x-values */ |
2329 | case 1: double_data[11]= get_real(infile,0);break; /* y-values */ |
||
2330 | case 2: double_data[12]= get_real(infile,0);break; /* x-values */ |
||
2331 | case 3: double_data[13]= get_real(infile,0);break; /* y-values */ |
||
2332 | case 4: stroke_color=get_color(infile,1);/* name or hex color */ |
||
2333 | if( double_data[10] == double_data[12] ){ /* vertical line*/ |
||
2334 | double_data[1] = xmin; |
||
2335 | double_data[3] = ymax; |
||
2336 | double_data[0] = double_data[10]; |
||
2337 | double_data[2] = double_data[10]; |
||
2338 | } |
||
2339 | else |
||
2340 | { |
||
2341 | if( double_data[11] == double_data[13] ){ /* horizontal line */ |
||
2342 | double_data[1] = double_data[11]; |
||
2343 | double_data[3] = double_data[11]; |
||
2344 | double_data[0] = ymin; |
||
2345 | double_data[2] = xmax; |
||
2346 | } |
||
2347 | else |
||
2348 | { |
||
2349 | /* m */ |
||
2350 | double_data[5] = (double_data[13] - double_data[11]) /(double_data[12] - double_data[10]); |
||
2351 | /* q */ |
||
2352 | double_data[6] = double_data[11] - ((double_data[13] - double_data[11]) /(double_data[12] - double_data[10]))*double_data[10]; |
||
2353 | |||
2354 | /*xmin,m*xmin+q,xmax,m*xmax+q*/ |
||
2355 | |||
2356 | double_data[1] = (double_data[5])*(xmin)+(double_data[6]); |
||
2357 | double_data[3] = (double_data[5])*(xmax)+(double_data[6]); |
||
2358 | double_data[0] = xmin; |
||
2359 | double_data[2] = xmax; |
||
2360 | } |
||
2361 | } |
||
2362 | decimals = find_number_of_digits(precision); |
||
14045 | schaersvoo | 2363 | fprintf(js_include_file,"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\",%d,%s,%d,%d,%s,%d,%d));\n",drag_type,click_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,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern); |
11806 | schaersvoo | 2364 | if(onclick > 0){click_cnt++;} |
2365 | /* click_cnt++;*/ |
||
2366 | reset(); |
||
2367 | break; |
||
7614 | schaersvoo | 2368 | } |
2369 | } |
||
2370 | break; |
||
8386 | schaersvoo | 2371 | |
11806 | schaersvoo | 2372 | case LINES: |
8370 | schaersvoo | 2373 | /* |
11806 | schaersvoo | 2374 | @ lines color,x1,y1,x2,y2...x_n-1,y_n-1,x_n,y_n |
2375 | @ draw multiple lines through points (x1:y1)--(x2:y2) ...(x_n-1:y_n-1)--(x_n:y_n) in color 'color' |
||
14071 | bpr | 2376 | @ 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 | 2377 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
14071 | bpr | 2378 | @ <b>attention</b>: the flydraw command ''lines`` is equivalent to canvasdraw command <a href="#polyline">polyline</a> |
12107 | schaersvoo | 2379 | @%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 | 2380 | */ |
2381 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
2382 | fill_color = stroke_color; |
||
2383 | i=0; |
||
2384 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 2385 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
8370 | schaersvoo | 2386 | if(i%2 == 0 ){ |
2387 | double_data[i] = get_real(infile,0); /* x */ |
||
2388 | } |
||
2389 | else |
||
2390 | { |
||
2391 | double_data[i] = get_real(infile,1); /* y */ |
||
2392 | } |
||
2393 | i++; |
||
2394 | } |
||
2395 | decimals = find_number_of_digits(precision); |
||
2396 | for(c = 0 ; c < i-1 ; c = c+4){ |
||
11806 | schaersvoo | 2397 | if( double_data[c] == double_data[c+2] ){ /* vertical line*/ |
2398 | double_data[c+1] = xmin; |
||
2399 | double_data[c+3] = ymax; |
||
2400 | double_data[c+2] = double_data[c]; |
||
2401 | } |
||
2402 | else |
||
2403 | { |
||
2404 | if( double_data[c+1] == double_data[c+3] ){ /* horizontal line */ |
||
2405 | double_data[c+3] = double_data[c+1]; |
||
2406 | double_data[c] = ymin; |
||
2407 | double_data[c+2] = xmax; |
||
2408 | } |
||
2409 | else |
||
2410 | { |
||
2411 | /* m */ |
||
2412 | double m = (double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]); |
||
2413 | /* q */ |
||
2414 | double q = double_data[c+1] - ((double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]))*double_data[c]; |
||
2415 | /*xmin,m*xmin+q,xmax,m*xmax+q*/ |
||
2416 | double_data[c+1] = (m)*(xmin)+(q); |
||
2417 | double_data[c+3] = (m)*(xmax)+(q); |
||
2418 | double_data[c] = xmin; |
||
2419 | double_data[c+2] = xmax; |
||
2420 | } |
||
2421 | } |
||
14045 | schaersvoo | 2422 | fprintf(js_include_file,"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\",%d,%s,%d,%d,%s,%d,%d));\n",drag_type,click_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,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern); |
8379 | schaersvoo | 2423 | if(onclick > 0){click_cnt++;} |
2424 | /* click_cnt++; */ |
||
8370 | schaersvoo | 2425 | } |
2426 | reset(); |
||
2427 | break; |
||
8386 | schaersvoo | 2428 | |
11806 | schaersvoo | 2429 | |
2430 | case LINEWIDTH: |
||
7614 | schaersvoo | 2431 | /* |
11806 | schaersvoo | 2432 | @ linewidth int |
2433 | @ default 1 |
||
12107 | schaersvoo | 2434 | @%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 | 2435 | */ |
11806 | schaersvoo | 2436 | line_width = (int) (get_real(infile,1)); |
2437 | break; |
||
2438 | |||
2439 | case LATTICE: |
||
2440 | /* |
||
2441 | @ lattice x0,y0,xv1,yv1,xv2,yv2,n1,n2,color |
||
14086 | bpr | 2442 | @ can <b>not</b> be set ''onclick`` or ''drag xy`` |
12107 | schaersvoo | 2443 | @%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 |
11806 | schaersvoo | 2444 | */ |
2445 | if( js_function[DRAW_LATTICE] != 1 ){ js_function[DRAW_LATTICE] = 1;} |
||
2446 | for( i = 0; i<9; i++){ |
||
7614 | schaersvoo | 2447 | switch(i){ |
14032 | schaersvoo | 2448 | case 0: int_data[0] = x2px(get_real(infile,0));break; /* x0-values -> x-pixels*/ |
2449 | case 1: int_data[1] = y2px(get_real(infile,0));break; /* y0-values -> y-pixels*/ |
||
2450 | case 2: int_data[2] = (int) (get_real(infile,0));break; /* x1-values -> x-pixels*/ |
||
2451 | case 3: int_data[3] = (int) -1*(get_real(infile,0));break; /* y1-values -> y-pixels*/ |
||
2452 | case 4: int_data[4] = (int) (get_real(infile,0));break; /* x2-values -> x-pixels*/ |
||
2453 | case 5: int_data[5] = (int) -1*(get_real(infile,0));break; /* y2-values -> y-pixels*/ |
||
11806 | schaersvoo | 2454 | case 6: int_data[6] = (int) (get_real(infile,0));break; /* n1-values */ |
2455 | case 7: int_data[7] = (int) (get_real(infile,0));break; /* n2-values */ |
||
2456 | case 8: stroke_color=get_color(infile,1); |
||
7614 | schaersvoo | 2457 | decimals = find_number_of_digits(precision); |
11996 | schaersvoo | 2458 | string_length = snprintf(NULL,0,"draw_lattice(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%.2f,%d,%s,%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_affine,affine_matrix,use_filled); |
11806 | schaersvoo | 2459 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
11996 | schaersvoo | 2460 | snprintf(tmp_buffer,string_length,"draw_lattice(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%.2f,%d,%s,%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_affine,affine_matrix,use_filled); |
11806 | schaersvoo | 2461 | add_to_buffer(tmp_buffer);break; |
2462 | default:break; |
||
7614 | schaersvoo | 2463 | } |
2464 | } |
||
11806 | schaersvoo | 2465 | reset(); |
7614 | schaersvoo | 2466 | break; |
8363 | schaersvoo | 2467 | |
11806 | schaersvoo | 2468 | case LEVELCURVE: |
8363 | schaersvoo | 2469 | /* |
11806 | schaersvoo | 2470 | @ levelcurve color,expression in x/y,l1,l2,... |
2471 | @ draws very primitive level curves for expression, with levels l1,l2,l3,...,l_n |
||
2472 | @ the quality is <b>not to be compared</b> with the Flydraw levelcurve. <br />(choose flydraw if you want quality...) |
||
2473 | @ 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 |
||
14066 | bpr | 2474 | @ note: the arrays for holding the javascript data are limited in size |
2475 | @ 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 | 2476 | @%levelcurve%size 400,400%xrange -10,10%yrange -10,10%levelcurve red,x*y,1,2,3,4 |
8363 | schaersvoo | 2477 | */ |
11806 | schaersvoo | 2478 | fill_color = get_color(infile,0); |
2479 | char *fun1 = get_string_argument(infile,0); |
||
2480 | if( strlen(fun1) == 0 ){canvas_error("function is NOT OK !");} |
||
2481 | i = 0; |
||
2482 | done = FALSE; |
||
2483 | while( !done ){ |
||
2484 | double_data[i] = get_real(infile,1); |
||
2485 | i++; |
||
2486 | } |
||
2487 | for(c = 0 ; c < i; c++){ |
||
14045 | schaersvoo | 2488 | fprintf(js_include_file,"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\",%d,%s,%d,%d,%s,%d,%d));\n",drag_type,click_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,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern); |
11806 | schaersvoo | 2489 | if(onclick > 0){click_cnt++;} |
2490 | /* click_cnt++; */ |
||
2491 | } |
||
2492 | reset(); |
||
2493 | break; |
||
8386 | schaersvoo | 2494 | |
11806 | schaersvoo | 2495 | case LEGEND: |
2496 | /* |
||
2497 | @ legend string1:string2:string3....string_n |
||
2498 | @ will be used to create a legend for a graph |
||
14066 | bpr | 2499 | @ also see command <a href='#piechart'>piechart</a> |
14071 | bpr | 2500 | @ will use the same colors per default as used in the graphs; use command <a href='#legendcolors'>legendcolors</a> to override the default |
14086 | bpr | 2501 | @ use command <a href="#fontsize">fontsize</a> to adjust. (command ''fontfamily`` is not active for command ''legend``) |
14066 | bpr | 2502 | @%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 | 2503 | */ |
2504 | temp = get_string(infile,1); |
||
2505 | if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); } |
||
14066 | bpr | 2506 | legend_cnt++; /* attention: starts with -1: it will be used in piechart etc */ |
11806 | schaersvoo | 2507 | fprintf(js_include_file,"var legend%d = [\"%s\"];",legend_cnt,temp); |
2508 | break; |
||
2509 | |||
2510 | case LEGENDCOLORS: |
||
2511 | /* |
||
2512 | @ legendcolors color1:color2:color3:...:color_n |
||
2513 | @ will be used to colour a legend: use this command after the legend command ! e.g.<br />legend test1:test2:test3<br />legendcolors blue:red:orange |
||
2514 | @ make sure the number of colours match the number of legend items |
||
2515 | @ command 'legend' in case of 'piechart' and 'barchart' will use these colours per default (no need to specify 'legendcolors' |
||
13960 | bpr | 2516 | @%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 | 2517 | */ |
2518 | if(legend_cnt == -1){canvas_error("use command \"legend\" before command \"legendcolors\" ! ");} |
||
2519 | temp = get_string(infile,1); |
||
2520 | if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); } |
||
2521 | fprintf(js_include_file,"var legendcolors%d = [\"%s\"];",legend_cnt,temp); |
||
2522 | break; |
||
2523 | |||
14078 | bpr | 2524 | case LINEGRAPH: /* scheme: var linegraph_0 = [ 'stroke_color','line_width','use_dashed', 'dashtype0','dashtype1','x1','y1',...,'x_n','y_n'];*/ |
11806 | schaersvoo | 2525 | /* |
2526 | @ linegraph x1:y1:x2:y2...x_n:y_n |
||
2527 | @ will plot your data in a graph |
||
14066 | bpr | 2528 | @ may <b>only</b> to be used together with command <a href='#grid'>grid</a> |
2529 | @ 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> |
||
2530 | @ use command <a href='#legend'>legend</a> to provide an optional legend in right-top-corner |
||
2531 | @ also see command <a href='#piechart'>piechart</a> |
||
11806 | schaersvoo | 2532 | @ multiple linegraphs may be used in a single plot |
14066 | bpr | 2533 | @ note: your arguments are not checked by canvasdraw: use your javascript console in case of trouble... |
2534 | @ <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 | 2535 | @%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 | 2536 | */ |
2537 | temp = get_string(infile,1); |
||
2538 | if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); } |
||
2539 | 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); |
||
2540 | linegraph_cnt++; |
||
2541 | reset(); |
||
2542 | break; |
||
2543 | |||
2544 | case MATHML: |
||
2545 | /* |
||
2546 | @ mathml x1,y1,x2,y2,mathml_string |
||
14038 | schaersvoo | 2547 | @ the mathml object is centered at (x1:y1) |
13952 | schaersvoo | 2548 | @ the 'mathml_string' can be produced using WIMS commands like 'texmath' followed by 'mathmlmath'... or write correct TeX and use only 'mathmlmath' |
13829 | bpr | 2549 | @ mathml will be displayed in a rectangle left top (x1:y1)...<br />x2 and y2 are still needed, but not used as the right bottom corner of the embedded div element. |
11806 | schaersvoo | 2550 | @ in case of drag(xy|x|y) | onclick the div rectangle left to corner will be the drag-anchor of the mathml object |
13988 | bpr | 2551 | @ can be set onclick <br />javascript:read_dragdrop(); 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 |
11806 | schaersvoo | 2552 | @ can be set draggable<br /> the javascript:read_dragdrop() will return all coordinates <br />in same order as the canvas script: unmoved object will have their original coordinates... |
2553 | @ 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 |
||
14066 | bpr | 2554 | @ 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 |
11806 | schaersvoo | 2555 | @ userdraw may be combined with 'mathml' ; the read_canvas() will contain the drawing. |
2556 | @ 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 | 2557 | @ other drag objects (circles/rects etc) are supported, but read_dragdrop() will probably be difficult to interpret... |
14066 | bpr | 2558 | @ 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 | 2559 | @ 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 | 2560 | @ use keyword <a href='#centered'>centered</a> to center the mathml/xml object on (x1:y1) |
13829 | bpr | 2561 | @%mathml_onclick%size 400,400%xrange -10,10%yrange -10,10%onclick%strokecolor red%mathml -5,5,0,0,<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,0,0,<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> |
13952 | schaersvoo | 2562 | @%mathml_drag%size 400,400%xrange -10,10%yrange -10,10%drag xy%strokecolor red%mathml -5,5,0,0,<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,0,0,<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 | 2563 | */ |
14062 | schaersvoo | 2564 | if(use_offset == 0){use_offset = 4;} /* always centered if not otherwise stated ! */ |
11806 | schaersvoo | 2565 | if( js_function[DRAW_XML] != 1 ){ js_function[DRAW_XML] = 1;} |
2566 | for(i=0;i<5;i++){ |
||
2567 | switch(i){ |
||
2568 | case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */ |
||
14032 | schaersvoo | 2569 | case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system -> pixel height */ |
14066 | bpr | 2570 | case 2: int_data[2]=x2px(get_real(infile,0));break;/* no more width needed: overflow */ |
2571 | case 3: int_data[3]=y2px(get_real(infile,0));break;/* no more height needed: overflow */ |
||
11806 | schaersvoo | 2572 | case 4: decimals = find_number_of_digits(precision); |
2573 | temp = get_string(infile,1); |
||
2574 | if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'"); } |
||
14044 | schaersvoo | 2575 | string_length = snprintf(NULL,0,"draw_xml(%d,%d,%d,\"%s\",%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d);\n",canvas_root_id,int_data[0],int_data[1],temp,drag_type,onclick,click_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,use_offset,use_snap); |
11806 | schaersvoo | 2576 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
14044 | schaersvoo | 2577 | snprintf(tmp_buffer,string_length,"draw_xml(%d,%d,%d,\"%s\",%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d);\n",canvas_root_id,int_data[0],int_data[1],temp,drag_type,onclick,click_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,use_offset,use_snap); |
11806 | schaersvoo | 2578 | add_to_buffer(tmp_buffer); |
2579 | if(onclick == 1 || onclick == 2 ){click_cnt++;} |
||
14038 | schaersvoo | 2580 | use_offset=0; |
11806 | schaersvoo | 2581 | /* |
14078 | bpr | 2582 | in case inputs are present, trigger adding the read_mathml() |
11806 | schaersvoo | 2583 | if no other reply_format is defined |
2584 | note: all other reply types will include a reading of elements with id='mathml'+p) |
||
2585 | */ |
||
2586 | if(strstr(temp,"mathml0") != NULL){ |
||
2587 | if(reply_format == 0 ){reply_format = 16;} /* no other reply type is defined */ |
||
2588 | } |
||
2589 | break; |
||
2590 | default:break; |
||
2591 | } |
||
2592 | } |
||
2593 | break; |
||
2594 | |||
2595 | case MOUSE: |
||
2596 | /* |
||
2597 | @ mouse color,fontsize |
||
2598 | @ will display the cursor (x:y) coordinates in 'color' and 'font size'<br /> using default fontfamily Ariel |
||
2599 | @ note: use command 'mouse' at the end of your script code (the same is true for command 'zoom') |
||
12107 | schaersvoo | 2600 | @%mouse%size 400,400%xrange -10,10%yrange -10,10%mouse red,22 |
11806 | schaersvoo | 2601 | */ |
2602 | stroke_color = get_color(infile,0); |
||
2603 | font_size = (int) (get_real(infile,1)); |
||
2604 | tmp_buffer = my_newmem(26); |
||
13371 | schaersvoo | 2605 | snprintf(tmp_buffer,26,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer); |
11806 | schaersvoo | 2606 | add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,2); |
2607 | break; |
||
2608 | |||
2609 | |||
2610 | case MOUSE_DEGREE: |
||
2611 | /* |
||
2612 | @ mouse_degree color,fontsize |
||
2613 | @ 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 Ariel |
||
2614 | @ The angle is positive in QI and QIII and the angle value is negative in QII and QIV |
||
2615 | @ note: use command 'mouse' at the end of your script code (the same is true for command 'zoom') |
||
12107 | schaersvoo | 2616 | @%mouse_degree%size 400,400%xrange -10,10%yrange -10,10%userdraw arc,blue%precision 100000%mouse_degree red,22 |
11806 | schaersvoo | 2617 | */ |
2618 | stroke_color = get_color(infile,0); |
||
2619 | font_size = (int) (get_real(infile,1)); |
||
2620 | tmp_buffer = my_newmem(26); |
||
13371 | schaersvoo | 2621 | snprintf(tmp_buffer,26,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer); |
11806 | schaersvoo | 2622 | add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,3); |
2623 | js_function[JS_FIND_ANGLE] = 1; |
||
2624 | break; |
||
2625 | case MOUSE_DISPLAY: |
||
2626 | /* |
||
2627 | @ display TYPE,color,fontsize |
||
2628 | @ TYPE may be x | y | xy | degree | radian | radius |
||
14086 | bpr | 2629 | @ will display the mouse cursor coordinates as x-only,y-only,(x:y),<br />the radius of a circle (this only in case 'userdraw circle(s),color')<br />or the angle in degrees or radians for commands <code>userdraw arc,color</code> or protractor, ruler (if set dynamic) |
11806 | schaersvoo | 2630 | @ use commands 'xunit' and / or 'yunit' to add the units to the mouse values.<br />The "degree | radian" will always have the appropriate symbol) |
14077 | bpr | 2631 | @ just like commands ''mouse``, ''mousex``, ''mousey``, ''mouse_degree``... only other name |
12111 | schaersvoo | 2632 | @%display_x%size 400,400%xrange -10,10%yrange -10,10%xunit \\u212B%display x,red,22 |
12107 | schaersvoo | 2633 | @%display_y%size 400,400%xrange -10,10%yrange -10,10%yunit seconds%display y,red,22 |
13936 | bpr | 2634 | @%display_xy%size 400,400%xrange -10,10%yrange -10,10%xunit centimetre%yunit seconds%display xy,red,22%userdraw segments,blue |
12107 | schaersvoo | 2635 | @%display_deg%size 400,400%xrange -10,10%yrange -10,10%display degree,red,22%fillcolor orange%opacity 200,50%userdraw arc,blue |
2636 | @%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 | 2637 | @%display_radius%size 400,400%xrange -10,10%yrange -10,10%xunit cm%xunit \\u212b%display radius,red,22%userdraw circle,blue |
11806 | schaersvoo | 2638 | */ |
2639 | temp = get_string_argument(infile,0); |
||
2640 | if( strstr(temp,"xy") != NULL ){ |
||
2641 | int_data[0] = 2; |
||
2642 | }else{ |
||
2643 | if( strstr(temp,"y") != NULL ){ |
||
2644 | int_data[0] = 1; |
||
2645 | }else{ |
||
2646 | if( strstr(temp,"x") != NULL ){ |
||
2647 | int_data[0] = 0; |
||
2648 | }else{ |
||
2649 | if(strstr(temp,"degree") != NULL){ |
||
2650 | int_data[0] = 3; |
||
2651 | js_function[JS_FIND_ANGLE] = 1; |
||
2652 | }else{ |
||
2653 | if(strstr(temp,"radian") != NULL){ |
||
2654 | int_data[0] = 4; |
||
2655 | js_function[JS_FIND_ANGLE] = 1; |
||
2656 | }else{ |
||
2657 | if(strstr(temp,"radius") != NULL){ |
||
2658 | int_data[0] = 5; |
||
2659 | }else{ |
||
2660 | int_data[0] = 2; |
||
2661 | } |
||
2662 | } |
||
2663 | } |
||
2664 | } |
||
2665 | } |
||
2666 | } |
||
2667 | stroke_color = get_color(infile,0); |
||
2668 | font_size = (int) (get_real(infile,1)); |
||
2669 | tmp_buffer = my_newmem(26); |
||
13371 | schaersvoo | 2670 | snprintf(tmp_buffer,26,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer); |
11806 | schaersvoo | 2671 | add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,int_data[0]); |
2672 | break; |
||
2673 | |||
2674 | case MOUSE_PRECISION: |
||
2675 | /* |
||
2676 | @ precision int |
||
2677 | @ 1 = no decimals ; 10 = 1 decimal ; 100 = 2 decimals etc |
||
2678 | @ may be used / changed before every object |
||
14077 | bpr | 2679 | @ 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 | 2680 | @%precision%size 400,400%xrange -10,10%yrange -10,10%precision 1%userdraw segment,red |
11806 | schaersvoo | 2681 | */ |
2682 | precision = (int) (get_real(infile,1)); |
||
2683 | if(precision < 1 ){precision = 1;}; |
||
2684 | break; |
||
2685 | |||
2686 | case MOUSEX: |
||
2687 | /* |
||
2688 | @ mousex color,fontsize |
||
14077 | bpr | 2689 | @ will display the cursor x-coordinate in ''color`` and ''font size``<br /> using the fontfamily Ariel |
2690 | @ note: use command ''mouse`` at the end of your script code (the same is true for command ''zoom``) |
||
11806 | schaersvoo | 2691 | |
2692 | */ |
||
2693 | stroke_color = get_color(infile,0); |
||
2694 | font_size = (int) (get_real(infile,1)); |
||
2695 | tmp_buffer = my_newmem(26); |
||
13371 | schaersvoo | 2696 | snprintf(tmp_buffer,26,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer); |
11806 | schaersvoo | 2697 | add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,0); |
2698 | break; |
||
2699 | case MOUSEY: |
||
2700 | /* |
||
2701 | @ mousey color,fontsize |
||
14077 | bpr | 2702 | @ will display the cursor y-coordinate in ''color`` and ''font size`` using default fontfamily Ariel |
2703 | @ note: use command ''mouse`` at the end of your script code (the same is true for command ''zoom``) |
||
11806 | schaersvoo | 2704 | |
2705 | */ |
||
2706 | stroke_color = get_color(infile,0); |
||
2707 | font_size = (int) (get_real(infile,1)); |
||
2708 | tmp_buffer = my_newmem(26); |
||
13371 | schaersvoo | 2709 | snprintf(tmp_buffer,26,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer); |
11806 | schaersvoo | 2710 | add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,1); |
2711 | break; |
||
2712 | |||
2713 | case MULTIDASH: |
||
2714 | /* |
||
2715 | @ multidash 0,1,1 |
||
14071 | bpr | 2716 | @ 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 | 2717 | @ use before command <a href='#multidraw'>multidraw</a> |
14077 | bpr | 2718 | @ if not set all objects will be set ''not dashed``...<br />unless a generic keyword ''dashed`` was given before command ''multidraw`` |
14071 | bpr | 2719 | @ 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 | 2720 | @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives... |
14077 | bpr | 2721 | @ always use the same sequence as is used for ''multidraw`` |
11806 | schaersvoo | 2722 | */ |
2723 | if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
||
2724 | temp = get_string(infile,1); |
||
2725 | temp = str_replace(temp,",","\",\""); |
||
2726 | fprintf(js_include_file,"var multidash = [\"%s\"];",temp); |
||
2727 | reset();/* if command 'dashed' was given...reset to not-dashed */ |
||
2728 | break; |
||
2729 | |||
2730 | case MULTIDRAW: |
||
2731 | /* |
||
2732 | @ multidraw obj_type_1,obj_type_2...obj_type_11 |
||
14066 | bpr | 2733 | @ for simple single object user drawings you could also use command <a href="#userdraw">userdraw</a> |
14077 | bpr | 2734 | @ implemented obj_types:<ul><li>point | points </li><li>circle | circles </li><li>line | lines </li><li>segment | segments </li><li>arrow | arrows <br />use command 'arrowhead int' for size (default value 8 pixels)</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)<br />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></ul> |
2735 | @ 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 |
||
14086 | bpr | 2736 | @ 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... |
13948 | schaersvoo | 2737 | @ 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) |
14078 | bpr | 2738 | @ 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 'inputstyle some_css' |
2739 | @ 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 | 2740 | @ a right mouse button click will remove the last drawn object of the selected drawing type. All other type of objects are not removed |
14071 | bpr | 2741 | @ multidraw is incompatible with command ''tooltip`` (the reserved div_area is used for the multidraw control buttons) |
2742 | @ all ''multidraw`` drawings will scale on zooming.<br />this in contrast to the command <a href="#userdraw">userdraw</a>. |
||
11806 | schaersvoo | 2743 | @ wims will <b>not</b> check the amount or validity of your command arguments ! <br />( use javascript console to debug any typo's ) |
14077 | bpr | 2744 | @ a local function read_canvas%d 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+";"+circlespoint_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_idline 13 = curvedarrows_x +";"+ curved_arrows_y +"\\n"<br />line 14 = curvedarrows2_x +";"+ curved_arrows_y +"\\n"<br />line 15 = userdraw_x +";"+userdraw_y + "\\n" note: this is for single 'userdraw object,color' and 'replyformat 29'<br/>line 16 = 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> |
11806 | schaersvoo | 2745 | @ 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 /> |
2746 | @ <b>attention</b>: for command argument 'closedpoly' only one polygone can be drawn.<br />The last point (e.g. the point clicked near the first point) of the array is removed. |
||
14071 | bpr | 2747 | @ 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)<br />This in contrast too many very slow do-it-all HTML5 canvas javascript libraries.<br />The mouselisteners are attached to the canvas-div element. |
14086 | bpr | 2748 | @ 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 (<img> tag with bitmap or SVG) 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,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 |
14071 | bpr | 2749 | @ 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 (makeing typo's 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 />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_click_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" |
12107 | schaersvoo | 2750 | @%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 |
14038 | schaersvoo | 2751 | @%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 Ariel%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%inputstyle 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 |
14044 | schaersvoo | 2752 | @%multidraw_demo%size 800,800%xrange -10,10%yrange -10,10%axis%axisnumbering%precision 1%grid 2,2,grey,2,2,5,grey%inputstyle color:blue;%fontfamily Italic 42pt Ariel%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 |
14063 | schaersvoo | 2753 | @%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 | 2754 | */ |
14038 | schaersvoo | 2755 | if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
11806 | schaersvoo | 2756 | if( use_userdraw == TRUE ){canvas_error("Only one userdraw primitive may be used in command 'userdraw' use command 'multidraw' for this...");} |
2757 | use_userdraw = TRUE; |
||
2758 | /* LET OP max 6 DRAW PRIMITIVES + TEXT */ |
||
2759 | temp = get_string(infile,1); |
||
2760 | temp = str_replace(temp,",","\",\""); |
||
14044 | schaersvoo | 2761 | /* if these are not set, set the default values for the 18 (more than enough !) draw_primitives + draw_text */ |
14066 | bpr | 2762 | /* int use_snap = 0; 0 = none 1=grid: 2=x-grid: 3=y-grid: 4=snap to points */ |
14044 | schaersvoo | 2763 | |
11806 | schaersvoo | 2764 | fprintf(js_include_file,"\ |
14044 | schaersvoo | 2765 | if( typeof(multisnaptogrid) == 'undefined' && multisnaptogrid == null){var multisnaptogrid = ['%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d'];}\ |
14038 | schaersvoo | 2766 | if( typeof(multistrokecolors) === 'undefined' && multistrokecolors == null ){ var multistrokecolors = ['%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s'];};\ |
2767 | if( typeof(multifillcolors) === 'undefined' && multifillcolors == null ){ var multifillcolors = ['%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s'];};\ |
||
2768 | if( typeof(multistrokeopacity) === 'undefined' && multistrokeopacity == null ){ var multistrokeopacity = ['%.2f','%.2f','%.2f','%.2f','%.2f','%.2f','%2.f','%2.f','%2.f','%.2f','%.2f','%.2f','%.2f','%.2f','%.2f','%2.f','%2.f','%2.f'];};\ |
||
2769 | if( typeof(multifillopacity) === 'undefined' && multifillopacity == null ){ var multifillopacity = ['%.2f','%.2f','%.2f','%.2f','%.2f','%.2f','%2.f','%2.f','%2.f','%.2f','%.2f','%.2f','%.2f','%.2f','%.2f','%2.f','%2.f','%2.f'];};\ |
||
2770 | if( typeof(multilinewidth) === 'undefined' && multilinewidth == null ){ var multilinewidth = ['%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d'];};\ |
||
2771 | if( typeof(multifill) === 'undefined' && multifill == null ){ var multifill = ['%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d'];};\ |
||
2772 | if( typeof(multidash) === 'undefined' && multidash == null ){ var multidash = ['%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d'];};\ |
||
11806 | schaersvoo | 2773 | if( typeof(multilabel) === 'undefined' && multilabel == null ){ var multilabel = [\"%s\",\"stop drawing\"];};\ |
14044 | schaersvoo | 2774 | if( typeof(multiuserinput) === 'undefined' && multiuserinput == null ){ var multiuserinput = ['0','0','0','0','0','0','0','0'];};\ |
11806 | schaersvoo | 2775 | var arrow_head = %d;var multifont_color = '%s';var multifont_family = '%s';", |
14044 | schaersvoo | 2776 | use_snap,use_snap,use_snap,use_snap,use_snap,use_snap,use_snap,use_snap,use_snap,use_snap,use_snap,use_snap,use_snap,use_snap,use_snap,use_snap,use_snap,use_snap, |
14038 | schaersvoo | 2777 | stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color, |
2778 | fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color, |
||
2779 | stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity, |
||
2780 | fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity, |
||
2781 | line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width, |
||
2782 | use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled, |
||
2783 | use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed, |
||
11806 | schaersvoo | 2784 | temp,arrow_head,font_color,font_family); |
2785 | |||
2786 | if(strstr(temp,"text") != NULL){ |
||
2787 | if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */ |
||
2788 | } |
||
2789 | |||
2790 | /* the canvasses range from 1000 ... 1008 */ |
||
14038 | schaersvoo | 2791 | add_js_multidraw(js_include_file,canvas_root_id,temp,input_style,use_offset); |
11806 | schaersvoo | 2792 | reply_precision = precision; |
2793 | if( reply_format == 0){reply_format = 29;} |
||
2794 | reset();/* if command 'filled' / 'dashed' was given...reset all */ |
||
2795 | break; |
||
2796 | case MULTILABEL: |
||
2797 | /* |
||
2798 | @ multilabel button_label_1,button_label_2,...,button_label_8,'stop drawing text' |
||
14066 | bpr | 2799 | @ use before command <a href='#multidraw'>multidraw</a> |
14071 | bpr | 2800 | @ 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'...) |
2801 | @ 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> |
||
2802 | @ all buttons can be ''styled`` by using command <code>inputstyle</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`` |
||
11806 | schaersvoo | 2803 | @ wims will not check the amount or validity of your input |
14071 | bpr | 2804 | @ always use the same sequence as is used for ''multidraw`` |
2805 | @ if you don't want the controls, and want to write your own interface, set <code>multilabel NOCONTROLS</code> |
||
11806 | schaersvoo | 2806 | */ |
2807 | if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
||
2808 | temp = get_string(infile,1); |
||
2809 | temp = str_replace(temp,",","\",\""); |
||
2810 | fprintf(js_include_file,"var multilabel = [\"%s\"];",temp); |
||
2811 | break; |
||
2812 | case MULTILINEWIDTH: |
||
2813 | /* |
||
2814 | @ multilinewidth linewidth_1,linewidth_2,...,linewidth_8 |
||
14066 | bpr | 2815 | @ use before command <a href='#multidraw'>multidraw</a> |
14071 | bpr | 2816 | @ if not set all line widths will be set by a previous command ''linewidth int`` |
2817 | @ 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 | 2818 | @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives... |
14071 | bpr | 2819 | @ always use the same sequence as is used for ''multidraw`` |
11806 | schaersvoo | 2820 | */ |
2821 | if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
||
2822 | temp = get_string(infile,1); |
||
2823 | temp = str_replace(temp,",","\",\""); |
||
2824 | fprintf(js_include_file,"var multilinewidth = [\"%s\"];",temp); |
||
2825 | break; |
||
2826 | case MULTIFILL: |
||
2827 | /* |
||
2828 | @ multifill 0,0,1,0,1,0,0 |
||
14071 | bpr | 2829 | @ 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...) |
14066 | bpr | 2830 | @ use before command <a href='#multidraw'>multidraw</a> |
14071 | bpr | 2831 | @ 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> |
14078 | bpr | 2832 | @ only suitable for draw_primitives like ''circle | circles``, ''triangle | triangles`` and ''polygon`` |
11806 | schaersvoo | 2833 | @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives... |
14071 | bpr | 2834 | @ always use the same sequence as is used for ''multidraw`` |
11806 | schaersvoo | 2835 | */ |
2836 | if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
||
2837 | temp = get_string(infile,1); |
||
2838 | temp = str_replace(temp,",","\",\""); |
||
2839 | fprintf(js_include_file,"var multifill = [\"%s\"];",temp); |
||
2840 | break; |
||
2841 | |||
2842 | case MULTIFILLCOLORS: |
||
2843 | /* |
||
2844 | @ multifillcolors color_name_1,color_name_2,...,color_name_8 |
||
14066 | bpr | 2845 | @ use before command <a href='#multidraw'>multidraw</a> |
14078 | bpr | 2846 | @ if not set all fillcolors (for circle | triangle | poly[3-9] | closedpoly ) will be ''stroke_color``, ''fill_opacity`` |
14071 | bpr | 2847 | @ 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 | 2848 | @ wims will <b>not</b> check if the number of colours matches the amount of draw primitives... |
14071 | bpr | 2849 | @ always use the same sequence as is used for ''multidraw' |
14078 | bpr | 2850 | @ 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 | 2851 | */ |
2852 | if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
||
2853 | fprintf(js_include_file,"var multifillcolors = ["); |
||
2854 | while( ! done ){ |
||
2855 | temp = get_color(infile,1); |
||
2856 | fprintf(js_include_file,"\"%s\",",temp); |
||
2857 | } |
||
2858 | fprintf(js_include_file,"\"0,0,0\"];");/* add black to avoid trouble with dangling comma... */ |
||
2859 | break; |
||
2860 | |||
2861 | case MULTIFILLOPACITY: |
||
2862 | /* |
||
2863 | @ multifillopacity fill_opacity_1,fill_opacity_2,...,fill_opacity_8 |
||
2864 | @ float values 0 - 1 or integer values 0 - 255 |
||
14066 | bpr | 2865 | @ use before command <a href='#multidraw'>multidraw</a> |
14071 | bpr | 2866 | @ if not set all fill opacity_ will be set by previous command <code>opacity int,int</code> and keyword ''filled`` |
2867 | @ 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 | 2868 | @ wims will not check the amount or validity of your input |
14071 | bpr | 2869 | @ always use the same sequence as is used for ''multidraw`` |
11806 | schaersvoo | 2870 | */ |
2871 | if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
||
2872 | temp = get_string(infile,1); |
||
2873 | temp = str_replace(temp,",","\",\""); |
||
2874 | fprintf(js_include_file,"var multifillopacity = [\"%s\"];",temp); |
||
2875 | break; |
||
2876 | case MULTISNAPTOGRID: |
||
2877 | /* |
||
2878 | @ multisnaptogrid 0,1,1 |
||
14071 | bpr | 2879 | @ alternative: <code>multisnap</code> |
2880 | @ 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>) |
||
2881 | @ freehand drawing...specify precision for reply: all objects snap to grid <code>multisnaptogrid 1,1,1,...</code> |
||
2882 | @ only the xy-values snap_to_grid: all objects snap to grid <code>multisnaptogrid 1,1,1,...</code> |
||
2883 | @ only the x-values snap_to_grid: all objects snap to x-grid <code>multisnaptogrid 2,2,2,...</code> |
||
2884 | @ only the y-values snap_to_grid: all objects snap to y-grid <code>multisnaptogrid 3,3,3,...</code> |
||
2885 | @ 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> |
||
2886 | @ <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> |
||
14066 | bpr | 2887 | @ use before command <a href='#multidraw'>multidraw</a> |
14071 | bpr | 2888 | @ attention: if not set all objects will be set ''no snap``... unless a generic command ''snaptogrid`` was given before command ''multidraw`` |
2889 | @ 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> |
||
2890 | @ always use the same sequence as is used for ''multidraw`` |
||
11806 | schaersvoo | 2891 | @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives... |
2892 | */ |
||
2893 | if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
||
2894 | temp = get_string(infile,1); |
||
14038 | schaersvoo | 2895 | fprintf(js_include_file,"var multisnaptogrid = [%s];",temp); |
11806 | schaersvoo | 2896 | reset();/* if command 'dashed' was given...reset to not-dashed */ |
2897 | break; |
||
2898 | case MULTISTROKECOLORS: |
||
2899 | /* |
||
2900 | @ multistrokecolors color_name_1,color_name_2,...,color_name_8 |
||
14066 | bpr | 2901 | @ use before command <a href='#multidraw'>multidraw</a> |
14071 | bpr | 2902 | @ if not set all colors will be ''stroke_color``, ''stroke_opacity`` |
2903 | @ 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 | 2904 | @ wims will <b>not</b> check if the number of colours matches the amount of draw primitives... |
14071 | bpr | 2905 | @ always use the same sequence as is used for ''multidraw`` |
11806 | schaersvoo | 2906 | */ |
2907 | if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
||
2908 | fprintf(js_include_file,"var multistrokecolors = ["); |
||
2909 | while( ! done ){ |
||
2910 | temp = get_color(infile,1); |
||
2911 | fprintf(js_include_file,"\"%s\",",temp); |
||
2912 | } |
||
2913 | fprintf(js_include_file,"\"0,0,0\"];");/* add black to avoid trouble with dangling comma... */ |
||
2914 | break; |
||
2915 | case MULTISTROKEOPACITY: |
||
2916 | /* |
||
2917 | @ multistrokeopacity stroke_opacity_1,stroke_opacity_2,...,stroke_opacity_7 |
||
2918 | @ float values 0 - 1 or integer values 0 - 255 |
||
14066 | bpr | 2919 | @ use before command <a href='#multidraw'>multidraw</a> |
14071 | bpr | 2920 | @ if not set all stroke opacity_ will be set by previous command <code>opacity int,int</code> |
2921 | @ 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 | 2922 | @ wims will not check the amount or validity of your input |
14071 | bpr | 2923 | @ always use the same sequence as is used for ''multidraw`` |
11806 | schaersvoo | 2924 | */ |
2925 | if( use_tooltip == 1){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");} |
||
2926 | temp = get_string(infile,1); |
||
2927 | temp = str_replace(temp,",","\",\""); |
||
2928 | fprintf(js_include_file,"var multistrokeopacity = [\"%s\"];",temp); |
||
2929 | break; |
||
2930 | |||
2931 | case MULTIUSERINPUT: |
||
2932 | /* |
||
2933 | @ multiuserinput 0,1,1,0 |
||
14071 | bpr | 2934 | @ alternative: <code>multiinput</code> |
2935 | @ 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 |
||
2936 | @ 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 |
||
14086 | bpr | 2937 | @ 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... |
11806 | schaersvoo | 2938 | @ in case of a triangle | poly3, three inputfields are provided. |
14086 | bpr | 2939 | @ in case of ''text`` and ``multiuserinput=1, 3'' inputfields will be shown: ''x,y,text`` |
2940 | @ in case of ''text`` and ``multiuserinput=0, 1'' inputfield will be shown: text ... a mouse click will place the text on the canvas. |
||
14066 | bpr | 2941 | @ may be styled using command <a href="#inputstyle">inputstyle</a> |
14071 | bpr | 2942 | @ an additional button ''stop drawing`` may be used to combine userbased drawings with ''drag&drop`` or ''onclick`` elements |
2943 | @ when exercise if finished (status=done) the buttons will not be shown.<br />To override this default behaviour use command / keyword ''status`` |
||
14066 | bpr | 2944 | @ use before command <a href='#multidraw'>multidraw</a> |
14071 | bpr | 2945 | @ always use the same sequence as is used for ''multidraw`` |
11806 | schaersvoo | 2946 | */ |
2947 | /* simple rawmath and input check */ |
||
2948 | if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */ |
||
2949 | temp = get_string(infile,1); |
||
2950 | temp = str_replace(temp,",","\",\""); |
||
2951 | fprintf(js_include_file,"var multiuserinput = [\"%s\"];",temp); |
||
2952 | break; |
||
2953 | |||
2954 | case NOXAXIS: |
||
2955 | /* |
||
13829 | bpr | 2956 | @ noaxis |
11806 | schaersvoo | 2957 | @ keyword |
2958 | @ if set, the automatic x-axis numbering will be ignored |
||
13936 | bpr | 2959 | @ use command <a href="#axis">axis</a> to have a visual x/y-axis lines (see command <a href="#grid">grid</a> |
11806 | schaersvoo | 2960 | @ to be used before command grid (see <a href="#grid">command grid</a>) |
2961 | */ |
||
11891 | schaersvoo | 2962 | fprintf(js_include_file,"x_strings = {};x_strings_up = [];\n"); |
2963 | use_axis_numbering = -1; |
||
11806 | schaersvoo | 2964 | break; |
2965 | case NOYAXIS: |
||
2966 | /* |
||
13829 | bpr | 2967 | @ noayis |
11806 | schaersvoo | 2968 | @ keyword |
2969 | @ if set, the automatic y-axis numbering will be ignored |
||
13936 | bpr | 2970 | @ use command <a href="#axis">axis</a> to have a visual x/y-axis lines (see command <a href="#grid">grid</a> |
11806 | schaersvoo | 2971 | @ to be used before command grid (see <a href="#grid">command grid</a>) |
2972 | */ |
||
11891 | schaersvoo | 2973 | fprintf(js_include_file,"y_strings = {};\n"); |
11806 | schaersvoo | 2974 | break; |
11890 | schaersvoo | 2975 | case NUMBERLINE: |
2976 | /* |
||
2977 | @ numberline x0,x1,xmajor,xminor,y0,y1 |
||
2978 | @ numberline is using xrange/yrange system for all dimensions |
||
11996 | schaersvoo | 2979 | @ 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 | 2980 | @ x0 is start x-value in xrange |
2981 | @ x1 is end x-value in xrange |
||
2982 | @ xmajor is step for major division |
||
14071 | bpr | 2983 | @ xminor is divisor of xmajor; using small (30% of major tick) tick marks: this behaviour is ''hardcoded`` |
2984 | @ is xminor is an even divisor, an extra tickmark (60% of major tick) is added to the numberline: this behaviour is ''hardcoded`` |
||
11890 | schaersvoo | 2985 | @ y0 is bottom of numberline; y1 endpoint of major tics |
13829 | bpr | 2986 | @ use command <a href="#linewidth">linewidth</a> to control appearance |
11890 | schaersvoo | 2987 | @ use <a href="#strokecolor">strokecolor</a> and <a href="#opacity">opacity</a> to controle measure line |
2988 | @ for all ticks linewidth and color / opacity are identical. |
||
2989 | @ 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 | 2990 | @ use <a href="#fontfamily">fontfamily</a> and <a href="#fontcolor">fontcolor</a> to control fonts settings |
14078 | bpr | 2991 | @ 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 | 2992 | @ <a href="#snaptogrid">snaptogrid, snaptopoints etc</a> and <a href="#zoom">zooming and panning</a> is supported |
2993 | @ onclick and dragging of the numberline are not -yet- supported |
||
14071 | bpr | 2994 | @ 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 | 2995 | @%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 | 2996 | */ |
2997 | if( js_function[DRAW_NUMBERLINE] != 1 ){ js_function[DRAW_NUMBERLINE] = 1;} |
||
2998 | for(i=0;i<6;i++){ |
||
2999 | switch(i){ |
||
3000 | case 0: double_data[0] = get_real(infile,0);break;/* xmin */ |
||
3001 | case 1: double_data[1] = get_real(infile,0);break;/* xmax */ |
||
3002 | case 2: double_data[2] = get_real(infile,0);break;/* xmajor */ |
||
3003 | case 3: double_data[3] = get_real(infile,0);break;/* xminor */ |
||
3004 | case 4: double_data[4] = get_real(infile,0);break;/* ymin */ |
||
3005 | case 5: double_data[5] = get_real(infile,1);/* ymax */ |
||
3006 | /* |
||
3007 | var draw_numberline%d = function(canvas_type,xmin,xmax,xmajor,xminor,ymin,ymax,linewidth,strokecolor,strokeopacity,fontfamily,fontcolor); |
||
3008 | */ |
||
3009 | fprintf(js_include_file,"snap_x = %f;snap_y = %f;",double_data[2] / double_data[3],double_data[5] - double_data[4] ); |
||
11996 | schaersvoo | 3010 | string_length = 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); |
11890 | schaersvoo | 3011 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
11996 | schaersvoo | 3012 | 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 | 3013 | add_to_buffer(tmp_buffer); |
3014 | numberline_cnt++; |
||
3015 | break; |
||
3016 | default:break; |
||
3017 | } |
||
3018 | } |
||
3019 | reset(); |
||
3020 | break; |
||
3021 | |||
3022 | break; |
||
11806 | schaersvoo | 3023 | case OPACITY: |
3024 | /* |
||
13951 | schaersvoo | 3025 | @ opacity [0-255],[0-255] |
3026 | @ opacity [0.0 - 1.0],[0.0 - 1.0] |
||
14071 | bpr | 3027 | @ alternative: <code>transparent</code> |
11806 | schaersvoo | 3028 | @ first item is stroke opacity, second is fill opacity |
13951 | schaersvoo | 3029 | @%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 | 3030 | */ |
3031 | for(i = 0 ; i<2;i++){ |
||
3032 | switch(i){ |
||
3033 | case 0: double_data[0]= get_real(infile,0);break; |
||
3034 | case 1: double_data[1]= get_real(infile,1);break; |
||
3035 | default: break; |
||
3036 | } |
||
3037 | } |
||
13951 | schaersvoo | 3038 | 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 | 3039 | if( double_data[0] > 1 ){ stroke_opacity = (double) (0.0039215*double_data[0]); }else{ stroke_opacity = 0.0;} /* 0.0 - 1.0 */ |
3040 | if( double_data[1] > 1 ){ fill_opacity = (double) (0.0039215*double_data[1]); }else{ fill_opacity = 0.0;} /* 0.0 - 1.0 */ |
||
11806 | schaersvoo | 3041 | break; |
3042 | |||
3043 | case ONCLICK: |
||
3044 | /* |
||
3045 | @ onclick |
||
3046 | @ keyword (no arguments required) |
||
14086 | bpr | 3047 | @ if the next object is clicked, its ''object onclick_or_drag sequence number`` in fly script is returned by <code>javascript:read_canvas();</code> |
3048 | @ 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`` |
||
14071 | bpr | 3049 | @ line based objects will show an increase in line width<br />font based objects will show the text in ''bold`` when clicked. |
11806 | schaersvoo | 3050 | @ the click zone (accuracy) is determined by 2× the line width of the object |
14071 | bpr | 3051 | @ 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 | 3052 | @ note: not all objects may be set onclick |
12107 | schaersvoo | 3053 | @%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 | 3054 | */ |
3055 | fprintf(js_include_file,"use_dragdrop_reply = true;"); |
||
3056 | onclick = 1; |
||
3057 | |||
3058 | break; |
||
3059 | |||
3060 | case PARALLEL: |
||
3061 | /* |
||
3062 | @ parallel x1,y1,x2,y2,dx,dy,n,[colorname or #hexcolor] |
||
14086 | bpr | 3063 | @ can <b>not</b> be set ''onclick`` or ''drag xy`` |
12107 | schaersvoo | 3064 | @%parallel%size 400,400%xrange -10,10%yrange -10,10%parallel -5,5,-4,-5,0.25,0,40,red |
11806 | schaersvoo | 3065 | */ |
3066 | for( i = 0;i < 8; i++ ){ |
||
3067 | switch(i){ |
||
14032 | schaersvoo | 3068 | case 0: double_data[0] = get_real(infile,0);break; /* x1-values -> x-pixels*/ |
3069 | case 1: double_data[1] = get_real(infile,0);break; /* y1-values -> y-pixels*/ |
||
3070 | case 2: double_data[2] = get_real(infile,0);break; /* x2-values -> x-pixels*/ |
||
3071 | case 3: double_data[3] = get_real(infile,0);break; /* y2-values -> y-pixels*/ |
||
11806 | schaersvoo | 3072 | case 4: double_data[4] = xmin + get_real(infile,0);break; /* xv -> x-pixels */ |
3073 | case 5: double_data[5] = ymax + get_real(infile,0);break; /* yv -> y-pixels */ |
||
14032 | schaersvoo | 3074 | case 6: int_data[0] = (int) (get_real(infile,0));break; /* n */ |
11806 | schaersvoo | 3075 | case 7: stroke_color=get_color(infile,1);/* name or hex color */ |
3076 | decimals = find_number_of_digits(precision); |
||
14045 | schaersvoo | 3077 | fprintf(js_include_file,"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\",%d,%s,%d,%d,%s,%d,%d));\n",drag_type,click_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,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern); |
11806 | schaersvoo | 3078 | if(onclick > 0){click_cnt++;} |
3079 | /* click_cnt++*/; |
||
3080 | reset(); |
||
3081 | break; |
||
3082 | default: break; |
||
3083 | } |
||
3084 | } |
||
3085 | break; |
||
3086 | |||
3087 | |||
3088 | case PLOTSTEPS: |
||
3089 | /* |
||
3090 | @ plotsteps a_number |
||
3091 | @ default 150 |
||
14066 | bpr | 3092 | @ only used for commands <a href="#curve">curve / plot</a> and <a href="#levelcurve">levelcurve</a> |
11806 | schaersvoo | 3093 | @ use with care ! |
3094 | */ |
||
3095 | plot_steps = (int) (get_real(infile,1)); |
||
3096 | break; |
||
13829 | bpr | 3097 | |
11806 | schaersvoo | 3098 | case POINT: |
3099 | /* |
||
3100 | @ point x,y,color |
||
3101 | @ draw a single point at (x;y) in color 'color' |
||
14071 | bpr | 3102 | @ use command <code>linewidth int</code> to adjust size |
11806 | schaersvoo | 3103 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
14071 | bpr | 3104 | @ will not resize on zooming (command <code>circle x,y,r,color</code> will resize on zooming) |
14066 | bpr | 3105 | @ attention: in case of command <a href="#rotate">rotate angle</a> a point has rotation center (0:0) in x/y-range |
12107 | schaersvoo | 3106 | @%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 | 3107 | */ |
3108 | for(i=0;i<3;i++){ |
||
3109 | switch(i){ |
||
3110 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
3111 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
3112 | case 2: stroke_color = get_color(infile,1);/* name or hex color */ |
||
3113 | decimals = find_number_of_digits(precision); |
||
14045 | schaersvoo | 3114 | fprintf(js_include_file,"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\",%d,%s,%d,%d,%s,%d,%d));\n",drag_type,click_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,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern); |
11806 | schaersvoo | 3115 | /* click_cnt++; */ |
3116 | if(onclick > 0){click_cnt++;} |
||
3117 | break; |
||
3118 | default: break; |
||
3119 | } |
||
3120 | } |
||
3121 | reset(); |
||
3122 | break; |
||
3123 | |||
3124 | case POINTS: |
||
3125 | /* |
||
3126 | @ points color,x1,y1,x2,y2,...,x_n,y_n |
||
3127 | @ draw multiple points at given coordinates in color 'color' |
||
14071 | bpr | 3128 | @ use command <code>linewidth int</code> to adjust size |
11806 | schaersvoo | 3129 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!) |
14066 | bpr | 3130 | @ attention: in case of command <a href="#rotate">rotate angle</a> the points have rotation center (0:0) in x/y-range |
12107 | schaersvoo | 3131 | @%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 |
3132 | @%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 | 3133 | */ |
8363 | schaersvoo | 3134 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
3135 | fill_color = stroke_color; |
||
3136 | i=0; |
||
3137 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 3138 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
8363 | schaersvoo | 3139 | if(i%2 == 0 ){ |
3140 | double_data[i] = get_real(infile,0); /* x */ |
||
3141 | } |
||
3142 | else |
||
3143 | { |
||
3144 | double_data[i] = get_real(infile,1); /* y */ |
||
3145 | } |
||
3146 | i++; |
||
3147 | } |
||
3148 | decimals = find_number_of_digits(precision); |
||
11806 | schaersvoo | 3149 | for(c = 0 ; c < i-1 ; c = c+2){ |
14045 | schaersvoo | 3150 | fprintf(js_include_file,"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\",%d,%s,%d,%d,%s,%d,%d));\n",drag_type,click_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,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern); |
8379 | schaersvoo | 3151 | /* click_cnt++; */ |
11806 | schaersvoo | 3152 | if(onclick > 0){click_cnt++;} |
8363 | schaersvoo | 3153 | } |
3154 | reset(); |
||
3155 | break; |
||
11806 | schaersvoo | 3156 | |
3157 | case POLY: |
||
3158 | /* |
||
3159 | @ poly color,x1,y1,x2,y2...x_n,y_n |
||
3160 | @ polygon color,x1,y1,x2,y2...x_n,y_n |
||
3161 | @ draw closed polygon |
||
14071 | bpr | 3162 | @ use command ''fpoly`` to fill it or use keyword <a href='#filled'>filled</a> |
11806 | schaersvoo | 3163 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
12107 | schaersvoo | 3164 | @%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 |
3165 | @%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 | 3166 | */ |
3167 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
3168 | i=0; |
||
3169 | c=0; |
||
3170 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 3171 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
11806 | schaersvoo | 3172 | for( c = 0 ; c < 2; c++){ |
3173 | if(c == 0 ){ |
||
3174 | double_data[i] = get_real(infile,0); |
||
3175 | i++; |
||
3176 | } |
||
3177 | else |
||
3178 | { |
||
3179 | double_data[i] = get_real(infile,1); |
||
3180 | i++; |
||
3181 | } |
||
3182 | } |
||
3183 | } |
||
14066 | bpr | 3184 | /* draw path: closed & optional filled */ |
11806 | schaersvoo | 3185 | decimals = find_number_of_digits(precision); |
14045 | schaersvoo | 3186 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,5,%s,[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d,%d));\n",drag_type,click_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,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern); |
11806 | schaersvoo | 3187 | if(onclick > 0){click_cnt++;} |
3188 | /* click_cnt++; */ |
||
3189 | reset(); |
||
3190 | break; |
||
3191 | |||
7614 | schaersvoo | 3192 | case POLYLINE: |
3193 | /* |
||
3194 | @ polyline color,x1,y1,x2,y2...x_n,y_n |
||
10975 | schaersvoo | 3195 | @ brokenline color,x1,y1,x2,y2...x_n,y_n |
3196 | @ path color,x1,y1,x2,y2...x_n,y_n |
||
14086 | bpr | 3197 | @ 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> |
3198 | @ 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 | 3199 | @ 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 | 3200 | @ use command <a href='#segments'>segments</a> for a series of segments. These may be clicked/dragged individually |
9406 | schaersvoo | 3201 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
12107 | schaersvoo | 3202 | @%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 |
3203 | @%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 | 3204 | */ |
13829 | bpr | 3205 | |
7614 | schaersvoo | 3206 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
3207 | i=0; |
||
3208 | c=0; |
||
3209 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 3210 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
7614 | schaersvoo | 3211 | for( c = 0 ; c < 2; c++){ |
3212 | if(c == 0 ){ |
||
3213 | double_data[i] = get_real(infile,0); |
||
3214 | i++; |
||
3215 | } |
||
3216 | else |
||
3217 | { |
||
3218 | double_data[i] = get_real(infile,1); |
||
3219 | i++; |
||
3220 | } |
||
3221 | } |
||
3222 | } |
||
14066 | bpr | 3223 | /* draw path: not closed & not filled */ |
7614 | schaersvoo | 3224 | decimals = find_number_of_digits(precision); |
14045 | schaersvoo | 3225 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,4,%s,[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d,%d));\n",drag_type,click_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,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern); |
8379 | schaersvoo | 3226 | if(onclick > 0){click_cnt++;} |
3227 | /* click_cnt++;*/ |
||
3228 | reset(); |
||
7614 | schaersvoo | 3229 | break; |
11806 | schaersvoo | 3230 | |
3231 | case POPUP: |
||
3232 | /* |
||
3233 | @ popup |
||
3234 | @ keyword (no arguments) |
||
14086 | bpr | 3235 | @ if fly-script starts with keyword ''popup``, the canvas image will be exclusively in a popup window (xsize px × ysize px) |
14071 | bpr | 3236 | @ 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`` |
14086 | bpr | 3237 | @ the popup window will be embedded into the page as a ''normal`` image, when ''status=done``; override with keyword <a href="#status">nostatus</a> |
14071 | bpr | 3238 | @ to access the read_canvas and read_dragdrop functions in a popup window, use: <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> |
3239 | @ 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 |
||
12107 | schaersvoo | 3240 | @%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 f(x)=%userinput function |
11806 | schaersvoo | 3241 | */ |
3242 | use_tooltip = 2; |
||
3243 | break; |
||
3244 | |||
3245 | case PROTRACTOR: |
||
7614 | schaersvoo | 3246 | /* |
11806 | schaersvoo | 3247 | @ protractor x,y,x_width,type,mode,use_a_scale |
3248 | @ x,y are the initial location |
||
14066 | bpr | 3249 | @ x_width: give the width in x-coordinate system (e.g. not in pixels !) |
3250 | @ type = 1: a triangle range 0 - 180<br />type = 2: a circle shape 0 - 360 |
||
3251 | @ 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 | 3252 | @ 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 | 3253 | @ use_scale = 1: the protractor will have some scale values printed; use_scale=0 to disable |
11806 | schaersvoo | 3254 | @ the rotating direction of the mouse around the protractor determines the clockwise/ counter clockwise rotation of the protractor... |
14071 | bpr | 3255 | @ commands ''stroke_color | fill_color | linewidth | opacity | font_family`` will determine the looks of the protractor. |
3256 | @ default replyformat: reply[0] = x;reply[1] = y;reply[2] = angle_in_radians<br />use command ''precision`` to set the reply precision. |
||
11806 | schaersvoo | 3257 | @ if combined with a ruler, use replyformat = 32 |
14071 | bpr | 3258 | @ command <code>snap_to_grid</code> may be used to assist the pupil at placing the protractor |
3259 | @ 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 | 3260 | @ only one protractor allowed (for the time being) |
3261 | @ 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... |
||
12107 | schaersvoo | 3262 | @%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 |
7614 | schaersvoo | 3263 | */ |
11806 | schaersvoo | 3264 | for( i = 0;i < 6; i++ ){ |
3265 | switch(i){ |
||
3266 | case 0: double_data[0] = get_real(infile,0);break; /* x-center */ |
||
3267 | case 1: double_data[1] = get_real(infile,0);break; /* y-center */ |
||
3268 | case 2: double_data[2] = get_real(infile,0);break; /* x-width */ |
||
3269 | case 3: int_data[0] = (int)(get_real(infile,0));break; /* type: 1==triangle 2 == circle */ |
||
3270 | case 4: int_data[1] = (int)(get_real(infile,0));break; /* passive mode == 0; active mode == -1 */ |
||
3271 | case 5: int_data[2] = (int)(get_real(infile,1)); /* use scale */ |
||
3272 | decimals = find_number_of_digits(precision); |
||
11821 | schaersvoo | 3273 | if( int_data[1] < 0 ){ js_function[JS_FIND_ANGLE] = 1;} |
14057 | schaersvoo | 3274 | add_js_protractor(js_include_file,canvas_root_id,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 | 3275 | |
3276 | string_length = snprintf(NULL,0,";protractor%d(); ",canvas_root_id); |
||
3277 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
3278 | snprintf(tmp_buffer,string_length,";protractor%d(); ",canvas_root_id); |
||
3279 | add_to_buffer(tmp_buffer); |
||
3280 | reply_precision = precision; |
||
3281 | /* no reply from protractor if non-interactive */ |
||
3282 | if( reply_format == 0 && int_data[1] == -1 ){reply_format = 30;} |
||
3283 | break; |
||
3284 | default: break; |
||
3285 | } |
||
3286 | } |
||
3287 | break; |
||
3288 | |||
3289 | case PIXELS: |
||
3290 | /* |
||
3291 | @ pixels color,x1,y1,x2,y2,x3,y3... |
||
3292 | @ draw rectangular "points" with diameter 1 pixel |
||
3293 | @ pixels can <b>not</b> be dragged or clicked |
||
14086 | bpr | 3294 | @ "pixelsize = 1" may be changed by command <code>pixelsize int</code> |
12111 | schaersvoo | 3295 | @%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 | 3296 | */ |
3297 | if( js_function[DRAW_PIXELS] != 1 ){ js_function[DRAW_PIXELS] = 1;} |
||
3298 | stroke_color=get_color(infile,0); |
||
7614 | schaersvoo | 3299 | i=0; |
3300 | c=0; |
||
3301 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 3302 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
7614 | schaersvoo | 3303 | for( c = 0 ; c < 2; c++){ |
3304 | if(c == 0 ){ |
||
3305 | double_data[i] = get_real(infile,0); |
||
3306 | i++; |
||
3307 | } |
||
3308 | else |
||
3309 | { |
||
3310 | double_data[i] = get_real(infile,1); |
||
3311 | i++; |
||
3312 | } |
||
3313 | } |
||
3314 | } |
||
11806 | schaersvoo | 3315 | decimals = find_number_of_digits(precision); |
3316 | /* *double_xy2js_array(double xy[],int len,int decimals) */ |
||
3317 | string_length = snprintf(NULL,0, "draw_setpixel(%s,\"%s\",%.2f,%d);\n",double_xy2js_array(double_data,i,decimals),stroke_color,stroke_opacity,pixelsize); |
||
3318 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
3319 | snprintf(tmp_buffer,string_length,"draw_setpixel(%s,\"%s\",%.2f,%d);\n",double_xy2js_array(double_data,i,decimals),stroke_color,stroke_opacity,pixelsize); |
||
3320 | add_to_buffer(tmp_buffer); |
||
3321 | reset(); |
||
7614 | schaersvoo | 3322 | break; |
11806 | schaersvoo | 3323 | |
3324 | case PIXELSIZE: |
||
7614 | schaersvoo | 3325 | /* |
11806 | schaersvoo | 3326 | @ pixelsize int |
3327 | @ in case you want to deviate from default pixelsize = 1(...) |
||
12111 | schaersvoo | 3328 | @ pixelsize 100 is of course a filled rectangle 100px × 100px |
7614 | schaersvoo | 3329 | */ |
11806 | schaersvoo | 3330 | pixelsize = (int) get_real(infile,1); |
3331 | break; |
||
8105 | schaersvoo | 3332 | |
11806 | schaersvoo | 3333 | case PIECHART: |
7614 | schaersvoo | 3334 | /* |
11806 | schaersvoo | 3335 | @ piechart xc,yc,radius,'data+colorlist' |
14066 | bpr | 3336 | @ (xc: yc) center of circle diagram in xrange/yrange |
11806 | schaersvoo | 3337 | @ radius in pixels |
3338 | @ 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 | 3339 | @ example data+colorlist: 32:red:65:green:23:black:43:orange:43:yellow:14:white |
11806 | schaersvoo | 3340 | @ the number of colors must match the number of data. |
14066 | bpr | 3341 | @ 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 | 3342 | @ use command <a href='#opacity'>opacity</a> to adjust fill_opacity of colours |
3343 | @ 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 | 3344 | @ 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 | 3345 | @%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% |
3346 | @%piechart_2%size 200,200%xrange -10,10%yrange -10,10%fontfamily 16px Ariel%centered%legend cars:motorcycles:bicycles:trikes%opacity 255,60%piechart 0,0,100,22:red:8:blue:63:green:7:purple |
||
7614 | schaersvoo | 3347 | */ |
11806 | schaersvoo | 3348 | if( js_function[DRAW_PIECHART] != 1 ){ js_function[DRAW_PIECHART] = 1;} |
7614 | schaersvoo | 3349 | for(i=0;i<5;i++){ |
3350 | switch(i){ |
||
11806 | schaersvoo | 3351 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */ |
14032 | schaersvoo | 3352 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y */ |
11806 | schaersvoo | 3353 | case 2: int_data[2] = (int)(get_real(infile,1));break;/* radius*/ |
3354 | case 3: temp = get_string(infile,1); |
||
3355 | if( strstr( temp, ":" ) != 0 ){ temp = str_replace(temp,":","\",\"");} |
||
12538 | schaersvoo | 3356 | string_length = 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); |
11806 | schaersvoo | 3357 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
12538 | schaersvoo | 3358 | 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 | 3359 | add_to_buffer(tmp_buffer); |
3360 | break; |
||
3361 | default:break; |
||
7614 | schaersvoo | 3362 | } |
3363 | } |
||
11806 | schaersvoo | 3364 | reset(); |
7614 | schaersvoo | 3365 | break; |
8304 | schaersvoo | 3366 | |
7614 | schaersvoo | 3367 | case RAYS: |
3368 | /* |
||
3369 | @ rays color,xc,yc,x1,y1,x2,y2,x3,y3...x_n,y_n |
||
3370 | @ draw rays in color 'color' and center (xc:yc) |
||
7786 | schaersvoo | 3371 | @ may be set draggable or onclick (every individual ray) |
12111 | schaersvoo | 3372 | @%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 |
3373 | @%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 | 3374 | */ |
3375 | stroke_color=get_color(infile,0); |
||
7786 | schaersvoo | 3376 | fill_color = stroke_color; |
3377 | double_data[0] = get_real(infile,0);/* xc */ |
||
3378 | double_data[1] = get_real(infile,0);/* yc */ |
||
3379 | i=2; |
||
3380 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 3381 | if(i > MAX_INT - 1){canvas_error("in command rays too many points / rays in argument: repeat command multiple times to fit");} |
7786 | schaersvoo | 3382 | if(i%2 == 0 ){ |
3383 | double_data[i] = get_real(infile,0); /* x */ |
||
7614 | schaersvoo | 3384 | } |
7786 | schaersvoo | 3385 | else |
3386 | { |
||
3387 | double_data[i] = get_real(infile,1); /* y */ |
||
7614 | schaersvoo | 3388 | } |
7786 | schaersvoo | 3389 | fprintf(js_include_file,"/* double_data[%d] = %f */\n",i,double_data[i]); |
3390 | i++; |
||
7614 | schaersvoo | 3391 | } |
8224 | bpr | 3392 | |
3393 | if( i%2 != 0 ){canvas_error("in command rays: unpaired x or y value");} |
||
3394 | decimals = find_number_of_digits(precision); |
||
7786 | schaersvoo | 3395 | for(c=2; c<i;c = c+2){ |
14045 | schaersvoo | 3396 | fprintf(js_include_file,"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\",%d,%s,%d,%d,%s,%d,%d));\n",drag_type,click_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,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern); |
8379 | schaersvoo | 3397 | /* click_cnt++; */ |
3398 | if(onclick > 0){click_cnt++;} |
||
7614 | schaersvoo | 3399 | } |
3400 | reset(); |
||
3401 | break; |
||
8304 | schaersvoo | 3402 | |
11806 | schaersvoo | 3403 | case RECT: |
8386 | schaersvoo | 3404 | /* |
11806 | schaersvoo | 3405 | @ rect x1,y1,x2,y2,color |
14071 | bpr | 3406 | @ use command <code>frect x1,y1,x2,y2,color</code> for a filled rectangle |
3407 | @ use command/keyword <a href='#filled'>filled</a> before command <code>rect x1,y1,x2,y2,color</code> |
||
9406 | schaersvoo | 3408 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
12111 | schaersvoo | 3409 | @%rect%size 400,400%xrange -10,10%yrange -10,10%rect 0,0,4,-4,green%rect 0,5,4,1,red |
8386 | schaersvoo | 3410 | */ |
11806 | schaersvoo | 3411 | for(i=0;i<5;i++){ |
3412 | switch(i){ |
||
3413 | case 0:double_data[0] = get_real(infile,0);break; /* x-values */ |
||
3414 | case 1:double_data[1] = get_real(infile,0);break; /* y-values */ |
||
3415 | case 2:double_data[2] = get_real(infile,0);break; /* x-values */ |
||
3416 | case 3:double_data[3] = get_real(infile,0);break; /* y-values */ |
||
3417 | case 4:stroke_color = get_color(infile,1);/* name or hex color */ |
||
8386 | schaersvoo | 3418 | decimals = find_number_of_digits(precision); |
14045 | schaersvoo | 3419 | fprintf(js_include_file,"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\",%d,%s,%d,%d,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[2],decimals,double_data[2],decimals,double_data[0],decimals,double_data[1],decimals,double_data[1],decimals,double_data[3],decimals,double_data[3],line_width,line_width,line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern); |
11806 | schaersvoo | 3420 | if(onclick > 0){click_cnt++;} |
3421 | /* click_cnt++; */ |
||
8386 | schaersvoo | 3422 | reset(); |
3423 | break; |
||
11806 | schaersvoo | 3424 | } |
3425 | } |
||
3426 | break; |
||
8386 | schaersvoo | 3427 | |
11806 | schaersvoo | 3428 | case RECTS: |
8304 | schaersvoo | 3429 | /* |
11806 | schaersvoo | 3430 | @ rects color,x1,y1,x2,y2,..... |
14071 | bpr | 3431 | @ use command <code>frect color,x1,y1,x2,y2,.....</code> for a filled rectangle |
3432 | @ use command/keyword <a href='#filled'>filled</a> before command <code>rects color,x1,y1,x2,y2,....</code> |
||
3433 | @ use command <code>fillcolor color</code> before ''frects`` to set the fill colour. |
||
9406 | schaersvoo | 3434 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually |
12111 | schaersvoo | 3435 | @%rects%size 400,400%xrange -10,10%yrange -10,10%rects red,0,0,4,-4,0,5,4,1 |
8304 | schaersvoo | 3436 | */ |
3437 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
||
3438 | fill_color = stroke_color; |
||
3439 | i=0; |
||
3440 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 3441 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
8304 | schaersvoo | 3442 | if(i%2 == 0 ){ |
3443 | double_data[i] = get_real(infile,0); /* x */ |
||
3444 | } |
||
3445 | else |
||
3446 | { |
||
3447 | double_data[i] = get_real(infile,1); /* y */ |
||
3448 | } |
||
3449 | i++; |
||
3450 | } |
||
3451 | decimals = find_number_of_digits(precision); |
||
3452 | for(c = 0 ; c < i-1 ; c = c+4){ |
||
14045 | schaersvoo | 3453 | fprintf(js_include_file,"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\",%d,%s,%d,%d,%s,%d,%d));\n",drag_type,click_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,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern); |
11806 | schaersvoo | 3454 | if(onclick > 0){click_cnt++;} |
8379 | schaersvoo | 3455 | /* click_cnt++; */ |
8304 | schaersvoo | 3456 | } |
3457 | reset(); |
||
3458 | break; |
||
8386 | schaersvoo | 3459 | |
11806 | schaersvoo | 3460 | case REPLYFORMAT: |
7614 | schaersvoo | 3461 | /* |
11806 | schaersvoo | 3462 | @ replyformat number |
3463 | @ use number=-1 to deactivate the js-functions read_canvas() and read_dragdrop() |
||
3464 | @ default values should be fine ! |
||
14071 | bpr | 3465 | @ 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 |
3466 | @ the last value for ''precision int`` will be used to calculate the reply coordinates, if needed (read_canvas();) |
||
14078 | bpr | 3467 | @ choose<ul><li>1 = x1,x2,x3,x4....x_n<br />y1,y2,y3,y4....y_n<br />x/y in pixels</li><li>2 = x1,x2,x3,x4....x_n<br /> y1,y2,y3,y4....y_n<br /> x/y in xrange / yrange coordinate system<br /></li><li>3 = x1,x2,x3,x4....x_n<br /> y1,y2,y3,y4....y_n<br /> r1,r2,r3,r4....r_n<br /> x/y in pixels <br /> r in pixels</li><li>4 = x1,x2,x3,x4....x_n<br /> y1,y2,y3,y4....y_n<br /> r1,r2,r3,r4....r_n<br /> x/y in xrange / yrange coordinate system<br /> r in pixels</li><li>5 = Ax1,Ax2,Ax3,Ax4....Ax_n<br /> Ay1,Ay2,Ay3,Ay4....Ay_n<br /> Bx1,Bx2,Bx3,Bx4....Bx_n<br /> By1,By2,By3,By4....By_n<br /> Cx1,Cx2,Cx3,Cx4....Cx_n<br /> Cy1,Cy2,Cy3,Cy4....Cy_n<br /> ....<br /> Zx1,Zx2,Zx3,Zx4....Zx_n<br /> Zy1,Zy2,Zy3,Zy4....Zy_n<br /> x/y in pixels<br /></li><li>6 = Ax1,Ax2,Ax3,Ax4....Ax_n<br /> Ay1,Ay2,Ay3,Ay4....Ay_n<br /> Bx1,Bx2,Bx3,Bx4....Bx_n<br /> By1,By2,By3,By4....By_n<br /> Cx1,Cx2,Cx3,Cx4....Cx_n<br /> Cy1,Cy2,Cy3,Cy4....Cy_n<br /> ....<br /> Zx1,Zx2,Zx3,Zx4....Zx_n<br /> Zy1,Zy2,Zy3,Zy4....Zy_n<br /> x/y in xrange / yrange coordinate system<br /></li><li>7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n<br /> x/y in pixels</li><li>8 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n<br /> x/y in xrange / yrange coordinate system</li><li>9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n<br /> x/y in pixels</li><li>10 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n<br /> x/y in xrange / yrange coordinate system</li><li>11 = Ax1,Ay1,Ax2,Ay2<br /> Bx1,By1,Bx2,By2<br /> Cx1,Cy1,Cx2,Cy2<br /> Dx1,Dy1,Dx2,Dy2<br /> ......<br /> Zx1,Zy1,Zx2,Zy2<br /> x/y in xrange / yrange coordinate system</li><li>12 = Ax1,Ay1,Ax2,Ay2<br /> Bx1,By1,Bx2,By2<br />Cx1,Cy1,Cx2,Cy2<br /> Dx1,Dy1,Dx2,Dy2<br /> ......<br /> Zx1,Zy1,Zx2,Zy2<br /> x/y in pixels</li><li>13 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2,Cx1:Cy1:Cx2:Cy2,Dx1:Dy1:Dx2:Dy2, ... ,Zx1:Zy1:Zx2:Zy2<br /> x/y in xrange / yrange coordinate system</li><li>14 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2....Zx1:Zy1:Zx2:Zy2<br /> x/y in pixels</li><li>15 = reply from inputfields,textareas<br /> reply1,reply2,reply3,...,reply_n</li><li>16 = mathml input fields </li><li>17 = read "userdraw text,color" only (x1,y1,text1 \\n x2,y2,text2...\\n...x_n,y_n,text_n <br /> x/y-values are in xrang/yrange</li><li>18 = read_canvas() will read all interactive clocks in H1:M1:S1,H2:M2:S2...Hn:Mn:Sn</li><li>19 = read_canvas() will return the object number of marked / clicked object (clock)<br />analogue to (shape library) onclick command </li><li>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 <br />e.g. expect something like 0:-5:4,1:6:2,2:-2:-5 <br /> the first image position is (-5:4), the second image position is (6:2) and the third image position is (-2:-5) <li>21 = (x1:y1) (x2:y2) ... (x_n:y_n)<br />verbatim coordinate return</li><li>22 = returns an array .... reply[0]=x1 reply[1]=y1 reply[2]=x2 reply[3]=y2 ... reply[n-1]=x_n reply[n]=y_n<br /> x/y in xrange / yrange coordinate system</li><li>23: can only be used for drawtype ''polyline``<br />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--> x1,y1,x2,y2,x3,y3,.....x(n-1),y(n-1),xn,yn multiple occurences will be filtered out.The reply will be in x-y-range (xreply \\n yreply)</li><li>24 = read all inputfield values: even those set ''readonly``</li><li>25 = angle1,angle2...angle_n: will return the radius (one or many) of the user drawn circle segment in degrees </li><li>26 = rad1,rad2...rad_n: will return the radius (one or many) of the user drawn circle segment in radians </li><li>27 = return (only) userdraw inputfields x1,y1,text1 \\n x2,y2,text2...\\n...x_n,y_n,text_n</li><li>28 = x1,y1,r1,x2,y2,r2...x_n,y_n,r_n <br />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></ul> |
14071 | bpr | 3468 | @ 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) |
11806 | schaersvoo | 3469 | */ |
3470 | reply_format = (int) get_real(infile,1); |
||
3471 | reply_precision = precision; |
||
3472 | break; |
||
3473 | |||
3474 | case ROUNDRECT: |
||
3475 | /* |
||
3476 | @ roundrect x1,y1,x2,y2,radius in px,color |
||
14071 | bpr | 3477 | @ use command <code>froundrect x1,y1,x2,y2,radius,color</code> for a filled rectangle |
3478 | @ use command/keyword <a href='#filled'>filled</a> before command <code>roundrect x1,y1,x2,y2,radius,color</code> |
||
3479 | @ fillcolor will be identical to ''color`` |
||
9406 | schaersvoo | 3480 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
12111 | schaersvoo | 3481 | @%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 | 3482 | */ |
11806 | schaersvoo | 3483 | for(i=0;i<6;i++){ |
3484 | switch(i){ |
||
3485 | case 0:double_data[0] = get_real(infile,0);break; /* x-values */ |
||
3486 | case 1:double_data[1] = get_real(infile,0);break; /* y-values */ |
||
3487 | case 2:double_data[2] = get_real(infile,0);break; /* x-values */ |
||
3488 | case 3:double_data[3] = get_real(infile,0);break; /* y-values */ |
||
3489 | case 4:int_data[0] = (int) (get_real(infile,0));break; /* radius value in pixels */ |
||
3490 | case 5:stroke_color = get_color(infile,1);/* name or hex color */ |
||
3491 | /* ensure no inverted roundrect is produced... */ |
||
3492 | 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];} |
||
3493 | 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 | 3494 | decimals = find_number_of_digits(precision); |
14045 | schaersvoo | 3495 | fprintf(js_include_file,"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\",%d,%s,%d,%d,%s,%d,%d));\n",drag_type,click_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,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern); |
8379 | schaersvoo | 3496 | if(onclick > 0){click_cnt++;} |
3497 | /* click_cnt++;*/ |
||
3498 | reset(); |
||
11806 | schaersvoo | 3499 | break; |
3500 | } |
||
3501 | } |
||
3502 | break; |
||
8386 | schaersvoo | 3503 | |
11806 | schaersvoo | 3504 | case ROUNDRECTS: |
8347 | schaersvoo | 3505 | /* |
11806 | schaersvoo | 3506 | @ roundrects color,radius in px,x1,y1,x2,y2,x3,y3,x4,y4,.... |
14066 | bpr | 3507 | @ for filled roundrects use command/keyword <a href='#filled'>filled</a> before command |
9406 | schaersvoo | 3508 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually |
13935 | bpr | 3509 | @%roundrects%size 400,400%xrange -10,10%yrange -10,10%roundrects blue,5,0,0,4,-4,5,4,1,2 |
8347 | schaersvoo | 3510 | */ |
11806 | schaersvoo | 3511 | |
8347 | schaersvoo | 3512 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
11806 | schaersvoo | 3513 | int_data[0] = (int) (get_real(infile,0)); /* radius value in pixels */ |
8347 | schaersvoo | 3514 | fill_color = stroke_color; |
3515 | i=0; |
||
3516 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 3517 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
8347 | schaersvoo | 3518 | if(i%2 == 0 ){ |
3519 | double_data[i] = get_real(infile,0); /* x */ |
||
3520 | } |
||
3521 | else |
||
3522 | { |
||
3523 | double_data[i] = get_real(infile,1); /* y */ |
||
3524 | } |
||
3525 | i++; |
||
3526 | } |
||
3527 | decimals = find_number_of_digits(precision); |
||
3528 | for(c = 0 ; c < i-1 ; c = c+4){ |
||
11806 | schaersvoo | 3529 | /* ensure no inverted roundrect is produced... */ |
3530 | 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];} |
||
3531 | 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];} |
||
14045 | schaersvoo | 3532 | fprintf(js_include_file,"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\",%d,%s,%d,%d,%s,%d,%d));\n",drag_type,click_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,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern); |
11806 | schaersvoo | 3533 | if(onclick > 0){click_cnt++;} |
8379 | schaersvoo | 3534 | /* click_cnt++; */ |
8347 | schaersvoo | 3535 | } |
3536 | reset(); |
||
3537 | break; |
||
8386 | schaersvoo | 3538 | |
11806 | schaersvoo | 3539 | case RULER: |
7614 | schaersvoo | 3540 | /* |
14078 | bpr | 3541 | @ ruler x,y,x-width,y-height,mode |
11806 | schaersvoo | 3542 | @ x,y are the initial location |
14078 | bpr | 3543 | @ x-width, y-height are the ruler dimensions width & height in xy-coordinate system |
14071 | bpr | 3544 | @ 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 | 3545 | @ 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 | 3546 | @ if combined with a protractor, use replyformat = 32 |
3547 | @ only one ruler allowed (for the time being) |
||
14071 | bpr | 3548 | @ 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 ''ruler`` 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 | 3549 | @ usage: first left click on the ruler 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... |
12111 | schaersvoo | 3550 | @%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%zoom red |
3551 | @%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%zoom red |
||
3552 | @%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%zoom red |
||
7614 | schaersvoo | 3553 | */ |
11806 | schaersvoo | 3554 | for( i = 0;i < 5; i++ ){ |
7614 | schaersvoo | 3555 | switch(i){ |
11806 | schaersvoo | 3556 | case 0: double_data[0] = get_real(infile,0);break; /* x-center */ |
3557 | case 1: double_data[1] = get_real(infile,0);break; /* y-center */ |
||
3558 | case 2: double_data[2] = get_real(infile,0);break; /* x-width */ |
||
3559 | case 3: double_data[3] = get_real(infile,0);break; /* y-width */ |
||
3560 | case 4: int_data[0] = (int)(get_real(infile,1)); /* passive mode */ |
||
3561 | decimals = find_number_of_digits(precision); |
||
3562 | if( int_data[0] < 0 ){ |
||
14032 | schaersvoo | 3563 | if( js_function[JS_FIND_ANGLE] != 1 ){ js_function[JS_FIND_ANGLE] = 1; } |
11806 | schaersvoo | 3564 | } |
14057 | schaersvoo | 3565 | add_js_ruler(js_include_file,canvas_root_id,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); |
11806 | schaersvoo | 3566 | string_length = snprintf(NULL,0,";ruler%d(); ",canvas_root_id); |
3567 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
3568 | snprintf(tmp_buffer,string_length,";ruler%d(); ",canvas_root_id); |
||
3569 | add_to_buffer(tmp_buffer); |
||
3570 | reply_precision = precision; |
||
3571 | /* no reply from ruler if non-interactive */ |
||
3572 | if( reply_format == 0 && int_data[0] == -1 ){reply_format = 31;} |
||
7614 | schaersvoo | 3573 | break; |
3574 | default: break; |
||
3575 | } |
||
3576 | } |
||
3577 | break; |
||
8386 | schaersvoo | 3578 | |
11806 | schaersvoo | 3579 | case RESETOFFSET: |
7614 | schaersvoo | 3580 | /* |
11806 | schaersvoo | 3581 | @ resetoffset |
3582 | @ keyword ; use to restore text placement on the canvas to the real (x;y) coordinates of the left bottom corner of the text |
||
3583 | @ 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 |
||
7614 | schaersvoo | 3584 | */ |
11806 | schaersvoo | 3585 | use_offset = 0; |
3586 | break; |
||
3587 | |||
3588 | case ROTATE: |
||
3589 | /* |
||
3590 | @ rotate rotation_angle |
||
3591 | @ angle in degrees |
||
3592 | @ (only) the next object will be rotated is given angle |
||
3593 | @ positive values rotate counter clockwise |
||
14066 | bpr | 3594 | @ 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) |
3595 | @ 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> |
||
3596 | @ 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 |
||
13939 | bpr | 3597 | @%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% |
11806 | schaersvoo | 3598 | */ |
3599 | use_rotate = TRUE; |
||
14066 | bpr | 3600 | angle = -1*(get_real(infile,1));/* -1: to be compatible with Flydraw... */ |
7614 | schaersvoo | 3601 | break; |
11806 | schaersvoo | 3602 | case ROTATION_CENTER: |
9306 | schaersvoo | 3603 | /* |
11806 | schaersvoo | 3604 | @ rotationcenter x_center,y_center |
3605 | @ define an rotation center in your x/y-coordinate system |
||
3606 | @ wims will not check the validity of your input; use javascript console to debug any erors |
||
3607 | @ if not defined a rotation will be around the first point of an object |
||
3608 | @ to be used before command <a href="#rotate">rotate</a> |
||
3609 | @ all other commands will use this rotation center, unless a <a href="#killrotation">killrotation</a> is given |
||
13956 | schaersvoo | 3610 | @%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 |
13969 | schaersvoo | 3611 | @%rotationcenter_slider%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%fillcolor black%strokecolor yellow%rotationcenter 0,0%fontsize 24%slider 0,2*pi,400,30,angle degrees,rotate...%plot red,5*sin(x)%filled%linewidth 1%opacity 150,50%fillcolor orange%angle 0,0,pi,0,0,blue |
9306 | schaersvoo | 3612 | */ |
11806 | schaersvoo | 3613 | temp = get_string(infile,1); |
3614 | string_length = snprintf(NULL,0,"[ %s ]",temp); |
||
3615 | check_string_length(string_length); |
||
3616 | rotation_center = my_newmem(string_length+1); |
||
3617 | snprintf(rotation_center,string_length,"[%s]",temp); |
||
9306 | schaersvoo | 3618 | break; |
11806 | schaersvoo | 3619 | |
3620 | case SIZE: |
||
3621 | /* |
||
3622 | @ size width,height |
||
3623 | @ set canvas size in pixels |
||
14066 | bpr | 3624 | @ mandatory first command (can only be preceded by keyword <a href="#popup">popup</a>) |
3625 | @ 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 | 3626 | */ |
3627 | found_size_command = 1; |
||
14066 | bpr | 3628 | /* using fabs: however "xsize == int": so "xsize = abs( (int) get_real(infile,0))" would be the idea... */ |
11806 | schaersvoo | 3629 | xsize = (int)(fabs(round(get_real(infile,0)))); /* just to be sure that sizes > 0 */ |
3630 | ysize = (int)(fabs(round(get_real(infile,1)))); |
||
3631 | /* sometimes we want xrange / yrange to be in pixels...without telling x/y-range */ |
||
3632 | xmin = 0;xmax = xsize; |
||
3633 | ymin = 0;ymax = ysize; |
||
3634 | |||
3635 | /* |
||
3636 | The sequence in which stuff is finally printed is important !! |
||
3637 | */ |
||
3638 | fprintf(stdout,"\n\ |
||
13970 | obado | 3639 | <script>\n\ |
11806 | schaersvoo | 3640 | /*<![CDATA[*/\n\ |
3641 | if( typeof(wims_status) === 'undefined' ){ var wims_status = \"$status\";};\ |
||
3642 | if( typeof(use_dragdrop_reply) === 'undefined' ){ var use_dragdrop_reply = false;};\ |
||
3643 | if( typeof(canvas_scripts) === 'undefined' ){ var canvas_scripts = new Array();};\ |
||
3644 | canvas_scripts.push(\"%d\");\n/*]]>*/\n</script>\n\ |
||
3645 | ",canvas_root_id); |
||
3646 | |||
3647 | /* style=\"display:block;position:relative;margin-left:auto;margin-right:auto;margin-bottom:4px;\" */ |
||
3648 | if( use_tooltip != 2){ |
||
3649 | fprintf(stdout,"<!-- canvasdraw div -->\n\ |
||
3650 | <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\ |
||
3651 | <!-- tooltip and input placeholder -->\n\ |
||
3652 | <div id=\"tooltip_placeholder_div%d\" style=\"text-align:center\"><span id=\"tooltip_placeholder%d\" style=\"display:none;\"></span></div>\ |
||
3653 | <!-- include actual object code via include file -->\n\ |
||
13970 | obado | 3654 | <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 | 3655 | } |
3656 | else |
||
3657 | { |
||
3658 | /* |
||
14066 | bpr | 3659 | set canvas_div invisible and do not include placeholder in main html page: |
11806 | schaersvoo | 3660 | the js-include will also be in a popup window...to be shown when wims $status = done |
3661 | */ |
||
3662 | fprintf(stdout,"<!-- canvasdraw div invisible -->\n\ |
||
3663 | <div tabindex=\"0\" id=\"canvas_div%d\" style=\"display:none;position:relative;width:%dpx;height:%dpx;margin-left:auto;margin-right:auto;\" ></div>\n\ |
||
3664 | <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>\ |
||
3665 | <!-- include actual object code via include file -->\n\ |
||
13970 | obado | 3666 | <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 | 3667 | } |
3668 | |||
14071 | bpr | 3669 | /* these must be global...it is all really very poor javascript:( */ |
13970 | obado | 3670 | fprintf(js_include_file,"\n/* begin generated javascript include for canvasdraw */\n\ |
11806 | schaersvoo | 3671 | \"use strict\";\n\ |
13970 | obado | 3672 | /* these variables and functions must be global */\n\ |
11806 | schaersvoo | 3673 | var read_dragdrop%d;\ |
14038 | schaersvoo | 3674 | var read_canvas_images;\ |
11806 | schaersvoo | 3675 | var read_canvas%d;\ |
3676 | var set_clock;\ |
||
3677 | var clear_draw_area%d;\ |
||
3678 | var update_draw_area%d;\ |
||
14038 | schaersvoo | 3679 | var place_image_on_canvas;\ |
11806 | schaersvoo | 3680 | var draw_boxplot;\ |
3681 | var redraw_all%d;\ |
||
3682 | var userdraw_primitive;\n\ |
||
13970 | obado | 3683 | var wims_canvas_function%d = function(){\n/* common used stuff */\n\ |
11806 | schaersvoo | 3684 | var userdraw_x = [];var userdraw_y = [];var userdraw_radius = [];\n\ |
3685 | var xsize = %d;\ |
||
3686 | var ysize = %d;\ |
||
3687 | var precision = 100;\ |
||
3688 | var canvas_div = document.getElementById(\"canvas_div%d\");\ |
||
3689 | 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;};\ |
||
3690 | 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;};\ |
||
3691 | 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);};};\ |
||
3692 | 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);};};\ |
||
3693 | 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);};};\ |
||
3694 | 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);};};\ |
||
3695 | function scale_x_radius(rx){return rx*xsize/(xmax - xmin);};\ |
||
3696 | function scale_y_radius(ry){return ry*ysize/(ymax - ymin);};\ |
||
3697 | function distance(x1,y1,x2,y2){return Math.sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) );};\ |
||
3698 | 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) ));};\ |
||
3699 | 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;};\ |
||
3700 | function slide(obj,dx,dy){for(var p = 0 ; p < obj.x.length; p++){obj.x[p] = x2px(obj.xorg[p] + dx);obj.y[p] = y2px(obj.yorg[p] + dy);};return obj;};\ |
||
14044 | schaersvoo | 3701 | var isTouch = (('ontouchstart' in window) || (navigator.msMaxTouchPoints > 0));var snap_x = 1;var snap_y = 1;\ |
11806 | schaersvoo | 3702 | function snap_to_x(x){return x2px(snap_x*(Math.round((px2x(x))/snap_x)));};\ |
11890 | schaersvoo | 3703 | function snap_to_y(y){return y2px(snap_y*(Math.round((px2y(y))/snap_y)));};\ |
14044 | schaersvoo | 3704 | 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;default: return [x,y];break;};};\ |
11806 | schaersvoo | 3705 | var xlogbase = 10;\ |
3706 | var ylogbase = 10;\ |
||
3707 | var use_xlogscale = 0;\ |
||
3708 | var use_ylogscale = 0;\ |
||
11891 | schaersvoo | 3709 | var x_strings = {};var x_strings_up = [];\ |
11806 | schaersvoo | 3710 | var y_strings = null;\ |
3711 | var use_pan_and_zoom = 0;\ |
||
3712 | var use_jsmath = 0;\ |
||
3713 | var xstart = 0;\ |
||
3714 | var ystart = 0;\ |
||
3715 | var unit_x=\" \";\ |
||
3716 | var unit_y=\" \";\ |
||
14038 | schaersvoo | 3717 | var external_canvas = create_canvas%d(%d,xsize,ysize);",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); |
14066 | bpr | 3718 | /* default add the drag code: nearly always used ...*/ |
11806 | schaersvoo | 3719 | add_drag_code(js_include_file,DRAG_CANVAS,canvas_root_id); |
3720 | |||
3721 | break; |
||
3722 | |||
3723 | |||
3724 | case SEGMENT: |
||
7614 | schaersvoo | 3725 | /* |
11806 | schaersvoo | 3726 | @ segment x1,y1,x2,y2,color |
14071 | bpr | 3727 | @ alternative: <code>seg</code> |
3728 | @ draw a line segment between points (x1:y1)--(x2:y2) in color ''color`` |
||
11806 | schaersvoo | 3729 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
14061 | schaersvoo | 3730 | @%segment_onclick%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%onclick%segment 1,1,-9,3,green |
3731 | @%segment_drag_y%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%drag y%segment 1,1,-9,3,green |
||
7614 | schaersvoo | 3732 | */ |
11806 | schaersvoo | 3733 | for(i=0;i<5;i++) { |
7614 | schaersvoo | 3734 | switch(i){ |
11806 | schaersvoo | 3735 | case 0: double_data[0]= get_real(infile,0);break; /* x1-values */ |
3736 | case 1: double_data[1]= get_real(infile,0);break; /* y1-values */ |
||
3737 | case 2: double_data[2]= get_real(infile,0);break; /* x2-values */ |
||
3738 | case 3: double_data[3]= get_real(infile,0);break; /* y2-values */ |
||
3739 | case 4: stroke_color=get_color(infile,1);/* name or hex color */ |
||
3740 | decimals = find_number_of_digits(precision); |
||
14045 | schaersvoo | 3741 | fprintf(js_include_file,"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\",%d,%s,%d,%d,%s,%d,%d));\n",drag_type,click_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,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern); |
11806 | schaersvoo | 3742 | if(onclick > 0){click_cnt++;} |
3743 | /* click_cnt++; */ |
||
3744 | reset(); |
||
3745 | break; |
||
3746 | default: break; |
||
7614 | schaersvoo | 3747 | } |
3748 | } |
||
3749 | break; |
||
10953 | bpr | 3750 | |
11806 | schaersvoo | 3751 | case SEGMENTS: |
9213 | schaersvoo | 3752 | /* |
11806 | schaersvoo | 3753 | @ segments color,x1,y1,x2,y2,...,x_n,y_n |
14071 | bpr | 3754 | @ alternative: <code>segs</code> |
3755 | @ draw multiple segments between points (x1:y1)--(x2:y2).....and... (x_n-1:y_n-1)--(x_n:y_n) in color ''color`` |
||
3756 | @ use command ''linewidth int'' to adust size |
||
11806 | schaersvoo | 3757 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!) |
12111 | schaersvoo | 3758 | @%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 |
3759 | @%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 | 3760 | */ |
11806 | schaersvoo | 3761 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
3762 | fill_color = stroke_color; |
||
3763 | i=0; |
||
3764 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 3765 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
11806 | schaersvoo | 3766 | if(i%2 == 0 ){ |
3767 | double_data[i] = get_real(infile,0); /* x */ |
||
3768 | } |
||
3769 | else |
||
3770 | { |
||
3771 | double_data[i] = get_real(infile,1); /* y */ |
||
3772 | } |
||
3773 | i++; |
||
3774 | } |
||
3775 | decimals = find_number_of_digits(precision); |
||
3776 | for(c = 0 ; c < i-1 ; c = c+4){ |
||
14045 | schaersvoo | 3777 | fprintf(js_include_file,"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\",%d,%s,%d,%d,%s,%d,%d));\n",drag_type,click_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,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern); |
11806 | schaersvoo | 3778 | if(onclick > 0){click_cnt++;} |
3779 | /* click_cnt++;*/ |
||
3780 | } |
||
3781 | reset(); |
||
9213 | schaersvoo | 3782 | break; |
11806 | schaersvoo | 3783 | |
3784 | case SETLIMITS: |
||
9213 | schaersvoo | 3785 | /* |
11806 | schaersvoo | 3786 | @ setlimits |
14071 | bpr | 3787 | @ keyword: if set, it will produce 4 inputfields for ''xmin,xmax,ymin,ymax`` and an ''ok`` button |
11806 | schaersvoo | 3788 | @ may be used for inputfield based zooming / panning |
3789 | @ may be styled using command <a href="#inputstyle">inputstyle</a> |
||
14071 | bpr | 3790 | @ use commands <a href="#xlabel">xlabel / ylabel</a> to change text from xmin to ''xlabel`` etc |
11806 | schaersvoo | 3791 | @ note:the input value will not be checked on validity |
12107 | schaersvoo | 3792 | @%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 | 3793 | */ |
11806 | schaersvoo | 3794 | if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */ |
3795 | add_setlimits(js_include_file,canvas_root_id,font_size,input_style); |
||
3796 | /* add_setlimits provides 'fprintf(js_include_file,"use_pan_and_zoom = 1;");' */ |
||
3797 | use_pan_and_zoom = TRUE; |
||
3798 | done = TRUE; |
||
9213 | schaersvoo | 3799 | break; |
11806 | schaersvoo | 3800 | |
3801 | case SETPIXEL: |
||
9213 | schaersvoo | 3802 | /* |
11806 | schaersvoo | 3803 | @ setpixel x,y,color |
3804 | @ A rectangular "point" with diameter 1 pixel centered at (x:y) in xrange / yrange |
||
3805 | @ pixels can <b>not</b> be dragged or clicked |
||
14086 | bpr | 3806 | @ "pixelsize = 1" may be changed by command <code>pixelsize int</code> |
12107 | schaersvoo | 3807 | @%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 | 3808 | */ |
11806 | schaersvoo | 3809 | if( js_function[DRAW_PIXELS] != 1 ){ js_function[DRAW_PIXELS] = 1;} |
3810 | for(i=0;i<3;i++){ |
||
3811 | switch(i){ |
||
3812 | case 0: double_data[0] = get_real(infile,0); break; /* x */ |
||
14032 | schaersvoo | 3813 | case 1: double_data[1] = get_real(infile,0); break; /* y */ |
11806 | schaersvoo | 3814 | case 2: stroke_color = get_color(infile,1); |
3815 | string_length = snprintf(NULL,0,"draw_setpixel([%f],[%f],\"%s\",%.2f,%d);\n",double_data[0],double_data[1],stroke_color,stroke_opacity,pixelsize); |
||
3816 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
3817 | snprintf(tmp_buffer,string_length,"draw_setpixel([%f],[%f],\"%s\",%.2f,%d);\n",double_data[0],double_data[1],stroke_color,stroke_opacity,pixelsize); |
||
3818 | add_to_buffer(tmp_buffer); |
||
3819 | break; |
||
3820 | default:break; |
||
3821 | } |
||
3822 | } |
||
3823 | reset(); |
||
3824 | break; |
||
3825 | |||
3826 | |||
3827 | case SLIDER: |
||
9213 | schaersvoo | 3828 | /* |
14071 | bpr | 3829 | @ slider start_value,end_value,width px,height px,type,label |
3830 | @ ''<em>''type</em> may be: xy,x,y,angle |
||
11806 | schaersvoo | 3831 | @ if a slider value display is desired, use for argument <em>type</em>:<br />xy display<br />x display<br />y display<br />angle radian<br />angle degree |
14071 | bpr | 3832 | @ if a unit (or something like that...) for x/y-value display is needed, use commands ''xunit`` and / or ''yunit`` |
14066 | bpr | 3833 | @ if the translation should be performed using a function, use for type: xy function,x function,y function<br />use commands sliderfunction_x and/or sliderfunction_y before the slider command to define the functions<br />example:<br /><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 | 3834 | @ use command ''slider`` before draggable/clickable objects. |
14066 | bpr | 3835 | @ 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> |
14071 | bpr | 3836 | @ no slider for a math function, these can be traced using command ''trace_jscurve some_function_in_x`` |
3837 | @ 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 | 3838 | @ amount of sliders is not limited. |
14071 | bpr | 3839 | @ <code>javascript:read_dragdrop();</code> will return an array with ''object_number:slider_value`` |
3840 | @ type=xy: will produce a 2D ''slider`` [rectangle width x heigh px] in your web page |
||
11806 | schaersvoo | 3841 | @ every draggable object may have its own slider (no limit in amount of sliders) |
3842 | @ label: some slider text |
||
3843 | @ use fillcolor for slider ball |
||
3844 | @ use strokecolor for slider bar |
||
3845 | @ use fontfamily / fontcolor to set used fonts |
||
3846 | @ use opacity (only fill opacity will be used) to set transparency |
||
14071 | bpr | 3847 | @ the slider canvas will be added to the ''tooltip div``: so incompatible with command tooltip ; setlimits etc |
13950 | schaersvoo | 3848 | @%slider_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 degrees,Rotate arrow%arrow 0,0,4.5,0,8,red%opacity 200,100%frect -4,4,1,-1,blue%killslider%frect -4,4,1,-1,blue |
3849 | @%slider_x%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,x,move arrow%arrow 0,0,4.5,0,8,red%opacity 200,100%frect -4,4,1,-1,blue%killslider%frect -4,4,1,-1,blue%display x,red,12 |
||
13951 | schaersvoo | 3850 | @%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 degrees,Rotate arrow%arrow 0,0,4.5,0,8,red%killslider%opacity 200,100%slider -2,2,300,30,x,move blue rectangle%frect -4,4,1,-1,blue%killslider%slider -2,2,300,30,y,move green rectangle%frect -4,4,1,-1,green |
9213 | schaersvoo | 3851 | */ |
11806 | schaersvoo | 3852 | slider_cnt++;/* slider starts at 1 */ |
3853 | for(i=0; i<6 ; i++){ |
||
3854 | switch(i){ |
||
3855 | case 0: double_data[0] = get_real(infile,0);break; /* start value */ |
||
3856 | case 1: double_data[1] = get_real(infile,0);break; /* end value */ |
||
3857 | case 2: int_data[0] = (int)(get_real(infile,0));break; /* width */ |
||
3858 | case 3: int_data[1] = (int)(get_real(infile,0));break; /* height */ |
||
14066 | bpr | 3859 | case 4: temp = get_string_argument(infile,0); /* type: xy,x,y,angle */ |
11806 | schaersvoo | 3860 | if(strstr(temp,"xy")!= 0){ |
3861 | slider = 4; |
||
3862 | } |
||
3863 | else |
||
3864 | { |
||
3865 | if(strstr(temp,"x") != 0){ |
||
3866 | slider = 1; |
||
3867 | } |
||
3868 | else |
||
3869 | { |
||
3870 | if(strstr(temp,"y") != 0){ |
||
3871 | slider = 2; |
||
3872 | } |
||
3873 | else |
||
3874 | { |
||
3875 | if(strstr(temp,"angle") != 0){ /* angle diplay radian */ |
||
3876 | slider = 3; |
||
3877 | } |
||
3878 | else |
||
3879 | { |
||
3880 | canvas_error("slider can be of type: xy,x,y,angle,fun_x:fun_y"); |
||
3881 | } |
||
3882 | } |
||
3883 | } |
||
3884 | } |
||
3885 | if(strstr(temp,"display")!=0){ |
||
3886 | if( slider == 4 ){ /* show x:y */ |
||
3887 | use_slider_display = 1; /* show x xy values in canvas window */ |
||
3888 | } |
||
3889 | else |
||
3890 | { |
||
3891 | if( slider == 1 ){ /* show only x -values */ |
||
3892 | use_slider_display = 10; |
||
3893 | } |
||
3894 | else |
||
3895 | { |
||
3896 | use_slider_display = 11; /* show only y -values*/ |
||
3897 | } |
||
3898 | } |
||
3899 | } |
||
3900 | else |
||
3901 | { |
||
3902 | if(strstr(temp,"degree")!= 0){ |
||
3903 | use_slider_display = 2; /* show angle values in canvas window */ |
||
3904 | } |
||
3905 | else |
||
3906 | { |
||
3907 | if(strstr(temp,"radian")!=0){ |
||
3908 | use_slider_display = 3; /* show radian values in canvas window */ |
||
3909 | } |
||
3910 | } |
||
3911 | } |
||
3912 | if(use_slider_display != 0 && slider_cnt == 1){ /*add just once the display js-code */ |
||
3913 | add_slider_display(js_include_file,canvas_root_id,precision,font_size,font_color,stroke_opacity); |
||
3914 | } |
||
3915 | if(strstr(temp,"fun")!= 0){ |
||
3916 | if( use_js_math == FALSE){/* add this stuff only once...*/ |
||
3917 | add_to_js_math(js_include_file); use_js_math = TRUE; |
||
3918 | } |
||
3919 | fprintf(js_include_file,"var slider_function%d = {x:to_js_math('%s'),y:to_js_math('%s')};",slider_cnt,slider_function_x,slider_function_y); |
||
3920 | slider_function_x = "x";slider_function_y = "y";/* reset the functions for next slider...*/ |
||
3921 | } |
||
3922 | else |
||
3923 | { |
||
3924 | fprintf(js_include_file,"var slider_function%d = {x:'x',y:'y'};",slider_cnt); |
||
14071 | bpr | 3925 | /* we must define these, otherwise 'use strict' will cause an error */ |
11806 | schaersvoo | 3926 | } |
3927 | break; |
||
3928 | case 5: /* some string used for slider description */ |
||
3929 | if(slider == 4){ |
||
3930 | add_xyslider(js_include_file,canvas_root_id,double_data[0],double_data[1],int_data[0],int_data[1],slider,get_string_argument(infile,1),slider_cnt,stroke_color,fill_color,line_width,fill_opacity,font_family,font_color,use_slider_display); |
||
3931 | } |
||
3932 | else |
||
3933 | { |
||
3934 | add_slider(js_include_file,canvas_root_id,double_data[0],double_data[1],int_data[0],int_data[1],slider,get_string_argument(infile,1),slider_cnt,stroke_color,fill_color,line_width,fill_opacity,font_family,font_color,use_slider_display); |
||
3935 | } |
||
3936 | break; |
||
3937 | } |
||
3938 | } |
||
9213 | schaersvoo | 3939 | break; |
11806 | schaersvoo | 3940 | case SLIDER_X: |
9213 | schaersvoo | 3941 | /* |
11806 | schaersvoo | 3942 | @ sliderfunction_x some_function_in_x |
3943 | @ default value "x" |
||
3944 | @ the x-value of the slider object(s) will be calculated with this function. |
||
3945 | @ default is the x-slider value itself |
||
14071 | bpr | 3946 | @ only used by command ''slider`` |
11806 | schaersvoo | 3947 | @ define before a slider command ! |
9213 | schaersvoo | 3948 | */ |
11806 | schaersvoo | 3949 | slider_function_x = get_string(infile,1); |
3950 | break; |
||
3951 | case SLIDER_Y: |
||
3952 | slider_function_y = get_string(infile,1); |
||
3953 | /* |
||
3954 | @ sliderfunction_y some_function_in_y |
||
3955 | @ default value "y" |
||
3956 | @ the y-value of the slider object(s) will be calculated with this function. |
||
14071 | bpr | 3957 | @ only used by command ''slider`` |
11806 | schaersvoo | 3958 | @ define before a slider command ! |
3959 | */ |
||
3960 | break; |
||
3961 | case SGRAPH: |
||
3962 | /* |
||
3963 | @ sgraph xstart,ystart,xmajor,ymajor,xminor,yminor,majorgrid_color,minorgrid_color |
||
14071 | bpr | 3964 | @ primitive implementation of a ''broken scale`` graph... |
3965 | @ 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 | 3966 | @%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 | 3967 | */ |
3968 | if( js_function[DRAW_SGRAPH] != 1 ){ js_function[DRAW_SGRAPH] = 1;} |
||
3969 | for(i = 0 ; i < 8 ;i++){ |
||
3970 | switch(i){ |
||
3971 | case 0:double_data[0] = get_real(infile,0);break; |
||
3972 | case 1:double_data[1] = get_real(infile,0);break; |
||
3973 | case 2:double_data[2] = get_real(infile,0);break; |
||
3974 | case 3:double_data[3] = get_real(infile,0);break; |
||
3975 | case 4:int_data[0] = (int)(get_real(infile,0));break; |
||
3976 | case 5:int_data[1] = (int)(get_real(infile,0));break; |
||
3977 | case 6:stroke_color = get_color(infile,0);break; |
||
3978 | case 7:font_color = get_color(infile,1); |
||
3979 | string_length = snprintf(NULL,0,"xstart = %f;\nystart = %f;\ndraw_sgraph(%d,%d,%f,%f,%d,%d,\"%s\",\"%s\",\"%s\",%f,%d);\n",double_data[0],double_data[1],GRID_CANVAS,precision,double_data[2],double_data[3],int_data[0],int_data[1],stroke_color,font_color,font_family,stroke_opacity,font_size); |
||
3980 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
3981 | 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); |
||
3982 | add_to_buffer(tmp_buffer); |
||
3983 | break; |
||
3984 | default:break; |
||
3985 | } |
||
3986 | } |
||
3987 | /* sgraph(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily,opacity)*/ |
||
9213 | schaersvoo | 3988 | break; |
11806 | schaersvoo | 3989 | |
3990 | case SNAPTOFUNCTION: |
||
9213 | schaersvoo | 3991 | /* |
11806 | schaersvoo | 3992 | @ snaptofunction some_function_in_x,some_funtion_in_y |
14066 | bpr | 3993 | @ alternative: <code>snaptofun some_function_in_x,some_funtion_in_y</code> |
11806 | schaersvoo | 3994 | @ the next object will snap to the calculated values |
14071 | bpr | 3995 | @ note: snaptofun is probably not really useful feature... |
14066 | bpr | 3996 | @ if you want only modification of y-values,just use: <code>snaptofunction x,5*sin(1/y)</code> |
3997 | @ if you want only modification of x-values,just use: <code>snaptofunction 5*sin(1/x),y</code> |
||
14071 | bpr | 3998 | @ for now only one instance of ''snaptofunction`` is allowed |
11806 | schaersvoo | 3999 | @ use rawmath on your functions: no validity checking is done by wims ! |
14071 | bpr | 4000 | @ note: switching x and y coordinates? <code>snaptofunction y,x</code> |
13960 | bpr | 4001 | @%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 |
4002 | @%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 | 4003 | */ |
11806 | schaersvoo | 4004 | temp = get_string_argument(infile,0); |
14038 | schaersvoo | 4005 | use_snap = 2; |
11806 | schaersvoo | 4006 | if( use_js_math == FALSE){/* add this stuff only once...*/ |
4007 | add_to_js_math(js_include_file); use_js_math = TRUE; |
||
4008 | } |
||
4009 | 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)); |
||
4010 | break; |
||
4011 | case SNAPTOPOINTS: |
||
4012 | /* |
||
4013 | @ snaptopoints x1,y1,x2,y2,x3,y3.... |
||
4014 | @ a userdraw object will snap to these points. |
||
14071 | bpr | 4015 | @ the array size (e.g. the number of points) of command ''snaptopoints`` is limited by constant MAX_INT (canvasdraw.h) |
4016 | @ a draggable object (use command ''drag x|y|xy``) will snap to the closed of these points when dragged (mouseup) |
||
14078 | bpr | 4017 | @ other options: use keyword ''snaptogrid``, ''xsnaptogrid`` or ''ysnaptogrid`` |
13950 | schaersvoo | 4018 | @%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 | 4019 | */ |
4020 | i = 0; |
||
14038 | schaersvoo | 4021 | use_snap = 4; |
11806 | schaersvoo | 4022 | while( ! done ){ /* get next item until EOL*/ |
11997 | schaersvoo | 4023 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
11806 | schaersvoo | 4024 | if(i%2 == 0 ){ |
4025 | double_data[i] = get_real(infile,0); /* x */ |
||
4026 | } |
||
4027 | else |
||
4028 | { |
||
4029 | double_data[i] = get_real(infile,1); /* y */ |
||
4030 | } |
||
4031 | i++; |
||
4032 | } |
||
4033 | decimals = find_number_of_digits(precision); |
||
14044 | schaersvoo | 4034 | 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 | 4035 | break; |
4036 | |||
4037 | case SNAPTOGRID: |
||
4038 | /* |
||
4039 | @ snaptogrid |
||
4040 | @ keyword (no arguments required) |
||
14071 | bpr | 4041 | @ a draggable object (use command ''drag x|y|xy``) will snap to the given grid when dragged (mouseup) |
11806 | schaersvoo | 4042 | @ in case of userdraw the drawn points will snap to xmajor / ymajor grid |
14078 | bpr | 4043 | @ if no grid is defined, points will snap to every integer xrange/yrange value. (eg snap_x=1,snap_y=1) |
14071 | bpr | 4044 | @ if you do not want a visible grid, but you only want a ''snaptogrid`` with some value...define this grid with opacity 0. |
4045 | @ 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 | 4046 | @%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 |
4047 | @%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 | 4048 | */ |
14038 | schaersvoo | 4049 | use_snap = 1; |
11806 | schaersvoo | 4050 | break; |
4051 | |||
4052 | case SQUARE: |
||
4053 | /* |
||
14078 | bpr | 4054 | @ square x,y,side (px),color |
14071 | bpr | 4055 | @ draw a square with left top corner (x:y) with side ''side`` in color 'color' |
4056 | @ use command <code>fsquare x,y,side,color</code> for a filled square |
||
4057 | @ use command/keyword <a href='#filled'>filled</a> before command <code>square x,y,side,color</code> |
||
11806 | schaersvoo | 4058 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
12107 | schaersvoo | 4059 | @%square%size 400,400%xrange -10,10%yrange -10,10%linewidth 3%filled%fillcolor blue%square 0,0,120,green |
11806 | schaersvoo | 4060 | */ |
11991 | schaersvoo | 4061 | for(i=0;i<4;i++){ |
11806 | schaersvoo | 4062 | switch(i){ |
4063 | case 0:double_data[0] = get_real(infile,0);break; /* x1-values */ |
||
4064 | case 1:double_data[1] = get_real(infile,0);break; /* y1-values */ |
||
11991 | schaersvoo | 4065 | case 2:double_data[2] = get_real(infile,0);break; /* width in px */ |
4066 | case 3:stroke_color = get_color(infile,1);/* name or hex color */ |
||
4067 | decimals = find_number_of_digits(precision); |
||
4068 | double_data[3] = double_data[0] + (xmax - xmin)*double_data[2]/xsize; |
||
4069 | double_data[4] = double_data[1] + -1*(ymax - ymin)*double_data[2]/ysize; |
||
14045 | schaersvoo | 4070 | fprintf(js_include_file,"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\",%d,%s,%d,%d,%s,%d,%d));\n",drag_type,click_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,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern); |
11991 | schaersvoo | 4071 | if(onclick > 0){click_cnt++;}/* click_cnt++; */ |
4072 | reset();break; |
||
4073 | default: break; |
||
11806 | schaersvoo | 4074 | } |
4075 | } |
||
9213 | schaersvoo | 4076 | break; |
13829 | bpr | 4077 | |
11806 | schaersvoo | 4078 | case STATUS: |
9213 | schaersvoo | 4079 | /* |
11806 | schaersvoo | 4080 | @ status |
4081 | @ keyword |
||
14066 | bpr | 4082 | @ alernative: nostatus |
14078 | bpr | 4083 | @ used to override the effects of ''status=done`` in wims (answer.phtml) |
14071 | bpr | 4084 | @ affects ''readonly`` in inputfields / textareas in canvasimage and all userdraw based commands |
4085 | @ 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 | 4086 | */ |
11806 | schaersvoo | 4087 | |
4088 | fprintf(js_include_file,"\nwims_status=\"waiting\";\n"); |
||
9213 | schaersvoo | 4089 | break; |
11806 | schaersvoo | 4090 | |
4091 | case STRING: |
||
9213 | schaersvoo | 4092 | /* |
11806 | schaersvoo | 4093 | @ string color,x,y,the text string |
14078 | bpr | 4094 | @ may be set ''onclick`` or ''drag xy`` |
14071 | bpr | 4095 | @ unicode supported: <code>string red,0,0,\\u2232</code> |
4096 | @ use a command like <code>fontfamily italic 24px Ariel</code> to set fonts on browser that support font change |
||
12311 | schaersvoo | 4097 | @%string%size 400,400%xrange -10,10%yrange -10,10%fontfamily 14px Ariel%crosshair -3,-3,red%crosshair 3,3,blue%string red,-3,-3,Hello World%fontfamily Italic 18px Ariel%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 | 4098 | */ |
11806 | schaersvoo | 4099 | for(i=0;i<5;i++){ |
4100 | switch(i){ |
||
4101 | case 0: stroke_color = get_color(infile,0);break;/* name or hex color */ |
||
4102 | case 1: double_data[0] = get_real(infile,0);break; /* x in xrange*/ |
||
4103 | case 2: double_data[1] = get_real(infile,0);break; /* y in yrange*/ |
||
4104 | case 3: decimals = find_number_of_digits(precision); |
||
4105 | temp = get_string_argument(infile,1); |
||
4106 | decimals = find_number_of_digits(precision); |
||
14045 | schaersvoo | 4107 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,14,[%.*f],[%.*f],[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d,%d));\n",drag_type,click_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,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern); |
11806 | schaersvoo | 4108 | if(onclick > 0){click_cnt++;} |
14038 | schaersvoo | 4109 | onclick = 0; |
4110 | use_offset = 0; |
||
4111 | reset();; |
||
11806 | schaersvoo | 4112 | break; |
4113 | default:break; |
||
4114 | } |
||
9213 | schaersvoo | 4115 | } |
4116 | break; |
||
11806 | schaersvoo | 4117 | |
4118 | case STRINGUP: |
||
9213 | schaersvoo | 4119 | /* |
11806 | schaersvoo | 4120 | @ stringup color,x,y,rotation_degrees,the text string |
14078 | bpr | 4121 | @ can <b>not</b> be set ''onclick`` or ''drag xy`` (because of translation matrix...mouse incompatible) |
14071 | bpr | 4122 | @ unicode supported: <code>stringup red,0,0,45,\\u2232</code> |
4123 | @ use a command like <code>fontfamily bold 34px Courier</code> to set fonts on browser that support font change |
||
4124 | @ 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) |
||
12311 | schaersvoo | 4125 | @%stringup%size 400,400%xrange -10,10%yrange -10,10%fontfamily 14px Ariel%crosshair -3,0,red%crosshair 3,0,blue%stringup red,-3,0,-90,Hello World%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 | 4126 | |
9213 | schaersvoo | 4127 | */ |
14066 | bpr | 4128 | if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;} /* can not be added to shape library: rotate / mouse issues */ |
11806 | schaersvoo | 4129 | for(i=0;i<6;i++){ |
4130 | switch(i){ |
||
4131 | case 0: font_color = get_color(infile,0);break;/* name or hex color */ |
||
4132 | case 1: int_data[0] = x2px(get_real(infile,0));break; /* x */ |
||
4133 | case 2: int_data[1] = y2px(get_real(infile,0));break; /* y */ |
||
4134 | case 3: double_data[0] = get_real(infile,0);break;/* rotation */ |
||
4135 | case 4: decimals = find_number_of_digits(precision); |
||
4136 | temp = get_string_argument(infile,1); |
||
11811 | schaersvoo | 4137 | string_length = snprintf(NULL,0,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,%.2f,\"%s\",%d,%.2f,%d,%s,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],font_size,font_family,font_color,stroke_opacity,double_data[0],temp,use_rotate,angle,use_affine,affine_matrix,use_offset); |
11806 | schaersvoo | 4138 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
11811 | schaersvoo | 4139 | snprintf(tmp_buffer,string_length,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,%.2f,\"%s\",%d,%.2f,%d,%s,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],font_size,font_family,font_color,stroke_opacity,double_data[0],temp,use_rotate,angle,use_affine,affine_matrix,use_offset); |
11806 | schaersvoo | 4140 | add_to_buffer(tmp_buffer); |
14038 | schaersvoo | 4141 | use_offset=0; |
4142 | reset(); |
||
11806 | schaersvoo | 4143 | break; |
4144 | default:break; |
||
4145 | } |
||
9213 | schaersvoo | 4146 | } |
4147 | break; |
||
11767 | schaersvoo | 4148 | |
11806 | schaersvoo | 4149 | case STYLE: |
11767 | schaersvoo | 4150 | /* |
11806 | schaersvoo | 4151 | @ highlight color,opacity,linewidth |
4152 | @ NOT IMPLEMENTED |
||
14071 | bpr | 4153 | @ use command ''onclick``: when the object receives a userclick it will increase its linewidth |
11767 | schaersvoo | 4154 | */ |
4155 | break; |
||
11806 | schaersvoo | 4156 | |
4157 | |||
4158 | case STROKECOLOR: |
||
9213 | schaersvoo | 4159 | /* |
11806 | schaersvoo | 4160 | @ strokecolor colorname or #hex |
14071 | bpr | 4161 | @ to be used for commands that do not supply a color argument (like command ''linegraph``) |
9213 | schaersvoo | 4162 | */ |
11806 | schaersvoo | 4163 | stroke_color = get_color(infile,1); |
9213 | schaersvoo | 4164 | break; |
11806 | schaersvoo | 4165 | |
4166 | case FLY_TEXT: |
||
9213 | schaersvoo | 4167 | /* |
11806 | schaersvoo | 4168 | @ text fontcolor,x,y,font,text_string |
14066 | bpr | 4169 | @ font may be described by keywords: giant,huge,normal,small,tiny |
14071 | bpr | 4170 | @ use command ''fontsize`` to increase base fontsize for these keywords |
14086 | bpr | 4171 | @ may be set ''onclick`` or ''drag xy`` |
11806 | schaersvoo | 4172 | @ backwards compatible with flydraw |
4173 | @ unicode supported: text red,0,0,huge,\\u2232 |
||
14071 | bpr | 4174 | @ use command ''string`` combined with ''fontfamily`` for a more fine grained control over html5 canvas text element |
14086 | bpr | 4175 | @ Avoid mixing old flydraw commands ''text``, ''textup`` with new canvasdraw commands ''string``, ''stringup``. If the fontfamily was set completely like <code>fontfamily italic 24px Ariel</code>. In that case reset ''fontfamily`` to something lke ''fontfamily Ariel`` before the old flydraw commands. |
12311 | schaersvoo | 4176 | @%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 | 4177 | */ |
11806 | schaersvoo | 4178 | for(i = 0; i < 5 ;i++){ |
4179 | switch(i){ |
||
4180 | case 0: stroke_color = get_color(infile,0);break;/* font_color == stroke_color name or hex color */ |
||
4181 | case 1: double_data[0] = get_real(infile,0);break; /* x */ |
||
4182 | case 2: double_data[1] = get_real(infile,0);break; /* y */ |
||
4183 | case 3: fly_font = get_string_argument(infile,0); |
||
4184 | if(strcmp(fly_font,"giant") == 0){ |
||
4185 | fly_font_size = (int)(font_size + 24); |
||
4186 | } |
||
4187 | else |
||
4188 | { |
||
4189 | if(strcmp(fly_font,"huge") == 0){ |
||
4190 | fly_font_size = (int)(font_size + 14); |
||
4191 | } |
||
4192 | else |
||
4193 | { |
||
4194 | if(strcmp(fly_font,"large") == 0){ |
||
4195 | fly_font_size = (int)(font_size + 6); |
||
4196 | } |
||
4197 | else |
||
4198 | { |
||
4199 | if(strcmp(fly_font,"small") == 0){ |
||
4200 | fly_font_size = (int)(font_size - 4); |
||
4201 | if(fly_font_size<0){fly_font_size = 8;} |
||
4202 | } |
||
4203 | } |
||
4204 | } |
||
4205 | } |
||
4206 | break; |
||
4207 | case 4: |
||
4208 | temp = get_string_argument(infile,1); |
||
4209 | decimals = find_number_of_digits(precision); |
||
14045 | schaersvoo | 4210 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,14,[%.*f],[%.*f],[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%f,\"%s\",%d,%s,%d,%s,%d,%d,%s,%d,%d));\n",drag_type,click_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",use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern); |
11806 | schaersvoo | 4211 | if(onclick > 0){click_cnt++;} |
14038 | schaersvoo | 4212 | onclick=0; |
4213 | use_offset = 0; |
||
11806 | schaersvoo | 4214 | reset(); |
4215 | break; |
||
4216 | default:break; |
||
4217 | } |
||
10953 | bpr | 4218 | } |
9213 | schaersvoo | 4219 | break; |
11806 | schaersvoo | 4220 | case TEXTAREA: |
9289 | schaersvoo | 4221 | /* |
11806 | schaersvoo | 4222 | @ textarea x,y,cols,rows,readonly,value |
14066 | bpr | 4223 | @ may be further controlled by <a href="#inputstyle">inputstyle</a> |
14078 | bpr | 4224 | @ 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 | 4225 | @ 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 | 4226 | @ keyword ''xoffset | centered`` is not active for command ''textarea`` |
12107 | schaersvoo | 4227 | @%textarea%size 400,400%xrange -10,10%yrange -10,10%inputstyle color:red;background-color:lightblue;font-size:14px;text-align:center%textarea -3,-2,6,3,1,?%inputstyle color:blue;background-color:yellow;font-size:14px;text-align:center%textarea 0,-2,8,2,1,? |
9289 | schaersvoo | 4228 | */ |
11806 | schaersvoo | 4229 | if( js_function[DRAW_TEXTAREAS] != 1 ){ js_function[DRAW_TEXTAREAS] = 1;} |
4230 | for(i = 0 ; i<6;i++){ |
||
9289 | schaersvoo | 4231 | switch(i){ |
11806 | schaersvoo | 4232 | case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in px */ |
4233 | case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in px */ |
||
4234 | case 2: int_data[2]=abs( (int)(get_real(infile,0)));break;/* cols */ |
||
4235 | case 3: int_data[3]=abs( (int)(get_real(infile,0)));break;/* rows */ |
||
4236 | case 4: if( get_real(infile,1) >0){int_data[4] = 1;}else{int_data[3] = 0;};break; /* readonly */ |
||
4237 | case 5: temp = get_string_argument(infile,1); |
||
4238 | string_length = snprintf(NULL,0, "draw_textareas(%d,%d,%d,%d,%d,%d,%d,\"%s\",\"%s\");\n",canvas_root_id,input_cnt,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],input_style,temp); |
||
4239 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
4240 | snprintf(tmp_buffer,string_length,"draw_textareas(%d,%d,%d,%d,%d,%d,%d,\"%s\",\"%s\");\n",canvas_root_id,input_cnt,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],input_style,temp); |
||
4241 | add_to_buffer(tmp_buffer); |
||
4242 | input_cnt++;break; |
||
9289 | schaersvoo | 4243 | default: break; |
4244 | } |
||
4245 | } |
||
11806 | schaersvoo | 4246 | if(reply_format == 0 ){reply_format = 15;} |
4247 | reset(); |
||
9289 | schaersvoo | 4248 | break; |
11806 | schaersvoo | 4249 | |
11830 | schaersvoo | 4250 | case TEXTFILL: |
4251 | /* |
||
4252 | @ textfill x0,y0,color,some_text |
||
4253 | @ x0,y0 in xrange / yrange |
||
4254 | @ color will be used for the font color |
||
4255 | @ use command <a href="#fontfamily">fontfamily</a> to set font type and size |
||
13829 | bpr | 4256 | @ there is also a command <a href="#userdraw">userdraw textfill,color,some_text</a> |
13951 | schaersvoo | 4257 | @%textfill%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%fontfamily 24pt Ariel%circles red,0,0,3,3,3,6%textfill 4,4,blue,HELLO WORLD |
11830 | schaersvoo | 4258 | */ |
4259 | |||
4260 | js_function[DRAW_TEXTFILL] = 1; |
||
4261 | if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */ |
||
4262 | js_function[DRAW_FILLTOBORDER] = 1; |
||
4263 | add_js_filltoborder(js_include_file,canvas_root_id,canvas_type); |
||
4264 | } |
||
4265 | decimals = find_number_of_digits(precision); |
||
4266 | for(i=0;i<4;i++){ |
||
4267 | switch(i){ |
||
4268 | case 0: double_data[0] = get_real(infile,0); break; /* x in px */ |
||
4269 | case 1: double_data[1] = get_real(infile,0); break; /* y in py */ |
||
13829 | bpr | 4270 | case 2: font_color = get_color(infile,0); break; |
11830 | schaersvoo | 4271 | case 3: temp = get_string(infile,1); |
4272 | string_length = 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); |
||
4273 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
||
4274 | 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); |
||
4275 | add_to_buffer(tmp_buffer); |
||
4276 | fill_cnt++; |
||
4277 | break; |
||
4278 | default:break; |
||
4279 | } |
||
4280 | } |
||
4281 | reset(); |
||
4282 | break; |
||
4283 | |||
4284 | |||
11806 | schaersvoo | 4285 | case FLY_TEXTUP: |
9289 | schaersvoo | 4286 | /* |
11806 | schaersvoo | 4287 | @ textup fontcolor,x,y,font,text_string |
14078 | bpr | 4288 | @ can <b>not</b> be set ''onclick`` or ''drag xy`` (because of translaton matrix...mouse incompatible) |
14066 | bpr | 4289 | @ font may be described by keywords: giant,huge,normal,small,tiny |
14071 | bpr | 4290 | @ use command ''fontsize`` to increase base fontsize for the keywords |
11806 | schaersvoo | 4291 | @ backwards compatible with flydraw |
4292 | @ unicode supported: textup red,0,0,huge,\\u2232 |
||
14071 | bpr | 4293 | @ use command ''stringup`` and ''fontfamily`` for a more fine grained control over html5 canvas text element |
14086 | bpr | 4294 | @ Avoid mixing old flydraw commands ''text``, ''textup`` with new canvasdraw commands ''string``; ''stringup``. If the fontfamily was set completely like <code>fontfamily italic 24px Ariel</code>. In that case reset ''fontfamily`` to something like ''fontfamily Ariel`` before the old flydraw commands. |
9289 | schaersvoo | 4295 | */ |
11806 | schaersvoo | 4296 | if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;} |
4297 | for(i = 0; i<5 ;i++){ |
||
9289 | schaersvoo | 4298 | switch(i){ |
11806 | schaersvoo | 4299 | case 0: font_color = get_color(infile,0);break;/* name or hex color */ |
4300 | case 1: int_data[0] = x2px(get_real(infile,0));break; /* x */ |
||
4301 | case 2: int_data[1] = y2px(get_real(infile,0));break; /* y */ |
||
4302 | case 3: fly_font = get_string_argument(infile,0); |
||
4303 | if(strcmp(fly_font,"giant") == 0){ |
||
4304 | fly_font_size = (int)(font_size + 24); |
||
4305 | } |
||
4306 | else |
||
4307 | { |
||
4308 | if(strcmp(fly_font,"huge") == 0){ |
||
4309 | fly_font_size = (int)(font_size + 14); |
||
4310 | } |
||
4311 | else |
||
4312 | { |
||
4313 | if(strcmp(fly_font,"large") == 0){ |
||
4314 | fly_font_size = (int)(font_size + 6); |
||
4315 | } |
||
4316 | else |
||
4317 | { |
||
4318 | if(strcmp(fly_font,"small") == 0){ |
||
4319 | fly_font_size = (int)(font_size - 4); |
||
4320 | if(fly_font_size<0){fly_font_size = 8;} |
||
4321 | } |
||
4322 | } |
||
4323 | } |
||
4324 | } |
||
4325 | break; |
||
4326 | case 4: |
||
9289 | schaersvoo | 4327 | decimals = find_number_of_digits(precision); |
11806 | schaersvoo | 4328 | temp = get_string_argument(infile,1); |
11811 | schaersvoo | 4329 | string_length = snprintf(NULL,0,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,90,\"%s\",%d,%.2f,%d,%s,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],fly_font_size,"null",font_color,stroke_opacity,temp,use_rotate,angle,use_affine,affine_matrix,use_offset); |
9289 | schaersvoo | 4330 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
11811 | schaersvoo | 4331 | snprintf(tmp_buffer,string_length,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,90,\"%s\",%d,%.2f,%d,%s,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],fly_font_size,"null",font_color,stroke_opacity,temp,use_rotate,angle,use_affine,affine_matrix,use_offset); |
9289 | schaersvoo | 4332 | add_to_buffer(tmp_buffer); |
14038 | schaersvoo | 4333 | reset();use_offset = 0; |
9289 | schaersvoo | 4334 | break; |
11806 | schaersvoo | 4335 | default:break; |
4336 | } |
||
4337 | } |
||
4338 | break; |
||
4339 | |||
4340 | |||
4341 | case TRACE_JSCURVE: |
||
4342 | /* |
||
4343 | @ trace_jscurve some_math_function |
||
4344 | @ will use a crosshair to trace the jsmath curve |
||
4345 | @ two inputfields will display the current x/y-values (numerical evaluation by javascript) |
||
14071 | bpr | 4346 | @ 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 |
11806 | schaersvoo | 4347 | @ use commands fontsize and inputstyle to format the fonts for labels and inputfields. |
14071 | bpr | 4348 | @ use commands ''linewidth, strokecolor, crosshairsize`` to adjust the corsshair. |
4349 | @ 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...) |
||
4350 | @ be aware that the formulas of the plotted function(s) can be found in the page javascript source |
||
13959 | bpr | 4351 | @%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%inputstyle 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 | 4352 | */ |
4353 | if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;} |
||
4354 | if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;} |
||
4355 | if( use_js_math == FALSE){ |
||
4356 | add_to_js_math(js_include_file); |
||
4357 | use_js_math = TRUE; |
||
4358 | } |
||
4359 | add_trace_js_mouse(js_include_file,TRACE_CANVAS,canvas_root_id,stroke_color,get_string(infile,1),font_size,stroke_opacity,line_width,crosshair_size,input_style); |
||
4360 | break; |
||
4361 | |||
4362 | |||
4363 | case TRANGE: |
||
4364 | /* |
||
4365 | @ trange tmin,tmax |
||
14071 | bpr | 4366 | @ alternative: <code>ranget</code> |
11806 | schaersvoo | 4367 | @ default -2,2 |
4368 | */ |
||
4369 | use_parametric = TRUE; |
||
4370 | for(i = 0 ; i<2; i++){ |
||
4371 | switch(i){ |
||
4372 | case 0: tmin = get_real(infile,0);break; |
||
4373 | case 1: tmax = get_real(infile,1);break; |
||
9289 | schaersvoo | 4374 | default: break; |
4375 | } |
||
4376 | } |
||
14066 | bpr | 4377 | if(tmin >= tmax ){canvas_error(" trange is not OK: tmin < tmax!\n");} |
9289 | schaersvoo | 4378 | break; |
11806 | schaersvoo | 4379 | case TRANSLATION: |
4380 | /* |
||
4381 | @ translation tx,ty |
||
14071 | bpr | 4382 | @ alternative: <code>translate</code> |
11806 | schaersvoo | 4383 | @ will translate the next objects tx in xrange and ty in yrange |
14071 | bpr | 4384 | @ use command ''killtranstation`` to end the command |
13958 | schaersvoo | 4385 | @%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 | 4386 | */ |
4387 | for(i = 0 ; i<2;i++){ |
||
4388 | switch(i){ |
||
4389 | case 0: double_data[0] = get_real(infile,0);break; |
||
4390 | case 1: double_data[1] = get_real(infile,1); |
||
4391 | use_affine = TRUE; |
||
4392 | decimals = find_number_of_digits(precision); |
||
4393 | string_length = snprintf(NULL,0, "[1,0,0,1,%.*f,%.*f] ",decimals,double_data[0]*xsize/(xmax - xmin),decimals,-1*double_data[1]*ysize/(ymax - ymin)); |
||
4394 | check_string_length(string_length);affine_matrix = my_newmem(string_length+1); |
||
4395 | snprintf(affine_matrix,string_length,"[1,0,0,1,%.*f,%.*f] ",decimals,double_data[0]*xsize/(xmax - xmin),decimals,-1*double_data[1]*ysize/(ymax - ymin)); |
||
4396 | break; |
||
4397 | default: break; |
||
4398 | } |
||
4399 | } |
||
4400 | break; |
||
4401 | |||
4402 | case TRIANGLE: |
||
4403 | /* |
||
4404 | @ triangle x1,y1,x2,y2,x3,y3,color |
||
14066 | bpr | 4405 | @ use ftriangle or keyword <a href='#filled'>filled</a> for a solid triangle |
11806 | schaersvoo | 4406 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
13948 | schaersvoo | 4407 | @%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 | 4408 | */ |
4409 | for(i=0;i<7;i++){ |
||
4410 | switch(i){ |
||
4411 | case 0: double_data[0] = get_real(infile,0);break; /* x */ |
||
4412 | case 1: double_data[1] = get_real(infile,0);break; /* y */ |
||
4413 | case 2: double_data[2] = get_real(infile,0);break; /* x */ |
||
4414 | case 3: double_data[3] = get_real(infile,0);break; /* y */ |
||
4415 | case 4: double_data[4] = get_real(infile,0);break; /* x */ |
||
4416 | case 5: double_data[5] = get_real(infile,0);break; /* y */ |
||
4417 | case 6: stroke_color = get_color(infile,1);/* name or hex color */ |
||
4418 | decimals = find_number_of_digits(precision); |
||
14045 | schaersvoo | 4419 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,5,%s,[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d,%d));\n",drag_type,click_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,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern); |
11806 | schaersvoo | 4420 | if(onclick > 0){click_cnt++;} |
4421 | /* click_cnt++;*/ |
||
4422 | reset(); |
||
4423 | break; |
||
4424 | default: break; |
||
4425 | } |
||
4426 | } |
||
4427 | break; |
||
4428 | case TRIANGLES: |
||
4429 | /* |
||
4430 | @ triangles color,x1,y1,x2,y2,x3,y3,... |
||
14066 | bpr | 4431 | @ use ftriangles or keyword <a href='#filled'>filled</a> for solid triangles |
11806 | schaersvoo | 4432 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!) |
13948 | schaersvoo | 4433 | @%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 | 4434 | */ |
4435 | stroke_color = get_color(infile,0);/* name or hex color */ |
||
4436 | i = 0; |
||
4437 | decimals = find_number_of_digits(precision); |
||
4438 | while( ! done ){ |
||
11997 | schaersvoo | 4439 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
11806 | schaersvoo | 4440 | double_data[0] = get_real(infile,0); /* x1 */ |
4441 | double_data[1] = get_real(infile,0); /* y1 */ |
||
4442 | double_data[2] = get_real(infile,0); /* x2 */ |
||
4443 | double_data[3] = get_real(infile,0); /* y2 */ |
||
4444 | double_data[4] = get_real(infile,0); /* x3 */ |
||
4445 | double_data[5] = get_real(infile,1); /* y3 */ |
||
14045 | schaersvoo | 4446 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,5,%s,[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d,%d));\n",drag_type,click_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,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern); |
11806 | schaersvoo | 4447 | if(onclick > 0){click_cnt++;} |
4448 | i = i + 6; |
||
4449 | } |
||
4450 | reset(); |
||
4451 | break; |
||
4452 | case USERBOXPLOT: |
||
4453 | /* |
||
4454 | @ userboxplot |
||
4455 | @ keyword, no arguments |
||
14066 | bpr | 4456 | @ use before command <a href="#boxplot">boxplot x_or_y,box-height_or_box-width,x_or_y-position</a> |
14071 | bpr | 4457 | @ if set, the student will have to calculate "min,Q1,median,Q3,max" and feed these data into the ''draw_boxplot`` function |
4458 | @ 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 | 4459 | */ |
4460 | if( js_function[DRAW_BOXPLOT] != 1 ){ js_function[DRAW_BOXPLOT] = 1;} |
||
4461 | fprintf(js_include_file,"var boxplot_source = 3;\n"); |
||
4462 | js_function[DRAW_JSBOXPLOT] = 2; |
||
4463 | break; |
||
4464 | |||
4465 | case USERBOXPLOTDATA: |
||
4466 | /* |
||
4467 | @ userboxplotdata |
||
4468 | @ keyword, no arguments |
||
14066 | bpr | 4469 | @ use before command <a href="#boxplot">boxplot x_or_y,box-height_or_box-width,x_or_y-position</a> |
14071 | bpr | 4470 | @ if set, the student will have to generate some statistical data. These data should be put in a named array ''student_boxplot_data`` |
14078 | bpr | 4471 | @ ''min,Q1,median,Q3,max`` are calculated by a js-function and the 'draw_boxplot' function will draw a boxplot. |
14066 | bpr | 4472 | @ see command <a href="#userboxplot">userboxplot</a> for calling 'draw_boxplot()' |
11806 | schaersvoo | 4473 | */ |
4474 | if( js_function[DRAW_BOXPLOT] != 1 ){ js_function[DRAW_BOXPLOT] = 1;} |
||
4475 | fprintf(js_include_file,"var boxplot_source = 2;\n"); |
||
4476 | js_function[DRAW_JSBOXPLOT] = 1; |
||
4477 | |||
4478 | break; |
||
4479 | |||
7614 | schaersvoo | 4480 | case USERDRAW: |
4481 | /* |
||
4482 | @ userdraw object_type,color |
||
9213 | schaersvoo | 4483 | @ only a single object_type is allowed. |
14066 | bpr | 4484 | @ for multiple different 'userdraw' objects in an exercise, use command <a href="#multidraw">multidraw</a> |
14071 | bpr | 4485 | @ 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> or <a href='#multifillcolors'>multifillcolors color1,color2,color_3,...</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</li><li>arc</li><li>arcs</li><li>input<br/>place a single inputfield on ''canvas`` <br />use commands 'inputstyle' for css styling: use command ''linewidth`` for adjusting the input field size (default 1)</li><li>inputs<br/>place multiple inputfield: placing inputfields on top of each other is not possible</li></ul> |
14078 | bpr | 4486 | @ 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) |
4487 | @ note: object_type text: Any string or multiple strings may be placed anywhere on the canvas.<br />''backspace / delete / esc`` will remove typed text if the mouse is clicked on the text.<br />You will need to hit ''enter`` to add the text to the array ''userdraw_txt``<br />Placing the cursor somewhere on a typed text and hitting ''delete/backspace/esc``, a confirm will popup asking to delete the selected text. This text will be removed from the ''userdraw_txt()`` answer array.<br />Use commands ''fontsize`` and ''fontfamily`` to control the text appearance |
||
11088 | schaersvoo | 4488 | @ note: object_type polygone: Will be finished (the object is closed) when clicked on the first point of the polygone again. |
14066 | bpr | 4489 | @ 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.which != 1: all buttons but left) |
14071 | bpr | 4490 | @ use a prefix <a href='#filled'>filled</a> or ''f`` to set fillable objects filled. (fcircles,filledcircles etc) |
11839 | schaersvoo | 4491 | @ for non solid filling, use command <a href="#fillpattern">fillpattern grid,hatch,diamond,dot</a> |
14071 | bpr | 4492 | @ use <a href='#opacity'>opacity int,int</a> and <a href='#fillcolor'>fillcolor color</a> to trigger coloured filling of fillable objects |
14078 | bpr | 4493 | @ use command ''dashed`` and/or ''dashtype int,int`` to trigger dashing |
4494 | @ use command ''replyformat int`` to control / adjust output formatting of javascript function read_canvas(); (the defaults should be fine...) |
||
14071 | bpr | 4495 | @ may be combined with onclick or drag xy of other components of flyscript objects (although not very useful...) |
14066 | bpr | 4496 | @ may be combined with keyword <a href='#userinput_xy'>userinput_xy</a> |
4497 | @ may be combined width the <a href='#snaptogrid'>snaptogrid snaptopoints </a> etc, to simplify the checking of the student reply |
||
13956 | schaersvoo | 4498 | @ the cursor may be appropriately styled using command <a href='cursor'>cursor</a> |
11088 | schaersvoo | 4499 | @ 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... |
14071 | bpr | 4500 | @ 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) |
14078 | bpr | 4501 | @ note: a special case is ''userdraw images,boguscolor``. Images (bitmap or svg) present in the exercise page and the img-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 /> On Gecko browsers there is an option to include MathML from the page onto the canvas, when the MathML code is embedded in a foreignObject,a div and an svg with size 1px, like in:<br /><code><svg xmlns="http://www.w3.org/2000/svg" width="1px" height="1px" onclick="javascript:place_image_on_canvas(this.id);" id='my_id'><br /><foreignObject width="100%" height="100%"><br /><div xmlns="http://www.w3.org/1999/xhtml" style="display:inline-block;width:auto;text-align: center;" > MATHML </div><br /></foreignObject><br /></svg></code><br />To resize and used the svg element, a small piece of javascript is needed...<br /><code>function resize_svg_mathml( mythings ){<br /> var len = mythings.length;<br />for(var p=0; p< len; p=p+2){<br /> var svg = document.getElementById(mythings[p]);<br />var div = document.getElementById(mythings[p+1]);<br />var w = parseInt(getComputedStyle(div).width);<br />var h = parseInt(getComputedStyle(div).height);<br />svg.setAttribute("height", h+'px');<br />svg.setAttribute("width", w+'px');<br />};<br />};<br /><br /> var mythings = [ array_with_image_ids ];<br />resize_svg_mathml(mythings);</code> |
12107 | schaersvoo | 4502 | @%userdraw_canvastype_a%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%snaptogrid%replyformat 10%colorpalette orange,yellow,red,green,lightgreen,blue,lightblue,cyan%canvastype 4%userdraw clickfill,blue%clearbutton REMOVE LAST RECTANGLE |
4503 | @%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 |
||
4504 | @%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 |
||
4505 | @%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 |
||
4506 | @%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 |
||
4507 | @%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 |
||
4508 | @%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 |
||
4509 | @%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 |
||
4510 | @%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 |
||
4511 | @%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 |
||
4512 | @%userdraw_line%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw line,green |
||
4513 | @%userdraw_lines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw lines,green |
||
4514 | @%userdraw_vline%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw vline,green |
||
4515 | @%userdraw_vlines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw vlines,green |
||
4516 | @%userdraw_hline%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw hline,green |
||
4517 | @%userdraw_hlines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw hlines,green |
||
4518 | @%userdraw_demiline%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw demiline,green |
||
4519 | @%userdraw_demilines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw demilines,green |
||
4520 | @%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 |
||
4521 | @%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 |
||
4522 | @%userdraw_point%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw point,green |
||
4523 | @%userdraw_points%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw points,green |
||
4524 | @%userdraw_arrow%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw arrow,green |
||
4525 | @%userdraw_arrows%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw arrows,green |
||
4526 | @%userdraw_arrow2%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw arrow2,green |
||
4527 | @%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 | 4528 | @%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 |
4529 | @%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 |
||
14071 | bpr | 4530 | @%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 |
4531 | @%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 | 4532 | @%userdraw_crosshair%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw crosshair,green |
4533 | @%userdraw_crosshairs%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw crosshairs,green |
||
4534 | @%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 |
||
4535 | @%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 |
||
4536 | @%userdraw_segment%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw segment,green |
||
4537 | @%userdraw_segments%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw segments,green |
||
4538 | @%userdraw_line%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw line,green |
||
4539 | @%userdraw_lines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw lines,green |
||
4540 | @%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 |
||
4541 | @%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 |
||
4542 | @%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 |
||
4543 | @%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 |
||
4544 | @%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 |
||
4545 | @%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 |
||
4546 | @%userdraw_freehandline%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw freehandline,green |
||
4547 | @%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 |
||
4548 | @%userdraw_freehandlines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw freehandlines,green |
||
4549 | @%userdraw_input%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%userdraw input,green |
||
4550 | @%userdraw_inputs%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%userdraw inputs,green |
||
4551 | @%userdraw_text%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%fontfamily 42px Courier%userdraw text,green |
||
14044 | schaersvoo | 4552 | @%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 | 4553 | @%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 |
4554 | @%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 | 4555 | @%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 | 4556 | */ |
4557 | if( use_userdraw == TRUE ){ /* only one object type may be drawn*/ |
||
14038 | schaersvoo | 4558 | canvas_error("Only one userdraw primitive may be used in command 'userdraw' use command 'multidraw' for this..."); |
7614 | schaersvoo | 4559 | } |
8074 | schaersvoo | 4560 | reply_precision = precision; |
7614 | schaersvoo | 4561 | use_userdraw = TRUE; |
13970 | obado | 4562 | fprintf(js_include_file,"\n/* begin userdraw mouse events */\n\ |
11839 | schaersvoo | 4563 | userdraw_x = new Array();userdraw_y = new Array();\ |
11041 | schaersvoo | 4564 | userdraw_radius = new Array();var xy_cnt=0;var canvas_userdraw = create_canvas%d(%d,xsize,ysize);\ |
11001 | schaersvoo | 4565 | var context_userdraw = canvas_userdraw.getContext(\"2d\");var use_dashed = %d;\ |
4566 | if(use_dashed == 1){if( context_userdraw.setLineDash ){context_userdraw.setLineDash([%d,%d]);}else{if(context_userdraw.mozDash){context_userdraw.mozDash = [%d,%d];};};};\ |
||
4567 | if(wims_status != \"done\"){\ |
||
14038 | schaersvoo | 4568 | canvas_div.addEventListener(\"mousedown\" ,user_draw,false);\ |
4569 | canvas_div.addEventListener(\"mousemove\" ,user_drag,false);\ |
||
4570 | canvas_div.addEventListener(\"touchstart\",function(e){ e.preventDefault();user_draw(e.changedTouches[0]);},false);\ |
||
4571 | canvas_div.addEventListener(\"touchmove\" ,function(e){ e.preventDefault();user_drag(e.changedTouches[0]);},false);\ |
||
4572 | canvas_div.addEventListener(\"touchend\" ,function(e){ e.preventDefault();user_draw(e.changedTouches[0]);},false);\ |
||
14044 | schaersvoo | 4573 | }\n/* end userdraw mouse & touch events */",canvas_root_id,DRAW_CANVAS,use_dashed,dashtype[0],dashtype[1],dashtype[0],dashtype[1]); |
7614 | schaersvoo | 4574 | draw_type = get_string_argument(infile,0); |
4575 | stroke_color = get_color(infile,1); |
||
4576 | if( strcmp(draw_type,"point") == 0 ){ |
||
4577 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
7876 | schaersvoo | 4578 | if(reply_format == 0 ){reply_format = 8;} |
7614 | schaersvoo | 4579 | /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */ |
12006 | schaersvoo | 4580 | /* |
14066 | bpr | 4581 | type = 0: a point ...radius is fixed |
4582 | type = 1: a circle ... read inputfield userinput_r |
||
4583 | num = 1: a single point / circle |
||
4584 | num = 2: multiple points / circles |
||
12006 | schaersvoo | 4585 | */ |
8071 | schaersvoo | 4586 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
8224 | bpr | 4587 | if(use_input_xy == 1){ |
12006 | schaersvoo | 4588 | add_input_circle(js_include_file,0,1); |
8815 | schaersvoo | 4589 | add_input_xy(js_include_file,canvas_root_id,font_size,input_style); |
7652 | schaersvoo | 4590 | } |
14044 | schaersvoo | 4591 | add_js_points(js_include_file,1,draw_type,line_width,line_width,stroke_color,stroke_opacity,1,stroke_color,stroke_opacity,0,1,1,use_snap); |
7614 | schaersvoo | 4592 | } |
4593 | else |
||
4594 | if( strcmp(draw_type,"points") == 0 ){ |
||
4595 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
7876 | schaersvoo | 4596 | if(reply_format == 0 ){reply_format = 8;} |
7614 | schaersvoo | 4597 | /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */ |
8071 | schaersvoo | 4598 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
8224 | bpr | 4599 | if(use_input_xy == 1){ |
12006 | schaersvoo | 4600 | add_input_circle(js_include_file,0,2); |
8815 | schaersvoo | 4601 | add_input_xy(js_include_file,canvas_root_id,font_size,input_style); |
7652 | schaersvoo | 4602 | } |
14044 | schaersvoo | 4603 | add_js_points(js_include_file,2,draw_type,line_width,line_width,stroke_color,stroke_opacity,1,stroke_color,stroke_opacity,0,1,1,use_snap); |
7614 | schaersvoo | 4604 | } |
4605 | else |
||
4606 | if( strcmp(draw_type,"segment") == 0 ){ |
||
4607 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
4608 | if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;} |
||
7876 | schaersvoo | 4609 | if(reply_format == 0){reply_format = 11;} |
8071 | schaersvoo | 4610 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
8224 | bpr | 4611 | if(use_input_xy == 1){ |
7652 | schaersvoo | 4612 | add_input_segment(js_include_file,1); |
8815 | schaersvoo | 4613 | add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style); |
7652 | schaersvoo | 4614 | } |
14044 | schaersvoo | 4615 | add_js_segments(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap); |
7614 | schaersvoo | 4616 | } |
4617 | else |
||
10975 | schaersvoo | 4618 | if( strcmp(draw_type,"polyline") == 0 || strcmp(draw_type,"brokenline") == 0 ){ |
7663 | schaersvoo | 4619 | if( js_function[DRAW_POLYLINE] != 1 ){ js_function[DRAW_POLYLINE] = 1;} |
7876 | schaersvoo | 4620 | if(reply_format == 0){reply_format = 23;} |
8071 | schaersvoo | 4621 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7780 | schaersvoo | 4622 | if( use_input_xy == 1 ){ |
4623 | add_input_polyline(js_include_file); |
||
8815 | schaersvoo | 4624 | add_input_xy(js_include_file,canvas_root_id,font_size,input_style); |
7663 | schaersvoo | 4625 | } |
14044 | schaersvoo | 4626 | add_js_polyline(js_include_file,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap); |
7663 | schaersvoo | 4627 | } |
4628 | else |
||
7614 | schaersvoo | 4629 | if( strcmp(draw_type,"segments") == 0 ){ |
4630 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
4631 | if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;} |
||
7876 | schaersvoo | 4632 | if(reply_format == 0){reply_format = 11;} |
8071 | schaersvoo | 4633 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
8224 | bpr | 4634 | if(use_input_xy == 1){ |
7652 | schaersvoo | 4635 | add_input_segment(js_include_file,2); |
8815 | schaersvoo | 4636 | add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style); |
7652 | schaersvoo | 4637 | } |
14044 | schaersvoo | 4638 | add_js_segments(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap); |
7614 | schaersvoo | 4639 | } |
4640 | else |
||
11839 | schaersvoo | 4641 | if( strcmp(draw_type,"circle") == 0 || strcmp(draw_type,"fcircle") == 0 || strcmp(draw_type,"filledcircle") == 0 ){ |
7614 | schaersvoo | 4642 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
7876 | schaersvoo | 4643 | if(reply_format == 0){reply_format = 10;} |
11875 | schaersvoo | 4644 | if(strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled = 1;}} |
7614 | schaersvoo | 4645 | /* 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n in x/y-range */ |
8071 | schaersvoo | 4646 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
8224 | bpr | 4647 | if(use_input_xy == 1){ |
12006 | schaersvoo | 4648 | /* |
14066 | bpr | 4649 | type = 0: a point ...radius is fixed |
4650 | type = 1: a circle ... read inputfield userinput_r |
||
4651 | num = 1: a single point / circle |
||
4652 | num = 2: multiple points / circles |
||
12006 | schaersvoo | 4653 | */ |
4654 | add_input_circle(js_include_file,1,1); |
||
8815 | schaersvoo | 4655 | add_input_xyr(js_include_file,canvas_root_id,font_size,input_style); |
7652 | schaersvoo | 4656 | } |
14044 | schaersvoo | 4657 | add_js_circles(js_include_file,1,draw_type,line_width,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1],use_snap); |
7614 | schaersvoo | 4658 | } |
4659 | else |
||
11839 | schaersvoo | 4660 | if( strcmp(draw_type,"circles") == 0 || strcmp(draw_type,"fcircles") == 0 || strcmp(draw_type,"filledcircles") == 0 ){ |
7614 | schaersvoo | 4661 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
7876 | schaersvoo | 4662 | if(reply_format == 0){reply_format = 10;} |
11839 | schaersvoo | 4663 | if(strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}} |
7614 | schaersvoo | 4664 | /* 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n in x/y-range */ |
14044 | schaersvoo | 4665 | add_js_circles(js_include_file,2,draw_type,line_width,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1],use_snap); |
8071 | schaersvoo | 4666 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
8224 | bpr | 4667 | if(use_input_xy == 1){ |
12006 | schaersvoo | 4668 | add_input_circle(js_include_file,1,2); |
8815 | schaersvoo | 4669 | add_input_xyr(js_include_file,canvas_root_id,font_size,input_style); |
7652 | schaersvoo | 4670 | } |
7614 | schaersvoo | 4671 | } |
4672 | else |
||
4673 | if(strcmp(draw_type,"crosshair") == 0 ){ |
||
4674 | if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;} |
||
7876 | schaersvoo | 4675 | if(reply_format == 0){reply_format = 8;} |
7614 | schaersvoo | 4676 | /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */ |
14044 | schaersvoo | 4677 | add_js_crosshairs(js_include_file,1,draw_type,line_width,crosshair_size ,stroke_color,stroke_opacity,use_snap); |
8071 | schaersvoo | 4678 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
8224 | bpr | 4679 | if(use_input_xy == 1){ |
7654 | schaersvoo | 4680 | add_input_crosshair(js_include_file,1); |
8815 | schaersvoo | 4681 | add_input_xy(js_include_file,canvas_root_id,font_size,input_style); |
7654 | schaersvoo | 4682 | } |
7614 | schaersvoo | 4683 | } |
4684 | else |
||
4685 | if(strcmp(draw_type,"crosshairs") == 0 ){ |
||
4686 | if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;} |
||
7876 | schaersvoo | 4687 | if(reply_format == 0){reply_format = 8;} |
7614 | schaersvoo | 4688 | /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */ |
14044 | schaersvoo | 4689 | add_js_crosshairs(js_include_file,2,draw_type,line_width,crosshair_size ,stroke_color,stroke_opacity,use_snap); |
8071 | schaersvoo | 4690 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
8224 | bpr | 4691 | if(use_input_xy == 1){ |
7654 | schaersvoo | 4692 | add_input_crosshair(js_include_file,2); |
8815 | schaersvoo | 4693 | add_input_xy(js_include_file,canvas_root_id,font_size,input_style); |
7654 | schaersvoo | 4694 | } |
7614 | schaersvoo | 4695 | } |
4696 | else |
||
4697 | if(strcmp(draw_type,"freehandline") == 0 ){ |
||
4698 | if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;} |
||
7876 | schaersvoo | 4699 | if(reply_format == 0){reply_format = 6;} |
14044 | schaersvoo | 4700 | add_js_paths(js_include_file,1,draw_type,line_width,0,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1],use_snap); |
7652 | schaersvoo | 4701 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 4702 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 4703 | } |
4704 | else |
||
4705 | if(strcmp(draw_type,"freehandlines") == 0 ){ |
||
4706 | if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;} |
||
7876 | schaersvoo | 4707 | if(reply_format == 0){reply_format = 6;} |
14044 | schaersvoo | 4708 | add_js_paths(js_include_file,2,draw_type,line_width,0,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1],use_snap); |
7652 | schaersvoo | 4709 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 4710 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 4711 | } |
4712 | else |
||
11839 | schaersvoo | 4713 | if(strcmp(draw_type,"path") == 0 || strcmp(draw_type,"fpath") == 0 || strcmp(draw_type,"filledpath") == 0 ){ |
7614 | schaersvoo | 4714 | if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;} |
13829 | bpr | 4715 | if( strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}} |
7876 | schaersvoo | 4716 | if(reply_format == 0){reply_format = 6;} |
14044 | schaersvoo | 4717 | add_js_paths(js_include_file,1,draw_type,line_width,1,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1],use_snap); |
7652 | schaersvoo | 4718 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 4719 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 4720 | } |
4721 | else |
||
11839 | schaersvoo | 4722 | if(strcmp(draw_type,"paths") == 0 || strcmp(draw_type,"fpaths") == 0 || strcmp(draw_type,"filledpaths") == 0 ){ |
7614 | schaersvoo | 4723 | if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;} |
13829 | bpr | 4724 | if( strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}} |
7876 | schaersvoo | 4725 | if(reply_format == 0){reply_format = 6;} |
14044 | schaersvoo | 4726 | add_js_paths(js_include_file,2,draw_type,line_width,1,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1],use_snap); |
7652 | schaersvoo | 4727 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 4728 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 4729 | } |
4730 | else |
||
4731 | if(strcmp(draw_type,"arrows") == 0 ){ |
||
4732 | if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;} |
||
7876 | schaersvoo | 4733 | if(reply_format == 0){reply_format = 11;} |
14044 | schaersvoo | 4734 | add_js_arrows(js_include_file,2,draw_type,line_width,1,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head,use_snap); |
8224 | bpr | 4735 | if(use_input_xy == 1){ |
7654 | schaersvoo | 4736 | add_input_arrow(js_include_file,2); |
8815 | schaersvoo | 4737 | add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style); |
7654 | schaersvoo | 4738 | } |
8071 | schaersvoo | 4739 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 4740 | } |
4741 | else |
||
7874 | schaersvoo | 4742 | if(strcmp(draw_type,"arrows2") == 0 ){ |
4743 | if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;} |
||
7876 | schaersvoo | 4744 | if(reply_format == 0){reply_format = 11;} |
14044 | schaersvoo | 4745 | add_js_arrows(js_include_file,2,draw_type,line_width,2,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head,use_snap); |
8224 | bpr | 4746 | if(use_input_xy == 1){ |
7874 | schaersvoo | 4747 | add_input_arrow(js_include_file,1); |
8815 | schaersvoo | 4748 | add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style); |
7874 | schaersvoo | 4749 | } |
8071 | schaersvoo | 4750 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7874 | schaersvoo | 4751 | } |
4752 | else |
||
4753 | if(strcmp(draw_type,"arrow2") == 0 ){ |
||
4754 | if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;} |
||
7876 | schaersvoo | 4755 | if(reply_format == 0){reply_format = 11;} |
14044 | schaersvoo | 4756 | add_js_arrows(js_include_file,1,draw_type,line_width,2,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head,use_snap); |
8224 | bpr | 4757 | if(use_input_xy == 1){ |
7874 | schaersvoo | 4758 | add_input_arrow(js_include_file,1); |
8815 | schaersvoo | 4759 | add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style); |
7874 | schaersvoo | 4760 | } |
8071 | schaersvoo | 4761 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7874 | schaersvoo | 4762 | } |
4763 | else |
||
7614 | schaersvoo | 4764 | if(strcmp(draw_type,"arrow") == 0 ){ |
4765 | if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;} |
||
7876 | schaersvoo | 4766 | if(reply_format == 0){reply_format = 11;} |
14044 | schaersvoo | 4767 | add_js_arrows(js_include_file,1,draw_type,line_width,1,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head,use_snap); |
8224 | bpr | 4768 | if(use_input_xy == 1){ |
7654 | schaersvoo | 4769 | add_input_arrow(js_include_file,1); |
8815 | schaersvoo | 4770 | add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style); |
7654 | schaersvoo | 4771 | } |
8071 | schaersvoo | 4772 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 4773 | } |
4774 | else |
||
14027 | schaersvoo | 4775 | if( strcmp(draw_type,"curvedarrow2") == 0 ){ |
14035 | schaersvoo | 4776 | if(reply_format == 0){reply_format = 2;} |
14044 | schaersvoo | 4777 | add_js_curvedarrow(js_include_file,canvas_root_id,1,line_width,stroke_color,stroke_opacity,use_dashed,arrow_head,2,use_snap); |
14027 | schaersvoo | 4778 | if(use_input_xy > 0){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
14038 | schaersvoo | 4779 | } |
4780 | else |
||
4781 | if( strcmp(draw_type,"curvedarrows2") == 0 ){ |
||
14035 | schaersvoo | 4782 | if(reply_format == 0){reply_format = 2;} |
14044 | schaersvoo | 4783 | add_js_curvedarrow(js_include_file,canvas_root_id,2,line_width,stroke_color,stroke_opacity,use_dashed,arrow_head,2,use_snap); |
14027 | schaersvoo | 4784 | if(use_input_xy > 0){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
14038 | schaersvoo | 4785 | } |
4786 | else |
||
4787 | if( strcmp(draw_type,"curvedarrows") == 0 ){ |
||
14035 | schaersvoo | 4788 | if(reply_format == 0){reply_format = 2;} |
14044 | schaersvoo | 4789 | add_js_curvedarrow(js_include_file,canvas_root_id,2,line_width,stroke_color,stroke_opacity,use_dashed,arrow_head,1,use_snap); |
14027 | schaersvoo | 4790 | if(use_input_xy > 0){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
14038 | schaersvoo | 4791 | } |
4792 | else |
||
4793 | if( strcmp(draw_type,"curvedarrow") == 0 ){ |
||
14035 | schaersvoo | 4794 | if(reply_format == 0){reply_format = 2;} |
14044 | schaersvoo | 4795 | add_js_curvedarrow(js_include_file,canvas_root_id,1,line_width,stroke_color,stroke_opacity,use_dashed,arrow_head,1,use_snap); |
14027 | schaersvoo | 4796 | if(use_input_xy > 0){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
14038 | schaersvoo | 4797 | } |
14025 | schaersvoo | 4798 | else |
11839 | schaersvoo | 4799 | if(strcmp(draw_type,"polygon") == 0 || strcmp(draw_type,"fpolygon") == 0 || strcmp(draw_type,"filledpolygon") == 0){ |
7614 | schaersvoo | 4800 | if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;} |
11839 | schaersvoo | 4801 | if(strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}} |
7876 | schaersvoo | 4802 | if(reply_format == 0){reply_format = 2;} |
14044 | schaersvoo | 4803 | add_js_poly(js_include_file,-1,draw_type,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1],use_snap); |
8071 | schaersvoo | 4804 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
4805 | if(use_input_xy == 2){ |
||
7780 | schaersvoo | 4806 | add_textarea_polygon(js_include_file); |
8815 | schaersvoo | 4807 | add_textarea_xy(js_include_file,canvas_root_id,input_style); |
7746 | schaersvoo | 4808 | } |
7614 | schaersvoo | 4809 | } |
8224 | bpr | 4810 | else |
7614 | schaersvoo | 4811 | if(strncmp(draw_type,"poly",4) == 0){ |
4812 | if(strlen(draw_type) < 5){canvas_error("use command \"userdraw poly[3-9],color\" eg userdraw poly6,blue");} |
||
4813 | if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;} |
||
7876 | schaersvoo | 4814 | if(reply_format == 0){reply_format = 2;} |
14044 | schaersvoo | 4815 | add_js_poly(js_include_file,(int) (draw_type[4]-'0'),draw_type,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1],use_snap); |
7652 | schaersvoo | 4816 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 4817 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 4818 | } |
8224 | bpr | 4819 | else |
11839 | schaersvoo | 4820 | if(strcmp(draw_type,"triangle") == 0 || strcmp(draw_type,"ftriangle") == 0 || strcmp(draw_type,"filledtriangle") == 0){ |
7614 | schaersvoo | 4821 | if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;} |
11839 | schaersvoo | 4822 | if(strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}} |
7876 | schaersvoo | 4823 | if(reply_format == 0){reply_format = 2;} |
14044 | schaersvoo | 4824 | add_js_poly(js_include_file,3,draw_type,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1],use_snap); |
7652 | schaersvoo | 4825 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 4826 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 4827 | } |
8224 | bpr | 4828 | else |
7989 | schaersvoo | 4829 | if( strcmp(draw_type,"hline") == 0 ){ |
4830 | if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;} |
||
4831 | if(reply_format == 0){reply_format = 11;} |
||
14044 | schaersvoo | 4832 | add_js_hlines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap); |
8071 | schaersvoo | 4833 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
4834 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
||
7989 | schaersvoo | 4835 | } |
4836 | else |
||
4837 | if( strcmp(draw_type,"hlines") == 0 ){ |
||
4838 | if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;} |
||
4839 | if(reply_format == 0){reply_format = 11;} |
||
14044 | schaersvoo | 4840 | add_js_hlines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap); |
8071 | schaersvoo | 4841 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
4842 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
||
7989 | schaersvoo | 4843 | } |
4844 | else |
||
4845 | if( strcmp(draw_type,"vline") == 0 ){ |
||
4846 | if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;} |
||
4847 | if(reply_format == 0){reply_format = 11;} |
||
14044 | schaersvoo | 4848 | add_js_hlines(js_include_file,3,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap); |
8071 | schaersvoo | 4849 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
4850 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
||
7989 | schaersvoo | 4851 | } |
4852 | else |
||
4853 | if( strcmp(draw_type,"vlines") == 0 ){ |
||
4854 | if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;} |
||
4855 | if(reply_format == 0){reply_format = 11;} |
||
14044 | schaersvoo | 4856 | add_js_hlines(js_include_file,4,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap); |
8071 | schaersvoo | 4857 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
4858 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
||
7989 | schaersvoo | 4859 | } |
4860 | else |
||
7614 | schaersvoo | 4861 | if( strcmp(draw_type,"line") == 0 ){ |
4862 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
4863 | if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;} |
||
7876 | schaersvoo | 4864 | if(reply_format == 0){reply_format = 11;} |
14044 | schaersvoo | 4865 | add_js_lines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap); |
7747 | schaersvoo | 4866 | if( use_input_xy == 1 ){ |
7780 | schaersvoo | 4867 | add_input_line(js_include_file,1); |
8815 | schaersvoo | 4868 | add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style); |
7747 | schaersvoo | 4869 | } |
8071 | schaersvoo | 4870 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 4871 | } |
4872 | else |
||
4873 | if( strcmp(draw_type,"lines") == 0 ){ |
||
4874 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
||
4875 | if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;} |
||
7876 | schaersvoo | 4876 | if(reply_format == 0){reply_format = 11;} |
14044 | schaersvoo | 4877 | add_js_lines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap); |
7747 | schaersvoo | 4878 | if( use_input_xy == 1 ){ |
7780 | schaersvoo | 4879 | add_input_line(js_include_file,2); |
8815 | schaersvoo | 4880 | add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style); |
7746 | schaersvoo | 4881 | } |
8071 | schaersvoo | 4882 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 4883 | } |
4884 | else |
||
8362 | schaersvoo | 4885 | if( strcmp(draw_type,"demilines") == 0 || strcmp(draw_type,"halflines") == 0 ){ |
8244 | schaersvoo | 4886 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
4887 | if( js_function[DRAW_DEMILINES] != 1 ){ js_function[DRAW_DEMILINES] = 1;} |
||
4888 | if(reply_format == 0){reply_format = 11;} |
||
14044 | schaersvoo | 4889 | add_js_demilines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap); |
8244 | schaersvoo | 4890 | if( use_input_xy == 1 ){ |
4891 | add_input_demiline(js_include_file,2); |
||
8815 | schaersvoo | 4892 | add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style); |
8244 | schaersvoo | 4893 | } |
4894 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
||
4895 | } |
||
4896 | else |
||
8362 | schaersvoo | 4897 | if( strcmp(draw_type,"demiline") == 0 || strcmp(draw_type,"halfline") == 0 ){ |
8244 | schaersvoo | 4898 | if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;} |
4899 | if( js_function[DRAW_DEMILINES] != 1 ){ js_function[DRAW_DEMILINES] = 1;} |
||
4900 | if(reply_format == 0){reply_format = 11;} |
||
14044 | schaersvoo | 4901 | add_js_demilines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap); |
8244 | schaersvoo | 4902 | if( use_input_xy == 1 ){ |
4903 | add_input_demiline(js_include_file,1); |
||
8815 | schaersvoo | 4904 | add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style); |
8244 | schaersvoo | 4905 | } |
4906 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
||
4907 | } |
||
4908 | else |
||
11839 | schaersvoo | 4909 | if( strcmp(draw_type,"rects") == 0 || strcmp(draw_type,"frects") == 0 || strcmp(draw_type,"filledrects") == 0 ){ |
7614 | schaersvoo | 4910 | if( js_function[DRAW_RECTS] != 1 ){ js_function[DRAW_RECTS] = 1;} |
12008 | schaersvoo | 4911 | if(strstr(draw_type,"f") != NULL){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}} |
7876 | schaersvoo | 4912 | if(reply_format == 0){reply_format = 2;} |
14044 | schaersvoo | 4913 | add_js_rect(js_include_file,2,0,draw_type,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1],use_snap); |
7652 | schaersvoo | 4914 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 4915 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 4916 | } |
8224 | bpr | 4917 | else |
11839 | schaersvoo | 4918 | if( strcmp(draw_type,"roundrects") == 0 || strcmp(draw_type,"froundrects") == 0 || strcmp(draw_type,"filledroundrects") == 0){ |
7614 | schaersvoo | 4919 | if( js_function[DRAW_ROUNDRECTS] != 1 ){ js_function[DRAW_ROUNDRECTS] = 1;} |
11839 | schaersvoo | 4920 | if( strstr(draw_type,"f") != NULL ){ if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}} |
7876 | schaersvoo | 4921 | if(reply_format == 0){reply_format = 2;} |
14044 | schaersvoo | 4922 | add_js_rect(js_include_file,2,1,draw_type,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1],use_snap); |
7652 | schaersvoo | 4923 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 4924 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 4925 | } |
8224 | bpr | 4926 | else |
11839 | schaersvoo | 4927 | if( strcmp(draw_type,"rect") == 0 || strcmp(draw_type,"frect") == 0 || strcmp(draw_type,"filledrect") == 0 ){ |
7614 | schaersvoo | 4928 | if( js_function[DRAW_RECTS] != 1 ){ js_function[DRAW_RECTS] = 1;} |
13829 | bpr | 4929 | if( strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}} |
7876 | schaersvoo | 4930 | if(reply_format == 0){reply_format = 2;} |
14044 | schaersvoo | 4931 | add_js_rect(js_include_file,1,0,draw_type,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1],use_snap); |
7652 | schaersvoo | 4932 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 4933 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 4934 | } |
8224 | bpr | 4935 | else |
11839 | schaersvoo | 4936 | if( strcmp(draw_type,"roundrect") == 0 || strcmp(draw_type,"froundrect") == 0 || strcmp(draw_type,"filledroundrect") == 0){ |
7614 | schaersvoo | 4937 | if( js_function[DRAW_ROUNDRECTS] != 1 ){ js_function[DRAW_ROUNDRECTS] = 1;} |
11839 | schaersvoo | 4938 | if( strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled = 1;}} |
7876 | schaersvoo | 4939 | if(reply_format == 0){reply_format = 2;} |
14044 | schaersvoo | 4940 | add_js_rect(js_include_file,1,1,draw_type,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1],use_snap); |
7652 | schaersvoo | 4941 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 4942 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 4943 | } |
4944 | else |
||
11839 | schaersvoo | 4945 | if( strcmp(draw_type,"arcs") == 0 || strcmp(draw_type,"farcs") == 0 || strcmp(draw_type,"filledarcs") == 0 ){ |
8083 | schaersvoo | 4946 | if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;} |
11839 | schaersvoo | 4947 | if( js_function[JS_FIND_ANGLE] != 1 ){ js_function[JS_FIND_ANGLE] = 1;} |
4948 | if( strstr(draw_type,"f") != NULL ){use_filled =1;} |
||
8083 | schaersvoo | 4949 | if(reply_format == 0){reply_format = 25;} |
14044 | schaersvoo | 4950 | add_js_arc(js_include_file,canvas_root_id,2,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1],use_filled,use_snap); |
8083 | schaersvoo | 4951 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
4952 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
||
4953 | } |
||
4954 | else |
||
11839 | schaersvoo | 4955 | if( strcmp(draw_type,"arc") == 0 || strcmp(draw_type,"farc") == 0 || strcmp(draw_type,"filledarc") == 0){ |
8071 | schaersvoo | 4956 | if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;} |
11017 | schaersvoo | 4957 | if( js_function[JS_FIND_ANGLE] != 1 ){ js_function[JS_FIND_ANGLE] = 1;} |
11839 | schaersvoo | 4958 | if( strstr(draw_type,"f") != NULL ){use_filled =1;} |
8083 | schaersvoo | 4959 | if(reply_format == 0){reply_format = 25;} |
14044 | schaersvoo | 4960 | add_js_arc(js_include_file,canvas_root_id,1,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1],use_filled,use_snap); |
8071 | schaersvoo | 4961 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
4962 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
||
4963 | } |
||
4964 | else |
||
7614 | schaersvoo | 4965 | if( strcmp(draw_type,"text") == 0){ |
7876 | schaersvoo | 4966 | if(reply_format == 0){reply_format = 17;} |
14044 | schaersvoo | 4967 | add_js_text(js_include_file,canvas_root_id,font_size,font_family,stroke_color,stroke_opacity,use_snap); |
7652 | schaersvoo | 4968 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
8071 | schaersvoo | 4969 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
7614 | schaersvoo | 4970 | } |
8116 | schaersvoo | 4971 | else |
14038 | schaersvoo | 4972 | if( strcmp(draw_type,"images") == 0){ |
4973 | if(reply_format == 0){reply_format = 29;} |
||
4974 | add_js_images(js_include_file,canvas_root_id,use_offset,use_snap); |
||
4975 | } |
||
4976 | else |
||
8116 | schaersvoo | 4977 | if( strcmp(draw_type,"inputs") == 0){ |
8224 | bpr | 4978 | if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;} |
8127 | schaersvoo | 4979 | if(reply_format == 0){reply_format = 27;} |
14044 | schaersvoo | 4980 | add_js_inputs(js_include_file,canvas_root_id,2,input_cnt,input_style,line_width,use_offset,use_snap); |
8116 | schaersvoo | 4981 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
4982 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
||
4983 | } |
||
4984 | else |
||
4985 | if( strcmp(draw_type,"input") == 0){ |
||
8224 | bpr | 4986 | if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;} |
8127 | schaersvoo | 4987 | if(reply_format == 0){reply_format = 27;} |
14044 | schaersvoo | 4988 | add_js_inputs(js_include_file,canvas_root_id,1,input_cnt,input_style,line_width,use_offset,use_snap); |
8116 | schaersvoo | 4989 | if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");} |
4990 | if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");} |
||
4991 | } |
||
11839 | schaersvoo | 4992 | else /* attention: THIS NEEDS TO BE LAST ! */ |
11825 | schaersvoo | 4993 | if( strstr(draw_type,"fill") != NULL ){ |
11005 | schaersvoo | 4994 | decimals = find_number_of_digits(precision); |
14044 | schaersvoo | 4995 | add_js_clickfill(js_include_file,canvas_root_id,stroke_color,(int) (fill_opacity/0.0039215),use_snap); |
4996 | if( reply_format == 0){reply_format = 10;} |
||
11825 | schaersvoo | 4997 | if( js_function[DRAW_FILLTOBORDER] != 1 ){js_function[DRAW_FILLTOBORDER] = 1;add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);} |
11830 | schaersvoo | 4998 | if( strcmp(draw_type,"gridfill") == 0){js_function[DRAW_GRIDFILL] = 1;string_length = snprintf(NULL,0,"draw_gridfill(%d,%d,%d,4,4,%d,'%s','0.01',%d,%d,true); ",FILL_CANVAS+fill_cnt,(int) (xmax),(int) (ymax),line_width,stroke_color,xsize,ysize);check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);snprintf(tmp_buffer,string_length,"draw_gridfill(%d,%d,%d,4,4,%d,'%s','0.01',%d,%d,true);",FILL_CANVAS+fill_cnt,(int) (xmax),(int) (ymax),line_width,stroke_color,xsize,ysize);add_to_buffer(tmp_buffer);fill_cnt++;} |
4999 | if( strcmp(draw_type,"diamondfill") == 0){js_function[DRAW_DIAMONDFILL] = 1;string_length = snprintf(NULL,0,"draw_diamondfill(%d,%d,%d,4,4,%d,'%s','0.01',%d,%d,true); ",FILL_CANVAS+fill_cnt,(int) (xmax),(int) (ymax),line_width,stroke_color,xsize,ysize);check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);snprintf(tmp_buffer,string_length,"draw_diamondfill(%d,%d,%d,4,4,%d,'%s','0.01',%d,%d,true);",FILL_CANVAS+fill_cnt,(int) (xmax),(int) (ymax),line_width,stroke_color,xsize,ysize);add_to_buffer(tmp_buffer);fill_cnt++;} |
||
5000 | if( strcmp(draw_type,"dotfill") == 0){js_function[DRAW_DOTFILL] = 1;string_length = snprintf(NULL,0,"draw_dotfill(%d,%d,%d,4,4,%d,'%s','0.01',%d,%d,true); ",FILL_CANVAS+fill_cnt,(int) (xmax),(int) (ymax),line_width,stroke_color,xsize,ysize);check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);snprintf(tmp_buffer,string_length,"draw_dotfill(%d,%d,%d,4,4,%d,'%s','0.01',%d,%d,true);",FILL_CANVAS+fill_cnt,(int) (xmax),(int) (ymax),line_width,stroke_color,xsize,ysize);add_to_buffer(tmp_buffer);fill_cnt++;} |
||
5001 | if( strcmp(draw_type,"hatchfill") == 0){js_function[DRAW_HATCHFILL] = 1;string_length = snprintf(NULL,0,"draw_hatchfill(%d,%d,%d,4,4,%d,'%s','0.01',%d,%d,true); ",FILL_CANVAS+fill_cnt,(int) (xmax),(int) (ymax),line_width,stroke_color,xsize,ysize);check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);snprintf(tmp_buffer,string_length,"draw_hatchfill(%d,%d,%d,4,4,%d,'%s','0.01',%d,%d,true);",FILL_CANVAS+fill_cnt,(int) (xmax),(int) (ymax),line_width,stroke_color,xsize,ysize);add_to_buffer(tmp_buffer);fill_cnt++;} |
||
5002 | if( strcmp(draw_type,"textfill") == 0){js_function[DRAW_TEXTFILL] = 1;temp = get_string(infile,1);string_length = snprintf(NULL,0,"draw_textfill(%d,%d,%d,'%s','%s',%d,%d,'%s',true); ",FILL_CANVAS+fill_cnt,(int) (xmax),(int) (ymax),stroke_color,font_family,xsize,ysize,temp);check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);snprintf(tmp_buffer,string_length,"draw_textfill(%d,%d,%d,'%s','%s',%d,%d,'%s',true); ",FILL_CANVAS+fill_cnt,(int) (xmax),(int) (ymax),stroke_color,font_family,xsize,ysize,temp);add_to_buffer(tmp_buffer);fill_cnt++;} |
||
11005 | schaersvoo | 5003 | } |
5004 | else |
||
7614 | schaersvoo | 5005 | { |
5006 | canvas_error("unknown drawtype or typo? "); |
||
5007 | } |
||
5008 | reset(); |
||
5009 | break; |
||
8386 | schaersvoo | 5010 | |
5011 | case USERINPUT: |
||
5012 | /* |
||
13955 | schaersvoo | 5013 | @ userinput function inputfield |
14071 | bpr | 5014 | @ alternative: <code>userinput_function</code> |
5015 | @ alternative: <code>userinput_xy</code> |
||
14086 | bpr | 5016 | @ textarea and inputfield are only usable in combination with some ''userdraw draw_ type`` |
8386 | schaersvoo | 5017 | @ function may be used any time (e.g. without userdraw) |
14071 | bpr | 5018 | @ multiple ''userinput function`` commands may be used. |
5019 | @ use command <code>functionlabel some_string</code> to define the inputfield text: default value "f(x)=" |
||
5020 | @ use command <code>strokecolor some_color</code> to adjust the plot / functionlabel color |
||
5021 | @ use command <code>inputstyle some_css</code> to adjust the inputfields |
||
5022 | @ use command <code>fontsize int</code> to adjust the label fonts. (default 12px) |
||
5023 | @ 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 |
||
13959 | bpr | 5024 | @%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%inputstyle color:blue;text-align:center%userinput function%# note: number of function inputs not limited |
13955 | schaersvoo | 5025 | @%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 |
5026 | @%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 |
||
5027 | @%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%inputstyle 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 | 5028 | */ |
5029 | temp = get_string_argument(infile,1); |
||
5030 | if(strstr(temp,"function") != 0 || strstr(temp,"curve") != 0 || strstr(temp,"plot") != 0 ){ |
||
5031 | if( js_function[DRAW_JSFUNCTION] != 1 ){ |
||
5032 | add_rawmath(js_include_file);/* add simple rawmath routine to correct user input of function */ |
||
5033 | js_function[DRAW_JSFUNCTION] = 1; |
||
5034 | if(reply_format == 0){reply_format = 24;}/* read canvas_input values */ |
||
8815 | schaersvoo | 5035 | add_input_jsfunction(js_include_file,canvas_root_id,input_style,function_label,input_cnt,stroke_color,stroke_opacity,line_width,use_dashed,dashtype[0],dashtype[1],font_size); |
8386 | schaersvoo | 5036 | input_cnt++; |
5037 | } |
||
10953 | bpr | 5038 | else |
8386 | schaersvoo | 5039 | { |
14078 | bpr | 5040 | /* no need to add DRAW_JSFUNCTION, just call it with the parameters */ |
8815 | schaersvoo | 5041 | fprintf(js_include_file,"add_input_jsfunction(%d,\"%s\",\"%s\",%d,\"%s\",\"%.2f\",%d,%d,%d,%d);\n",input_cnt,input_style,function_label,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],font_size); |
8386 | schaersvoo | 5042 | input_cnt++; |
5043 | } |
||
5044 | if( use_js_math == FALSE){/* add this stuff only once...*/ |
||
5045 | add_to_js_math(js_include_file); |
||
5046 | use_js_math = TRUE; |
||
5047 | } |
||
5048 | if( use_js_plot == FALSE){ |
||
5049 | use_js_plot = TRUE; |
||
5050 | add_jsplot(js_include_file,canvas_root_id); /* this plots the function on JSPLOT_CANVAS */ |
||
5051 | } |
||
5052 | } |
||
5053 | else |
||
5054 | { |
||
5055 | if(strstr(temp,"inputfield") != 0 ){ |
||
5056 | if( use_input_xy != 0 ){canvas_error("userinput_xy can not be combined with usertextarea_xy command");} |
||
5057 | if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */ |
||
5058 | use_input_xy = 1; |
||
5059 | } |
||
5060 | else |
||
5061 | { |
||
5062 | if(strstr(temp,"textarea") != 0 ){ |
||
5063 | if( use_input_xy != 0 ){canvas_error("usertextarea_xy can not be combined with userinput_xy command");} |
||
5064 | if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */ |
||
5065 | use_input_xy = 2; |
||
5066 | } |
||
5067 | else |
||
5068 | { |
||
5069 | canvas_error("userinput argument may be \"function,inputfield,textarea\""); |
||
5070 | } |
||
5071 | } |
||
5072 | } |
||
5073 | break; |
||
5074 | case USERINPUT_XY: |
||
5075 | /* |
||
5076 | @ userinput_xy |
||
9372 | schaersvoo | 5077 | @ keyword (no arguments required) |
8386 | schaersvoo | 5078 | @ to be used in combination with command "userdraw object_type,color" |
14078 | bpr | 5079 | @ 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 | 5080 | @ the student may use this as correction for (x:y) on a drawing (or to draw without mouse, using just the coordinates) |
14071 | bpr | 5081 | @ 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 | 5082 | @ can <b>not</b> be combined with command ''intooltip tiptext`` <br />note: the ''tooltip div element`` is used for placing inputfields |
8386 | schaersvoo | 5083 | @ user drawings will not zoom on zooming (or pan on panning) |
14071 | bpr | 5084 | @ use command inputstyle some_css`` to adjust the inputarea. |
5085 | @ use command ''fontsize int`` to adjust the text labels (if needed) |
||
13950 | schaersvoo | 5086 | @%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 | 5087 | */ |
5088 | /* add simple eval check to avoid code injection with unprotected eval(string) */ |
||
5089 | if( use_input_xy != 0 ){canvas_error("userinput_xy can not be combined with usertextarea_xy command");} |
||
5090 | if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */ |
||
5091 | use_input_xy = 1; |
||
5092 | break; |
||
5093 | |||
5094 | case USERINPUT_FUNCTION: |
||
5095 | /* |
||
5096 | @ userinput_function |
||
9372 | schaersvoo | 5097 | @ keyword (no arguments required) |
14078 | bpr | 5098 | @ if set, a inputfield will be added to the page |
8386 | schaersvoo | 5099 | @ repeat keyword for more function input fields |
5100 | @ the userinput value will be plotted in the canvas |
||
14071 | bpr | 5101 | @ 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 |
14078 | bpr | 5102 | @ use before this command ''userinput_function``,<br />commands like ''inputstyle some_css``, ''xlabel some_description``, ''opacity int,int``, ''linewidth int``, ''dashed`` and ''dashtype int,int`` to modify |
14071 | bpr | 5103 | @ fontsize can be set using command ''fontsize int`` |
5104 | @ incompatible with command ''intooltip link_text_or_image``: it uses the tooltip div for adding the inputfield |
||
13950 | schaersvoo | 5105 | @%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%inputstyle color:blue;text-align:center;font-family:Italic;%strokecolor blue%functionlabel g(x)=%userinput function%# second inputfield%inputstyle color:green;text-align:center;font-family:Italic;%strokecolor green%functionlabel h(x)=%userinput function%# third inputfield%inputstyle color:purple;text-align:center;font-family:Italic;%strokecolor purple%functionlabel k(x)=%userinput function%# no limit in number of function inputfields |
8386 | schaersvoo | 5106 | */ |
5107 | if( js_function[DRAW_JSFUNCTION] != 1 ){ |
||
5108 | js_function[DRAW_JSFUNCTION] = 1; |
||
5109 | add_rawmath(js_include_file); |
||
5110 | if(reply_format == 0){reply_format = 24;}/* read canvas_input values */ |
||
8815 | schaersvoo | 5111 | add_input_jsfunction(js_include_file,canvas_root_id,input_style,function_label,input_cnt,stroke_color,stroke_opacity,line_width,use_dashed,dashtype[0],dashtype[1],font_size); |
8386 | schaersvoo | 5112 | input_cnt++; |
5113 | } |
||
10953 | bpr | 5114 | else |
8386 | schaersvoo | 5115 | { |
14078 | bpr | 5116 | /* no need to add DRAW_JSFUNCTION, just call it with the parameters */ |
8815 | schaersvoo | 5117 | fprintf(js_include_file,"add_input_jsfunction(%d,\"%s\",\"%s\",%d,\"%s\",\"%.2f\",%d,%d,%d,%d);\n",input_cnt,input_style,function_label,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],font_size); |
8386 | schaersvoo | 5118 | input_cnt++; |
5119 | } |
||
5120 | if( use_js_math == FALSE){/* add this stuff only once...*/ |
||
5121 | add_to_js_math(js_include_file); |
||
5122 | use_js_math = TRUE; |
||
5123 | } |
||
5124 | if( use_js_plot == FALSE){ |
||
5125 | use_js_plot = TRUE; |
||
5126 | add_jsplot(js_include_file,canvas_root_id); /* this plots the function on JSPLOT_CANVAS */ |
||
5127 | } |
||
5128 | break; |
||
5129 | |||
5130 | |||
5131 | |||
11806 | schaersvoo | 5132 | case USERTEXTAREA_XY: |
7788 | schaersvoo | 5133 | /* |
11806 | schaersvoo | 5134 | @ usertextarea_xy |
13955 | schaersvoo | 5135 | @ NOT IMPLEMENTED !! |
11806 | schaersvoo | 5136 | @ keyword (no arguments required) |
14086 | bpr | 5137 | @ to be used in combination with command <code>userdraw object_type,color</code> wherein object_type is only segment / polyline for the time being... |
5138 | @ if set two textareas are added to the document (one for x-values, one for y-values) |
||
11806 | schaersvoo | 5139 | @ the student may use this as correction for (x:y) on a drawing (or to draw without mouse, using just the coordinates) |
5140 | @ user drawings will not zoom on zooming (or pan on panning) |
||
14071 | bpr | 5141 | @ use command ''inputstyle some_css`` to adjust the inputarea. |
5142 | @ use command ''fontsize int`` to adjust the text labels (if needed) |
||
7788 | schaersvoo | 5143 | */ |
11806 | schaersvoo | 5144 | if( use_input_xy != 0 ){canvas_error("usertextarea_xy can not be combined with userinput_xy command");} |
5145 | if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */ |
||
5146 | use_input_xy = 2; |
||
7788 | schaersvoo | 5147 | break; |
8386 | schaersvoo | 5148 | |
11806 | schaersvoo | 5149 | case VLINE: |
8386 | schaersvoo | 5150 | /* |
11806 | schaersvoo | 5151 | @ vline x,y,color |
14071 | bpr | 5152 | @ alternative: <code>verticalline</code> |
11806 | schaersvoo | 5153 | @ draw a vertical line through point (x:y) in color 'color' |
5154 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> |
||
12107 | schaersvoo | 5155 | @%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 | 5156 | */ |
11806 | schaersvoo | 5157 | for(i=0;i<3;i++) { |
7614 | schaersvoo | 5158 | switch(i){ |
11806 | schaersvoo | 5159 | case 0: double_data[0] = get_real(infile,0);break; /* x-values */ |
5160 | case 1: double_data[1] = get_real(infile,0);break; /* y-values */ |
||
5161 | case 2: stroke_color=get_color(infile,1);/* name or hex color */ |
||
5162 | double_data[2] = double_data[0]; |
||
7614 | schaersvoo | 5163 | decimals = find_number_of_digits(precision); |
14045 | schaersvoo | 5164 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d,%d));\n",drag_type,click_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,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern); |
11806 | schaersvoo | 5165 | if(onclick > 0){click_cnt++;} |
5166 | /* click_cnt++; */ |
||
8379 | schaersvoo | 5167 | reset(); |
7614 | schaersvoo | 5168 | break; |
5169 | } |
||
5170 | } |
||
5171 | break; |
||
5172 | |||
11806 | schaersvoo | 5173 | case VLINES: |
11802 | schaersvoo | 5174 | /* |
11806 | schaersvoo | 5175 | @ vlines color,x1,y1,x2,y2.... |
14071 | bpr | 5176 | @ alternative: <code>verticallines</code> |
11806 | schaersvoo | 5177 | @ draw vertical lines through points (x1:y1),(x2:y2)... in color 'color' |
5178 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually |
||
13939 | bpr | 5179 | @%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 | 5180 | */ |
11806 | schaersvoo | 5181 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
5182 | fill_color = stroke_color; |
||
5183 | i=0; |
||
5184 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 5185 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
11806 | schaersvoo | 5186 | if(i%2 == 0 ){ |
5187 | double_data[i] = get_real(infile,0); /* x */ |
||
7614 | schaersvoo | 5188 | } |
11806 | schaersvoo | 5189 | else |
5190 | { |
||
5191 | double_data[i] = get_real(infile,1); /* y */ |
||
7983 | schaersvoo | 5192 | } |
11806 | schaersvoo | 5193 | i++; |
7983 | schaersvoo | 5194 | } |
11806 | schaersvoo | 5195 | decimals = find_number_of_digits(precision); |
5196 | for(c = 0 ; c < i-1 ; c = c+2){ |
||
14045 | schaersvoo | 5197 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d,%d));\n",drag_type,click_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,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern); |
11806 | schaersvoo | 5198 | if(onclick > 0){click_cnt++;} |
5199 | /* click_cnt++; */ |
||
5200 | } |
||
5201 | reset(); |
||
7983 | schaersvoo | 5202 | break; |
11806 | schaersvoo | 5203 | |
5204 | case VIDEO: |
||
7614 | schaersvoo | 5205 | /* |
11806 | schaersvoo | 5206 | @ video x,y,w,h,videofile location |
14066 | bpr | 5207 | @ x,y: left top corner of audio element (in xrange / yrange) |
5208 | @ w,y: width and height in pixels |
||
5209 | @ video format may be in *.mp4 (todo: other formats) |
||
13950 | schaersvoo | 5210 | @%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 | 5211 | */ |
11806 | schaersvoo | 5212 | if( js_function[DRAW_VIDEO] != 1 ){ js_function[DRAW_VIDEO] = 1;} |
7614 | schaersvoo | 5213 | for(i=0;i<5;i++){ |
5214 | switch(i){ |
||
11806 | schaersvoo | 5215 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */ |
5216 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system -> pixel */ |
||
5217 | case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */ |
||
5218 | case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */ |
||
5219 | case 4: temp = get_string(infile,1); |
||
5220 | string_length = snprintf(NULL,0, "draw_video(%d,%d,%d,%d,%d,\"%s\");\n",canvas_root_id,int_data[0],int_data[1],int_data[2],int_data[3],temp); |
||
7614 | schaersvoo | 5221 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
11806 | schaersvoo | 5222 | 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 | 5223 | add_to_buffer(tmp_buffer); |
5224 | break; |
||
5225 | default:break; |
||
5226 | } |
||
5227 | } |
||
5228 | reset(); |
||
5229 | break; |
||
11806 | schaersvoo | 5230 | |
7614 | schaersvoo | 5231 | case X_AXIS_STRINGS: |
5232 | /* |
||
5233 | @ xaxis num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n |
||
14071 | bpr | 5234 | @ alternative: <code>xaxistext num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n</code> |
13936 | bpr | 5235 | @ usable for commands <a href="#numberline">numberline</a> and <a href="#grid">grid</a> or combinations thereof |
9346 | schaersvoo | 5236 | @ use these x-axis num1...num_n values instead of default xmin...xmax |
14071 | bpr | 5237 | @ in case of command ''grid``. there is no need to use keyword <a href="#axisnumbering">axisnumbering</a> |
13936 | bpr | 5238 | @ use command <a href="#axis">axis</a> to have visual x/y-axis lines (see command <a href="#grid">grid</a> |
14086 | bpr | 5239 | @ use command ''fontcolor``, ''fontfamily`` to adjust font <br />defaults: black,12,Ariel<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 | 5240 | @ a javascript error message will flag non-matching value:name pairs |
14071 | bpr | 5241 | @ if the ''x-axis words`` are too big and will overlap, a simple alternating offset will be applied |
11044 | schaersvoo | 5242 | @ to be used before command grid (see <a href="#grid">command grid</a>) |
14078 | bpr | 5243 | @ ''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 | 5244 | @%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 | 5245 | */ |
11891 | schaersvoo | 5246 | use_axis_numbering++; |
7614 | schaersvoo | 5247 | temp = get_string(infile,1); |
5248 | if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");} |
||
5249 | if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/ |
||
11891 | schaersvoo | 5250 | fprintf(js_include_file,"x_strings[%d] = [\"%s\"];x_strings_up[%d] = null;",use_axis_numbering,temp,use_axis_numbering); |
7614 | schaersvoo | 5251 | break; |
9341 | schaersvoo | 5252 | case X_AXIS_STRINGS_UP: |
5253 | /* |
||
5254 | @ xaxisup num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n |
||
14071 | bpr | 5255 | @ alternative: <code>xaxistextup num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n</code> |
9341 | schaersvoo | 5256 | @ the text will be rotated 90° up |
11044 | schaersvoo | 5257 | @ no need to use keyword <a href="#axisnumbering">axisnumbering</a> |
13936 | bpr | 5258 | @ use command <a href="#axis">axis</a> to have visual x/y-axis lines (see command <a href="#grid">grid</a> |
9346 | schaersvoo | 5259 | @ use these x-axis num1...num_n values instead of default xmin...xmax |
14086 | bpr | 5260 | @ use command ''fontcolor``, <a href="#fontfamily">fontfamily</a> to adjust font <br />defaults: black,12,Ariel<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 | 5261 | @ a javascript error message will flag non-matching value:name pairs |
14071 | bpr | 5262 | @ 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 | 5263 | @ to be used before command grid (see <a href="#grid">command grid</a>) |
14086 | bpr | 5264 | @''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 | 5265 | @%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 | 5266 | */ |
11891 | schaersvoo | 5267 | use_axis_numbering++; |
9341 | schaersvoo | 5268 | temp = get_string(infile,1); |
5269 | if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");} |
||
5270 | if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/ |
||
11891 | schaersvoo | 5271 | fprintf(js_include_file,"x_strings_up[%d] = 1;x_strings[%d] = [\"%s\"];",use_axis_numbering,use_axis_numbering,temp); |
9341 | schaersvoo | 5272 | break; |
8224 | bpr | 5273 | |
11806 | schaersvoo | 5274 | case XERRORBARS: |
7614 | schaersvoo | 5275 | /* |
11806 | schaersvoo | 5276 | @ xerrorbars color,E1,E2,x1,y1,x2,y2,...,x_n,y_n |
5277 | @ 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' |
||
5278 | @ the errors E1 and E2 values are in xrange. |
||
14071 | bpr | 5279 | @ use command ''linewidth int`` to adust size |
11806 | schaersvoo | 5280 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!) |
12107 | schaersvoo | 5281 | @%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 | 5282 | |
7614 | schaersvoo | 5283 | */ |
11806 | schaersvoo | 5284 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
5285 | fill_color = stroke_color; |
||
5286 | i=0; |
||
5287 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 5288 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
11806 | schaersvoo | 5289 | if(i%2 == 0 ){ |
5290 | double_data[i] = get_real(infile,0); /* x */ |
||
8071 | schaersvoo | 5291 | } |
11806 | schaersvoo | 5292 | else |
5293 | { |
||
5294 | double_data[i] = get_real(infile,1); /* y */ |
||
7614 | schaersvoo | 5295 | } |
11806 | schaersvoo | 5296 | i++; |
7614 | schaersvoo | 5297 | } |
11806 | schaersvoo | 5298 | decimals = find_number_of_digits(precision); |
5299 | for(c = 2 ; c < i-1 ; c = c+2){ |
||
14045 | schaersvoo | 5300 | fprintf(js_include_file,"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\",%d,%s,%d,%d,%s,%d,%d));\n",drag_type,click_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,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern); |
11806 | schaersvoo | 5301 | /* click_cnt++; */ |
5302 | if(onclick > 0){click_cnt++;} |
||
5303 | } |
||
7614 | schaersvoo | 5304 | reset(); |
5305 | break; |
||
11806 | schaersvoo | 5306 | |
5307 | case XRANGE: |
||
7614 | schaersvoo | 5308 | /* |
11806 | schaersvoo | 5309 | @ xrange xmin,xmax |
14071 | bpr | 5310 | @ alternative: <code>rangex</code> |
11806 | schaersvoo | 5311 | @ if not given: 0,xsize (eg in pixels) |
7614 | schaersvoo | 5312 | */ |
11806 | schaersvoo | 5313 | for(i = 0 ; i<2; i++){ |
7614 | schaersvoo | 5314 | switch(i){ |
11806 | schaersvoo | 5315 | case 0: xmin = get_real(infile,0);break; |
5316 | case 1: xmax = get_real(infile,1);break; |
||
7614 | schaersvoo | 5317 | default: break; |
5318 | } |
||
5319 | } |
||
14066 | bpr | 5320 | if(xmin >= xmax){canvas_error(" xrange is not OK: xmin < xmax !\n");} |
11806 | schaersvoo | 5321 | fprintf(js_include_file,"var xmin = %f;var xmax = %f;\n",xmin,xmax); |
5322 | found_size_command++; |
||
7614 | schaersvoo | 5323 | break; |
8386 | schaersvoo | 5324 | |
5325 | |||
5326 | |||
11806 | schaersvoo | 5327 | case XSNAPTOGRID: |
7614 | schaersvoo | 5328 | /* |
11806 | schaersvoo | 5329 | @ xsnaptogrid |
5330 | @ keyword (no arguments required) |
||
14086 | bpr | 5331 | @ a draggable object (use command ''drag x|y|xy``) will snap to the given x-grid values when dragged (mouseup) |
11806 | schaersvoo | 5332 | @ in case of userdraw the drawn points will snap to xmajor grid |
14078 | bpr | 5333 | @ if no grid is defined, points will snap to every integer xrange value. (eg snap_x=1) |
14071 | bpr | 5334 | @ if you do not want a visible grid, but you only want a ''snaptogrid`` with some value...define this grid with opacity 0. |
5335 | @ 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 | 5336 | @%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 |
5337 | @%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 | 5338 | |
7614 | schaersvoo | 5339 | */ |
14038 | schaersvoo | 5340 | use_snap = 2; |
11806 | schaersvoo | 5341 | break; |
8386 | schaersvoo | 5342 | |
11806 | schaersvoo | 5343 | case XOFFSET: |
7614 | schaersvoo | 5344 | /* |
12063 | schaersvoo | 5345 | @ xoffset |
13829 | bpr | 5346 | @ keyword ; to place the text centered above the text coordinates(x:y) ... |
5347 | @ may be used for points or other things requiring centered labels |
||
12063 | schaersvoo | 5348 | @ use <a href="#fontfamily">fontfamily</a> for setting the font |
11811 | schaersvoo | 5349 | @ 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) |
12107 | schaersvoo | 5350 | @%xoffset%size 400,400%xrange -10,10%yrange -10,10%fontfamily 12pt Ariel%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 | 5351 | */ |
12063 | schaersvoo | 5352 | use_offset = 2; |
11806 | schaersvoo | 5353 | break; |
8386 | schaersvoo | 5354 | |
11806 | schaersvoo | 5355 | case XYOFFSET: |
7614 | schaersvoo | 5356 | /* |
11806 | schaersvoo | 5357 | @ xyoffset |
5358 | @ keyword ; to place the text (x:y) to (x+dx:y+dy)... dx/dy are dependent on fontsize/fontfamily |
||
13829 | bpr | 5359 | @ may be used for points or other things requiring labels |
12063 | schaersvoo | 5360 | @ use <a href="#fontfamily">fontfamily</a> for setting the font |
11806 | schaersvoo | 5361 | @ only active for commands <a href="#text">text</a> and <a href="#string">string</a> (e.g. objects in the drag/drop/onclick-librariy |
14071 | bpr | 5362 | @ 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> |
12107 | schaersvoo | 5363 | @%xyoffset%size 400,400%xrange -10,10%yrange -10,10%fontfamily 12pt Ariel%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 | 5364 | */ |
12063 | schaersvoo | 5365 | use_offset = 3; |
11806 | schaersvoo | 5366 | break; |
8386 | schaersvoo | 5367 | |
7996 | schaersvoo | 5368 | case XUNIT: |
5369 | /* |
||
5370 | @ xunit some_unit_for_x-values |
||
5371 | @ unicode allowed (no html code) |
||
12007 | schaersvoo | 5372 | @ use together with command <a href='#display'>display or mouse</a> |
14071 | bpr | 5373 | @ will display the cursor x-coordinate in ''unit`` |
12107 | schaersvoo | 5374 | @%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 | 5375 | */ |
5376 | fprintf(js_include_file,"unit_x = \"%s\";",get_string(infile,1)); |
||
5377 | break; |
||
11806 | schaersvoo | 5378 | |
5379 | case XLABEL: |
||
7996 | schaersvoo | 5380 | /* |
11806 | schaersvoo | 5381 | @ xlabel some_string |
5382 | @ will be used to create a label for the x-axis (label is in quadrant I) |
||
14071 | bpr | 5383 | @ can only be used together with command ''grid``<br />not depending on keywords ''axis`` and ''axisnumbering`` |
14086 | bpr | 5384 | @ 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) |
14071 | bpr | 5385 | @ see <a href=''z#ylabel'>ylabel</a> |
12107 | schaersvoo | 5386 | @%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 | 5387 | */ |
11806 | schaersvoo | 5388 | temp = get_string(infile,1); |
5389 | fprintf(js_include_file,"var xaxislabel = \"%s\";",temp); |
||
7996 | schaersvoo | 5390 | break; |
8071 | schaersvoo | 5391 | |
11806 | schaersvoo | 5392 | case XLOGBASE: |
7991 | schaersvoo | 5393 | /* |
11806 | schaersvoo | 5394 | @ xlogbase number |
5395 | @ sets the logbase number for the x-axis |
||
5396 | @ default value 10 |
||
5397 | @ use together with commands xlogscale / xylogscale |
||
7991 | schaersvoo | 5398 | */ |
11806 | schaersvoo | 5399 | fprintf(js_include_file,"xlogbase=%d;",(int)(get_real(infile,1))); |
7991 | schaersvoo | 5400 | break; |
5401 | |||
11806 | schaersvoo | 5402 | case XLOGSCALE: |
7614 | schaersvoo | 5403 | /* |
11806 | schaersvoo | 5404 | @ xlogscale ymajor,yminor,majorcolor,minorcolor |
14071 | bpr | 5405 | @ the x/y-range are set using commands <code>xrange xmin,xmax</code> and <code>yrange ymin,ymax</code> |
11806 | schaersvoo | 5406 | @ ymajor is the major step on the y-axis; yminor is the divisor for the y-step |
14071 | bpr | 5407 | @ the linewidth is set using command ''linewidth int`` |
14066 | bpr | 5408 | @ the opacity of major / minor grid lines is set by command <a href='#opacity'>opacity</a> |
14078 | bpr | 5409 | @ default logbase number = 10 ... when needed, set the logbase number with command ``xlogbase number`` |
14071 | bpr | 5410 | @ 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> |
5411 | @ note: the complete canvas will be used for the ''log paper`` |
||
11806 | schaersvoo | 5412 | @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values |
14071 | bpr | 5413 | @ note: command ''mouse color,fontsize`` will show the real values in the logpaper.<br />\ |
5414 | @ 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 | 5415 | @ note: in case of userdraw, the use of keyword <a href='#userinput_xy'>userinput_xy</a> may be handy ! |
14071 | bpr | 5416 | @ <b>attention</b>: keyword ''snaptogrid`` may not lead to the desired result... |
12107 | schaersvoo | 5417 | @%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 | 5418 | */ |
11972 | schaersvoo | 5419 | use_axis_numbering++;if(use_axis_numbering > 1){use_axis_numbering = 1;} |
11806 | schaersvoo | 5420 | if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");} |
5421 | if( js_function[DRAW_XLOGSCALE] != 1 ){ js_function[DRAW_XLOGSCALE] = 1;} |
||
5422 | for(i=0;i<4;i++){ |
||
7614 | schaersvoo | 5423 | switch(i){ |
11806 | schaersvoo | 5424 | case 0: double_data[0] = get_real(infile,0);break; /* xmajor */ |
5425 | case 1: int_data[0] = (int) (get_real(infile,0));break; /* xminor */ |
||
5426 | case 2: stroke_color = get_color(infile,0); break; |
||
5427 | case 3: fill_color = get_color(infile,1); |
||
5428 | string_length = snprintf(NULL,0,"draw_grid%d(%d,%d,\"%s\",\"%s\",%.2f,%.2f,%d,\"%s\",\"%s\",%d,%f,%d,%d); ",canvas_root_id,GRID_CANVAS,line_width,stroke_color,fill_color,stroke_opacity,fill_opacity,font_size,font_family,font_color,use_axis_numbering,double_data[0],int_data[0],precision); |
||
5429 | tmp_buffer = my_newmem(string_length+1); |
||
5430 | 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); |
||
5431 | fprintf(js_include_file,"use_xlogscale=1;snap_y = %f;snap_x = xlogbase;",double_data[0]/int_data[0]); |
||
5432 | add_to_buffer(tmp_buffer); |
||
5433 | break; |
||
7614 | schaersvoo | 5434 | default:break; |
5435 | } |
||
5436 | } |
||
5437 | break; |
||
11806 | schaersvoo | 5438 | |
5439 | case XYLOGSCALE: |
||
7614 | schaersvoo | 5440 | /* |
11806 | schaersvoo | 5441 | @ xylogscale majorcolor,minorcolor |
14071 | bpr | 5442 | @ the x/y-range are set using commands ''xrange xmin,xmax`` and ''yrange ymin,ymax`` |
5443 | @ the linewidth is set using command ''linewidth int`` |
||
5444 | @ the opacity of major / minor grid lines is set by command ''opacity [0-255],[0-255]`` |
||
14078 | bpr | 5445 | @ default logbase number = 10 ... when needed, set the logbase number with command ''xlogbase number`` and/or ''ylogbase number`` |
14071 | bpr | 5446 | @ 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> |
5447 | @ note: the complete canvas will be used for the ''log paper`` |
||
11806 | schaersvoo | 5448 | @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values |
14071 | bpr | 5449 | @ note: command ''mouse color,fontsize`` will show the real values in the logpaper.<br />\ |
5450 | @ 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 | 5451 | @ note: in case of userdraw, the use of keyword ''userinput_xy`` may be handy ! |
14071 | bpr | 5452 | @ <b>attention</b>: keyword ''snaptogrid`` may not lead to the desired result... |
13829 | bpr | 5453 | @%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 | 5454 | */ |
11972 | schaersvoo | 5455 | use_axis_numbering++;if(use_axis_numbering > 1){use_axis_numbering = 1;} |
11806 | schaersvoo | 5456 | if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");} |
5457 | if( js_function[DRAW_XYLOGSCALE] != 1 ){ js_function[DRAW_XYLOGSCALE] = 1;} |
||
5458 | for(i=0;i<2;i++){ |
||
7614 | schaersvoo | 5459 | switch(i){ |
11806 | schaersvoo | 5460 | case 0: stroke_color = get_color(infile,0); break; |
5461 | case 1: fill_color = get_color(infile,1); |
||
5462 | string_length = snprintf(NULL,0,"draw_grid%d(%d,%d,\"%s\",\"%s\",%.2f,%.2f,%d,\"%s\",\"%s\",%d,%d); ",canvas_root_id,GRID_CANVAS,line_width,stroke_color,fill_color,stroke_opacity,fill_opacity,font_size,font_family,font_color,use_axis_numbering,precision); |
||
5463 | tmp_buffer = my_newmem(string_length+1); |
||
5464 | 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); |
||
5465 | fprintf(js_include_file,"use_xlogscale=1;use_ylogscale=1;snap_x = xlogbase;snap_y = ylogbase;"); |
||
5466 | add_to_buffer(tmp_buffer); |
||
5467 | break; |
||
7614 | schaersvoo | 5468 | default:break; |
5469 | } |
||
5470 | } |
||
5471 | break; |
||
11806 | schaersvoo | 5472 | |
5473 | |||
5474 | case Y_AXIS_STRINGS: |
||
7647 | schaersvoo | 5475 | /* |
11806 | schaersvoo | 5476 | @ yaxis num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n |
14071 | bpr | 5477 | @ alternative: <code>yaxistext num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n</code> |
14086 | bpr | 5478 | @ use command ''fontcolor``, ''fontfamily`` to adjust font <br />defaults: black,12,Ariel<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 | 5479 | @ no need to use keyword <a href="#axisnumbering">axisnumbering</a> |
13936 | bpr | 5480 | @ use command <a href="#axis">axis</a> to have visual x/y-axis lines (see command <a href="#grid">grid</a> |
14071 | bpr | 5481 | @ use these y-axis num1...num_n values instead of default ymin...ymax |
11806 | schaersvoo | 5482 | @ a javascript error message will flag non-matching value:name pairs |
5483 | @ to be used before command grid (see <a href="#grid">command grid</a>) |
||
12107 | schaersvoo | 5484 | @%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 | 5485 | */ |
11806 | schaersvoo | 5486 | temp = get_string(infile,1); |
5487 | if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");} |
||
5488 | if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/ |
||
5489 | fprintf(js_include_file,"y_strings = [\"%s\"];\n ",temp); |
||
11891 | schaersvoo | 5490 | use_axis_numbering++; |
11806 | schaersvoo | 5491 | break; |
5492 | |||
5493 | |||
5494 | case YERRORBARS: |
||
7614 | schaersvoo | 5495 | /* |
11806 | schaersvoo | 5496 | @ yerrorbars color,E1,E2,x1,y1,x2,y2,...,x_n,y_n |
5497 | @ draw multiple points with y-errorbars E1 (error value under point) and E2 (error value above point) at given coordinates in color 'color' |
||
5498 | @ the errors E1 and E2 values are in yrange. |
||
14071 | bpr | 5499 | @ use command ''linewidth int`` to adust size |
11806 | schaersvoo | 5500 | @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!) |
12107 | schaersvoo | 5501 | @%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 | 5502 | */ |
11806 | schaersvoo | 5503 | stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/ |
5504 | fill_color = stroke_color; |
||
11772 | schaersvoo | 5505 | i=0; |
5506 | while( ! done ){ /* get next item until EOL*/ |
||
11997 | schaersvoo | 5507 | if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");} |
11772 | schaersvoo | 5508 | if(i%2 == 0 ){ |
5509 | double_data[i] = get_real(infile,0); /* x */ |
||
5510 | } |
||
5511 | else |
||
5512 | { |
||
5513 | double_data[i] = get_real(infile,1); /* y */ |
||
5514 | } |
||
5515 | i++; |
||
5516 | } |
||
11806 | schaersvoo | 5517 | for(c = 2 ; c < i-1 ; c = c+2){ |
14045 | schaersvoo | 5518 | fprintf(js_include_file,"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\",%d,%s,%d,%d,%s,%d,%d));\n",drag_type,click_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,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern); |
11806 | schaersvoo | 5519 | /* click_cnt++; */ |
5520 | if(onclick > 0){click_cnt++;} |
||
8083 | schaersvoo | 5521 | } |
11806 | schaersvoo | 5522 | decimals = find_number_of_digits(precision); |
8083 | schaersvoo | 5523 | reset(); |
11806 | schaersvoo | 5524 | break; |
11811 | schaersvoo | 5525 | case YOFFSET: |
5526 | /* |
||
5527 | @ yoffset |
||
13829 | bpr | 5528 | @ keyword ; to place the text centered above the text coordinates(x:y) ... |
5529 | @ may be used for points or other things requiring centered labels |
||
12063 | schaersvoo | 5530 | @ use <a href="#fontfamily">fontfamily</a> for setting the font |
5531 | @ 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) |
||
12107 | schaersvoo | 5532 | @%yoffset%size 400,400%xrange -10,10%yrange -10,10%fontfamily 12pt Ariel%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 | 5533 | */ |
12063 | schaersvoo | 5534 | use_offset = 1; |
11811 | schaersvoo | 5535 | break; |
5536 | |||
11806 | schaersvoo | 5537 | case YRANGE: |
7614 | schaersvoo | 5538 | /* |
11806 | schaersvoo | 5539 | @ yrange ymin,ymax |
14071 | bpr | 5540 | @ alternative: <code>rangey</code> |
11806 | schaersvoo | 5541 | @ if not given 0,ysize (eg in pixels) |
7614 | schaersvoo | 5542 | */ |
11806 | schaersvoo | 5543 | for(i = 0 ; i<2; i++){ |
7614 | schaersvoo | 5544 | switch(i){ |
11806 | schaersvoo | 5545 | case 0: ymin = get_real(infile,0);break; |
5546 | case 1: ymax = get_real(infile,1);break; |
||
5547 | default: break; |
||
7614 | schaersvoo | 5548 | } |
5549 | } |
||
14066 | bpr | 5550 | if(ymin >= ymax){canvas_error(" yrange is not OK: ymin < ymax !\n");} |
11806 | schaersvoo | 5551 | fprintf(js_include_file,"var ymin = %f;var ymax = %f;\n",ymin,ymax); |
5552 | found_size_command++; |
||
5553 | break; |
||
5554 | |||
5555 | case YSNAPTOGRID: |
||
7614 | schaersvoo | 5556 | /* |
11806 | schaersvoo | 5557 | @ ysnaptogrid |
5558 | @ keyword (no arguments required) |
||
14086 | bpr | 5559 | @ a draggable object (use command ''drag x|y|xy``) will snap to the given y-grid values when dragged (mouseup) |
11806 | schaersvoo | 5560 | @ in case of userdraw the drawn points will snap to ymajor grid |
14078 | bpr | 5561 | @ if no grid is defined, points will snap to every integer yrange value. (eg snap_y=1) |
14071 | bpr | 5562 | @ if you do not want a visible grid, but you only want a ''snaptogrid`` with some value...define this grid with opacity 0. |
5563 | @ 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 /> |
||
13959 | bpr | 5564 | @%ysnaptogrid_1%size 400,400%xrange -10,10%yrange -10,10%ysnaptogrid%grid 1,1,grey%linewidth 2%userdraw crosshairs,blue%inputstyle font-size:8px;color:blue%clearbutton delete all crosshairs |
5565 | @%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 | 5566 | */ |
14038 | schaersvoo | 5567 | use_snap = 3; |
7614 | schaersvoo | 5568 | break; |
11080 | schaersvoo | 5569 | |
7614 | schaersvoo | 5570 | case YLABEL: |
5571 | /* |
||
5572 | @ ylabel some_string |
||
8224 | bpr | 5573 | @ will be used to create a (vertical) label for the y-axis (label is in quadrant I) |
14071 | bpr | 5574 | @ can only be used together with command <a href="#grid">grid</a><br />not depending on keywords ''axis`` and ''axisnumbering`` |
14086 | bpr | 5575 | @ 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) |
12107 | schaersvoo | 5576 | @%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 | 5577 | */ |
5578 | temp = get_string(infile,1); |
||
7653 | schaersvoo | 5579 | fprintf(js_include_file,"var yaxislabel = \"%s\";",temp); |
7614 | schaersvoo | 5580 | break; |
7735 | schaersvoo | 5581 | case YLOGBASE: |
5582 | /* |
||
5583 | @ ylogbase number |
||
5584 | @ sets the logbase number for the y-axis |
||
5585 | @ default value 10 |
||
5586 | @ use together with commands ylogscale / xylogscale |
||
5587 | */ |
||
5588 | fprintf(js_include_file,"ylogbase=%d;",(int)(get_real(infile,1))); |
||
5589 | break; |
||
7614 | schaersvoo | 5590 | case YLOGSCALE: |
7729 | schaersvoo | 5591 | /* |
5592 | @ ylogscale xmajor,xminor,majorcolor,minorcolor |
||
14071 | bpr | 5593 | @ the x/y-range are set using commands ''xrange xmin,xmax`` and ''yrange ymin,ymax`` |
7729 | schaersvoo | 5594 | @ xmajor is the major step on the x-axis; xminor is the divisor for the x-step |
14071 | bpr | 5595 | @ the linewidth is set using command ''linewidth int`` |
5596 | @ the opacity of major / minor grid lines is set by command ''opacity [0-255],[0-255]`` |
||
14078 | bpr | 5597 | @ default logbase number = 10 ... when needed, set the logbase number with command ''ylogbase number`` |
14071 | bpr | 5598 | @ 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> |
5599 | @ note: the complete canvas will be used for the ''log paper`` |
||
11088 | schaersvoo | 5600 | @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values |
14071 | bpr | 5601 | @ note: command ''mouse color,fontsize`` will show the real values in the logpaper.<br />\ |
5602 | @ 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 | 5603 | @ note: in case of userdraw, the use of keyword ''userinput_xy`` may be handy ! |
14071 | bpr | 5604 | @ <b>attention</b>: keyword ''snaptogrid`` may not lead to the desired result... |
7729 | schaersvoo | 5605 | */ |
11972 | schaersvoo | 5606 | use_axis_numbering++;if(use_axis_numbering > 1){use_axis_numbering = 1;} |
7729 | schaersvoo | 5607 | if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");} |
5608 | if( js_function[DRAW_YLOGSCALE] != 1 ){ js_function[DRAW_YLOGSCALE] = 1;} |
||
5609 | for(i=0;i<4;i++){ |
||
5610 | switch(i){ |
||
5611 | case 0: double_data[0] = get_real(infile,0);break; /* xmajor */ |
||
5612 | case 1: int_data[0] = (int) (get_real(infile,0));break; /* xminor */ |
||
5613 | case 2: stroke_color = get_color(infile,0); break; |
||
8224 | bpr | 5614 | case 3: fill_color = get_color(infile,1); |
7779 | schaersvoo | 5615 | string_length = snprintf(NULL,0,"draw_grid%d(%d,%d,\"%s\",\"%s\",%.2f,%.2f,%d,\"%s\",\"%s\",%d,%f,%d,%d); ",canvas_root_id,GRID_CANVAS,line_width,stroke_color,fill_color,stroke_opacity,fill_opacity,font_size,font_family,font_color,use_axis_numbering,double_data[0],int_data[0],precision); |
7729 | schaersvoo | 5616 | tmp_buffer = my_newmem(string_length+1); |
7779 | schaersvoo | 5617 | 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 | 5618 | fprintf(js_include_file,"use_ylogscale=1;snap_x = %f;snap_y = ylogbase;",double_data[0]/int_data[0]); |
7729 | schaersvoo | 5619 | add_to_buffer(tmp_buffer); |
5620 | break; |
||
5621 | default:break; |
||
5622 | } |
||
5623 | } |
||
7614 | schaersvoo | 5624 | break; |
11806 | schaersvoo | 5625 | |
5626 | case YUNIT: |
||
7735 | schaersvoo | 5627 | /* |
11806 | schaersvoo | 5628 | @ yunit some_unit_for_y-values |
5629 | @ unicode allowed (no html code) |
||
5630 | @ use together with command mousey |
||
14071 | bpr | 5631 | @ will display the cursor y-coordinate in ''unit`` |
7735 | schaersvoo | 5632 | */ |
11806 | schaersvoo | 5633 | fprintf(js_include_file,"unit_y = \"%s\";",get_string(infile,1)); |
5634 | break; |
||
5635 | |||
5636 | case ZOOM: |
||
5637 | /* |
||
5638 | @ zoom button_color |
||
14071 | bpr | 5639 | @ introduce a very small ''controlpanel`` at the lower right corner |
5640 | @ giving six 15×15px ''active`` rectangle areas<br />(for ×,leftarrow,rightarrow,uparrow,downarrow and a ''-`` and a ''+`` sign ) for zooming and/or panning of the image |
||
5641 | @ the ''x`` symbol will do a <code>location.reload</code> of the page, and thus reset all canvas drawings. |
||
5642 | @ choose an appropriate colour, so the small ''x,arrows,-,+`` are clearly visible |
||
5643 | @ command ''opacity`` may be used to set stroke_opacity of buttons |
||
5644 | @ note: use command ''zoom`` at the end of your script code (the same is true for command ''mouse``) |
||
11806 | schaersvoo | 5645 | @ note: only objects that may be set draggable / clickable will be zoomed / panned |
14071 | bpr | 5646 | @ note: when an object is dragged, zooming / panning will cause the coordinates to be reset to the original position: e.g. dragging / panning will get lost. (array with ''drag data`` is erased). This is a design flaw and not a feature !! |
11806 | schaersvoo | 5647 | */ |
5648 | fprintf(js_include_file,"use_pan_and_zoom = 1;"); |
||
5649 | use_pan_and_zoom = TRUE; |
||
5650 | stroke_color = get_color(infile,1); |
||
5651 | /* we use BG_CANVAS (0) */ |
||
5652 | add_zoom_buttons(js_include_file,canvas_root_id,stroke_color,stroke_opacity); |
||
5653 | done = TRUE; |
||
5654 | break; |
||
5655 | |||
5656 | /* ready */ |
||
7614 | schaersvoo | 5657 | default:sync_input(infile); |
5658 | break; |
||
5659 | } |
||
8224 | bpr | 5660 | } |
7614 | schaersvoo | 5661 | /* we are done parsing script file */ |
14066 | bpr | 5662 | /* check if xrange / yrange was set explicit ... or use xmin=0 xmax=xsize ymin=0 ymax=ysize: Quadrant I */ |
7983 | schaersvoo | 5663 | if( found_size_command == 1 ){ |
5664 | fprintf(js_include_file,"var xmin = 0;var xmax = %d;var ymin = 0;var ymax = %d",xsize,ysize); |
||
5665 | } |
||
5666 | else |
||
5667 | { |
||
5668 | if( found_size_command != 3 ){ |
||
8222 | schaersvoo | 5669 | canvas_error("Please specify both xrange and yrange ..."); |
7983 | schaersvoo | 5670 | } |
5671 | } |
||
8257 | schaersvoo | 5672 | |
14066 | bpr | 5673 | /* if needed, add generic draw functions (grid / xml etc) to buffer: these are no draggable/clickable shapes / objects ! */ |
11021 | schaersvoo | 5674 | add_javascript_function(js_function,canvas_root_id); |
7614 | schaersvoo | 5675 | /* add read_canvas() etc functions if needed */ |
8257 | schaersvoo | 5676 | if( reply_format > 0 ){ add_read_canvas(canvas_root_id,reply_format,reply_precision);} |
7797 | schaersvoo | 5677 | if( use_pan_and_zoom == TRUE ){ |
5678 | /* in case of zooming ... */ |
||
13970 | obado | 5679 | fprintf(js_include_file,"\n/* some extra global stuff : need to rethink panning and zooming !!! */\n\ |
7797 | schaersvoo | 5680 | precision = %d;var xmin_start=xmin;var xmax_start=xmax;\ |
7729 | schaersvoo | 5681 | var ymin_start=ymin;var ymax_start=xmax;\ |
5682 | var zoom_x_increment=0;var zoom_y_increment=0;\ |
||
5683 | var pan_x_increment=0;var pan_y_increment=0;\ |
||
5684 | if(use_ylogscale == 0 ){\ |
||
7956 | schaersvoo | 5685 | zoom_x_increment = (xmax - xmin)/20;zoom_y_increment = (ymax - ymin)/20;pan_x_increment = (xmax - xmin)/20;pan_y_increment = (ymax - ymin)/20;\ |
7729 | schaersvoo | 5686 | }else{\ |
5687 | zoom_x_increment = (xmax - xmin)/20;\ |
||
5688 | pan_x_increment = (xmax - xmin)/20;\ |
||
5689 | };\ |
||
9406 | schaersvoo | 5690 | var zoom_xy=[xmin,xmax,ymin,ymax];\ |
7653 | schaersvoo | 5691 | function start_canvas%d(type){\ |
9406 | schaersvoo | 5692 | zoom_xy=[xmin,xmax,ymin,ymax];\ |
7653 | schaersvoo | 5693 | switch(type){\ |
7729 | schaersvoo | 5694 | case 0:xmin = xmin + zoom_x_increment;ymin = ymin + zoom_y_increment;xmax = xmax - zoom_x_increment;ymax = ymax - zoom_y_increment;break;\ |
5695 | case 1:xmin = xmin - zoom_x_increment;ymin = ymin - zoom_y_increment;xmax = xmax + zoom_x_increment;ymax = ymax + zoom_y_increment;break;\ |
||
7653 | schaersvoo | 5696 | case 2:xmin = xmin - pan_x_increment;ymin = ymin ;xmax = xmax - pan_x_increment;ymax = ymax;break;\ |
5697 | case 3:xmin = xmin + pan_x_increment;ymin = ymin ;xmax = xmax + pan_x_increment;ymax = ymax;break;\ |
||
5698 | case 4:xmin = xmin;ymin = ymin - pan_y_increment ;xmax = xmax;ymax = ymax - pan_y_increment;break;\ |
||
5699 | case 5:xmin = xmin;ymin = ymin + pan_y_increment ;xmax = xmax;ymax = ymax + pan_y_increment;break;\ |
||
11004 | schaersvoo | 5700 | case 6:xmin = xmin_start; xmax = xmax_start;ymin = ymin_start;ymax = ymax_start;break;\ |
7653 | schaersvoo | 5701 | default:break;\ |
5702 | };\ |
||
5703 | if(xmax<=xmin){xmin=xmin_start;xmax=xmax_start;};\ |
||
5704 | if(ymax<=ymin){ymin=ymin_start;ymax=ymax_start;};\ |
||
9406 | schaersvoo | 5705 | try{dragstuff.Zoom(xmin,xmax,ymin,ymax);}catch(e){};\ |
11088 | schaersvoo | 5706 | if(typeof(redraw_all%d) === 'function' ){redraw_all%d(zoom_xy);}\ |
9406 | schaersvoo | 5707 | %s ;\ |
7653 | schaersvoo | 5708 | };\ |
7797 | schaersvoo | 5709 | start_canvas%d(333);\ |
9438 | schaersvoo | 5710 | };\ |
13970 | obado | 5711 | \n/* end wims_canvas_function */\n\ |
9406 | schaersvoo | 5712 | wims_canvas_function%d();\n",precision,canvas_root_id,canvas_root_id,canvas_root_id,buffer,canvas_root_id,canvas_root_id); |
7797 | schaersvoo | 5713 | } |
5714 | else |
||
5715 | { |
||
5716 | /* no zoom, just add buffer */ |
||
13970 | obado | 5717 | fprintf(js_include_file,"\n/* add buffer */\n\ |
7797 | schaersvoo | 5718 | %s\ |
5719 | };\n\ |
||
13970 | obado | 5720 | /* end wims_canvas_function */\n\ |
7797 | schaersvoo | 5721 | wims_canvas_function%d();\n",buffer,canvas_root_id); |
5722 | } |
||
7614 | schaersvoo | 5723 | /* done writing the javascript include file */ |
5724 | fclose(js_include_file); |
||
5725 | |||
5726 | } |
||
5727 | |||
5728 | /* if using a tooltip, this should always be printed to the *.phtml file, so stdout */ |
||
9329 | schaersvoo | 5729 | if( use_tooltip > 0 ){ |
5730 | if( use_tooltip == 1 ){ |
||
5731 | add_js_tooltip(canvas_root_id,tooltip_text,bgcolor,xsize,ysize); |
||
5732 | } |
||
5733 | else |
||
5734 | { |
||
5735 | if( use_tooltip == 2 ){ |
||
5736 | add_js_popup(canvas_root_id,xsize,ysize,getfile_cmd); |
||
5737 | } |
||
5738 | } |
||
5739 | } |
||
7614 | schaersvoo | 5740 | exit(EXIT_SUCCESS); |
5741 | } |
||
5742 | /* end main() */ |
||
5743 | |||
5744 | /****************************************************************************** |
||
5745 | ** |
||
5746 | ** sync_input |
||
5747 | ** |
||
5748 | ** synchronises input line - reads to end of line, leaving file pointer |
||
5749 | ** at first character of next line. |
||
5750 | ** |
||
5751 | ** Used by: |
||
5752 | ** main program - error handling. |
||
5753 | ** |
||
5754 | ******************************************************************************/ |
||
5755 | void sync_input(FILE *infile) |
||
5756 | { |
||
5757 | int c = 0; |
||
5758 | |||
7658 | schaersvoo | 5759 | if( c == '\n' || c == ';' ) return; |
5760 | while( ( (c=getc(infile)) != EOF ) && (c != '\n') && (c != '\r') && (c != ';')) ; |
||
7614 | schaersvoo | 5761 | if( c == EOF ) finished = 1; |
7658 | schaersvoo | 5762 | if( c == '\n' || c == '\r' || c == ';') line_number++; |
7614 | schaersvoo | 5763 | return; |
5764 | } |
||
5765 | |||
5766 | /******************************************************************************/ |
||
5767 | |||
5768 | char *str_replace(const char *str, const char *old, const char *new){ |
||
5769 | /* http://creativeandcritical.net/str-replace-c/ */ |
||
5770 | if(strlen(str) > MAX_BUFFER){canvas_error("string argument too big");} |
||
5771 | char *ret, *r; |
||
5772 | const char *p, *q; |
||
5773 | size_t oldlen = strlen(old); |
||
5774 | size_t count = 0; |
||
5775 | size_t retlen = 0; |
||
5776 | size_t newlen = strlen(new); |
||
5777 | if (oldlen != newlen){ |
||
5778 | for (count = 0, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen){ |
||
5779 | count++; |
||
5780 | retlen = p - str + strlen(p) + count * (newlen - oldlen); |
||
5781 | } |
||
8224 | bpr | 5782 | } |
7614 | schaersvoo | 5783 | else |
5784 | { |
||
5785 | retlen = strlen(str); |
||
5786 | } |
||
8224 | bpr | 5787 | |
7614 | schaersvoo | 5788 | if ((ret = malloc(retlen + 1)) == NULL){ |
5789 | ret = NULL; |
||
5790 | canvas_error("string argument is NULL"); |
||
5791 | } |
||
5792 | else |
||
5793 | { |
||
5794 | for (r = ret, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen) { |
||
5795 | size_t l = q - p; |
||
5796 | memcpy(r, p, l); |
||
5797 | r += l; |
||
5798 | memcpy(r, new, newlen); |
||
5799 | r += newlen; |
||
5800 | } |
||
5801 | strcpy(r, p); |
||
5802 | } |
||
5803 | return ret; |
||
5804 | } |
||
5805 | |||
5806 | /******************************************************************************/ |
||
7848 | bpr | 5807 | |
7614 | schaersvoo | 5808 | char *get_color(FILE *infile , int last){ |
5809 | int c,i = 0,is_hex = 0; |
||
5810 | char temp[MAX_COLOR_STRING], *string; |
||
8305 | schaersvoo | 5811 | const char *not_allowed = "0123456789"; |
10891 | schaersvoo | 5812 | while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != ',' ) && ( c != ';' ) && ( c != '\t' ) ){ |
7614 | schaersvoo | 5813 | if( i > MAX_COLOR_STRING ){ canvas_error("colour string is too big ... ? ");} |
5814 | if( c == '#' ){ |
||
5815 | is_hex = 1; |
||
5816 | } |
||
5817 | if( c != ' '){ |
||
8304 | schaersvoo | 5818 | 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 | 5819 | temp[i]=tolower(c); |
5820 | i++; |
||
5821 | } |
||
5822 | } |
||
10891 | schaersvoo | 5823 | if( ( c == '\n' || c == EOF || c == ';' || c == '\t' ) && last == 0){canvas_error("expecting more arguments in command");} |
5824 | if( c == '\n' || c == ';' || c == '\t' ){ done = TRUE; line_number++; } |
||
7614 | schaersvoo | 5825 | if( c == EOF ){finished = 1;} |
5826 | if( finished == 1 && last != 1 ){ canvas_error("expected more arguments");} |
||
5827 | temp[i]='\0'; |
||
5828 | if( strlen(temp) == 0 ){ canvas_error("expected a colorname or hexnumber, but found nothing !!");} |
||
5829 | if( is_hex == 1 ){ |
||
5830 | char red[3], green[3], blue[3]; |
||
5831 | red[0] = toupper(temp[1]); red[1] = toupper(temp[2]); red[2] = '\0'; |
||
5832 | green[0] = toupper(temp[3]); green[1] = toupper(temp[4]); green[2] = '\0'; |
||
5833 | blue[0] = toupper(temp[5]); blue[1] = toupper(temp[6]); blue[2] = '\0'; |
||
5834 | int r = (int) strtol(red, NULL, 16); |
||
5835 | int g = (int) strtol(green, NULL, 16); |
||
5836 | int b = (int) strtol(blue, NULL, 16); |
||
5837 | string = (char *)my_newmem(12); |
||
5838 | snprintf(string,11,"%d,%d,%d",r,g,b); |
||
5839 | return string; |
||
5840 | } |
||
5841 | else |
||
5842 | { |
||
5843 | string = (char *)my_newmem(sizeof(temp)); |
||
5844 | snprintf(string,sizeof(temp),"%s",temp); |
||
8304 | schaersvoo | 5845 | for( i = 0; i < NUMBER_OF_COLORNAMES ; i++ ){ |
7614 | schaersvoo | 5846 | if( strcmp( colors[i].name , string ) == 0 ){ |
5847 | return colors[i].rgb; |
||
5848 | } |
||
5849 | } |
||
8304 | schaersvoo | 5850 | canvas_error("I was expecting a color name or hexnumber...but found nothing."); |
7614 | schaersvoo | 5851 | } |
8304 | schaersvoo | 5852 | return "0,0,255"; |
7614 | schaersvoo | 5853 | } |
5854 | |||
14066 | bpr | 5855 | char *get_string(FILE *infile,int last){ /* last = 0: more arguments ; last=1 final argument */ |
7614 | schaersvoo | 5856 | int c,i=0; |
5857 | char temp[MAX_BUFFER], *string; |
||
10891 | schaersvoo | 5858 | while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != '\t') ){ |
7614 | schaersvoo | 5859 | temp[i]=c; |
5860 | i++; |
||
5861 | if(i > MAX_BUFFER){ canvas_error("string size too big...repeat command to fit string");break;} |
||
5862 | } |
||
10891 | schaersvoo | 5863 | if( ( c == '\n' || c == '\t' || c == EOF ) && last == 0){canvas_error("expecting more arguments in command");} |
5864 | if( c == '\n' || c == '\t') { done = TRUE; line_number++; } |
||
11022 | schaersvoo | 5865 | if( c == EOF ) {finished = 1;} |
7614 | schaersvoo | 5866 | temp[i]='\0'; |
11022 | schaersvoo | 5867 | if( strlen(temp) == 0 && last != 3 ){ canvas_error("expected a word or string, but found nothing !!");} |
7614 | schaersvoo | 5868 | string=(char *)my_newmem(strlen(temp)); |
5869 | snprintf(string,sizeof(temp),"%s",temp); |
||
5870 | return string; |
||
5871 | } |
||
5872 | |||
14066 | bpr | 5873 | char *get_string_argument(FILE *infile,int last){ /* last = 0: more arguments ; last=1 final argument */ |
7614 | schaersvoo | 5874 | int c,i=0; |
5875 | char temp[MAX_BUFFER], *string; |
||
10891 | schaersvoo | 5876 | while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != '\t') && ( c != ',')){ |
7614 | schaersvoo | 5877 | temp[i]=c; |
5878 | i++; |
||
5879 | if(i > MAX_BUFFER){ canvas_error("string size too big...will cut it off");break;} |
||
5880 | } |
||
8224 | bpr | 5881 | if( ( c == '\n' || c == EOF) && last == 0){canvas_error("expecting more arguments in command");} |
10891 | schaersvoo | 5882 | if( c == '\n' || c == '\t' ) { line_number++; } |
7614 | schaersvoo | 5883 | if( c == EOF ) {finished = 1;} |
9478 | schaersvoo | 5884 | if( finished == 1 && last == 0 ){ canvas_error("expected more arguments");} |
7614 | schaersvoo | 5885 | temp[i]='\0'; |
10953 | bpr | 5886 | /* |
8322 | schaersvoo | 5887 | 17.10.2014 removed (question Perrin) |
5888 | may cause some unwanted effects... |
||
14078 | bpr | 5889 | if( strlen(temp) == 0 ){ canvas_error("expected a word or string (without comma), but found nothing !!");} |
8322 | schaersvoo | 5890 | */ |
7614 | schaersvoo | 5891 | string=(char *)my_newmem(sizeof(temp)); |
5892 | snprintf(string,sizeof(temp),"%s",temp); |
||
5893 | done = TRUE; |
||
5894 | return string; |
||
5895 | } |
||
5896 | |||
14066 | bpr | 5897 | double get_real(FILE *infile, int last){ /* accept anything that looks like an number ? last = 0: more arguments ; last=1 final argument */ |
7614 | schaersvoo | 5898 | int c,i=0,found_calc = 0; |
5899 | double y; |
||
5900 | char tmp[MAX_INT]; |
||
10953 | bpr | 5901 | /* |
14066 | bpr | 5902 | these things are 'allowed functions': *,^,+,-,/,(,),e,arc,cos,tan,pi,log,ln,sqrt,abs |
8383 | schaersvoo | 5903 | but there should be a better way to avoid segfaults ! |
8348 | schaersvoo | 5904 | */ |
5905 | const char *allowed = "earcostanpilogqb*+-/^()";/* assuming these are allowed stuff in a 'number'*/ |
||
5906 | const char *not_allowed = "#dfhjkmuvwxyz{}[]%&~!$";/* avoid segmentation faults in a "atof()" and "wims eval" */ |
||
10891 | schaersvoo | 5907 | while(( (c=getc(infile)) != EOF ) && ( c != ',') && (c != '\n') && (c != '\t') && ( c != ';')){ |
7614 | schaersvoo | 5908 | if( c != ' ' ){ |
8224 | bpr | 5909 | if( i == 0 && c == '+' ){ |
7614 | schaersvoo | 5910 | continue; |
8224 | bpr | 5911 | } |
7614 | schaersvoo | 5912 | else |
5913 | { |
||
8304 | schaersvoo | 5914 | c = tolower(c); |
5915 | if( strchr(not_allowed,c) != 0 ){canvas_error("found a character not associated with a number...");} |
||
5916 | if( strchr(allowed,c) != 0 ){found_calc = 1;}/* hand the string over to wims eval() */ |
||
7614 | schaersvoo | 5917 | tmp[i] = c; |
5918 | i++; |
||
5919 | } |
||
5920 | } |
||
5921 | if( i > MAX_INT - 1){canvas_error("number too large");} |
||
5922 | } |
||
10891 | schaersvoo | 5923 | if( ( c == '\n' || c == EOF || c == ';' || c == '\t' ) && last == 0){canvas_error("expecting more arguments in command");} |
5924 | if( c == '\n' || c == ';' || c == '\t' ){ done = TRUE; line_number++; } |
||
7614 | schaersvoo | 5925 | if( c == EOF ){done = TRUE ; finished = 1;} |
5926 | tmp[i]='\0'; |
||
5927 | if( strlen(tmp) == 0 ){canvas_error("expected a number , but found nothing !!");} |
||
8304 | schaersvoo | 5928 | if( found_calc == 1 ){ /* use wims eval to calculate 2*pi/3 */ |
7848 | bpr | 5929 | void *f = eval_create(tmp); |
7614 | schaersvoo | 5930 | assert(f);if( f == NULL ){canvas_error("I'm having trouble parsing your \"expression\" ") ;} |
7848 | bpr | 5931 | y = eval_x(f, 1); |
14066 | bpr | 5932 | /* if function is bogus; y = 1: so no core dumps */ |
7848 | bpr | 5933 | eval_destroy(f); |
7614 | schaersvoo | 5934 | } |
5935 | else |
||
5936 | { |
||
5937 | y = atof(tmp); |
||
5938 | } |
||
5939 | return y; |
||
5940 | } |
||
8304 | schaersvoo | 5941 | |
13829 | bpr | 5942 | |
7614 | schaersvoo | 5943 | void canvas_error(char *msg){ |
14066 | bpr | 5944 | fprintf(stdout,"\n</script><hr /><span style=\"color:red\">FATAL syntax error:line %d: %s</span><hr />",line_number,msg); |
7614 | schaersvoo | 5945 | finished = 1; |
5946 | exit(EXIT_SUCCESS); |
||
5947 | } |
||
5948 | |||
5949 | |||
5950 | /* convert x/y coordinates to pixel */ |
||
5951 | int x2px(double x){ |
||
5952 | return x*xsize/(xmax - xmin) - xsize*xmin/(xmax - xmin); |
||
5953 | } |
||
5954 | |||
5955 | int y2px(double y){ |
||
5956 | return -1*y*ysize/(ymax - ymin) + ymax*ysize/(ymax - ymin); |
||
5957 | } |
||
5958 | |||
5959 | double px2x(int x){ |
||
5960 | return (x*(xmax - xmin)/xsize + xmin); |
||
5961 | } |
||
5962 | double px2y(int y){ |
||
5963 | return (y*(ymax - ymin)/ysize + ymin); |
||
5964 | } |
||
5965 | |||
5966 | void add_to_buffer(char *tmp){ |
||
5967 | if( tmp == NULL || tmp == 0 ){ canvas_error("nothing to add_to_buffer()...");} |
||
5968 | /* do we have enough space left in buffer[MAX_BUFFER] ? */ |
||
5969 | int space_left = (int) (sizeof(buffer) - strlen(buffer)); |
||
5970 | if( space_left > strlen(tmp)){ |
||
5971 | strncat(buffer,tmp,space_left - 1);/* add safely "tmp" to the string buffer */ |
||
5972 | } |
||
5973 | else |
||
5974 | { |
||
5975 | canvas_error("buffer is too big\n"); |
||
5976 | } |
||
5977 | tmp = NULL;free(tmp); |
||
5978 | return; |
||
5979 | } |
||
5980 | |||
5981 | void reset(){ |
||
14038 | schaersvoo | 5982 | use_filled = FALSE; |
5983 | use_dashed = FALSE; |
||
5984 | use_rotate = FALSE; |
||
8379 | schaersvoo | 5985 | onclick = 0; |
7614 | schaersvoo | 5986 | } |
5987 | |||
5988 | |||
5989 | |||
5990 | /* What reply format in read_canvas(); |
||
5991 | |||
5992 | note:if userdraw is combined with inputfields...every "userdraw" based answer will append "\n" and inputfield.value() |
||
5993 | 1 = x1,x2,x3,x4....x_n |
||
5994 | y1,y2,y3,y4....y_n |
||
5995 | |||
5996 | x/y in pixels |
||
5997 | |||
5998 | 2 = x1,x2,x3,x4....x_n |
||
5999 | y1,y2,y3,y4....y_n |
||
6000 | x/y in xrange / yrange coordinate system |
||
6001 | |||
6002 | 3 = x1,x2,x3,x4....x_n |
||
6003 | y1,y2,y3,y4....y_n |
||
6004 | r1,r2,r3,r4....r_n |
||
6005 | |||
8224 | bpr | 6006 | x/y in pixels |
7614 | schaersvoo | 6007 | r in pixels |
6008 | |||
6009 | 4 = x1,x2,x3,x4....x_n |
||
6010 | y1,y2,y3,y4....y_n |
||
6011 | r1,r2,r3,r4....r_n |
||
6012 | |||
6013 | x/y in xrange / yrange coordinate system |
||
6014 | r in pixels |
||
6015 | |||
6016 | 5 = Ax1,Ax2,Ax3,Ax4....Ax_n |
||
6017 | Ay1,Ay2,Ay3,Ay4....Ay_n |
||
6018 | Bx1,Bx2,Bx3,Bx4....Bx_n |
||
6019 | By1,By2,By3,By4....By_n |
||
6020 | Cx1,Cx2,Cx3,Cx4....Cx_n |
||
6021 | Cy1,Cy2,Cy3,Cy4....Cy_n |
||
6022 | .... |
||
6023 | Zx1,Zx2,Zx3,Zx4....Zx_n |
||
6024 | Zy1,Zy2,Zy3,Zy4....Zy_n |
||
8224 | bpr | 6025 | |
7614 | schaersvoo | 6026 | x/y in pixels |
6027 | |||
6028 | 6 = Ax1,Ax2,Ax3,Ax4....Ax_n |
||
6029 | Ay1,Ay2,Ay3,Ay4....Ay_n |
||
6030 | Bx1,Bx2,Bx3,Bx4....Bx_n |
||
6031 | By1,By2,By3,By4....By_n |
||
6032 | Cx1,Cx2,Cx3,Cx4....Cx_n |
||
6033 | Cy1,Cy2,Cy3,Cy4....Cy_n |
||
6034 | .... |
||
6035 | Zx1,Zx2,Zx3,Zx4....Zx_n |
||
6036 | Zy1,Zy2,Zy3,Zy4....Zy_n |
||
6037 | |||
6038 | x/y in xrange / yrange coordinate system |
||
8224 | bpr | 6039 | |
7614 | schaersvoo | 6040 | 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n |
8224 | bpr | 6041 | |
7614 | schaersvoo | 6042 | x/y in pixels |
6043 | |||
6044 | 8 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n |
||
8224 | bpr | 6045 | |
7614 | schaersvoo | 6046 | x/y in xrange / yrange coordinate system |
6047 | |||
8224 | bpr | 6048 | 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n |
7614 | schaersvoo | 6049 | |
6050 | x/y in pixels |
||
6051 | |||
14044 | schaersvoo | 6052 | 10 = x1 ; y1 ;r1 \n x2;y2;r2 \n x3;y3;r3 \n ...x_n:y_n:r_n \n |
7614 | schaersvoo | 6053 | |
6054 | x/y in xrange / yrange coordinate system |
||
14044 | schaersvoo | 6055 | r is userdraw_radius |
7614 | schaersvoo | 6056 | |
6057 | 11 = Ax1,Ay1,Ax2,Ay2 |
||
6058 | Bx1,By1,Bx2,By2 |
||
6059 | Cx1,Cy1,Cx2,Cy2 |
||
6060 | Dx1,Dy1,Dx2,Dy2 |
||
6061 | ...... |
||
6062 | Zx1,Zy1,Zx2,Zy2 |
||
8224 | bpr | 6063 | |
7614 | schaersvoo | 6064 | x/y in xrange / yrange coordinate system |
6065 | |||
6066 | 12 = Ax1,Ay1,Ax2,Ay2 |
||
6067 | Bx1,By1,Bx2,By2 |
||
6068 | Cx1,Cy1,Cx2,Cy2 |
||
6069 | Dx1,Dy1,Dx2,Dy2 |
||
6070 | ...... |
||
6071 | Zx1,Zy1,Zx2,Zy2 |
||
8224 | bpr | 6072 | |
7614 | schaersvoo | 6073 | x/y in pixels |
6074 | |||
14078 | bpr | 6075 | 13 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2,Cx1:Cy1:Cx2:Cy2,Dx1:Dy1:Dx2:Dy2, ..., Zx1:Zy1:Zx2:Zy2 |
7614 | schaersvoo | 6076 | |
6077 | x/y in xrange / yrange coordinate system |
||
6078 | 14 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2....Zx1:Zy1:Zx2:Zy2 |
||
6079 | x/y in pixels |
||
6080 | 15 = reply from inputfields,textareas |
||
6081 | reply1,reply2,reply3,...,reply_n |
||
14071 | bpr | 6082 | only fields set write (e.g. will not read readonly inputfield values. |
7614 | schaersvoo | 6083 | |
6084 | 16 = read mathml inputfields only |
||
6085 | |||
11080 | schaersvoo | 6086 | 17 = read userdraw text only (x1,y1,text1\nx2,y2,text2..\n.x_n,y_n,text_n |
14066 | bpr | 6087 | when ready: calculate size_t of string via snprintf(NULL,0,"blah blah..."); |
7614 | schaersvoo | 6088 | |
14066 | bpr | 6089 | 18 = read clock(s): H1:M1:S1,H2:M2:S2,...H_n:M_n:S_n |
7614 | schaersvoo | 6090 | 19 = return clicked object number (analogue to shape-library onclick) |
14071 | bpr | 6091 | 20 = return x/y-data in x-range/y-range of all ''draggable`` images |
7614 | schaersvoo | 6092 | 21 = return verbatim coordinates (x1:y1) (x2:y2)...(x_n:y_n) |
14066 | bpr | 6093 | 22 = array: x1,y1,x2,y2,x3,y3,x4,y4...x_n,y_n |
7614 | schaersvoo | 6094 | x/y in xrange / yrange coordinate system |
14071 | bpr | 6095 | 23 = answertype for a polyline: remove multiple occurences due to reclick on a point to create next polyline segment |
6096 | 24 = read all inputfield values: even those set <code>readonly</code> |
||
8224 | bpr | 6097 | 25 = return all userdrawn arcs in degrees: |
6098 | 26 = return all userdrawn arcs in radians: |
||
11080 | schaersvoo | 6099 | 27 = return (only) userdraw inputfields array: x1,y1,text1 \n x2,y2,text2... |
8322 | schaersvoo | 6100 | 28 = x1,y1,r1,x2,y2,r2...x_n,y_n,r_n |
10953 | bpr | 6101 | x/y/r in xrange / yrange coordinate system: may be used to reinput into command |
14071 | bpr | 6102 | <code>circles color,x1,y1,r1,x2,y2,r2...x_n,y_n,r_n</code> |
14078 | bpr | 6103 | will not return anything else (e.g. no inputfields, text etc) |
14066 | bpr | 6104 | 29 = mulidraw read: |
10953 | bpr | 6105 | |
7614 | schaersvoo | 6106 | */ |
6107 | |||
14066 | bpr | 6108 | /* |
6109 | SCHAERSVOORDE: replyformat 2,7,8,21,22,23,24 |
||
14044 | schaersvoo | 6110 | USERDRAW DEFAULTS: 2,6,8,10,11,15,16,17,18,19,20,23,24,25,27,29,31 |
14066 | bpr | 6111 | OEF: 22,23,28 |
14044 | schaersvoo | 6112 | */ |
8257 | schaersvoo | 6113 | void add_read_canvas(int canvas_root_id,int type_reply,int reply_precision){ |
14038 | schaersvoo | 6114 | /* just 1 reply type allowed...except for format 34 !!! */ |
8074 | schaersvoo | 6115 | fprintf(js_include_file,"\ |
13970 | obado | 6116 | \n/* begin set_reply_precision() */\n\ |
8074 | schaersvoo | 6117 | function set_reply_precision(){\ |
6118 | var len = userdraw_x.length;\ |
||
6119 | var prec = %d;\ |
||
6120 | for(var p = 0 ; p < len ; p++ ){\ |
||
6121 | userdraw_x[p] = (Math.round(prec*userdraw_x[p]))/prec;\ |
||
6122 | userdraw_y[p] = (Math.round(prec*userdraw_y[p]))/prec;\ |
||
6123 | };\ |
||
6124 | len = userdraw_radius.length;\ |
||
6125 | if( len > 0 ){\ |
||
6126 | for(var p = 0 ; p < len ; p++ ){\ |
||
6127 | userdraw_radius[p] = (Math.round(prec*userdraw_radius[p]))/prec;\ |
||
6128 | };\ |
||
6129 | };\ |
||
6130 | };",reply_precision); |
||
7963 | schaersvoo | 6131 | |
7614 | schaersvoo | 6132 | switch(type_reply){ |
8224 | bpr | 6133 | /* |
7614 | schaersvoo | 6134 | answers may have: |
6135 | x-values,y-values,r-values,input-fields,mathml-inputfields,text-typed answers |
||
6136 | */ |
||
6137 | case 1: fprintf(js_include_file,"\ |
||
13970 | obado | 6138 | \n/* begin function 1 read_canvas%d() */\n\ |
8257 | schaersvoo | 6139 | read_canvas%d = function(){\ |
7614 | schaersvoo | 6140 | if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\ |
8074 | schaersvoo | 6141 | set_reply_precision();\ |
7614 | schaersvoo | 6142 | if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\ |
6143 | var p = 0;var input_reply = new Array();\ |
||
6144 | if( document.getElementById(\"canvas_input0\")){\ |
||
6145 | var t = 0;\ |
||
6146 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
6147 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
6148 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
6149 | p++;\ |
||
6150 | };\ |
||
6151 | t++;\ |
||
6152 | };\ |
||
6153 | };\ |
||
11088 | schaersvoo | 6154 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6155 | return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+input_reply + \"\\n\"+userdraw_text;\ |
6156 | }\ |
||
6157 | else\ |
||
6158 | {\ |
||
6159 | return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+input_reply;\ |
||
6160 | }\ |
||
6161 | }\ |
||
6162 | else\ |
||
6163 | {\ |
||
11088 | schaersvoo | 6164 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6165 | return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_text;\ |
6166 | }\ |
||
6167 | else\ |
||
6168 | {\ |
||
6169 | return userdraw_x+\"\\n\"+userdraw_y;\ |
||
6170 | }\ |
||
6171 | };\ |
||
8108 | schaersvoo | 6172 | };\n\ |
13970 | obado | 6173 | /* end function 1 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 6174 | break; |
6175 | case 2: fprintf(js_include_file,"\ |
||
13970 | obado | 6176 | \n/* begin function 2 read_canvas%d() */\n\ |
8257 | schaersvoo | 6177 | read_canvas%d = function(){\ |
7614 | schaersvoo | 6178 | if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\ |
8074 | schaersvoo | 6179 | set_reply_precision();\ |
7614 | schaersvoo | 6180 | var reply_x = new Array();var reply_y = new Array();var p = 0;\ |
8074 | schaersvoo | 6181 | var prec = %d;\ |
7614 | schaersvoo | 6182 | while(userdraw_x[p]){\ |
8074 | schaersvoo | 6183 | reply_x[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\ |
6184 | reply_y[p] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\ |
||
7614 | schaersvoo | 6185 | p++;\ |
6186 | };\ |
||
11806 | schaersvoo | 6187 | if(p == 0){return;};\ |
7614 | schaersvoo | 6188 | if( document.getElementById(\"canvas_input0\")){\ |
6189 | var p = 0;var input_reply = new Array();\ |
||
6190 | if( document.getElementById(\"canvas_input0\")){\ |
||
6191 | var t = 0;\ |
||
6192 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
6193 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
6194 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
6195 | p++;\ |
||
6196 | };\ |
||
6197 | t++;\ |
||
6198 | };\ |
||
6199 | };\ |
||
11088 | schaersvoo | 6200 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6201 | return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
6202 | }\ |
||
6203 | else\ |
||
6204 | {\ |
||
6205 | return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply;\ |
||
6206 | }\ |
||
6207 | }\ |
||
6208 | else\ |
||
6209 | {\ |
||
11088 | schaersvoo | 6210 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6211 | return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_text;\ |
6212 | }\ |
||
6213 | else\ |
||
6214 | {\ |
||
6215 | return reply_x+\"\\n\"+reply_y;\ |
||
6216 | };\ |
||
6217 | };\ |
||
8108 | schaersvoo | 6218 | };\n\ |
13970 | obado | 6219 | /* end function 2 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7614 | schaersvoo | 6220 | break; |
6221 | case 3: fprintf(js_include_file,"\ |
||
13970 | obado | 6222 | \n/* begin function 3 read_canvas%d() */\n\ |
8257 | schaersvoo | 6223 | read_canvas%d = function(){\ |
7614 | schaersvoo | 6224 | if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\ |
8074 | schaersvoo | 6225 | set_reply_precision();\ |
7614 | schaersvoo | 6226 | if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\ |
6227 | var p = 0;var input_reply = new Array();\ |
||
6228 | if( document.getElementById(\"canvas_input0\")){\ |
||
6229 | var t = 0;\ |
||
6230 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
6231 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
6232 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
6233 | p++;\ |
||
6234 | };\ |
||
6235 | t++;\ |
||
6236 | };\ |
||
6237 | };\ |
||
11088 | schaersvoo | 6238 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6239 | return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
6240 | }\ |
||
6241 | else\ |
||
6242 | {\ |
||
6243 | return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+input_reply;\ |
||
6244 | }\ |
||
6245 | }\ |
||
6246 | else\ |
||
6247 | {\ |
||
11088 | schaersvoo | 6248 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6249 | return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+userdrawW_text;\ |
6250 | }\ |
||
6251 | else\ |
||
6252 | {\ |
||
6253 | return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius;\ |
||
6254 | }\ |
||
6255 | }\ |
||
8108 | schaersvoo | 6256 | };\n\ |
13970 | obado | 6257 | /* end function 3 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 6258 | break; |
6259 | case 4: fprintf(js_include_file,"\ |
||
13970 | obado | 6260 | \n/* begin function 4 read_canvas%d() */\n\ |
8257 | schaersvoo | 6261 | read_canvas%d = function(){\ |
8074 | schaersvoo | 6262 | var prec = %d;\ |
7614 | schaersvoo | 6263 | var reply_x = new Array();var reply_y = new Array();var p = 0;\ |
6264 | while(userdraw_x[p]){\ |
||
8074 | schaersvoo | 6265 | reply_x[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\ |
6266 | reply_y[p] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;;\ |
||
7614 | schaersvoo | 6267 | p++;\ |
6268 | };\ |
||
11806 | schaersvoo | 6269 | if(p == 0){return;};\ |
7614 | schaersvoo | 6270 | if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\ |
6271 | var p = 0;var input_reply = new Array();\ |
||
6272 | if( document.getElementById(\"canvas_input0\")){\ |
||
6273 | var t = 0;\ |
||
6274 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
6275 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
6276 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
6277 | p++;\ |
||
6278 | };\ |
||
6279 | t++;\ |
||
6280 | };\ |
||
6281 | };\ |
||
11088 | schaersvoo | 6282 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6283 | return reply_x+\"\\n\"+reply_y +\"\\n\"+userdraw_radius+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
6284 | }\ |
||
6285 | else\ |
||
6286 | {\ |
||
6287 | return reply_x+\"\\n\"+reply_y +\"\\n\"+userdraw_radius+\"\\n\"+input_reply;\ |
||
6288 | }\ |
||
6289 | }\ |
||
6290 | else\ |
||
6291 | {\ |
||
11088 | schaersvoo | 6292 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6293 | return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_radius+\"\\n\"+userdraw_text;\ |
6294 | }\ |
||
6295 | else\ |
||
6296 | {\ |
||
6297 | return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_radius;\ |
||
6298 | }\ |
||
6299 | };\ |
||
8108 | schaersvoo | 6300 | };\n\ |
13970 | obado | 6301 | /* end function 4 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7614 | schaersvoo | 6302 | break; |
8224 | bpr | 6303 | /* |
14066 | bpr | 6304 | attention: we reset userdraw_x / userdraw_y: because userdraw_x = [][] userdraw_y = [][] |
8224 | bpr | 6305 | used for userdraw multiple paths |
7614 | schaersvoo | 6306 | */ |
6307 | case 5: fprintf(js_include_file,"\ |
||
13970 | obado | 6308 | \n/* begin function 5 read_canvas%d() */\n\ |
8257 | schaersvoo | 6309 | read_canvas%d = function(){\ |
8074 | schaersvoo | 6310 | set_reply_precision();\ |
7614 | schaersvoo | 6311 | var p = 0;\ |
6312 | var reply = \"\";\ |
||
6313 | for(p = 0; p < userdraw_x.length;p++){\ |
||
6314 | if(userdraw_x[p] != null ){\ |
||
6315 | reply = reply + userdraw_x[p]+\"\\n\"+userdraw_y[p]+\"\\n\";\ |
||
6316 | };\ |
||
6317 | };\ |
||
11806 | schaersvoo | 6318 | if(p == 0){return;};\ |
7614 | schaersvoo | 6319 | userdraw_x = [];userdraw_y = [];\ |
6320 | if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\ |
||
6321 | var p = 0;var input_reply = new Array();\ |
||
6322 | if( document.getElementById(\"canvas_input0\")){\ |
||
6323 | var t = 0;\ |
||
6324 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
6325 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
6326 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
6327 | p++;\ |
||
6328 | };\ |
||
6329 | t++;\ |
||
6330 | };\ |
||
6331 | };\ |
||
11088 | schaersvoo | 6332 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6333 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
6334 | }\ |
||
6335 | else\ |
||
6336 | {\ |
||
6337 | return reply +\"\\n\"+input_reply;\ |
||
6338 | }\ |
||
6339 | }\ |
||
6340 | else\ |
||
6341 | {\ |
||
11088 | schaersvoo | 6342 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6343 | return reply+\"\\n\"+userdraw_text;\ |
6344 | }\ |
||
6345 | else\ |
||
6346 | {\ |
||
6347 | return reply;\ |
||
6348 | }\ |
||
6349 | };\ |
||
8108 | schaersvoo | 6350 | };\n\ |
13970 | obado | 6351 | /* end function 5 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 6352 | break; |
8224 | bpr | 6353 | /* |
14066 | bpr | 6354 | attention: we reset userdraw_x / userdraw_y: because userdraw_x = [][] userdraw_y = [][] |
8224 | bpr | 6355 | used for userdraw multiple paths |
7614 | schaersvoo | 6356 | */ |
6357 | case 6: fprintf(js_include_file,"\ |
||
13970 | obado | 6358 | \n/* begin function 6 read_canvas%d() */\n\ |
8257 | schaersvoo | 6359 | read_canvas%d = function(){\ |
7614 | schaersvoo | 6360 | var p = 0;\ |
6361 | var reply = \"\";\ |
||
6362 | var tmp_x = new Array();\ |
||
6363 | var tmp_y = new Array();\ |
||
8074 | schaersvoo | 6364 | var prec = %d;\ |
7614 | schaersvoo | 6365 | for(p = 0 ; p < userdraw_x.length; p++){\ |
6366 | tmp_x = userdraw_x[p];\ |
||
6367 | tmp_y = userdraw_y[p];\ |
||
6368 | if(tmp_x != null){\ |
||
6369 | for(var i = 0 ; i < tmp_x.length ; i++){\ |
||
8074 | schaersvoo | 6370 | tmp_x[i] = (Math.round(prec*(px2x(tmp_x[i]))))/prec;\ |
6371 | tmp_y[i] = (Math.round(prec*(px2y(tmp_y[i]))))/prec;\ |
||
7614 | schaersvoo | 6372 | };\ |
6373 | reply = reply + tmp_x + \"\\n\" + tmp_y +\"\\n\";\ |
||
6374 | };\ |
||
6375 | };\ |
||
11806 | schaersvoo | 6376 | if(p == 0){return;};\ |
7614 | schaersvoo | 6377 | userdraw_x = [];userdraw_y = [];\ |
6378 | if( document.getElementById(\"canvas_input0\") ){\ |
||
6379 | var p = 0;var input_reply = new Array();\ |
||
6380 | if( document.getElementById(\"canvas_input0\")){\ |
||
6381 | var t = 0;\ |
||
6382 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
6383 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
6384 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
6385 | p++;\ |
||
6386 | };\ |
||
6387 | t++;\ |
||
6388 | };\ |
||
6389 | };\ |
||
11088 | schaersvoo | 6390 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6391 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
6392 | }\ |
||
6393 | else\ |
||
6394 | {\ |
||
6395 | return reply +\"\\n\"+input_reply;\ |
||
6396 | }\ |
||
6397 | }\ |
||
6398 | else\ |
||
6399 | {\ |
||
11088 | schaersvoo | 6400 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6401 | return reply +\"\\n\"+userdraw_text;\ |
6402 | }\ |
||
6403 | else\ |
||
6404 | {\ |
||
6405 | return reply;\ |
||
6406 | }\ |
||
6407 | };\ |
||
8108 | schaersvoo | 6408 | };\n\ |
13970 | obado | 6409 | /* end function 6 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7614 | schaersvoo | 6410 | break; |
6411 | case 7: fprintf(js_include_file,"\ |
||
13970 | obado | 6412 | \n/* begin function 7 read_canvas%d() */\n\ |
8257 | schaersvoo | 6413 | read_canvas%d = function(){\ |
8074 | schaersvoo | 6414 | set_reply_precision();\ |
7614 | schaersvoo | 6415 | var reply = new Array();\ |
6416 | var p = 0;\ |
||
6417 | while(userdraw_x[p]){\ |
||
6418 | reply[p] = userdraw_x[p] +\":\" + userdraw_y[p];\ |
||
6419 | p++;\ |
||
6420 | };\ |
||
11806 | schaersvoo | 6421 | if(p == 0){return;};\ |
7614 | schaersvoo | 6422 | if( document.getElementById(\"canvas_input0\") ){\ |
6423 | var p = 0;var input_reply = new Array();\ |
||
6424 | if( document.getElementById(\"canvas_input0\")){\ |
||
6425 | var t = 0;\ |
||
6426 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
6427 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
6428 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
6429 | p++;\ |
||
6430 | };\ |
||
6431 | t++;\ |
||
6432 | };\ |
||
6433 | };\ |
||
11088 | schaersvoo | 6434 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6435 | return reply+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
6436 | }\ |
||
6437 | else\ |
||
6438 | {\ |
||
6439 | return reply+\"\\n\"+input_reply;\ |
||
6440 | }\ |
||
7862 | schaersvoo | 6441 | }\ |
7614 | schaersvoo | 6442 | else\ |
6443 | {\ |
||
11088 | schaersvoo | 6444 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6445 | return reply+\"\\n\"+userdraw_text;\ |
6446 | }\ |
||
6447 | else\ |
||
6448 | {\ |
||
6449 | return reply;\ |
||
6450 | }\ |
||
6451 | };\ |
||
8108 | schaersvoo | 6452 | };\n\ |
13970 | obado | 6453 | /* end function 7 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 6454 | break; |
6455 | case 8: fprintf(js_include_file,"\ |
||
13970 | obado | 6456 | \n/* begin function 8 read_canvas%d() */\n\ |
8257 | schaersvoo | 6457 | read_canvas%d = function(){\ |
7614 | schaersvoo | 6458 | var reply = new Array();\ |
6459 | var p = 0;\ |
||
8074 | schaersvoo | 6460 | var prec = %d;\ |
7614 | schaersvoo | 6461 | while(userdraw_x[p]){\ |
8074 | schaersvoo | 6462 | reply[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec +\":\" + (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\ |
7614 | schaersvoo | 6463 | p++;\ |
6464 | };\ |
||
11806 | schaersvoo | 6465 | if(p == 0){return;};\ |
7614 | schaersvoo | 6466 | if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\ |
6467 | var p = 0;var input_reply = new Array();\ |
||
6468 | if( document.getElementById(\"canvas_input0\")){\ |
||
6469 | var t = 0;\ |
||
6470 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
6471 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
6472 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
6473 | p++;\ |
||
6474 | };\ |
||
6475 | t++;\ |
||
6476 | };\ |
||
6477 | };\ |
||
11088 | schaersvoo | 6478 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6479 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
6480 | }\ |
||
6481 | else\ |
||
6482 | {\ |
||
6483 | return reply +\"\\n\"+input_reply;\ |
||
6484 | }\ |
||
6485 | }\ |
||
6486 | else\ |
||
6487 | {\ |
||
11088 | schaersvoo | 6488 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6489 | return reply +\"\\n\"+userdraw_text;\ |
6490 | }\ |
||
6491 | else\ |
||
6492 | {\ |
||
6493 | return reply;\ |
||
6494 | }\ |
||
6495 | };\ |
||
8108 | schaersvoo | 6496 | };\n\ |
13970 | obado | 6497 | /* end function 8 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7614 | schaersvoo | 6498 | break; |
6499 | case 9: fprintf(js_include_file,"\ |
||
13970 | obado | 6500 | \n/* begin function 9 read_canvas%d() */\n\ |
8257 | schaersvoo | 6501 | read_canvas%d = function(){\ |
8074 | schaersvoo | 6502 | set_reply_precision();\ |
7614 | schaersvoo | 6503 | var reply = new Array();\ |
6504 | var p = 0;\ |
||
6505 | while(userdraw_x[p]){\ |
||
6506 | reply[p] = userdraw_x[p] +\":\" + userdraw_y[p] + \":\" + userdraw_radius[p];\ |
||
6507 | p++;\ |
||
6508 | };\ |
||
11806 | schaersvoo | 6509 | if(p == 0){return;};\ |
7614 | schaersvoo | 6510 | if( document.getElementById(\"canvas_input0\") ){\ |
6511 | var p = 0;var input_reply = new Array();\ |
||
6512 | if( document.getElementById(\"canvas_input0\")){\ |
||
6513 | var t = 0;\ |
||
6514 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
6515 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
6516 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
6517 | p++;\ |
||
6518 | };\ |
||
6519 | t++;\ |
||
6520 | };\ |
||
6521 | };\ |
||
11088 | schaersvoo | 6522 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6523 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
6524 | }\ |
||
6525 | else\ |
||
6526 | {\ |
||
6527 | return reply +\"\\n\"+input_reply;\ |
||
6528 | }\ |
||
6529 | }\ |
||
6530 | else\ |
||
6531 | {\ |
||
11088 | schaersvoo | 6532 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6533 | return reply +\"\\n\"+userdraw_text;\ |
6534 | }\ |
||
6535 | else\ |
||
6536 | {\ |
||
6537 | return reply;\ |
||
6538 | }\ |
||
6539 | };\ |
||
8108 | schaersvoo | 6540 | };\n\ |
13970 | obado | 6541 | /* end function 9 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 6542 | break; |
6543 | case 10: fprintf(js_include_file,"\ |
||
13970 | obado | 6544 | \n/* begin function 10 read_canvas%d() */\n\ |
8257 | schaersvoo | 6545 | read_canvas%d = function(){\ |
7614 | schaersvoo | 6546 | var reply = new Array();\ |
6547 | var p = 0;\ |
||
8074 | schaersvoo | 6548 | var prec = %d;\ |
14044 | schaersvoo | 6549 | var reply = \"\";\ |
7614 | schaersvoo | 6550 | while(userdraw_x[p]){\ |
14044 | schaersvoo | 6551 | reply = reply + (Math.round(prec*(px2x(userdraw_x[p]))))/prec +\";\" + (Math.round(prec*(px2y(userdraw_y[p]))))/prec + \";\" + (Math.round(prec*userdraw_radius[p]))/prec + \"\\n\";\ |
7614 | schaersvoo | 6552 | p++;\ |
6553 | };\ |
||
11806 | schaersvoo | 6554 | if(p == 0){return;};\ |
14044 | schaersvoo | 6555 | return reply;\ |
8108 | schaersvoo | 6556 | };\n\ |
13970 | obado | 6557 | /* end function 10 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7614 | schaersvoo | 6558 | break; |
6559 | case 11: fprintf(js_include_file,"\ |
||
13970 | obado | 6560 | \n/* begin function 11 read_canvas%d() */\n\ |
8257 | schaersvoo | 6561 | read_canvas%d = function(){\ |
7614 | schaersvoo | 6562 | var reply = \"\";\ |
6563 | var p = 0;\ |
||
8074 | schaersvoo | 6564 | var prec = %d;\ |
13521 | schaersvoo | 6565 | while(userdraw_x[p+1]){\ |
8074 | schaersvoo | 6566 | reply = reply + (Math.round(prec*(px2x(userdraw_x[p]))))/prec +\",\" + (Math.round(prec*(px2y(userdraw_y[p]))))/prec +\",\" + (Math.round(prec*(px2x(userdraw_x[p+1]))))/prec +\",\" + (Math.round(prec*(px2y(userdraw_y[p+1]))))/prec +\"\\n\" ;\ |
7614 | schaersvoo | 6567 | p = p+2;\ |
6568 | };\ |
||
11806 | schaersvoo | 6569 | if(p == 0){return;};\ |
7614 | schaersvoo | 6570 | if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\ |
6571 | var p = 0;var input_reply = new Array();\ |
||
6572 | if( document.getElementById(\"canvas_input0\")){\ |
||
6573 | var t = 0;\ |
||
6574 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
6575 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
6576 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
6577 | p++;\ |
||
6578 | };\ |
||
6579 | t++;\ |
||
6580 | };\ |
||
6581 | };\ |
||
11088 | schaersvoo | 6582 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6583 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
6584 | }\ |
||
6585 | else\ |
||
6586 | {\ |
||
6587 | return reply +\"\\n\"+input_reply;\ |
||
6588 | }\ |
||
6589 | }\ |
||
6590 | else\ |
||
6591 | {\ |
||
11088 | schaersvoo | 6592 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6593 | return reply +\"\\n\"+userdraw_text;\ |
6594 | }\ |
||
6595 | else\ |
||
6596 | {\ |
||
6597 | return reply;\ |
||
6598 | }\ |
||
6599 | };\ |
||
8108 | schaersvoo | 6600 | };\n\ |
13970 | obado | 6601 | /* end function 11 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7614 | schaersvoo | 6602 | break; |
6603 | case 12: fprintf(js_include_file,"\ |
||
13970 | obado | 6604 | \n/* begin function 12 read_canvas%d() */\n\ |
8257 | schaersvoo | 6605 | read_canvas%d = function(){\ |
8074 | schaersvoo | 6606 | set_reply_precision();\ |
7614 | schaersvoo | 6607 | var reply = \"\";\ |
6608 | var p = 0;\ |
||
13522 | schaersvoo | 6609 | while(userdraw_x[p+1]){\ |
6610 | reply = reply + userdraw_x[p] +\",\" + userdraw_y[p] +\",\" + userdraw_x[p+1] +\",\" + userdraw_y[p+1] +\"\\n\" ;\ |
||
6611 | p=p+2;\ |
||
7614 | schaersvoo | 6612 | };\ |
13522 | schaersvoo | 6613 | };\ |
11806 | schaersvoo | 6614 | if(p == 0){return;};\ |
7614 | schaersvoo | 6615 | if( document.getElementById(\"canvas_input0\") ){\ |
6616 | var p = 0;var input_reply = new Array();\ |
||
6617 | if( document.getElementById(\"canvas_input0\")){\ |
||
6618 | var t = 0;\ |
||
6619 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
6620 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
6621 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
6622 | p++;\ |
||
6623 | };\ |
||
6624 | t++;\ |
||
6625 | };\ |
||
6626 | };\ |
||
11088 | schaersvoo | 6627 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6628 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
6629 | }\ |
||
6630 | else\ |
||
6631 | {\ |
||
6632 | return reply +\"\\n\"+input_reply;\ |
||
6633 | }\ |
||
6634 | }\ |
||
6635 | else\ |
||
6636 | {\ |
||
11088 | schaersvoo | 6637 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6638 | return reply +\"\\n\"+userdraw_text\ |
6639 | }\ |
||
6640 | else\ |
||
6641 | {\ |
||
6642 | return reply;\ |
||
6643 | }\ |
||
6644 | };\ |
||
8108 | schaersvoo | 6645 | };\n\ |
13970 | obado | 6646 | /* end function 12 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 6647 | break; |
6648 | case 13: fprintf(js_include_file,"\ |
||
13970 | obado | 6649 | \n/* begin function 13 read_canvas%d() */\n\ |
8257 | schaersvoo | 6650 | read_canvas%d = function(){\ |
7614 | schaersvoo | 6651 | var reply = new Array();\ |
6652 | var p = 0;var i = 0;\ |
||
8074 | schaersvoo | 6653 | var prec = %d;\ |
13521 | schaersvoo | 6654 | while(userdraw_x[p+1]){\ |
8074 | schaersvoo | 6655 | reply[i] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec +\":\" + (Math.round(prec*(px2y(userdraw_y[p]))))/prec +\":\" + (Math.round(prec*(px2x(userdraw_x[p+1]))))/prec +\":\" + (Math.round(prec*(px2y(userdraw_y[p+1]))))/prec;\ |
7614 | schaersvoo | 6656 | p = p+2;i++;\ |
6657 | };\ |
||
11806 | schaersvoo | 6658 | if(p == 0){return;};\ |
7614 | schaersvoo | 6659 | if( document.getElementById(\"canvas_input0\") ){\ |
6660 | var p = 0;var input_reply = new Array();\ |
||
6661 | if( document.getElementById(\"canvas_input0\")){\ |
||
6662 | var t = 0;\ |
||
6663 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
6664 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
6665 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
6666 | p++;\ |
||
6667 | };\ |
||
6668 | t++;\ |
||
6669 | };\ |
||
6670 | };\ |
||
11088 | schaersvoo | 6671 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6672 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
6673 | }\ |
||
6674 | else\ |
||
6675 | {\ |
||
6676 | return reply +\"\\n\"+input_reply;\ |
||
6677 | }\ |
||
6678 | }\ |
||
6679 | else\ |
||
6680 | {\ |
||
11088 | schaersvoo | 6681 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6682 | return reply +\"\\n\"+userdraw_text\ |
6683 | }\ |
||
6684 | else\ |
||
6685 | {\ |
||
6686 | return reply;\ |
||
6687 | }\ |
||
6688 | };\ |
||
8108 | schaersvoo | 6689 | };\n\ |
13970 | obado | 6690 | /* end function 13 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7614 | schaersvoo | 6691 | break; |
6692 | case 14: fprintf(js_include_file,"\ |
||
13970 | obado | 6693 | \n/* begin function 14 read_canvas%d() */\n\ |
8257 | schaersvoo | 6694 | read_canvas%d = function(){\ |
8074 | schaersvoo | 6695 | set_reply_precision();\ |
7614 | schaersvoo | 6696 | var reply = new Array();\ |
6697 | var p = 0;var i = 0;\ |
||
13521 | schaersvoo | 6698 | while(userdraw_x[p+1]){\ |
7614 | schaersvoo | 6699 | reply[i] = userdraw_x[p] +\":\" + userdraw_y[p] +\":\" + userdraw_x[p+1] +\":\" + userdraw_y[p+1];\ |
6700 | p = p+2;i++;\ |
||
6701 | };\ |
||
11806 | schaersvoo | 6702 | if(p == 0){return;};\ |
7614 | schaersvoo | 6703 | if( document.getElementById(\"canvas_input0\") ){\ |
6704 | var p = 0;var input_reply = new Array();\ |
||
6705 | if( document.getElementById(\"canvas_input0\")){\ |
||
6706 | var t = 0;\ |
||
6707 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
6708 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
6709 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
6710 | p++;\ |
||
6711 | };\ |
||
6712 | t++;\ |
||
6713 | };\ |
||
6714 | };\ |
||
11088 | schaersvoo | 6715 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6716 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
6717 | }\ |
||
6718 | else\ |
||
6719 | {\ |
||
6720 | return reply +\"\\n\"+input_reply;\ |
||
6721 | }\ |
||
6722 | }\ |
||
6723 | else\ |
||
6724 | {\ |
||
11088 | schaersvoo | 6725 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6726 | return reply +\"\\n\"+userdraw_text;\ |
6727 | }\ |
||
6728 | else\ |
||
6729 | {\ |
||
6730 | return reply;\ |
||
6731 | }\ |
||
6732 | };\ |
||
8108 | schaersvoo | 6733 | };\n\ |
13970 | obado | 6734 | /* end function 14 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 6735 | break; |
6736 | case 15: fprintf(js_include_file,"\ |
||
13970 | obado | 6737 | \n/* begin function 15 read_canvas%d() */\n\ |
8257 | schaersvoo | 6738 | read_canvas%d = function(){\ |
7614 | schaersvoo | 6739 | var input_reply = new Array();\ |
6740 | var p = 0;\ |
||
6741 | if( document.getElementById(\"canvas_input0\")){\ |
||
6742 | var t = 0;\ |
||
6743 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
6744 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
6745 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
6746 | p++;\ |
||
6747 | };\ |
||
6748 | t++;\ |
||
6749 | };\ |
||
6750 | };\ |
||
11088 | schaersvoo | 6751 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6752 | return input_reply +\"\\n\"+userdraw_text;\ |
6753 | }\ |
||
6754 | else\ |
||
6755 | {\ |
||
6756 | return input_reply;\ |
||
6757 | };\ |
||
8108 | schaersvoo | 6758 | };\n\ |
13970 | obado | 6759 | /* end function 15 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 6760 | break; |
6761 | case 16: fprintf(js_include_file,"\ |
||
13970 | obado | 6762 | \n/* begin function 16 read_mathml() */\n\ |
7614 | schaersvoo | 6763 | function read_mathml(){\ |
6764 | var reply = new Array();\ |
||
6765 | var p = 0;\ |
||
6766 | if( document.getElementById(\"mathml0\")){\ |
||
6767 | while(document.getElementById(\"mathml\"+p)){\ |
||
6768 | reply[p] = document.getElementById(\"mathml\"+p).value;\ |
||
6769 | p++;\ |
||
6770 | };\ |
||
6771 | };\ |
||
6772 | return reply;\ |
||
6773 | };\ |
||
6774 | this.read_mathml = read_mathml;\n\ |
||
13970 | obado | 6775 | /* end function 16 read_mathml() */"); |
7614 | schaersvoo | 6776 | break; |
6777 | case 17: fprintf(js_include_file,"\ |
||
13970 | obado | 6778 | \n/* begin function 17 read_canvas%d() */\n\ |
8257 | schaersvoo | 6779 | read_canvas%d = function(){\ |
11080 | schaersvoo | 6780 | var len = userdraw_x.length;\ |
6781 | if( len == 0){alert(\"no text typed...\");return;}\ |
||
6782 | var rep = px2x(userdraw_x[0])+\",\"+px2y(userdraw_y[0])+\",\"+userdraw_text[0];\ |
||
6783 | for(var p = 1 ; p < len ; p++){\ |
||
6784 | rep = rep + \"\\n\" + px2x(userdraw_x[p]) + \",\" + px2y(userdraw_y[p]) + \",\" + userdraw_text[p];\ |
||
6785 | };\ |
||
6786 | return rep;\ |
||
8108 | schaersvoo | 6787 | };\n\ |
13970 | obado | 6788 | /* end function 17 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 6789 | break; |
6790 | case 18: fprintf(js_include_file,"\ |
||
13970 | obado | 6791 | \n/* javascript has no real modulo function */\n\ |
10956 | schaersvoo | 6792 | function mod(n, m){\ |
6793 | var m = parseInt(((n %% m) + m) %% m);\ |
||
6794 | return m;\ |
||
6795 | };\ |
||
13970 | obado | 6796 | \n/* begin function 18 read_canvas%d() */\n\ |
8257 | schaersvoo | 6797 | read_canvas%d = function(){\ |
7614 | schaersvoo | 6798 | var p = 0;\ |
6799 | var reply = new Array();\ |
||
6800 | var name;\ |
||
6801 | var t = true;\ |
||
8000 | schaersvoo | 6802 | var h;var m;var s;\ |
7614 | schaersvoo | 6803 | while(t){\ |
8000 | schaersvoo | 6804 | try{\ |
6805 | name = eval('clocks'+p);\ |
||
6806 | h = name.H;m = name.M;s = name.S;\ |
||
10956 | schaersvoo | 6807 | h = mod((h+m/60+s/3600),12);m = mod((m + s/60),60);s = mod(s,60);\ |
8000 | schaersvoo | 6808 | reply[p] = h+\":\"+m+\":\"+s;\ |
6809 | p++;\ |
||
6810 | }catch(e){t=false;};\ |
||
7614 | schaersvoo | 6811 | };\ |
8000 | schaersvoo | 6812 | if( p == 0 ){alert(\"clock(s) not modified...\");return;}\ |
7614 | schaersvoo | 6813 | return reply;\ |
8108 | schaersvoo | 6814 | };\n\ |
13970 | obado | 6815 | /* end function 18 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 6816 | break; |
6817 | case 19: fprintf(js_include_file,"\ |
||
13970 | obado | 6818 | \n/* begin function 19 read_canvas%d() */\n\ |
8257 | schaersvoo | 6819 | read_canvas%d = function(){\ |
7614 | schaersvoo | 6820 | return reply[0];\ |
8108 | schaersvoo | 6821 | };\n\ |
13970 | obado | 6822 | /* end function 19 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id); |
8130 | schaersvoo | 6823 | break; |
7614 | schaersvoo | 6824 | case 20: fprintf(js_include_file,"\ |
13970 | obado | 6825 | \n/* begin function 20 read_canvas%d() */\n\ |
8257 | schaersvoo | 6826 | read_canvas%d = function(){\ |
8074 | schaersvoo | 6827 | var prec = %d;\ |
7614 | schaersvoo | 6828 | var len = ext_drag_images.length;\ |
6829 | var reply = new Array(len);\ |
||
6830 | for(var p = 0 ; p < len ; p++){\ |
||
6831 | var img = ext_drag_images[p];\ |
||
8556 | schaersvoo | 6832 | reply[p] = p+\":\"+(Math.round(prec*(px2x(img[6]))))/prec+\":\"+(Math.round(prec*(px2y(img[7]))))/prec;\ |
7614 | schaersvoo | 6833 | };\ |
6834 | return reply;\ |
||
8108 | schaersvoo | 6835 | };\n\ |
13970 | obado | 6836 | /* end function 20 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7614 | schaersvoo | 6837 | break; |
6838 | case 21: fprintf(js_include_file,"\ |
||
13970 | obado | 6839 | \n/* begin function 21 read_canvas%d() */\n\ |
8257 | schaersvoo | 6840 | read_canvas%d = function(){\ |
7614 | schaersvoo | 6841 | if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\ |
6842 | var reply_coord = new Array();var p = 0;\ |
||
8074 | schaersvoo | 6843 | var prec = %d;\ |
7614 | schaersvoo | 6844 | while(userdraw_x[p]){\ |
8074 | schaersvoo | 6845 | reply_coord[p] = \"(\"+(Math.round(prec*(px2x(userdraw_x[p]))))/prec+\":\"+(Math.round(prec*(px2y(userdraw_y[p]))))/prec+\")\";\ |
7614 | schaersvoo | 6846 | p++;\ |
6847 | };\ |
||
11806 | schaersvoo | 6848 | if(p == 0){return;};\ |
7614 | schaersvoo | 6849 | if( document.getElementById(\"canvas_input0\") ){\ |
6850 | var p = 0;var input_reply = new Array();\ |
||
6851 | if( document.getElementById(\"canvas_input0\")){\ |
||
6852 | var t = 0;\ |
||
6853 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
6854 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
6855 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
6856 | p++;\ |
||
6857 | };\ |
||
6858 | t++;\ |
||
6859 | };\ |
||
6860 | };\ |
||
11088 | schaersvoo | 6861 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6862 | return reply_coord+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
6863 | }\ |
||
6864 | else\ |
||
6865 | {\ |
||
6866 | return reply_coord+\"\\n\"+input_reply;\ |
||
6867 | }\ |
||
6868 | }\ |
||
6869 | else\ |
||
6870 | {\ |
||
11088 | schaersvoo | 6871 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6872 | return reply_coord+\"\\n\"+userdraw_text;\ |
6873 | }\ |
||
6874 | else\ |
||
6875 | {\ |
||
6876 | return reply_coord;\ |
||
6877 | };\ |
||
6878 | };\ |
||
8108 | schaersvoo | 6879 | };\n\ |
13970 | obado | 6880 | /* end function 21 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7614 | schaersvoo | 6881 | break; |
6882 | case 22: fprintf(js_include_file,"\ |
||
13970 | obado | 6883 | \n/* begin function 22 read_canvas%d() */\n\ |
8257 | schaersvoo | 6884 | read_canvas%d = function(){\ |
7614 | schaersvoo | 6885 | var reply = new Array();\ |
7963 | schaersvoo | 6886 | var lu = userdraw_x.length;\ |
11806 | schaersvoo | 6887 | if(lu == 0){return;};\ |
7614 | schaersvoo | 6888 | var idx = 0;\ |
8074 | schaersvoo | 6889 | var prec = %d;\ |
7963 | schaersvoo | 6890 | for(var p = 0 ; p < lu ; p++){\ |
8074 | schaersvoo | 6891 | reply[idx] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;idx++;\ |
6892 | reply[idx] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;idx++;\ |
||
7614 | schaersvoo | 6893 | };\ |
6894 | if( document.getElementById(\"canvas_input0\") ){\ |
||
6895 | var p = 0;var input_reply = new Array();\ |
||
6896 | if( document.getElementById(\"canvas_input0\")){\ |
||
6897 | var t = 0;\ |
||
6898 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
6899 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
6900 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
6901 | p++;\ |
||
6902 | };\ |
||
6903 | t++;\ |
||
6904 | };\ |
||
6905 | };\ |
||
11088 | schaersvoo | 6906 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6907 | return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
6908 | }\ |
||
6909 | else\ |
||
6910 | {\ |
||
6911 | return reply +\"\\n\"+input_reply;\ |
||
6912 | }\ |
||
6913 | }\ |
||
6914 | else\ |
||
6915 | {\ |
||
11088 | schaersvoo | 6916 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7614 | schaersvoo | 6917 | return reply +\"\\n\"+userdraw_text;\ |
6918 | }\ |
||
6919 | else\ |
||
6920 | {\ |
||
6921 | return reply;\ |
||
6922 | }\ |
||
6923 | };\ |
||
8108 | schaersvoo | 6924 | };\n\ |
13970 | obado | 6925 | /* end function 22 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7614 | schaersvoo | 6926 | break; |
7782 | schaersvoo | 6927 | case 23: fprintf(js_include_file,"\ |
13970 | obado | 6928 | \n/* begin function 23 read_canvas%d() default 5 px marge */\n\ |
8257 | schaersvoo | 6929 | read_canvas%d = function(){\ |
7782 | schaersvoo | 6930 | if( userdraw_x.length < 2){alert(\"nothing drawn...\");return;}\ |
6931 | var lu = userdraw_x.length;\ |
||
6932 | if( lu != userdraw_y.length ){ alert(\"x / y mismatch !\");return;}\ |
||
7962 | schaersvoo | 6933 | var reply_x = new Array();var reply_y = new Array();\ |
6934 | var marge = 5;var p = 0;\ |
||
8074 | schaersvoo | 6935 | var prec = %d;\ |
7782 | schaersvoo | 6936 | for(var i = 0; i < lu - 1 ; i++ ){\ |
10987 | schaersvoo | 6937 | if( Math.abs(userdraw_x[i] - userdraw_x[i+1]) || Math.abs(userdraw_y[i] - userdraw_y[i+1])){\ |
8074 | schaersvoo | 6938 | reply_x[p] = (Math.round(prec*(px2x(userdraw_x[i]))))/prec;reply_y[p] = (Math.round(prec*(px2y(userdraw_y[i]))))/prec;\ |
7962 | schaersvoo | 6939 | if( isNaN(reply_x[p]) || isNaN(reply_y[p]) ){ alert(\"hmmmm ?\");return; };\ |
6940 | p++;\ |
||
7782 | schaersvoo | 6941 | };\ |
8074 | schaersvoo | 6942 | reply_x[p] = (Math.round(prec*(px2x(userdraw_x[lu-1]))))/prec;reply_y[p] = (Math.round(prec*(px2y(userdraw_y[lu-1]))))/prec;\ |
7782 | schaersvoo | 6943 | };\ |
6944 | if( document.getElementById(\"canvas_input0\")){\ |
||
6945 | var p = 0;var input_reply = new Array();\ |
||
6946 | if( document.getElementById(\"canvas_input0\")){\ |
||
6947 | var t = 0;\ |
||
6948 | while(document.getElementById(\"canvas_input\"+t)){\ |
||
6949 | if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\ |
||
6950 | input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\ |
||
6951 | p++;\ |
||
6952 | };\ |
||
6953 | t++;\ |
||
6954 | };\ |
||
6955 | };\ |
||
11088 | schaersvoo | 6956 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7782 | schaersvoo | 6957 | return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\ |
6958 | }\ |
||
6959 | else\ |
||
6960 | {\ |
||
6961 | return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply;\ |
||
6962 | }\ |
||
6963 | }\ |
||
6964 | else\ |
||
6965 | {\ |
||
11088 | schaersvoo | 6966 | if( typeof(userdraw_text) !== 'undefined' ){\ |
7782 | schaersvoo | 6967 | return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_text;\ |
6968 | }\ |
||
6969 | else\ |
||
6970 | {\ |
||
6971 | return reply_x+\"\\n\"+reply_y;\ |
||
6972 | };\ |
||
6973 | };\ |
||
8108 | schaersvoo | 6974 | };\n\ |
13970 | obado | 6975 | /* end function 23 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
7782 | schaersvoo | 6976 | break; |
7984 | schaersvoo | 6977 | case 24: fprintf(js_include_file,"\n\ |
13970 | obado | 6978 | /* begin function 24 read_canvas%d() */\n\ |
8257 | schaersvoo | 6979 | read_canvas%d = function(){\ |
7984 | schaersvoo | 6980 | var input_reply = new Array();\ |
6981 | var p = 0;\ |
||
6982 | if( document.getElementById(\"canvas_input0\")){\ |
||
6983 | while(document.getElementById(\"canvas_input\"+p)){\ |
||
6984 | input_reply[p] = document.getElementById(\"canvas_input\"+p).value;\ |
||
6985 | p++;\ |
||
6986 | };\ |
||
6987 | return input_reply;\ |
||
6988 | };\ |
||
8108 | schaersvoo | 6989 | };\n\ |
13970 | obado | 6990 | /* end function 24 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id); |
7984 | schaersvoo | 6991 | break; |
8083 | schaersvoo | 6992 | case 25: |
14066 | bpr | 6993 | fprintf(js_include_file,"\n/* begin function 25 read_canvas%d(): angle(s) in degrees */\n\ |
8257 | schaersvoo | 6994 | read_canvas%d = function(){\ |
8083 | schaersvoo | 6995 | if( userdraw_radius.length < 1){alert(\"nothing drawn...\");return;}\ |
6996 | var lu = userdraw_radius.length;\ |
||
6997 | var prec = %d;\ |
||
6998 | var angle_reply = new Array(lu);\ |
||
6999 | for(var p = 0 ; p < lu ; p++){\ |
||
7000 | angle_reply[p] = (Math.round(prec*180*(userdraw_radius[p])/Math.PI))/prec;\ |
||
7001 | };\ |
||
7002 | return angle_reply;\ |
||
8108 | schaersvoo | 7003 | };\n\ |
13970 | obado | 7004 | /* end function 25 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
8083 | schaersvoo | 7005 | break; |
7006 | case 26: |
||
14066 | bpr | 7007 | fprintf(js_include_file,"\n/* begin function 26 read_canvas%d(): angle(s) in radians */\n\ |
8257 | schaersvoo | 7008 | read_canvas%d = function(){\ |
8083 | schaersvoo | 7009 | if( userdraw_radius.length < 1){alert(\"nothing drawn...\");return;}\ |
7010 | var lu = userdraw_radius.length;\ |
||
7011 | var prec = %d;\ |
||
7012 | var angle_reply = new Array(lu);\ |
||
7013 | for(var p = 0 ; p < lu ; p++){\ |
||
7014 | angle_reply[p] = (Math.round(prec*(userdraw_radius[p])))/prec;\ |
||
7015 | };\ |
||
7016 | return angle_reply;\ |
||
8108 | schaersvoo | 7017 | };\n\ |
13970 | obado | 7018 | /* end function 26 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
8083 | schaersvoo | 7019 | break; |
8127 | schaersvoo | 7020 | case 27: |
14066 | bpr | 7021 | fprintf(js_include_file,"\n/* begin function 27 read_canvas%d(): inputfield(s) location and their values: */\n\ |
8257 | schaersvoo | 7022 | read_canvas%d = function(){\ |
8127 | schaersvoo | 7023 | var lu = userdraw_x.length;\ |
14044 | schaersvoo | 7024 | if( lu < 1){alert(\"nothing drawn...\");return;};\ |
8127 | schaersvoo | 7025 | set_reply_precision();\ |
14044 | schaersvoo | 7026 | var prec = %d;var rep = \"\";\ |
8127 | schaersvoo | 7027 | for(var p = 0 ; p < lu ; p++){\ |
14044 | schaersvoo | 7028 | rep = rep + (Math.round(prec*(px2x(userdraw_x[p]))))/prec+\";\"+(Math.round(prec*(px2y(userdraw_y[p]))))/prec+\";\"+ document.getElementById(\"canvas_input\"+p).value + \"\\n\";\ |
8127 | schaersvoo | 7029 | };\ |
11080 | schaersvoo | 7030 | return rep;\ |
8127 | schaersvoo | 7031 | };\n\ |
13970 | obado | 7032 | /* end function 27 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
8127 | schaersvoo | 7033 | break; |
8322 | schaersvoo | 7034 | case 28: |
13970 | obado | 7035 | fprintf(js_include_file,"\n/* begin function 28 read_canvas%d() */\n\ |
8322 | schaersvoo | 7036 | read_canvas%d = function(){\ |
7037 | var prec = %d;\ |
||
7038 | var reply = new Array();var p = 0;\ |
||
7039 | var idx = 0;\ |
||
7040 | while(userdraw_x[p]){\ |
||
7041 | reply[idx] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\ |
||
7042 | idx++;\ |
||
7043 | reply[idx] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\ |
||
7044 | idx++;\ |
||
7045 | reply[idx] = (Math.round(prec*(px2x(userdraw_radius[p]) - px2x(0))))/prec;\ |
||
7046 | idx++;\ |
||
7047 | p++;\ |
||
7048 | };\ |
||
7049 | if( p == 0){alert(\"nothing drawn...\");return;}\ |
||
7050 | return reply;\ |
||
7051 | };\n\ |
||
13970 | obado | 7052 | /* end function 28 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
8322 | schaersvoo | 7053 | break; |
9213 | schaersvoo | 7054 | case 29: |
13970 | obado | 7055 | fprintf(js_include_file,"\n/* begin function 29 read_canvas%d() */\n\ |
14038 | schaersvoo | 7056 | function x_precision(array_x){\ |
9213 | schaersvoo | 7057 | var len = array_x.length;\ |
7058 | var x_array = new Array(len);\ |
||
14038 | schaersvoo | 7059 | var prec = %d;\ |
7060 | for(var p = 0 ; p < len ; p++ ){\ |
||
7061 | x_array[p] = (Math.round(prec*(px2x(array_x[p]))))/prec;\ |
||
7062 | };\ |
||
7063 | return x_array;\ |
||
7064 | };\ |
||
7065 | function y_precision(array_y){\ |
||
7066 | var len = array_y.length;\ |
||
9213 | schaersvoo | 7067 | var y_array = new Array(len);\ |
7068 | var prec = %d;\ |
||
7069 | for(var p = 0 ; p < len ; p++ ){\ |
||
7070 | y_array[p] = (Math.round(prec*(px2y(array_y[p]))))/prec;\ |
||
7071 | };\ |
||
14038 | schaersvoo | 7072 | return y_array;\ |
7073 | };\ |
||
9213 | schaersvoo | 7074 | function round_to_pixel(array_r){\ |
7075 | var len = array_r.length;\ |
||
7076 | for(var p = 0 ; p < len ; p++ ){\ |
||
7077 | array_r[p] = Math.round(array_r[p]);\ |
||
7078 | };\ |
||
7079 | return array_r;\ |
||
7080 | };\ |
||
7081 | read_canvas%d = function(){\ |
||
14038 | schaersvoo | 7082 | function uniq_fast(arr){\ |
7083 | var seen = {};\ |
||
7084 | var out = [];\ |
||
7085 | var len = arr.length;\ |
||
7086 | var j = 0;\ |
||
7087 | for(var i = 0; i < len; i++){\ |
||
7088 | var item = arr[i];\ |
||
7089 | if(seen[item] !== 1) {\ |
||
7090 | seen[item] = 1;out[j++] = item;\ |
||
7091 | };\ |
||
7092 | };\ |
||
7093 | return out;\ |
||
7094 | };\ |
||
7095 | function list_unique(arr1,arr2,arr3){\ |
||
7096 | var len1 = arr1.length;\ |
||
7097 | if(len1 != arr2.length){alert('mismatch in number of x and y values...');return;};\ |
||
7098 | var sum = [];var R1=[];var R2=[];\ |
||
7099 | arr1 = x_precision(arr1);\ |
||
7100 | arr2 = y_precision(arr2);\ |
||
7101 | if(arr3 == null){\ |
||
7102 | for(var p=0;p<len1;p++){ sum[p] = arr1[p]+'#'+arr2[p]; };\ |
||
7103 | sum = uniq_fast(sum);var len2=sum.length;\ |
||
7104 | for(var p=0;p<len2;p++){\ |
||
7105 | var tmp = (sum[p]).split('#');\ |
||
7106 | R1[p] = tmp[0];\ |
||
7107 | R2[p] = tmp[1];\ |
||
7108 | };\ |
||
7109 | return [R1,R2];\ |
||
7110 | }else{\ |
||
7111 | var R3 = [];\ |
||
7112 | for(var p=0;p<len1;p++){ sum[p] = arr1[p]+'#'+arr2[p]+'#'+arr3[p];};\ |
||
7113 | sum = uniq_fast(sum);var len2=sum.length;\ |
||
7114 | for(var p=0;p<len2;p++){\ |
||
7115 | var tmp = (sum[p]).split('#');\ |
||
7116 | R1[p] = tmp[0];\ |
||
7117 | R2[p] = tmp[1];\ |
||
7118 | R3[p] = tmp[2];\ |
||
7119 | };\ |
||
7120 | return [R1,R2,R3];\ |
||
7121 | };\ |
||
7122 | };\ |
||
9300 | schaersvoo | 7123 | var reply=\" \";\ |
14038 | schaersvoo | 7124 | if( typeof(points_x) === 'object' && points_x.length > 0 ){var xyz = list_unique(points_x,points_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\";}else{ reply = reply + \"\\n\"; };\ |
7125 | if( typeof(circles_x) === 'object' && circles_x.length > 0 ){var xyz = list_unique(circles_x,circles_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\";+\";\"+round_to_pixel(multi_radius)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\ |
||
7126 | if( typeof(segments_x) === 'object' && segments_x.length > 0 ){ var xyz = list_unique(segments_x,segments_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\";}else{ reply = reply + \"\\n\"; };\ |
||
7127 | if( typeof(arrows_x) === 'object' && arrows_x.length > 0 ){var xyz = list_unique(arrows_x,arrows_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\"; }else{ reply = reply + \"\\n\"; };\ |
||
7128 | if( typeof(lines_x) === 'object' && lines_x.length > 0 ){ var xyz = list_unique(lines_x,lines_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\"; }else{ reply = reply + \"\\n\"; };\ |
||
7129 | if( typeof(triangles_x) === 'object' && triangles_x.length > 0){var xyz = list_unique(triangles_x,triangles_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\"; }else{ reply = reply + \"\\n\"; };\ |
||
7130 | if( typeof(polys_x) === 'object' && polys_x.length > 0){ var xyz = list_unique(polys_x,polys_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\"; }else{ reply = reply + \"\\n\"; };\ |
||
7131 | if( typeof(rects_x) === 'object' && rects_x.length > 0 ){var xyz = list_unique(rects_x,rects_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\"; }else{ reply = reply + \"\\n\"; };\ |
||
7132 | if( typeof(closedpoly_x) === 'object' && closedpoly_x.length > 0){ closedpoly_x.pop();closedpoly_y.pop();var xyz = list_unique(closedpoly_x,closedpoly_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\";}else{ reply = reply + \"\\n\"; };\ |
||
7133 | if( typeof(parallelogram_x) === 'object' && parallelogram_x.length > 0){var xyz = list_unique(parallelogram_x,parallelogram_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\"; }else{ reply = reply + \"\\n\"; };\ |
||
7134 | if( typeof(text_x) === 'object' && text_x.length > 0){var xyz = list_unique(text_x,text_y,text_abc);reply = reply + xyz[0] +\";\"+xyz[1]+\";\"+xyz[2]+\"\\n\";}else{ reply = reply + \"\\n\"; };\ |
||
7135 | if( typeof(images_x) === 'object' && images_x.length > 0){var xyz = list_unique(images_x,images_y,images_id);reply = reply + xyz[0] +\";\"+xyz[1]+\";\"+xyz[2]+\"\\n\";}else{ reply = reply + \"\\n\"; };\ |
||
7136 | if( typeof(curvedarrows_x) === 'object' && curvedarrows_x.length > 0){var xyz = list_unique(curvedarrows_x,curvedarrows_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\"; }else{ reply = reply + \"\\n\";};\ |
||
7137 | if( typeof(curvedarrows2_x) === 'object' && curvedarrows2_x.length > 0){var xyz = list_unique(curvedarrows2_x,curvedarrows2_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\"; }else{ reply = reply + \"\\n\";};\ |
||
7138 | if( typeof(userdraw_x) === 'object' && userdraw_radius.x> 0){var xyz = list_unique(userdraw_x,userdraw_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\"; return reply;;};\ |
||
7139 | if( typeof(userdraw_radius) === 'object' && userdraw_radius.length > 0){var xyz = list_unique(userdraw_x,userdraw_y,userdraw_radius);reply = reply + xyz[0] +\";\"+xyz[1]+\";\"+xyz[2]+\"\\n\"; return reply;;};\ |
||
9213 | schaersvoo | 7140 | return reply;\ |
14038 | schaersvoo | 7141 | };\ |
14044 | schaersvoo | 7142 | /* end function 29 read_canvas%d() */",canvas_root_id,reply_precision,reply_precision,canvas_root_id,canvas_root_id); |
9213 | schaersvoo | 7143 | break; |
9289 | schaersvoo | 7144 | case 30: |
13970 | obado | 7145 | fprintf(js_include_file,"\n/* begin function 30 read_canvas%d() */\n\ |
9289 | schaersvoo | 7146 | read_canvas%d = function(){\ |
7147 | var reply = new Array(3);\ |
||
7148 | var prec = %d;\ |
||
7149 | reply[0] = (Math.round(prec*(px2x(protractor_data[0]))))/prec;\ |
||
7150 | reply[1] = (Math.round(prec*(px2y(protractor_data[1]))))/prec;\ |
||
7151 | reply[2] = (Math.round(prec*(protractor_data[2])))/prec;\ |
||
7152 | return reply;\ |
||
7153 | };\n\ |
||
13970 | obado | 7154 | /* end function 30 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
9289 | schaersvoo | 7155 | break; |
7156 | case 31: |
||
13970 | obado | 7157 | fprintf(js_include_file,"\n/* begin function 31 read_canvas%d() */\n\ |
9289 | schaersvoo | 7158 | read_canvas%d = function(){\ |
7159 | var reply = new Array(3);\ |
||
7160 | var prec = %d;\ |
||
7161 | reply[0] = (Math.round(prec*(px2x(ruler_data[0]))))/prec;\ |
||
7162 | reply[1] = (Math.round(prec*(px2y(ruler_data[1]))))/prec;\ |
||
7163 | reply[2] = (Math.round(prec*(ruler_data[2])))/prec;\ |
||
7164 | return reply;\ |
||
7165 | };\n\ |
||
13970 | obado | 7166 | /* end function 31 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
9289 | schaersvoo | 7167 | break; |
7168 | case 32: |
||
13970 | obado | 7169 | fprintf(js_include_file,"\n/* begin function 32 read_canvas%d() */\n\ |
9289 | schaersvoo | 7170 | read_canvas%d = function(){\ |
7171 | var reply = new Array(6);\ |
||
7172 | var prec = %d;\ |
||
7173 | reply[0] = (Math.round(prec*(px2x(ruler_data[0]))))/prec;\ |
||
7174 | reply[1] = (Math.round(prec*(px2y(ruler_data[1]))))/prec;\ |
||
7175 | reply[2] = (Math.round(prec*(ruler_data[2])))/prec;\ |
||
7176 | reply[3] = (Math.round(prec*(px2x(protractor_data[0]))))/prec;\ |
||
7177 | reply[4] = (Math.round(prec*(px2y(protractor_data[1]))))/prec;\ |
||
7178 | reply[5] = (Math.round(prec*(protractor_data[2])))/prec;\ |
||
7179 | return reply;\ |
||
7180 | };\n\ |
||
13970 | obado | 7181 | /* end function 32 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id); |
9289 | schaersvoo | 7182 | break; |
14038 | schaersvoo | 7183 | case 33: |
7184 | fprintf(js_include_file,"\n/* begin function 33 read_canvas%d() */\n\ |
||
7185 | read_canvas%d = function(){\ |
||
7186 | var reply = userdraw_x+'\\n'+userdraw_y;\ |
||
7187 | return reply;\ |
||
7188 | };\n\ |
||
7189 | /* end function 32 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id); |
||
7190 | break; |
||
7191 | case 34: fprintf(js_include_file,"\ |
||
7192 | \n/* begin special OEF function (replyformat 34) read_canvas_images() \\n note: only suitable for reading a single canvas in exercise page */\n\ |
||
7193 | var read_canvas_images = function(){\ |
||
7194 | var prec = %d;\ |
||
7195 | var len = ext_drag_images.length;\ |
||
7196 | var reply = new Array(len);\ |
||
7197 | for(var p = 0 ; p < len ; p++){\ |
||
7198 | var img = ext_drag_images[p];\ |
||
7199 | reply[p] = p+\":\"+(Math.round(prec*(px2x(img[6]))))/prec+\":\"+(Math.round(prec*(px2y(img[7]))))/prec;\ |
||
7200 | };\ |
||
7201 | return reply;\ |
||
7202 | };\n\ |
||
7203 | /* end function 20 read_canvas_images() */",reply_precision); |
||
7204 | break; |
||
7205 | |||
7614 | schaersvoo | 7206 | default: canvas_error("hmmm unknown replyformat...");break; |
7207 | } |
||
7208 | return; |
||
7209 | } |
||
7210 | |||
7211 | |||
8224 | bpr | 7212 | /* |
14066 | bpr | 7213 | add drawfunction: |
7614 | schaersvoo | 7214 | - functions used by userdraw_primitives (circle,rect,path,triangle...) |
14078 | bpr | 7215 | - things not covered by the drag&drop library (static objects like parallel, lattice, gridfill, imagefill) |
7614 | schaersvoo | 7216 | - grid / mathml |
7217 | - will not scale or zoom in |
||
7218 | - will not be filled via pixel operations like fill / floodfill / filltoborder / clickfill |
||
8224 | bpr | 7219 | - is printed directly into 'js_include_file' |
7614 | schaersvoo | 7220 | */ |
7221 | |||
11021 | schaersvoo | 7222 | void add_javascript_function(int js_function[],int canvas_root_id){ |
7614 | schaersvoo | 7223 | int i; |
7224 | for(i = 0 ; i < MAX_JS_FUNCTIONS; i++){ |
||
11017 | schaersvoo | 7225 | if( js_function[i] == 1){ |
7614 | schaersvoo | 7226 | switch(i){ |
11026 | bpr | 7227 | case JS_FIND_ANGLE: |
11025 | schaersvoo | 7228 | fprintf(js_include_file,"\n\ |
13970 | obado | 7229 | /* function find_angle() */\n\ |
14044 | schaersvoo | 7230 | function find_angle(xc,yc,x1,y1){var dx = x1 - xc;var dy = yc - y1;return Math.atan2(dx,dy);};"); |
11017 | schaersvoo | 7231 | break; |
8448 | schaersvoo | 7232 | case DRAW_EXTERNAL_IMAGE: |
14066 | bpr | 7233 | /* |
13969 | schaersvoo | 7234 | the external_canvas is already created: it needs to be FIRST in order to do some drawing onto it |
7235 | only drag_xy ! |
||
7236 | snaptogrid | xsnaptogrid | ysnaptogrid works |
||
7237 | 14/5/2019 |
||
7238 | on heavy styled wims (unice.fr etc problems with mouse? |
||
7239 | now uniform method of retreiving mouse coordinates dragstuff.getMouse() |
||
8448 | schaersvoo | 7240 | */ |
13970 | obado | 7241 | fprintf(js_include_file,"\n/* drag external images */\n\ |
7653 | schaersvoo | 7242 | var external_ctx = external_canvas.getContext(\"2d\");\ |
7243 | var external_canvas_rect = external_canvas.getBoundingClientRect();\ |
||
7244 | canvas_div.addEventListener(\"mousedown\",setxy,false);\ |
||
7245 | canvas_div.addEventListener(\"mouseup\",dragstop,false);\ |
||
7246 | canvas_div.addEventListener(\"mousemove\",dragxy,false);\ |
||
7247 | var selected_image = null;\ |
||
7248 | var ext_image_cnt = 0;\ |
||
7249 | var ext_drag_images = new Array();\ |
||
14038 | schaersvoo | 7250 | var ext_centered = 0;\ |
14044 | schaersvoo | 7251 | function draw_external_image(URL,sx,sy,swidth,sheight,x0,y0,width,height,idx,resizable,draggable,click_cnt,centered,use_snap){\ |
14038 | schaersvoo | 7252 | ext_centered = centered;\ |
7653 | schaersvoo | 7253 | ext_image_cnt = idx;\ |
8448 | schaersvoo | 7254 | if(draggable == 1 ){\ |
7255 | reply[click_cnt] = 0;\ |
||
7256 | };\ |
||
7653 | schaersvoo | 7257 | var image = new Image();\ |
7258 | image.src = URL;\ |
||
7259 | image.onload = function(){\ |
||
8448 | schaersvoo | 7260 | if( sx < 1 ){ sx = 0; };\ |
7261 | if( sy < 1 ){ sy = 0; };\ |
||
7262 | if( swidth < 1 ){swidth = image.width;};\ |
||
7263 | if( sheight < 1 ){sheight = image.height;};\ |
||
7264 | if( width < 1 ){width = image.width;};\ |
||
7265 | if( height < 1 ){height = image.height;};\ |
||
7266 | if( resizable == 0 ){\ |
||
7267 | if( swidth > image.width ){ swidth = image.width; };\ |
||
7268 | if( sheight > image.height){ sheight = image.height;};\ |
||
7269 | if( width > image.width ){ width = image.width; };\ |
||
7270 | if( height > image.height){ height = image.height;};\ |
||
7271 | };\ |
||
14044 | schaersvoo | 7272 | var img = new Array(12);\ |
7653 | schaersvoo | 7273 | img[0] = draggable;img[1] = image;img[2] = sx;img[3] = sy;img[4] = swidth;img[5] = sheight;\ |
14044 | schaersvoo | 7274 | img[8] = width;img[9] = height;img[10] = click_cnt;img[11] = use_snap;\ |
14062 | schaersvoo | 7275 | img[6] = x0;img[7] = y0;\ |
7653 | schaersvoo | 7276 | ext_drag_images[idx] = img;\ |
14062 | schaersvoo | 7277 | if(centered == 4){\ |
7278 | external_ctx.drawImage(img[1],img[2],img[3],img[4],img[5],parseInt(img[6] - 0.5*img[8]),parseInt(img[7] - 0.5*img[9]),img[8],img[9]);\ |
||
7279 | }else{\ |
||
7280 | external_ctx.drawImage(img[1],img[2],img[3],img[4],img[5],img[6],img[7],img[8],img[9]);\ |
||
7281 | };\ |
||
7653 | schaersvoo | 7282 | };\ |
7283 | };\ |
||
7284 | function dragstop(evt){\ |
||
7285 | selected_image = null;return;\ |
||
7286 | };\ |
||
7287 | function dragxy(evt){\ |
||
7288 | if( selected_image != null ){\ |
||
14044 | schaersvoo | 7289 | var s_img = ext_drag_images[selected_image];\ |
13969 | schaersvoo | 7290 | var mouse = dragstuff.getMouse(evt,external_canvas);\ |
14044 | schaersvoo | 7291 | var xy = multisnap_check(mouse.x,mouse.y,s_img[11]);\ |
14062 | schaersvoo | 7292 | var x = parseInt(xy[0] - 0.5*s_img[8]) ;var y = parseInt(xy[1] - 0.5*s_img[9]);\ |
7293 | s_img[6] = xy[0];s_img[7] = xy[1];\ |
||
7653 | schaersvoo | 7294 | ext_drag_images[selected_image] = s_img;\ |
7295 | external_ctx.clearRect(0,0,xsize,ysize);\ |
||
7296 | for(var i = 0; i <= ext_image_cnt ; i++){\ |
||
7297 | var img = ext_drag_images[i];\ |
||
14062 | schaersvoo | 7298 | external_ctx.drawImage(img[1],img[2],img[3],img[4],img[5],x,y,img[8],img[9]);\ |
7653 | schaersvoo | 7299 | };\ |
7300 | };\ |
||
7301 | };\ |
||
7302 | function setxy(evt){\ |
||
7303 | if( ! selected_image && evt.which == 1 ){\ |
||
13969 | schaersvoo | 7304 | var mouse = dragstuff.getMouse(evt,external_canvas);\ |
7305 | var xm = mouse.x;\ |
||
7306 | var ym = mouse.y;\ |
||
14062 | schaersvoo | 7307 | var img;var xmarge;var ymarge;\ |
7653 | schaersvoo | 7308 | for(var p = 0 ; p <= ext_image_cnt ; p++){\ |
8448 | schaersvoo | 7309 | if( ext_drag_images[p] ){\ |
7310 | img = ext_drag_images[p];\ |
||
7311 | if( img[0] != 0 ){\ |
||
14062 | schaersvoo | 7312 | xmarge = 0.5*img[8];ymarge = 0.5*img[9];\ |
7313 | if( xm > img[6] - xmarge && xm < img[6] + img[8]){\ |
||
7314 | if( ym > img[7] - ymarge && ym < img[7] + img[9]){\ |
||
8448 | schaersvoo | 7315 | if( img[0] == 1){\ |
7316 | if( reply[img[10]] == 1 ){\ |
||
7317 | reply[img[10]] = 0;external_ctx.strokeStyle = '#ffffff';\ |
||
7318 | }\ |
||
7319 | else\ |
||
7320 | {\ |
||
7321 | reply[img[10]] = 1;external_ctx.strokeStyle = '#00ff00';\ |
||
7322 | };\ |
||
13969 | schaersvoo | 7323 | external_ctx.lineWidth = 4;\ |
8448 | schaersvoo | 7324 | external_ctx.beginPath();\ |
7325 | external_ctx.rect(img[6],img[7],img[8],img[9]);\ |
||
7326 | external_ctx.closePath();\ |
||
7327 | external_ctx.stroke();\ |
||
7328 | return;\ |
||
7329 | }\ |
||
7330 | else\ |
||
7331 | {\ |
||
7332 | img[6] = xm;\ |
||
7333 | img[7] = ym;\ |
||
7334 | ext_drag_images[p] = img;\ |
||
7335 | selected_image = p;\ |
||
7336 | dragxy(evt);\ |
||
7337 | };\ |
||
7338 | };\ |
||
7653 | schaersvoo | 7339 | };\ |
7340 | };\ |
||
7341 | };\ |
||
7342 | };\ |
||
7343 | }\ |
||
7344 | else\ |
||
7345 | {\ |
||
7346 | selected_image = null;\ |
||
7347 | };\ |
||
8448 | schaersvoo | 7348 | };"); |
7614 | schaersvoo | 7349 | break; |
8370 | schaersvoo | 7350 | case DRAW_BEZIER: |
13970 | obado | 7351 | fprintf(js_include_file,"\n/* draw bezier curve */\n\ |
11874 | schaersvoo | 7352 | if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\ |
8370 | schaersvoo | 7353 | var draw_bezier = function(canvas_type,linewidth,xy_points,fill_color,fill_opacity,stroke_color,stroke_opacity,use_filled,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_affine,affine_matrix){\ |
7354 | var obj;\ |
||
7355 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
7356 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
7357 | }\ |
||
7358 | else\ |
||
7359 | {\ |
||
7360 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
7361 | };\ |
||
7362 | var ctx = obj.getContext(\"2d\");\ |
||
7363 | ctx.save();\ |
||
7364 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
7365 | ctx.lineWidth = linewidth;\ |
||
11088 | schaersvoo | 7366 | if(linewidth%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
8370 | schaersvoo | 7367 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);};\ |
7368 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);};\ |
||
7369 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
7370 | ctx.beginPath();\ |
||
7371 | ctx.moveTo(x2px(xy_points[0]),y2px(xy_points[1]));\ |
||
7372 | ctx.bezierCurveTo(x2px(xy_points[2]),y2px(xy_points[3]),x2px(xy_points[4]),y2px(xy_points[5]),x2px(xy_points[6]),y2px(xy_points[7]));\ |
||
11874 | schaersvoo | 7373 | var color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\ |
11875 | schaersvoo | 7374 | if(use_filled > 1 ){ if(! all_fill_patterns[use_filled] ){ var pat = create_Pattern(0,0,use_filled,color); all_fill_patterns[use_filled] = pat;};ctx.fillStyle = all_fill_patterns[use_filled]; } else { ctx.fillStyle = color;};\ |
8370 | schaersvoo | 7375 | ctx.stroke();\ |
7376 | ctx.restore();\ |
||
7377 | };\n",canvas_root_id,canvas_root_id,canvas_root_id); |
||
7378 | break; |
||
13829 | bpr | 7379 | |
7614 | schaersvoo | 7380 | case DRAW_GRIDFILL:/* not used for userdraw */ |
13970 | obado | 7381 | fprintf(js_include_file,"\n/* draw gridfill */\n\ |
11827 | schaersvoo | 7382 | var grid_fill_pattern;\ |
11823 | schaersvoo | 7383 | var draw_gridfill = function(canvas_type,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize,use_userdraw){\ |
11820 | schaersvoo | 7384 | if( dx == 0 || dy == 0 ){alert(\"increment is zero !!! \");return;};\ |
7385 | if( typeof(fill_canvas_no) != 'object' ){ var fill_canvas_no = []; };\ |
||
7386 | var fc = %d+canvas_type;\n\ |
||
7387 | fill_canvas_no.push(fc);\ |
||
7388 | var obj = create_canvas%d(fc,xsize,ysize);\n\ |
||
7389 | var ctx = obj.getContext('2d');\n\ |
||
7614 | schaersvoo | 7390 | var x,y;\ |
11820 | schaersvoo | 7391 | ctx.fillStyle='rgba(255,255,255,0.01)';\n\ |
7392 | ctx.rect(0,0,xsize,ysize);\n\ |
||
7393 | ctx.fill();\n\ |
||
7394 | ctx.lineWidth = linewidth;\ |
||
7395 | if(linewidth%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
||
7396 | ctx.strokeStyle=\"rgba(\"+color+\",0.01)\";\ |
||
7397 | for( x = 0 ; x < xsize ; x = x + dx ){\ |
||
7398 | ctx.beginPath();\ |
||
7399 | ctx.moveTo(x,0);\ |
||
7400 | ctx.lineTo(x,ysize);\ |
||
7401 | ctx.closePath();\ |
||
7402 | ctx.stroke();\ |
||
7614 | schaersvoo | 7403 | };\ |
11820 | schaersvoo | 7404 | for( y = 0 ; y < ysize; y = y + dy ){\ |
7405 | ctx.beginPath();\ |
||
7406 | ctx.moveTo(0,y);\ |
||
7407 | ctx.lineTo(xsize,y);\ |
||
7408 | ctx.closePath();\ |
||
7409 | ctx.stroke();\ |
||
7614 | schaersvoo | 7410 | };\ |
11823 | schaersvoo | 7411 | if( use_userdraw ){\ |
7412 | grid_fill_pattern = ctx;\ |
||
7413 | }\ |
||
7414 | else\ |
||
7415 | {\ |
||
11874 | schaersvoo | 7416 | setTimeout(function(){ filltoborder( x0,y0,color,color,canvas_type,true,ctx); },500);};return;\ |
7417 | };",canvas_root_id,canvas_root_id); |
||
7614 | schaersvoo | 7418 | break; |
8224 | bpr | 7419 | |
7614 | schaersvoo | 7420 | case DRAW_IMAGEFILL:/* not used for userdraw */ |
13970 | obado | 7421 | fprintf(js_include_file,"\n/* draw imagefill */\n\ |
11874 | schaersvoo | 7422 | var draw_imagefill = function(canvas_type,x0,y0,URL,xsize,ysize,use_userdraw,use_scaling){\ |
11854 | schaersvoo | 7423 | if( typeof(fill_canvas_no) != 'object' ){ var fill_canvas_no = []; };\ |
7424 | var fc = %d+canvas_type;\ |
||
7425 | fill_canvas_no.push(fc);\ |
||
7426 | var obj = create_canvas%d(fc,xsize,ysize);\ |
||
7427 | var ctx = obj.getContext('2d');\ |
||
7428 | var img = new Image();\ |
||
7429 | img.src = URL;\ |
||
11857 | schaersvoo | 7430 | obj.style.visibility = 'hidden';\ |
7431 | img.onload = function(){\ |
||
11874 | schaersvoo | 7432 | if( use_scaling == 1 ){\ |
7433 | ctx.drawImage(img,x0,y0,xsize,ysize);\ |
||
7434 | }else{\ |
||
7435 | var w0 = img.width;var h0 = img.height;var w;var h;\ |
||
7436 | for( w = x0; w < xsize ; w = w + w0 ){\ |
||
7437 | for( h = y0; h < ysize; h = h + h0){\ |
||
7438 | ctx.drawImage(img,w,h,w0,h0);\ |
||
7439 | };\ |
||
7440 | };\ |
||
7441 | };\ |
||
11857 | schaersvoo | 7442 | if( use_userdraw ){\ |
7443 | image_pattern = ctx;\ |
||
7444 | }\ |
||
7445 | else\ |
||
7446 | {\ |
||
7447 | setTimeout(function(){ filltoborder( x0,y0,'red','red',canvas_type,true,ctx); },500);\ |
||
7448 | };\ |
||
7449 | };\ |
||
11854 | schaersvoo | 7450 | };",canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 7451 | break; |
8224 | bpr | 7452 | |
7614 | schaersvoo | 7453 | case DRAW_DOTFILL:/* not used for userdraw */ |
13970 | obado | 7454 | fprintf(js_include_file,"\n/* draw dotfill */\n\ |
11827 | schaersvoo | 7455 | var dot_fill_pattern;\ |
11823 | schaersvoo | 7456 | var draw_dotfill = function(canvas_type,x0,y0,dx,dy,radius,color,opacity,xsize,ysize,use_userdraw){\n\ |
11820 | schaersvoo | 7457 | if( dx == 0 || dy == 0 ){alert(\"increment is zero !!! \");return;};\ |
11818 | schaersvoo | 7458 | if( typeof(fill_canvas_no) != 'object' ){ var fill_canvas_no = []; };\ |
11820 | schaersvoo | 7459 | var fc = %d+canvas_type;\ |
11818 | schaersvoo | 7460 | fill_canvas_no.push(fc);\ |
11820 | schaersvoo | 7461 | var obj = create_canvas%d(fc,xsize,ysize);\ |
7462 | var ctx = obj.getContext('2d');\ |
||
7463 | var x,y;\ |
||
7464 | ctx.fillStyle='rgba(255,255,255,0.01)';\ |
||
7465 | ctx.rect(0,0,xsize,ysize);\ |
||
7466 | ctx.fill();\ |
||
7467 | ctx.fillStyle=\"rgba(\"+color+\",0.01)\";\ |
||
7468 | ctx.strokeStyle=\"rgba(\"+color+\",0.01)\";\ |
||
7469 | for( x = 0 ; x < xsize ; x = x + dx ){\ |
||
7470 | for( y = 0 ; y < ysize ; y = y + dy ){\ |
||
7471 | ctx.beginPath();\ |
||
7472 | ctx.arc(x,y,radius,0,2*Math.PI,false);\ |
||
7473 | ctx.closePath();\ |
||
7474 | ctx.fill();\ |
||
7475 | };\ |
||
7476 | };\ |
||
11823 | schaersvoo | 7477 | if( use_userdraw ){\ |
11824 | schaersvoo | 7478 | dot_fill_pattern = ctx;\ |
11823 | schaersvoo | 7479 | }\ |
7480 | else\ |
||
7481 | {\ |
||
11874 | schaersvoo | 7482 | setTimeout(function(){ filltoborder( x0,y0,color,color,canvas_type,true,ctx); },500);\ |
7483 | };\ |
||
7484 | return;\ |
||
7485 | };",canvas_root_id,canvas_root_id); |
||
7614 | schaersvoo | 7486 | break; |
7645 | schaersvoo | 7487 | |
11830 | schaersvoo | 7488 | case DRAW_TEXTFILL:/* not used for userdraw */ |
13970 | obado | 7489 | fprintf(js_include_file,"\n/* draw textfill */\n\ |
11830 | schaersvoo | 7490 | var text_fill_pattern;\ |
7491 | var draw_textfill = function(canvas_type,x0,y0,color,fontfamily,xsize,ysize,txt,use_userdraw){\n\ |
||
7492 | if( typeof(fill_canvas_no) != 'object' ){ var fill_canvas_no = []; };\ |
||
7493 | var fc = %d+canvas_type;\ |
||
7494 | fill_canvas_no.push(fc);\ |
||
7495 | var obj = create_canvas%d(fc,xsize,ysize);\ |
||
7496 | var ctx = obj.getContext('2d');\ |
||
7497 | ctx.font = fontfamily;\ |
||
11832 | schaersvoo | 7498 | var dx = (ctx.measureText(txt)).width;\ |
11830 | schaersvoo | 7499 | var dy = parseInt(fontfamily)+2;\ |
7500 | ctx.fillStyle='rgba(255,255,255,0.01)';\ |
||
7501 | ctx.rect(0,0,xsize,ysize);\ |
||
7502 | ctx.fill();\ |
||
7503 | ctx.fillStyle=\"rgba(\"+color+\",0.01)\";\ |
||
7504 | for(var x = 0 ; x < xsize ; x = x + dx ){\ |
||
7505 | for(var y = 0 ; y < ysize ; y = y + dy ){\ |
||
7506 | ctx.fillText(txt,x,y);\ |
||
7507 | };\ |
||
7508 | };\ |
||
7509 | if( use_userdraw ){\ |
||
7510 | text_fill_pattern = ctx;\ |
||
7511 | }\ |
||
7512 | else\ |
||
7513 | {\ |
||
7514 | setTimeout(function(){ filltoborder( x0,y0,color,color,canvas_type,true,ctx); },500);};\ |
||
7515 | return;};",canvas_root_id,canvas_root_id); |
||
7516 | break; |
||
7517 | |||
7647 | schaersvoo | 7518 | case DRAW_DIAMONDFILL:/* not used for userdraw */ |
13970 | obado | 7519 | fprintf(js_include_file,"\n/* draw hatch fill */\n\ |
11827 | schaersvoo | 7520 | var diamond_fill_pattern;\ |
11823 | schaersvoo | 7521 | var draw_diamondfill = function(canvas_type,x0,y0,dx,dy,linewidth,color,stroke_opacity,xsize,ysize,use_userdraw){\ |
11820 | schaersvoo | 7522 | if( dx == 0 || dy == 0 ){alert(\"increment is zero !!! \");return;};\ |
7523 | if( typeof(fill_canvas_no) != 'object' ){ var fill_canvas_no = []; };\ |
||
7524 | var fc = %d+canvas_type;\ |
||
7525 | fill_canvas_no.push(fc);\ |
||
7526 | var obj = create_canvas%d(fc,xsize,ysize);\ |
||
7527 | var ctx = obj.getContext('2d');\ |
||
7614 | schaersvoo | 7528 | var x;\ |
7529 | var y;\ |
||
7530 | ctx.lineWidth = linewidth;\ |
||
11820 | schaersvoo | 7531 | ctx.fillStyle='rgba(255,255,255,0.01)';\ |
7532 | ctx.rect(0,0,xsize,ysize);\ |
||
7533 | ctx.fill();\ |
||
11088 | schaersvoo | 7534 | if(linewidth%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
11820 | schaersvoo | 7535 | ctx.strokeStyle=\"rgba(\"+color+\",0.01)\";\ |
7614 | schaersvoo | 7536 | y = ysize;\ |
11820 | schaersvoo | 7537 | ctx.beginPath();\ |
7538 | for( x = 0 ; x < xsize ; x = x + dx ){\ |
||
7539 | ctx.moveTo(x,0);\ |
||
7614 | schaersvoo | 7540 | ctx.lineTo(xsize,y);\ |
7541 | y = y - dy;\ |
||
7542 | };\ |
||
11820 | schaersvoo | 7543 | y=0;\ |
7614 | schaersvoo | 7544 | for( x = xsize ; x > 0 ; x = x - dx){\ |
7545 | ctx.moveTo(x,ysize);\ |
||
11820 | schaersvoo | 7546 | ctx.lineTo(0,y);\ |
7614 | schaersvoo | 7547 | y = y + dy;\ |
7548 | };\ |
||
11820 | schaersvoo | 7549 | y = 0;\ |
7550 | for( x = 0 ; x < xsize ; x = x + dx ){\ |
||
7551 | ctx.moveTo(x,0);\ |
||
7552 | ctx.lineTo(0,y);\ |
||
7553 | y = y + dy;\ |
||
7554 | };\ |
||
7555 | y = 0;\ |
||
7556 | for( x = 0 ; x < xsize ; x = x + dx ){\ |
||
7614 | schaersvoo | 7557 | ctx.moveTo(xsize,y);\ |
7558 | ctx.lineTo(x,ysize);\ |
||
11820 | schaersvoo | 7559 | y = y + dy;\ |
7614 | schaersvoo | 7560 | };\ |
11820 | schaersvoo | 7561 | ctx.closePath();\ |
7614 | schaersvoo | 7562 | ctx.stroke();\ |
11823 | schaersvoo | 7563 | if( use_userdraw ){\ |
11827 | schaersvoo | 7564 | diamond_fill_pattern = ctx;\ |
11823 | schaersvoo | 7565 | }\ |
7566 | else\ |
||
7567 | {\ |
||
7568 | setTimeout(function(){ filltoborder( x0,y0,color,color,canvas_type,true,ctx); },500);};\ |
||
7614 | schaersvoo | 7569 | return;\ |
11820 | schaersvoo | 7570 | }",canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 7571 | break; |
8224 | bpr | 7572 | |
7647 | schaersvoo | 7573 | case DRAW_HATCHFILL:/* not used for userdraw */ |
13970 | obado | 7574 | fprintf(js_include_file,"\n/* draw hatch fill */\n\ |
11827 | schaersvoo | 7575 | var hatch_fill_pattern;\ |
11823 | schaersvoo | 7576 | var draw_hatchfill = function(canvas_type,x0,y0,dx,dy,linewidth,color,stroke_opacity,xsize,ysize,use_userdraw){\ |
11820 | schaersvoo | 7577 | if( dx == 0 || dy == 0 ){alert(\"increment is zero !!! \");return;};\ |
7578 | if( typeof(fill_canvas_no) != 'object' ){ var fill_canvas_no = []; };\ |
||
7579 | var fc = %d+canvas_type;\ |
||
7580 | fill_canvas_no.push(fc);\ |
||
7581 | var obj = create_canvas%d(fc,xsize,ysize);\ |
||
7582 | var ctx = obj.getContext('2d');\ |
||
7583 | var x,y;\ |
||
7584 | ctx.fillStyle='rgba(255,255,255,0.01)';\ |
||
7585 | ctx.rect(0,0,xsize,ysize);\ |
||
7586 | ctx.fill();\ |
||
7587 | ctx.strokeStyle=\"rgba(\"+color+\",0.01)\";\ |
||
7647 | schaersvoo | 7588 | ctx.lineWidth = linewidth;\ |
11088 | schaersvoo | 7589 | if(linewidth%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
7647 | schaersvoo | 7590 | y = ysize;\ |
11820 | schaersvoo | 7591 | ctx.beginPath();\ |
7592 | for( x = 0 ; x < xsize ; x = x + dx ){\ |
||
7593 | ctx.moveTo(x,0);\ |
||
7647 | schaersvoo | 7594 | ctx.lineTo(xsize,y);\ |
7595 | y = y - dy;\ |
||
7596 | };\ |
||
11820 | schaersvoo | 7597 | y = 0;\ |
7647 | schaersvoo | 7598 | for( x = xsize ; x >= dx ; x = x - dx){\ |
7599 | ctx.moveTo(x,ysize);\ |
||
11820 | schaersvoo | 7600 | ctx.lineTo(0,y);\ |
7647 | schaersvoo | 7601 | y = y + dy;\ |
7602 | };\ |
||
11820 | schaersvoo | 7603 | ctx.closePath();\ |
7647 | schaersvoo | 7604 | ctx.stroke();\ |
11823 | schaersvoo | 7605 | if( use_userdraw ){\ |
7606 | hatch_fill_pattern = ctx;\ |
||
7607 | }\ |
||
7608 | else\ |
||
7609 | {\ |
||
7610 | setTimeout(function(){ filltoborder( x0,y0,color,color,canvas_type,true,ctx); },500);};\ |
||
7647 | schaersvoo | 7611 | return;\ |
11820 | schaersvoo | 7612 | };",canvas_root_id,canvas_root_id); |
7647 | schaersvoo | 7613 | break; |
7614 | schaersvoo | 7614 | case DRAW_CIRCLES:/* used for userdraw */ |
13970 | obado | 7615 | fprintf(js_include_file,"\n/* draw circles */\n\ |
11874 | schaersvoo | 7616 | if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\ |
8105 | schaersvoo | 7617 | var draw_circles = function(ctx,x_points,y_points,radius,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_affine,affine_matrix){\ |
7614 | schaersvoo | 7618 | ctx.save();\ |
8071 | schaersvoo | 7619 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 7620 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
7621 | ctx.lineWidth = line_width;\ |
||
11839 | schaersvoo | 7622 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
7623 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\n\ |
||
11874 | schaersvoo | 7624 | var color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\ |
11875 | schaersvoo | 7625 | if(use_filled > 1 ){ if(! all_fill_patterns[use_filled] ){ var pat = create_Pattern(0,0,use_filled,color); all_fill_patterns[use_filled] = pat;};ctx.fillStyle = all_fill_patterns[use_filled]; } else { ctx.fillStyle = color;};\ |
11088 | schaersvoo | 7626 | if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
7614 | schaersvoo | 7627 | for(var p = 0 ; p < x_points.length ; p++ ){\ |
7628 | ctx.beginPath();\ |
||
7629 | ctx.arc(x_points[p],y_points[p],radius[p],0,2*Math.PI,false);\ |
||
7630 | ctx.closePath();\ |
||
11839 | schaersvoo | 7631 | if(use_filled != 0 ){ctx.fill();};\ |
7614 | schaersvoo | 7632 | ctx.stroke();\ |
7633 | }\ |
||
7634 | ctx.restore();\ |
||
7635 | return;\ |
||
7653 | schaersvoo | 7636 | };"); |
7614 | schaersvoo | 7637 | break; |
14066 | bpr | 7638 | case DRAW_POLYLINE:/* user for userdraw: draw lines through points */ |
13970 | obado | 7639 | fprintf(js_include_file,"\n/* draw polyline */\n\ |
11874 | schaersvoo | 7640 | if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\ |
8105 | schaersvoo | 7641 | var draw_polyline = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_affine,affine_matrix){\ |
7663 | schaersvoo | 7642 | ctx.save();\ |
8071 | schaersvoo | 7643 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7663 | schaersvoo | 7644 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
7645 | ctx.lineWidth = line_width;\ |
||
11088 | schaersvoo | 7646 | if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
7663 | schaersvoo | 7647 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
7648 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
7649 | ctx.clearRect(0,0,xsize,ysize);\ |
||
7650 | ctx.beginPath();\ |
||
7651 | for(var p = 0 ; p < x_points.length-1 ; p++ ){\ |
||
7652 | ctx.moveTo(x_points[p],y_points[p]);\ |
||
7653 | ctx.lineTo(x_points[p+1],y_points[p+1]);\ |
||
7654 | }\ |
||
7655 | ctx.closePath();\ |
||
7656 | ctx.stroke();\ |
||
7657 | for(var p = 0 ; p < x_points.length ; p++ ){\ |
||
7658 | ctx.beginPath();\ |
||
7659 | ctx.arc(x_points[p],y_points[p],line_width,0,2*Math.PI,false);\ |
||
7660 | ctx.closePath();ctx.fill();ctx.stroke();\ |
||
7661 | };\ |
||
7662 | ctx.restore();\ |
||
7663 | return;\ |
||
7664 | };"); |
||
7665 | break; |
||
8224 | bpr | 7666 | |
7614 | schaersvoo | 7667 | case DRAW_SEGMENTS:/* used for userdraw */ |
13970 | obado | 7668 | fprintf(js_include_file,"\n/* draw segments */\n\ |
8105 | schaersvoo | 7669 | var draw_segments = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_affine,affine_matrix){\ |
7614 | schaersvoo | 7670 | ctx.save();\ |
8071 | schaersvoo | 7671 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 7672 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
7673 | ctx.lineWidth = line_width;\ |
||
11088 | schaersvoo | 7674 | if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
7614 | schaersvoo | 7675 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
7676 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
7677 | for(var p = 0 ; p < x_points.length ; p = p+2 ){\ |
||
7678 | ctx.beginPath();\ |
||
7679 | ctx.moveTo(x_points[p],y_points[p]);\ |
||
7680 | ctx.lineTo(x_points[p+1],y_points[p+1]);\ |
||
7681 | ctx.closePath();\ |
||
7682 | ctx.stroke();\ |
||
7683 | }\ |
||
7684 | ctx.restore();\ |
||
7685 | return;\ |
||
7686 | };"); |
||
7687 | break; |
||
8224 | bpr | 7688 | |
7614 | schaersvoo | 7689 | case DRAW_LINES:/* used for userdraw */ |
13970 | obado | 7690 | fprintf(js_include_file,"\n/* draw lines */\n\ |
7614 | schaersvoo | 7691 | function calc_line(x1,x2,y1,y2){\ |
7692 | var marge = 2;\ |
||
7693 | if(x1 < x2+marge && x1>x2-marge){\ |
||
7694 | return [x1,0,x1,ysize];\ |
||
7695 | };\ |
||
7696 | if(y1 < y2+marge && y1>y2-marge){\ |
||
7697 | return [0,y1,xsize,y1];\ |
||
7698 | };\ |
||
7699 | var Y1 = y1 - (x1)*(y2 - y1)/(x2 - x1);\ |
||
7700 | var Y2 = y1 + (xsize - x1)*(y2 - y1)/(x2 - x1);\ |
||
7701 | return [0,Y1,xsize,Y2];\ |
||
7702 | };\ |
||
8105 | schaersvoo | 7703 | var draw_lines = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_affine,affine_matrix){\ |
7614 | schaersvoo | 7704 | ctx.save();\ |
7705 | var line = new Array(4);\ |
||
8071 | schaersvoo | 7706 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 7707 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
7708 | ctx.lineWidth = line_width;\ |
||
11088 | schaersvoo | 7709 | if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
7614 | schaersvoo | 7710 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
7711 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
7712 | for(var p = 0 ; p < x_points.length ; p = p+2 ){\ |
||
7713 | line = calc_line(x_points[p],x_points[p+1],y_points[p],y_points[p+1]);\ |
||
7714 | ctx.beginPath();\ |
||
7715 | ctx.moveTo(line[0],line[1]);\ |
||
7716 | ctx.lineTo(line[2],line[3]);\ |
||
7717 | ctx.closePath();\ |
||
7718 | ctx.stroke();\ |
||
7719 | }\ |
||
7720 | ctx.restore();\ |
||
7721 | return;\ |
||
7722 | };"); |
||
7723 | break; |
||
7724 | |||
8244 | schaersvoo | 7725 | case DRAW_DEMILINES:/* used for userdraw */ |
13970 | obado | 7726 | fprintf(js_include_file,"\n/* draw demilines */\n\ |
8244 | schaersvoo | 7727 | function find_inf_point(x1,y1,x2,y2){\ |
7728 | if(x1<x2+2 && x1>x2-2){if(y1<y2){return [x1,y1,x1,ysize];}else{return [x1,0,x1,y1];};};\ |
||
7729 | var rc = (y2 - y1)/(x2 - x1);var q = y1 - (x1)*rc;\ |
||
7730 | if( x1 < x2 ){ return [x1,y1,xsize,rc*xsize+q];}else{return [x1,y1,0,q];};\ |
||
7731 | };\ |
||
7732 | var draw_demilines = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_affine,affine_matrix){\ |
||
7733 | ctx.save();\ |
||
7734 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
||
7735 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
||
7736 | ctx.lineWidth = line_width;\ |
||
11088 | schaersvoo | 7737 | if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
8244 | schaersvoo | 7738 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
7739 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
7740 | var pair = new Array(4);\ |
||
7741 | for(var p = 0 ; p < x_points.length ; p = p+2 ){\ |
||
7742 | pair = find_inf_point(x_points[p],y_points[p],x_points[p+1],y_points[p+1]);\ |
||
7743 | ctx.beginPath();\ |
||
7744 | ctx.moveTo(pair[0],pair[1]);\ |
||
7745 | ctx.lineTo(pair[2],pair[3]);\ |
||
7746 | ctx.closePath();\ |
||
7747 | ctx.stroke();\ |
||
7748 | }\ |
||
7749 | ctx.restore();\ |
||
7750 | return;\ |
||
7751 | };"); |
||
7752 | break; |
||
7753 | |||
7614 | schaersvoo | 7754 | case DRAW_CROSSHAIRS:/* used for userdraw */ |
13970 | obado | 7755 | fprintf(js_include_file,"\n/* draw crosshairs */\n\ |
8105 | schaersvoo | 7756 | var draw_crosshairs = function(ctx,x_points,y_points,line_width,crosshair_size,stroke_color,stroke_opacity,use_rotate,angle,use_affine,affine_matrix){\ |
12311 | schaersvoo | 7757 | ctx.save();\ |
8071 | schaersvoo | 7758 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 7759 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
7760 | ctx.lineWidth = line_width;\ |
||
11088 | schaersvoo | 7761 | if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
7614 | schaersvoo | 7762 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
7763 | var x1,x2,y1,y2;\ |
||
7764 | for(var p = 0 ; p < x_points.length ; p++ ){\ |
||
7765 | x1 = x_points[p] - crosshair_size;\ |
||
7766 | x2 = x_points[p] + crosshair_size;\ |
||
7767 | y1 = y_points[p] - crosshair_size;\ |
||
7768 | y2 = y_points[p] + crosshair_size;\ |
||
7769 | ctx.beginPath();\ |
||
7770 | ctx.moveTo(x1,y1);\ |
||
7771 | ctx.lineTo(x2,y2);\ |
||
7772 | ctx.closePath();\ |
||
7773 | ctx.stroke();\ |
||
7774 | ctx.beginPath();\ |
||
7775 | ctx.moveTo(x2,y1);\ |
||
7776 | ctx.lineTo(x1,y2);\ |
||
7777 | ctx.closePath();\ |
||
7778 | ctx.stroke();\ |
||
7779 | }\ |
||
7780 | ctx.restore();\ |
||
7781 | return;\ |
||
7653 | schaersvoo | 7782 | };"); |
7614 | schaersvoo | 7783 | break; |
7784 | |||
7785 | case DRAW_RECTS:/* used for userdraw */ |
||
13970 | obado | 7786 | fprintf(js_include_file,"\n/* draw rects */\n\ |
11874 | schaersvoo | 7787 | if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\ |
8105 | schaersvoo | 7788 | var draw_rects = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_affine,affine_matrix){\ |
12000 | schaersvoo | 7789 | var color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\ |
7614 | schaersvoo | 7790 | ctx.save();\ |
8071 | schaersvoo | 7791 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 7792 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
7793 | ctx.lineWidth = line_width;\ |
||
11088 | schaersvoo | 7794 | if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
8448 | schaersvoo | 7795 | ctx.strokeStyle = 'rgba('+stroke_color+','+stroke_opacity+')';\ |
7614 | schaersvoo | 7796 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];}};\ |
11875 | schaersvoo | 7797 | if(use_filled > 1 ){ if(! all_fill_patterns[use_filled] ){ var pat = create_Pattern(0,0,use_filled,color); all_fill_patterns[use_filled] = pat;};ctx.fillStyle = all_fill_patterns[use_filled]; } else { ctx.fillStyle = color;};\ |
7614 | schaersvoo | 7798 | for(var p = 0 ; p < x_points.length ; p = p + 2){\ |
7799 | ctx.beginPath();\ |
||
7800 | ctx.rect(x_points[p],y_points[p],x_points[p+1]-x_points[p],y_points[p+1]-y_points[p]);\ |
||
7801 | ctx.closePath();\ |
||
11839 | schaersvoo | 7802 | if(use_filled != 0 ){ctx.fill();}\ |
7614 | schaersvoo | 7803 | ctx.stroke();\ |
7804 | };\ |
||
7805 | ctx.restore();\ |
||
7806 | return;\ |
||
7653 | schaersvoo | 7807 | };"); |
7614 | schaersvoo | 7808 | break; |
7809 | |||
7810 | case DRAW_ROUNDRECTS:/* used for userdraw */ |
||
13970 | obado | 7811 | fprintf(js_include_file,"\n/* draw round rects */\n\ |
11874 | schaersvoo | 7812 | if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\ |
8105 | schaersvoo | 7813 | var draw_roundrects = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,use_rotate,angle,use_affine,affine_matrix){\ |
12000 | schaersvoo | 7814 | var color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\ |
7614 | schaersvoo | 7815 | ctx.save();\ |
8071 | schaersvoo | 7816 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 7817 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
7818 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
||
9462 | schaersvoo | 7819 | ctx.lineWidth = line_width;\ |
11088 | schaersvoo | 7820 | if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
11875 | schaersvoo | 7821 | if(use_filled > 1 ){ if(! all_fill_patterns[use_filled] ){ var pat = create_Pattern(0,0,use_filled,color); all_fill_patterns[use_filled] = pat;};ctx.fillStyle = all_fill_patterns[use_filled]; } else { ctx.fillStyle = color;};\ |
7614 | schaersvoo | 7822 | var x,y,w,h,r;\ |
7823 | for(var p = 0; p < x_points.length; p = p+2){\ |
||
7824 | x = x_points[p];y = y_points[p];w = x_points[p+1] - x;h = y_points[p+1] - y;r = parseInt(0.1*w);\ |
||
7825 | ctx.beginPath();ctx.moveTo(x + r, y);\ |
||
7826 | ctx.lineTo(x + w - r, y);\ |
||
7827 | ctx.quadraticCurveTo(x + w, y, x + w, y + r);\ |
||
7828 | ctx.lineTo(x + w, y + h - r);\ |
||
7829 | ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);\ |
||
7830 | ctx.lineTo(x + r, y + h);\ |
||
7831 | ctx.quadraticCurveTo(x, y + h, x, y + h - r);\ |
||
7832 | ctx.lineTo(x, y + r);\ |
||
7833 | ctx.quadraticCurveTo(x, y, x + r, y);\ |
||
7834 | ctx.closePath();if( use_dashed == 1 ){ctx.setLineDash([dashtype0,dashtype1]);};\ |
||
7835 | ctx.strokeStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
11839 | schaersvoo | 7836 | if( use_filled != 0 ){ctx.fill();};\ |
7614 | schaersvoo | 7837 | ctx.stroke();\ |
7838 | }\ |
||
7839 | ctx.restore();\ |
||
7653 | schaersvoo | 7840 | };"); |
8224 | bpr | 7841 | break; |
7614 | schaersvoo | 7842 | |
7843 | case DRAW_ELLIPSES:/* not used for userdraw */ |
||
13970 | obado | 7844 | fprintf(js_include_file,"\n/* draw ellipses */\n\ |
11874 | schaersvoo | 7845 | if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\ |
8105 | schaersvoo | 7846 | var draw_ellipses = function(canvas_type,x_points,y_points,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,use_rotate,angle,use_affine,affine_matrix){\ |
7614 | schaersvoo | 7847 | var obj;\ |
7848 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
7849 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
7850 | }\ |
||
7851 | else\ |
||
7852 | {\ |
||
7853 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
7854 | };\ |
||
7855 | var ctx = obj.getContext(\"2d\");\ |
||
7856 | ctx.save();\ |
||
8071 | schaersvoo | 7857 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 7858 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
11875 | schaersvoo | 7859 | if(use_filled > 1 ){ if(! all_fill_patterns[use_filled] ){ var pat = create_Pattern(0,0,use_filled,color); all_fill_patterns[use_filled] = pat;};ctx.fillStyle = all_fill_patterns[use_filled]; } else { ctx.fillStyle = color;};\ |
7614 | schaersvoo | 7860 | var cx,cy,ry,rx;\ |
7861 | ctx.lineWidth = line_width;\ |
||
11088 | schaersvoo | 7862 | if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
7614 | schaersvoo | 7863 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
7864 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
7865 | for(var p=0;p< x_points.length;p = p+2){\ |
||
7866 | ctx.beginPath();\ |
||
7867 | cx = x_points[p];cy = y_points[p];rx = 0.25*x_points[p+1];ry = 0.25*y_points[p+1];\ |
||
7868 | ctx.translate(cx - rx, cy - ry);\ |
||
7869 | ctx.scale(rx, ry);\ |
||
7870 | ctx.arc(1, 1, 1, 0, 2 * Math.PI, false);\ |
||
11839 | schaersvoo | 7871 | if( use_filled != 0 ){ctx.fill();}\ |
7614 | schaersvoo | 7872 | ctx.stroke();\ |
7873 | };\ |
||
7874 | ctx.restore();\ |
||
7653 | schaersvoo | 7875 | };",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 7876 | break; |
7877 | |||
7878 | case DRAW_PATHS: /* used for userdraw */ |
||
13970 | obado | 7879 | fprintf(js_include_file,"\n/* draw paths */\n\ |
11874 | schaersvoo | 7880 | if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\ |
8105 | schaersvoo | 7881 | var draw_paths = function(ctx,x_points,y_points,line_width,closed_path,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,use_rotate,angle,use_affine,affine_matrix){\ |
7614 | schaersvoo | 7882 | ctx.save();\ |
8071 | schaersvoo | 7883 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 7884 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
7885 | ctx.lineWidth = line_width;\ |
||
11088 | schaersvoo | 7886 | if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
7614 | schaersvoo | 7887 | ctx.lineJoin = \"round\";\ |
7888 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
11874 | schaersvoo | 7889 | var color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\ |
11875 | schaersvoo | 7890 | if(use_filled > 1 ){ if(! all_fill_patterns[use_filled] ){ var pat = create_Pattern(0,0,use_filled,color); all_fill_patterns[use_filled] = pat;};ctx.fillStyle = all_fill_patterns[use_filled]; } else { ctx.fillStyle = color;};\ |
7614 | schaersvoo | 7891 | ctx.beginPath();\ |
7892 | ctx.moveTo(x_points[0],y_points[0]);\ |
||
7893 | for(var p = 1 ; p < x_points.length ; p++ ){ctx.lineTo(x_points[p],y_points[p]);}\ |
||
7894 | if(closed_path == 1){ctx.lineTo(x_points[0],y_points[0]);ctx.closePath();}\ |
||
7895 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
||
11839 | schaersvoo | 7896 | if(use_filled != 0){ctx.fill();}\ |
7614 | schaersvoo | 7897 | ctx.stroke();\ |
7898 | ctx.restore();\ |
||
7899 | return;\ |
||
7900 | };"); |
||
8224 | bpr | 7901 | |
7614 | schaersvoo | 7902 | break; |
7903 | case DRAW_ARROWS:/* used for userdraw */ |
||
13970 | obado | 7904 | fprintf(js_include_file,"\n/* draw arrows */\n\ |
8105 | schaersvoo | 7905 | var draw_arrows = function(ctx,x_points,y_points,arrow_head,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,type,use_rotate,angle,use_affine,affine_matrix){\ |
7614 | schaersvoo | 7906 | ctx.save();\ |
8071 | schaersvoo | 7907 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 7908 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
7909 | ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
7910 | ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
7911 | ctx.lineWidth = line_width;\ |
||
11088 | schaersvoo | 7912 | if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
7614 | schaersvoo | 7913 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
7914 | ctx.lineCap = \"round\";\ |
||
7915 | var x1,y1,x2,y2,dx,dy,len;\ |
||
7916 | for(var p = 0 ; p < x_points.length - 1 ; p = p +2){\ |
||
7874 | schaersvoo | 7917 | ctx.save();\ |
7614 | schaersvoo | 7918 | x1 = x_points[p];y1 = y_points[p];x2 = x_points[p+1];y2 = y_points[p+1];dx = x2 - x1;dy = y2 - y1;\ |
7919 | len = Math.sqrt(dx*dx+dy*dy);\ |
||
7920 | ctx.translate(x2,y2);\ |
||
7921 | ctx.rotate(Math.atan2(dy,dx));\ |
||
7922 | ctx.lineCap = \"round\";\ |
||
7923 | ctx.beginPath();\ |
||
7924 | ctx.moveTo(0,0);\ |
||
7925 | ctx.lineTo(-len,0);\ |
||
7926 | ctx.closePath();\ |
||
7927 | ctx.stroke();\ |
||
7928 | ctx.beginPath();\ |
||
7929 | ctx.moveTo(0,0);\ |
||
7930 | ctx.lineTo(-1*arrow_head,-0.5*arrow_head);\ |
||
7931 | ctx.lineTo(-1*arrow_head, 0.5*arrow_head);\ |
||
7932 | ctx.closePath();\ |
||
7933 | ctx.fill();\ |
||
7874 | schaersvoo | 7934 | ctx.restore();\ |
7614 | schaersvoo | 7935 | if( type == 2 ){\ |
7936 | ctx.save();\ |
||
7937 | ctx.translate(x1,y1);\ |
||
7938 | ctx.rotate(Math.atan2(-dy,-dx));\ |
||
7939 | ctx.beginPath();\ |
||
7940 | ctx.moveTo(0,0);\ |
||
8347 | schaersvoo | 7941 | ctx.lineTo(-1*arrow_head,-0.4*arrow_head);\ |
7942 | ctx.lineTo(-1*arrow_head, 0.4*arrow_head);\ |
||
7614 | schaersvoo | 7943 | ctx.closePath();\ |
7944 | ctx.stroke();\ |
||
7945 | ctx.fill();\ |
||
7874 | schaersvoo | 7946 | ctx.restore();\ |
8379 | schaersvoo | 7947 | };\ |
7948 | };\ |
||
7614 | schaersvoo | 7949 | ctx.restore();\ |
7950 | return;\ |
||
7653 | schaersvoo | 7951 | };"); |
7614 | schaersvoo | 7952 | break; |
7953 | |||
7954 | case DRAW_VIDEO:/* not used for userdraw */ |
||
13970 | obado | 7955 | fprintf(js_include_file,"\n/* draw video */\n\ |
8105 | schaersvoo | 7956 | var draw_video = function(canvas_root_id,x,y,w,h,URL){\ |
7614 | schaersvoo | 7957 | var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\ |
7958 | var video_div = document.createElement(\"div\");\ |
||
7959 | canvas_div.appendChild(video_div);\ |
||
7960 | video_div.style.position = \"absolute\";\ |
||
7961 | video_div.style.left = x+\"px\";\ |
||
7962 | video_div.style.top = y+\"px\";\ |
||
7963 | video_div.style.width = w+\"px\";\ |
||
7964 | video_div.style.height = h+\"px\";\ |
||
7965 | var video = document.createElement(\"video\");\ |
||
7966 | video_div.appendChild(video);\ |
||
7967 | video.style.width = w+\"px\";\ |
||
7968 | video.style.height = h+\"px\";\ |
||
7969 | video.autobuffer = true;\ |
||
7970 | video.controls = true;video.autoplay = false;\ |
||
7971 | var src = document.createElement(\"source\");\ |
||
7972 | src.type = \"video/mp4\";\ |
||
7973 | src.src = URL;\ |
||
7974 | video.appendChild(src);\ |
||
7975 | video.load();\ |
||
7976 | return;\ |
||
8224 | bpr | 7977 | };"); |
7614 | schaersvoo | 7978 | break; |
8224 | bpr | 7979 | |
7614 | schaersvoo | 7980 | case DRAW_AUDIO:/* not used for userdraw */ |
13970 | obado | 7981 | fprintf(js_include_file,"\n/* draw audio */\n\ |
8105 | schaersvoo | 7982 | var draw_audio = function(canvas_root_id,x,y,w,h,loop,visible,URL1,URL2){\ |
7614 | schaersvoo | 7983 | var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\ |
7984 | var audio_div = document.createElement(\"div\");\ |
||
7985 | canvas_div.appendChild(audio_div);\ |
||
7986 | audio_div.style.position = \"absolute\";\ |
||
7987 | audio_div.style.left = x+\"px\";\ |
||
7988 | audio_div.style.top = y+\"px\";\ |
||
7989 | audio_div.style.width = w+\"px\";\ |
||
7990 | audio_div.style.height = h+\"px\";\ |
||
7991 | var audio = document.createElement(\"audio\");\ |
||
7992 | audio_div.appendChild(audio);\ |
||
7993 | audio.setAttribute(\"style\",\"width:\"+w+\"px;height:\"+h+\"px\");\ |
||
7994 | audio.autobuffer = true;\ |
||
8379 | schaersvoo | 7995 | if(visible == 1 ){ audio.controls = true;audio.autoplay = false;}else{ audio.controls = false;audio.autoplay = true;};\ |
7996 | if(loop == 1 ){ audio.loop = true;}else{ audio.loop = false;};\ |
||
7614 | schaersvoo | 7997 | var src1 = document.createElement(\"source\");\ |
7998 | src1.type = \"audio/ogg\";\ |
||
7999 | src1.src = URL1;\ |
||
8000 | audio.appendChild(src1);\ |
||
8001 | var src2 = document.createElement(\"source\");\ |
||
8002 | src2.type = \"audio/mpeg\";\ |
||
8003 | src2.src = URL2;\ |
||
8004 | audio.appendChild(src2);\ |
||
8005 | audio.load();\ |
||
8006 | return;\ |
||
7653 | schaersvoo | 8007 | };"); |
7614 | schaersvoo | 8008 | break; |
8224 | bpr | 8009 | |
7614 | schaersvoo | 8010 | case DRAW_HTTP:/* not used for userdraw */ |
13970 | obado | 8011 | fprintf(js_include_file,"\n/* draw http */\n\ |
8105 | schaersvoo | 8012 | var draw_http = function(canvas_root_id,x,y,w,h,URL){\ |
7614 | schaersvoo | 8013 | var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\ |
8014 | var http_div = document.createElement(\"div\");\ |
||
8015 | var iframe = document.createElement(\"iframe\");\ |
||
8016 | canvas_div.appendChild(http_div);\ |
||
8017 | http_div.appendChild(iframe);\ |
||
8018 | iframe.src = URL;\ |
||
8019 | iframe.setAttribute(\"width\",w);\ |
||
8020 | iframe.setAttribute(\"height\",h);\ |
||
8021 | return;\ |
||
7653 | schaersvoo | 8022 | };"); |
7614 | schaersvoo | 8023 | break; |
8224 | bpr | 8024 | |
13829 | bpr | 8025 | case DRAW_XML: /* |
14066 | bpr | 8026 | onclick=1: click |
14062 | schaersvoo | 8027 | onclick=2 drag ==> always centered (use_offset=4) |
11238 | schaersvoo | 8028 | xy:drag_type = 0; |
8029 | x: drag_type = 1; |
||
8030 | y: drag_type = 2; |
||
8031 | */ |
||
8032 | |||
13970 | obado | 8033 | fprintf(js_include_file,"\n/* draw xml */\n\ |
14044 | schaersvoo | 8034 | var draw_xml = function(canvas_root_id,x,y,mathml,drag_type,onclick,click_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,centered,use_snap){\ |
7614 | schaersvoo | 8035 | var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\ |
8036 | var xml_div = document.createElement(\"div\");\ |
||
8037 | canvas_div.appendChild(xml_div);\ |
||
8038 | xml_div.innerHTML = mathml;\ |
||
14038 | schaersvoo | 8039 | xml_div.style.position = \"absolute\"; xml_div.style.left = x+\"px\";xml_div.style.top = y+\"px\";\ |
8040 | var factor = 1;\ |
||
8041 | if( centered > 0 ){ factor = 0.5;};\ |
||
8042 | var xml_div_width = factor*(parseInt(window.getComputedStyle(xml_div).width , 10));\ |
||
8043 | var xml_div_height = factor*(parseInt(window.getComputedStyle(xml_div).height ,10));\ |
||
8379 | schaersvoo | 8044 | xml_div.style.color = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
11745 | schaersvoo | 8045 | var color_org = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
11756 | schaersvoo | 8046 | var back_color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\ |
8047 | var no_color = \"rgba(255,255,255,0)\";\ |
||
11745 | schaersvoo | 8048 | var dragging = false;\ |
11747 | schaersvoo | 8049 | if( onclick == 2 ){reply[click_cnt] = px2x(x)+','+px2y(y);};\ |
8050 | if( onclick == 1 ){reply[click_cnt] = 0;};\ |
||
8051 | if( onclick == 2 ){\ |
||
8052 | xml_div.onclick = function(){\ |
||
11756 | schaersvoo | 8053 | canvas_div.onclick = function(evt){if(dragging){dragging = false;xml_div.style.color = color_org; xml_div.style.backgroundColor = no_color;}else{dragging = true;xml_div.style.color = 'red';xml_div.style.backgroundColor = back_color;};};\ |
11747 | schaersvoo | 8054 | canvas_div.onmousemove = function(evt){\ |
8055 | if(!dragging){return;};\ |
||
8056 | var x1;var y1;\ |
||
8057 | var mouse = dragstuff.getMouse(evt,xml_div);\ |
||
14044 | schaersvoo | 8058 | var xy = multisnap_check(mouse.x,mouse.y,use_snap);\ |
11747 | schaersvoo | 8059 | switch(drag_type){\ |
14044 | schaersvoo | 8060 | case 0: x1 = xy[0]-xml_div_width;y1=xy[1]-xml_div_height;break;\ |
8061 | case 1: x1 = xy[0]-xml_div_width;y1 = y;break;\ |
||
8062 | case 2: x1 = x;y1 = xy[1]-xml_div_height;break;\ |
||
8063 | default:x1 = xy[0];y1 = xy[1]; break;\ |
||
11747 | schaersvoo | 8064 | };\ |
8065 | xml_div.style.left = x1 + 'px';xml_div.style.top = y1 + 'px';\ |
||
14062 | schaersvoo | 8066 | reply[click_cnt] = px2x(xy[0])+','+px2y(xy[1]);\ |
11238 | schaersvoo | 8067 | };\ |
7614 | schaersvoo | 8068 | };\ |
11238 | schaersvoo | 8069 | };\ |
8070 | if(onclick == 1){\ |
||
11747 | schaersvoo | 8071 | xml_div.onclick = function(){\ |
11756 | schaersvoo | 8072 | if(reply[click_cnt] == 0){ reply[click_cnt] = 1; xml_div.style.color = 'red';xml_div.style.backgroundColor = back_color;}else{reply[click_cnt] = 0;xml_div.style.color = color_org;xml_div.style.backgroundColor = no_color;};};\ |
7614 | schaersvoo | 8073 | };\ |
8074 | return;\ |
||
11745 | schaersvoo | 8075 | };"); |
7614 | schaersvoo | 8076 | break; |
7654 | schaersvoo | 8077 | case DRAW_SGRAPH: |
8224 | bpr | 8078 | /* |
7654 | schaersvoo | 8079 | xstart = given |
8080 | ystart = given |
||
8081 | sgraph(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily) |
||
8082 | */ |
||
13970 | obado | 8083 | fprintf(js_include_file,"\n/* draw sgraph */\n\ |
8105 | schaersvoo | 8084 | var draw_sgraph = function(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily,opacity,font_size){\ |
7658 | schaersvoo | 8085 | var obj;if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){obj = document.getElementById(\"wims_canvas%d\"+canvas_type);}else{ obj = create_canvas%d(canvas_type,xsize,ysize);};\ |
8086 | var ctx = obj.getContext(\"2d\");\ |
||
8087 | ctx.font = fontfamily;\ |
||
8088 | var minor_opacity = 0.8*opacity;\ |
||
8089 | ctx.clearRect(0,0,xsize,ysize);\ |
||
7976 | schaersvoo | 8090 | var zero_x = 0.1*xsize;\ |
8091 | var zero_y = 0.9*ysize;\ |
||
8129 | schaersvoo | 8092 | var snor_x;var snor_y;\ |
7654 | schaersvoo | 8093 | if( xstart != xmin){\ |
7658 | schaersvoo | 8094 | snor_x = 0.1*xsize;\ |
8095 | }\ |
||
8096 | else\ |
||
8097 | {\ |
||
8098 | snor_x = 0;\ |
||
8099 | xstart = xmin;\ |
||
8100 | };\ |
||
8101 | ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\ |
||
8102 | ctx.lineWidth = 2;\ |
||
8103 | ctx.beginPath();\ |
||
8104 | ctx.moveTo(xsize,zero_y);\ |
||
8105 | ctx.lineTo(zero_x,zero_y);\ |
||
8106 | ctx.lineTo(zero_x,0);\ |
||
8107 | ctx.stroke();\ |
||
8108 | ctx.closePath();\ |
||
8109 | ctx.beginPath();\ |
||
8110 | ctx.moveTo(zero_x,zero_y);\ |
||
8111 | ctx.lineTo(zero_x + 0.25*snor_x,zero_y - 0.1*snor_x);\ |
||
8112 | ctx.lineTo(zero_x + 0.5*snor_x,zero_y + 0.1*snor_x);\ |
||
8113 | ctx.lineTo(zero_x + 0.75*snor_x,zero_y - 0.1*snor_x);\ |
||
8114 | ctx.lineTo(zero_x + snor_x,zero_y);\ |
||
8115 | ctx.stroke();\ |
||
8116 | ctx.closePath();\ |
||
8117 | ctx.beginPath();\ |
||
8118 | var num = xstart;\ |
||
7660 | schaersvoo | 8119 | var flipflop = 1;\ |
7658 | schaersvoo | 8120 | var step_x = xmajor*(xsize - zero_x - snor_x)/(xmax - xstart);\ |
7976 | schaersvoo | 8121 | var txtsize;var txt_marge=step_x - 5;\ |
7658 | schaersvoo | 8122 | for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\ |
7976 | schaersvoo | 8123 | txtsize = ctx.measureText(num).width;\ |
8124 | if( txtsize > txt_marge ){if( flipflop == 1 ){flipflop = 0;}else{flipflop = 1;};};\ |
||
8125 | if( flipflop == 1){\ |
||
8126 | ctx.fillText(num,x - 0.5*txtsize,zero_y+font_size);\ |
||
8127 | }\ |
||
8128 | else\ |
||
8129 | {\ |
||
8130 | ctx.fillText(num,x - 0.5*txtsize,zero_y+2*font_size);\ |
||
8379 | schaersvoo | 8131 | };\ |
7976 | schaersvoo | 8132 | num = num + xmajor;\ |
7658 | schaersvoo | 8133 | };\ |
8134 | ctx.stroke();\ |
||
8135 | ctx.closePath();\ |
||
8136 | ctx.lineWidth = 1;\ |
||
8137 | ctx.beginPath();\ |
||
8138 | for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\ |
||
8139 | ctx.moveTo(x,zero_y);\ |
||
8140 | ctx.lineTo(x,0);\ |
||
8141 | };\ |
||
8142 | ctx.stroke();\ |
||
8143 | ctx.closePath();\ |
||
8144 | if( xminor > 1){\ |
||
8145 | ctx.lineWidth = 0.5;\ |
||
8146 | ctx.beginPath();\ |
||
8147 | ctx.strokeStyle = \"rgba(\"+minorcolor+\",\"+minor_opacity+\")\";\ |
||
8148 | var minor_step_x = step_x / xminor;\ |
||
8149 | var nx;\ |
||
8150 | for(var x = zero_x+snor_x; x < xsize;x = x + step_x){\ |
||
8151 | num = 1;\ |
||
8152 | for(var p = 1 ; p < xminor ; p++){\ |
||
8153 | nx = x + num*minor_step_x;\ |
||
8154 | ctx.moveTo(nx,zero_y);\ |
||
8155 | ctx.lineTo(nx,0);\ |
||
8156 | num++;\ |
||
8157 | };\ |
||
8158 | };\ |
||
8159 | ctx.stroke();\ |
||
8160 | ctx.closePath();\ |
||
8161 | ctx.beginPath();\ |
||
8162 | ctx.lineWidth = 2;\ |
||
8163 | ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\ |
||
8164 | for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\ |
||
8165 | ctx.moveTo(x,zero_y);ctx.lineTo(x,zero_y - 12);\ |
||
8166 | };\ |
||
8167 | for(var x = zero_x+snor_x ; x < xsize;x = x + minor_step_x){\ |
||
8168 | ctx.moveTo(x,zero_y);ctx.lineTo(x,zero_y - 6);\ |
||
8169 | };\ |
||
8170 | ctx.stroke();\ |
||
8171 | ctx.closePath();\ |
||
8172 | ctx.lineWidth = 0.5;\ |
||
8173 | };\ |
||
8174 | xmin = xstart - (xmajor*(zero_x+snor_x)/step_x);\ |
||
8175 | if( ystart != ymin){\ |
||
8176 | snor_y = 0.1*ysize;\ |
||
8177 | }\ |
||
8178 | else\ |
||
8179 | {\ |
||
8180 | snor_y = 0;\ |
||
8181 | ystart = ymin;\ |
||
8182 | };\ |
||
8183 | ctx.lineWidth = 2;\ |
||
8184 | ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\ |
||
8185 | ctx.beginPath();\ |
||
8186 | ctx.moveTo(zero_x,zero_y);\ |
||
8187 | ctx.lineTo(zero_x - 0.1*snor_y,zero_y - 0.25*snor_y);\ |
||
8188 | ctx.lineTo(zero_x + 0.1*snor_y,zero_y - 0.5*snor_y);\ |
||
8189 | ctx.lineTo(zero_x - 0.1*snor_y,zero_y - 0.75*snor_y);\ |
||
8190 | ctx.lineTo(zero_x,zero_y - snor_y);\ |
||
8191 | ctx.stroke();\ |
||
8192 | ctx.closePath();\ |
||
8193 | ctx.beginPath();\ |
||
8194 | ctx.lineWidth = 1;\ |
||
8195 | num = ystart;\ |
||
8196 | var step_y = ymajor*(zero_y - snor_y)/(ymax - ystart);\ |
||
8197 | for(var y = zero_y - snor_y ; y > 0; y = y - step_y){\ |
||
8198 | ctx.moveTo(zero_x,y);\ |
||
8199 | ctx.lineTo(xsize,y);\ |
||
8200 | ctx.fillText(num,zero_x - ctx.measureText(num+\" \").width,parseInt(y+0.2*font_size));\ |
||
8201 | num = num + ymajor;\ |
||
8202 | };\ |
||
8203 | ctx.stroke();\ |
||
8204 | ctx.closePath();\ |
||
8205 | if( yminor > 1){\ |
||
8206 | ctx.lineWidth = 0.5;\ |
||
8207 | ctx.beginPath();\ |
||
8208 | ctx.strokeStyle = \"rgba(\"+minorcolor+\",\"+minor_opacity+\")\";\ |
||
8209 | var minor_step_y = step_y / yminor;\ |
||
8210 | var ny;\ |
||
8211 | for(var y = 0 ; y < zero_y - snor_y ;y = y + step_y){\ |
||
8212 | num = 1;\ |
||
8213 | for(var p = 1 ;p < yminor;p++){\ |
||
8214 | ny = y + num*minor_step_y;\ |
||
8215 | ctx.moveTo(zero_x,ny);\ |
||
8216 | ctx.lineTo(xsize,ny);\ |
||
8217 | num++;\ |
||
8218 | };\ |
||
8219 | };\ |
||
8220 | ctx.stroke();\ |
||
8221 | ctx.closePath();\ |
||
8222 | ctx.lineWidth = 2;\ |
||
8223 | ctx.beginPath();\ |
||
8224 | ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\ |
||
8225 | for(var y = zero_y - snor_y ; y > 0 ;y = y - step_y){\ |
||
8226 | ctx.moveTo(zero_x,y);\ |
||
8227 | ctx.lineTo(zero_x+12,y);\ |
||
8228 | };\ |
||
8229 | for(var y = zero_y - snor_y ; y > 0 ;y = y - minor_step_y){\ |
||
8230 | ctx.moveTo(zero_x,y);\ |
||
8231 | ctx.lineTo(zero_x+6,y);\ |
||
8232 | };\ |
||
8233 | ctx.stroke();\ |
||
8234 | ctx.closePath();\ |
||
8235 | };\ |
||
8236 | ymin = ystart - (ymajor*(ysize - zero_y + snor_y)/step_y);\ |
||
11088 | schaersvoo | 8237 | if( typeof(legend%d) !== 'undefined' ){\ |
7654 | schaersvoo | 8238 | ctx.globalAlpha = 1.0;\ |
8239 | var y_offset = 2*font_size;\ |
||
8240 | var txt;var txt_size;\ |
||
8241 | var x_offset = xsize - 2*font_size;\ |
||
8242 | var l_length = legend%d.length;var barcolor = new Array();\ |
||
11088 | schaersvoo | 8243 | if( typeof(legendcolors%d) !== 'undefined' ){\ |
7654 | schaersvoo | 8244 | for(var p = 0 ; p < l_length ; p++){\ |
8245 | barcolor[p] = legendcolors%d[p];\ |
||
8246 | };\ |
||
8247 | }else{\ |
||
8248 | if( barcolor.length == 0 ){\ |
||
8249 | for(var p = 0 ; p < l_length ; p++){\ |
||
8250 | barcolor[p] = stroke_color;\ |
||
8251 | };\ |
||
8252 | };\ |
||
8253 | };\ |
||
8254 | for(var p = 0; p < l_length; p++){\ |
||
8255 | ctx.fillStyle = barcolor[p];\ |
||
8256 | txt = legend%d[p];\ |
||
8257 | txt_size = ctx.measureText(txt).width;\ |
||
8258 | ctx.fillText(legend%d[p],x_offset - txt_size, y_offset);\ |
||
8259 | y_offset = parseInt(y_offset + 1.5*font_size);\ |
||
8260 | };\ |
||
8261 | };\ |
||
11088 | schaersvoo | 8262 | if( typeof(xaxislabel) !== 'undefined' ){\ |
7658 | schaersvoo | 8263 | ctx.fillStyle = \'#000000\';\ |
8264 | var txt_size = ctx.measureText(xaxislabel).width + 4 ;\ |
||
8265 | ctx.fillText(xaxislabel,xsize - txt_size, zero_y - 7);\ |
||
8266 | };\ |
||
11088 | schaersvoo | 8267 | if( typeof(yaxislabel) !== 'undefined'){\ |
7658 | schaersvoo | 8268 | ctx.save();\ |
8269 | ctx.fillStyle = \'#000000\';\ |
||
8270 | var txt_size = ctx.measureText(yaxislabel).width;\ |
||
8271 | ctx.translate(zero_x+8 + font_size,txt_size+font_size);\ |
||
8272 | ctx.rotate(-0.5*Math.PI);\ |
||
8273 | ctx.fillText(yaxislabel,0,0);\ |
||
7874 | schaersvoo | 8274 | ctx.restore();\ |
7658 | schaersvoo | 8275 | };\ |
7654 | schaersvoo | 8276 | };\n",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id); |
8277 | break; |
||
11890 | schaersvoo | 8278 | case DRAW_NUMBERLINE: |
13970 | obado | 8279 | fprintf(js_include_file,"\n/* draw numberline */\n\ |
11996 | schaersvoo | 8280 | var draw_numberline = function(canvas_type,use_axis_numbering,x0,x1,xmajor,xminor,y0,y1,linewidth,strokecolor,strokeopacity,fontfamily,fontcolor,precision){\ |
11890 | schaersvoo | 8281 | var obj = create_canvas%d(canvas_type,xsize,ysize);\ |
8282 | var ctx = obj.getContext(\"2d\");\ |
||
8283 | ctx.lineWidth = linewidth || 1;\ |
||
8284 | ctx.strokeStyle = \"rgba(\"+strokecolor+\",\"+strokeopacity+\")\";\ |
||
8285 | ctx.font = fontfamily || 'Ariel 12px';\ |
||
8286 | var fontsize = parseInt(ctx.font);\ |
||
8287 | ctx.fillStyle = \"rgba(\"+fontcolor+\",\"+strokeopacity+\")\";\ |
||
8288 | x1 = x2px(x1);\ |
||
8289 | x0 = x2px(x0);\ |
||
8290 | y0 = y2px(y0);\ |
||
8291 | y1 = y2px(y1);\ |
||
8292 | var sub_devision = -1;\ |
||
8293 | if( xminor%%2 == 0 ){ sub_devision = xminor/2; };\ |
||
11892 | schaersvoo | 8294 | var ybase1 = parseInt( y0 + fontsize + 2 );\ |
8295 | var ybase2 = parseInt( ybase1 + fontsize + 2 );\ |
||
11890 | schaersvoo | 8296 | var yh = Math.abs(parseInt( y0 - 0.3*(y0 -y1)));\ |
8297 | var ys = Math.abs(parseInt( y0 - 0.6*(y0 -y1)));\ |
||
8298 | xmajor = x2px(xmajor) - x2px(0);\ |
||
8299 | var i;var len;var p;\ |
||
8300 | xminor = xmajor / xminor;\ |
||
8301 | ctx.beginPath();\ |
||
8302 | for(p = x0 ; p < x1 ; p = p + xmajor){\ |
||
8303 | ctx.moveTo(p,y0);ctx.lineTo(p,y1);i = 0;\ |
||
8304 | for(var s = p ; s < p + xmajor ; s = s + xminor ){\ |
||
8305 | ctx.moveTo(s,y0);\ |
||
8306 | if( sub_devision == i){ ctx.lineTo(s,ys); } else { ctx.lineTo(s,yh); };\ |
||
8307 | i++;\ |
||
8308 | };\ |
||
8309 | };\ |
||
8310 | ctx.moveTo(p,y0);ctx.lineTo(p,y1);\ |
||
8311 | ctx.closePath();\ |
||
8312 | ctx.stroke();\ |
||
11996 | schaersvoo | 8313 | if( use_axis_numbering >-1 ){\ |
11891 | schaersvoo | 8314 | var str = x_strings[use_axis_numbering];\ |
8315 | len = str.length;if((len/2+0.5)%%2 == 0){ alert(\"xaxis number unpaired: text missing ! \");return;};\ |
||
11892 | schaersvoo | 8316 | var corr;var x_nums;var x_text;var flipflop = 0;var off = ybase1;\ |
11890 | schaersvoo | 8317 | ctx.beginPath();\ |
11891 | schaersvoo | 8318 | if( x_strings_up[use_axis_numbering] == null){\ |
11890 | schaersvoo | 8319 | for(var p = 0 ; p < len ; p = p+2){\ |
11891 | schaersvoo | 8320 | var x_nums = x2px(eval(str[p]));\ |
8321 | var x_text = str[p+1];\ |
||
11890 | schaersvoo | 8322 | corr = ctx.measureText(x_text).width;\ |
11892 | schaersvoo | 8323 | if( corr > xmajor){ if(flipflop == 0 ){flipflop = 1; off = ybase2;}else{flipflop = 0; off = ybase1;};};\ |
11996 | schaersvoo | 8324 | ctx.fillText(x_text,parseInt(x_nums-0.5*corr),off);\ |
11890 | schaersvoo | 8325 | };\ |
8326 | }\ |
||
8327 | else\ |
||
8328 | {\ |
||
8329 | for(var p = 0 ; p < len ; p = p+2){\ |
||
11891 | schaersvoo | 8330 | x_nums = x2px(eval(str[p]));\ |
8331 | x_text = str[p+1];\ |
||
11892 | schaersvoo | 8332 | corr = ctx.measureText(x_text).width + ybase1 - fontsize;\ |
11890 | schaersvoo | 8333 | ctx.save();\ |
8334 | ctx.translate(x_nums+0.5*fontsize, corr);\ |
||
8335 | ctx.rotate(-1.5708);\ |
||
8336 | ctx.fillText(x_text,0,0);\ |
||
8337 | ctx.restore();\ |
||
8338 | };\ |
||
8339 | }\ |
||
8340 | }\ |
||
8341 | else\ |
||
8342 | {\ |
||
11892 | schaersvoo | 8343 | var corr;var num;var flipflop = 0;var off = ybase1;\ |
8344 | var prec = parseInt(Math.log(precision)/Math.log(10));\ |
||
11890 | schaersvoo | 8345 | for(var p = x0 ; p < x1+xmajor ; p = p+xmajor){\ |
11892 | schaersvoo | 8346 | num = (px2x(p)).toFixed(prec);\ |
11996 | schaersvoo | 8347 | corr = ctx.measureText(num).width;\ |
11892 | schaersvoo | 8348 | if( corr > xmajor){ if(flipflop == 0 ){flipflop = 1; off = ybase2;}else{flipflop = 0; off = ybase1;};};\ |
11996 | schaersvoo | 8349 | ctx.fillText(num,parseInt(p - 0.5*corr),off);\ |
11890 | schaersvoo | 8350 | };\ |
8351 | };\ |
||
8352 | };",canvas_root_id); |
||
8353 | break; |
||
7614 | schaersvoo | 8354 | case DRAW_GRID:/* not used for userdraw */ |
13970 | obado | 8355 | fprintf(js_include_file,"\n/* draw grid */\n\ |
8105 | schaersvoo | 8356 | var draw_grid%d = function(canvas_type,precision,stroke_opacity,xmajor,ymajor,xminor,yminor,tics_length,line_width,stroke_color,axis_color,font_size,font_family,use_axis,use_axis_numbering,use_rotate,angle,use_affine,affine_matrix,use_dashed,dashtype0,dashtype1,font_color,fill_opacity){\ |
7988 | schaersvoo | 8357 | var obj;if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){obj = document.getElementById(\"wims_canvas%d\"+canvas_type);}else{obj = create_canvas%d(canvas_type,xsize,ysize);};\ |
8358 | var ctx = obj.getContext(\"2d\");ctx.clearRect(0,0,xsize,ysize);\ |
||
7614 | schaersvoo | 8359 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
8360 | ctx.save();\ |
||
8071 | schaersvoo | 8361 | if( use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);};\ |
7614 | schaersvoo | 8362 | if( use_rotate == 1 ){ctx.translate(x2px(0),y2px(0));ctx.rotate(angle*Math.PI/180);ctx.translate(-1*(x2px(0)),-1*(y2px(0)));};\ |
8363 | var stroke_color = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
8364 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+1.0+\")\";\ |
||
8365 | var axis_color = \"rgba(\"+axis_color+\",\"+stroke_opacity+\")\";\ |
||
8366 | ctx.font = font_family;\ |
||
7988 | schaersvoo | 8367 | var barcolor = new Array();\ |
7614 | schaersvoo | 8368 | var xstep = xsize*xmajor/(xmax - xmin);\ |
8369 | var ystep = ysize*ymajor/(ymax - ymin);\ |
||
8370 | var x2step = xstep / xminor;\ |
||
8371 | var y2step = ystep / yminor;\ |
||
7996 | schaersvoo | 8372 | var zero_x = x2px(0);;var zero_y = y2px(0);var f_x;var f_y;\ |
8373 | if(xmin < 0 ){ f_x = -1;}else{ f_x = 1;}\ |
||
8374 | if(ymin < 0 ){ f_y = -1;}else{ f_y = 1;}\ |
||
11088 | schaersvoo | 8375 | if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
7614 | schaersvoo | 8376 | ctx.beginPath();\ |
8377 | ctx.lineWidth = line_width;\ |
||
8378 | ctx.strokeStyle = stroke_color;\ |
||
8379 | for(var p = zero_x ; p < xsize; p = p + xstep){\ |
||
8380 | ctx.moveTo(p,0);\ |
||
8381 | ctx.lineTo(p,ysize);\ |
||
8382 | };\ |
||
8383 | for(var p = zero_x ; p > 0; p = p - xstep){\ |
||
8384 | ctx.moveTo(p,0);\ |
||
8385 | ctx.lineTo(p,ysize);\ |
||
8386 | };\ |
||
8387 | for(var p = zero_y ; p < ysize; p = p + ystep){\ |
||
8388 | ctx.moveTo(0,p);\ |
||
8389 | ctx.lineTo(xsize,p);\ |
||
8390 | };\ |
||
8391 | for(var p = zero_y ; p > 0; p = p - ystep){\ |
||
8392 | ctx.moveTo(0,p);\ |
||
8393 | ctx.lineTo(xsize,p);\ |
||
8394 | };\ |
||
11088 | schaersvoo | 8395 | if( typeof(xaxislabel) !== 'undefined' ){\ |
7614 | schaersvoo | 8396 | ctx.save();\ |
8397 | ctx.font = \"italic \"+font_size+\"px Ariel\";\ |
||
12007 | schaersvoo | 8398 | var corr = parseInt(1.1*ctx.measureText(xaxislabel).width);\ |
8399 | ctx.fillText(xaxislabel,xsize - corr,zero_y - tics_length - 0.4*font_size);\ |
||
7614 | schaersvoo | 8400 | ctx.restore();\ |
8401 | };\ |
||
11088 | schaersvoo | 8402 | if( typeof(yaxislabel) !== 'undefined' ){\ |
7614 | schaersvoo | 8403 | ctx.save();\ |
8404 | ctx.font = \"italic \"+font_size+\"px Ariel\";\ |
||
12007 | schaersvoo | 8405 | var corr = parseInt(ctx.measureText(yaxislabel).width + font_size);\ |
8406 | ctx.translate(zero_x+tics_length + font_size,corr);\ |
||
7614 | schaersvoo | 8407 | ctx.rotate(-0.5*Math.PI);\ |
8408 | ctx.fillText(yaxislabel,0,0);\ |
||
8409 | ctx.restore();\ |
||
8410 | };\ |
||
8411 | ctx.stroke();\ |
||
8412 | ctx.closePath();\ |
||
8413 | if( use_axis == 1 ){\ |
||
7988 | schaersvoo | 8414 | ctx.save();\ |
7614 | schaersvoo | 8415 | ctx.beginPath();\ |
8416 | ctx.strokeStyle = stroke_color;\ |
||
8417 | ctx.lineWidth = 0.6*line_width;\ |
||
8418 | for(var p = zero_x ; p < xsize; p = p + x2step){\ |
||
8419 | ctx.moveTo(p,0);\ |
||
8420 | ctx.lineTo(p,ysize);\ |
||
8421 | };\ |
||
8422 | for(var p = zero_x ; p > 0; p = p - x2step){\ |
||
8423 | ctx.moveTo(p,0);\ |
||
8424 | ctx.lineTo(p,ysize);\ |
||
8425 | };\ |
||
8426 | for(var p = zero_y ; p < ysize; p = p + y2step){\ |
||
8427 | ctx.moveTo(0,p);\ |
||
8428 | ctx.lineTo(xsize,p);\ |
||
8429 | };\ |
||
8430 | for(var p = zero_y ; p > 0; p = p - y2step){\ |
||
8431 | ctx.moveTo(0,p);\ |
||
8432 | ctx.lineTo(xsize,p);\ |
||
8433 | };\ |
||
8434 | ctx.stroke();\ |
||
8435 | ctx.closePath();\ |
||
8436 | ctx.beginPath();\ |
||
8437 | ctx.lineWidth = 2*line_width;\ |
||
8438 | ctx.strokeStyle = axis_color;\ |
||
8439 | ctx.moveTo(0,zero_y);\ |
||
8440 | ctx.lineTo(xsize,zero_y);\ |
||
8441 | ctx.moveTo(zero_x,0);\ |
||
8442 | ctx.lineTo(zero_x,ysize);\ |
||
8443 | ctx.stroke();\ |
||
8444 | ctx.closePath();\ |
||
8445 | ctx.lineWidth = line_width+0.5;\ |
||
8446 | ctx.beginPath();\ |
||
8447 | for(var p = zero_x ; p < xsize; p = p + xstep){\ |
||
8448 | ctx.moveTo(p,zero_y-tics_length);\ |
||
8449 | ctx.lineTo(p,zero_y+tics_length);\ |
||
8450 | };\ |
||
8451 | for(var p = zero_x ; p > 0; p = p - xstep){\ |
||
8452 | ctx.moveTo(p,zero_y-tics_length);\ |
||
8453 | ctx.lineTo(p,zero_y+tics_length);\ |
||
8454 | };\ |
||
8455 | for(var p = zero_y ; p < ysize; p = p + ystep){\ |
||
8456 | ctx.moveTo(zero_x-tics_length,p);\ |
||
8457 | ctx.lineTo(zero_x+tics_length,p);\ |
||
8458 | };\ |
||
8459 | for(var p = zero_y ; p > 0; p = p - ystep){\ |
||
8460 | ctx.moveTo(zero_x-tics_length,p);\ |
||
8461 | ctx.lineTo(zero_x+tics_length,p);\ |
||
8462 | };\ |
||
8463 | for(var p = zero_x ; p < xsize; p = p + x2step){\ |
||
8464 | ctx.moveTo(p,zero_y-0.5*tics_length);\ |
||
8465 | ctx.lineTo(p,zero_y+0.5*tics_length);\ |
||
8466 | };\ |
||
8467 | for(var p = zero_x ; p > 0; p = p - x2step){\ |
||
8468 | ctx.moveTo(p,zero_y-0.5*tics_length);\ |
||
8469 | ctx.lineTo(p,zero_y+0.5*tics_length);\ |
||
8470 | };\ |
||
8471 | for(var p = zero_y ; p < ysize; p = p + y2step){\ |
||
8472 | ctx.moveTo(zero_x-0.5*tics_length,p);\ |
||
8473 | ctx.lineTo(zero_x+0.5*tics_length,p);\ |
||
8474 | };\ |
||
8475 | for(var p = zero_y ; p > 0; p = p - y2step){\ |
||
8476 | ctx.moveTo(zero_x-0.5*tics_length,p);\ |
||
8477 | ctx.lineTo(zero_x+0.5*tics_length,p);\ |
||
8478 | };\ |
||
8479 | ctx.stroke();\ |
||
8480 | ctx.closePath();\ |
||
7988 | schaersvoo | 8481 | ctx.restore();\ |
8482 | };\ |
||
11891 | schaersvoo | 8483 | if( use_axis_numbering != -1 ){\ |
7988 | schaersvoo | 8484 | ctx.save();\ |
8485 | ctx.fillColor = axis_color;\ |
||
8110 | schaersvoo | 8486 | ctx.strokeStyle = axis_color;\ |
8487 | ctx.lineWidth = 2*line_width;\ |
||
7988 | schaersvoo | 8488 | ctx.font = font_family;\ |
8489 | var shift = zero_y+2*font_size;var flip=0;var skip=0;var corr;var cnt;var disp_cnt;var prec;\ |
||
11891 | schaersvoo | 8490 | if( x_strings[use_axis_numbering] != null ){\ |
8491 | var str = x_strings[use_axis_numbering];\ |
||
8492 | var len = str.length;if((len/2+0.5)%%2 == 0){ alert(\"xaxis number unpaired: text missing ! \");return;};\ |
||
8110 | schaersvoo | 8493 | ctx.beginPath();\ |
11891 | schaersvoo | 8494 | if( x_strings_up[use_axis_numbering] == null){\ |
9341 | schaersvoo | 8495 | for(var p = 0 ; p < len ; p = p+2){\ |
11891 | schaersvoo | 8496 | var x_nums = x2px(eval(str[p]));\ |
8497 | var x_text = str[p+1];\ |
||
9341 | schaersvoo | 8498 | corr = ctx.measureText(x_text).width;\ |
8499 | skip = 1.2*corr/xstep;\ |
||
8500 | if( zero_y+2*font_size > ysize ){shift = ysize - 2*font_size;};\ |
||
8501 | if( skip > 1 ){if(flip == 0 ){flip = 1; shift = shift + font_size;}else{flip = 0; shift = shift - font_size;}};\ |
||
8502 | ctx.fillText(x_text,parseInt(x_nums-0.5*corr),shift);\ |
||
8503 | ctx.moveTo(x_nums,zero_y - tics_length);\ |
||
8504 | ctx.lineTo(x_nums,zero_y + tics_length);\ |
||
8505 | };\ |
||
8506 | }\ |
||
8507 | else\ |
||
8508 | {\ |
||
8509 | for(var p = 0 ; p < len ; p = p+2){\ |
||
11891 | schaersvoo | 8510 | var x_nums = x2px(eval(str[p]));\ |
8511 | var x_text = str[p+1];\ |
||
9341 | schaersvoo | 8512 | corr = 2 + tics_length + zero_y + ctx.measureText(x_text).width;\ |
8513 | if( corr > ysize ){corr = ysize;};\ |
||
8514 | ctx.save();\ |
||
9346 | schaersvoo | 8515 | ctx.translate(x_nums+0.25*font_size, corr);\ |
9341 | schaersvoo | 8516 | ctx.rotate(-1.5708);\ |
8517 | ctx.fillText(x_text,0,0);\ |
||
8518 | ctx.restore();\ |
||
8519 | ctx.moveTo(x_nums,zero_y - tics_length);\ |
||
8520 | ctx.lineTo(x_nums,zero_y + tics_length);\ |
||
8521 | };\ |
||
7988 | schaersvoo | 8522 | };\ |
8110 | schaersvoo | 8523 | ctx.closePath();\ |
7988 | schaersvoo | 8524 | }\ |
8525 | else\ |
||
8526 | {\ |
||
8527 | skip = 1;cnt = px2x(zero_x);\ |
||
8528 | prec = Math.log(precision)/(Math.log(10));\ |
||
8529 | var y_basis;if(f_y == 1){ y_basis = ysize }else{ y_basis = zero_y + 1.4*font_size;};\ |
||
8530 | for( var p = zero_x ; p < xsize ; p = p+xstep){\ |
||
8531 | if(skip == 0 ){\ |
||
7990 | schaersvoo | 8532 | disp_cnt = cnt.toFixed(prec);\ |
7988 | schaersvoo | 8533 | corr = ctx.measureText(disp_cnt).width;\ |
8534 | skip = parseInt(1.2*corr/xstep);\ |
||
8535 | ctx.fillText(disp_cnt,p-0.5*corr,y_basis);\ |
||
7614 | schaersvoo | 8536 | }\ |
7988 | schaersvoo | 8537 | else\ |
8538 | {\ |
||
8539 | skip--;\ |
||
7614 | schaersvoo | 8540 | };\ |
7988 | schaersvoo | 8541 | cnt = cnt + xmajor;\ |
7614 | schaersvoo | 8542 | };\ |
7988 | schaersvoo | 8543 | cnt = px2x(zero_x);skip = 1;\ |
8544 | for( var p = zero_x ; p > 0 ; p = p-xstep){\ |
||
8545 | if(skip == 0 ){\ |
||
7990 | schaersvoo | 8546 | disp_cnt = cnt.toFixed(prec);\ |
7988 | schaersvoo | 8547 | corr = ctx.measureText(disp_cnt).width;\ |
8548 | skip = parseInt(1.2*corr/xstep);\ |
||
8549 | ctx.fillText(disp_cnt,p-0.5*corr,y_basis);\ |
||
8550 | }\ |
||
8551 | else\ |
||
8552 | {\ |
||
8553 | skip--;\ |
||
7614 | schaersvoo | 8554 | };\ |
7988 | schaersvoo | 8555 | cnt = cnt - xmajor;\ |
7614 | schaersvoo | 8556 | };\ |
8557 | };\ |
||
7988 | schaersvoo | 8558 | if( y_strings != null ){\ |
8559 | var len = y_strings.length;if((len/2+0.5)%%2 == 0){ alert(\"yaxis number unpaired: text missing ! \");return;};\ |
||
8110 | schaersvoo | 8560 | ctx.beginPath();\ |
7988 | schaersvoo | 8561 | for(var p = 0 ; p < len ; p = p+2){\ |
8562 | var y_nums = y2px(eval(y_strings[p]));\ |
||
8563 | var y_text = y_strings[p+1];\ |
||
8564 | corr = 2 + tics_length + ctx.measureText(y_text).width;\ |
||
8565 | if( corr > zero_x){corr = parseInt(zero_x+2); }\ |
||
8110 | schaersvoo | 8566 | ctx.fillText(y_text,zero_x - corr,y_nums + 0.5*font_size);\ |
8567 | ctx.moveTo(zero_x - tics_length,y_nums);\ |
||
8568 | ctx.lineTo(zero_x + tics_length,y_nums);\ |
||
7614 | schaersvoo | 8569 | };\ |
8110 | schaersvoo | 8570 | ctx.closePath();\ |
7988 | schaersvoo | 8571 | }\ |
8572 | else\ |
||
8573 | {\ |
||
7991 | schaersvoo | 8574 | if(f_x == 1){ corr = 1.5*tics_length; }\ |
7988 | schaersvoo | 8575 | cnt = px2y(zero_y);skip = 1;\ |
8576 | for( var p = zero_y ; p < ysize ; p = p+ystep){\ |
||
8577 | if(skip == 0 ){\ |
||
8578 | skip = parseInt(1.4*font_size/ystep);\ |
||
7990 | schaersvoo | 8579 | disp_cnt = cnt.toFixed(prec);\ |
7988 | schaersvoo | 8580 | if(f_x == -1 ){ corr = parseInt(zero_x - (2 + tics_length + ctx.measureText(disp_cnt).width));};\ |
8581 | ctx.fillText(disp_cnt,parseInt(corr),parseInt(p+(0.4*font_size)));\ |
||
8582 | }\ |
||
8583 | else\ |
||
8584 | {\ |
||
8585 | skip--;\ |
||
8586 | };\ |
||
8587 | cnt = cnt - ymajor;\ |
||
7614 | schaersvoo | 8588 | };\ |
7988 | schaersvoo | 8589 | corr = 0;cnt = px2y(zero_y);skip = 1;\ |
7991 | schaersvoo | 8590 | if(f_x == 1){ corr = 1.5*tics_length; }\ |
7988 | schaersvoo | 8591 | for( var p = zero_y ; p > 0 ; p = p-ystep){\ |
8592 | if(skip == 0 ){\ |
||
8593 | skip = parseInt(1.4*font_size/ystep);\ |
||
7990 | schaersvoo | 8594 | disp_cnt = cnt.toFixed(prec);\ |
7988 | schaersvoo | 8595 | if(f_x == -1 ){corr = parseInt(zero_x - (2 + tics_length + ctx.measureText(disp_cnt).width));};\ |
8596 | ctx.fillText(disp_cnt,parseInt(corr),parseInt(p+(0.4*font_size)));\ |
||
8597 | }\ |
||
8598 | else\ |
||
8599 | {\ |
||
8600 | skip--;\ |
||
8601 | };\ |
||
8602 | cnt = cnt + ymajor;\ |
||
7614 | schaersvoo | 8603 | };\ |
8604 | };\ |
||
7988 | schaersvoo | 8605 | ctx.stroke();\ |
7614 | schaersvoo | 8606 | ctx.restore();\ |
8607 | };\ |
||
11088 | schaersvoo | 8608 | if( typeof(legend0) !== 'undefined' ){\ |
7988 | schaersvoo | 8609 | ctx.save();\ |
7614 | schaersvoo | 8610 | ctx.globalAlpha = 1.0;\ |
8611 | ctx.font = \"bold \"+font_size+\"px Ariel\";\ |
||
8612 | var y_offset = 2*font_size;\ |
||
8613 | var txt;var txt_size;\ |
||
8614 | var x_offset = xsize - 2*font_size;\ |
||
7956 | schaersvoo | 8615 | var l_length = legend0.length;\ |
11088 | schaersvoo | 8616 | if( typeof(legendcolors0) !== 'undefined' ){\ |
7614 | schaersvoo | 8617 | for(var p = 0 ; p < l_length ; p++){\ |
7956 | schaersvoo | 8618 | barcolor[p] = legendcolors0[p];\ |
7614 | schaersvoo | 8619 | };\ |
7988 | schaersvoo | 8620 | }\ |
8621 | else\ |
||
8622 | {\ |
||
7614 | schaersvoo | 8623 | if( barcolor.length == 0 ){\ |
8624 | for(var p = 0 ; p < l_length ; p++){\ |
||
8625 | barcolor[p] = stroke_color;\ |
||
8626 | };\ |
||
8627 | };\ |
||
8628 | };\ |
||
8629 | for(var p = 0; p < l_length; p++){\ |
||
8630 | ctx.fillStyle = barcolor[p];\ |
||
7956 | schaersvoo | 8631 | txt = legend0[p];\ |
7614 | schaersvoo | 8632 | txt_size = ctx.measureText(txt).width;\ |
7956 | schaersvoo | 8633 | ctx.fillText(legend0[p],x_offset - txt_size, y_offset);\ |
7614 | schaersvoo | 8634 | y_offset = parseInt(y_offset + 1.5*font_size);\ |
8635 | };\ |
||
7988 | schaersvoo | 8636 | ctx.restore();\ |
7614 | schaersvoo | 8637 | };\ |
11088 | schaersvoo | 8638 | if( typeof(barchart_0) !== 'undefined' ){\ |
7991 | schaersvoo | 8639 | ctx.save();\ |
8640 | var num_barcharts = 0;\ |
||
8641 | var bar_name = eval('barchart_0');\ |
||
11088 | schaersvoo | 8642 | while( typeof(bar_name) !== 'undefined' ){\ |
7991 | schaersvoo | 8643 | try{ bar_name = eval('barchart_'+num_barcharts);num_barcharts++;}catch(e){break;};\ |
8644 | };\ |
||
9346 | schaersvoo | 8645 | var bar_width = parseInt(0.8*x2step/(num_barcharts));\ |
7991 | schaersvoo | 8646 | for(var i=0 ; i< num_barcharts ; i++){\ |
8647 | bar_name = eval('barchart_'+i);\ |
||
8648 | var bar_x = new Array();\ |
||
8649 | var bar_y = new Array();\ |
||
8650 | var lb = bar_name.length;\ |
||
8651 | var idx = 0;\ |
||
8652 | var dx = parseInt(0.5*i*bar_width);\ |
||
8653 | for( var p = 0 ; p < lb ; p = p + 3 ){\ |
||
8654 | bar_x[idx] = x2px(bar_name[p]);\ |
||
8655 | bar_y[idx] = y2px(bar_name[p+1]);\ |
||
8656 | barcolor[idx] = bar_name[p+2];\ |
||
8657 | idx++;\ |
||
8658 | };\ |
||
8659 | ctx.globalAlpha = fill_opacity;\ |
||
8660 | for( var p = 0; p < idx ; p++ ){\ |
||
11739 | schaersvoo | 8661 | ctx.beginPath();\ |
7991 | schaersvoo | 8662 | ctx.strokeStyle = barcolor[p];\ |
8663 | ctx.fillStyle = barcolor[p];\ |
||
9346 | schaersvoo | 8664 | ctx.rect(bar_x[p]-0.4*x2step+dx,bar_y[p],bar_width,zero_y - bar_y[p]);\ |
11739 | schaersvoo | 8665 | ctx.fill();\ |
8666 | ctx.stroke();\ |
||
8667 | ctx.closePath();\ |
||
7991 | schaersvoo | 8668 | };\ |
8669 | };\ |
||
8670 | ctx.restore();\ |
||
8671 | };\ |
||
11088 | schaersvoo | 8672 | if( typeof(linegraph_0) !== 'undefined' ){\ |
7996 | schaersvoo | 8673 | ctx.save();\ |
8674 | ctx.globalAlpha = 1.0;\ |
||
8675 | var i = 0;\ |
||
8676 | var line_name = eval('linegraph_'+i);\ |
||
11088 | schaersvoo | 8677 | while ( typeof(line_name) !== 'undefined' ){\ |
7996 | schaersvoo | 8678 | ctx.strokeStyle = 'rgba('+line_name[0]+','+stroke_opacity+')';\ |
8679 | ctx.lineWidth = parseInt(line_name[1]);\ |
||
8680 | if(line_name[2] == \"1\"){\ |
||
8681 | var d1 = parseInt(line_name[3]);\ |
||
8682 | var d2 = parseInt(line_name[4]);\ |
||
8683 | if(ctx.setLineDash){ ctx.setLineDash([d1,d2]); } else { ctx.mozDash = [d1,d2];};\ |
||
8684 | }\ |
||
8685 | else\ |
||
8686 | {\ |
||
8687 | if(ctx.setLineDash){ctx.setLineDash = null;}\ |
||
8688 | if(ctx.mozDash){ctx.mozDash = null;}\ |
||
8689 | };\ |
||
8690 | var data_x = new Array();\ |
||
8691 | var data_y = new Array();\ |
||
8692 | var lb = line_name.length;\ |
||
8693 | var idx = 0;\ |
||
8694 | for( var p = 5 ; p < lb ; p = p + 2 ){\ |
||
8695 | data_x[idx] = x2px(line_name[p]);\ |
||
8696 | data_y[idx] = y2px(line_name[p+1]);\ |
||
8697 | idx++;\ |
||
8698 | };\ |
||
8699 | for( var p = 0; p < idx ; p++){\ |
||
8700 | ctx.beginPath();\ |
||
8701 | ctx.moveTo(data_x[p],data_y[p]);\ |
||
8702 | ctx.lineTo(data_x[p+1],data_y[p+1]);\ |
||
8703 | ctx.stroke();\ |
||
8704 | ctx.closePath();\ |
||
8705 | };\ |
||
8706 | i++;\ |
||
8707 | try{ line_name = eval('linegraph_'+i); }catch(e){ break; }\ |
||
8708 | };\ |
||
8709 | ctx.restore();\ |
||
8710 | };\ |
||
7614 | schaersvoo | 8711 | return;\ |
7989 | schaersvoo | 8712 | };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 8713 | break; |
8224 | bpr | 8714 | |
7614 | schaersvoo | 8715 | case DRAW_PIECHART: |
13970 | obado | 8716 | fprintf(js_include_file,"\n/* draw piecharts */\n\ |
11875 | schaersvoo | 8717 | if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\ |
12538 | schaersvoo | 8718 | function draw_piechart(canvas_type,x_center,y_center,radius, data_color_list,fill_opacity,legend_cnt,font_family,use_filled,use_offset){\ |
7614 | schaersvoo | 8719 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
8720 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
8721 | }\ |
||
8722 | else\ |
||
8723 | {\ |
||
8724 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
8725 | };\ |
||
12538 | schaersvoo | 8726 | var center_text = use_offset || 0;\ |
7614 | schaersvoo | 8727 | var ld = data_color_list.length;\ |
8728 | var sum = 0;\ |
||
8729 | var idx = 0;\ |
||
7956 | schaersvoo | 8730 | var font_size = parseInt(font_family.replace(/[^0-9\\.]+/g, \"\"));\ |
7614 | schaersvoo | 8731 | var colors = new Array();\ |
8732 | var data = new Array();\ |
||
8733 | for(var p = 0;p < ld; p = p + 2){\ |
||
8734 | data[idx] = parseFloat(data_color_list[p]);\ |
||
8735 | sum = sum + data[idx];\ |
||
8736 | colors[idx] = data_color_list[p+1];\ |
||
8737 | idx++;\ |
||
8738 | };\ |
||
11875 | schaersvoo | 8739 | if( use_filled > 1 ){\ |
8740 | var i = 2;\ |
||
8741 | for(var p = 0 ; p < idx ; p++){\ |
||
8742 | if(i > 5 ){ i = 2; };\ |
||
8743 | var pat = create_Pattern(0,0,i,colors[p]); all_fill_patterns[p] = pat;i++;\ |
||
8744 | };\ |
||
8745 | };\ |
||
7614 | schaersvoo | 8746 | var ctx = obj.getContext(\"2d\");\ |
8747 | ctx.save();\ |
||
8748 | var angle;\ |
||
8749 | var angle_end = 0;\ |
||
8750 | var offset = Math.PI / 2;\ |
||
8751 | ctx.globalAlpha = fill_opacity;\ |
||
12538 | schaersvoo | 8752 | var angles = [];\ |
7614 | schaersvoo | 8753 | for(var p=0; p < idx; p++){\ |
8754 | ctx.beginPath();\ |
||
8755 | ctx.moveTo(x_center,y_center);\ |
||
8756 | angle = Math.PI * (2 * data[p] / sum);\ |
||
8757 | ctx.arc(x_center,y_center, radius, angle_end - offset, angle_end + angle - offset, false);\ |
||
8758 | ctx.lineTo(x_center, y_center);\ |
||
11875 | schaersvoo | 8759 | if( use_filled > 1 ){ ctx.fillStyle = all_fill_patterns[p]; }else{ ctx.fillStyle = colors[p];};\ |
7614 | schaersvoo | 8760 | ctx.fill();\ |
8761 | ctx.closePath();\ |
||
12538 | schaersvoo | 8762 | angles.push(angle_end + angle - offset);\ |
7614 | schaersvoo | 8763 | angle_end = angle_end + angle;\ |
8764 | };\ |
||
11088 | schaersvoo | 8765 | if(typeof(legend0) !== 'undefined'){\ |
7956 | schaersvoo | 8766 | var legenda = eval(\"legend\"+legend_cnt);\ |
7614 | schaersvoo | 8767 | ctx.globalAlpha = 1.0;\ |
7956 | schaersvoo | 8768 | ctx.font = font_family;\ |
12538 | schaersvoo | 8769 | var y_offset = font_size;\ |
7614 | schaersvoo | 8770 | var x_offset = 0;\ |
8771 | var txt;var txt_size;\ |
||
8772 | for(var p = 0; p < idx; p++){\ |
||
8773 | ctx.fillStyle = colors[p];\ |
||
7956 | schaersvoo | 8774 | txt = legenda[p];\ |
12538 | schaersvoo | 8775 | txt_size = ctx.measureText(txt).width + 2;\ |
8776 | if(center_text == 4){\ |
||
8777 | ctx.save();\ |
||
8778 | ctx.translate(x_center, y_center);\ |
||
8779 | ctx.rotate(angles[p]);\ |
||
8780 | ctx.fillText(txt,radius-txt_size,0);\ |
||
8781 | ctx.restore();\ |
||
8782 | }\ |
||
8783 | else\ |
||
8784 | {\ |
||
8785 | if( x_center + radius + txt_size > xsize ){ x_offset = x_center + radius + txt_size - xsize;} else { x_offset = 0; };\ |
||
8786 | ctx.fillText(txt,x_center + radius - x_offset, y_center - radius + y_offset);\ |
||
8787 | y_offset = parseInt(y_offset + 1.5*font_size);\ |
||
8788 | };\ |
||
7614 | schaersvoo | 8789 | };\ |
8790 | };\ |
||
8791 | ctx.restore();\ |
||
7956 | schaersvoo | 8792 | };",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 8793 | break; |
9433 | schaersvoo | 8794 | case DRAW_JSBOXPLOT: |
13970 | obado | 8795 | fprintf(js_include_file,"\n/* draw jsboxplots */\n\ |
11874 | schaersvoo | 8796 | if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\ |
9433 | schaersvoo | 8797 | function statistics(data){\ |
8798 | var len = data.length;\ |
||
8799 | var min = 10000000;\ |
||
8800 | var max = -10000000;\ |
||
8801 | var sum = 0;var d;\ |
||
8802 | for(var i=0;i<len;i++){\ |
||
8803 | d = data[i];\ |
||
8804 | if(d < min){min = d;}else{if(d > max){max = d;};};\ |
||
8805 | sum+= parseFloat(data[i]);\ |
||
8806 | };\ |
||
8807 | var mean = parseFloat(sum/len);\ |
||
8808 | var variance = 0;\ |
||
8809 | for(var i=0;i<len;i++){\ |
||
8810 | d = data[i];\ |
||
8811 | variance += (d - mean)*(d - mean);\ |
||
8812 | };\ |
||
8813 | variance = parseFloat(variance / len);\ |
||
8814 | var std = Math.sqrt(variance);\ |
||
8815 | data.sort(function(a,b){return a - b;});\ |
||
8816 | var median;var Q1;var Q3;\ |
||
8817 | var half = Math.floor(0.5*len);\ |
||
8818 | var q1 = Math.floor(0.25*len);\ |
||
8819 | var q3 = Math.floor(0.75*len);\ |
||
8820 | var half = Math.floor(0.5*len);\ |
||
8821 | if(len %%2 == 1){\ |
||
8822 | median = data[half];\ |
||
8823 | Q1 = data[q1];\ |
||
8824 | Q3 = data[q3];\ |
||
8825 | }\ |
||
8826 | else\ |
||
8827 | {\ |
||
8828 | median = (data[half - 1] + data[half] )/2;\ |
||
8829 | Q1 = (data[q1 - 1] + data[q1] )/2;\ |
||
8830 | Q3 = (data[q3 - 1] + data[q3] )/2;\ |
||
8831 | };\ |
||
8832 | return [min,Q1,median,Q3,max];\ |
||
8833 | };"); |
||
8834 | break; |
||
8835 | case DRAW_BOXPLOT: |
||
13970 | obado | 8836 | fprintf(js_include_file,"\n/* draw boxplots */\n\ |
11874 | schaersvoo | 8837 | if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\ |
9465 | schaersvoo | 8838 | 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){\ |
14044 | schaersvoo | 8839 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){obj = document.getElementById(\"wims_canvas%d\"+canvas_type);}else{obj = create_canvas%d(canvas_type,xsize,ysize);};\ |
9433 | schaersvoo | 8840 | var ctx = obj.getContext(\"2d\");\ |
8841 | ctx.clearRect(0,0,xsize,ysize);\ |
||
8842 | ctx.save();\ |
||
8843 | ctx.lineWidth = line_width;\ |
||
11088 | schaersvoo | 8844 | if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
9433 | schaersvoo | 8845 | ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
11875 | schaersvoo | 8846 | var colors = new Array(2);\ |
8847 | colors[0] = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\ |
||
8848 | colors[1] = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
8849 | if( use_filled > 1 ){\ |
||
8850 | var pat = create_Pattern(0,0,3,colors[0]);\ |
||
8851 | all_fill_patterns[0] = pat;\ |
||
8852 | pat = create_Pattern(0,0,4,colors[1]);\ |
||
8853 | all_fill_patterns[1] = pat;\ |
||
8854 | };\ |
||
9433 | schaersvoo | 8855 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{if(ctx.mozDash){ ctx.mozDash = [dashtype0,dashtype1];};};};\ |
8856 | var hh = 0.25*hw;\ |
||
9465 | schaersvoo | 8857 | switch(boxplot_source){\ |
11088 | schaersvoo | 8858 | case 1: if( typeof(jsboxplot_data) === 'undefined'){return;};data = statistics(jsboxplot_data);break;\ |
8859 | case 2: if( typeof(student_boxplot_data) === 'undefined'){return;};data = statistics(student_boxplot_data);break;\ |
||
8860 | case 3: if( typeof(student_boxplot) === 'undefined'){return;};data = student_boxplot;break;\ |
||
9465 | schaersvoo | 8861 | default: break;\ |
9433 | schaersvoo | 8862 | };\ |
8863 | var min,Q1,median,Q3,max;\ |
||
8864 | if(xy == 1 ){\ |
||
8865 | min=x2px(data[0]);Q1=x2px(data[1]);median=x2px(data[2]);Q3=x2px(data[3]);max=x2px(data[4]);\ |
||
8866 | hh = Math.abs(y2px(hh) - y2px(ystart));\ |
||
8867 | hw = Math.abs(y2px(hw) - y2px(ystart));\ |
||
8868 | cxy = y2px(cxy);\ |
||
9465 | schaersvoo | 8869 | ctx.beginPath();\ |
9433 | schaersvoo | 8870 | ctx.moveTo(min,cxy);\ |
8871 | ctx.lineTo(Q1,cxy);\ |
||
8872 | ctx.moveTo(Q3,cxy);\ |
||
8873 | ctx.lineTo(max,cxy);\ |
||
8874 | ctx.moveTo(min,cxy+hh);\ |
||
8875 | ctx.lineTo(min,cxy-hh);\ |
||
8876 | ctx.moveTo(max,cxy+hh);\ |
||
8877 | ctx.lineTo(max,cxy-hh);\ |
||
9465 | schaersvoo | 8878 | ctx.closePath();\ |
8879 | ctx.stroke();\ |
||
8880 | ctx.beginPath();\ |
||
9433 | schaersvoo | 8881 | ctx.rect(Q1,cxy-2*hh,median-Q1,hw);\ |
9465 | schaersvoo | 8882 | ctx.closePath();\ |
11839 | schaersvoo | 8883 | if( use_filled != 0 ){\ |
12024 | schaersvoo | 8884 | if( use_filled == 1 ) {ctx.fillStyle = colors[0]; }else{ ctx.fillStyle = all_fill_patterns[0] };\ |
9465 | schaersvoo | 8885 | ctx.fill();\ |
8886 | };\ |
||
8887 | ctx.stroke();\ |
||
8888 | ctx.beginPath();\ |
||
9433 | schaersvoo | 8889 | ctx.rect(median,cxy-2*hh,Q3-median,hw);\ |
9465 | schaersvoo | 8890 | ctx.closePath();\ |
11839 | schaersvoo | 8891 | if( use_filled != 0 ){\ |
12075 | schaersvoo | 8892 | if( use_filled == 1 ) {ctx.fillStyle = colors[1]; }else{ ctx.fillStyle = all_fill_patterns[1] };\ |
9465 | schaersvoo | 8893 | ctx.fill();\ |
8894 | };\ |
||
8895 | ctx.stroke();\ |
||
9433 | schaersvoo | 8896 | }else{\ |
8897 | min=y2px(data[0]);Q1=y2px(data[1]);median=y2px(data[2]);Q3=y2px(data[3]);max=y2px(data[4]);\ |
||
8898 | hh = Math.abs(x2px(hh) - x2px(xstart));\ |
||
8899 | hw = Math.abs(x2px(hw) - x2px(xstart));\ |
||
8900 | cxy = x2px(cxy);\ |
||
9465 | schaersvoo | 8901 | ctx.beginPath();\ |
9433 | schaersvoo | 8902 | ctx.moveTo(cxy,min);\ |
8903 | ctx.lineTo(cxy,Q1);\ |
||
8904 | ctx.moveTo(cxy,Q3);\ |
||
8905 | ctx.lineTo(cxy,max);\ |
||
8906 | ctx.moveTo(cxy + hh,min);\ |
||
8907 | ctx.lineTo(cxy - hh,min);\ |
||
8908 | ctx.moveTo(cxy + hh,max);\ |
||
8909 | ctx.lineTo(cxy - hh,max);\ |
||
9465 | schaersvoo | 8910 | ctx.closePath;\ |
8911 | ctx.stroke();\ |
||
8912 | ctx.beginPath();\ |
||
9433 | schaersvoo | 8913 | ctx.rect(cxy - 2*hh,Q1,hw,median - Q1);\ |
9465 | schaersvoo | 8914 | ctx.closePath();\ |
11839 | schaersvoo | 8915 | if( use_filled != 0 ){\ |
12075 | schaersvoo | 8916 | if( use_filled == 1 ) {ctx.fillStyle = colors[0]; }else{ ctx.fillStyle = all_fill_patterns[0] };\ |
9465 | schaersvoo | 8917 | ctx.fill();\ |
8918 | };\ |
||
8919 | ctx.stroke();\ |
||
8920 | ctx.beginPath();\ |
||
9433 | schaersvoo | 8921 | ctx.rect(cxy - 2*hh,median,hw,Q3 - median);\ |
9465 | schaersvoo | 8922 | ctx.closePath();\ |
11839 | schaersvoo | 8923 | if( use_filled != 0 ){\ |
12075 | schaersvoo | 8924 | if( use_filled == 1 ) {ctx.fillStyle = colors[1]; }else{ ctx.fillStyle = all_fill_patterns[1] };\ |
9465 | schaersvoo | 8925 | ctx.fill();\ |
8926 | };\ |
||
8927 | ctx.stroke();\ |
||
9433 | schaersvoo | 8928 | };\ |
8929 | ctx.restore();};",canvas_root_id,canvas_root_id,canvas_root_id); |
||
8930 | break; |
||
7614 | schaersvoo | 8931 | case DRAW_ARCS: |
13970 | obado | 8932 | fprintf(js_include_file,"\n/* draw arcs */\n\ |
11874 | schaersvoo | 8933 | if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\ |
8105 | schaersvoo | 8934 | var draw_arc = function(ctx,xc,yc,r,start,end,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_affine,affine_matrix){\ |
7614 | schaersvoo | 8935 | ctx.save();\ |
8936 | if( use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{if(ctx.mozDash){ ctx.mozDash = [dashtype0,dashtype1];};};};\ |
||
8071 | schaersvoo | 8937 | if( use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);};\ |
7614 | schaersvoo | 8938 | if( use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);};\ |
8939 | if(end < start){var tmp = end;end = start;start=tmp;};\ |
||
8071 | schaersvoo | 8940 | start = 360 - start;\ |
8941 | end = 360 - end;\ |
||
7614 | schaersvoo | 8942 | ctx.lineWidth = line_width;\ |
11088 | schaersvoo | 8943 | if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
7614 | schaersvoo | 8944 | ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
11874 | schaersvoo | 8945 | var color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\ |
11875 | schaersvoo | 8946 | if(use_filled > 1 ){ if(! all_fill_patterns[use_filled] ){ var pat = create_Pattern(0,0,use_filled,color); all_fill_patterns[use_filled] = pat;};ctx.fillStyle = all_fill_patterns[use_filled]; } else { ctx.fillStyle = color;};\ |
8071 | schaersvoo | 8947 | ctx.beginPath();\ |
8948 | ctx.moveTo(xc,yc);\ |
||
8949 | ctx.arc(xc, yc, r, start*(Math.PI / 180), end*(Math.PI / 180),true);\ |
||
8950 | ctx.lineTo(xc,yc);\ |
||
8951 | ctx.closePath();\ |
||
11875 | schaersvoo | 8952 | if( use_filled != 0 ){ctx.fill();};\ |
8071 | schaersvoo | 8953 | ctx.stroke();\ |
7614 | schaersvoo | 8954 | ctx.restore();\ |
8071 | schaersvoo | 8955 | };"); |
8224 | bpr | 8956 | |
7614 | schaersvoo | 8957 | break; |
7983 | schaersvoo | 8958 | case DRAW_CENTERSTRING: |
13970 | obado | 8959 | fprintf(js_include_file,"\n/* draw centerstring */\n\ |
8105 | schaersvoo | 8960 | var draw_centerstring = function(canvas_type,y,font_family,stroke_color,stroke_opacity,text){\ |
7983 | schaersvoo | 8961 | var obj;\ |
8962 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
8963 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
8964 | }\ |
||
8965 | else\ |
||
8966 | {\ |
||
8967 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
8968 | };\ |
||
8969 | var ctx = obj.getContext(\"2d\");\ |
||
8970 | ctx.save();\ |
||
9481 | schaersvoo | 8971 | ctx.clearRect(0,0,xsize,ysize);\ |
7983 | schaersvoo | 8972 | ctx.font = font_family;\ |
8973 | ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
8974 | var stringwidth = ctx.measureText(text).width;\ |
||
8975 | var x = parseInt((xsize - stringwidth)/2);if( x < 0 ){x = 0;};\ |
||
8976 | ctx.fillText(text,x,y2px(y));\ |
||
9481 | schaersvoo | 8977 | ctx.restore();\ |
7983 | schaersvoo | 8978 | return;\ |
8979 | };",canvas_root_id,canvas_root_id,canvas_root_id); |
||
8980 | break; |
||
7614 | schaersvoo | 8981 | case DRAW_TEXTS: |
13970 | obado | 8982 | fprintf(js_include_file,"\n/* draw text */\n\ |
11811 | schaersvoo | 8983 | var draw_text = function(canvas_type,x,y,font_size,font_family,stroke_color,stroke_opacity,angle2,text,use_rotate,angle,use_affine,affine_matrix,use_offset){\ |
12000 | schaersvoo | 8984 | var obj;\ |
8985 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
8986 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
8987 | }\ |
||
8988 | else\ |
||
8989 | {\ |
||
8990 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
8991 | };\ |
||
8992 | var ctx = obj.getContext(\"2d\");\ |
||
8993 | if( font_family != 'null' ){\ |
||
8994 | ctx.font = font_family;\ |
||
8995 | }\ |
||
8996 | else\ |
||
8997 | {\ |
||
8998 | ctx.font = font_size+'px Ariel';\ |
||
8999 | };\ |
||
9000 | if( use_offset == 3 ){if(angle2 < 0 ){ y = y + 0.8*font_size; x = x + (Math.cos(angle2))*font_size; }else{y = y - 0.8*font_size; x = x + (Math.sin(angle2))*font_size;};};\ |
||
9001 | if(angle2 == 0 && angle != 0){\ |
||
9002 | ctx.save();\ |
||
9003 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
||
9004 | if(use_rotate == 1 ){\ |
||
9005 | ctx.rotate(angle*Math.PI/180);};\ |
||
9006 | ctx.restore();\ |
||
9007 | };\ |
||
9008 | ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
9009 | if(angle2 != 0){\ |
||
9010 | ctx.save();\ |
||
9011 | ctx.translate(x,y);\ |
||
9012 | ctx.rotate((360-angle2)*(Math.PI / 180));\ |
||
9013 | ctx.fillText(text,0,0);\ |
||
9014 | ctx.restore();\ |
||
9015 | }\ |
||
9016 | else\ |
||
9017 | {\ |
||
9018 | ctx.fillText(text,x,y);\ |
||
9019 | };\ |
||
7614 | schaersvoo | 9020 | return;\ |
12000 | schaersvoo | 9021 | };",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 9022 | break; |
9023 | case DRAW_CURVE: |
||
13970 | obado | 9024 | fprintf(js_include_file,"\n/* draw curve */\n\ |
8105 | schaersvoo | 9025 | var draw_curve = function(canvas_type,type,x_points,y_points,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,use_rotate,angle,use_affine,affine_matrix){\ |
7614 | schaersvoo | 9026 | var obj;\ |
9027 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
9028 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
9029 | }\ |
||
9030 | else\ |
||
9031 | {\ |
||
9032 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
9033 | };\ |
||
9034 | var ctx = obj.getContext(\"2d\");\ |
||
9035 | ctx.save();\ |
||
8071 | schaersvoo | 9036 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 9037 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
9038 | ctx.beginPath();ctx.lineWidth = line_width;\ |
||
11088 | schaersvoo | 9039 | if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\ |
7614 | schaersvoo | 9040 | if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\ |
9041 | ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
||
9042 | ctx.moveTo(x2px(x_points[0]),y2px(y_points[0]));\ |
||
9043 | for(var p = 1 ; p < x_points.length ; p++){\ |
||
9044 | if( y2px(y_points[p]) > -5 && y2px(y_points[p]) < ysize+5 ){\ |
||
9045 | ctx.lineTo(x2px(x_points[p]),y2px(y_points[p]));\ |
||
9046 | }\ |
||
9047 | else\ |
||
9048 | {\ |
||
9049 | ctx.stroke();\ |
||
9050 | ctx.beginPath();\ |
||
9051 | p++;\ |
||
9052 | ctx.moveTo(x2px(x_points[p]),y2px(y_points[p]));\ |
||
9053 | };\ |
||
9054 | };\ |
||
9055 | ctx.stroke();\ |
||
9056 | ctx.restore();\ |
||
7653 | schaersvoo | 9057 | };",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 9058 | break; |
8224 | bpr | 9059 | |
7614 | schaersvoo | 9060 | case DRAW_INPUTS: |
13970 | obado | 9061 | fprintf(js_include_file,"\n/* draw input fields */\n\ |
11803 | schaersvoo | 9062 | var draw_inputs = function(root_id,input_cnt,x,y,size,readonly,style,value,use_offset){\ |
7614 | schaersvoo | 9063 | var canvas_div = document.getElementById(\"canvas_div\"+root_id);\ |
9064 | var input = document.createElement(\"input\");\ |
||
9065 | input.setAttribute(\"id\",\"canvas_input\"+input_cnt);\ |
||
9066 | input.setAttribute(\"style\",\"position:absolute;left:\"+x+\"px;top:\"+y+\"px;\"+style);\ |
||
9067 | input.setAttribute(\"size\",size);\ |
||
9068 | input.setAttribute(\"value\",value);\ |
||
7877 | schaersvoo | 9069 | if( readonly == 0 || wims_status == \"done\" ){ input.setAttribute(\"readonly\",\"readonly\");if( wims_status == \"done\" ){input.setAttribute(\"value\",\"\");};};\ |
11803 | schaersvoo | 9070 | canvas_div.appendChild(input);\ |
9071 | if(use_offset != 0 ){ center_input('canvas_input'+input_cnt,x,y,style);};\ |
||
9072 | };\ |
||
9073 | function center_input(id,x,y,style){\ |
||
9074 | var inp = document.getElementById(id);\ |
||
9075 | var pos = inp.getBoundingClientRect();\ |
||
9076 | var center_x = parseInt(x - 0.5*(pos.width));\ |
||
9077 | var center_y = parseInt(y - 0.5*(pos.height));\ |
||
9078 | try{ inp.setAttribute(\"style\",\"position:absolute;left:\"+center_x+\"px;top:\"+center_y+\"px;\"+style );}\ |
||
9079 | catch(e){return;};\ |
||
9080 | };"); |
||
7614 | schaersvoo | 9081 | break; |
8224 | bpr | 9082 | |
7614 | schaersvoo | 9083 | case DRAW_TEXTAREAS: |
13970 | obado | 9084 | fprintf(js_include_file,"\n/* draw text area inputfields */\n\ |
8105 | schaersvoo | 9085 | var draw_textareas = function(root_id,input_cnt,x,y,cols,rows,readonly,style,value){\ |
7614 | schaersvoo | 9086 | var canvas_div = document.getElementById(\"canvas_div\"+root_id);\ |
9087 | var textarea = document.createElement(\"textarea\");\ |
||
9088 | textarea.setAttribute(\"id\",\"canvas_input\"+input_cnt);\ |
||
9089 | textarea.setAttribute(\"style\",\"position:absolute;left:\"+x+\"px;top:\"+y+\"px;\"+style);\ |
||
9090 | textarea.setAttribute(\"cols\",cols);\ |
||
9091 | textarea.setAttribute(\"rows\",rows);\ |
||
7877 | schaersvoo | 9092 | textarea.value = value;\ |
9093 | if( readonly == 0 || wims_status == \"done\" ){ textarea.setAttribute(\"readonly\",\"readonly\");if( wims_status == \"done\" ){textarea.value=\"\";};};\ |
||
7653 | schaersvoo | 9094 | canvas_div.appendChild(textarea);};"); |
7614 | schaersvoo | 9095 | break; |
8224 | bpr | 9096 | |
7614 | schaersvoo | 9097 | case DRAW_PIXELS: |
13970 | obado | 9098 | fprintf(js_include_file,"\n/* draw pixel */\n\ |
8105 | schaersvoo | 9099 | var draw_setpixel = function(x,y,color,opacity,pixelsize){\ |
11997 | schaersvoo | 9100 | var idx = 2000+Math.ceil(1000*(Math.random()));\ |
9101 | var canvas = create_canvas%d(idx,xsize,ysize);\ |
||
7614 | schaersvoo | 9102 | var d = 0.5*pixelsize;\ |
9103 | var ctx = canvas.getContext(\"2d\");\ |
||
9462 | schaersvoo | 9104 | if(pixelsize%%2 == 1){ ctx.translate(0.5,0.5);};\ |
7614 | schaersvoo | 9105 | ctx.fillStyle = \"rgba(\"+color+\",\"+opacity+\")\";\ |
9106 | ctx.clearRect(0,0,xsize,ysize);\ |
||
9107 | for(var p=0; p<x.length;p++){\ |
||
9108 | ctx.fillRect( x2px(x[p]) - d, y2px(y[p]) - d , pixelsize, pixelsize );\ |
||
9109 | };\ |
||
9110 | ctx.fill();ctx.stroke();\ |
||
9111 | };",canvas_root_id); |
||
9112 | break; |
||
9113 | |||
9114 | case DRAW_CLOCK: |
||
13970 | obado | 9115 | fprintf(js_include_file,"\n/* begin command clock */\n\ |
7614 | schaersvoo | 9116 | var clock_canvas = create_canvas%d(%d,xsize,ysize);\ |
9117 | var clock_ctx = clock_canvas.getContext(\"2d\");\ |
||
9118 | var clock = function(xc,yc,radius,H,M,S,type,interaction,h_color,m_color,s_color,bg_color,fg_color){\ |
||
8130 | schaersvoo | 9119 | clock_ctx.clearRect(xc - radius,yc - radius,2*radius,2*radius);\ |
7614 | schaersvoo | 9120 | clock_ctx.save();\ |
7997 | schaersvoo | 9121 | clock_ctx.globalAlpha = clock_bg_opacity;\ |
7614 | schaersvoo | 9122 | this.type = type || 0;\ |
9123 | this.interaction = interaction || 0;\ |
||
7862 | schaersvoo | 9124 | this.H = H;\ |
9125 | this.M = M;\ |
||
9126 | this.S = S;\ |
||
7614 | schaersvoo | 9127 | this.xc = xc || xsize/2;\ |
9128 | this.yc = yc || ysize/2;\ |
||
9129 | this.radius = radius || xsize/4;\ |
||
9130 | var font_size = parseInt(0.2*this.radius);\ |
||
11991 | schaersvoo | 9131 | this.H_color = h_color || \"black\";\ |
9132 | this.M_color = m_color || \"black\";\ |
||
9133 | this.S_color = s_color || \"black\";\ |
||
9134 | this.fg_color = fg_color || \"black\";\ |
||
7614 | schaersvoo | 9135 | this.bg_color = bg_color || \"white\";\ |
9136 | clock_ctx.translate(this.xc,this.yc);\ |
||
9137 | clock_ctx.beginPath();\ |
||
9138 | clock_ctx.arc(0,0,this.radius,0,2*Math.PI,false);\ |
||
9139 | clock_ctx.fillStyle = this.bg_color;\ |
||
9140 | clock_ctx.fill();\ |
||
9141 | clock_ctx.closePath();\ |
||
9142 | clock_ctx.beginPath();\ |
||
9143 | clock_ctx.font = font_size+\"px Arial\";\ |
||
9144 | clock_ctx.fillStyle = this.fg_color;\ |
||
9145 | clock_ctx.textAlign = \"center\";\ |
||
9146 | clock_ctx.textBaseline = 'middle';\ |
||
9147 | var angle;var x1,y1,x2,y2;\ |
||
9148 | var angle_cos;var angle_sin;\ |
||
7997 | schaersvoo | 9149 | clock_ctx.globalAlpha = clock_fg_opacity;\ |
7614 | schaersvoo | 9150 | switch(type){\ |
9151 | case 0:clock_ctx.beginPath();\ |
||
9152 | for(var p = 1; p <= 12 ; p++){\ |
||
9153 | angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 12));\ |
||
9154 | angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 12));\ |
||
9155 | x1 = 0.8*angle_cos;y1 = 0.8*angle_sin;x2 = angle_cos;y2 = angle_sin;\ |
||
9156 | clock_ctx.moveTo(x1,y1);\ |
||
9157 | clock_ctx.lineTo(x2,y2);\ |
||
9158 | };\ |
||
9159 | for(var p = 1; p <= 60 ; p++){\ |
||
9160 | angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 60));\ |
||
9161 | angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 60));\ |
||
9162 | x1 = 0.9*angle_cos;y1 = 0.9*angle_sin;x2 = angle_cos;y2 = angle_sin;\ |
||
9163 | clock_ctx.moveTo(x1,y1);\ |
||
9164 | clock_ctx.lineTo(x2,y2);\ |
||
9165 | };\ |
||
9166 | clock_ctx.closePath();\ |
||
9167 | clock_ctx.stroke();\ |
||
9168 | break;\ |
||
9169 | case 1:\ |
||
9170 | for(var p= 1; p <= 12 ; p++){ angle = (p - 3) * (Math.PI * 2) / 12;x1 = 0.9*this.radius*Math.cos(angle);y1 = 0.9*this.radius*Math.sin(angle);clock_ctx.fillText(p, x1, y1);};break;\ |
||
7862 | schaersvoo | 9171 | case 2:\ |
9172 | for(var p= 1; p <= 12 ; p++){ angle = (p - 3) * (Math.PI * 2) / 12;x1 = 0.8*this.radius*Math.cos(angle);y1 = 0.8*this.radius*Math.sin(angle);clock_ctx.fillText(p, x1, y1);};\ |
||
7614 | schaersvoo | 9173 | clock_ctx.beginPath();\ |
9174 | for(var p = 1; p <= 12 ; p++){\ |
||
9175 | angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 12));\ |
||
9176 | angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 12));\ |
||
9177 | x1 = 0.9*angle_cos;y1 = 0.9*angle_sin;x2 = angle_cos;y2 = angle_sin;\ |
||
9178 | clock_ctx.moveTo(x1,y1);\ |
||
9179 | clock_ctx.lineTo(x2,y2);\ |
||
9180 | };\ |
||
9181 | for(var p = 1; p <= 60 ; p++){\ |
||
9182 | angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 60));\ |
||
9183 | angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 60));\ |
||
9184 | x1 = 0.95*angle_cos;y1 = 0.95*angle_sin;x2 = angle_cos;y2 = angle_sin;\ |
||
9185 | clock_ctx.moveTo(x1,y1);\ |
||
9186 | clock_ctx.lineTo(x2,y2);\ |
||
9187 | };\ |
||
9188 | clock_ctx.closePath();\ |
||
9189 | clock_ctx.stroke();\ |
||
9190 | break;\ |
||
9191 | };\ |
||
9192 | angle = (this.H - 3 + this.M/60 ) * 2 * Math.PI / 12;\ |
||
9193 | clock_ctx.rotate(angle);\ |
||
9194 | clock_ctx.beginPath();\ |
||
9195 | clock_ctx.moveTo(-3, -2);\ |
||
9196 | clock_ctx.lineTo(-3, 2);\ |
||
11026 | bpr | 9197 | clock_ctx.lineTo(this.radius * 0.6, 1);\ |
9198 | clock_ctx.lineTo(this.radius * 0.6, -1);\ |
||
7614 | schaersvoo | 9199 | clock_ctx.fillStyle = this.H_color;\ |
9200 | clock_ctx.fill();\ |
||
9201 | clock_ctx.rotate(-angle);\ |
||
9202 | angle = (this.M - 15 + this.S/60) * 2 * Math.PI / 60;\ |
||
9203 | clock_ctx.rotate(angle);\ |
||
9204 | clock_ctx.beginPath();\ |
||
9205 | clock_ctx.moveTo(-3, -2);\ |
||
9206 | clock_ctx.lineTo(-3, 2);\ |
||
9207 | clock_ctx.lineTo(this.radius * 0.8, 1);\ |
||
9208 | clock_ctx.lineTo(this.radius * 0.8, -1);\ |
||
9209 | clock_ctx.fillStyle = this.M_color;\ |
||
9210 | clock_ctx.fill();\ |
||
9211 | clock_ctx.rotate(-angle);\ |
||
9212 | angle = (this.S - 15) * 2 * Math.PI / 60;\ |
||
9213 | clock_ctx.rotate(angle);\ |
||
9214 | clock_ctx.beginPath();\ |
||
9215 | clock_ctx.moveTo(0,0);\ |
||
11026 | bpr | 9216 | clock_ctx.lineTo(this.radius * 0.9, 1);\ |
9217 | clock_ctx.lineTo(this.radius * 0.9, -1);\ |
||
7614 | schaersvoo | 9218 | clock_ctx.strokeStyle = this.S_color;\ |
9219 | clock_ctx.stroke();\ |
||
9220 | clock_ctx.restore();\ |
||
7653 | schaersvoo | 9221 | };",canvas_root_id,CLOCK_CANVAS); |
7614 | schaersvoo | 9222 | break; |
9223 | |||
9224 | case DRAW_LATTICE: |
||
13970 | obado | 9225 | fprintf(js_include_file,"\n/* draw lattice */\n\ |
11991 | schaersvoo | 9226 | var draw_lattice = function(canvas_type,line_width,x0,y0,dx1,dy1,dx2,dy2,n1,n2,fill_color,fill_opacity,stroke_color,stroke_opacity,use_rotate,angle,use_affine,affine_matrix,use_filled){\ |
7614 | schaersvoo | 9227 | var obj;\ |
9228 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
9229 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
9230 | }\ |
||
9231 | else\ |
||
9232 | {\ |
||
9233 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
9234 | };\ |
||
9235 | var ctx = obj.getContext(\"2d\");\ |
||
9236 | ctx.save();\ |
||
8071 | schaersvoo | 9237 | if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\ |
7614 | schaersvoo | 9238 | if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\ |
11874 | schaersvoo | 9239 | var color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\ |
11875 | schaersvoo | 9240 | if(use_filled > 1 ){ if(! all_fill_patterns[use_filled] ){ var pat = create_Pattern(0,0,use_filled,color); all_fill_patterns[use_filled] = pat;};ctx.fillStyle = all_fill_patterns[use_filled]; } else { ctx.fillStyle = color;};\ |
7614 | schaersvoo | 9241 | ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\ |
9242 | var radius = line_width;\ |
||
9243 | var x = 0;\ |
||
9244 | var y = 0;\ |
||
9245 | var x_step_px = xsize/(xmax-xmin);\ |
||
9246 | var y_step_px = ysize/(ymax-ymin);\ |
||
9247 | var xv1 = dx1*x_step_px;\ |
||
9248 | var yv1 = dy1*y_step_px;\ |
||
9249 | var xv2 = dx2*x_step_px;\ |
||
9250 | var yv2 = dy2*y_step_px;\ |
||
9251 | for(var p = 0; p < n1 ;p++){\ |
||
9252 | x = p*xv1 + x0;\ |
||
9253 | y = p*yv1 + y0;\ |
||
9254 | for(var c = 0; c < n2 ; c++){\ |
||
9255 | ctx.beginPath();\ |
||
9256 | ctx.arc(x+c*xv2,y+c*yv2,radius,0,2*Math.PI,false);\ |
||
9257 | ctx.fill();\ |
||
9258 | ctx.stroke();\ |
||
9259 | ctx.closePath();\ |
||
9260 | };\ |
||
9261 | };\ |
||
9262 | ctx.restore();\ |
||
9263 | return;\ |
||
7653 | schaersvoo | 9264 | };",canvas_root_id,canvas_root_id,canvas_root_id); |
7614 | schaersvoo | 9265 | break; |
7735 | schaersvoo | 9266 | case DRAW_XYLOGSCALE: |
13970 | obado | 9267 | fprintf(js_include_file,"\n/* draw xylogscale */\n\ |
8105 | schaersvoo | 9268 | var draw_grid%d = function(canvas_type,line_width,major_color,minor_color,major_opacity,minor_opacity,font_size,font_family,font_color,use_axis_numbering,precision){\ |
7956 | schaersvoo | 9269 | var obj;\ |
9270 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
9271 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
9272 | }\ |
||
9273 | else\ |
||
9274 | {\ |
||
9275 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
9276 | };\ |
||
9277 | var ctx = obj.getContext(\"2d\");\ |
||
7735 | schaersvoo | 9278 | ctx.clearRect(0,0,xsize,ysize);\ |
7956 | schaersvoo | 9279 | ctx.save();\ |
7739 | schaersvoo | 9280 | var xmarge;var ymarge;var x_e;var y_e;var num;var corr;var xtxt;var ytxt;\ |
7956 | schaersvoo | 9281 | var x_min = Math.log(xmin)/Math.log(xlogbase);\ |
9282 | var x_max = Math.log(xmax)/Math.log(xlogbase);\ |
||
9283 | var y_min = Math.log(ymin)/Math.log(ylogbase);\ |
||
9284 | var y_max = Math.log(ymax)/Math.log(ylogbase);\ |
||
11972 | schaersvoo | 9285 | if(use_axis_numbering != -1){\ |
7956 | schaersvoo | 9286 | ctx.font = font_family;\ |
9287 | xmarge = ctx.measureText(ylogbase+'^'+y_max.toFixed(0)+' ').width;\ |
||
9288 | ymarge = parseInt(1.5*font_size);\ |
||
9289 | ctx.save();\ |
||
9290 | ctx.fillStyle=\"rgba(255,215,0,0.2)\";\ |
||
9291 | ctx.rect(0,0,xmarge,ysize);\ |
||
9292 | ctx.rect(0,ysize-ymarge,xsize,ysize);\ |
||
9293 | ctx.fill();\ |
||
9294 | ctx.restore();\ |
||
9295 | }else{xmarge = 0;ymarge = 0;};\ |
||
11088 | schaersvoo | 9296 | if( typeof(xaxislabel) !== 'undefined' ){\ |
7956 | schaersvoo | 9297 | ctx.save();\ |
9298 | ctx.font = \"italic \"+font_size+\"px Ariel\";\ |
||
9299 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\ |
||
9300 | corr = ctx.measureText(xaxislabel).width;\ |
||
9301 | ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\ |
||
9302 | ctx.restore();\ |
||
9303 | };\ |
||
11088 | schaersvoo | 9304 | if( typeof(yaxislabel) !== 'undefined' ){\ |
7956 | schaersvoo | 9305 | ctx.save();\ |
9306 | ctx.font = \"italic \"+font_size+\"px Ariel\";\ |
||
9307 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\ |
||
9308 | corr = ctx.measureText(yaxislabel).width;\ |
||
9309 | ctx.translate(xmarge+font_size,corr+font_size);\ |
||
9310 | ctx.rotate(-0.5*Math.PI);\ |
||
9311 | ctx.fillText(yaxislabel,0,0);\ |
||
9312 | ctx.restore();\ |
||
9313 | };\ |
||
9314 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\ |
||
9315 | ctx.lineWidth = line_width;\ |
||
9316 | for(var p = x_min; p <= x_max ; p++){\ |
||
9317 | num = Math.pow(xlogbase,p);\ |
||
9318 | for(var i = 1 ; i < xlogbase ; i++){\ |
||
9319 | x_e = x2px(i*num);\ |
||
7735 | schaersvoo | 9320 | if( i == 1 ){\ |
7956 | schaersvoo | 9321 | ctx.lineWidth = line_width;\ |
9322 | ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\ |
||
11972 | schaersvoo | 9323 | if( use_axis_numbering != -1 && p > x_min){\ |
7956 | schaersvoo | 9324 | xtxt = xlogbase+'^'+p.toFixed(0);\ |
9325 | corr = 0.5*(ctx.measureText(xtxt).width);\ |
||
9326 | ctx.fillText(xtxt,x_e - corr,ysize - 4);\ |
||
9327 | };\ |
||
7735 | schaersvoo | 9328 | }else{\ |
7956 | schaersvoo | 9329 | ctx.lineWidth = 0.2*line_width;\ |
9330 | ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\ |
||
9331 | };\ |
||
7738 | schaersvoo | 9332 | if( x_e >= xmarge ){\ |
7956 | schaersvoo | 9333 | ctx.beginPath();\ |
9334 | ctx.moveTo(x_e,0);\ |
||
9335 | ctx.lineTo(x_e,ysize - ymarge);\ |
||
9336 | ctx.stroke();\ |
||
9337 | ctx.closePath();\ |
||
7738 | schaersvoo | 9338 | };\ |
7956 | schaersvoo | 9339 | };\ |
9340 | };\ |
||
9341 | for(var p = y_min; p <= y_max ; p++){\ |
||
9342 | num = Math.pow(ylogbase,p);\ |
||
9343 | for(var i = 1 ; i < ylogbase ; i++){\ |
||
9344 | y_e = y2px(i*num);\ |
||
9345 | if( i == 1 ){\ |
||
9346 | ctx.lineWidth = line_width;\ |
||
7735 | schaersvoo | 9347 | ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\ |
11972 | schaersvoo | 9348 | if( use_axis_numbering != -1 && p > y_min){\ |
7956 | schaersvoo | 9349 | ctx.fillText(ylogbase+'^'+p.toFixed(0),0,y_e);\ |
9350 | };\ |
||
9351 | }else{\ |
||
9352 | ctx.lineWidth = 0.2*line_width;\ |
||
9353 | ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\ |
||
9354 | };\ |
||
9355 | ctx.beginPath();\ |
||
9356 | ctx.moveTo(xmarge,y_e);\ |
||
9357 | ctx.lineTo(xsize,y_e);\ |
||
9358 | ctx.stroke();\ |
||
9359 | ctx.closePath();\ |
||
9360 | };\ |
||
9361 | };\ |
||
7735 | schaersvoo | 9362 | ctx.restore();\ |
9363 | };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id); |
||
9364 | break; |
||
7614 | schaersvoo | 9365 | |
7735 | schaersvoo | 9366 | case DRAW_XLOGSCALE: |
13970 | obado | 9367 | fprintf(js_include_file,"\n/* draw xlogscale */\n\ |
8105 | schaersvoo | 9368 | var draw_grid%d = function(canvas_type,line_width,major_color,minor_color,major_opacity,minor_opacity,font_size,font_family,font_color,use_axis_numbering,ymajor,yminor,precision){\ |
7956 | schaersvoo | 9369 | var obj;\ |
9370 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
9371 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
9372 | }\ |
||
9373 | else\ |
||
9374 | {\ |
||
9375 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
9376 | };\ |
||
9377 | var ctx = obj.getContext(\"2d\");\ |
||
7735 | schaersvoo | 9378 | ctx.clearRect(0,0,xsize,ysize);\ |
7956 | schaersvoo | 9379 | ctx.save();\ |
9380 | ctx.lineWidth = line_width;\ |
||
7739 | schaersvoo | 9381 | var prec = Math.log(precision)/Math.log(10);\ |
7735 | schaersvoo | 9382 | var x_min = Math.log(xmin)/Math.log(xlogbase);\ |
9383 | var x_max = Math.log(xmax)/Math.log(xlogbase);\ |
||
9384 | var y_min = 0;var y_max = ysize;var x_e;var corr;\ |
||
7739 | schaersvoo | 9385 | var xtxt;var ytxt;var num;var xmarge;var ymarge;\ |
11972 | schaersvoo | 9386 | if(use_axis_numbering != -1){\ |
7956 | schaersvoo | 9387 | ctx.font = font_family;\ |
9388 | xmarge = ctx.measureText(ymax.toFixed(prec)+' ').width;\ |
||
9389 | ymarge = parseInt(1.5*font_size);\ |
||
9390 | ctx.save();\ |
||
9391 | ctx.fillStyle=\"rgba(255,215,0,0.2)\";\ |
||
9392 | ctx.rect(0,0,xmarge,ysize);\ |
||
9393 | ctx.rect(0,ysize-ymarge,xsize,ysize);\ |
||
9394 | ctx.fill();\ |
||
9395 | ctx.restore();\ |
||
9396 | }else{xmarge = 0;ymarge = 0;};\ |
||
11088 | schaersvoo | 9397 | if( typeof(xaxislabel) !== 'undefined' ){\ |
7956 | schaersvoo | 9398 | ctx.save();\ |
9399 | ctx.font = \"italic \"+font_size+\"px Ariel\";\ |
||
9400 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\ |
||
9401 | corr = ctx.measureText(xaxislabel).width;\ |
||
9402 | ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\ |
||
9403 | ctx.restore();\ |
||
9404 | };\ |
||
11088 | schaersvoo | 9405 | if( typeof(yaxislabel) !== 'undefined' ){\ |
7956 | schaersvoo | 9406 | ctx.save();\ |
9407 | ctx.font = \"italic \"+font_size+\"px Ariel\";\ |
||
9408 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\ |
||
9409 | corr = ctx.measureText(yaxislabel).width;\ |
||
9410 | ctx.translate(xmarge+font_size,corr+font_size);\ |
||
9411 | ctx.rotate(-0.5*Math.PI);\ |
||
9412 | ctx.fillText(yaxislabel,0,0);\ |
||
9413 | ctx.restore();\ |
||
9414 | };\ |
||
9415 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\ |
||
9416 | ctx.lineWidth = line_width;\ |
||
9417 | for(var p = x_min; p <= x_max ; p++){\ |
||
9418 | num = Math.pow(xlogbase,p);\ |
||
9419 | for(var i = 1 ; i < xlogbase ; i++){\ |
||
9420 | x_e = x2px(i*num);\ |
||
7735 | schaersvoo | 9421 | if( i == 1 ){\ |
7956 | schaersvoo | 9422 | ctx.lineWidth = line_width;\ |
7739 | schaersvoo | 9423 | ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\ |
11972 | schaersvoo | 9424 | if( use_axis_numbering != -1 && p > x_min ){\ |
7735 | schaersvoo | 9425 | xtxt = xlogbase+'^'+p.toFixed(0);\ |
9426 | corr = 0.5*(ctx.measureText(xtxt).width);\ |
||
9427 | ctx.fillText(xtxt,x_e - corr,ysize - 4);\ |
||
9428 | };\ |
||
9429 | }else{\ |
||
7956 | schaersvoo | 9430 | ctx.lineWidth = 0.2*line_width;\ |
7735 | schaersvoo | 9431 | ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\ |
9432 | };\ |
||
7739 | schaersvoo | 9433 | if( x_e >= xmarge ){\ |
7956 | schaersvoo | 9434 | ctx.beginPath();\ |
9435 | ctx.moveTo(x_e,0);\ |
||
9436 | ctx.lineTo(x_e,ysize - ymarge);\ |
||
9437 | ctx.stroke();\ |
||
9438 | ctx.closePath();\ |
||
7739 | schaersvoo | 9439 | };\ |
9440 | };\ |
||
7956 | schaersvoo | 9441 | };\ |
7735 | schaersvoo | 9442 | var stepy = Math.abs(y2px(ymajor) - y2px(0));\ |
9443 | var minor_step = stepy / yminor;\ |
||
7749 | schaersvoo | 9444 | for(var y = 0 ; y < ysize - stepy ; y = y + stepy){\ |
7735 | schaersvoo | 9445 | ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\ |
7956 | schaersvoo | 9446 | ctx.lineWidth = line_width;\ |
9447 | ctx.beginPath();\ |
||
9448 | ctx.moveTo(xmarge,y);\ |
||
9449 | ctx.lineTo(xsize,y);\ |
||
9450 | ctx.stroke();\ |
||
9451 | ctx.closePath();\ |
||
11972 | schaersvoo | 9452 | if( use_axis_numbering != -1){\ |
7735 | schaersvoo | 9453 | ytxt = (px2y(y)).toFixed(prec);\ |
9454 | ctx.fillText( ytxt,0 ,y + 0.5*font_size );\ |
||
9455 | };\ |
||
9456 | for(var dy = 1 ; dy < yminor ; dy++){\ |
||
9457 | ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\ |
||
7956 | schaersvoo | 9458 | ctx.lineWidth = 0.2*line_width;\ |
9459 | ctx.beginPath();\ |
||
7739 | schaersvoo | 9460 | ctx.moveTo(xmarge,y+dy*minor_step);\ |
7956 | schaersvoo | 9461 | ctx.lineTo(xsize,y+dy*minor_step);\ |
9462 | ctx.stroke();\ |
||
9463 | ctx.closePath();\ |
||
7735 | schaersvoo | 9464 | };\ |
9465 | };\ |
||
7956 | schaersvoo | 9466 | ctx.restore();\ |
9467 | };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id); |
||
7735 | schaersvoo | 9468 | break; |
7729 | schaersvoo | 9469 | case DRAW_YLOGSCALE: |
13970 | obado | 9470 | fprintf(js_include_file,"\n/* draw ylogscale */\n\ |
8105 | schaersvoo | 9471 | var draw_grid%d = function(canvas_type,line_width,major_color,minor_color,major_opacity,minor_opacity,font_size,font_family,font_color,use_axis_numbering,xmajor,xminor,precision){\ |
7956 | schaersvoo | 9472 | var obj;\ |
9473 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\ |
||
9474 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\ |
||
9475 | }\ |
||
9476 | else\ |
||
9477 | {\ |
||
9478 | obj = create_canvas%d(canvas_type,xsize,ysize);\ |
||
9479 | };\ |
||
9480 | var ctx = obj.getContext(\"2d\");\ |
||
7729 | schaersvoo | 9481 | ctx.clearRect(0,0,xsize,ysize);\ |
7956 | schaersvoo | 9482 | ctx.save();\ |
9483 | ctx.lineWidth = line_width;\ |
||
7735 | schaersvoo | 9484 | var y_min = Math.log(ymin)/Math.log(ylogbase);\ |
9485 | var y_max = Math.log(ymax)/Math.log(ylogbase);\ |
||
8109 | schaersvoo | 9486 | var x_min = 0;var x_max = xsize;var y_s;var y_e;var num;var xmarge;var ymarge;\ |
11972 | schaersvoo | 9487 | if(use_axis_numbering != -1){\ |
7956 | schaersvoo | 9488 | ctx.font = font_family;\ |
9489 | xmarge = ctx.measureText(ylogbase+\"^\"+y_max.toFixed(0)+' ').width;\ |
||
9490 | ymarge = 2*font_size;\ |
||
9491 | ctx.save();\ |
||
9492 | ctx.fillStyle=\"rgba(255,215,0,0.2)\";\ |
||
9493 | ctx.rect(0,0,xmarge,ysize);\ |
||
9494 | ctx.rect(0,ysize-ymarge,xsize,ysize);\ |
||
9495 | ctx.fill();\ |
||
9496 | ctx.restore();\ |
||
9497 | }else{xmarge = 0;ymarge = 0;};\ |
||
11088 | schaersvoo | 9498 | if( typeof(xaxislabel) !== 'undefined' ){\ |
7956 | schaersvoo | 9499 | ctx.save();\ |
9500 | ctx.font = \"italic \"+font_size+\"px Ariel\";\ |
||
9501 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\ |
||
9502 | corr = ctx.measureText(xaxislabel).width;\ |
||
9503 | ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\ |
||
9504 | ctx.restore();\ |
||
9505 | };\ |
||
11088 | schaersvoo | 9506 | if( typeof(yaxislabel) !== 'undefined' ){\ |
7956 | schaersvoo | 9507 | ctx.save();\ |
9508 | ctx.font = \"italic \"+font_size+\"px Ariel\";\ |
||
9509 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\ |
||
9510 | corr = ctx.measureText(yaxislabel).width;\ |
||
9511 | ctx.translate(xmarge+font_size,corr+font_size);\ |
||
9512 | ctx.rotate(-0.5*Math.PI);\ |
||
9513 | ctx.fillText(yaxislabel,0,0);\ |
||
9514 | ctx.restore();\ |
||
9515 | };\ |
||
9516 | ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\ |
||
9517 | ctx.lineWidth = line_width;\ |
||
9518 | for(var p = y_min; p <= y_max ; p++){\ |
||
9519 | num = Math.pow(ylogbase,p);\ |
||
9520 | for(var i = 1 ; i < ylogbase ; i++){\ |
||
9521 | y_e = y2px(i*num);\ |
||
7729 | schaersvoo | 9522 | if( i == 1 ){\ |
7956 | schaersvoo | 9523 | ctx.lineWidth = line_width;\ |
7729 | schaersvoo | 9524 | ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\ |
11972 | schaersvoo | 9525 | if( use_axis_numbering != -1 && p > y_min){\ |
7735 | schaersvoo | 9526 | ctx.fillText(ylogbase+'^'+p.toFixed(0),0,y_e);\ |
7729 | schaersvoo | 9527 | };\ |
9528 | }else{\ |
||
7956 | schaersvoo | 9529 | ctx.lineWidth = 0.2*line_width;\ |
7729 | schaersvoo | 9530 | ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\ |
9531 | };\ |
||
7956 | schaersvoo | 9532 | ctx.beginPath();\ |
9533 | ctx.moveTo(xmarge,y_e);\ |
||
9534 | ctx.lineTo(xsize,y_e);\ |
||
9535 | ctx.stroke();\ |
||
9536 | ctx.closePath();\ |
||
9537 | };\ |
||
9538 | };\ |
||
7729 | schaersvoo | 9539 | var stepx = Math.abs(x2px(xmajor) - x2px(0));\ |
9540 | var minor_step = stepx / xminor;\ |
||
9541 | var prec = Math.log(precision)/Math.log(10);\ |
||
9542 | var xtxt;var corr;var flip = 0;\ |
||
7749 | schaersvoo | 9543 | for(var x = stepx ; x < xsize ; x = x + stepx){\ |
7729 | schaersvoo | 9544 | ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\ |
7956 | schaersvoo | 9545 | ctx.lineWidth = line_width;\ |
9546 | ctx.beginPath();\ |
||
9547 | ctx.moveTo(x,ysize-ymarge);\ |
||
9548 | ctx.lineTo(x,0);\ |
||
9549 | ctx.stroke();\ |
||
9550 | ctx.closePath();\ |
||
11972 | schaersvoo | 9551 | if( use_axis_numbering != -1){\ |
7729 | schaersvoo | 9552 | xtxt = (px2x(x)).toFixed(prec);\ |
9553 | corr = 0.5*(ctx.measureText(xtxt).width);\ |
||
9554 | if(flip == 0 ){flip = 1;ctx.fillText( xtxt,x - corr ,ysize - 0.2*font_size );}else{\ |
||
9555 | flip = 0;ctx.fillText( xtxt,x - corr ,ysize - 1.2*font_size );};\ |
||
9556 | };\ |
||
9557 | for(var dx = 1 ; dx < xminor ; dx++){\ |
||
9558 | ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\ |
||
7956 | schaersvoo | 9559 | ctx.lineWidth = 0.2*line_width;\ |
9560 | ctx.beginPath();\ |
||
7739 | schaersvoo | 9561 | ctx.moveTo(x+dx*minor_step,ysize - ymarge);\ |
7956 | schaersvoo | 9562 | ctx.lineTo(x+dx*minor_step,0);\ |
9563 | ctx.stroke();\ |
||
9564 | ctx.closePath();\ |
||
7735 | schaersvoo | 9565 | };\ |
9566 | };\ |
||
7956 | schaersvoo | 9567 | ctx.restore();\ |
9568 | };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id); |
||
7729 | schaersvoo | 9569 | break; |
9213 | schaersvoo | 9570 | |
7614 | schaersvoo | 9571 | default:break; |
9572 | } |
||
9573 | } |
||
9574 | } |
||
9575 | return; |
||
9576 | } |
||
9577 | |||
9578 | void check_string_length(int L){ |
||
9466 | schaersvoo | 9579 | if( L > MAX_BUFFER-1){ |
7614 | schaersvoo | 9580 | canvas_error("problem with your arguments to command..."); |
9581 | } |
||
9582 | return; |
||
9583 | } |
||
9584 | |||
9585 | |||
9586 | int get_token(FILE *infile){ |
||
9587 | int c,i=0; |
||
9588 | char temp[MAX_INT], *input_type; |
||
9589 | char *line="line", |
||
9590 | *audio="audio", |
||
9591 | *blink="blink", |
||
9592 | *arrowhead="arrowhead", |
||
9593 | *crosshairsize="crosshairsize", |
||
9594 | *crosshair="crosshair", |
||
9595 | *crosshairs="crosshairs", |
||
9596 | *audioobject="audioobject", |
||
9597 | *style="style", |
||
9598 | *mouse="mouse", |
||
7991 | schaersvoo | 9599 | *mousex="mousex", |
9600 | *mousey="mousey", |
||
8071 | schaersvoo | 9601 | *mouse_display="display", |
9602 | *mouse_degree="mouse_degree", |
||
7614 | schaersvoo | 9603 | *userdraw="userdraw", |
9604 | *highlight="highlight", |
||
9605 | *http="http", |
||
9606 | *rays="rays", |
||
9607 | *dashtype="dashtype", |
||
9608 | *dashed="dashed", |
||
9609 | *filled="filled", |
||
9610 | *lattice="lattice", |
||
9611 | *parallel="parallel", |
||
9612 | *segment="segment", |
||
8299 | schaersvoo | 9613 | *segments="segments", |
7614 | schaersvoo | 9614 | *dsegment="dsegment", |
9374 | schaersvoo | 9615 | *dsegments="dsegments", |
7614 | schaersvoo | 9616 | *seg="seg", |
9383 | schaersvoo | 9617 | *segs="segs", |
7614 | schaersvoo | 9618 | *bgimage="bgimage", |
9619 | *bgcolor="bgcolor", |
||
9620 | *strokecolor="strokecolor", |
||
9621 | *backgroundimage="backgroundimage", |
||
9622 | *text="text", |
||
9623 | *textup="textup", |
||
9624 | *mouseprecision="mouseprecision", |
||
9625 | *precision="precision", |
||
9626 | *plotsteps="plotsteps", |
||
9627 | *plotstep="plotstep", |
||
9628 | *tsteps="tsteps", |
||
9629 | *curve="curve", |
||
9630 | *dcurve="dcurve", |
||
14038 | schaersvoo | 9631 | *curvedarrow="curvedarrow", |
9632 | *curvedarrows="curvedarrows", |
||
9633 | *curvedarrow2="curvedarrow2", |
||
9634 | *curvedarrows2="curvedarrows2", |
||
7614 | schaersvoo | 9635 | *plot="plot", |
9636 | *dplot="dplot", |
||
7788 | schaersvoo | 9637 | *levelcurve="levelcurve", |
7614 | schaersvoo | 9638 | *fontsize="fontsize", |
9639 | *fontcolor="fontcolor", |
||
9640 | *axis="axis", |
||
9641 | *axisnumbering="axisnumbering", |
||
9642 | *axisnumbers="axisnumbers", |
||
9643 | *arrow="arrow", |
||
9382 | schaersvoo | 9644 | *vector="vector", |
9645 | *vectors="vectors", |
||
7614 | schaersvoo | 9646 | *darrow="darrow", |
9647 | *arrow2="arrow2", |
||
9648 | *darrow2="darrow2", |
||
8304 | schaersvoo | 9649 | *arrows="arrows", |
8347 | schaersvoo | 9650 | *arrows2="arrows2", |
7614 | schaersvoo | 9651 | *zoom="zoom", |
9652 | *grid="grid", |
||
9653 | *hline="hline", |
||
7786 | schaersvoo | 9654 | *dhline="dhline", |
7614 | schaersvoo | 9655 | *drag="drag", |
9656 | *horizontalline="horizontalline", |
||
9383 | schaersvoo | 9657 | *horizontallines="horizontallines", |
7614 | schaersvoo | 9658 | *vline="vline", |
7786 | schaersvoo | 9659 | *dvline="dvline", |
7614 | schaersvoo | 9660 | *verticalline="verticalline", |
9383 | schaersvoo | 9661 | *verticallines="verticallines", |
7614 | schaersvoo | 9662 | *triangle="triangle", |
9306 | schaersvoo | 9663 | *triangles="triangles", |
7614 | schaersvoo | 9664 | *ftriangle="ftriangle", |
9374 | schaersvoo | 9665 | *ftriangles="ftriangles", |
7614 | schaersvoo | 9666 | *mathml="mathml", |
9667 | *html="html", |
||
9668 | *input="input", |
||
8146 | schaersvoo | 9669 | *clearbutton="clearbutton", |
9386 | schaersvoo | 9670 | *erase="erase", |
9671 | *delete="delete", |
||
7614 | schaersvoo | 9672 | *inputstyle="inputstyle", |
9673 | *textarea="textarea", |
||
9674 | *trange="trange", |
||
9675 | *ranget="ranget", |
||
9676 | *xrange="xrange", |
||
9677 | *yrange="yrange", |
||
9678 | *rangex="rangex", |
||
9679 | *rangey="rangey", |
||
8370 | schaersvoo | 9680 | *path="path", |
7614 | schaersvoo | 9681 | *polyline="polyline", |
8351 | schaersvoo | 9682 | *brokenline="brokenline", |
7614 | schaersvoo | 9683 | *lines="lines", |
9684 | *poly="poly", |
||
9685 | *polygon="polygon", |
||
9686 | *fpolygon="fpolygon", |
||
9687 | *fpoly="fpoly", |
||
9688 | *filledpoly="filledpoly", |
||
9689 | *filledpolygon="filledpolygon", |
||
9690 | *rect="rect", |
||
9691 | *frect="frect", |
||
9692 | *rectangle="rectangle", |
||
9693 | *frectangle="frectangle", |
||
9694 | *square="square", |
||
9695 | *fsquare="fsquare", |
||
9374 | schaersvoo | 9696 | *fsquares="fsquares", |
8363 | schaersvoo | 9697 | *rects="rects", |
9698 | *frects="frects", |
||
7614 | schaersvoo | 9699 | *dline="dline", |
9700 | *arc="arc", |
||
9701 | *filledarc="filledarc", |
||
9374 | schaersvoo | 9702 | *farc="farc", |
7614 | schaersvoo | 9703 | *size="size", |
9704 | *string="string", |
||
9705 | *stringup="stringup", |
||
9706 | *copy="copy", |
||
9707 | *copyresized="copyresized", |
||
9708 | *opacity="opacity", |
||
9709 | *transparent="transparent", |
||
9710 | *fill="fill", |
||
9711 | *point="point", |
||
9712 | *points="points", |
||
9713 | *linewidth="linewidth", |
||
9714 | *circle="circle", |
||
8304 | schaersvoo | 9715 | *circles="circles", |
7614 | schaersvoo | 9716 | *fcircle="fcircle", |
9374 | schaersvoo | 9717 | *fcircles="fcircles", |
7614 | schaersvoo | 9718 | *disk="disk", |
9374 | schaersvoo | 9719 | *disks="disks", |
7614 | schaersvoo | 9720 | *comment="#", |
9721 | *end="end", |
||
9722 | *ellipse="ellipse", |
||
12110 | schaersvoo | 9723 | *ellipses="ellipses", |
7614 | schaersvoo | 9724 | *fellipse="fellipse", |
9725 | *rotate="rotate", |
||
7785 | schaersvoo | 9726 | *affine="affine", |
9907 | schaersvoo | 9727 | *rotationcenter="rotationcenter", |
9728 | *killrotate="killrotate", |
||
7785 | schaersvoo | 9729 | *killaffine="killaffine", |
7614 | schaersvoo | 9730 | *fontfamily="fontfamily", |
9731 | *fillcolor="fillcolor", |
||
9732 | *clicktile="clicktile", |
||
9733 | *clicktile_colors="clicktile_colors", |
||
9734 | *translation="translation", |
||
9735 | *translate="translate", |
||
9736 | *killtranslation="killtranslation", |
||
9737 | *killtranslate="killtranslate", |
||
9738 | *onclick="onclick", |
||
8370 | schaersvoo | 9739 | *roundrects="roundrects", |
7614 | schaersvoo | 9740 | *roundrect="roundrect", |
9741 | *froundrect="froundrect", |
||
9374 | schaersvoo | 9742 | *froundrects="froundrects", |
7614 | schaersvoo | 9743 | *roundrectangle="roundrectangle", |
9744 | *patternfill="patternfill", |
||
9745 | *hatchfill="hatchfill", |
||
9746 | *diafill="diafill", |
||
7647 | schaersvoo | 9747 | *diamondfill="diamondfill", |
7614 | schaersvoo | 9748 | *dotfill="dotfill", |
11830 | schaersvoo | 9749 | *textfill="textfill", |
7614 | schaersvoo | 9750 | *gridfill="gridfill", |
9751 | *imagefill="imagefill", |
||
7735 | schaersvoo | 9752 | *xlogbase="xlogbase", |
9753 | *ylogbase="ylogbase", |
||
7614 | schaersvoo | 9754 | *xlogscale="xlogscale", |
9755 | *ylogscale="ylogscale", |
||
9756 | *xylogscale="xylogscale", |
||
9757 | *intooltip="intooltip", |
||
9329 | schaersvoo | 9758 | *popup="popup", |
7614 | schaersvoo | 9759 | *replyformat="replyformat", |
9760 | *floodfill="floodfill", |
||
11772 | schaersvoo | 9761 | *fillall="fillall", |
7614 | schaersvoo | 9762 | *filltoborder="filltoborder", |
9763 | *setpixel="setpixel", |
||
9764 | *pixels="pixels", |
||
9765 | *pixelsize="pixelsize", |
||
9766 | *xaxis="xaxis", |
||
9341 | schaersvoo | 9767 | *xaxisup="xaxisup", |
7614 | schaersvoo | 9768 | *yaxis="yaxis", |
9769 | *xaxistext="xaxistext", |
||
9341 | schaersvoo | 9770 | *xaxistextup="xaxistextup", |
7614 | schaersvoo | 9771 | *yaxistext="yaxistext", |
9772 | *piechart="piechart", |
||
9433 | schaersvoo | 9773 | *boxplot="boxplot", |
9465 | schaersvoo | 9774 | *boxplotdata="boxplotdata", |
9775 | *userboxplot="userboxplot", |
||
9776 | *userboxplotdata="userboxplotdata", |
||
7614 | schaersvoo | 9777 | *legend="legend", |
9778 | *legendcolors="legendcolors", |
||
9779 | *xlabel="xlabel", |
||
9780 | *ylabel="ylabel", |
||
9781 | *barchart="barchart", |
||
9782 | *linegraph="linegraph", |
||
9783 | *clock="clock", |
||
9784 | *animate="animate", |
||
9785 | *video="video", |
||
9786 | *status="status", |
||
7877 | schaersvoo | 9787 | *nostatus="nostatus", |
7652 | schaersvoo | 9788 | *snaptogrid="snaptogrid", |
7784 | schaersvoo | 9789 | *xsnaptogrid="xsnaptogrid", |
9790 | *ysnaptogrid="ysnaptogrid", |
||
8379 | schaersvoo | 9791 | *snaptopoints="snaptopoints", |
9213 | schaersvoo | 9792 | *snaptofunction="snaptofunction", |
9793 | *snaptofun="snaptofun", |
||
7654 | schaersvoo | 9794 | *userinput_xy="userinput_xy", |
8193 | schaersvoo | 9795 | *userinput_function="userinput_function", |
7663 | schaersvoo | 9796 | *usertextarea_xy="usertextarea_xy", |
8222 | schaersvoo | 9797 | *userinput="userinput", |
7823 | schaersvoo | 9798 | *jsmath="jsmath", |
7858 | schaersvoo | 9799 | *trace_jscurve="trace_jscurve", |
7838 | schaersvoo | 9800 | *setlimits="setlimits", |
7858 | schaersvoo | 9801 | *jscurve="jscurve", |
9802 | *jsplot="jsplot", |
||
7983 | schaersvoo | 9803 | *sgraph="sgraph", |
7984 | schaersvoo | 9804 | *title="title", |
7996 | schaersvoo | 9805 | *centerstring="centerstring", |
9806 | *xunit="xunit", |
||
8071 | schaersvoo | 9807 | *yunit="yunit", |
8101 | schaersvoo | 9808 | *slider="slider", |
8105 | schaersvoo | 9809 | *killslider="killslider", |
8244 | schaersvoo | 9810 | *angle="angle", |
8365 | schaersvoo | 9811 | *halflines="halflines", |
9812 | *demilines="demilines", |
||
8244 | schaersvoo | 9813 | *halfline="halfline", |
8297 | schaersvoo | 9814 | *demiline="demiline", |
8366 | schaersvoo | 9815 | *hlines="hlines", |
9816 | *vlines="vlines", |
||
8370 | schaersvoo | 9817 | *bezier="bezier", |
9213 | schaersvoo | 9818 | *functionlabel="functionlabel", |
9819 | *sliderfunction_x="sliderfunction_x", |
||
9820 | *sliderfunction_y="sliderfunction_y", |
||
9821 | *multidraw="multidraw", |
||
9822 | *multilinewidth="multilinewidth", |
||
9823 | *multistrokecolors="multistrokecolors", |
||
9824 | *multifillcolors="multifillcolors", |
||
9825 | *multistrokeopacity="multistrokeopacity", |
||
9826 | *multifillopacity="multifillopacity", |
||
9827 | *multifill="multifill", |
||
9828 | *multidash="multidash", |
||
9829 | *multilabel="multilabel", |
||
9830 | *multiuserinput="multiuserinput", |
||
14038 | schaersvoo | 9831 | *multiinput="multiinput", |
9289 | schaersvoo | 9832 | *multisnaptogrid="multisnaptogrid", |
14038 | schaersvoo | 9833 | *multisnap="multisnap", |
9289 | schaersvoo | 9834 | *protractor="protractor", |
9386 | schaersvoo | 9835 | *ruler="ruler", |
9836 | *cursor="cursor", |
||
9427 | schaersvoo | 9837 | *pointer="pointer", |
9838 | *yerrorbars="yerrorbars", |
||
11006 | schaersvoo | 9839 | *xerrorbars="xerrorbars", |
11044 | schaersvoo | 9840 | *noxaxis="noxaxis", |
9841 | *noyaxis="noyaxis", |
||
11767 | schaersvoo | 9842 | *colorpalette="colorpalette", |
14038 | schaersvoo | 9843 | *imagepalette="imagepalette", |
12063 | schaersvoo | 9844 | *yoffset="yoffset", |
11802 | schaersvoo | 9845 | *xoffset="xoffset", |
9846 | *centered="centered", |
||
9847 | *xyoffset="xyoffset", |
||
9848 | *resetoffset="resetoffset", |
||
11837 | schaersvoo | 9849 | *fillpattern="fillpattern", |
11890 | schaersvoo | 9850 | *numberline="numberline", |
11006 | schaersvoo | 9851 | *canvastype="canvastype"; |
7614 | schaersvoo | 9852 | |
10891 | schaersvoo | 9853 | while(((c = getc(infile)) != EOF)&&(c!='\n')&&(c!=',')&&(c!='=')&&(c!='\r')&&(c!='\t')){ |
9854 | if( i == 0 && (c == ' ') ){ continue; /* white spaces or tabs allowed before first command identifier */ |
||
9855 | }else{ |
||
9856 | if( c == ' ' ){ |
||
7614 | schaersvoo | 9857 | break; |
10891 | schaersvoo | 9858 | }else{ |
9859 | temp[i] = c; |
||
9860 | if(i > MAX_INT - 2){canvas_error("command string too long !");} |
||
9861 | i++; |
||
9862 | } |
||
9863 | } |
||
9864 | if(temp[0] == '#'){ break; } |
||
7614 | schaersvoo | 9865 | } |
10891 | schaersvoo | 9866 | if (c == '\n' || c == '\r' || c == '\t' ){ line_number++; } |
9867 | if (c == EOF) {finished=1;return 0;} |
||
7614 | schaersvoo | 9868 | |
9869 | temp[i]='\0'; |
||
9870 | input_type=(char*)my_newmem(strlen(temp)); |
||
9871 | snprintf(input_type,sizeof(temp),"%s",temp); |
||
10891 | schaersvoo | 9872 | /* fprintf(stdout,"temp = %s <br/>",input_type); */ |
7614 | schaersvoo | 9873 | if( strcmp(input_type, size) == 0 ){ |
9874 | free(input_type); |
||
9875 | return SIZE; |
||
9876 | } |
||
9877 | if( strcmp(input_type, xrange) == 0 ){ |
||
9878 | free(input_type); |
||
9879 | return XRANGE; |
||
9880 | } |
||
9881 | if( strcmp(input_type, rangex) == 0 ){ |
||
9882 | free(input_type); |
||
9883 | return XRANGE; |
||
9884 | } |
||
9885 | if( strcmp(input_type, trange) == 0 ){ |
||
9886 | free(input_type); |
||
9887 | return TRANGE; |
||
9888 | } |
||
9889 | if( strcmp(input_type, ranget) == 0 ){ |
||
9890 | free(input_type); |
||
9891 | return TRANGE; |
||
9892 | } |
||
9893 | if( strcmp(input_type, yrange) == 0 ){ |
||
9894 | free(input_type); |
||
9895 | return YRANGE; |
||
9896 | } |
||
9897 | if( strcmp(input_type, rangey) == 0 ){ |
||
9898 | free(input_type); |
||
9899 | return YRANGE; |
||
9900 | } |
||
9901 | if( strcmp(input_type, linewidth) == 0 ){ |
||
9902 | free(input_type); |
||
9903 | return LINEWIDTH; |
||
9904 | } |
||
9905 | if( strcmp(input_type, dashed) == 0 ){ |
||
9906 | free(input_type); |
||
9907 | return DASHED; |
||
9908 | } |
||
9909 | if( strcmp(input_type, dashtype) == 0 ){ |
||
9910 | free(input_type); |
||
9911 | return DASHTYPE; |
||
9912 | } |
||
9913 | if( strcmp(input_type, axisnumbering) == 0 ){ |
||
9914 | free(input_type); |
||
9915 | return AXIS_NUMBERING; |
||
9916 | } |
||
9917 | if( strcmp(input_type, axisnumbers) == 0 ){ |
||
9918 | free(input_type); |
||
9919 | return AXIS_NUMBERING; |
||
9920 | } |
||
9921 | if( strcmp(input_type, axis) == 0 ){ |
||
9922 | free(input_type); |
||
9923 | return AXIS; |
||
9924 | } |
||
9925 | if( strcmp(input_type, grid) == 0 ){ |
||
9926 | free(input_type); |
||
9927 | return GRID; |
||
9928 | } |
||
9383 | schaersvoo | 9929 | if( strcmp(input_type, hlines) == 0 || strcmp(input_type, horizontallines) == 0 ){ |
8366 | schaersvoo | 9930 | free(input_type); |
9931 | return HLINES; |
||
9932 | } |
||
9383 | schaersvoo | 9933 | if( strcmp(input_type, vlines) == 0 || strcmp(input_type, verticallines) == 0 ){ |
8366 | schaersvoo | 9934 | free(input_type); |
9935 | return VLINES; |
||
9936 | } |
||
9383 | schaersvoo | 9937 | if( strcmp(input_type, hline) == 0 || strcmp(input_type, horizontalline) == 0 ){ |
7614 | schaersvoo | 9938 | free(input_type); |
9939 | return HLINE; |
||
9940 | } |
||
9941 | if( strcmp(input_type, vline) == 0 || strcmp(input_type, verticalline) == 0 ){ |
||
9942 | free(input_type); |
||
9943 | return VLINE; |
||
9944 | } |
||
9945 | if( strcmp(input_type, line) == 0 ){ |
||
9946 | free(input_type); |
||
9947 | return LINE; |
||
9948 | } |
||
9383 | schaersvoo | 9949 | if( strcmp(input_type, segments) == 0 || strcmp(input_type, segs) == 0 ){ |
8299 | schaersvoo | 9950 | free(input_type); |
9951 | return SEGMENTS; |
||
9952 | } |
||
7614 | schaersvoo | 9953 | if( strcmp(input_type, seg) == 0 || strcmp(input_type, segment) == 0 ){ |
9954 | free(input_type); |
||
9955 | return SEGMENT; |
||
9956 | } |
||
9374 | schaersvoo | 9957 | if( strcmp(input_type, dsegments) == 0 ){ |
9958 | free(input_type); |
||
9959 | use_dashed = TRUE; |
||
9960 | return SEGMENTS; |
||
9961 | } |
||
7614 | schaersvoo | 9962 | if( strcmp(input_type, dsegment) == 0 ){ |
9963 | free(input_type); |
||
9964 | use_dashed = TRUE; |
||
9965 | return SEGMENT; |
||
9966 | } |
||
9967 | if( strcmp(input_type, crosshairsize) == 0 ){ |
||
9968 | free(input_type); |
||
9969 | return CROSSHAIRSIZE; |
||
9970 | } |
||
9971 | if( strcmp(input_type, arrowhead) == 0 ){ |
||
9972 | free(input_type); |
||
9973 | return ARROWHEAD; |
||
9974 | } |
||
9975 | if( strcmp(input_type, crosshairs) == 0 ){ |
||
9976 | free(input_type); |
||
9977 | return CROSSHAIRS; |
||
9978 | } |
||
9979 | if( strcmp(input_type, crosshair) == 0 ){ |
||
9980 | free(input_type); |
||
9981 | return CROSSHAIR; |
||
9982 | } |
||
9983 | if( strcmp(input_type, onclick) == 0 ){ |
||
9984 | free(input_type); |
||
9985 | return ONCLICK; |
||
9986 | } |
||
9987 | if( strcmp(input_type, drag) == 0 ){ |
||
9988 | free(input_type); |
||
9989 | return DRAG; |
||
9990 | } |
||
9991 | if( strcmp(input_type, userdraw) == 0 ){ |
||
9992 | free(input_type); |
||
9993 | return USERDRAW; |
||
9994 | } |
||
9995 | if( strcmp(input_type, highlight) == 0 || strcmp(input_type, style) == 0 ){ |
||
9996 | free(input_type); |
||
9997 | return STYLE; |
||
9998 | } |
||
9999 | if( strcmp(input_type, fillcolor) == 0 ){ |
||
10000 | free(input_type); |
||
10001 | return FILLCOLOR; |
||
10002 | } |
||
10003 | if( strcmp(input_type, strokecolor) == 0 ){ |
||
10004 | free(input_type); |
||
10005 | return STROKECOLOR; |
||
10006 | } |
||
10007 | if( strcmp(input_type, filled) == 0 ){ |
||
10008 | free(input_type); |
||
10009 | return FILLED; |
||
10010 | } |
||
10011 | if( strcmp(input_type, http) == 0 ){ |
||
10012 | free(input_type); |
||
10013 | return HTTP; |
||
10014 | } |
||
10015 | if( strcmp(input_type, rays) == 0 ){ |
||
10016 | free(input_type); |
||
10017 | return RAYS; |
||
10018 | } |
||
10019 | if( strcmp(input_type, lattice) == 0 ){ |
||
10020 | free(input_type); |
||
10021 | return LATTICE; |
||
10022 | } |
||
10023 | if( strcmp(input_type, bgimage) == 0 ){ |
||
10024 | free(input_type); |
||
10025 | return BGIMAGE; |
||
10026 | } |
||
10027 | if( strcmp(input_type, bgcolor) == 0 ){ |
||
10028 | free(input_type); |
||
10029 | return BGCOLOR; |
||
10030 | } |
||
10031 | if( strcmp(input_type, backgroundimage) == 0 ){ |
||
10032 | free(input_type); |
||
10033 | return BGIMAGE; |
||
10034 | } |
||
10035 | if( strcmp(input_type, text) == 0 ){ |
||
10036 | free(input_type); |
||
10037 | return FLY_TEXT; |
||
10038 | } |
||
10039 | if( strcmp(input_type, textup) == 0 ){ |
||
10040 | free(input_type); |
||
10041 | return FLY_TEXTUP; |
||
10042 | } |
||
10043 | if( strcmp(input_type, mouse) == 0 ){ |
||
10044 | free(input_type); |
||
10045 | return MOUSE; |
||
10046 | } |
||
7991 | schaersvoo | 10047 | if( strcmp(input_type, mousex) == 0 ){ |
10048 | free(input_type); |
||
10049 | return MOUSEX; |
||
10050 | } |
||
10051 | if( strcmp(input_type, mousey) == 0 ){ |
||
10052 | free(input_type); |
||
10053 | return MOUSEY; |
||
10054 | } |
||
8071 | schaersvoo | 10055 | if( strcmp(input_type, mouse_degree) == 0 ){ |
10056 | free(input_type); |
||
10057 | return MOUSE_DEGREE; |
||
10058 | } |
||
10059 | if( strcmp(input_type, mouse_display) == 0 ){ |
||
10060 | free(input_type); |
||
10061 | return MOUSE_DISPLAY; |
||
10062 | } |
||
7614 | schaersvoo | 10063 | if( strcmp(input_type, mouseprecision) == 0 ){ |
10064 | free(input_type); |
||
10065 | return MOUSE_PRECISION; |
||
10066 | } |
||
10067 | if( strcmp(input_type, precision) == 0 ){ |
||
10068 | free(input_type); |
||
10069 | return MOUSE_PRECISION; |
||
10070 | } |
||
10071 | if( strcmp(input_type, curve) == 0 ){ |
||
10072 | free(input_type); |
||
10073 | return CURVE; |
||
10074 | } |
||
10075 | if( strcmp(input_type, dcurve) == 0 ){ |
||
7788 | schaersvoo | 10076 | use_dashed = TRUE; |
7614 | schaersvoo | 10077 | free(input_type); |
10078 | return CURVE; |
||
10079 | } |
||
10080 | if( strcmp(input_type, plot) == 0 ){ |
||
10081 | free(input_type); |
||
10082 | return CURVE; |
||
10083 | } |
||
10084 | if( strcmp(input_type, dplot) == 0 ){ |
||
7788 | schaersvoo | 10085 | use_dashed = TRUE; |
7614 | schaersvoo | 10086 | free(input_type); |
10087 | return CURVE; |
||
10088 | } |
||
7788 | schaersvoo | 10089 | if( strcmp(input_type, levelcurve) == 0 ){ |
10090 | free(input_type); |
||
10091 | return LEVELCURVE; |
||
10092 | } |
||
7614 | schaersvoo | 10093 | if( strcmp(input_type, plotsteps) == 0 ){ |
10094 | free(input_type); |
||
10095 | return PLOTSTEPS; |
||
10096 | } |
||
10097 | if( strcmp(input_type, plotstep) == 0 ){ |
||
10098 | free(input_type); |
||
10099 | return PLOTSTEPS; |
||
10100 | } |
||
10101 | if( strcmp(input_type, tsteps) == 0 ){ |
||
10102 | free(input_type); |
||
10103 | return PLOTSTEPS; |
||
10104 | } |
||
10105 | if( strcmp(input_type, fontsize) == 0 ){ |
||
10106 | free(input_type); |
||
10107 | return FONTSIZE; |
||
10108 | } |
||
10109 | if( strcmp(input_type, fontcolor) == 0 ){ |
||
10110 | free(input_type); |
||
10111 | return FONTCOLOR; |
||
10112 | } |
||
10113 | if( strcmp(input_type, arrow2) == 0 ){ |
||
10114 | free(input_type); |
||
10115 | return ARROW2; |
||
10116 | } |
||
10117 | if( strcmp(input_type, darrow) == 0 ){ |
||
10118 | free(input_type); |
||
8071 | schaersvoo | 10119 | use_dashed = TRUE; |
7614 | schaersvoo | 10120 | return ARROW; |
10121 | } |
||
10122 | if( strcmp(input_type, darrow2) == 0 ){ |
||
10123 | free(input_type); |
||
10124 | use_dashed = TRUE; |
||
10125 | return ARROW2; |
||
10126 | } |
||
8347 | schaersvoo | 10127 | if( strcmp(input_type, arrows2) == 0 ){ |
10128 | free(input_type); |
||
10129 | return ARROWS2; |
||
10130 | } |
||
9382 | schaersvoo | 10131 | if( strcmp(input_type, arrows) == 0 || strcmp(input_type, vectors) == 0 ){ |
8304 | schaersvoo | 10132 | free(input_type); |
10133 | return ARROWS; |
||
10134 | } |
||
9382 | schaersvoo | 10135 | if( strcmp(input_type, arrow) == 0 || strcmp(input_type, vector) == 0 ){ |
8304 | schaersvoo | 10136 | free(input_type); |
10137 | return ARROW; |
||
10138 | } |
||
7614 | schaersvoo | 10139 | if( strcmp(input_type, zoom) == 0 ){ |
10140 | free(input_type); |
||
10141 | return ZOOM; |
||
10142 | } |
||
10143 | if( strcmp(input_type, triangle) == 0 ){ |
||
10144 | free(input_type); |
||
10145 | return TRIANGLE; |
||
10146 | } |
||
9306 | schaersvoo | 10147 | if( strcmp(input_type, triangles) == 0 ){ |
10148 | free(input_type); |
||
10149 | return TRIANGLES; |
||
10150 | } |
||
9374 | schaersvoo | 10151 | if( strcmp(input_type, ftriangles) == 0 ){ |
10152 | free(input_type); |
||
10153 | use_filled = TRUE; |
||
10154 | return TRIANGLES; |
||
10155 | } |
||
7614 | schaersvoo | 10156 | if( strcmp(input_type, ftriangle) == 0 ){ |
10157 | free(input_type); |
||
10158 | use_filled = TRUE; |
||
10159 | return TRIANGLE; |
||
10160 | } |
||
10161 | if( strcmp(input_type, input) == 0 ){ |
||
10162 | free(input_type); |
||
10163 | return INPUT; |
||
10164 | } |
||
10165 | if( strcmp(input_type, inputstyle) == 0 ){ |
||
10166 | free(input_type); |
||
10167 | return INPUTSTYLE; |
||
10168 | } |
||
10169 | if( strcmp(input_type, textarea) == 0 ){ |
||
10170 | free(input_type); |
||
10171 | return TEXTAREA; |
||
10172 | } |
||
10173 | if( strcmp(input_type, mathml) == 0 ){ |
||
10174 | free(input_type); |
||
10175 | return MATHML; |
||
10176 | } |
||
10177 | if( strcmp(input_type, html) == 0 ){ |
||
10178 | free(input_type); |
||
10179 | return MATHML; |
||
10180 | } |
||
10181 | if( strcmp(input_type, fontfamily) == 0 ){ |
||
10182 | free(input_type); |
||
10183 | return FONTFAMILY; |
||
10184 | } |
||
10975 | schaersvoo | 10185 | if( strcmp(input_type, polyline) == 0 || strcmp(input_type, path) == 0 || strcmp(input_type, brokenline) == 0 ){ |
7614 | schaersvoo | 10186 | free(input_type); |
10187 | return POLYLINE; |
||
10188 | } |
||
8351 | schaersvoo | 10189 | if( strcmp(input_type, lines) == 0 ){ |
10190 | free(input_type); |
||
10191 | return LINES; |
||
10192 | } |
||
9374 | schaersvoo | 10193 | if( strcmp(input_type, rects) == 0){ |
8363 | schaersvoo | 10194 | free(input_type); |
10195 | return RECTS; |
||
10196 | } |
||
9383 | schaersvoo | 10197 | if( strcmp(input_type, frects) == 0 ){ |
8363 | schaersvoo | 10198 | free(input_type); |
9374 | schaersvoo | 10199 | use_filled = TRUE; |
8363 | schaersvoo | 10200 | return RECTS; |
10201 | } |
||
7614 | schaersvoo | 10202 | if( strcmp(input_type, rect) == 0 || strcmp(input_type, rectangle) == 0 ){ |
10203 | free(input_type); |
||
10204 | return RECT; |
||
10205 | } |
||
9374 | schaersvoo | 10206 | if( strcmp(input_type, square) == 0 ){ |
10207 | free(input_type); |
||
11991 | schaersvoo | 10208 | return SQUARE; |
9374 | schaersvoo | 10209 | } |
10210 | if( strcmp(input_type, fsquare) == 0 ){ |
||
10211 | free(input_type); |
||
10212 | use_filled = TRUE; |
||
10213 | return SQUARE; |
||
10214 | } |
||
10215 | if( strcmp(input_type, fsquares) == 0 ){ |
||
10216 | free(input_type); |
||
10217 | use_filled = TRUE; |
||
10218 | return RECTS; |
||
10219 | } |
||
8370 | schaersvoo | 10220 | if( strcmp(input_type, roundrects) == 0 ){ |
10221 | free(input_type); |
||
10222 | return ROUNDRECTS; |
||
10223 | } |
||
7614 | schaersvoo | 10224 | if( strcmp(input_type, roundrect) == 0 || strcmp(input_type, roundrectangle) == 0 ){ |
10225 | free(input_type); |
||
10226 | return ROUNDRECT; |
||
10227 | } |
||
9374 | schaersvoo | 10228 | if( strcmp(input_type, froundrects) == 0 ){ |
7614 | schaersvoo | 10229 | free(input_type); |
10230 | use_filled = TRUE; |
||
9374 | schaersvoo | 10231 | return ROUNDRECTS; |
7614 | schaersvoo | 10232 | } |
9374 | schaersvoo | 10233 | if( strcmp(input_type, froundrect) == 0 ){ |
7614 | schaersvoo | 10234 | free(input_type); |
10235 | use_filled = TRUE; |
||
9374 | schaersvoo | 10236 | return ROUNDRECT; |
7614 | schaersvoo | 10237 | } |
10238 | if( strcmp(input_type, dline) == 0 ){ |
||
10239 | use_dashed = TRUE; |
||
10240 | free(input_type); |
||
10241 | return LINE; |
||
10242 | } |
||
7786 | schaersvoo | 10243 | if( strcmp(input_type, dvline) == 0 ){ |
10244 | use_dashed = TRUE; |
||
10245 | free(input_type); |
||
10246 | return VLINE; |
||
10247 | } |
||
10248 | if( strcmp(input_type, dhline) == 0 ){ |
||
10249 | use_dashed = TRUE; |
||
10250 | free(input_type); |
||
10251 | return HLINE; |
||
10252 | } |
||
9386 | schaersvoo | 10253 | if( strcmp(input_type, halflines) == 0 || strcmp(input_type, demilines) == 0 ){ |
10254 | free(input_type); |
||
10255 | return HALFLINES; |
||
10256 | } |
||
10257 | if( strcmp(input_type, halfline) == 0 || strcmp(input_type, demiline) == 0 ){ |
||
10258 | free(input_type); |
||
10259 | return HALFLINE; |
||
10260 | } |
||
7614 | schaersvoo | 10261 | if( strcmp(input_type, frect) == 0 || strcmp(input_type, frectangle) == 0 ){ |
10262 | use_filled = TRUE; |
||
10263 | free(input_type); |
||
10264 | return RECT; |
||
10265 | } |
||
8304 | schaersvoo | 10266 | if( strcmp(input_type, circles) == 0 ){ |
10267 | free(input_type); |
||
10268 | return CIRCLES; |
||
10269 | } |
||
7614 | schaersvoo | 10270 | if( strcmp(input_type, fcircle) == 0 || strcmp(input_type, disk) == 0 ){ |
10271 | use_filled = TRUE; |
||
10272 | free(input_type); |
||
10273 | return CIRCLE; |
||
10274 | } |
||
9374 | schaersvoo | 10275 | if( strcmp(input_type, fcircles) == 0 || strcmp(input_type, disks) == 0 ){ |
10276 | use_filled = TRUE; |
||
10277 | free(input_type); |
||
10278 | return CIRCLES; |
||
10279 | } |
||
7614 | schaersvoo | 10280 | if( strcmp(input_type, circle) == 0 ){ |
10281 | free(input_type); |
||
10282 | return CIRCLE; |
||
10283 | } |
||
10284 | if( strcmp(input_type, point) == 0 ){ |
||
10285 | free(input_type); |
||
10286 | return POINT; |
||
10287 | } |
||
10288 | if( strcmp(input_type, points) == 0 ){ |
||
10289 | free(input_type); |
||
10290 | return POINTS; |
||
10291 | } |
||
9374 | schaersvoo | 10292 | if( strcmp(input_type, filledarc) == 0 || strcmp(input_type, farc) == 0 ){ |
7614 | schaersvoo | 10293 | use_filled = TRUE; |
10294 | free(input_type); |
||
10295 | return ARC; |
||
10296 | } |
||
10297 | if( strcmp(input_type, arc) == 0 ){ |
||
10298 | free(input_type); |
||
10299 | return ARC; |
||
10300 | } |
||
10301 | if( strcmp(input_type, poly) == 0 || strcmp(input_type, polygon) == 0 ){ |
||
10302 | free(input_type); |
||
10303 | return POLY; |
||
10304 | } |
||
10305 | if( strcmp(input_type, fpoly) == 0 || strcmp(input_type, filledpoly) == 0 || strcmp(input_type,filledpolygon) == 0 || strcmp(input_type,fpolygon) == 0 ){ |
||
10306 | use_filled = TRUE; |
||
10307 | free(input_type); |
||
10308 | return POLY; |
||
10309 | } |
||
10310 | if( strcmp(input_type, ellipse) == 0){ |
||
10311 | free(input_type); |
||
10312 | return ELLIPSE; |
||
10313 | } |
||
12110 | schaersvoo | 10314 | if( strcmp(input_type, ellipses) == 0){ |
10315 | free(input_type); |
||
10316 | return ELLIPSES; |
||
10317 | } |
||
7614 | schaersvoo | 10318 | if( strcmp(input_type, string) == 0 ){ |
10319 | free(input_type); |
||
10320 | return STRING; |
||
10321 | } |
||
10322 | if( strcmp(input_type, stringup) == 0 ){ |
||
10323 | free(input_type); |
||
10324 | return STRINGUP; |
||
10325 | } |
||
9385 | schaersvoo | 10326 | if( strcmp(input_type, opacity) == 0 || strcmp(input_type, transparent) == 0 ){ |
7614 | schaersvoo | 10327 | free(input_type); |
10328 | return OPACITY; |
||
10329 | } |
||
10330 | if( strcmp(input_type, comment) == 0){ |
||
10331 | free(input_type); |
||
10332 | return COMMENT; |
||
10333 | } |
||
10334 | if( strcmp(input_type, fellipse) == 0){ |
||
10335 | free(input_type); |
||
10336 | use_filled = TRUE; |
||
10337 | return ELLIPSE; |
||
8224 | bpr | 10338 | } |
9386 | schaersvoo | 10339 | if( strcmp(input_type, clearbutton) == 0 || strcmp(input_type, erase) == 0 || strcmp(input_type, delete) == 0){ |
7614 | schaersvoo | 10340 | free(input_type); |
8146 | schaersvoo | 10341 | return CLEARBUTTON; |
7614 | schaersvoo | 10342 | } |
10343 | if( strcmp(input_type, translation) == 0 || strcmp(input_type, translate) == 0 ){ |
||
10344 | free(input_type); |
||
10345 | return TRANSLATION; |
||
10346 | } |
||
10347 | if( strcmp(input_type, killtranslation) == 0 || strcmp(input_type, killtranslate) == 0){ |
||
10348 | free(input_type); |
||
10349 | return KILLTRANSLATION; |
||
10350 | } |
||
10351 | if( strcmp(input_type, rotate) == 0){ |
||
10352 | free(input_type); |
||
10353 | return ROTATE; |
||
10354 | } |
||
9907 | schaersvoo | 10355 | if( strcmp(input_type, killrotate) == 0){ |
10356 | free(input_type); |
||
10357 | return KILLROTATE; |
||
10358 | } |
||
10359 | if( strcmp(input_type, rotationcenter) == 0){ |
||
10360 | free(input_type); |
||
10361 | return ROTATION_CENTER; |
||
10362 | } |
||
7785 | schaersvoo | 10363 | if( strcmp(input_type, affine) == 0){ |
10364 | free(input_type); |
||
10365 | return AFFINE; |
||
10366 | } |
||
10367 | if( strcmp(input_type, killaffine) == 0){ |
||
10368 | free(input_type); |
||
10369 | return KILLAFFINE; |
||
10370 | } |
||
7614 | schaersvoo | 10371 | if( strcmp(input_type, slider) == 0 ){ |
10372 | free(input_type); |
||
10373 | return SLIDER; |
||
10374 | } |
||
8101 | schaersvoo | 10375 | if( strcmp(input_type, killslider) == 0 ){ |
10376 | free(input_type); |
||
10377 | return KILLSLIDER; |
||
10378 | } |
||
7614 | schaersvoo | 10379 | if( strcmp(input_type, copy) == 0 ){ |
10380 | free(input_type); |
||
10381 | return COPY; |
||
10382 | } |
||
10383 | if( strcmp(input_type, copyresized) == 0 ){ |
||
10384 | free(input_type); |
||
10385 | return COPYRESIZED; |
||
10386 | } |
||
10387 | if( strcmp(input_type, xlogscale) == 0 ){ |
||
10388 | free(input_type); |
||
10389 | return XLOGSCALE; |
||
10390 | } |
||
10391 | if( strcmp(input_type, ylogscale) == 0 ){ |
||
10392 | free(input_type); |
||
10393 | return YLOGSCALE; |
||
10394 | } |
||
10395 | if( strcmp(input_type, xylogscale) == 0 ){ |
||
10396 | free(input_type); |
||
10397 | return XYLOGSCALE; |
||
10398 | } |
||
10399 | if( strcmp(input_type, ylogscale) == 0 ){ |
||
10400 | free(input_type); |
||
10401 | return YLOGSCALE; |
||
10402 | } |
||
7735 | schaersvoo | 10403 | if( strcmp(input_type, xlogbase) == 0 ){ |
7614 | schaersvoo | 10404 | free(input_type); |
7735 | schaersvoo | 10405 | return XLOGBASE; |
7614 | schaersvoo | 10406 | } |
7735 | schaersvoo | 10407 | if( strcmp(input_type, ylogbase) == 0 ){ |
10408 | free(input_type); |
||
10409 | return YLOGBASE; |
||
10410 | } |
||
7614 | schaersvoo | 10411 | if( strcmp(input_type, intooltip) == 0 ){ |
10412 | free(input_type); |
||
10413 | return INTOOLTIP; |
||
10414 | } |
||
9329 | schaersvoo | 10415 | if( strcmp(input_type, popup) == 0 ){ |
10416 | free(input_type); |
||
10417 | return POPUP; |
||
10418 | } |
||
7614 | schaersvoo | 10419 | if( strcmp(input_type,video) == 0 ){ |
10420 | free(input_type); |
||
10421 | return VIDEO; |
||
10422 | } |
||
11772 | schaersvoo | 10423 | if( strcmp(input_type,fillall) == 0 ){ |
10424 | free(input_type); |
||
10425 | return FILLALL; |
||
10426 | } |
||
7614 | schaersvoo | 10427 | if( strcmp(input_type,floodfill) == 0 || strcmp(input_type,fill) == 0 ){ |
10428 | free(input_type); |
||
10429 | return FLOODFILL; |
||
8224 | bpr | 10430 | } |
7614 | schaersvoo | 10431 | if( strcmp(input_type,filltoborder) == 0 ){ |
10432 | free(input_type); |
||
10433 | return FILLTOBORDER; |
||
8224 | bpr | 10434 | } |
14038 | schaersvoo | 10435 | if( strcmp(input_type, curvedarrow2) == 0 ){ |
10436 | free(input_type); |
||
10437 | return CURVEDARROW2; |
||
10438 | } |
||
10439 | if( strcmp(input_type, curvedarrow) == 0 ){ |
||
10440 | free(input_type); |
||
10441 | return CURVEDARROW; |
||
10442 | } |
||
10443 | if( strcmp(input_type, curvedarrows) == 0 ){ |
||
10444 | free(input_type); |
||
10445 | return CURVEDARROWS; |
||
10446 | } |
||
10447 | if( strcmp(input_type, curvedarrows2) == 0 ){ |
||
10448 | free(input_type); |
||
10449 | return CURVEDARROWS2; |
||
10450 | } |
||
7614 | schaersvoo | 10451 | if( strcmp(input_type, replyformat) == 0 ){ |
10452 | free(input_type); |
||
10453 | return REPLYFORMAT; |
||
10454 | } |
||
10455 | if( strcmp(input_type, pixelsize) == 0 ){ |
||
10456 | free(input_type); |
||
10457 | return PIXELSIZE; |
||
10458 | } |
||
10459 | if( strcmp(input_type, setpixel) == 0 ){ |
||
10460 | free(input_type); |
||
10461 | return SETPIXEL; |
||
10462 | } |
||
10463 | if( strcmp(input_type, pixels) == 0 ){ |
||
10464 | free(input_type); |
||
10465 | return PIXELS; |
||
10466 | } |
||
10467 | if( strcmp(input_type, xaxis) == 0 || strcmp(input_type, xaxistext) == 0 ){ |
||
10468 | free(input_type); |
||
10469 | return X_AXIS_STRINGS; |
||
10470 | } |
||
9341 | schaersvoo | 10471 | if( strcmp(input_type, xaxisup) == 0 || strcmp(input_type, xaxistextup) == 0 ){ |
10472 | free(input_type); |
||
10473 | return X_AXIS_STRINGS_UP; |
||
10474 | } |
||
7614 | schaersvoo | 10475 | if( strcmp(input_type, yaxis) == 0 || strcmp(input_type, yaxistext) == 0 ){ |
10476 | free(input_type); |
||
10477 | return Y_AXIS_STRINGS; |
||
10478 | } |
||
10479 | if( strcmp(input_type, legend) == 0 ){ |
||
10480 | free(input_type); |
||
10481 | return LEGEND; |
||
10482 | } |
||
10483 | if( strcmp(input_type, legendcolors) == 0 ){ |
||
10484 | free(input_type); |
||
10485 | return LEGENDCOLORS; |
||
10486 | } |
||
10487 | if( strcmp(input_type, xlabel) == 0 ){ |
||
10488 | free(input_type); |
||
10489 | return XLABEL; |
||
10490 | } |
||
10491 | if( strcmp(input_type, ylabel) == 0 ){ |
||
10492 | free(input_type); |
||
10493 | return YLABEL; |
||
10494 | } |
||
8370 | schaersvoo | 10495 | if( strcmp(input_type, bezier) == 0 ){ |
10496 | free(input_type); |
||
10497 | return BEZIER; |
||
10498 | } |
||
7614 | schaersvoo | 10499 | if( strcmp(input_type, animate) == 0 ){ |
10500 | free(input_type); |
||
10501 | return ANIMATE; |
||
10502 | } |
||
9354 | schaersvoo | 10503 | /* these are bitmap related flydraw commands...must be removed. eventually */ |
7614 | schaersvoo | 10504 | if( strcmp(input_type, transparent) == 0 ){ |
10505 | free(input_type); |
||
10506 | return TRANSPARENT; |
||
10507 | } |
||
7877 | schaersvoo | 10508 | if( strcmp(input_type, status) == 0 || strcmp(input_type, nostatus) == 0 ){ |
7614 | schaersvoo | 10509 | free(input_type); |
10510 | return STATUS; |
||
10511 | } |
||
7784 | schaersvoo | 10512 | if( strcmp(input_type, xsnaptogrid) == 0 ){ |
10513 | free(input_type); |
||
10514 | return XSNAPTOGRID; |
||
10515 | } |
||
10516 | if( strcmp(input_type, ysnaptogrid) == 0 ){ |
||
10517 | free(input_type); |
||
10518 | return YSNAPTOGRID; |
||
10519 | } |
||
8379 | schaersvoo | 10520 | if( strcmp(input_type, snaptogrid) == 0 ){ |
10521 | free(input_type); |
||
10522 | return SNAPTOGRID; |
||
10523 | } |
||
10524 | if( strcmp(input_type, snaptopoints) == 0 ){ |
||
10525 | free(input_type); |
||
10526 | return SNAPTOPOINTS; |
||
10527 | } |
||
9213 | schaersvoo | 10528 | if( strcmp(input_type, snaptofunction) == 0 || strcmp(input_type, snaptofun) == 0 ){ |
10529 | free(input_type); |
||
10530 | return SNAPTOFUNCTION; |
||
10531 | } |
||
7652 | schaersvoo | 10532 | if( strcmp(input_type, userinput_xy) == 0 ){ |
7614 | schaersvoo | 10533 | free(input_type); |
7652 | schaersvoo | 10534 | return USERINPUT_XY; |
10535 | } |
||
8193 | schaersvoo | 10536 | if( strcmp(input_type, userinput_function) == 0 ){ |
10537 | free(input_type); |
||
10538 | return USERINPUT_FUNCTION; |
||
10539 | } |
||
7663 | schaersvoo | 10540 | if( strcmp(input_type, usertextarea_xy) == 0 ){ |
10541 | free(input_type); |
||
10542 | return USERTEXTAREA_XY; |
||
10543 | } |
||
8222 | schaersvoo | 10544 | if( strcmp(input_type, userinput) == 0 ){ |
10545 | free(input_type); |
||
10546 | return USERINPUT; |
||
10547 | } |
||
8105 | schaersvoo | 10548 | if( strcmp(input_type, angle) == 0 ){ |
7996 | schaersvoo | 10549 | free(input_type); |
8105 | schaersvoo | 10550 | return ANGLE; |
10551 | } |
||
8297 | schaersvoo | 10552 | if( strcmp(input_type, functionlabel) == 0 ){ |
8244 | schaersvoo | 10553 | free(input_type); |
8297 | schaersvoo | 10554 | return FUNCTION_LABEL; |
10555 | } |
||
9213 | schaersvoo | 10556 | if( strcmp(input_type, sliderfunction_x) == 0 ){ |
8297 | schaersvoo | 10557 | free(input_type); |
9213 | schaersvoo | 10558 | return SLIDER_X; |
10559 | } |
||
10560 | if( strcmp(input_type, sliderfunction_y) == 0 ){ |
||
10561 | free(input_type); |
||
10562 | return SLIDER_Y; |
||
10563 | } |
||
10564 | if( strcmp(input_type, multidraw) == 0 ){ |
||
10565 | free(input_type); |
||
10566 | return MULTIDRAW; |
||
10567 | } |
||
10568 | if( strcmp(input_type, multistrokeopacity) == 0 ){ |
||
10569 | free(input_type); |
||
10570 | return MULTISTROKEOPACITY; |
||
10571 | } |
||
10572 | if( strcmp(input_type, multifillopacity) == 0 ){ |
||
10573 | free(input_type); |
||
10574 | return MULTIFILLOPACITY; |
||
10575 | } |
||
10576 | if( strcmp(input_type, multilinewidth) == 0 ){ |
||
10577 | free(input_type); |
||
10578 | return MULTILINEWIDTH; |
||
10579 | } |
||
10580 | if( strcmp(input_type, multistrokecolors) == 0 ){ |
||
10581 | free(input_type); |
||
10582 | return MULTISTROKECOLORS; |
||
10583 | } |
||
10584 | if( strcmp(input_type, multifill) == 0 ){ |
||
10585 | free(input_type); |
||
10586 | return MULTIFILL; |
||
10587 | } |
||
10588 | if( strcmp(input_type, multifillcolors) == 0 ){ |
||
10589 | free(input_type); |
||
10590 | return MULTIFILLCOLORS; |
||
10591 | } |
||
10592 | if( strcmp(input_type, multilabel) == 0 ){ |
||
10593 | free(input_type); |
||
10594 | return MULTILABEL; |
||
10595 | } |
||
10596 | if( strcmp(input_type, multidash) == 0 ){ |
||
10597 | free(input_type); |
||
10598 | return MULTIDASH; |
||
10599 | } |
||
14038 | schaersvoo | 10600 | if( strcmp(input_type, multisnaptogrid) == 0 || strcmp(input_type, multisnap) == 0 ){ |
9213 | schaersvoo | 10601 | free(input_type); |
10602 | return MULTISNAPTOGRID; |
||
10603 | } |
||
14038 | schaersvoo | 10604 | if( strcmp(input_type, multiuserinput) == 0 || strcmp(input_type, multiinput) == 0 ){ |
9213 | schaersvoo | 10605 | free(input_type); |
10606 | return MULTIUSERINPUT; |
||
10607 | } |
||
9386 | schaersvoo | 10608 | if( strcmp(input_type, parallel) == 0 ){ |
10609 | free(input_type); |
||
10610 | return PARALLEL; |
||
10611 | } |
||
9289 | schaersvoo | 10612 | if( strcmp(input_type, protractor) == 0 ){ |
10613 | free(input_type); |
||
10614 | return PROTRACTOR; |
||
10615 | } |
||
10616 | if( strcmp(input_type, ruler) == 0 ){ |
||
10617 | free(input_type); |
||
10618 | return RULER; |
||
10619 | } |
||
9386 | schaersvoo | 10620 | if( strcmp(input_type, cursor) == 0 || strcmp(input_type, pointer) == 0 ){ |
9213 | schaersvoo | 10621 | free(input_type); |
9386 | schaersvoo | 10622 | return CURSOR; |
10623 | } |
||
10624 | if( strcmp(input_type, sgraph) == 0 ){ |
||
10625 | free(input_type); |
||
10626 | return SGRAPH; |
||
10627 | } |
||
10628 | if( strcmp(input_type, jsmath) == 0 ){ |
||
10629 | free(input_type); |
||
10630 | return JSMATH; |
||
10631 | } |
||
10632 | if( strcmp(input_type, trace_jscurve) == 0 ){ |
||
10633 | free(input_type); |
||
10634 | return TRACE_JSCURVE; |
||
10635 | } |
||
10636 | if( strcmp(input_type, jscurve) == 0 || strcmp(input_type, jsplot) == 0 ){ |
||
10637 | free(input_type); |
||
10638 | return JSCURVE; |
||
10639 | } |
||
10640 | if( strcmp(input_type, centerstring) == 0 || strcmp(input_type, title) == 0 ){ |
||
10641 | free(input_type); |
||
10642 | return CENTERSTRING; |
||
10643 | } |
||
10644 | if( strcmp(input_type, setlimits) == 0 ){ |
||
10645 | free(input_type); |
||
10646 | return SETLIMITS; |
||
10647 | } |
||
10648 | if( strcmp(input_type, xunit) == 0 ){ |
||
10649 | free(input_type); |
||
10650 | return XUNIT; |
||
10651 | } |
||
10652 | if( strcmp(input_type, yunit) == 0 ){ |
||
10653 | free(input_type); |
||
10654 | return YUNIT; |
||
10655 | } |
||
10656 | if( strcmp(input_type, fill) == 0 ){ |
||
10657 | free(input_type); |
||
10658 | return FLOODFILL; |
||
10659 | } |
||
10660 | if( strcmp(input_type, end) == 0){ |
||
10661 | free(input_type); |
||
10662 | return END; |
||
10663 | } |
||
10664 | if( strcmp(input_type, blink) == 0 ){ |
||
10665 | free(input_type); |
||
10666 | return BLINK; |
||
10667 | } |
||
10668 | if( strcmp(input_type, audio) == 0 ){ |
||
10669 | free(input_type); |
||
10670 | return AUDIO; |
||
10671 | } |
||
10672 | if( strcmp(input_type, audioobject) == 0 ){ |
||
10673 | free(input_type); |
||
10674 | return AUDIOOBJECT; |
||
10675 | } |
||
10676 | if( strcmp(input_type, patternfill) == 0 ){ |
||
10677 | free(input_type); |
||
10678 | return PATTERNFILL; |
||
10679 | } |
||
10680 | if( strcmp(input_type, hatchfill) == 0 ){ |
||
10681 | free(input_type); |
||
10682 | return HATCHFILL; |
||
10683 | } |
||
10684 | if( strcmp(input_type, diafill) == 0 || strcmp(input_type, diamondfill) == 0 ){ |
||
10685 | free(input_type); |
||
10686 | return DIAMONDFILL; |
||
10687 | } |
||
10688 | if( strcmp(input_type, dotfill) == 0 ){ |
||
10689 | free(input_type); |
||
10690 | return DOTFILL; |
||
10691 | } |
||
11830 | schaersvoo | 10692 | if( strcmp(input_type, textfill) == 0 ){ |
10693 | free(input_type); |
||
10694 | return TEXTFILL; |
||
10695 | } |
||
9386 | schaersvoo | 10696 | if( strcmp(input_type, gridfill) == 0 ){ |
10697 | free(input_type); |
||
10698 | return GRIDFILL; |
||
10699 | } |
||
10700 | if( strcmp(input_type, imagefill) == 0 ){ |
||
10701 | free(input_type); |
||
10702 | return IMAGEFILL; |
||
10703 | } |
||
10704 | if( strcmp(input_type, clicktile_colors) == 0 ){ |
||
10705 | free(input_type); |
||
10706 | return CLICKTILE_COLORS; |
||
10707 | } |
||
10708 | if( strcmp(input_type, clicktile) == 0 ){ |
||
10709 | free(input_type); |
||
10710 | return CLICKTILE; |
||
10711 | } |
||
10712 | if( strcmp(input_type, piechart) == 0 ){ |
||
10713 | free(input_type); |
||
10714 | return PIECHART; |
||
10715 | } |
||
9433 | schaersvoo | 10716 | if( strcmp(input_type, boxplot) == 0 ){ |
10717 | free(input_type); |
||
10718 | return BOXPLOT; |
||
10719 | } |
||
9465 | schaersvoo | 10720 | if( strcmp(input_type, boxplotdata) == 0 ){ |
9433 | schaersvoo | 10721 | free(input_type); |
9465 | schaersvoo | 10722 | return BOXPLOTDATA; |
9433 | schaersvoo | 10723 | } |
9465 | schaersvoo | 10724 | if( strcmp(input_type, userboxplot) == 0 ){ |
10725 | free(input_type); |
||
10726 | return USERBOXPLOT; |
||
10727 | } |
||
10728 | if( strcmp(input_type, userboxplotdata) == 0 ){ |
||
10729 | free(input_type); |
||
10730 | return USERBOXPLOT; |
||
10731 | } |
||
9386 | schaersvoo | 10732 | if( strcmp(input_type, barchart) == 0 ){ |
10733 | free(input_type); |
||
10734 | return BARCHART; |
||
10735 | } |
||
10736 | if( strcmp(input_type, linegraph) == 0 ){ |
||
10737 | free(input_type); |
||
10738 | return LINEGRAPH; |
||
10739 | } |
||
10740 | if( strcmp(input_type, clock) == 0 ){ |
||
10741 | free(input_type); |
||
10742 | return CLOCK; |
||
10743 | } |
||
9427 | schaersvoo | 10744 | if( strcmp(input_type, yerrorbars) == 0 ){ |
9386 | schaersvoo | 10745 | free(input_type); |
9427 | schaersvoo | 10746 | return YERRORBARS; |
10747 | } |
||
10748 | if( strcmp(input_type, xerrorbars) == 0 ){ |
||
10749 | free(input_type); |
||
10750 | return XERRORBARS; |
||
10751 | } |
||
11006 | schaersvoo | 10752 | if( strcmp(input_type, canvastype) == 0 ){ |
9427 | schaersvoo | 10753 | free(input_type); |
11006 | schaersvoo | 10754 | return CANVASTYPE; |
10755 | } |
||
11044 | schaersvoo | 10756 | if( strcmp(input_type, noyaxis) == 0 ){ |
11006 | schaersvoo | 10757 | free(input_type); |
11044 | schaersvoo | 10758 | return NOYAXIS; |
10759 | } |
||
10760 | if( strcmp(input_type, noxaxis) == 0 ){ |
||
10761 | free(input_type); |
||
10762 | return NOXAXIS; |
||
10763 | } |
||
11767 | schaersvoo | 10764 | if( strcmp(input_type, colorpalette) == 0 ){ |
11044 | schaersvoo | 10765 | free(input_type); |
11767 | schaersvoo | 10766 | return COLORPALETTE; |
10767 | } |
||
14038 | schaersvoo | 10768 | if( strcmp(input_type, imagepalette) == 0 ){ |
10769 | free(input_type); |
||
10770 | return IMAGEPALETTE; |
||
10771 | } |
||
11802 | schaersvoo | 10772 | if( strcmp(input_type, resetoffset) == 0 ){ |
11767 | schaersvoo | 10773 | free(input_type); |
11802 | schaersvoo | 10774 | return RESETOFFSET; |
10775 | } |
||
10776 | if( strcmp(input_type, xyoffset) == 0 ){ |
||
10777 | free(input_type); |
||
10778 | return XYOFFSET; |
||
10779 | } |
||
12063 | schaersvoo | 10780 | if( strcmp(input_type, centered) == 0 ){ |
11802 | schaersvoo | 10781 | free(input_type); |
12063 | schaersvoo | 10782 | return CENTERED; |
11802 | schaersvoo | 10783 | } |
12063 | schaersvoo | 10784 | if( strcmp(input_type, yoffset) == 0 ){ |
11802 | schaersvoo | 10785 | free(input_type); |
11811 | schaersvoo | 10786 | return YOFFSET; |
10787 | } |
||
12063 | schaersvoo | 10788 | if( strcmp(input_type, xoffset) == 0 ){ |
10789 | free(input_type); |
||
10790 | return XOFFSET; |
||
10791 | } |
||
11837 | schaersvoo | 10792 | if( strcmp(input_type, fillpattern) == 0 ){ |
11811 | schaersvoo | 10793 | free(input_type); |
11837 | schaersvoo | 10794 | return FILLPATTERN; |
10795 | } |
||
11890 | schaersvoo | 10796 | if( strcmp(input_type, numberline) == 0 ){ |
11837 | schaersvoo | 10797 | free(input_type); |
11890 | schaersvoo | 10798 | return NUMBERLINE; |
10799 | } |
||
10800 | free(input_type); |
||
7614 | schaersvoo | 10801 | ungetc(c,infile); |
10802 | return 0; |
||
10803 | } |
||
14038 | schaersvoo | 10804 | |
10805 | |||
10806 | |||
10807 | |||
10808 | |||
10809 | |||
10810 | |||
10811 | |||
10812 | |||
10813 | |||
10814 | |||
10815 | |||
10816 |