diff options
| author | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
|---|---|---|
| committer | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
| commit | 3bf9df6b2785fa6d951086978a3e66f49427166a (patch) | |
| tree | 2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /utils/vgui_panel_zoo/ScrollBar2Demo.cpp | |
| download | archived-source-engine-2018-hl2-src-master.tar.xz archived-source-engine-2018-hl2-src-master.zip | |
Diffstat (limited to 'utils/vgui_panel_zoo/ScrollBar2Demo.cpp')
| -rw-r--r-- | utils/vgui_panel_zoo/ScrollBar2Demo.cpp | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/utils/vgui_panel_zoo/ScrollBar2Demo.cpp b/utils/vgui_panel_zoo/ScrollBar2Demo.cpp new file mode 100644 index 0000000..1055ebc --- /dev/null +++ b/utils/vgui_panel_zoo/ScrollBar2Demo.cpp @@ -0,0 +1,126 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// +#include "DemoPage.h" + +#include <VGUI/IVGui.h> + +#include <vgui/IScheme.h> +#include <vgui_controls/ScrollBar.h> +#include <vgui_controls/Label.h> +#include <stdio.h> + +using namespace vgui; + +//----------------------------------------------------------------------------- +// A ScrollBar is an class for selecting a numerical value from a range. +// E.g. in the case of a scrolling text window we use the scroll bar to select +// what line/char of text display should start at in the text window. + +// Some terms: +// +// There are arrow buttons on either end of the scroll bar. +// These move the scroll bar 'slider' or 'nob' across the space between the arrows. +// The nob moves over a user specified 'range' of numbers. +// +// ---------------------------------------------------- +// | / |..............| |................ | \ | +// | \ |..............| nob |.................| / | +// ---------------------------------------------------- +// +// In this demo we create a horizongal scroll bar that is not attached to anything. +// We display the current value of the slider nob next to the scroll bar. +//----------------------------------------------------------------------------- +class ScrollBar2Demo: public DemoPage +{ + public: + ScrollBar2Demo(Panel *parent, const char *name); + ~ScrollBar2Demo(); + + void OnSliderMoved(); + + private: + ScrollBar *m_pScrollbar; + Label *m_pScrollValue; + + DECLARE_PANELMAP(); +}; + +//----------------------------------------------------------------------------- +// Purpose: Constructor +//----------------------------------------------------------------------------- +ScrollBar2Demo::ScrollBar2Demo(Panel *parent, const char *name) : DemoPage(parent, name) +{ + // A vertical slider + m_pScrollbar = new ScrollBar (this, "AScrollbar", false); + + // Set the position of the bar + m_pScrollbar->SetPos(100, 100); + + // Set the size of the bar + m_pScrollbar->SetSize (200, 20); + + // Set the size of the bar nob, which is actually proportionally + // related to how many lines of info fit into the window the + // scroll bar is attatched to vs how many total lines there are. + // With a size of 10, the scroll bar value will pass from 0 to 100. + m_pScrollbar->SetRangeWindow(50); + + // Set the range of the bar, + // We want our range displayed to go from 0 to 100. + // We must take size of the bar nob into account, and set the max to 110. + m_pScrollbar->SetRange(0, 110); + + // Set how far the scroll bar slider moves + // when a scroll bar arrow button is pressed + m_pScrollbar->SetButtonPressedScrollValue(5); + + // Set the starting value of the bar nob. + // This will put the nob at the top of the vertical scroll bar. + m_pScrollbar->SetValue(0); + + // Finally we create a little label to tell us what the current value + // of the scroll bar is. + // We will update it every time the slider is moved. + m_pScrollValue = new Label (this, "ScrollBarValue", "0"); + + // Stick the label next to the scroll bar. + m_pScrollValue->SetPos(100, 130); +} + +//----------------------------------------------------------------------------- +// Purpose: Destructor +//----------------------------------------------------------------------------- +ScrollBar2Demo::~ScrollBar2Demo() +{ +} + +//----------------------------------------------------------------------------- +// Purpose: Respond to movement of the scroll bar nob by updating the label's +// text with the current value of the scrollbar. +//----------------------------------------------------------------------------- +void ScrollBar2Demo::OnSliderMoved() +{ + char number[6]; + sprintf (number, "%d", m_pScrollbar->GetValue()); + m_pScrollValue->SetText(number); +} + +//----------------------------------------------------------------------------- +// Purpose: Message map +//----------------------------------------------------------------------------- +MessageMapItem_t ScrollBar2Demo::m_MessageMap[] = +{ + MAP_MESSAGE( ScrollBar2Demo, "ScrollBarSliderMoved", OnSliderMoved ), +}; +IMPLEMENT_PANELMAP(ScrollBar2Demo, Panel); + + +Panel* ScrollBar2Demo_Create(Panel *parent) +{ + return new ScrollBar2Demo(parent, "ScrollBar2Demo"); +} + |