ccanvas -- a cavvas wrapper that allows calculated coordinates and numeric parameters
From
clt.to.davebr@clt.to.davebr@dfgh.net to
comp.lang.tcl on Sat Apr 6 15:47:17 2024
From Newsgroup: comp.lang.tcl
see ccanvas on chiselapp.com
I use ccanvas where exact sizes matter. It has been useful making templates for small parts, or checking layouts or part fit up.
ccanvas should act like a canvas with added features:
Any numeric argument can be an expression using canvas units, tcl variables, and x,y coordinates from an associated coordinate list. Like Tcl expr, it is wise, but not always necessary, to brace expressions.
.c create line $xo $yo x+1.5i y x=x1 y+5c=y1 x(0) y -width 1.7m -fill red
draws a line 1.7 mm wide, starting at the coordinates in $xo $yo, then right 1.5 inches, then down 5 centimeters, finally back left directly below the first point. The lower right most coordinates are saved in tcl variables x1, y1
ccanvas unit scaling can be set for each ccanvas using the -scale option.
-scrollregion can be set so the 0,0 point is at any of the common Tk anchor points (centered, n, ne ...) of the window (or in the normal way using 4 coordinates)
New sub commands:
dup -- duplicates tagged items, making changes to their options (in particular -tags -addtags -dtags)
flip -- mirror item coordinates in a vertical line (flip right or left)
flop -- mirror item coordinates in a horizontal line (flop down or up)
crotate -- is a different take on rotation from Tk 8.7 rotate (ccanvas supports rotate if the underlying canvas does)
expr -- returns the result of an expression in the ccanvas context
exprs -- returns a list of results from multiple expressions.
All the calculations are done using Tcl expr, so all its operators and functions are available. Lengths are converted to pixels before Tcl expr gets them. Angle arguments to trig functions (sin cos tan) are converted to radians for use in Tcl expr. Angle results from inverse trig functions (asin acos, atan) are converted back to degrees (canvas default angle units) before further use in the expression. Note no sanity checks are done on unit use! sin(5i) will not give an error, but I doubt the result would be useful.
I've been using some of the expression evaluation code for a few years, so that is pretty stable. The new subcommands might change (crotate in particular).
This is implemented as a snit widgetadapter. It is easy to add new subcommands (just add a new snit method).
If you try it and find something odd, or wrong let me know.
dave b
--- Synchronet 3.20a-Linux NewsLink 1.114