Text-Renderer/src/TextRenderer.h

96 lines
2.4 KiB
C++

//
// Created by my on 2019/11/16.
//
#ifndef TEXTRENDERER_TEXTRENDERER_H
#define TEXTRENDERER_TEXTRENDERER_H
#define BOLD 0b001
#define ITALICS 0b010
#define UNDERLINE 0b100
#include <string>
#include <Color.hpp>
#include <vkvm.hpp>
#include <iostream>
#include <thread>
#include "Font.h"
/**
* @author: Yajie Qi, Shaohua Tong
* @since: v0.0.0
* @brief: gets a string from the Shared Memory and converts the text into a bitmap-array.
*/
class TextRenderer {
public:
// TextRenderer(int windowWidth, int windowHeight, vkvm::Color backgroundColor, vkvm::Color fontColor,
// Font font);
TextRenderer(int windowWidth, int windowHeight, vkvm::Color backGroundColor, vkvm::Color fontColor, vkvm::Color speicialFontColor,
Font font, int fontSize);
void update(std::string text);
void setOldText(std::string text);
std::vector<std::vector<bool>> getCharacter(unsigned char character, Font font);
void setLeftMargin(int margin);
void setBottomMargin(int margin);
void clear();
void clear(int startX, int startY, int endX, int endY);
void check();
void setWindowWidth(int windowWidth);
void setWindowHeight(int windowHeight);
int getWindowWidth();
int getWindowHeight();
void startBlinkThread();
std::thread blink_thread;
private:
// std::mutex mutex;
std::string oldText;
vkvm::Color backgroundColor;
vkvm::Color fontColor;
vkvm::Color speicialFontColor;
// Blink blink;
Font font;
char returnCharacter = '\n';
char specialCharacter = -127;
int fontSize = 1;
int left_margin = 1;
int bottom_margin = 1;
int type{};
int windowWidth;
int windowHeight;
int fontWidth;
int fontHeight;
int currentX;
int currentY;
int oldTextsize{};
int blinkX = 0;
int blinkY = 0;
bool isBold();
bool isItalics();
bool isUnderline();
void fontProcessing(std::vector<std::vector<bool>> characterBitmap);
void translateToSharedMemory(std::vector<std::vector<bool>> characterBitmap, int startX, int startY, vkvm::Color fontColor);
void checkWindowSize();
void blink1();
void checkFontColor();
void checkBackgroundColor();
void checkText();
// void setPixelRange(int startX, int startY, int endX, int endY, int type);
std::string adjustText(std::string newText);
std::string adjustText(std::string newText, int startLine, int endLine);
};
#endif //TEXTRENDERER_TEXTRENDERER_H