03.01.2013 Views

Chapter 1

Chapter 1

Chapter 1

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

The two points that define Trect can be interpreted by specific graphics implementations in<br />

different ways. One common interpretation is to place the top-left point inside the rectangle,<br />

and the bottom-right point is just outside it, as shown in Figure 11.4:<br />

Figure 11.4<br />

This definition makes some things easier, such as calculating the size, because you simply<br />

subtract the x and y coordinates of the top-left from the bottom-right point. It also makes<br />

other things harder, such as rubber- banding calculations for interactively drawing a<br />

rectangle, because you have to add (1, 1) to the pointer coordinates to include the bottomright<br />

corner correctly. If TRect is defined to include its bottom-right corner, it simply makes<br />

different things easier and different things harder. It's important to remember that the<br />

definition of the rectangle depends on the specific graphics interpretation.<br />

Rectangles should be normalized, so that iTl coordinates are never greater than<br />

corresponding iBr coordinates. If you perform a calculation on a TRect that might violate<br />

this condition, call Normalize() to clear things up, by swapping the x coordinate values<br />

and/or y coordinate values as necessary.<br />

Region-related classes<br />

Several region-related classes are also defined in e32std.h. These define a region of<br />

arbitrary shape as the union of several rectangles. The region classes are used extensively<br />

by the window server, but only in specialized application programs.<br />

A region can potentially have very many rectangles so that the region classes, in general,<br />

can allocate resources on the heap. They are heavily optimized so that, if only relatively few<br />

rectangles are needed to define the region, then no heap-based allocation is necessary. So,<br />

while points, rectangles, and sizes are simple, T classes that are easy to allocate anywhere<br />

and pass around in client-server call's regions require more careful management and like C<br />

classes, need to be deleted or cleaned up when no longer required.<br />

11.2.2 Setting up the Graphics Context<br />

CGraphicsContext holds several important items of context for drawing functions:<br />

� Pen<br />

� Brush<br />

� Font<br />

� Current position<br />

� Origin<br />

� Clipping Region<br />

� Justification.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!