[Home] [Prev] [Next] [Up]


XGDraw class

Initializes an XGView object for drawing.

Usage:

#include <XView.h>

class XGDraw;

Description

This class should be created on the stack.

This provides a stack-safe mechanism for initializing and shutting down drawing into an XGView.

The constructor for this class is serialized to allow only one thread at a time to draw. As drawing contexts are created and destroyed on the stack, and as only one thread at a time is allowed to draw, there are a few consequences.

First, as only one thread at a time has access, holding the XGDraw object is inadvisable. This means that a drawing process which may take a while to complete should be broken into several smaller pieces.

Second, there is always one global drawing object which is being drawn into. This allows multithreaded drawing to take place safely on the Macintosh, where the native drawing environment is not reentrant.

Normally, when you have a method which needs to draw into a view, you would simply create this object on the stack when the method enters:

XGDraw draw(this);

Assuming, of course, that the calling method is a member of the XGView you want to draw into.

Construction/Destruction

XGDraw::XGDraw(XGView *view)

This constructs this drawing object, and initializes the specified view as the current drawing view. This will spin-lock if another task is currently drawing. If this task is currently drawing, this will push the prior drawing context onto an internal stack.

XGDraw::~XGDraw()

This releases the view as the current drawing view, and pops the drawing stack. If the drawing stack is empty, this releases the spinlock on other tasks which want to draw.

State Support

static XGDraw *XGDraw::GetDraw()

This gets the current drawing object. Because there is only one drawing context (as only one thread at a time can draw), this is a global resource.

Clipping

void XGDraw:ClipRect(Rect *area = NULL);

This clips the specified area in the current drawing context. That is, this intersects the current view rectangle that is visible with the specified rectangle. If the parameter is NULL, this resets the clipping area to the full area of the view.

Drawing Context Handle

HDC XGDraw:GetDC(void)

Windows OS Only. This returns the Device Context handle for the current drawing object. This is used in the Win32 version of the YAAF library for drawing.

NOTE: The YAAF library does not encapsulate drawing. Thus, when writing the drawing routine, you customarly have to write it twice: one version for the Macintosh, and the other version for Windows, separated by the appropriate OPT_xxxOS macro.

I did this for a simple reason: the various drawing APIs are so convoluted, and contain enough subtle differences, that providing a single API for drawing just didn't make any sense. I mean, even the LineTo() routines differ on drawing the last pixel!

So bah! I just punt, and add the work to the user. I mean, it's not like the Windows GDI or the MacOS Quickdraw routines are rocket science!


[Home] [Prev] [Next] [Up]