Formspec: change the appeareance of the cursor on fields and co. (#8665)

master
DS 2020-01-11 20:17:11 +01:00 committed by SmallJoker
parent 3189e4466b
commit 4c8af5492b
2 changed files with 45 additions and 12 deletions

View File

@ -1304,7 +1304,9 @@ void GUIFormSpecMenu::parsePwdField(parserData* data, const std::string &element
name, name,
wlabel, wlabel,
L"", L"",
258 + m_fields.size() 258 + m_fields.size(),
0,
ECI_IBEAM
); );
spec.send = true; spec.send = true;
@ -1463,7 +1465,9 @@ void GUIFormSpecMenu::parseSimpleField(parserData *data,
name, name,
wlabel, wlabel,
utf8_to_wide(unescape_string(default_val)), utf8_to_wide(unescape_string(default_val)),
258 + m_fields.size() 258 + m_fields.size(),
0,
ECI_IBEAM
); );
createTextField(data, spec, rect, false); createTextField(data, spec, rect, false);
@ -1525,7 +1529,9 @@ void GUIFormSpecMenu::parseTextArea(parserData* data, std::vector<std::string>&
name, name,
wlabel, wlabel,
utf8_to_wide(unescape_string(default_val)), utf8_to_wide(unescape_string(default_val)),
258 + m_fields.size() 258 + m_fields.size(),
0,
ECI_IBEAM
); );
createTextField(data, spec, rect, type == "textarea"); createTextField(data, spec, rect, type == "textarea");
@ -3331,11 +3337,18 @@ void GUIFormSpecMenu::drawMenu()
#endif #endif
/* /*
Draw fields/buttons tooltips Draw fields/buttons tooltips and update the mouse cursor
*/ */
gui::IGUIElement *hovered = gui::IGUIElement *hovered =
Environment->getRootGUIElement()->getElementFromPoint(m_pointer); Environment->getRootGUIElement()->getElementFromPoint(m_pointer);
#ifndef HAVE_TOUCHSCREENGUI
gui::ICursorControl *cursor_control = RenderingEngine::get_raw_device()->
getCursorControl();
gui::ECURSOR_ICON current_cursor_icon = cursor_control->getActiveIcon();
#endif
bool hovered_element_found = false;
if (hovered != NULL) { if (hovered != NULL) {
s32 id = hovered->getID(); s32 id = hovered->getID();
@ -3351,23 +3364,40 @@ void GUIFormSpecMenu::drawMenu()
} }
} }
// Find and update the current tooltip // Find and update the current tooltip and cursor icon
if (id != -1 && delta >= m_tooltip_show_delay) { if (id != -1) {
for (const FieldSpec &field : m_fields) { for (const FieldSpec &field : m_fields) {
if (field.fid != id) if (field.fid != id)
continue; continue;
const std::wstring &text = m_tooltips[field.fname].tooltip; if (delta >= m_tooltip_show_delay) {
if (!text.empty()) const std::wstring &text = m_tooltips[field.fname].tooltip;
showTooltip(text, m_tooltips[field.fname].color, if (!text.empty())
m_tooltips[field.fname].bgcolor); showTooltip(text, m_tooltips[field.fname].color,
m_tooltips[field.fname].bgcolor);
}
#ifndef HAVE_TOUCHSCREENGUI
if (current_cursor_icon != field.fcursor_icon)
cursor_control->setActiveIcon(field.fcursor_icon);
#endif
hovered_element_found = true;
break; break;
} }
} }
} }
if (!hovered_element_found) {
// no element is hovered
#ifndef HAVE_TOUCHSCREENGUI
if (current_cursor_icon != ECI_NORMAL)
cursor_control->setActiveIcon(ECI_NORMAL);
#endif
}
m_tooltip_element->draw(); m_tooltip_element->draw();
/* /*

View File

@ -143,7 +143,8 @@ class GUIFormSpecMenu : public GUIModalMenu
FieldSpec() = default; FieldSpec() = default;
FieldSpec(const std::string &name, const std::wstring &label, FieldSpec(const std::string &name, const std::wstring &label,
const std::wstring &default_text, s32 id, int priority = 0) : const std::wstring &default_text, s32 id, int priority = 0,
gui::ECURSOR_ICON cursor_icon = ECI_NORMAL) :
fname(name), fname(name),
flabel(label), flabel(label),
fdefault(unescape_enriched(translate_string(default_text))), fdefault(unescape_enriched(translate_string(default_text))),
@ -151,7 +152,8 @@ class GUIFormSpecMenu : public GUIModalMenu
send(false), send(false),
ftype(f_Unknown), ftype(f_Unknown),
is_exit(false), is_exit(false),
priority(priority) priority(priority),
fcursor_icon(cursor_icon)
{ {
} }
@ -165,6 +167,7 @@ class GUIFormSpecMenu : public GUIModalMenu
// Draw priority for formspec version < 3 // Draw priority for formspec version < 3
int priority; int priority;
core::rect<s32> rect; core::rect<s32> rect;
gui::ECURSOR_ICON fcursor_icon;
}; };
struct TooltipSpec struct TooltipSpec