102 Patches: Detours to the Rescue
C reference for DttR maintainers and modders.
Loading...
Searching...
No Matches
dttr_imgui.h
Go to the documentation of this file.
1#ifndef DTTR_IMGUI_H
2#define DTTR_IMGUI_H
3
4#include <SDL3/SDL.h>
5#include <cimgui.h>
6#include <cimgui_impl.h>
7#include <cimgui_impl_sdlgpu3.h>
8#include <stdbool.h>
9
10#define DTTR_IMGUI_COLOR_LINK ((ImVec4_c){0.33f, 0.63f, 1.0f, 1.0f})
11#define DTTR_IMGUI_COLOR_STACK_FRAME_BG ((ImVec4_c){0.10f, 0.11f, 0.12f, 1.0f})
12#define DTTR_IMGUI_COLOR_BUTTON_BG ((ImVec4_c){0.184f, 0.204f, 0.227f, 1.0f})
13#define DTTR_IMGUI_COLOR_BUTTON_BG_HOVERED ((ImVec4_c){0.235f, 0.267f, 0.298f, 1.0f})
14#define DTTR_IMGUI_COLOR_BUTTON_BG_ACTIVE ((ImVec4_c){0.145f, 0.165f, 0.188f, 1.0f})
15#define DTTR_IMGUI_COLOR_BUTTON_TEXT ((ImVec4_c){0.91f, 0.90f, 0.87f, 1.0f})
16#define DTTR_IMGUI_SCALE_EPSILON 0.001f
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
27
28static inline float DTTR_ImGui_NormalizeDesktopScale(float scale) {
29 return scale > 0.0f ? scale : 1.0f;
30}
31
32static inline float DTTR_ImGui_GetWindowDesktopScale(SDL_Window *window) {
34 window ? SDL_GetWindowDisplayScale(window) : 0.0f
35 );
36}
37
40) {
42 state && state->initialized ? state->current_scale : 0.0f
43 );
44}
45
46static inline bool DTTR_ImGui_ScaleChanged(float a, float b) {
47 const float delta = a > b ? a - b : b - a;
48 return delta > DTTR_IMGUI_SCALE_EPSILON;
49}
50
53 float scale
54) {
55 if (!state) {
56 return false;
57 }
58
60 ImGuiStyle *style = igGetStyle();
61
62 if (!state->initialized) {
63 state->base_style = *style;
64 state->initialized = true;
65 } else if (!DTTR_ImGui_ScaleChanged(state->current_scale, scale)) {
66 return false;
67 } else {
68 *style = state->base_style;
69 }
70
71 ImGuiStyle_ScaleAllSizes(style, scale);
72 style->FontScaleMain = state->base_style.FontScaleMain * scale;
73 state->current_scale = scale;
74 return true;
75}
76
83
97
100 const char *title,
101 int width,
102 int height
103);
106
110
113 const SDL_Event *event,
114 bool *running
115);
119
122 const char *title,
123 ImGuiWindowFlags flags
124);
126
129 const char *id,
130 const char *label,
131 ImVec2_c size
132);
133void DTTR_ImGuiDialog_CenterNextItem(float item_width);
136 const char *title,
137 const char *version
138);
141 const char *message,
142 float padding_x,
143 float padding_y
144);
147 int width,
148 float padding_y
149);
150
151bool DTTR_ImGui_ErrorShow(const char *title, const char *message);
152
153#ifdef __cplusplus
154}
155
156#endif
157
158#endif // DTTR_IMGUI_H
const DTTR_BackendState * state
void void * ctx
DTTR_Graphics_COM_Direct3DDevice7 void DWORD flags DWORD void DWORD flags
const DWORD size
void void DWORD HANDLE event
void DTTR_ImGuiDialog_End(DTTR_ImGuiDialogContext *ctx)
void DTTR_ImGuiDialog_DrawHeader(const DTTR_ImGuiDialogContext *ctx, const char *title, const char *version)
bool DTTR_ImGui_ErrorShow(const char *title, const char *message)
void DTTR_ImGuiDialog_CenterNextItem(float item_width)
static float DTTR_ImGui_GetCurrentDesktopScale(const DTTR_ImGuiDesktopScaleState *state)
Definition dttr_imgui.h:38
void DTTR_ImGuiDialog_Render(DTTR_ImGuiDialogContext *ctx)
static bool DTTR_ImGui_ScaleChanged(float a, float b)
Definition dttr_imgui.h:46
bool DTTR_ImGuiDialog_RefreshScale(DTTR_ImGuiDialogContext *ctx)
bool DTTR_ImGuiDialog_BeginRoot(DTTR_ImGuiDialogContext *ctx, const char *title, ImGuiWindowFlags flags)
float DTTR_ImGuiDialog_ScaledFloat(const DTTR_ImGuiDialogContext *ctx, float value)
static bool DTTR_ImGui_ApplyWindowDesktopScale(DTTR_ImGuiDesktopScaleState *state, SDL_Window *window)
Definition dttr_imgui.h:77
void DTTR_ImGuiDialog_OffsetCursorY(const DTTR_ImGuiDialogContext *ctx, float amount)
void DTTR_ImGuiDialog_DrawPaddedText(const DTTR_ImGuiDialogContext *ctx, const char *message, float padding_x, float padding_y)
void DTTR_ImGuiDialog_ProcessEvents(const DTTR_ImGuiDialogContext *ctx, bool *running)
static bool DTTR_ImGui_ApplyDesktopScale(DTTR_ImGuiDesktopScaleState *state, float scale)
Definition dttr_imgui.h:51
bool DTTR_ImGuiDialog_Button(const DTTR_ImGuiDialogContext *ctx, const char *id, const char *label, ImVec2_c size)
static float DTTR_ImGui_GetWindowDesktopScale(SDL_Window *window)
Definition dttr_imgui.h:32
void DTTR_ImGuiDialog_EndRoot()
void DTTR_ImGuiDialog_NewFrame(const DTTR_ImGuiDialogContext *ctx)
void DTTR_ImGuiDialog_ProcessEvent(const DTTR_ImGuiDialogContext *ctx, const SDL_Event *event, bool *running)
#define DTTR_IMGUI_SCALE_EPSILON
Definition dttr_imgui.h:16
static float DTTR_ImGui_NormalizeDesktopScale(float scale)
Definition dttr_imgui.h:28
void DTTR_ImGuiDialog_FitWindowToContent(DTTR_ImGuiDialogContext *ctx, int width, float padding_y)
void DTTR_ImGuiDialog_Shutdown()
bool DTTR_ImGuiDialog_Begin(DTTR_ImGuiDialogContext *ctx, const char *title, int width, int height)
union SDL_Event SDL_Event
Definition dttr_mods.h:19
struct SDL_Window SDL_Window
Definition dttr_mods.h:18
SDL_GLContext gl_context
Definition dttr_imgui.h:86
ImGuiContext * imgui_context
Definition dttr_imgui.h:87
ImGuiContext * previous_imgui_context
Definition dttr_imgui.h:88
DTTR_ImGuiDesktopScaleState imgui_scale
Definition dttr_imgui.h:89