aboutsummaryrefslogtreecommitdiff
path: root/render.c
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2023-05-06 09:02:04 +1000
committerquou <quou@disroot.org>2023-05-06 09:02:04 +1000
commit2ab411c4b8855d11d48454a93262e8eae3ba7fc7 (patch)
treee608ebd0bea71570be0a3619f9848f975669e5ef /render.c
parentfb104368dd33b66e0575dcc0327cbae7046a4e1e (diff)
Menus, game over, dying, etc.
Diffstat (limited to 'render.c')
-rw-r--r--render.c92
1 files changed, 89 insertions, 3 deletions
diff --git a/render.c b/render.c
index 578abef..b2a59e2 100644
--- a/render.c
+++ b/render.c
@@ -73,7 +73,7 @@ Colour blend_mod(Colour dst, Colour src, Colour mod) {
void init_font(
BM_Font* font,
- Bitmap* bmp,
+ const Bitmap* bmp,
int char_w,
int char_h,
int chars_across
@@ -84,28 +84,65 @@ void init_font(
font->chars_across = chars_across;
}
-void rfont_char(int x, int y, char c) {
+void rfont_char(const BM_Font* font, int x, int y, char c) {
+ Rectangle rect;
+ c -= ' ';
+
+ rect.x = (c % font->chars_across) * font->char_w;
+ rect.y = (c / font->chars_across) * font->char_h;
+ rect.w = font->char_w;
+ rect.h = font->char_h;
+
+ render_bitmap(font->bmp, x, y, &rect);
}
-void rfont_char_col(int x, int y, char c, Colour colour) {
+void rfont_char_col(
+ const BM_Font* font,
+ int x,
+ int y,
+ char c,
+ Colour colour
+) {
+ Rectangle rect;
+
+ c -= ' ';
+
+ rect.x = (c % font->chars_across) * font->char_w;
+ rect.y = (c / font->chars_across) * font->char_h;
+ rect.w = font->char_w;
+ rect.h = font->char_h;
+ render_bitmap_col(font->bmp, x, y, &rect, colour);
}
void rfont_text(
+ const BM_Font* font,
int x,
int y,
const char* text
) {
+ const char* c;
+
+ for (c = text; *c; c++) {
+ rfont_char(font, x, y, *c);
+ x += font->char_w;
+ }
}
void rfont_text_col(
+ const BM_Font* font,
int x,
int y,
const char* text,
Colour colour
) {
+ const char* c;
+ for (c = text; *c; c++) {
+ rfont_char_col(font, x, y, *c, colour);
+ x += font->char_w;
+ }
}
void render_bitmap(
@@ -173,5 +210,54 @@ void render_bitmap_col(
const Rectangle* rect,
Colour colour
) {
+ int i, j, stride, sstride, n;
+ Colour* dst;
+ const Colour* src;
+ Rectangle sub;
+ sub = *rect;
+
+ if (sub.w <= 0) { return; }
+ if (sub.h <= 0) { return; }
+ if (sub.w > bitmap->w) { return; }
+ if (sub.h > bitmap->h) { return; }
+
+ if ((n = -x) > 0) {
+ sub.w -= n;
+ sub.x += n;
+ x += n;
+ }
+
+ if ((n = -y) > 0) {
+ sub.h -= n;
+ sub.y += n;
+ y += n;
+ }
+
+ if ((n = x + sub.w - renderer_w) > 0) {
+ sub.w -= n;
+ }
+
+ if ((n = y + sub.h - renderer_h) > 0) {
+ sub.h -= n;
+ }
+
+ if (sub.w <= 0) { return; }
+ if (sub.h <= 0) { return; }
+
+ dst = renderer.pixels + (x + y * renderer_w);
+ src = bitmap->pixels + (sub.x + sub.y * bitmap->w);
+
+ stride = renderer_w - sub.w;
+ sstride = bitmap->w - sub.w;
+
+ for (i = 0; i < sub.h; i++) {
+ for (j = 0; j < sub.w; j++) {
+ *dst = blend_mod(*dst, *src, colour);
+ dst++;
+ src++;
+ }
+ dst += stride;
+ src += sstride;
+ }
}