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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//===========================================================================//
#ifndef URLBUTTON_H
#define URLBUTTON_H
#ifdef _WIN32
#pragma once
#endif
#include <vgui/VGUI.h>
#include <vgui/Dar.h>
#include <Color.h>
#include <vgui_controls/Label.h>
#include "vgui/MouseCode.h"
namespace vgui
{
//-----------------------------------------------------------------------------
// Purpose: A control that looks like a hyperlink, but behaves like a button.
//-----------------------------------------------------------------------------
class URLButton : public Label
{
DECLARE_CLASS_SIMPLE( URLButton, Label );
public:
// You can optionally pass in the panel to send the click message to and the name of the command to send to that panel.
URLButton(Panel *parent, const char *panelName, const char *text, Panel *pActionSignalTarget=NULL, const char *pCmd=NULL);
URLButton(Panel *parent, const char *panelName, const wchar_t *text, Panel *pActionSignalTarget=NULL, const char *pCmd=NULL);
~URLButton();
private:
void Init();
public:
// Set armed state.
virtual void SetArmed(bool state);
// Check armed state
virtual bool IsArmed( void );
// Check depressed state
virtual bool IsDepressed();
// Set button force depressed state.
virtual void ForceDepressed(bool state);
// Set button depressed state with respect to the force depressed state.
virtual void RecalculateDepressedState( void );
// Set button selected state.
virtual void SetSelected(bool state);
// Check selected state
virtual bool IsSelected( void );
//Set whether or not the button captures all mouse input when depressed.
virtual void SetUseCaptureMouse( bool state );
// Check if mouse capture is enabled.
virtual bool IsUseCaptureMouseEnabled( void );
// Activate a button click.
MESSAGE_FUNC( DoClick, "PressButton" );
MESSAGE_FUNC( OnHotkey, "Hotkey" )
{
DoClick();
}
// Set button to be mouse clickable or not.
virtual void SetMouseClickEnabled( MouseCode code, bool state );
// sets the how this button activates
enum ActivationType_t
{
ACTIVATE_ONPRESSEDANDRELEASED, // normal button behaviour
ACTIVATE_ONPRESSED, // menu buttons, toggle buttons
ACTIVATE_ONRELEASED, // menu items
};
virtual void SetButtonActivationType(ActivationType_t activationType);
// Message targets that the button has been pressed
virtual void FireActionSignal( void );
// Perform graphical layout of button
virtual void PerformLayout();
virtual bool RequestInfo(KeyValues *data);
// Respond when key focus is received
virtual void OnSetFocus();
// Respond when focus is killed
virtual void OnKillFocus();
// Set button border attribute enabled, controls display of button.
virtual void SetButtonBorderEnabled( bool state );
// Get button foreground color
virtual Color GetButtonFgColor();
// Get button background color
virtual Color GetButtonBgColor();
// Set the command to send when the button is pressed
// Set the panel to send the command to with AddActionSignalTarget()
virtual void SetCommand( const char *command );
// Set the message to send when the button is pressed
virtual void SetCommand( KeyValues *message );
/* CUSTOM MESSAGE HANDLING
"PressButton" - makes the button act as if it had just been pressed by the user (just like DoClick())
input: none
*/
virtual void OnCursorEntered();
virtual void OnCursorExited();
virtual void SizeToContents();
virtual KeyValues *GetCommand();
bool IsDrawingFocusBox();
void DrawFocusBox( bool bEnable );
protected:
// Paint button on screen
virtual void Paint(void);
// Get button border attributes.
virtual void ApplySchemeSettings(IScheme *pScheme);
MESSAGE_FUNC_INT( OnSetState, "SetState", state );
virtual void OnMousePressed(MouseCode code);
virtual void OnMouseDoublePressed(MouseCode code);
virtual void OnMouseReleased(MouseCode code);
virtual void OnKeyCodePressed(KeyCode code);
virtual void OnKeyCodeReleased(KeyCode code);
// Get control settings for editing
virtual void GetSettings( KeyValues *outResourceData );
virtual void ApplySettings( KeyValues *inResourceData );
virtual const char *GetDescription( void );
KeyValues *GetActionMessage();
private:
enum ButtonFlags_t
{
ARMED = 0x0001,
DEPRESSED = 0x0002,
FORCE_DEPRESSED = 0x0004,
BUTTON_BORDER_ENABLED = 0x0008,
USE_CAPTURE_MOUSE = 0x0010,
BUTTON_KEY_DOWN = 0x0020,
DEFAULT_BUTTON = 0x0040,
SELECTED = 0x0080,
DRAW_FOCUS_BOX = 0x0100,
BLINK = 0x0200,
ALL_FLAGS = 0xFFFF,
};
CUtlFlags< unsigned short > _buttonFlags; // see ButtonFlags_t
int _mouseClickMask;
KeyValues *_actionMessage;
ActivationType_t _activationType;
Color _defaultFgColor, _defaultBgColor;
bool m_bSelectionStateSaved;
};
} // namespace vgui
#endif // URLBUTTON_H
|