From 4c2c03ed4d18fdf5215a0e1de1ffed0499e281e5 Mon Sep 17 00:00:00 2001 From: rxi Date: Thu, 14 May 2020 08:43:27 +0100 Subject: [PATCH] Made draw_text/draw_rect not push command if result is not on-screen --- src/rencache.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/rencache.c b/src/rencache.c index 4e65c06..7132759 100644 --- a/src/rencache.c +++ b/src/rencache.c @@ -119,6 +119,7 @@ void rencache_set_clip_rect(RenRect rect) { void rencache_draw_rect(RenRect rect, RenColor color) { + if (!rects_overlap(screen_rect, rect)) { return; } Command *cmd = push_command(DRAW_RECT, sizeof(Command)); cmd->rect = rect; cmd->color = color; @@ -126,16 +127,22 @@ void rencache_draw_rect(RenRect rect, RenColor color) { int rencache_draw_text(RenFont *font, const char *text, int x, int y, RenColor color) { - int sz = strlen(text) + 1; - Command *cmd = push_command(DRAW_TEXT, sizeof(Command) + sz); - memcpy(cmd->text, text, sz); - cmd->color = color; - cmd->font = font; - cmd->rect.x = x; - cmd->rect.y = y; - cmd->rect.width = ren_get_font_width(font, text); - cmd->rect.height = ren_get_font_height(font); - return x + cmd->rect.width; + RenRect rect; + rect.x = x; + rect.y = y; + rect.width = ren_get_font_width(font, text); + rect.height = ren_get_font_height(font); + + if (rects_overlap(screen_rect, rect)) { + int sz = strlen(text) + 1; + Command *cmd = push_command(DRAW_TEXT, sizeof(Command) + sz); + memcpy(cmd->text, text, sz); + cmd->color = color; + cmd->font = font; + cmd->rect = rect; + } + + return x + rect.width; }