add Bold and underline in TextRenderer
This commit is contained in:
parent
c719c8f655
commit
ab2d13f6bb
|
@ -19,18 +19,31 @@ bool isQuit(std::string command);
|
|||
int main() {
|
||||
vkvm::initialize(0);
|
||||
|
||||
Font font("../res/font1.bmp", "../res/font1.toml");
|
||||
|
||||
std::string oldText;
|
||||
std::string currentText;
|
||||
TextRenderer textRenderer(vkvm::Color(255, 255, 255), vkvm::Color(0, 0, 0));
|
||||
|
||||
|
||||
/*************************set back to shared memory(only for test)********************************************/
|
||||
vkvm::Color fontColor1(0, 0, 0);
|
||||
vkvm::Color backgroudColor1(255, 255, 255);
|
||||
Font font1("../res/font3.bmp", "../res/font3.toml");
|
||||
vkvm::setFont(vkvm::FontType(3, "font", font1.height(), font1.width()));
|
||||
vkvm::setForegroundColor(fontColor1);
|
||||
vkvm::setBackgroundColor(backgroudColor1);
|
||||
/**************************get text and font from shared memory*******************************************/
|
||||
std::string fontResourcePath = "../res/font" + std::to_string(vkvm::getFont().getId()) + ".bmp";
|
||||
std::string fontConfigureFilePath = "../res/font" + std::to_string(vkvm::getFont().getId()) + ".toml";
|
||||
Font font = Font(fontResourcePath, fontConfigureFilePath);
|
||||
TextRenderer textRenderer(vkvm::Color(255, 255, 255), vkvm::Color(0, 0, 0). font);
|
||||
vkvm::Color fontColor = vkvm::getForegroundColor();
|
||||
vkvm::Color backgroundColor = vkvm::getBackgroundColor();
|
||||
/*********************************************************************/
|
||||
|
||||
std::string command;
|
||||
|
||||
std::cout << "TextRender: " << std::endl;
|
||||
std::getline(std::cin, command);
|
||||
while(!isQuit(command)) {
|
||||
if(command.compare("update")) {
|
||||
vkvm::setText("Hello World.");
|
||||
currentText = vkvm::getText();
|
||||
textRenderer.update(currentText);
|
||||
}
|
||||
|
|
BIN
res/font3.bmp
BIN
res/font3.bmp
Binary file not shown.
Before Width: | Height: | Size: 448 KiB |
|
@ -3,14 +3,14 @@
|
|||
//
|
||||
#include "TextRenderer.h"
|
||||
|
||||
TextRenderer::TextRenderer(vkvm::Color backgroundColor, vkvm::Color fontColor)
|
||||
: backgroundColor(backgroundColor), fontColor(fontColor) {
|
||||
TextRenderer::TextRenderer(vkvm::Color backgroundColor, vkvm::Color fontColor, Font font)
|
||||
: backgroundColor(backgroundColor), fontColor(fontColor), font(font) {
|
||||
windowWidth = vkvm::getWidth();
|
||||
fontWidth = font.width();
|
||||
fontHeight = font.height();
|
||||
}
|
||||
|
||||
void TextRenderer::update(std::string text) {
|
||||
void TextRenderer::update(std::string newText) {
|
||||
int startX;
|
||||
int startY;
|
||||
int i;
|
||||
|
@ -19,10 +19,6 @@ void TextRenderer::update(std::string text) {
|
|||
|
||||
std::cout << "get window's width from shared memery: (" << windowWidth << ")" << std::endl;
|
||||
|
||||
std::string newText = vkvm::getText();
|
||||
|
||||
std::cout << "get text:" << newText << std::endl;
|
||||
|
||||
for(i = 0; i < newText.size(); i++) {
|
||||
if(i > oldText.size() || oldText[i] != newText[i]) {
|
||||
startX = i % fontNumbersInOneLine * fontWidth;
|
||||
|
@ -32,6 +28,8 @@ void TextRenderer::update(std::string text) {
|
|||
translateToSharedMemory(characterBitmap, startX, startY);
|
||||
}
|
||||
}
|
||||
|
||||
oldText = newText;
|
||||
}
|
||||
|
||||
void TextRenderer::setOldText(std::string text) {
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
*/
|
||||
class TextRenderer {
|
||||
public:
|
||||
TextRenderer(vkvm::Color defaultBackgroundColor, vkvm::Color fontColor);
|
||||
TextRenderer(vkvm::Color defaultBackgroundColor, vkvm::Color fontColor, Font font);
|
||||
|
||||
void update(std::string text);
|
||||
void setOldText(std::string text);
|
||||
|
@ -33,7 +33,7 @@ private:
|
|||
vkvm::Color backgroundColor;
|
||||
vkvm::Color fontColor;
|
||||
vkvm::FontType fontType = vkvm::getFont();
|
||||
Font font = Font(fontType.getName(), "../res/font3.toml");
|
||||
Font font;
|
||||
int type;
|
||||
int windowWidth;
|
||||
int fontWidth;
|
||||
|
|
Loading…
Reference in New Issue