serenity/LibGUI/GResizeCorner.cpp
Andreas Kling ea9a39a9f2 LibGUI+WindowServer: Add a GResizeCorner widget.
This widget is automatically included in GStatusBar, but can be added in
any other place, too. When clicked (with the left button), it initiates a
window resize (using a WM request.)

In this patch I also fixed up some issues with override cursors being
cleared after the WindowServer finishes a drag or resize.
2019-05-03 01:38:24 +02:00

46 lines
1.2 KiB
C++

#include <LibGUI/GResizeCorner.h>
#include <LibGUI/GPainter.h>
#include <LibGUI/GWindow.h>
#include <SharedGraphics/GraphicsBitmap.h>
#include <WindowServer/WSAPITypes.h>
GResizeCorner::GResizeCorner(GWidget* parent)
: GWidget(parent)
{
set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
set_preferred_size({ 16, 16 });
m_bitmap = GraphicsBitmap::load_from_file("/res/icons/resize-corner.png");
ASSERT(m_bitmap);
}
GResizeCorner::~GResizeCorner()
{
}
void GResizeCorner::paint_event(GPaintEvent& event)
{
GPainter painter(*this);
painter.add_clip_rect(event.rect());
painter.fill_rect(rect(), background_color());
painter.blit({ 0, 0 }, *m_bitmap, m_bitmap->rect());
GWidget::paint_event(event);
}
void GResizeCorner::mousedown_event(GMouseEvent& event)
{
if (event.button() == GMouseButton::Left)
window()->start_wm_resize();
GWidget::mousedown_event(event);
}
void GResizeCorner::enter_event(CEvent& event)
{
window()->set_override_cursor(GStandardCursor::ResizeDiagonalTLBR);
GWidget::enter_event(event);
}
void GResizeCorner::leave_event(CEvent& event)
{
window()->set_override_cursor(GStandardCursor::None);
GWidget::leave_event(event);
}