commit c09ec60905efc97bdac7010df7e67d0d60be0bf5
parent 1ca256bd293ecdac07e55ffeba030406e17ce6a3
Author: bsandro <[email protected]>
Date: Mon, 7 Aug 2023 02:25:22 +0300
Figured out some panel inner workings, added couple of new buttons and started reworking the overall layout.
Diffstat:
M | TODO | | | 4 | ++-- |
M | gui/main.c | | | 58 | +++++++++++++++++++++++++++++++++++++++++----------------- |
2 files changed, 43 insertions(+), 19 deletions(-)
diff --git a/TODO b/TODO
@@ -1,5 +1,5 @@
-- Decide on GUI toolkit
-- Build GUI with a selector of columns count and real time preview of the resulting spritesheet
- Add 'debug' and 'release' builds into makefile
- Wrap errors into sane messages and not just asserts
- Support drag-n-drop for GUI version
+- Implement file open/save window
+- i18n
diff --git a/gui/main.c b/gui/main.c
@@ -55,6 +55,7 @@ typedef struct {
frame_t *frames;
uint32_t frame_count;
void *raw_mem;
+ char *path;
} animation_t;
// let it be global variable for now
@@ -226,9 +227,22 @@ spritesheet_t gen_spritesheet(animation_t *img, int cols) {
return ss;
}
+int ButtonSaveEvent(UIElement *element, UIMessage msg, int di, void *dp) {
+ (void)di;
+ (void)dp;
+ if (msg == UI_MSG_CLICKED) {
+ printf("save\n");
+ }
+
+ return 0;
+}
+
int ButtonCloseEvent(UIElement *element, UIMessage msg, int di, void *dp) {
+ (void)di;
+ (void)dp;
if (msg == UI_MSG_CLICKED) {
printf("bye\n");
+ free(img);
exit(0);
}
@@ -269,6 +283,8 @@ void update_preview(UIImageDisplay *img_disp) {
}
int SliderEvent(UIElement *element, UIMessage msg, int di, void *dp) {
+ (void)di;
+ (void)dp;
if (msg == UI_MSG_VALUE_CHANGED) {
float slider_pos = ((UISlider *)element)->position;
float step = 1.0f / (float)img->frame_count;
@@ -287,17 +303,23 @@ int main(int argc, const char **argv) {
atexit(print_webp_version);
UIInitialise();
- UIWindow *win = UIWindowCreate(0, 0, "emote2ss gui", 800, 600);
- UIPanel *panel = UIPanelCreate(&win->e, UI_PANEL_GRAY|UI_PANEL_MEDIUM_SPACING);
- UILabel *label = UILabelCreate(&panel->e, 0, "webp to spritesheet converter", -1);
- UISlider *slider = UISliderCreate(&panel->e, 0);
- UIImageDisplay *img_disp = UIImageDisplayCreate(&panel->e, UI_ELEMENT_V_FILL|UI_ELEMENT_H_FILL|UI_IMAGE_DISPLAY_INTERACTIVE|_UI_IMAGE_DISPLAY_ZOOM_FIT, NULL, 0, 0, 0);
+ UIWindow *win = UIWindowCreate(0, 0, "emote2ss gui", 0, 0);
+ UIPanel *panelv = UIPanelCreate(&win->e, UI_PANEL_GRAY|UI_PANEL_MEDIUM_SPACING);
+
+ UIPanel *panelh = UIPanelCreate(&panelv->e, UI_PANEL_GRAY|UI_PANEL_MEDIUM_SPACING|UI_PANEL_HORIZONTAL);
+ UILabel *label = UILabelCreate(&panelh->e, 0, "webp to spritesheet converter", -1);
+ UISlider *slider = UISliderCreate(&panelh->e, 0);
+ UIButton *btnopen = UIButtonCreate(&panelh->e, 0, "Open", -1);
+ //btnopen->e.messageUser = ButtonOpenEvent;
+ UIButton *btnsave = UIButtonCreate(&panelh->e, 0, "Save", -1);
+ btnsave->e.messageUser = ButtonSaveEvent;
+ UIButton *btnexit = UIButtonCreate(&panelh->e, 0, "Close", -1);
+ btnexit->e.messageUser = ButtonCloseEvent;
+
+ UIImageDisplay *img_disp = UIImageDisplayCreate(&panelv->e, UI_ELEMENT_V_FILL|UI_ELEMENT_H_FILL|UI_IMAGE_DISPLAY_INTERACTIVE|_UI_IMAGE_DISPLAY_ZOOM_FIT, NULL, 0, 0, 0);
img_disp->e.cp = label;
slider->e.messageUser = SliderEvent;
slider->e.cp = img_disp;
- UIButton *btn = UIButtonCreate(&panel->e, 0, "Close", -1);
- btn->e.messageUser = ButtonCloseEvent;
- //return UIMessageLoop();
if (argc < 2) {
printf("Usage: %s anim_file.webp\n", argc>0?argv[0]:"emote2ss_gui");
@@ -307,20 +329,22 @@ int main(int argc, const char **argv) {
img = malloc(sizeof(animation_t));
assert(img!=NULL);
bzero(img, sizeof(animation_t));
- char out_name[PATH_MAX];
- char *in_path = strndup(argv[1], PATH_MAX-1);
- assert(in_path!=NULL);
- int r = read_webp(in_path, img);
+ char out_name[NAME_MAX-1];
+ img->path = strndup(argv[1], PATH_MAX-1);
+ assert(img->path!=NULL);
+ int r = read_webp(img->path, img);
assert(r==0);
- char *in_name = basename((char *)in_path);
- char *in_dir = dirname((char *)in_path);
- int n = snprintf(out_name, NAME_MAX, "atlas_%s", in_name);
+
+ char *in_name = basename(img->path);
+ char *in_dir = dirname(img->path);
+ int n = snprintf(out_name, NAME_MAX-1, "atlas_%s", in_name);
assert(n>0);
- printf("[path:%s][%s -> %s(%d)]\ndimensions: %dx%d\nframes: %d\n", in_dir, in_name, out_name, cols, img->width, img->height, img->frame_count);
+ printf("[%s/%s -> %s]\ncols: %d\ndimensions: %dx%dpx\nframes: %d\n", in_dir, in_name, out_name, cols, img->width, img->height, img->frame_count);
update_preview(img_disp);
- //@todo free(img);
+ //free(img->path);
+ //free(img);
// temporary
return UIMessageLoop();