ui: Add Orbital menu bar and new font/color style

This commit is contained in:
Alexandro Sanchez Bach 2021-10-12 18:07:41 +02:00
parent 19c3ba5e90
commit 0f209a05d5
8 changed files with 223 additions and 89 deletions

BIN
bin/fonts/Roboto-Medium.ttf Normal file

Binary file not shown.

Binary file not shown.

View file

@ -9,8 +9,6 @@
*/
#include "ui.h"
#include "ui/ui_style.h"
#include <orbital/host/graphics/vulkan.h>
#include <SDL2/SDL_vulkan.h>
@ -151,7 +149,7 @@ UI::UI() {
// Initialize ImGui
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ui_style_initialize();
ui.init();
ImGui_ImplSDL2_InitForVulkan(window);
ImGui_ImplVulkan_InitInfo init_info = {};
@ -258,8 +256,7 @@ void UI::loop() {
ImGui::NewFrame();
// Window
ImGui::ShowDemoWindow();
//orbital_display_draw(&ui);
ui.render();
ImGui::Render();
frame_render();

View file

@ -17,6 +17,7 @@
#include "ui/imgui/imgui_impl_sdl.h"
#include "ui/imgui/imgui_impl_vulkan.h"
#include "ui/ui_orbital.h"
// Forward declarations
class VulkanManager;
@ -44,6 +45,8 @@ private:
int w;
int h;
OrbitalUI ui;
/**
* Main UI iteration.
*/

View file

@ -0,0 +1,168 @@
/**
* Orbital UI renderer for ImGui.
*
* Copyright 2017-2021. Orbital project.
* Released under MIT license. Read LICENSE for more details.
*
* Authors:
* - Alexandro Sanchez Bach <alexandro@phi.nz>
*/
#include "ui_orbital.h"
#include <core.h>
#define SDL_MAIN_HANDLED
#include <SDL2/SDL.h>
#define IMGUI_IMPL_API
#include <imgui.h>
void OrbitalUI::init() {
// Calculate DPI scaling
float dpi_scale = 1.0;
float dpi_diagonal;
if (SDL_GetDisplayDPI(0, &dpi_diagonal, nullptr, nullptr) == 0)
dpi_scale = dpi_diagonal / 96.0f;
// Create new fonts
ImFontConfig font_config{};
font_config.FontDataOwnedByAtlas = false;
font_text_data = fs::read_bin("fonts/Roboto-Medium.ttf");
font_code_data = fs::read_bin("fonts/RobotoMono-Medium.ttf");
ImGuiIO& io = ImGui::GetIO();
font_default = io.Fonts->AddFontDefault();
font_text = io.Fonts->AddFontFromMemoryTTF(font_text_data.data(), static_cast<S32>(font_text_data.size()),
16.f * dpi_scale, &font_config, io.Fonts->GetGlyphRangesDefault());
font_code = io.Fonts->AddFontFromMemoryTTF(font_code_data.data(), static_cast<S32>(font_code_data.size()),
16.f * dpi_scale, &font_config, io.Fonts->GetGlyphRangesDefault());
// Initialize style
auto& style = ImGui::GetStyle();
style.Colors[ImGuiCol_Text] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
style.Colors[ImGuiCol_TextDisabled] = ImVec4(0.50f, 0.50f, 0.50f, 1.00f);
style.Colors[ImGuiCol_WindowBg] = ImVec4(0.13f, 0.14f, 0.15f, 1.00f);
style.Colors[ImGuiCol_ChildBg] = ImVec4(0.13f, 0.14f, 0.15f, 1.00f);
style.Colors[ImGuiCol_PopupBg] = ImVec4(0.13f, 0.14f, 0.15f, 1.00f);
style.Colors[ImGuiCol_Border] = ImVec4(0.43f, 0.43f, 0.50f, 0.50f);
style.Colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
style.Colors[ImGuiCol_FrameBg] = ImVec4(0.25f, 0.25f, 0.25f, 1.00f);
style.Colors[ImGuiCol_FrameBgHovered] = ImVec4(0.38f, 0.38f, 0.38f, 1.00f);
style.Colors[ImGuiCol_FrameBgActive] = ImVec4(0.67f, 0.67f, 0.67f, 0.39f);
style.Colors[ImGuiCol_TitleBg] = ImVec4(0.08f, 0.08f, 0.09f, 1.00f);
style.Colors[ImGuiCol_TitleBgActive] = ImVec4(0.08f, 0.08f, 0.09f, 1.00f);
style.Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.00f, 0.00f, 0.00f, 0.51f);
style.Colors[ImGuiCol_MenuBarBg] = ImVec4(0.14f, 0.14f, 0.14f, 1.00f);
style.Colors[ImGuiCol_ScrollbarBg] = ImVec4(0.02f, 0.02f, 0.02f, 0.53f);
style.Colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.31f, 0.31f, 0.31f, 1.00f);
style.Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f);
style.Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.51f, 0.51f, 0.51f, 1.00f);
style.Colors[ImGuiCol_CheckMark] = ImVec4(0.11f, 0.64f, 0.92f, 1.00f);
style.Colors[ImGuiCol_SliderGrab] = ImVec4(0.11f, 0.64f, 0.92f, 1.00f);
style.Colors[ImGuiCol_SliderGrabActive] = ImVec4(0.08f, 0.50f, 0.72f, 1.00f);
style.Colors[ImGuiCol_Button] = ImVec4(0.25f, 0.25f, 0.25f, 1.00f);
style.Colors[ImGuiCol_ButtonHovered] = ImVec4(0.38f, 0.38f, 0.38f, 1.00f);
style.Colors[ImGuiCol_ButtonActive] = ImVec4(0.67f, 0.67f, 0.67f, 0.39f);
style.Colors[ImGuiCol_Header] = ImVec4(0.22f, 0.22f, 0.22f, 1.00f);
style.Colors[ImGuiCol_HeaderHovered] = ImVec4(0.25f, 0.25f, 0.25f, 1.00f);
style.Colors[ImGuiCol_HeaderActive] = ImVec4(0.67f, 0.67f, 0.67f, 0.39f);
style.Colors[ImGuiCol_Separator] = style.Colors[ImGuiCol_Border];
style.Colors[ImGuiCol_SeparatorHovered] = ImVec4(0.41f, 0.42f, 0.44f, 1.00f);
style.Colors[ImGuiCol_SeparatorActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.95f);
style.Colors[ImGuiCol_ResizeGrip] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
style.Colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.29f, 0.30f, 0.31f, 0.67f);
style.Colors[ImGuiCol_ResizeGripActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.95f);
style.Colors[ImGuiCol_Tab] = ImVec4(0.08f, 0.08f, 0.09f, 0.83f);
style.Colors[ImGuiCol_TabHovered] = ImVec4(0.33f, 0.34f, 0.36f, 0.83f);
style.Colors[ImGuiCol_TabActive] = ImVec4(0.23f, 0.23f, 0.24f, 1.00f);
style.Colors[ImGuiCol_TabUnfocused] = ImVec4(0.08f, 0.08f, 0.09f, 1.00f);
style.Colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.13f, 0.14f, 0.15f, 1.00f);
style.Colors[ImGuiCol_DockingPreview] = ImVec4(0.26f, 0.59f, 0.98f, 0.70f);
style.Colors[ImGuiCol_DockingEmptyBg] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f);
style.Colors[ImGuiCol_PlotLines] = ImVec4(0.61f, 0.61f, 0.61f, 1.00f);
style.Colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.00f, 0.43f, 0.35f, 1.00f);
style.Colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
style.Colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f);
style.Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.26f, 0.59f, 0.98f, 0.35f);
style.Colors[ImGuiCol_DragDropTarget] = ImVec4(0.11f, 0.64f, 0.92f, 1.00f);
style.Colors[ImGuiCol_NavHighlight] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
style.Colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.00f, 1.00f, 1.00f, 0.70f);
style.Colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.20f);
style.Colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.35f);
}
void OrbitalUI::render() {
render_menus();
}
void OrbitalUI::render_menus() {
ImGui::PushFont(font_text);
ImGui::BeginMainMenuBar();
if (ImGui::BeginMenu("File", true)) {
if (ImGui::MenuItem("Open kernel...")) {
// TODO
}
ImGui::Separator();
if (ImGui::MenuItem("Exit", NULL, false, true)) {
SDL_Event quit;
quit.type = SDL_QUIT;
SDL_PushEvent(&quit);
}
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Machine", true)) {
const bool running = true;
if (ImGui::MenuItem("Resume", nullptr, false, !running)) {
// TODO
}
if (ImGui::MenuItem("Pause", nullptr, false, running)) {
// TODO
}
if (ImGui::MenuItem("Reset")) {
// TODO
}
ImGui::Separator();
if (ImGui::MenuItem("Load state")) {
// TODO
}
if (ImGui::MenuItem("Save state")) {
// TODO
}
ImGui::Separator();
if (ImGui::MenuItem("Configuration...")) {
// TODO
}
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Tools", true)) {
ImGui::MenuItem("Statistics", "Alt+1", &show_stats, true);
ImGui::MenuItem("UART Output", "Alt+2", &show_uart, true);
ImGui::MenuItem("GPU Debugger", "Alt+3", &show_gpu_debugger, true);
ImGui::MenuItem("Executing Processes", "Alt+4", &show_executing_processes, true);
ImGui::MenuItem("Process List", "Alt+5", &show_process_list, true);
ImGui::Separator();
ImGui::MenuItem("CP Commands", "Alt+6", &show_trace_cp, false);
ImGui::MenuItem("ICC Commands", "Alt+7", &show_trace_icc, false);
ImGui::MenuItem("SAMU Commands", "Alt+8", &show_trace_samu, false);
ImGui::Separator();
ImGui::MenuItem("Memory Editor (GPA)", "Ctrl+1", &show_mem_gpa, false);
ImGui::MenuItem("Memory Editor (GVA)", "Ctrl+2", &show_mem_gva, false);
ImGui::MenuItem("Memory Editor (GART)", "Ctrl+3", &show_mem_gart, false);
ImGui::MenuItem("Memory Editor (IOMMU)", "Ctrl+4", &show_mem_iommu, false);
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Help", true)) {
if (ImGui::MenuItem("About...", NULL, false, false)) {
// TODO
}
ImGui::EndMenu();
}
ImGui::EndMainMenuBar();
ImGui::PopFont();
}

