+ hex Werte umrechnen zu Color

This commit is contained in:
Johannes Theiner 2019-11-21 12:37:52 +01:00
parent 26a49cd79b
commit 511f04edae
4 changed files with 12 additions and 1 deletions

View File

@ -4,7 +4,12 @@ namespace vkvm {
Color::Color(unsigned char red, unsigned char green, unsigned char blue) noexcept Color::Color(unsigned char red, unsigned char green, unsigned char blue) noexcept
: red(red), green(green), blue(blue) { : 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 { auto Color::getRed() -> unsigned char {

View File

@ -18,6 +18,8 @@ namespace vkvm {
public: public:
Color(unsigned char red, unsigned char green, unsigned char blue) noexcept; Color(unsigned char red, unsigned char green, unsigned char blue) noexcept;
explicit Color(unsigned int hex) noexcept;
auto getRed() -> unsigned char; auto getRed() -> unsigned char;
auto getGreen() -> unsigned char; auto getGreen() -> unsigned char;

View File

@ -77,7 +77,7 @@ namespace vkvm {
if (reg->keyboardBuffer_index_write == sizeof(reg->keyboardBuffer)) { if (reg->keyboardBuffer_index_write == sizeof(reg->keyboardBuffer)) {
reg->keyboardBuffer_index_write = 0; reg->keyboardBuffer_index_write = 0;
} }
reg->keyboardBuffer[reg->keyboardBuffer_index_write++] = keyCode.getValue(); reg->keyboardBuffer[reg->keyboardBuffer_index_write++] = keyCode;
unlockSharedMemory(); unlockSharedMemory();
} }

View File

@ -10,6 +10,7 @@ TEST_CASE("Colors") {
vkvm::setPixel(13, 13, vkvm::red);//NOLINT vkvm::setPixel(13, 13, vkvm::red);//NOLINT
vkvm::setPixel(14, 14, vkvm::blue);//NOLINT vkvm::setPixel(14, 14, vkvm::blue);//NOLINT
vkvm::setPixel(15, 15, vkvm::Color(66, 77, 88)); //NOLINT vkvm::setPixel(15, 15, vkvm::Color(66, 77, 88)); //NOLINT
vkvm::setPixel(16, 16, vkvm::Color(0xFFFFFF));//NOLINT
SECTION("RGB") { SECTION("RGB") {
REQUIRE(vkvm::getPixel(10, 10) == vkvm::black);//NOLINT 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(13, 13) == vkvm::red);//NOLINT
REQUIRE(vkvm::getPixel(14, 14) == vkvm::blue);//NOLINT REQUIRE(vkvm::getPixel(14, 14) == vkvm::blue);//NOLINT
REQUIRE(vkvm::getPixel(15, 15) == vkvm::Color(66, 77, 88));//NOLINT REQUIRE(vkvm::getPixel(15, 15) == vkvm::Color(66, 77, 88));//NOLINT
REQUIRE(vkvm::getPixel(16, 16) == vkvm::white);//NOLINT
} }
SECTION("TwoColors") { SECTION("TwoColors") {
@ -28,6 +30,7 @@ TEST_CASE("Colors") {
REQUIRE(vkvm::getPixel(13, 13) == vkvm::black);//NOLINT REQUIRE(vkvm::getPixel(13, 13) == vkvm::black);//NOLINT
REQUIRE(vkvm::getPixel(14, 14) == vkvm::black);//NOLINT REQUIRE(vkvm::getPixel(14, 14) == vkvm::black);//NOLINT
REQUIRE(vkvm::getPixel(15, 15) == 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(13, 13) == vkvm::Color(85, 85, 85));//NOLINT
REQUIRE(vkvm::getPixel(14, 14) == 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(15, 15) == vkvm::Color(77, 77, 77));//NOLINT
REQUIRE(vkvm::getPixel(16, 16) == vkvm::white);//NOLINT
} }
} }