From f206950ae83c0909611151915554db71024b135e Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E8=AB=8F=E8=A8=AA=E5=AD=90?= Date: Wed, 22 May 2024 19:10:54 +0900 Subject: [PATCH] =?utf8?q?=E5=86=8D=E3=83=AC=E3=83=B3=E3=83=80=E3=83=BC?= =?utf8?q?=E3=83=AA=E3=83=B3=E3=82=B0=E3=81=AE=E5=95=8F=E9=A1=8C=E3=81=AE?= =?utf8?q?=E4=BF=AE=E6=AD=A3=20+=20=E7=94=BB=E5=83=8F=E5=9B=9E=E8=BB=A2?= =?utf8?q?=E6=A9=9F=E8=83=BD=E6=80=A7=E3=81=AE=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 ++ main.c | 38 +++++++++++++++++++++++++++++++++++--- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c226bc6..052ae57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ * NetBSDは「/usr/pkg」→「/usr/local」 * スペルミスの修正 * manpageでコントロールの説明の追加 +* 再レンダーリングの問題の修正 +* 画像回転機能性の追加 # 0.5.0 * .desktopファイルの追加 diff --git a/main.c b/main.c index dd91b6a..98715fc 100644 --- a/main.c +++ b/main.c @@ -1,3 +1,4 @@ +#include "SDL2/SDL_render.h" #include #include #include @@ -28,6 +29,9 @@ int drag = 0; // ズーム float zoom = 1.0f; +// 回転 +float angle = 0.0f; + const char* sofname = "mivfx"; const char* version = "0.6.0"; @@ -68,6 +72,22 @@ bool dlfile(const char* url, const char* filename) { return true; } +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; + renderQuad.w = h; + renderQuad.h = w; + + SDL_SetWindowSize(window, newWindowWidth + 20, newWindowHeight + 20); + + SDL_RenderClear(renderer); + SDL_RenderCopyEx(renderer, texture, NULL, &renderQuad, angle, NULL, SDL_FLIP_NONE); + SDL_RenderPresent(renderer); +} + void windowevent(SDL_Event e) { int windowWidth, windowHeight; SDL_GetWindowSize(window, &windowWidth, &windowHeight); @@ -80,6 +100,12 @@ void windowevent(SDL_Event e) { quit = true; } else if (e.key.keysym.sym == SDLK_a) { // GIFアニメーションの停止・続き、0.6.0から追加する予定 + } else if (e.key.keysym.sym == SDLK_r) { + angle -= 90.0f; + rotateWindow(windowWidth, windowHeight); + } else if (e.key.keysym.sym == SDLK_t) { + angle += 90.0f; + rotateWindow(windowWidth, windowHeight); } } else if (e.type == SDL_MOUSEBUTTONDOWN) { if (e.button.button == SDL_BUTTON_LEFT) { @@ -182,6 +208,9 @@ void windowevent(SDL_Event e) { SDL_SetWindowSize(window, scaledWidth, scaledHeight); SDL_RenderCopy(renderer, texture, NULL, &renderQuad); } 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); @@ -211,15 +240,18 @@ void windowevent(SDL_Event e) { } SDL_RenderCopy(renderer, texture, NULL, &renderQuad); - if (init == 0) SDL_SetWindowSize(window, imgWidth + 20, imgHeight + 20); - init = 1; + SDL_SetWindowSize(window, imgWidth + 20, imgHeight + 20); SDL_RenderPresent(renderer); } } +void usage() { + printf("%s-%s\nusage: %s [file or url]\n", sofname, version, sofname); +} + int main(int argc, char* argv[]) { if (argc < 2) { - printf("%s-%s\nusage: %s \n", sofname, version, sofname); + usage(); return 1; } -- 2.43.0