simple-draw/main/main.cpp

57 lines
1.7 KiB
C++

#include <iostream>
#include "../src/demo.h"
#include "internal.hpp"
#include "vkvm.hpp"
#include "../src/DrawRender.hpp"
#include <unistd.h>
/**
* @author: Shaohua Tong
* @since: v0.0.1
* Circle and Square and Mouse brush can show in GUI
*/
void outPutPixel(int windowHeight, int windowWidth, vkvm::Color brushColor);
int main() {
vkvm::initialize(0);
vkvm::registerEvent(vkvm::EventType::MouseDrag, [](){
std::cout << "drag" << std::endl;
vkvm::Color backgroundColor = vkvm::getBackgroundColor();
vkvm::Color penColor(160,180,123);
int penWidth = 10;
DrawRender drawRender(vkvm::getWidth(), vkvm::getHeight(), backgroundColor, penColor, penWidth);
drawRender.update(vkvm::getMousePosition(), BRUSH);
});
vkvm::registerEvent(vkvm::EventType::MouseButton, [](){
vkvm::Color backgroundColor = vkvm::getBackgroundColor();
vkvm::Color penColor(160,180,123);
int penWidth = 10;
DrawRender drawRender(vkvm::getWidth(), vkvm::getHeight(), backgroundColor, penColor, penWidth);
drawRender.update(vkvm::getMousePosition(), CIRCLE);
});
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";
}
}