added tooltip hiding when context menus are opened

added tooltips to TiaOutputWidget and TiaZoomWidget
This commit is contained in:
thrust26 2020-11-19 16:40:16 +01:00
parent 3b85ceaa75
commit 998f423662
6 changed files with 111 additions and 1 deletions

View File

@ -247,6 +247,7 @@ void RomListWidget::handleMouseDown(int x, int y, MouseButton b, int clickCount)
// Set selected and add menu at current x,y mouse location // Set selected and add menu at current x,y mouse location
_selectedItem = findItem(x, y); _selectedItem = findItem(x, y);
scrollToSelected(); scrollToSelected();
dialog().tooltip().hide();
myMenu->show(x + getAbsX(), y + getAbsY(), myMenu->show(x + getAbsX(), y + getAbsY(),
dialog().surface().dstRect(), _selectedItem); dialog().surface().dstRect(), _selectedItem);
} }
@ -518,7 +519,6 @@ bool RomListWidget::changedToolTip(const Common::Point& oldPos,
return getToolTipIndex(oldPos) != getToolTipIndex(newPos); return getToolTipIndex(oldPos) != getToolTipIndex(newPos);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void RomListWidget::drawWidget(bool hilite) void RomListWidget::drawWidget(bool hilite)
{ {

View File

@ -22,6 +22,8 @@
#include "FBSurface.hxx" #include "FBSurface.hxx"
#include "Widget.hxx" #include "Widget.hxx"
#include "GuiObject.hxx" #include "GuiObject.hxx"
#include "Dialog.hxx"
#include "ToolTip.hxx"
#include "ContextMenu.hxx" #include "ContextMenu.hxx"
#include "TiaZoomWidget.hxx" #include "TiaZoomWidget.hxx"
#include "Debugger.hxx" #include "Debugger.hxx"
@ -55,6 +57,7 @@ TiaOutputWidget::TiaOutputWidget(GuiObject* boss, const GUI::Font& font,
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void TiaOutputWidget::loadConfig() void TiaOutputWidget::loadConfig()
{ {
setEnabled(true);
setDirty(); setDirty();
} }
@ -110,6 +113,7 @@ void TiaOutputWidget::handleMouseDown(int x, int y, MouseButton b, int clickCoun
myClickX = x; myClickX = x;
myClickY = y; myClickY = y;
dialog().tooltip().hide();
// Add menu at current x,y mouse location // Add menu at current x,y mouse location
myMenu->show(x + getAbsX(), y + getAbsY(), dialog().surface().dstRect()); myMenu->show(x + getAbsX(), y + getAbsY(), dialog().surface().dstRect());
} }
@ -158,6 +162,51 @@ void TiaOutputWidget::handleCommand(CommandSender* sender, int cmd, int data, in
} }
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Common::Point TiaOutputWidget::getToolTipIndex(const Common::Point& pos) const
{
const Int32 width = instance().console().tia().width();
const Int32 height = instance().console().tia().height();
const int col = (pos.x - 1 - getAbsX()) >> 1;
const int row = pos.y - 1 - getAbsY();
if(col < 0 || col >= width || row < 0 || row >= height)
return Common::Point(-1, -1);
else
return Common::Point(col, row);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
string TiaOutputWidget::getToolTip(const Common::Point& pos) const
{
Common::Point idx = getToolTipIndex(pos);
if(idx.x < 0)
return EmptyString;
uInt32 height = instance().console().tia().height();
// limit to 274 lines (PAL default without scaling)
uInt32 yStart = height <= FrameManager::Metrics::baseHeightPAL
? 0 : (height - FrameManager::Metrics::baseHeightPAL) >> 1;
const Int32 i = idx.x + (yStart + idx.y) * instance().console().tia().width();
uInt8* tiaOutputBuffer = instance().console().tia().outputBuffer();
ostringstream buf;
buf << _toolTipText
<< "X: #" << idx.x
<< "\nY: #" << idx.y
<< "\nC: $" << Common::Base::toString(tiaOutputBuffer[i], Common::Base::Fmt::_16);
return buf.str();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool TiaOutputWidget::changedToolTip(const Common::Point& oldPos,
const Common::Point& newPos) const
{
return getToolTipIndex(oldPos) != getToolTipIndex(newPos);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void TiaOutputWidget::drawWidget(bool hilite) void TiaOutputWidget::drawWidget(bool hilite)
{ {

View File

@ -47,6 +47,13 @@ class TiaOutputWidget : public Widget, public CommandSender
bool handleKeyDown(StellaKey key, StellaMod mod) override; bool handleKeyDown(StellaKey key, StellaMod mod) override;
bool handleKeyUp(StellaKey key, StellaMod mod) override; bool handleKeyUp(StellaKey key, StellaMod mod) override;
*/ */
string getToolTip(const Common::Point& pos) const override;
bool changedToolTip(const Common::Point& oldPos, const Common::Point& newPos) const override;
protected:
bool hasToolTip() const override { return true; }
Common::Point getToolTipIndex(const Common::Point& pos) const;
private: private:
unique_ptr<ContextMenu> myMenu; unique_ptr<ContextMenu> myMenu;
TiaZoomWidget* myZoom{nullptr}; TiaZoomWidget* myZoom{nullptr};

View File

@ -26,6 +26,8 @@
#include "FBSurface.hxx" #include "FBSurface.hxx"
#include "Widget.hxx" #include "Widget.hxx"
#include "GuiObject.hxx" #include "GuiObject.hxx"
#include "Dialog.hxx"
#include "ToolTip.hxx"
#include "ContextMenu.hxx" #include "ContextMenu.hxx"
#include "FrameManager.hxx" #include "FrameManager.hxx"
#include "TiaZoomWidget.hxx" #include "TiaZoomWidget.hxx"
@ -127,6 +129,7 @@ void TiaZoomWidget::handleMouseDown(int x, int y, MouseButton b, int clickCount)
} }
else if(b == MouseButton::RIGHT) else if(b == MouseButton::RIGHT)
{ {
dialog().tooltip().hide();
// Add menu at current x,y mouse location // Add menu at current x,y mouse location
myMenu->show(x + getAbsX(), y + getAbsY(), dialog().surface().dstRect()); myMenu->show(x + getAbsX(), y + getAbsY(), dialog().surface().dstRect());
} }
@ -141,6 +144,8 @@ void TiaZoomWidget::handleMouseUp(int x, int y, MouseButton b, int clickCount)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void TiaZoomWidget::handleMouseWheel(int x, int y, int direction) void TiaZoomWidget::handleMouseWheel(int x, int y, int direction)
{ {
dialog().tooltip().hide();
// zoom towards mouse position // zoom towards mouse position
myClickX = x; myClickX = x;
myClickY = y; myClickY = y;
@ -274,6 +279,47 @@ void TiaZoomWidget::handleCommand(CommandSender* sender, int cmd, int data, int
} }
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Common::Point TiaZoomWidget::getToolTipIndex(const Common::Point& pos) const
{
const Int32 width = instance().console().tia().width() * 2;
const Int32 height = instance().console().tia().height();
const int col = (pos.x - 1 - getAbsX()) / (myZoomLevel << 1) + (myOffX >> 1);
const int row = (pos.y - 1 - getAbsY()) / myZoomLevel + myOffY;
if(col < 0 || col >= width || row < 0 || row >= height)
return Common::Point(-1, -1);
else
return Common::Point(col, row);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
string TiaZoomWidget::getToolTip(const Common::Point& pos) const
{
Common::Point idx = getToolTipIndex(pos);
if(idx.x < 0)
return EmptyString;
const Int32 i = idx.x + idx.y * instance().console().tia().width();
uInt8* tiaOutputBuffer = instance().console().tia().outputBuffer();
ostringstream buf;
buf << _toolTipText
<< "X: #" << idx.x
<< "\nY: #" << idx.y
<< "\nC: $" << Common::Base::toString(tiaOutputBuffer[i], Common::Base::Fmt::_16);
return buf.str();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool TiaZoomWidget::changedToolTip(const Common::Point& oldPos,
const Common::Point& newPos) const
{
return getToolTipIndex(oldPos) != getToolTipIndex(newPos);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void TiaZoomWidget::drawWidget(bool hilite) void TiaZoomWidget::drawWidget(bool hilite)
{ {

View File

@ -34,6 +34,13 @@ class TiaZoomWidget : public Widget, public CommandSender
void loadConfig() override; void loadConfig() override;
void setPos(int x, int y); void setPos(int x, int y);
string getToolTip(const Common::Point& pos) const override;
bool changedToolTip(const Common::Point& oldPos, const Common::Point& newPos) const override;
protected:
bool hasToolTip() const override { return true; }
Common::Point getToolTipIndex(const Common::Point& pos) const;
private: private:
void zoom(int level); void zoom(int level);
void recalc(); void recalc();

View File

@ -568,6 +568,7 @@ void LauncherDialog::handleMouseDown(int x, int y, MouseButton b, int clickCount
// Grab right mouse button for context menu, send left to base class // Grab right mouse button for context menu, send left to base class
if(b == MouseButton::RIGHT) if(b == MouseButton::RIGHT)
{ {
dialog().tooltip().hide();
// Dynamically create context menu for ROM list options // Dynamically create context menu for ROM list options
VariantList items; VariantList items;