| [ Team LiB ] |
|
HintsScreen Coordinates vs. Canvas Coordinatesset id [$c find closest [$c canvasx %x] [$c canvasy %y]] Large Coordinate SpacesCoordinates for canvas items are stored internally as floating point numbers, so the values returned by the coords operation will be floating point numbers. If you have a very large canvas, you may need to adjust the precision with which you see coordinates by setting the tcl_precision variable. This is an issue if you query coordinates, perform a computation on them, and then update the coordinates. (Tcl 8.0 changed the default tcl_precision from 6 to 12.) Scaling and RotationThe scale operation scales the coordinates of one or more canvas items. It is not possible to scale the whole coordinate space. The main problem with this is that you can lose precision when scaling and unscaling objects because their internal coordinates are actually changed by the scale operation. For simple cases this is not a problem, but in extreme cases it can show up. The canvas does not support rotation. ResourcesThere is no resource database support built into the canvas and its items. You can, however, define resources and query them yourself. For example, you could define: *Canvas.foreground: blue This would have no effect by default. However, your code could look for this resource with option get, and specify this color directly for the -fill attribute of your objects:
set fg [option get $c foreground {}]
$c create rect 0 0 10 10 -fill $fg
The main reason to take this approach is to let your users customize the appearance of canvas objects without changing your code. Objects with Many PointsThe canvas implementation seems well optimized to handle lots of canvas objects. However, if an object like a line or a polygon has many points that define it, the implementation ends up scanning through these points linearly. This can adversely affect the time it takes to process mouse events in the area of the canvas containing such an item. Apparently any object in the vicinity of a mouse click is scanned to see if the mouse has hit it so that any bindings can be fired. Selecting Canvas ItemsExample 38-5 on page 596 implements cut and paste of canvas objects. The example exchanges the logical description of canvas objects with the selection mechanism. |
| [ Team LiB ] |
|