-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcore.h
More file actions
109 lines (89 loc) · 2.98 KB
/
core.h
File metadata and controls
109 lines (89 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#pragma once
#include "log.h"
#include <exception>
#include <stdexcept>
#include <sys/types.h>
#include <type_traits>
#include <vector>
#include <cstdio>
unsigned int getWidth();
void setWidth();
unsigned int getHeight();
void setHeight ();
bool getbPadding ();
void setbPadding ();
bool getbIsInitialized ();
void setbIsInitialized ();
class ScreenChar {
public:
char ch;
int foreColor, backColor;
ScreenChar (char chInp, int foreColorInp = 7, int backColorInp = 0) {
ch = chInp;
if (foreColorInp > 15 || foreColorInp < 0 || backColorInp > 15 || backColorInp < 0) {
logWarning("Color numbers are between 0 and 15.");
}
else {
if (foreColorInp<=7) {
foreColor = 30+foreColorInp;
}
else {
foreColor = 82+foreColorInp;
}
if (backColorInp<=7) {
backColor = 40+backColorInp;
}
else {
backColor = 92+backColorInp;
}
}
}
};
class Position {
public:
unsigned int x;
unsigned int y;
public:
Position (unsigned int xInp, unsigned int yInp) {
x = xInp;
y = yInp;
}
};
class Layer {
public:
std::vector<std::vector<ScreenChar>> layer;
Layer (ScreenChar charToFill) {
for (int y = 0; y < getHeight(); y++) { // goes through every x and y cell and adds it into the layer which is a 2D vector
std::vector<ScreenChar> row;
for (int x = 0; x < getWidth(); x++) {
row.push_back(charToFill);
}
layer.push_back(row);
}
}
void putCharAt (Position pos, ScreenChar sch) { // changes one character on a layer
try {
layer.at(pos.y).at(pos.x) = sch;
}
catch (const std::exception e) {
char* str;
std::snprintf(str, 1000, "Position with values x: %i y: %i is out of bound", pos.x, pos.y);
logError(str);
}
}
void drawLayer () {
for (int y = 0; y < getHeight(); y++) {
for (int x = 0; x < getWidth(); x++) {
ScreenChar* currentChar = &(layer.at(y).at(x));
if (getbPadding() && x != getWidth()-1) { printf("\033[%u;%um%c \033[0m", (*currentChar).backColor, (*currentChar).foreColor, (*currentChar).ch); }
else { printf("\033[%u;%um%c\033[0m", (*currentChar).backColor, (*currentChar).foreColor, (*currentChar).ch); }
}
printf("\n");
}
}
};
std::vector<Layer> getLayers ();
void setLayers (std::vector<Layer> inp);
void initialize (unsigned int widthInp, unsigned int heightInp, bool doPadding = false);
void drawAllLayers ();
void createLayer (ScreenChar sch);