Skip to content

Commit

Permalink
Fix panels forwarding clicks from anywhere
Browse files Browse the repository at this point in the history
Very similar to ab28f93. Broken by 69e0a8b where I added an extra MouseDownInside check to the OnMouseDown (used to be OnMouseClick) of every component except that of sliders AND apparently panels, great.
  • Loading branch information
LBPHacker committed Mar 18, 2024
1 parent 4b866c4 commit bb471e6
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions src/gui/interface/Panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,32 +114,35 @@ void Panel::OnMouseClick(int localx, int localy, unsigned button)

void Panel::OnMouseDown(int x, int y, unsigned button)
{
auto localx = x - Position.X;
auto localy = y - Position.Y;
//check if clicked a child
for(int i = children.size()-1; i >= 0 ; --i)
if (MouseDownInside)
{
//child must be enabled
if(children[i]->Enabled)
auto localx = x - Position.X;
auto localy = y - Position.Y;
//check if clicked a child
for(int i = children.size()-1; i >= 0 ; --i)
{
//is mouse inside?
if( localx >= children[i]->Position.X + ViewportPosition.X &&
localy >= children[i]->Position.Y + ViewportPosition.Y &&
localx < children[i]->Position.X + ViewportPosition.X + children[i]->Size.X &&
localy < children[i]->Position.Y + ViewportPosition.Y + children[i]->Size.Y )
//child must be enabled
if(children[i]->Enabled)
{
GetParentWindow()->FocusComponent(children[i]);
children[i]->MouseDownInside = true;
break;
//is mouse inside?
if( localx >= children[i]->Position.X + ViewportPosition.X &&
localy >= children[i]->Position.Y + ViewportPosition.Y &&
localx < children[i]->Position.X + ViewportPosition.X + children[i]->Size.X &&
localy < children[i]->Position.Y + ViewportPosition.Y + children[i]->Size.Y )
{
GetParentWindow()->FocusComponent(children[i]);
children[i]->MouseDownInside = true;
break;
}
}
}
}

XOnMouseDown(x, y, button);
for (size_t i = 0; i < children.size(); ++i)
{
if(children[i]->Enabled)
children[i]->OnMouseDown(x - Position.X - ViewportPosition.X, y - Position.Y - ViewportPosition.Y, button);
XOnMouseDown(x, y, button);
for (size_t i = 0; i < children.size(); ++i)
{
if(children[i]->Enabled)
children[i]->OnMouseDown(x - Position.X - ViewportPosition.X, y - Position.Y - ViewportPosition.Y, button);
}
}
}

Expand Down

0 comments on commit bb471e6

Please sign in to comment.