Use constructors/destructors for WIDGETs, unduplicating a tonne of probable copy/paste abuse in the process.
parent
7a49623b7f
commit
bd2f6fb7ce
|
@ -30,6 +30,43 @@
|
|||
#include "lib/ivis_common/pieblitfunc.h"
|
||||
#include "lib/ivis_common/piepalette.h"
|
||||
|
||||
W_BARGRAPH::W_BARGRAPH(W_BARINIT const *init)
|
||||
: WIDGET(init, WIDG_BARGRAPH)
|
||||
, barPos(init->orientation)
|
||||
, majorSize(init->size)
|
||||
, minorSize(init->minorSize)
|
||||
, iRange(init->iRange)
|
||||
, iValue(0)
|
||||
, iOriginal(0)
|
||||
, majorCol(init->sCol)
|
||||
, minorCol(init->sMinorCol)
|
||||
, pTip(init->pTip)
|
||||
{
|
||||
/* Set the display function */
|
||||
if (display == NULL)
|
||||
{
|
||||
if (init->style & WBAR_TROUGH)
|
||||
{
|
||||
display = barGraphDisplayTrough;
|
||||
}
|
||||
else if (init->style & WBAR_DOUBLE)
|
||||
{
|
||||
display = barGraphDisplayDouble;
|
||||
}
|
||||
else
|
||||
{
|
||||
display = barGraphDisplay;
|
||||
}
|
||||
}
|
||||
|
||||
/* Set the minor colour if necessary */
|
||||
// Actually, this sets the major colour to the minor colour. The minor colour used to be left completely uninitialised... Wonder what it was for..?
|
||||
if (style & WBAR_DOUBLE)
|
||||
{
|
||||
majorCol = minorCol;
|
||||
}
|
||||
}
|
||||
|
||||
/* Create a barGraph widget data structure */
|
||||
W_BARGRAPH* barGraphCreate(const W_BARINIT* psInit)
|
||||
{
|
||||
|
@ -59,67 +96,13 @@ W_BARGRAPH* barGraphCreate(const W_BARINIT* psInit)
|
|||
}
|
||||
|
||||
/* Allocate the required memory */
|
||||
W_BARGRAPH *psWidget = new W_BARGRAPH;
|
||||
W_BARGRAPH *psWidget = new W_BARGRAPH(psInit);
|
||||
if (psWidget == NULL)
|
||||
{
|
||||
debug(LOG_FATAL, "barGraphCreate: Out of memory");
|
||||
abort();
|
||||
return NULL;
|
||||
}
|
||||
/* Allocate the memory for the tip and copy it if necessary */
|
||||
if (psInit->pTip)
|
||||
{
|
||||
psWidget->pTip = psInit->pTip;
|
||||
}
|
||||
else
|
||||
{
|
||||
psWidget->pTip = NULL;
|
||||
}
|
||||
|
||||
/* Initialise the structure */
|
||||
psWidget->type = WIDG_BARGRAPH;
|
||||
psWidget->id = psInit->id;
|
||||
psWidget->formID = psInit->formID;
|
||||
psWidget->style = psInit->style;
|
||||
psWidget->x = psInit->x;
|
||||
psWidget->y = psInit->y;
|
||||
psWidget->width = psInit->width;
|
||||
psWidget->height = psInit->height;
|
||||
psWidget->callback = psInit->pCallback;
|
||||
psWidget->pUserData = psInit->pUserData;
|
||||
psWidget->UserData = psInit->UserData;
|
||||
psWidget->barPos = psInit->orientation;
|
||||
psWidget->majorSize = psInit->size;
|
||||
psWidget->minorSize = psInit->minorSize;
|
||||
psWidget->iRange = psInit->iRange;
|
||||
|
||||
/* Set the display function */
|
||||
if (psInit->pDisplay)
|
||||
{
|
||||
psWidget->display = psInit->pDisplay;
|
||||
}
|
||||
else if (psInit->style & WBAR_TROUGH)
|
||||
{
|
||||
psWidget->display = barGraphDisplayTrough;
|
||||
}
|
||||
else if (psInit->style & WBAR_DOUBLE)
|
||||
{
|
||||
psWidget->display = barGraphDisplayDouble;
|
||||
}
|
||||
else
|
||||
{
|
||||
psWidget->display = barGraphDisplay;
|
||||
}
|
||||
/* Set the major colour */
|
||||
psWidget->majorCol = psInit->sCol;
|
||||
|
||||
/* Set the minor colour if necessary */
|
||||
if (psInit->style & WBAR_DOUBLE)
|
||||
{
|
||||
psWidget->majorCol = psInit->sMinorCol;
|
||||
}
|
||||
|
||||
barGraphInitialise(psWidget);
|
||||
|
||||
return psWidget;
|
||||
}
|
||||
|
@ -133,12 +116,6 @@ void barGraphFree(W_BARGRAPH *psWidget)
|
|||
delete psWidget;
|
||||
}
|
||||
|
||||
/* Initialise a barGraph widget before running it */
|
||||
void barGraphInitialise(W_BARGRAPH *psWidget)
|
||||
{
|
||||
(void)psWidget;
|
||||
}
|
||||
|
||||
|
||||
/* Set the current size of a bar graph */
|
||||
void widgSetBarSize(W_SCREEN *psScreen, UDWORD id, UDWORD iValue)
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
|
||||
struct W_BARGRAPH : public WIDGET
|
||||
{
|
||||
W_BARGRAPH(W_BARINIT const *init);
|
||||
|
||||
UWORD barPos; // Orientation of the bar on the widget
|
||||
UWORD majorSize; // Percentage of the main bar that is filled
|
||||
UWORD minorSize; // Percentage of the minor bar if there is one
|
||||
|
@ -45,9 +47,6 @@ extern W_BARGRAPH* barGraphCreate(const W_BARINIT* psInit);
|
|||
/* Free the memory used by a barGraph */
|
||||
extern void barGraphFree(W_BARGRAPH *psWidget);
|
||||
|
||||
/* Initialise a barGraph widget before running it */
|
||||
extern void barGraphInitialise(W_BARGRAPH *psWidget);
|
||||
|
||||
/* Respond to a mouse moving over a barGraph */
|
||||
extern void barGraphHiLite(W_BARGRAPH *psWidget, W_CONTEXT *psContext);
|
||||
|
||||
|
|
|
@ -38,6 +38,22 @@ BOOL buttonStartUp(void)
|
|||
return true;
|
||||
}
|
||||
|
||||
W_BUTTON::W_BUTTON(W_BUTINIT const *init)
|
||||
: WIDGET(init, WIDG_BUTTON)
|
||||
, pText(init->pText)
|
||||
, pTip(init->pTip)
|
||||
, HilightAudioID(WidgGetHilightAudioID())
|
||||
, ClickedAudioID(WidgGetClickedAudioID())
|
||||
, AudioCallback(WidgGetAudioCallback())
|
||||
, FontID(init->FontID)
|
||||
{
|
||||
if (display == NULL)
|
||||
{
|
||||
display = buttonDisplay;
|
||||
}
|
||||
|
||||
buttonInitialise(this);
|
||||
}
|
||||
|
||||
/* Create a button widget data structure */
|
||||
W_BUTTON* buttonCreate(const W_BUTINIT* psInit)
|
||||
|
@ -50,59 +66,13 @@ W_BUTTON* buttonCreate(const W_BUTINIT* psInit)
|
|||
}
|
||||
|
||||
/* Allocate the required memory */
|
||||
W_BUTTON *psWidget = new W_BUTTON;
|
||||
W_BUTTON *psWidget = new W_BUTTON(psInit);
|
||||
if (psWidget == NULL)
|
||||
{
|
||||
debug(LOG_FATAL, "buttonCreate: Out of memory" );
|
||||
abort();
|
||||
return NULL;
|
||||
}
|
||||
/* Allocate memory for the text and copy it if necessary */
|
||||
if (psInit->pText)
|
||||
{
|
||||
psWidget->pText = psInit->pText;
|
||||
}
|
||||
else
|
||||
{
|
||||
psWidget->pText = NULL;
|
||||
}
|
||||
/* Allocate the memory for the tip and copy it if necessary */
|
||||
if (psInit->pTip)
|
||||
{
|
||||
psWidget->pTip = psInit->pTip;
|
||||
}
|
||||
else
|
||||
{
|
||||
psWidget->pTip = NULL;
|
||||
}
|
||||
|
||||
/* Initialise the structure */
|
||||
psWidget->type = WIDG_BUTTON;
|
||||
psWidget->id = psInit->id;
|
||||
psWidget->formID = psInit->formID;
|
||||
psWidget->style = psInit->style;
|
||||
psWidget->x = psInit->x;
|
||||
psWidget->y = psInit->y;
|
||||
psWidget->width = psInit->width;
|
||||
psWidget->height = psInit->height;
|
||||
psWidget->callback = psInit->pCallback;
|
||||
psWidget->pUserData = psInit->pUserData;
|
||||
psWidget->UserData = psInit->UserData;
|
||||
psWidget->AudioCallback = WidgGetAudioCallback();
|
||||
psWidget->HilightAudioID = WidgGetHilightAudioID();
|
||||
psWidget->ClickedAudioID = WidgGetClickedAudioID();
|
||||
|
||||
if (psInit->pDisplay)
|
||||
{
|
||||
psWidget->display = psInit->pDisplay;
|
||||
}
|
||||
else
|
||||
{
|
||||
psWidget->display = buttonDisplay;
|
||||
}
|
||||
psWidget->FontID = psInit->FontID;
|
||||
|
||||
buttonInitialise(psWidget);
|
||||
|
||||
return psWidget;
|
||||
}
|
||||
|
|
|
@ -40,6 +40,8 @@
|
|||
|
||||
struct W_BUTTON : public WIDGET
|
||||
{
|
||||
W_BUTTON(W_BUTINIT const *init);
|
||||
|
||||
UDWORD state; // The current button state
|
||||
const char *pText; // The text for the button
|
||||
const char *pTip; // The tool tip for the button
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
#include "lib/framework/frame.h"
|
||||
#include "lib/framework/utf.h"
|
||||
#include "lib/framework/wzapp_c.h"
|
||||
#include "widget.h"
|
||||
#include "widgint.h"
|
||||
#include "editbox.h"
|
||||
|
@ -54,11 +55,41 @@
|
|||
/* Calculate how much of the start of a string can fit into the edit box */
|
||||
static void fitStringStart(utf_32_char *pBuffer, UDWORD boxWidth, UWORD *pCount, UWORD *pCharWidth);
|
||||
|
||||
W_EDITBOX::W_EDITBOX(W_EDBINIT const *init)
|
||||
: WIDGET(init, WIDG_EDITBOX)
|
||||
, FontID(init->FontID)
|
||||
, blinkOffset(wzGetTicks())
|
||||
, pBoxDisplay(init->pBoxDisplay)
|
||||
, pFontDisplay(init->pFontDisplay)
|
||||
, HilightAudioID(WidgGetHilightAudioID())
|
||||
, ClickedAudioID(WidgGetClickedAudioID())
|
||||
, AudioCallback(WidgGetAudioCallback())
|
||||
{
|
||||
char const *text = init->pText;
|
||||
if (!text)
|
||||
{
|
||||
text = "";
|
||||
}
|
||||
aText = UTF8toUTF32(text, &aTextAllocated);
|
||||
|
||||
if (display == NULL)
|
||||
{
|
||||
display = editBoxDisplay;
|
||||
}
|
||||
|
||||
editBoxInitialise(this);
|
||||
|
||||
init_scrap();
|
||||
}
|
||||
|
||||
W_EDITBOX::~W_EDITBOX()
|
||||
{
|
||||
free(aText);
|
||||
}
|
||||
|
||||
/* Create an edit box widget data structure */
|
||||
W_EDITBOX* editBoxCreate(const W_EDBINIT* psInit)
|
||||
{
|
||||
const char *text;
|
||||
|
||||
if (psInit->style & ~(WEDB_PLAIN | WIDG_HIDDEN | WEDB_DISABLED))
|
||||
{
|
||||
ASSERT( false, "Unknown edit box style" );
|
||||
|
@ -66,7 +97,7 @@ W_EDITBOX* editBoxCreate(const W_EDBINIT* psInit)
|
|||
}
|
||||
|
||||
/* Allocate the required memory */
|
||||
W_EDITBOX *psWidget = new W_EDITBOX;
|
||||
W_EDITBOX *psWidget = new W_EDITBOX(psInit);
|
||||
if (psWidget == NULL)
|
||||
{
|
||||
debug(LOG_FATAL, "editBoxCreate: Out of memory");
|
||||
|
@ -74,47 +105,6 @@ W_EDITBOX* editBoxCreate(const W_EDBINIT* psInit)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/* Initialise the structure */
|
||||
psWidget->type = WIDG_EDITBOX;
|
||||
psWidget->id = psInit->id;
|
||||
psWidget->formID = psInit->formID;
|
||||
psWidget->style = psInit->style;
|
||||
psWidget->x = psInit->x;
|
||||
psWidget->y = psInit->y;
|
||||
psWidget->width = psInit->width;
|
||||
psWidget->height = psInit->height;
|
||||
psWidget->FontID = psInit->FontID;
|
||||
if (psInit->pDisplay)
|
||||
{
|
||||
psWidget->display = psInit->pDisplay;
|
||||
}
|
||||
else
|
||||
{
|
||||
psWidget->display = editBoxDisplay;
|
||||
}
|
||||
psWidget->callback = psInit->pCallback;
|
||||
psWidget->pUserData = psInit->pUserData;
|
||||
psWidget->UserData = psInit->UserData;
|
||||
psWidget->pBoxDisplay = psInit->pBoxDisplay;
|
||||
psWidget->pFontDisplay = psInit->pFontDisplay;
|
||||
|
||||
psWidget->AudioCallback = WidgGetAudioCallback();
|
||||
psWidget->HilightAudioID = WidgGetHilightAudioID();
|
||||
psWidget->ClickedAudioID = WidgGetClickedAudioID();
|
||||
|
||||
text = psInit->pText;
|
||||
if (!text)
|
||||
{
|
||||
text = "";
|
||||
}
|
||||
psWidget->aText = UTF8toUTF32(text, &psWidget->aTextAllocated);
|
||||
|
||||
editBoxInitialise(psWidget);
|
||||
|
||||
psWidget->blinkOffset = SDL_GetTicks();
|
||||
|
||||
init_scrap();
|
||||
|
||||
return psWidget;
|
||||
}
|
||||
|
||||
|
@ -122,7 +112,6 @@ W_EDITBOX* editBoxCreate(const W_EDBINIT* psInit)
|
|||
/* Free the memory used by an edit box */
|
||||
void editBoxFree(W_EDITBOX *psWidget)
|
||||
{
|
||||
free(psWidget->aText);
|
||||
delete psWidget;
|
||||
}
|
||||
|
||||
|
|
|
@ -39,6 +39,9 @@
|
|||
|
||||
struct W_EDITBOX : public WIDGET
|
||||
{
|
||||
W_EDITBOX(W_EDBINIT const *init);
|
||||
~W_EDITBOX();
|
||||
|
||||
UDWORD state; // The current edit box state
|
||||
utf_32_char *aText; // The text in the edit box
|
||||
size_t aTextAllocated; // Allocated bytes.
|
||||
|
|
|
@ -46,24 +46,36 @@ struct TAB_POS
|
|||
SDWORD TabMultiplier; //Added to keep track of tab scroll
|
||||
};
|
||||
|
||||
/* Set default colours for a form */
|
||||
static void formSetDefaultColours(W_FORM *psForm)
|
||||
W_FORM::W_FORM(W_FORMINIT const *init)
|
||||
: WIDGET(init, WIDG_FORM)
|
||||
, disableChildren(init->disableChildren)
|
||||
, Ax0(0), Ay0(0), Ax1(0), Ay1(0) // These assignments were previously done by a memset.
|
||||
, animCount(0)
|
||||
, startTime(0) // This assignment was previously done by a memset.
|
||||
, psLastHiLite(NULL)
|
||||
, psWidgets(NULL)
|
||||
{
|
||||
psForm->aColours[WCOL_BKGRND] = WZCOL_FORM_BACKGROUND;
|
||||
psForm->aColours[WCOL_TEXT] = WZCOL_FORM_TEXT;
|
||||
psForm->aColours[WCOL_LIGHT] = WZCOL_FORM_LIGHT;
|
||||
psForm->aColours[WCOL_DARK] = WZCOL_FORM_DARK;
|
||||
psForm->aColours[WCOL_HILITE] = WZCOL_FORM_HILITE;
|
||||
psForm->aColours[WCOL_CURSOR] = WZCOL_FORM_CURSOR;
|
||||
psForm->aColours[WCOL_TIPBKGRND] = WZCOL_FORM_TIP_BACKGROUND;
|
||||
psForm->aColours[WCOL_DISABLE] = WZCOL_FORM_DISABLE;
|
||||
if (display == NULL)
|
||||
{
|
||||
display = formDisplay;
|
||||
}
|
||||
|
||||
aColours[WCOL_BKGRND] = WZCOL_FORM_BACKGROUND;
|
||||
aColours[WCOL_TEXT] = WZCOL_FORM_TEXT;
|
||||
aColours[WCOL_LIGHT] = WZCOL_FORM_LIGHT;
|
||||
aColours[WCOL_DARK] = WZCOL_FORM_DARK;
|
||||
aColours[WCOL_HILITE] = WZCOL_FORM_HILITE;
|
||||
aColours[WCOL_CURSOR] = WZCOL_FORM_CURSOR;
|
||||
aColours[WCOL_TIPBKGRND] = WZCOL_FORM_TIP_BACKGROUND;
|
||||
aColours[WCOL_DISABLE] = WZCOL_FORM_DISABLE;
|
||||
}
|
||||
|
||||
|
||||
/* Create a plain form widget */
|
||||
static W_FORM* formCreatePlain(const W_FORMINIT* psInit)
|
||||
{
|
||||
/* Allocate the required memory */
|
||||
W_FORM *psWidget = new W_FORM;
|
||||
W_FORM *psWidget = new W_FORM(psInit);
|
||||
if (psWidget == NULL)
|
||||
{
|
||||
debug(LOG_FATAL, "formCreatePlain: Out of memory");
|
||||
|
@ -71,40 +83,6 @@ static W_FORM* formCreatePlain(const W_FORMINIT* psInit)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/* Initialise the structure */
|
||||
psWidget->type = WIDG_FORM;
|
||||
psWidget->id = psInit->id;
|
||||
psWidget->formID = psInit->formID;
|
||||
psWidget->style = psInit->style;
|
||||
psWidget->disableChildren = psInit->disableChildren;
|
||||
psWidget->animCount = 0;
|
||||
psWidget->x = psInit->x;
|
||||
psWidget->y = psInit->y;
|
||||
psWidget->width = psInit->width;
|
||||
psWidget->height = psInit->height;
|
||||
|
||||
if (psInit->pDisplay)
|
||||
{
|
||||
psWidget->display = psInit->pDisplay;
|
||||
}
|
||||
else
|
||||
{
|
||||
psWidget->display = formDisplay;
|
||||
}
|
||||
psWidget->callback = psInit->pCallback;
|
||||
psWidget->pUserData = psInit->pUserData;
|
||||
psWidget->UserData = psInit->UserData;
|
||||
psWidget->psWidgets = NULL;
|
||||
psWidget->psLastHiLite = NULL;
|
||||
formSetDefaultColours(psWidget);
|
||||
|
||||
// These assignments were previously done by a memset.
|
||||
psWidget->psNext = NULL;
|
||||
psWidget->Ax0 = psWidget->Ay0 = psWidget->Ax1 = psWidget->Ay1 = 0;
|
||||
psWidget->startTime = 0;
|
||||
|
||||
formInitialise(psWidget);
|
||||
|
||||
return psWidget;
|
||||
}
|
||||
|
||||
|
@ -120,11 +98,25 @@ static void formFreePlain(W_FORM *psWidget)
|
|||
}
|
||||
|
||||
|
||||
W_CLICKFORM::W_CLICKFORM(W_FORMINIT const *init)
|
||||
: W_FORM(init)
|
||||
, state(WCLICK_NORMAL)
|
||||
, pTip(init->pTip)
|
||||
, HilightAudioID(WidgGetHilightAudioID())
|
||||
, ClickedAudioID(WidgGetClickedAudioID())
|
||||
, AudioCallback(WidgGetAudioCallback())
|
||||
{
|
||||
if (init->pDisplay == NULL)
|
||||
{
|
||||
display = formDisplayClickable;
|
||||
}
|
||||
}
|
||||
|
||||
/* Create a plain form widget */
|
||||
static W_CLICKFORM* formCreateClickable(const W_FORMINIT* psInit)
|
||||
{
|
||||
/* Allocate the required memory */
|
||||
W_CLICKFORM *psWidget = new W_CLICKFORM;
|
||||
W_CLICKFORM *psWidget = new W_CLICKFORM(psInit);
|
||||
if (psWidget == NULL)
|
||||
{
|
||||
debug(LOG_FATAL, "formCreateClickable: Out of memory");
|
||||
|
@ -132,45 +124,6 @@ static W_CLICKFORM* formCreateClickable(const W_FORMINIT* psInit)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/* Initialise the structure */
|
||||
psWidget->type = WIDG_FORM;
|
||||
psWidget->id = psInit->id;
|
||||
psWidget->formID = psInit->formID;
|
||||
psWidget->style = psInit->style;
|
||||
psWidget->disableChildren = psInit->disableChildren;
|
||||
psWidget->animCount = 0;
|
||||
psWidget->x = psInit->x;
|
||||
psWidget->y = psInit->y;
|
||||
psWidget->width = psInit->width;
|
||||
psWidget->height = psInit->height;
|
||||
psWidget->callback = psInit->pCallback;
|
||||
psWidget->pUserData = psInit->pUserData;
|
||||
psWidget->UserData = psInit->UserData;
|
||||
|
||||
psWidget->AudioCallback = WidgGetAudioCallback();
|
||||
psWidget->HilightAudioID = WidgGetHilightAudioID();
|
||||
psWidget->ClickedAudioID = WidgGetClickedAudioID();
|
||||
|
||||
if (psInit->pDisplay)
|
||||
{
|
||||
psWidget->display = psInit->pDisplay;
|
||||
}
|
||||
else
|
||||
{
|
||||
psWidget->display = formDisplayClickable;
|
||||
}
|
||||
psWidget->psWidgets = NULL;
|
||||
psWidget->psLastHiLite = NULL;
|
||||
psWidget->pTip = psInit->pTip;
|
||||
formSetDefaultColours((W_FORM *)psWidget);
|
||||
|
||||
// These assignments were previously done by a memset.
|
||||
psWidget->psNext = NULL;
|
||||
psWidget->Ax0 = psWidget->Ay0 = psWidget->Ax1 = psWidget->Ay1 = 0;
|
||||
psWidget->startTime = 0;
|
||||
|
||||
formInitialise((W_FORM *)psWidget);
|
||||
|
||||
return psWidget;
|
||||
}
|
||||
|
||||
|
@ -187,12 +140,56 @@ static void formFreeClickable(W_CLICKFORM *psWidget)
|
|||
}
|
||||
|
||||
|
||||
W_TABFORM::W_TABFORM(W_FORMINIT const *init)
|
||||
: W_FORM(init)
|
||||
, majorPos(init->majorPos), minorPos(init->minorPos)
|
||||
, majorSize(init->majorSize), minorSize(init->minorSize)
|
||||
, tabMajorThickness(init->tabMajorThickness)
|
||||
, tabMinorThickness(init->tabMinorThickness)
|
||||
, tabMajorGap(init->tabMajorGap)
|
||||
, tabMinorGap(init->tabMinorGap)
|
||||
, tabVertOffset(init->tabVertOffset)
|
||||
, tabHorzOffset(init->tabHorzOffset)
|
||||
, majorOffset(init->majorOffset)
|
||||
, minorOffset(init->minorOffset)
|
||||
, majorT(0), minorT(0)
|
||||
, state(0) // This assignment was previously done by a memset.
|
||||
, tabHiLite(~0)
|
||||
, TabMultiplier(init->TabMultiplier)
|
||||
, numStats(init->numStats)
|
||||
, numButtons(init->numButtons)
|
||||
, pTabDisplay(init->pTabDisplay)
|
||||
{
|
||||
memset(asMajor, 0, sizeof(asMajor));
|
||||
|
||||
/* Allocate the memory for tool tips and copy them in */
|
||||
/* Set up the tab data.
|
||||
* All widget pointers have been zeroed by the memset above.
|
||||
*/
|
||||
numMajor = init->numMajor;
|
||||
for (unsigned major = 0; major < init->numMajor; ++major)
|
||||
{
|
||||
/* Check for a tip for the major tab */
|
||||
asMajor[major].pTip = init->apMajorTips[major];
|
||||
asMajor[major].lastMinor = 0;
|
||||
|
||||
/* Check for tips for the minor tab */
|
||||
asMajor[major].numMinor = init->aNumMinors[major];
|
||||
for (unsigned minor = 0; minor < init->aNumMinors[major]; ++minor)
|
||||
{
|
||||
asMajor[major].asMinor[minor].pTip = init->apMinorTips[major][minor];
|
||||
}
|
||||
}
|
||||
|
||||
if (init->pDisplay == NULL)
|
||||
{
|
||||
display = formDisplayTabbed;
|
||||
}
|
||||
}
|
||||
|
||||
/* Create a tabbed form widget */
|
||||
static W_TABFORM* formCreateTabbed(const W_FORMINIT* psInit)
|
||||
{
|
||||
UDWORD major,minor;
|
||||
W_MAJORTAB *psMajor;
|
||||
|
||||
if (psInit->numMajor == 0)
|
||||
{
|
||||
ASSERT(false, "formCreateTabbed: Must have at least one major tab on a tabbed form");
|
||||
|
@ -209,7 +206,7 @@ static W_TABFORM* formCreateTabbed(const W_FORMINIT* psInit)
|
|||
ASSERT(false, "formCreateTabbed: Too many Major tabs" );
|
||||
return NULL;
|
||||
}
|
||||
for(major=0; major<psInit->numMajor; major++)
|
||||
for (unsigned major = 0; major < psInit->numMajor; ++major)
|
||||
{
|
||||
if (psInit->aNumMinors[major] >= WFORM_MAXMINOR)
|
||||
{
|
||||
|
@ -224,91 +221,13 @@ static W_TABFORM* formCreateTabbed(const W_FORMINIT* psInit)
|
|||
}
|
||||
|
||||
/* Allocate the required memory */
|
||||
W_TABFORM *psWidget = new W_TABFORM;
|
||||
W_TABFORM *psWidget = new W_TABFORM(psInit);
|
||||
if (psWidget == NULL)
|
||||
{
|
||||
debug(LOG_FATAL, "formCreateTabbed: Out of memory");
|
||||
abort();
|
||||
return NULL;
|
||||
}
|
||||
memset(psWidget->asMajor, 0, sizeof(psWidget->asMajor));
|
||||
|
||||
/* Allocate the memory for tool tips and copy them in */
|
||||
psMajor = psWidget->asMajor;
|
||||
for (major = 0; major < psInit->numMajor; ++major)
|
||||
{
|
||||
/* Check for a tip for the major tab */
|
||||
psMajor->pTip = psInit->apMajorTips[major];
|
||||
|
||||
/* Check for tips for the minor tab */
|
||||
for(minor = 0; minor < psInit->aNumMinors[major]; ++minor)
|
||||
{
|
||||
psMajor->asMinor[minor].pTip = psInit->apMinorTips[major][minor];
|
||||
}
|
||||
psMajor++;
|
||||
}
|
||||
|
||||
/* Initialise the structure */
|
||||
psWidget->type = WIDG_FORM;
|
||||
psWidget->id = psInit->id;
|
||||
psWidget->formID = psInit->formID;
|
||||
psWidget->style = psInit->style;
|
||||
psWidget->disableChildren = psInit->disableChildren;
|
||||
psWidget->animCount = 0;
|
||||
psWidget->x = psInit->x;
|
||||
psWidget->y = psInit->y;
|
||||
psWidget->width = psInit->width;
|
||||
psWidget->height = psInit->height;
|
||||
if (psInit->pDisplay)
|
||||
{
|
||||
psWidget->display = psInit->pDisplay;
|
||||
}
|
||||
else
|
||||
{
|
||||
psWidget->display = formDisplayTabbed;
|
||||
}
|
||||
psWidget->callback = psInit->pCallback;
|
||||
psWidget->pUserData = psInit->pUserData;
|
||||
psWidget->UserData = psInit->UserData;
|
||||
psWidget->psLastHiLite = NULL;
|
||||
psWidget->majorSize = psInit->majorSize;
|
||||
psWidget->minorSize = psInit->minorSize;
|
||||
psWidget->tabMajorThickness = psInit->tabMajorThickness;
|
||||
psWidget->tabMinorThickness = psInit->tabMinorThickness;
|
||||
psWidget->tabMajorGap = psInit->tabMajorGap;
|
||||
psWidget->tabMinorGap = psInit->tabMinorGap;
|
||||
psWidget->tabVertOffset = psInit->tabVertOffset;
|
||||
psWidget->tabHorzOffset = psInit->tabHorzOffset;
|
||||
psWidget->majorOffset = psInit->majorOffset;
|
||||
psWidget->minorOffset = psInit->minorOffset;
|
||||
psWidget->majorPos = psInit->majorPos;
|
||||
psWidget->minorPos = psInit->minorPos;
|
||||
psWidget->pTabDisplay = psInit->pTabDisplay;
|
||||
psWidget->TabMultiplier = psInit->TabMultiplier;
|
||||
psWidget->numButtons = psInit->numButtons;
|
||||
psWidget->numStats = psInit->numStats;
|
||||
psWidget->majorT = 0;
|
||||
psWidget->minorT = 0;
|
||||
|
||||
formSetDefaultColours((W_FORM *)psWidget);
|
||||
|
||||
/* Set up the tab data.
|
||||
* All widget pointers have been zeroed by the memset above.
|
||||
*/
|
||||
psWidget->numMajor = psInit->numMajor;
|
||||
for (major=0; major<psInit->numMajor; major++)
|
||||
{
|
||||
psWidget->asMajor[major].numMinor = psInit->aNumMinors[major];
|
||||
}
|
||||
|
||||
// These assignments were previously done by a memset.
|
||||
psWidget->psNext = NULL;
|
||||
psWidget->Ax0 = psWidget->Ay0 = psWidget->Ax1 = psWidget->Ay1 = 0;
|
||||
psWidget->startTime = 0;
|
||||
psWidget->psWidgets = NULL;
|
||||
psWidget->state = 0;
|
||||
|
||||
formInitialise((W_FORM *)psWidget);
|
||||
|
||||
return psWidget;
|
||||
}
|
||||
|
@ -736,43 +655,6 @@ void formGetOrigin(W_FORM *psWidget, SDWORD *pXOrigin, SDWORD *pYOrigin)
|
|||
}
|
||||
|
||||
|
||||
/* Initialise a form widget before running it */
|
||||
void formInitialise(W_FORM *psWidget)
|
||||
{
|
||||
W_TABFORM *psTabForm;
|
||||
W_CLICKFORM *psClickForm;
|
||||
UDWORD i;
|
||||
|
||||
if (psWidget->style & WFORM_TABBED)
|
||||
{
|
||||
ASSERT( psWidget != NULL,
|
||||
"formInitialise: invalid tab form pointer" );
|
||||
psTabForm = (W_TABFORM *)psWidget;
|
||||
psTabForm->majorT = 0;
|
||||
psTabForm->minorT = 0;
|
||||
psTabForm->tabHiLite = (UWORD)(-1);
|
||||
for (i=0; i<psTabForm->numMajor; i++)
|
||||
{
|
||||
psTabForm->asMajor[i].lastMinor = 0;
|
||||
}
|
||||
}
|
||||
else if (psWidget->style & WFORM_CLICKABLE)
|
||||
{
|
||||
ASSERT( psWidget != NULL,
|
||||
"formInitialise: invalid clickable form pointer" );
|
||||
psClickForm = (W_CLICKFORM *)psWidget;
|
||||
psClickForm->state = WCLICK_NORMAL;
|
||||
}
|
||||
else
|
||||
{
|
||||
ASSERT( psWidget != NULL,
|
||||
"formInitialise: invalid form pointer" );
|
||||
}
|
||||
|
||||
psWidget->psLastHiLite = NULL;
|
||||
}
|
||||
|
||||
|
||||
// Currently in game, I can only find that warzone uses horizontal tabs.
|
||||
// So ONLY this routine was modified. Will have to modify the vert. tab
|
||||
// routine if we ever use it.
|
||||
|
|
|
@ -30,6 +30,8 @@
|
|||
/* The standard form */
|
||||
struct W_FORM : public WIDGET
|
||||
{
|
||||
W_FORM(W_FORMINIT const *init);
|
||||
|
||||
BOOL disableChildren; ///< Disable all child widgets if true
|
||||
UWORD Ax0,Ay0,Ax1,Ay1; ///< Working coords for animations.
|
||||
UDWORD animCount; ///< Animation counter.
|
||||
|
@ -60,6 +62,8 @@ struct W_MAJORTAB
|
|||
/* The tabbed form data structure */
|
||||
struct W_TABFORM : public W_FORM
|
||||
{
|
||||
W_TABFORM(W_FORMINIT const *init);
|
||||
|
||||
UWORD majorPos, minorPos; // Position of the tabs on the form
|
||||
UWORD majorSize,minorSize; // the size of tabs horizontally and vertically
|
||||
UWORD tabMajorThickness; // The thickness of the tabs
|
||||
|
@ -99,6 +103,8 @@ struct W_TABFORM : public W_FORM
|
|||
/* The clickable form data structure */
|
||||
struct W_CLICKFORM : public W_FORM
|
||||
{
|
||||
W_CLICKFORM(W_FORMINIT const *init);
|
||||
|
||||
UDWORD state; // Button state of the form
|
||||
const char *pTip; // Tip for the form
|
||||
SWORD HilightAudioID; // Audio ID for form clicked sound
|
||||
|
@ -117,9 +123,6 @@ extern void formFree(W_FORM *psWidget);
|
|||
/* Add a widget to a form */
|
||||
extern BOOL formAddWidget(W_FORM *psForm, WIDGET *psWidget, W_INIT *psInit);
|
||||
|
||||
/* Initialise a form widget before running it */
|
||||
extern void formInitialise(W_FORM *psWidget);
|
||||
|
||||
/* Return the widgets currently displayed by a form */
|
||||
extern WIDGET *formGetWidgets(W_FORM *psWidget);
|
||||
|
||||
|
|
|
@ -30,6 +30,24 @@
|
|||
// FIXME Direct iVis implementation include!
|
||||
#include "lib/ivis_common/textdraw.h"
|
||||
|
||||
W_LABEL::W_LABEL(W_LABINIT const *init)
|
||||
: WIDGET(init, WIDG_LABEL)
|
||||
, FontID(init->FontID)
|
||||
, pTip(init->pTip)
|
||||
{
|
||||
if (display == NULL)
|
||||
{
|
||||
display = labelDisplay;
|
||||
}
|
||||
|
||||
aText[0] = '\0';
|
||||
if (init->pText)
|
||||
{
|
||||
sstrcpy(aText, init->pText);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Create a button widget data structure */
|
||||
W_LABEL* labelCreate(const W_LABINIT* psInit)
|
||||
{
|
||||
|
@ -42,47 +60,13 @@ W_LABEL* labelCreate(const W_LABINIT* psInit)
|
|||
}
|
||||
|
||||
/* Allocate the required memory */
|
||||
W_LABEL *psWidget = new W_LABEL;
|
||||
W_LABEL *psWidget = new W_LABEL(psInit);
|
||||
if (psWidget == NULL)
|
||||
{
|
||||
debug(LOG_FATAL, "labelCreate: Out of memory");
|
||||
abort();
|
||||
return NULL;
|
||||
}
|
||||
/* Allocate the memory for the tip and copy it if necessary */
|
||||
psWidget->pTip = psInit->pTip;
|
||||
|
||||
/* Initialise the structure */
|
||||
psWidget->type = WIDG_LABEL;
|
||||
psWidget->id = psInit->id;
|
||||
psWidget->formID = psInit->formID;
|
||||
psWidget->style = psInit->style;
|
||||
psWidget->x = psInit->x;
|
||||
psWidget->y = psInit->y;
|
||||
psWidget->width = psInit->width;
|
||||
psWidget->height = psInit->height;
|
||||
|
||||
if (psInit->pDisplay)
|
||||
{
|
||||
psWidget->display = psInit->pDisplay;
|
||||
}
|
||||
else
|
||||
{
|
||||
psWidget->display = labelDisplay;
|
||||
}
|
||||
psWidget->callback = psInit->pCallback;
|
||||
psWidget->pUserData = psInit->pUserData;
|
||||
psWidget->UserData = psInit->UserData;
|
||||
psWidget->FontID = psInit->FontID;
|
||||
|
||||
if (psInit->pText)
|
||||
{
|
||||
sstrcpy(psWidget->aText, psInit->pText);
|
||||
}
|
||||
else
|
||||
{
|
||||
psWidget->aText[0] = 0;
|
||||
}
|
||||
|
||||
return psWidget;
|
||||
}
|
||||
|
@ -131,8 +115,6 @@ void labelDisplay(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, PIELIGHT *pC
|
|||
/* Respond to a mouse moving over a label */
|
||||
void labelHiLite(W_LABEL *psWidget, W_CONTEXT *psContext)
|
||||
{
|
||||
psWidget->state |= WLABEL_HILITE;
|
||||
|
||||
/* If there is a tip string start the tool tip */
|
||||
if (psWidget->pTip)
|
||||
{
|
||||
|
@ -147,7 +129,6 @@ void labelHiLite(W_LABEL *psWidget, W_CONTEXT *psContext)
|
|||
/* Respond to the mouse moving off a label */
|
||||
void labelHiLiteLost(W_LABEL *psWidget)
|
||||
{
|
||||
psWidget->state &= ~(WLABEL_HILITE);
|
||||
if (psWidget->pTip)
|
||||
{
|
||||
tipStop((WIDGET *)psWidget);
|
||||
|
|
|
@ -28,12 +28,10 @@
|
|||
#include "widgbase.h"
|
||||
#include "lib/ivis_common/textdraw.h"
|
||||
|
||||
// label states.
|
||||
#define WLABEL_HILITE 0x0004 // label is hilited
|
||||
|
||||
struct W_LABEL : public WIDGET
|
||||
{
|
||||
UDWORD state; // The current button state
|
||||
W_LABEL(W_LABINIT const *init);
|
||||
|
||||
char aText[WIDG_MAXSTR]; // Text on the label
|
||||
enum iV_fonts FontID;
|
||||
const char *pTip; // The tool tip for the button
|
||||
|
|
|
@ -34,6 +34,24 @@ void sliderEnableDrag(BOOL Enable)
|
|||
DragEnabled = Enable;
|
||||
}
|
||||
|
||||
W_SLIDER::W_SLIDER(W_SLDINIT const *init)
|
||||
: WIDGET(init, WIDG_SLIDER)
|
||||
, orientation(init->orientation)
|
||||
, numStops(init->numStops)
|
||||
, barSize(init->barSize)
|
||||
, pTip(init->pTip)
|
||||
{
|
||||
if (display == NULL)
|
||||
{
|
||||
display = sliderDisplay;
|
||||
}
|
||||
|
||||
sliderInitialise(this);
|
||||
|
||||
pos = init->pos; // Must be after sliderInitialise().
|
||||
}
|
||||
|
||||
|
||||
/* Create a slider widget data structure */
|
||||
W_SLIDER* sliderCreate(const W_SLDINIT* psInit)
|
||||
{
|
||||
|
@ -79,44 +97,13 @@ W_SLIDER* sliderCreate(const W_SLDINIT* psInit)
|
|||
}
|
||||
|
||||
/* Allocate the required memory */
|
||||
W_SLIDER *psWidget = new W_SLIDER;
|
||||
W_SLIDER *psWidget = new W_SLIDER(psInit);
|
||||
if (psWidget == NULL)
|
||||
{
|
||||
debug(LOG_FATAL, "sliderCreate: Out of memory");
|
||||
abort();
|
||||
return NULL;
|
||||
}
|
||||
/* Allocate the memory for the tip and copy it if necessary */
|
||||
psWidget->pTip = psInit->pTip;
|
||||
|
||||
/* Initialise the structure */
|
||||
psWidget->type = WIDG_SLIDER;
|
||||
psWidget->id = psInit->id;
|
||||
psWidget->formID = psInit->formID;
|
||||
psWidget->style = psInit->style;
|
||||
psWidget->x = psInit->x;
|
||||
psWidget->y = psInit->y;
|
||||
psWidget->width = psInit->width;
|
||||
psWidget->height = psInit->height;
|
||||
|
||||
if (psInit->pDisplay)
|
||||
{
|
||||
psWidget->display = psInit->pDisplay;
|
||||
}
|
||||
else
|
||||
{
|
||||
psWidget->display = sliderDisplay;
|
||||
}
|
||||
psWidget->callback = psInit->pCallback;
|
||||
psWidget->pUserData = psInit->pUserData;
|
||||
psWidget->UserData = psInit->UserData;
|
||||
psWidget->orientation = psInit->orientation;
|
||||
psWidget->numStops = psInit->numStops;
|
||||
psWidget->barSize = psInit->barSize;
|
||||
|
||||
sliderInitialise(psWidget);
|
||||
|
||||
psWidget->pos = psInit->pos;
|
||||
|
||||
return psWidget;
|
||||
}
|
||||
|
|
|
@ -33,6 +33,8 @@
|
|||
|
||||
struct W_SLIDER : public WIDGET
|
||||
{
|
||||
W_SLIDER(W_SLDINIT const *init);
|
||||
|
||||
UWORD orientation; // The orientation of the slider
|
||||
UWORD numStops; // Number of stop positions on the slider
|
||||
UWORD barSize; // Thickness of slider bar
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
struct WIDGET;
|
||||
struct W_CONTEXT;
|
||||
struct W_FORM;
|
||||
struct W_INIT;
|
||||
|
||||
/* The display function prototype */
|
||||
typedef void (*WIDGET_DISPLAY)(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, PIELIGHT *pColours);
|
||||
|
@ -64,6 +65,7 @@ enum WIDGET_TYPE
|
|||
/* The base widget data type */
|
||||
struct WIDGET
|
||||
{
|
||||
WIDGET(W_INIT const *init, WIDGET_TYPE type);
|
||||
virtual ~WIDGET() {}
|
||||
|
||||
UDWORD formID; ///< ID of the widgets base form.
|
||||
|
|
|
@ -82,6 +82,23 @@ void widgShutDown(void)
|
|||
{
|
||||
}
|
||||
|
||||
|
||||
WIDGET::WIDGET(W_INIT const *init, WIDGET_TYPE type)
|
||||
: formID(init->formID)
|
||||
, id(init->id)
|
||||
, type(type)
|
||||
, style(init->style)
|
||||
, x(init->x), y(init->y)
|
||||
, width(init->width), height(init->height)
|
||||
, display(init->pDisplay)
|
||||
, callback(init->pCallback)
|
||||
, pUserData(init->pUserData)
|
||||
, UserData(init->UserData)
|
||||
|
||||
, psNext(NULL)
|
||||
{}
|
||||
|
||||
|
||||
// reset psMouseOverWidget (a global) when needed
|
||||
void CheckpsMouseOverWidget( void *psWidget )
|
||||
{
|
||||
|
@ -660,7 +677,8 @@ static void widgStartForm(W_FORM *psForm)
|
|||
W_FORMGETALL sGetAll;
|
||||
|
||||
/* Initialise this form */
|
||||
formInitialise(psForm);
|
||||
// This whole function should be redundant, since all widgets are initialised when created...
|
||||
//formInitialise(psForm);
|
||||
|
||||
/*Initialise the widgets on the form */
|
||||
formInitGetAllWidgets(psForm, &sGetAll);
|
||||
|
|
Loading…
Reference in New Issue