diff --git a/src/debugger/gui/DataGridWidget.cxx b/src/debugger/gui/DataGridWidget.cxx index d11375d29..9e75a955f 100644 --- a/src/debugger/gui/DataGridWidget.cxx +++ b/src/debugger/gui/DataGridWidget.cxx @@ -583,13 +583,14 @@ int DataGridWidget::getToolTipIndex(Common::Point pos) const string DataGridWidget::getToolTip(Common::Point pos) const { const Int32 val = _valueList[getToolTipIndex(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; + buf << _toolTipText + << "$" << Common::Base::toString(val, Common::Base::Fmt::_16) + << " = #" << val; + if(val < 0x100) + buf << " = %" << Common::Base::toString(val, Common::Base::Fmt::_2); + return buf.str(); } diff --git a/src/debugger/gui/DebuggerDialog.cxx b/src/debugger/gui/DebuggerDialog.cxx index b8c0662ee..07e530ac6 100644 --- a/src/debugger/gui/DebuggerDialog.cxx +++ b/src/debugger/gui/DebuggerDialog.cxx @@ -18,6 +18,7 @@ #include "Cart.hxx" #include "Widget.hxx" #include "Dialog.hxx" +#include "ToolTip.hxx" #include "Settings.hxx" #include "StellaKeys.hxx" #include "EventHandler.hxx" @@ -406,6 +407,7 @@ void DebuggerDialog::createFont() break; } } + tooltip().setFont(*myNFont); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/debugger/gui/RomListWidget.cxx b/src/debugger/gui/RomListWidget.cxx index 58d392ee9..e595fc6aa 100644 --- a/src/debugger/gui/RomListWidget.cxx +++ b/src/debugger/gui/RomListWidget.cxx @@ -442,6 +442,69 @@ void RomListWidget::lostFocusWidget() abortEditMode(); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Common::Point RomListWidget::getToolTipIndex(Common::Point pos) const +{ + const Common::Rect& r = getEditRect(); + const int col = (pos.x - r.x() - getAbsX()) / _font.getMaxCharWidth(); + const int row = (pos.y - getAbsY()) / _lineHeight; + + if(col < 0) + return Common::Point(-1, -1); + else + return Common::Point(col, row + _currentPos); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +string RomListWidget::getToolTip(Common::Point pos) const +{ + const Common::Point idx = getToolTipIndex(pos); + + if(idx.y == -1) + return EmptyString; + + const string bytes = myDisasm->list[idx.y].bytes; + + if(bytes.length() < idx.x + 1) + return EmptyString; + + Int32 val; + if(bytes.length() == 8 && bytes[2] != ' ') + { + // Binary value + val = stol(bytes, 0, 2); + } + else + { + // hex 1..3 values + if(idx.x % 3 == 2) + // Skip gaps between hex values + return EmptyString; + + // Get one hex byte + const string valStr = bytes.substr((idx.x / 3) * 3, 2); + + val = stol(valStr, 0, 16); + + } + ostringstream buf; + + buf << _toolTipText + << "$" << Common::Base::toString(val, Common::Base::Fmt::_16) + << " = #" << val; + if(val < 0x100) + buf << " = %" << Common::Base::toString(val, Common::Base::Fmt::_2); + + return buf.str(); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool RomListWidget::changedToolTip(Common::Point oldPos, Common::Point newPos) const +{ + return getToolTipIndex(oldPos) != getToolTipIndex(newPos); +} + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void RomListWidget::drawWidget(bool hilite) { diff --git a/src/debugger/gui/RomListWidget.hxx b/src/debugger/gui/RomListWidget.hxx index 37473d12f..3f26d217f 100644 --- a/src/debugger/gui/RomListWidget.hxx +++ b/src/debugger/gui/RomListWidget.hxx @@ -56,6 +56,9 @@ class RomListWidget : public EditableWidget void setSelected(int item); void setHighlighted(int item); + string getToolTip(Common::Point pos) const override; + bool changedToolTip(Common::Point oldPos, Common::Point newPos) const override; + protected: void handleMouseDown(int x, int y, MouseButton b, int clickCount) override; void handleMouseUp(int x, int y, MouseButton b, int clickCount) override; @@ -77,11 +80,15 @@ class RomListWidget : public EditableWidget void endEditMode() override; void abortEditMode() override; void lostFocusWidget() override; + + bool hasToolTip() const override { return true; } + void scrollToSelected() { scrollToCurrent(_selectedItem); } void scrollToHighlighted() { scrollToCurrent(_highlightedItem); } private: void scrollToCurrent(int item); + Common::Point getToolTipIndex(Common::Point pos) const; private: unique_ptr myMenu; diff --git a/src/debugger/gui/ToggleWidget.cxx b/src/debugger/gui/ToggleWidget.cxx index 60f4ee154..e20544783 100644 --- a/src/debugger/gui/ToggleWidget.cxx +++ b/src/debugger/gui/ToggleWidget.cxx @@ -223,6 +223,7 @@ string ToggleWidget::getToolTip(Common::Point pos) const { const int idx = getToolTipIndex(pos); Int32 val = 0; + ostringstream buf; if(_swapBits) for(int col = _cols - 1; col >= 0; --col) @@ -238,13 +239,12 @@ string ToggleWidget::getToolTip(Common::Point pos) const } val <<= _shiftBits; - 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; + buf << _toolTipText + << "$" << Common::Base::toString(val, Common::Base::Fmt::_16) + << " = #" << val; + if(val < 0x100) + buf << " = %" << Common::Base::toString(val, Common::Base::Fmt::_2); - // TODO: time leading spaces and zeroes - buf << "$" << hex << " = #" << dec << " = %" << bin; return buf.str(); } diff --git a/src/gui/LauncherDialog.cxx b/src/gui/LauncherDialog.cxx index 9c140e15c..5092299ec 100644 --- a/src/gui/LauncherDialog.cxx +++ b/src/gui/LauncherDialog.cxx @@ -30,6 +30,7 @@ #include "StellaSettingsDialog.hxx" #include "WhatsNewDialog.hxx" #include "MessageBox.hxx" +#include "ToolTip.hxx" #include "OSystem.hxx" #include "FrameBuffer.hxx" #include "FBSurface.hxx" @@ -56,8 +57,7 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - LauncherDialog::LauncherDialog(OSystem& osystem, DialogContainer& parent, int x, int y, int w, int h) - : Dialog(osystem, parent, osystem.frameBuffer().launcherFont(), "", - x, y, w, h) + : Dialog(osystem, parent, x, y, w, h) { myUseMinimalUI = instance().settings().getBool("minimal_ui"); @@ -80,6 +80,8 @@ LauncherDialog::LauncherDialog(OSystem& osystem, DialogContainer& parent, const string& lblAllFiles = "Show all files"; const string& lblFound = "XXXX items found"; + tooltip().setFont(font); + lwidth = font.getStringWidth(lblRom); lwidth2 = font.getStringWidth(lblAllFiles) + CheckboxWidget::boxSize(font); int lwidth3 = font.getStringWidth(lblFilter); diff --git a/src/gui/ToolTip.cxx b/src/gui/ToolTip.cxx index 36c8b1b20..85f5bedf4 100644 --- a/src/gui/ToolTip.cxx +++ b/src/gui/ToolTip.cxx @@ -32,16 +32,24 @@ // + disable when in edit mode // - option to disable tips // - multi line tips -// - nicer formating of DataDridWidget tip -// - allow reversing ToogleWidget (TooglePixelWidget) -// - shift checkbox bits +// + nicer formating of DataDridWidget tip +// + allow reversing ToogleWidget (TooglePixelWidget) +// + shift checkbox bits // - RomListWidget (hex codes, maybe disassembly operands) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ToolTip::ToolTip(Dialog& dialog, const GUI::Font& font) - : myDialog(dialog), - myFont(font) + : myDialog(dialog) { + myScale = myDialog.instance().frameBuffer().hidpiScaleFactor(); + + setFont(font); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void ToolTip::setFont(const GUI::Font& font) +{ + myFont = &font; const int fontWidth = font.getMaxCharWidth(), fontHeight = font.getFontHeight(); @@ -51,7 +59,6 @@ ToolTip::ToolTip(Dialog& dialog, const GUI::Font& font) myHeight = fontHeight + myTextYOfs * 2; mySurface = myDialog.instance().frameBuffer().allocateSurface(myWidth, myHeight); - myScale = myDialog.instance().frameBuffer().hidpiScaleFactor(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -86,7 +93,7 @@ void ToolTip::release() { if(myTipShown) { - myTimer = DELAY_TIME; + myTimer = DELAY_TIME - 1; myTipShown = false; myDialog.setDirtyChain(); @@ -118,7 +125,16 @@ void ToolTip::show() const uInt32 V_GAP = 1; const uInt32 H_CURSOR = 18; string text = myTipWidget->getToolTip(myPos); - uInt32 width = std::min(myWidth, myFont.getStringWidth(text) + myTextXOfs * 2); + + myTipShown = true; + if(text.empty()) + { + release(); + return; + } + + uInt32 width = std::min(myWidth, myFont->getStringWidth(text) + myTextXOfs * 2); + //uInt32 height = std::min(myHeight, font.getFontHeight() + myTextYOfs * 2); // Note: The rects include HiDPI scaling const Common::Rect imageRect = myDialog.instance().frameBuffer().imageRect(); const Common::Rect dialogRect = myDialog.surface().dstRect(); @@ -142,7 +158,7 @@ void ToolTip::show() mySurface->frameRect(0, 0, width, myHeight, kColor); mySurface->fillRect(1, 1, width - 2, myHeight - 2, kWidColor); - mySurface->drawString(myFont, text, myTextXOfs, myTextYOfs, + mySurface->drawString(*myFont, text, myTextXOfs, myTextYOfs, width - myTextXOfs * 2, myHeight - myTextYOfs * 2, kTextColor); myTipShown = true; diff --git a/src/gui/ToolTip.hxx b/src/gui/ToolTip.hxx index b3bbf547a..879200c06 100644 --- a/src/gui/ToolTip.hxx +++ b/src/gui/ToolTip.hxx @@ -40,6 +40,8 @@ class ToolTip ToolTip(Dialog& dialog, const GUI::Font& font); ~ToolTip() = default; + void setFont(const GUI::Font& font); + /** Request a tooltip display. */ @@ -73,7 +75,7 @@ class ToolTip static constexpr uInt32 DELAY_TIME = 45; // display delay Dialog& myDialog; - const GUI::Font& myFont; + const GUI::Font* myFont{nullptr}; const Widget* myTipWidget{nullptr}; const Widget* myFocusWidget{nullptr};