new architecture of Code for show cursor and Preview

This commit is contained in:
Shaohua Tong 2019-12-11 11:49:58 +01:00
parent 227183bfe5
commit d053170cf5
4 changed files with 14 additions and 12 deletions

View File

@ -22,7 +22,7 @@ file(GLOB_RECURSE TESTS test/*.cpp)
set(LIB_PATH "${CMAKE_SOURCE_DIR}/../library")
include_directories(${LIB_PATH}/include)
add_executable(SimpleDraw ${SOURCES} ${HEADERS} main/main.cpp src/DrawRender.cpp src/DrawRender.hpp src/Circle.cpp src/Circle.hpp src/Rectangle.cpp src/Rectangle.hpp src/utils.cpp src/utils.hpp src/Shapes.cpp src/Shapes.hpp src/Cursor.cpp src/Cursor.hpp)
add_executable(SimpleDraw ${SOURCES} ${HEADERS} main/main.cpp)
target_link_libraries(SimpleDraw ${LIB_PATH}/lib/liblibrary.a)

View File

@ -32,11 +32,11 @@ Circle::Circle(vkvm::Coordinates center, int radius, int penWidth, bool brush) {
distance = utils::squareOfDistance(temp, center);
if(!brush) {
if( distance < (radius * radius) && distance > ((radius - penWidth) * (radius - penWidth)))
if( distance <= (radius * radius) && distance >= ((radius - penWidth) * (radius - penWidth)))
circle[y_draw][x_draw] = true;
}
else {
if( distance < (radius * radius))
if( distance <= (radius * radius))
circle[y_draw][x_draw] = true;
}
}

View File

@ -96,6 +96,8 @@ void DrawRender::clear() {
vkvm::setPixel(x, y, backgroundColor);
}
}
shapes = Shapes();
}
void DrawRender::cursorCreator() {
@ -144,7 +146,6 @@ void DrawRender::clearToSharedMemory(std::vector<std::vector<bool>> shape, int s
else {
vkvm::setPixel(currentX, currentY, penColor);
}
}
currentX++;
}

View File

@ -19,18 +19,19 @@ void Shapes::addShape(std::vector<std::vector<bool>> shape, int startX, int star
endXs[count-1] = endX;
endYs[count-1] = endY;
shapes[count-1].resize(shape.size());
for(int y = 0; y < shape.size(); y++) {
shapes[count-1][y].resize(shape[y].size());
for(int x = 0; x < shape[y].size(); x++) {
shapes[count-1][y][x] = shape[y][x];
}
}
// shapes[count-1].resize(shape.size());
// for(int y = 0; y < shape.size(); y++) {
// shapes[count-1][y].resize(shape[y].size());
// for(int x = 0; x < shape[y].size(); x++) {
// shapes[count-1][y][x] = shape[y][x];
// }
// }
shapes[count-1] = shape;
}
bool Shapes::containsPixel(int x, int y) {
for(int i = 0; i < count; i++) {
if(x > startXs[i] && x < endXs[i] && y > startYs[i] && y < endYs[i]) {
if(x >= startXs[i] && x < endXs[i] && y >= startYs[i] && y < endYs[i]) {
if(shapes[i][y-startYs[i]][x-startXs[i]]) {
return true;
}