Skip to content

Commit

Permalink
Merge pull request #112 from Jarod42/buttonHasMouse
Browse files Browse the repository at this point in the history
Button has mouse
  • Loading branch information
Jarod42 authored Sep 27, 2024
2 parents 2f197df + cd9241f commit b3b2cbe
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
1 change: 1 addition & 0 deletions include/guisan/widgets/button.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ namespace gcn

void mousePressed(MouseEvent& mouseEvent) override;
void mouseReleased(MouseEvent& mouseEvent) override;
void mouseClicked(MouseEvent& mouseEvent) override;
void mouseEntered(MouseEvent& mouseEvent) override;
void mouseExited(MouseEvent& mouseEvent) override;
void mouseDragged(MouseEvent& mouseEvent) override;
Expand Down
2 changes: 1 addition & 1 deletion include/guisan/widgets/togglebutton.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ namespace gcn

// Inherited from MouseListener

void mouseReleased(MouseEvent& mouseEvent) override;
void mouseClicked(MouseEvent& mouseEvent) override;

// Inherited from KeyListener

Expand Down
16 changes: 10 additions & 6 deletions src/widgets/button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,15 @@ namespace gcn
{
if (mMousePressed)
{
return true;
return mHasMouse;
}
return mKeyPressed;
}

void Button::mousePressed(MouseEvent& mouseEvent)
{
mHasMouse = gcn::Rectangle(0, 0, getWidth(), getHeight())
.isContaining(mouseEvent.getX(), mouseEvent.getY());
if (mouseEvent.isConsumed())
{
return;
Expand All @@ -228,16 +230,18 @@ namespace gcn

void Button::mouseReleased(MouseEvent& mouseEvent)
{
if (mouseEvent.getButton() == MouseEvent::Left
&& mMousePressed)
if (mouseEvent.getButton() == MouseEvent::Left)
{
mMousePressed = false;
distributeActionEvent();
mouseEvent.consume();
}
else if (mouseEvent.getButton() == MouseEvent::Left)
}

void Button::mouseClicked(MouseEvent& mouseEvent)
{
if (mouseEvent.getButton() == MouseEvent::Left)
{
mMousePressed = false;
distributeActionEvent();
mouseEvent.consume();
}
}
Expand Down
12 changes: 2 additions & 10 deletions src/widgets/togglebutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,22 +158,14 @@ namespace gcn
mSelected = selected;
}

void ToggleButton::mouseReleased(MouseEvent& mouseEvent)
void ToggleButton::mouseClicked(MouseEvent& mouseEvent)
{
if (mouseEvent.getButton() == MouseEvent::Left
&& mMousePressed
&& mHasMouse)
if (mouseEvent.getButton() == MouseEvent::Left)
{
mMousePressed = false;
toggleSelected();
distributeActionEvent();
mouseEvent.consume();
}
else if (mouseEvent.getButton() == MouseEvent::Left)
{
mMousePressed = false;
mouseEvent.consume();
}
}

void ToggleButton::keyReleased(KeyEvent& keyEvent)
Expand Down

0 comments on commit b3b2cbe

Please sign in to comment.