diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-15 13:06:01 +0200 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-15 13:06:01 +0200 |
commit | a38cfbc9f15b0816e65efc7a8ccb30994ab60f30 (patch) | |
tree | 62d2a73a1c70c7683643ae3891fdb6b1e3d1dc53 | |
parent | 5a62972ec9e8b288e90a90450d338a2c0c1176be (diff) |
add artist visibility toggling
-rw-r--r-- | ArtistVisibilityCommand.cpp | 13 | ||||
-rw-r--r-- | ArtistVisibilityCommand.h | 12 | ||||
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | ViewController.cpp | 4 | ||||
-rw-r--r-- | ViewController.h | 6 |
5 files changed, 35 insertions, 1 deletions
diff --git a/ArtistVisibilityCommand.cpp b/ArtistVisibilityCommand.cpp new file mode 100644 index 0000000..b442daf --- /dev/null +++ b/ArtistVisibilityCommand.cpp @@ -0,0 +1,13 @@ +#include "ArtistVisibilityCommand.h" +#include "ViewController.h" + +void ArtistVisibilityCommand::set(bool visible) { + ViewController & controller = this->get_controller(); + controller.set_artists_visible(visible); +} + +void ArtistVisibilityCommand::toggle() { + ViewController & controller = this->get_controller(); + controller.set_artists_visible(!controller.get_artists_visible()); +} + diff --git a/ArtistVisibilityCommand.h b/ArtistVisibilityCommand.h new file mode 100644 index 0000000..416c801 --- /dev/null +++ b/ArtistVisibilityCommand.h @@ -0,0 +1,12 @@ +#pragma once + +#include "Command.h" + +class ArtistVisibilityCommand : public Command { + using Command::Command; + +public: + virtual void toggle(); + virtual void set(bool visible); +}; + diff --git a/CMakeLists.txt b/CMakeLists.txt index ac6511d..a238235 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,6 +46,7 @@ add_executable(main OpenFileGUICommand.cpp LoadFilesCommand.cpp MuseumPauseCommand.cpp + ArtistVisibilityCommand.cpp ) target_link_libraries(main diff --git a/ViewController.cpp b/ViewController.cpp index 6422bbb..a23283d 100644 --- a/ViewController.cpp +++ b/ViewController.cpp @@ -1,4 +1,5 @@ #include "ViewController.h" +#include "ArtistVisibilityCommand.h" #include "Exception.h" #include "KeyboardCode.h" #include "MouseCode.h" @@ -18,7 +19,7 @@ ViewController::~ViewController() { void ViewController::update() { this->update_size(); this->update_tiles(); - this->update_artists(); + if (this->draw_artists) this->update_artists(); } void ViewController::update_size() { @@ -72,6 +73,7 @@ void ViewController::ev_keydown(KeyboardCode key) { break; } case KEY_A: { + ArtistVisibilityCommand(this->cmd_base).toggle(); break; } case KEY_LEFT: { diff --git a/ViewController.h b/ViewController.h index 1e41a2c..0b86468 100644 --- a/ViewController.h +++ b/ViewController.h @@ -20,6 +20,10 @@ public: void ev_mousedown(MouseCode code); void ev_mousemove(unsigned x, unsigned y); +public: + void set_artists_visible(bool visible) { this->draw_artists = visible; } + bool get_artists_visible() { return this->draw_artists; } + private: void update_size(); void update_tiles(); @@ -29,6 +33,8 @@ private: Museum & museum; View & view; const Command * cmd_base = nullptr; + + bool draw_artists = true; private: unsigned int scale = 16; |