Flipped UI, minor changes

Flipped UI, removed extra Batch2D, added comments and minor changes
This commit is contained in:
MihailRis
2022-06-29 14:03:36 +03:00
committed by GitHub
parent c3b4357852
commit 88c1695903
7 changed files with 67 additions and 66 deletions
+6 -6
View File
@@ -74,13 +74,13 @@ void Batch2D::rect(float x, float y, float w, float h){
void Batch2D::rect(float x, float y, float w, float h,
float u, float v, float tx, float ty,
float r, float g, float b, float a){
vertex(x, y, u, v, r,g,b,a);
vertex(x+w, y+h, u+tx, v+ty, r,g,b,a);
vertex(x, y+h, u, v+ty, r,g,b,a);
vertex(x, y, u, v+ty, r,g,b,a);
vertex(x+w, y+h, u+tx, v, r,g,b,a);
vertex(x, y+h, u, v, r,g,b,a);
vertex(x, y, u, v, r,g,b,a);
vertex(x+w, y, u+tx, v, r,g,b,a);
vertex(x+w, y+h, u+tx, v+ty, r,g,b,a);
vertex(x, y, u, v+ty, r,g,b,a);
vertex(x+w, y, u+tx, v+ty, r,g,b,a);
vertex(x+w, y+h, u+tx, v, r,g,b,a);
}
void Batch2D::render() {
+16 -20
View File
@@ -9,15 +9,8 @@ Font::~Font(){
delete texture;
}
void Font::draw(Batch2D* batch, std::string text, int x, int y) {
for (char c : text){
float u = (c % 16) / 16.0f;
float v = 1.0f - ((c / 16) / 16.0f) - 1.0f/16.0f;
batch->rect(x, y, 8, 8, u, v, 1.0f/16.0f, 1.0f/16.0f, 1,1,1,1);
int gw = 7;
switch (c){
int Font::getGlyphWidth(char c) {
switch (c){
case 'l':
case 'i':
case 'j':
@@ -25,16 +18,19 @@ void Font::draw(Batch2D* batch, std::string text, int x, int y) {
case '.':
case ',':
case ':':
case ';':
gw = 3;
break;
case 't':
gw = 5;
break;
case ' ':
gw = 3;
break;
}
x += gw;
case ';': return 3;
case 't': return 5;
case ' ': return 3;
}
return 7;
}
void Font::draw(Batch2D* batch, std::string text, int x, int y) {
for (char c : text){
float u = (c % 16) / 16.0f;
float v = 1.0f - ((c / 16) / 16.0f) - 1.0f/16.0f;
batch->rect(x, y, 8, 8, u, v, 1.0f/16.0f, 1.0f/16.0f, 1,1,1,1);
x += getGlyphWidth(c);
}
}
+1
View File
@@ -12,6 +12,7 @@ public:
Font(Texture* texture);
~Font();
int getGlyphWidth(char c);
void draw(Batch2D* batch, std::string text, int x, int y);
};