Files
armorpaint/paint/sources/console.c
T

85 lines
2.1 KiB
C
Raw Normal View History

2026-03-09 13:17:15 +01:00
#include "global.h"
2026-03-07 21:12:59 +01:00
void console_draw_toast(char *s) {
draw_begin(NULL, false, 0);
2025-03-02 21:07:17 +01:00
draw_set_color(0x55000000);
2025-03-09 17:02:12 +01:00
draw_filled_rect(0, 0, iron_window_width(), iron_window_height());
2026-03-06 12:56:38 +01:00
f32 scale = UI_SCALE();
2026-03-15 21:14:44 +01:00
f32 x = iron_window_width() / 2.0;
2026-03-06 12:56:38 +01:00
f32 y = iron_window_height() - 200 * scale;
2025-03-02 19:44:26 +01:00
draw_filled_rect(x - 200 * scale, y, 400 * scale, 80 * scale);
2025-03-10 20:26:45 +01:00
draw_set_font(base_font, math_floor(22 * scale));
2025-03-02 21:07:17 +01:00
draw_set_color(0xffffffff);
2026-03-15 21:14:44 +01:00
draw_string(s, x - draw_string_width(draw_font, draw_font_size, s) / 2.0, y + 40 * scale - draw_font_height(draw_font, draw_font_size) / 2.0);
2025-06-21 16:49:53 +02:00
draw_end();
2024-03-09 14:52:33 +01:00
}
2026-03-07 21:12:59 +01:00
void console_toast(char *s) {
2024-03-09 14:52:33 +01:00
// Show a popup message
2026-03-06 12:56:38 +01:00
gpu_texture_t *current = _draw_current;
bool in_use = gpu_in_use;
2026-01-10 13:50:53 +01:00
if (in_use)
2025-10-15 18:39:55 +02:00
draw_end();
2026-03-23 23:20:02 +01:00
console_log(s);
2025-08-05 22:53:56 +02:00
console_draw_toast(s);
2026-01-10 13:50:53 +01:00
if (in_use)
2026-03-06 12:56:38 +01:00
draw_begin(current, false, 0);
2024-03-09 14:52:33 +01:00
}
2026-03-13 17:44:47 +01:00
void console_draw_progress(void *_) {
2024-03-09 14:52:33 +01:00
console_draw_toast(console_progress_text);
}
2026-03-07 21:12:59 +01:00
void console_progress(char *s) {
// Keep popup message displayed until s == NULL
if (s == NULL) {
2025-08-16 20:43:45 +02:00
sys_remove_render(console_draw_progress);
2024-03-09 14:52:33 +01:00
}
2026-03-07 21:12:59 +01:00
else if (console_progress_text == NULL) {
sys_notify_on_render(console_draw_progress, NULL);
2024-03-09 14:52:33 +01:00
}
2026-03-07 21:12:59 +01:00
if (s != NULL) {
2026-03-23 23:20:02 +01:00
console_log(s);
2024-03-20 16:13:54 +01:00
}
2026-03-06 12:56:38 +01:00
gc_unroot(console_progress_text);
console_progress_text = string_copy(s);
gc_root(console_progress_text);
2024-10-25 18:58:10 +02:00
// Pass one frame to immediately show the message
2025-03-10 20:26:45 +01:00
draw_end();
2025-03-11 19:49:42 +01:00
sys_render();
2026-03-07 21:12:59 +01:00
draw_begin(NULL, false, 0);
2025-06-19 19:55:16 +02:00
gpu_present();
2025-08-15 22:04:07 +02:00
ui_end_input();
2024-03-09 14:52:33 +01:00
}
2026-03-07 21:12:59 +01:00
void console_info(char *s) {
2024-03-09 14:52:33 +01:00
console_message_timer = 5.0;
2026-03-06 12:56:38 +01:00
gc_unroot(console_message);
console_message = string_copy(s);
gc_root(console_message);
2024-03-09 14:52:33 +01:00
console_message_color = 0x00000000;
base_redraw_status();
2026-03-23 23:20:02 +01:00
console_log(s);
2024-03-09 14:52:33 +01:00
}
2026-03-07 21:12:59 +01:00
void console_error(char *s) {
2024-03-09 14:52:33 +01:00
console_message_timer = 8.0;
2026-03-06 12:56:38 +01:00
gc_unroot(console_message);
console_message = string_copy(s);
gc_root(console_message);
2024-03-09 14:52:33 +01:00
console_message_color = 0xffaa0000;
base_redraw_status();
2026-03-23 23:20:02 +01:00
console_log(s);
2024-03-09 14:52:33 +01:00
}
2026-03-07 21:12:59 +01:00
void console_log(char *s) {
2025-03-09 17:02:12 +01:00
iron_log(s);
2024-03-09 14:52:33 +01:00
base_redraw_console();
2026-03-15 10:47:53 +01:00
string_array_push(console_last_traces, string_copy(s));
2026-03-06 12:56:38 +01:00
if (console_last_traces->length > 100) {
2026-03-13 17:44:47 +01:00
array_shift(console_last_traces);
2024-03-20 16:13:54 +01:00
}
2024-03-09 14:52:33 +01:00
}