diff --git a/Servers/WindowServer/WSMenu.cpp b/Servers/WindowServer/WSMenu.cpp index 661f8c6967..ba952a11d7 100644 --- a/Servers/WindowServer/WSMenu.cpp +++ b/Servers/WindowServer/WSMenu.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include 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 { if (m_items.is_empty()) return 0; - return (m_items.last()->rect().bottom() - 1) + vertical_padding(); + return (m_items.last()->rect().bottom() - 1) + frame_thickness() * 2; } void WSMenu::redraw() @@ -59,14 +60,14 @@ void WSMenu::redraw() WSWindow& WSMenu::ensure_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) { int height = 0; if (item->type() == WSMenuItem::Text) height = item_height(); else if (item->type() == WSMenuItem::Separator) 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); } @@ -86,8 +87,8 @@ void WSMenu::draw() Painter painter(*menu_window()->backing_store()); Rect rect { { }, menu_window()->size() }; - painter.draw_rect(rect, Color::White); - painter.fill_rect(rect.shrunken(2, 2), Color::LightGray); + painter.fill_rect(rect.shrunken(4, 4), Color::LightGray); + StylePainter::paint_menu_frame(painter, rect); for (auto& item : m_items) { if (item->type() == WSMenuItem::Text) { diff --git a/Servers/WindowServer/WSMenu.h b/Servers/WindowServer/WSMenu.h index 028d840b61..2c2362186d 100644 --- a/Servers/WindowServer/WSMenu.h +++ b/Servers/WindowServer/WSMenu.h @@ -55,7 +55,7 @@ public: int height() const; 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 left_padding() const { return 14; } int right_padding() const { return 14; } diff --git a/Servers/WindowServer/WSWindowFrame.cpp b/Servers/WindowServer/WSWindowFrame.cpp index 6a3b08c1f5..bf511db46c 100644 --- a/Servers/WindowServer/WSWindowFrame.cpp +++ b/Servers/WindowServer/WSWindowFrame.cpp @@ -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 { return { 2, 2, m_window.width() + 2, window_titlebar_height }; @@ -109,10 +104,8 @@ void WSWindowFrame::paint(Painter& painter) PainterStateSaver saver(painter); painter.translate(rect().location()); - if (m_window.type() == WSWindowType::Menu) { - painter.draw_rect(menu_window_rect(m_window.rect()), Color::LightGray); + if (m_window.type() == WSWindowType::Menu) return; - } if (m_window.type() == WSWindowType::WindowSwitcher) return; @@ -193,7 +186,7 @@ static Rect frame_rect_for_window_type(WSWindowType type, const Rect& rect) { switch (type) { case WSWindowType::Menu: - return menu_window_rect(rect); + return rect; case WSWindowType::Normal: return { rect.x() - 3, rect.y() - window_titlebar_height - 3, rect.width() + 6, rect.height() + 6 + window_titlebar_height }; case WSWindowType::WindowSwitcher: diff --git a/Servers/WindowServer/WSWindowManager.cpp b/Servers/WindowServer/WSWindowManager.cpp index d62bbdce5b..aef6b73342 100644 --- a/Servers/WindowServer/WSWindowManager.cpp +++ b/Servers/WindowServer/WSWindowManager.cpp @@ -379,7 +379,7 @@ void WSWindowManager::handle_menu_mouse_event(WSMenu& menu, const WSMouseEvent& close_current_menu(); if (!menu.is_empty()) { 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); } m_current_menu = menu.make_weak_ptr(); @@ -826,7 +826,7 @@ void WSWindowManager::draw_menubar() auto menubar_rect = this->menubar_rect(); 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; for_each_active_menubar_menu([&] (WSMenu& menu) { Color text_color = Color::Black; diff --git a/SharedGraphics/StylePainter.cpp b/SharedGraphics/StylePainter.cpp index 5e5741d78b..522a526868 100644 --- a/SharedGraphics/StylePainter.cpp +++ b/SharedGraphics/StylePainter.cpp @@ -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); } } + +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); +} diff --git a/SharedGraphics/StylePainter.h b/SharedGraphics/StylePainter.h index 0f22c65b8f..b31ecaec74 100644 --- a/SharedGraphics/StylePainter.h +++ b/SharedGraphics/StylePainter.h @@ -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_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_menu_frame(Painter&, const Rect&); };