forked from sears2424/Source-PlusPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLabel.h
225 lines (183 loc) · 6.67 KB
/
Label.h
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#ifndef LABEL_H
#define LABEL_H
#ifdef _WIN32
#pragma once
#endif
#include "utlvector.h"
#include "vgui/VGUI.h"
#include "vgui_controls/Panel.h"
#include "vgui_controls/PHandle.h"
namespace vgui
{
//-----------------------------------------------------------------------------
// Purpose: Contains and displays a set of images
// By default starts with one TextImage
//-----------------------------------------------------------------------------
class Label : public Panel
{
DECLARE_CLASS_SIMPLE( Label, Panel );
public:
// Constructors
Label(Panel *parent, const char *panelName, const char *text);
Label(Panel *parent, const char *panelName, const wchar_t *wszText);
virtual ~Label();
public:
// Take the string and looks it up in the localization file to convert it to unicode
virtual void SetText(const char *tokenName);
// Set unicode text directly
virtual void SetText(const wchar_t *unicodeString, bool bClearUnlocalizedSymbol = false );
// Get the current text
virtual void GetText(OUT_Z_BYTECAP(bufferLen) char *textOut, int bufferLen);
virtual void GetText(OUT_Z_BYTECAP(bufLenInBytes) wchar_t *textOut, int bufLenInBytes);
// Content alignment
// Get the size of the content within the label
virtual void GetContentSize(int &wide, int &tall);
// Set how the content aligns itself within the label
// alignment code, used to determine how the images are layed out within the Label
enum Alignment
{
a_northwest = 0,
a_north,
a_northeast,
a_west,
a_center,
a_east,
a_southwest,
a_south,
a_southeast,
};
virtual void SetContentAlignment(Alignment alignment);
virtual void SetEnabled(bool state);
// Additional offset at the Start of the text (from whichever sides it is aligned)
virtual void SetTextInset(int xInset, int yInset);
virtual void GetTextInset(int *xInset, int *yInset );
// Text colors
virtual void SetFgColor(Color color);
virtual Color GetFgColor();
// colors to use when the label is disabled
virtual void SetDisabledFgColor1(Color color);
virtual void SetDisabledFgColor2(Color color);
virtual Color GetDisabledFgColor1();
virtual Color GetDisabledFgColor2();
// Set whether the text is displayed bright or dull
enum EColorState
{
CS_NORMAL,
CS_DULL,
CS_BRIGHT,
};
virtual void SetTextColorState(EColorState state);
// Font
virtual void SetFont(HFont font);
virtual HFont GetFont();
// Hotkey
virtual Panel *HasHotkey(wchar_t key);
virtual void SetHotkey(wchar_t key);
virtual wchar_t GetHotKey();
// Labels can be associated with controls, and alter behaviour based on the associates behaviour
// If the associate is disabled, so are we
// If the associate has focus, we may alter how we draw
// If we get a hotkey press or focus message, we forward the focus to the associate
virtual void SetAssociatedControl(Panel *control);
// Multiple image handling
// Images are drawn from left to right across the label, ordered by index
// By default there is a TextImage in position 0 (see GetTextImage()/SetTextImageIndex())
virtual int AddImage(IImage *image, int preOffset); // Return the index the image was placed in
virtual void SetImageAtIndex(int index, IImage *image, int preOffset);
virtual void SetImagePreOffset(int index, int preOffset); // Set the offset in pixels before the image
virtual IImage *GetImageAtIndex(int index);
virtual int GetImageCount();
virtual void ClearImages();
virtual void ResetToSimpleTextImage();
// fixes the layout bounds of the image within the label
virtual void SetImageBounds(int index, int x, int width);
// Teturns a pointer to the default text image
virtual TextImage *GetTextImage();
// Moves where the default text image is within the image array (it starts in position 0)
// Setting it to -1 removes it from the image list
// Returns the index the default text image was previously in
virtual int SetTextImageIndex(int newIndex);
// Message handling
// outputData - keyName is the name of the attribute requested.
// for Labels "text" is an option that returns the default text image text
// returns true on success in finding the requested value. false on failure.
virtual bool RequestInfo(KeyValues *outputData);
/* INFO HANDLING
"GetText"
returns:
"text" - text contained in the label
*/
/* CUSTOM MESSAGE HANDLING
"SetText"
input: "text" - label text is set to be this string
*/
virtual void SizeToContents();
// the +8 is padding to the content size
// the code which uses it should really set that itself;
// however a lot of existing code relies on this
enum Padding
{
Content = 8,
};
void SetWrap( bool bWrap );
void SetCenterWrap( bool bWrap );
void SetAllCaps( bool bAllCaps );
protected:
virtual void PerformLayout();
virtual wchar_t CalculateHotkey(const char *text);
virtual wchar_t CalculateHotkey(const wchar_t *text);
virtual void ComputeAlignment(int &tx0, int &ty0, int &tx1, int &ty1);
virtual void Paint();
MESSAGE_FUNC_PARAMS( OnSetText, "SetText", params );
virtual void DrawDashedLine(int x0, int y0, int x1, int y1, int dashLen, int gapLen);
virtual void OnRequestFocus(VPANEL subFocus, VPANEL defaultPanel);
MESSAGE_FUNC( OnHotkeyPressed, "Hotkey" );
virtual void OnMousePressed(MouseCode code);
virtual void OnSizeChanged(int wide, int tall);
// makes sure that the maxIndex will be a valid index
virtual void EnsureImageCapacity(int maxIndex);
// editing
virtual void ApplySchemeSettings(IScheme *pScheme);
virtual void GetSettings( KeyValues *outResourceData );
virtual void ApplySettings( KeyValues *inResourceData );
virtual const char *GetDescription( void );
MESSAGE_FUNC_PARAMS( OnDialogVariablesChanged, "DialogVariables", dialogVariables );
void HandleAutoSizing( void );
private:
void Init();
Alignment _contentAlignment;
TextImage *_textImage; // this is the textImage, if the full text will not
// fit we put as much as we can and add an elipsis (...)
struct TImageInfo
{
IImage *image;
short offset;
short xpos;
short width;
};
CUtlVector<TImageInfo> _imageDar;
int _textInset[2];
Color _disabledFgColor1;
Color _disabledFgColor2;
Color _associateColor;
int _textImageIndex; // index in the image array that the default _textimage resides
EColorState _textColorState;
PHandle _associate;
char *_associateName;
char *_fontOverrideName;
wchar_t _hotkey; // the hotkey contained in the text
bool m_bWrap;
bool m_bCenterWrap;
bool m_bAllCaps;
bool m_bAutoWideToContents;
bool m_bAutoWideDirty;
bool m_bUseProportionalInsets;
};
} // namespace vgui
#endif // LABEL_H