Graphics Reference
In-Depth Information
it then initializes the menu- and keyboard-command handling. Following this,
we add the graphical items to the GraphPaper that we named Paper ; we locate
that with the FindName method. A Canvas has a Children collection, and with
gp.Children.Add(myTriangle) , we make the triangle we've created a child of
the Canvas , which makes it get displayed within the Canvas .
Now let's look at the details of the creation of the triangle. We declare the
triangle to be a new Polygon and then add several Point stothe Polygon .This
describes the geometry of the triangle, but not its appearance. In WPF, appearance
is characterized by a Stroke (how lines are drawn) and a Fill (how regions are
filled in), each of which is defined by a Brush , which can be remarkably com-
plex; in our case, we'll use simple predefined strokes and fills, available from the
Brushes class. The lines will be drawn in black, and the triangle will be filled with
a light green color. The thickness of the stroke is set to 1.0 ; because of the way
GraphPaper is defined, that's 1. 0 mm. Indeed, recall that all units in a GraphPaper
refer to millimeters. The grid is based on 5 mm distances between grid lines, and
the triangle we've created will be 10 mm tall (although with a brush thickness of
1. 0, it will actually be slightly taller; we imagine the brush being dragged around
the outline, with the brush center passing along the geometric figure 4 ). In sum-
mary, the GraphPaper called Paper provides a place in which to draw geometric
shapes; the units used on the graph paper are millimeters, and the coordinates have
been set up so that ( 0, 0 ) is positioned more or less in the center of the canvas, with
the first coordinate increasing as we move to the right and the second coordinate
increasing as we move up. This latter coordinate direction is not the choice made
in WPF, in which the second coordinate would increase as we move downward.
4.3.1 Coordinate Systems
Why does the second coordinate increase downward in WPF? There are a number
of possible justifications for this (some of which may not even have been in the
designers' minds), and some reasonable criticisms as well. The natural criticism
is that anyone who has studied mathematics is used to the conventional Cartesian
coordinates, in which the y -axis points upward; those only slightly more familiar
with mathematics are used to angles measured from the x -axis and increasing as
the other ray of the angle moves counterclockwise . Why, with all these years of
experience, would one change things?
The counterargument is that several other things are naturally described with a
coordinate that increases as we move downward . Matrices, for instance, have row
and column indices, with the first row at the top, the second row below it, etc. If
we think of a matrix as containing a collection of grayscale values, we can think
of it as describing a black-and-white image. It would be nice if, when it was dis-
played β€œin the obvious way,” the resultant image looked the way we expected from
the matrix representation (see Figure 4.3). But if we use Cartesian coordinates in
the obvious way, the resultant image ends up upside down. [By the way, there's the
further problem that matrix indices are almost always given as β€œ(row, column)”
pairs; unfortunately, the column corresponds to horizontal position and the row
4. The brush in this case actually draws lines that are mitered at the corners so that the
shape remains triangular; this can be adjusted as a property of the Brush ,however.At
very sharp corners, the miter can extend a long distance; because of this, one can also
set a MiterLimit .
 
 
Search WWH ::




Custom Search