• Keine Ergebnisse gefunden

Clipping the Drawing Area

Im Dokument PENPOINT THE POWER OF (Seite 185-190)

If you send a DC one or more drawing messages that result in the creation of an image that extends beyond the boundaries of the selected window, the DC draws only the part of the image that is inside the window. This is the most obvious and common example of the process of clipping, and it happens automatically.

As a rule, windows cannot draw within one another's boundaries. Such behavior would be startling to the user, as welL~s difficult to manage. Since the user is to a great extent in charge of what happens on the screen, the ordering of windows is only partially under your control. The .drawing context ensures that drawing will remain confined to the window to which it is bound.

Figure 9-2 depicts two situations in which clipping becomes an issue. In the first, the target window has no embedded windows, but the user draws

out-ImagePoint: Graphics and Imaging System

side its borders. The dashed line portion of the drawing is not displayed.

Nevertheless, all drawings will be captured by PicSegs, even those that are clipped. The right side of Figure 9-2 shows an "intruder" window overlapping the window in which drawing is taking place. Note that here, clipping ensures that the drawing of a continuous line does not disrupt the contents of the overlapped (and perhaps embedded) windows.

/

./

/

Figure 9-2 Clipping in Two Situations

We saw in Chapter 7 that you can override this normally polite behavior of win-dows within the relationships of a family of winwin-dows (parent and children) so that they share some common drawing area. If you do this and then draw into a window whose visible area overlaps into a parent or sibling window, the DC will behave accordingly, drawing in these other windows' boundaries.

There is another way you can alter the clipping region within which drawing takes place. You can define a subset of your window's total area as the area for drawing. If you do this, then all draw messages sent to the DC will be clipped within that defined area.

Ultimately, however, all drawing takes place through a DC and appears within a clip region that can be an entire window (the common situation), a larger area (in the case of a family of windows that cooperate to permit such behavior), or a portion of an entire window.

Repainting a Window

When part of your window gets dirty, it probably will need repainting. For example, if another window overlaps your window and is moved by the user, this dirties the previously overlapped portion of your window. Fortunately, you need not keep careful track of the status of your window in this regard; Pen-Point will notify your window if it requires repainting.

When you receive a message (msgWinRepaint) indicating your window needs repainting, you send your window msgBeginRepaint. Thereafter, all drawing operations you perform on the window affect only the dirty region until you send msgWinEndRepaint. This process of confining repainting to the area that requires it makes the use of a multiple, overlapped window system more efficient than it would be if every window completely repainted all its contents any time any pixel needed repainting. It also reduces to an absolute minimum any screen flicker or flash the user would see.

You can further control the repainting operation by sending an argument to the window when you send msgWinBeginRepaint. This is sometimes important if the drawing you are performing involves a significant amount of computa-tion, because it can accelerate the update process. Normally, however, you simply don't worry about what portion of your window requires repainting; you let PenPoint handle it.

It probably appears that repainting your entire window is never necessary or appropriate unless all of its contents have been made dirty and require updat-ing. While that is generally true, it is not always the case. You can repaint your window any time you need to without waiting for an instruction from the sys-tem. For instance, you would do this every time the data values or content of your window changed and needed updating. There may be times when you want to handle the repainting this way; PenPoint does not get in the way of your desire to do so. You would simply send msgWinDirtyRect to the window, followed by msgWinUpdate, msgWinBeginPaint, and msgWinEndPaint.

ImagePoint: Graphics and Imaging System

Graphics Primitives

As indicated previously, there are two categories of shapes for which Pen-Point defines primitives: open and closed. There are two other types of graph-ics primitives as well. One relates to displaying text and the other to copying rectangles of bits. We will look at each of these categories of graphics primi-tives in turn.

Open Shape Primitives

PenPoint includes primitives for drawing lines, curves, and arcs.

You use msgDcDrwPolyline to draw aline that can consist of multiple line segments. Each segment is a straight line joining two points on the display.

Figure 9-3 shows two sample lines that might be created with msgDcDrawPolyline.

The longer line consists of several shorter line segments, each of which is a single straight line. The shorter line consists of a single straight line between two points. In both cases, msgDcDrawPolyline takes as an argument a pointer to an array containing the points through which the line is to be drawn, as well as a number that defines the number of points in the array.

Bezier curves can be drawn with the message msgDcDrawBezier. This command takes a pointer to an array of four points that act as control points for the curve. Figure 9-4 shows a sample Bezier curve drawn with this command:

The third type of open shape for which PenPoint defines a graphics primitive is the arc. As you can see from Figure 9-5, an arc is a portion of an ellipse. From PenPoint's perspective, an arc is defined by a rectangle enclosing the ellipse of which the curve is a part and the two points that form the end points of the arc. The message msgOcOrawArcRays produces an arc like the one shown in Figure 9-5. It takes a pointer to a structure called SYSDC_ARC_RAYS, which defines the enclosing rectangle and the two points that delimit the arc.

~ __ ~_m"' ____ ' ___ m~_mmmm ___ '~'m_Q!~~J~,~J:~~~, _____ ", __ Wm'~m_'wmm'ww"'ww_:~~:'w

Figure 9-3 msgDcDrawPolyline Sample Line Output

~ ... ~ .. r..~~.i.~.!;J. ... ~.~.p.~.r. ... . (23 >

Figure 9-4 msgDcDraw8ezier Sample Curve

ImagePoint: Graphics and Imaging System

Drawing Paper

Figure 9-5 msgDcDrawArcRays Sample Arc

Im Dokument PENPOINT THE POWER OF (Seite 185-190)