mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:37:35 +00:00
Add concept of size increments to windowing system.
Use this to implement incremental resizing for Terminal so that we only ever resize to fit a perfect number of rows and columns. This is very nice. :^)
This commit is contained in:
parent
fd575055c2
commit
6084cd0c56
12 changed files with 47 additions and 4 deletions
|
@ -170,6 +170,8 @@ struct WSAPI_ClientMessage {
|
|||
WSAPI_Rect rect;
|
||||
bool has_alpha_channel;
|
||||
float opacity;
|
||||
WSAPI_Size base_size;
|
||||
WSAPI_Size size_increment;
|
||||
} window;
|
||||
struct {
|
||||
WSAPI_Size size;
|
||||
|
|
|
@ -319,6 +319,7 @@ void WSClientConnection::handle_request(WSAPICreateWindowRequest& request)
|
|||
window->set_title(request.title());
|
||||
window->set_rect(request.rect());
|
||||
window->set_opacity(request.opacity());
|
||||
window->set_size_increment(request.size_increment());
|
||||
m_windows.set(window_id, move(window));
|
||||
WSAPI_ServerMessage response;
|
||||
response.type = WSAPI_ServerMessage::Type::DidCreateWindow;
|
||||
|
|
|
@ -349,12 +349,14 @@ private:
|
|||
|
||||
class WSAPICreateWindowRequest : public WSAPIClientRequest {
|
||||
public:
|
||||
WSAPICreateWindowRequest(int client_id, const Rect& rect, const String& title, bool has_alpha_channel, float opacity)
|
||||
WSAPICreateWindowRequest(int client_id, const Rect& rect, const String& title, bool has_alpha_channel, float opacity, const Size& base_size, const Size& size_increment)
|
||||
: WSAPIClientRequest(WSMessage::APICreateWindowRequest, client_id)
|
||||
, m_rect(rect)
|
||||
, m_title(title)
|
||||
, m_opacity(opacity)
|
||||
, m_has_alpha_channel(has_alpha_channel)
|
||||
, m_base_size(base_size)
|
||||
, m_size_increment(size_increment)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -362,12 +364,16 @@ public:
|
|||
String title() const { return m_title; }
|
||||
bool has_alpha_channel() const { return m_has_alpha_channel; }
|
||||
float opacity() const { return m_opacity; }
|
||||
Size size_increment() const { return m_size_increment; }
|
||||
Size base_size() const { return m_base_size; }
|
||||
|
||||
private:
|
||||
Rect m_rect;
|
||||
String m_title;
|
||||
float m_opacity { 0 };
|
||||
bool m_has_alpha_channel { false };
|
||||
Size m_size_increment;
|
||||
Size m_base_size;
|
||||
};
|
||||
|
||||
class WSAPIDestroyWindowRequest : public WSAPIClientRequest {
|
||||
|
|
|
@ -302,7 +302,7 @@ void WSMessageLoop::on_receive_from_client(int client_id, const WSAPI_ClientMess
|
|||
break;
|
||||
case WSAPI_ClientMessage::Type::CreateWindow:
|
||||
ASSERT(message.text_length < sizeof(message.text));
|
||||
post_message(client, make<WSAPICreateWindowRequest>(client_id, message.window.rect, String(message.text, message.text_length), message.window.has_alpha_channel, message.window.opacity));
|
||||
post_message(client, make<WSAPICreateWindowRequest>(client_id, message.window.rect, String(message.text, message.text_length), message.window.has_alpha_channel, message.window.opacity, message.window.base_size, message.window.size_increment));
|
||||
break;
|
||||
case WSAPI_ClientMessage::Type::DestroyWindow:
|
||||
post_message(client, make<WSAPIDestroyWindowRequest>(client_id, message.window_id));
|
||||
|
|
|
@ -70,6 +70,12 @@ public:
|
|||
bool has_painted_since_last_resize() const { return m_has_painted_since_last_resize; }
|
||||
void set_has_painted_since_last_resize(bool b) { m_has_painted_since_last_resize = b; }
|
||||
|
||||
Size size_increment() const { return m_size_increment; }
|
||||
void set_size_increment(const Size& increment) { m_size_increment = increment; }
|
||||
|
||||
Size base_size() const { return m_base_size; }
|
||||
void set_base_size(const Size& size) { m_base_size = size; }
|
||||
|
||||
// For InlineLinkedList.
|
||||
// FIXME: Maybe make a ListHashSet and then WSWindowManager can just use that.
|
||||
WSWindow* m_next { nullptr };
|
||||
|
@ -89,4 +95,6 @@ private:
|
|||
int m_window_id { -1 };
|
||||
float m_opacity { 1 };
|
||||
Rect m_last_lazy_resize_rect;
|
||||
Size m_size_increment;
|
||||
Size m_base_size;
|
||||
};
|
||||
|
|
|
@ -548,6 +548,14 @@ void WSWindowManager::process_mouse_event(WSMouseEvent& event, WSWindow*& event_
|
|||
auto new_rect = m_resize_window_original_rect;
|
||||
new_rect.set_width(max(50, new_rect.width() + dx));
|
||||
new_rect.set_height(max(50, new_rect.height() + dy));
|
||||
|
||||
if (!m_resize_window->size_increment().is_null()) {
|
||||
int horizontal_incs = (new_rect.width() - m_resize_window->base_size().width()) / m_resize_window->size_increment().width();
|
||||
new_rect.set_width(m_resize_window->base_size().width() + horizontal_incs * m_resize_window->size_increment().width());
|
||||
int vertical_incs = (new_rect.height() - m_resize_window->base_size().height()) / m_resize_window->size_increment().height();
|
||||
new_rect.set_height(m_resize_window->base_size().height() + vertical_incs * m_resize_window->size_increment().height());
|
||||
}
|
||||
|
||||
if (m_resize_window->rect() == new_rect)
|
||||
return;
|
||||
#ifdef RESIZE_DEBUG
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue