diff --git a/src/menus/main_menu.c b/src/menus/main_menu.c index 93c05fc..d895c02 100644 --- a/src/menus/main_menu.c +++ b/src/menus/main_menu.c @@ -45,7 +45,7 @@ int FileExist(const char* path) { void main_menu_process_events(SDL_Window* window, SDL_Renderer* renderer, SDL_Event* event, EZ_MENU* current_menu) //exectuted each frame with all avaliable events { - if(main_menu_input_active==1) + if(main_menu_input_active) { if (event->type == SDL_TEXTINPUT) { diff --git a/src/menus/selection_menu.c b/src/menus/selection_menu.c index 096fded..dded747 100644 --- a/src/menus/selection_menu.c +++ b/src/menus/selection_menu.c @@ -7,6 +7,7 @@ #include "../utils/EZ_UI/elements/EZ_image.h" #include "../utils/EZ_UI/elements/EZ_button.h" #include "../utils/EZ_UI/elements/EZ_text.h" +#include "../utils/Application/ApplicationUtils.h" #include #include #include @@ -83,11 +84,20 @@ void button_action_switch_result(EZ_button* tmp) (void)tmp; EZ_drag_select* drag_grid=((EZ_drag_select*)selection_menu_objects[10]); //EZ_drag_select* drag_word=((EZ_drag_select*)selection_menu_objects[12]); + + int s_w, s_h; + + SDL_GetWindowSize(main_window, &s_w, &s_h); + + SDL_Rect selected_grid = anchore_to_rect(main_window, drag_grid->drawable_drag.dst_anchore); + + SDL_Rect drag_rect = anchore_to_rect(main_window, drag_grid->drag_anchore); + SDL_Rect grid_rect ={ - drag_grid->selected_zone.x - anchore_to_rect(main_window, drag_grid->drag_anchore).x, - drag_grid->selected_zone.y - anchore_to_rect(main_window, drag_grid->drag_anchore).y, - drag_grid->selected_zone.w, - drag_grid->selected_zone.h + (int)(((double)(selected_grid.x - drag_rect.x)) * ((double)loaded_image->w/(double)drag_rect.w)), + (int)(((double)(selected_grid.y - drag_rect.y)) * ((double)loaded_image->h/(double)drag_rect.h)), + (int)((double)selected_grid.w * ((double)loaded_image->w/(double)drag_rect.w)), + (int)((double)selected_grid.h * ((double)loaded_image->h/(double)drag_rect.h)) }; /* @@ -98,14 +108,24 @@ void button_action_switch_result(EZ_button* tmp) drag_word->selected_zone.h }; */ - export_split_grid(loaded_image, grid_rect, "split/grid"); + export_split_grid(loaded_image, grid_rect, combine_path(application_directory, "split/grid/")); EZ_select_menu(2); result_menu_enter(); } void selection_menu_enter(void) { - EZ_edit_image((EZ_image*)selection_menu_objects[0], loaded_image, main_renderer, 1); + EZ_drag_select* drag_grid=((EZ_drag_select*)selection_menu_objects[10]); + EZ_drag_select* drag_word=((EZ_drag_select*)selection_menu_objects[12]); + + EZ_image* img = (EZ_image*)selection_menu_objects[0]; + EZ_edit_image(img, loaded_image, main_renderer, 1); + + drag_grid->drag_anchore = img->drawable_image.dst_anchore; + drag_grid->interactible_select.anchore = img->drawable_image.dst_anchore; + + drag_word->drag_anchore = img->drawable_image.dst_anchore; + drag_word->interactible_select.anchore = img->drawable_image.dst_anchore; } void load_selection_menu(SDL_Renderer* renderer) diff --git a/src/utils/Application/ApplicationUtils.c b/src/utils/Application/ApplicationUtils.c index 06e8990..99f6cd2 100644 --- a/src/utils/Application/ApplicationUtils.c +++ b/src/utils/Application/ApplicationUtils.c @@ -1,5 +1,6 @@ #include #include +#include #include char* path_get_directory(char* path) @@ -62,3 +63,11 @@ char* combine_path(char* first_path, char* second_path) return res; } + +void mkpath(const char* file_path) +{ + int cmd_len = strlen(file_path)+11; + char cmd[cmd_len]; + sprintf(cmd, "mkdir -p %s", file_path); + system(cmd); +} diff --git a/src/utils/Application/ApplicationUtils.h b/src/utils/Application/ApplicationUtils.h index b7680aa..4ea9a12 100644 --- a/src/utils/Application/ApplicationUtils.h +++ b/src/utils/Application/ApplicationUtils.h @@ -5,4 +5,6 @@ char* path_get_directory(char* path); char* combine_path(char* first_path, char* second_path); +void mkpath(const char* file_path); + #endif diff --git a/src/utils/Spliting/Spliting.c b/src/utils/Spliting/Spliting.c index 4b82177..aafba73 100644 --- a/src/utils/Spliting/Spliting.c +++ b/src/utils/Spliting/Spliting.c @@ -6,6 +6,7 @@ #include #include "Spliting.h" #include "../Image/ImageUtils.h" +#include "../Application/ApplicationUtils.h" int split_margin = 1; @@ -57,6 +58,9 @@ int* get_grid_vertical_split(SDL_Surface* surface, SDL_Rect rect, int* nb_splits { int nb_split = get_grid_vertical_nb(surface, rect); + if (nb_split <= 0) + errx(EXIT_FAILURE, "get_grid_vertical_split: nb_split not valid"); + int* vertical_split_array = (int*)calloc(nb_split, sizeof(int)); *nb_splits = nb_split - (nb_split % 2); @@ -158,6 +162,9 @@ int* get_grid_horizontal_split(SDL_Surface* surface, SDL_Rect rect, int* nb_spli { int nb_split = get_grid_horizontal_nb(surface, rect); + if (nb_split <= 0) + errx(EXIT_FAILURE, "get_grid_horizontal_split: nb_split not valid"); + int* horizontal_split_array = (int*)calloc(nb_split, sizeof(int)); *nb_splits = nb_split - (nb_split % 2); @@ -254,10 +261,7 @@ void export_split_grid(SDL_Surface* surface, SDL_Rect rect, const char* save_dir int first_dim; int second_dim; - struct stat st = {0}; - - if (stat(save_dir, &st) == -1) - mkdir(save_dir, 0700); + mkpath(save_dir); SDL_Rect** splits = get_grid_split(surface, rect, &first_dim, &second_dim);