N64FlashcartMenu/src/menu/path.c

144 lines
3.6 KiB
C
Raw Normal View History

New browser view using rdpq acceleration + MP3 player (#10) <!--- Provide a general summary of your changes in the Title above --> ## Description This change replaces deprecated graphics libdragon api with rdpq hardware accelerated drawing calls. New view has been added: MP3 player <!--- Describe your changes in detail --> ## Motivation and Context Use newest and supported features of libdragon api <!--- What does this sample do? What problem does it solve? --> <!--- If it fixes/closes/resolves an open issue, please link to the issue here --> ## How Has This Been Tested? On hardware with SC64 flashcart <!-- (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. --> ## Screenshots ![Screenshot 2023-07-08 23-57-56](https://github.com/Polprzewodnikowy/N64FlashcartMenu/assets/3756990/3f791246-5f70-43d1-8c54-aeac62513ff3) ![Screenshot 2023-07-08 23-58-16](https://github.com/Polprzewodnikowy/N64FlashcartMenu/assets/3756990/fdf436bf-6201-4b43-bebc-70be993ebc50) ## Types of changes <!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [ ] Improvement (non-breaking change that adds a new feature) - [ ] Bug fix (fixes an issue) - [x] 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! --> - [x] My code follows the code style of this project. - [x] 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>
2023-07-09 00:01:41 +02:00
#include <assert.h>
2023-07-02 21:52:58 +02:00
#include <stdlib.h>
#include <string.h>
New browser view using rdpq acceleration + MP3 player (#10) <!--- Provide a general summary of your changes in the Title above --> ## Description This change replaces deprecated graphics libdragon api with rdpq hardware accelerated drawing calls. New view has been added: MP3 player <!--- Describe your changes in detail --> ## Motivation and Context Use newest and supported features of libdragon api <!--- What does this sample do? What problem does it solve? --> <!--- If it fixes/closes/resolves an open issue, please link to the issue here --> ## How Has This Been Tested? On hardware with SC64 flashcart <!-- (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. --> ## Screenshots ![Screenshot 2023-07-08 23-57-56](https://github.com/Polprzewodnikowy/N64FlashcartMenu/assets/3756990/3f791246-5f70-43d1-8c54-aeac62513ff3) ![Screenshot 2023-07-08 23-58-16](https://github.com/Polprzewodnikowy/N64FlashcartMenu/assets/3756990/fdf436bf-6201-4b43-bebc-70be993ebc50) ## Types of changes <!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [ ] Improvement (non-breaking change that adds a new feature) - [ ] Bug fix (fixes an issue) - [x] 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! --> - [x] My code follows the code style of this project. - [x] 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>
2023-07-09 00:01:41 +02:00
2023-07-02 21:52:58 +02:00
#include "path.h"
#define PATH_CAPACITY_INITIAL 255
#define PATH_CAPACITY_ALIGNMENT 32
static void path_resize (path_t *path, size_t min_length) {
path->capacity = min_length > PATH_CAPACITY_INITIAL ? min_length : PATH_CAPACITY_INITIAL;
size_t alignment = path->capacity % PATH_CAPACITY_ALIGNMENT;
if (alignment != (PATH_CAPACITY_ALIGNMENT - 1)) {
path->capacity += PATH_CAPACITY_ALIGNMENT - alignment;
}
path->buffer = realloc(path->buffer, (path->capacity + 1) * sizeof(char));
New browser view using rdpq acceleration + MP3 player (#10) <!--- Provide a general summary of your changes in the Title above --> ## Description This change replaces deprecated graphics libdragon api with rdpq hardware accelerated drawing calls. New view has been added: MP3 player <!--- Describe your changes in detail --> ## Motivation and Context Use newest and supported features of libdragon api <!--- What does this sample do? What problem does it solve? --> <!--- If it fixes/closes/resolves an open issue, please link to the issue here --> ## How Has This Been Tested? On hardware with SC64 flashcart <!-- (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. --> ## Screenshots ![Screenshot 2023-07-08 23-57-56](https://github.com/Polprzewodnikowy/N64FlashcartMenu/assets/3756990/3f791246-5f70-43d1-8c54-aeac62513ff3) ![Screenshot 2023-07-08 23-58-16](https://github.com/Polprzewodnikowy/N64FlashcartMenu/assets/3756990/fdf436bf-6201-4b43-bebc-70be993ebc50) ## Types of changes <!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [ ] Improvement (non-breaking change that adds a new feature) - [ ] Bug fix (fixes an issue) - [x] 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! --> - [x] My code follows the code style of this project. - [x] 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>
2023-07-09 00:01:41 +02:00
assert(path->buffer != NULL);
2023-07-02 21:52:58 +02:00
}
static path_t *path_create (char *string) {
2023-07-02 21:52:58 +02:00
if (string == NULL) {
string = "";
}
path_t *path = calloc(1, sizeof(path_t));
New browser view using rdpq acceleration + MP3 player (#10) <!--- Provide a general summary of your changes in the Title above --> ## Description This change replaces deprecated graphics libdragon api with rdpq hardware accelerated drawing calls. New view has been added: MP3 player <!--- Describe your changes in detail --> ## Motivation and Context Use newest and supported features of libdragon api <!--- What does this sample do? What problem does it solve? --> <!--- If it fixes/closes/resolves an open issue, please link to the issue here --> ## How Has This Been Tested? On hardware with SC64 flashcart <!-- (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. --> ## Screenshots ![Screenshot 2023-07-08 23-57-56](https://github.com/Polprzewodnikowy/N64FlashcartMenu/assets/3756990/3f791246-5f70-43d1-8c54-aeac62513ff3) ![Screenshot 2023-07-08 23-58-16](https://github.com/Polprzewodnikowy/N64FlashcartMenu/assets/3756990/fdf436bf-6201-4b43-bebc-70be993ebc50) ## Types of changes <!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [ ] Improvement (non-breaking change that adds a new feature) - [ ] Bug fix (fixes an issue) - [x] 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! --> - [x] My code follows the code style of this project. - [x] 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>
2023-07-09 00:01:41 +02:00
assert(path != NULL);
2023-07-02 21:52:58 +02:00
path_resize(path, strlen(string));
memset(path->buffer, 0, path->capacity + 1);
strcpy(path->buffer, string);
path->root = path->buffer;
return path;
}
static void path_append (path_t *path, char *string) {
size_t buffer_length = strlen(path->buffer);
size_t string_length = strlen(string);
size_t new_path_length = buffer_length + string_length;
if (new_path_length > path->capacity) {
path_resize(path, new_path_length);
}
strcat(path->buffer, string);
}
path_t *path_init (char *prefix, char *string) {
path_t *path = path_create(prefix);
size_t prefix_length = strlen(prefix);
if ((prefix_length > 0) && (prefix[prefix_length - 1] == '/')) {
path->root = path->buffer + prefix_length - 1;
} else {
path->root = path->buffer + prefix_length;
path_append(path, "/");
}
path_push(path, string);
2023-07-02 21:52:58 +02:00
return path;
}
void path_free (path_t *path) {
if (path != NULL) {
free(path->buffer);
free(path);
}
2023-07-02 21:52:58 +02:00
}
path_t *path_clone (path_t *path) {
path_t *cloned = path_create(path->buffer);
cloned->root = cloned->buffer + (path->root - path->buffer);
return cloned;
}
path_t *path_clone_push (path_t *path, char *string) {
path_t *cloned = path_clone(path);
path_push(cloned, string);
return cloned;
2023-07-02 21:52:58 +02:00
}
char *path_get (path_t *path) {
return path->buffer;
}
char *path_last_get (path_t *path) {
char *last_slash = strrchr(path->root, '/');
return (last_slash == NULL) ? path->root : (last_slash + 1);
2023-07-02 21:52:58 +02:00
}
New browser view using rdpq acceleration + MP3 player (#10) <!--- Provide a general summary of your changes in the Title above --> ## Description This change replaces deprecated graphics libdragon api with rdpq hardware accelerated drawing calls. New view has been added: MP3 player <!--- Describe your changes in detail --> ## Motivation and Context Use newest and supported features of libdragon api <!--- What does this sample do? What problem does it solve? --> <!--- If it fixes/closes/resolves an open issue, please link to the issue here --> ## How Has This Been Tested? On hardware with SC64 flashcart <!-- (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. --> ## Screenshots ![Screenshot 2023-07-08 23-57-56](https://github.com/Polprzewodnikowy/N64FlashcartMenu/assets/3756990/3f791246-5f70-43d1-8c54-aeac62513ff3) ![Screenshot 2023-07-08 23-58-16](https://github.com/Polprzewodnikowy/N64FlashcartMenu/assets/3756990/fdf436bf-6201-4b43-bebc-70be993ebc50) ## Types of changes <!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [ ] Improvement (non-breaking change that adds a new feature) - [ ] Bug fix (fixes an issue) - [x] 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! --> - [x] My code follows the code style of this project. - [x] 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>
2023-07-09 00:01:41 +02:00
bool path_is_root (path_t *path) {
return (strcmp(path->root, "/") == 0);
2023-07-02 21:52:58 +02:00
}
void path_pop (path_t *path) {
if (path_is_root(path)) {
return;
}
char *last_slash = strrchr(path->root, '/');
if (last_slash == path->root) {
*(last_slash + 1) = '\0';
} else if (last_slash != NULL) {
2023-07-02 21:52:58 +02:00
*last_slash = '\0';
}
}
void path_push (path_t *path, char *string) {
if (path->buffer[strlen(path->buffer) - 1] != '/') {
path_append(path, "/");
}
if (string[0] == '/') {
string += 1;
}
path_append(path, string);
}
void path_push_subdir (path_t *path, char *string) {
char *file = path_last_get(path);
char *tmp = alloca(strlen(file) + 1);
strcpy(tmp, file);
path_pop(path);
path_push(path, string);
path_push(path, tmp);
}
2023-07-02 21:52:58 +02:00
char *path_ext_get (path_t *path) {
char *buffer = path_last_get(path);
char *last_dot = strrchr(buffer, '.');
if (last_dot != NULL) {
return last_dot + 1;
}
return NULL;
}
void path_ext_remove (path_t *path) {
char *buffer = path_last_get(path);
char *last_dot = strrchr(buffer, '.');
if (last_dot != NULL) {
*last_dot = '\0';
}
}
void path_ext_replace (path_t *path, char *ext) {
path_ext_remove(path);
path_append(path, ".");
path_append(path, ext);
}