mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 22:29:39 -06:00
Merge pull request #7478 from stenzek/imgui
Replace raster font with dear imgui
This commit is contained in:
@ -143,6 +143,7 @@ PRIVATE
|
||||
core
|
||||
Qt5::Widgets
|
||||
uicommon
|
||||
imgui
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
|
@ -463,6 +463,9 @@
|
||||
<ProjectReference Include="$(CoreDir)VideoBackends\Vulkan\Vulkan.vcxproj">
|
||||
<Project>{29f29a19-f141-45ad-9679-5a2923b49da3}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\..\Externals\imgui\imgui.vcxproj">
|
||||
<Project>{4c3b2264-ea73-4a7b-9cfe-65b0fd635ebb}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "DolphinQt/HotkeyScheduler.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <thread>
|
||||
|
||||
#include <QCoreApplication>
|
||||
@ -26,6 +27,7 @@
|
||||
|
||||
#include "InputCommon/ControllerInterface/ControllerInterface.h"
|
||||
|
||||
#include "VideoCommon/OnScreenDisplay.h"
|
||||
#include "VideoCommon/RenderBase.h"
|
||||
#include "VideoCommon/VertexShaderManager.h"
|
||||
#include "VideoCommon/VideoConfig.h"
|
||||
@ -286,43 +288,62 @@ void HotkeyScheduler::Run()
|
||||
else if (IsHotkey(HK_NEXT_GAME_WIIMOTE_PROFILE_4))
|
||||
m_profile_cycler.NextWiimoteProfileForGame(3);
|
||||
|
||||
const auto show_msg = [](OSDMessage message) {
|
||||
if (g_renderer)
|
||||
g_renderer->ShowOSDMessage(message);
|
||||
auto ShowVolume = []() {
|
||||
OSD::AddMessage(std::string("Volume: ") +
|
||||
(SConfig::GetInstance().m_IsMuted ?
|
||||
"Muted" :
|
||||
std::to_string(SConfig::GetInstance().m_Volume)) +
|
||||
"%");
|
||||
};
|
||||
|
||||
// Volume
|
||||
if (IsHotkey(HK_VOLUME_DOWN))
|
||||
{
|
||||
show_msg(OSDMessage::VolumeChanged);
|
||||
settings.DecreaseVolume(3);
|
||||
ShowVolume();
|
||||
}
|
||||
|
||||
if (IsHotkey(HK_VOLUME_UP))
|
||||
{
|
||||
show_msg(OSDMessage::VolumeChanged);
|
||||
settings.IncreaseVolume(3);
|
||||
ShowVolume();
|
||||
}
|
||||
|
||||
if (IsHotkey(HK_VOLUME_TOGGLE_MUTE))
|
||||
{
|
||||
show_msg(OSDMessage::VolumeChanged);
|
||||
AudioCommon::ToggleMuteVolume();
|
||||
ShowVolume();
|
||||
}
|
||||
|
||||
// Graphics
|
||||
const auto efb_scale = Config::Get(Config::GFX_EFB_SCALE);
|
||||
auto ShowEFBScale = []() {
|
||||
switch (Config::Get(Config::GFX_EFB_SCALE))
|
||||
{
|
||||
case EFB_SCALE_AUTO_INTEGRAL:
|
||||
OSD::AddMessage("Internal Resolution: Auto (integral)");
|
||||
break;
|
||||
case 1:
|
||||
OSD::AddMessage("Internal Resolution: Native");
|
||||
break;
|
||||
default:
|
||||
OSD::AddMessage("Internal Resolution: %dx", g_Config.iEFBScale);
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
if (IsHotkey(HK_INCREASE_IR))
|
||||
{
|
||||
show_msg(OSDMessage::IRChanged);
|
||||
Config::SetCurrent(Config::GFX_EFB_SCALE, efb_scale + 1);
|
||||
ShowEFBScale();
|
||||
}
|
||||
if (IsHotkey(HK_DECREASE_IR))
|
||||
{
|
||||
show_msg(OSDMessage::IRChanged);
|
||||
if (efb_scale > EFB_SCALE_AUTO_INTEGRAL)
|
||||
{
|
||||
Config::SetCurrent(Config::GFX_EFB_SCALE, efb_scale - 1);
|
||||
ShowEFBScale();
|
||||
}
|
||||
}
|
||||
|
||||
if (IsHotkey(HK_TOGGLE_CROP))
|
||||
@ -330,34 +351,55 @@ void HotkeyScheduler::Run()
|
||||
|
||||
if (IsHotkey(HK_TOGGLE_AR))
|
||||
{
|
||||
show_msg(OSDMessage::ARToggled);
|
||||
const int aspect_ratio = (static_cast<int>(Config::Get(Config::GFX_ASPECT_RATIO)) + 1) & 3;
|
||||
Config::SetCurrent(Config::GFX_ASPECT_RATIO, static_cast<AspectMode>(aspect_ratio));
|
||||
switch (static_cast<AspectMode>(aspect_ratio))
|
||||
{
|
||||
case AspectMode::Stretch:
|
||||
OSD::AddMessage("Stretch");
|
||||
break;
|
||||
case AspectMode::Analog:
|
||||
OSD::AddMessage("Force 4:3");
|
||||
break;
|
||||
case AspectMode::AnalogWide:
|
||||
OSD::AddMessage("Force 16:9");
|
||||
break;
|
||||
case AspectMode::Auto:
|
||||
default:
|
||||
OSD::AddMessage("Auto");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (IsHotkey(HK_TOGGLE_EFBCOPIES))
|
||||
{
|
||||
show_msg(OSDMessage::EFBCopyToggled);
|
||||
Config::SetCurrent(Config::GFX_HACK_SKIP_EFB_COPY_TO_RAM,
|
||||
!Config::Get(Config::GFX_HACK_SKIP_EFB_COPY_TO_RAM));
|
||||
const bool new_value = !Config::Get(Config::GFX_HACK_SKIP_EFB_COPY_TO_RAM);
|
||||
Config::SetCurrent(Config::GFX_HACK_SKIP_EFB_COPY_TO_RAM, new_value);
|
||||
OSD::AddMessage(StringFromFormat("Copy EFB: %s", new_value ? "to Texture" : "to RAM"));
|
||||
}
|
||||
|
||||
auto ShowXFBCopies = []() {
|
||||
OSD::AddMessage(StringFromFormat(
|
||||
"Copy XFB: %s%s", Config::Get(Config::GFX_HACK_IMMEDIATE_XFB) ? " (Immediate)" : "",
|
||||
Config::Get(Config::GFX_HACK_SKIP_XFB_COPY_TO_RAM) ? "to Texture" : "to RAM"));
|
||||
};
|
||||
|
||||
if (IsHotkey(HK_TOGGLE_XFBCOPIES))
|
||||
{
|
||||
show_msg(OSDMessage::XFBChanged);
|
||||
Config::SetCurrent(Config::GFX_HACK_SKIP_XFB_COPY_TO_RAM,
|
||||
!Config::Get(Config::GFX_HACK_SKIP_XFB_COPY_TO_RAM));
|
||||
ShowXFBCopies();
|
||||
}
|
||||
if (IsHotkey(HK_TOGGLE_IMMEDIATE_XFB))
|
||||
{
|
||||
show_msg(OSDMessage::XFBChanged);
|
||||
|
||||
Config::SetCurrent(Config::GFX_HACK_IMMEDIATE_XFB,
|
||||
!Config::Get(Config::GFX_HACK_IMMEDIATE_XFB));
|
||||
ShowXFBCopies();
|
||||
}
|
||||
if (IsHotkey(HK_TOGGLE_FOG))
|
||||
{
|
||||
show_msg(OSDMessage::FogToggled);
|
||||
Config::SetCurrent(Config::GFX_DISABLE_FOG, !Config::Get(Config::GFX_DISABLE_FOG));
|
||||
const bool new_value = !Config::Get(Config::GFX_DISABLE_FOG);
|
||||
Config::SetCurrent(Config::GFX_DISABLE_FOG, new_value);
|
||||
OSD::AddMessage(StringFromFormat("Fog: %s", new_value ? "Enabled" : "Disabled"));
|
||||
}
|
||||
|
||||
if (IsHotkey(HK_TOGGLE_DUMPTEXTURES))
|
||||
@ -368,22 +410,28 @@ void HotkeyScheduler::Run()
|
||||
|
||||
Core::SetIsThrottlerTempDisabled(IsHotkey(HK_TOGGLE_THROTTLE, true));
|
||||
|
||||
auto ShowEmulationSpeed = []() {
|
||||
OSD::AddMessage(
|
||||
SConfig::GetInstance().m_EmulationSpeed <= 0 ?
|
||||
"Speed Limit: Unlimited" :
|
||||
StringFromFormat("Speed Limit: %li%%",
|
||||
std::lround(SConfig::GetInstance().m_EmulationSpeed * 100.f)));
|
||||
};
|
||||
|
||||
if (IsHotkey(HK_DECREASE_EMULATION_SPEED))
|
||||
{
|
||||
show_msg(OSDMessage::SpeedChanged);
|
||||
|
||||
auto speed = SConfig::GetInstance().m_EmulationSpeed - 0.1;
|
||||
speed = (speed <= 0 || (speed >= 0.95 && speed <= 1.05)) ? 1.0 : speed;
|
||||
SConfig::GetInstance().m_EmulationSpeed = speed;
|
||||
ShowEmulationSpeed();
|
||||
}
|
||||
|
||||
if (IsHotkey(HK_INCREASE_EMULATION_SPEED))
|
||||
{
|
||||
show_msg(OSDMessage::SpeedChanged);
|
||||
|
||||
auto speed = SConfig::GetInstance().m_EmulationSpeed + 0.1;
|
||||
speed = (speed >= 0.95 && speed <= 1.05) ? 1.0 : speed;
|
||||
SConfig::GetInstance().m_EmulationSpeed = speed;
|
||||
ShowEmulationSpeed();
|
||||
}
|
||||
|
||||
// Slot Saving / Loading
|
||||
|
@ -164,6 +164,7 @@ static WindowSystemInfo GetWindowSystemInfo(QWindow* window)
|
||||
else
|
||||
wsi.render_surface = window ? reinterpret_cast<void*>(window->winId()) : nullptr;
|
||||
#endif
|
||||
wsi.render_surface_scale = window ? static_cast<float>(window->devicePixelRatio()) : 1.0f;
|
||||
|
||||
return wsi;
|
||||
}
|
||||
|
@ -17,6 +17,8 @@
|
||||
#include <QScreen>
|
||||
#include <QTimer>
|
||||
|
||||
#include "imgui.h"
|
||||
|
||||
#include "Core/ConfigManager.h"
|
||||
#include "Core/Core.h"
|
||||
#include "Core/State.h"
|
||||
@ -26,6 +28,7 @@
|
||||
#include "DolphinQt/Resources.h"
|
||||
#include "DolphinQt/Settings.h"
|
||||
|
||||
#include "VideoCommon/RenderBase.h"
|
||||
#include "VideoCommon/VertexShaderManager.h"
|
||||
#include "VideoCommon/VideoConfig.h"
|
||||
|
||||
@ -49,6 +52,8 @@ RenderWidget::RenderWidget(QWidget* parent) : QWidget(parent)
|
||||
|
||||
connect(&Settings::Instance(), &Settings::EmulationStateChanged, this, [this](Core::State state) {
|
||||
SetFillBackground(SConfig::GetInstance().bRenderToMain && state == Core::State::Uninitialized);
|
||||
if (state == Core::State::Running)
|
||||
SetImGuiKeyMap();
|
||||
});
|
||||
|
||||
// We have to use Qt::DirectConnection here because we don't want those signals to get queued
|
||||
@ -153,6 +158,8 @@ void RenderWidget::showFullScreen()
|
||||
|
||||
bool RenderWidget::event(QEvent* event)
|
||||
{
|
||||
PassEventToImGui(event);
|
||||
|
||||
switch (event->type())
|
||||
{
|
||||
case QEvent::Paint:
|
||||
@ -244,3 +251,83 @@ void RenderWidget::OnFreeLookMouseMove(QMouseEvent* event)
|
||||
m_last_mouse[0] = event->x();
|
||||
m_last_mouse[1] = event->y();
|
||||
}
|
||||
|
||||
void RenderWidget::PassEventToImGui(const QEvent* event)
|
||||
{
|
||||
if (!Core::IsRunningAndStarted())
|
||||
return;
|
||||
|
||||
switch (event->type())
|
||||
{
|
||||
case QEvent::KeyPress:
|
||||
case QEvent::KeyRelease:
|
||||
{
|
||||
// As the imgui KeysDown array is only 512 elements wide, and some Qt keys which
|
||||
// we need to track (e.g. alt) are above this value, we mask the lower 9 bits.
|
||||
// Even masked, the key codes are still unique, so conflicts aren't an issue.
|
||||
// The actual text input goes through AddInputCharactersUTF8().
|
||||
const QKeyEvent* key_event = static_cast<const QKeyEvent*>(event);
|
||||
const bool is_down = event->type() == QEvent::KeyPress;
|
||||
const int key = (key_event->key() & 0x1FF);
|
||||
auto lock = g_renderer->GetImGuiLock();
|
||||
if (key < ArraySize(ImGui::GetIO().KeysDown))
|
||||
ImGui::GetIO().KeysDown[key] = is_down;
|
||||
|
||||
if (is_down)
|
||||
{
|
||||
auto utf8 = key_event->text().toUtf8();
|
||||
ImGui::GetIO().AddInputCharactersUTF8(utf8.constData());
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case QEvent::MouseMove:
|
||||
{
|
||||
auto lock = g_renderer->GetImGuiLock();
|
||||
ImGui::GetIO().MousePos.x = static_cast<const QMouseEvent*>(event)->x();
|
||||
ImGui::GetIO().MousePos.y = static_cast<const QMouseEvent*>(event)->y();
|
||||
}
|
||||
break;
|
||||
|
||||
case QEvent::MouseButtonPress:
|
||||
case QEvent::MouseButtonRelease:
|
||||
{
|
||||
auto lock = g_renderer->GetImGuiLock();
|
||||
const u32 button_mask = static_cast<u32>(static_cast<const QMouseEvent*>(event)->buttons());
|
||||
for (size_t i = 0; i < ArraySize(ImGui::GetIO().MouseDown); i++)
|
||||
ImGui::GetIO().MouseDown[i] = (button_mask & (1u << i)) != 0;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void RenderWidget::SetImGuiKeyMap()
|
||||
{
|
||||
static const int key_map[][2] = {{ImGuiKey_Tab, Qt::Key_Tab},
|
||||
{ImGuiKey_LeftArrow, Qt::Key_Left},
|
||||
{ImGuiKey_RightArrow, Qt::Key_Right},
|
||||
{ImGuiKey_UpArrow, Qt::Key_Up},
|
||||
{ImGuiKey_DownArrow, Qt::Key_Down},
|
||||
{ImGuiKey_PageUp, Qt::Key_PageUp},
|
||||
{ImGuiKey_PageDown, Qt::Key_PageDown},
|
||||
{ImGuiKey_Home, Qt::Key_Home},
|
||||
{ImGuiKey_End, Qt::Key_End},
|
||||
{ImGuiKey_Insert, Qt::Key_Insert},
|
||||
{ImGuiKey_Delete, Qt::Key_Delete},
|
||||
{ImGuiKey_Backspace, Qt::Key_Backspace},
|
||||
{ImGuiKey_Space, Qt::Key_Space},
|
||||
{ImGuiKey_Enter, Qt::Key_Enter},
|
||||
{ImGuiKey_Escape, Qt::Key_Escape},
|
||||
{ImGuiKey_A, Qt::Key_A},
|
||||
{ImGuiKey_C, Qt::Key_C},
|
||||
{ImGuiKey_V, Qt::Key_V},
|
||||
{ImGuiKey_X, Qt::Key_X},
|
||||
{ImGuiKey_Y, Qt::Key_Y},
|
||||
{ImGuiKey_Z, Qt::Key_Z}};
|
||||
auto lock = g_renderer->GetImGuiLock();
|
||||
for (size_t i = 0; i < ArraySize(key_map); i++)
|
||||
ImGui::GetIO().KeyMap[key_map[i][0]] = (key_map[i][1] & 0x1FF);
|
||||
}
|
||||
|
@ -36,6 +36,8 @@ private:
|
||||
void OnKeepOnTopChanged(bool top);
|
||||
void SetFillBackground(bool fill);
|
||||
void OnFreeLookMouseMove(QMouseEvent* event);
|
||||
void PassEventToImGui(const QEvent* event);
|
||||
void SetImGuiKeyMap();
|
||||
void dragEnterEvent(QDragEnterEvent* event) override;
|
||||
void dropEvent(QDropEvent* event) override;
|
||||
|
||||
|
Reference in New Issue
Block a user