aboutsummaryrefslogtreecommitdiff
path: root/ViewController.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ViewController.cpp')
-rw-r--r--ViewController.cpp76
1 files changed, 44 insertions, 32 deletions
diff --git a/ViewController.cpp b/ViewController.cpp
index fc08c68..6422bbb 100644
--- a/ViewController.cpp
+++ b/ViewController.cpp
@@ -2,11 +2,18 @@
#include "Exception.h"
#include "KeyboardCode.h"
#include "MouseCode.h"
+#include "MuseumPauseCommand.h"
#include "OpenFileGUICommand.h"
#include "View.h"
#include "Museum.h"
-ViewController::ViewController(Museum & m, View & v) : museum(m), view(v) {};
+ViewController::ViewController(Museum & m, View & v) : museum(m), view(v) {
+ this->cmd_base = new Command(this->museum, this->view, *this);
+}
+
+ViewController::~ViewController() {
+ delete this->cmd_base;
+}
void ViewController::update() {
this->update_size();
@@ -51,47 +58,52 @@ void ViewController::update_artists() {
}
void ViewController::ev_keydown(KeyboardCode key) {
- switch (key) {
- case KEY_SPACE: {
- printf("TODO: toggle museum.pause\n");
- // MuseumPauseCommand().toggle();
- break;
- }
- case KEY_ENTER: {
- break;
- }
- case KEY_O: {
- try {
- OpenFileGUICommand(this->museum, this->view, *this).execute();
- } catch (Exception & e) {
- printf("OpenFileGUICommand error: %s\n", e.what());
+ try {
+ switch (key) {
+ case KEY_SPACE: {
+ MuseumPauseCommand(this->cmd_base).toggle();
+ break;
}
- break;
- }
- case KEY_A: {
- break;
- }
- case KEY_LEFT: {
- break;
- }
- case KEY_RIGHT: {
- break;
+ case KEY_ENTER: {
+ break;
+ }
+ case KEY_O: {
+ OpenFileGUICommand(this->cmd_base).execute();
+ break;
+ }
+ case KEY_A: {
+ break;
+ }
+ case KEY_LEFT: {
+ break;
+ }
+ case KEY_RIGHT: {
+ break;
+ }
+ default: break;
}
- default: break;
+ } catch (Exception & e) {
+ printf("%s\n", e.what());
}
}
void ViewController::ev_mousedown(MouseCode button) {
- printf("mouse %d\n", button);
- switch (button) {
- case MOUSE_LEFT: {
- // MuseumPauseCommand().toggle();
- break;
+ try {
+ switch (button) {
+ case MOUSE_LEFT: {
+ break;
+ }
+ default: break;
}
- default: break;
+ } catch (Exception & e) {
+ printf("%s\n", e.what());
}
}
void ViewController::ev_mousemove(unsigned x, unsigned y) {
+ this->mouse_pos = {
+ static_cast<float>(x) / static_cast<float>(this->scale),
+ static_cast<float>(y) / static_cast<float>(this->scale),
+ };
}