~ fix code to reduce warnings
This commit is contained in:
parent
2286c59325
commit
a8914cb357
0
.ci/clang-tidy.sh
Normal file → Executable file
0
.ci/clang-tidy.sh
Normal file → Executable file
@ -1,10 +1,10 @@
|
||||
#include "Bitmap.h"
|
||||
#include "Font.h"
|
||||
#include "TextRenderer.h"
|
||||
#include "internal.hpp"
|
||||
#include "../src/Bitmap.h"
|
||||
#include "../src/Font.h"
|
||||
#include "../src/TextRenderer.h"
|
||||
#include <internal.hpp>
|
||||
#include <iostream>
|
||||
|
||||
bool isQuit(std::string command);
|
||||
bool isQuit(const std::string& command);
|
||||
|
||||
/**
|
||||
* @author: Julian Hinxlage
|
||||
@ -37,14 +37,17 @@ int main() {
|
||||
std::string command;
|
||||
std::cout << "TextRender: ";
|
||||
std::getline(std::cin, command);
|
||||
while (!isQuit(command)) {
|
||||
while (command != "quit") {
|
||||
if (command == "clear") {
|
||||
textRenderer.clear();
|
||||
} if (command == "redblue") {
|
||||
vkvm::setBackgroundColor(vkvm::red);
|
||||
vkvm::setForegroundColor(vkvm::blue);
|
||||
} else {
|
||||
vkvm::setText(command);
|
||||
currentText = vkvm::getText();
|
||||
textRenderer.update(currentText);
|
||||
}
|
||||
|
||||
vkvm::setText(command);
|
||||
currentText = vkvm::getText();
|
||||
textRenderer.update(currentText);
|
||||
std::cout << "TextRender: ";
|
||||
std::getline(std::cin, command);
|
||||
|
||||
@ -54,29 +57,4 @@ int main() {
|
||||
std::cout << "TextRender finished." << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// std::string str;
|
||||
// std::cout << "string to draw: ";
|
||||
// std::getline(std::cin, str);
|
||||
//
|
||||
// for (int i = 0; i < font.height(); i++) {
|
||||
// for (char c : str) {
|
||||
// for (int j = 0; j < font.width(); j++) {
|
||||
// if (font.getPixel(c,j,i)) {
|
||||
// std::cout << "█";
|
||||
// } else {
|
||||
// std::cout << " ";
|
||||
// }
|
||||
// }
|
||||
// std::cout << " ";
|
||||
// }
|
||||
// std::cout << std::endl;
|
||||
// }
|
||||
//
|
||||
// return 0;
|
||||
|
||||
bool isQuit(std::string command) {
|
||||
return command.compare("quit") == 0;
|
||||
}
|
||||
}
|
@ -26,11 +26,10 @@ void Bitmap::load(const std::string &file) {
|
||||
for(int i = 0; i < str.size();i++){
|
||||
data[i] = str[i];
|
||||
}
|
||||
|
||||
offset = (int)*(unsigned int*)(&data[10]);
|
||||
width = (int)*(unsigned int*)(&data[18]);
|
||||
height = (int)*(unsigned int*)(&data[22]);
|
||||
bpp = (int)*(unsigned short*)(&data[28]);
|
||||
offset = *reinterpret_cast<int*>(&data[10]);
|
||||
width = *reinterpret_cast<int*>(&data[18]);
|
||||
height = *reinterpret_cast<int*>(&data[22]);
|
||||
bpp = *reinterpret_cast<uint16_t *>(&data[28]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -54,7 +53,8 @@ unsigned int Bitmap::getPixel(int x, int y) {
|
||||
unsigned int pixel = 0;
|
||||
char *ptr = getData() + ((getHeight() - 1 - y) * getWidth() + x) * (getBitsPerPixel() / 8);
|
||||
for(int i = 0; i < getBitsPerPixel() / 8;i++){
|
||||
*((char*)&pixel+i) = ptr[i];
|
||||
auto value = reinterpret_cast<char*>(&pixel+i);
|
||||
*value = ptr[i];
|
||||
}
|
||||
if(pixel != 0){
|
||||
return pixel;
|
||||
|
12
src/Font.cpp
12
src/Font.cpp
@ -3,7 +3,7 @@
|
||||
//
|
||||
|
||||
#include "Font.h"
|
||||
#include <cpptoml.h>
|
||||
#include "../lib/toml/cpptoml.h"
|
||||
|
||||
Font::Font() {
|
||||
xOffset = 0;
|
||||
@ -34,10 +34,10 @@ void Font::load(const std::string &file, const std::string &configFile) {
|
||||
xStart = config->get_as<int>("xStart").value_or(0);
|
||||
yStart = config->get_as<int>("yStart").value_or(0);
|
||||
fillValue = config->get_as<unsigned int>("fillValue").value_or(0);
|
||||
firstChar = (char)config->get_as<int>("firstChar").value_or(0);
|
||||
firstChar = config->get_as<char>("firstChar").value_or(0);
|
||||
pixelSize = config->get_as<int>("pixelSize").value_or(0);
|
||||
gap = config->get_as<int>("gap").value_or(-1);
|
||||
invertedColors = config->get_as<int>("invertedColors").value_or(0);
|
||||
invertedColors = config->get_as<bool>("invertedColors").value_or(0);
|
||||
}
|
||||
|
||||
int Font::width() {
|
||||
@ -71,10 +71,6 @@ bool Font::getPixel(char character, int x, int y) {
|
||||
int yPos = yIndex * (ySize + yOffset) + yStart;
|
||||
|
||||
bool value = bitmap.getPixel((xPos + x) * pixelSize, (yPos + y) * pixelSize) == fillValue;
|
||||
if(invertedColors){
|
||||
return !value;
|
||||
}else{
|
||||
return value;
|
||||
}
|
||||
return invertedColors != value;
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @brief: this class provides pixel access based on characters
|
||||
*/
|
||||
class Font {
|
||||
public:
|
||||
private:
|
||||
Bitmap bitmap;
|
||||
|
||||
//space between characters
|
||||
@ -40,6 +40,8 @@ public:
|
||||
|
||||
bool invertedColors;
|
||||
|
||||
public:
|
||||
|
||||
Font();
|
||||
explicit Font(const std::string &file, const std::string &configFile);
|
||||
void load(const std::string &file, const std::string &configFile);
|
||||
|
@ -3,18 +3,20 @@
|
||||
//
|
||||
#include "TextRenderer.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
TextRenderer::TextRenderer() {}
|
||||
|
||||
TextRenderer::TextRenderer() = default;
|
||||
|
||||
|
||||
void TextRenderer::update(std::string newText) {
|
||||
int startX = 0;
|
||||
int startY = 0;
|
||||
int i;
|
||||
std::string fontResourcePath = "../res/font" + std::to_string(vkvm::getFont().getId()) + ".bmp";
|
||||
std::string fontConfigureFilePath = "../res/font" + std::to_string(vkvm::getFont().getId()) + ".toml";
|
||||
std::string fontResourcePath = "../res/font" + std::to_string(vkvm::getFont()) + ".bmp";
|
||||
std::string fontConfigureFilePath = "../res/font" + std::to_string(vkvm::getFont()) + ".toml";
|
||||
font = Font(fontResourcePath, fontConfigureFilePath);
|
||||
int fontNumbersInOneLine = vkvm::getWidth() / (vkvm::getFont().getWidth() + left_margin);
|
||||
int fontNumbersInOneLine = vkvm::getWidth() / (font.width() + left_margin);
|
||||
std::vector<std::vector<bool>> characterBitmap;
|
||||
|
||||
for(i = 0; i < newText.size(); i++) {
|
||||
@ -31,7 +33,8 @@ void TextRenderer::update(std::string newText) {
|
||||
}
|
||||
|
||||
void TextRenderer::clear() {
|
||||
int x, y;
|
||||
int x;
|
||||
int y;
|
||||
for(y = 0; y < vkvm::getHeight(); y++) {
|
||||
for(x = 0; x < vkvm::getWidth(); x++) {
|
||||
vkvm::setPixel(x, y, vkvm::getBackgroundColor());
|
||||
@ -40,7 +43,7 @@ void TextRenderer::clear() {
|
||||
}
|
||||
|
||||
void TextRenderer::setOldText(std::string text) {
|
||||
oldText = text;
|
||||
oldText = std::move(text);
|
||||
}
|
||||
|
||||
std::vector<std::vector<bool>> TextRenderer::getCharacter(unsigned char character) {
|
||||
@ -62,7 +65,8 @@ std::vector<std::vector<bool>> TextRenderer::getCharacter(unsigned char characte
|
||||
}
|
||||
|
||||
void TextRenderer::translateToSharedMemory(std::vector<std::vector<bool>> characterBitmap, int startX, int startY) {
|
||||
int x, y;
|
||||
int x;
|
||||
int y;
|
||||
int currentX = startX;
|
||||
int currentY = startY;
|
||||
|
||||
|
@ -5,15 +5,11 @@
|
||||
#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 "Font.h"
|
||||
#include <Color.hpp>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vkvm.hpp>
|
||||
|
||||
/**
|
||||
* @author: Yajie Qi, Shaohua Tong
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "../src/Bitmap.h"
|
||||
#include "../src/Font.h"
|
||||
#include <catch2/catch.hpp>
|
||||
#include "Bitmap.h"
|
||||
#include "Font.h"
|
||||
|
||||
TEST_CASE("default values") {
|
||||
Bitmap bitmap = Bitmap();
|
||||
@ -20,7 +20,7 @@ TEST_CASE("Font") {
|
||||
Font font("../res/font1.bmp", "../res/font1.toml");
|
||||
REQUIRE(font.width() == 5);
|
||||
REQUIRE(font.height() == 7);
|
||||
REQUIRE(!font.getPixel('a', 1,1));
|
||||
REQUIRE_FALSE(font.getPixel('a', 1,1));
|
||||
REQUIRE(font.getPixel('a', 1,2));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user