From 99c0cd66bc94648b1a2ee741739a29cd127d3081 Mon Sep 17 00:00:00 2001 From: thrust26 Date: Mon, 16 Nov 2020 23:50:10 +0100 Subject: [PATCH] added value tool tips to debugger (DataGridWiget, ToogleWidget) --- src/debugger/gui/CpuWidget.cxx | 4 ++-- src/debugger/gui/DataGridWidget.cxx | 17 +++++++++++++++++ src/debugger/gui/DataGridWidget.hxx | 3 +++ src/debugger/gui/ToggleWidget.cxx | 26 ++++++++++++++++++++++++++ src/debugger/gui/ToggleWidget.hxx | 3 +++ src/gui/Dialog.cxx | 2 +- src/gui/Dialog.hxx | 3 --- src/gui/ToolTip.cxx | 29 +++++++++++++++++++---------- src/gui/ToolTip.hxx | 11 ++++++----- src/gui/Widget.hxx | 8 ++++++-- 10 files changed, 83 insertions(+), 23 deletions(-) diff --git a/src/debugger/gui/CpuWidget.cxx b/src/debugger/gui/CpuWidget.cxx index 31f939f01..ea6fbb96f 100644 --- a/src/debugger/gui/CpuWidget.cxx +++ b/src/debugger/gui/CpuWidget.cxx @@ -109,10 +109,10 @@ CpuWidget::CpuWidget(GuiObject* boss, const GUI::Font& lfont, const GUI::Font& n { new StaticTextWidget(boss, lfont, myCpuGridDecValue->getLeft() - fontWidth, ypos + row * lineHeight + 2, - lwidth - 2, fontHeight, "#"); + fontWidth, fontHeight, "#"); new StaticTextWidget(boss, lfont, myCpuGridBinValue->getLeft() - fontWidth, ypos + row * lineHeight + 2, - lwidth - 2, fontHeight, "%"); + fontWidth, fontHeight, "%"); } // Create a bitfield widget for changing the processor status diff --git a/src/debugger/gui/DataGridWidget.cxx b/src/debugger/gui/DataGridWidget.cxx index 63c637ecd..f6898b6c8 100644 --- a/src/debugger/gui/DataGridWidget.cxx +++ b/src/debugger/gui/DataGridWidget.cxx @@ -570,6 +570,23 @@ void DataGridWidget::handleCommand(CommandSender* sender, int cmd, } } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +string DataGridWidget::getToolTip(int x, int y) const +{ + const int col = (x - getAbsX()) / _colWidth; + const int row = (y - getAbsY()) / _rowHeight; + const int pos = row * _cols + col; + const Int32 val = _valueList[pos]; + const string hex = Common::Base::toString(val, Common::Base::Fmt::_16); + const string dec = Common::Base::toString(val, Common::Base::Fmt::_10); + const string bin = Common::Base::toString(val, Common::Base::Fmt::_2); + ostringstream buf; + + // TODO: time leading spaces and zeroes + buf << "$" << hex << " = #" << dec << " = %" << bin; + return buf.str(); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void DataGridWidget::drawWidget(bool hilite) { diff --git a/src/debugger/gui/DataGridWidget.hxx b/src/debugger/gui/DataGridWidget.hxx index 9096879f3..f50270f4f 100644 --- a/src/debugger/gui/DataGridWidget.hxx +++ b/src/debugger/gui/DataGridWidget.hxx @@ -84,6 +84,9 @@ class DataGridWidget : public EditableWidget void setCrossed(bool enable) { _crossGrid = enable; } + string getToolTip(int x = 0, int y = 0) const override; + bool hasToolTip() const override { return true; } + protected: void drawWidget(bool hilite) override; diff --git a/src/debugger/gui/ToggleWidget.cxx b/src/debugger/gui/ToggleWidget.cxx index 4f9ddccfa..346c51121 100644 --- a/src/debugger/gui/ToggleWidget.cxx +++ b/src/debugger/gui/ToggleWidget.cxx @@ -16,6 +16,7 @@ //============================================================================ #include "OSystem.hxx" +#include "Base.hxx" #include "StellaKeys.hxx" #include "Widget.hxx" #include "ToggleWidget.hxx" @@ -209,3 +210,28 @@ void ToggleWidget::handleCommand(CommandSender* sender, int cmd, } } } + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +string ToggleWidget::getToolTip(int x, int y) const +{ + const int row = (y - getAbsY()) / _rowHeight; + const int pos = row * _cols;// +col; + Int32 val = 0; + + for(int col = 0; col < _cols; ++col) + { + val <<= 1; + val += _stateList[pos + col]; + } + + const string hex = Common::Base::toString(val, Common::Base::Fmt::_16); + const string dec = Common::Base::toString(val, Common::Base::Fmt::_10); + const string bin = Common::Base::toString(val, Common::Base::Fmt::_2); + ostringstream buf; + + // TODO: time leading spaces and zeroes + buf << "$" << hex << " = #" << dec << " = %" << bin; + return buf.str(); +} + + diff --git a/src/debugger/gui/ToggleWidget.hxx b/src/debugger/gui/ToggleWidget.hxx index 0d6759467..a671f53e9 100644 --- a/src/debugger/gui/ToggleWidget.hxx +++ b/src/debugger/gui/ToggleWidget.hxx @@ -46,6 +46,9 @@ class ToggleWidget : public Widget, public CommandSender void setEditable(bool editable) { _editable = editable; } bool isEditable() const { return _editable; } + string getToolTip(int x = 0, int y = 0) const override; + bool hasToolTip() const override { return true; } + protected: protected: diff --git a/src/gui/Dialog.cxx b/src/gui/Dialog.cxx index f58d98536..b9678182e 100644 --- a/src/gui/Dialog.cxx +++ b/src/gui/Dialog.cxx @@ -67,7 +67,7 @@ Dialog::Dialog(OSystem& instance, DialogContainer& parent, const GUI::Font& font attr.blendalpha = 25; // darken background dialogs by 25% _shadeSurface->applyAttributes(); - _toolTip = make_unique(instance, *this, font); + _toolTip = make_unique(*this, font); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/gui/Dialog.hxx b/src/gui/Dialog.hxx index b134d7d37..f628ec792 100644 --- a/src/gui/Dialog.hxx +++ b/src/gui/Dialog.hxx @@ -124,9 +124,6 @@ class Dialog : public GuiObject bool shouldResize(uInt32& w, uInt32& h) const; ToolTip& tooltip() { return *_toolTip; } - //bool enableToolTip(); - //void showToolTip(int x, int y); - //void hideToolTip(); protected: void draw() override { } diff --git a/src/gui/ToolTip.cxx b/src/gui/ToolTip.cxx index 82c0df10b..9531ee5ef 100644 --- a/src/gui/ToolTip.cxx +++ b/src/gui/ToolTip.cxx @@ -24,35 +24,44 @@ #include "ToolTip.hxx" +// TODO: +// - disable when in edit mode +// - option to disable tips +// - multi line tips +// - nicer formating of DataDridWidget tip +// - allow reversing ToogleWidget (TooglePixelWidget) + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -ToolTip::ToolTip(OSystem& instance, Dialog& dialog, const GUI::Font& font) +ToolTip::ToolTip(Dialog& dialog, const GUI::Font& font) : myDialog(dialog), myFont(font) { const int fontWidth = font.getMaxCharWidth(), fontHeight = font.getFontHeight(); - myTextXOfs = fontHeight < 24 ? 5 : 8; //3 : 5; - myWidth = myTextXOfs * 2 + fontWidth * MAX_LEN; - myHeight = fontHeight + TEXT_Y_OFS * 2; + myTextXOfs = fontHeight < 24 ? 5 : 8; // 3 : 5; + myTextYOfs = fontHeight < 24 ? 2 : 3; + myWidth = fontWidth * MAX_LEN + myTextXOfs * 2; + myHeight = fontHeight + myTextYOfs * 2; + mySurface = myDialog.instance().frameBuffer().allocateSurface(myWidth, myHeight); myScale = myDialog.instance().frameBuffer().hidpiScaleFactor(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void ToolTip::request(Widget* widget) +void ToolTip::request(const Widget* widget) { if(myWidget != widget) - { release(); - } + if(myTimer == DELAY_TIME) { myWidget = widget; const uInt32 VGAP = 1; const uInt32 hCursor = 18; - string text = widget->getToolTip(); + string text = widget->getToolTip(myPos.x, myPos.y); uInt32 width = std::min(myWidth, myFont.getStringWidth(text) + myTextXOfs * 2); // Note: These include HiDPI scaling: const Common::Rect imageRect = myDialog.instance().frameBuffer().imageRect(); @@ -77,8 +86,8 @@ void ToolTip::request(Widget* widget) mySurface->frameRect(0, 0, width, myHeight, kColor); mySurface->fillRect(1, 1, width - 2, myHeight - 2, kWidColor); - mySurface->drawString(myFont, text, myTextXOfs, TEXT_Y_OFS, - width - myTextXOfs * 2, myHeight - TEXT_Y_OFS * 2, kTextColor); + mySurface->drawString(myFont, text, myTextXOfs, myTextYOfs, + width - myTextXOfs * 2, myHeight - myTextYOfs * 2, kTextColor); myDialog.setDirtyChain(); } myTimer++; diff --git a/src/gui/ToolTip.hxx b/src/gui/ToolTip.hxx index d3164a09d..125343294 100644 --- a/src/gui/ToolTip.hxx +++ b/src/gui/ToolTip.hxx @@ -19,7 +19,7 @@ #define TOOL_TIP_HXX /** - * Class for providing tooltip functionality + * Class for providing tool tip functionality * * @author Thomas Jentzsch */ @@ -37,13 +37,13 @@ public: // Maximum tooltip length static constexpr uInt32 MAX_LEN = 80; - ToolTip(OSystem& instance, Dialog& dialog, const GUI::Font& font); + ToolTip(Dialog& dialog, const GUI::Font& font); ~ToolTip() = default; /** Request a tooltip display */ - void request(Widget* widget); + void request(const Widget* widget); /** @@ -63,18 +63,19 @@ public: private: static constexpr uInt32 DELAY_TIME = 45; // display delay - static constexpr int TEXT_Y_OFS = 2; + //static constexpr int TEXT_Y_OFS = 2; Dialog& myDialog; const GUI::Font& myFont; - Widget* myWidget{nullptr}; + const Widget* myWidget{nullptr}; uInt32 myTimer{0}; Common::Point myPos; uInt32 myWidth{0}; uInt32 myHeight{0}; uInt32 myScale{1}; uInt32 myTextXOfs{0}; + uInt32 myTextYOfs{0}; shared_ptr mySurface; }; diff --git a/src/gui/Widget.hxx b/src/gui/Widget.hxx index bf831a5eb..42612cc99 100644 --- a/src/gui/Widget.hxx +++ b/src/gui/Widget.hxx @@ -105,8 +105,8 @@ class Widget : public GuiObject void setShadowColor(ColorId color) { _shadowcolor = color; setDirty(); } void setToolTip(const string& text); - const string& getToolTip() const { return _toolTipText; } - bool hasToolTip() const { return !_toolTipText.empty(); } + virtual string getToolTip(int x = 0, int y = 0) const { return _toolTipText; } + virtual bool hasToolTip() const { return !_toolTipText.empty(); } virtual void loadConfig() { } @@ -181,6 +181,10 @@ class StaticTextWidget : public Widget const string& text = "", TextAlign align = TextAlign::Left, ColorId shadowColor = kNone); ~StaticTextWidget() override = default; + + void handleMouseEntered() override {} + void handleMouseLeft() override {} + void setValue(int value); void setLabel(const string& label); void setAlign(TextAlign align) { _align = align; setDirty(); }