aligned tooltip font to dialog font

improved debugger tooltip display
added tooltips for RomListWidget bytes
This commit is contained in:
thrust26 2020-11-17 18:10:54 +01:00
parent 92b77f32c4
commit 9bb6959dd8
8 changed files with 116 additions and 23 deletions

View File

@ -583,13 +583,14 @@ int DataGridWidget::getToolTipIndex(Common::Point pos) const
string DataGridWidget::getToolTip(Common::Point pos) const string DataGridWidget::getToolTip(Common::Point pos) const
{ {
const Int32 val = _valueList[getToolTipIndex(pos)]; 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; ostringstream buf;
// TODO: time leading spaces and zeroes buf << _toolTipText
buf << "$" << hex << " = #" << dec << " = %" << bin; << "$" << Common::Base::toString(val, Common::Base::Fmt::_16)
<< " = #" << val;
if(val < 0x100)
buf << " = %" << Common::Base::toString(val, Common::Base::Fmt::_2);
return buf.str(); return buf.str();
} }

View File

@ -18,6 +18,7 @@
#include "Cart.hxx" #include "Cart.hxx"
#include "Widget.hxx" #include "Widget.hxx"
#include "Dialog.hxx" #include "Dialog.hxx"
#include "ToolTip.hxx"
#include "Settings.hxx" #include "Settings.hxx"
#include "StellaKeys.hxx" #include "StellaKeys.hxx"
#include "EventHandler.hxx" #include "EventHandler.hxx"
@ -406,6 +407,7 @@ void DebuggerDialog::createFont()
break; break;
} }
} }
tooltip().setFont(*myNFont);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -442,6 +442,69 @@ void RomListWidget::lostFocusWidget()
abortEditMode(); 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) void RomListWidget::drawWidget(bool hilite)
{ {

View File

@ -56,6 +56,9 @@ class RomListWidget : public EditableWidget
void setSelected(int item); void setSelected(int item);
void setHighlighted(int item); void setHighlighted(int item);
string getToolTip(Common::Point pos) const override;
bool changedToolTip(Common::Point oldPos, Common::Point newPos) const override;
protected: protected:
void handleMouseDown(int x, int y, MouseButton b, int clickCount) override; void handleMouseDown(int x, int y, MouseButton b, int clickCount) override;
void handleMouseUp(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 endEditMode() override;
void abortEditMode() override; void abortEditMode() override;
void lostFocusWidget() override; void lostFocusWidget() override;
bool hasToolTip() const override { return true; }
void scrollToSelected() { scrollToCurrent(_selectedItem); } void scrollToSelected() { scrollToCurrent(_selectedItem); }
void scrollToHighlighted() { scrollToCurrent(_highlightedItem); } void scrollToHighlighted() { scrollToCurrent(_highlightedItem); }
private: private:
void scrollToCurrent(int item); void scrollToCurrent(int item);
Common::Point getToolTipIndex(Common::Point pos) const;
private: private:
unique_ptr<RomListSettings> myMenu; unique_ptr<RomListSettings> myMenu;

View File

@ -223,6 +223,7 @@ string ToggleWidget::getToolTip(Common::Point pos) const
{ {
const int idx = getToolTipIndex(pos); const int idx = getToolTipIndex(pos);
Int32 val = 0; Int32 val = 0;
ostringstream buf;
if(_swapBits) if(_swapBits)
for(int col = _cols - 1; col >= 0; --col) for(int col = _cols - 1; col >= 0; --col)
@ -238,13 +239,12 @@ string ToggleWidget::getToolTip(Common::Point pos) const
} }
val <<= _shiftBits; val <<= _shiftBits;
const string hex = Common::Base::toString(val, Common::Base::Fmt::_16); buf << _toolTipText
const string dec = Common::Base::toString(val, Common::Base::Fmt::_10); << "$" << Common::Base::toString(val, Common::Base::Fmt::_16)
const string bin = Common::Base::toString(val, Common::Base::Fmt::_2); << " = #" << val;
ostringstream buf; 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(); return buf.str();
} }

View File

@ -30,6 +30,7 @@
#include "StellaSettingsDialog.hxx" #include "StellaSettingsDialog.hxx"
#include "WhatsNewDialog.hxx" #include "WhatsNewDialog.hxx"
#include "MessageBox.hxx" #include "MessageBox.hxx"
#include "ToolTip.hxx"
#include "OSystem.hxx" #include "OSystem.hxx"
#include "FrameBuffer.hxx" #include "FrameBuffer.hxx"
#include "FBSurface.hxx" #include "FBSurface.hxx"
@ -56,8 +57,7 @@
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
LauncherDialog::LauncherDialog(OSystem& osystem, DialogContainer& parent, LauncherDialog::LauncherDialog(OSystem& osystem, DialogContainer& parent,
int x, int y, int w, int h) int x, int y, int w, int h)
: Dialog(osystem, parent, osystem.frameBuffer().launcherFont(), "", : Dialog(osystem, parent, x, y, w, h)
x, y, w, h)
{ {
myUseMinimalUI = instance().settings().getBool("minimal_ui"); myUseMinimalUI = instance().settings().getBool("minimal_ui");
@ -80,6 +80,8 @@ LauncherDialog::LauncherDialog(OSystem& osystem, DialogContainer& parent,
const string& lblAllFiles = "Show all files"; const string& lblAllFiles = "Show all files";
const string& lblFound = "XXXX items found"; const string& lblFound = "XXXX items found";
tooltip().setFont(font);
lwidth = font.getStringWidth(lblRom); lwidth = font.getStringWidth(lblRom);
lwidth2 = font.getStringWidth(lblAllFiles) + CheckboxWidget::boxSize(font); lwidth2 = font.getStringWidth(lblAllFiles) + CheckboxWidget::boxSize(font);
int lwidth3 = font.getStringWidth(lblFilter); int lwidth3 = font.getStringWidth(lblFilter);

View File

@ -32,16 +32,24 @@
// + disable when in edit mode // + disable when in edit mode
// - option to disable tips // - option to disable tips
// - multi line tips // - multi line tips
// - nicer formating of DataDridWidget tip // + nicer formating of DataDridWidget tip
// - allow reversing ToogleWidget (TooglePixelWidget) // + allow reversing ToogleWidget (TooglePixelWidget)
// - shift checkbox bits // + shift checkbox bits
// - RomListWidget (hex codes, maybe disassembly operands) // - RomListWidget (hex codes, maybe disassembly operands)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ToolTip::ToolTip(Dialog& dialog, const GUI::Font& font) ToolTip::ToolTip(Dialog& dialog, const GUI::Font& font)
: myDialog(dialog), : myDialog(dialog)
myFont(font)
{ {
myScale = myDialog.instance().frameBuffer().hidpiScaleFactor();
setFont(font);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void ToolTip::setFont(const GUI::Font& font)
{
myFont = &font;
const int fontWidth = font.getMaxCharWidth(), const int fontWidth = font.getMaxCharWidth(),
fontHeight = font.getFontHeight(); fontHeight = font.getFontHeight();
@ -51,7 +59,6 @@ ToolTip::ToolTip(Dialog& dialog, const GUI::Font& font)
myHeight = fontHeight + myTextYOfs * 2; myHeight = fontHeight + myTextYOfs * 2;
mySurface = myDialog.instance().frameBuffer().allocateSurface(myWidth, myHeight); mySurface = myDialog.instance().frameBuffer().allocateSurface(myWidth, myHeight);
myScale = myDialog.instance().frameBuffer().hidpiScaleFactor();
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -86,7 +93,7 @@ void ToolTip::release()
{ {
if(myTipShown) if(myTipShown)
{ {
myTimer = DELAY_TIME; myTimer = DELAY_TIME - 1;
myTipShown = false; myTipShown = false;
myDialog.setDirtyChain(); myDialog.setDirtyChain();
@ -118,7 +125,16 @@ void ToolTip::show()
const uInt32 V_GAP = 1; const uInt32 V_GAP = 1;
const uInt32 H_CURSOR = 18; const uInt32 H_CURSOR = 18;
string text = myTipWidget->getToolTip(myPos); 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 // Note: The rects include HiDPI scaling
const Common::Rect imageRect = myDialog.instance().frameBuffer().imageRect(); const Common::Rect imageRect = myDialog.instance().frameBuffer().imageRect();
const Common::Rect dialogRect = myDialog.surface().dstRect(); const Common::Rect dialogRect = myDialog.surface().dstRect();
@ -142,7 +158,7 @@ void ToolTip::show()
mySurface->frameRect(0, 0, width, myHeight, kColor); mySurface->frameRect(0, 0, width, myHeight, kColor);
mySurface->fillRect(1, 1, width - 2, myHeight - 2, kWidColor); 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); width - myTextXOfs * 2, myHeight - myTextYOfs * 2, kTextColor);
myTipShown = true; myTipShown = true;

View File

@ -40,6 +40,8 @@ class ToolTip
ToolTip(Dialog& dialog, const GUI::Font& font); ToolTip(Dialog& dialog, const GUI::Font& font);
~ToolTip() = default; ~ToolTip() = default;
void setFont(const GUI::Font& font);
/** /**
Request a tooltip display. Request a tooltip display.
*/ */
@ -73,7 +75,7 @@ class ToolTip
static constexpr uInt32 DELAY_TIME = 45; // display delay static constexpr uInt32 DELAY_TIME = 45; // display delay
Dialog& myDialog; Dialog& myDialog;
const GUI::Font& myFont; const GUI::Font* myFont{nullptr};
const Widget* myTipWidget{nullptr}; const Widget* myTipWidget{nullptr};
const Widget* myFocusWidget{nullptr}; const Widget* myFocusWidget{nullptr};