Graphics Reference
In-Depth Information
Display-form-factor independence: The display screens on today's
devices come in a huge variety of sizes and aspect ratios (also known as
form factors). To ensure compatibility with a large variety of form factors,
from phone to tablet to desktop, a developer should keep scene geometry
as abstract as possible and nail down the geometry at runtime using logic
that considers the current situation (form factor, window size, etc.). For
example, in deciding on a 1-inch diameter for our clock, we were thinking
about icons on a laptop form factor; we might well choose a different opti-
mal size for a smartphone device. An abstract coordinate system allows for
runtime decision making on actual physical sizing. For further discussion
on this important topic, see Section 2.6.
We now see that the use of an abstract coordinate system is advantageous in
several ways, so let's continue with that strategy.
There's a further advantage to the abstract coordinate system: It's often easier
to specify a shape using small numbers—for example, to say, “I want a disk that
goes from
1to1in x and y, and then I want to move it to be centered at ( 37, 12 ) ,”
rather than saying, “I want a disk that goes from 36 to 38 in x and from 11 to 13
in y .” In the former specification, it's easy to see that the radius of the disk is 1,
and that it's a circular disk rather than an elliptical one. This idea—that it's easier
to work in some coordinate systems than in others—will arise again and again,
and we embody it in a principle:
T HE COORDINATE - SYSTEM / BASIS PRINCIPLE : Always choose a coordi-
nate system or basis in which your work is most convenient, and use transfor-
mations to relate different coordinate systems or bases.
2.4.4 The WPF Canvas Coordinate System
At this point, you have been informed of only one characteristic of WPF canvas
coordinates. Figure 2.11 demonstrates the other important features: The origin
(0,0) lies at the upper-left corner of the canvas, the positive x -axis extends to the
right, the positive y -axis extends downward, and the canvas is “bounded” on all
four sides (represented by the light-blue rectangle in the figure). That is to say,
each WPF canvas has a definitive width and height (usually controlled by layout
logic as described previously). In the common case of ClipToBounds=”True” ,
these bounds are strictly enforced, so any visual information lying outside the
bounds is invisible. 4
With this information, we can now return to developing our clock applica-
tion. Let's prepare by reviewing the sequence of “spaces” through which the
scene's geometry travels from abstract to physical to device, shown in Figure 2.12.
We already discussed the application and WPF canvas coordinate systems, and in
Section 2.4.5 we show you how the former system is mapped to the latter. So here
we'll briefly address the final transition shown in the sequence, the mapping of the
WPF canvas to actual pixels on the display device. This part of the pipeline is not
4. As we implement this application throughout Section 2.4, we'll assume the canvas
is large enough to show the entire clock, but Inline Exercise 2.5 will invite you to
investigate what happens when it's not.
 
 
 
Search WWH ::




Custom Search