114 lines
3.5 KiB
C++
114 lines
3.5 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
|
|
*/
|
|
|
|
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]() {
|
|
vkvm::Coordinates mousePosition = vkvm::getMousePosition();
|
|
mousePosition.y = mousePosition.y - 30;
|
|
drawRender.setMousePostion(mousePosition);
|
|
|
|
drawRender.graphicsUpdate(CURSOR);
|
|
vkvm::callEvent(vkvm::EventType::Redraw);
|
|
|
|
if(drawRender.getMouseDown()) {
|
|
if (drawRender.getTurnOnBrush()) {
|
|
drawRender.graphicsUpdate(BRUSH);
|
|
vkvm::callEvent(vkvm::EventType::Redraw);
|
|
}
|
|
|
|
if((drawRender.getKeyCode()) == vkvm::KeyCode::C) {
|
|
drawRender.graphicsUpdate(CIRCLE);
|
|
vkvm::callEvent(vkvm::EventType::Redraw);
|
|
}
|
|
|
|
else if((drawRender.getKeyCode()) == vkvm::KeyCode::R) {
|
|
drawRender.graphicsUpdate(RECTANGLE);
|
|
vkvm::callEvent(vkvm::EventType::Redraw);
|
|
}
|
|
}
|
|
});
|
|
|
|
vkvm::registerEvent(vkvm::EventType::MouseLeftDown, [&drawRender]() {
|
|
drawRender.setFinish(false);
|
|
|
|
if(!drawRender.getMouseDown()) {
|
|
drawRender.setMouseDown(true);
|
|
|
|
vkvm::Coordinates mousePosition = vkvm::getMousePosition();
|
|
mousePosition.y = mousePosition.y - 30;
|
|
drawRender.setMouseLeftDownPostion(mousePosition);
|
|
}
|
|
|
|
if((!drawRender.getTurnOnBrush()) && ((drawRender.getKeyCode() - 65536) == vkvm::KeyCode::B)) {
|
|
drawRender.setTurnOnBrush(true);
|
|
}
|
|
});
|
|
|
|
vkvm::registerEvent(vkvm::EventType::MouseLeftUp, [&drawRender]() {
|
|
drawRender.setFinish(true);
|
|
|
|
vkvm::Coordinates mousePosition = vkvm::getMousePosition();
|
|
mousePosition.y = mousePosition.y - 30;
|
|
drawRender.setMousePostion(mousePosition);
|
|
|
|
if(((drawRender.getKeyCode()) == vkvm::KeyCode::C) && drawRender.getPainting()) {
|
|
drawRender.graphicsUpdate(CIRCLE);
|
|
vkvm::callEvent(vkvm::EventType::Redraw);
|
|
}
|
|
|
|
else if(((drawRender.getKeyCode()) == vkvm::KeyCode::R) && drawRender.getPainting()) {
|
|
drawRender.graphicsUpdate(RECTANGLE);
|
|
vkvm::callEvent(vkvm::EventType::Redraw);
|
|
}
|
|
|
|
drawRender.setTurnOnBrush(false);
|
|
drawRender.setMouseDown(false);
|
|
drawRender.setPainting(false);
|
|
|
|
|
|
});
|
|
|
|
vkvm::registerEvent(vkvm::EventType::KeyDown, [&drawRender]() {
|
|
drawRender.setKeyCode(vkvm::getLastPressedKey());
|
|
|
|
if((drawRender.getKeyCode()) == vkvm::KeyCode::D) {
|
|
drawRender.clear();
|
|
vkvm::callEvent(vkvm::EventType::Redraw);
|
|
}
|
|
|
|
else if((drawRender.getKeyCode()) == vkvm::KeyCode::Q) {
|
|
drawRender.graphicsUpdate(SHAPE);
|
|
vkvm::callEvent(vkvm::EventType::Redraw);
|
|
}
|
|
});
|
|
|
|
vkvm::registerEvent(vkvm::EventType::KeyUp, [&drawRender]() {
|
|
drawRender.setKeyCode(vkvm::getLastPressedKey());
|
|
|
|
if((drawRender.getKeyCode()) == vkvm::KeyCode::D) {
|
|
drawRender.clear();
|
|
vkvm::callEvent(vkvm::EventType::Redraw);
|
|
}
|
|
});
|
|
|
|
while(1){
|
|
sleep(5);
|
|
}
|
|
|
|
return 0;
|
|
} |