+ fillValue in Font

This commit is contained in:
Julian Hinxlage 2019-10-23 11:42:32 +02:00
parent 7da7d96b17
commit d95f142d0f
3 changed files with 10 additions and 10 deletions

View File

@ -16,18 +16,15 @@ int main() {
std::string str;
std::cout << "string to draw: ";
std::cin >> str;
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++) {
unsigned int pixel = font.getPixel(c,j,i);
if (pixel == 0) {
std::cout << " ";
if (font.getPixel(c,j,i)) {
std::cout << "";
} else {
std::cout << "1";
std::cout << " ";
}
}
std::cout << " ";

View File

@ -13,6 +13,7 @@ Font::Font() {
yCount = 4;
xStart = 1;
yStart = 2;
fillValue = 0xffffff;
}
Font::Font(const std::string &file) : Font() {
@ -31,7 +32,7 @@ int Font::height() {
return ySize;
}
unsigned int Font::getPixel(char character, int x, int y) {
bool Font::getPixel(char character, int x, int y) {
//index of character(x and y)
int index = (character - ' ');
int xIndex = index % xCount;
@ -41,6 +42,6 @@ unsigned int Font::getPixel(char character, int x, int y) {
int xPos = xIndex * (xSize + xOffset) + xStart;
int yPos = yIndex * (ySize + yOffset) + yStart;
return bitmap.getPixel(xPos + x, yPos + y);
return bitmap.getPixel(xPos + x, yPos + y) == fillValue;
}

View File

@ -28,13 +28,15 @@ public:
int xStart;
int yStart;
unsigned int fillValue;
Font();
explicit Font(const std::string &file);
void load(const std::string &file);
int width();
int height();
unsigned int getPixel(char character, int x, int y);
bool getPixel(char character, int x, int y);
};