106 lines
3.4 KiB
C++
106 lines
3.4 KiB
C++
#include <iostream>
|
|
#include "internal.hpp"
|
|
#include "vkvm.hpp"
|
|
#include "../src/DrawRender.hpp"
|
|
#include <unistd.h>
|
|
|
|
/**
|
|
* @author: Shaohua Tong
|
|
* @since: v0.0.1
|
|
* draw circle, square, rectangle and mouse drawing
|
|
*/
|
|
void outPutPixel(int windowHeight, int windowWidth, vkvm::Color brushColor);
|
|
|
|
int main() {
|
|
vkvm::initialize(0);
|
|
|
|
vkvm::Color penColor(250,102,0);
|
|
int penWidth = 5;
|
|
DrawRender drawRender(vkvm::getWidth(), vkvm::getHeight(), vkvm::getBackgroundColor(), penColor, penWidth);
|
|
|
|
vkvm::registerEvent(vkvm::EventType::MouseMove, [&drawRender]() {
|
|
if(drawRender.getMouseDown() == true) {
|
|
vkvm::Coordinates mousePosition = vkvm::getMousePosition();
|
|
mousePosition.y = mousePosition.y - 30;
|
|
drawRender.setMousePostion(mousePosition);
|
|
|
|
if (drawRender.getTurnOnBrush() == true ) {
|
|
drawRender.brushUpdate(mousePosition);
|
|
vkvm::callEvent(vkvm::EventType::Redraw);
|
|
}
|
|
|
|
else if((drawRender.getKeyCode() - 65536) == vkvm::KeyCode::S) {
|
|
drawRender.graphicsUpdate(SQUARE);
|
|
vkvm::callEvent(vkvm::EventType::Redraw);
|
|
}
|
|
|
|
else if((drawRender.getKeyCode() - 65536) == vkvm::KeyCode::C) {
|
|
drawRender.graphicsUpdate(CIRCLE);
|
|
vkvm::callEvent(vkvm::EventType::Redraw);
|
|
}
|
|
|
|
else if((drawRender.getKeyCode() - 65536) == vkvm::KeyCode::R) {
|
|
drawRender.graphicsUpdate(RECTANGLE);
|
|
vkvm::callEvent(vkvm::EventType::Redraw);
|
|
}
|
|
}
|
|
});
|
|
|
|
vkvm::registerEvent(vkvm::EventType::MouseLeftDown, [&drawRender]() {
|
|
if(drawRender.getMouseDown() == false) {
|
|
drawRender.setMouseDown(true);
|
|
|
|
vkvm::Coordinates mousePosition = vkvm::getMousePosition();
|
|
mousePosition.y = mousePosition.y - 30;
|
|
drawRender.setMouseLeftDownPostion(mousePosition);
|
|
}
|
|
|
|
if((drawRender.getTurnOnBrush() == false) && ((drawRender.getKeyCode() - 65536) == vkvm::KeyCode::B)) {
|
|
drawRender.setTurnOnBrush(true);
|
|
}
|
|
});
|
|
|
|
vkvm::registerEvent(vkvm::EventType::MouseLeftUp, [&drawRender]() {
|
|
drawRender.setTurnOnBrush(false);
|
|
drawRender.setMouseDown(false);
|
|
drawRender.setPainting(false);
|
|
});
|
|
|
|
vkvm::registerEvent(vkvm::EventType::KeyDown, [&drawRender]() {
|
|
drawRender.setKeyCode(vkvm::getLastPressedKey());
|
|
|
|
if((drawRender.getKeyCode() - 65536) == vkvm::KeyCode::D) {
|
|
drawRender.clear();
|
|
vkvm::callEvent(vkvm::EventType::Redraw);
|
|
}
|
|
});
|
|
|
|
vkvm::registerEvent(vkvm::EventType::KeyUp, [&drawRender]() {
|
|
drawRender.setKeyCode(vkvm::getLastPressedKey());
|
|
|
|
if((drawRender.getKeyCode() - 65536) == vkvm::KeyCode::D) {
|
|
drawRender.clear();
|
|
vkvm::callEvent(vkvm::EventType::Redraw);
|
|
}
|
|
});
|
|
|
|
while(1){
|
|
sleep(5);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
/***************************read pixel in shared memory and test output in console******************************************/
|
|
void outPutPixel(int windowHeight, int windowWidth, vkvm::Color penColor) {
|
|
for(int y = 0; y < windowHeight; y++) {
|
|
for(int x = 0; x < windowWidth; x++) {
|
|
if(vkvm::getPixel(x, y).getRed() == penColor.getRed()) {
|
|
std::cout << "*";
|
|
} else {
|
|
std::cout << " ";
|
|
}
|
|
}
|
|
std::cout << "\n";
|
|
}
|
|
} |