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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: An arbitrary picker
//
//=============================================================================
#ifndef PICKER_H
#define PICKER_H
#ifdef _WIN32
#pragma once
#endif
#include "vgui_controls/EditablePanel.h"
#include "vgui_controls/Frame.h"
#include "tier1/utlstring.h"
//-----------------------------------------------------------------------------
// Forward declarations
//-----------------------------------------------------------------------------
namespace vgui
{
class Panel;
}
//-----------------------------------------------------------------------------
// List of strings to appear in the picker
//-----------------------------------------------------------------------------
enum PickerChoiceType_t
{
PICKER_CHOICE_STRING = 0,
PICKER_CHOICE_PTR,
};
struct PickerInfo_t
{
const char *m_pChoiceString; // This is what displays in the dialog
union
{
const char *m_pChoiceValue;
void *m_pChoiceValuePtr;
};
};
struct PickerList_t
{
PickerList_t() : m_Type( PICKER_CHOICE_STRING ) {}
PickerList_t( int nGrowSize, int nInitSize ) : m_Choices( nGrowSize, nInitSize ), m_Type( PICKER_CHOICE_STRING ) {}
int Count() const { return m_Choices.Count(); }
PickerInfo_t& operator[]( int i ) { return m_Choices[i]; }
const PickerInfo_t& operator[]( int i ) const { return m_Choices[i]; }
int AddToTail() { return m_Choices.AddToTail(); }
void RemoveAll() { return m_Choices.RemoveAll(); }
PickerChoiceType_t m_Type;
CUtlVector< PickerInfo_t > m_Choices;
};
//-----------------------------------------------------------------------------
// Purpose: Base class for choosing raw assets
//-----------------------------------------------------------------------------
class CPicker : public vgui::EditablePanel
{
DECLARE_CLASS_SIMPLE( CPicker, vgui::EditablePanel );
public:
CPicker( vgui::Panel *pParent, const char *pColumnHeader, const char *pTextType );
~CPicker();
// Sets the list of strings to display
void SetStringList( const PickerList_t &list );
// Purpose:
virtual void OnKeyCodePressed( vgui::KeyCode code );
// Returns the selected string
PickerChoiceType_t GetSelectionType() const;
const char *GetSelectedString( ) const;
void *GetSelectedPtr( ) const;
// Returns the index of the selected string
int GetSelectedIndex();
private:
void RefreshChoiceList( );
MESSAGE_FUNC( OnTextChanged, "TextChanged" );
vgui::TextEntry *m_pFilterList;
vgui::ListPanel *m_pPickerBrowser;
CUtlString m_Filter;
const char *m_pPickerType;
const char *m_pPickerTextType;
const char *m_pPickerExt;
const char *m_pPickerSubDir;
PickerChoiceType_t m_Type;
friend class CPickerFrame;
};
//-----------------------------------------------------------------------------
// Purpose: Modal dialog for picker
//-----------------------------------------------------------------------------
class CPickerFrame : public vgui::Frame
{
DECLARE_CLASS_SIMPLE( CPickerFrame, vgui::Frame );
public:
CPickerFrame( vgui::Panel *pParent, const char *pTitle, const char *pColumnHeader, const char *pTextType );
~CPickerFrame();
// Inherited from Frame
virtual void OnCommand( const char *pCommand );
// Purpose: Activate the dialog
// The message "Picked" will be sent if something is picked.
// You can pass in keyvalues to get added to the message also.
void DoModal( const PickerList_t &list, KeyValues *pContextKeyValues = NULL );
private:
void CleanUpMessage();
CPicker *m_pPicker;
vgui::Button *m_pOpenButton;
vgui::Button *m_pCancelButton;
KeyValues *m_pContextKeyValues;
};
#endif // PICKER_H
|