View file

@ -0,0 +1,50 @@
/**
* Orbital UI renderer for ImGui.
*
* Copyright 2017-2021. Orbital project.
* Released under MIT license. Read LICENSE for more details.
*
* Authors:
* - Alexandro Sanchez Bach <alexandro@phi.nz>
*/
#pragma once
#define IMGUI_IMPL_API
#include <imgui.h>
#include <vector>
class OrbitalUI {
public:
// Initialization
void init();
// Interface
void render();
private:
// Fonts
ImFont* font_default{};
ImFont* font_text{};
ImFont* font_code{};
std::vector<std::uint8_t> font_text_data;
std::vector<std::uint8_t> font_code_data;
// State
bool show_stats;
bool show_uart;
bool show_gpu_debugger;
bool show_executing_processes;
bool show_process_list;
bool show_trace_cp;
bool show_trace_icc;
bool show_trace_samu;
bool show_mem_gpa;
bool show_mem_gva;
bool show_mem_gart;
bool show_mem_iommu;
// Helpers
void render_menus();
};

View file

@ -1,70 +0,0 @@
/**
* Custom ImGui style.
*
* Copyright 2017-2020. Orbital project.
* Released under MIT license. Read LICENSE for more details.
*
* Authors:
* - Alexandro Sanchez Bach <alexandro@phi.nz>
* - Mason Lee Back
*/
#include "ui_style.h"
#define IMGUI_IMPL_API
#include <imgui.h>
void ui_style_initialize() {
auto& style = ImGui::GetStyle();
style.ScaleAllSizes(2);
style.WindowPadding = ImVec2(5, 5);
style.WindowRounding = 0.0f;
style.WindowBorderSize = 1.0f;
style.FramePadding = ImVec2(5, 5);
style.FrameRounding = 2.0f;
style.ItemSpacing = ImVec2(12, 8);
style.ItemInnerSpacing = ImVec2(8, 6);
style.IndentSpacing = 25.0f;
style.ScrollbarSize = 15.0f;
style.ScrollbarRounding = 9.0f;
style.GrabMinSize = 5.0f;
style.GrabRounding = 1.0f;
style.TabRounding = 1.0f;
style.Colors[ImGuiCol_Text] = ImVec4(0.80f, 0.80f, 0.83f, 1.00f);
style.Colors[ImGuiCol_TextDisabled] = ImVec4(0.24f, 0.23f, 0.29f, 1.00f);
style.Colors[ImGuiCol_WindowBg] = ImVec4(0.07f, 0.07f, 0.07f, 1.00f);
style.Colors[ImGuiCol_ChildBg] = ImVec4(0.07f, 0.07f, 0.09f, 1.00f);
style.Colors[ImGuiCol_PopupBg] = ImVec4(0.07f, 0.07f, 0.09f, 1.00f);
style.Colors[ImGuiCol_Border] = ImVec4(0.05f, 0.05f, 0.05f, 0.88f);
style.Colors[ImGuiCol_BorderShadow] = ImVec4(0.92f, 0.91f, 0.88f, 0.00f);
style.Colors[ImGuiCol_FrameBg] = ImVec4(0.10f, 0.09f, 0.12f, 1.00f);
style.Colors[ImGuiCol_FrameBgHovered] = ImVec4(0.24f, 0.23f, 0.29f, 1.00f);
style.Colors[ImGuiCol_FrameBgActive] = ImVec4(0.56f, 0.56f, 0.58f, 1.00f);
style.Colors[ImGuiCol_TitleBg] = ImVec4(0.10f, 0.09f, 0.12f, 1.00f);
style.Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(1.00f, 0.98f, 0.95f, 0.75f);
style.Colors[ImGuiCol_TitleBgActive] = ImVec4(0.07f, 0.07f, 0.09f, 1.00f);
style.Colors[ImGuiCol_MenuBarBg] = ImVec4(0.10f, 0.09f, 0.12f, 1.00f);
style.Colors[ImGuiCol_ScrollbarBg] = ImVec4(0.10f, 0.09f, 0.12f, 1.00f);
style.Colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.80f, 0.80f, 0.83f, 0.31f);
style.Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.56f, 0.56f, 0.58f, 1.00f);
style.Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.06f, 0.05f, 0.07f, 1.00f);
style.Colors[ImGuiCol_CheckMark] = ImVec4(0.80f, 0.80f, 0.83f, 0.31f);
style.Colors[ImGuiCol_SliderGrab] = ImVec4(0.80f, 0.80f, 0.83f, 0.31f);
style.Colors[ImGuiCol_SliderGrabActive] = ImVec4(0.06f, 0.05f, 0.07f, 1.00f);
style.Colors[ImGuiCol_Button] = ImVec4(0.10f, 0.09f, 0.12f, 1.00f);
style.Colors[ImGuiCol_ButtonHovered] = ImVec4(0.24f, 0.23f, 0.29f, 1.00f);
style.Colors[ImGuiCol_ButtonActive] = ImVec4(0.56f, 0.56f, 0.58f, 1.00f);
style.Colors[ImGuiCol_Header] = ImVec4(0.10f, 0.09f, 0.12f, 1.00f);
style.Colors[ImGuiCol_HeaderHovered] = ImVec4(0.56f, 0.56f, 0.58f, 1.00f);
style.Colors[ImGuiCol_HeaderActive] = ImVec4(0.06f, 0.05f, 0.07f, 1.00f);
style.Colors[ImGuiCol_ResizeGrip] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
style.Colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.56f, 0.56f, 0.58f, 1.00f);
style.Colors[ImGuiCol_ResizeGripActive] = ImVec4(0.06f, 0.05f, 0.07f, 1.00f);
style.Colors[ImGuiCol_PlotLines] = ImVec4(0.40f, 0.39f, 0.38f, 0.63f);
style.Colors[ImGuiCol_PlotLinesHovered] = ImVec4(0.25f, 1.00f, 0.00f, 1.00f);
style.Colors[ImGuiCol_PlotHistogram] = ImVec4(0.40f, 0.39f, 0.38f, 0.63f);
style.Colors[ImGuiCol_PlotHistogramHovered] = ImVec4(0.25f, 1.00f, 0.00f, 1.00f);
style.Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.25f, 1.00f, 0.00f, 0.43f);
}

View file

@ -1,14 +0,0 @@
/**
* Custom ImGui style.
*
* Copyright 2017-2020. Orbital project.
* Released under MIT license. Read LICENSE for more details.
*
* Authors:
* - Alexandro Sanchez Bach <alexandro@phi.nz>
* - Mason Lee Back
*/
#pragma once
void ui_style_initialize();