text: Use std::strings for text drawing functions
This commit is contained in:
parent
fcc7d6be10
commit
da9d546440
@ -47,7 +47,7 @@ static void drawFrame(gfxScreen_t screen, char b, char g, char r)
|
|||||||
int screenWidth = (screen == GFX_TOP) ? 400 : 320;
|
int screenWidth = (screen == GFX_TOP) ? 400 : 320;
|
||||||
std::string& textBuffer = (screen == GFX_TOP) ? bufferTop : bufferBottom;
|
std::string& textBuffer = (screen == GFX_TOP) ? bufferTop : bufferBottom;
|
||||||
|
|
||||||
u8* bufAdr = gfxGetFramebuffer(screen, GFX_LEFT, NULL, NULL);
|
u8* bufAdr = gfxGetFramebuffer(screen, GFX_LEFT, nullptr, nullptr);
|
||||||
for (int i = 0; i < screenWidth * screenHeight * 3; i += 3) {
|
for (int i = 0; i < screenWidth * screenHeight * 3; i += 3) {
|
||||||
bufAdr[i] = b;
|
bufAdr[i] = b;
|
||||||
bufAdr[i+1] = g;
|
bufAdr[i+1] = g;
|
||||||
@ -59,7 +59,7 @@ static void drawFrame(gfxScreen_t screen, char b, char g, char r)
|
|||||||
deleteFirstLine(&textBuffer);
|
deleteFirstLine(&textBuffer);
|
||||||
lines--;
|
lines--;
|
||||||
}
|
}
|
||||||
gfxDrawText(screen, GFX_LEFT, NULL, textBuffer.c_str(), screenHeight - fontDefault.height * 3, 10);
|
gfxDrawText(screen, GFX_LEFT, nullptr, textBuffer, screenHeight - fontDefault.height * 3, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawFrames()
|
void drawFrames()
|
||||||
|
@ -53,28 +53,25 @@ int drawCharacter(u8* fb, font_s* font, char c, s16 x, s16 y, u16 w, u16 h)
|
|||||||
return cd->xa;
|
return cd->xa;
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawString(u8* fb, font_s* f, const char* str, s16 x, s16 y, u16 w, u16 h)
|
void drawString(u8* fb, font_s* f, const std::string& str, s16 x, s16 y, u16 w, u16 h)
|
||||||
{
|
{
|
||||||
if (!f || !fb || !str)
|
if (!f || !fb)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int k, dx = 0, dy = 0;
|
int dx = 0, dy = 0;
|
||||||
int length = strlen(str);
|
for (const char& c : str)
|
||||||
for (k = 0; k < length; k++)
|
|
||||||
{
|
{
|
||||||
dx += drawCharacter(fb, f, str[k], x + dx, y + dy, w, h);
|
dx += drawCharacter(fb, f, c, x + dx, y + dy, w, h);
|
||||||
if(str[k]=='\n') {
|
if (c == '\n') {
|
||||||
dx = 0;
|
dx = 0;
|
||||||
dy -= f->height;
|
dy -= f->height;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void gfxDrawText(gfxScreen_t screen, gfx3dSide_t side, font_s* font, const char* str, s16 x, s16 y)
|
void gfxDrawText(gfxScreen_t screen, gfx3dSide_t side, font_s* font, const std::string& str, s16 x, s16 y)
|
||||||
{
|
{
|
||||||
if(!str)
|
if (!font)
|
||||||
return;
|
|
||||||
if(!font)
|
|
||||||
font = &fontDefault;
|
font = &fontDefault;
|
||||||
|
|
||||||
u16 fbWidth, fbHeight;
|
u16 fbWidth, fbHeight;
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <string>
|
||||||
|
|
||||||
#include "font.h"
|
#include "font.h"
|
||||||
|
|
||||||
int drawCharacter(u8* fb, font_s* f, char c, s16 x, s16 y, u16 w, u16 h);
|
int drawCharacter(u8* fb, font_s* f, char c, s16 x, s16 y, u16 w, u16 h);
|
||||||
void drawString(u8* fb, font_s* f, const char* str, s16 x, s16 y, u16 w, u16 h);
|
void drawString(u8* fb, font_s* f, const std::string& str, s16 x, s16 y, u16 w, u16 h);
|
||||||
void gfxDrawText(gfxScreen_t screen, gfx3dSide_t side, font_s* f, const char* str, s16 x, s16 y);
|
void gfxDrawText(gfxScreen_t screen, gfx3dSide_t side, font_s* f, const std::string& str, s16 x, s16 y);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user