LibGUI: Make ResizeCorner theme-aware

This commit is contained in:
Tibor Nagy 2020-02-16 07:03:23 +01:00 committed by Andreas Kling
parent 4d8547d112
commit fc24b2b57d
Notes: sideshowbarker 2024-07-19 09:17:04 +09:00
3 changed files with 53 additions and 7 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 127 B

View file

@ -24,7 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <LibGfx/Bitmap.h>
#include <LibGfx/CharacterBitmap.h>
#include <LibGfx/Palette.h>
#include <LibGUI/Painter.h>
#include <LibGUI/ResizeCorner.h>
@ -32,14 +32,55 @@
namespace GUI {
static const char* s_resize_corner_shadows_data = {
" "
" ## "
" # "
" "
" ## ## "
" # # "
" "
" ## ## ## "
" # # # "
" "
" ## ## ## ## "
" # # # # "
" "
" ## ## ## ## ## "
" # # # # # "
" "
};
static const char* s_resize_corner_highlights_data = {
" "
" "
" # "
" "
" "
" # # "
" "
" "
" # # # "
" "
" "
" # # # # "
" "
" "
" # # # # # "
" "
};
static Gfx::CharacterBitmap* s_resize_corner_shadows_bitmap;
static Gfx::CharacterBitmap* s_resize_corner_highlights_bitmap;
static const int s_resize_corner_bitmap_width = 16;
static const int s_resize_corner_bitmap_height = 16;
ResizeCorner::ResizeCorner(Widget* parent)
: Widget(parent)
{
set_background_role(ColorRole::Button);
set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
set_preferred_size(16, 16);
m_bitmap = Gfx::Bitmap::load_from_file("/res/icons/resize-corner.png");
ASSERT(m_bitmap);
}
ResizeCorner::~ResizeCorner()
@ -51,7 +92,15 @@ void ResizeCorner::paint_event(PaintEvent& event)
Painter painter(*this);
painter.add_clip_rect(event.rect());
painter.fill_rect(rect(), palette().color(background_role()));
painter.blit({ 0, 0 }, *m_bitmap, m_bitmap->rect());
if (!s_resize_corner_shadows_bitmap)
s_resize_corner_shadows_bitmap = &Gfx::CharacterBitmap::create_from_ascii(s_resize_corner_shadows_data, s_resize_corner_bitmap_width, s_resize_corner_bitmap_height).leak_ref();
painter.draw_bitmap({ 0, 0 }, *s_resize_corner_shadows_bitmap, palette().threed_shadow1());
if (!s_resize_corner_highlights_bitmap)
s_resize_corner_highlights_bitmap = &Gfx::CharacterBitmap::create_from_ascii(s_resize_corner_highlights_data, s_resize_corner_bitmap_width, s_resize_corner_bitmap_height).leak_ref();
painter.draw_bitmap({ 0, 0 }, *s_resize_corner_highlights_bitmap, palette().threed_highlight());
Widget::paint_event(event);
}

View file

@ -40,9 +40,6 @@ protected:
virtual void mousedown_event(MouseEvent&) override;
virtual void enter_event(Core::Event&) override;
virtual void leave_event(Core::Event&) override;
private:
RefPtr<Gfx::Bitmap> m_bitmap;
};
}