diff options
feat: Implement aspect LED video wall
3 files changed, 31 insertions, 4 deletions
| -rw-r--r-- | src/LEDVideoWall.cpp | 25 | ||||
| -rw-r--r-- | src/LEDVideoWall.h | 1 | ||||
| -rw-r--r-- | src/cli.hpp | 9 |
diff --git a/src/LEDVideoWall.cpp b/src/LEDVideoWall.cpp index b86afb0..ad3dc3c 100644 --- a/src/LEDVideoWall.cpp +++ b/src/LEDVideoWall.cpp @@ -10,10 +10,16 @@ LEDVideoWall* LEDVideoWall::Freeform(mm panel_width, mm panel_height, mm wall_ma (wall_max_height / panel_height) * panel_height); } +LEDVideoWall* LEDVideoWall::Aspect(mm panel_width, mm panel_height, unsigned int aspect_width, unsigned int aspect_height) { + return new LEDVideoWall( + aspect_width * panel_width, + aspect_height * panel_height); +} + LEDVideoWall::LEDVideoWall(mm width, mm height) : Screen(width, height) { } enum class LEDVideoWallType { - Freeform = 0 + Freeform = 0, Aspect }; LEDVideoWall* LEDVideoWall::fromCommandLine() { @@ -29,11 +35,11 @@ LEDVideoWall* LEDVideoWall::fromCommandLine() { "Enter height for a single panel (in mm): ", "Invalid panel height, try again!"); - unsigned int itype = 1; + unsigned int itype = 2; cli::readUserInputMax( itype, - (unsigned int)1, - "Select an LED video wall type [0 for Freeform]: ", + (unsigned int)2, + "Select an LED video wall type [0 for Freeform, 1 for Aspect]: ", "Invalid type, try again!"); LEDVideoWallType type = static_cast<LEDVideoWallType>(itype); @@ -53,6 +59,17 @@ LEDVideoWall* LEDVideoWall::fromCommandLine() { return LEDVideoWall::Freeform(ipanel_width, ipanel_height, iwall_max_width, iwall_max_height); }; + + case LEDVideoWallType::Aspect: { + mm i_width = 0, i_height = 0; + printf("Enter aspect ratio (in the format 'width:height'): "); + while (scanf("%d:%d", &i_width, &i_height) != 2) { + printf("Invalid input, try again!\n"); + printf("Enter aspect ratio (in the format 'width:height'): "); + } + + return LEDVideoWall::Aspect(ipanel_width, ipanel_height, i_width, i_height); + }; } throw std::logic_error("Implementation error: didn't handle all types of LED video walls!"); } diff --git a/src/LEDVideoWall.h b/src/LEDVideoWall.h index 043aaed..fe8b9ea 100644 --- a/src/LEDVideoWall.h +++ b/src/LEDVideoWall.h @@ -10,6 +10,7 @@ public: // Named constructor idiom https://isocpp.org/wiki/faq/ctors#named-ctor-idiom static LEDVideoWall* Freeform(mm panel_width, mm panel_height, mm wall_max_width, mm wall_max_height); + static LEDVideoWall* Aspect(mm panel_width, mm panel_height, unsigned int aspect_width, unsigned int aspect_height); static LEDVideoWall* fromCommandLine(); diff --git a/src/cli.hpp b/src/cli.hpp index 6fa9c1b..21f2ae5 100644 --- a/src/cli.hpp +++ b/src/cli.hpp @@ -18,7 +18,16 @@ namespace cli { std::cout << enter_message; std::cin >> outValue; + } + } + template <typename T> + void readUserInputMax(T& outValue, T max_value, const char* enter_message, const char* error_message) { + readUserInput(outValue, enter_message, error_message); + while (outValue >= max_value) { + std::cerr << error_message << std::endl; + readUserInput(outValue, enter_message, error_message); + } } } |