diff --git a/CMakeLists.txt b/CMakeLists.txt index 2e26241..0d3419f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,7 +26,7 @@ include_directories(lib/toml) set(LIB_PATH "${CMAKE_SOURCE_DIR}/../library") include_directories(${LIB_PATH}/include) -add_executable(Terminal ${SOURCES} ${HEADERS} main/main.cpp src/Terminal.h src/Terminal.cpp src/Bitmap.cpp src/Bitmap.h src/Font.cpp src/Font.h) +add_executable(Terminal ${SOURCES} ${HEADERS} main/main.cpp src/Terminal.h src/Terminal.cpp) target_link_libraries(Terminal ${LIB_PATH}/lib/liblibrary.a) diff --git a/src/Bitmap.cpp b/src/Bitmap.cpp deleted file mode 100644 index a264e50..0000000 --- a/src/Bitmap.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#include "Bitmap.h" -#include -#include - -Bitmap::Bitmap() { - offset = 0; - width = 0; - height = 0; - bpp = 0; -} - -Bitmap::Bitmap(const std::string &file) { - offset = 0; - width = 0; - height = 0; - bpp = 0; - load(file); -} - -void Bitmap::load(const std::string &file) { - std::ifstream stream; - stream.open(file); - if(stream.is_open()){ - std::string str((std::istreambuf_iterator(stream)),std::istreambuf_iterator()); - data.resize(str.size()); - 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]); - } -} - -int Bitmap::getWidth() { - return width; -} - -int Bitmap::getHeight() { - return height; -} - -char *Bitmap::getData() { - return &data[offset]; -} - -int Bitmap::getBitsPerPixel() { - return bpp; -} - -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]; - } - if(pixel != 0){ - return pixel; - } - return pixel; -} diff --git a/src/Bitmap.h b/src/Bitmap.h deleted file mode 100644 index e1b61a9..0000000 --- a/src/Bitmap.h +++ /dev/null @@ -1,67 +0,0 @@ -#ifndef TERMINAL_BITMAP_H -#define TERMINAL_BITMAP_H - -#include -#include - -/** - * @author: Julian Hinxlage - * @since: v0.0.0 - * @brief: Used to load a Bitmap from a file. - */ -class Bitmap { -public: - Bitmap(); - explicit Bitmap(const std::string &file); - - /** - * @author: Julian Hinxlage - * @since: v0.0.0 - * @brief: Used to load a Bitmap from a file. - */ - void load(const std::string &file); - - /** - * @author: Julian Hinxlage - * @since: v0.0.0 - * @return: the width of the image. - */ - int getWidth(); - - /** - * @author: Julian Hinxlage - * @since: v0.0.0 - * @return: the height of the image - */ - int getHeight(); - - /** - * @author: Julian Hinxlage - * @since: v0.0.0 - * @return: the pixel data as an byte array - */ - char *getData(); - - /** - * @author: Julian Hinxlage - * @since: v0.0.0 - * @return: the number of bits uses per pixel - */ - int getBitsPerPixel(); - - /** - * @author: Julian Hinxlage - * @since: v0.0.0 - * @return: the pixel value by coordinates, (0,0) is on the top left - */ - unsigned int getPixel(int x, int y); - -private: - int width; - int height; - int offset; - int bpp; - std::vector data; -}; - -#endif //TERMINAL_BITMAP_H diff --git a/src/Font.cpp b/src/Font.cpp deleted file mode 100644 index e9cb8ea..0000000 --- a/src/Font.cpp +++ /dev/null @@ -1,79 +0,0 @@ -#include "Font.h" -#include - - -Font::Font() { - xOffset = 0; - yOffset = 0; - xSize = 0; - ySize = 0; - xCount = 0; - yCount = 0; - xStart = 0; - yStart = 0; - fillValue = 0; - firstChar = ' '; -} - -Font::Font(const std::string &file, const std::string &configFile) : Font() { - load(file, configFile); -} - -void Font::load(const std::string &file, const std::string &configFile) { - bitmap.load(file); - auto config = cpptoml::parse_file(configFile); - xOffset = config->get_as("xOffset").value_or(0); - yOffset = config->get_as("yOffset").value_or(0); - xSize = config->get_as("xSize").value_or(0); - ySize = config->get_as("ySize").value_or(0); - xCount = config->get_as("xCount").value_or(0); - yCount = config->get_as("yOffset").value_or(0); - xStart = config->get_as("xStart").value_or(0); - yStart = config->get_as("yStart").value_or(0); - fillValue = config->get_as("fillValue").value_or(0); - firstChar = (char)config->get_as("firstChar").value_or(0); - pixelSize = config->get_as("pixelSize").value_or(0); - gap = config->get_as("gap").value_or(-1); - invertedColors = config->get_as("invertedColors").value_or(0); -} - -int Font::width() { - return xSize; -} - -int Font::height() { - return ySize; -} - -bool Font::getPixel(char character, int x, int y) { - //index of character(x and y) - int index = (character - firstChar); - - if(gap != -1){ - if (index >= gap){ - index++; - } - } - - int xIndex = index % xCount; - int yIndex = index / xCount; - - if(index < 0){ - yIndex--; - xIndex += xCount; - } - - //character index to pixel index conversion - int xPos = xIndex * (xSize + xOffset) + xStart; - int yPos = yIndex * (ySize + yOffset) + yStart; - - bool value = bitmap.getPixel((xPos + x) * pixelSize, (yPos + y) * pixelSize) == fillValue; - if(invertedColors){ - return !value; - }else{ - return value; - } -} - - - diff --git a/src/Font.h b/src/Font.h deleted file mode 100644 index 8274834..0000000 --- a/src/Font.h +++ /dev/null @@ -1,51 +0,0 @@ -// -// Created by yukun on 05.12.19. -// - -#ifndef TERMINAL_FONT_H -#define TERMINAL_FONT_H -#include "Bitmap.h" - -/** - * @author: Julian Hinxlage - * @since: v0.0.0 - * @brief: this class provides pixel access based on characters - */ -class Font { -public: - Bitmap bitmap; - - //space between characters - int xOffset; - int yOffset; - - //size of a character - int xSize; - int ySize; - - //count of characters per row - int xCount; - //count of rows - int yCount; - - //pixel offset of first character - int xStart; - int yStart; - - unsigned int fillValue; - char firstChar; - int pixelSize; - int gap; - - bool invertedColors; - - Font(); - explicit Font(const std::string &file, const std::string &configFile); - void load(const std::string &file, const std::string &configFile); - - int width(); - int height(); - bool getPixel(char character, int x, int y); -}; - -#endif //TERMINAL_FONT_H