|
|

|
|
|
Listing 1: Protecting the application from having access to an
uninitialized Box
|
void drawableInit(Drawable *drawablePtr, DrawableType type,
int left, int top, int right, int bottom)
{
drawablePtr->color = BLACK;
drawablePtr->area.left = left;
drawablePtr->area.top = top;
drawablePtr->area.right = right;
drawablePtr->area.bottom = bottom;
drawablePtr->type = type;
drawablePtr->parentPtr = NULL;
drawablePtr->nextContainedPtr = NULL;
/*
The object
is not initially dirty. It will be marked dirty when
it is added to a container
*/
drawablePtr->nextDirtyDrawablePtr = NULL;
drawablePtr->dirty = FALSE;
drawablePtr->oldParentPtr = NULL;
}
Box * boxCreate(int left, int top, int right, int bottom)
{
Box *boxPtr;
boxPtr = salloc(sizeof(Box));
assert (boxPtr != NULL);
drawableInit(&boxPtr->drawable, BOX, left, top, right, bottom);
boxPtr->filled = FALSE;
return boxPtr;
}
Text * textCreate(int left, int top, char *string)
{
Text *textPtr;
int right;
int bottom;
textPtr = salloc(sizeof(Line));
assert(textPtr != NULL);
#ifdef USING_BGI
right = left + textwidth(string);
bottom = top + textheight(string);
#endif
drawableInit(&textPtr->drawable,TEXT,left,top,right,bottom);
textPtr->string = string;
return textPtr;
|
Back
|
|
|
|
|