From 5a2c72b932b3801d6d57c23961df73d1ea58cc2e Mon Sep 17 00:00:00 2001 From: Etienne Draugr death overlord Date: Mon, 15 Apr 2019 10:03:01 +0300 Subject: [PATCH] [FIX] now elems and win are in good resizeble situation --- .vscode/launch.json | 4 +- libui/Makefile | 8 +- libui/include/libui.h | 2 +- libui/src/ui_el/ui_el_add_child.c | 5 +- libui/src/ui_el/ui_el_set_abs_pos.c | 6 +- libui/src/ui_el/ui_el_set_abs_size.c | 8 +- libui/src/ui_el/ui_el_set_rel_pos.c | 4 +- libui/src/ui_el/ui_el_set_rel_size.c | 4 +- libui/src/ui_main/ui_main_add_window.c | 9 +- .../src/ui_main/ui_main_remove_window_by_id.c | 14 +- libui/src/ui_win/ui_win_create.c | 12 +- src/main.c | 198 ++++-------------- 12 files changed, 94 insertions(+), 180 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index ae17a4c..b82236d 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -10,10 +10,10 @@ "request": "launch", "program": "${workspaceFolder}/guimp", "args": [], - "stopAtEntry": false, + "stopAtEntry": true, "cwd": "${workspaceFolder}", "environment": [], - "externalConsole": true, + "externalConsole": false, "MIMode": "lldb" } ] diff --git a/libui/Makefile b/libui/Makefile index ac50cf9..62e00bf 100644 --- a/libui/Makefile +++ b/libui/Makefile @@ -6,7 +6,7 @@ # By: edraugr- +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2019/03/07 16:14:32 by sbednar #+# #+# # -# Updated: 2019/04/10 06:35:26 by edraugr- ### ########.fr # +# Updated: 2019/04/11 23:34:48 by edraugr- ### ########.fr # # # # **************************************************************************** # @@ -33,7 +33,11 @@ SRC_UI_EL = ui_el_add_child.c \ ui_el_set_current_texture_by_id.c \ ui_el_add_texture.c \ ui_el_create_texture_from_surface.c \ - ui_el_get_current_texture.c + ui_el_get_current_texture.c \ + ui_el_set_abs_size.c \ + ui_el_set_rel_size.c \ + ui_el_set_abs_pos.c \ + ui_el_set_rel_pos.c SRC_UI_DRAW_EV = ui_el_draw_event.c diff --git a/libui/include/libui.h b/libui/include/libui.h index ec858a9..8dd7458 100644 --- a/libui/include/libui.h +++ b/libui/include/libui.h @@ -6,7 +6,7 @@ /* By: edraugr- +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/03/10 19:09:04 by sbednar #+# #+# */ -/* Updated: 2019/04/10 13:45:10 by edraugr- ### ########.fr */ +/* Updated: 2019/04/15 09:07:35 by edraugr- ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libui/src/ui_el/ui_el_add_child.c b/libui/src/ui_el/ui_el_add_child.c index 24df498..62d6148 100644 --- a/libui/src/ui_el/ui_el_add_child.c +++ b/libui/src/ui_el/ui_el_add_child.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* ui_el_add_child.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: sbednar +#+ +:+ +#+ */ +/* By: edraugr- +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/03/28 14:55:52 by edraugr- #+# #+# */ -/* Updated: 2019/04/04 05:25:29 by sbednar ### ########.fr */ +/* Updated: 2019/04/15 06:40:12 by edraugr- ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,6 +18,7 @@ int ui_el_add_child(t_ui_el *el, t_ui_el *child) if ((node = ft_lstnew(NULL, 0)) == NULL) return (FUNCTION_FAILURE); + child->parent = el; node->content = (void *)child; ft_lstadd_back(&(el->children), node); return (FUNCTION_SUCCESS); diff --git a/libui/src/ui_el/ui_el_set_abs_pos.c b/libui/src/ui_el/ui_el_set_abs_pos.c index 5bfe617..3cb02a5 100644 --- a/libui/src/ui_el/ui_el_set_abs_pos.c +++ b/libui/src/ui_el/ui_el_set_abs_pos.c @@ -6,7 +6,7 @@ /* By: edraugr- +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/10 13:35:28 by edraugr- #+# #+# */ -/* Updated: 2019/04/10 14:00:57 by edraugr- ### ########.fr */ +/* Updated: 2019/04/15 06:16:15 by edraugr- ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,6 +20,6 @@ void ui_el_set_abs_pos(t_ui_el *el, int x, int y) return ; el->rect.x = x; el->rect.y = y; - el->frect.x = (float)((float)p->rect.x / (float)x); - el->frect.y = (float)((float)p->rect.y / (float)y); + el->frect.x = (float)((float)x / (float)p->rect.w); + el->frect.y = (float)((float)y / (float)p->rect.h); } diff --git a/libui/src/ui_el/ui_el_set_abs_size.c b/libui/src/ui_el/ui_el_set_abs_size.c index 9f77767..7ebad9f 100644 --- a/libui/src/ui_el/ui_el_set_abs_size.c +++ b/libui/src/ui_el/ui_el_set_abs_size.c @@ -6,7 +6,7 @@ /* By: edraugr- +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/10 13:33:27 by edraugr- #+# #+# */ -/* Updated: 2019/04/10 13:47:08 by edraugr- ### ########.fr */ +/* Updated: 2019/04/12 20:43:52 by edraugr- ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,7 +16,7 @@ void ui_el_set_abs_size(t_ui_el *el, int w, int h) { t_ui_el *p; - if (!el || !(p = el->parent)) + if (!el || !(p = el->parent) || w == 0 || h == 0) return ; // if (x > p->rect.x || x < 0) // x > 0 ? x = p->p->rect.x : x = 0; @@ -24,6 +24,6 @@ void ui_el_set_abs_size(t_ui_el *el, int w, int h) // y > 0 ? y = p->p->rect.y : y = 0; el->rect.w = w; el->rect.h = h; - el->frect.w = (float)((float)p->rect.w / (float)w); - el->frect.h = (float)((float)p->rect.h / (float)h); + el->frect.w = (float)((float)w / (float)p->rect.w); + el->frect.h = (float)((float)h / (float)p->rect.h); } diff --git a/libui/src/ui_el/ui_el_set_rel_pos.c b/libui/src/ui_el/ui_el_set_rel_pos.c index bca3775..863365b 100644 --- a/libui/src/ui_el/ui_el_set_rel_pos.c +++ b/libui/src/ui_el/ui_el_set_rel_pos.c @@ -6,13 +6,13 @@ /* By: edraugr- +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/10 13:35:52 by edraugr- #+# #+# */ -/* Updated: 2019/04/10 14:06:17 by edraugr- ### ########.fr */ +/* Updated: 2019/04/11 23:34:42 by edraugr- ### ########.fr */ /* */ /* ************************************************************************** */ #include "libui.h" -void ui_el_set_rel_size(t_ui_el *el, float x, float y) +void ui_el_set_rel_pos(t_ui_el *el, float x, float y) { t_ui_el *p; diff --git a/libui/src/ui_el/ui_el_set_rel_size.c b/libui/src/ui_el/ui_el_set_rel_size.c index 95c2c62..5be36fc 100644 --- a/libui/src/ui_el/ui_el_set_rel_size.c +++ b/libui/src/ui_el/ui_el_set_rel_size.c @@ -6,7 +6,7 @@ /* By: edraugr- +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/10 13:35:05 by edraugr- #+# #+# */ -/* Updated: 2019/04/10 14:06:00 by edraugr- ### ########.fr */ +/* Updated: 2019/04/12 20:19:05 by edraugr- ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,7 +16,7 @@ void ui_el_set_rel_size(t_ui_el *el, float w, float h) { t_ui_el *p; - if (!el || !(p = el->parent)) + if (!el || !(p = el->parent) || w == 0.0 || h == 0.0) return ; el->frect.w = w; el->frect.h = h; diff --git a/libui/src/ui_main/ui_main_add_window.c b/libui/src/ui_main/ui_main_add_window.c index e15de0a..8487351 100644 --- a/libui/src/ui_main/ui_main_add_window.c +++ b/libui/src/ui_main/ui_main_add_window.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* ui_main_add_window.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: sbednar +#+ +:+ +#+ */ +/* By: edraugr- +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/03/30 22:02:32 by sbednar #+# #+# */ -/* Updated: 2019/04/04 00:06:08 by sbednar ### ########.fr */ +/* Updated: 2019/04/15 09:05:07 by edraugr- ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,8 +16,11 @@ int ui_main_add_window(t_ui_main *m, t_ui_win *w) { t_list *node; - if (!(node = ft_lstnew((void *)w, sizeof(t_ui_win)))) + // if (!(node = ft_lstnew((void *)w, sizeof(t_ui_win)))) + // return (FUNCTION_FAILURE); + if (!(node = ft_lstnew(NULL, 0))) return (FUNCTION_FAILURE); + node->content = (void *)w; if (m->windows == NULL) m->windows = node; else diff --git a/libui/src/ui_main/ui_main_remove_window_by_id.c b/libui/src/ui_main/ui_main_remove_window_by_id.c index 2855f6a..329ce72 100644 --- a/libui/src/ui_main/ui_main_remove_window_by_id.c +++ b/libui/src/ui_main/ui_main_remove_window_by_id.c @@ -3,15 +3,23 @@ /* ::: :::::::: */ /* ui_main_remove_window_by_id.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: sbednar +#+ +:+ +#+ */ +/* By: edraugr- +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/03/30 23:34:51 by sbednar #+# #+# */ -/* Updated: 2019/03/31 02:46:33 by sbednar ### ########.fr */ +/* Updated: 2019/04/15 09:55:47 by edraugr- ### ########.fr */ /* */ /* ************************************************************************** */ #include "libui.h" +static void ft_lstdelones_without_cont(t_list **alst) +{ + if (!alst) + return ; + free(*alst); + *alst = NULL; +} + void ui_main_remove_window_by_id(t_ui_main *m, Uint32 windowID) { t_list *prev; @@ -30,7 +38,7 @@ void ui_main_remove_window_by_id(t_ui_main *m, Uint32 windowID) else prev->next = cur->next; ui_win_close(win); - ft_lstdelones(&cur); + ft_lstdelones_without_cont(&cur); return ; } prev = cur; diff --git a/libui/src/ui_win/ui_win_create.c b/libui/src/ui_win/ui_win_create.c index fc11290..9d71677 100644 --- a/libui/src/ui_win/ui_win_create.c +++ b/libui/src/ui_win/ui_win_create.c @@ -6,7 +6,7 @@ /* By: edraugr- +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/03/29 21:00:14 by sbednar #+# #+# */ -/* Updated: 2019/04/10 02:17:17 by edraugr- ### ########.fr */ +/* Updated: 2019/04/12 20:13:13 by edraugr- ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,8 +21,14 @@ void ui_win_create(t_ui_win *w) ; w->sdl_renderer = SDL_CreateRenderer(w->sdl_window, -1, 0); w->sdl_windowID = SDL_GetWindowID(w->sdl_window); - // w->canvas.rect.x = w->size.x; - // w->canvas.rect.y = w->size.y; + // w->canvas.rect.w = w->size.x; + // w->canvas.rect.h = w->size.y; + // w->canvas.rect.x = 0; + // w->canvas.rect.y = 0; + // w->canvas.frect.x = 0.0; + // w->canvas.frect.y = 0.0; + // w->canvas.frect.w = 1.0; + // w->canvas.frect.h = 1.0; SDL_SetWindowResizable(w->sdl_window, (w->params) & WIN_RESIZABLE ? SDL_TRUE : SDL_FALSE); SDL_RaiseWindow(w->sdl_window); } diff --git a/src/main.c b/src/main.c index e485c6b..28f9750 100644 --- a/src/main.c +++ b/src/main.c @@ -6,7 +6,7 @@ /* By: edraugr- +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/03/07 16:09:10 by sbednar #+# #+# */ -/* Updated: 2019/04/10 14:13:27 by edraugr- ### ########.fr */ +/* Updated: 2019/04/15 09:59:33 by edraugr- ### ########.fr */ /* */ /* ************************************************************************** */ @@ -32,122 +32,43 @@ static void test_for_main(void *a1, void *a2) static void find_new_size(void *a1, void *a2) { t_ui_el *el = (t_ui_el *)a1; - t_ui_win *w = (t_ui_win *)a2; + (void)a2; if (!(el->params & EL_DYNAMIC_SIZE)) - return; - el->rect.x = w->size.x * el->frect.x; - el->rect.y = w->size.y * el->frect.y; - el->rect.w = w->size.x * (el->frect.w - el->frect.x); - el->rect.h = w->size.y * (el->frect.h - el->frect.y); + return ; + ui_el_set_rel_size(el, el->frect.w, el->frect.h); } -static void update_window_size(void *a1, void *a2) +static void find_dynamic_elements(void *a1, void *a2) { - t_ui_main *m; t_ui_win *w; - Uint32 windowID; - m = (t_ui_main *)a1; - windowID = *((Uint32 *)a2); - w = ui_main_find_window_by_id(m, windowID); + w = (t_ui_win *)a2; + (void)a1; if (w != NULL) { - SDL_GetWindowSize(w->sdl_window, &(w->size.x), &(w->size.y)); + bfs_iter_root(&(w->canvas), &find_new_size, NULL);//w); } - //refresh canvas } -static void find_dynamic_elements(void *a1, void *a2) +static void update_window_size(void *a1, void *a2) { - Uint32 windowID; t_ui_main *m; t_ui_win *w; + Uint32 windowID; m = (t_ui_main *)a1; windowID = *((Uint32 *)a2); w = ui_main_find_window_by_id(m, windowID); if (w != NULL) { - bfs_iter_root(&(w->canvas), &find_new_size, w); + SDL_GetWindowSize(w->sdl_window, &(w->size.x), &(w->size.y)); + w->canvas.rect.w = w->size.x; + w->canvas.rect.h = w->size.y; + find_dynamic_elements(a1, (void *)w); } } -// static void draw_placeholder(const void *el) -// { -// char *tmp; - -// tmp = ft_itoa(CAST_X_TO_Y(el, t_ui_el *)->test); -// ft_putendl(tmp); -// free(tmp); -// } - -static void test() -{ -// t_ui_el *root = ui_el_init(NULL, NULL); -// t_list *lst = ft_lstnew(CAST_X_TO_Y(ui_el_init(root, NULL), const void *), sizeof(t_ui_el)); -// ft_lstadd_back(&lst, ft_lstnew(CAST_X_TO_Y(ui_el_init(root, NULL), const void *), sizeof(t_ui_el))); -// ft_lstadd_back(&lst, ft_lstnew(CAST_X_TO_Y(ui_el_init(root, NULL), const void *), sizeof(t_ui_el))); -// ft_lstadd_back(&lst, ft_lstnew(CAST_X_TO_Y(ui_el_init(root, NULL), const void *), sizeof(t_ui_el))); -// ft_lstadd_back(&lst, ft_lstnew(CAST_X_TO_Y(ui_el_init(root, NULL), const void *), sizeof(t_ui_el))); -// ft_lstadd_back(&lst, ft_lstnew(CAST_X_TO_Y(ui_el_init(root, NULL), const void *), sizeof(t_ui_el))); -// int i = 1; -// t_list *tmp = lst; -// while(tmp) -// { -// CAST_X_TO_Y(tmp->content, t_ui_el *)->test = i; -// tmp = tmp->next; -// ++i; -// } -// root->children = lst; - -// root->test = 0; -// lst = ft_lstnew(CAST_X_TO_Y(ui_el_init(root, NULL), const void *), sizeof(t_ui_el)); -// ft_lstadd_back(&lst, ft_lstnew(CAST_X_TO_Y(ui_el_init(root, NULL), const void *), sizeof(t_ui_el))); -// ft_lstadd_back(&lst, ft_lstnew(CAST_X_TO_Y(ui_el_init(root, NULL), const void *), sizeof(t_ui_el))); -// ft_lstadd_back(&lst, ft_lstnew(CAST_X_TO_Y(ui_el_init(root, NULL), const void *), sizeof(t_ui_el))); -// tmp = lst; -// i = 1; -// while(tmp) -// { -// CAST_X_TO_Y(tmp->content, t_ui_el *)->test = i * 10; -// tmp = tmp->next; -// ++i; -// } -// CAST_X_TO_Y(root->children->next->next->content, t_ui_el *)->children = lst; - -// lst = ft_lstnew(CAST_X_TO_Y(ui_el_init(root, NULL), const void *), sizeof(t_ui_el)); -// ft_lstadd_back(&lst, ft_lstnew(CAST_X_TO_Y(ui_el_init(root, NULL), const void *), sizeof(t_ui_el))); -// ft_lstadd_back(&lst, ft_lstnew(CAST_X_TO_Y(ui_el_init(root, NULL), const void *), sizeof(t_ui_el))); -// ft_lstadd_back(&lst, ft_lstnew(CAST_X_TO_Y(ui_el_init(root, NULL), const void *), sizeof(t_ui_el))); -// tmp = lst; -// i = 1; -// while(tmp) -// { -// CAST_X_TO_Y(tmp->content, t_ui_el *)->test = i * 100; -// tmp = tmp->next; -// ++i; -// } -// CAST_X_TO_Y(root->children->next->content, t_ui_el *)->children = lst; - -// lst = ft_lstnew(CAST_X_TO_Y(ui_el_init(root, NULL), const void *), sizeof(t_ui_el)); -// ft_lstadd_back(&lst, ft_lstnew(CAST_X_TO_Y(ui_el_init(root, NULL), const void *), sizeof(t_ui_el))); -// ft_lstadd_back(&lst, ft_lstnew(CAST_X_TO_Y(ui_el_init(root, NULL), const void *), sizeof(t_ui_el))); -// ft_lstadd_back(&lst, ft_lstnew(CAST_X_TO_Y(ui_el_init(root, NULL), const void *), sizeof(t_ui_el))); -// tmp = lst; -// i = 1; -// while(tmp) -// { -// CAST_X_TO_Y(tmp->content, t_ui_el *)->test = i * 1000; -// tmp = tmp->next; -// ++i; -// } -// CAST_X_TO_Y((CAST_X_TO_Y(root->children->next->content, t_ui_el *)->children->next->content), t_ui_el *)->children = lst; - -// // t_list *lst = ft_lstnew(NULL, 0); -// // lst->content = CAST_X_TO_Y(root, void *); -// bfs_iter_root(root, draw_placeholder); -} void log_setup(t_ui_win *w) { @@ -224,7 +145,6 @@ static void testOnPtrLBHold(void *main, void *el_v) dx += dur; dy += dur; el->rect.x += dur; - //el->rect.y += dur; } } @@ -247,22 +167,20 @@ int main(int argc, char *argv[]) w.size.x = 640; w.size.y = 480; log_setup(&w); - w.canvas.frect.x = 0; - w.canvas.frect.y = 0; - w.canvas.frect.w = 1; - w.canvas.frect.h = 1; + w.canvas.frect.x = 0.0; + w.canvas.frect.y = 0.0; + w.canvas.frect.w = 1.0; + w.canvas.frect.h = 1.0; w.canvas.rect.w = w.size.x; w.canvas.rect.h = w.size.y; - w.canvas.params = EL_DYNAMIC_SIZE; - w.canvas.id = 0; + w.canvas.rect.x = 0; + w.canvas.rect.y = 0; + w.canvas.id = 123; ui_event_add_listener(&(w.events.onResize), &update_window_size); - ui_event_add_listener(&(w.events.onResize), &find_dynamic_elements); ui_event_add_listener(&(w.events.onClose), &test_for_main); ui_win_create(&w); w.canvas.sdl_renderer = w.sdl_renderer; - // ui_el_load_surface_from(&(w.canvas), "test3.jpg"); - // ui_el_create_texture(&(w.canvas)); ui_el_add_texture_from_file(&(w.canvas), "test3.jpg", TID_DEFAULT); ui_event_add_listener(&(w.canvas.events.onRender), &ui_el_draw_event); @@ -272,39 +190,28 @@ int main(int argc, char *argv[]) ui_event_add_listener(&(el1.events.onPointerExit), &ui_log_el_pointer_exit); ui_event_add_listener(&(el1.events.onPointerStay), &ui_log_el_pointer_stay); ui_event_add_listener(&(el1.events.onRender), &ui_el_draw_event); - el1.rect.x = 100; - el1.rect.y = 100; - el1.rect.w = 200; - el1.rect.h = 100; - el1.frect.x = 0.3; - el1.frect.y = 0.3; - el1.frect.w = 0.1; - el1.frect.h = 0.1; - //el1.params = EL_DYNAMIC_SIZE; + ui_el_add_child(&(w.canvas), &el1); + ui_el_set_abs_pos(&el1, 100, 100); + ui_el_set_abs_size(&el1, 200, 100); + el1.params |= EL_DYNAMIC_SIZE; el1.id = 10; el1.sdl_renderer = w.sdl_renderer; - // ui_el_load_surface_from(&el1, "test2.jpg"); - // ui_el_create_texture(&el1); ui_el_add_texture_from_file(&el1, "test2.jpg", TID_DEFAULT); - ui_el_add_child(&(w.canvas), &el1); + + t_ui_el el2; ui_el_init(&el2); ui_event_add_listener(&(el2.events.onPointerEnter), &ui_log_el_pointer_enter); ui_event_add_listener(&(el2.events.onPointerExit), &ui_log_el_pointer_exit); ui_event_add_listener(&(el2.events.onPointerStay), &ui_log_el_pointer_stay); ui_event_add_listener(&(el2.events.onRender), &ui_el_draw_event); - el2.rect.x = 300; - el2.rect.y = 300; - el2.rect.w = 100; - el2.rect.h = 100; + ui_el_add_child(&(w.canvas), &el2); + ui_el_set_abs_pos(&el2, 300, 300); + ui_el_set_abs_size(&el2, 100, 100); el2.id = 20; el2.sdl_renderer = w.sdl_renderer; - // ui_el_load_surface_from(&el2, "test3.jpg"); - // ui_el_create_texture(&el2); ui_el_add_texture_from_file(&el2, "test6.jpeg", TID_DEFAULT); - ui_el_add_child(&(w.canvas), &el2); ui_event_add_listener(&(el2.events.onPointerStay), &testOnPtrStay); - //ui_event_add_listener(&(el2.events.onPointerLeftButtonHold), &testOnPtrLBHold); t_ui_el el11; ui_el_init(&el11); @@ -312,14 +219,11 @@ int main(int argc, char *argv[]) ui_event_add_listener(&(el11.events.onPointerExit), &ui_log_el_pointer_exit); ui_event_add_listener(&(el11.events.onPointerStay), &ui_log_el_pointer_stay); ui_event_add_listener(&(el11.events.onRender), &ui_el_draw_event); - el11.rect.x = 100; - el11.rect.y = 100; - el11.rect.w = 100; - el11.rect.h = 200; + ui_el_add_child(&el1, &el11); + ui_el_set_abs_pos(&el11, 100, 100); + ui_el_set_abs_size(&el11, 100, 200); el11.id = 2220; el11.sdl_renderer = w.sdl_renderer; - // ui_el_load_surface_from(&el11, "test4.jpeg"); - // ui_el_create_texture(&el11); ui_el_add_texture_from_file(&el11, "test4.jpeg", TID_DEFAULT); ui_el_add_texture_from_file(&el11, "test.bmp", TID_ONFOCUSED); ui_el_add_texture_from_file(&el11, "test5.png", TID_ONACTIVE); @@ -328,8 +232,6 @@ int main(int argc, char *argv[]) ui_event_add_listener(&(el11.events.onPointerLeftButtonPressed), testOnPtrLBDown); ui_event_add_listener(&(el11.events.onPointerLeftButtonReleased), testOnPtrEnter); ui_event_add_listener(&(el11.events.onPointerLeftButtonHold), &testOnPtrLBHold); - //el11.params |= EL_IGNOR_RAYCAST; - ui_el_add_child(&el1, &el11); t_ui_win w1; @@ -343,8 +245,6 @@ int main(int argc, char *argv[]) w1.params = 0; ui_win_create(&w1); w1.canvas.sdl_renderer = (w1.sdl_renderer); - // ui_el_load_surface_from(&w1.canvas, "test2.jpg"); - // ui_el_create_texture(&w1.canvas); ui_el_add_texture_from_file(&(w1.canvas), "test2.jpg", TID_DEFAULT); ui_event_add_listener(&(w1.canvas.events.onRender), &ui_el_draw_event); @@ -358,36 +258,28 @@ int main(int argc, char *argv[]) w2.title = ft_strdup("TEST3"); w2.size.x = 200; w2.size.y = 100; - w2.canvas.rect.w = 200; - w2.canvas.rect.h = 100; + w2.canvas.frect.x = 0.0; + w2.canvas.frect.y = 0.0; + w2.canvas.frect.w = 1.0; + w2.canvas.frect.h = 1.0; + w2.canvas.rect.w = w2.size.x; + w2.canvas.rect.h = w2.size.y; + w2.canvas.rect.x = 0; + w2.canvas.rect.y = 0; w2.params = WIN_RESIZABLE; + + ui_event_add_listener(&(w2.canvas.events.onRender), &ui_el_draw_event); + ui_event_add_listener(&(w2.events.onResize), &update_window_size); ui_win_create(&w2); + log_setup(&w2); w2.canvas.sdl_renderer = (w2.sdl_renderer); - // ui_el_load_surface_from(&w2.canvas, "test2.jpg"); - // ui_el_create_texture(&w2.canvas); ui_el_add_texture_from_file(&(w2.canvas), "test2.jpg", TID_DEFAULT); - ui_event_add_listener(&(w2.canvas.events.onRender), &ui_el_draw_event); - - log_setup(&w2); ui_event_add_listener(&(w2.events.onClose), &test_for_notmain); - ui_main_add_window(&m, &w); ui_main_add_window(&m, &w1); ui_main_add_window(&m, &w2); - // SDL_SetRenderDrawColor(w.sdl_renderer, 255, 0, 0, 255); - // SDL_RenderClear(w.sdl_renderer); - // SDL_RenderPresent(w.sdl_renderer); - - // SDL_SetRenderDrawColor(w1.sdl_renderer, 0, 255, 0, 255); - // SDL_RenderClear(w1.sdl_renderer); - // SDL_RenderPresent(w1.sdl_renderer); - - // SDL_SetRenderDrawColor(w2.sdl_renderer, 0, 0, 255, 255); - // SDL_RenderClear(w2.sdl_renderer); - // SDL_RenderPresent(w2.sdl_renderer); - ui_main_loop(&m); return (0); }