From 511f04edae55d3b5e4a9bbc31f33f55cb1654c34 Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Thu, 21 Nov 2019 12:37:52 +0100 Subject: [PATCH] + hex Werte umrechnen zu Color --- src/Color.cpp | 5 +++++ src/Color.hpp | 2 ++ src/internal.cpp | 2 +- test/color_test.cpp | 4 ++++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Color.cpp b/src/Color.cpp index 3acc402..f554401 100644 --- a/src/Color.cpp +++ b/src/Color.cpp @@ -4,7 +4,12 @@ namespace vkvm { Color::Color(unsigned char red, unsigned char green, unsigned char blue) noexcept : red(red), green(green), blue(blue) { + } + Color::Color(unsigned int hex) noexcept { + red = (unsigned char) ((hex >> 16 & 0xFF));//NOLINT + green = (unsigned char) ((hex >> 8u & 0xFF));//NOLINT + blue = (unsigned char) ((hex & 0xFF));//NOLINT } auto Color::getRed() -> unsigned char { diff --git a/src/Color.hpp b/src/Color.hpp index 909eb9e..b622d3d 100644 --- a/src/Color.hpp +++ b/src/Color.hpp @@ -18,6 +18,8 @@ namespace vkvm { public: Color(unsigned char red, unsigned char green, unsigned char blue) noexcept; + explicit Color(unsigned int hex) noexcept; + auto getRed() -> unsigned char; auto getGreen() -> unsigned char; diff --git a/src/internal.cpp b/src/internal.cpp index a6c5937..614e42c 100644 --- a/src/internal.cpp +++ b/src/internal.cpp @@ -77,7 +77,7 @@ namespace vkvm { if (reg->keyboardBuffer_index_write == sizeof(reg->keyboardBuffer)) { reg->keyboardBuffer_index_write = 0; } - reg->keyboardBuffer[reg->keyboardBuffer_index_write++] = keyCode.getValue(); + reg->keyboardBuffer[reg->keyboardBuffer_index_write++] = keyCode; unlockSharedMemory(); } diff --git a/test/color_test.cpp b/test/color_test.cpp index 9037a40..32154ff 100644 --- a/test/color_test.cpp +++ b/test/color_test.cpp @@ -10,6 +10,7 @@ TEST_CASE("Colors") { vkvm::setPixel(13, 13, vkvm::red);//NOLINT vkvm::setPixel(14, 14, vkvm::blue);//NOLINT vkvm::setPixel(15, 15, vkvm::Color(66, 77, 88)); //NOLINT + vkvm::setPixel(16, 16, vkvm::Color(0xFFFFFF));//NOLINT SECTION("RGB") { REQUIRE(vkvm::getPixel(10, 10) == vkvm::black);//NOLINT @@ -18,6 +19,7 @@ TEST_CASE("Colors") { REQUIRE(vkvm::getPixel(13, 13) == vkvm::red);//NOLINT REQUIRE(vkvm::getPixel(14, 14) == vkvm::blue);//NOLINT REQUIRE(vkvm::getPixel(15, 15) == vkvm::Color(66, 77, 88));//NOLINT + REQUIRE(vkvm::getPixel(16, 16) == vkvm::white);//NOLINT } SECTION("TwoColors") { @@ -28,6 +30,7 @@ TEST_CASE("Colors") { REQUIRE(vkvm::getPixel(13, 13) == vkvm::black);//NOLINT REQUIRE(vkvm::getPixel(14, 14) == vkvm::black);//NOLINT REQUIRE(vkvm::getPixel(15, 15) == vkvm::black);//NOLINT + REQUIRE(vkvm::getPixel(16, 16) == vkvm::white);//NOLINT } @@ -39,6 +42,7 @@ TEST_CASE("Colors") { REQUIRE(vkvm::getPixel(13, 13) == vkvm::Color(85, 85, 85));//NOLINT REQUIRE(vkvm::getPixel(14, 14) == vkvm::Color(85, 85, 85));//NOLINT REQUIRE(vkvm::getPixel(15, 15) == vkvm::Color(77, 77, 77));//NOLINT + REQUIRE(vkvm::getPixel(16, 16) == vkvm::white);//NOLINT } }