From 53aa5817abf03389503bbaba29a8a763e6d5d3a7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E8=AB=8F=E8=A8=AA=E5=AD=90?= Date: Fri, 3 May 2024 00:40:48 +0900 Subject: [PATCH] =?utf8?q?=E3=83=9E=E3=82=A6=E3=82=B9=E3=81=A7=E4=BD=BF?= =?utf8?q?=E3=81=A3=E3=81=A6=E7=94=BB=E5=83=8F=E3=82=92=E7=A7=BB=E5=8B=95?= =?utf8?q?=E5=87=BA=E6=9D=A5=E3=82=8B=E6=A7=98=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + main.c | 16 +++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 87fdb63..0af2a41 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * サイズ変更の修正 * Pixivからダウンロード出来る様に * ズーム機能性の追加 +* マウスで使って画像を移動出来る様に # 0.4.0 * URLから画像ファイルを開ける様に diff --git a/main.c b/main.c index 6d0c2fb..26f3317 100644 --- a/main.c +++ b/main.c @@ -17,9 +17,13 @@ int screenWidth; int screenHeight; int init = 0; SDL_Rect renderQuad; +float newWidth; +float newHeight; // マウス -int mouseX, mouseY, drag = 0; +int mouseX = 10; +int mouseY = 10; +int drag = 0; // ズーム float zoom = 1.0f; @@ -88,11 +92,14 @@ void windowevent(SDL_Event e) { } } else if (e.type == SDL_MOUSEMOTION) { if (drag) { - // TODO: 画像サイズを変わらないと、画面が黒くになる int newMouseX, newMouseY; SDL_GetMouseState(&newMouseX, &newMouseY); SDL_RenderClear(renderer); + if (newWidth == 0.0f) renderQuad.w = imgWidth; + else renderQuad.w = (int)newWidth; + if (newHeight == 0.0f) renderQuad.h = imgHeight; + else renderQuad.h = (int)newHeight; renderQuad.x = newMouseX - (renderQuad.w / 2); renderQuad.y = newMouseY - (renderQuad.h / 2); @@ -101,7 +108,6 @@ void windowevent(SDL_Event e) { SDL_RenderPresent(renderer); } } else if (e.type == SDL_MOUSEWHEEL) { - // TODO: ノートパソコンでおかしくなる float zoomSpeed = 0.1f; if (e.wheel.y > 0) { zoom += zoomSpeed; @@ -114,8 +120,8 @@ void windowevent(SDL_Event e) { } // 画像のサイズが変わった場合 - float newWidth = (float)imgWidth * zoom; - float newHeight = (float)imgHeight * zoom; + newWidth = (float)imgWidth * zoom; + newHeight = (float)imgHeight * zoom; float minLimit = 50.0f; // 画像は50x50以下じゃ駄目 -- 2.43.0