aboutsummaryrefslogtreecommitdiffstats
path: root/source/player/player_settings.h
blob: 5d873aa2c9654088b5e109db4644b1208df51267 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#ifndef PLAYER_SETTINGS_H
#define PLAYER_SETTINGS_H

// NOTE: every tweakable lives in one plain struct. the ui reads it directly through one pointer
// (ui_settings), so a "setting" costs exactly what a constant used to cost: one load.
//
// the Settings view, editing, h / l adjusting, clamping and saving are all driven by a single
// table of SettingDesc (player_settings.cpp). adding a setting = a field here + one table line.

//- colors

typedef enum UIColor {
	UI_COLOR_BG,
	UI_COLOR_PANEL,
	UI_COLOR_PANEL_EDGE,
	UI_COLOR_FOCUS_EDGE,
	UI_COLOR_TAB,
	UI_COLOR_TAB_ACTIVE,
	UI_COLOR_HEADER,
	UI_COLOR_HOVER,
	UI_COLOR_SELECTED,
	UI_COLOR_ZEBRA,
	UI_COLOR_TEXT,
	UI_COLOR_TEXT_DIM,
	UI_COLOR_TEXT_FAINT,
	UI_COLOR_ACCENT,
	UI_COLOR_TRACK,
	UI_COLOR_DROP,
	UI_COLOR_ON_ACCENT,
	UI_COLOR_MARKED,    // multi selected rows
	UI_COLOR_COUNT,
} UIColor;

typedef enum UIScheme {
	UI_SCHEME_MONO_DARK,
	UI_SCHEME_MONO_LIGHT,
	UI_SCHEME_AMBER,
	UI_SCHEME_PHOSPHOR,
	UI_SCHEME_GRUVBOX,
	UI_SCHEME_NORD,
	UI_SCHEME_SOLARIZED,
	UI_SCHEME_HIGH_CONTRAST,
	UI_SCHEME_CUSTOM, // any color edited by hand
	UI_SCHEME_COUNT,
} UIScheme;

//- fonts
// NOTE: one list of known font files, each font setting is an index into it. entries that aren't
// installed are skipped when cycling and fall back to the first one that is.

typedef struct FontChoice FontChoice;
struct FontChoice {
	const char *name;
	const char *path;
};

#define UI_FONT_CHOICES 20

//- the settings

typedef struct Settings Settings;
struct Settings {
	//- appearance
	f32 zoom;
	u32 scheme;            // UIScheme
	f32 text_gamma;        // glyph coverage curve: < 1 bolder, > 1 thinner
	u32 font_ui;           // FontChoice indices
	u32 font_bold;
	u32 font_mono;
	f32 font_size;
	f32 font_size_small;
	u32 colors[UI_COLOR_COUNT];

	//- layout
	f32 row_height;
	f32 tab_height;
	f32 column_height;
	f32 status_height;
	f32 gap;
	f32 tree_indent;
	b32 show_columns;
	b32 show_scrollbars;
	b32 zebra;
	b32 bold_playing;      // the playing row's name in the bold font

	//- playback
	f32 volume;
	u32 autoplay;          // AutoplayMode
	u32 seek_seconds;
	u32 seek_big;          // { } multiplier

	//- downloads
	u32 jobs;
	b32 confirm_delete;

	//- behaviour
	f32 scroll_speed;      // 0 = instant
	u32 scroll_lines;      // per wheel notch
	u32 double_click_ms;
	f32 message_seconds;

	//- performance
	u32 fps_cap;           // 0 = whatever the compositor asks for
	u32 tick_hz;           // redraws per second while only the playback clock moves
};

typedef enum SettingKind {
	SETTING_KIND_SECTION,
	SETTING_KIND_F32,
	SETTING_KIND_U32,
	SETTING_KIND_BOOL,
	SETTING_KIND_ENUM,   // u32 holding an index into names
	SETTING_KIND_CHOICE, // u32 holding one of `values`, shown as `names`
	SETTING_KIND_COLOR,
	SETTING_KIND_FONT,
	SETTING_KIND_ACTION,
	SETTING_KIND_INFO,
} SettingKind;

typedef enum SettingAction {
	SETTING_ACTION_NONE,
	SETTING_ACTION_RESET_LAYOUT,
	SETTING_ACTION_RESET_SETTINGS,
	SETTING_ACTION_RESET_COLORS,
	SETTING_INFO_FRAME,
	SETTING_INFO_ON_DISK,
	SETTING_INFO_DATA_DIR,
	SETTING_INFO_RELOADS,
} SettingAction;

typedef struct SettingDesc SettingDesc;
struct SettingDesc {
	u8           kind;   // SettingKind
	const char  *name;   // also the key it's saved under
	u32          offset; // into Settings
	f32          min, max, step;
	const char **names;  // enum / choice labels
	const u32   *values; // choice values
	u32          count;
	u32          action; // SettingAction for actions and info rows
	const char  *note;
};

// NOTE: the pointer every theme lookup goes through. set at the top of each ui frame (the hot
// reloaded .so has its own copy of this global) and once by the host.
global_variable Settings *ui_settings = 0;
// NOTE: a by-value copy taken at the top of every ui frame. the theme macros read this one: a
// fixed address, one load instead of pointer then field, and stores through other pointers
// during the frame can't make the compiler reload through ui_settings
global_variable Settings ui_theme = {};

internal void        settings_default(Settings *settings);
internal void        settings_apply_scheme(Settings *settings, u32 scheme);
internal void        settings_clamp(Settings *settings);
internal u32         settings_desc_count(void);
internal SettingDesc *settings_desc(u32 index);
internal String8     settings_format(Arena *arena, Settings *settings, SettingDesc *desc);
internal void        settings_adjust(Settings *settings, SettingDesc *desc, s32 direction);
internal b32         settings_parse(Settings *settings, SettingDesc *desc, const char *text);
internal b32         settings_set(Settings *settings, const char *assignment); // "name=value"
internal String8     settings_serialize(Arena *arena, Settings *settings);
internal void        settings_deserialize(Settings *settings, String8 data);
internal const FontChoice *font_choice(u32 index);

#endif // PLAYER_SETTINGS_H