Graphics Reference
In-Depth Information
Cartesian
Entry (1,2)
.1
.9
.7
1
WPF
.5
.1
.7
.5
.1
.1
.1
.5
(a)
(b)
(c)
Figure 4.3: (a) A 3
4 matrix with entries between 0 and 1 representing various shades
of gray, from black (0) to white (1). If we convert each entry to a small rectangle of the
corresponding shade of blue, we get the “shaded matrix” shown in (b). (c) If we display
the matrix by displaying the values in column j and row i as a small square centered at
location (i , j) in the Cartesian plane, the resultant image is flipped across the horizontal
axis. If, on the other hand, we do the same thing in WPF coordinates, the result is not
inverted.
×
to vertical position, which is exactly the opposite of the ( x , y ) convention of both
Cartesian and WPF coordinates.]
A further argument, beyond images, is that text in Western writing flows from
top to bottom and from left to right, and thus our way of thinking about 2D layout
also flows in that way. Furthermore, our conventional interfaces start at the top
(that's where the menu bar is) and draw our eyes downward into the content.
Finally, many early raster graphics systems tended to describe the individual pixels
in this way, with ( 0, 0 ) in the top-left corner of the screen.
Regardless of the rationale, this is the convention chosen by the WPF devel-
opers. Fortunately, they also included a mechanism by which one can change
the coordinates used in a canvas. 5 Thus, our test bed has conventional Cartesian
coordinates.
A second version of the test bed, using the y -increases-down coordinate sys-
tem, is also available on the topic's website. You'll probably choose to use that
version when you're experimenting with image data, for instance.
4.3.2 WPF Data Dependencies
Our triangle is a Polygon made from three Point s. Built into WPF is the capabil-
ity to determine when things have changed in a way that necessitates redrawing.
When we say that the GraphPaper is to add this triangle to its collection of chil-
dren, we're not saying anything about actually drawing the triangle. When WPF
decides that it needs to display the canvas, it displays all the canvas's children. We
have simply told it what one of those children is . One thing that prompts WPF to
redisplay the canvas is the information that one of the children has changed. For
example, if we removed the triangle as a child, the canvas would be automatically
5. More precisely, they included something that says how canvas coordinates should be
converted to coordinates in the containing object—a window, a panel, etc.—and this
allows us to invert the y -coordinate and to move ( 0, 0 ) to the center of the canvas, much
as we did with the clock example in Chapter 2.
 
 
Search WWH ::




Custom Search