From 90685f24953472f616855ae5a864b53d8e752c68 Mon Sep 17 00:00:00 2001 From: Marco Cawthorne Date: Wed, 5 Apr 2023 10:58:12 -0700 Subject: [PATCH] Introducing VGUITheme, so we can start removing the CLASSIC_VGUI ifdef and start overriding visual appearance on any widget or group of widgets. --- src/vgui/include.src | 2 + src/vgui/ui.qc | 38 ++++--- src/vgui/ui_button.qc | 24 ++--- src/vgui/ui_checkbox.qc | 15 +-- src/vgui/ui_color.qc | 48 +++++++++ src/vgui/ui_frame.qc | 22 ----- src/vgui/ui_radio.qc | 15 +-- src/vgui/ui_scrollbar.qc | 94 ++++++------------ src/vgui/ui_textbox.qc | 7 +- src/vgui/ui_theme.qc | 207 +++++++++++++++++++++++++++++++++++++++ src/vgui/ui_window.qc | 41 ++++---- 11 files changed, 369 insertions(+), 144 deletions(-) create mode 100644 src/vgui/ui_color.qc create mode 100644 src/vgui/ui_theme.qc diff --git a/src/vgui/include.src b/src/vgui/include.src index d19bc4dc..ef995000 100644 --- a/src/vgui/include.src +++ b/src/vgui/include.src @@ -1,4 +1,6 @@ #includelist +../vgui/ui_color.qc +../vgui/ui_theme.qc ../vgui/ui.qc ../vgui/ui_control.qc ../vgui/ui_button.qc diff --git a/src/vgui/ui.qc b/src/vgui/ui.qc index 368725ca..3d4d7f1a 100644 --- a/src/vgui/ui.qc +++ b/src/vgui/ui.qc @@ -34,18 +34,6 @@ font_s g_fntDefault; var int g_vguiWidgetCount; -#ifdef CLASSIC_VGUI - #ifndef UI_MAINCOLOR - #define UI_MAINCOLOR [255,170,0] / 255 - #endif - #ifndef UI_MAINALPHA - #define UI_MAINALPHA 255 - #endif -#else - var vector UI_MAINCOLOR; - var float UI_MAINALPHA; -#endif - /** Return whether a VGUI panel is active on the 2D overlay level. */ int VGUI_Active(void) @@ -118,6 +106,11 @@ public: /** Hide the widget. */ nonvirtual void Hide(void); + /** Sets the VGUITheme to use on this widget (and any children it may have) */ + nonvirtual void SetTheme(VGUITheme); + /** Returns the VGUI that will be used on this widget. */ + nonvirtual VGUITheme GetTheme(void); + /** Called when the position of the widget was changed in any capacity. */ virtual void PositionChanged(vector, vector); /** Called when the size of the widget has changed in any capacity. */ @@ -143,6 +136,7 @@ private: VGUIWidget m_parent; int m_iFlags; bool m_bVisible; + VGUITheme m_theme; }; void @@ -160,6 +154,26 @@ VGUIWidget::VGUIWidget(void) Spawned(); } +void +VGUIWidget::SetTheme(VGUITheme theme) +{ + m_theme = theme; +} + +VGUITheme +VGUIWidget::GetTheme(void) +{ + /* if no theme set, but we have a parent... inherit the parents' theme recursively */ + if (!m_theme && m_parent) + return m_parent.GetTheme(); + + /* we have nothing, use the default one. */ + if (!m_theme) + m_theme = spawn(VGUITheme); + + return m_theme; +} + bool VGUIWidget::Visible(void) { diff --git a/src/vgui/ui_button.qc b/src/vgui/ui_button.qc index 5a0b16e1..f71508af 100644 --- a/src/vgui/ui_button.qc +++ b/src/vgui/ui_button.qc @@ -156,18 +156,12 @@ void VGUIButton::Draw(void) { #ifndef CLASSIC_VGUI - drawfill(m_parent.m_vecOrigin + m_vecOrigin, m_vecSize, m_vecColor, m_flAlpha); + VGUITheme theme = GetTheme(); if (m_iFlags & BUTTON_DOWN) { - drawfill(m_parent.m_vecOrigin + m_vecOrigin + [0, m_vecSize[1] - 1], [m_vecSize[0], 1], [1,1,1], 0.5f); - drawfill(m_parent.m_vecOrigin + m_vecOrigin, [m_vecSize[0], 1], [0,0,0], 0.5f); - drawfill(m_parent.m_vecOrigin + m_vecOrigin + [0, 1], [1, m_vecSize[1] - 2], [0,0,0], 0.5f); - drawfill(m_parent.m_vecOrigin + m_vecOrigin + [m_vecSize[0] - 1, 1], [1, m_vecSize[1] - 2], [1,1,1], 0.5f); + theme.DrawButton(m_parent.m_vecOrigin + m_vecOrigin, m_vecSize, VGUI_STATE_ACTIVE); } else { - drawfill(m_parent.m_vecOrigin + m_vecOrigin + [0, m_vecSize[1] - 1], [m_vecSize[0], 1], [0,0,0], 0.5f); - drawfill(m_parent.m_vecOrigin + m_vecOrigin, [m_vecSize[0], 1], [1,1,1], 0.5f); - drawfill(m_parent.m_vecOrigin + m_vecOrigin + [0, 1], [1, m_vecSize[1] - 2], [1,1,1], 0.5f); - drawfill(m_parent.m_vecOrigin + m_vecOrigin + [m_vecSize[0] - 1, 1], [1, m_vecSize[1] - 2], [0,0,0], 0.5f); + theme.DrawButton(m_parent.m_vecOrigin + m_vecOrigin, m_vecSize, VGUI_STATE_NORMAL); } float textPadding = 8; @@ -178,14 +172,14 @@ VGUIButton::Draw(void) length = Font_StringWidth(keyText, FALSE, g_fntDefault); textPadding += length + 8; - Font_DrawText(m_parent.m_vecOrigin + m_vecOrigin + [8, 8], keyText, g_fntDefault); + theme.DrawText(m_parent.m_vecOrigin + m_vecOrigin + [8, 8], keyText, m_vecSize, g_fntDefault); } if (m_strTitle) { if (m_iFlags & BUTTON_HOVER) { - Font_DrawText(m_parent.m_vecOrigin + m_vecOrigin + [textPadding, 8], m_strTitle, g_fntDefault); + theme.DrawText(m_parent.m_vecOrigin + m_vecOrigin + [textPadding, 8], m_strTitle, m_vecSize, g_fntDefault); } else { - Font_DrawText(m_parent.m_vecOrigin + m_vecOrigin + [textPadding, 8], m_strTitle, g_fntDefault); + theme.DrawText(m_parent.m_vecOrigin + m_vecOrigin + [textPadding, 8], m_strTitle, m_vecSize, g_fntDefault); } } @@ -256,9 +250,6 @@ VGUIButton::Input(float flEVType, float flKey, float flChar, float flDevID) if (flKey == K_MOUSE1) { FlagRemove(BUTTON_LASTACTIVE); if (mouseHover) { - if (tmpVGUIButton1) - tmpVGUIButton1(); - OnMouseDown(); FlagAdd(BUTTON_DOWN); @@ -279,6 +270,9 @@ VGUIButton::Input(float flEVType, float flKey, float flChar, float flDevID) if (m_iFlags & BUTTON_DOWN && mouseHover) { OnMouseUp(); + if (tmpVGUIButton1) + tmpVGUIButton1(); + if (m_strExec) localcmd(sprintf("%s\n", m_strExec)); diff --git a/src/vgui/ui_checkbox.qc b/src/vgui/ui_checkbox.qc index b7247673..2ea6c52f 100644 --- a/src/vgui/ui_checkbox.qc +++ b/src/vgui/ui_checkbox.qc @@ -76,13 +76,12 @@ void VGUICheckbox::SetValue (int iValue) void VGUICheckbox::Draw(void) { #ifndef CLASSIC_VGUI - drawfill(m_parent.m_vecOrigin + m_vecOrigin, m_vecSize, m_vecColor, m_flAlpha); + VGUITheme theme = GetTheme(); + theme.DrawControlBackground(m_parent.m_vecOrigin + m_vecOrigin, m_vecSize, VGUI_STATE_ACTIVE); + if (m_iFlags & CHECKBOX_DOWN) { - drawfill(m_parent.m_vecOrigin + m_vecOrigin, [m_vecSize[0], 1], [0,0,0], 0.5f); - drawfill(m_parent.m_vecOrigin + m_vecOrigin + [0, m_vecSize[1] - 1], [m_vecSize[0], 1], [1,1,1], 0.5f); - drawfill(m_parent.m_vecOrigin + m_vecOrigin + [0, 1], [1, m_vecSize[1] - 2], [0,0,0], 0.5f); - drawfill(m_parent.m_vecOrigin + m_vecOrigin + [m_vecSize[0] - 1, 1], [1, m_vecSize[1] - 2], [1,1,1], 0.5f); + theme.DrawBorder(m_parent.m_vecOrigin + m_vecOrigin, m_vecSize, VGUI_BORDER_INSET, __NULL__); } if (m_iFlags & CHECKBOX_CHECKED) { @@ -90,6 +89,10 @@ void VGUICheckbox::Draw(void) } else { drawpic(m_parent.m_vecOrigin + m_vecOrigin, "textures/ui/steam/icon_emptybox", [16,16], [1,1,1], 1.0f, 0); } + + if (m_strTitle) { + theme.DrawText(m_parent.m_vecOrigin + m_vecOrigin + [24, 3], m_strTitle, m_vecSize, g_fntDefault); + } #else if (m_iFlags & CHECKBOX_DOWN) { drawfill(m_parent.m_vecOrigin + m_vecOrigin, [m_vecSize[0], 1], m_vecColor, 1.0f); @@ -103,10 +106,10 @@ void VGUICheckbox::Draw(void) } else { drawpic(m_parent.m_vecOrigin + m_vecOrigin, "textures/ui/steam/icon_emptybox", [16,16], m_vecColor, 1.0f, 0); } -#endif if (m_strTitle) { Font_DrawText(m_parent.m_vecOrigin + m_vecOrigin + [24, 3], m_strTitle, g_fntDefault); } +#endif } bool VGUICheckbox::Input (float flEVType, float flKey, float flChar, float flDevID) diff --git a/src/vgui/ui_color.qc b/src/vgui/ui_color.qc new file mode 100644 index 00000000..18bcd069 --- /dev/null +++ b/src/vgui/ui_color.qc @@ -0,0 +1,48 @@ + +/** Container class that'll deal with handling colors via a variety of different means. */ +class VGUIColor +{ +public: + void VGUIColor(void); + + nonvirtual void SetColor(vector); + nonvirtual void SetColorWithAlpha(vector, float); + nonvirtual vector GetColor(void); + nonvirtual float GetAlpha(void); + +private: + vector m_colorValue; + float m_alphaValue; +}; + +void +VGUIColor::VGUIColor(void) +{ + m_colorValue = [0.0f, 0.0f, 0.0f]; + m_alphaValue = 1.0f; +} + +void +VGUIColor::SetColor(vector value) +{ + m_colorValue = value; +} + +void +VGUIColor::SetColorWithAlpha(vector color, float alpha) +{ + m_colorValue = color; + m_alphaValue = alpha; +} + +vector +VGUIColor::GetColor(void) +{ + return m_colorValue; +} + +float +VGUIColor::GetAlpha(void) +{ + return m_alphaValue; +} \ No newline at end of file diff --git a/src/vgui/ui_frame.qc b/src/vgui/ui_frame.qc index 4b5788d1..fbd62a0e 100644 --- a/src/vgui/ui_frame.qc +++ b/src/vgui/ui_frame.qc @@ -14,28 +14,6 @@ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -enumflags -{ - WINDOW_DRAGGING, - WINDOW_RESIZING, -}; - -typedef enumflags -{ - VGUIFrameBorderless, - VGUIFrameTitled, - VGUIFrameClosable, - VGUIFrameMiniaturizable, - VGUIFrameResizeable, - VGUIFrameMovable, -} VGUIFrameStyle_t; - -#define VGUIFrameStyleDefault VGUIFrameMovable | \ - VGUIFrameTitled | \ - VGUIFrameClosable | \ - VGUIFrameMiniaturizable - -/** Top-most window class in VGUILib */ class VGUIFrame:VGUIWidget { public: diff --git a/src/vgui/ui_radio.qc b/src/vgui/ui_radio.qc index c24e7a3b..1be3041c 100644 --- a/src/vgui/ui_radio.qc +++ b/src/vgui/ui_radio.qc @@ -85,19 +85,22 @@ void VGUIRadio::SetFunc (void(void) vFunc) void VGUIRadio::Draw(void) { #ifndef CLASSIC_VGUI - drawfill(m_parent.m_vecOrigin + m_vecOrigin, m_vecSize, m_vecColor, m_flAlpha); + VGUITheme theme = GetTheme(); + + theme.DrawControlBackground(m_parent.m_vecOrigin + m_vecOrigin, m_vecSize, VGUI_STATE_ACTIVE); if (m_iFlags & RADIO_DOWN) { - drawfill(m_parent.m_vecOrigin + m_vecOrigin, [m_vecSize[0], 1], [0,0,0], 0.5f); - drawfill(m_parent.m_vecOrigin + m_vecOrigin + [0, m_vecSize[1] - 1], [m_vecSize[0], 1], [1,1,1], 0.5f); - drawfill(m_parent.m_vecOrigin + m_vecOrigin + [0, 1], [1, m_vecSize[1] - 2], [0,0,0], 0.5f); - drawfill(m_parent.m_vecOrigin + m_vecOrigin + [m_vecSize[0] - 1, 1], [1, m_vecSize[1] - 2], [1,1,1], 0.5f); + theme.DrawBorder(m_parent.m_vecOrigin + m_vecOrigin, m_vecSize, VGUI_BORDER_INSET, __NULL__); } if (m_iFlags & RADIO_ACTIVE) { drawpic(m_parent.m_vecOrigin + m_vecOrigin, "textures/ui/steam/icon_radiosel", [16,16], [1,1,1], 1.0f, 0); } else { drawpic(m_parent.m_vecOrigin + m_vecOrigin, "textures/ui/steam/icon_radiounsel", [16,16], [1,1,1], 1.0f, 0); } + + if (m_strTitle) { + theme.DrawText(m_parent.m_vecOrigin + m_vecOrigin + [24, 3], m_strTitle, m_vecSize, g_fntDefault); + } #else if (m_iFlags & RADIO_DOWN) { drawfill(m_parent.m_vecOrigin + m_vecOrigin, [m_vecSize[0], 1], m_vecColor, 1.0f); @@ -110,11 +113,11 @@ void VGUIRadio::Draw(void) } else { drawpic(m_parent.m_vecOrigin + m_vecOrigin, "textures/ui/steam/icon_radiounsel", [16,16], m_vecColor, 1.0f, 0); } -#endif if (m_strTitle) { Font_DrawText(m_parent.m_vecOrigin + m_vecOrigin + [24, 3], m_strTitle, g_fntDefault); } +#endif } bool VGUIRadio::Input (float flEVType, float flKey, float flChar, float flDevID) diff --git a/src/vgui/ui_scrollbar.qc b/src/vgui/ui_scrollbar.qc index eeb18994..c2b700b5 100644 --- a/src/vgui/ui_scrollbar.qc +++ b/src/vgui/ui_scrollbar.qc @@ -66,64 +66,49 @@ void VGUIScrollbar::VGUIScrollbar(void) void VGUIScrollbar::Draw(void) { vector vecSize = [20, m_iLength]; + vector vecUpPos = m_parent.m_vecOrigin + m_vecOrigin; + vector vecDownPos = m_parent.m_vecOrigin + m_vecOrigin + [0, m_iLength - 20]; + vector vecSliderPos = m_parent.m_vecOrigin + m_vecOrigin + [0, 20]; #ifndef CLASSIC_VGUI - drawfill(m_parent.m_vecOrigin + m_vecOrigin, vecSize, m_vecColor, m_flAlpha); + VGUITheme theme = GetTheme(); + + vecSliderPos[1] += (m_iLength - 60) * (m_flValue / m_flMax); if (m_iFlags & BUTTON_DOWN) { - drawfill(m_parent.m_vecOrigin + m_vecOrigin + [0, vecSize[1] - 1], [vecSize[0], 1], [1,1,1], 0.5f); - drawfill(m_parent.m_vecOrigin + m_vecOrigin, [vecSize[0], 1], [0,0,0], 0.5f); - drawfill(m_parent.m_vecOrigin + m_vecOrigin + [0, 1], [1, vecSize[1] - 2], [0,0,0], 0.5f); - drawfill(m_parent.m_vecOrigin + m_vecOrigin + [vecSize[0] - 1, 1], [1, vecSize[1] - 2], [1,1,1], 0.5f); + theme.DrawScrollbar(m_parent.m_vecOrigin + m_vecOrigin, vecSize, VGUI_STATE_ACTIVE); } else { - drawfill(m_parent.m_vecOrigin + m_vecOrigin + [0, vecSize[1] - 1], [vecSize[0], 1], [0,0,0], 0.5f); - drawfill(m_parent.m_vecOrigin + m_vecOrigin, [vecSize[0], 1], [1,1,1], 0.5f); - drawfill(m_parent.m_vecOrigin + m_vecOrigin + [0, 1], [1, vecSize[1] - 2], [1,1,1], 0.5f); - drawfill(m_parent.m_vecOrigin + m_vecOrigin + [vecSize[0] - 1, 1], [1, vecSize[1] - 2], [0,0,0], 0.5f); + theme.DrawScrollbar(m_parent.m_vecOrigin + m_vecOrigin, vecSize, VGUI_STATE_NORMAL); } + + // Slider Button + if (m_iFlags & SCROLLBAR_SLIDER_DOWN) { + theme.DrawScroller(vecSliderPos, [20,20], VGUI_STATE_ACTIVE); + } else { + theme.DrawScroller(vecSliderPos, [20,20], VGUI_STATE_NORMAL); + } + + // Button UP + if (m_iFlags & SCROLLBAR_UP_DOWN) { + theme.DrawButton(vecUpPos, [20,20], VGUI_STATE_ACTIVE); + } else { + theme.DrawButton(vecUpPos, [20,20], VGUI_STATE_NORMAL); + } + drawpic(vecUpPos + [2,2], "textures/ui/steam/icon_up", [16,16], [1,1,1], 1.0f, 0); + + if (m_iFlags & SCROLLBAR_DN_DOWN) { + theme.DrawButton(vecDownPos, [20,20], VGUI_STATE_ACTIVE); + } else { + theme.DrawButton(vecDownPos, [20,20], VGUI_STATE_NORMAL); + } + drawpic(vecDownPos + [2,2], "textures/ui/steam/icon_down", [16,16], [1,1,1], 1.0f, 0); + #else drawfill(m_parent.m_vecOrigin + m_vecOrigin + [0, vecSize[1] - 1], [vecSize[0], 1], m_vecColor, 1.0f); drawfill(m_parent.m_vecOrigin + m_vecOrigin, [vecSize[0], 1], m_vecColor, 1.0f); drawfill(m_parent.m_vecOrigin + m_vecOrigin + [0, 1], [1, vecSize[1] - 2], m_vecColor, 1.0f); drawfill(m_parent.m_vecOrigin + m_vecOrigin + [vecSize[0] - 1, 1], [1, vecSize[1] - 2], m_vecColor, 1.0f); -#endif - vector vecUpPos = m_parent.m_vecOrigin + m_vecOrigin; - vector vecDownPos = m_parent.m_vecOrigin + m_vecOrigin + [0, m_iLength - 20]; - vector vecSliderPos = m_parent.m_vecOrigin + m_vecOrigin + [0, 20]; - - vecSliderPos[1] += (m_iLength - 60) * (m_flValue / m_flMax); - - // Slider Button - drawfill(vecSliderPos, [20,20], m_vecColor, m_flAlpha); - if (m_iFlags & SCROLLBAR_SLIDER_DOWN) { - drawfill(vecSliderPos, [20, 1], [0,0,0], 0.5f); - drawfill(vecSliderPos + [0, 19], [20, 1], [1,1,1], 0.5f); - drawfill(vecSliderPos + [0, 1], [1, 18], [0,0,0], 0.5f); - drawfill(vecSliderPos + [19, 1], [1, 18], [1,1,1], 0.5f); - } else { - drawfill(vecSliderPos, [20, 1], [1,1,1], 0.5f); - drawfill(vecSliderPos + [0, 19], [20, 1], [0,0,0], 0.5f); - drawfill(vecSliderPos + [0, 1], [1, 18], [1,1,1], 0.5f); - drawfill(vecSliderPos + [19, 1], [1, 18], [0,0,0], 0.5f); - } - - // Button UP -#ifndef CLASSIC_VGUI - drawfill(vecUpPos, [20,20], m_vecColor, m_flAlpha); - if (m_iFlags & SCROLLBAR_UP_DOWN) { - drawfill(vecUpPos, [20, 1], [0,0,0], 0.5f); - drawfill(vecUpPos + [0, 19], [20, 1], [1,1,1], 0.5f); - drawfill(vecUpPos + [0, 1], [1, 18], [0,0,0], 0.5f); - drawfill(vecUpPos + [19, 1], [1, 18], [1,1,1], 0.5f); - } else { - drawfill(vecUpPos, [20, 1], [1,1,1], 0.5f); - drawfill(vecUpPos + [0, 19], [20, 1], [0,0,0], 0.5f); - drawfill(vecUpPos + [0, 1], [1, 18], [1,1,1], 0.5f); - drawfill(vecUpPos + [19, 1], [1, 18], [0,0,0], 0.5f); - } - drawpic(vecUpPos + [2,2], "textures/ui/steam/icon_up", [16,16], [1,1,1], 1.0f, 0); -#else if (m_iFlags & SCROLLBAR_UP_DOWN) { drawfill(vecUpPos, [20,20], m_vecColor, 0.25f); drawfill(vecUpPos, [20, 1], m_vecColor, 1.0f); @@ -137,23 +122,8 @@ void VGUIScrollbar::Draw(void) drawfill(vecUpPos + [19, 1], [1, 18], m_vecColor, 1.0f); } drawpic(vecUpPos + [2,2], "textures/ui/steam/icon_up", [16,16], m_vecColor, 1.0f, 0); -#endif + // Button DOWN -#ifndef CLASSIC_VGUI - drawfill(vecDownPos, [20,20], m_vecColor, m_flAlpha); - if (m_iFlags & SCROLLBAR_DN_DOWN) { - drawfill(vecDownPos, [20, 1], [0,0,0], 0.5f); - drawfill(vecDownPos + [0, 19], [20, 1], [1,1,1], 0.5f); - drawfill(vecDownPos + [0, 1], [1, 18], [0,0,0], 0.5f); - drawfill(vecDownPos + [19, 1], [1, 18], [1,1,1], 0.5f); - } else { - drawfill(vecDownPos, [20, 1], [1,1,1], 0.5f); - drawfill(vecDownPos+ [0, 19], [20, 1], [0,0,0], 0.5f); - drawfill(vecDownPos + [0, 1], [1, 18], [1,1,1], 0.5f); - drawfill(vecDownPos + [19, 1], [1, 18], [0,0,0], 0.5f); - } - drawpic(vecDownPos + [2,2], "textures/ui/steam/icon_down", [16,16], [1,1,1], 1.0f, 0); -#else if (m_iFlags & SCROLLBAR_DN_DOWN) { drawfill(vecDownPos, [20,20], m_vecColor, 0.25f); drawfill(vecDownPos, [20, 1], m_vecColor, 1.0f); diff --git a/src/vgui/ui_textbox.qc b/src/vgui/ui_textbox.qc index 7d549ab8..cf5724bd 100644 --- a/src/vgui/ui_textbox.qc +++ b/src/vgui/ui_textbox.qc @@ -67,10 +67,9 @@ void VGUITextBox::Draw(void) { #ifdef CLASSIC_VGUI - drawfill(m_parent.m_vecOrigin + m_vecOrigin + [0, m_vecSize[1] - 1], [m_vecSize[0], 1], m_vecColor, 1.0f); - drawfill(m_parent.m_vecOrigin + m_vecOrigin, [m_vecSize[0], 1], m_vecColor, 1.0f); - drawfill(m_parent.m_vecOrigin + m_vecOrigin + [0, 1], [1, m_vecSize[1] - 2], m_vecColor, 1.0f); - drawfill(m_parent.m_vecOrigin + m_vecOrigin + [m_vecSize[0] - 1, 1], [1, m_vecSize[1] - 2], m_vecColor, 1.0f); + VGUITheme theme = GetTheme(); + + theme. DrawTextBackground(m_parent.m_vecOrigin + m_vecOrigin, m_vecSize, VGUI_STATE_NORMAL); #else drawfill(m_parent.m_vecOrigin + m_vecOrigin, m_vecSize, [0,0,0], 0.25f); drawfill(m_parent.m_vecOrigin + m_vecOrigin, [m_vecSize[0], 1], [0,0,0], 0.5f); diff --git a/src/vgui/ui_theme.qc b/src/vgui/ui_theme.qc new file mode 100644 index 00000000..2ace713f --- /dev/null +++ b/src/vgui/ui_theme.qc @@ -0,0 +1,207 @@ +/* For VGUITheme, we want to allow everyone some basic overrides to handle most of the drawing +tasks. However, this is matter that will slowly expand to encompass more features. +If you plan on doing something really 'out there' that you can't do within this Theme framework, +I encourage you to just maintain your own objects with overridden draw functions for best +forward compatibility. + +Why does this exist? Because the support for VGUI type elements needs variable appearances +and we can't rely on ifdefs to do the bulk of the work, that's why. The official inspiration +also referred to as TrackerUI has changed many times in appearance and we'd like to offer +means of handling any such styles. +*/ + +#ifdef CLASSIC_VGUI + #ifndef UI_MAINCOLOR + #define UI_MAINCOLOR [255,170,0] / 255 + #endif + #ifndef UI_MAINALPHA + #define UI_MAINALPHA 255 + #endif +#else + var vector UI_MAINCOLOR; + var float UI_MAINALPHA; +#endif + +/** State of the widget we're going to draw. */ +typedef enum +{ + VGUI_STATE_NORMAL, /** The widget is in normal operation. */ + VGUI_STATE_ACTIVE, /** The widget is active. */ + VGUI_STATE_HOVER, /** The mouse or another pointing device is hovering over the widget. */ + VGUI_STATE_FOCUSED, /** The widget is focused. */ + VGUI_STATE_DISABLED, /** The widget is disabled. */ + VGUI_STATE_CHECKED /** The widget is pressed or enabled. */ +} VGUIDrawState_t; + +/** Style of the border to be drawn within the VGUITheme. */ +typedef enum +{ + VGUI_BORDER_LINE, /**< Thin line border. */ + VGUI_BORDER_INSET, /**< Inset border, used for control elements. */ + VGUI_BORDER_OUTSET, /**< Outset border, often used for windows. */ + //VGUI_BORDER_DOTTED, + //VGUI_BORDER_DASHED, + //VGUI_BORDER_RIDGE, + //VGUI_BORDER_GROOVE + VGUI_BORDER_NONE /**< No border */ +} VGUIBorderStyle_t; + +/** Abstract class than can be set/overriden to customize to final appearance of GUI widgets */ +class +VGUITheme +{ +public: + virtual void VGUITheme(void); + + /** Draw a border at the specified position, size and VGUIBorderStyle_t. */ + virtual void DrawBorder(vector, vector, VGUIBorderStyle_t, VGUIColor); + /** Draw a control item background at the specified position, size and VGUIDrawState_t. */ + virtual void DrawControlBackground(vector, vector, VGUIDrawState_t); + /** Draw a text field background at the specified position, size and VGUIDrawState_t. */ + virtual void DrawTextBackground(vector, vector, VGUIDrawState_t); + /** Draw a window background at the specified position, size and VGUIDrawState_t. */ + virtual void DrawWindowBackground(vector, vector, VGUIDrawState_t); + /** Draw a button body at the specified position, size and VGUIDrawState_t. */ + virtual void DrawButton(vector, vector, VGUIDrawState_t); + /** Draw a scroller at the specified position, size and VGUIDrawState_t. */ + virtual void DrawScroller(vector, vector, VGUIDrawState_t); + /** Draw a scrollbar at the specified position, size and VGUIDrawState_t. */ + virtual void DrawScrollbar(vector, vector, VGUIDrawState_t); + /** Draw a progress indicator at the specified position, size and VGUIDrawState_t. */ + virtual void DrawProgressIndicator(vector, vector, float, VGUIDrawState_t); + /** Draws generic text onto a widget. */ + virtual void DrawText(vector, string, vector, font_s); + /** Draw a window body. */ + virtual void DrawWindow(vector, vector, VGUIDrawState_t); + +private: + VGUIColor m_controlBackgroundColor; + VGUIColor m_windowBackgroundColor; + VGUIColor m_textBackgroundColor; + VGUIColor m_textColor; + VGUIColor m_windowBorderColor; +}; + +void +VGUITheme::VGUITheme(void) +{ + m_controlBackgroundColor = spawn(VGUIColor); + //m_controlBackgroundColor.SetColor([0.298, 0.345, 0.267]); + m_controlBackgroundColor.SetColor(UI_MAINCOLOR); + m_windowBackgroundColor = spawn(VGUIColor); + //m_windowBackgroundColor.SetColor([0.298, 0.345, 0.267]); + m_windowBackgroundColor.SetColor(UI_MAINCOLOR); + m_textBackgroundColor = spawn(VGUIColor); + //m_textBackgroundColor.SetColor([0.243, 0.275, 0.216]); + m_textBackgroundColor.SetColor(UI_MAINCOLOR); + m_textColor = spawn(VGUIColor); + //m_textColor.SetColor([0.847, 0.871, 0.827]); + m_textColor.SetColor(UI_MAINCOLOR); + m_windowBorderColor = spawn(VGUIColor); + //m_windowBorderColor.SetColor([0.533, 0.569, 0.502]); + m_windowBorderColor.SetColor(UI_MAINCOLOR); +} + +void +VGUITheme::DrawBorder(vector atPos, vector withSize, VGUIBorderStyle_t borderStyle, VGUIColor color) +{ + switch (borderStyle) { + case VGUI_BORDER_INSET: + drawfill(atPos + [0, withSize[1] - 1], [withSize[0], 1], [1,1,1], 0.5f); + drawfill(atPos, [withSize[0], 1], [0,0,0], 0.5f); + drawfill(atPos + [0, 1], [1, withSize[1] - 2], [0,0,0], 0.5f); + drawfill(atPos + [withSize[0] - 1, 1], [1, withSize[1] - 2], [1,1,1], 0.5f); + break; + case VGUI_BORDER_OUTSET: + drawfill(atPos + [0, withSize[1] - 1], [withSize[0], 1], [0,0,0], 0.5f); + drawfill(atPos, [withSize[0], 1], [1,1,1], 0.5f); + drawfill(atPos + [0, 1], [1, withSize[1] - 2], [1,1,1], 0.5f); + drawfill(atPos + [withSize[0] - 1, 1], [1, withSize[1] - 2], [0,0,0], 0.5f); + break; + case VGUI_BORDER_LINE: + drawfill(atPos + [0, withSize[1] - 1], [withSize[0], 1], color.GetColor(), color.GetAlpha()); + drawfill(atPos, [withSize[0], 1], color.GetColor(), color.GetAlpha()); + drawfill(atPos + [0, 1], [1, withSize[1] - 2], color.GetColor(), color.GetAlpha()); + drawfill(atPos + [withSize[0] - 1, 1], [1, withSize[1] - 2], color.GetColor(), color.GetAlpha()); + break; + default: + case VGUI_BORDER_NONE: + break; + } +} + +void +VGUITheme::DrawControlBackground(vector atPos, vector withSize, VGUIDrawState_t drawStyle) +{ + drawfill(atPos, withSize, m_controlBackgroundColor.GetColor(), m_controlBackgroundColor.GetAlpha()); +} + +void +VGUITheme::DrawTextBackground(vector atPos, vector withSize, VGUIDrawState_t drawStyle) +{ + drawfill(atPos, withSize, m_textBackgroundColor.GetColor(), m_textBackgroundColor.GetAlpha()); +} + +void +VGUITheme::DrawWindowBackground(vector atPos, vector withSize, VGUIDrawState_t drawStyle) +{ + drawfill(atPos, withSize, m_windowBackgroundColor.GetColor(), m_windowBackgroundColor.GetAlpha()); +} + +void +VGUITheme::DrawButton(vector atPos, vector withSize, VGUIDrawState_t drawStyle) +{ + DrawControlBackground(atPos, withSize, drawStyle); + + if (drawStyle == VGUI_STATE_ACTIVE) { + drawfill(atPos + [0, withSize[1] - 1], [withSize[0], 1], [1,1,1], 0.5f); + drawfill(atPos, [withSize[0], 1], [0,0,0], 0.5f); + drawfill(atPos + [0, 1], [1, withSize[1] - 2], [0,0,0], 0.5f); + drawfill(atPos + [withSize[0] - 1, 1], [1, withSize[1] - 2], [1,1,1], 0.5f); + } else { + drawfill(atPos + [0, withSize[1] - 1], [withSize[0], 1], [0,0,0], 0.5f); + drawfill(atPos, [withSize[0], 1], [1,1,1], 0.5f); + drawfill(atPos + [0, 1], [1, withSize[1] - 2], [1,1,1], 0.5f); + drawfill(atPos + [withSize[0] - 1, 1], [1, withSize[1] - 2], [0,0,0], 0.5f); + } +} + +void +VGUITheme::DrawScroller(vector atPos, vector withSize, VGUIDrawState_t drawStyle) +{ + DrawControlBackground(atPos, withSize, drawStyle); + drawfill(atPos + [0, withSize[1] - 1], [withSize[0], 1], [0,0,0], 0.5f); + drawfill(atPos, [withSize[0], 1], [1,1,1], 0.5f); + drawfill(atPos + [0, 1], [1, withSize[1] - 2], [1,1,1], 0.5f); + drawfill(atPos + [withSize[0] - 1, 1], [1, withSize[1] - 2], [0,0,0], 0.5f); +} + +void +VGUITheme::DrawScrollbar(vector atPos, vector withSize, VGUIDrawState_t drawStyle) +{ + DrawTextBackground(atPos, withSize, drawStyle); +} + +void +VGUITheme::DrawProgressIndicator(vector atPos, vector withSize, float progressValue, VGUIDrawState_t drawStyle) +{ + float barLength = (withSize[0] - 4) * progressValue; + DrawTextBackground(atPos, withSize, drawStyle); + drawfill(atPos + [2, 2], [barLength, withSize[1] - 4], [1,1,1], 1.0f); +} + +void +VGUITheme::DrawText(vector atPos, string withText, vector boundSize, font_s textFont) +{ + //drawsetcliparea(atPos[0], atPos[1], boundSize[0], boundSize[1]); + //drawfill(atPos, boundSize, [1,1,1], 0.5f); + Font_DrawText(atPos, withText, textFont); + //drawresetcliparea(); +} + +void +VGUITheme::DrawWindow(vector atPos, vector withSize, VGUIDrawState_t drawStyle) +{ + DrawWindowBackground(atPos, withSize, drawStyle); + DrawBorder(atPos, withSize, VGUI_BORDER_OUTSET, m_windowBorderColor); +} \ No newline at end of file diff --git a/src/vgui/ui_window.qc b/src/vgui/ui_window.qc index 0299ea06..a2a95717 100644 --- a/src/vgui/ui_window.qc +++ b/src/vgui/ui_window.qc @@ -212,23 +212,6 @@ void VGUIWindow::Draw(void) if (m_styleMask & VGUIWindowResizeable) { drawpic(m_vecOrigin + m_vecSize - [16,16], "textures/ui/steam/icon_resizer", [16,16], m_vecColor, 1.0f, 0); } -#else - if (m_styleMask & VGUIWindowFullscreen) - drawfill([0,0], video_res, m_vecColor, m_flAlpha); - else - drawfill(m_vecOrigin, m_vecSize, m_vecColor, m_flAlpha); - - if (!(m_styleMask & VGUIWindowBorderless)) { - drawfill(m_vecOrigin, [m_vecSize[0], 1], [1,1,1], 0.5f); - drawfill(m_vecOrigin + [0, m_vecSize[1] - 1], [m_vecSize[0], 1], [0,0,0], 0.5f); - drawfill(m_vecOrigin + [0, 1], [1, m_vecSize[1] - 2], [1,1,1], 0.5f); - drawfill(m_vecOrigin + [m_vecSize[0] - 1, 1], [1, m_vecSize[1] - 2], [0,0,0], 0.5f); - } - - if (m_styleMask & VGUIWindowResizeable) { - drawpic(m_vecOrigin + m_vecSize - [16,16], "textures/ui/steam/icon_resizer", [16,16], m_vecColor, 1.0f, 0); - } -#endif if (m_styleMask & VGUIWindowTitled) if (m_strTitle) { @@ -239,6 +222,30 @@ void VGUIWindow::Draw(void) Font_DrawText(m_vecOrigin + [8, 8], m_strTitle, g_fntDefault); } } +#else + VGUITheme theme = GetTheme(); + + if (m_styleMask & VGUIWindowFullscreen) + theme.DrawWindowBackground([0, 0], video_res, VGUI_STATE_ACTIVE); + else if (!(m_styleMask & VGUIWindowBorderless)) + theme.DrawWindow(m_vecOrigin, m_vecSize, VGUI_STATE_ACTIVE); + else + theme.DrawWindowBackground(m_vecOrigin, m_vecSize, VGUI_STATE_ACTIVE); + + if (m_styleMask & VGUIWindowResizeable) { + drawpic(m_vecOrigin + m_vecSize - [16,16], "textures/ui/steam/icon_resizer", [16,16], m_vecColor, 1.0f, 0); + } + + if (m_styleMask & VGUIWindowTitled) + if (m_strTitle) { + if (m_strIcon) { + theme.DrawText(m_vecOrigin + [26, 8], m_strTitle, m_vecSize, g_fntDefault); + drawpic(m_vecOrigin + [4, 4], m_strIcon, [16,16], [1,1,1], 1.0f, 0); + } else { + theme.DrawText(m_vecOrigin + [8, 8], m_strTitle, m_vecSize, g_fntDefault); + } + } +#endif #ifdef UI_DEVELOPER if (m_iFlags & WINDOW_DRAGGING) {