Add an initial spacer implementation.

git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@5424 4a71c877-e1ca-e34f-864e-861f7616d084
master
Freddie Witherden 2008-07-08 16:55:15 +00:00
parent f99660d986
commit 4f07f76034
2 changed files with 185 additions and 0 deletions

104
lib/betawidget/spacer.c Normal file
View File

@ -0,0 +1,104 @@
#include "spacer.h"
static spacerVtbl vtbl;
const classInfo spacerClassInfo =
{
&widgetClassInfo,
"spacer"
};
spacer *spacerCreate(const char *id, spacerDirection direction)
{
spacer *instance = malloc(sizeof(spacer));
if (instance == NULL)
{
return NULL;
}
// Call the constructor
spacerInit(instance, id, direction);
// Return the new object
return instance;
}
static void spacerInitVtbl(spacer *self)
{
static bool initialised = false;
if (!initialised)
{
// Copy our parents vtable into ours
vtbl.widgetVtbl = *(WIDGET(self)->vtbl);
// Overload widget's destroy, draw and size methods
vtbl.widgetVtbl.destroy = spacerDestroyImpl;
vtbl.widgetVtbl.doDraw = spacerDoDrawImpl;
vtbl.widgetVtbl.getMinSize = spacerGetMinSizeImpl;
vtbl.widgetVtbl.getMaxSize = spacerGetMaxSizeImpl;
initialised = true;
}
// Replace our parents vtable with our own
WIDGET(self)->vtbl = &vtbl.widgetVtbl;
// Set our vtablr
self->vtbl = &vtbl;
}
void spacerInit(spacer *self, const char *id, spacerDirection direction)
{
// Init our parent
widgetInit(WIDGET(self), id);
// Prepare our vtable
spacerInitVtbl(self);
// Set our type
WIDGET(self)->classInfo = &spacerClassInfo;
// Set our direction
self->direction = direction;
}
void spacerDestroyImpl(widget *self)
{
// Call our parents destructor
widgetDestroyImpl(self);
}
size spacerGetMinSizeImpl(widget *self)
{
// We have no minimum size
size minSize = { 0, 0 };
return minSize;
}
size spacerGetMaxSizeImpl(widget *self)
{
size maxSize = { 0, 0 };
switch (SPACER(self)->direction)
{
case SPACER_DIRECTION_HORIZONTAL:
// We have no max horizontal (x-axis) size
maxSize.x = INT16_MAX;
break;
case SPACER_DIRECTION_VERTICAL:
// We have no max vertical (y-axis) size
maxSize.y = INT16_MAX;
break;
}
return maxSize;
}
void spacerDoDrawImpl(widget *self)
{
// NO-OP
(void) self;
}

81
lib/betawidget/spacer.h Normal file
View File

@ -0,0 +1,81 @@
#ifndef SPACER_H_
#define SPACER_H_
#include "widget.h"
/*
* Forward declarations
*/
typedef struct _spacer spacer;
typedef struct _spacerVtbl spacerVtbl;
typedef enum _spacerDirection spacerDirection;
/*
* The directions a spacer can act in
*/
enum _spacerDirection
{
SPACER_DIRECTION_HORIZONTAL,
SPACER_DIRECTION_VERTICAL
};
struct _spacerVtbl
{
widgetVtbl widgetVtbl;
// No additional virtual methods
};
struct _spacer
{
/*
* Parent
*/
widget widget;
/*
* Our vtable
*/
spacerVtbl *vtbl;
/*
* Which direction we should act in
*/
spacerDirection direction;
};
/*
* Type information
*/
extern const classInfo spacerClassInfo;
/*
* Helper macros
*/
#define SPACER(self) (assert(widgetIsA(WIDGET(self), &spacerClassInfo)), \
(spacer *) (self))
/*
* Protected methods
*/
void spacerInit(spacer *self, const char *id, spacerDirection direction);
void spacerDestroyImpl(widget *self);
void spacerDoDrawImpl(widget *self);
size spacerGetMinSizeImpl(widget *self);
size spacerGetMaxSizeImpl(widget *self);
/*
* Public methods
*/
/**
* Constructs a new spacer object and returns it.
*
* @param id The id of the widget.
* @param direction The direction of the spacer.
* @return A pointer to an spacer on success otherwise NULL.
*/
spacer *spacerCreate(const char *id, spacerDirection direction);
#endif /*SPACER_H_*/