simple-draw/main/main.cpp

75 lines
2.6 KiB
C++

#include <iostream>
#include "../src/demo.h"
#include "internal.hpp"
#include "vkvm.hpp"
#include "../src/DrawRender.h"
/**
* @author: Shaohua Tong
* @since: v0.0.0
* A circle and squre is converted and displayed in the console.
* Currently only to test.
*/
void outPutPixel(int windowHeight, int windowWidth, vkvm::Color brushColor);
int main() {
vkvm::initialize(0);
/*************************set back to shared memory(only for test)********************************************/
int windowWidth = 30;
int windowHeight = 30;
int penWidth = 2;
vkvm::setWidth(windowWidth);
vkvm::setHeight(windowHeight);
//vkvm::setPenWIdth(penWidth); maybe
vkvm::Color penColor1(1, 1, 1);
vkvm::Color backgroudColor1(255, 255, 255);
vkvm::setForegroundColor(penColor1);
vkvm::setBackgroundColor(backgroudColor1);
/**************************get color, widnowsWidth, windowsHeightm, penColor, penWidth from shared memory****************************/
vkvm::Color penColor = vkvm::getForegroundColor();
vkvm::Color backgroundColor = vkvm::getBackgroundColor();
DrawRender drawRender(windowWidth, windowHeight, backgroundColor, penColor, penWidth);
/*************************get Mouseposition and update back to shared meomory********************************************/
std::string command;
std::cout << "DrawRender: ";
std::getline(std::cin, command);
//vkvm::getMousePosition();
vkvm::Coordinates mousePostiion;
mousePostiion.x = 15;
mousePostiion.y = 15;
while(command.compare("quit") != 0) {
if(command.compare("circle") == 0) {
drawRender.update(mousePostiion, CIRCLE);
outPutPixel(windowHeight, windowWidth, penColor);
}
if(command.compare("square") == 0) {
drawRender.update(mousePostiion, SQUARE);
outPutPixel(windowHeight, windowWidth, penColor);
}
if(command.compare("clear")) {
drawRender.clear();
}
std::cout << "DrawRender: ";
std::getline(std::cin, command);
}
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";
}
}