-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdialog.h
executable file
·127 lines (93 loc) · 3.08 KB
/
dialog.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
#ifndef _DIALOG_H_
#define _DIALOG_H_
#include <functional>
#include <string>
#include <vector>
#include <SDL.h>
#include <SDL_ttf.h>
#include "sdl_ttf_multifont.h"
#include "window.h"
class CDialog : public CWindow
{
public:
// x_fn and y_fn are function that return dialog coordinates.
// They are functions so that we can handle moving the dialog on resize.
// Empty functions mean centered.
CDialog(const std::string &p_title, std::function<Sint16()> x_fn = {},
std::function<Sint16()> y_fn = {});
// Destructor
virtual ~CDialog(void);
// Add a label
void addLabel(const std::string &p_label);
// Add a menu option
void addOption(const std::string &p_option);
// Sets the color of the borders and title background.
void setBorderColor(SDL_Color color) { m_borderColor = color; }
// Init. Call after all options are added.
void init(void);
// Accessors
int getX() const { return m_x; }
int getY() const { return m_y; }
const unsigned int &getHighlightedIndex(void) const;
int border_x() const { return border_x_; };
int border_y() const { return border_y_; };
int width() const { return width_; };
int height() const { return height_; };
int line_height() const { return line_height_; };
private:
// Forbidden
CDialog(void);
CDialog(const CDialog &p_source);
const CDialog &operator =(const CDialog &p_source);
void onResize() override;
// Key press management
const bool keyPress(const SDL_Event &p_event) override;
// Key hold management
const bool keyHold(void) override;
bool mouseDown(int button, int x, int y) override;
bool mouseWheel(int dx, int dy) override;
// Draw
void render(const bool p_focus) const override;
// Move cursor
const bool moveCursorUp(const bool p_loop);
const bool moveCursorDown(const bool p_loop);
void freeResources();
// Returns the line index at the given coordinates or -1.
int getLineAt(int x, int y) const;
// Dimensions in physical pixels.
int border_x_, border_y_;
int padding_x_;
int line_height_;
int width_, height_;
SDL_Color m_borderColor;
// Number of titles (0 or 1), labels, and options
bool m_nbTitle;
unsigned char m_nbLabels;
unsigned char m_nbOptions;
// List of lines
std::vector<std::string> m_lines;
SDL_Surface *m_titleImg;
std::vector<SDL_Surface *> m_linesImg;
std::vector<SDL_Surface *> m_linesImgCursor1;
std::vector<SDL_Surface *> m_linesImgCursor2;
// The highlighted item
unsigned int m_highlightedLine;
// The image representing the dialog
SDL_Surface *m_image;
// The cursor
SDL_Surface *m_cursor1;
SDL_Surface *m_cursor2;
// Coordinates
std::function<Sint16()> m_x_fn;
std::function<Sint16()> m_y_fn;
int m_x, m_y;
int m_cursorX, m_cursorY;
// Relative coordinates, for better resize handling.
float relative_x;
float relative_y;
// Line clip
mutable SDL_Rect m_clip;
// Pointers to resources
const Fonts &m_fonts;
};
#endif