emote2ss

Animated webp to spritesheets converting tool
git clone git://bsandro.tech/emote2ss
Log | Files | Refs | README | LICENSE

commit 7fe61474d8742fbbad4402065d7ad22303c771a0
parent b3ca1887a06544b3d4a0609dc6f91a64fa2d99bf
Author: bsandro <email@bsandro.tech>
Date:   Thu, 17 Aug 2023 02:01:13 +0300

output filename bugfix

Diffstat:
Mgui/main.c | 26++++++++++++++++----------
1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/gui/main.c b/gui/main.c @@ -247,11 +247,13 @@ int ButtonDialogSaveEvent(UIElement *element, UIMessage msg, int di, void *dp) { // get values of path and filename inputs UITextbox *path_input = (UITextbox *)element->parent->children; UITextbox *filename_input = (UITextbox *)path_input->e.next; - printf("path_input: %s\nfilename_input: %s\n", path_input->string, filename_input->string); - int path_len = strlen(path_input->string) + strlen(filename_input->string) + 2; // DIR_SEPARATOR and '\0' + printf("path_input: %p\nfilename_input: %p\n", path_input, filename_input); + printf("path_input: %s(%d)\nfilename_input: %s(%d)\n", path_input->string, strlen(path_input->string), filename_input->string, strlen(filename_input->string)); + int path_len = path_input->bytes + filename_input->bytes + 2; // DIR_SEPARATOR + '\0' printf("path_len: %d\n", path_len); char out_name[path_len]; - int n = snprintf(out_name, PATH_MAX, "%s%c%s", path_input->string, DIR_SEPARATOR, filename_input->string); + out_name[path_len-1] = '\0'; + int n = snprintf(out_name, path_len, "%s%c%s", path_input->string, DIR_SEPARATOR, filename_input->string); printf("strlen(out_name): %d\n", strlen(out_name)); printf("out_name: %s\n", out_name); WebpWrite(out_name, img); @@ -290,9 +292,11 @@ int ButtonCloseEvent(UIElement *element, UIMessage msg, int di, void *dp) { return 0; } -void ShowSaveWindow(UIWindow *parent) { +typedef int (*CallbackFn)(struct UIElement *element, UIMessage message, int di, void *dp); +//@todo title, default filename, callback +void ShowModalWindow(UIWindow *parent, CallbackFn cb) { if (modal_win == NULL) { - printf("create save window\n"); + printf("create modal window\n"); modal_win = UIWindowCreate(parent, NULL, "Save File", 0, 0); modal_win->e.messageUser = WinModalEvent; UIPanel *panel_out = UIPanelCreate(&modal_win->e, UI_PANEL_GRAY|UI_PANEL_EXPAND); @@ -304,13 +308,15 @@ void ShowSaveWindow(UIWindow *parent) { UITextbox *path_input = UITextboxCreate(&panel_top->e, UI_ELEMENT_TAB_STOP|UI_ELEMENT_H_FILL); UITextboxReplace(path_input, img->dirname, -1, false); UITextbox *filename_input = UITextboxCreate(&panel_top->e, UI_ELEMENT_TAB_STOP|UI_ELEMENT_H_FILL); + printf("path_input: %p\nfilename_input: %p\n", path_input, filename_input); char out_name[strlen(img->filename)+7]; int n = snprintf(out_name, NAME_MAX, "atlas_%s", img->filename); assert(n>0); UITextboxReplace(filename_input, out_name, -1, false); UIButton *btn_save = UIButtonCreate(&panel_top->e, UI_ELEMENT_TAB_STOP, "Save", -1); - btn_save->e.messageUser = ButtonDialogSaveEvent; + //btn_save->e.messageUser = ButtonDialogSaveEvent; + btn_save->e.messageUser = cb; UIButton *btn_cancel = UIButtonCreate(&panel_top->e, UI_ELEMENT_TAB_STOP, "Cancel", -1); btn_cancel->e.messageUser = ButtonCloseEvent; @@ -327,7 +333,7 @@ void ShowSaveWindow(UIWindow *parent) { int ButtonSaveEvent(UIElement *element, UIMessage msg, int di, void *dp) { if (msg == UI_MSG_CLICKED) { printf("save button clicked\n"); - ShowSaveWindow(element->window); + ShowModalWindow(element->window, ButtonDialogSaveEvent); } return 0; } @@ -340,7 +346,7 @@ int ButtonOpenEvent(UIElement *element, UIMessage msg, int di, void *dp) { return 0; } -void update_preview(UIImageDisplay *img_disp) { +void PreviewUpdate(UIImageDisplay *img_disp) { // gen new spritesheet and refresh the preview Spritesheet ss = GenSpritesheet(img, cols); //printf("spritesheet width: %d, height: %d, stride: %d, len: %zu\n", ss.width, ss.height, ss.stride, ss.len); @@ -373,7 +379,7 @@ int SliderEvent(UIElement *element, UIMessage msg, int di, void *dp) { if (new_cols > 0 && cols != new_cols) { //printf("new_cols: %d\n", new_cols); cols = new_cols; - update_preview(element->cp); + PreviewUpdate(element->cp); } } @@ -448,7 +454,7 @@ int WinMain(HINSTANCE instance, HINSTANCE previousInstance, LPSTR commandLine, i assert(n>0); printf("[%s/%s -> %s]\ncols: %d\ndimensions: %dx%dpx\nframes: %d\n", img->dirname, img->filename, out_name, cols, img->width, img->height, img->frame_count); - update_preview(img_disp); + PreviewUpdate(img_disp); //@todo cleanup on new image load! //free(img->path);