commit f139219eb3f4a99ff3716ac8bb16e96cd0a296b5
parent a9cdbac7ebc9876c9923bfad29d583016a23e176
Author: bsandro <email@bsandro.tech>
Date: Thu, 12 Sep 2024 23:42:03 +0300
printf() noize cleanup
Diffstat:
M | gui/main.c | | | 57 | +++++++++++++++++++-------------------------------------- |
1 file changed, 19 insertions(+), 38 deletions(-)
diff --git a/gui/main.c b/gui/main.c
@@ -81,7 +81,7 @@ int ReadFile(const char *filename, const uint8_t **data, size_t *size) {
assert(infile != NULL);
fseek(infile, 0, SEEK_END);
size_t fsize = ftell(infile);
- printf("%s: %zu bytes\n", filename, fsize);
+ // printf("%s: %zu bytes\n", filename, fsize);
fseek(infile, 0, SEEK_SET);
uint8_t *fdata = malloc(fsize+1);
@@ -139,7 +139,7 @@ void WebpWrite(const char *path, Animation *img) {
FILE *fp = fopen(path, "wb");
assert(fp!=NULL);
size_t encoded = WebPEncodeLosslessRGBA(ss.data, ss.width, ss.height, ss.stride, &out);
- printf("size: %zu, encoded: %zu\n", img->width*img->height*sizeof(uint32_t), encoded);
+ // printf("size: %zu, encoded: %zu\n", img->width*img->height*sizeof(uint32_t), encoded);
assert(encoded!=0);
size_t written = fwrite(out, sizeof(uint8_t), encoded, fp);
assert(written==encoded);
@@ -149,7 +149,7 @@ void WebpWrite(const char *path, Animation *img) {
int WinModalEvent(UIElement *element, UIMessage msg, int di, void *dp) {
if (msg == UI_MSG_DESTROY) {
- printf("modal bye\n");
+ // printf("modal bye\n");
assert(element==modal_win);
modal_win = NULL;
}
@@ -161,21 +161,20 @@ 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: %p\nfilename_input: %p\n", path_input, filename_input);
+ // printf("path_input: %p\nfilename_input: %p\n", path_input, filename_input);
// that printf might work incorrectly because path_input->string might not contain valid C string with \0 at the end
- printf("path_input: %s(%d)\nfilename_input: %s(%d)\n", path_input->string, path_input->bytes, filename_input->string, filename_input->bytes);
+ // printf("path_input: %s(%d)\nfilename_input: %s(%d)\n", path_input->string, path_input->bytes, filename_input->string, filename_input->bytes);
int path_len = path_input->bytes + filename_input->bytes + 2; // DIR_SEPARATOR and '\0'
- printf("path_len: %d\n", path_len);
+ // printf("path_len: %d\n", path_len);
char out_name[path_len];
out_name[path_input->bytes] = DIR_SEPARATOR;
out_name[path_len-1] = '\0';
memcpy(out_name, path_input->string, path_input->bytes);
memcpy(out_name+path_input->bytes+1, filename_input->string, filename_input->bytes);
- printf("strlen(out_name): %d\n", strlen(out_name));
- printf("out_name: %s\n", out_name);
+ // printf("strlen(out_name): %d\n", strlen(out_name));
+ // printf("out_name: %s\n", out_name);
WebpWrite(out_name, img);
-
- printf("save dialog window close\n");
+ // printf("save dialog window close\n");
assert(element->window==modal_win);
UIElementDestroy(element->window);
}
@@ -184,11 +183,11 @@ 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) {
- printf("open dialog window close\n");
+ // 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));
+ // 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);
@@ -214,32 +213,19 @@ int ButtonDialogOpenEvent(UIElement *element, UIMessage msg, int di, void *dp) {
/*
@todo
- display/update resulting spritesheet dimensions in pixels
-+ display list of files and directories in open directory
-+ first click on directory highlights it, second - opens it
-+ open directory full path is being copied into the path field above
-+ list has .. element to move up in the hierarchy
-+ click on filename highlights it and copies the name into file name field above
- unify path and filename fields (more canonical way)
- `-> copy the full path+name into the unified field
- use system open/save dialog on Windows
-+ sort directories before files in list
-+ do not display "." item
-+ filter files to only show those with .webp extension
-+ (bug) displayed file name is truncated
- move the whole subroutine into a separate file
-+ (bug) reset scroll on directory change
-+ sort names alphabetically
-+ (bug) path and name are being concatenated during copying
- prohibit interaction with parent window
*/
static int FilelistFilter(const struct dirent *f) {
if (strncmp(f->d_name, ".", 255)==0) return 0;
if (f->d_type==DT_DIR) return 1;
- //@todo not very optimal
+ //@todo not very efficient
size_t len = strlen(f->d_name);
// checking for the ".webp" at the very end
- printf("name: %s, len: %u, extension: %s\n", f->d_name, len, f->d_name+len-5);
if (len<6) return 0;
return strncmp(f->d_name+len-5, ".webp", 255)==0;
}
@@ -262,7 +248,7 @@ int TableEvent(UIElement *element, UIMessage msg, int di, void *dp) {
UITable *table = (UITable *)element;
if (filelist==NULL) {
table->itemCount = scandir(dir_name, &filelist, FilelistFilter, FilelistCompare);
- //printf("populated dir %s with %d items\n", dir_name, table->itemCount);
+ // printf("populated dir %s with %d items\n", dir_name, table->itemCount);
}
if (msg==UI_MSG_TABLE_GET_ITEM) {
UITableGetItem *m = (UITableGetItem *)dp;
@@ -284,7 +270,6 @@ int TableEvent(UIElement *element, UIMessage msg, int di, void *dp) {
//element->cp = realpath(filelist[hit]->d_name, NULL);
//@todo memory leak
element->cp = realpath(newpath, NULL);
- printf("new dir: %s\n", element->cp);
//@todo cleanup filelist!
filelist = NULL;
selected = -1;
@@ -311,8 +296,6 @@ int TableEvent(UIElement *element, UIMessage msg, int di, void *dp) {
UITextbox *path_input = (UITextbox *)panel_top->e.children;
UITextbox *file_input = (UITextbox *)path_input->e.next;
// string, bytes, UITextboxReplace
- printf("path: %s (%d bytes)\nfile: %s(%d)\n", path_input->string, path_input->bytes, file_input->string, file_input->bytes);
- printf("old path: %s\n", (char *)element->cp);
UITextboxClear(path_input, false);
UITextboxClear(file_input, false);
UITextboxReplace(path_input, (char *)element->cp, -1, false);
@@ -322,11 +305,9 @@ int TableEvent(UIElement *element, UIMessage msg, int di, void *dp) {
}
}
} else if (msg==UI_MSG_DESTROY) {
- printf("destroy table\n");
filelist = NULL;
selected = -1;
} else if (msg==UI_MSG_UPDATE) {
- //printf("processing table signal %d\n", msg);
UITableResizeColumns(table);
}
return 0;
@@ -343,7 +324,7 @@ typedef int (*CallbackFn)(struct UIElement *element, UIMessage message, int di,
void ShowModalWindow(UIWindow *parent, const char *def_dir, const char *def_file, CallbackFn cb) {
if (modal_win == NULL) {
- printf("create modal window\n");
+ // printf("create modal window\n");
modal_win = UIWindowCreate(parent, NULL, def_file?"Save File":"Open File", WIN_WIDTH, WIN_HEIGHT);
modal_win->e.messageUser = WinModalEvent;
UIPanel *panel_out = UIPanelCreate(&modal_win->e, UI_PANEL_GRAY|UI_PANEL_EXPAND);
@@ -379,7 +360,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) {
- printf("save button clicked\n");
+ // printf("save button clicked\n");
char fname[strlen(img->filename)+7];
int n = snprintf(fname, NAME_MAX, "atlas_%s", img->filename);
assert(n>0);
@@ -390,7 +371,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");
+ // printf("open button clicked\n");
ShowModalWindow(element->window, getenv("HOME"), NULL, ButtonDialogOpenEvent);
}
return 0;
@@ -440,7 +421,7 @@ 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");
+ // printf("bye\n");
free(img);
exit(0);
}
@@ -455,7 +436,7 @@ int WinMain(HINSTANCE instance, HINSTANCE previousInstance, LPSTR commandLine, i
// just some silly stuff, always wanted to try that
prctl(PR_SET_NAME, "webp-anim-2-spritesheet");
- printf("argv[0]: %s\n", argv[0]);
+ // printf("argv[0]: %s\n", argv[0]);
atexit(print_webp_version);