mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-11 10:54:15 +02:00
Fix OnMouseEnter/Leave inside Panels
Also remove OnMouseMovedInside and the dx and dy parameters of OnMouseMoved because nothing used these for anything.
This commit is contained in:
@@ -1055,10 +1055,17 @@ void GameView::updateToolButtonScroll()
|
|||||||
{
|
{
|
||||||
for (auto *button : toolButtons)
|
for (auto *button : toolButtons)
|
||||||
{
|
{
|
||||||
if (button->Position.X < x && button->Position.X + button->Size.X > x)
|
auto inside = button->Position.X < x && button->Position.X + button->Size.X > x;
|
||||||
|
if (inside && !button->MouseInside)
|
||||||
|
{
|
||||||
|
button->MouseInside = true;
|
||||||
button->OnMouseEnter(x, y);
|
button->OnMouseEnter(x, y);
|
||||||
else
|
}
|
||||||
|
if (!inside && button->MouseInside)
|
||||||
|
{
|
||||||
|
button->MouseInside = false;
|
||||||
button->OnMouseLeave(x, y);
|
button->OnMouseLeave(x, y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -189,11 +189,7 @@ void Component::OnMouseHover(int localx, int localy)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void Component::OnMouseMoved(int localx, int localy, int dx, int dy)
|
void Component::OnMouseMoved(int localx, int localy)
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void Component::OnMouseMovedInside(int localx, int localy, int dx, int dy)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -43,6 +43,7 @@ namespace ui
|
|||||||
bool Enabled;
|
bool Enabled;
|
||||||
bool Visible;
|
bool Visible;
|
||||||
bool DoesTextInput;
|
bool DoesTextInput;
|
||||||
|
bool MouseInside;
|
||||||
bool MouseDownInside;
|
bool MouseDownInside;
|
||||||
|
|
||||||
ui::Appearance Appearance;
|
ui::Appearance Appearance;
|
||||||
@@ -96,20 +97,8 @@ namespace ui
|
|||||||
// Params:
|
// Params:
|
||||||
// localx: Local mouse X position.
|
// localx: Local mouse X position.
|
||||||
// localy: Local mouse Y position.
|
// localy: Local mouse Y position.
|
||||||
// dx: Mouse X delta.
|
|
||||||
// dy: Mouse Y delta.
|
|
||||||
///
|
///
|
||||||
virtual void OnMouseMoved(int localx, int localy, int dx, int dy);
|
virtual void OnMouseMoved(int localx, int localy);
|
||||||
|
|
||||||
///
|
|
||||||
// Called: When the mouse moves.
|
|
||||||
// Params:
|
|
||||||
// localx: Local mouse X position.
|
|
||||||
// localy: Local mouse Y position.
|
|
||||||
// dx: Mouse X delta.
|
|
||||||
// dy: Mouse Y delta.
|
|
||||||
///
|
|
||||||
virtual void OnMouseMovedInside(int localx, int localy, int dx, int dy);
|
|
||||||
|
|
||||||
///
|
///
|
||||||
// Called: When the mouse moves on top of the item.
|
// Called: When the mouse moves on top of the item.
|
||||||
|
@@ -133,7 +133,7 @@ void DirectionSelector::Draw(const ui::Point& screenPos)
|
|||||||
g->BlendEllipse(center + value.offset, { handleRadius, handleRadius }, borderColor);
|
g->BlendEllipse(center + value.offset, { handleRadius, handleRadius }, borderColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DirectionSelector::OnMouseMoved(int x, int y, int dx, int dy)
|
void DirectionSelector::OnMouseMoved(int x, int y)
|
||||||
{
|
{
|
||||||
if (mouseDown)
|
if (mouseDown)
|
||||||
{
|
{
|
||||||
|
@@ -78,7 +78,7 @@ public:
|
|||||||
void SetValues(float x, float y);
|
void SetValues(float x, float y);
|
||||||
|
|
||||||
void Draw(const ui::Point& screenPos) override;
|
void Draw(const ui::Point& screenPos) override;
|
||||||
void OnMouseMoved(int x, int y, int dx, int dy) override;
|
void OnMouseMoved(int x, int y) override;
|
||||||
void OnMouseDown(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;
|
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 OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) override { altDown = alt; }
|
||||||
|
@@ -146,7 +146,7 @@ void Label::OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Label::OnMouseMoved(int localx, int localy, int dx, int dy)
|
void Label::OnMouseMoved(int localx, int localy)
|
||||||
{
|
{
|
||||||
if (selecting)
|
if (selecting)
|
||||||
{
|
{
|
||||||
|
@@ -60,7 +60,7 @@ namespace ui
|
|||||||
void OnContextMenuAction(int item) override;
|
void OnContextMenuAction(int item) override;
|
||||||
virtual void OnMouseDown(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 OnMouseUp(int x, int y, unsigned button) override;
|
||||||
void OnMouseMoved(int localx, int localy, int dx, int dy) override;
|
void OnMouseMoved(int localx, int localy) override;
|
||||||
void OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) override;
|
void OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) override;
|
||||||
void Draw(const Point& screenPos) override;
|
void Draw(const Point& screenPos) override;
|
||||||
void Tick(float dt) override;
|
void Tick(float dt) override;
|
||||||
|
@@ -10,8 +10,7 @@ using namespace ui;
|
|||||||
Panel::Panel(Point position, Point size):
|
Panel::Panel(Point position, Point size):
|
||||||
Component(position, size),
|
Component(position, size),
|
||||||
InnerSize(size),
|
InnerSize(size),
|
||||||
ViewportPosition(0, 0),
|
ViewportPosition(0, 0)
|
||||||
mouseInside(false)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,6 +26,7 @@ void Panel::AddChild(Component* c)
|
|||||||
{
|
{
|
||||||
c->SetParent(this);
|
c->SetParent(this);
|
||||||
c->SetParentWindow(this->GetParentWindow());
|
c->SetParentWindow(this->GetParentWindow());
|
||||||
|
c->MouseInside = false;
|
||||||
c->MouseDownInside = false;
|
c->MouseDownInside = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,25 +165,26 @@ void Panel::OnMouseHover(int localx, int localy)
|
|||||||
XOnMouseHover(localx, localy);
|
XOnMouseHover(localx, localy);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Panel::OnMouseMoved(int localx, int localy, int dx, int dy)
|
void Panel::OnMouseMoved(int localx, int localy)
|
||||||
{
|
{
|
||||||
XOnMouseMoved(localx, localy, dx, dy);
|
PropagateMouseMove();
|
||||||
|
XOnMouseMoved(localx, localy);
|
||||||
for (size_t i = 0; i < children.size(); ++i)
|
for (size_t i = 0; i < children.size(); ++i)
|
||||||
{
|
{
|
||||||
if(children[i]->Enabled)
|
if(children[i]->Enabled)
|
||||||
children[i]->OnMouseMoved(localx - children[i]->Position.X - ViewportPosition.X, localy - children[i]->Position.Y - ViewportPosition.Y, dx, dy);
|
children[i]->OnMouseMoved(localx - children[i]->Position.X - ViewportPosition.X, localy - children[i]->Position.Y - ViewportPosition.Y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Panel::OnMouseMovedInside(int localx, int localy, int dx, int dy)
|
void Panel::PropagateMouseMove()
|
||||||
{
|
{
|
||||||
mouseInside = true;
|
auto localx = ui::Engine::Ref().GetMouseX() - GetScreenPos().X;
|
||||||
|
auto localy = ui::Engine::Ref().GetMouseY() - GetScreenPos().Y;
|
||||||
for (size_t i = 0; i < children.size(); ++i)
|
for (size_t i = 0; i < children.size(); ++i)
|
||||||
{
|
{
|
||||||
if (children[i]->Enabled)
|
if (children[i]->Enabled)
|
||||||
{
|
{
|
||||||
Point local (localx - children[i]->Position.X - ViewportPosition.X, localy - children[i]->Position.Y - ViewportPosition.Y)
|
Point local (localx - children[i]->Position.X - ViewportPosition.X, localy - children[i]->Position.Y - ViewportPosition.Y);
|
||||||
, prevlocal (local.X - dx, local.Y - dy);
|
|
||||||
|
|
||||||
// mouse currently inside?
|
// mouse currently inside?
|
||||||
if( local.X >= 0 &&
|
if( local.X >= 0 &&
|
||||||
@@ -191,14 +192,12 @@ void Panel::OnMouseMovedInside(int localx, int localy, int dx, int dy)
|
|||||||
local.X < children[i]->Size.X &&
|
local.X < children[i]->Size.X &&
|
||||||
local.Y < children[i]->Size.Y )
|
local.Y < children[i]->Size.Y )
|
||||||
{
|
{
|
||||||
children[i]->OnMouseMovedInside(localx - children[i]->Position.X - ViewportPosition.X, localy - children[i]->Position.Y - ViewportPosition.Y, dx, dy);
|
children[i]->OnMouseMoved(localx - children[i]->Position.X - ViewportPosition.X, localy - children[i]->Position.Y - ViewportPosition.Y);
|
||||||
|
|
||||||
// was the mouse outside?
|
// was the mouse outside?
|
||||||
if(!(prevlocal.X >= 0 &&
|
if (!children[i]->MouseInside)
|
||||||
prevlocal.Y >= 0 &&
|
|
||||||
prevlocal.X < children[i]->Size.X &&
|
|
||||||
prevlocal.Y < children[i]->Size.Y ) )
|
|
||||||
{
|
{
|
||||||
|
children[i]->MouseInside = true;
|
||||||
children[i]->OnMouseEnter(local.X, local.Y);
|
children[i]->OnMouseEnter(local.X, local.Y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -206,31 +205,24 @@ void Panel::OnMouseMovedInside(int localx, int localy, int dx, int dy)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// was the mouse inside?
|
// was the mouse inside?
|
||||||
if( prevlocal.X >= 0 &&
|
if (children[i]->MouseInside)
|
||||||
prevlocal.Y >= 0 &&
|
|
||||||
prevlocal.X < children[i]->Size.X &&
|
|
||||||
prevlocal.Y < children[i]->Size.Y )
|
|
||||||
{
|
{
|
||||||
|
children[i]->MouseInside = false;
|
||||||
children[i]->OnMouseLeave(local.X, local.Y);
|
children[i]->OnMouseLeave(local.X, local.Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// always allow hover on parent (?)
|
|
||||||
XOnMouseMovedInside(localx, localy, dx, dy);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Panel::OnMouseEnter(int localx, int localy)
|
void Panel::OnMouseEnter(int localx, int localy)
|
||||||
{
|
{
|
||||||
mouseInside = true;
|
|
||||||
XOnMouseEnter(localx, localy);
|
XOnMouseEnter(localx, localy);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Panel::OnMouseLeave(int localx, int localy)
|
void Panel::OnMouseLeave(int localx, int localy)
|
||||||
{
|
{
|
||||||
mouseInside = false;
|
|
||||||
XOnMouseLeave(localx, localy);
|
XOnMouseLeave(localx, localy);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -332,11 +324,7 @@ void Panel::XOnMouseHover(int localx, int localy)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void Panel::XOnMouseMoved(int localx, int localy, int dx, int dy)
|
void Panel::XOnMouseMoved(int localx, int localy)
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void Panel::XOnMouseMovedInside(int localx, int localy, int dx, int dy)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -51,8 +51,7 @@ namespace ui
|
|||||||
void Draw(const Point& screenPos) override;
|
void Draw(const Point& screenPos) override;
|
||||||
|
|
||||||
void OnMouseHover(int localx, int localy) override;
|
void OnMouseHover(int localx, int localy) override;
|
||||||
void OnMouseMoved(int localx, int localy, int dx, int dy) override;
|
void OnMouseMoved(int localx, int localy) override;
|
||||||
void OnMouseMovedInside(int localx, int localy, int dx, int dy) override;
|
|
||||||
void OnMouseEnter(int localx, int localy) override;
|
void OnMouseEnter(int localx, int localy) override;
|
||||||
void OnMouseLeave(int localx, int localy) override;
|
void OnMouseLeave(int localx, int localy) override;
|
||||||
void OnMouseDown(int x, int y, unsigned button) override;
|
void OnMouseDown(int x, int y, unsigned button) override;
|
||||||
@@ -66,7 +65,6 @@ namespace ui
|
|||||||
protected:
|
protected:
|
||||||
// child components
|
// child components
|
||||||
std::vector<ui::Component*> children;
|
std::vector<ui::Component*> children;
|
||||||
bool mouseInside;
|
|
||||||
|
|
||||||
// Overridable. Called by XComponent::Tick()
|
// Overridable. Called by XComponent::Tick()
|
||||||
virtual void XTick(float dt);
|
virtual void XTick(float dt);
|
||||||
@@ -79,10 +77,7 @@ namespace ui
|
|||||||
virtual void XOnMouseHover(int localx, int localy);
|
virtual void XOnMouseHover(int localx, int localy);
|
||||||
|
|
||||||
// Overridable. Called by XComponent::OnMouseMoved()
|
// Overridable. Called by XComponent::OnMouseMoved()
|
||||||
virtual void XOnMouseMoved(int localx, int localy, int dx, int dy);
|
virtual void XOnMouseMoved(int localx, int localy);
|
||||||
|
|
||||||
// Overridable. Called by XComponent::OnMouseMovedInside()
|
|
||||||
virtual void XOnMouseMovedInside(int localx, int localy, int dx, int dy);
|
|
||||||
|
|
||||||
// Overridable. Called by XComponent::OnMouseEnter()
|
// Overridable. Called by XComponent::OnMouseEnter()
|
||||||
virtual void XOnMouseEnter(int localx, int localy);
|
virtual void XOnMouseEnter(int localx, int localy);
|
||||||
@@ -110,6 +105,8 @@ namespace ui
|
|||||||
|
|
||||||
// Overridable. Called by XComponent::OnKeyRelease()
|
// Overridable. Called by XComponent::OnKeyRelease()
|
||||||
virtual void XOnKeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt);
|
virtual void XOnKeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt);
|
||||||
|
|
||||||
|
void PropagateMouseMove();
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -355,17 +355,18 @@ void SaveButton::OnMouseDown(int x, int y, unsigned int button)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SaveButton::OnMouseMovedInside(int x, int y, int dx, int dy)
|
void SaveButton::OnMouseMoved(int x, int y)
|
||||||
{
|
{
|
||||||
if(y > Size.Y-11)
|
isMouseInsideAuthor = false;
|
||||||
isMouseInsideAuthor = true;
|
isMouseInsideHistory = false;
|
||||||
else
|
if (MouseInside)
|
||||||
isMouseInsideAuthor = false;
|
{
|
||||||
|
if(y > Size.Y-11)
|
||||||
|
isMouseInsideAuthor = true;
|
||||||
|
|
||||||
if(showVotes && y > Size.Y-29 && y < Size.Y - 18 && x > 0 && x < 9)
|
if(showVotes && y > Size.Y-29 && y < Size.Y - 18 && x > 0 && x < 9)
|
||||||
isMouseInsideHistory = true;
|
isMouseInsideHistory = true;
|
||||||
else
|
}
|
||||||
isMouseInsideHistory = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SaveButton::OnMouseEnter(int x, int y)
|
void SaveButton::OnMouseEnter(int x, int y)
|
||||||
|
@@ -53,7 +53,7 @@ public:
|
|||||||
void OnMouseEnter(int x, int y) override;
|
void OnMouseEnter(int x, int y) override;
|
||||||
void OnMouseLeave(int x, int y) override;
|
void OnMouseLeave(int x, int y) override;
|
||||||
|
|
||||||
void OnMouseMovedInside(int x, int y, int dx, int dy) override;
|
void OnMouseMoved(int x, int y) override;
|
||||||
|
|
||||||
void AddContextMenu(int menuType);
|
void AddContextMenu(int menuType);
|
||||||
void OnContextMenuAction(int item) override;
|
void OnContextMenuAction(int item) override;
|
||||||
|
@@ -108,10 +108,11 @@ void ScrollPanel::XOnMouseUp(int x, int y, unsigned int button)
|
|||||||
scrollbarClickLocation = 0;
|
scrollbarClickLocation = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScrollPanel::XOnMouseMoved(int x, int y, int dx, int dy)
|
void ScrollPanel::XOnMouseMoved(int x, int y)
|
||||||
{
|
{
|
||||||
if(maxOffset.Y>0 && InnerSize.Y>0)
|
if(maxOffset.Y>0 && InnerSize.Y>0)
|
||||||
{
|
{
|
||||||
|
auto oldViewportPositionY = ViewportPosition.Y;
|
||||||
float scrollHeight = float(Size.Y)*(float(Size.Y)/float(InnerSize.Y));
|
float scrollHeight = float(Size.Y)*(float(Size.Y)/float(InnerSize.Y));
|
||||||
float scrollPos = 0;
|
float scrollPos = 0;
|
||||||
if (-ViewportPosition.Y>0)
|
if (-ViewportPosition.Y>0)
|
||||||
@@ -155,11 +156,18 @@ void ScrollPanel::XOnMouseMoved(int x, int y, int dx, int dy)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
isMouseInsideScrollbar = false;
|
isMouseInsideScrollbar = false;
|
||||||
|
|
||||||
|
if (oldViewportPositionY != ViewportPosition.Y)
|
||||||
|
{
|
||||||
|
PropagateMouseMove();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScrollPanel::XTick(float dt)
|
void ScrollPanel::XTick(float dt)
|
||||||
{
|
{
|
||||||
|
auto oldViewportPositionY = ViewportPosition.Y;
|
||||||
|
|
||||||
if (panning)
|
if (panning)
|
||||||
{
|
{
|
||||||
auto scrollY = initialOffsetY + scrollbarInitialYClick - (Engine::Ref().GetMouseY() - GetScreenPos().Y);
|
auto scrollY = initialOffsetY + scrollbarInitialYClick - (Engine::Ref().GetMouseY() - GetScreenPos().Y);
|
||||||
@@ -229,9 +237,9 @@ void ScrollPanel::XTick(float dt)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mouseInside && scrollBarWidth < 6)
|
if (MouseInside && scrollBarWidth < 6)
|
||||||
scrollBarWidth++;
|
scrollBarWidth++;
|
||||||
else if (!mouseInside && scrollBarWidth > 0 && !scrollbarSelected)
|
else if (!MouseInside && scrollBarWidth > 0 && !scrollbarSelected)
|
||||||
scrollBarWidth--;
|
scrollBarWidth--;
|
||||||
|
|
||||||
if (isMouseInsideScrollbarArea && scrollbarClickLocation && !scrollbarSelected)
|
if (isMouseInsideScrollbarArea && scrollbarClickLocation && !scrollbarSelected)
|
||||||
@@ -251,4 +259,9 @@ void ScrollPanel::XTick(float dt)
|
|||||||
offsetY += scrollbarClickLocation*scrollHeight/10;
|
offsetY += scrollbarClickLocation*scrollHeight/10;
|
||||||
ViewportPosition.Y -= int(scrollbarClickLocation*scrollHeight/10);
|
ViewportPosition.Y -= int(scrollbarClickLocation*scrollHeight/10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (oldViewportPositionY != ViewportPosition.Y)
|
||||||
|
{
|
||||||
|
PropagateMouseMove();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -41,6 +41,6 @@ namespace ui
|
|||||||
void XOnMouseWheelInside(int localx, int localy, int d) override;
|
void XOnMouseWheelInside(int localx, int localy, int d) override;
|
||||||
void XOnMouseDown(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 XOnMouseUp(int x, int y, unsigned int button) override;
|
||||||
void XOnMouseMoved(int localx, int localy, int dx, int dy) override;
|
void XOnMouseMoved(int localx, int localy) override;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@@ -40,7 +40,7 @@ void Slider::updatePosition(int position)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Slider::OnMouseMoved(int x, int y, int dx, int dy)
|
void Slider::OnMouseMoved(int x, int y)
|
||||||
{
|
{
|
||||||
if(isMouseDown)
|
if(isMouseDown)
|
||||||
{
|
{
|
||||||
|
@@ -24,7 +24,7 @@ public:
|
|||||||
Slider(Point position, Point size, int steps);
|
Slider(Point position, Point size, int steps);
|
||||||
virtual ~Slider() = default;
|
virtual ~Slider() = default;
|
||||||
|
|
||||||
void OnMouseMoved(int x, int y, int dx, int dy) override;
|
void OnMouseMoved(int x, int y) override;
|
||||||
void OnMouseDown(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 OnMouseUp(int x, int y, unsigned button) override;
|
||||||
void Draw(const Point& screenPos) override;
|
void Draw(const Point& screenPos) override;
|
||||||
|
@@ -592,7 +592,7 @@ void Textbox::OnMouseUp(int x, int y, unsigned button)
|
|||||||
Label::OnMouseUp(x, y, button);
|
Label::OnMouseUp(x, y, button);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Textbox::OnMouseMoved(int localx, int localy, int dx, int dy)
|
void Textbox::OnMouseMoved(int localx, int localy)
|
||||||
{
|
{
|
||||||
if(mouseDown)
|
if(mouseDown)
|
||||||
{
|
{
|
||||||
@@ -601,7 +601,7 @@ void Textbox::OnMouseMoved(int localx, int localy, int dx, int dy)
|
|||||||
cursor = index.raw_index;
|
cursor = index.raw_index;
|
||||||
resetCursorPosition();
|
resetCursorPosition();
|
||||||
}
|
}
|
||||||
Label::OnMouseMoved(localx, localy, dx, dy);
|
Label::OnMouseMoved(localx, localy);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Textbox::OnDefocus()
|
void Textbox::OnDefocus()
|
||||||
|
@@ -55,7 +55,7 @@ public:
|
|||||||
void OnContextMenuAction(int item) override;
|
void OnContextMenuAction(int item) override;
|
||||||
void OnMouseDown(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 OnMouseUp(int x, int y, unsigned button) override;
|
||||||
void OnMouseMoved(int localx, int localy, int dx, int dy) override;
|
void OnMouseMoved(int localx, int localy) override;
|
||||||
void OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) override;
|
void OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) override;
|
||||||
void OnVKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt);
|
void OnVKeyPress(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) override;
|
void OnKeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) override;
|
||||||
|
@@ -43,12 +43,16 @@ void Window::AddComponent(Component* c)
|
|||||||
if (c->GetParentWindow() == NULL)
|
if (c->GetParentWindow() == NULL)
|
||||||
{
|
{
|
||||||
c->SetParentWindow(this);
|
c->SetParentWindow(this);
|
||||||
|
c->MouseInside = false;
|
||||||
c->MouseDownInside = false;
|
c->MouseDownInside = false;
|
||||||
Components.push_back(c);
|
Components.push_back(c);
|
||||||
|
|
||||||
if (Engine::Ref().GetMouseX() > Position.X + c->Position.X && Engine::Ref().GetMouseX() < Position.X + c->Position.X + c->Size.X &&
|
if (Engine::Ref().GetMouseX() > Position.X + c->Position.X && Engine::Ref().GetMouseX() < Position.X + c->Position.X + c->Size.X &&
|
||||||
Engine::Ref().GetMouseY() > Position.Y + c->Position.Y && Engine::Ref().GetMouseY() < Position.Y + c->Position.Y + c->Size.Y)
|
Engine::Ref().GetMouseY() > Position.Y + c->Position.Y && Engine::Ref().GetMouseY() < Position.Y + c->Position.Y + c->Size.Y)
|
||||||
|
{
|
||||||
|
c->MouseInside = true;
|
||||||
c->OnMouseEnter(Engine::Ref().GetMouseX() - (Position.X + c->Position.X), Engine::Ref().GetMouseY() - (Position.Y + c->Position.Y));
|
c->OnMouseEnter(Engine::Ref().GetMouseX() - (Position.X + c->Position.X), Engine::Ref().GetMouseY() - (Position.Y + c->Position.Y));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -486,21 +490,17 @@ void Window::DoMouseMove(int x_, int y_, int dx, int dy)
|
|||||||
Point local(x - Components[i]->Position.X, y - Components[i]->Position.Y);
|
Point local(x - Components[i]->Position.X, y - Components[i]->Position.Y);
|
||||||
Point a(local.X - dx, local.Y - dy);
|
Point a(local.X - dx, local.Y - dy);
|
||||||
|
|
||||||
Components[i]->OnMouseMoved(local.X, local.Y, dx, dy);
|
Components[i]->OnMouseMoved(local.X, local.Y);
|
||||||
|
|
||||||
if (local.X >= 0 &&
|
if (local.X >= 0 &&
|
||||||
local.Y >= 0 &&
|
local.Y >= 0 &&
|
||||||
local.X < Components[i]->Size.X &&
|
local.X < Components[i]->Size.X &&
|
||||||
local.Y < Components[i]->Size.Y && !halt)
|
local.Y < Components[i]->Size.Y && !halt)
|
||||||
{
|
{
|
||||||
Components[i]->OnMouseMovedInside(local.X, local.Y, dx, dy);
|
|
||||||
|
|
||||||
// entering?
|
// entering?
|
||||||
if (!(a.X >= 0 &&
|
if (!Components[i]->MouseInside)
|
||||||
a.Y >= 0 &&
|
|
||||||
a.X < Components[i]->Size.X &&
|
|
||||||
a.Y < Components[i]->Size.Y ))
|
|
||||||
{
|
{
|
||||||
|
Components[i]->MouseInside = true;
|
||||||
Components[i]->OnMouseEnter(local.X, local.Y);
|
Components[i]->OnMouseEnter(local.X, local.Y);
|
||||||
}
|
}
|
||||||
if (Components[i]->Enabled)
|
if (Components[i]->Enabled)
|
||||||
@@ -509,11 +509,9 @@ void Window::DoMouseMove(int x_, int y_, int dx, int dy)
|
|||||||
else if (!halt)
|
else if (!halt)
|
||||||
{
|
{
|
||||||
// leaving?
|
// leaving?
|
||||||
if (a.X >= 0 &&
|
if (Components[i]->MouseInside)
|
||||||
a.Y >= 0 &&
|
|
||||||
a.X < Components[i]->Size.X &&
|
|
||||||
a.Y < Components[i]->Size.Y )
|
|
||||||
{
|
{
|
||||||
|
Components[i]->MouseInside = false;
|
||||||
Components[i]->OnMouseLeave(local.X, local.Y);
|
Components[i]->OnMouseLeave(local.X, local.Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user