mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2025-01-17 22:25:37 +00:00
Frontend: Use imgui functions for handling SDL events
This commit is contained in:
parent
0d71ebccc8
commit
f538123210
|
@ -468,8 +468,7 @@ static void HandleSDLControllerButtonEventForController(const SDL_Event* ev, Dig
|
||||||
|
|
||||||
void SDLInterface::HandleSDLEvent(const SDL_Event* event)
|
void SDLInterface::HandleSDLEvent(const SDL_Event* event)
|
||||||
{
|
{
|
||||||
if (PassEventToImGui(event))
|
ImGui_ImplSDL2_ProcessEvent(event);
|
||||||
return;
|
|
||||||
|
|
||||||
switch (event->type)
|
switch (event->type)
|
||||||
{
|
{
|
||||||
|
@ -489,8 +488,11 @@ void SDLInterface::HandleSDLEvent(const SDL_Event* event)
|
||||||
|
|
||||||
case SDL_KEYDOWN:
|
case SDL_KEYDOWN:
|
||||||
case SDL_KEYUP:
|
case SDL_KEYUP:
|
||||||
HandleSDLKeyEvent(event);
|
{
|
||||||
break;
|
if (!ImGui::GetIO().WantCaptureKeyboard)
|
||||||
|
HandleSDLKeyEvent(event);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case SDL_CONTROLLERDEVICEADDED:
|
case SDL_CONTROLLERDEVICEADDED:
|
||||||
{
|
{
|
||||||
|
@ -573,66 +575,6 @@ void SDLInterface::HandleSDLKeyEvent(const SDL_Event* event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SDLInterface::PassEventToImGui(const SDL_Event* event)
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
switch (event->type)
|
|
||||||
{
|
|
||||||
case SDL_MOUSEWHEEL:
|
|
||||||
{
|
|
||||||
if (event->wheel.x > 0)
|
|
||||||
io.MouseWheelH += 1;
|
|
||||||
if (event->wheel.x < 0)
|
|
||||||
io.MouseWheelH -= 1;
|
|
||||||
if (event->wheel.y > 0)
|
|
||||||
io.MouseWheel += 1;
|
|
||||||
if (event->wheel.y < 0)
|
|
||||||
io.MouseWheel -= 1;
|
|
||||||
return io.WantCaptureMouse;
|
|
||||||
}
|
|
||||||
|
|
||||||
case SDL_MOUSEBUTTONDOWN:
|
|
||||||
case SDL_MOUSEBUTTONUP:
|
|
||||||
{
|
|
||||||
bool down = event->type == SDL_MOUSEBUTTONDOWN;
|
|
||||||
if (event->button.button == SDL_BUTTON_LEFT)
|
|
||||||
io.MouseDown[0] = down;
|
|
||||||
if (event->button.button == SDL_BUTTON_RIGHT)
|
|
||||||
io.MouseDown[1] = down;
|
|
||||||
if (event->button.button == SDL_BUTTON_MIDDLE)
|
|
||||||
io.MouseDown[2] = down;
|
|
||||||
return io.WantCaptureMouse;
|
|
||||||
}
|
|
||||||
|
|
||||||
case SDL_MOUSEMOTION:
|
|
||||||
{
|
|
||||||
io.MousePos.x = float(event->motion.x);
|
|
||||||
io.MousePos.y = float(event->motion.y);
|
|
||||||
return io.WantCaptureMouse;
|
|
||||||
}
|
|
||||||
|
|
||||||
case SDL_TEXTINPUT:
|
|
||||||
{
|
|
||||||
io.AddInputCharactersUTF8(event->text.text);
|
|
||||||
return io.WantCaptureKeyboard;
|
|
||||||
}
|
|
||||||
|
|
||||||
case SDL_KEYDOWN:
|
|
||||||
case SDL_KEYUP:
|
|
||||||
{
|
|
||||||
int key = event->key.keysym.scancode;
|
|
||||||
IM_ASSERT(key >= 0 && key < IM_ARRAYSIZE(io.KeysDown));
|
|
||||||
io.KeysDown[key] = (event->type == SDL_KEYDOWN);
|
|
||||||
io.KeyShift = ((SDL_GetModState() & KMOD_SHIFT) != 0);
|
|
||||||
io.KeyCtrl = ((SDL_GetModState() & KMOD_CTRL) != 0);
|
|
||||||
io.KeyAlt = ((SDL_GetModState() & KMOD_ALT) != 0);
|
|
||||||
io.KeySuper = ((SDL_GetModState() & KMOD_GUI) != 0);
|
|
||||||
return io.WantCaptureKeyboard;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SDLInterface::Render()
|
void SDLInterface::Render()
|
||||||
{
|
{
|
||||||
DrawImGui();
|
DrawImGui();
|
||||||
|
|
|
@ -75,7 +75,6 @@ private:
|
||||||
|
|
||||||
void HandleSDLEvent(const SDL_Event* event);
|
void HandleSDLEvent(const SDL_Event* event);
|
||||||
void HandleSDLKeyEvent(const SDL_Event* event);
|
void HandleSDLKeyEvent(const SDL_Event* event);
|
||||||
bool PassEventToImGui(const SDL_Event* event);
|
|
||||||
void Render();
|
void Render();
|
||||||
void RenderDisplay();
|
void RenderDisplay();
|
||||||
void DrawMainMenuBar();
|
void DrawMainMenuBar();
|
||||||
|
|
Loading…
Reference in a new issue