/* * Copyright (c) 2025 Aldrik Ramaekers * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include "ui.hpp" #include "imgui.h" #include "locales.hpp" #include "strops.hpp" ImFont* fontBold; ImFont* fontBig; static ui_status current_status; void ui_draw_status() { float region_width = ImGui::GetContentRegionAvail().x; float text_width = ImGui::CalcTextSize(current_status.text).x; if (current_status.loading) { ImGui::SetCursorPosX(ImGui::GetCursorPosX() + region_width - text_width - 20.0f); ImGui::Text("%c", "|/-\\"[(int)(ImGui::GetTime() / 0.1f) & 3]); return; } if (current_status.visible) { ImGui::SetCursorPosX(ImGui::GetCursorPosX() + region_width - text_width); ImGui::PushStyleColor(ImGuiCol_Text, current_status.color); ImGui::TextUnformatted(current_status.text); ImGui::PopStyleColor(); } ImGuiIO& io = ImGui::GetIO(); current_status.time += io.DeltaTime; if (current_status.time >= STATUS_FLASH_INTERVAL && current_status.flash_count < STATUS_MAX_FLASHES) { current_status.visible = !current_status.visible; if (current_status.visible) current_status.flash_count++; current_status.time = 0.0f; } if (current_status.time >= STATUS_DURATION) { current_status.text[0] = 0; } } void ui_set_status_ex(const char* txt, int color) { current_status.flash_count = 0; current_status.visible = true; current_status.time = 0.0f; current_status.color = color; current_status.loading = false; strops_copy(current_status.text, txt, STATUS_TEXT_LEN); } void ui_set_status_error(const char* txt) { ui_set_status_ex(txt, COLOR_ERROR); } void ui_set_status(const char* txt) { ui_set_status_ex(txt, COLOR_DEFAULT); } void ui_set_status_loading(bool loading) { current_status.visible = true; current_status.time = 0.0f; current_status.loading = loading; } ui_status ui_get_status() { return current_status; }