emote2ss

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

commit d74a4e3bac06ffb9df754d1c61dbe091bf468a23
parent ac14707c5384ded3c6021063937a11e01a74b30e
Author: bsandro <email@bsandro.tech>
Date:   Thu, 10 Apr 2025 22:41:56 +0300

Using bitmap font again

Diffstat:
MTODO | 1+
Mgui/Makefile | 5++++-
Mgui/main.c | 2--
Mgui/ui.c | 32+++++++++++++++++---------------
4 files changed, 22 insertions(+), 18 deletions(-)

diff --git a/TODO b/TODO @@ -16,3 +16,4 @@ - M$ Windows build - Use system open/save dialog on Windows? - Remember last open directory +- Bug: closing the modal window closes the application diff --git a/gui/Makefile b/gui/Makefile @@ -2,7 +2,7 @@ NAME:=emote2ss_gui SRC:=$(wildcard *.c) DEPS:=$(wildcard ../include/*.h) OBJ:=$(SRC:.c=.o) -LIBS:=libwebp libwebpdemux x11 +LIBS:=libwebp libwebpdemux x11 #freetype2 CFLAGS=-O0 -g -std=c99 -DUI_LINUX -ffast-math -I. -I../include/ ${shell pkg-config --cflags $(LIBS)} LDFLAGS=-lc -lm ${shell pkg-config --libs $(LIBS)} @@ -18,3 +18,6 @@ clean: $(NAME): $(OBJ) $(CC) $(OBJ) -o ../$@ $(LDFLAGS) + +run: $(NAME) + ../$(NAME) diff --git a/gui/main.c b/gui/main.c @@ -41,10 +41,8 @@ int main(int argc, const char **argv) { #else int WinMain(HINSTANCE instance, HINSTANCE previousInstance, LPSTR commandLine, int showCommand) { #endif - // just some silly stuff, always wanted to try that prctl(PR_SET_NAME, "webp-anim-to-spritesheet"); - atexit(print_webp_version); UIInitialise(); UIWindow *win = MainWindowCreate("emote2ss", WIN_WIDTH, WIN_HEIGHT); diff --git a/gui/ui.c b/gui/ui.c @@ -34,6 +34,8 @@ static int FilelistCompare(const struct dirent **a, const struct dirent **b) { } UIWindow * MainWindowCreate(const char *wname, int w, int h) { + //UIFont *font = UIFontActivate(UIFontCreate("../font.ttf", 19)); + //assert(font!=NULL); UIWindow *win = UIWindowCreate(0, 0, wname, w, h); win->e.messageUser = WinMainEvent; UIPanel *panelv = UIPanelCreate(&win->e, UI_PANEL_GRAY|UI_PANEL_MEDIUM_SPACING); @@ -58,8 +60,8 @@ UIWindow * MainWindowCreate(const char *wname, int w, int h) { } int WinModalEvent(UIElement *element, UIMessage msg, int di, void *dp) { - if (msg == UI_MSG_DESTROY) { - // printf("modal bye\n"); + if (msg==UI_MSG_DESTROY) { + //printf("modal bye\n"); assert(element==modal_win); modal_win = NULL; } @@ -67,7 +69,7 @@ int WinModalEvent(UIElement *element, UIMessage msg, int di, void *dp) { } int ButtonDialogSaveEvent(UIElement *element, UIMessage msg, int di, void *dp) { - if (msg == UI_MSG_CLICKED) { + if (msg==UI_MSG_CLICKED) { // get values of path and filename inputs UITextbox *path_input = (UITextbox *)element->parent->children; UITextbox *filename_input = (UITextbox *)path_input->e.next; @@ -92,7 +94,7 @@ int ButtonDialogSaveEvent(UIElement *element, UIMessage msg, int di, void *dp) { } int ButtonDialogOpenEvent(UIElement *element, UIMessage msg, int di, void *dp) { - if (msg == UI_MSG_CLICKED) { + 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; @@ -197,14 +199,14 @@ int TableEvent(UIElement *element, UIMessage msg, int di, void *dp) { } int ButtonCloseEvent(UIElement *element, UIMessage msg, int di, void *dp) { - if (msg == UI_MSG_CLICKED) { + if (msg==UI_MSG_CLICKED) { UIElementDestroy(&element->window->e); } return 0; } void ShowModalWindow(UIWindow *parent, const char *def_dir, const char *def_file, CallbackFn cb) { - if (modal_win == NULL) { + if (modal_win==NULL) { // printf("create modal window\n"); int w = UIElementMessage(&parent->e, UI_MSG_GET_WIDTH, 0, 0); int h = UIElementMessage(&parent->e, UI_MSG_GET_HEIGHT, 0, 0); @@ -214,14 +216,14 @@ void ShowModalWindow(UIWindow *parent, const char *def_dir, const char *def_file 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_DISABLED|UI_ELEMENT_H_FILL); - if (def_dir != NULL) { + 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); - if (def_file != NULL) { + if (def_file!=NULL) { UITextboxReplace(filename_input, def_file, -1, false); } @@ -246,7 +248,7 @@ void ShowModalWindow(UIWindow *parent, const char *def_dir, const char *def_file } int ButtonSaveEvent(UIElement *element, UIMessage msg, int di, void *dp) { - if (msg == UI_MSG_CLICKED) { + if (msg==UI_MSG_CLICKED) { // printf("save button clicked\n"); char fname[strlen(img->filename)+7]; int n = snprintf(fname, NAME_MAX, "atlas_%s", img->filename); @@ -257,7 +259,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) { + if (msg==UI_MSG_CLICKED) { // printf("open button clicked\n"); ShowModalWindow(element->window, getenv("HOME"), NULL, ButtonDialogOpenEvent); } @@ -265,13 +267,13 @@ int ButtonOpenEvent(UIElement *element, UIMessage msg, int di, void *dp) { } int SliderEvent(UIElement *element, UIMessage msg, int di, void *dp) { - if (msg == UI_MSG_VALUE_CHANGED) { - if (img == NULL) return 1; + if (msg==UI_MSG_VALUE_CHANGED) { + if (img==NULL) return 1; float slider_pos = ((UISlider *)element)->position; float step = 1.0f / (float)img->frame_count; int new_cols = (int)(slider_pos / step); - if (new_cols > 0 && cols != new_cols) { + if (new_cols>0 && cols!=new_cols) { //printf("new_cols: %d\n", new_cols); cols = new_cols; PreviewUpdate(img, element->cp); @@ -282,8 +284,8 @@ int SliderEvent(UIElement *element, UIMessage msg, int di, void *dp) { } int WinMainEvent(UIElement *element, UIMessage msg, int di, void *dp) { - if (msg == UI_MSG_DESTROY) { - // printf("bye\n"); + if (msg==UI_MSG_DESTROY) { + printf("main win bye\n"); free(img); exit(0); }