88 lines
1.5 KiB
C++
88 lines
1.5 KiB
C++
#include "render.h"
|
|
#include <gint/display.h>
|
|
#include <gint/defs/attributes.h>
|
|
#include <stdio.h>
|
|
|
|
extern "C" {
|
|
extern font_t font_nooncraft;
|
|
}
|
|
|
|
GCONSTRUCTOR
|
|
static void init_font(void)
|
|
{
|
|
dfont(&font_nooncraft);
|
|
}
|
|
|
|
static bool nightMode = false;
|
|
|
|
static inline int fg()
|
|
{
|
|
return nightMode ? C_WHITE : C_BLACK;
|
|
}
|
|
static inline int bg()
|
|
{
|
|
return nightMode ? C_BLACK : C_WHITE;
|
|
}
|
|
static inline void dglyph(int x, int y, Glyph g)
|
|
{
|
|
dtext_opt(x, y, fg(), bg(), DTEXT_LEFT, DTEXT_TOP, &g, 1);
|
|
}
|
|
|
|
void renderSetNight(bool night)
|
|
{
|
|
nightMode = night;
|
|
}
|
|
|
|
void renderClear(void)
|
|
{
|
|
dclear(bg());
|
|
}
|
|
|
|
void renderUpdate(void)
|
|
{
|
|
dupdate();
|
|
}
|
|
|
|
static int cellX(int x, bool text)
|
|
{
|
|
return 4 + 7 * x - (!text && (x & 1));
|
|
}
|
|
|
|
static int cellY(int y, bool text)
|
|
{
|
|
(void)text;
|
|
return 2 + 7 * y - (y & 1);
|
|
}
|
|
|
|
void renderGlyph(int x, int y, Glyph g)
|
|
{
|
|
dglyph(cellX(x, true), cellY(y, true), g);
|
|
}
|
|
|
|
void renderCluster(int x, int y, GlyphCluster c)
|
|
{
|
|
int px = cellX(x & -2, false);
|
|
int py = cellY(y & -2, false);
|
|
|
|
dglyph(px, py, c.glyphs[0]);
|
|
dglyph(px+6, py, c.glyphs[1]);
|
|
dglyph(px, py+6, c.glyphs[2]);
|
|
dglyph(px+6, py+6, c.glyphs[3]);
|
|
}
|
|
|
|
void renderText(int x, int y, char const *text)
|
|
{
|
|
for(int i = 0; text[i]; i++)
|
|
renderGlyph(x + i, y, text[i]);
|
|
}
|
|
|
|
void renderFormat(int x, int y, char const *fmt, ...)
|
|
{
|
|
static char str[128];
|
|
va_list args;
|
|
va_start(args, fmt);
|
|
vsnprintf(str, sizeof str, fmt, args);
|
|
va_end(args);
|
|
renderText(x, y, str);
|
|
}
|