#include #include "internal.hpp" #include "vkvm.hpp" #include "../src/DrawRender.hpp" #include /** * @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]() { 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; } /***************************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"; } }