From: 諏訪子 Date: Thu, 2 May 2024 13:37:00 +0000 (+0900) Subject: Merge branch 'master' of gitler.moe:suwako/mivfx into mousemove X-Git-Tag: mivfx-0.5.0~7^2~1 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=cb6a765e8fc22951c0ff5e0a35533cc58c88b563;p=mivfx.git Merge branch 'master' of gitler.moe:suwako/mivfx into mousemove --- cb6a765e8fc22951c0ff5e0a35533cc58c88b563 diff --cc main.c index 3d08ff2,52b5f83..6d0c2fb --- a/main.c +++ b/main.c @@@ -18,9 -18,9 +18,12 @@@ int screenHeight int init = 0; SDL_Rect renderQuad; +// マウス +int mouseX, mouseY, drag = 0; + + // ズーム + float zoom = 1.0f; + const char* sofname = "mivfx"; const char* version = "0.5.0"; @@@ -76,29 -74,45 +77,68 @@@ void windowevent(SDL_Event e) } else if (e.key.keysym.sym == SDLK_a) { // GIFアニメーションの停止・続き、0.6.0から追加する予定 } + } else if (e.type == SDL_MOUSEBUTTONDOWN) { + if (e.button.button == SDL_BUTTON_LEFT) { + drag = 1; + SDL_GetMouseState(&mouseX, &mouseY); + } + } else if (e.type == SDL_MOUSEBUTTONUP) { + if (e.button.button == SDL_BUTTON_LEFT) { + drag = 0; + } + } else if (e.type == SDL_MOUSEMOTION) { + if (drag) { + // TODO: 画像サイズを変わらないと、画面が黒くになる + int newMouseX, newMouseY; + SDL_GetMouseState(&newMouseX, &newMouseY); + SDL_RenderClear(renderer); + + renderQuad.x = newMouseX - (renderQuad.w / 2); + renderQuad.y = newMouseY - (renderQuad.h / 2); + + SDL_RenderClear(renderer); + SDL_RenderCopy(renderer, texture, NULL, &renderQuad); + SDL_RenderPresent(renderer); + } + } else if (e.type == SDL_MOUSEWHEEL) { + // TODO: ノートパソコンでおかしくなる + float zoomSpeed = 0.1f; + if (e.wheel.y > 0) { + zoom += zoomSpeed; + } else if (e.wheel.y < 0) { + zoom -= zoomSpeed; + } + + if (zoom < 0.1f) { + zoom = 0.1f; + } + + // 画像のサイズが変わった場合 + float newWidth = (float)imgWidth * zoom; + float newHeight = (float)imgHeight * zoom; + float minLimit = 50.0f; + + // 画像は50x50以下じゃ駄目 + if (newWidth < minLimit || newHeight < minLimit) { + newWidth = minLimit; + newHeight = minLimit; + } else if (newWidth < minLimit & newHeight >= minLimit) { + newWidth = minLimit; + } else if (newWidth >= minLimit && newHeight < minLimit) { + newHeight = minLimit; + } + + // テキスチャーのレンダーリングサイズの設定 + SDL_RenderClear(renderer); + + renderQuad.w = (int)newWidth; + renderQuad.h = (int)newHeight; + renderQuad.x = (windowWidth - renderQuad.w) / 2; + renderQuad.y = (windowHeight - renderQuad.h) / 2; + + SDL_RenderClear(renderer); + SDL_RenderCopy(renderer, texture, NULL, &renderQuad); + SDL_RenderPresent(renderer); } else if (e.type == SDL_WINDOWEVENT && e.window.event == SDL_WINDOWEVENT_RESIZED) { // ウィンドウのサイズが変わった場合 int newWidth = e.window.data1;