emote2ss

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

commit e7da0f9bfb9bcbb8284552715c35a98050f924da
parent 7fe61474d8742fbbad4402065d7ad22303c771a0
Author: bsandro <email@bsandro.tech>
Date:   Mon, 21 Aug 2023 00:59:36 +0300

Open File dialog skeleton

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

diff --git a/gui/main.c b/gui/main.c @@ -249,7 +249,7 @@ int ButtonDialogSaveEvent(UIElement *element, UIMessage msg, int di, void *dp) { UITextbox *filename_input = (UITextbox *)path_input->e.next; 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' + int path_len = path_input->bytes + filename_input->bytes + 2; // DIR_SEPARATOR and '\0' printf("path_len: %d\n", path_len); char out_name[path_len]; out_name[path_len-1] = '\0'; @@ -265,6 +265,19 @@ int ButtonDialogSaveEvent(UIElement *element, UIMessage msg, int di, void *dp) { return 0; } +int ButtonDialogOpenEvent(UIElement *element, UIMessage msg, int di, void *dp) { + if (msg == UI_MSG_CLICKED) { + printf("open dialog window close\n"); + UITextbox *path_input = (UITextbox *)element->parent->children; + UITextbox *filename_input = (UITextbox *)path_input->e.next; + 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)); + + UIElementDestroy(element->window); + } + return 0; +} + int TableEvent(UIElement *element, UIMessage msg, int di, void *dp) { static int selected = -1; if (msg == UI_MSG_TABLE_GET_ITEM) { @@ -293,38 +306,40 @@ int ButtonCloseEvent(UIElement *element, UIMessage msg, int di, void *dp) { } typedef int (*CallbackFn)(struct UIElement *element, UIMessage message, int di, void *dp); -//@todo title, default filename, callback -void ShowModalWindow(UIWindow *parent, CallbackFn cb) { + +void ShowModalWindow(UIWindow *parent, const char *def_dir, const char *def_file, CallbackFn cb) { if (modal_win == NULL) { printf("create modal window\n"); - modal_win = UIWindowCreate(parent, NULL, "Save File", 0, 0); + modal_win = UIWindowCreate(parent, NULL, def_file?"Save File":"Open File", 0, 0); modal_win->e.messageUser = WinModalEvent; UIPanel *panel_out = UIPanelCreate(&modal_win->e, UI_PANEL_GRAY|UI_PANEL_EXPAND); - UILabel *lbl_title = UILabelCreate(&panel_out->e, 0, "Save File", -1); + UILabel *lbl_title = UILabelCreate(&panel_out->e, 0, def_file?"Save File":"Open File", -1); UIPanel *panel_top = UIPanelCreate(&panel_out->e, UI_PANEL_GRAY|UI_PANEL_MEDIUM_SPACING|UI_PANEL_HORIZONTAL); UITextbox *path_input = UITextboxCreate(&panel_top->e, UI_ELEMENT_TAB_STOP|UI_ELEMENT_H_FILL); - UITextboxReplace(path_input, img->dirname, -1, false); + if (def_dir != NULL) { + UITextboxReplace(path_input, def_dir, -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); + if (def_file != NULL) { + UITextboxReplace(filename_input, def_file, -1, false); + } - UIButton *btn_save = UIButtonCreate(&panel_top->e, UI_ELEMENT_TAB_STOP, "Save", -1); - //btn_save->e.messageUser = ButtonDialogSaveEvent; + UIButton *btn_save = UIButtonCreate(&panel_top->e, UI_ELEMENT_TAB_STOP, def_file?"Save":"Open", -1); btn_save->e.messageUser = cb; UIButton *btn_cancel = UIButtonCreate(&panel_top->e, UI_ELEMENT_TAB_STOP, "Cancel", -1); btn_cancel->e.messageUser = ButtonCloseEvent; - UITable *table = UITableCreate(&panel_out->e, UI_ELEMENT_V_FILL, "Directory"); + /*UITable *table = UITableCreate(&panel_out->e, UI_ELEMENT_V_FILL, "Directory"); table->itemCount = 100; table->e.messageUser = TableEvent; - UITableResizeColumns(table); + UITableResizeColumns(table);*/ } else { UIElementFocus(modal_win); } @@ -333,7 +348,10 @@ void ShowModalWindow(UIWindow *parent, CallbackFn cb) { int ButtonSaveEvent(UIElement *element, UIMessage msg, int di, void *dp) { if (msg == UI_MSG_CLICKED) { printf("save button clicked\n"); - ShowModalWindow(element->window, ButtonDialogSaveEvent); + char fname[strlen(img->filename)+7]; + int n = snprintf(fname, NAME_MAX, "atlas_%s", img->filename); + assert(n>0); + ShowModalWindow(element->window, img->dirname, fname, ButtonDialogSaveEvent); } return 0; } @@ -341,7 +359,7 @@ int ButtonSaveEvent(UIElement *element, UIMessage msg, int di, void *dp) { int ButtonOpenEvent(UIElement *element, UIMessage msg, int di, void *dp) { if (msg == UI_MSG_CLICKED) { printf("open button clicked\n"); - //ShowLoadWindow(element->window); + ShowModalWindow(element->window, getenv("HOME"), NULL, ButtonDialogOpenEvent); } return 0; }