mirror of
https://github.com/fortressforever/fortressforever-2013.git
synced 2024-11-10 07:11:45 +00:00
Made LuaUI_BasePanel's SetPos/SetSize/DrawText functions use proportionality, so that size/position is scaled appropriately depending on your resolution
* SetPos can use .res-style string parameters with the 'r' and 'c' prefixes to set alignment * SetSize can use .res-style string parameters with the 'f' prefix to make it fill its parent Had to edit vgui_controls/Panel.h to make a few member variables protected instead of private
This commit is contained in:
parent
369121c058
commit
450bf12e72
4 changed files with 253 additions and 3 deletions
|
@ -82,13 +82,21 @@ void FF_Lua_InitUI( lua_State *L )
|
||||||
.def("SetPaintBackgroundEnabled", &vgui::Panel::SetPaintBackgroundEnabled)
|
.def("SetPaintBackgroundEnabled", &vgui::Panel::SetPaintBackgroundEnabled)
|
||||||
.def("SetPaintBackgroundType", &vgui::Panel::SetPaintBackgroundType)
|
.def("SetPaintBackgroundType", &vgui::Panel::SetPaintBackgroundType)
|
||||||
.def("GetSize", &vgui::Panel::GetSize, pure_out_value(_2) + pure_out_value(_3)) // _1 is the this pointer
|
.def("GetSize", &vgui::Panel::GetSize, pure_out_value(_2) + pure_out_value(_3)) // _1 is the this pointer
|
||||||
.def("SetSize", &vgui::Panel::SetSize)
|
.def("SetRawSize", &vgui::Panel::SetSize)
|
||||||
.def("GetPos", &vgui::Panel::GetPos, pure_out_value(_2) + pure_out_value(_3)) // _1 is the this pointer
|
.def("GetPos", &vgui::Panel::GetPos, pure_out_value(_2) + pure_out_value(_3)) // _1 is the this pointer
|
||||||
.def("SetPos", &vgui::Panel::SetPos)
|
.def("SetRawPos", &vgui::Panel::SetPos)
|
||||||
.def("SetEnabled", &vgui::Panel::SetEnabled),
|
.def("SetEnabled", &vgui::Panel::SetEnabled),
|
||||||
|
|
||||||
class_<CFF_CL_LuaUI_BasePanel, bases<CHudElement, vgui::Panel>>("Panel")
|
class_<CFF_CL_LuaUI_BasePanel, bases<CHudElement, vgui::Panel>>("Panel")
|
||||||
.def(constructor<lua_State *, const char *>())
|
.def(constructor<lua_State *, const char *>())
|
||||||
|
.def("SetPos", (void(CFF_CL_LuaUI_BasePanel::*)(const char*, const char*))&CFF_CL_LuaUI_BasePanel::SetProportionalPos)
|
||||||
|
.def("SetPos", (void(CFF_CL_LuaUI_BasePanel::*)(int, int))&CFF_CL_LuaUI_BasePanel::SetProportionalPos)
|
||||||
|
.def("SetWide", (void(CFF_CL_LuaUI_BasePanel::*)(const char*))&CFF_CL_LuaUI_BasePanel::SetProportionalWide)
|
||||||
|
.def("SetWide", (void(CFF_CL_LuaUI_BasePanel::*)(int))&CFF_CL_LuaUI_BasePanel::SetProportionalWide)
|
||||||
|
.def("SetTall", (void(CFF_CL_LuaUI_BasePanel::*)(const char*))&CFF_CL_LuaUI_BasePanel::SetProportionalTall)
|
||||||
|
.def("SetTall", (void(CFF_CL_LuaUI_BasePanel::*)(int))&CFF_CL_LuaUI_BasePanel::SetProportionalTall)
|
||||||
|
.def("SetSize", (void(CFF_CL_LuaUI_BasePanel::*)(const char*, const char*))&CFF_CL_LuaUI_BasePanel::SetProportionalSize)
|
||||||
|
.def("SetSize", (void(CFF_CL_LuaUI_BasePanel::*)(int, int))&CFF_CL_LuaUI_BasePanel::SetProportionalSize)
|
||||||
.def("DrawText", &CFF_CL_LuaUI_BasePanel::DrawText)
|
.def("DrawText", &CFF_CL_LuaUI_BasePanel::DrawText)
|
||||||
.def("DrawBox", &CFF_CL_LuaUI_BasePanel::DrawBox),
|
.def("DrawBox", &CFF_CL_LuaUI_BasePanel::DrawBox),
|
||||||
|
|
||||||
|
|
|
@ -95,6 +95,7 @@ void CFF_CL_LuaUI_BasePanel::Paint()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Drawtext helper function
|
||||||
void CFF_CL_LuaUI_BasePanel::DrawText( const char *szText, int xpos, int ypos )
|
void CFF_CL_LuaUI_BasePanel::DrawText( const char *szText, int xpos, int ypos )
|
||||||
{
|
{
|
||||||
wchar_t wszText[255];
|
wchar_t wszText[255];
|
||||||
|
@ -107,6 +108,230 @@ void CFF_CL_LuaUI_BasePanel::DrawText( const char *szText, int xpos, int ypos )
|
||||||
|
|
||||||
surface()->DrawSetTextFont(font);
|
surface()->DrawSetTextFont(font);
|
||||||
surface()->DrawSetTextColor(GetFgColor());
|
surface()->DrawSetTextColor(GetFgColor());
|
||||||
|
|
||||||
|
if (IsProportional())
|
||||||
|
{
|
||||||
|
xpos = scheme()->GetProportionalScaledValueEx(GetScheme(), xpos);
|
||||||
|
ypos = scheme()->GetProportionalScaledValueEx(GetScheme(), ypos);
|
||||||
|
}
|
||||||
|
|
||||||
surface()->DrawSetTextPos(xpos, ypos);
|
surface()->DrawSetTextPos(xpos, ypos);
|
||||||
surface()->DrawUnicodeString( wszText );
|
surface()->DrawUnicodeString( wszText );
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
==========================================================
|
||||||
|
Note: Proportional width/height/pos code is based on
|
||||||
|
vgui::Panel::ApplySettings in Panel.cpp
|
||||||
|
|
||||||
|
FF TODO: Rewrite this to be more Lua-friendly (get rid of
|
||||||
|
string-based alignment settings)
|
||||||
|
==========================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
/// Set width proportionally
|
||||||
|
void CFF_CL_LuaUI_BasePanel::SetProportionalWide( int wide )
|
||||||
|
{
|
||||||
|
if ( IsProportional() )
|
||||||
|
{
|
||||||
|
// scale the width up to our screen co-ords
|
||||||
|
wide = scheme()->GetProportionalScaledValueEx(GetScheme(), wide);
|
||||||
|
}
|
||||||
|
|
||||||
|
BaseClass::SetWide( wide );
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set width proportionally with an optional 'f' prefix to fill the parent
|
||||||
|
void CFF_CL_LuaUI_BasePanel::SetProportionalWide( const char *wstr )
|
||||||
|
{
|
||||||
|
int iScreenWide, iScreenTall;
|
||||||
|
surface()->GetScreenSize( iScreenWide, iScreenTall );
|
||||||
|
|
||||||
|
_buildModeFlags &= ~(BUILDMODE_SAVE_WIDE_FULL);
|
||||||
|
|
||||||
|
if (wstr[0] == 'f' || wstr[0] == 'F')
|
||||||
|
{
|
||||||
|
_buildModeFlags |= BUILDMODE_SAVE_WIDE_FULL;
|
||||||
|
wstr++;
|
||||||
|
}
|
||||||
|
int wide = atoi(wstr);
|
||||||
|
// now correct the alignment
|
||||||
|
if (_buildModeFlags & BUILDMODE_SAVE_WIDE_FULL)
|
||||||
|
{
|
||||||
|
wide = iScreenWide - wide;
|
||||||
|
}
|
||||||
|
|
||||||
|
SetProportionalWide( wide );
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set height proportionally
|
||||||
|
void CFF_CL_LuaUI_BasePanel::SetProportionalTall( int tall )
|
||||||
|
{
|
||||||
|
if ( IsProportional() )
|
||||||
|
{
|
||||||
|
// scale the height up to our screen co-ords
|
||||||
|
tall = scheme()->GetProportionalScaledValueEx(GetScheme(), tall);
|
||||||
|
}
|
||||||
|
|
||||||
|
BaseClass::SetTall( tall );
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set height proportionally with an optional 'f' prefix to fill the parent
|
||||||
|
void CFF_CL_LuaUI_BasePanel::SetProportionalTall( const char *hstr )
|
||||||
|
{
|
||||||
|
int iScreenWide, iScreenTall;
|
||||||
|
surface()->GetScreenSize( iScreenWide, iScreenTall );
|
||||||
|
|
||||||
|
_buildModeFlags &= ~(BUILDMODE_SAVE_TALL_FULL);
|
||||||
|
|
||||||
|
// allow tall to be use the "fill" option, set to the height of the parent/screen
|
||||||
|
if (hstr[0] == 'f' || hstr[0] == 'F')
|
||||||
|
{
|
||||||
|
_buildModeFlags |= BUILDMODE_SAVE_TALL_FULL;
|
||||||
|
hstr++;
|
||||||
|
}
|
||||||
|
int tall = atoi(hstr);
|
||||||
|
// now correct the alignment
|
||||||
|
if (_buildModeFlags & BUILDMODE_SAVE_TALL_FULL)
|
||||||
|
{
|
||||||
|
tall = iScreenTall - tall;
|
||||||
|
}
|
||||||
|
|
||||||
|
SetProportionalTall( tall );
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set size proportionally
|
||||||
|
void CFF_CL_LuaUI_BasePanel::SetProportionalSize( int w, int h )
|
||||||
|
{
|
||||||
|
SetProportionalWide( w );
|
||||||
|
SetProportionalTall( h );
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set size proportionally with optional 'f' prefixes to fill the parent
|
||||||
|
void CFF_CL_LuaUI_BasePanel::SetProportionalSize( const char *wstr, const char *hstr )
|
||||||
|
{
|
||||||
|
SetProportionalWide( wstr );
|
||||||
|
SetProportionalTall( hstr );
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set position proportionally
|
||||||
|
void CFF_CL_LuaUI_BasePanel::SetProportionalPos( int x, int y )
|
||||||
|
{
|
||||||
|
// scale the x up to our screen co-ords
|
||||||
|
if ( IsProportional() )
|
||||||
|
{
|
||||||
|
x = scheme()->GetProportionalScaledValueEx(GetScheme(), x);
|
||||||
|
y = scheme()->GetProportionalScaledValueEx(GetScheme(), y);
|
||||||
|
}
|
||||||
|
|
||||||
|
BaseClass::SetPos( x, y );
|
||||||
|
}
|
||||||
|
|
||||||
|
void CFF_CL_LuaUI_BasePanel::SetProportionalPos( const char *xstr, const char *ystr )
|
||||||
|
{
|
||||||
|
// clear any alignment flags
|
||||||
|
_buildModeFlags &= ~(BUILDMODE_SAVE_XPOS_RIGHTALIGNED | BUILDMODE_SAVE_XPOS_CENTERALIGNED | BUILDMODE_SAVE_YPOS_BOTTOMALIGNED | BUILDMODE_SAVE_YPOS_CENTERALIGNED | BUILDMODE_SAVE_PROPORTIONAL_TO_PARENT);
|
||||||
|
|
||||||
|
// get the position
|
||||||
|
int alignScreenWide, alignScreenTall; // screen dimensions used for pinning in splitscreen
|
||||||
|
surface()->GetScreenSize( alignScreenWide, alignScreenTall );
|
||||||
|
|
||||||
|
int screenWide = alignScreenWide;
|
||||||
|
int screenTall = alignScreenTall;
|
||||||
|
|
||||||
|
// temporarily remove the override to get the fullscreen dimensions
|
||||||
|
if ( surface()->IsScreenSizeOverrideActive() )
|
||||||
|
{
|
||||||
|
surface()->ForceScreenSizeOverride( false, 0, 0 );
|
||||||
|
surface()->GetScreenSize( screenWide, screenTall );
|
||||||
|
|
||||||
|
// restore the override
|
||||||
|
surface()->ForceScreenSizeOverride( true, alignScreenWide, alignScreenTall );
|
||||||
|
}
|
||||||
|
|
||||||
|
int parentX = 0;
|
||||||
|
int parentY = 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
// flag to cause windows to get screenWide and screenTall from their parents,
|
||||||
|
// this allows children windows to use fill and right/bottom alignment even
|
||||||
|
// if their parent does not use the full screen.
|
||||||
|
if ( inResourceData->GetInt( "proportionalToParent", 0 ) == 1 )
|
||||||
|
{
|
||||||
|
_buildModeFlags |= BUILDMODE_SAVE_PROPORTIONAL_TO_PARENT;
|
||||||
|
if ( GetParent() != NULL )
|
||||||
|
{
|
||||||
|
GetParent()->GetBounds( parentX, parentY, alignScreenWide, alignScreenTall );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
int x, y;
|
||||||
|
GetPos(x, y);
|
||||||
|
|
||||||
|
if (xstr)
|
||||||
|
{
|
||||||
|
// look for alignment flags
|
||||||
|
if (xstr[0] == 'r' || xstr[0] == 'R')
|
||||||
|
{
|
||||||
|
_buildModeFlags |= BUILDMODE_SAVE_XPOS_RIGHTALIGNED;
|
||||||
|
xstr++;
|
||||||
|
}
|
||||||
|
else if (xstr[0] == 'c' || xstr[0] == 'C')
|
||||||
|
{
|
||||||
|
_buildModeFlags |= BUILDMODE_SAVE_XPOS_CENTERALIGNED;
|
||||||
|
xstr++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get the value
|
||||||
|
x = atoi(xstr);
|
||||||
|
|
||||||
|
// scale the x up to our screen co-ords
|
||||||
|
if ( IsProportional() )
|
||||||
|
{
|
||||||
|
x = scheme()->GetProportionalScaledValueEx(GetScheme(), x);
|
||||||
|
y = scheme()->GetProportionalScaledValueEx(GetScheme(), y);
|
||||||
|
}
|
||||||
|
// now correct the alignment
|
||||||
|
if (_buildModeFlags & BUILDMODE_SAVE_XPOS_RIGHTALIGNED)
|
||||||
|
{
|
||||||
|
x = alignScreenWide - x;
|
||||||
|
}
|
||||||
|
else if (_buildModeFlags & BUILDMODE_SAVE_XPOS_CENTERALIGNED)
|
||||||
|
{
|
||||||
|
x = (alignScreenWide / 2) + x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ystr)
|
||||||
|
{
|
||||||
|
// look for alignment flags
|
||||||
|
if (ystr[0] == 'r' || ystr[0] == 'R')
|
||||||
|
{
|
||||||
|
_buildModeFlags |= BUILDMODE_SAVE_YPOS_BOTTOMALIGNED;
|
||||||
|
ystr++;
|
||||||
|
}
|
||||||
|
else if (ystr[0] == 'c' || ystr[0] == 'C')
|
||||||
|
{
|
||||||
|
_buildModeFlags |= BUILDMODE_SAVE_YPOS_CENTERALIGNED;
|
||||||
|
ystr++;
|
||||||
|
}
|
||||||
|
y = atoi(ystr);
|
||||||
|
if (IsProportional())
|
||||||
|
{
|
||||||
|
// scale the y up to our screen co-ords
|
||||||
|
y = scheme()->GetProportionalScaledValueEx(GetScheme(), y);
|
||||||
|
}
|
||||||
|
// now correct the alignment
|
||||||
|
if (_buildModeFlags & BUILDMODE_SAVE_YPOS_BOTTOMALIGNED)
|
||||||
|
{
|
||||||
|
y = alignScreenTall - y;
|
||||||
|
}
|
||||||
|
else if (_buildModeFlags & BUILDMODE_SAVE_YPOS_CENTERALIGNED)
|
||||||
|
{
|
||||||
|
y = (alignScreenTall / 2) + y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BaseClass::SetPos( x, y );
|
||||||
}
|
}
|
|
@ -24,6 +24,16 @@ public:
|
||||||
virtual void Paint();
|
virtual void Paint();
|
||||||
// --> from vgui::Panel
|
// --> from vgui::Panel
|
||||||
|
|
||||||
|
void SetProportionalWide( int wide );
|
||||||
|
void SetProportionalWide( const char *wstr );
|
||||||
|
void SetProportionalTall( int tall );
|
||||||
|
void SetProportionalTall( const char *hstr );
|
||||||
|
void SetProportionalSize( int w, int h );
|
||||||
|
void SetProportionalSize( const char *wstr, const char *hstr );
|
||||||
|
|
||||||
|
void SetProportionalPos( int x, int y );
|
||||||
|
void SetProportionalPos( const char *xstr, const char *ystr );
|
||||||
|
|
||||||
void DrawText( const char *szText, int xpos, int ypos );
|
void DrawText( const char *szText, int xpos, int ypos );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -722,7 +722,8 @@ protected:
|
||||||
bool m_PassUnhandledInput;
|
bool m_PassUnhandledInput;
|
||||||
NAV_DIRECTION m_LastNavDirection;
|
NAV_DIRECTION m_LastNavDirection;
|
||||||
|
|
||||||
private:
|
// FF --> Make these accessible in derived classes
|
||||||
|
protected:
|
||||||
enum BuildModeFlags_t
|
enum BuildModeFlags_t
|
||||||
{
|
{
|
||||||
BUILDMODE_EDITABLE = 0x01,
|
BUILDMODE_EDITABLE = 0x01,
|
||||||
|
@ -758,6 +759,8 @@ private:
|
||||||
IS_MOUSE_DISABLED_FOR_THIS_PANEL_ONLY = 0x8000,
|
IS_MOUSE_DISABLED_FOR_THIS_PANEL_ONLY = 0x8000,
|
||||||
ALL_FLAGS = 0xFFFF,
|
ALL_FLAGS = 0xFFFF,
|
||||||
};
|
};
|
||||||
|
private:
|
||||||
|
// FF <--
|
||||||
|
|
||||||
// used to get the Panel * for users with only IClientPanel
|
// used to get the Panel * for users with only IClientPanel
|
||||||
virtual Panel *GetPanel() { return this; }
|
virtual Panel *GetPanel() { return this; }
|
||||||
|
@ -849,7 +852,11 @@ private:
|
||||||
short m_nResizeDeltaY;
|
short m_nResizeDeltaY;
|
||||||
|
|
||||||
HCursor _cursor;
|
HCursor _cursor;
|
||||||
|
// FF --> Make this accessible in derived classes
|
||||||
|
protected:
|
||||||
unsigned short _buildModeFlags; // flags that control how the build mode dialog handles this panel
|
unsigned short _buildModeFlags; // flags that control how the build mode dialog handles this panel
|
||||||
|
private:
|
||||||
|
// FF <--
|
||||||
|
|
||||||
byte _pinCorner : 4; // the corner of the dialog this panel is pinned to
|
byte _pinCorner : 4; // the corner of the dialog this panel is pinned to
|
||||||
byte _autoResizeDirection : 4; // the directions in which the panel will auto-resize to
|
byte _autoResizeDirection : 4; // the directions in which the panel will auto-resize to
|
||||||
|
|
Loading…
Reference in a new issue