3DS: System fonts draw something now

Even if that something is just boxes
This commit is contained in:
UnknownShadow200 2023-04-21 21:37:34 +10:00
parent 5347d136ef
commit f076195472
3 changed files with 121 additions and 10 deletions

View File

@ -1388,7 +1388,7 @@ static int Font_SysTextWidth(struct DrawTextArgs* args) {
static void Font_SysTextDraw(struct DrawTextArgs* args, struct Bitmap* bmp, int x, int y, cc_bool shadow) {
interop_SysTextDraw(args, bmp, x, y, shadow);
}
#elif defined CC_BUILD_PSP || defined CC_BUILD_3DS
#elif defined CC_BUILD_PSP
void SysFonts_Register(const cc_string* path) { }
const cc_string* SysFonts_UNSAFE_GetDefault(void) { return &String_Empty; }
@ -1419,4 +1419,114 @@ static int Font_SysTextWidth(struct DrawTextArgs* args) {
static void Font_SysTextDraw(struct DrawTextArgs* args, struct Bitmap* bmp, int x, int y, cc_bool shadow) {
}
#elif defined CC_BUILD_3DS
#include <3ds.h>
void SysFonts_Register(const cc_string* path) { }
const cc_string* SysFonts_UNSAFE_GetDefault(void) { return &String_Empty; }
void SysFonts_GetNames(struct StringsBuffer* buffer) { }
cc_result SysFont_Make(struct FontDesc* desc, const cc_string* fontName, int size, int flags) {
desc->size = size;
desc->flags = flags;
desc->height = Drawer2D_AdjHeight(size);
desc->handle = fontGetSystemFont();
return 0;
}
void SysFont_MakeDefault(struct FontDesc* desc, int size, int flags) {
SysFont_Make(desc, NULL, size, flags);
}
void Font_Free(struct FontDesc* desc) {
desc->size = 0;
desc->handle = NULL;
}
static int Font_SysTextWidth(struct DrawTextArgs* args) {
int width = 0;
cc_string left = args->text, part;
char colorCode = 'f';
CFNT_s* font = (CFNT_s*)args->font->handle;
while (Drawer2D_UNSAFE_NextPart(&left, &part, &colorCode))
{
for (int i = 0; i < part.length; i++)
{
cc_unichar cp = Convert_CP437ToUnicode(part.buffer[i]);
int glyphIndex = fontGlyphIndexFromCodePoint(font, cp);
if (glyphIndex < 0) continue;
charWidthInfo_s* wInfo = fontGetCharWidthInfo(font, glyphIndex);
width += wInfo->charWidth;
}
}
return max(1, width);
}
static void DrawGlyph(CFNT_s* font, struct Bitmap* bmp, int x, int y, int glyphIndex) {
TGLP_s* tglp = font->finf.tglp;
//int glyphsPerSheet = tglp->nRows * tglp->nLines;
//int sheetIdx = glyphIndex / glyphsPerSheet;
//int sheetPos = glyphIndex % glyphsPerSheet;
//u8* sheet = tglp->sheetData + (sheetIdx * tglp->sheetSize);
//int rowY = sheetPos / tglp->nRows;
//int rowX = sheetPos % tglp->nRows;
//int FMT = tglp->sheetFmt;
//Platform_Log1("FMT: %i", &FMT);
charWidthInfo_s* wInfo = fontGetCharWidthInfo(font, glyphIndex);
/*for (int Y = 0; Y < tglp->cellHeight; Y++)
{
for (int X = wInfo->left; X < wInfo->left + wInfo->glyphWidth; X++)
{
int XX = x + X, YY = y + Y;
if (XX < 0 || YY < 0 || XX >= bmp->width || YY >= bmp->height) continue;
int srcX = X + rowX * tglp->cellWidth;
int srcY = Y + rowY * tglp->cellHeight; // TODO wrong. morton offset too?
u8 VALUE = ((sheet + srcY * (tglp->sheetWidth >> 1))[srcX >> 1] & 0x0F) << 4;
Bitmap_GetPixel(bmp, XX, YY) = BitmapColor_RGB(VALUE, VALUE, VALUE);
}
}*/
for (int Y = 0; Y < tglp->cellHeight; Y++)
{
for (int X = wInfo->left; X < wInfo->left + wInfo->glyphWidth; X++)
{
int XX = x + X, YY = y + Y;
if (XX < 0 || YY < 0 || XX >= bmp->width || YY >= bmp->height) continue;
Bitmap_GetPixel(bmp, XX, YY) = BITMAPCOLOR_WHITE;
}
}
}
static void Font_SysTextDraw(struct DrawTextArgs* args, struct Bitmap* bmp, int x, int y, cc_bool shadow) {
cc_string left = args->text, part;
char colorCode = 'f';
CFNT_s* font = (CFNT_s*)args->font->handle;
while (Drawer2D_UNSAFE_NextPart(&left, &part, &colorCode))
{
for (int i = 0; i < part.length; i++)
{
cc_unichar cp = Convert_CP437ToUnicode(part.buffer[i]);
int glyphIndex = fontGlyphIndexFromCodePoint(font, cp);
if (glyphIndex < 0) continue;
DrawGlyph(font, bmp, x, y, glyphIndex);
charWidthInfo_s* wInfo = fontGetCharWidthInfo(font, glyphIndex);
x += wInfo->charWidth;
}
}
}
#endif

View File

@ -36,7 +36,7 @@
#endif
/* Only show up to 40 frames in backtrace */
#define MAX_BACKTRACE_FRAMES 40x
#define MAX_BACKTRACE_FRAMES 40
static void AbortCommon(cc_result result, const char* raw_msg, void* ctx);

View File

@ -20,7 +20,6 @@
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <poll.h>
@ -360,9 +359,9 @@ int Socket_ValidAddress(const cc_string* address) {
}
cc_result Socket_Connect(cc_socket* s, const cc_string* address, int port) {
int addrSize, blocking_raw = -1; /* non-blocking mode */
union SocketAddress addr;
cc_result res;
int flags;
*s = -1;
if (!ParseAddress(&addr, address))
@ -370,13 +369,15 @@ cc_result Socket_Connect(cc_socket* s, const cc_string* address, int port) {
*s = socket(AF_INET, SOCK_STREAM, 0); // https://www.3dbrew.org/wiki/SOCU:socket
if (*s == -1) return errno;
ioctl(*s, FIONBIO, &blocking_raw);
// non blocking mode
flags = fcntl(*s, F_GETFL, 0);
if (flags >= 0) fcntl(*s, F_SETFL, flags | O_NONBLOCK);
addr.v4.sin_family = AF_INET;
addr.v4.sin_port = htons(port);
addrSize = sizeof(addr.v4);
res = connect(*s, &addr.raw, addrSize);
res = connect(*s, &addr.raw, sizeof(addr.v4));
return res == -1 ? errno : 0;
}