diff --git a/src/common/input/Button.cpp b/src/common/input/Button.cpp index d793b0e31..af40291a7 100644 --- a/src/common/input/Button.cpp +++ b/src/common/input/Button.cpp @@ -51,6 +51,19 @@ void Button::GetText(char* const text, size_t size) const SendMessage(m_button_hwnd, WM_GETTEXT, size, reinterpret_cast(text)); } +void Button::AddTooltip(HWND hwnd, HWND tooltip_hwnd, char *text) const +{ + assert((hwnd != NULL) && (tooltip_hwnd != NULL)); + + TOOLINFO tool = { 0 }; + tool.cbSize = sizeof(tool); + tool.hwnd = hwnd; + tool.uFlags = TTF_IDISHWND | TTF_SUBCLASS; + tool.uId = reinterpret_cast(m_button_hwnd); + tool.lpszText = text; + SendMessage(tooltip_hwnd, TTM_ADDTOOL, 0, reinterpret_cast(&tool)); +} + LRESULT CALLBACK ButtonDukeSubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData) { switch (uMsg) diff --git a/src/common/input/Button.h b/src/common/input/Button.h index 7ed520884..a74afded5 100644 --- a/src/common/input/Button.h +++ b/src/common/input/Button.h @@ -50,6 +50,7 @@ public: int GetId() const { return m_id; } int GetIndex() const { return m_index; } void *GetWnd() const { return m_wnd; } + void AddTooltip(HWND hwnd, HWND tooltip_hwnd, char *text) const; private: diff --git a/src/common/input/EmuDevice.cpp b/src/common/input/EmuDevice.cpp index 8fd311d1e..b92411d91 100644 --- a/src/common/input/EmuDevice.cpp +++ b/src/common/input/EmuDevice.cpp @@ -31,9 +31,12 @@ #include "gui/resource/ResCxbx.h" +static char *tooltip_text = "Left-click: start input detection\nRight-click: clear binding\nShift + right-click: toggle mouse input mode"; + EmuDevice::EmuDevice(int type, HWND hwnd, void *wnd) { m_hwnd = hwnd; + CreateTooltipWindow(); switch (type) { @@ -41,6 +44,7 @@ EmuDevice::EmuDevice(int type, HWND hwnd, void *wnd) case to_underlying(XBOX_INPUT_DEVICE::MS_CONTROLLER_S): { for (size_t i = 0; i < ARRAY_SIZE(button_xbox_ctrl_id); i++) { m_buttons.push_back(new Button(button_xbox_ctrl_id[i], i, hwnd, wnd)); + m_buttons.back()->AddTooltip(m_hwnd, m_tooltip_hwnd, tooltip_text); // Install the subclass for the button control SetWindowSubclass(GetDlgItem(hwnd, button_xbox_ctrl_id[i]), ButtonDukeSubclassProc, 0, reinterpret_cast(m_buttons[i])); @@ -51,6 +55,7 @@ EmuDevice::EmuDevice(int type, HWND hwnd, void *wnd) case to_underlying(XBOX_INPUT_DEVICE::STEEL_BATTALION_CONTROLLER): { for (size_t i = 0; i < ARRAY_SIZE(button_sbc_id); i++) { m_buttons.push_back(new Button(button_sbc_id[i], i, hwnd, wnd)); + m_buttons.back()->AddTooltip(m_hwnd, m_tooltip_hwnd, tooltip_text); // Install the subclass for the button control SetWindowSubclass(GetDlgItem(hwnd, button_sbc_id[i]), ButtonSbcSubclassProc, 0, reinterpret_cast(m_buttons[i])); @@ -63,6 +68,7 @@ EmuDevice::EmuDevice(int type, HWND hwnd, void *wnd) EmuDevice::~EmuDevice() { + DestroyWindow(m_tooltip_hwnd); for (auto button : m_buttons) { delete button; } @@ -99,3 +105,17 @@ void EmuDevice::ClearButtons() button->ClearText(); }); } + +void EmuDevice::CreateTooltipWindow() +{ + m_tooltip_hwnd = CreateWindow(TOOLTIPS_CLASS, NULL, + WS_POPUP | TTS_ALWAYSTIP, + CW_USEDEFAULT, CW_USEDEFAULT, + CW_USEDEFAULT, CW_USEDEFAULT, + m_hwnd, NULL, + GetModuleHandle(NULL), NULL); + + SendMessage(m_tooltip_hwnd, TTM_ACTIVATE, TRUE, 0); + SendMessage(m_tooltip_hwnd, TTM_SETMAXTIPWIDTH, 0, 500); + SendMessage(m_tooltip_hwnd, TTM_SETDELAYTIME, TTDT_AUTOPOP, 15000); +} diff --git a/src/common/input/EmuDevice.h b/src/common/input/EmuDevice.h index 8a8735f63..e9a914467 100644 --- a/src/common/input/EmuDevice.h +++ b/src/common/input/EmuDevice.h @@ -46,8 +46,11 @@ public: private: + void CreateTooltipWindow(); + std::vector m_buttons; HWND m_hwnd; + HWND m_tooltip_hwnd; }; template void EmuDevice::BindDefault(const std::array &arr);