-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathConfig.cpp
More file actions
71 lines (60 loc) · 2.36 KB
/
Config.cpp
File metadata and controls
71 lines (60 loc) · 2.36 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
68
69
70
71
#include <wx/app.h>
#include <wx/button.h>
#include <wx/clrpicker.h>
#include <wx/config.h>
#include <wx/frame.h>
#include <wx/panel.h>
#include <wx/settings.h>
namespace ConfigExample {
class Frame : public wxFrame {
public:
Frame() : wxFrame {nullptr, wxID_ANY, "Config example"} {
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() {
auto backgroundColor = panel->GetBackgroundColour();
config.Read("BackgroundColor", &backgroundColor, wxSystemSettings::GetColour(wxSystemColour::wxSYS_COLOUR_BTNFACE));
panel->SetBackgroundColour(backgroundColor);
SetPosition({static_cast<int>(config.Read("Left", 100)), static_cast<int>(config.Read("Top", 50))});
SetClientSize({static_cast<int>(config.Read("Width", 335)), static_cast<int>(config.Read("Height", 45))});
Refresh();
colourPicker->SetColour(panel->GetBackgroundColour());
}
void save_config() {
config.Write("BackgroundColor", panel->GetBackgroundColour());
config.Write("Left", GetPosition().x);
config.Write("Top", GetPosition().y);
config.Write("Width", GetSize().GetWidth());
config.Write("Height", GetSize().GetHeight());
config.Flush();
}
void reset_config() {
config.DeleteAll();
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}};
wxConfig config;
};
class Application : public wxApp {
auto OnInit() -> bool override {return (new Frame)->Show();}
};
}
wxIMPLEMENT_APP(ConfigExample::Application);