From 992bf65b2a280ff5735f9b2be8f0f6de98cbe8d7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E8=AB=8F=E8=A8=AA=E5=AD=90?= Date: Wed, 22 May 2024 21:07:19 +0900 Subject: [PATCH] =?utf8?q?=E4=BB=8A=E3=81=BE=E3=81=A7=E6=B0=97=E3=81=A5?= =?utf8?q?=E3=81=8D=E3=81=AA=E3=81=8B=E3=81=A3=E3=81=9F=E3=83=90=E3=82=B0?= =?utf8?q?=E3=81=AE=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- main.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/main.c b/main.c index 98715fc..d380486 100644 --- a/main.c +++ b/main.c @@ -1,4 +1,3 @@ -#include "SDL2/SDL_render.h" #include #include #include @@ -76,8 +75,10 @@ void rotateWindow(int w, int h) { if (angle >= 360.0f) angle = 0.0f; else if (angle <= -360.0f) angle = 0.0f; - int newWindowWidth = h - 20; - int newWindowHeight = w - 20; + int newWindowWidth = h; + int newWindowHeight = w; + renderQuad.x = 10; + renderQuad.y = 10; renderQuad.w = h; renderQuad.h = w; @@ -172,6 +173,7 @@ void windowevent(SDL_Event e) { SDL_RenderCopy(renderer, texture, NULL, &renderQuad); SDL_RenderPresent(renderer); } else if (e.type == SDL_WINDOWEVENT && e.window.event == SDL_WINDOWEVENT_RESIZED) { + SDL_RenderClear(renderer); // ウィンドウのサイズが変わった場合 int newWidth = e.window.data1; int newHeight = e.window.data2; @@ -200,25 +202,24 @@ void windowevent(SDL_Event e) { if (scaledHeight >= (screenHeight-20)) scaledHeight = screenHeight-20; // テキスチャーのレンダーリングサイズの設定 - renderQuad.x = imgWidth; - renderQuad.y = imgHeight; - renderQuad.w = scaledWidth; - renderQuad.h = scaledHeight; + SDL_Rect renderQuad = { 10, 10, scaledWidth, scaledHeight }; + + SDL_SetWindowSize(window, scaledWidth + 20, scaledHeight + 20); + SDL_RenderCopy(renderer, texture, NULL, &renderQuad); + SDL_RenderPresent(renderer); + } else if (e.type == SDL_WINDOWEVENT && e.window.event == SDL_WINDOWEVENT_MOVED) { + SDL_Rect renderQuad = { 10, 10, imgWidth, imgHeight }; - SDL_SetWindowSize(window, scaledWidth, scaledHeight); + SDL_RenderClear(renderer); SDL_RenderCopy(renderer, texture, NULL, &renderQuad); + SDL_SetWindowSize(window, imgWidth + 20, imgHeight + 20); + SDL_RenderPresent(renderer); } else if (e.type == SDL_WINDOWEVENT && e.window.event == SDL_WINDOWEVENT_EXPOSED) { if (init == 1) return; init = 1; - SDL_Rect renderQuad = { imgWidth, imgHeight, imgWidth, imgHeight }; SDL_RenderClear(renderer); - renderQuad.w = (windowWidth - 20); - renderQuad.h = (windowHeight - 20); - renderQuad.x = (windowWidth - renderQuad.w) / 2; - renderQuad.y = (windowHeight - renderQuad.h) / 2; - if ( (imgWidth >= (screenWidth - 100)) && imgHeight >= (screenHeight - 100) @@ -239,6 +240,8 @@ void windowevent(SDL_Event e) { imgWidth = (imgHeight * aspectRatio); } + SDL_Rect renderQuad = { 10, 10, imgWidth, imgHeight }; + SDL_RenderCopy(renderer, texture, NULL, &renderQuad); SDL_SetWindowSize(window, imgWidth + 20, imgHeight + 20); SDL_RenderPresent(renderer); -- 2.43.0