Skip to content

Commit 66bf021

Browse files
Dynamic grid function set
1 parent 1d7a164 commit 66bf021

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

Fonts/fonts.h

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,19 @@
99

1010
class Fonts
1111
{
12+
int def_rows;
13+
int def_cols;
1214
int char_rows;
1315
int char_cols;
1416
int curr_col;
15-
std::vector<std::vector<char> > letters;
17+
std::vector<std::vector<char>> letters;
1618

1719
protected:
18-
char **getCharGrid()
20+
char **getCharGrid(int rows = 0, int cols = 0)
1921
{
22+
this->char_rows = rows ? rows : def_rows;
23+
this->char_cols = cols ? cols : def_cols;
24+
2025
char **char_grid = new char *[char_rows];
2126
for (int i = 0; i < char_rows; i++)
2227
{
@@ -28,13 +33,13 @@ class Fonts
2833
}
2934

3035
public:
31-
Fonts(int char_rows, int char_cols)
36+
Fonts(int def_rows, int def_cols)
3237
{
33-
this->char_rows = char_rows;
34-
this->char_cols = char_cols;
38+
this->def_rows = def_rows;
39+
this->def_cols = def_cols;
3540

36-
letters.reserve(char_rows);
37-
for (int i = 0; i < char_rows; i++)
41+
letters.reserve(def_rows);
42+
for (int i = 0; i < def_rows; i++)
3843
{
3944
letters.emplace_back(100, ' '); // Create rows with 100 spaces each
4045
}
@@ -45,6 +50,12 @@ class Fonts
4550
{
4651
if (!character)
4752
return;
53+
54+
while (letters.size() < char_rows)
55+
{
56+
letters.emplace_back(100, ' ');
57+
}
58+
4859
for (int i = 0; i < char_rows; i++)
4960
{
5061
for (int j = 0; j < char_cols; j++)
@@ -55,7 +66,7 @@ class Fonts
5566
curr_col += (char_cols + 2);
5667
}
5768

58-
std::vector<std::vector<char> > getletters()
69+
std::vector<std::vector<char>> getletters()
5970
{
6071
return letters;
6172
}

example.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ using namespace ascii;
66
int main()
77
{
88
Ascii a = Ascii(banner);
9-
a.print("w");
9+
a.print("wA");
1010
return 0;
1111
}

0 commit comments

Comments
 (0)