mirror of https://github.com/stella-emu/stella.git
added value tool tips to debugger (DataGridWiget, ToogleWidget)
This commit is contained in:
parent
004b34f51e
commit
99c0cd66bc
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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<ToolTip>(instance, *this, font);
|
||||
_toolTip = make_unique<ToolTip>(*this, font);
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
|
|
@ -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 { }
|
||||
|
|
|
@ -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++;
|
||||
|
|
|
@ -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<FBSurface> mySurface;
|
||||
};
|
||||
|
||||
|
|
|
@ -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(); }
|
||||
|
|
Loading…
Reference in New Issue