2019-11-22 19:45:52 +01:00
|
|
|
#include <iostream>
|
|
|
|
#include "internal.hpp"
|
|
|
|
#include "vkvm.hpp"
|
2019-11-27 16:03:56 +01:00
|
|
|
#include "../src/DrawRender.hpp"
|
|
|
|
#include <unistd.h>
|
2019-11-22 19:45:52 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author: Shaohua Tong
|
2019-11-27 16:03:56 +01:00
|
|
|
* @since: v0.0.1
|
2019-11-29 17:54:09 +01:00
|
|
|
* draw circle, square, rectangle and mouse drawing
|
2019-11-22 19:45:52 +01:00
|
|
|
*/
|
|
|
|
void outPutPixel(int windowHeight, int windowWidth, vkvm::Color brushColor);
|
2019-10-16 16:38:35 +02:00
|
|
|
|
|
|
|
int main() {
|
2019-11-22 19:45:52 +01:00
|
|
|
vkvm::initialize(0);
|
|
|
|
|
2019-11-29 17:54:09 +01:00
|
|
|
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]() {
|
2019-12-09 14:32:30 +01:00
|
|
|
vkvm::Coordinates mousePosition = vkvm::getMousePosition();
|
|
|
|
mousePosition.y = mousePosition.y - 30;
|
|
|
|
drawRender.setMousePostion(mousePosition);
|
2019-11-29 17:54:09 +01:00
|
|
|
|
2019-12-09 14:32:30 +01:00
|
|
|
drawRender.graphicsUpdate(CURSOR);
|
|
|
|
vkvm::callEvent(vkvm::EventType::Redraw);
|
2019-11-29 17:54:09 +01:00
|
|
|
|
2019-12-09 14:32:30 +01:00
|
|
|
if(drawRender.getMouseDown()) {
|
|
|
|
if (drawRender.getTurnOnBrush()) {
|
|
|
|
drawRender.graphicsUpdate(BRUSH);
|
2019-11-29 17:54:09 +01:00
|
|
|
vkvm::callEvent(vkvm::EventType::Redraw);
|
|
|
|
}
|
|
|
|
|
2019-12-18 12:18:35 +01:00
|
|
|
if((drawRender.getKeyCode()) == vkvm::KeyCode::C) {
|
2019-11-29 17:54:09 +01:00
|
|
|
drawRender.graphicsUpdate(CIRCLE);
|
|
|
|
vkvm::callEvent(vkvm::EventType::Redraw);
|
|
|
|
}
|
|
|
|
|
2019-12-18 12:18:35 +01:00
|
|
|
else if((drawRender.getKeyCode()) == vkvm::KeyCode::R) {
|
2019-11-29 17:54:09 +01:00
|
|
|
drawRender.graphicsUpdate(RECTANGLE);
|
|
|
|
vkvm::callEvent(vkvm::EventType::Redraw);
|
|
|
|
}
|
|
|
|
}
|
2019-11-27 16:03:56 +01:00
|
|
|
});
|
|
|
|
|
2019-11-29 17:54:09 +01:00
|
|
|
vkvm::registerEvent(vkvm::EventType::MouseLeftDown, [&drawRender]() {
|
2019-12-09 14:32:30 +01:00
|
|
|
drawRender.setFinish(false);
|
|
|
|
|
|
|
|
if(!drawRender.getMouseDown()) {
|
2019-11-29 17:54:09 +01:00
|
|
|
drawRender.setMouseDown(true);
|
|
|
|
|
|
|
|
vkvm::Coordinates mousePosition = vkvm::getMousePosition();
|
|
|
|
mousePosition.y = mousePosition.y - 30;
|
|
|
|
drawRender.setMouseLeftDownPostion(mousePosition);
|
|
|
|
}
|
|
|
|
|
2019-12-09 14:32:30 +01:00
|
|
|
if((!drawRender.getTurnOnBrush()) && ((drawRender.getKeyCode() - 65536) == vkvm::KeyCode::B)) {
|
2019-11-29 17:54:09 +01:00
|
|
|
drawRender.setTurnOnBrush(true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
vkvm::registerEvent(vkvm::EventType::MouseLeftUp, [&drawRender]() {
|
2019-12-09 14:32:30 +01:00
|
|
|
drawRender.setFinish(true);
|
|
|
|
|
|
|
|
vkvm::Coordinates mousePosition = vkvm::getMousePosition();
|
|
|
|
mousePosition.y = mousePosition.y - 30;
|
|
|
|
drawRender.setMousePostion(mousePosition);
|
|
|
|
|
2019-12-18 12:18:35 +01:00
|
|
|
if(((drawRender.getKeyCode()) == vkvm::KeyCode::C) && drawRender.getPainting()) {
|
2019-12-09 14:32:30 +01:00
|
|
|
drawRender.graphicsUpdate(CIRCLE);
|
|
|
|
vkvm::callEvent(vkvm::EventType::Redraw);
|
|
|
|
}
|
|
|
|
|
2019-12-18 12:18:35 +01:00
|
|
|
else if(((drawRender.getKeyCode()) == vkvm::KeyCode::R) && drawRender.getPainting()) {
|
2019-12-09 14:32:30 +01:00
|
|
|
drawRender.graphicsUpdate(RECTANGLE);
|
|
|
|
vkvm::callEvent(vkvm::EventType::Redraw);
|
|
|
|
}
|
|
|
|
|
2019-11-29 17:54:09 +01:00
|
|
|
drawRender.setTurnOnBrush(false);
|
|
|
|
drawRender.setMouseDown(false);
|
|
|
|
drawRender.setPainting(false);
|
2019-12-09 14:32:30 +01:00
|
|
|
|
|
|
|
|
2019-11-29 17:54:09 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
vkvm::registerEvent(vkvm::EventType::KeyDown, [&drawRender]() {
|
|
|
|
drawRender.setKeyCode(vkvm::getLastPressedKey());
|
|
|
|
|
2019-12-18 12:18:35 +01:00
|
|
|
if((drawRender.getKeyCode()) == vkvm::KeyCode::D) {
|
2019-11-29 17:54:09 +01:00
|
|
|
drawRender.clear();
|
|
|
|
vkvm::callEvent(vkvm::EventType::Redraw);
|
|
|
|
}
|
2019-12-09 14:32:30 +01:00
|
|
|
|
2019-12-18 12:18:35 +01:00
|
|
|
else if((drawRender.getKeyCode()) == vkvm::KeyCode::Q) {
|
2019-12-09 14:32:30 +01:00
|
|
|
drawRender.graphicsUpdate(SHAPE);
|
|
|
|
vkvm::callEvent(vkvm::EventType::Redraw);
|
|
|
|
}
|
2019-11-29 17:54:09 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
vkvm::registerEvent(vkvm::EventType::KeyUp, [&drawRender]() {
|
|
|
|
drawRender.setKeyCode(vkvm::getLastPressedKey());
|
|
|
|
|
2019-12-18 12:18:35 +01:00
|
|
|
if((drawRender.getKeyCode()) == vkvm::KeyCode::D) {
|
2019-11-29 17:54:09 +01:00
|
|
|
drawRender.clear();
|
|
|
|
vkvm::callEvent(vkvm::EventType::Redraw);
|
|
|
|
}
|
2019-11-27 16:03:56 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
while(1){
|
|
|
|
sleep(5);
|
2019-11-22 19:45:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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";
|
|
|
|
}
|
2019-11-29 17:54:09 +01:00
|
|
|
}
|