From: 諏訪子 Date: Thu, 2 May 2024 11:21:50 +0000 (+0900) Subject: マウスでの移動 X-Git-Tag: mivfx-0.5.0~7^2~2 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=6345979d2eae19550dff441d52c8aea771c47229;p=mivfx.git マウスでの移動 --- diff --git a/main.c b/main.c index 300f39c..3d08ff2 100644 --- a/main.c +++ b/main.c @@ -18,6 +18,9 @@ int screenHeight; int init = 0; SDL_Rect renderQuad; +// マウス +int mouseX, mouseY, drag = 0; + const char* sofname = "mivfx"; const char* version = "0.5.0"; @@ -73,6 +76,29 @@ 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_WINDOWEVENT && e.window.event == SDL_WINDOWEVENT_RESIZED) { // ウィンドウのサイズが変わった場合 int newWidth = e.window.data1;