From 29f2a22d34554737a67af5b2b2ab8613591383be Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 10 Feb 2019 08:23:03 +0100 Subject: [PATCH] LibGUI: Minor cleanup in GScrollBar. --- FileManager/DirectoryView.cpp | 6 ++-- LibGUI/GScrollBar.cpp | 67 +++++++++++++++++------------------ 2 files changed, 37 insertions(+), 36 deletions(-) diff --git a/FileManager/DirectoryView.cpp b/FileManager/DirectoryView.cpp index 19759154f4..c87d652e28 100644 --- a/FileManager/DirectoryView.cpp +++ b/FileManager/DirectoryView.cpp @@ -98,8 +98,10 @@ Rect DirectoryView::row_rect(int item_index) const void DirectoryView::mousedown_event(GMouseEvent& event) { - for (int i = 0; i < item_count(); ++i) { - if (row_rect(i).contains(event.position())) { + if (event.button() == GMouseButton::Left) { + for (int i = 0; i < item_count(); ++i) { + if (!row_rect(i).contains(event.position())) + continue; auto& entry = this->entry(i); if (entry.is_directory()) { FileSystemPath new_path(String::format("%s/%s", m_path.characters(), entry.name.characters())); diff --git a/LibGUI/GScrollBar.cpp b/LibGUI/GScrollBar.cpp index 281b9a86df..c8dd63e3ad 100644 --- a/LibGUI/GScrollBar.cpp +++ b/LibGUI/GScrollBar.cpp @@ -3,9 +3,42 @@ #include #include +static const char* s_up_arrow_bitmap_data = { + " " + " " + " ## " + " #### " + " ###### " + " ######## " + " ## " + " ## " + " ## " + " " +}; + +static const char* s_down_arrow_bitmap_data = { + " " + " ## " + " ## " + " ## " + " ######## " + " ###### " + " #### " + " ## " + " " + " " +}; + +static CharacterBitmap* s_up_arrow_bitmap; +static CharacterBitmap* s_down_arrow_bitmap; + GScrollBar::GScrollBar(GWidget* parent) : GWidget(parent) { + if (!s_up_arrow_bitmap) + s_up_arrow_bitmap = CharacterBitmap::create_from_ascii(s_up_arrow_bitmap_data, 10, 10).leak_ref(); + if (!s_down_arrow_bitmap) + s_down_arrow_bitmap = CharacterBitmap::create_from_ascii(s_down_arrow_bitmap_data, 10, 10).leak_ref(); } GScrollBar::~GScrollBar() @@ -88,42 +121,8 @@ Rect GScrollBar::scrubber_rect() const return { 0, (int)y, button_size(), button_size() }; } -static const char* s_up_arrow_bitmap_data = { - " " - " " - " ## " - " #### " - " ###### " - " ######## " - " ## " - " ## " - " ## " - " " -}; - -static const char* s_down_arrow_bitmap_data = { - " " - " ## " - " ## " - " ## " - " ######## " - " ###### " - " #### " - " ## " - " " - " " -}; - -static CharacterBitmap* s_up_arrow_bitmap; -static CharacterBitmap* s_down_arrow_bitmap; - void GScrollBar::paint_event(GPaintEvent&) { - if (!s_up_arrow_bitmap) - s_up_arrow_bitmap = CharacterBitmap::create_from_ascii(s_up_arrow_bitmap_data, 10, 10).leak_ref(); - if (!s_down_arrow_bitmap) - s_down_arrow_bitmap = CharacterBitmap::create_from_ascii(s_down_arrow_bitmap_data, 10, 10).leak_ref(); - Painter painter(*this); painter.fill_rect(rect(), Color(164, 164, 164));