mirror of
https://github.com/Polprzewodnikowy/N64FlashcartMenu.git
synced 2024-11-25 03:56:54 +01:00
Add Text viewer (#87)
<!--- Provide a general summary of your changes in the Title above --> ## Description <!--- Describe your changes in detail --> Adds a basic text viewer. It does not (yet) support full file content. superseeds #21 ## Motivation and Context <!--- What does this sample do? What problem does it solve? --> <!--- If it fixes/closes/resolves an open issue, please link to the issue here --> There were too many changes to merge from the original PR. ## How Has This Been Tested? <!-- (if applicable) --> <!--- Please describe in detail how you tested your sample/changes. --> <!--- Include details of your testing environment, and the tests you ran to --> <!--- see how your change affects other areas of the code, etc. --> On an SC64 via devcontainer. ## Screenshots <!-- (if appropriate): --> ## Types of changes <!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [x] Improvement (non-breaking change that adds a new feature) - [ ] Bug fix (fixes an issue) - [ ] Breaking change (breaking change) - [ ] Config and build (change in the configuration and build system, has no impact on code or features) ## Checklist: <!--- Go over all the following points, and put an `x` in all the boxes that apply. --> <!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> - [ ] My code follows the code style of this project. - [ ] My change requires a change to the documentation. - [ ] I have updated the documentation accordingly. - [ ] I have added tests to cover my changes. - [ ] All new and existing tests passed. <!--- It would be nice if you could sign off your contribution by replacing the name with your GitHub user name and GitHub email contact. --> Signed-off-by: GITHUB_USER <GITHUB_USER_EMAIL> --------- Co-authored-by: Mateusz Faderewski <sc@mateuszfaderewski.pl> Co-authored-by: Mateusz Faderewski <polprzewodnikowy@gmail.com>
This commit is contained in:
parent
a2e50a9c82
commit
14e45c0230
1
Makefile
1
Makefile
@ -56,6 +56,7 @@ SRCS = \
|
|||||||
menu/views/fault.c \
|
menu/views/fault.c \
|
||||||
menu/views/file_info.c \
|
menu/views/file_info.c \
|
||||||
menu/views/image_viewer.c \
|
menu/views/image_viewer.c \
|
||||||
|
menu/views/text_viewer.c \
|
||||||
menu/views/load_disk.c \
|
menu/views/load_disk.c \
|
||||||
menu/views/load_emulator.c \
|
menu/views/load_emulator.c \
|
||||||
menu/views/load_rom.c \
|
menu/views/load_rom.c \
|
||||||
|
@ -148,6 +148,7 @@ static view_t menu_views[] = {
|
|||||||
{ MENU_MODE_FILE_INFO, view_file_info_init, view_file_info_display },
|
{ MENU_MODE_FILE_INFO, view_file_info_init, view_file_info_display },
|
||||||
{ MENU_MODE_SYSTEM_INFO, view_system_info_init, view_system_info_display },
|
{ MENU_MODE_SYSTEM_INFO, view_system_info_init, view_system_info_display },
|
||||||
{ MENU_MODE_IMAGE_VIEWER, view_image_viewer_init, view_image_viewer_display },
|
{ MENU_MODE_IMAGE_VIEWER, view_image_viewer_init, view_image_viewer_display },
|
||||||
|
{ MENU_MODE_TEXT_VIEWER, view_text_viewer_init, view_text_viewer_display },
|
||||||
{ MENU_MODE_MUSIC_PLAYER, view_music_player_init, view_music_player_display },
|
{ MENU_MODE_MUSIC_PLAYER, view_music_player_init, view_music_player_display },
|
||||||
{ MENU_MODE_CREDITS, view_credits_init, view_credits_display },
|
{ MENU_MODE_CREDITS, view_credits_init, view_credits_display },
|
||||||
{ MENU_MODE_SETTINGS_EDITOR, view_settings_init, view_settings_display },
|
{ MENU_MODE_SETTINGS_EDITOR, view_settings_init, view_settings_display },
|
||||||
|
@ -29,6 +29,7 @@ typedef enum {
|
|||||||
MENU_MODE_FILE_INFO,
|
MENU_MODE_FILE_INFO,
|
||||||
MENU_MODE_SYSTEM_INFO,
|
MENU_MODE_SYSTEM_INFO,
|
||||||
MENU_MODE_IMAGE_VIEWER,
|
MENU_MODE_IMAGE_VIEWER,
|
||||||
|
MENU_MODE_TEXT_VIEWER,
|
||||||
MENU_MODE_MUSIC_PLAYER,
|
MENU_MODE_MUSIC_PLAYER,
|
||||||
MENU_MODE_CREDITS,
|
MENU_MODE_CREDITS,
|
||||||
MENU_MODE_SETTINGS_EDITOR,
|
MENU_MODE_SETTINGS_EDITOR,
|
||||||
@ -50,6 +51,7 @@ typedef enum {
|
|||||||
ENTRY_TYPE_EMULATOR,
|
ENTRY_TYPE_EMULATOR,
|
||||||
ENTRY_TYPE_SAVE,
|
ENTRY_TYPE_SAVE,
|
||||||
ENTRY_TYPE_IMAGE,
|
ENTRY_TYPE_IMAGE,
|
||||||
|
ENTRY_TYPE_TEXT,
|
||||||
ENTRY_TYPE_MUSIC,
|
ENTRY_TYPE_MUSIC,
|
||||||
ENTRY_TYPE_OTHER,
|
ENTRY_TYPE_OTHER,
|
||||||
} entry_type_t;
|
} entry_type_t;
|
||||||
|
@ -14,6 +14,7 @@ static const char *disk_extensions[] = { "ndd", NULL };
|
|||||||
static const char *emulator_extensions[] = { "nes", "sfc", "smc", "gb", "gbc", "sms", "gg", "sg", NULL };
|
static const char *emulator_extensions[] = { "nes", "sfc", "smc", "gb", "gbc", "sms", "gg", "sg", NULL };
|
||||||
static const char *save_extensions[] = { "sav", NULL }; // TODO: "eep", "sra", "srm", "fla" could be used if transfered from different flashcarts.
|
static const char *save_extensions[] = { "sav", NULL }; // TODO: "eep", "sra", "srm", "fla" could be used if transfered from different flashcarts.
|
||||||
static const char *image_extensions[] = { "png", NULL };
|
static const char *image_extensions[] = { "png", NULL };
|
||||||
|
static const char *text_extensions[] = { "txt", "ini", "yml", "yaml", NULL };
|
||||||
static const char *music_extensions[] = { "mp3", NULL };
|
static const char *music_extensions[] = { "mp3", NULL };
|
||||||
|
|
||||||
|
|
||||||
@ -46,6 +47,10 @@ static int compare_entry (const void *pa, const void *pb) {
|
|||||||
return -1;
|
return -1;
|
||||||
} else if (b->type == ENTRY_TYPE_IMAGE) {
|
} else if (b->type == ENTRY_TYPE_IMAGE) {
|
||||||
return 1;
|
return 1;
|
||||||
|
} else if (a->type == ENTRY_TYPE_TEXT) {
|
||||||
|
return -1;
|
||||||
|
} else if (b->type == ENTRY_TYPE_TEXT) {
|
||||||
|
return 1;
|
||||||
} else if (a->type == ENTRY_TYPE_MUSIC) {
|
} else if (a->type == ENTRY_TYPE_MUSIC) {
|
||||||
return -1;
|
return -1;
|
||||||
} else if (b->type == ENTRY_TYPE_MUSIC) {
|
} else if (b->type == ENTRY_TYPE_MUSIC) {
|
||||||
@ -110,6 +115,8 @@ static bool load_directory (menu_t *menu) {
|
|||||||
entry->type = ENTRY_TYPE_SAVE;
|
entry->type = ENTRY_TYPE_SAVE;
|
||||||
} else if (file_has_extensions(info.fname, image_extensions)) {
|
} else if (file_has_extensions(info.fname, image_extensions)) {
|
||||||
entry->type = ENTRY_TYPE_IMAGE;
|
entry->type = ENTRY_TYPE_IMAGE;
|
||||||
|
} else if (file_has_extensions(info.fname, text_extensions)) {
|
||||||
|
entry->type = ENTRY_TYPE_TEXT;
|
||||||
} else if (file_has_extensions(info.fname, music_extensions)) {
|
} else if (file_has_extensions(info.fname, music_extensions)) {
|
||||||
entry->type = ENTRY_TYPE_MUSIC;
|
entry->type = ENTRY_TYPE_MUSIC;
|
||||||
} else {
|
} else {
|
||||||
@ -297,6 +304,9 @@ static void process (menu_t *menu) {
|
|||||||
case ENTRY_TYPE_IMAGE:
|
case ENTRY_TYPE_IMAGE:
|
||||||
menu->next_mode = MENU_MODE_IMAGE_VIEWER;
|
menu->next_mode = MENU_MODE_IMAGE_VIEWER;
|
||||||
break;
|
break;
|
||||||
|
case ENTRY_TYPE_TEXT:
|
||||||
|
menu->next_mode = MENU_MODE_TEXT_VIEWER;
|
||||||
|
break;
|
||||||
case ENTRY_TYPE_MUSIC:
|
case ENTRY_TYPE_MUSIC:
|
||||||
menu->next_mode = MENU_MODE_MUSIC_PLAYER;
|
menu->next_mode = MENU_MODE_MUSIC_PLAYER;
|
||||||
break;
|
break;
|
||||||
@ -334,6 +344,7 @@ static void draw (menu_t *menu, surface_t *d) {
|
|||||||
case ENTRY_TYPE_ROM: action = "A: Load"; break;
|
case ENTRY_TYPE_ROM: action = "A: Load"; break;
|
||||||
case ENTRY_TYPE_DISK: action = "A: Load"; break;
|
case ENTRY_TYPE_DISK: action = "A: Load"; break;
|
||||||
case ENTRY_TYPE_IMAGE: action = "A: Show"; break;
|
case ENTRY_TYPE_IMAGE: action = "A: Show"; break;
|
||||||
|
case ENTRY_TYPE_TEXT: action = "A: View"; break;
|
||||||
case ENTRY_TYPE_MUSIC: action = "A: Play"; break;
|
case ENTRY_TYPE_MUSIC: action = "A: Play"; break;
|
||||||
default: action = "A: Info"; break;
|
default: action = "A: Info"; break;
|
||||||
}
|
}
|
||||||
|
78
src/menu/views/text_viewer.c
Normal file
78
src/menu/views/text_viewer.c
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
#include <fatfs/ff.h>
|
||||||
|
|
||||||
|
#include "utils/fs.h"
|
||||||
|
#include "views.h"
|
||||||
|
|
||||||
|
static char *file_content;
|
||||||
|
|
||||||
|
static void process (menu_t *menu) {
|
||||||
|
if (menu->actions.back) {
|
||||||
|
menu->next_mode = MENU_MODE_BROWSER;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void draw (menu_t *menu, surface_t *d) {
|
||||||
|
rdpq_attach(d, NULL);
|
||||||
|
|
||||||
|
component_background_draw();
|
||||||
|
|
||||||
|
component_layout_draw();
|
||||||
|
|
||||||
|
component_main_text_draw(
|
||||||
|
ALIGN_CENTER, VALIGN_TOP,
|
||||||
|
"TEXT VIEWER\n"
|
||||||
|
"\n"
|
||||||
|
);
|
||||||
|
|
||||||
|
component_main_text_draw(
|
||||||
|
ALIGN_LEFT, VALIGN_TOP,
|
||||||
|
"\n"
|
||||||
|
"\n"
|
||||||
|
"%s\n",
|
||||||
|
file_content
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
component_actions_bar_text_draw(
|
||||||
|
ALIGN_LEFT, VALIGN_TOP,
|
||||||
|
"\n"
|
||||||
|
"B: Back"
|
||||||
|
);
|
||||||
|
|
||||||
|
rdpq_detach_show();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void view_text_viewer_init (menu_t *menu) {
|
||||||
|
path_t *path = path_clone_push(menu->browser.directory, menu->browser.entry->name);
|
||||||
|
|
||||||
|
uint32_t file_size = file_get_size(path_get(path));
|
||||||
|
|
||||||
|
if (file_size > 1024) { // FIXME: this is just a placeholder until scrolling is implemented.
|
||||||
|
file_size = 1024; // For the moment, we just set it to that, since any more would be a waste.
|
||||||
|
}
|
||||||
|
|
||||||
|
file_content = calloc(file_size, 1);
|
||||||
|
|
||||||
|
// read file content
|
||||||
|
FIL fil;
|
||||||
|
UINT br;
|
||||||
|
|
||||||
|
if (f_open(&fil, strip_sd_prefix(path_get(path)), FA_READ) != FR_OK) {
|
||||||
|
debugf("Error loading file\n");
|
||||||
|
}
|
||||||
|
if (f_read(&fil, file_content, file_size, &br) != FR_OK) {
|
||||||
|
f_close(&fil);
|
||||||
|
debugf("Error loading file content\n");
|
||||||
|
}
|
||||||
|
if (f_close(&fil) != FR_OK) {
|
||||||
|
debugf("Error closing file\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
path_free(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
void view_text_viewer_display (menu_t *menu, surface_t *display) {
|
||||||
|
process(menu);
|
||||||
|
draw(menu, display);
|
||||||
|
}
|
@ -32,6 +32,9 @@ void view_system_info_display (menu_t *menu, surface_t *display);
|
|||||||
void view_image_viewer_init (menu_t *menu);
|
void view_image_viewer_init (menu_t *menu);
|
||||||
void view_image_viewer_display (menu_t *menu, surface_t *display);
|
void view_image_viewer_display (menu_t *menu, surface_t *display);
|
||||||
|
|
||||||
|
void view_text_viewer_init (menu_t *menu);
|
||||||
|
void view_text_viewer_display (menu_t *menu, surface_t *display);
|
||||||
|
|
||||||
void view_music_player_init (menu_t *menu);
|
void view_music_player_init (menu_t *menu);
|
||||||
void view_music_player_display (menu_t *menu, surface_t *display);
|
void view_music_player_display (menu_t *menu, surface_t *display);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user