nuclide/Source/vgui/ui.cpp
Marco Hladik 97ea5e6208 Initial commit of the new VGUI replacement code. This dates back to the days
of TW 1.2 (the version that never got released) and besides some primitive
windowing is usable enough in its current state.

Misc fixes to FreeCS as well.
2019-08-03 10:40:34 -07:00

143 lines
3 KiB
C++

/***
*
* Copyright (c) 2016-2019 Marco 'eukara' Hladik. All rights reserved.
*
* See the file LICENSE attached with the sources for usage details.
*
****/
font_s g_fntDefault;
#if 0
var vector UI_MAINCOLOR;
var float UI_MAINALPHA;
#else
#define UI_MAINCOLOR '76 88 68' / 255
#define UI_MAINALPHA 255
#endif
int Util_MouseAbove(vector vecMousePos, vector vecPos, vector vecSize)
{
if (vecMousePos[0] >= vecPos[0] && vecMousePos[0] <= vecPos[0] + vecSize[0]) {
if (vecMousePos[1] >= vecPos[1] && vecMousePos[1] <= vecPos[1] + vecSize[1]) {
return 1;
}
}
return 0;
}
class CUIWidget
{
vector m_vecOrigin;
CUIWidget m_next;
CUIWidget m_parent;
int m_iFlags;
virtual void( CUIWidget ) Add;
virtual void( int ) FlagAdd;
virtual void( int ) FlagRemove;
virtual void( vector ) SetPos;
virtual vector() GetPos;
virtual int() GetPosWidth;
virtual int() GetPosHeight;
virtual void( ) Draw;
virtual void( float, float, float, float ) Input;
};
void CUIWidget :: SetPos ( vector vecPos )
{
m_vecOrigin = vecPos;
}
vector CUIWidget :: GetPos ( void )
{
return m_vecOrigin;
}
int CUIWidget :: GetPosWidth ( void )
{
return m_vecOrigin[0];
}
int CUIWidget :: GetPosHeight ( void )
{
return m_vecOrigin[1];
}
void CUIWidget :: FlagAdd ( int iFlag )
{
m_iFlags |= iFlag;
}
void CUIWidget :: FlagRemove ( int iFlag )
{
m_iFlags -= ( m_iFlags & iFlag );
}
void CUIWidget :: Add ( CUIWidget wNew )
{
CUIWidget wNext = this;
CUIWidget wParent;
do {
wParent = wNext;
wNext = wNext.m_next;
} while ( wNext );
wParent.m_next = wNew;
wNew.m_parent = this;
}
void CUIWidget :: Draw ( void )
{
CUIWidget wNext = this;
do {
wNext = wNext.m_next;
if ( wNext && wNext.m_iFlags & 1 && wNext.m_parent.m_iFlags & 1 ) {
wNext.Draw();
}
} while ( wNext );
}
void CUIWidget :: Input ( float flEVType, float flKey, float flChar, float flDevID )
{
CUIWidget wNext = this;
do {
wNext = wNext.m_next;
if ( wNext && wNext.m_iFlags & 1 && wNext.m_parent.m_iFlags & 1 ) {
wNext.Input( flEVType, flKey, flChar, flDevID );
}
} while ( wNext );
}
void UISystem_Init ( void )
{
/*string strTemp;
string strUIFile = "scripts/ui_style.txt";
filestream fileUI = fopen( strUIFile, FILE_READ );
UI_MAINCOLOR = '68 68 68' / 255;
UI_MAINALPHA = 1.0f;
if ( fileUI >= 0 ) {
while ( ( strTemp = fgets( fileUI ) ) ) {
if ( tokenizebyseparator( strTemp, "=" ) == 2 ) {
switch ( argv( 0 ) ) {
case "COLOR":
UI_MAINCOLOR = stov( argv( 1 ) ) / 255;
break;
case "ALPHA":
UI_MAINALPHA = stof( argv( 1 ) ) / 255;
break;
}
}
}
fclose( fileUI );
} else {
error( sprintf( "[MENU] Cannot load UI file %s!", strUIFile ) );
}*/
Font_Load( "scripts/ui_font.txt", g_fntDefault );
precache_pic( "textures/ui/steam/icon_radiosel" );
precache_pic( "textures/ui/steam/icon_radiounsel" );
precache_pic( "textures/ui/steam/icon_checked" );
precache_pic( "textures/ui/steam/icon_emptybox" );
precache_pic( "textures/ui/steam/icon_down" );
precache_pic( "textures/ui/steam/icon_up" );
precache_pic( "textures/ui/steam/icon_close" );
}