feat: fixed grid split

This commit is contained in:
2024-11-02 16:36:41 +01:00
parent cae8a6935b
commit 3e23633fa2
5 changed files with 46 additions and 11 deletions

View File

@ -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 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) if (event->type == SDL_TEXTINPUT)
{ {

View File

@ -7,6 +7,7 @@
#include "../utils/EZ_UI/elements/EZ_image.h" #include "../utils/EZ_UI/elements/EZ_image.h"
#include "../utils/EZ_UI/elements/EZ_button.h" #include "../utils/EZ_UI/elements/EZ_button.h"
#include "../utils/EZ_UI/elements/EZ_text.h" #include "../utils/EZ_UI/elements/EZ_text.h"
#include "../utils/Application/ApplicationUtils.h"
#include <unistd.h> #include <unistd.h>
#include <SDL.h> #include <SDL.h>
#include <SDL_ttf.h> #include <SDL_ttf.h>
@ -83,11 +84,20 @@ void button_action_switch_result(EZ_button* tmp)
(void)tmp; (void)tmp;
EZ_drag_select* drag_grid=((EZ_drag_select*)selection_menu_objects[10]); 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_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 ={ SDL_Rect grid_rect ={
drag_grid->selected_zone.x - anchore_to_rect(main_window, drag_grid->drag_anchore).x, (int)(((double)(selected_grid.x - drag_rect.x)) * ((double)loaded_image->w/(double)drag_rect.w)),
drag_grid->selected_zone.y - anchore_to_rect(main_window, drag_grid->drag_anchore).y, (int)(((double)(selected_grid.y - drag_rect.y)) * ((double)loaded_image->h/(double)drag_rect.h)),
drag_grid->selected_zone.w, (int)((double)selected_grid.w * ((double)loaded_image->w/(double)drag_rect.w)),
drag_grid->selected_zone.h (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 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); EZ_select_menu(2);
result_menu_enter(); result_menu_enter();
} }
void selection_menu_enter(void) 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) void load_selection_menu(SDL_Renderer* renderer)

View File

@ -1,5 +1,6 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h>
#include <err.h> #include <err.h>
char* path_get_directory(char* path) char* path_get_directory(char* path)
@ -62,3 +63,11 @@ char* combine_path(char* first_path, char* second_path)
return res; 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);
}

View File

@ -5,4 +5,6 @@ char* path_get_directory(char* path);
char* combine_path(char* first_path, char* second_path); char* combine_path(char* first_path, char* second_path);
void mkpath(const char* file_path);
#endif #endif

View File

@ -6,6 +6,7 @@
#include <unistd.h> #include <unistd.h>
#include "Spliting.h" #include "Spliting.h"
#include "../Image/ImageUtils.h" #include "../Image/ImageUtils.h"
#include "../Application/ApplicationUtils.h"
int split_margin = 1; 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); 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)); int* vertical_split_array = (int*)calloc(nb_split, sizeof(int));
*nb_splits = nb_split - (nb_split % 2); *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); 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)); int* horizontal_split_array = (int*)calloc(nb_split, sizeof(int));
*nb_splits = nb_split - (nb_split % 2); *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 first_dim;
int second_dim; int second_dim;
struct stat st = {0}; mkpath(save_dir);
if (stat(save_dir, &st) == -1)
mkdir(save_dir, 0700);
SDL_Rect** splits = get_grid_split(surface, rect, &first_dim, &second_dim); SDL_Rect** splits = get_grid_split(surface, rect, &first_dim, &second_dim);