[Classes] [Prev] [Next] [Methods]

CDrawingContext

Methods Index

Heritage
Description
Usage
Protected Data Members
Public Methods
Constructor, Destructor, and Initializer Methods
Drawing Methods
State Methods
Invalidate Methods
Protected Methods
Implementation Methods
Canceled Methods

CDrawingContext


Heritage

Superclass: CStackable

Subclasses: None


Description

The CDrawingContext class serves as a wrapper to the XVT Portability Toolkit drawing protocol. It allows for use of the XVT-Power++ mathematical objects CPoint and CRect, and it takes advantage of drawing tools through the CEnvironment class.

The CDrawingContext class also factors out the need to set global units before converting to the XVT Portability Toolkit mathematical structures. CDrawingContext methods always assumes global, window relative coordinates.

Since CDrawingContext uses a stacking scheme, it is possible to call other methods that create CDrawingContext objects; when those methods go out of the scope, the previous drawing context is brought back into scope. This is important because it allows you to avoid reapplying the environment to the drawing window.


Usage

A drawing context is created on the stack, typically, within a CView-derived Draw method. When you construct the CDrawingContext, initializing it with the CView, the drawing context object creates a local copy of the view's environment. This is done so that changes can be made without affecting the shared environment. In addition, the drawing object sets the global units.

The following is an example of constructing a CDrawingContext object initialized with a CView (CMyView):

void CMyView::Draw(const CRect &theFrame)
{
CView::Draw(theFrame);
CDrawingContext aDC(this); // makes a copy of
// the environment
aDC.DrawOval(GetGlobalFrame());
}
A drawing context does not have to be created relative to a CView, like this:

void CSomeClass::PaintSomething(void)
{
CDrawingContext aDC(itsCWindow, CEnvironment());
aDC.DrawRect(itsSize, 15, 15); // rounded rect
}
See Also: For more information on the XVT Portability Toolkit's drawing protocol, see the xvt_dwin_* sections in the XVT Portability Toolkit Reference.


Protected Data Members

BOOLEAN itIsView; The flag for window or view usage
BOOLEAN itIsUpdateTools; The flag for updating tools
CView *itsView; The view
CEnvironment itsEnv; The current drawing environment
short isLocalQueueOverride Flag for determining if local or global region update policy is to be used
short isLocalRegionedQueue Are update regions being queued by local object
static short isRegionedQueue Are update regions being queued in general
RWOrdered itsInvalidateQueue List of invalidated regions (CRectRWC*)


Public Methods

Constructor, Destructor, and Initializer Methods

CDrawingContext(CView *theView);
CDrawingContext(CWindow *theWindow, 
const CEnvironment &theEnvironment);
virtual ~CDrawingContext();

Drawing Methods

void DrawLine(const CPoint &theStartPoint,
const CPoint &theEndPoint,
BOOLEAN theBegArrow = FALSE,
BOOLEAN theEndArrow = FALSE);
void DrawLine(const CPoint &theEndPoint,
BOOLEAN theBegArrow = FALSE,
BOOLEAN theEndArrow = FALSE);
void DrawIcon(int theIconId, const CPoint &theTopLeft);
void DrawArc(const CRect &theFrame,
const CPoint &theStartPnt,
const CPoint &theEndPnt);
void DrawPie(const CRect &theFrame,
const CPoint &theStartPnt,
const CPoint &theEndPnt);
void DrawPolygon(const RWOrdered &thePoints,
BOOLEAN thePolyIsFilled = TRUE);
void DrawText(const CStringRW &theText, 
const CPoint &theBaseLine);
void DrawPicture(PICTURE thePict, 
const CRect &theViewRegion);
void DrawRect(const CRect &theFrame,
short theWidthRounded = 0, // w & h in pixels
short theHeightRounded = 0);
void DrawPixmap(XVT_PIXMAP thePixmap,
const CRect &theSourceRegion,
const CRect &theDestRegion);
void DrawImage(XVT_IMAGE theImage,
const CRect &theSourceRegion,
const CRect &theDestRegion);
void DrawOval(const CRect &theFrame);
void DrawOutsetFrame(const CRect &theOuterFrame,
int theBorderWidth, /* in pixels */
COLOR theUpShadow,
COLOR theDownShadow);
void DrawInsetFrame(const CRect &theOuterFrame,
int theBorderWidth, /* in pixels */
COLOR theUpShadow,
COLOR theDownShadow);
void DrawOutsetText(
const CStringRW& theText,
const CPoint& theBaseline,
COLOR theUpShadow = COLOR_WHITE,
COLOR theDownShadow = COLOR_GRAY);
void DrawInsetText(
const CStringRW& theText,
const CPoint& theBaseline,
COLOR theUpShadow = COLOR_WHITE,
COLOR theDownShadow = COLOR_GRAY);

State Methods

void SetLinePos(const CPoint &theLoc);
void SetEnv(const CEnvironment &theEnvironment);
CEnvironment & GetEnv(void);
CEnvironment & operator () (void);
void SetClip(const CRect &theClipFrame = MAXRect);
CRect GetClip(void);
void SetCaretPos(const CPoint &theLoc);
void SetCaretVisible(BOOLEAN isVisible = TRUE);
void SetCaretSize(int theWidth, int theHeight);
void ScrollRect(const CRect &theRegion, 
int theHDist,
int theVDist);
void InvalidateRect(const CRect &theRegion = MAXRect);
BOOLEAN IsUpdateNeeded(const CRect &theRegion);

Invalidate Methods

The following methods are used to invalidate many regions of a window at once. Some platforms, notably the Mac, can efficiently invalidate many discontiguous regions. However, other platforms work most efficiently when invalidating the sum of the regions: the following interface supports this notion. By default all regions are unioned (QueueInvalidate) and invalidated (FlushInvalidate) as a single frame, except on the Mac where each region is invalidated. This behavior may be overridden for all uses by calling SetRegionedQueue(). Also, there are cases where you will always want to send independent invalidates, but on a local basis. SetLocalRegionedQueue() will set the behavior locally to a CDrawingContext instance.

void QueueInvalidate( const CRect& theRect );
void FlushInvalidate();
void ClearInvalidate();
void SetLocalRegionedQueue( BOOLEAN isRegioned );
static BOOLEAN IsRegionedQueue();
static void SetRegionedQueue( BOOLEAN isRegioned );

Protected Methods

Implementation Methods

void MakeCurrent(void);
virtual void DoUpdate(void);

Canceled Methods

The new and delete operators are overloaded to provide CStackable functionality:

CDrawingContext(const CDrawingContext &);
CDrawingContext& operator= (const CDrawingContext &);


[Classes] [Prev] [Next] [Methods]

support@xvt.com


Visit our online help desk for tech support

Copyright © 2009, Providence Software Solutions Inc. All rights reserved.