-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmvc_ap.cpp
More file actions
74 lines (61 loc) · 2.3 KB
/
Copy pathmvc_ap.cpp
File metadata and controls
74 lines (61 loc) · 2.3 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
72
73
74
#include <gtkmm.h>
#include <memory>
#include "controller/Controller.h"
#include "model/SharedData.h"
#include "view/DisplayWidget.h"
#include "view/EditorWidget.h"
class ContainerWindow : public Gtk::Window {
public:
ContainerWindow();
private:
// Main Layout
Gtk::Box mainLayout_;
Gtk::Box topRowLayout_; // Horizontal arrangement (2 Displays side-by-side)
// Model & Controller are shared across all Views,
// so we should use as shared pointers
// Model
std::shared_ptr<SharedData> dataModel_;
// Controllers
std::shared_ptr<Controller> controller_;
// Views
std::unique_ptr<EditorWidget> editorView_;
std::unique_ptr<DisplayWidget> displayViewLeft_;
std::unique_ptr<DisplayWidget> displayViewRight_;
};
ContainerWindow::ContainerWindow()
: mainLayout_(Gtk::Orientation::VERTICAL),
topRowLayout_(Gtk::Orientation::HORIZONTAL) {
set_title("MVC Integrated Demo");
set_default_size(600, 400);
// Init MVC
dataModel_ = std::make_shared<SharedData>();
controller_ = std::make_shared<Controller>(dataModel_);
// Create child Views (Widgets)
editorView_ =
std::make_unique<EditorWidget>(controller_, dataModel_->getData());
// Create two displays of different colors for easier viewing
displayViewLeft_ = std::make_unique<DisplayWidget>(
"ZONE 2: MONITOR A (Blue)", "blue", dataModel_->getData());
displayViewRight_ = std::make_unique<DisplayWidget>(
"ZONE 3: MONITOR B (Red)", "red", dataModel_->getData());
dataModel_->addObserver(editorView_.get());
dataModel_->addObserver(displayViewLeft_.get());
dataModel_->addObserver(displayViewRight_.get());
// Layout Arrangement (Container)
// Top Row: 2 Displays side-by-side (evenly spaced)
displayViewLeft_->set_hexpand(true);
displayViewRight_->set_hexpand(true);
topRowLayout_.append(*displayViewLeft_);
topRowLayout_.append(*displayViewRight_);
// Bottom Row: Editor
editorView_->set_vexpand(
false); // Editor doesn't need to be stretched too large
// Combine into Main Layout
mainLayout_.append(topRowLayout_); // Add top row
mainLayout_.append(*editorView_); // Add bottom row
set_child(mainLayout_);
}
int main(int argc, char* argv[]) {
auto app = Gtk::Application::create("org.gtkmm.example.singlemvc");
return app->make_window_and_run<ContainerWindow>(argc, argv);
}