sa2 & mouse: fix dead y zone used to draw the menu.
Signed-off-by: Andrea Odetti <mariofutire@gmail.com>
This commit is contained in:
parent
a8057a5850
commit
db71bb1a4c
6 changed files with 35 additions and 2 deletions
|
@ -95,6 +95,8 @@ namespace sa2
|
|||
myOffset = (width * borderHeight + borderWidth) * sizeof(bgra_t);
|
||||
|
||||
allocateTexture(myTexture, myBorderlessWidth, myBorderlessHeight);
|
||||
|
||||
myDeadTopZone = 0;
|
||||
}
|
||||
|
||||
SDLImGuiFrame::~SDLImGuiFrame()
|
||||
|
@ -125,6 +127,7 @@ namespace sa2
|
|||
const ImVec2 uv1(1, 0);
|
||||
|
||||
const float menuBarHeight = mySettings.drawMenuBar(this);
|
||||
myDeadTopZone = menuBarHeight;
|
||||
|
||||
if (mySettings.windowed)
|
||||
{
|
||||
|
@ -143,6 +146,16 @@ namespace sa2
|
|||
}
|
||||
}
|
||||
|
||||
void SDLImGuiFrame::GetRelativeMousePosition(const SDL_MouseMotionEvent & motion, double & x, double & y) const
|
||||
{
|
||||
// this currently ignores a windowed apple video and applies to the whole sdl window
|
||||
int width, height;
|
||||
SDL_GetWindowSize(myWindow.get(), &width, &height);
|
||||
|
||||
x = double(motion.x) / double(width);
|
||||
y = double(std::max(motion.y, myDeadTopZone) - myDeadTopZone) / double(std::max(height - myDeadTopZone, 1));
|
||||
}
|
||||
|
||||
void SDLImGuiFrame::RenderPresent()
|
||||
{
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
|
|
|
@ -27,6 +27,7 @@ namespace sa2
|
|||
protected:
|
||||
|
||||
void ProcessSingleEvent(const SDL_Event & event, bool & quit) override;
|
||||
void GetRelativeMousePosition(const SDL_MouseMotionEvent & motion, double & x, double & y) const override;
|
||||
|
||||
private:
|
||||
|
||||
|
@ -38,6 +39,8 @@ namespace sa2
|
|||
size_t myBorderlessWidth;
|
||||
size_t myBorderlessHeight;
|
||||
|
||||
Sint32 myDeadTopZone; // for mouse position
|
||||
|
||||
SDL_GLContext myGLContext;
|
||||
ImTextureID myTexture;
|
||||
|
||||
|
|
|
@ -60,4 +60,14 @@ namespace sa2
|
|||
SDL_RenderPresent(myRenderer.get());
|
||||
}
|
||||
|
||||
void SDLRendererFrame::GetRelativeMousePosition(const SDL_MouseMotionEvent & motion, double & x, double & y) const
|
||||
{
|
||||
int width, height;
|
||||
SDL_GetWindowSize(myWindow.get(), &width, &height);
|
||||
|
||||
x = double(motion.x) / double(width);
|
||||
y = double(motion.y) / double(height);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -18,6 +18,9 @@ namespace sa2
|
|||
void UpdateTexture() override;
|
||||
void RenderPresent() override;
|
||||
|
||||
protected:
|
||||
void GetRelativeMousePosition(const SDL_MouseMotionEvent & motion, double & x, double & y) const override;
|
||||
|
||||
private:
|
||||
SDL_Rect myRect;
|
||||
int myPitch;
|
||||
|
|
|
@ -342,8 +342,11 @@ namespace sa2
|
|||
const int sizeX = iMaxX - iMinX + 1;
|
||||
const int sizeY = iMaxY - iMinY + 1;
|
||||
|
||||
const int newX = lround(double(motion.x) / double(width) * sizeX + iMinX);
|
||||
const int newY = lround(double(motion.y) / double(height) * sizeY + iMinY);
|
||||
double x, y;
|
||||
GetRelativeMousePosition(motion, x, y);
|
||||
|
||||
const int newX = lround(x * sizeX + iMinX);
|
||||
const int newY = lround(y * sizeY + iMinY);
|
||||
dx = newX - iX;
|
||||
dy = newY - iY;
|
||||
}
|
||||
|
|
|
@ -44,6 +44,7 @@ namespace sa2
|
|||
void SetApplicationIcon();
|
||||
|
||||
virtual void ProcessSingleEvent(const SDL_Event & event, bool & quit);
|
||||
virtual void GetRelativeMousePosition(const SDL_MouseMotionEvent & motion, double & x, double & y) const = 0;
|
||||
|
||||
void ProcessKeyDown(const SDL_KeyboardEvent & key);
|
||||
void ProcessKeyUp(const SDL_KeyboardEvent & key);
|
||||
|
|
Loading…
Add table
Reference in a new issue