Previous Thread
Next Thread
Print Thread
Debugger memory view clicks end in wrong spot #114770
02/27/19 09:35 PM
02/27/19 09:35 PM
Joined: Feb 2014
Posts: 251
G
Golden Child Offline OP
Senior Member
Golden Child  Offline OP
Senior Member
G
Joined: Feb 2014
Posts: 251
Hi all,

Was fiddling with the debugger and noticed that the debugger memory view doesn't always register clicks in the right spot. If you have a very tall memory window, the clicks get more out of sync the further down you go.

It clicks in the right spot if your window is small enough.

I'm running Ubuntu 18.10 so I don't know if this is on other systems too.

In the file: src/osd/modules/debugger/qt/memorywindow.cpp there's a mousePressEvent:

Code
void DebuggerMemView::mousePressEvent(QMouseEvent* event)
{
	const bool leftClick = event->button() == Qt::LeftButton;
	const bool rightClick = event->button() == Qt::RightButton;

	if (leftClick || rightClick)
	{
		QFontMetrics actualFont = fontMetrics();
		const double fontWidth = actualFont.width(QString(100, '_')) / 100.;
//		const int fontHeight = std::max(1, actualFont.height());
//
// here let's use:  actualFont.lineSpacing()

const int fontHeight = std::max(1, actualFont.lineSpacing());

//printf("fontheight actualfont.height() = %d\n",actualFont.height());
//printf("fontheight actualfont.lineSpacing() = %d\n",actualFont.lineSpacing());


		debug_view_xy topLeft = view()->visible_position();
		debug_view_xy clickViewPosition;
		clickViewPosition.x = topLeft.x + (event->x() / fontWidth);
		clickViewPosition.y = topLeft.y + (event->y() / fontHeight);
		if (leftClick)
		{
			view()->process_click(DCK_LEFT_CLICK, clickViewPosition);
		}



I noticed that in some places the code would use actualFont.height() and in others actualFont.lineSpacing() so I wondered if changing it to lineSpacing() would fix it. It seems to fix it for me.

Under my Ubuntu 18.10 I get these values from the printf:

fontheight actualfont.height() = 17
fontheight actualfont.lineSpacing() = 16

The one pixel difference gets magnified the further down you go so that explains it.

Re: Debugger memory view clicks end in wrong spot [Re: Golden Child] #114771
02/27/19 10:27 PM
02/27/19 10:27 PM
Joined: Mar 2001
Posts: 16,204
USA
R
R. Belmont Online content
Very Senior Member
R. Belmont  Online Content
Very Senior Member
R
Joined: Mar 2001
Posts: 16,204
USA
Thanks! I've just committed this change, so if you pull from Github and build it should be fixed.

Re: Debugger memory view clicks end in wrong spot [Re: Golden Child] #114773
02/28/19 12:42 AM
02/28/19 12:42 AM
Joined: Feb 2014
Posts: 251
G
Golden Child Offline OP
Senior Member
Golden Child  Offline OP
Senior Member
G
Joined: Feb 2014
Posts: 251
Thanks, RB!

Re: Debugger memory view clicks end in wrong spot [Re: Golden Child] #114774
02/28/19 11:12 AM
02/28/19 11:12 AM
Joined: Feb 2014
Posts: 251
G
Golden Child Offline OP
Senior Member
Golden Child  Offline OP
Senior Member
G
Joined: Feb 2014
Posts: 251
Hi RB,

I noticed that the DebuggerView has the same issue: If you have a really tall disassembly pane or window, the clicks register above where you clicked as well.

In the paint event lineSpacing() is used

Code
void DebuggerView::paintEvent(QPaintEvent* event)
{
        // Tell the MAME debug view how much real estate is available
        QFontMetrics actualFont = fontMetrics();
        const double fontWidth = actualFont.width(QString(100, '_')) / 100.;
        const int fontHeight = std::max(1, actualFont.lineSpacing());


and in the mousePressEvent actualFont.height() gets used:


Code
void DebuggerView::mousePressEvent(QMouseEvent* event)
{
        if (m_view == nullptr)
                return;

        if (event->button() == Qt::LeftButton)
        {
                QFontMetrics actualFont = fontMetrics();
                const double fontWidth = actualFont.width(QString(100, '_')) / 100.;
//              const int fontHeight = std::max(1, actualFont.height());

                const int fontHeight = std::max(1, actualFont.lineSpacing());


This is what I get for rotating my monitor in portrait mode 8-)

Re: Debugger memory view clicks end in wrong spot [Re: Golden Child] #114775
02/28/19 11:37 AM
02/28/19 11:37 AM
Joined: Feb 2004
Posts: 2,044
Sydney, Australia
Vas Crabb Offline
Very Senior Member
Vas Crabb  Offline
Very Senior Member
Joined: Feb 2004
Posts: 2,044
Sydney, Australia
Why don't you find all the cases of it, and submit a PR? Or factor out that stuff to a common base class for the views so the same bug can't appear in multiple places again?

Re: Debugger memory view clicks end in wrong spot [Re: Golden Child] #114776
02/28/19 12:41 PM
02/28/19 12:41 PM
Joined: Feb 2014
Posts: 251
G
Golden Child Offline OP
Senior Member
Golden Child  Offline OP
Senior Member
G
Joined: Feb 2014
Posts: 251
Hi Vas,

You're right, I'm going to figure out this git stuff. 8-)

As much fun as I have fiddling with mame I should.

Re: Debugger memory view clicks end in wrong spot [Re: Golden Child] #114791
03/03/19 02:23 PM
03/03/19 02:23 PM
Joined: Feb 2014
Posts: 251
G
Golden Child Offline OP
Senior Member
Golden Child  Offline OP
Senior Member
G
Joined: Feb 2014
Posts: 251
Ok, I think I'm figuring out how this git stuff works.

I've got a one-line fix:

https://github.com/mamedev/mame/pull/4705


I discovered a couple of neat git things with ubuntu along the way: gitk and git gui

sudo apt install gitk
sudo apt install git-gui

It's a lot easier to be able to visualize things with gitk and more user-friendly with "git gui" than doing the command line.

Re: Debugger memory view clicks end in wrong spot [Re: Golden Child] #114792
03/03/19 04:00 PM
03/03/19 04:00 PM
Joined: Aug 2004
Posts: 1,382
Robbbert Offline
Very Senior Member
Robbbert  Offline
Very Senior Member
Joined: Aug 2004
Posts: 1,382
I've committed it for you.

Re: Debugger memory view clicks end in wrong spot [Re: Golden Child] #114793
03/03/19 05:01 PM
03/03/19 05:01 PM
Joined: Feb 2014
Posts: 251
G
Golden Child Offline OP
Senior Member
Golden Child  Offline OP
Senior Member
G
Joined: Feb 2014
Posts: 251
Thanks! Now I'm commited! Or should I *be* commited? 8-)


Who's Online Now
3 registered members (mixmaster, Gregoire Duval, 1 invisible), 32 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Shout Box
Forum Statistics
Forums9
Topics8,653
Posts113,409
Members4,846
Most Online324
Dec 20th, 2018
Powered by UBB.threads™ PHP Forum Software 7.6.1.1
(Release build 20180111)
Page Time: 0.040s Queries: 14 (0.016s) Memory: 5.6550 MB (Peak: 5.8662 MB) Zlib enabled. Server Time: 2019-05-23 14:55:48 UTC