1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#ifndef MOUSEOVERPANELBUTTON_H
#define MOUSEOVERPANELBUTTON_H
#ifdef _WIN32
#pragma once
#endif
#include <vgui/IScheme.h>
#include <vgui_controls/Button.h>
#include <vgui/KeyCode.h>
#include <filesystem.h>
extern vgui::Panel *g_lastPanel;
extern vgui::Button *g_lastButton;
//-----------------------------------------------------------------------------
// Purpose: Triggers a new panel when the mouse goes over the button
//
// the new panel has the same dimensions as the passed templatePanel and is of
// the same class.
//
// must at least inherit from vgui::EditablePanel to support LoadControlSettings
//-----------------------------------------------------------------------------
template <class T>
class MouseOverButton : public vgui::Button
{
private:
DECLARE_CLASS_SIMPLE( MouseOverButton, vgui::Button );
public:
MouseOverButton(vgui::Panel *parent, const char *panelName, T *templatePanel ) :
Button( parent, panelName, "MouseOverButton")
{
m_pPanel = new T( parent, NULL );
m_pPanel ->SetVisible( false );
// copy size&pos from template panel
int x,y,wide,tall;
templatePanel->GetBounds( x, y, wide, tall );
m_pPanel->SetBounds( x, y, wide, tall );
int px, py;
templatePanel->GetPinOffset( px, py );
int rx, ry;
templatePanel->GetResizeOffset( rx, ry );
// Apply pin settings from template, too
m_pPanel->SetAutoResize( templatePanel->GetPinCorner(), templatePanel->GetAutoResize(), px, py, rx, ry );
m_bPreserveArmedButtons = false;
m_bUpdateDefaultButtons = false;
}
virtual void SetPreserveArmedButtons( bool bPreserve ){ m_bPreserveArmedButtons = bPreserve; }
virtual void SetUpdateDefaultButtons( bool bUpdate ){ m_bUpdateDefaultButtons = bUpdate; }
virtual void ShowPage()
{
if( m_pPanel )
{
m_pPanel->SetVisible( true );
m_pPanel->MoveToFront();
g_lastPanel = m_pPanel;
}
}
virtual void HidePage()
{
if ( m_pPanel )
{
m_pPanel->SetVisible( false );
}
}
const char *GetClassPage( const char *className )
{
static char classPanel[ _MAX_PATH ];
Q_snprintf( classPanel, sizeof( classPanel ), "classes/%s.res", className);
if ( g_pFullFileSystem->FileExists( classPanel, IsX360() ? "MOD" : "GAME" ) )
{
}
else if (g_pFullFileSystem->FileExists( "classes/default.res", IsX360() ? "MOD" : "GAME" ) )
{
Q_snprintf ( classPanel, sizeof( classPanel ), "classes/default.res" );
}
else
{
return NULL;
}
return classPanel;
}
#ifdef REFRESH_CLASSMENU_TOOL
void RefreshClassPage( void )
{
m_pPanel->LoadControlSettings( GetClassPage( GetName() ) );
}
#endif
virtual void ApplySettings( KeyValues *resourceData )
{
BaseClass::ApplySettings( resourceData );
// name, position etc of button is set, now load matching
// resource file for associated info panel:
m_pPanel->LoadControlSettings( GetClassPage( GetName() ) );
}
T *GetClassPanel( void ) { return m_pPanel; }
virtual void OnCursorExited()
{
if ( !m_bPreserveArmedButtons )
{
BaseClass::OnCursorExited();
}
}
virtual void OnCursorEntered()
{
BaseClass::OnCursorEntered();
if ( !IsEnabled() )
return;
// are we updating the default buttons?
if ( m_bUpdateDefaultButtons )
{
SetAsDefaultButton( 1 );
}
// are we preserving the armed state (and need to turn off the old button)?
if ( m_bPreserveArmedButtons )
{
if ( g_lastButton && g_lastButton != this )
{
g_lastButton->SetArmed( false );
}
g_lastButton = this;
}
// turn on our panel (if it isn't already)
if ( m_pPanel && ( !m_pPanel->IsVisible() ) )
{
// turn off the previous panel
if ( g_lastPanel && g_lastPanel->IsVisible() )
{
g_lastPanel->SetVisible( false );
}
ShowPage();
}
}
virtual void OnKeyCodeReleased( vgui::KeyCode code )
{
BaseClass::OnKeyCodeReleased( code );
if ( m_bPreserveArmedButtons )
{
if ( g_lastButton )
{
g_lastButton->SetArmed( true );
}
}
}
private:
T *m_pPanel;
bool m_bPreserveArmedButtons;
bool m_bUpdateDefaultButtons;
};
#define MouseOverPanelButton MouseOverButton<vgui::EditablePanel>
#endif // MOUSEOVERPANELBUTTON_H
|