/* * 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 #include #include "ui.hpp" #include "strops.hpp" #include "config.hpp" #include "locales.hpp" #include "administration_writer.hpp" #include "administration_reader.hpp" #include int ui::load_image(const char* filename) { int width, height, channels; unsigned char* data = stbi_load(filename, &width, &height, &channels, 0); if (!data) { return 0; } GLuint textureID; glGenTextures(1, &textureID); glBindTexture(GL_TEXTURE_2D, textureID); // Set texture parameters glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Upload texture data GLenum format = (channels == 4) ? GL_RGBA : GL_RGB; glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, GL_UNSIGNED_BYTE, data); //glGenerateMipmap(GL_TEXTURE_2D); // Free image memory stbi_image_free(data); return textureID; } void ui::draw_setup() { static int img = load_image("/home/aldrik/Projects/open-books/build/splash.png"); ImVec2 area = ImGui::GetContentRegionAvail(); ImGui::PushStyleVar(ImGuiStyleVar_ButtonTextAlign, ImVec2(0.0f, 0.5f)); ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(10.0f, 10.0f)); ImGui::PushFont(ui::fontBig); const char* title = "OpenBooks"; ImVec2 textSize = ImGui::CalcTextSize(title); ImGui::SetCursorPos(ImVec2((area.x - textSize.x) * 0.5f, 20)); ImGui::Text(title); ImGui::PopFont(); ImGui::Spacing(); ImGui::Spacing(); if (ImGui::Button(ICON_FA_FILE_IMPORT " Load administration", ImVec2(area.x, 0))) { // @locale if (administration_reader::open_existing(NULL)) { ui::set_state(ui::main_state::UI_SETTINGS); ui::recreate_window_for_main_views(); } } if (ImGui::Button(ICON_FA_FOLDER_PLUS " Create administration", ImVec2(area.x, 0))) { // @locale if (administration_reader::open_existing(NULL)) { ui::set_state(ui::main_state::UI_SETTINGS); ui::recreate_window_for_main_views(); } } ImGui::PopStyleVar(); ImGui::PopStyleVar(); char version_txt[100]; strops::format(version_txt, sizeof(version_txt), "VERSION: %s %s", config::PROGRAM_VERSION, _DATE_); textSize = ImGui::CalcTextSize(version_txt); ImGui::SetCursorPos(ImVec2(5, area.y)); ImGui::PushFont(ui::fontSmall); ImGui::Text(version_txt); ImGui::PopFont(); int imageW = 150; int imageH = 150; ImGui::SetCursorScreenPos(ImVec2(area.x - imageW + 20, area.y - imageH + 20)); ImGui::Image(img, ImVec2(imageW, imageH)); } void ui::setup_setup() { } void ui::destroy_setup() { }