From 11b5bf84f314fd6d2f002f9277a38b101826f32f Mon Sep 17 00:00:00 2001 From: Paranoid-Pufferfish Date: Thu, 26 Dec 2024 19:43:33 +0100 Subject: [PATCH] Forgot --- main.c | 1509 ++++++++------------------------------------------------ 1 file changed, 193 insertions(+), 1316 deletions(-) diff --git a/main.c b/main.c index 296b159..bf1d3aa 100644 --- a/main.c +++ b/main.c @@ -11,6 +11,180 @@ #include "game_board.h" #include "decision_tree.h" #define CREDITS "Authors:\n- MOUHOUS Mathya (G3)\n- AIT MEDDOUR Fouâd-Eddine (G1)\nSoftware Used:\n- SDL3 master (https://github.com/libsdl-org/SDL)\n- SDL3_ttf master (https://github.com/libsdl-org/SDL_ttf)\n- SDL3_image master (https://github.com/libsdl-org/SDL_image)\n- CMake 3.30.6 (https://gitlab.kitware.com/cmake/cmake)\nFont : Acme 9 Regular\nTested On :\n- Ubuntu 24.10\n- Gentoo amd64 Stable\n- Windows 10 KVM/QEMU\n- Windows 11" +#define RESIZE_HANDLER \ +int h, w;\ +SDL_GetWindowSize(window, &w, &h);\ +window_resolution.x = (float) w;\ +window_resolution.y = (float) h;\ +scale_ratio = (SDL_FPoint){window_resolution.x / 1366, window_resolution.y / 768};\ +TTF_SetFontSize(font,SDL_min(scale_ratio.x, scale_ratio.y) * 30);\ +TTF_SetFontSize(font_underlined,SDL_min(scale_ratio.x, scale_ratio.y) * 30);\ +TTF_SetFontSize(font_credits,SDL_min(scale_ratio.x, scale_ratio.y) * 23);\ +board_dims = window_resolution.y - 300;\ +piece_size = board_dims / 5;\ +empty_square_size = piece_size / 3;\ +graphical_board = (SDL_FRect){\ + (window_resolution.x - board_dims) / 2, (window_resolution.y - board_dims) / 2 + 70,\ + board_dims, board_dims\ +};\ +hot_points[0] = (SDL_FPoint){graphical_board.x, graphical_board.y};\ +hot_points[1] = (SDL_FPoint){graphical_board.x + board_dims / 2, graphical_board.y};\ +hot_points[2] = (SDL_FPoint){graphical_board.x + board_dims, graphical_board.y};\ +hot_points[3] = (SDL_FPoint){graphical_board.x, graphical_board.y + board_dims / 2};\ +hot_points[4] = (SDL_FPoint){\ + graphical_board.x + board_dims / 2, graphical_board.y + board_dims / 2\ +};\ +hot_points[5] = (SDL_FPoint){\ + graphical_board.x + board_dims, graphical_board.y + board_dims / 2\ +};\ +hot_points[6] = (SDL_FPoint){graphical_board.x, graphical_board.y + board_dims};\ +hot_points[7] = (SDL_FPoint){\ + graphical_board.x + board_dims / 2, graphical_board.y + board_dims\ +};\ +hot_points[8] = (SDL_FPoint){\ + graphical_board.x + board_dims, graphical_board.y + board_dims\ +};\ +text_w = 0;\ +text_h = 0;\ +TTF_GetTextSize(CREDITS_text, &text_w, &text_h);\ +CREDITS_rect = (SDL_FRect){\ + (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 75, (float) text_w,\ + (float) text_h\ +};\ +TTF_GetTextSize(WELCOME_text, &text_w, &text_h);\ +WELCOME_x = (window_resolution.x - (float) text_w) / 2;\ +TTF_GetTextSize(ORDER_text, &text_w, &text_h);\ +ORDER_x = (window_resolution.x - (float) text_w) / 2;\ +TTF_GetTextSize(ABOUT_TITLE_text, &text_w, &text_h);\ +ABOUT_TITLE_x = (window_resolution.x - (float) text_w) / 2;\ +TTF_GetTextSize(SETTINGS_TITLE_text, &text_w, &text_h);\ +SETTINGS_TITLE_x = (window_resolution.x - (float) text_w) / 2;\ +TTF_GetTextSize(ROUNDS_text, &text_w, &text_h);\ +ROUNDS_x = (window_resolution.x - (float) text_w) / 2;\ +TTF_GetTextSize(AI_IS_THINKING_text, &text_w, &text_h);\ +AI_THINKING_x = (window_resolution.x - (float) text_w) / 2;\ +AI_THINKING_y = (window_resolution.y - (float) text_h);\ +TTF_GetTextSize(BACK_text, &text_w, &text_h);\ +BACK_rect = (SDL_FRect){\ + 0, (window_resolution.y - (float) text_h), (float) text_w, (float) text_h\ +};\ +TTF_GetTextSize(RETRY_text, &text_w, &text_h);\ +RETRY_rect = (SDL_FRect){\ + 0, (window_resolution.y - (float) text_h) / 2, (float) text_w, (float) text_h\ +};\ +TTF_GetTextSize(MAIN_MENU_text, &text_w, &text_h);\ +MAIN_MENU_rect = (SDL_FRect){\ + (window_resolution.x - (float) text_w), (window_resolution.y - (float) text_h) / 2,\ + (float) text_w,\ + (float) text_h\ +};\ +menu_y = scale_ratio.y * 50;\ +menu_x = 0;\ +TTF_GetTextSize(PVP_text, &text_w, &text_h);\ +PVP_rect = (SDL_FRect){\ + menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h\ +};\ +TTF_GetTextSize(PVA_text, &text_w, &text_h);\ +PVA_rect = (SDL_FRect){\ + menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h\ +};\ +TTF_GetTextSize(AVA_text, &text_w, &text_h);\ +AVA_rect = (SDL_FRect){\ + menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h\ +};\ +TTF_GetTextSize(SETTINGS_text, &text_w, &text_h);\ +SETTINGS_rect = (SDL_FRect){\ + menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h\ +};\ +TTF_GetTextSize(ABOUT_text, &text_w, &text_h);\ +ABOUT_rect = (SDL_FRect){\ + menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h\ +};\ +TTF_GetTextSize(QUIT_text, &text_w, &text_h);\ +QUIT_rect = (SDL_FRect){\ + menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h\ +};\ +TTF_GetTextSize(AIFirst_text, &text_w, &text_h);\ +AIFirst_rect = (SDL_FRect){\ + (window_resolution.x - (float) text_w) / 4, scale_ratio.y * 400, (float) text_w,\ + (float) text_h\ +};\ +TTF_GetTextSize(PlayerFirst_text, &text_w, &text_h);\ +PlayerFirst_rect = (SDL_FRect){\ + 3 * (window_resolution.x - (float) text_w) / 4, scale_ratio.y * 400, (float) text_w,\ + (float) text_h\ +};\ +TTF_GetTextSize(ENTROPY_text, &text_w, &text_h);\ +ENTROPY_rect = (SDL_FRect){\ + (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 100, (float) text_w,\ + (float) text_h\ +};\ +TTF_GetTextSize(FULLSCREEN_text, &text_w, &text_h);\ +FULLSCREEN_rect = (SDL_FRect){\ + (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 100, (float) text_w,\ + (float) text_h\ +};\ +TTF_GetTextSize(PLAYER1_COLOR_text, &text_w, &text_h);\ +PLAYER1_COLOR_rect = (SDL_FRect){\ + (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 300, (float) text_w,\ + (float) text_h\ +};\ +TTF_GetTextSize(PLAYER1_COLOR_setting_text, &text_w, &text_h);\ +PLAYER1_COLOR_setting_rect = (SDL_FRect){\ + (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 400, (float) text_w,\ + (float) text_h\ +};\ +TTF_GetTextSize(PLAYER2_COLOR_text, &text_w, &text_h);\ +PLAYER2_COLOR_rect = (SDL_FRect){\ + (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 500, (float) text_w,\ + (float) text_h\ +};\ +TTF_GetTextSize(PLAYER2_COLOR_setting_text, &text_w, &text_h);\ +PLAYER2_COLOR_setting_rect = (SDL_FRect){\ + (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 600, (float) text_w,\ + (float) text_h\ +};\ +TTF_GetTextSize(AI_ONE_text, &text_w, &text_h);\ +AI_ONE_rect = (SDL_FRect){\ + (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 200, (float) text_w,\ + (float) text_h\ +};\ +TTF_GetTextSize(AI_TWO_text, &text_w, &text_h);\ +AI_TWO_rect = (SDL_FRect){\ + (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 400, (float) text_w,\ + (float) text_h\ +};\ +TTF_GetTextSize(NO_RANDOMNESS_text, &text_w, &text_h);\ +NO_RANDOMNESS_rect = (SDL_FRect){0, scale_ratio.y * 300, (float) text_w, (float) text_h};\ +TTF_GetTextSize(SOME_RANDOMNESS_text, &text_w, &text_h);\ +SOME_RANDOMNESS_rect = (SDL_FRect){\ + (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 300, (float) text_w,\ + (float) text_h\ +};\ +TTF_GetTextSize(ALL_RANDOMNESS_text, &text_w, &text_h);\ +ALL_RANDOMNESS_rect = (SDL_FRect){\ + (window_resolution.x - (float) text_w), scale_ratio.y * 300, (float) text_w,\ + (float) text_h\ +};\ +TTF_GetTextSize(NO_RANDOMNESS2_text, &text_w, &text_h);\ +NO_RANDOMNESS2_rect = (SDL_FRect){0, scale_ratio.y * 500, (float) text_w, (float) text_h};\ +TTF_GetTextSize(SOME_RANDOMNESS2_text, &text_w, &text_h);\ +SOME_RANDOMNESS2_rect = (SDL_FRect){\ + (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 500, (float) text_w,\ + (float) text_h\ +};\ +TTF_GetTextSize(ALL_RANDOMNESS2_text, &text_w, &text_h);\ +ALL_RANDOMNESS2_rect = (SDL_FRect){\ + (window_resolution.x - (float) text_w), scale_ratio.y * 500, (float) text_w,\ + (float) text_h\ +};\ +TTF_GetTextSize(NEXT_text, &text_w, &text_h);\ +TTF_DrawRendererText(NEXT_text, window_resolution.x - (float) text_w,\ + window_resolution.y - (float) text_h);\ +NEXT_rect = (SDL_FRect){\ + window_resolution.x - (float) text_w, window_resolution.y - (float) text_h,\ + (float) text_w, (float) text_h\ +}; typedef enum ACHI_SCENE { ACHI_MENU, @@ -200,12 +374,12 @@ int main(void) { TTF_Text *MAIN_MENU_text = TTF_CreateText(text_engine, font_underlined, "Main Menu", 0); TTF_Text *ABOUT_TITLE_text = TTF_CreateText(text_engine, font, "About the project", 0); TTF_Text *SETTINGS_TITLE_text = TTF_CreateText(text_engine, font, "Settings", 0); - TTF_Text *CREDITS_text = TTF_CreateText(text_engine,font_credits,CREDITS,0); + TTF_Text *CREDITS_text = TTF_CreateText(text_engine, font_credits,CREDITS, 0); int text_w = 0; int text_h = 0; - TTF_GetTextSize(CREDITS_text,&text_w,&text_h); + TTF_GetTextSize(CREDITS_text, &text_w, &text_h); SDL_FRect CREDITS_rect = {(window_resolution.x - (float) text_w) / 2, 75, (float) text_w, (float) text_h}; TTF_GetTextSize(WELCOME_text, &text_w, &text_h); @@ -372,174 +546,9 @@ int main(void) { while (SDL_PollEvent(&event)) { switch (event.type) { - case SDL_EVENT_WINDOW_RESIZED: { - int h, w; - SDL_GetWindowSize(window, &w, &h); - window_resolution.x = (float) w; - window_resolution.y = (float) h; - scale_ratio = (SDL_FPoint){window_resolution.x / 1366, window_resolution.y / 768}; - TTF_SetFontSize(font,SDL_min(scale_ratio.x, scale_ratio.y) * 30); - TTF_SetFontSize(font_underlined,SDL_min(scale_ratio.x, scale_ratio.y) * 30); - TTF_SetFontSize(font_credits,SDL_min(scale_ratio.x, scale_ratio.y) * 23); - board_dims = window_resolution.y - 300; - piece_size = board_dims / 5; - empty_square_size = piece_size / 3; - graphical_board = (SDL_FRect){ - (window_resolution.x - board_dims) / 2, (window_resolution.y - board_dims) / 2 + 70, - board_dims, board_dims - }; - hot_points[0] = (SDL_FPoint){graphical_board.x, graphical_board.y}; - hot_points[1] = (SDL_FPoint){graphical_board.x + board_dims / 2, graphical_board.y}; - hot_points[2] = (SDL_FPoint){graphical_board.x + board_dims, graphical_board.y}; - hot_points[3] = (SDL_FPoint){graphical_board.x, graphical_board.y + board_dims / 2}; - hot_points[4] = (SDL_FPoint){ - graphical_board.x + board_dims / 2, graphical_board.y + board_dims / 2 - }; - hot_points[5] = (SDL_FPoint){ - graphical_board.x + board_dims, graphical_board.y + board_dims / 2 - }; - hot_points[6] = (SDL_FPoint){graphical_board.x, graphical_board.y + board_dims}; - hot_points[7] = (SDL_FPoint){ - graphical_board.x + board_dims / 2, graphical_board.y + board_dims - }; - hot_points[8] = (SDL_FPoint){ - graphical_board.x + board_dims, graphical_board.y + board_dims - }; - text_w = 0; - text_h = 0; - TTF_GetTextSize(CREDITS_text,&text_w,&text_h); - CREDITS_rect = (SDL_FRect){(window_resolution.x - (float) text_w) / 2, scale_ratio.y * 75, (float) text_w, (float) text_h}; - TTF_GetTextSize(WELCOME_text, &text_w, &text_h); - WELCOME_x = (window_resolution.x - (float) text_w) / 2; - TTF_GetTextSize(ORDER_text, &text_w, &text_h); - ORDER_x = (window_resolution.x - (float) text_w) / 2; - TTF_GetTextSize(ABOUT_TITLE_text, &text_w, &text_h); - ABOUT_TITLE_x = (window_resolution.x - (float) text_w) / 2; - TTF_GetTextSize(SETTINGS_TITLE_text, &text_w, &text_h); - SETTINGS_TITLE_x = (window_resolution.x - (float) text_w) / 2; - TTF_GetTextSize(ROUNDS_text, &text_w, &text_h); - ROUNDS_x = (window_resolution.x - (float) text_w) / 2; - TTF_GetTextSize(AI_IS_THINKING_text, &text_w, &text_h); - AI_THINKING_x = (window_resolution.x - (float) text_w) / 2; - AI_THINKING_y = (window_resolution.y - (float) text_h); - TTF_GetTextSize(BACK_text, &text_w, &text_h); - BACK_rect = (SDL_FRect){ - 0, (window_resolution.y - (float) text_h), (float) text_w, (float) text_h - }; - TTF_GetTextSize(RETRY_text, &text_w, &text_h); - RETRY_rect = (SDL_FRect){ - 0, (window_resolution.y - (float) text_h) / 2, (float) text_w, (float) text_h - }; - TTF_GetTextSize(MAIN_MENU_text, &text_w, &text_h); - MAIN_MENU_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w), (window_resolution.y - (float) text_h) / 2, - (float) text_w, - (float) text_h - }; - menu_y = scale_ratio.y * 50; - menu_x = 0; - - TTF_GetTextSize(PVP_text, &text_w, &text_h); - PVP_rect = (SDL_FRect){ - menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h - }; - TTF_GetTextSize(PVA_text, &text_w, &text_h); - PVA_rect = (SDL_FRect){ - menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h - }; - TTF_GetTextSize(AVA_text, &text_w, &text_h); - AVA_rect = (SDL_FRect){ - menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h - }; - TTF_GetTextSize(SETTINGS_text, &text_w, &text_h); - SETTINGS_rect = (SDL_FRect){ - menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h - }; - TTF_GetTextSize(ABOUT_text, &text_w, &text_h); - ABOUT_rect = (SDL_FRect){ - menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h - }; - TTF_GetTextSize(QUIT_text, &text_w, &text_h); - QUIT_rect = (SDL_FRect){ - menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h - }; - TTF_GetTextSize(AIFirst_text, &text_w, &text_h); - AIFirst_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 4, scale_ratio.y * 400, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(PlayerFirst_text, &text_w, &text_h); - PlayerFirst_rect = (SDL_FRect){ - 3 * (window_resolution.x - (float) text_w) / 4, scale_ratio.y * 400, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(ENTROPY_text, &text_w, &text_h); - ENTROPY_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 100, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(FULLSCREEN_text, &text_w, &text_h); - FULLSCREEN_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 100, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(PLAYER1_COLOR_text, &text_w, &text_h); - PLAYER1_COLOR_rect = (SDL_FRect){(window_resolution.x - (float) text_w) / 2,scale_ratio.y *300, (float) text_w, (float) text_h}; - TTF_GetTextSize(PLAYER1_COLOR_setting_text, &text_w, &text_h); - PLAYER1_COLOR_setting_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 400, (float) text_w, (float) text_h - }; - - TTF_GetTextSize(PLAYER2_COLOR_text, &text_w, &text_h); - PLAYER2_COLOR_rect = (SDL_FRect){(window_resolution.x - (float) text_w) / 2, scale_ratio.y * 500, (float) text_w, (float) text_h}; - TTF_GetTextSize(PLAYER2_COLOR_setting_text, &text_w, &text_h); - PLAYER2_COLOR_setting_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y *600, (float) text_w, (float) text_h - }; - TTF_GetTextSize(AI_ONE_text, &text_w, &text_h); - AI_ONE_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 200, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(AI_TWO_text, &text_w, &text_h); - AI_TWO_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 400, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(NO_RANDOMNESS_text, &text_w, &text_h); - NO_RANDOMNESS_rect = (SDL_FRect){0, scale_ratio.y * 300, (float) text_w, (float) text_h}; - - TTF_GetTextSize(SOME_RANDOMNESS_text, &text_w, &text_h); - SOME_RANDOMNESS_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 300, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(ALL_RANDOMNESS_text, &text_w, &text_h); - ALL_RANDOMNESS_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w), scale_ratio.y * 300, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(NO_RANDOMNESS2_text, &text_w, &text_h); - NO_RANDOMNESS2_rect = (SDL_FRect){0, scale_ratio.y * 500, (float) text_w, (float) text_h}; - TTF_GetTextSize(SOME_RANDOMNESS2_text, &text_w, &text_h); - SOME_RANDOMNESS2_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 500, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(ALL_RANDOMNESS2_text, &text_w, &text_h); - ALL_RANDOMNESS2_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w), scale_ratio.y * 500, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(NEXT_text, &text_w, &text_h); - TTF_DrawRendererText(NEXT_text, window_resolution.x - (float) text_w, - window_resolution.y - (float) text_h); - NEXT_rect = (SDL_FRect){ - window_resolution.x - (float) text_w, window_resolution.y - (float) text_h, - (float) text_w, (float) text_h - }; - } - break; + case SDL_EVENT_WINDOW_RESIZED: + RESIZE_HANDLER + break; case SDL_EVENT_QUIT: quit = true; break; case SDL_EVENT_MOUSE_BUTTON_UP: @@ -593,172 +602,7 @@ int main(void) { while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_EVENT_WINDOW_RESIZED: - int h, w; - SDL_GetWindowSize(window, &w, &h); - window_resolution.x = (float) w; - window_resolution.y = (float) h; - scale_ratio = (SDL_FPoint){window_resolution.x / 1366, window_resolution.y / 768}; - TTF_SetFontSize(font,SDL_min(scale_ratio.x, scale_ratio.y) * 30); - TTF_SetFontSize(font_underlined,SDL_min(scale_ratio.x, scale_ratio.y) * 30); - TTF_SetFontSize(font_credits,SDL_min(scale_ratio.x, scale_ratio.y) * 23); - board_dims = window_resolution.y - 300; - piece_size = board_dims / 5; - empty_square_size = piece_size / 3; - graphical_board = (SDL_FRect){ - (window_resolution.x - board_dims) / 2, (window_resolution.y - board_dims) / 2 + 70, - board_dims, board_dims - }; - hot_points[0] = (SDL_FPoint){graphical_board.x, graphical_board.y}; - hot_points[1] = (SDL_FPoint){graphical_board.x + board_dims / 2, graphical_board.y}; - hot_points[2] = (SDL_FPoint){graphical_board.x + board_dims, graphical_board.y}; - hot_points[3] = (SDL_FPoint){graphical_board.x, graphical_board.y + board_dims / 2}; - hot_points[4] = (SDL_FPoint){ - graphical_board.x + board_dims / 2, graphical_board.y + board_dims / 2 - }; - hot_points[5] = (SDL_FPoint){ - graphical_board.x + board_dims, graphical_board.y + board_dims / 2 - }; - hot_points[6] = (SDL_FPoint){graphical_board.x, graphical_board.y + board_dims}; - hot_points[7] = (SDL_FPoint){ - graphical_board.x + board_dims / 2, graphical_board.y + board_dims - }; - hot_points[8] = (SDL_FPoint){ - graphical_board.x + board_dims, graphical_board.y + board_dims - }; - text_w = 0; - text_h = 0; - TTF_GetTextSize(CREDITS_text,&text_w,&text_h); - CREDITS_rect = (SDL_FRect){(window_resolution.x - (float) text_w) / 2, scale_ratio.y * 75, (float) text_w, (float) text_h}; - TTF_GetTextSize(WELCOME_text, &text_w, &text_h); - WELCOME_x = (window_resolution.x - (float) text_w) / 2; - TTF_GetTextSize(ORDER_text, &text_w, &text_h); - ORDER_x = (window_resolution.x - (float) text_w) / 2; - TTF_GetTextSize(ABOUT_TITLE_text, &text_w, &text_h); - ABOUT_TITLE_x = (window_resolution.x - (float) text_w) / 2; - - TTF_GetTextSize(SETTINGS_TITLE_text, &text_w, &text_h); - SETTINGS_TITLE_x = (window_resolution.x - (float) text_w) / 2; - TTF_GetTextSize(ROUNDS_text, &text_w, &text_h); - ROUNDS_x = (window_resolution.x - (float) text_w) / 2; - TTF_GetTextSize(AI_IS_THINKING_text, &text_w, &text_h); - AI_THINKING_x = (window_resolution.x - (float) text_w) / 2; - AI_THINKING_y = (window_resolution.y - (float) text_h); - TTF_GetTextSize(BACK_text, &text_w, &text_h); - BACK_rect = (SDL_FRect){ - 0, (window_resolution.y - (float) text_h), (float) text_w, (float) text_h - }; - TTF_GetTextSize(RETRY_text, &text_w, &text_h); - RETRY_rect = (SDL_FRect){ - 0, (window_resolution.y - (float) text_h) / 2, (float) text_w, (float) text_h - }; - TTF_GetTextSize(MAIN_MENU_text, &text_w, &text_h); - MAIN_MENU_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w), (window_resolution.y - (float) text_h) / 2, - (float) text_w, - (float) text_h - }; - menu_y = scale_ratio.y * 50; - menu_x = 0; - - TTF_GetTextSize(PVP_text, &text_w, &text_h); - PVP_rect = (SDL_FRect){ - menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h - }; - TTF_GetTextSize(PVA_text, &text_w, &text_h); - PVA_rect = (SDL_FRect){ - menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h - }; - TTF_GetTextSize(AVA_text, &text_w, &text_h); - AVA_rect = (SDL_FRect){ - menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h - }; - TTF_GetTextSize(SETTINGS_text, &text_w, &text_h); - SETTINGS_rect = (SDL_FRect){ - menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h - }; - TTF_GetTextSize(ABOUT_text, &text_w, &text_h); - ABOUT_rect = (SDL_FRect){ - menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h - }; - TTF_GetTextSize(QUIT_text, &text_w, &text_h); - QUIT_rect = (SDL_FRect){ - menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h - }; - TTF_GetTextSize(AIFirst_text, &text_w, &text_h); - AIFirst_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 4, scale_ratio.y * 400, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(PlayerFirst_text, &text_w, &text_h); - PlayerFirst_rect = (SDL_FRect){ - 3 * (window_resolution.x - (float) text_w) / 4, scale_ratio.y * 400, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(ENTROPY_text, &text_w, &text_h); - ENTROPY_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 100, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(FULLSCREEN_text, &text_w, &text_h); - FULLSCREEN_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 100, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(PLAYER1_COLOR_text, &text_w, &text_h); - PLAYER1_COLOR_rect = (SDL_FRect){(window_resolution.x - (float) text_w) / 2,scale_ratio.y *300, (float) text_w, (float) text_h}; - TTF_GetTextSize(PLAYER1_COLOR_setting_text, &text_w, &text_h); - PLAYER1_COLOR_setting_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 400, (float) text_w, (float) text_h - }; - - TTF_GetTextSize(PLAYER2_COLOR_text, &text_w, &text_h); - PLAYER2_COLOR_rect = (SDL_FRect){(window_resolution.x - (float) text_w) / 2, scale_ratio.y *500, (float) text_w, (float) text_h}; - TTF_GetTextSize(PLAYER2_COLOR_setting_text, &text_w, &text_h); - PLAYER2_COLOR_setting_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y *600, (float) text_w, (float) text_h - }; - TTF_GetTextSize(AI_ONE_text, &text_w, &text_h); - AI_ONE_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 200, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(AI_TWO_text, &text_w, &text_h); - AI_TWO_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 400, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(NO_RANDOMNESS_text, &text_w, &text_h); - NO_RANDOMNESS_rect = (SDL_FRect){0, scale_ratio.y * 300, (float) text_w, (float) text_h}; - - TTF_GetTextSize(SOME_RANDOMNESS_text, &text_w, &text_h); - SOME_RANDOMNESS_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 300, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(ALL_RANDOMNESS_text, &text_w, &text_h); - ALL_RANDOMNESS_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w), scale_ratio.y * 300, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(NO_RANDOMNESS2_text, &text_w, &text_h); - NO_RANDOMNESS2_rect = (SDL_FRect){0, scale_ratio.y * 500, (float) text_w, (float) text_h}; - TTF_GetTextSize(SOME_RANDOMNESS2_text, &text_w, &text_h); - SOME_RANDOMNESS2_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 500, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(ALL_RANDOMNESS2_text, &text_w, &text_h); - ALL_RANDOMNESS2_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w), scale_ratio.y * 500, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(NEXT_text, &text_w, &text_h); - TTF_DrawRendererText(NEXT_text, window_resolution.x - (float) text_w, - window_resolution.y - (float) text_h); - NEXT_rect = (SDL_FRect){ - window_resolution.x - (float) text_w, window_resolution.y - (float) text_h, - (float) text_w, (float) text_h - }; + RESIZE_HANDLER break; case SDL_EVENT_QUIT: quit = true; break; @@ -825,175 +669,9 @@ int main(void) { while (SDL_PollEvent(&event)) { switch (event.type) { - case SDL_EVENT_WINDOW_RESIZED: { - int h, w; - SDL_GetWindowSize(window, &w, &h); - window_resolution.x = (float) w; - window_resolution.y = (float) h; - scale_ratio = (SDL_FPoint){window_resolution.x / 1366, window_resolution.y / 768}; - TTF_SetFontSize(font,SDL_min(scale_ratio.x, scale_ratio.y) * 30); - TTF_SetFontSize(font_underlined,SDL_min(scale_ratio.x, scale_ratio.y) * 30); - TTF_SetFontSize(font_credits,SDL_min(scale_ratio.x, scale_ratio.y) * 23); - board_dims = window_resolution.y - 300; - piece_size = board_dims / 5; - empty_square_size = piece_size / 3; - graphical_board = (SDL_FRect){ - (window_resolution.x - board_dims) / 2, (window_resolution.y - board_dims) / 2 + 70, - board_dims, board_dims - }; - hot_points[0] = (SDL_FPoint){graphical_board.x, graphical_board.y}; - hot_points[1] = (SDL_FPoint){graphical_board.x + board_dims / 2, graphical_board.y}; - hot_points[2] = (SDL_FPoint){graphical_board.x + board_dims, graphical_board.y}; - hot_points[3] = (SDL_FPoint){graphical_board.x, graphical_board.y + board_dims / 2}; - hot_points[4] = (SDL_FPoint){ - graphical_board.x + board_dims / 2, graphical_board.y + board_dims / 2 - }; - hot_points[5] = (SDL_FPoint){ - graphical_board.x + board_dims, graphical_board.y + board_dims / 2 - }; - hot_points[6] = (SDL_FPoint){graphical_board.x, graphical_board.y + board_dims}; - hot_points[7] = (SDL_FPoint){ - graphical_board.x + board_dims / 2, graphical_board.y + board_dims - }; - hot_points[8] = (SDL_FPoint){ - graphical_board.x + board_dims, graphical_board.y + board_dims - }; - text_w = 0; - text_h = 0; - TTF_GetTextSize(CREDITS_text,&text_w,&text_h); - CREDITS_rect = (SDL_FRect){(window_resolution.x - (float) text_w) / 2, scale_ratio.y * 75, (float) text_w, (float) text_h}; - TTF_GetTextSize(WELCOME_text, &text_w, &text_h); - WELCOME_x = (window_resolution.x - (float) text_w) / 2; - TTF_GetTextSize(ORDER_text, &text_w, &text_h); - ORDER_x = (window_resolution.x - (float) text_w) / 2; - TTF_GetTextSize(ABOUT_TITLE_text, &text_w, &text_h); - ABOUT_TITLE_x = (window_resolution.x - (float) text_w) / 2; - TTF_GetTextSize(SETTINGS_TITLE_text, &text_w, &text_h); - SETTINGS_TITLE_x = (window_resolution.x - (float) text_w) / 2; - TTF_GetTextSize(ROUNDS_text, &text_w, &text_h); - ROUNDS_x = (window_resolution.x - (float) text_w) / 2; - TTF_GetTextSize(AI_IS_THINKING_text, &text_w, &text_h); - AI_THINKING_x = (window_resolution.x - (float) text_w) / 2; - AI_THINKING_y = (window_resolution.y - (float) text_h); - TTF_GetTextSize(BACK_text, &text_w, &text_h); - BACK_rect = (SDL_FRect){ - 0, (window_resolution.y - (float) text_h), (float) text_w, (float) text_h - }; - TTF_GetTextSize(RETRY_text, &text_w, &text_h); - RETRY_rect = (SDL_FRect){ - 0, (window_resolution.y - (float) text_h) / 2, (float) text_w, (float) text_h - }; - TTF_GetTextSize(MAIN_MENU_text, &text_w, &text_h); - MAIN_MENU_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w), (window_resolution.y - (float) text_h) / 2, - (float) text_w, - (float) text_h - }; - menu_y = scale_ratio.y * 50; - menu_x = 0; - - TTF_GetTextSize(PVP_text, &text_w, &text_h); - PVP_rect = (SDL_FRect){ - menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h - }; - TTF_GetTextSize(PVA_text, &text_w, &text_h); - PVA_rect = (SDL_FRect){ - menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h - }; - TTF_GetTextSize(AVA_text, &text_w, &text_h); - AVA_rect = (SDL_FRect){ - menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h - }; - TTF_GetTextSize(SETTINGS_text, &text_w, &text_h); - SETTINGS_rect = (SDL_FRect){ - menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h - }; - TTF_GetTextSize(ABOUT_text, &text_w, &text_h); - ABOUT_rect = (SDL_FRect){ - menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h - }; - TTF_GetTextSize(QUIT_text, &text_w, &text_h); - QUIT_rect = (SDL_FRect){ - menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h - }; - TTF_GetTextSize(AIFirst_text, &text_w, &text_h); - AIFirst_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 4, scale_ratio.y * 400, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(PlayerFirst_text, &text_w, &text_h); - PlayerFirst_rect = (SDL_FRect){ - 3 * (window_resolution.x - (float) text_w) / 4, scale_ratio.y * 400, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(ENTROPY_text, &text_w, &text_h); - ENTROPY_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 100, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(FULLSCREEN_text, &text_w, &text_h); - FULLSCREEN_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 100, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(PLAYER1_COLOR_text, &text_w, &text_h); - PLAYER1_COLOR_rect = (SDL_FRect){(window_resolution.x - (float) text_w) / 2,scale_ratio.y *300, (float) text_w, (float) text_h}; - TTF_GetTextSize(PLAYER1_COLOR_setting_text, &text_w, &text_h); - PLAYER1_COLOR_setting_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 400, (float) text_w, (float) text_h - }; - - TTF_GetTextSize(PLAYER2_COLOR_text, &text_w, &text_h); - PLAYER2_COLOR_rect = (SDL_FRect){(window_resolution.x - (float) text_w) / 2, scale_ratio.y *500, (float) text_w, (float) text_h}; - TTF_GetTextSize(PLAYER2_COLOR_setting_text, &text_w, &text_h); - PLAYER2_COLOR_setting_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y *600, (float) text_w, (float) text_h - }; - - TTF_GetTextSize(AI_ONE_text, &text_w, &text_h); - AI_ONE_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 200, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(AI_TWO_text, &text_w, &text_h); - AI_TWO_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 400, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(NO_RANDOMNESS_text, &text_w, &text_h); - NO_RANDOMNESS_rect = (SDL_FRect){0, scale_ratio.y * 300, (float) text_w, (float) text_h}; - - TTF_GetTextSize(SOME_RANDOMNESS_text, &text_w, &text_h); - SOME_RANDOMNESS_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 300, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(ALL_RANDOMNESS_text, &text_w, &text_h); - ALL_RANDOMNESS_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w), scale_ratio.y * 300, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(NO_RANDOMNESS2_text, &text_w, &text_h); - NO_RANDOMNESS2_rect = (SDL_FRect){0, scale_ratio.y * 500, (float) text_w, (float) text_h}; - TTF_GetTextSize(SOME_RANDOMNESS2_text, &text_w, &text_h); - SOME_RANDOMNESS2_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 500, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(ALL_RANDOMNESS2_text, &text_w, &text_h); - ALL_RANDOMNESS2_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w), scale_ratio.y * 500, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(NEXT_text, &text_w, &text_h); - TTF_DrawRendererText(NEXT_text, window_resolution.x - (float) text_w, - window_resolution.y - (float) text_h); - NEXT_rect = (SDL_FRect){ - window_resolution.x - (float) text_w, window_resolution.y - (float) text_h, - (float) text_w, (float) text_h - }; - } - break; + case SDL_EVENT_WINDOW_RESIZED: + RESIZE_HANDLER + break; case SDL_EVENT_QUIT: quit = true; break; case SDL_EVENT_MOUSE_BUTTON_UP: @@ -1047,172 +725,7 @@ int main(void) { while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_EVENT_WINDOW_RESIZED: - int h, w; - SDL_GetWindowSize(window, &w, &h); - window_resolution.x = (float) w; - window_resolution.y = (float) h; - scale_ratio = (SDL_FPoint){window_resolution.x / 1366, window_resolution.y / 768}; - TTF_SetFontSize(font,SDL_min(scale_ratio.x, scale_ratio.y) * 30); - TTF_SetFontSize(font_underlined,SDL_min(scale_ratio.x, scale_ratio.y) * 30); - TTF_SetFontSize(font_credits,SDL_min(scale_ratio.x, scale_ratio.y) * 23); - board_dims = window_resolution.y - 300; - piece_size = board_dims / 5; - empty_square_size = piece_size / 3; - graphical_board = (SDL_FRect){ - (window_resolution.x - board_dims) / 2, (window_resolution.y - board_dims) / 2 + 70, - board_dims, board_dims - }; - hot_points[0] = (SDL_FPoint){graphical_board.x, graphical_board.y}; - hot_points[1] = (SDL_FPoint){graphical_board.x + board_dims / 2, graphical_board.y}; - hot_points[2] = (SDL_FPoint){graphical_board.x + board_dims, graphical_board.y}; - hot_points[3] = (SDL_FPoint){graphical_board.x, graphical_board.y + board_dims / 2}; - hot_points[4] = (SDL_FPoint){ - graphical_board.x + board_dims / 2, graphical_board.y + board_dims / 2 - }; - hot_points[5] = (SDL_FPoint){ - graphical_board.x + board_dims, graphical_board.y + board_dims / 2 - }; - hot_points[6] = (SDL_FPoint){graphical_board.x, graphical_board.y + board_dims}; - hot_points[7] = (SDL_FPoint){ - graphical_board.x + board_dims / 2, graphical_board.y + board_dims - }; - hot_points[8] = (SDL_FPoint){ - graphical_board.x + board_dims, graphical_board.y + board_dims - }; - text_w = 0; - text_h = 0; - TTF_GetTextSize(CREDITS_text,&text_w,&text_h); - CREDITS_rect = (SDL_FRect){(window_resolution.x - (float) text_w) / 2, scale_ratio.y * 75, (float) text_w, (float) text_h}; - TTF_GetTextSize(WELCOME_text, &text_w, &text_h); - WELCOME_x = (window_resolution.x - (float) text_w) / 2; - TTF_GetTextSize(ORDER_text, &text_w, &text_h); - ORDER_x = (window_resolution.x - (float) text_w) / 2; - TTF_GetTextSize(ABOUT_TITLE_text, &text_w, &text_h); - ABOUT_TITLE_x = (window_resolution.x - (float) text_w) / 2; - - TTF_GetTextSize(SETTINGS_TITLE_text, &text_w, &text_h); - SETTINGS_TITLE_x = (window_resolution.x - (float) text_w) / 2; - TTF_GetTextSize(ROUNDS_text, &text_w, &text_h); - ROUNDS_x = (window_resolution.x - (float) text_w) / 2; - TTF_GetTextSize(AI_IS_THINKING_text, &text_w, &text_h); - AI_THINKING_x = (window_resolution.x - (float) text_w) / 2; - AI_THINKING_y = (window_resolution.y - (float) text_h); - TTF_GetTextSize(BACK_text, &text_w, &text_h); - BACK_rect = (SDL_FRect){ - 0, (window_resolution.y - (float) text_h), (float) text_w, (float) text_h - }; - TTF_GetTextSize(RETRY_text, &text_w, &text_h); - RETRY_rect = (SDL_FRect){ - 0, (window_resolution.y - (float) text_h) / 2, (float) text_w, (float) text_h - }; - TTF_GetTextSize(MAIN_MENU_text, &text_w, &text_h); - MAIN_MENU_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w), (window_resolution.y - (float) text_h) / 2, - (float) text_w, - (float) text_h - }; - menu_y = scale_ratio.y * 50; - menu_x = 0; - - TTF_GetTextSize(PVP_text, &text_w, &text_h); - PVP_rect = (SDL_FRect){ - menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h - }; - TTF_GetTextSize(PVA_text, &text_w, &text_h); - PVA_rect = (SDL_FRect){ - menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h - }; - TTF_GetTextSize(AVA_text, &text_w, &text_h); - AVA_rect = (SDL_FRect){ - menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h - }; - TTF_GetTextSize(SETTINGS_text, &text_w, &text_h); - SETTINGS_rect = (SDL_FRect){ - menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h - }; - TTF_GetTextSize(ABOUT_text, &text_w, &text_h); - ABOUT_rect = (SDL_FRect){ - menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h - }; - TTF_GetTextSize(QUIT_text, &text_w, &text_h); - QUIT_rect = (SDL_FRect){ - menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h - }; - TTF_GetTextSize(AIFirst_text, &text_w, &text_h); - AIFirst_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 4, scale_ratio.y * 400, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(PlayerFirst_text, &text_w, &text_h); - PlayerFirst_rect = (SDL_FRect){ - 3 * (window_resolution.x - (float) text_w) / 4, scale_ratio.y * 400, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(ENTROPY_text, &text_w, &text_h); - ENTROPY_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 100, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(FULLSCREEN_text, &text_w, &text_h); - FULLSCREEN_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 100, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(PLAYER1_COLOR_text, &text_w, &text_h); - PLAYER1_COLOR_rect = (SDL_FRect){(window_resolution.x - (float) text_w) / 2,scale_ratio.y *300, (float) text_w, (float) text_h}; - TTF_GetTextSize(PLAYER1_COLOR_setting_text, &text_w, &text_h); - PLAYER1_COLOR_setting_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 400, (float) text_w, (float) text_h - }; - - TTF_GetTextSize(PLAYER2_COLOR_text, &text_w, &text_h); - PLAYER2_COLOR_rect = (SDL_FRect){(window_resolution.x - (float) text_w) / 2, scale_ratio.y *500, (float) text_w, (float) text_h}; - TTF_GetTextSize(PLAYER2_COLOR_setting_text, &text_w, &text_h); - PLAYER2_COLOR_setting_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y *600, (float) text_w, (float) text_h - }; - TTF_GetTextSize(AI_ONE_text, &text_w, &text_h); - AI_ONE_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 200, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(AI_TWO_text, &text_w, &text_h); - AI_TWO_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 400, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(NO_RANDOMNESS_text, &text_w, &text_h); - NO_RANDOMNESS_rect = (SDL_FRect){0, scale_ratio.y * 300, (float) text_w, (float) text_h}; - - TTF_GetTextSize(SOME_RANDOMNESS_text, &text_w, &text_h); - SOME_RANDOMNESS_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 300, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(ALL_RANDOMNESS_text, &text_w, &text_h); - ALL_RANDOMNESS_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w), scale_ratio.y * 300, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(NO_RANDOMNESS2_text, &text_w, &text_h); - NO_RANDOMNESS2_rect = (SDL_FRect){0, scale_ratio.y * 500, (float) text_w, (float) text_h}; - TTF_GetTextSize(SOME_RANDOMNESS2_text, &text_w, &text_h); - SOME_RANDOMNESS2_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 500, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(ALL_RANDOMNESS2_text, &text_w, &text_h); - ALL_RANDOMNESS2_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w), scale_ratio.y * 500, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(NEXT_text, &text_w, &text_h); - TTF_DrawRendererText(NEXT_text, window_resolution.x - (float) text_w, - window_resolution.y - (float) text_h); - NEXT_rect = (SDL_FRect){ - window_resolution.x - (float) text_w, window_resolution.y - (float) text_h, - (float) text_w, (float) text_h - }; + RESIZE_HANDLER break; case SDL_EVENT_QUIT: quit = true; break; @@ -1404,159 +917,7 @@ int main(void) { while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_EVENT_WINDOW_RESIZED: - int h, w; - SDL_GetWindowSize(window, &w, &h); - window_resolution.x = (float) w; - window_resolution.y = (float) h; - scale_ratio = (SDL_FPoint){window_resolution.x / 1366, window_resolution.y / 768}; - TTF_SetFontSize(font,SDL_min(scale_ratio.x, scale_ratio.y) * 30); - TTF_SetFontSize(font_underlined,SDL_min(scale_ratio.x, scale_ratio.y) * 30); - TTF_SetFontSize(font_credits,SDL_min(scale_ratio.x, scale_ratio.y) * 23); - board_dims = window_resolution.y - 300; - piece_size = board_dims / 5; - empty_square_size = piece_size / 3; - graphical_board = (SDL_FRect){ - (window_resolution.x - board_dims) / 2, (window_resolution.y - board_dims) / 2 + 70, - board_dims, board_dims - }; - hot_points[0] = (SDL_FPoint){graphical_board.x, graphical_board.y}; - hot_points[1] = (SDL_FPoint){graphical_board.x + board_dims / 2, graphical_board.y}; - hot_points[2] = (SDL_FPoint){graphical_board.x + board_dims, graphical_board.y}; - hot_points[3] = (SDL_FPoint){graphical_board.x, graphical_board.y + board_dims / 2}; - hot_points[4] = (SDL_FPoint){ - graphical_board.x + board_dims / 2, graphical_board.y + board_dims / 2 - }; - hot_points[5] = (SDL_FPoint){ - graphical_board.x + board_dims, graphical_board.y + board_dims / 2 - }; - hot_points[6] = (SDL_FPoint){graphical_board.x, graphical_board.y + board_dims}; - hot_points[7] = (SDL_FPoint){ - graphical_board.x + board_dims / 2, graphical_board.y + board_dims - }; - hot_points[8] = (SDL_FPoint){ - graphical_board.x + board_dims, graphical_board.y + board_dims - }; - text_w = 0; - text_h = 0; - TTF_GetTextSize(CREDITS_text,&text_w,&text_h); - CREDITS_rect = (SDL_FRect){(window_resolution.x - (float) text_w) / 2, scale_ratio.y * 75, (float) text_w, (float) text_h}; - TTF_GetTextSize(WELCOME_text, &text_w, &text_h); - WELCOME_x = (window_resolution.x - (float) text_w) / 2; - TTF_GetTextSize(ORDER_text, &text_w, &text_h); - ORDER_x = (window_resolution.x - (float) text_w) / 2; - TTF_GetTextSize(ABOUT_TITLE_text, &text_w, &text_h); - ABOUT_TITLE_x = (window_resolution.x - (float) text_w) / 2; - - TTF_GetTextSize(SETTINGS_TITLE_text, &text_w, &text_h); - SETTINGS_TITLE_x = (window_resolution.x - (float) text_w) / 2; - TTF_GetTextSize(ROUNDS_text, &text_w, &text_h); - ROUNDS_x = (window_resolution.x - (float) text_w) / 2; - TTF_GetTextSize(AI_IS_THINKING_text, &text_w, &text_h); - AI_THINKING_x = (window_resolution.x - (float) text_w) / 2; - AI_THINKING_y = (window_resolution.y - (float) text_h); - TTF_GetTextSize(BACK_text, &text_w, &text_h); - BACK_rect = (SDL_FRect){ - 0, (window_resolution.y - (float) text_h), (float) text_w, (float) text_h - }; - TTF_GetTextSize(RETRY_text, &text_w, &text_h); - RETRY_rect = (SDL_FRect){ - 0, (window_resolution.y - (float) text_h) / 2, (float) text_w, (float) text_h - }; - TTF_GetTextSize(MAIN_MENU_text, &text_w, &text_h); - MAIN_MENU_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w), (window_resolution.y - (float) text_h) / 2, - (float) text_w, - (float) text_h - }; - menu_y = scale_ratio.y * 50; - menu_x = 0; - - TTF_GetTextSize(PVP_text, &text_w, &text_h); - PVP_rect = (SDL_FRect){ - menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h - }; - TTF_GetTextSize(PVA_text, &text_w, &text_h); - PVA_rect = (SDL_FRect){ - menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h - }; - TTF_GetTextSize(AVA_text, &text_w, &text_h); - AVA_rect = (SDL_FRect){ - menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h - }; - TTF_GetTextSize(SETTINGS_text, &text_w, &text_h); - SETTINGS_rect = (SDL_FRect){ - menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h - }; - TTF_GetTextSize(ABOUT_text, &text_w, &text_h); - ABOUT_rect = (SDL_FRect){ - menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h - }; - TTF_GetTextSize(QUIT_text, &text_w, &text_h); - QUIT_rect = (SDL_FRect){ - menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h - }; - TTF_GetTextSize(AIFirst_text, &text_w, &text_h); - AIFirst_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 4, scale_ratio.y * 400, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(PlayerFirst_text, &text_w, &text_h); - PlayerFirst_rect = (SDL_FRect){ - 3 * (window_resolution.x - (float) text_w) / 4, scale_ratio.y * 400, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(ENTROPY_text, &text_w, &text_h); - ENTROPY_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 100, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(AI_ONE_text, &text_w, &text_h); - AI_ONE_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 200, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(AI_TWO_text, &text_w, &text_h); - AI_TWO_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 400, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(NO_RANDOMNESS_text, &text_w, &text_h); - NO_RANDOMNESS_rect = (SDL_FRect){ - 0, scale_ratio.y * 300, (float) text_w, (float) text_h - }; - - TTF_GetTextSize(SOME_RANDOMNESS_text, &text_w, &text_h); - SOME_RANDOMNESS_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 300, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(ALL_RANDOMNESS_text, &text_w, &text_h); - ALL_RANDOMNESS_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w), scale_ratio.y * 300, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(NO_RANDOMNESS2_text, &text_w, &text_h); - NO_RANDOMNESS2_rect = (SDL_FRect){ - 0, scale_ratio.y * 500, (float) text_w, (float) text_h - }; - TTF_GetTextSize(SOME_RANDOMNESS2_text, &text_w, &text_h); - SOME_RANDOMNESS2_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 500, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(ALL_RANDOMNESS2_text, &text_w, &text_h); - ALL_RANDOMNESS2_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w), scale_ratio.y * 500, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(NEXT_text, &text_w, &text_h); - TTF_DrawRendererText(NEXT_text, window_resolution.x - (float) text_w, - window_resolution.y - (float) text_h); - NEXT_rect = (SDL_FRect){ - window_resolution.x - (float) text_w, window_resolution.y - (float) text_h, - (float) text_w, (float) text_h - }; - + RESIZE_HANDLER break; case SDL_EVENT_QUIT: quit = true; break; @@ -1886,159 +1247,7 @@ int main(void) { while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_EVENT_WINDOW_RESIZED: - int h, w; - SDL_GetWindowSize(window, &w, &h); - window_resolution.x = (float) w; - window_resolution.y = (float) h; - scale_ratio = (SDL_FPoint){window_resolution.x / 1366, window_resolution.y / 768}; - TTF_SetFontSize(font,SDL_min(scale_ratio.x, scale_ratio.y) * 30); - TTF_SetFontSize(font_underlined,SDL_min(scale_ratio.x, scale_ratio.y) * 30); - TTF_SetFontSize(font_credits,SDL_min(scale_ratio.x, scale_ratio.y) * 23); - board_dims = window_resolution.y - 300; - piece_size = board_dims / 5; - empty_square_size = piece_size / 3; - graphical_board = (SDL_FRect){ - (window_resolution.x - board_dims) / 2, (window_resolution.y - board_dims) / 2 + 70, - board_dims, board_dims - }; - hot_points[0] = (SDL_FPoint){graphical_board.x, graphical_board.y}; - hot_points[1] = (SDL_FPoint){graphical_board.x + board_dims / 2, graphical_board.y}; - hot_points[2] = (SDL_FPoint){graphical_board.x + board_dims, graphical_board.y}; - hot_points[3] = (SDL_FPoint){graphical_board.x, graphical_board.y + board_dims / 2}; - hot_points[4] = (SDL_FPoint){ - graphical_board.x + board_dims / 2, graphical_board.y + board_dims / 2 - }; - hot_points[5] = (SDL_FPoint){ - graphical_board.x + board_dims, graphical_board.y + board_dims / 2 - }; - hot_points[6] = (SDL_FPoint){graphical_board.x, graphical_board.y + board_dims}; - hot_points[7] = (SDL_FPoint){ - graphical_board.x + board_dims / 2, graphical_board.y + board_dims - }; - hot_points[8] = (SDL_FPoint){ - graphical_board.x + board_dims, graphical_board.y + board_dims - }; - text_w = 0; - text_h = 0; - TTF_GetTextSize(CREDITS_text,&text_w,&text_h); - CREDITS_rect = (SDL_FRect){(window_resolution.x - (float) text_w) / 2, scale_ratio.y * 75, (float) text_w, (float) text_h}; - TTF_GetTextSize(WELCOME_text, &text_w, &text_h); - WELCOME_x = (window_resolution.x - (float) text_w) / 2; - TTF_GetTextSize(ORDER_text, &text_w, &text_h); - ORDER_x = (window_resolution.x - (float) text_w) / 2; - TTF_GetTextSize(ABOUT_TITLE_text, &text_w, &text_h); - ABOUT_TITLE_x = (window_resolution.x - (float) text_w) / 2; - - TTF_GetTextSize(SETTINGS_TITLE_text, &text_w, &text_h); - SETTINGS_TITLE_x = (window_resolution.x - (float) text_w) / 2; - TTF_GetTextSize(ROUNDS_text, &text_w, &text_h); - ROUNDS_x = (window_resolution.x - (float) text_w) / 2; - TTF_GetTextSize(AI_IS_THINKING_text, &text_w, &text_h); - AI_THINKING_x = (window_resolution.x - (float) text_w) / 2; - AI_THINKING_y = (window_resolution.y - (float) text_h); - TTF_GetTextSize(BACK_text, &text_w, &text_h); - BACK_rect = (SDL_FRect){ - 0, (window_resolution.y - (float) text_h), (float) text_w, (float) text_h - }; - TTF_GetTextSize(RETRY_text, &text_w, &text_h); - RETRY_rect = (SDL_FRect){ - 0, (window_resolution.y - (float) text_h) / 2, (float) text_w, (float) text_h - }; - TTF_GetTextSize(MAIN_MENU_text, &text_w, &text_h); - MAIN_MENU_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w), (window_resolution.y - (float) text_h) / 2, - (float) text_w, - (float) text_h - }; - menu_y = scale_ratio.y * 50; - menu_x = 0; - - TTF_GetTextSize(PVP_text, &text_w, &text_h); - PVP_rect = (SDL_FRect){ - menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h - }; - TTF_GetTextSize(PVA_text, &text_w, &text_h); - PVA_rect = (SDL_FRect){ - menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h - }; - TTF_GetTextSize(AVA_text, &text_w, &text_h); - AVA_rect = (SDL_FRect){ - menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h - }; - TTF_GetTextSize(SETTINGS_text, &text_w, &text_h); - SETTINGS_rect = (SDL_FRect){ - menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h - }; - TTF_GetTextSize(ABOUT_text, &text_w, &text_h); - ABOUT_rect = (SDL_FRect){ - menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h - }; - TTF_GetTextSize(QUIT_text, &text_w, &text_h); - QUIT_rect = (SDL_FRect){ - menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h - }; - TTF_GetTextSize(AIFirst_text, &text_w, &text_h); - AIFirst_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 4, scale_ratio.y * 400, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(PlayerFirst_text, &text_w, &text_h); - PlayerFirst_rect = (SDL_FRect){ - 3 * (window_resolution.x - (float) text_w) / 4, scale_ratio.y * 400, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(ENTROPY_text, &text_w, &text_h); - ENTROPY_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 100, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(AI_ONE_text, &text_w, &text_h); - AI_ONE_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 200, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(AI_TWO_text, &text_w, &text_h); - AI_TWO_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 400, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(NO_RANDOMNESS_text, &text_w, &text_h); - NO_RANDOMNESS_rect = (SDL_FRect){ - 0, scale_ratio.y * 300, (float) text_w, (float) text_h - }; - - TTF_GetTextSize(SOME_RANDOMNESS_text, &text_w, &text_h); - SOME_RANDOMNESS_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 300, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(ALL_RANDOMNESS_text, &text_w, &text_h); - ALL_RANDOMNESS_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w), scale_ratio.y * 300, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(NO_RANDOMNESS2_text, &text_w, &text_h); - NO_RANDOMNESS2_rect = (SDL_FRect){ - 0, scale_ratio.y * 500, (float) text_w, (float) text_h - }; - TTF_GetTextSize(SOME_RANDOMNESS2_text, &text_w, &text_h); - SOME_RANDOMNESS2_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 500, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(ALL_RANDOMNESS2_text, &text_w, &text_h); - ALL_RANDOMNESS2_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w), scale_ratio.y * 500, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(NEXT_text, &text_w, &text_h); - TTF_DrawRendererText(NEXT_text, window_resolution.x - (float) text_w, - window_resolution.y - (float) text_h); - NEXT_rect = (SDL_FRect){ - window_resolution.x - (float) text_w, window_resolution.y - (float) text_h, - (float) text_w, (float) text_h - }; - + RESIZE_HANDLER break; case SDL_EVENT_QUIT: SDL_Log("Quitting"); quit = true; @@ -2095,7 +1304,8 @@ int main(void) { TTF_SetTextColor(FULLSCREEN_text, 0xFF, 0xFF, 0xFF,SDL_ALPHA_OPAQUE); TTF_DrawRendererText(FULLSCREEN_text, FULLSCREEN_rect.x, FULLSCREEN_rect.y); if (SDL_PointInRectFloat(&mouse, &BACK_rect) || SDL_PointInRectFloat(&mouse, &FULLSCREEN_rect) || - SDL_PointInRectFloat(&mouse, &PLAYER1_COLOR_rect)|| SDL_PointInRectFloat(&mouse,&PLAYER2_COLOR_rect)) + SDL_PointInRectFloat(&mouse, &PLAYER1_COLOR_rect) || SDL_PointInRectFloat( + &mouse, &PLAYER2_COLOR_rect)) SDL_SetCursor(pointing_cursor); if (SDL_PointInRectFloat(&mouse, &FULLSCREEN_rect)) TTF_SetTextFont(FULLSCREEN_text, font_underlined); @@ -2127,8 +1337,7 @@ int main(void) { if (selected_color == 1) { strcat(buf, event.text.text); player1_color_hex = (int) strtol(buf, nullptr, 16); - } - else if (selected_color == 2) { + } else if (selected_color == 2) { strcat(buf, event.text.text); player2_color_hex = (int) strtol(buf, nullptr, 16); } @@ -2139,8 +1348,7 @@ int main(void) { if (selected_color == 1) { buf[strlen(buf) - 1] = '\0'; player1_color_hex = (int) strtol(buf, nullptr, 16); - } - else if (selected_color == 2) { + } else if (selected_color == 2) { buf[strlen(buf) - 1] = '\0'; player2_color_hex = (int) strtol(buf, nullptr, 16); } @@ -2241,172 +1449,7 @@ int main(void) { } break; case SDL_EVENT_WINDOW_RESIZED: - int h, w; - SDL_GetWindowSize(window, &w, &h); - window_resolution.x = (float) w; - window_resolution.y = (float) h; - scale_ratio = (SDL_FPoint){window_resolution.x / 1366, window_resolution.y / 768}; - TTF_SetFontSize(font,SDL_min(scale_ratio.x, scale_ratio.y) * 30); - TTF_SetFontSize(font_underlined,SDL_min(scale_ratio.x, scale_ratio.y) * 30); - TTF_SetFontSize(font_credits,SDL_min(scale_ratio.x, scale_ratio.y) * 23); - board_dims = window_resolution.y - 300; - piece_size = board_dims / 5; - empty_square_size = piece_size / 3; - graphical_board = (SDL_FRect){ - (window_resolution.x - board_dims) / 2, (window_resolution.y - board_dims) / 2 + 70, - board_dims, board_dims - }; - hot_points[0] = (SDL_FPoint){graphical_board.x, graphical_board.y}; - hot_points[1] = (SDL_FPoint){graphical_board.x + board_dims / 2, graphical_board.y}; - hot_points[2] = (SDL_FPoint){graphical_board.x + board_dims, graphical_board.y}; - hot_points[3] = (SDL_FPoint){graphical_board.x, graphical_board.y + board_dims / 2}; - hot_points[4] = (SDL_FPoint){ - graphical_board.x + board_dims / 2, graphical_board.y + board_dims / 2 - }; - hot_points[5] = (SDL_FPoint){ - graphical_board.x + board_dims, graphical_board.y + board_dims / 2 - }; - hot_points[6] = (SDL_FPoint){graphical_board.x, graphical_board.y + board_dims}; - hot_points[7] = (SDL_FPoint){ - graphical_board.x + board_dims / 2, graphical_board.y + board_dims - }; - hot_points[8] = (SDL_FPoint){ - graphical_board.x + board_dims, graphical_board.y + board_dims - }; - text_w = 0; - text_h = 0; - TTF_GetTextSize(CREDITS_text,&text_w,&text_h); - CREDITS_rect = (SDL_FRect){(window_resolution.x - (float) text_w) / 2, scale_ratio.y * 75, (float) text_w, (float) text_h}; - TTF_GetTextSize(WELCOME_text, &text_w, &text_h); - WELCOME_x = (window_resolution.x - (float) text_w) / 2; - TTF_GetTextSize(ORDER_text, &text_w, &text_h); - ORDER_x = (window_resolution.x - (float) text_w) / 2; - TTF_GetTextSize(ABOUT_TITLE_text, &text_w, &text_h); - ABOUT_TITLE_x = (window_resolution.x - (float) text_w) / 2; - - TTF_GetTextSize(SETTINGS_TITLE_text, &text_w, &text_h); - SETTINGS_TITLE_x = (window_resolution.x - (float) text_w) / 2; - TTF_GetTextSize(ROUNDS_text, &text_w, &text_h); - ROUNDS_x = (window_resolution.x - (float) text_w) / 2; - TTF_GetTextSize(AI_IS_THINKING_text, &text_w, &text_h); - AI_THINKING_x = (window_resolution.x - (float) text_w) / 2; - AI_THINKING_y = (window_resolution.y - (float) text_h); - TTF_GetTextSize(BACK_text, &text_w, &text_h); - BACK_rect = (SDL_FRect){ - 0, (window_resolution.y - (float) text_h), (float) text_w, (float) text_h - }; - TTF_GetTextSize(RETRY_text, &text_w, &text_h); - RETRY_rect = (SDL_FRect){ - 0, (window_resolution.y - (float) text_h) / 2, (float) text_w, (float) text_h - }; - TTF_GetTextSize(MAIN_MENU_text, &text_w, &text_h); - MAIN_MENU_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w), (window_resolution.y - (float) text_h) / 2, - (float) text_w, - (float) text_h - }; - menu_y = scale_ratio.y * 50; - menu_x = 0; - - TTF_GetTextSize(PVP_text, &text_w, &text_h); - PVP_rect = (SDL_FRect){ - menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h - }; - TTF_GetTextSize(PVA_text, &text_w, &text_h); - PVA_rect = (SDL_FRect){ - menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h - }; - TTF_GetTextSize(AVA_text, &text_w, &text_h); - AVA_rect = (SDL_FRect){ - menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h - }; - TTF_GetTextSize(SETTINGS_text, &text_w, &text_h); - SETTINGS_rect = (SDL_FRect){ - menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h - }; - TTF_GetTextSize(ABOUT_text, &text_w, &text_h); - ABOUT_rect = (SDL_FRect){ - menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h - }; - TTF_GetTextSize(QUIT_text, &text_w, &text_h); - QUIT_rect = (SDL_FRect){ - menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h - }; - TTF_GetTextSize(AIFirst_text, &text_w, &text_h); - AIFirst_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 4, scale_ratio.y * 400, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(PlayerFirst_text, &text_w, &text_h); - PlayerFirst_rect = (SDL_FRect){ - 3 * (window_resolution.x - (float) text_w) / 4, scale_ratio.y * 400, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(ENTROPY_text, &text_w, &text_h); - ENTROPY_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 100, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(FULLSCREEN_text, &text_w, &text_h); - FULLSCREEN_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 100, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(PLAYER1_COLOR_text, &text_w, &text_h); - PLAYER1_COLOR_rect = (SDL_FRect){(window_resolution.x - (float) text_w) / 2,scale_ratio.y *300, (float) text_w, (float) text_h}; - TTF_GetTextSize(PLAYER1_COLOR_setting_text, &text_w, &text_h); - PLAYER1_COLOR_setting_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 400, (float) text_w, (float) text_h - }; - - TTF_GetTextSize(PLAYER2_COLOR_text, &text_w, &text_h); - PLAYER2_COLOR_rect = (SDL_FRect){(window_resolution.x - (float) text_w) / 2, scale_ratio.y *500, (float) text_w, (float) text_h}; - TTF_GetTextSize(PLAYER2_COLOR_setting_text, &text_w, &text_h); - PLAYER2_COLOR_setting_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y *600, (float) text_w, (float) text_h - }; - TTF_GetTextSize(AI_ONE_text, &text_w, &text_h); - AI_ONE_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 200, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(AI_TWO_text, &text_w, &text_h); - AI_TWO_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 400, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(NO_RANDOMNESS_text, &text_w, &text_h); - NO_RANDOMNESS_rect = (SDL_FRect){0, scale_ratio.y * 300, (float) text_w, (float) text_h}; - - TTF_GetTextSize(SOME_RANDOMNESS_text, &text_w, &text_h); - SOME_RANDOMNESS_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 300, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(ALL_RANDOMNESS_text, &text_w, &text_h); - ALL_RANDOMNESS_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w), scale_ratio.y * 300, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(NO_RANDOMNESS2_text, &text_w, &text_h); - NO_RANDOMNESS2_rect = (SDL_FRect){0, scale_ratio.y * 500, (float) text_w, (float) text_h}; - TTF_GetTextSize(SOME_RANDOMNESS2_text, &text_w, &text_h); - SOME_RANDOMNESS2_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 500, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(ALL_RANDOMNESS2_text, &text_w, &text_h); - ALL_RANDOMNESS2_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w), scale_ratio.y * 500, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(NEXT_text, &text_w, &text_h); - TTF_DrawRendererText(NEXT_text, window_resolution.x - (float) text_w, - window_resolution.y - (float) text_h); - NEXT_rect = (SDL_FRect){ - window_resolution.x - (float) text_w, window_resolution.y - (float) text_h, - (float) text_w, (float) text_h - }; + RESIZE_HANDLER break; case SDL_EVENT_QUIT: quit = true; @@ -2418,179 +1461,13 @@ int main(void) { case ACHI_ABOUT: TTF_DrawRendererText(ABOUT_TITLE_text, ABOUT_TITLE_x, 0); TTF_DrawRendererText(BACK_text, BACK_rect.x, BACK_rect.y); - TTF_DrawRendererText(CREDITS_text,CREDITS_rect.x,CREDITS_rect.y); + TTF_DrawRendererText(CREDITS_text, CREDITS_rect.x, CREDITS_rect.y); if (SDL_PointInRectFloat(&mouse, &BACK_rect)) SDL_SetCursor(pointing_cursor); while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_EVENT_WINDOW_RESIZED: - int h, w; - SDL_GetWindowSize(window, &w, &h); - window_resolution.x = (float) w; - window_resolution.y = (float) h; - scale_ratio = (SDL_FPoint){window_resolution.x / 1366, window_resolution.y / 768}; - TTF_SetFontSize(font,SDL_min(scale_ratio.x, scale_ratio.y) * 30); - TTF_SetFontSize(font_underlined,SDL_min(scale_ratio.x, scale_ratio.y) * 30); - TTF_SetFontSize(font_credits,SDL_min(scale_ratio.x, scale_ratio.y) * 23); - board_dims = window_resolution.y - 300; - piece_size = board_dims / 5; - empty_square_size = piece_size / 3; - graphical_board = (SDL_FRect){ - (window_resolution.x - board_dims) / 2, (window_resolution.y - board_dims) / 2 + 70, - board_dims, board_dims - }; - hot_points[0] = (SDL_FPoint){graphical_board.x, graphical_board.y}; - hot_points[1] = (SDL_FPoint){graphical_board.x + board_dims / 2, graphical_board.y}; - hot_points[2] = (SDL_FPoint){graphical_board.x + board_dims, graphical_board.y}; - hot_points[3] = (SDL_FPoint){graphical_board.x, graphical_board.y + board_dims / 2}; - hot_points[4] = (SDL_FPoint){ - graphical_board.x + board_dims / 2, graphical_board.y + board_dims / 2 - }; - hot_points[5] = (SDL_FPoint){ - graphical_board.x + board_dims, graphical_board.y + board_dims / 2 - }; - hot_points[6] = (SDL_FPoint){graphical_board.x, graphical_board.y + board_dims}; - hot_points[7] = (SDL_FPoint){ - graphical_board.x + board_dims / 2, graphical_board.y + board_dims - }; - hot_points[8] = (SDL_FPoint){ - graphical_board.x + board_dims, graphical_board.y + board_dims - }; - text_w = 0; - text_h = 0; - TTF_GetTextSize(CREDITS_text,&text_w,&text_h); - CREDITS_rect = (SDL_FRect){(window_resolution.x - (float) text_w) / 2, scale_ratio.y * 75, (float) text_w, (float) text_h}; - TTF_GetTextSize(WELCOME_text, &text_w, &text_h); - WELCOME_x = (window_resolution.x - (float) text_w) / 2; - TTF_GetTextSize(ORDER_text, &text_w, &text_h); - ORDER_x = (window_resolution.x - (float) text_w) / 2; - TTF_GetTextSize(ABOUT_TITLE_text, &text_w, &text_h); - ABOUT_TITLE_x = (window_resolution.x - (float) text_w) / 2; - - TTF_GetTextSize(SETTINGS_TITLE_text, &text_w, &text_h); - SETTINGS_TITLE_x = (window_resolution.x - (float) text_w) / 2; - TTF_GetTextSize(ROUNDS_text, &text_w, &text_h); - ROUNDS_x = (window_resolution.x - (float) text_w) / 2; - TTF_GetTextSize(AI_IS_THINKING_text, &text_w, &text_h); - AI_THINKING_x = (window_resolution.x - (float) text_w) / 2; - AI_THINKING_y = (window_resolution.y - (float) text_h); - TTF_GetTextSize(BACK_text, &text_w, &text_h); - BACK_rect = (SDL_FRect){ - 0, (window_resolution.y - (float) text_h), (float) text_w, (float) text_h - }; - TTF_GetTextSize(RETRY_text, &text_w, &text_h); - RETRY_rect = (SDL_FRect){ - 0, (window_resolution.y - (float) text_h) / 2, (float) text_w, (float) text_h - }; - TTF_GetTextSize(MAIN_MENU_text, &text_w, &text_h); - MAIN_MENU_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w), (window_resolution.y - (float) text_h) / 2, - (float) text_w, - (float) text_h - }; - menu_y = scale_ratio.y * 50; - menu_x = 0; - - TTF_GetTextSize(PVP_text, &text_w, &text_h); - PVP_rect = (SDL_FRect){ - menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h - }; - TTF_GetTextSize(PVA_text, &text_w, &text_h); - PVA_rect = (SDL_FRect){ - menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h - }; - TTF_GetTextSize(AVA_text, &text_w, &text_h); - AVA_rect = (SDL_FRect){ - menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h - }; - TTF_GetTextSize(SETTINGS_text, &text_w, &text_h); - SETTINGS_rect = (SDL_FRect){ - menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h - }; - TTF_GetTextSize(ABOUT_text, &text_w, &text_h); - ABOUT_rect = (SDL_FRect){ - menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h - }; - TTF_GetTextSize(QUIT_text, &text_w, &text_h); - QUIT_rect = (SDL_FRect){ - menu_x, menu_y += scale_ratio.y * 100, (float) text_w, (float) text_h - }; - TTF_GetTextSize(AIFirst_text, &text_w, &text_h); - AIFirst_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 4, scale_ratio.y * 400, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(PlayerFirst_text, &text_w, &text_h); - PlayerFirst_rect = (SDL_FRect){ - 3 * (window_resolution.x - (float) text_w) / 4, scale_ratio.y * 400, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(ENTROPY_text, &text_w, &text_h); - ENTROPY_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 100, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(FULLSCREEN_text, &text_w, &text_h); - FULLSCREEN_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 100, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(PLAYER1_COLOR_text, &text_w, &text_h); - PLAYER1_COLOR_rect = (SDL_FRect){(window_resolution.x - (float) text_w) / 2,scale_ratio.y *300, (float) text_w, (float) text_h}; - TTF_GetTextSize(PLAYER1_COLOR_setting_text, &text_w, &text_h); - PLAYER1_COLOR_setting_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 400, (float) text_w, (float) text_h - }; - - TTF_GetTextSize(PLAYER2_COLOR_text, &text_w, &text_h); - PLAYER2_COLOR_rect = (SDL_FRect){(window_resolution.x - (float) text_w) / 2, scale_ratio.y *500, (float) text_w, (float) text_h}; - TTF_GetTextSize(PLAYER2_COLOR_setting_text, &text_w, &text_h); - PLAYER2_COLOR_setting_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y *600, (float) text_w, (float) text_h - }; - TTF_GetTextSize(AI_ONE_text, &text_w, &text_h); - AI_ONE_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 200, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(AI_TWO_text, &text_w, &text_h); - AI_TWO_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 400, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(NO_RANDOMNESS_text, &text_w, &text_h); - NO_RANDOMNESS_rect = (SDL_FRect){0, scale_ratio.y * 300, (float) text_w, (float) text_h}; - - TTF_GetTextSize(SOME_RANDOMNESS_text, &text_w, &text_h); - SOME_RANDOMNESS_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 300, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(ALL_RANDOMNESS_text, &text_w, &text_h); - ALL_RANDOMNESS_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w), scale_ratio.y * 300, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(NO_RANDOMNESS2_text, &text_w, &text_h); - NO_RANDOMNESS2_rect = (SDL_FRect){0, scale_ratio.y * 500, (float) text_w, (float) text_h}; - TTF_GetTextSize(SOME_RANDOMNESS2_text, &text_w, &text_h); - SOME_RANDOMNESS2_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w) / 2, scale_ratio.y * 500, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(ALL_RANDOMNESS2_text, &text_w, &text_h); - ALL_RANDOMNESS2_rect = (SDL_FRect){ - (window_resolution.x - (float) text_w), scale_ratio.y * 500, (float) text_w, - (float) text_h - }; - TTF_GetTextSize(NEXT_text, &text_w, &text_h); - TTF_DrawRendererText(NEXT_text, window_resolution.x - (float) text_w, - window_resolution.y - (float) text_h); - NEXT_rect = (SDL_FRect){ - window_resolution.x - (float) text_w, window_resolution.y - (float) text_h, - (float) text_w, (float) text_h - }; - + RESIZE_HANDLER break; case SDL_EVENT_QUIT: quit = true; break;