From 5f3570f140c4da34ef4dccc6d809a3c42e0e6ff2 Mon Sep 17 00:00:00 2001 From: Marco Cawthorne Date: Fri, 20 May 2022 16:35:36 -0700 Subject: [PATCH] VGUI: UIButton now resizes when an image is set that's larger than the button area. Also add method SetIconColor() --- src/vgui/ui_button.qc | 20 +++++++++++++++++++- src/vgui/ui_window.qc | 3 ++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/vgui/ui_button.qc b/src/vgui/ui_button.qc index 7e2d6dc4..1e5752da 100644 --- a/src/vgui/ui_button.qc +++ b/src/vgui/ui_button.qc @@ -24,7 +24,9 @@ enumflags class CUIButton:CUIWidget { + vector m_vecIMGSize; vector m_vecColor; + vector m_vecIconColor; float m_flAlpha; vector m_vecSize; string m_strTitle; @@ -55,6 +57,7 @@ CUIButton::CUIButton(void) m_vecColor = UI_MAINCOLOR; m_flAlpha = 1.0f; m_vecSize = [96,24]; + m_vecIconColor = [1,1,1]; m_iFlags = BUTTON_VISIBLE; } @@ -64,6 +67,12 @@ CUIButton::SetColor(vector vecColor) m_vecColor = vecColor; } +void +CUIButton::SetIconColor(vector vecColor) +{ + m_vecIconColor = vecColor; +}; + void CUIButton::SetSize(vector vecSize) { @@ -104,7 +113,13 @@ CUIButton::SetTitle(string strName) void CUIButton::SetIcon(string strName) { + vector vecImgSize; m_strIcon = strName; + m_vecIMGSize = drawgetimagesize(strName); + + if (vlen(GetSize()) < vlen(m_vecIMGSize)) { + SetSize(m_vecIMGSize + [4,4]); + } } void CUIButton::SetFunc(void(void) vFunc) @@ -166,7 +181,10 @@ CUIButton::Draw(void) } } if (m_strIcon) { - drawpic(m_parent.m_vecOrigin + m_vecOrigin + [2,2], m_strIcon, [16,16], m_vecColor, 1.0f, 0); + if (m_iFlags & BUTTON_DOWN) + drawpic(m_parent.m_vecOrigin + m_vecOrigin + [2,2], m_strIcon, m_vecIMGSize, m_vecIconColor * 0.25, 1.0f, 0); + else + drawpic(m_parent.m_vecOrigin + m_vecOrigin + [2,2], m_strIcon, m_vecIMGSize, m_vecIconColor, 1.0f, 0); } } diff --git a/src/vgui/ui_window.qc b/src/vgui/ui_window.qc index 9544b6e7..5caa5e62 100644 --- a/src/vgui/ui_window.qc +++ b/src/vgui/ui_window.qc @@ -81,7 +81,8 @@ void CUIWindow::CUIWindow(void) m_btnClose = spawn(CUIButton); m_btnClose.SetTitle(__NULL__); - m_btnClose.m_strIcon = "textures/ui/steam/icon_close"; + m_btnClose.SetIcon("textures/ui/steam/icon_close"); + m_btnClose.SetIconColor(m_vecColor); m_btnClose.SetColor(m_vecColor); m_btnClose.SetFunc(WindowButtonClose); m_btnClose.SetSize([20,20]);