Skip to content

Commit

Permalink
WindowServer: Improve the look of menus.
Browse files Browse the repository at this point in the history
This patch makes menus stand out a bit more from their background by using
the same kind of shading that Windows 2000 had.
  • Loading branch information
awesomekling committed Apr 16, 2019
1 parent 311019d commit 86361d3
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 18 deletions.
13 changes: 7 additions & 6 deletions Servers/WindowServer/WSMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <WindowServer/WSAPITypes.h>
#include <WindowServer/WSClientConnection.h>
#include <SharedGraphics/Painter.h>
#include <SharedGraphics/StylePainter.h>
#include <SharedGraphics/Font.h>

WSMenu::WSMenu(WSClientConnection* client, int menu_id, String&& name)
Expand Down Expand Up @@ -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()
Expand All @@ -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);
}

Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion Servers/WindowServer/WSMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class WSMenu final : public CObject {
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; }
Expand Down
11 changes: 2 additions & 9 deletions Servers/WindowServer/WSWindowFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions Servers/WindowServer/WSWindowManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
19 changes: 19 additions & 0 deletions SharedGraphics/StylePainter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
1 change: 1 addition & 0 deletions SharedGraphics/StylePainter.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ class StylePainter {
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&);
};

0 comments on commit 86361d3

Please sign in to comment.