aboutsummaryrefslogtreecommitdiff
path: root/src/strings33.c
diff options
context:
space:
mode:
authorpk33 <pk33@pk33.space>2024-11-03 22:26:28 +0100
committerpk33 <pk33@pk33.space>2024-11-03 22:26:28 +0100
commit0ffb4f8463e3e06e8d88b7be22f5cb7adb702361 (patch)
tree05e626d6ce4e0d8e544a40f8a14965cf4fdd5780 /src/strings33.c
parent6c69ea8da9d306e4e6d21d0feee5213fea15f49e (diff)
downloadengine33-0ffb4f8463e3e06e8d88b7be22f5cb7adb702361.tar.gz
fonts, text and basic ui for on-screen log
Diffstat (limited to 'src/strings33.c')
-rw-r--r--src/strings33.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/strings33.c b/src/strings33.c
new file mode 100644
index 0000000..0bb7ea0
--- /dev/null
+++ b/src/strings33.c
@@ -0,0 +1,78 @@
+#include "stdarg.h"
+#include "stdio.h"
+#include "string.h"
+
+#include "strings33.h"
+#include "types.h"
+
+
+extern Font33 defFont;
+extern Font33 bigFont;
+
+static Font33 *fonts[2] = {
+ &defFont, &bigFont
+};
+
+
+
+void e33_uprintf( Surface *surf, Size f, u32 col, Size x, Size y, const char *fmt, ... )
+{
+ static char tmp[512];
+
+ va_list args;
+ va_start(args, fmt);
+
+ vsprintf(tmp, fmt, args);
+ e33_uprint( surf, f, col, x, y, tmp );
+
+ va_end(args);
+}
+
+
+void e33_uprint( Surface *surf, Size f, u32 col, Size x, Size y, const char *str )
+{
+ Size i, j, ofs;
+ Font33 *font = fonts[f];
+ Size sWidth = surf->w;
+ Size sHeight = surf->h;
+ FontGlyph33 *glyphs = font->glyphs;
+ Size fbw = surf->w;
+ Size fbh = surf->h;
+ u32 *out;
+ uSize slen = strlen(str);
+
+ Size strWid = 0;
+ for( i = 0; i < slen; ++i ) {
+ strWid += glyphs[ str[i] - 0x20 ].width;
+ }
+
+ if( (x + strWid) >= sWidth ) {
+ x -= (strWid - (sWidth - x));
+ }
+ if( (y + font->height) >= sHeight ) {
+ y -= (font->height - (sHeight - y));
+ }
+
+ if(x < 0) { x = 0; }
+ if(y < 0) { y = 0; }
+ out = surf->data + (x + (y * surf->w));
+
+ for( i = 0, ofs = 0; i < slen; ++i )
+ {
+ FontGlyph33 *glyph = &glyphs[ str[i] - 0x20 ];
+ Size numPlots = glyph->num_plots;
+ Size gWidth = glyph->width;
+ u16 *plots = glyph->plots;
+
+ for( j = 0; j < numPlots; ++j )
+ {
+ Size plot = plots[j];
+ Size offset = (((plot & font->yAnd) * fbw) + (plot >> font->xShift)) + ofs;
+
+ memcpy( out + offset, &col, sizeof(u32) );
+ }
+
+ ofs += gWidth;
+ }
+}
+