-
Notifications
You must be signed in to change notification settings - Fork 224
/
theme.c
343 lines (293 loc) · 11.4 KB
/
theme.c
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
/*
VitaShell
Copyright (C) 2015-2018, TheFloW
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "main.h"
#include "init.h"
#include "file.h"
#include "config.h"
#include "theme.h"
#include "utils.h"
INCLUDE_EXTERN_RESOURCE(default_colors_txt);
INCLUDE_EXTERN_RESOURCE(default_archive_icon_png);
INCLUDE_EXTERN_RESOURCE(default_audio_icon_png);
INCLUDE_EXTERN_RESOURCE(default_battery_bar_charge_png);
INCLUDE_EXTERN_RESOURCE(default_battery_bar_green_png);
INCLUDE_EXTERN_RESOURCE(default_battery_bar_red_png);
INCLUDE_EXTERN_RESOURCE(default_battery_png);
INCLUDE_EXTERN_RESOURCE(default_cover_png);
INCLUDE_EXTERN_RESOURCE(default_fastforward_png);
INCLUDE_EXTERN_RESOURCE(default_fastrewind_png);
INCLUDE_EXTERN_RESOURCE(default_file_icon_png);
INCLUDE_EXTERN_RESOURCE(default_file_symlink_icon_png);
INCLUDE_EXTERN_RESOURCE(default_folder_icon_png);
INCLUDE_EXTERN_RESOURCE(default_folder_symlink_icon_png);
INCLUDE_EXTERN_RESOURCE(default_ftp_png);
INCLUDE_EXTERN_RESOURCE(default_image_icon_png);
INCLUDE_EXTERN_RESOURCE(default_pause_png);
INCLUDE_EXTERN_RESOURCE(default_play_png);
INCLUDE_EXTERN_RESOURCE(default_sfo_icon_png);
INCLUDE_EXTERN_RESOURCE(default_text_icon_png);
// Shell colors
int BACKGROUND_COLOR;
int TITLE_COLOR;
int PATH_COLOR;
int DATE_TIME_COLOR;
// Settings color
int SETTINGS_MENU_COLOR;
int SETTINGS_MENU_FOCUS_COLOR;
int SETTINGS_MENU_TITLE_COLOR;
int SETTINGS_MENU_ITEM_COLOR;
int SETTINGS_MENU_OPTION_COLOR;
// File browser colors
int FOCUS_COLOR;
int FILE_COLOR;
int FILE_SYMLINK_COLOR;
int FOLDER_SYMLINK_COLOR;
int SFO_COLOR;
int TXT_COLOR;
int FOLDER_COLOR;
int IMAGE_COLOR;
int ARCHIVE_COLOR;
int SCROLL_BAR_COLOR;
int SCROLL_BAR_BG_COLOR;
int MARKED_COLOR;
// Context menu colors
int CONTEXT_MENU_TEXT_COLOR;
int CONTEXT_MENU_FOCUS_COLOR;
int CONTEXT_MENU_COLOR;
int CONTEXT_MENU_MORE_COLOR;
int INVISIBLE_COLOR;
// Dialog colors
int DIALOG_COLOR;
int DIALOG_BG_COLOR;
int PROGRESS_BAR_COLOR;
int PROGRESS_BAR_BG_COLOR;
// Hex editor colors
int HEX_COLOR;
int HEX_OFFSET_COLOR;
int HEX_NIBBLE_COLOR;
// Text editor colors
int TEXT_COLOR;
int TEXT_FOCUS_COLOR;
int TEXT_LINE_NUMBER_COLOR;
int TEXT_LINE_NUMBER_COLOR_FOCUS;
int TEXT_HIGHLIGHT_COLOR;
// Photo viewer colors
int PHOTO_ZOOM_COLOR;
// Audio player colors
int AUDIO_INFO_ASSIGN;
int AUDIO_INFO;
int AUDIO_SPEED;
int AUDIO_TIME_CURRENT;
int AUDIO_TIME_SLASH;
int AUDIO_TIME_TOTAL;
int AUDIO_TIME_BAR;
int AUDIO_TIME_BAR_BG;
vita2d_texture *folder_icon = NULL, *folder_symlink_icon = NULL, *file_icon = NULL,*file_symlink_icon = NULL, *archive_icon =NULL, *image_icon = NULL,
*audio_icon = NULL, *sfo_icon = NULL, *text_icon = NULL,
*ftp_image = NULL, *dialog_image = NULL, *context_image = NULL, *context_more_image = NULL, *settings_image = NULL, *battery_image = NULL,
*battery_bar_red_image = NULL, *battery_bar_green_image = NULL, *battery_bar_charge_image = NULL, *bg_browser_image = NULL, *bg_hex_image = NULL, *bg_text_image = NULL,
*bg_photo_image = NULL, *bg_audio_image = NULL, *cover_image = NULL, *play_image = NULL, *pause_image = NULL, *fastforward_image = NULL, *fastrewind_image = NULL;
vita2d_texture *wallpaper_image;
vita2d_texture *previous_wallpaper_image = NULL, *current_wallpaper_image = NULL;
vita2d_pgf *font = NULL;
char font_size_cache[256];
typedef struct {
char *name;
void *default_buf;
vita2d_texture **texture;
} ThemeImage;
ThemeImage theme_images[] = {
{ "archive_icon.png", &_binary_resources_default_archive_icon_png_start, &archive_icon },
{ "audio_icon.png", &_binary_resources_default_audio_icon_png_start, &audio_icon },
{ "battery.png", &_binary_resources_default_battery_png_start, &battery_image },
{ "battery_bar_charge.png", &_binary_resources_default_battery_bar_charge_png_start, &battery_bar_charge_image },
{ "battery_bar_green.png", &_binary_resources_default_battery_bar_green_png_start, &battery_bar_green_image },
{ "battery_bar_red.png", &_binary_resources_default_battery_bar_red_png_start, &battery_bar_red_image },
{ "bg_audioplayer.png", NULL, &bg_audio_image },
{ "bg_browser.png", NULL, &bg_browser_image },
{ "bg_hexeditor.png", NULL, &bg_hex_image },
{ "bg_photoviewer.png", NULL, &bg_photo_image },
{ "bg_texteditor.png", NULL, &bg_text_image },
{ "context.png", NULL, &context_image },
{ "context_more.png", NULL, &context_more_image },
{ "cover.png", &_binary_resources_default_cover_png_start, &cover_image },
{ "dialog.png", NULL, &dialog_image },
{ "fastforward.png", &_binary_resources_default_fastforward_png_start, &fastforward_image },
{ "fastrewind.png", &_binary_resources_default_fastrewind_png_start, &fastrewind_image },
{ "file_icon.png", &_binary_resources_default_file_icon_png_start, &file_icon },
{ "file_symlink_icon.png", &_binary_resources_default_file_symlink_icon_png_start,
&file_symlink_icon },
{ "folder_icon.png", &_binary_resources_default_folder_icon_png_start, &folder_icon },
{ "folder_symlink_icon.png", &_binary_resources_default_folder_symlink_icon_png_start,
&folder_symlink_icon },
{ "ftp.png", &_binary_resources_default_ftp_png_start, &ftp_image },
{ "image_icon.png", &_binary_resources_default_image_icon_png_start, &image_icon },
{ "pause.png", &_binary_resources_default_pause_png_start, &pause_image },
{ "play.png", &_binary_resources_default_play_png_start, &play_image },
{ "settings.png", NULL, &settings_image },
{ "sfo_icon.png", &_binary_resources_default_sfo_icon_png_start, &sfo_icon },
{ "text_icon.png", &_binary_resources_default_text_icon_png_start, &text_icon },
{ "wallpaper.png", NULL, &wallpaper_image },
};
#define N_THEME_IMAGES (sizeof(theme_images) / sizeof(ThemeImage))
void loadTheme() {
#define COLOR_ENTRY(name) { #name, CONFIG_TYPE_HEXDECIMAL, (void *)&name }
ConfigEntry colors_entries[] = {
// Shell colors
COLOR_ENTRY(BACKGROUND_COLOR),
COLOR_ENTRY(TITLE_COLOR),
COLOR_ENTRY(PATH_COLOR),
COLOR_ENTRY(DATE_TIME_COLOR),
// Settings colors
COLOR_ENTRY(SETTINGS_MENU_COLOR),
COLOR_ENTRY(SETTINGS_MENU_FOCUS_COLOR),
COLOR_ENTRY(SETTINGS_MENU_TITLE_COLOR),
COLOR_ENTRY(SETTINGS_MENU_ITEM_COLOR),
COLOR_ENTRY(SETTINGS_MENU_OPTION_COLOR),
// File browser colors
COLOR_ENTRY(FOCUS_COLOR),
COLOR_ENTRY(FILE_COLOR),
COLOR_ENTRY(FILE_SYMLINK_COLOR),
COLOR_ENTRY(FOLDER_SYMLINK_COLOR),
COLOR_ENTRY(SFO_COLOR),
COLOR_ENTRY(TXT_COLOR),
COLOR_ENTRY(FOLDER_COLOR),
COLOR_ENTRY(IMAGE_COLOR),
COLOR_ENTRY(ARCHIVE_COLOR),
COLOR_ENTRY(SCROLL_BAR_COLOR),
COLOR_ENTRY(SCROLL_BAR_BG_COLOR),
COLOR_ENTRY(MARKED_COLOR),
// Context menu colors
COLOR_ENTRY(CONTEXT_MENU_TEXT_COLOR),
COLOR_ENTRY(CONTEXT_MENU_FOCUS_COLOR),
COLOR_ENTRY(CONTEXT_MENU_COLOR),
COLOR_ENTRY(CONTEXT_MENU_MORE_COLOR),
COLOR_ENTRY(INVISIBLE_COLOR),
// Dialog colors
COLOR_ENTRY(DIALOG_COLOR),
COLOR_ENTRY(DIALOG_BG_COLOR),
COLOR_ENTRY(PROGRESS_BAR_COLOR),
COLOR_ENTRY(PROGRESS_BAR_BG_COLOR),
// Hex editor colors
COLOR_ENTRY(HEX_COLOR),
COLOR_ENTRY(HEX_OFFSET_COLOR),
COLOR_ENTRY(HEX_NIBBLE_COLOR),
// Text editor colors
COLOR_ENTRY(TEXT_COLOR),
COLOR_ENTRY(TEXT_FOCUS_COLOR),
COLOR_ENTRY(TEXT_LINE_NUMBER_COLOR),
COLOR_ENTRY(TEXT_LINE_NUMBER_COLOR_FOCUS),
COLOR_ENTRY(TEXT_HIGHLIGHT_COLOR),
// Photo viewer colors
COLOR_ENTRY(PHOTO_ZOOM_COLOR),
// Audio player colors
COLOR_ENTRY(AUDIO_INFO_ASSIGN),
COLOR_ENTRY(AUDIO_INFO),
COLOR_ENTRY(AUDIO_SPEED),
COLOR_ENTRY(AUDIO_TIME_CURRENT),
COLOR_ENTRY(AUDIO_TIME_SLASH),
COLOR_ENTRY(AUDIO_TIME_TOTAL),
COLOR_ENTRY(AUDIO_TIME_BAR),
COLOR_ENTRY(AUDIO_TIME_BAR_BG),
};
int i;
// Load default config file
readConfigBuffer(&_binary_resources_default_colors_txt_start, (int)&_binary_resources_default_colors_txt_size,
colors_entries, sizeof(colors_entries) / sizeof(ConfigEntry));
// Load custom config file
if (use_custom_config) {
char path[MAX_PATH_LENGTH];
char *theme_name = NULL;
ConfigEntry theme_entries[] = {
{ "THEME_NAME", CONFIG_TYPE_STRING, (void *)&theme_name },
};
// Load theme config
readConfig("ux0:VitaShell/theme/theme.txt", theme_entries, sizeof(theme_entries) / sizeof(ConfigEntry));
if (theme_name) {
// Load colors config
snprintf(path, MAX_PATH_LENGTH, "ux0:VitaShell/theme/%s/colors.txt", theme_name);
readConfig(path, colors_entries, sizeof(colors_entries) / sizeof(ConfigEntry));
// Font
snprintf(path, MAX_PATH_LENGTH, "ux0:VitaShell/theme/%s/font.pgf", theme_name);
font = vita2d_load_custom_pgf(path);
// Load theme
for (i = 0; i < N_THEME_IMAGES; i++) {
snprintf(path, MAX_PATH_LENGTH, "ux0:VitaShell/theme/%s/%s", theme_name, theme_images[i].name);
if (theme_images[i].texture && *(theme_images[i].texture) == NULL)
*(theme_images[i].texture) = vita2d_load_PNG_file(path);
}
}
}
// Load default theme
for (i = 0; i < N_THEME_IMAGES; i++) {
if (theme_images[i].texture && *(theme_images[i].texture) == NULL && theme_images[i].default_buf)
*(theme_images[i].texture) = vita2d_load_PNG_buffer(theme_images[i].default_buf);
}
// Load default pngs
if (!dialog_image) {
dialog_image = vita2d_create_empty_texture(SCREEN_WIDTH, SCREEN_HEIGHT);
void *data = vita2d_texture_get_datap(dialog_image);
int y;
for (y = 0; y < SCREEN_HEIGHT; y++) {
int x;
for (x = 0; x < SCREEN_WIDTH; x++) {
((uint32_t *)data)[x + SCREEN_WIDTH * y] = DIALOG_BG_COLOR;
}
}
}
if (!context_image) {
context_image = vita2d_create_empty_texture(SCREEN_WIDTH, SCREEN_HEIGHT);
void *data = vita2d_texture_get_datap(context_image);
int y;
for (y = 0; y < SCREEN_HEIGHT; y++) {
int x;
for (x = 0; x < SCREEN_WIDTH; x++) {
((uint32_t *)data)[x + SCREEN_WIDTH * y] = CONTEXT_MENU_COLOR;
}
}
}
if (!context_more_image) {
context_more_image = vita2d_create_empty_texture(SCREEN_WIDTH, SCREEN_HEIGHT);
void *data = vita2d_texture_get_datap(context_more_image);
int y;
for (y = 0; y < SCREEN_HEIGHT; y++) {
int x;
for (x = 0; x < SCREEN_WIDTH; x++) {
((uint32_t *)data)[x + SCREEN_WIDTH * y] = CONTEXT_MENU_MORE_COLOR;
}
}
}
if (!settings_image) {
settings_image = vita2d_create_empty_texture(SCREEN_WIDTH, SCREEN_HEIGHT);
void *data = vita2d_texture_get_datap(settings_image);
int y;
for (y = 0; y < SCREEN_HEIGHT; y++) {
int x;
for (x = 0; x < SCREEN_WIDTH; x++) {
((uint32_t *)data)[x + SCREEN_WIDTH * y] = SETTINGS_MENU_COLOR;
}
}
}
// Load system fonts
if (!font)
font = loadSystemFonts();
// Font size cache
for (i = 0; i < 256; i++) {
char character[2];
character[0] = i;
character[1] = '\0';
font_size_cache[i] = pgf_text_width(character);
}
}