+ pixelwerte getter/setter

This commit is contained in:
Johannes Theiner 2019-11-21 11:35:54 +01:00
parent 3c76d941fa
commit e4dce850cc
8 changed files with 84 additions and 12 deletions

View File

@ -9,7 +9,7 @@ filelist="$(find . -not \( -path './*build*' -prune \) -not \( -path './include'
for file in $filelist; do
if echo "$file" | grep -q -E ".*(\.cpp|\.h|\.hpp)$" ; then
#Extra check missing dependencies due to clang-tidy doesn't toggle exit code.
clang_tidy_lib_check="$(clang-tidy -warnings-as-errors='*' --color -header-filter='.*,-cpptoml.hpp' "$file" -- -I. -std=c++14 2>&1)"
clang_tidy_lib_check="$(clang-tidy -warnings-as-errors='*' --color "$file" -- -I. -std=c++14 2>&1)"
for tidy_line in $clang_tidy_lib_check; do
echo "$tidy_line" | grep -q -v -E "^Error while processing*"
if [ $? -eq 1 ]; then

View File

@ -1,2 +1,3 @@
Checks: '*,-llvm-header-guard,-fuchsia*,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-pro-bounds-constant-array-index,-bugprone-narrowing-conversions,-cppcoreguidelines-narrowing-conversions,-cppcoreguidelines-pro-type-const-cast,-cppcoreguidelines-pro-type-reinterpret-cast,-hicpp-signed-bitwise,-bugprone-exception-escape,-cppcoreguidelines-pro-type-member-init,-cppcoreguidelines-pro-type-cstyle-cast,-hicpp-member-init,-google-readability-namespace-comments,-llvm-namespace-comment,-cppcoreguidelines-pro-type-vararg,-hicpp-vararg,-modernize-use-trailing-return-type'
WarningsAsErrors: 'true'
WarningsAsErrors: 'true'
HeaderFilterRegex: '.*,-catch.hpp'

View File

@ -12,8 +12,7 @@ project(library)
set(CMAKE_CXX_STANDARD 14)
# enable clang_tidy
set(CMAKE_CXX_CLANG_TIDY "clang-tidy;-checks=*")
set(CMAKE_CXX_CLANG_TIDY clang-tidy;-header-filter=.;)
set(CMAKE_CXX_CLANG_TIDY clang-tidy;)
file(GLOB_RECURSE SOURCES src/*.cpp)
@ -22,7 +21,7 @@ file(GLOB_RECURSE TESTS test/*.cpp)
include_directories(src)
include_directories(test)
add_library(library ${SOURCES} ${HEADERS} src/FontType.cpp)
add_library(library ${SOURCES} ${HEADERS})
file(COPY "${CMAKE_SOURCE_DIR}/src/"
DESTINATION "${CMAKE_SOURCE_DIR}/include"

View File

@ -30,4 +30,12 @@ namespace vkvm {
auto Color::setBlue(unsigned char value) -> void {
blue = value;
}
bool Color::operator==(const Color &other) const {
return this->blue == other.blue && this->green == other.green && this->red == other.red;
}
bool Color::operator!=(const Color &other) const {
return this->blue != other.blue || this->green != other.green || this->red != other.red;
}
}

View File

@ -30,10 +30,17 @@ namespace vkvm {
auto setBlue(unsigned char value) -> void;
bool operator==(const Color &other) const ;
bool operator!=(const Color &other) const ;
};
const static Color black = Color(0, 0, 0);
const static Color white = Color(255, 255, 255);
const static Color green = Color(0, 255, 0);
const static Color red = Color(255, 0, 0);
const static Color blue = Color(0, 0, 255);
}

View File

@ -55,7 +55,7 @@ constexpr int keyboardBufferSize = 16;
key_t sharedMemoryKey;
int sharedMemorySize;
int interruptEntyCount = 256; //NOLINT
int interruptEntrysPerEventType = 8;
int interruptEntrysPerEventType = 8; //NOLINT
int reservedSize = 1024; //NOLINT
std::vector<std::function<void()>> eventTable;
};

View File

@ -23,9 +23,9 @@ namespace vkvm {
setHeight(600);// NOLINT
setWidth(800);// NOLINT
setMousePosition(42, 42);// NOLINT
setBackgroundColor(Color(200, 50, 20));// NOLINT
setForegroundColor(Color(20, 200, 50));// NOLINT
setMode(GraphicMode::RGB);// NOLINT
setBackgroundColor(black);
setForegroundColor(white);
setMode(GraphicMode::RGB);
setRedrawInterval(20);// NOLINT
setTimerInterruptInterval(10);// NOLINT
}
@ -69,10 +69,22 @@ namespace vkvm {
}
auto getPixel(int x, int y) -> Color {
//TODO(julian): other than RGB colores
//only RGB colores for now
unsigned char *ptr = reinterpret_cast<unsigned char *>(getPixelArea()) + (y * getWidth() + x) * 3;
return {ptr[0], ptr[1], ptr[2]};
Color color = {ptr[0], ptr[1], ptr[2]};
if(getMode() == GraphicMode::TwoColors || getMode() == GraphicMode::Text) {
if(color != getForegroundColor()) {
color = getBackgroundColor();
}
}
else if(getMode() == GraphicMode::Gray_256) {
unsigned char average = (color.getBlue() + color.getGreen() + color.getRed()) / 3;
color = {average, average, average};
}
return color;
}
auto setText(std::string text) -> bool {

45
test/color_test.cpp Normal file
View File

@ -0,0 +1,45 @@
#include "../src/vkvm.hpp"
#include <catch2/catch.hpp>
#include <iostream>
TEST_CASE("Colors") {
vkvm::initialize(0);
vkvm::setPixel(10, 10, vkvm::black);//NOLINT
vkvm::setPixel(11, 11, vkvm::white);//NOLINT
vkvm::setPixel(12, 12, vkvm::green);//NOLINT
vkvm::setPixel(13, 13, vkvm::red);//NOLINT
vkvm::setPixel(14, 14, vkvm::blue);//NOLINT
vkvm::setPixel(15, 15, vkvm::Color(66, 77, 88)); //NOLINT
SECTION("RGB") {
REQUIRE(vkvm::getPixel(10, 10) == vkvm::black);//NOLINT
REQUIRE(vkvm::getPixel(11, 11) == vkvm::white);//NOLINT
REQUIRE(vkvm::getPixel(12, 12) == vkvm::green);//NOLINT
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
}
SECTION("TwoColors") {
vkvm::setMode(vkvm::TwoColors);
REQUIRE(vkvm::getPixel(10, 10) == vkvm::black);//NOLINT
REQUIRE(vkvm::getPixel(11, 11) == vkvm::white);//NOLINT
REQUIRE(vkvm::getPixel(12, 12) == vkvm::black);//NOLINT
REQUIRE(vkvm::getPixel(13, 13) == vkvm::black);//NOLINT
REQUIRE(vkvm::getPixel(14, 14) == vkvm::black);//NOLINT
REQUIRE(vkvm::getPixel(15, 15) == vkvm::black);//NOLINT
}
SECTION("Gray256") {
vkvm::setMode(vkvm::Gray_256);
REQUIRE(vkvm::getPixel(10, 10) == vkvm::black);//NOLINT
REQUIRE(vkvm::getPixel(11, 11) == vkvm::white);//NOLINT
REQUIRE(vkvm::getPixel(12, 12) == 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(15, 15) == vkvm::Color(77, 77, 77));//NOLINT
}
}