mirror of
https://github.com/SerenityOS/serenity
synced 2024-09-06 08:56:40 +00:00
LibGUI: Switch to a resizing cursor when hovering or using a GSplitter.
Also expose the various standard cursors on WSWindowManager so they can be reused by the override mechanism.
This commit is contained in:
parent
94c68dc55a
commit
6673284b06
|
@ -14,6 +14,7 @@ public:
|
|||
RetainPtr(const T* ptr) : m_ptr(const_cast<T*>(ptr)) { retain_if_not_null(m_ptr); }
|
||||
RetainPtr(T* ptr) : m_ptr(ptr) { retain_if_not_null(m_ptr); }
|
||||
RetainPtr(T& object) : m_ptr(&object) { m_ptr->retain(); }
|
||||
RetainPtr(const T& object) : m_ptr(const_cast<T*>(&object)) { m_ptr->retain(); }
|
||||
RetainPtr(AdoptTag, T& object) : m_ptr(&object) { }
|
||||
RetainPtr(RetainPtr& other) : m_ptr(other.copy_ref().leak_ref()) { }
|
||||
RetainPtr(RetainPtr&& other) : m_ptr(other.leak_ref()) { }
|
||||
|
|
|
@ -35,6 +35,7 @@ class CONSUMABLE(unconsumed) Retained {
|
|||
public:
|
||||
enum AdoptTag { Adopt };
|
||||
|
||||
RETURN_TYPESTATE(unconsumed) Retained(const T& object) : m_ptr(&object) { m_ptr->retain(); }
|
||||
RETURN_TYPESTATE(unconsumed) Retained(T& object) : m_ptr(&object) { m_ptr->retain(); }
|
||||
template<typename U> RETURN_TYPESTATE(unconsumed) Retained(U& object) : m_ptr(&static_cast<T&>(object)) { m_ptr->retain(); }
|
||||
RETURN_TYPESTATE(unconsumed) Retained(AdoptTag, T& object) : m_ptr(&object) { }
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include <LibGUI/GSplitter.h>
|
||||
#include <LibGUI/GBoxLayout.h>
|
||||
#include <LibGUI/GWindow.h>
|
||||
|
||||
GSplitter::GSplitter(Orientation orientation, GWidget* parent)
|
||||
: GFrame(parent)
|
||||
|
@ -18,12 +19,15 @@ GSplitter::~GSplitter()
|
|||
void GSplitter::enter_event(GEvent&)
|
||||
{
|
||||
set_background_color(Color::from_rgb(0xd6d2ce));
|
||||
window()->set_override_cursor(m_orientation == Orientation::Horizontal ? GStandardCursor::ResizeHorizontal : GStandardCursor::ResizeVertical);
|
||||
update();
|
||||
}
|
||||
|
||||
void GSplitter::leave_event(GEvent&)
|
||||
{
|
||||
set_background_color(Color::LightGray);
|
||||
if (!m_resizing)
|
||||
window()->set_override_cursor(GStandardCursor::None);
|
||||
update();
|
||||
}
|
||||
|
||||
|
@ -108,4 +112,7 @@ void GSplitter::mouseup_event(GMouseEvent& event)
|
|||
if (event.button() != GMouseButton::Left)
|
||||
return;
|
||||
m_resizing = false;
|
||||
if (!rect().contains(event.position()))
|
||||
window()->set_override_cursor(GStandardCursor::None);
|
||||
|
||||
}
|
||||
|
|
|
@ -12,6 +12,8 @@ enum class GStandardCursor {
|
|||
None = 0,
|
||||
Arrow,
|
||||
IBeam,
|
||||
ResizeHorizontal,
|
||||
ResizeVertical,
|
||||
};
|
||||
|
||||
class GWindow : public GObject {
|
||||
|
|
|
@ -51,6 +51,8 @@ enum class WSAPI_StandardCursor : unsigned char {
|
|||
None = 0,
|
||||
Arrow,
|
||||
IBeam,
|
||||
ResizeHorizontal,
|
||||
ResizeVertical,
|
||||
};
|
||||
|
||||
struct WSAPI_ServerMessage {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include <WindowServer/WSCursor.h>
|
||||
#include <WindowServer/WSWindowManager.h>
|
||||
|
||||
WSCursor::WSCursor(Retained<GraphicsBitmap>&& bitmap, const Point& hotspot)
|
||||
: m_bitmap(move(bitmap))
|
||||
|
@ -26,9 +27,13 @@ RetainPtr<WSCursor> WSCursor::create(WSStandardCursor standard_cursor)
|
|||
case WSStandardCursor::None:
|
||||
return nullptr;
|
||||
case WSStandardCursor::Arrow:
|
||||
return create(*GraphicsBitmap::load_from_file("/res/cursors/arrow.png"));
|
||||
return WSWindowManager::the().arrow_cursor();
|
||||
case WSStandardCursor::IBeam:
|
||||
return create(*GraphicsBitmap::load_from_file("/res/cursors/i-beam.png"));
|
||||
return WSWindowManager::the().i_beam_cursor();
|
||||
case WSStandardCursor::ResizeHorizontal:
|
||||
return WSWindowManager::the().resize_horizontally_cursor();
|
||||
case WSStandardCursor::ResizeVertical:
|
||||
return WSWindowManager::the().resize_vertically_cursor();
|
||||
}
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@ enum class WSStandardCursor {
|
|||
None = 0,
|
||||
Arrow,
|
||||
IBeam,
|
||||
ResizeHorizontal,
|
||||
ResizeVertical,
|
||||
};
|
||||
|
||||
class WSCursor : public Retainable<WSCursor> {
|
||||
|
|
|
@ -87,6 +87,15 @@ public:
|
|||
const WSCursor& active_cursor() const;
|
||||
Rect current_cursor_rect() const;
|
||||
|
||||
const WSCursor& arrow_cursor() const { return *m_arrow_cursor; }
|
||||
const WSCursor& resize_horizontally_cursor() const { return *m_resize_horizontally_cursor; }
|
||||
const WSCursor& resize_vertically_cursor() const { return *m_resize_vertically_cursor; }
|
||||
const WSCursor& resize_diagonally_tlbr_cursor() const { return *m_resize_diagonally_tlbr_cursor; }
|
||||
const WSCursor& resize_diagonally_bltr_cursor() const { return *m_resize_diagonally_bltr_cursor; }
|
||||
const WSCursor& i_beam_cursor() const { return *m_i_beam_cursor; }
|
||||
const WSCursor& disallowed_cursor() const { return *m_disallowed_cursor; }
|
||||
const WSCursor& move_cursor() const { return *m_move_cursor; }
|
||||
|
||||
private:
|
||||
void process_mouse_event(const WSMouseEvent&, WSWindow*& event_window);
|
||||
bool process_ongoing_window_resize(const WSMouseEvent&, WSWindow*& event_window);
|
||||
|
|
Loading…
Reference in a new issue