summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ui/ui_shared.c426
-rw-r--r--src/ui/ui_shared.h10
2 files changed, 156 insertions, 280 deletions
diff --git a/src/ui/ui_shared.c b/src/ui/ui_shared.c
index 8862f328..315f6135 100644
--- a/src/ui/ui_shared.c
+++ b/src/ui/ui_shared.c
@@ -1773,9 +1773,8 @@ void Script_Reset( itemDef_t *item, char **args )
{
if( resetItem->type == ITEM_TYPE_LISTBOX )
{
- listBoxDef_t * listPtr = ( listBoxDef_t* )resetItem->typeData;
resetItem->cursorPos = 0;
- listPtr->startPos = 0;
+ resetItem->typeData.list->startPos = 0;
DC->feederSelection( resetItem->special, 0 );
}
}
@@ -2668,7 +2667,7 @@ qboolean Item_SetFocus( itemDef_t *item, float x, float y )
int Item_ListBox_MaxScroll( itemDef_t *item )
{
- listBoxDef_t *listPtr = ( listBoxDef_t* )item->typeData;
+ listBoxDef_t *listPtr = item->typeData.list;
int count = DC->feederCount( item->special );
int max;
@@ -2686,7 +2685,7 @@ int Item_ListBox_MaxScroll( itemDef_t *item )
int Item_ListBox_ThumbPosition( itemDef_t *item )
{
float max, pos, size;
- listBoxDef_t *listPtr = ( listBoxDef_t* )item->typeData;
+ int startPos = item->typeData.list->startPos;
max = Item_ListBox_MaxScroll( item );
@@ -2699,7 +2698,7 @@ int Item_ListBox_ThumbPosition( itemDef_t *item )
else
pos = 0;
- pos *= listPtr->startPos;
+ pos *= startPos;
return item->window.rect.x + 1 + SCROLLBAR_WIDTH + pos;
}
else
@@ -2711,7 +2710,7 @@ int Item_ListBox_ThumbPosition( itemDef_t *item )
else
pos = 0;
- pos *= listPtr->startPos;
+ pos *= startPos;
return item->window.rect.y + 1 + SCROLLBAR_HEIGHT + pos;
}
}
@@ -2750,7 +2749,7 @@ int Item_ListBox_ThumbDrawPosition( itemDef_t *item )
float Item_Slider_ThumbPosition( itemDef_t *item )
{
float value, range, x;
- editFieldDef_t *editDef = item->typeData;
+ editFieldDef_t *editDef = item->typeData.edit;
if( item->text )
x = item->textRect.x + item->textRect.w + ITEM_VALUE_OFFSET;
@@ -2804,12 +2803,10 @@ int Item_Slider_OverSlider( itemDef_t *item, float x, float y )
int Item_ListBox_OverLB( itemDef_t *item, float x, float y )
{
rectDef_t r;
- listBoxDef_t *listPtr;
int thumbstart;
int count;
count = DC->feederCount( item->special );
- listPtr = ( listBoxDef_t* )item->typeData;
if( item->window.flags & WINDOW_HORIZONTAL )
{
@@ -2889,7 +2886,7 @@ int Item_ListBox_OverLB( itemDef_t *item, float x, float y )
void Item_ListBox_MouseEnter( itemDef_t *item, float x, float y )
{
rectDef_t r;
- listBoxDef_t *listPtr = ( listBoxDef_t* )item->typeData;
+ listBoxDef_t *listPtr = item->typeData.list;
item->window.flags &= ~( WINDOW_LB_LEFTARROW | WINDOW_LB_RIGHTARROW | WINDOW_LB_THUMB |
WINDOW_LB_PGUP | WINDOW_LB_PGDN );
@@ -3043,7 +3040,7 @@ qboolean Item_OwnerDraw_HandleKey( itemDef_t *item, int key )
qboolean Item_ListBox_HandleKey( itemDef_t *item, int key, qboolean down, qboolean force )
{
- listBoxDef_t *listPtr = ( listBoxDef_t* )item->typeData;
+ listBoxDef_t *listPtr = item->typeData.list;
int count = DC->feederCount( item->special );
int max, viewmax;
@@ -3362,12 +3359,10 @@ qboolean Item_YesNo_HandleKey( itemDef_t *item, int key )
int Item_Multi_CountSettings( itemDef_t *item )
{
- multiDef_t *multiPtr = ( multiDef_t* )item->typeData;
-
- if( multiPtr == NULL )
+ if( item->typeData.multi == NULL )
return 0;
- return multiPtr->count;
+ return item->typeData.multi->count;
}
int Item_Multi_FindCvarByValue( itemDef_t *item )
@@ -3375,7 +3370,7 @@ int Item_Multi_FindCvarByValue( itemDef_t *item )
char buff[1024];
float value = 0;
int i;
- multiDef_t *multiPtr = ( multiDef_t* )item->typeData;
+ multiDef_t *multiPtr = item->typeData.multi;
if( multiPtr )
{
@@ -3407,7 +3402,7 @@ const char *Item_Multi_Setting( itemDef_t *item )
char buff[1024];
float value = 0;
int i;
- multiDef_t *multiPtr = ( multiDef_t* )item->typeData;
+ multiDef_t *multiPtr = item->typeData.multi;
if( multiPtr )
{
@@ -3436,7 +3431,7 @@ const char *Item_Multi_Setting( itemDef_t *item )
qboolean Item_Combobox_HandleKey( itemDef_t *item, int key )
{
- comboBoxDef_t *comboPtr = (comboBoxDef_t *)item->typeData;
+ comboBoxDef_t *comboPtr = item->typeData.combo;
qboolean mouseOver = Rect_ContainsPoint( &item->window.rect, DC->cursorx, DC->cursory );
int count = DC->feederCount( item->special );
@@ -3472,12 +3467,11 @@ qboolean Item_Combobox_HandleKey( itemDef_t *item, int key )
qboolean Item_Multi_HandleKey( itemDef_t *item, int key )
{
- multiDef_t *multiPtr = ( multiDef_t* )item->typeData;
qboolean mouseOver = Rect_ContainsPoint( &item->window.rect, DC->cursorx, DC->cursory );
int max = Item_Multi_CountSettings( item );
qboolean changed = qfalse;
- if( multiPtr )
+ if( item->typeData.multi )
{
if( item->window.flags & WINDOW_HASFOCUS && item->cvar && max > 0 )
{
@@ -3498,11 +3492,11 @@ qboolean Item_Multi_HandleKey( itemDef_t *item, int key )
if( changed )
{
- if( multiPtr->strDef )
- DC->setCVar( item->cvar, multiPtr->cvarStr[current] );
+ if( item->typeData.multi->strDef )
+ DC->setCVar( item->cvar, item->typeData.multi->cvarStr[current] );
else
{
- float value = multiPtr->cvarValue[current];
+ float value = item->typeData.multi->cvarValue[current];
if( ( ( float )( ( int ) value ) ) == value )
DC->setCVar( item->cvar, va( "%i", ( int ) value ) );
@@ -3523,7 +3517,7 @@ qboolean Item_Multi_HandleKey( itemDef_t *item, int key )
static void Item_TextField_CalcPaintOffset( itemDef_t *item, char *buff )
{
- editFieldDef_t *editPtr = ( editFieldDef_t* )item->typeData;
+ editFieldDef_t *editPtr = item->typeData.edit;
if( item->cursorPos < editPtr->paintOffset )
editPtr->paintOffset = item->cursorPos;
@@ -3559,7 +3553,7 @@ qboolean Item_TextField_HandleKey( itemDef_t *item, int key )
char buff[1024];
int len;
itemDef_t *newItem = NULL;
- editFieldDef_t *editPtr = ( editFieldDef_t* )item->typeData;
+ editFieldDef_t *editPtr = item->typeData.edit;
qboolean releaseFocus = qtrue;
if( item->cvar )
@@ -3748,8 +3742,6 @@ static void Scroll_ListBox_ThumbFunc( void *p )
rectDef_t r;
int pos, max;
- listBoxDef_t *listPtr = ( listBoxDef_t* )si->item->typeData;
-
if( si->item->window.flags & WINDOW_HORIZONTAL )
{
if( DC->cursorx == si->xStart )
@@ -3768,7 +3760,7 @@ static void Scroll_ListBox_ThumbFunc( void *p )
else if( pos > max )
pos = max;
- listPtr->startPos = pos;
+ si->item->typeData.list->startPos = pos;
si->xStart = DC->cursorx;
}
else if( DC->cursory != si->yStart )
@@ -3786,7 +3778,7 @@ static void Scroll_ListBox_ThumbFunc( void *p )
else if( pos > max )
pos = max;
- listPtr->startPos = pos;
+ si->item->typeData.list->startPos = pos;
si->yStart = DC->cursory;
}
@@ -3812,7 +3804,6 @@ static void Scroll_Slider_ThumbFunc( void *p )
{
float x, value, cursorx;
scrollInfo_t *si = ( scrollInfo_t* )p;
- editFieldDef_t *editDef = si->item->typeData;
if( si->item->text )
x = si->item->textRect.x + si->item->textRect.w + ITEM_VALUE_OFFSET;
@@ -3828,8 +3819,8 @@ static void Scroll_Slider_ThumbFunc( void *p )
value = cursorx - x;
value /= SLIDER_WIDTH;
- value *= ( editDef->maxVal - editDef->minVal );
- value += editDef->minVal;
+ value *= si->item->typeData.edit->maxVal - si->item->typeData.edit->minVal;
+ value += si->item->typeData.edit->minVal;
DC->setCVar( si->item->cvar, va( "%f", value ) );
}
@@ -3899,42 +3890,34 @@ void Item_StopCapture( itemDef_t *item )
qboolean Item_Slider_HandleKey( itemDef_t *item, int key, qboolean down )
{
- float x, value, width, work;
+ float x, value, width;
if( item->window.flags & WINDOW_HASFOCUS && item->cvar &&
Rect_ContainsPoint( &item->window.rect, DC->cursorx, DC->cursory ) )
{
- if( key == K_MOUSE1 || key == K_ENTER || key == K_MOUSE2 || key == K_MOUSE3 )
+ if( item->typeData.edit && ( key == K_ENTER ||
+ key == K_MOUSE1 || key == K_MOUSE2 || key == K_MOUSE3 ) )
{
- editFieldDef_t *editDef = item->typeData;
-
- if( editDef )
- {
- rectDef_t testRect;
- width = SLIDER_WIDTH;
+ rectDef_t testRect;
+ width = SLIDER_WIDTH;
- if( item->text )
- x = item->textRect.x + item->textRect.w + ITEM_VALUE_OFFSET;
- else
- x = item->window.rect.x;
+ if( item->text )
+ x = item->textRect.x + item->textRect.w + ITEM_VALUE_OFFSET;
+ else
+ x = item->window.rect.x;
- testRect = item->window.rect;
- testRect.x = x;
- value = ( float )SLIDER_THUMB_WIDTH / 2;
- testRect.x -= value;
- testRect.w = ( SLIDER_WIDTH + ( float )SLIDER_THUMB_WIDTH / 2 );
+ testRect = item->window.rect;
+ value = ( float )SLIDER_THUMB_WIDTH / 2;
+ testRect.x = x - value;
+ testRect.w = SLIDER_WIDTH + value;
- if( Rect_ContainsPoint( &testRect, DC->cursorx, DC->cursory ) )
- {
- work = DC->cursorx - x;
- value = work / width;
- value *= ( editDef->maxVal - editDef->minVal );
- // vm fuckage
- // value = (((float)(DC->cursorx - x)/ SLIDER_WIDTH) * (editDef->maxVal - editDef->minVal));
- value += editDef->minVal;
- DC->setCVar( item->cvar, va( "%f", value ) );
- return qtrue;
- }
+ if( Rect_ContainsPoint( &testRect, DC->cursorx, DC->cursory ) )
+ {
+ value = ( float )( DC->cursorx - x ) / width;
+ value *= ( item->typeData.edit->maxVal - item->typeData.edit->minVal );
+ value += item->typeData.edit->minVal;
+ DC->setCVar( item->cvar, va( "%f", value ) );
+ return qtrue;
}
}
}
@@ -4159,16 +4142,14 @@ void Menus_Activate( menuDef_t *menu )
{
if( menu->items[ i ]->type == ITEM_TYPE_LISTBOX )
{
- listBoxDef_t *listPtr = ( listBoxDef_t* )menu->items[ i ]->typeData;
menu->items[ i ]->cursorPos = 0;
- listPtr->startPos = 0;
+ menu->items[ i ]->typeData.list->startPos = 0;
DC->feederSelection( menu->items[ i ]->special, 0 );
}
else if( menu->items[ i ]->type == ITEM_TYPE_COMBO )
{
- comboBoxDef_t *comboPtr = (comboBoxDef_t *)menu->items[ i ]->typeData;
-
- comboPtr->cursorPos = DC->feederInitialise( menu->items[ i ]->special );
+ menu->items[ i ]->typeData.combo->cursorPos =
+ DC->feederInitialise( menu->items[ i ]->special );
}
}
@@ -4980,7 +4961,7 @@ void Item_TextField_Paint( itemDef_t *item )
vec4_t newColor;
int offset = ( item->text && *item->text ) ? ITEM_VALUE_OFFSET : 0;
menuDef_t *parent = ( menuDef_t* )item->parent;
- editFieldDef_t *editPtr = ( editFieldDef_t* )item->typeData;
+ editFieldDef_t *editPtr = item->typeData.edit;
char cursor = DC->getOverstrikeMode() ? '|' : '_';
qboolean editing = ( item->window.flags & WINDOW_HASFOCUS && g_editingField );
const int cursorWidth = editing ? EDIT_CURSOR_WIDTH : 0;
@@ -5090,15 +5071,15 @@ void Item_Combobox_Paint( itemDef_t *item )
vec4_t newColor;
const char *text = "";
menuDef_t *parent = (menuDef_t *)item->parent;
- comboBoxDef_t *comboPtr = (comboBoxDef_t *)item->typeData;
if( item->window.flags & WINDOW_HASFOCUS )
memcpy( newColor, &parent->focusColor, sizeof( vec4_t ) );
else
memcpy( &newColor, &item->window.foreColor, sizeof( vec4_t ) );
- if( comboPtr )
- text = DC->feederItemText( item->special, comboPtr->cursorPos, 0, NULL );
+ if( item->typeData.combo )
+ text = DC->feederItemText( item->special, item->typeData.combo->cursorPos,
+ 0, NULL );
if( item->text )
{
@@ -5382,10 +5363,9 @@ void Item_Bind_Paint( itemDef_t *item )
float value;
int maxChars = 0;
menuDef_t *parent = ( menuDef_t* )item->parent;
- editFieldDef_t *editPtr = ( editFieldDef_t* )item->typeData;
- if( editPtr )
- maxChars = editPtr->maxPaintChars;
+ if( item->typeData.edit )
+ maxChars = item->typeData.edit->maxPaintChars;
value = ( item->cvar ) ? DC->getCVarValue( item->cvar ) : 0;
@@ -5552,7 +5532,7 @@ void Item_Model_Paint( itemDef_t *item )
refEntity_t ent;
vec3_t mins, maxs, origin;
vec3_t angles;
- modelDef_t *modelPtr = ( modelDef_t* )item->typeData;
+ modelDef_t *modelPtr = item->typeData.model;
if( modelPtr == NULL )
return;
@@ -5652,7 +5632,7 @@ void Item_ListBox_Paint( itemDef_t *item )
int i, count;
qhandle_t image;
qhandle_t optionalImage;
- listBoxDef_t *listPtr = ( listBoxDef_t* )item->typeData;
+ listBoxDef_t *listPtr = item->typeData.list;
menuDef_t *menu = ( menuDef_t * )item->parent;
float one, two;
@@ -6331,9 +6311,8 @@ void Menu_SetFeederSelection( menuDef_t *menu, int feeder, int index, const char
{
if( index == 0 )
{
- listBoxDef_t *listPtr = ( listBoxDef_t* )menu->items[i]->typeData;
- listPtr->cursorPos = 0;
- listPtr->startPos = 0;
+ menu->items[ i ]->typeData.list->cursorPos = 0;
+ menu->items[ i ]->typeData.list->startPos = 0;
}
menu->items[i]->cursorPos = index;
@@ -6518,43 +6497,50 @@ void Menu_Paint( menuDef_t *menu, qboolean forcePaint )
/*
===============
Item_ValidateTypeData
+
+If the typeData pointer is null, allocate it a memory block appropriate to the
+item type and memset it to 0
===============
*/
void Item_ValidateTypeData( itemDef_t *item )
{
- if( item->typeData )
+ if( item->typeData.data )
return;
- if( item->type == ITEM_TYPE_LISTBOX )
- {
- item->typeData = UI_Alloc( sizeof( listBoxDef_t ) );
- memset( item->typeData, 0, sizeof( listBoxDef_t ) );
- }
- else if( item->type == ITEM_TYPE_COMBO )
- {
- item->typeData = UI_Alloc( sizeof( comboBoxDef_t ) );
- memset( item->typeData, 0, sizeof( comboBoxDef_t ) );
- }
- else if( item->type == ITEM_TYPE_EDITFIELD ||
- item->type == ITEM_TYPE_NUMERICFIELD ||
- item->type == ITEM_TYPE_YESNO ||
- item->type == ITEM_TYPE_BIND ||
- item->type == ITEM_TYPE_SLIDER ||
- item->type == ITEM_TYPE_TEXT )
+ switch( item->type )
{
- item->typeData = UI_Alloc( sizeof( editFieldDef_t ) );
- memset( item->typeData, 0, sizeof( editFieldDef_t ) );
+ case ITEM_TYPE_LISTBOX:
+ item->typeData.list = UI_Alloc( sizeof( listBoxDef_t ) );
+ memset( item->typeData.list, 0, sizeof( listBoxDef_t ) );
+ break;
- if( item->type == ITEM_TYPE_EDITFIELD )
- {
- if( !( ( editFieldDef_t * ) item->typeData )->maxPaintChars )
- ( ( editFieldDef_t * ) item->typeData )->maxPaintChars = MAX_EDITFIELD;
- }
+ case ITEM_TYPE_COMBO:
+ item->typeData.combo = UI_Alloc( sizeof( comboBoxDef_t ) );
+ memset( item->typeData.combo, 0, sizeof( comboBoxDef_t ) );
+ break;
+
+ case ITEM_TYPE_EDITFIELD:
+ case ITEM_TYPE_NUMERICFIELD:
+ case ITEM_TYPE_YESNO:
+ case ITEM_TYPE_BIND:
+ case ITEM_TYPE_SLIDER:
+ case ITEM_TYPE_TEXT:
+ item->typeData.edit = UI_Alloc( sizeof( editFieldDef_t ) );
+ memset( item->typeData.edit, 0, sizeof( editFieldDef_t ) );
+
+ if( item->type == ITEM_TYPE_EDITFIELD )
+ item->typeData.edit->maxPaintChars = MAX_EDITFIELD;
+ break;
+
+ case ITEM_TYPE_MULTI:
+ item->typeData.multi = UI_Alloc( sizeof( multiDef_t ) );
+ memset( item->typeData.multi, 0, sizeof( multiDef_t ) );
+ break;
+
+ case ITEM_TYPE_MODEL:
+ item->typeData.model = UI_Alloc( sizeof( modelDef_t ) );
+ memset( item->typeData.model, 0, sizeof( modelDef_t ) );
}
- else if( item->type == ITEM_TYPE_MULTI )
- item->typeData = UI_Alloc( sizeof( multiDef_t ) );
- else if( item->type == ITEM_TYPE_MODEL )
- item->typeData = UI_Alloc( sizeof( modelDef_t ) );
}
/*
@@ -6671,15 +6657,13 @@ qboolean ItemParse_group( itemDef_t *item, int handle )
qboolean ItemParse_asset_model( itemDef_t *item, int handle )
{
const char *temp;
- modelDef_t *modelPtr;
Item_ValidateTypeData( item );
- modelPtr = ( modelDef_t* )item->typeData;
if( !PC_String_Parse( handle, &temp ) )
return qfalse;
item->asset = DC->registerModel( temp );
- modelPtr->angle = rand() % 360;
+ item->typeData.model->angle = rand() % 360;
return qtrue;
}
@@ -6698,72 +6682,43 @@ qboolean ItemParse_asset_shader( itemDef_t *item, int handle )
// model_origin <number> <number> <number>
qboolean ItemParse_model_origin( itemDef_t *item, int handle )
{
- modelDef_t *modelPtr;
Item_ValidateTypeData( item );
- modelPtr = ( modelDef_t* )item->typeData;
- if( PC_Float_Parse( handle, &modelPtr->origin[0] ) )
- {
- if( PC_Float_Parse( handle, &modelPtr->origin[1] ) )
- {
- if( PC_Float_Parse( handle, &modelPtr->origin[2] ) )
- return qtrue;
- }
- }
-
- return qfalse;
+ return ( PC_Float_Parse( handle, &item->typeData.model->origin[0] ) &&
+ PC_Float_Parse( handle, &item->typeData.model->origin[1] ) &&
+ PC_Float_Parse( handle, &item->typeData.model->origin[2] ) );
}
// model_fovx <number>
qboolean ItemParse_model_fovx( itemDef_t *item, int handle )
{
- modelDef_t *modelPtr;
Item_ValidateTypeData( item );
- modelPtr = ( modelDef_t* )item->typeData;
-
- if( !PC_Float_Parse( handle, &modelPtr->fov_x ) )
- return qfalse;
- return qtrue;
+ return PC_Float_Parse( handle, &item->typeData.model->fov_x );
}
// model_fovy <number>
qboolean ItemParse_model_fovy( itemDef_t *item, int handle )
{
- modelDef_t *modelPtr;
Item_ValidateTypeData( item );
- modelPtr = ( modelDef_t* )item->typeData;
-
- if( !PC_Float_Parse( handle, &modelPtr->fov_y ) )
- return qfalse;
- return qtrue;
+ return PC_Float_Parse( handle, &item->typeData.model->fov_y );
}
// model_rotation <integer>
qboolean ItemParse_model_rotation( itemDef_t *item, int handle )
{
- modelDef_t *modelPtr;
Item_ValidateTypeData( item );
- modelPtr = ( modelDef_t* )item->typeData;
-
- if( !PC_Int_Parse( handle, &modelPtr->rotationSpeed ) )
- return qfalse;
- return qtrue;
+ return PC_Int_Parse( handle, &item->typeData.model->rotationSpeed );
}
// model_angle <integer>
qboolean ItemParse_model_angle( itemDef_t *item, int handle )
{
- modelDef_t *modelPtr;
Item_ValidateTypeData( item );
- modelPtr = ( modelDef_t* )item->typeData;
- if( !PC_Int_Parse( handle, &modelPtr->angle ) )
- return qfalse;
-
- return qtrue;
+ return PC_Int_Parse( handle, &item->typeData.model->angle );
}
// rect <rectangle>
@@ -6805,7 +6760,7 @@ qboolean ItemParse_notselectable( itemDef_t *item, int handle )
{
listBoxDef_t *listPtr;
Item_ValidateTypeData( item );
- listPtr = ( listBoxDef_t* )item->typeData;
+ listPtr = item->typeData.list;
if( item->type == ITEM_TYPE_LISTBOX && listPtr )
listPtr->notselectable = qtrue;
@@ -6818,7 +6773,7 @@ qboolean ItemParse_noscrollbar( itemDef_t *item, int handle )
{
listBoxDef_t *listPtr;
Item_ValidateTypeData( item );
- listPtr = ( listBoxDef_t* )item->typeData;
+ listPtr = item->typeData.list;
if( item->type == ITEM_TYPE_LISTBOX && listPtr )
listPtr->noscrollbar = qtrue;
@@ -6855,30 +6810,18 @@ qboolean ItemParse_type( itemDef_t *item, int handle )
// uses textalignx for storage
qboolean ItemParse_elementwidth( itemDef_t *item, int handle )
{
- listBoxDef_t *listPtr;
-
Item_ValidateTypeData( item );
- listPtr = ( listBoxDef_t* )item->typeData;
-
- if( !PC_Float_Parse( handle, &listPtr->elementWidth ) )
- return qfalse;
- return qtrue;
+ return PC_Float_Parse( handle, &item->typeData.list->elementWidth );
}
// elementheight, used for listbox image elements
// uses textaligny for storage
qboolean ItemParse_elementheight( itemDef_t *item, int handle )
{
- listBoxDef_t *listPtr;
-
Item_ValidateTypeData( item );
- listPtr = ( listBoxDef_t* )item->typeData;
-
- if( !PC_Float_Parse( handle, &listPtr->elementHeight ) )
- return qfalse;
- return qtrue;
+ return PC_Float_Parse( handle, &item->typeData.list->elementHeight );
}
// feeder <float>
@@ -6894,59 +6837,39 @@ qboolean ItemParse_feeder( itemDef_t *item, int handle )
// uses textstyle for storage
qboolean ItemParse_elementtype( itemDef_t *item, int handle )
{
- listBoxDef_t *listPtr;
-
Item_ValidateTypeData( item );
- if( !item->typeData )
- return qfalse;
-
- listPtr = ( listBoxDef_t* )item->typeData;
-
- if( !PC_Int_Parse( handle, &listPtr->elementStyle ) )
- return qfalse;
-
- return qtrue;
+ return ( item->typeData.list &&
+ PC_Int_Parse( handle, &item->typeData.list->elementStyle ) );
}
// columns sets a number of columns and an x pos and width per..
qboolean ItemParse_columns( itemDef_t *item, int handle )
{
- int num, i;
- listBoxDef_t *listPtr;
+ int i;
Item_ValidateTypeData( item );
- if( !item->typeData )
+ if( !item->typeData.list ||
+ !PC_Int_Parse( handle, &item->typeData.list->numColumns ) )
return qfalse;
- listPtr = ( listBoxDef_t* )item->typeData;
+ if( item->typeData.list->numColumns > MAX_LB_COLUMNS )
+ item->typeData.list->numColumns = MAX_LB_COLUMNS;
- if( PC_Int_Parse( handle, &num ) )
+ for( i = 0; i < item->typeData.list->numColumns; i++ )
{
- if( num > MAX_LB_COLUMNS )
- num = MAX_LB_COLUMNS;
-
- listPtr->numColumns = num;
+ int pos, width, align;
- for( i = 0; i < num; i++ )
- {
- int pos, width, align;
+ if( !PC_Int_Parse( handle, &pos ) ||
+ !PC_Int_Parse( handle, &width ) ||
+ !PC_Int_Parse( handle, &align ) )
+ return qfalse;
- if( PC_Int_Parse( handle, &pos ) &&
- PC_Int_Parse( handle, &width ) &&
- PC_Int_Parse( handle, &align ) )
- {
- listPtr->columnInfo[i].pos = pos;
- listPtr->columnInfo[i].width = width;
- listPtr->columnInfo[i].align = align;
- }
- else
- return qfalse;
- }
+ item->typeData.list->columnInfo[i].pos = pos;
+ item->typeData.list->columnInfo[i].width = width;
+ item->typeData.list->columnInfo[i].align = align;
}
- else
- return qfalse;
return qtrue;
}
@@ -7123,19 +7046,10 @@ qboolean ItemParse_cinematic( itemDef_t *item, int handle )
qboolean ItemParse_doubleClick( itemDef_t *item, int handle )
{
- listBoxDef_t *listPtr;
-
Item_ValidateTypeData( item );
- if( !item->typeData )
- return qfalse;
-
- listPtr = ( listBoxDef_t* )item->typeData;
-
- if( !PC_Script_Parse( handle, &listPtr->doubleClick ) )
- return qfalse;
-
- return qtrue;
+ return ( item->typeData.list &&
+ PC_Script_Parse( handle, &item->typeData.list->doubleClick ) );
}
qboolean ItemParse_onFocus( itemDef_t *item, int handle )
@@ -7220,19 +7134,16 @@ qboolean ItemParse_cvarTest( itemDef_t *item, int handle )
qboolean ItemParse_cvar( itemDef_t *item, int handle )
{
- editFieldDef_t *editPtr;
-
Item_ValidateTypeData( item );
if( !PC_String_Parse( handle, &item->cvar ) )
return qfalse;
- if( item->typeData )
+ if( item->typeData.edit )
{
- editPtr = ( editFieldDef_t* )item->typeData;
- editPtr->minVal = -1;
- editPtr->maxVal = -1;
- editPtr->defVal = -1;
+ item->typeData.edit->minVal = -1;
+ item->typeData.edit->maxVal = -1;
+ item->typeData.edit->defVal = -1;
}
return qtrue;
@@ -7240,59 +7151,30 @@ qboolean ItemParse_cvar( itemDef_t *item, int handle )
qboolean ItemParse_maxChars( itemDef_t *item, int handle )
{
- editFieldDef_t *editPtr;
- int maxChars;
-
Item_ValidateTypeData( item );
- if( !item->typeData )
- return qfalse;
-
- if( !PC_Int_Parse( handle, &maxChars ) )
- return qfalse;
-
- editPtr = ( editFieldDef_t* )item->typeData;
- editPtr->maxChars = maxChars;
- return qtrue;
+ return ( item->typeData.edit &&
+ PC_Int_Parse( handle, &item->typeData.edit->maxChars ) );
}
qboolean ItemParse_maxPaintChars( itemDef_t *item, int handle )
{
- editFieldDef_t *editPtr;
- int maxChars;
-
Item_ValidateTypeData( item );
- if( !item->typeData )
- return qfalse;
-
- if( !PC_Int_Parse( handle, &maxChars ) )
- return qfalse;
-
- editPtr = ( editFieldDef_t* )item->typeData;
- editPtr->maxPaintChars = maxChars;
- return qtrue;
+ return ( item->typeData.edit &&
+ PC_Int_Parse( handle, &item->typeData.edit->maxPaintChars ) );
}
qboolean ItemParse_maxFieldWidth( itemDef_t *item, int handle )
{
- editFieldDef_t *editPtr;
- int maxFieldWidth;
-
Item_ValidateTypeData( item );
- if( !item->typeData )
+ if( !item->typeData.edit ||
+ !PC_Int_Parse( handle, &item->typeData.edit->maxFieldWidth ) )
return qfalse;
- if( !PC_Int_Parse( handle, &maxFieldWidth ) )
- return qfalse;
-
- editPtr = ( editFieldDef_t* )item->typeData;
-
- if( maxFieldWidth < MIN_FIELD_WIDTH )
- editPtr->maxFieldWidth = MIN_FIELD_WIDTH;
- else
- editPtr->maxFieldWidth = maxFieldWidth;
+ if( item->typeData.edit->maxFieldWidth < MIN_FIELD_WIDTH )
+ item->typeData.edit->maxFieldWidth = MIN_FIELD_WIDTH;
return qtrue;
}
@@ -7301,22 +7183,13 @@ qboolean ItemParse_maxFieldWidth( itemDef_t *item, int handle )
qboolean ItemParse_cvarFloat( itemDef_t *item, int handle )
{
- editFieldDef_t *editPtr;
-
Item_ValidateTypeData( item );
- if( !item->typeData )
- return qfalse;
-
- editPtr = ( editFieldDef_t* )item->typeData;
-
- if( PC_String_Parse( handle, &item->cvar ) &&
- PC_Float_Parse( handle, &editPtr->defVal ) &&
- PC_Float_Parse( handle, &editPtr->minVal ) &&
- PC_Float_Parse( handle, &editPtr->maxVal ) )
- return qtrue;
-
- return qfalse;
+ return ( item->typeData.edit &&
+ PC_String_Parse( handle, &item->cvar ) &&
+ PC_Float_Parse( handle, &item->typeData.edit->defVal ) &&
+ PC_Float_Parse( handle, &item->typeData.edit->minVal ) &&
+ PC_Float_Parse( handle, &item->typeData.edit->maxVal ) );
}
qboolean ItemParse_cvarStrList( itemDef_t *item, int handle )
@@ -7327,13 +7200,11 @@ qboolean ItemParse_cvarStrList( itemDef_t *item, int handle )
Item_ValidateTypeData( item );
- if( !item->typeData )
+ if( !item->typeData.multi )
return qfalse;
- multiPtr = ( multiDef_t* )item->typeData;
-
+ multiPtr = item->typeData.multi;
multiPtr->count = 0;
-
multiPtr->strDef = qtrue;
if( !trap_Parse_ReadToken( handle, &token ) )
@@ -7385,13 +7256,11 @@ qboolean ItemParse_cvarFloatList( itemDef_t *item, int handle )
Item_ValidateTypeData( item );
- if( !item->typeData )
+ if( !item->typeData.multi )
return qfalse;
- multiPtr = ( multiDef_t* )item->typeData;
-
+ multiPtr = item->typeData.multi;
multiPtr->count = 0;
-
multiPtr->strDef = qfalse;
if( !trap_Parse_ReadToken( handle, &token ) )
@@ -7650,15 +7519,14 @@ void Item_InitControls( itemDef_t *item )
if( item->type == ITEM_TYPE_LISTBOX )
{
- listBoxDef_t *listPtr = ( listBoxDef_t* )item->typeData;
item->cursorPos = 0;
- if( listPtr )
+ if( item->typeData.list )
{
- listPtr->cursorPos = 0;
- listPtr->startPos = 0;
- listPtr->endPos = 0;
- listPtr->cursorPos = 0;
+ item->typeData.list->cursorPos = 0;
+ item->typeData.list->startPos = 0;
+ item->typeData.list->endPos = 0;
+ item->typeData.list->cursorPos = 0;
}
}
}
diff --git a/src/ui/ui_shared.h b/src/ui/ui_shared.h
index 48bf78cd..c42dd241 100644
--- a/src/ui/ui_shared.h
+++ b/src/ui/ui_shared.h
@@ -282,7 +282,15 @@ typedef struct itemDef_s
colorRangeDef_t colorRanges[MAX_COLOR_RANGES];
float special; // used for feeder id's etc.. diff per type
int cursorPos; // cursor position in characters
- void *typeData; // type specific data ptr's
+ union
+ {
+ void *data;
+ listBoxDef_t *list;
+ editFieldDef_t *edit;
+ multiDef_t *multi;
+ comboBoxDef_t *combo;
+ modelDef_t *model;
+ } typeData; // type specific data pointers
}
itemDef_t;