pass RenWindow by argument (#1321)

* pass RenWindow to all renderer functions that need it

* pass RenWindow to all rencache functions that need it
This commit is contained in:
Jan
2023-08-19 12:30:41 +08:00
committed by takase1121
parent 5907118683
commit a951c3cd39
7 changed files with 73 additions and 70 deletions
+11 -11
View File
@@ -175,9 +175,9 @@ void rencache_draw_rect(RenRect rect, RenColor color) {
}
}
float rencache_draw_text(RenFont **fonts, const char *text, size_t len, float x, int y, RenColor color)
float rencache_draw_text(RenWindow *window_renderer, RenFont **fonts, const char *text, size_t len, float x, int y, RenColor color)
{
float width = ren_font_group_get_width(fonts, text, len);
float width = ren_font_group_get_width(window_renderer, fonts, text, len);
RenRect rect = { x, y, (int)width, ren_font_group_get_height(fonts) };
if (rects_overlap(last_clip_rect, rect)) {
int sz = len + 1;
@@ -201,11 +201,11 @@ void rencache_invalidate(void) {
}
void rencache_begin_frame() {
void rencache_begin_frame(RenWindow *window_renderer) {
/* reset all cells if the screen width/height has changed */
int w, h;
resize_issue = false;
ren_get_size(&w, &h);
ren_get_size(window_renderer, &w, &h);
if (screen_rect.width != w || h != screen_rect.height) {
screen_rect.width = w;
screen_rect.height = h;
@@ -244,7 +244,7 @@ static void push_rect(RenRect r, int *count) {
}
void rencache_end_frame() {
void rencache_end_frame(RenWindow *window_renderer) {
/* update cells from commands */
Command *cmd = NULL;
RenRect cr = screen_rect;
@@ -286,33 +286,33 @@ void rencache_end_frame() {
for (int i = 0; i < rect_count; i++) {
/* draw */
RenRect r = rect_buf[i];
ren_set_clip_rect(r);
ren_set_clip_rect(window_renderer, r);
cmd = NULL;
while (next_command(&cmd)) {
switch (cmd->type) {
case SET_CLIP:
ren_set_clip_rect(intersect_rects(cmd->rect, r));
ren_set_clip_rect(window_renderer, intersect_rects(cmd->rect, r));
break;
case DRAW_RECT:
ren_draw_rect(cmd->rect, cmd->color);
ren_draw_rect(window_renderer, cmd->rect, cmd->color);
break;
case DRAW_TEXT:
ren_font_group_set_tab_size(cmd->fonts, cmd->tab_size);
ren_draw_text(cmd->fonts, cmd->text, cmd->len, cmd->text_x, cmd->rect.y, cmd->color);
ren_draw_text(window_renderer, cmd->fonts, cmd->text, cmd->len, cmd->text_x, cmd->rect.y, cmd->color);
break;
}
}
if (show_debug) {
RenColor color = { rand(), rand(), rand(), 50 };
ren_draw_rect(r, color);
ren_draw_rect(window_renderer, r, color);
}
}
/* update dirty rects */
if (rect_count > 0) {
ren_update_rects(rect_buf, rect_count);
ren_update_rects(window_renderer, rect_buf, rect_count);
}
/* swap cell buffer and reset */