102 Patches: Detours to the Rescue
C reference for DttR maintainers and modders.
Loading...
Searching...
No Matches
gui_internal.h
Go to the documentation of this file.
1#ifndef DTTR_CONFIG_TOOL_INTERNAL_H
2#define DTTR_CONFIG_TOOL_INTERNAL_H
3
4#include <dttr_config.h>
5#include <dttr_imgui.h>
6#include <dttr_path.h>
7#include <dttr_sdl.h>
8
9#include <SDL3/SDL.h>
10
11#include <stdbool.h>
12#include <stdio.h>
13#include <string.h>
14
15#define DTTR_CONFIG_UI_WINDOW_H 550
16#define DTTR_CONFIG_UI_LABEL_W 170.0f
17#define DTTR_CONFIG_UI_INPUT_W 285.0f
18#define DTTR_CONFIG_UI_PATH_INPUT_W 160.0f
19#define DTTR_CONFIG_UI_PATH_BUTTON_W 70.0f
20#define DTTR_CONFIG_UI_GAMEPAD_SOURCE_W 135.0f
21#define DTTR_CONFIG_UI_GAMEPAD_BUTTON_W 58.0f
22#define DTTR_CONFIG_UI_PANEL_PADDING_X 7.5f
23#define DTTR_CONFIG_UI_PANEL_PADDING_Y 14.0f
24#define DTTR_CONFIG_UI_ITEM_SPACING_X 8.0f
25#define DTTR_CONFIG_UI_ITEM_SPACING_Y 6.0f
26#define DTTR_CONFIG_UI_TABLE_CELL_PADDING_X 8.0f
27#define DTTR_CONFIG_UI_TABLE_CELL_PADDING_Y 4.0f
28#define DTTR_CONFIG_UI_HEADER_TEXT_INSET_X 2.0f
29#define DTTR_CONFIG_UI_COMBO_POPUP_PADDING_Y 0.0f
30#define DTTR_CONFIG_UI_SECTION_SPACING 10.0f
31#define DTTR_CONFIG_UI_LABEL_TEXT_COLOR ((ImVec4_c){0.72f, 0.50f, 0.95f, 1.0f})
32#define DTTR_CONFIG_UI_CHANGED_LABEL_TEXT_COLOR ((ImVec4_c){1.0f, 0.82f, 0.25f, 1.0f})
33#define DTTR_CONFIG_UI_SAVED_CHANGED_LABEL_TEXT_COLOR \
34 ((ImVec4_c){0.48f, 0.78f, 1.0f, 1.0f})
35#define DTTR_CONFIG_UI_TOOLTIP_DEFAULT_TEXT_COLOR ((ImVec4_c){0.48f, 0.90f, 0.48f, 1.0f})
36#define DTTR_CONFIG_UI_SELECTED_TAB_BG ((ImVec4_c){0.115f, 0.130f, 0.150f, 1.0f})
37#define DTTR_CONFIG_UI_BORDER_COLOR ((ImVec4_c){0.105f, 0.115f, 0.125f, 1.0f})
38#define DTTR_CONFIG_UI_TABLE_BORDER_COLOR ((ImVec4_c){0.135f, 0.145f, 0.155f, 1.0f})
39#define DTTR_CONFIG_UI_SEPARATOR_COLOR ((ImVec4_c){0.120f, 0.130f, 0.140f, 1.0f})
40#define DTTR_CONFIG_UI_PATH_BUTTON_SPACING 4.0f
41#define DTTR_CONFIG_UI_STATUS_TEXT_COLOR ((ImVec4_c){1.0f, 0.82f, 0.25f, 1.0f})
42#define DTTR_CONFIG_UI_HINT_TEXT_COLOR ((ImVec4_c){0.72f, 0.74f, 0.78f, 1.0f})
43#define DTTR_CONFIG_UI_WARNING_TEXT_COLOR ((ImVec4_c){1.0f, 0.55f, 0.18f, 1.0f})
44#define DTTR_CONFIG_UI_STATUS_TIMEOUT_MS 5000
45#define DTTR_CONFIG_UI_HEADER_TOP_SPACING 0.0f
46#define DTTR_CONFIG_UI_TOOLTIP_PADDING_Y 4.0f
47#define DTTR_CONFIG_UI_TOOLTIP_WRAP_W 360.0f
48
49#define CONFIG_TABLE_FLAGS \
50 (ImGuiTableFlags_BordersInnerH | ImGuiTableFlags_BordersOuterH \
51 | ImGuiTableFlags_SizingStretchProp | ImGuiTableFlags_NoSavedSettings \
52 | ImGuiTableFlags_PadOuterX)
53
54#ifndef DTTR_VERSION
55#define DTTR_VERSION "unknown"
56#endif
57
63
77
78#define FIELD_DIFFERS(state, base, field) \
79 (memcmp(&(state)->config.field, &(state)->base.field, sizeof((state)->config.field)) \
80 != 0)
81#define FIELD_UNSAVED(state, field) FIELD_DIFFERS(state, saved_config, field)
82#define FIELD_DEFAULT_CHANGED(state, field) FIELD_DIFFERS(state, defaults, field)
83#define PATH_FIELD_DIFFERS(state, base, field) \
84 (!DTTR_Path_MatchesNormalized((state)->config.field, (state)->base.field))
85#define PATH_FIELD_UNSAVED(state, field) PATH_FIELD_DIFFERS(state, saved_config, field)
86#define PATH_FIELD_DEFAULT_CHANGED(state, field) \
87 PATH_FIELD_DIFFERS(state, defaults, field)
88#define FIELD_LABEL_STATE(state, field) \
89 make_config_label_state( \
90 FIELD_UNSAVED(state, field), \
91 FIELD_DEFAULT_CHANGED(state, field) \
92 )
93#define PATH_FIELD_LABEL_STATE(state, field) \
94 make_config_label_state( \
95 PATH_FIELD_UNSAVED(state, field), \
96 PATH_FIELD_DEFAULT_CHANGED(state, field) \
97 )
98
103
104void set_status(config_ui_state *state, const char *status);
109int gamepad_button_row_action(int row);
110const char *gamepad_button_row_label(int row);
112const char *game_action_tooltip(int action);
117config_label_state make_config_label_state(bool unsaved_changed, bool default_changed);
120 const config_ui_state *state,
121 int source,
122 int action
123);
125
126bool choice_combo(
127 const char *label,
128 int *value,
129 DTTR_ConfigChoiceList choices,
130 const char *const *tooltips
131);
132void show_tooltip(const char *text);
135 const char *id,
136 const char *label,
137 float width
138);
139void push_config_theme();
140void pop_config_theme();
144);
148);
152void end_padded_panel();
155 const char *id,
156 float label_width,
157 float input_width,
158 float table_width
159);
162 const char *id,
163 float label_width,
164 float input_width
165);
166void end_settings_table();
169void begin_setting_row();
170float table_input_width(const DTTR_ImGuiDialogContext *ctx, float input_width);
171float path_text_input_width(const DTTR_ImGuiDialogContext *ctx, int button_count);
173 const char *label,
174 const char *tooltip,
175 config_label_state label_state
176);
179 const char *label,
180 const char *id,
181 char *buf,
182 size_t buf_size,
183 const char *tooltip,
184 config_label_state label_state
185);
189 const char *label,
190 const char *id,
191 char *buf,
192 size_t buf_size,
193 const char *tooltip,
194 config_label_state label_state
195);
199 const char *label,
200 const char *id,
201 char *buf,
202 size_t buf_size,
203 const char *tooltip,
204 config_label_state label_state
205);
208 const char *label,
209 const char *id,
210 int *value,
211 int step,
212 int step_fast,
213 const char *tooltip,
214 config_label_state label_state
215);
218 const char *label,
219 const char *id,
220 float *value,
221 const char *tooltip,
222 config_label_state label_state
223);
226 const char *label,
227 const char *id,
228 bool *value,
229 const char *tooltip,
230 config_label_state label_state
231);
234 const char *label,
235 const char *id,
236 int *value,
237 DTTR_ConfigChoiceList choices,
238 const char *const *tooltips,
239 const char *tooltip,
240 config_label_state label_state
241);
242
246
247const char *source_label(int source);
248const char *source_tooltip(int source);
252void capture_source(config_ui_state *state, int new_source);
255 const char *id,
256 float input_width
257);
264
265#endif
const DTTR_BackendState * state
void void * ctx
void void DWORD HANDLE event
#define DTTR_GAMEPAD_SOURCE_COUNT
Definition dttr_config.h:53
DTTR_ConfigChoiceList
union SDL_Event SDL_Event
Definition dttr_mods.h:20
static game_data_source source
Definition game_data.c:21
void capture_source(config_ui_state *state, int new_source)
Definition gui_state.c:149
float path_text_input_width(const DTTR_ImGuiDialogContext *ctx, int button_count)
const char * source_tooltip(int source)
bool gamepad_button_rows_have_unsaved_changes(const config_ui_state *state)
Definition gui_state.c:254
void load_config(config_ui_state *state)
Definition gui_state.c:185
bool choice_combo(const char *label, int *value, DTTR_ConfigChoiceList choices, const char *const *tooltips)
Definition gui_widgets.c:68
int gamepad_default_source_for_action(const config_ui_state *state, int action)
Definition gui_state.c:88
void set_mods_dir_from_config_path(config_ui_state *state)
Definition gui_state.c:101
bool begin_settings_table_with_width(const DTTR_ImGuiDialogContext *ctx, const char *id, float label_width, float input_width, float table_width)
float table_input_width(const DTTR_ImGuiDialogContext *ctx, float input_width)
bool begin_padded_panel(const DTTR_ImGuiDialogContext *ctx)
bool labeled_input_float(const DTTR_ImGuiDialogContext *ctx, const char *label, const char *id, float *value, const char *tooltip, config_label_state label_state)
const char * source_label(int source)
config_label_state
@ CONFIG_LABEL_DEFAULT
@ CONFIG_LABEL_SAVED_CHANGED
@ CONFIG_LABEL_UNSAVED
bool themed_row_button(const DTTR_ImGuiDialogContext *ctx, const char *id, const char *label, float width)
void sync_config_from_rows(config_ui_state *state)
Definition gui_state.c:172
config_label_state make_config_label_state(bool unsaved_changed, bool default_changed)
Definition gui_state.c:246
void same_path_button_row(const DTTR_ImGuiDialogContext *ctx)
Definition gui_widgets.c:5
bool begin_gamepad_button_table(const DTTR_ImGuiDialogContext *ctx)
const char * gamepad_button_row_label(int row)
Definition gui_state.c:83
bool config_has_unsaved_changes(const config_ui_state *state)
Definition gui_state.c:286
bool labeled_input_int(const DTTR_ImGuiDialogContext *ctx, const char *label, const char *id, int *value, int step, int step_fast, const char *tooltip, config_label_state label_state)
bool labeled_checkbox(const DTTR_ImGuiDialogContext *ctx, const char *label, const char *id, bool *value, const char *tooltip, config_label_state label_state)
bool begin_settings_table(const DTTR_ImGuiDialogContext *ctx, const char *id, float label_width, float input_width)
void save_config(config_ui_state *state)
Definition gui_state.c:205
bool begin_config_content_region(const DTTR_ImGuiDialogContext *ctx, const config_ui_state *state)
void draw_config_label(const char *label, const char *tooltip, config_label_state label_state)
void draw_tabs(const DTTR_ImGuiDialogContext *ctx, config_ui_state *state)
Definition gui_tabs.c:31
void draw_general_tab(const DTTR_ImGuiDialogContext *ctx, config_ui_state *state)
void show_tooltip(const char *text)
void add_scaled_vertical_spacing(const DTTR_ImGuiDialogContext *ctx, float height)
Definition gui_widgets.c:12
void draw_footer_text(const DTTR_ImGuiDialogContext *ctx, const config_ui_state *state)
void pop_config_theme()
void draw_audio_tab(const DTTR_ImGuiDialogContext *ctx, config_ui_state *state)
void begin_config_table_row()
void sync_rows_from_config(config_ui_state *state)
Definition gui_state.c:117
void begin_setting_row()
void end_settings_table()
void cancel_binding(config_ui_state *state)
Definition gui_state.c:140
int source_from_event(const SDL_Event *event)
void draw_gamepad_tab(const DTTR_ImGuiDialogContext *ctx, config_ui_state *state)
int gamepad_button_row_action(int row)
Definition gui_state.c:78
void request_reset_defaults(const DTTR_ImGuiDialogContext *ctx, config_ui_state *state)
Definition gui_state.c:223
void open_log_file_dialog(const DTTR_ImGuiDialogContext *ctx, config_ui_state *state)
bool labeled_log_path_picker(const DTTR_ImGuiDialogContext *ctx, config_ui_state *state, const char *label, const char *id, char *buf, size_t buf_size, const char *tooltip, config_label_state label_state)
int config_window_width()
Definition gui_widgets.c:50
float config_standard_input_width()
Definition gui_widgets.c:36
bool begin_tab_settings_table(const DTTR_ImGuiDialogContext *ctx, const char *id, float input_width)
Definition gui_tabs.c:13
bool event_cancels_binding(const SDL_Event *event)
Definition gui_state.c:135
bool labeled_input_text(const DTTR_ImGuiDialogContext *ctx, const char *label, const char *id, char *buf, size_t buf_size, const char *tooltip, config_label_state label_state)
int gamepad_button_row_count()
Definition gui_state.c:65
void open_pcdogs_iso_dialog(const DTTR_ImGuiDialogContext *ctx, config_ui_state *state)
Definition gui_dialogs.c:96
void push_config_theme()
config_label_state gamepad_button_label_state(const config_ui_state *state, int source, int action)
Definition gui_state.c:269
void end_config_content_region()
void end_padded_panel()
bool labeled_path_picker(const DTTR_ImGuiDialogContext *ctx, config_ui_state *state, const char *label, const char *id, char *buf, size_t buf_size, const char *tooltip, config_label_state label_state)
void open_pcdogs_dir_dialog(const DTTR_ImGuiDialogContext *ctx, config_ui_state *state)
Definition gui_dialogs.c:85
bool labeled_choice_combo(const DTTR_ImGuiDialogContext *ctx, const char *label, const char *id, int *value, DTTR_ConfigChoiceList choices, const char *const *tooltips, const char *tooltip, config_label_state label_state)
void draw_modding_tab(const DTTR_ImGuiDialogContext *ctx, config_ui_state *state)
void reset_defaults(config_ui_state *state)
Definition gui_state.c:217
void set_status(config_ui_state *state, const char *status)
Definition gui_state.c:96
const char * game_action_tooltip(int action)
Definition gui_state.c:26
float config_footer_height(const DTTR_ImGuiDialogContext *ctx, const config_ui_state *state)
void draw_graphics_tab(const DTTR_ImGuiDialogContext *ctx, config_ui_state *state)
Uint64 status_expires_at_ms
int button_actions[DTTR_GAMEPAD_SOURCE_COUNT]
char path[MAX_PATH]
DTTR_Config saved_config
int button_sources[DTTR_GAMEPAD_SOURCE_COUNT]
DTTR_Config defaults
DTTR_Config config
char status[256]
char mods_dir[MAX_PATH]