Skip to content

Commit

Permalink
Re #211 Select move from game time properly
Browse files Browse the repository at this point in the history
There was a problem with how gametime move selection worked:

1. Click a spot on game time (which selects a move in the game)
2. Press right arrow a couple times to select a different move
3. Click the same spot on game time

This should rewind the game back to the spot clicked in game time, but
if you didn't move the mouse between steps 1. and 3., the move wasn't
updated.

Another bug is fixed: any time the user clicked a spot in game time, the
move was updated twice: once on mouse "press" and once on mouse
"release".
  • Loading branch information
limitedAtonement committed Jul 27, 2024
1 parent d983d2d commit 49c2af2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
31 changes: 14 additions & 17 deletions src/gui/chartwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,22 @@ void ChartWidget::resizeEvent(QResizeEvent*)
updatePolygons();
}

void ChartWidget::handleMouseEvent(QMouseEvent *event)
void ChartWidget::handleMouseEvent(QMouseEvent *event, bool deduplicate)
{
if (width() && m_values.size() && (m_values[0].count()>1))
if (!width() || !m_values.size() || (m_values[0].count()<2))
{
QPointF p = EVENT_POSITION(event);
double multiplierW = ((double)width()) / (m_values[0].count()-1);
double x = 0.5 + (p.x() / multiplierW);
if (m_lastSentIndicator!=(int)x)
{
emit halfMoveRequested((int)x);
m_lastSentIndicator = (int)x;
}
return;
}
QPointF p = EVENT_POSITION(event);
double multiplierW = ((double)width()) / (m_values[0].count()-1);
double x = 0.5 + (p.x() / multiplierW);
int move_index = static_cast<int>(x);
if (deduplicate && m_lastSentIndicator==move_index)
{
return;
}
emit halfMoveRequested(move_index);
m_lastSentIndicator = move_index;
}

#if QT_VERSION < 0x060000
Expand All @@ -155,7 +158,7 @@ void ChartWidget::leaveEvent(QEvent *event)

void ChartWidget::mousePressEvent(QMouseEvent *event)
{
handleMouseEvent(event);
handleMouseEvent(event, false);
QWidget::mousePressEvent(event);
}

Expand All @@ -165,12 +168,6 @@ void ChartWidget::mouseMoveEvent(QMouseEvent *event)
QWidget::mouseMoveEvent(event);
}

void ChartWidget::mouseReleaseEvent(QMouseEvent *event)
{
handleMouseEvent(event);
QWidget::mouseReleaseEvent(event);
}

void ChartWidget::updatePly()
{
if (m_values.size() && (m_values[0].count()>1))
Expand Down
3 changes: 1 addition & 2 deletions src/gui/chartwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ class ChartWidget : public QWidget
void halfMoveRequested(int);

protected:
void handleMouseEvent(QMouseEvent *event);
void handleMouseEvent(QMouseEvent *event, bool deduplicate = true);
virtual void paintEvent(QPaintEvent* event);
virtual void resizeEvent(QResizeEvent* event);
virtual void mousePressEvent(QMouseEvent* event);
virtual void mouseMoveEvent(QMouseEvent* event);
virtual void mouseReleaseEvent(QMouseEvent* event);
#if QT_VERSION < 0x060000
virtual void enterEvent(QEvent *event);
#else
Expand Down

0 comments on commit 49c2af2

Please sign in to comment.