Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

198 lines
5.6 KiB

//========= Copyright © 1996-2005, 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>
// 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());
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());
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);
}
}