/
UIDialog.h
91 lines (74 loc) · 1.93 KB
/
UIDialog.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
#ifndef _UIDialog_h
#define _UIDialog_h
#include "screenlib/UIPanel.h"
#include "screenlib/UIElementButton.h"
class UIDialog;
/* This function gets called when the dialog is shown.
*/
typedef void (*UIDialogInitHandler)(UIDialog *dialog);
/* This function gets called when the dialog is hidden.
The status defaults to 0, but can be changed by dialog buttons.
*/
typedef void (*UIDialogDoneHandler)(UIDialog *dialog, int status);
class UIDialog : public UIPanel
{
public:
UIDialog(UIManager *ui, const char *name);
virtual ~UIDialog();
virtual bool IsA(UIElementType type) {
return UIPanel::IsA(type) || type == GetType();
}
/* Set a function that's called when the dialog is hidden */
void SetDialogHandlers(UIDialogInitHandler handleInit,
UIDialogDoneHandler handleDone) {
m_handleInit = handleInit;
m_handleDone = handleDone;
}
void SetDialogStatus(int status) {
m_status = status;
}
virtual bool Load(rapidxml::xml_node<> *node, const UITemplates *templates);
virtual void Show();
virtual void Hide();
virtual void Draw();
virtual bool HandleEvent(const SDL_Event &event);
protected:
enum {
COLOR_BLACK,
COLOR_DARK,
COLOR_MEDIUM,
COLOR_LIGHT,
COLOR_WHITE,
NUM_COLORS
};
Uint32 m_colors[NUM_COLORS];
bool m_expand;
int m_step;
int m_status;
UIDialogInitHandler m_handleInit;
UIDialogDoneHandler m_handleDone;
protected:
static UIElementType s_elementType;
public:
static UIElementType GetType() {
if (!s_elementType) {
s_elementType = GenerateType();
}
return s_elementType;
}
};
//
// A class to make it easy to launch a dialog from a button
//
class UIDialogLauncher : public UIButtonDelegate
{
public:
UIDialogLauncher(UIManager *ui, const char *name, UIDialogInitHandler = NULL, UIDialogDoneHandler handleDone = NULL);
virtual void OnClick();
protected:
UIManager *m_ui;
const char *m_name;
UIDialogInitHandler m_handleInit;
UIDialogDoneHandler m_handleDone;
};
#endif // _UIDialog_h