Compare commits
2 Commits
37731d2a95
...
653b2074c0
Author | SHA1 | Date | |
---|---|---|---|
653b2074c0 | |||
25cbaf4f90 |
@ -29,6 +29,14 @@ namespace ui
|
||||
*/
|
||||
Point normalize(Point point);
|
||||
|
||||
/**
|
||||
* @brief Transform an absolute position to a position relative to this rectangle.
|
||||
*
|
||||
* @param pos The original absolute position.
|
||||
* @return Point The position relative to this rectangle.
|
||||
*/
|
||||
Point relative(Point pos);
|
||||
|
||||
/**
|
||||
* @brief Return a copy of this rectangle with no negative values (normalized to 0).
|
||||
*
|
||||
|
@ -17,6 +17,14 @@ namespace ui
|
||||
return point;
|
||||
}
|
||||
|
||||
Point Rect::relative(Point point)
|
||||
{
|
||||
point = normalize(point);
|
||||
point.x -= pos.x;
|
||||
point.y -= pos.y;
|
||||
return point;
|
||||
}
|
||||
|
||||
Rect Rect::absolute()
|
||||
{
|
||||
return Rect { ui::Point { pos.x < 0 ? 0 : pos.x, pos.y < 0 ? 0 : pos.y }, width, height };
|
||||
|
@ -20,21 +20,7 @@ void Mouse::update(const moon::MousePacket& packet)
|
||||
m_position.y -= packet.ydelta;
|
||||
m_position = m_screen_rect.normalize(m_position);
|
||||
|
||||
if ((packet.buttons & moon::MouseButton::Left) && !m_dragging_window)
|
||||
{
|
||||
g_windows.for_each_reversed([this](Window* window) {
|
||||
if (!this->m_dragging_window && window->surface.contains(this->m_position))
|
||||
{
|
||||
this->m_dragging_window = window;
|
||||
this->m_initial_drag_position = ui::Point { this->m_position.x - window->surface.pos.x,
|
||||
this->m_position.y - window->surface.pos.y };
|
||||
os::println("Started drag: window at (%d,%d,%d,%d) with offset (%d,%d)", window->surface.pos.x,
|
||||
window->surface.pos.y, window->surface.width, window->surface.height,
|
||||
this->m_initial_drag_position.x, this->m_initial_drag_position.y);
|
||||
}
|
||||
});
|
||||
}
|
||||
else if (m_dragging_window && !(packet.buttons & moon::MouseButton::Left))
|
||||
if (m_dragging_window && !(packet.buttons & moon::MouseButton::Left))
|
||||
{
|
||||
os::println("Stopped drag: window at (%d,%d,%d,%d) with offset (%d,%d)", m_dragging_window->surface.pos.x,
|
||||
m_dragging_window->surface.pos.y, m_dragging_window->surface.width,
|
||||
@ -48,6 +34,21 @@ void Mouse::update(const moon::MousePacket& packet)
|
||||
m_dragging_window->surface.pos =
|
||||
ui::Point { m_position.x - m_initial_drag_position.x, m_position.y - m_initial_drag_position.y };
|
||||
m_dragging_window->surface = m_dragging_window->surface.absolute();
|
||||
m_dragging_window->focus();
|
||||
}
|
||||
|
||||
else if ((packet.buttons & moon::MouseButton::Left) && !m_dragging_window)
|
||||
{
|
||||
g_windows.for_each_reversed([this](Window* window) {
|
||||
if (!this->m_dragging_window && window->surface.contains(this->m_position))
|
||||
{
|
||||
this->m_dragging_window = window;
|
||||
this->m_initial_drag_position = ui::Point { this->m_position.x - window->surface.pos.x,
|
||||
this->m_position.y - window->surface.pos.y };
|
||||
os::println("Started drag: window at (%d,%d,%d,%d) with offset (%d,%d)", window->surface.pos.x,
|
||||
window->surface.pos.y, window->surface.width, window->surface.height,
|
||||
this->m_initial_drag_position.x, this->m_initial_drag_position.y);
|
||||
window->focus();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user