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 /gameui/vcontrolslistpanel.cpp | |
| download | archived-source-engine-2018-hl2-src-master.tar.xz archived-source-engine-2018-hl2-src-master.zip | |
Diffstat (limited to 'gameui/vcontrolslistpanel.cpp')
| -rw-r--r-- | gameui/vcontrolslistpanel.cpp | 207 |
1 files changed, 207 insertions, 0 deletions
diff --git a/gameui/vcontrolslistpanel.cpp b/gameui/vcontrolslistpanel.cpp new file mode 100644 index 0000000..f644d3e --- /dev/null +++ b/gameui/vcontrolslistpanel.cpp @@ -0,0 +1,207 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// + +#include "vcontrolslistpanel.h" +#include "GameUI_Interface.h" +#include "EngineInterface.h" + +#include <vgui/IInput.h> +#include <vgui/IScheme.h> +#include <vgui/ISurface.h> +#include <vgui/IVGui.h> +#include <vgui/Cursor.h> +#include <KeyValues.h> + +// NVNT including for input system access +#include "tier2/tier2.h" +#include "inputsystem/iinputsystem.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include <tier0/memdbgon.h> + +using namespace vgui; + +//----------------------------------------------------------------------------- +// Purpose: panel used for inline editing of key bindings +//----------------------------------------------------------------------------- +class CInlineEditPanel : public vgui::Panel +{ +public: + CInlineEditPanel() : vgui::Panel(NULL, "InlineEditPanel") + { + } + + virtual void Paint() + { + int x = 0, y = 0, wide, tall; + GetSize(wide, tall); + + // Draw a white rectangle around that cell + vgui::surface()->DrawSetColor( 255, 165, 0, 255 ); + vgui::surface()->DrawFilledRect( x, y, x + wide, y + tall ); + } + + virtual void OnKeyCodeTyped(KeyCode code) + { + // forward up + if (GetParent()) + { + GetParent()->OnKeyCodeTyped(code); + } + } + + virtual void ApplySchemeSettings(IScheme *pScheme) + { + Panel::ApplySchemeSettings(pScheme); + SetBorder(pScheme->GetBorder("DepressedButtonBorder")); + } + + void OnMousePressed(vgui::MouseCode code) + { + // forward up mouse pressed messages to be handled by the key options + if (GetParent()) + { + GetParent()->OnMousePressed(code); + } + } +}; + +//----------------------------------------------------------------------------- +// Purpose: Construction +//----------------------------------------------------------------------------- +VControlsListPanel::VControlsListPanel( vgui::Panel *parent, const char *listName ) : vgui::SectionedListPanel( parent, listName ) +{ + m_bCaptureMode = false; + m_nClickRow = 0; + m_pInlineEditPanel = new CInlineEditPanel(); + m_hFont = INVALID_FONT; +} + +//----------------------------------------------------------------------------- +// Purpose: Destructor +//----------------------------------------------------------------------------- +VControlsListPanel::~VControlsListPanel() +{ + m_pInlineEditPanel->MarkForDeletion(); +} + +//----------------------------------------------------------------------------- +// Purpose: +//----------------------------------------------------------------------------- +void VControlsListPanel::ApplySchemeSettings(IScheme *pScheme ) +{ + BaseClass::ApplySchemeSettings( pScheme ); + m_hFont = pScheme->GetFont("Default", IsProportional() ); +} + +//----------------------------------------------------------------------------- +// Purpose: Start capture prompt display +//----------------------------------------------------------------------------- +void VControlsListPanel::StartCaptureMode( HCursor hCursor ) +{ + m_bCaptureMode = true; + EnterEditMode(m_nClickRow, 1, m_pInlineEditPanel); + input()->SetMouseFocus(m_pInlineEditPanel->GetVPanel()); + input()->SetMouseCapture(m_pInlineEditPanel->GetVPanel()); + // NVNT tell the input system that novint devices + // should be set unable to do menu mouse emulation. + g_pInputSystem->SetNovintPure(true); + + engine->StartKeyTrapMode(); + + if (hCursor) + { + m_pInlineEditPanel->SetCursor(hCursor); + + // save off the cursor position so we can restore it + vgui::input()->GetCursorPos( m_iMouseX, m_iMouseY ); + } +} + +//----------------------------------------------------------------------------- +// Purpose: Finish capture prompt display +//----------------------------------------------------------------------------- +void VControlsListPanel::EndCaptureMode( HCursor hCursor ) +{ + m_bCaptureMode = false; + input()->SetMouseCapture(NULL); + LeaveEditMode(); + RequestFocus(); + input()->SetMouseFocus(GetVPanel()); + // NVNT tell the input system that novint devices + // should be allowed to do menu mouse emulation. + g_pInputSystem->SetNovintPure(false); + if (hCursor) + { + m_pInlineEditPanel->SetCursor(hCursor); + surface()->SetCursor(hCursor); + if ( hCursor != dc_none ) + { + vgui::input()->SetCursorPos ( m_iMouseX, m_iMouseY ); + } + } +} + +//----------------------------------------------------------------------------- +// Purpose: Set active row column +//----------------------------------------------------------------------------- +void VControlsListPanel::SetItemOfInterest(int itemID) +{ + m_nClickRow = itemID; +} + +//----------------------------------------------------------------------------- +// Purpose: Retrieve row, column of interest +//----------------------------------------------------------------------------- +int VControlsListPanel::GetItemOfInterest() +{ + return m_nClickRow; +} + +//----------------------------------------------------------------------------- +// Purpose: returns true if we're currently waiting to capture a key +//----------------------------------------------------------------------------- +bool VControlsListPanel::IsCapturing( void ) +{ + return m_bCaptureMode; +} + +//----------------------------------------------------------------------------- +// Purpose: Forwards mouse pressed message up to keyboard page when in capture +//----------------------------------------------------------------------------- +void VControlsListPanel::OnMousePressed(vgui::MouseCode code) +{ + if (IsCapturing()) + { + // forward up mouse pressed messages to be handled by the key options + if (GetParent()) + { + GetParent()->OnMousePressed(code); + } + } + else + { + BaseClass::OnMousePressed(code); + } +} + + +//----------------------------------------------------------------------------- +// Purpose: input handler +//----------------------------------------------------------------------------- +void VControlsListPanel::OnMouseDoublePressed( vgui::MouseCode code ) +{ + if (IsItemIDValid(GetSelectedItem())) + { + // enter capture mode + OnKeyCodePressed(KEY_ENTER); + } + else + { + BaseClass::OnMouseDoublePressed(code); + } +} |