Skip to content

Commit

Permalink
osd: Draw log from bottom to top
Browse files Browse the repository at this point in the history
  • Loading branch information
Electry committed Dec 26, 2019
1 parent 6cab573 commit ea3e21e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ static int sceDisplaySetFrameBuf_patched(const SceDisplayFrameBuf *pParam, int s

// Draw first x characters from log
if (g_main.config.log_enabled) {
osd_draw_string(20, 150, g_osd_buffer);
osd_draw_log(20, 150, pParam->height, g_osd_buffer);
}
}
// Wrong version
Expand Down
22 changes: 22 additions & 0 deletions src/osd.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,25 @@ void osd_draw_stringf(int x, int y, const char *format, ...) {

osd_draw_string(x, y, buffer);
}

void osd_draw_log(int x, int y, int maxy, const char *str) {
size_t slen = strlen(str);
if (slen <= 3)
return;

size_t line_end = slen - 1;

for (int i = slen - 2; i >= 0; i--) {
if (i == 0 || str[i - 1] == '\n') {
maxy -= FONT_HEIGHT;
if (maxy < y)
break;

for (size_t i_cur = 0; i_cur < line_end - i; i_cur++) {
osd_draw_char(str[i + i_cur], x + (i_cur * FONT_WIDTH * g_font_scale), (maxy - FONT_HEIGHT));
}

line_end = i - 1;
}
}
}
2 changes: 2 additions & 0 deletions src/osd.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ void osd_draw_char(const char character, int x, int y);
void osd_draw_string(int x, int y, const char *str);
void osd_draw_stringf(int x, int y, const char *format, ...);

void osd_draw_log(int x, int y, int maxy, const char *str);

#endif

0 comments on commit ea3e21e

Please sign in to comment.