From da194e8eed4649aad8702a4142becf889b7c029a Mon Sep 17 00:00:00 2001 From: Marco Cawthorne Date: Mon, 15 Jan 2024 16:28:46 -0800 Subject: [PATCH] VGUIWindow: migrate non Window specific bits into its own class: VGUIView --- src/vgui/include.src | 1 + src/vgui/ui_view.qc | 73 +++++++++++++++++++++++++++++++++++++++++++ src/vgui/ui_window.qc | 37 ++-------------------- 3 files changed, 77 insertions(+), 34 deletions(-) create mode 100644 src/vgui/ui_view.qc diff --git a/src/vgui/include.src b/src/vgui/include.src index ef995000..c426f95d 100644 --- a/src/vgui/include.src +++ b/src/vgui/include.src @@ -7,6 +7,7 @@ ../vgui/ui_menubutton.qc ../vgui/ui_radio.qc ../vgui/ui_checkbox.qc +../vgui/ui_view.qc ../vgui/ui_window.qc ../vgui/ui_frame.qc ../vgui/ui_label.qc diff --git a/src/vgui/ui_view.qc b/src/vgui/ui_view.qc new file mode 100644 index 00000000..e5a82634 --- /dev/null +++ b/src/vgui/ui_view.qc @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2016-2022 Vera Visions LLC. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER + * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +class VGUIView:VGUIWidget +{ +public: + void VGUIView(void); + + /* overrides */ + virtual void Add(VGUIWidget); + virtual void Draw(void); + virtual bool Input(float, float, float, float); +}; + +void +VGUIView::VGUIView(void) +{ +} + +void +VGUIView::Add(VGUIWidget wNew) +{ + VGUIWidget wNext = this; + VGUIWidget wParent; + do { + wParent = wNext; + wNext = wNext.m_children; + } while (wNext); + wParent.m_children = wNew; + wNew.m_parent = this; +} + +void VGUIView::Draw(void) +{ + VGUIWidget wNext = this; + g_vguiWidgetCount = 0; + do { + wNext = wNext.m_children; + if (wNext && wNext.Visible() && wNext.m_parent.Visible()) { + g_vguiWidgetCount++; + wNext.Draw(); + } + } while (wNext); +} + +bool VGUIView::Input (float flEVType, float flKey, float flChar, float flDevID) +{ + float ret = false; + + VGUIWidget wNext = this; + do { + wNext = wNext.m_children; + if (wNext && wNext.Visible() && wNext.m_parent.Visible()) { + ret = wNext.Input(flEVType, flKey, flChar, flDevID); + } + + if (ret == true) + return true; + } while (wNext); +} diff --git a/src/vgui/ui_window.qc b/src/vgui/ui_window.qc index c9878f60..cdd7a1f8 100644 --- a/src/vgui/ui_window.qc +++ b/src/vgui/ui_window.qc @@ -41,7 +41,7 @@ typedef enumflags .void(void) tmpVGUIWindow2; /** Top-most window class in VGUILib */ -class VGUIWindow:VGUIWidget +class VGUIWindow:VGUIView { public: void VGUIWindow(void); @@ -75,7 +75,6 @@ public: virtual void WindowDidClose(void); /* overrides */ - virtual void Add(VGUIWidget); virtual void Draw(void); virtual void SizeChanged(vector, vector); virtual bool Input(float, float, float, float); @@ -107,19 +106,6 @@ VGUIWindow::NowVisible(void) Focus(); } -void -VGUIWindow::Add(VGUIWidget wNew) -{ - VGUIWidget wNext = this; - VGUIWidget wParent; - do { - wParent = wNext; - wNext = wNext.m_children; - } while (wNext); - wParent.m_children = wNew; - wNew.m_parent = this; -} - bool VGUIWindow::Focus(void) { @@ -303,15 +289,7 @@ void VGUIWindow::Draw(void) } #endif - VGUIWidget wNext = this; - g_vguiWidgetCount = 0; - do { - wNext = wNext.m_children; - if (wNext && wNext.Visible() && wNext.m_parent.Visible()) { - g_vguiWidgetCount++; - wNext.Draw(); - } - } while (wNext); + super::Draw(); #ifdef UI_DEVELOPER if (m_iFlags & WINDOW_DRAGGING) { @@ -370,16 +348,7 @@ bool VGUIWindow::Input (float flEVType, float flKey, float flChar, float flDevID } if (ret == false) { - VGUIWidget wNext = this; - do { - wNext = wNext.m_children; - if (wNext && wNext.Visible() && wNext.m_parent.Visible()) { - ret = wNext.Input(flEVType, flKey, flChar, flDevID); - } - - if (ret == true) - return true; - } while (wNext); + ret = super::Input(flEVType, flKey, flChar, flDevID); } return (ret);