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;
|
||||
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) {
|
||||
bufAdr[i] = b;
|
||||
bufAdr[i+1] = g;
|
||||
@ -59,7 +59,7 @@ static void drawFrame(gfxScreen_t screen, char b, char g, char r)
|
||||
deleteFirstLine(&textBuffer);
|
||||
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()
|
||||
|
@ -53,28 +53,25 @@ int drawCharacter(u8* fb, font_s* font, char c, s16 x, s16 y, u16 w, u16 h)
|
||||
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;
|
||||
|
||||
int k, dx = 0, dy = 0;
|
||||
int length = strlen(str);
|
||||
for (k = 0; k < length; k++)
|
||||
int dx = 0, dy = 0;
|
||||
for (const char& c : str)
|
||||
{
|
||||
dx += drawCharacter(fb, f, str[k], x + dx, y + dy, w, h);
|
||||
if(str[k]=='\n') {
|
||||
dx += drawCharacter(fb, f, c, x + dx, y + dy, w, h);
|
||||
if (c == '\n') {
|
||||
dx = 0;
|
||||
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)
|
||||
return;
|
||||
if(!font)
|
||||
if (!font)
|
||||
font = &fontDefault;
|
||||
|
||||
u16 fbWidth, fbHeight;
|
||||
|
@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
|
||||
#include "font.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 gfxDrawText(gfxScreen_t screen, gfx3dSide_t side, font_s* f, const char* str, s16 x, s16 y);
|
||||
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 std::string& str, s16 x, s16 y);
|
||||
|
Loading…
x
Reference in New Issue
Block a user