GUI: Implemented link tooltips for RichTextWidget

This commit is contained in:
Eugene Sandulenko 2023-08-31 16:48:56 +02:00
parent 125d3dfa69
commit 2b35c7997f
5 changed files with 23 additions and 8 deletions

View File

@ -546,13 +546,15 @@ void GuiManager::runLoop() {
&& systemMillisNowForTooltipCheck - _lastMousePosition.time > (uint32)kTooltipDelay
&& !activeDialog->isDragging()) {
Widget *wdg = activeDialog->findWidget(_lastMousePosition.x, _lastMousePosition.y);
if (wdg && wdg->hasTooltip() && !(wdg->getFlags() & WIDGET_PRESSED)
if (wdg && (wdg->hasTooltip() || (wdg->getFlags() & WIDGET_DYN_TOOLTIP)) && !(wdg->getFlags() & WIDGET_PRESSED)
&& (_lastTooltipShown.wdg != wdg || systemMillisNowForTooltipCheck - _lastTooltipShown.time > (uint32)kTooltipSameWidgetDelay)) {
_lastTooltipShown.time = systemMillisNowForTooltipCheck;
_lastTooltipShown.wdg = wdg;
_lastTooltipShown.x = _lastMousePosition.x;
_lastTooltipShown.y = _lastMousePosition.y;
if (wdg->getType() != kEditTextWidget || activeDialog->getFocusWidget() != wdg) {
if (wdg->getFlags() & WIDGET_DYN_TOOLTIP)
wdg->handleTooltipUpdate(_lastMousePosition.x- activeDialog->_x - wdg->getRelX(), _lastMousePosition.y - activeDialog->_y - wdg->getRelY());
Tooltip *tooltip = new Tooltip();
tooltip->setup(activeDialog, wdg, _lastMousePosition.x, _lastMousePosition.y);
tooltip->runModal();

View File

@ -104,6 +104,7 @@ public:
virtual Common::Rect getClipRect() const;
virtual void handleMouseWheel(int x, int y, int direction) {};
virtual void handleTooltipUpdate(int x, int y) {};
protected:
virtual void releaseFocus() = 0;
};

View File

@ -57,7 +57,8 @@ enum {
// The PopUpWidget for example does not want this behavior, since the
// mouse down will open up a new dialog which silently eats the mouse
// up event for its own purposes.
WIDGET_IGNORE_DRAG = 1 << 10
WIDGET_IGNORE_DRAG = 1 << 10,
WIDGET_DYN_TOOLTIP = 1 << 11, // Widgets updates tooltip by coordinates
};
enum {
@ -203,7 +204,7 @@ protected:
Common::U32String _label;
Graphics::TextAlign _align;
ThemeEngine::FontStyle _font;
ThemeEngine::FontColor _fontColor;
ThemeEngine::FontColor _fontColor;
bool _useEllipsis;
public:
@ -217,7 +218,7 @@ public:
void setAlign(Graphics::TextAlign align);
Graphics::TextAlign getAlign() const { return _align; }
void readLabel() { read(_label); }
void setFontColor(ThemeEngine::FontColor color);
void setFontColor(ThemeEngine::FontColor color);
protected:
void drawWidget() override;
@ -323,7 +324,7 @@ protected:
class CheckboxWidget : public ButtonWidget {
protected:
bool _state;
bool _overrideText;
bool _overrideText;
int _spacing;
public:
CheckboxWidget(GuiObject *boss, int x, int y, int w, int h, bool scale, const Common::U32String &label, const Common::U32String &tooltip = Common::U32String(), uint32 cmd = 0, uint8 hotkey = 0);
@ -338,8 +339,8 @@ public:
void toggleState() { setState(!_state); }
bool getState() const { return _state; }
void setOverride(bool enable);
void setOverride(bool enable);
protected:
void drawWidget() override;
};

View File

@ -71,7 +71,7 @@ RichTextWidget::RichTextWidget(GuiObject *boss, const Common::String &name, cons
}
void RichTextWidget::init() {
setFlags(WIDGET_ENABLED | WIDGET_CLEARBG);
setFlags(WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_TRACK_MOUSE | WIDGET_DYN_TOOLTIP);
_type = kRichTextWidget;
@ -93,6 +93,15 @@ void RichTextWidget::handleMouseWheel(int x, int y, int direction) {
_verticalScroll->handleMouseWheel(x, y, direction);
}
void RichTextWidget::handleMouseDown(int x, int y, int button, int clickCount) {
warning("M: %s", _txtWnd->getMouseLink(x + _x + _scrolledX, y + _y + _scrolledY).encode().c_str());
}
void RichTextWidget::handleTooltipUpdate(int x, int y) {
_tooltip = _txtWnd->getMouseLink(x + _x + _scrolledX, y + _y + _scrolledY);
//warning("t: %s", _tooltip.encode().c_str());
}
void RichTextWidget::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
Widget::handleCommand(sender, cmd, data);
switch (cmd) {

View File

@ -58,6 +58,8 @@ public:
void handleCommand(CommandSender *sender, uint32 cmd, uint32 data) override;
void handleMouseWheel(int x, int y, int direction) override;
void handleMouseDown(int x, int y, int button, int clickCount) override;
void handleTooltipUpdate(int x, int y) override;
void markAsDirty() override;