ougge/src/GUI/MainWindow.hpp
2024-08-08 18:03:20 +03:00

50 lines
1.2 KiB
C++

#pragma once
#include <SDL.h>
#include <imgui.h>
#include "../std.hpp"
#include "../time.hpp"
/// converts hex color to float vector
#define RGBAHexToF(R8,G8,B8,A8) ImVec4(((u8)35)/255.0f, ((u8)35)/255.0f, ((u8)50)/255.0f, ((u8)255)/255.0f)
/// converts float vector to hex color
#define RGBAFToHex(VEC4) {(u8)(VEC4.x*255), (u8)(VEC4.y*255), (u8)(VEC4.z*255), (u8)(VEC4.w*255)}
namespace ougge::GUI {
#define default_font "DroidSans"
using UpdatingFunc = void (*)(f64 deltaTime);
class MainWindow {
public:
ImVec4 clear_color = RGBAHexToF(35,35,50,255);
f32 default_font_size = 14.0f;
int fps_max = 60;
// called on each frame
UpdatingFunc update = nullptr;
private:
bool loop_running = false;
bool show_demo_window = false;
bool show_metrics_window = false;
SDL_Window* sdl_window = nullptr;
SDL_Renderer* sdl_renderer = nullptr;
public:
void open(const char* window_title, UpdatingFunc update);
void startUpdateLoop();
void close();
private:
void destroy();
f32 getDPI();
void poll_events(bool waitForEvent);
void draw_frame();
void draw_ui();
void draw_debug_window();
void draw_bg_window();
};
}