Add tooltip to buttons in input gui

This commit is contained in:
ergo720 2021-02-18 20:19:07 +01:00
parent 240dc03dd5
commit 559230a02a
4 changed files with 37 additions and 0 deletions

View File

@ -51,6 +51,19 @@ void Button::GetText(char* const text, size_t size) const
SendMessage(m_button_hwnd, WM_GETTEXT, size, reinterpret_cast<LPARAM>(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<UINT_PTR>(m_button_hwnd);
tool.lpszText = text;
SendMessage(tooltip_hwnd, TTM_ADDTOOL, 0, reinterpret_cast<LPARAM>(&tool));
}
LRESULT CALLBACK ButtonDukeSubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
{
switch (uMsg)

View File

@ -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:

View File

@ -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<DWORD_PTR>(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<DWORD_PTR>(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);
}

View File

@ -46,8 +46,11 @@ public:
private:
void CreateTooltipWindow();
std::vector<Button*> m_buttons;
HWND m_hwnd;
HWND m_tooltip_hwnd;
};
template void EmuDevice::BindDefault(const std::array<const char *, XBOX_CTRL_NUM_BUTTONS> &arr);