mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-23 08:00:20 +00:00
WindowServer: Improve the look of menus.
This patch makes menus stand out a bit more from their background by using the same kind of shading that Windows 2000 had.
This commit is contained in:
parent
311019d8ee
commit
86361d3d45
Notes:
sideshowbarker
2024-07-19 14:41:11 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/86361d3d453
6 changed files with 32 additions and 18 deletions
|
@ -7,6 +7,7 @@
|
||||||
#include <WindowServer/WSAPITypes.h>
|
#include <WindowServer/WSAPITypes.h>
|
||||||
#include <WindowServer/WSClientConnection.h>
|
#include <WindowServer/WSClientConnection.h>
|
||||||
#include <SharedGraphics/Painter.h>
|
#include <SharedGraphics/Painter.h>
|
||||||
|
#include <SharedGraphics/StylePainter.h>
|
||||||
#include <SharedGraphics/Font.h>
|
#include <SharedGraphics/Font.h>
|
||||||
|
|
||||||
WSMenu::WSMenu(WSClientConnection* client, int menu_id, String&& name)
|
WSMenu::WSMenu(WSClientConnection* client, int menu_id, String&& name)
|
||||||
|
@ -38,14 +39,14 @@ int WSMenu::width() const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return max(longest, rect_in_menubar().width()) + horizontal_padding();
|
return max(longest, rect_in_menubar().width()) + horizontal_padding() + frame_thickness() * 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
int WSMenu::height() const
|
int WSMenu::height() const
|
||||||
{
|
{
|
||||||
if (m_items.is_empty())
|
if (m_items.is_empty())
|
||||||
return 0;
|
return 0;
|
||||||
return (m_items.last()->rect().bottom() - 1) + vertical_padding();
|
return (m_items.last()->rect().bottom() - 1) + frame_thickness() * 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WSMenu::redraw()
|
void WSMenu::redraw()
|
||||||
|
@ -59,14 +60,14 @@ void WSMenu::redraw()
|
||||||
WSWindow& WSMenu::ensure_menu_window()
|
WSWindow& WSMenu::ensure_menu_window()
|
||||||
{
|
{
|
||||||
if (!m_menu_window) {
|
if (!m_menu_window) {
|
||||||
Point next_item_location(1, vertical_padding() / 2);
|
Point next_item_location(frame_thickness(), frame_thickness());
|
||||||
for (auto& item : m_items) {
|
for (auto& item : m_items) {
|
||||||
int height = 0;
|
int height = 0;
|
||||||
if (item->type() == WSMenuItem::Text)
|
if (item->type() == WSMenuItem::Text)
|
||||||
height = item_height();
|
height = item_height();
|
||||||
else if (item->type() == WSMenuItem::Separator)
|
else if (item->type() == WSMenuItem::Separator)
|
||||||
height = 7;
|
height = 7;
|
||||||
item->set_rect({ next_item_location, { width() - 2, height } });
|
item->set_rect({ next_item_location, { width() - frame_thickness() * 2, height } });
|
||||||
next_item_location.move_by(0, height);
|
next_item_location.move_by(0, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,8 +87,8 @@ void WSMenu::draw()
|
||||||
Painter painter(*menu_window()->backing_store());
|
Painter painter(*menu_window()->backing_store());
|
||||||
|
|
||||||
Rect rect { { }, menu_window()->size() };
|
Rect rect { { }, menu_window()->size() };
|
||||||
painter.draw_rect(rect, Color::White);
|
painter.fill_rect(rect.shrunken(4, 4), Color::LightGray);
|
||||||
painter.fill_rect(rect.shrunken(2, 2), Color::LightGray);
|
StylePainter::paint_menu_frame(painter, rect);
|
||||||
|
|
||||||
for (auto& item : m_items) {
|
for (auto& item : m_items) {
|
||||||
if (item->type() == WSMenuItem::Text) {
|
if (item->type() == WSMenuItem::Text) {
|
||||||
|
|
|
@ -55,7 +55,7 @@ public:
|
||||||
int height() const;
|
int height() const;
|
||||||
|
|
||||||
int item_height() const { return 18; }
|
int item_height() const { return 18; }
|
||||||
int vertical_padding() const { return 4; }
|
int frame_thickness() const { return 2; }
|
||||||
int horizontal_padding() const { return left_padding() + right_padding(); }
|
int horizontal_padding() const { return left_padding() + right_padding(); }
|
||||||
int left_padding() const { return 14; }
|
int left_padding() const { return 14; }
|
||||||
int right_padding() const { return 14; }
|
int right_padding() const { return 14; }
|
||||||
|
|
|
@ -66,11 +66,6 @@ WSWindowFrame::~WSWindowFrame()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline Rect menu_window_rect(const Rect& rect)
|
|
||||||
{
|
|
||||||
return rect.inflated(2, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
Rect WSWindowFrame::title_bar_rect() const
|
Rect WSWindowFrame::title_bar_rect() const
|
||||||
{
|
{
|
||||||
return { 2, 2, m_window.width() + 2, window_titlebar_height };
|
return { 2, 2, m_window.width() + 2, window_titlebar_height };
|
||||||
|
@ -109,10 +104,8 @@ void WSWindowFrame::paint(Painter& painter)
|
||||||
PainterStateSaver saver(painter);
|
PainterStateSaver saver(painter);
|
||||||
painter.translate(rect().location());
|
painter.translate(rect().location());
|
||||||
|
|
||||||
if (m_window.type() == WSWindowType::Menu) {
|
if (m_window.type() == WSWindowType::Menu)
|
||||||
painter.draw_rect(menu_window_rect(m_window.rect()), Color::LightGray);
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if (m_window.type() == WSWindowType::WindowSwitcher)
|
if (m_window.type() == WSWindowType::WindowSwitcher)
|
||||||
return;
|
return;
|
||||||
|
@ -193,7 +186,7 @@ static Rect frame_rect_for_window_type(WSWindowType type, const Rect& rect)
|
||||||
{
|
{
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case WSWindowType::Menu:
|
case WSWindowType::Menu:
|
||||||
return menu_window_rect(rect);
|
return rect;
|
||||||
case WSWindowType::Normal:
|
case WSWindowType::Normal:
|
||||||
return { rect.x() - 3, rect.y() - window_titlebar_height - 3, rect.width() + 6, rect.height() + 6 + window_titlebar_height };
|
return { rect.x() - 3, rect.y() - window_titlebar_height - 3, rect.width() + 6, rect.height() + 6 + window_titlebar_height };
|
||||||
case WSWindowType::WindowSwitcher:
|
case WSWindowType::WindowSwitcher:
|
||||||
|
|
|
@ -379,7 +379,7 @@ void WSWindowManager::handle_menu_mouse_event(WSMenu& menu, const WSMouseEvent&
|
||||||
close_current_menu();
|
close_current_menu();
|
||||||
if (!menu.is_empty()) {
|
if (!menu.is_empty()) {
|
||||||
auto& menu_window = menu.ensure_menu_window();
|
auto& menu_window = menu.ensure_menu_window();
|
||||||
menu_window.move_to({ menu.rect_in_menubar().x(), menu.rect_in_menubar().bottom() });
|
menu_window.move_to({ menu.rect_in_menubar().x(), menu.rect_in_menubar().bottom() + 2 });
|
||||||
menu_window.set_visible(true);
|
menu_window.set_visible(true);
|
||||||
}
|
}
|
||||||
m_current_menu = menu.make_weak_ptr();
|
m_current_menu = menu.make_weak_ptr();
|
||||||
|
@ -826,7 +826,7 @@ void WSWindowManager::draw_menubar()
|
||||||
auto menubar_rect = this->menubar_rect();
|
auto menubar_rect = this->menubar_rect();
|
||||||
|
|
||||||
m_back_painter->fill_rect(menubar_rect, Color::LightGray);
|
m_back_painter->fill_rect(menubar_rect, Color::LightGray);
|
||||||
m_back_painter->draw_line({ 0, menubar_rect.bottom() }, { menubar_rect.right(), menubar_rect.bottom() }, Color::White);
|
m_back_painter->draw_line({ 0, menubar_rect.bottom() }, { menubar_rect.right(), menubar_rect.bottom() }, Color::MidGray);
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for_each_active_menubar_menu([&] (WSMenu& menu) {
|
for_each_active_menubar_menu([&] (WSMenu& menu) {
|
||||||
Color text_color = Color::Black;
|
Color text_color = Color::Black;
|
||||||
|
|
|
@ -166,3 +166,22 @@ void StylePainter::paint_frame(Painter& painter, const Rect& rect, FrameShape sh
|
||||||
painter.draw_line(inner_rect.top_right(), inner_rect.bottom_right().translated(0, -1), bottom_right_color);
|
painter.draw_line(inner_rect.top_right(), inner_rect.bottom_right().translated(0, -1), bottom_right_color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void StylePainter::paint_menu_frame(Painter& painter, const Rect& rect)
|
||||||
|
{
|
||||||
|
Color top_left_color;
|
||||||
|
Color bottom_right_color;
|
||||||
|
Color base_color = Color::from_rgb(0xc0c0c0);
|
||||||
|
Color dark_shade = Color::from_rgb(0x404040);
|
||||||
|
Color mid_shade = Color::from_rgb(0x808080);
|
||||||
|
Color light_shade = Color::from_rgb(0xffffff);
|
||||||
|
|
||||||
|
painter.draw_line(rect.top_left(), rect.top_right(), base_color);
|
||||||
|
painter.draw_line(rect.top_left().translated(0, 1), rect.bottom_left(), base_color);
|
||||||
|
painter.draw_line(rect.top_left().translated(1, 1), rect.top_right().translated(-1, 1), light_shade);
|
||||||
|
painter.draw_line(rect.top_left().translated(1, 1), rect.bottom_left().translated(1, -1), light_shade);
|
||||||
|
painter.draw_line(rect.top_right(), rect.bottom_right(), dark_shade);
|
||||||
|
painter.draw_line(rect.bottom_left(), rect.bottom_right(), dark_shade);
|
||||||
|
painter.draw_line(rect.top_right().translated(-1, 1), rect.bottom_right().translated(-1, -1), mid_shade);
|
||||||
|
painter.draw_line(rect.bottom_left().translated(1, -1), rect.bottom_right().translated(-1, -1), mid_shade);
|
||||||
|
}
|
||||||
|
|
|
@ -12,4 +12,5 @@ public:
|
||||||
static void paint_button(Painter&, const Rect&, ButtonStyle, bool pressed, bool hovered = false, bool checked = false, bool enabled = true);
|
static void paint_button(Painter&, const Rect&, ButtonStyle, bool pressed, bool hovered = false, bool checked = false, bool enabled = true);
|
||||||
static void paint_surface(Painter&, const Rect&, bool paint_vertical_lines = true);
|
static void paint_surface(Painter&, const Rect&, bool paint_vertical_lines = true);
|
||||||
static void paint_frame(Painter&, const Rect&, FrameShape, FrameShadow, int thickness, bool skip_vertical_lines = false);
|
static void paint_frame(Painter&, const Rect&, FrameShape, FrameShadow, int thickness, bool skip_vertical_lines = false);
|
||||||
|
static void paint_menu_frame(Painter&, const Rect&);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue