SDL: Support Mouse.
In ImGui there are a couple of issues: 1) it ignores the menu area when computing relative motion 2) does not work well with windowed video Signed-off-by: Andrea Odetti <mariofutire@gmail.com>
This commit is contained in:
parent
dd683e8e48
commit
f144cb037f
3 changed files with 69 additions and 0 deletions
|
@ -175,6 +175,16 @@ namespace sa2
|
|||
return; // do not pass on
|
||||
}
|
||||
}
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
case SDL_MOUSEMOTION:
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
if (io.WantCaptureMouse)
|
||||
{
|
||||
return; // do not pass on
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SDLFrame::ProcessSingleEvent(event, quit);
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include "NTSC.h"
|
||||
#include "CPU.h"
|
||||
#include "Mockingboard.h"
|
||||
#include "MouseInterface.h"
|
||||
|
||||
#include "linux/paddle.h"
|
||||
#include "linux/keyboard.h"
|
||||
|
@ -245,6 +246,17 @@ namespace sa2
|
|||
ProcessText(e.text);
|
||||
break;
|
||||
}
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
{
|
||||
ProcessMouseButton(e.button);
|
||||
break;
|
||||
}
|
||||
case SDL_MOUSEMOTION:
|
||||
{
|
||||
ProcessMouseMotion(e.motion);
|
||||
break;
|
||||
}
|
||||
case SDL_DROPFILE:
|
||||
{
|
||||
ProcessDropEvent(e.drop);
|
||||
|
@ -254,6 +266,51 @@ namespace sa2
|
|||
}
|
||||
}
|
||||
|
||||
void SDLFrame::ProcessMouseButton(const SDL_MouseButtonEvent & event)
|
||||
{
|
||||
CardManager & cardManager = GetCardMgr();
|
||||
|
||||
if (cardManager.IsMouseCardInstalled() && cardManager.GetMouseCard()->IsActiveAndEnabled())
|
||||
{
|
||||
switch (event.button)
|
||||
{
|
||||
case SDL_BUTTON_LEFT:
|
||||
case SDL_BUTTON_RIGHT:
|
||||
{
|
||||
const eBUTTONSTATE state = (event.state == SDL_PRESSED) ? BUTTON_DOWN : BUTTON_UP;
|
||||
const eBUTTON button = (event.button == SDL_BUTTON_LEFT) ? BUTTON0 : BUTTON1;
|
||||
cardManager.GetMouseCard()->SetButton(button, state);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SDLFrame::ProcessMouseMotion(const SDL_MouseMotionEvent & motion)
|
||||
{
|
||||
CardManager & cardManager = GetCardMgr();
|
||||
|
||||
if (cardManager.IsMouseCardInstalled() && cardManager.GetMouseCard()->IsActiveAndEnabled())
|
||||
{
|
||||
int iX, iMinX, iMaxX;
|
||||
int iY, iMinY, iMaxY;
|
||||
cardManager.GetMouseCard()->GetXY(iX, iMinX, iMaxX, iY, iMinY, iMaxY);
|
||||
|
||||
int width, height;
|
||||
SDL_GetWindowSize(myWindow.get(), &width, &height);
|
||||
|
||||
const int newX = int((double(motion.x) / double(width)) * (iMaxX - iMinX) + iMinX);
|
||||
const int newY = int((double(motion.y) / double(height)) * (iMaxY - iMinY) + iMinY);
|
||||
|
||||
const int dx = newX - iX;
|
||||
const int dy = newY - iY;
|
||||
|
||||
int outOfBoundsX;
|
||||
int outOfBoundsY;
|
||||
cardManager.GetMouseCard()->SetPositionRel(dx, dy, &outOfBoundsX, &outOfBoundsY);
|
||||
}
|
||||
}
|
||||
|
||||
void SDLFrame::ProcessDropEvent(const SDL_DropEvent & drop)
|
||||
{
|
||||
const char * filename = drop.file;
|
||||
|
|
|
@ -48,6 +48,8 @@ namespace sa2
|
|||
void ProcessKeyUp(const SDL_KeyboardEvent & key);
|
||||
void ProcessText(const SDL_TextInputEvent & text);
|
||||
void ProcessDropEvent(const SDL_DropEvent & drop);
|
||||
void ProcessMouseButton(const SDL_MouseButtonEvent & button);
|
||||
void ProcessMouseMotion(const SDL_MouseMotionEvent & motion);
|
||||
|
||||
std::shared_ptr<SDL_Window> myWindow;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue