mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 03:37:43 +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
8 changed files with 31 additions and 2 deletions
|
@ -14,6 +14,7 @@ public:
|
||||||
RetainPtr(const T* ptr) : m_ptr(const_cast<T*>(ptr)) { retain_if_not_null(m_ptr); }
|
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* ptr) : m_ptr(ptr) { retain_if_not_null(m_ptr); }
|
||||||
RetainPtr(T& object) : m_ptr(&object) { m_ptr->retain(); }
|
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(AdoptTag, T& object) : m_ptr(&object) { }
|
||||||
RetainPtr(RetainPtr& other) : m_ptr(other.copy_ref().leak_ref()) { }
|
RetainPtr(RetainPtr& other) : m_ptr(other.copy_ref().leak_ref()) { }
|
||||||
RetainPtr(RetainPtr&& other) : m_ptr(other.leak_ref()) { }
|
RetainPtr(RetainPtr&& other) : m_ptr(other.leak_ref()) { }
|
||||||
|
|
|
@ -35,6 +35,7 @@ class CONSUMABLE(unconsumed) Retained {
|
||||||
public:
|
public:
|
||||||
enum AdoptTag { Adopt };
|
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(); }
|
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(); }
|
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) { }
|
RETURN_TYPESTATE(unconsumed) Retained(AdoptTag, T& object) : m_ptr(&object) { }
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include <LibGUI/GSplitter.h>
|
#include <LibGUI/GSplitter.h>
|
||||||
#include <LibGUI/GBoxLayout.h>
|
#include <LibGUI/GBoxLayout.h>
|
||||||
|
#include <LibGUI/GWindow.h>
|
||||||
|
|
||||||
GSplitter::GSplitter(Orientation orientation, GWidget* parent)
|
GSplitter::GSplitter(Orientation orientation, GWidget* parent)
|
||||||
: GFrame(parent)
|
: GFrame(parent)
|
||||||
|
@ -18,12 +19,15 @@ GSplitter::~GSplitter()
|
||||||
void GSplitter::enter_event(GEvent&)
|
void GSplitter::enter_event(GEvent&)
|
||||||
{
|
{
|
||||||
set_background_color(Color::from_rgb(0xd6d2ce));
|
set_background_color(Color::from_rgb(0xd6d2ce));
|
||||||
|
window()->set_override_cursor(m_orientation == Orientation::Horizontal ? GStandardCursor::ResizeHorizontal : GStandardCursor::ResizeVertical);
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GSplitter::leave_event(GEvent&)
|
void GSplitter::leave_event(GEvent&)
|
||||||
{
|
{
|
||||||
set_background_color(Color::LightGray);
|
set_background_color(Color::LightGray);
|
||||||
|
if (!m_resizing)
|
||||||
|
window()->set_override_cursor(GStandardCursor::None);
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,4 +112,7 @@ void GSplitter::mouseup_event(GMouseEvent& event)
|
||||||
if (event.button() != GMouseButton::Left)
|
if (event.button() != GMouseButton::Left)
|
||||||
return;
|
return;
|
||||||
m_resizing = false;
|
m_resizing = false;
|
||||||
|
if (!rect().contains(event.position()))
|
||||||
|
window()->set_override_cursor(GStandardCursor::None);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,8 @@ enum class GStandardCursor {
|
||||||
None = 0,
|
None = 0,
|
||||||
Arrow,
|
Arrow,
|
||||||
IBeam,
|
IBeam,
|
||||||
|
ResizeHorizontal,
|
||||||
|
ResizeVertical,
|
||||||
};
|
};
|
||||||
|
|
||||||
class GWindow : public GObject {
|
class GWindow : public GObject {
|
||||||
|
|
|
@ -51,6 +51,8 @@ enum class WSAPI_StandardCursor : unsigned char {
|
||||||
None = 0,
|
None = 0,
|
||||||
Arrow,
|
Arrow,
|
||||||
IBeam,
|
IBeam,
|
||||||
|
ResizeHorizontal,
|
||||||
|
ResizeVertical,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct WSAPI_ServerMessage {
|
struct WSAPI_ServerMessage {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include <WindowServer/WSCursor.h>
|
#include <WindowServer/WSCursor.h>
|
||||||
|
#include <WindowServer/WSWindowManager.h>
|
||||||
|
|
||||||
WSCursor::WSCursor(Retained<GraphicsBitmap>&& bitmap, const Point& hotspot)
|
WSCursor::WSCursor(Retained<GraphicsBitmap>&& bitmap, const Point& hotspot)
|
||||||
: m_bitmap(move(bitmap))
|
: m_bitmap(move(bitmap))
|
||||||
|
@ -26,9 +27,13 @@ RetainPtr<WSCursor> WSCursor::create(WSStandardCursor standard_cursor)
|
||||||
case WSStandardCursor::None:
|
case WSStandardCursor::None:
|
||||||
return nullptr;
|
return nullptr;
|
||||||
case WSStandardCursor::Arrow:
|
case WSStandardCursor::Arrow:
|
||||||
return create(*GraphicsBitmap::load_from_file("/res/cursors/arrow.png"));
|
return WSWindowManager::the().arrow_cursor();
|
||||||
case WSStandardCursor::IBeam:
|
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();
|
ASSERT_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,8 @@ enum class WSStandardCursor {
|
||||||
None = 0,
|
None = 0,
|
||||||
Arrow,
|
Arrow,
|
||||||
IBeam,
|
IBeam,
|
||||||
|
ResizeHorizontal,
|
||||||
|
ResizeVertical,
|
||||||
};
|
};
|
||||||
|
|
||||||
class WSCursor : public Retainable<WSCursor> {
|
class WSCursor : public Retainable<WSCursor> {
|
||||||
|
|
|
@ -87,6 +87,15 @@ public:
|
||||||
const WSCursor& active_cursor() const;
|
const WSCursor& active_cursor() const;
|
||||||
Rect current_cursor_rect() 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:
|
private:
|
||||||
void process_mouse_event(const WSMouseEvent&, WSWindow*& event_window);
|
void process_mouse_event(const WSMouseEvent&, WSWindow*& event_window);
|
||||||
bool process_ongoing_window_resize(const WSMouseEvent&, WSWindow*& event_window);
|
bool process_ongoing_window_resize(const WSMouseEvent&, WSWindow*& event_window);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue