Clean up OnMouseClick/Unclick madness
This is a prerequisite for making ScrollPanel work nicely on touch screens. Engine used the terms MouseClick and MouseUnclick to refer to events that are traditionally called MouseDown and MouseUp, this was fixed with simple renaming. Component and friends similarly used the terms MouseClick and MouseUnclick to refer to events that are traditionally called MouseDown and MouseUp and, succumbing to their own confusing terminology, also implemented behaviours associated with both the actual events MouseDown and MouseClick in code that was responsible for handling only the actual event MouseDown (i.e. what they called MouseClick). This had been overlooked for a long time because nobody cares that a checkbox changes state when the mouse button is pressed on it rather than when it is released. The fix is to migrate many pieces of code that run in response to MouseDown events, such as checkbox state change code, to MouseClick events, and to redefine a MouseClick to mean a sequence of MouseDown and MouseUp inside the component, rather than just a MouseDown. This is complicated by the fact that MouseClick events report mouse coordinates relative to the top left corner of the component, while MouseDown events report them relative to the top left corner of the container of the component. Other pieces of code that make sense to be run in response to MouseDown events, such as label selection code, were left alone.
This commit is contained in:
parent
ae07c55f4d
commit
69e0a8b0aa
@ -349,7 +349,7 @@ static void EventProcess(const SDL_Event &event)
|
||||
mousey = event.button.y;
|
||||
}
|
||||
mouseButton = event.button.button;
|
||||
engine.onMouseClick(mousex, mousey, mouseButton);
|
||||
engine.onMouseDown(mousex, mousey, mouseButton);
|
||||
|
||||
mouseDown = true;
|
||||
if constexpr (!DEBUG)
|
||||
@ -365,7 +365,7 @@ static void EventProcess(const SDL_Event &event)
|
||||
mousey = event.button.y;
|
||||
}
|
||||
mouseButton = event.button.button;
|
||||
engine.onMouseUnclick(mousex, mousey, mouseButton);
|
||||
engine.onMouseUp(mousex, mousey, mouseButton);
|
||||
|
||||
mouseDown = false;
|
||||
if constexpr (!DEBUG)
|
||||
|
@ -87,7 +87,7 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
void OnMouseUnclick(int x, int y, unsigned int button) override
|
||||
void OnMouseClick(int x, int y, unsigned int button) override
|
||||
{
|
||||
if(isButtonDown)
|
||||
{
|
||||
@ -96,7 +96,7 @@ public:
|
||||
else if(rightDown)
|
||||
DoRightAction();
|
||||
}
|
||||
ui::Button::OnMouseUnclick(x, y, button);
|
||||
ui::Button::OnMouseClick(x, y, button);
|
||||
|
||||
}
|
||||
void OnMouseHover(int x, int y) override
|
||||
@ -120,16 +120,19 @@ public:
|
||||
toolTip = newToolTip1;
|
||||
toolTip2 = newToolTip2;
|
||||
}
|
||||
void OnMouseClick(int x, int y, unsigned int button) override
|
||||
void OnMouseDown(int x, int y, unsigned int button) override
|
||||
{
|
||||
ui::Button::OnMouseDown(x, y, button);
|
||||
if (MouseDownInside)
|
||||
{
|
||||
ui::Button::OnMouseClick(x, y, button);
|
||||
rightDown = false;
|
||||
leftDown = false;
|
||||
if(x >= splitPosition)
|
||||
if(x - Position.X >= splitPosition)
|
||||
rightDown = true;
|
||||
else if(x < splitPosition)
|
||||
else if(x - Position.X < splitPosition)
|
||||
leftDown = true;
|
||||
}
|
||||
}
|
||||
void DoRightAction()
|
||||
{
|
||||
if(!Enabled)
|
||||
|
@ -16,12 +16,15 @@ ToolButton::ToolButton(ui::Point position, ui::Point size, String text, ByteStri
|
||||
Component::TextPosition(buttonDisplayText);
|
||||
}
|
||||
|
||||
void ToolButton::OnMouseClick(int x, int y, unsigned int button)
|
||||
void ToolButton::OnMouseDown(int x, int y, unsigned int button)
|
||||
{
|
||||
if (MouseDownInside)
|
||||
{
|
||||
isButtonDown = true;
|
||||
}
|
||||
}
|
||||
|
||||
void ToolButton::OnMouseUnclick(int x, int y, unsigned int button)
|
||||
void ToolButton::OnMouseClick(int x, int y, unsigned int button)
|
||||
{
|
||||
if(isButtonDown)
|
||||
{
|
||||
|
@ -9,7 +9,7 @@ class ToolButton: public ui::Button
|
||||
ByteString toolIdentifier;
|
||||
public:
|
||||
ToolButton(ui::Point position, ui::Point size, String text, ByteString toolIdentifier, String toolTip = String());
|
||||
void OnMouseUnclick(int x, int y, unsigned int button) override;
|
||||
void OnMouseDown(int x, int y, unsigned int button) override;
|
||||
void OnMouseUp(int x, int y, unsigned int button) override;
|
||||
void OnMouseClick(int x, int y, unsigned int button) override;
|
||||
void Draw(const ui::Point& screenPos) override;
|
||||
|
@ -51,7 +51,7 @@ void AvatarButton::Draw(const Point& screenPos)
|
||||
}
|
||||
}
|
||||
|
||||
void AvatarButton::OnMouseUnclick(int x, int y, unsigned int button)
|
||||
void AvatarButton::OnMouseClick(int x, int y, unsigned int button)
|
||||
{
|
||||
if(button != 1)
|
||||
{
|
||||
@ -70,18 +70,21 @@ void AvatarButton::OnContextMenuAction(int item)
|
||||
//Do nothing
|
||||
}
|
||||
|
||||
void AvatarButton::OnMouseClick(int x, int y, unsigned int button)
|
||||
void AvatarButton::OnMouseDown(int x, int y, unsigned int button)
|
||||
{
|
||||
if (MouseDownInside)
|
||||
{
|
||||
if(button == SDL_BUTTON_RIGHT)
|
||||
{
|
||||
if(menu)
|
||||
menu->Show(GetScreenPos() + ui::Point(x, y));
|
||||
menu->Show(GetContainerPos() + ui::Point(x, y));
|
||||
}
|
||||
else
|
||||
{
|
||||
isButtonDown = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AvatarButton::OnMouseEnter(int x, int y)
|
||||
{
|
||||
|
@ -30,7 +30,7 @@ public:
|
||||
virtual ~AvatarButton() = default;
|
||||
|
||||
void OnMouseClick(int x, int y, unsigned int button) override;
|
||||
void OnMouseUnclick(int x, int y, unsigned int button) override;
|
||||
void OnMouseDown(int x, int y, unsigned int button) override;
|
||||
|
||||
void OnMouseEnter(int x, int y) override;
|
||||
void OnMouseLeave(int x, int y) override;
|
||||
|
@ -86,7 +86,7 @@ void Button::Draw(const Point& screenPos)
|
||||
|
||||
if (Enabled)
|
||||
{
|
||||
if (isButtonDown || (isTogglable && toggle))
|
||||
if ((isButtonDown && MouseDownInside) || (isTogglable && toggle))
|
||||
{
|
||||
textColour = Appearance.TextActive;
|
||||
borderColour = Appearance.BorderActive;
|
||||
@ -140,7 +140,7 @@ void Button::Draw(const Point& screenPos)
|
||||
}
|
||||
}
|
||||
|
||||
void Button::OnMouseUnclick(int x, int y, unsigned int button)
|
||||
void Button::OnMouseClick(int x, int y, unsigned int button)
|
||||
{
|
||||
if(button == 1)
|
||||
{
|
||||
@ -171,7 +171,9 @@ void Button::OnMouseUp(int x, int y, unsigned int button)
|
||||
isAltButtonDown = false;
|
||||
}
|
||||
|
||||
void Button::OnMouseClick(int x, int y, unsigned int button)
|
||||
void Button::OnMouseDown(int x, int y, unsigned int button)
|
||||
{
|
||||
if (MouseDownInside)
|
||||
{
|
||||
if(!Enabled)
|
||||
return;
|
||||
@ -184,6 +186,7 @@ void Button::OnMouseClick(int x, int y, unsigned int button)
|
||||
isAltButtonDown = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Button::OnMouseEnter(int x, int y)
|
||||
{
|
||||
|
@ -18,7 +18,7 @@ public:
|
||||
virtual ~Button() = default;
|
||||
|
||||
void OnMouseClick(int x, int y, unsigned int button) override;
|
||||
void OnMouseUnclick(int x, int y, unsigned int button) override;
|
||||
void OnMouseDown(int x, int y, unsigned int button) override;
|
||||
void OnMouseUp(int x, int y, unsigned int button) override;
|
||||
|
||||
void OnMouseEnter(int x, int y) override;
|
||||
|
@ -124,17 +124,21 @@ void Component::SetParent(Panel* new_parent)
|
||||
this->_parent = new_parent;
|
||||
}
|
||||
|
||||
Point Component::GetScreenPos()
|
||||
Point Component::GetContainerPos()
|
||||
{
|
||||
Point newPos(0,0);
|
||||
if(GetParentWindow())
|
||||
newPos += GetParentWindow()->Position;
|
||||
if(GetParent())
|
||||
newPos += GetParent()->Position + GetParent()->ViewportPosition;
|
||||
newPos += Position;
|
||||
return newPos;
|
||||
}
|
||||
|
||||
Point Component::GetScreenPos()
|
||||
{
|
||||
return GetContainerPos() + Position;
|
||||
}
|
||||
|
||||
Graphics * Component::GetGraphics()
|
||||
{
|
||||
return parentstate_->GetGraphics();
|
||||
@ -201,10 +205,6 @@ void Component::OnMouseLeave(int localx, int localy)
|
||||
{
|
||||
}
|
||||
|
||||
void Component::OnMouseUnclick(int localx, int localy, unsigned button)
|
||||
{
|
||||
}
|
||||
|
||||
void Component::OnMouseUp(int x, int y, unsigned button)
|
||||
{
|
||||
}
|
||||
|
@ -43,6 +43,7 @@ namespace ui
|
||||
bool Enabled;
|
||||
bool Visible;
|
||||
bool DoesTextInput;
|
||||
bool MouseDownInside;
|
||||
|
||||
ui::Appearance Appearance;
|
||||
//virtual void SetAppearance(ui::Appearance);
|
||||
@ -51,6 +52,7 @@ namespace ui
|
||||
|
||||
void Refresh();
|
||||
|
||||
Point GetContainerPos();
|
||||
Point GetScreenPos();
|
||||
|
||||
/* See the parent of this component.
|
||||
@ -146,7 +148,7 @@ namespace ui
|
||||
virtual void OnMouseUp(int x, int y, unsigned button);
|
||||
|
||||
///
|
||||
// Called: When a mouse button is pressed on top of the item.
|
||||
// Called: When a mouse button is pressed and then released on top of the item.
|
||||
// Params:
|
||||
// x: X position of the mouse.
|
||||
// y: Y position of the mouse.
|
||||
@ -154,15 +156,6 @@ namespace ui
|
||||
///
|
||||
virtual void OnMouseClick(int localx, int localy, unsigned button);
|
||||
|
||||
///
|
||||
// Called: When a mouse button is released on top of the item.
|
||||
// Params:
|
||||
// x: X position of the mouse.
|
||||
// y: Y position of the mouse.
|
||||
// button: The button that is being released.
|
||||
///
|
||||
virtual void OnMouseUnclick(int localx, int localy, unsigned button);
|
||||
|
||||
///
|
||||
// Called: When the mouse wheel moves/changes.
|
||||
// Params:
|
||||
|
@ -142,11 +142,14 @@ void DirectionSelector::OnMouseMoved(int x, int y, int dx, int dy)
|
||||
CheckHovering(x, y);
|
||||
}
|
||||
|
||||
void DirectionSelector::OnMouseClick(int x, int y, unsigned button)
|
||||
void DirectionSelector::OnMouseDown(int x, int y, unsigned button)
|
||||
{
|
||||
if (MouseDownInside)
|
||||
{
|
||||
mouseDown = true;
|
||||
SetPositionAbs({ x, y });
|
||||
CheckHovering(x, y);
|
||||
SetPositionAbs({ x - Position.X, y - Position.Y });
|
||||
CheckHovering(x - Position.X, y - Position.Y);
|
||||
}
|
||||
}
|
||||
|
||||
void DirectionSelector::OnMouseUp(int x, int y, unsigned button)
|
||||
|
@ -79,7 +79,7 @@ public:
|
||||
|
||||
void Draw(const ui::Point& screenPos) override;
|
||||
void OnMouseMoved(int x, int y, int dx, int dy) override;
|
||||
void OnMouseClick(int x, int y, unsigned int button) override;
|
||||
void OnMouseDown(int x, int y, unsigned int button) override;
|
||||
void OnMouseUp(int x, int y, unsigned button) override;
|
||||
inline void OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) override { altDown = alt; }
|
||||
inline void OnKeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) override { altDown = alt; }
|
||||
|
@ -268,14 +268,14 @@ void Engine::onTextEditing(String text, int start)
|
||||
}
|
||||
}
|
||||
|
||||
void Engine::onMouseClick(int x, int y, unsigned button)
|
||||
void Engine::onMouseDown(int x, int y, unsigned button)
|
||||
{
|
||||
mouseb_ |= button;
|
||||
if (state_ && !ignoreEvents)
|
||||
state_->DoMouseDown(x, y, button);
|
||||
}
|
||||
|
||||
void Engine::onMouseUnclick(int x, int y, unsigned button)
|
||||
void Engine::onMouseUp(int x, int y, unsigned button)
|
||||
{
|
||||
mouseb_ &= ~button;
|
||||
if (state_ && !ignoreEvents)
|
||||
|
@ -30,8 +30,8 @@ namespace ui
|
||||
|
||||
void initialMouse(int x, int y);
|
||||
void onMouseMove(int x, int y);
|
||||
void onMouseClick(int x, int y, unsigned button);
|
||||
void onMouseUnclick(int x, int y, unsigned button);
|
||||
void onMouseDown(int x, int y, unsigned button);
|
||||
void onMouseUp(int x, int y, unsigned button);
|
||||
void onMouseWheel(int x, int y, int delta);
|
||||
void onKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt);
|
||||
void onKeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt);
|
||||
|
@ -88,26 +88,29 @@ void Label::OnContextMenuAction(int item)
|
||||
}
|
||||
}
|
||||
|
||||
void Label::OnMouseClick(int x, int y, unsigned button)
|
||||
void Label::OnMouseDown(int x, int y, unsigned button)
|
||||
{
|
||||
if (MouseDownInside)
|
||||
{
|
||||
if(button == SDL_BUTTON_RIGHT)
|
||||
{
|
||||
if (menu)
|
||||
{
|
||||
menu->Show(GetScreenPos() + ui::Point(x, y));
|
||||
menu->Show(GetContainerPos() + ui::Point(x, y));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
selecting = true;
|
||||
auto tp = textPosition - Vec2{ scrollX, 0 };
|
||||
selectionIndex0 = textWrapper.Point2Index(x - tp.X, y - tp.Y);
|
||||
selectionIndex0 = textWrapper.Point2Index(x - Position.X - tp.X, y - Position.Y - tp.Y);
|
||||
selectionIndexL = selectionIndex0;
|
||||
selectionIndexH = selectionIndex0;
|
||||
|
||||
updateSelection();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Label::copySelection()
|
||||
{
|
||||
|
@ -58,7 +58,7 @@ namespace ui
|
||||
void SetTextColour(Colour textColour) { this->textColour = textColour; }
|
||||
|
||||
void OnContextMenuAction(int item) override;
|
||||
virtual void OnMouseClick(int x, int y, unsigned button) override;
|
||||
virtual void OnMouseDown(int x, int y, unsigned button) override;
|
||||
void OnMouseUp(int x, int y, unsigned button) override;
|
||||
void OnMouseMoved(int localx, int localy, int dx, int dy) override;
|
||||
void OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) override;
|
||||
|
@ -27,6 +27,7 @@ void Panel::AddChild(Component* c)
|
||||
{
|
||||
c->SetParent(this);
|
||||
c->SetParentWindow(this->GetParentWindow());
|
||||
c->MouseDownInside = false;
|
||||
}
|
||||
|
||||
int Panel::GetChildCount()
|
||||
@ -108,8 +109,13 @@ void Panel::OnKeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl,
|
||||
|
||||
void Panel::OnMouseClick(int localx, int localy, unsigned button)
|
||||
{
|
||||
bool childclicked = false;
|
||||
XOnMouseClick(localx, localy, 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)
|
||||
{
|
||||
@ -122,29 +128,18 @@ void Panel::OnMouseClick(int localx, int localy, unsigned button)
|
||||
localx < children[i]->Position.X + ViewportPosition.X + children[i]->Size.X &&
|
||||
localy < children[i]->Position.Y + ViewportPosition.Y + children[i]->Size.Y )
|
||||
{
|
||||
childclicked = true;
|
||||
GetParentWindow()->FocusComponent(children[i]);
|
||||
children[i]->OnMouseClick(localx - children[i]->Position.X - ViewportPosition.X, localy - children[i]->Position.Y - ViewportPosition.Y, button);
|
||||
children[i]->MouseDownInside = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//if a child wasn't clicked, send click to ourself
|
||||
if(!childclicked)
|
||||
{
|
||||
XOnMouseClick(localx, localy, button);
|
||||
GetParentWindow()->FocusComponent(this);
|
||||
}
|
||||
}
|
||||
|
||||
void Panel::OnMouseDown(int x, int y, unsigned button)
|
||||
{
|
||||
XOnMouseDown(x, y, button);
|
||||
for (size_t i = 0; i < children.size(); ++i)
|
||||
{
|
||||
if(children[i]->Enabled)
|
||||
children[i]->OnMouseDown(x, y, button);
|
||||
children[i]->OnMouseDown(x - Position.X - ViewportPosition.X, y - Position.Y - ViewportPosition.Y, button);
|
||||
}
|
||||
}
|
||||
|
||||
@ -239,43 +234,38 @@ void Panel::OnMouseLeave(int localx, int localy)
|
||||
XOnMouseLeave(localx, localy);
|
||||
}
|
||||
|
||||
void Panel::OnMouseUnclick(int localx, int localy, unsigned button)
|
||||
void Panel::OnMouseUp(int x, int y, unsigned button)
|
||||
{
|
||||
bool childunclicked = false;
|
||||
|
||||
auto localx = x - Position.X;
|
||||
auto localy = y - Position.Y;
|
||||
//check if clicked a child
|
||||
for(int i = children.size()-1; i >= 0 ; --i)
|
||||
{
|
||||
//child must be unlocked
|
||||
//child must be enabled
|
||||
if(children[i]->Enabled)
|
||||
{
|
||||
//is mouse inside?
|
||||
if( localx >= children[i]->Position.X + ViewportPosition.X &&
|
||||
if( children[i]->MouseDownInside &&
|
||||
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 )
|
||||
{
|
||||
childunclicked = true;
|
||||
children[i]->OnMouseUnclick(localx - children[i]->Position.X - ViewportPosition.X, localy - children[i]->Position.Y - ViewportPosition.Y, button);
|
||||
children[i]->OnMouseClick(localx - children[i]->Position.X - ViewportPosition.X, localy - children[i]->Position.Y - ViewportPosition.Y, button);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//if a child wasn't clicked, send click to ourself
|
||||
if (!childunclicked)
|
||||
for (auto *child : children)
|
||||
{
|
||||
XOnMouseUnclick(localx, localy, button);
|
||||
}
|
||||
child->MouseDownInside = false;
|
||||
}
|
||||
|
||||
void Panel::OnMouseUp(int x, int y, unsigned button)
|
||||
{
|
||||
XOnMouseUp(x, y, button);
|
||||
for (size_t i = 0; i < children.size(); ++i)
|
||||
{
|
||||
if (children[i]->Enabled)
|
||||
children[i]->OnMouseUp(x, y, button);
|
||||
children[i]->OnMouseUp(x - Position.X - ViewportPosition.X, y - Position.Y - ViewportPosition.Y, button);
|
||||
}
|
||||
}
|
||||
|
||||
@ -358,10 +348,6 @@ void Panel::XOnMouseLeave(int localx, int localy)
|
||||
{
|
||||
}
|
||||
|
||||
void Panel::XOnMouseUnclick(int localx, int localy, unsigned button)
|
||||
{
|
||||
}
|
||||
|
||||
void Panel::XOnMouseUp(int x, int y, unsigned button)
|
||||
{
|
||||
}
|
||||
|
@ -58,7 +58,6 @@ namespace ui
|
||||
void OnMouseDown(int x, int y, unsigned button) override;
|
||||
void OnMouseUp(int x, int y, unsigned button) override;
|
||||
void OnMouseClick(int localx, int localy, unsigned button) override;
|
||||
void OnMouseUnclick(int localx, int localy, unsigned button) override;
|
||||
void OnMouseWheel(int localx, int localy, int d) override;
|
||||
void OnMouseWheelInside(int localx, int localy, int d) override;
|
||||
void OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) override;
|
||||
@ -100,9 +99,6 @@ namespace ui
|
||||
// Overridable. Called by XComponent::OnMouseClick()
|
||||
virtual void XOnMouseClick(int localx, int localy, unsigned button);
|
||||
|
||||
// Overridable. Called by XComponent::OnMouseUnclick()
|
||||
virtual void XOnMouseUnclick(int localx, int localy, unsigned button);
|
||||
|
||||
// Overridable. Called by XComponent::OnMouseWheel()
|
||||
virtual void XOnMouseWheel(int localx, int localy, int d);
|
||||
|
||||
|
@ -64,9 +64,11 @@ void RichLabel::SetText(String newText)
|
||||
regions = newRegions;
|
||||
}
|
||||
|
||||
void RichLabel::OnMouseClick(int x, int y, unsigned button)
|
||||
void RichLabel::OnMouseDown(int x, int y, unsigned button)
|
||||
{
|
||||
int cursorPosition = displayTextWrapper.Point2Index(x - textPosition.X, y - textPosition.Y).raw_index;
|
||||
if (MouseDownInside)
|
||||
{
|
||||
int cursorPosition = displayTextWrapper.Point2Index(x - Position.X - textPosition.X, y - Position.Y - textPosition.Y).raw_index;
|
||||
for (auto const ®ion : regions)
|
||||
{
|
||||
if (region.begin <= cursorPosition && region.end > cursorPosition)
|
||||
@ -78,5 +80,6 @@ void RichLabel::OnMouseClick(int x, int y, unsigned button)
|
||||
}
|
||||
}
|
||||
}
|
||||
Label::OnMouseClick(x, y, button);
|
||||
}
|
||||
Label::OnMouseDown(x, y, button);
|
||||
}
|
||||
|
@ -24,6 +24,6 @@ namespace ui
|
||||
RichLabel(Point position, Point size, String text);
|
||||
|
||||
void SetText(String newText) override;
|
||||
void OnMouseClick(int x, int y, unsigned button) override;
|
||||
void OnMouseDown(int x, int y, unsigned button) override;
|
||||
};
|
||||
}
|
||||
|
@ -262,7 +262,7 @@ void SaveButton::Draw(const Point& screenPos)
|
||||
}
|
||||
}
|
||||
|
||||
void SaveButton::OnMouseUnclick(int x, int y, unsigned int button)
|
||||
void SaveButton::OnMouseClick(int x, int y, unsigned int button)
|
||||
{
|
||||
if(button != 1)
|
||||
{
|
||||
@ -333,12 +333,14 @@ void SaveButton::OnContextMenuAction(int item)
|
||||
}
|
||||
}
|
||||
|
||||
void SaveButton::OnMouseClick(int x, int y, unsigned int button)
|
||||
void SaveButton::OnMouseDown(int x, int y, unsigned int button)
|
||||
{
|
||||
if (MouseDownInside)
|
||||
{
|
||||
if(button == SDL_BUTTON_RIGHT)
|
||||
{
|
||||
if(menu)
|
||||
menu->Show(GetScreenPos() + ui::Point(x, y));
|
||||
menu->Show(GetContainerPos() + ui::Point(x, y));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -351,6 +353,7 @@ void SaveButton::OnMouseClick(int x, int y, unsigned int button)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SaveButton::OnMouseMovedInside(int x, int y, int dx, int dy)
|
||||
{
|
||||
|
@ -48,7 +48,7 @@ public:
|
||||
virtual ~SaveButton();
|
||||
|
||||
void OnMouseClick(int x, int y, unsigned int button) override;
|
||||
void OnMouseUnclick(int x, int y, unsigned int button) override;
|
||||
void OnMouseDown(int x, int y, unsigned int button) override;
|
||||
|
||||
void OnMouseEnter(int x, int y) override;
|
||||
void OnMouseLeave(int x, int y) override;
|
||||
|
@ -70,16 +70,19 @@ void ScrollPanel::Draw(const Point& screenPos)
|
||||
}
|
||||
}
|
||||
|
||||
void ScrollPanel::XOnMouseClick(int x, int y, unsigned int button)
|
||||
void ScrollPanel::XOnMouseDown(int x, int y, unsigned int button)
|
||||
{
|
||||
if (MouseDownInside)
|
||||
{
|
||||
if (isMouseInsideScrollbar)
|
||||
{
|
||||
scrollbarSelected = true;
|
||||
scrollbarInitialYOffset = int(offsetY);
|
||||
}
|
||||
scrollbarInitialYClick = y;
|
||||
scrollbarInitialYClick = y - Position.Y;
|
||||
scrollbarClickLocation = 100;
|
||||
}
|
||||
}
|
||||
|
||||
void ScrollPanel::XOnMouseUp(int x, int y, unsigned int button)
|
||||
{
|
||||
|
@ -28,7 +28,7 @@ namespace ui
|
||||
void Draw(const Point& screenPos) override;
|
||||
void XTick(float dt) override;
|
||||
void XOnMouseWheelInside(int localx, int localy, int d) override;
|
||||
void XOnMouseClick(int localx, int localy, unsigned int button) override;
|
||||
void XOnMouseDown(int localx, int localy, unsigned int button) override;
|
||||
void XOnMouseUp(int x, int y, unsigned int button) override;
|
||||
void XOnMouseMoved(int localx, int localy, int dx, int dy) override;
|
||||
};
|
||||
|
@ -48,10 +48,10 @@ void Slider::OnMouseMoved(int x, int y, int dx, int dy)
|
||||
}
|
||||
}
|
||||
|
||||
void Slider::OnMouseClick(int x, int y, unsigned button)
|
||||
void Slider::OnMouseDown(int x, int y, unsigned button)
|
||||
{
|
||||
isMouseDown = true;
|
||||
updatePosition(x);
|
||||
updatePosition(x - Position.X);
|
||||
}
|
||||
|
||||
void Slider::OnMouseUp(int x, int y, unsigned button)
|
||||
|
@ -25,7 +25,7 @@ public:
|
||||
virtual ~Slider() = default;
|
||||
|
||||
void OnMouseMoved(int x, int y, int dx, int dy) override;
|
||||
void OnMouseClick(int x, int y, unsigned button) override;
|
||||
void OnMouseDown(int x, int y, unsigned button) override;
|
||||
void OnMouseUp(int x, int y, unsigned button) override;
|
||||
void Draw(const Point& screenPos) override;
|
||||
void SetColour(Colour col1, Colour col2);
|
||||
|
@ -569,18 +569,21 @@ void Textbox::OnTextEditing(String text)
|
||||
updateSelection();
|
||||
}
|
||||
|
||||
void Textbox::OnMouseClick(int x, int y, unsigned button)
|
||||
void Textbox::OnMouseDown(int x, int y, unsigned button)
|
||||
{
|
||||
if (MouseDownInside)
|
||||
{
|
||||
if (button != SDL_BUTTON_RIGHT)
|
||||
{
|
||||
StopTextEditing();
|
||||
mouseDown = true;
|
||||
auto tp = textPosition - Vec2{ scrollX, 0 };
|
||||
auto index = textWrapper.Point2Index(x-tp.X, y-tp.Y);
|
||||
auto index = textWrapper.Point2Index(x-Position.X-tp.X, y-Position.Y-tp.Y);
|
||||
cursor = index.raw_index;
|
||||
resetCursorPosition();
|
||||
}
|
||||
Label::OnMouseClick(x, y, button);
|
||||
}
|
||||
Label::OnMouseDown(x, y, button);
|
||||
}
|
||||
|
||||
void Textbox::OnMouseUp(int x, int y, unsigned button)
|
||||
|
@ -53,7 +53,7 @@ public:
|
||||
|
||||
void Tick(float dt) override;
|
||||
void OnContextMenuAction(int item) override;
|
||||
void OnMouseClick(int x, int y, unsigned button) override;
|
||||
void OnMouseDown(int x, int y, unsigned button) override;
|
||||
void OnMouseUp(int x, int y, unsigned button) override;
|
||||
void OnMouseMoved(int localx, int localy, int dx, int dy) override;
|
||||
void OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) override;
|
||||
|
@ -43,6 +43,7 @@ void Window::AddComponent(Component* c)
|
||||
if (c->GetParentWindow() == NULL)
|
||||
{
|
||||
c->SetParentWindow(this);
|
||||
c->MouseDownInside = false;
|
||||
Components.push_back(c);
|
||||
|
||||
if (Engine::Ref().GetMouseX() > Position.X + c->Position.X && Engine::Ref().GetMouseX() < Position.X + c->Position.X + c->Size.X &&
|
||||
@ -440,7 +441,7 @@ void Window::DoMouseDown(int x_, int y_, unsigned button)
|
||||
FocusComponent(Components[i]);
|
||||
if (!DEBUG || !debugMode)
|
||||
{
|
||||
Components[i]->OnMouseClick(x - Components[i]->Position.X, y - Components[i]->Position.Y, button);
|
||||
Components[i]->MouseDownInside = true;
|
||||
}
|
||||
clickState = true;
|
||||
break;
|
||||
@ -537,13 +538,17 @@ void Window::DoMouseUp(int x_, int y_, unsigned button)
|
||||
{
|
||||
if (Components[i]->Enabled && Components[i]->Visible)
|
||||
{
|
||||
if (x >= Components[i]->Position.X && y >= Components[i]->Position.Y && x < Components[i]->Position.X + Components[i]->Size.X && y < Components[i]->Position.Y + Components[i]->Size.Y)
|
||||
if (Components[i]->MouseDownInside && x >= Components[i]->Position.X && y >= Components[i]->Position.Y && x < Components[i]->Position.X + Components[i]->Size.X && y < Components[i]->Position.Y + Components[i]->Size.Y)
|
||||
{
|
||||
Components[i]->OnMouseUnclick(x - Components[i]->Position.X, y - Components[i]->Position.Y, button);
|
||||
Components[i]->OnMouseClick(x - Components[i]->Position.X, y - Components[i]->Position.Y, button);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (auto *component : Components)
|
||||
{
|
||||
component->MouseDownInside = false;
|
||||
}
|
||||
|
||||
//on mouse up
|
||||
for (int i = Components.size() - 1; i >= 0 && !halt; --i)
|
||||
|
Loading…
Reference in New Issue
Block a user