Skip to content

Commit

Permalink
Decrease number of arguments of UI_DrawString
Browse files Browse the repository at this point in the history
  • Loading branch information
a1batross committed Jul 22, 2018
1 parent 78120a3 commit 99a8998
Show file tree
Hide file tree
Showing 20 changed files with 161 additions and 166 deletions.
22 changes: 11 additions & 11 deletions BaseMenu.cpp
Expand Up @@ -319,17 +319,17 @@ UI_DrawString
=================
*/
int UI_DrawString( HFont font, int x, int y, int w, int h,
const char *string, const unsigned int color, bool forceColor,
int charH, ETextAlignment justify, bool shadow, bool limitBySize )
const char *string, const unsigned int color,
int charH, ETextAlignment justify, uint flags )
{
int modulate, shadowModulate;
uint modulate, shadowModulate = 0;
int xx = 0, yy, ofsX = 0, ofsY = 0, ch;
int maxX = x;

if( !string || !string[0] )
return x;

if( shadow )
if( flags & ETF_SHADOW )
{
shadowModulate = PackAlpha( uiColorBlack, UnpackAlpha( color ));

Expand Down Expand Up @@ -415,9 +415,9 @@ int UI_DrawString( HFont font, int x, int y, int w, int h,

charWide = g_FontMgr.GetCharacterWidthScaled( font, uch, charH );

if( limitBySize && pixelWide + charWide >= w )
if( !(flags & ETF_NOSIZELIMIT) && pixelWide + charWide > w )
{
// does we have free space for new line?
// do we have free space for new line?
if( yy < (yy + h) - charH )
{
// try to word wrap
Expand Down Expand Up @@ -492,7 +492,7 @@ int UI_DrawString( HFont font, int x, int y, int w, int h,
{
modulate = color;
}
else if( !forceColor )
else if( !(flags & ETF_FORCECOL) )
{
modulate = PackAlpha( g_iColorTable[colorNum], UnpackAlpha( color ));
}
Expand All @@ -509,19 +509,19 @@ int UI_DrawString( HFont font, int x, int y, int w, int h,
if( !ch )
continue;

if( shadow )
g_FontMgr.DrawCharacter( font, ch, Point( xx + ofsX, yy + ofsY ), charH, shadowModulate );
if( flags & ETF_SHADOW )
g_FontMgr.DrawCharacter( font, ch, Point( xx + ofsX, yy + ofsY ), charH, shadowModulate, flags & ETF_ADDITIVE );

#ifdef DEBUG_WHITESPACE
if( ch == ' ' )
{
g_FontMgr.DrawCharacter( font, '_', Point( xx, yy ), charH, modulate );
g_FontMgr.DrawCharacter( font, '_', Point( xx, yy ), charH, modulate, flags & ETF_ADDITIVE );
xx += g_FontMgr.GetCharacterWidthScaled( font, ch, charH );
continue;
}
#endif

xx += g_FontMgr.DrawCharacter( font, ch, Point( xx, yy ), charH, modulate );
xx += g_FontMgr.DrawCharacter( font, ch, Point( xx, yy ), charH, modulate, flags & ETF_ADDITIVE );

maxX = Q_max( xx, maxX );
}
Expand Down
20 changes: 15 additions & 5 deletions BaseMenu.h
Expand Up @@ -183,13 +183,27 @@ bool UI_CursorInRect( int x, int y, int w, int h );
void UI_EnableAlphaFactor( float a );
void UI_DisableAlphaFactor();

enum ETextFlags
{
ETF_FORCECOL = BIT( 0 ),
ETF_SHADOW = BIT( 1 ),
ETF_NOSIZELIMIT = BIT( 2 ),
ETF_ADDITIVE = BIT( 3 )
};

int UI_DrawString( HFont font, int x, int y, int w, int h, const char *str, const unsigned int col, int charH, ETextAlignment justify, uint flags = 0 );
inline int UI_DrawString( HFont font, Point pos, Size size, const char *str, const unsigned int col, int charH, ETextAlignment justify, uint flags = 0 )
{
return UI_DrawString( font, pos.x, pos.y, size.w, size.h, str, col, charH, justify, flags );
}

void UI_DrawPic( int x, int y, int w, int h, const unsigned int color, const char *pic );
void UI_DrawPicAdditive( int x, int y, int w, int h, const unsigned int color, const char *pic );
void UI_DrawPicTrans( int x, int y, int width, int height, const unsigned int color, const char *pic );
void UI_DrawPicHoles( int x, int y, int width, int height, const unsigned int color, const char *pic );
void UI_FillRect( int x, int y, int w, int h, const unsigned int color );
void UI_DrawRectangleExt(int in_x, int in_y, int in_w, int in_h, const unsigned int color, int outlineWidth, int flag = QM_TOP | QM_BOTTOM | QM_LEFT | QM_RIGHT);
int UI_DrawString( HFont font, int x, int y, int w, int h, const char *str, const unsigned int col, bool forceCol, int charH, ETextAlignment justify, bool shadow, bool limitBySize = true );

inline void UI_DrawRectangle( int x, int y, int w, int h, const unsigned int color, int flag = QM_TOP | QM_BOTTOM | QM_LEFT | QM_RIGHT)
{
UI_DrawRectangleExt( x, y, w, h, color, uiStatic.outlineWidth, flag );
Expand Down Expand Up @@ -227,10 +241,6 @@ inline void UI_DrawRectangleExt( Point pos, Size size, const unsigned int color,
{
UI_DrawRectangleExt( pos.x, pos.y, size.w, size.h, color, outlineWidth, flag );
}
inline int UI_DrawString( HFont font, Point pos, Size size, const char *str, const unsigned int col, bool forceCol, Size chSize, ETextAlignment justify, bool shadow, bool limitBySize = true )
{
return UI_DrawString( font, pos.x, pos.y, size.w, size.h, str, col, forceCol, chSize.h, justify, shadow, limitBySize );
}

void UI_StartSound( const char *sound );
void UI_LoadBmpButtons( void );
Expand Down
18 changes: 0 additions & 18 deletions Color.h
Expand Up @@ -22,44 +22,26 @@ class CColor
public:
CColor( ) : rgba( 0 ), init( false ) { }
CColor( unsigned int rgba ) : rgba( rgba ), init( false ) { }
CColor( int rgba ) : rgba( (unsigned int)rgba ), init( false ) { }

inline unsigned int operator =( unsigned int color )
{
Set( color );
return color;
}
inline int operator =( int color )
{
Set( color );
return color;
}

inline operator unsigned int() { return rgba; }
inline operator int() { return (int)rgba; }

inline void Set( unsigned int color )
{
rgba = color;
init = true;
}

inline void Set( int color )
{
rgba = (unsigned int)color;
init = true;
}

inline void SetDefault( unsigned int color )
{
if( !IsOk() ) Set( color );
}

inline void SetDefault( int color )
{
if( !IsOk() ) Set( color );
}

// get rid of this someday
inline bool IsOk() { return init; }

Expand Down
7 changes: 3 additions & 4 deletions EngineCallback.cpp
Expand Up @@ -58,15 +58,14 @@ int EngFuncs::DrawConsoleString(int x, int y, const char *string)
{
Point pt( x, y );
Size sz;
Size charSz;
int charSz;

sz.w = ScreenWidth - pt.x;
sz.h = ScreenHeight - pt.y;

charSz.w = 0;
charSz.h = g_FontMgr.GetFontTall( uiStatic.hConsoleFont );
charSz = g_FontMgr.GetFontTall( uiStatic.hConsoleFont );

return UI_DrawString( uiStatic.hConsoleFont, pt, sz, string, color, false, charSz, QM_TOPLEFT, false );
return UI_DrawString( uiStatic.hConsoleFont, pt, sz, string, color, charSz, QM_TOPLEFT );
}

void EngFuncs::ConsoleStringLen(const char *string, int *length, int *height)
Expand Down
4 changes: 2 additions & 2 deletions Utils.h
Expand Up @@ -103,7 +103,7 @@ inline unsigned int PackAlpha( const unsigned int ulRGB, const unsigned int ulAl
return (ulRGB)|(ulAlpha<<24);
}

inline int UnpackAlpha( const unsigned int ulRGBA )
inline unsigned int UnpackAlpha( const unsigned int ulRGBA )
{
return ((ulRGBA & 0xFF000000) >> 24);
}
Expand All @@ -113,7 +113,7 @@ inline float InterpVal( const float from, const float to, const float frac )
return from + (to - from) * frac;
}

inline int InterpColor( const int from, const int to, const float frac )
inline unsigned int InterpColor( const unsigned int from, const unsigned int to, const float frac )
{
return PackRGBA(
InterpVal( Red( from ), Red( to ), frac ),
Expand Down
14 changes: 7 additions & 7 deletions controls/Action.cpp
Expand Up @@ -46,10 +46,10 @@ void CMenuAction::VidInit( )
else
{
if( size.w < 1 )
size.w = g_FontMgr.GetTextWideScaled( font, szName, charSize.h ) / uiStatic.scaleX;
size.w = g_FontMgr.GetTextWideScaled( font, szName, charSize ) / uiStatic.scaleX;

if( size.h < 1 )
size.h = charSize.h * 1.5;
size.h = charSize * 1.5;
}

m_bLimitBySize = false;
Expand Down Expand Up @@ -119,7 +119,7 @@ CMenuAction::Draw
*/
void CMenuAction::Draw( )
{
bool shadow = (iFlags & QMF_DROPSHADOW);
uint textflags = ( iFlags & QMF_DROPSHADOW ? ETF_SHADOW : 0 ) | ( m_bLimitBySize ? 0 : ETF_NOSIZELIMIT );

if( m_szBackground )
UI_DrawPic( m_scPos, m_scSize, m_iBackcolor, m_szBackground );
Expand All @@ -142,27 +142,27 @@ void CMenuAction::Draw( )

if( iFlags & QMF_GRAYED )
{
UI_DrawString( font, m_scPos, m_scSize, szName, uiColorDkGrey, true, m_scChSize, eTextAlignment, shadow, m_bLimitBySize );
UI_DrawString( font, m_scPos, m_scSize, szName, uiColorDkGrey, m_scChSize, eTextAlignment, textflags | ETF_FORCECOL );
return; // grayed
}

if( this != m_pParent->ItemAtCursor() )
{
UI_DrawString( font, m_scPos, m_scSize, szName, iColor, false, m_scChSize, eTextAlignment, shadow, m_bLimitBySize );
UI_DrawString( font, m_scPos, m_scSize, szName, iColor, m_scChSize, eTextAlignment, textflags );
return; // no focus
}

if( eFocusAnimation == QM_HIGHLIGHTIFFOCUS )
{
UI_DrawString( font, m_scPos, m_scSize, szName, iFocusColor, false, m_scChSize, eTextAlignment, shadow, m_bLimitBySize );
UI_DrawString( font, m_scPos, m_scSize, szName, iFocusColor, m_scChSize, eTextAlignment, textflags );
}
else if( eFocusAnimation == QM_PULSEIFFOCUS )
{
int color;

color = PackAlpha( iColor, 255 * (0.5 + 0.5 * sin( (float)uiStatic.realTime / UI_PULSE_DIVISOR )));

UI_DrawString( font, m_scPos, m_scSize, szName, color, false, m_scChSize, eTextAlignment, shadow, m_bLimitBySize );
UI_DrawString( font, m_scPos, m_scSize, szName, color, m_scChSize, eTextAlignment, textflags );
}
}

Expand Down
13 changes: 5 additions & 8 deletions controls/BaseItem.cpp
Expand Up @@ -95,16 +95,13 @@ void CMenuBaseItem::SetCharSize(EFontSizes fs)
case QM_LIGHTBLUR:
case QM_HEAVYBLUR:
#endif
charSize.w = UI_MED_CHAR_WIDTH;
charSize.h = UI_MED_CHAR_HEIGHT;
charSize = UI_MED_CHAR_HEIGHT;
break;
case QM_SMALLFONT:
charSize.w = UI_SMALL_CHAR_WIDTH;
charSize.h = UI_SMALL_CHAR_HEIGHT;
charSize = UI_SMALL_CHAR_HEIGHT;
break;
case QM_BIGFONT:
charSize.w = UI_BIG_CHAR_WIDTH;
charSize.h = UI_BIG_CHAR_HEIGHT;
charSize = UI_BIG_CHAR_HEIGHT;
break;
}
}
Expand Down Expand Up @@ -187,15 +184,15 @@ void CMenuBaseItem::CalcPosition()

void CMenuBaseItem::CalcSizes()
{
m_scChSize = charSize;
if( iFlags & QMF_DISABLESCAILING )
{
m_scSize = size;
m_scChSize = charSize;
}
else
{
m_scSize = size.Scale();
m_scChSize = charSize.Scale();
m_scChSize *= uiStatic.scaleY;
}

if( m_scSize.w < 0 )
Expand Down
7 changes: 3 additions & 4 deletions controls/BaseItem.h
Expand Up @@ -134,7 +134,6 @@ class CMenuBaseItem
inline void SetCoord( int x, int y ) { pos.x = x; pos.y = y; }
inline void SetSize( int w, int h ) { size.w = w; size.h = h; }
inline void SetRect( int x, int y, int w, int h ) { SetCoord( x, y ); SetSize( w, h ); }
// inline void SetCharSize( int w, int h ) { charSize.w = w; charSize.h = h; }
inline Point GetRenderPosition() const { return m_scPos; }
inline Size GetRenderSize() const { return m_scSize; }

Expand All @@ -144,7 +143,7 @@ class CMenuBaseItem
{
szName = name;
szStatusText = status;
if( tag ) szTag = tag;
szTag = tag;
}

CMenuItemsHolder* Parent() const { return m_pParent; }
Expand All @@ -156,7 +155,7 @@ class CMenuBaseItem

Point pos;
Size size;
Size charSize;
int charSize;

const char *szName;
const char *szStatusText;
Expand Down Expand Up @@ -189,7 +188,7 @@ class CMenuBaseItem

Point m_scPos;
Size m_scSize;
Size m_scChSize;
int m_scChSize;
};

#include "ItemsHolder.h"
Expand Down
8 changes: 4 additions & 4 deletions controls/CheckBox.cpp
Expand Up @@ -48,8 +48,8 @@ void CMenuCheckBox::VidInit( void )
m_scTextPos.x = m_scPos.x + (m_scSize.w * 1.5f );
m_scTextPos.y = m_scPos.y;

m_scTextSize.w = g_FontMgr.GetTextWideScaled( font, szName, m_scChSize.h );
m_scTextSize.h = m_scChSize.h;
m_scTextSize.w = g_FontMgr.GetTextWideScaled( font, szName, m_scChSize );
m_scTextSize.h = m_scChSize;
}

/*
Expand Down Expand Up @@ -122,9 +122,9 @@ CMenuCheckBox::Draw
*/
void CMenuCheckBox::Draw( void )
{
bool shadow = (iFlags & QMF_DROPSHADOW);
uint textflags = ( iFlags & QMF_DROPSHADOW ? ETF_SHADOW : 0 ) | ETF_NOSIZELIMIT | ETF_FORCECOL;

UI_DrawString( font, m_scTextPos, m_scTextSize, szName, uiColorHelp, true, m_scChSize, eTextAlignment, shadow, false );
UI_DrawString( font, m_scTextPos, m_scTextSize, szName, uiColorHelp, m_scChSize, eTextAlignment, textflags );

if( szStatusText && iFlags & QMF_NOTIFY )
{
Expand Down

0 comments on commit 99a8998

Please sign in to comment.