-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathConfig2.cpp
More file actions
67 lines (56 loc) · 2.31 KB
/
Config2.cpp
File metadata and controls
67 lines (56 loc) · 2.31 KB
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
#include "Settings.hpp"
#include <wx/app.h>
#include <wx/button.h>
#include <wx/clrpicker.h>
#include <wx/frame.h>
#include <wx/panel.h>
namespace Config2Example {
class Frame : public wxFrame {
public:
Frame() : wxFrame {nullptr, wxID_ANY, Properties::Settings::DefaultSettings().Caption()} {
reload_config();
colourPicker->Bind(wxEVT_COLOURPICKER_CHANGED, [&](wxColourPickerEvent& event) {
panel->SetBackgroundColour(event.GetColour());
Refresh();
});
saveButton->Bind(wxEVT_BUTTON, [&](wxCommandEvent& event) {
save_config();
});
reloadButton->Bind(wxEVT_BUTTON, [&](wxCommandEvent& event) {
reload_config();
});
resetButton->Bind(wxEVT_BUTTON, [&](wxCommandEvent& event) {
reset_config();
});
}
private:
void reload_config() {
Properties::Settings::DefaultSettings().Reload();
SetPosition(Properties::Settings::DefaultSettings().Position());
SetClientSize(Properties::Settings::DefaultSettings().Size());
panel->SetBackgroundColour(Properties::Settings::DefaultSettings().BackgroundColour());
colourPicker->SetColour(Properties::Settings::DefaultSettings().BackgroundColour());
Refresh();
}
void save_config() {
Properties::Settings::DefaultSettings().Position(GetPosition());
Properties::Settings::DefaultSettings().Size(GetSize());
Properties::Settings::DefaultSettings().BackgroundColour(panel->GetBackgroundColour());
Properties::Settings::DefaultSettings().Save();
}
void reset_config() {
Properties::Settings::DefaultSettings().Reset();
reload_config();
}
wxPanel* panel = new wxPanel {this};
wxColourPickerCtrl* colourPicker = new wxColourPickerCtrl {panel, wxID_ANY, {0, 0, 0}, {10, 10}, {75, 25}};
wxButton* saveButton = new wxButton {panel, wxID_ANY, "&Save", {90, 10}, {75, 25}};
wxButton* reloadButton = new wxButton {panel, wxID_ANY, "&Reload", {170, 10}, {75, 25}};
wxButton* resetButton = new wxButton {panel, wxID_ANY, "R&eset", {250, 10}, {75, 25}};
wxColour defaultBackgroundColor = panel->GetBackgroundColour();
};
class Application : public wxApp {
auto OnInit() -> bool override {return (new Frame)->Show();}
};
}
wxIMPLEMENT_APP(Config2Example::Application);