From a9a192b9fe3c30005b024efb47ee35d43255ffec Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E8=AB=8F=E8=A8=AA=E5=AD=90?= Date: Thu, 2 May 2024 19:00:38 +0900 Subject: [PATCH] =?utf8?q?=E7=94=BB=E5=83=8F=E3=81=AF=E5=A4=A7=E3=81=8D?= =?utf8?q?=E9=81=8E=E3=81=8E=E3=82=8B=E3=81=AE=E5=A0=B4=E5=90=88=E3=80=81?= =?utf8?q?=E7=94=BB=E9=9D=A2=E3=81=AB=E5=90=88=E3=81=86=E3=81=BE=E3=81=A7?= =?utf8?q?=E5=B0=8F=E3=81=95=E3=81=8F=E3=81=AB=E3=81=99=E3=82=8B=E6=A7=98?= =?utf8?q?=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + CHANGELOG.md | 1 + main.c | 41 +++++++++++++++++++++++++++++++++++------ 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index d4d3cd9..ac2f9af 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ mivfx release +*.core diff --git a/CHANGELOG.md b/CHANGELOG.md index 302b9b0..93bae8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # 0.5.0 * .desktopファイルの追加 * CDNを回避する様に +* 画像は大き過ぎるの場合、画面に合うまで小さくにする様に # 0.4.0 * URLから画像ファイルを開ける様に diff --git a/main.c b/main.c index db2e31b..07b161b 100644 --- a/main.c +++ b/main.c @@ -15,6 +15,8 @@ int imgWidth; int imgHeight; int screenWidth; int screenHeight; +int init = 0; +SDL_Rect renderQuad; const char* sofname = "mivfx"; const char* version = "0.5.0"; @@ -50,6 +52,10 @@ bool dlfile(const char* url, const char* filename) { } void windowevent(SDL_Event e) { + int windowWidth, windowHeight; + SDL_GetWindowSize(window, &windowWidth, &windowHeight); + SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); + if (e.type == SDL_QUIT) { quit = true; } else if (e.type == SDL_WINDOWEVENT && e.window.event == SDL_WINDOWEVENT_RESIZED) { @@ -85,15 +91,38 @@ void windowevent(SDL_Event e) { SDL_RenderCopy(renderer, texture, NULL, &renderQuad); SDL_SetWindowSize(window, scaledWidth, scaledHeight); } else if (e.type == SDL_WINDOWEVENT && e.window.event == SDL_WINDOWEVENT_EXPOSED) { - // 再描画が必要な場合 - - // 画面の更新 + SDL_Rect renderQuad = { imgWidth, imgHeight, imgWidth, imgHeight }; SDL_RenderClear(renderer); - // テキスチャーの表示 - SDL_RenderCopy(renderer, texture, NULL, NULL); + renderQuad.x = (windowWidth - renderQuad.w) / 2; + renderQuad.y = (windowHeight - renderQuad.h) / 2; + + if (init == 0) { + renderQuad.w = imgWidth; + renderQuad.h = imgHeight; + } - // 画面の更新 + if ( + (imgWidth >= (screenWidth - 100)) && + imgHeight >= (screenHeight - 100) + ) { + imgWidth -= (screenWidth * 3); + imgHeight -= (screenHeight * 3); + } else if ( + (imgWidth >= (screenWidth - 100)) && + imgHeight <= (screenHeight - 100) + ) { + imgWidth -= (screenWidth * 3); + } else if ( + (imgWidth <= (screenWidth - 100)) && + imgHeight >= (screenHeight - 100) + ) { + imgHeight -= (screenHeight * 3); + } + + SDL_RenderCopy(renderer, texture, NULL, &renderQuad); + if (init == 0) SDL_SetWindowSize(window, imgWidth + 20, imgHeight + 20); + init = 1; SDL_RenderPresent(renderer); } } -- 2.43.0