-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathvtree.h
More file actions
268 lines (240 loc) · 11.2 KB
/
Copy pathvtree.h
File metadata and controls
268 lines (240 loc) · 11.2 KB
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
#ifndef VTREE_H
#define VTREE_H
#include <SDL2/SDL.h>
#include <SDL2/SDL_ttf.h>
#include <SDL2/SDL_image.h>
#include <stdbool.h>
#define MAX_PATH 1024
#define MAX_FILES 1000 // imgview sibling cap — do not remove
#define FILES_INIT_CAP 512
#define MAX_CLIPBOARD 100
#define GLYPH_CACHE_SIZE 128
#define THEME_PRESET_COUNT 1 // only the built-in Dark fallback lives in C now
typedef enum {
MODE_EXPLORER,
MODE_CONTEXT_MENU,
MODE_SETTINGS,
MODE_OSK,
MODE_VIEW_CHOOSE, // "Open as: Text / Hex / Cancel" picker
MODE_VIEW_TEXT, // text viewer / editor
MODE_VIEW_HEX, // hex viewer / editor
MODE_VIEW_IMAGE, // image viewer
MODE_SNAKE, // easter egg
} AppMode;
typedef enum { OP_NONE, OP_COPY, OP_CUT } FileOp;
typedef enum { OSK_LOWER, OSK_UPPER, OSK_SPECIAL, OSK_LAYER_COUNT } OSKLayer;
typedef enum { OSK_FOR_RENAME, OSK_FOR_TEXT_EDIT, OSK_FOR_NEW_FILE, OSK_FOR_NEW_DIR, OSK_FOR_SETTINGS_PATH, OSK_FOR_TV_SEARCH } OSKPurpose;
typedef struct {
char buf[256]; // text buffer
int len; // strlen(buf)
int cursor; // insertion point (0..len), caret position
bool insert_mode; // true = insert (default), false = overwrite
bool kb_visible; // keyboard grid visible (can be toggled)
int scroll_x; // horizontal pixel scroll offset for input field
int row, col; // grid focus: row 0..OSK_CHAR_ROWS-1 or OSK_CHAR_ROWS (action)
char orig_name[256];
char dir_path[MAX_PATH];
OSKLayer layer;
} OSKState;
extern OSKState osk;
extern OSKPurpose osk_purpose;
typedef struct { char name[256]; bool is_dir; bool is_link; bool marked; long long size; } FileEntry;
typedef struct { char current_path[MAX_PATH]; FileEntry *files; int file_capacity, file_count, selected_index, scroll_offset; } AppState;
typedef struct {
SDL_Color bg, alt_bg, header_bg, text, text_disabled, link, highlight_bg, highlight_text, marked;
SDL_Color menu_bg;
SDL_Color menu_border;
// Hex-viewer byte-category colours (optional per theme; fallback = built-in Dark values)
SDL_Color hex_zero; // 0x00 — null bytes
SDL_Color hex_ctrl; // 0x01–0x1F — control codes
SDL_Color hex_space; // 0x20 — space character
SDL_Color hex_punct; // punctuation / symbols
SDL_Color hex_digit; // 0x30–0x39 — ASCII digits
SDL_Color hex_letter; // A–Z, a–z — ASCII letters
SDL_Color hex_high; // 0x80–0xFE — high/non-ASCII bytes
SDL_Color hex_full; // 0xFF — all-ones byte
} Theme;
// ---------------------------------------------------------------------------
// Named theme loaded from file (config.ini [Theme.Name] or theme.ini)
// ---------------------------------------------------------------------------
#define MAX_NAMED_THEMES 32
#define MAX_THEME_NAME 64
typedef struct {
char name[MAX_THEME_NAME];
Theme colors;
} NamedTheme;
extern NamedTheme named_themes[MAX_NAMED_THEMES];
extern int named_theme_count;
extern int current_named_theme; // index into named_themes[], -1 = custom
typedef struct {
int screen_w, screen_h;
int font_size_list, font_size_header, font_size_footer, font_size_menu;
int font_size_hex; // independent font size for the hex viewer
char start_left[MAX_PATH], start_right[MAX_PATH];
char gamecontrollerdb[MAX_PATH]; // path to gamecontrollerdb.txt; "" = use CWD default
Theme theme;
// Explorer / global keys
SDL_GameControllerButton k_confirm, k_back, k_menu, k_mark;
SDL_GameControllerButton k_pgup, k_pgdn; // page up / page down in file manager + viewers
SDL_GameControllerButton k_menu2; // system menu key (Settings/About/Exit) in two-menu mode
// OSK-specific keys (independent, fully rebindable)
SDL_GameControllerButton osk_k_type; // press selected key (default: a)
SDL_GameControllerButton osk_k_bksp; // backspace at cursor (default: x)
SDL_GameControllerButton osk_k_shift; // cycle layer (default: y)
SDL_GameControllerButton osk_k_cancel; // cancel OSK (default: b)
SDL_GameControllerButton osk_k_toggle; // show / hide keyboard (default: back)
SDL_GameControllerButton osk_k_ins; // toggle insert/overwrite (default: leftshoulder)
// Extra file-type extensions (appended to built-in lists at runtime)
#define MAX_EXTRA_EXTS 64
#define MAX_EXT_LEN 16
char font_path[MAX_PATH]; // basename of active font file (e.g. "font.ttf")
char extra_image_exts[MAX_EXTRA_EXTS][MAX_EXT_LEN];
int extra_image_ext_count;
char extra_text_exts[MAX_EXTRA_EXTS][MAX_EXT_LEN];
int extra_text_ext_count;
bool show_hidden; // show dotfiles / hidden entries
bool remember_dirs; // save pane paths on exit and restore on next launch
bool exec_scripts; // allow executing .sh files (experimental)
bool single_pane; // show only one full-width pane instead of the split view
bool paste_to_opposite; // skip dest dialog and always paste into the non-active pane
bool two_menu_mode; // k_menu goes to file-ops directly; k_menu2 opens system menu
bool tint_icons; // tint file-list icons to match their row's theme colour
bool ui_sounds; // play subtle programmatic UI sounds
int rotation; // display rotation: 0=none, 1=90°CW, 2=180°, 3=270°CW
char language_name[64]; // display name of the active language (e.g. "English")
// Keyboard input mode (--keyb flag): use SDL_KEYDOWN instead of gamepad events
bool keyboard_mode;
SDL_Keycode kbd_k_confirm, kbd_k_back, kbd_k_menu, kbd_k_mark;
SDL_Keycode kbd_k_pgup, kbd_k_pgdn, kbd_k_menu2;
SDL_Keycode kbd_k_x; // maps to SDL_CONTROLLER_BUTTON_X (osk_bksp / imgview zoom-out)
SDL_Keycode kbd_k_start; // maps to SDL_CONTROLLER_BUTTON_START (osk_ins)
char kbd_label_confirm[32], kbd_label_back[32], kbd_label_menu[32], kbd_label_mark[32];
char kbd_label_pgup[32], kbd_label_pgdn[32], kbd_label_menu2[32];
char kbd_label_x[32], kbd_label_start[32];
} AppConfig;
typedef struct {
char text[MAX_PATH];
TTF_Font *font;
SDL_Color color;
SDL_Texture *texture;
int w, h;
Uint32 last_used;
} GlyphEntry;
extern GlyphEntry glyph_cache[GLYPH_CACHE_SIZE];
extern Uint32 glyph_frame;
extern AppConfig cfg;
extern AppState panes[2];
extern int active_pane;
extern AppMode current_mode;
extern bool debug_mode;
extern FILE *debug_log_file;
void vtree_log(const char *fmt, ...);
extern bool delete_confirm_active;
extern int settings_index;
extern char configfile[MAX_PATH];
// Legacy single-preset name table (just "Dark" now; kept so settings UI compiles)
extern const char *theme_preset_names[THEME_PRESET_COUNT];
extern int current_theme_preset; // -1 = custom/none
typedef struct {
char src_paths[MAX_CLIPBOARD][MAX_PATH];
char names[MAX_CLIPBOARD][256];
int count;
FileOp op;
} Clipboard;
extern Clipboard clip;
// Paste progress — written by paste_thread_fn/copy_file_data, read by render thread
extern volatile bool paste_abort;
extern volatile long long paste_bytes_done;
extern volatile long long paste_bytes_total;
extern volatile int paste_files_done; // individual files completed (not clipboard items)
extern volatile int paste_files_total; // total files to copy (counted before copy starts)
extern char paste_prog_name[MAX_PATH]; // current filename being copied (updated per-file)
extern char paste_copy_root[MAX_PATH]; // src root for computing relative display paths
// config.c
void load_config();
void save_config();
void apply_theme_preset(int idx); // applies named_themes[idx]
// fileop.c
void load_dir(int p_idx, const char *path);
int copy_path(const char *src, const char *dest);
int delete_path(const char *path);
int count_files(const char *path);
char *trim(char *str);
void format_size(long long bytes, char *out);
void join_path(char *out, const char *dir, const char *name);
void copy_str(char *dst, const char *src, size_t dst_size); // safe, always-terminating strncpy replacement
// lang.c — i18n
#include "lang.h"
// main.c
void destroy_glyph_cache();
void draw_txt(TTF_Font *f, const char *txt, int x, int y, SDL_Color col);
void draw_txt_clipped(TTF_Font *f, const char *txt, int x, int y, int max_w, SDL_Color col);
extern SDL_Renderer *renderer;
extern SDL_Window *window;
extern SDL_GameController *pad;
extern TTF_Font *font_list, *font_header, *font_footer, *font_menu, *font_hex;
extern char vtree_font_path[MAX_PATH]; // full resolved path of the active font file
extern char vtree_exe_dir[MAX_PATH]; // directory containing the vtree binary
extern Uint32 glyph_frame;
// File-type icon textures (NULL = not loaded, fall back to tex_file)
extern SDL_Texture *tex_file, *tex_folder, *tex_img, *tex_txt, *tex_dirup;
// viewer.c — text viewer / editor
void viewer_open(const char *path);
void viewer_close(void);
void viewer_osk_commit(const char *new_text);
bool viewer_osk_is_pending(void);
int viewer_osk_line_index(void);
const char *viewer_get_line(int idx);
void viewer_handle_button(SDL_GameControllerButton btn, bool *dpad_up_held, bool *dpad_down_held,
bool *dpad_left_held, bool *dpad_right_held, Uint32 now);
void viewer_handle_repeat(Uint32 now);
void viewer_draw(void);
bool viewer_search_osk_is_pending(void);
const char *viewer_search_current_query(void);
void viewer_search_commit(const char *query);
// hexview.c — hex viewer / editor
void hexview_open(const char *path);
void hexview_close(void);
void hexview_handle_button(SDL_GameControllerButton btn, bool *dpad_up_held, bool *dpad_down_held,
bool *dpad_left_held, bool *dpad_right_held, Uint32 now);
void hexview_handle_repeat(Uint32 now);
void hexview_draw(void);
// keyboard.c — on-screen keyboard
const char *btn_label(SDL_GameControllerButton btn);
void osk_init_common(void);
void osk_enter(const char *dir, const char *filename);
void osk_enter_tv(const char *line_text);
void osk_enter_search(const char *query);
void osk_enter_new(const char *dir, bool is_dir);
void osk_enter_path(char *target, const char *current_val);
extern char *osk_path_target;
void osk_type(char ch);
void osk_backspace(void);
void osk_cycle_layer(void);
void osk_press(void);
void osk_move(int dr, int dc);
void osk_cursor_left(void);
void osk_cursor_right(void);
void osk_confirm(void);
void draw_osk(void);
// ui_audio.c — UI sound effects
void ui_audio_open(void);
void ui_audio_close(void);
void ui_sound_navigate(void);
void ui_sound_confirm(void);
void ui_sound_back(void);
void ui_sound_mark(void);
void ui_sound_tab(void);
void ui_sound_osk_type(void);
void ui_sound_osk_bksp(void);
// snake.c — easter egg
void snake_enter(void);
void snake_handle_button(SDL_GameControllerButton btn);
void snake_tick(Uint32 now);
void snake_draw(void);
// imgview.c — image viewer
void imgview_open(const char *path);
void imgview_close(void);
void imgview_handle_button(SDL_GameControllerButton btn, Uint32 now);
void imgview_draw(void);
#endif