Serenity Operating System
at portability 125 lines 4.2 kB view raw
1/* 2 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, this 9 * list of conditions and the following disclaimer. 10 * 11 * 2. Redistributions in binary form must reproduce the above copyright notice, 12 * this list of conditions and the following disclaimer in the documentation 13 * and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27#include <LibGfx/CharacterBitmap.h> 28#include <LibGfx/Palette.h> 29#include <LibGUI/Painter.h> 30#include <LibGUI/ResizeCorner.h> 31#include <LibGUI/Window.h> 32 33namespace GUI { 34 35static const char* s_resize_corner_shadows_data = { 36 " " 37 " ## " 38 " # " 39 " " 40 " ## ## " 41 " # # " 42 " " 43 " ## ## ## " 44 " # # # " 45 " " 46 " ## ## ## ## " 47 " # # # # " 48 " " 49 " ## ## ## ## ## " 50 " # # # # # " 51 " " 52}; 53 54static const char* s_resize_corner_highlights_data = { 55 " " 56 " " 57 " # " 58 " " 59 " " 60 " # # " 61 " " 62 " " 63 " # # # " 64 " " 65 " " 66 " # # # # " 67 " " 68 " " 69 " # # # # # " 70 " " 71}; 72 73static Gfx::CharacterBitmap* s_resize_corner_shadows_bitmap; 74static Gfx::CharacterBitmap* s_resize_corner_highlights_bitmap; 75static const int s_resize_corner_bitmap_width = 16; 76static const int s_resize_corner_bitmap_height = 16; 77 78ResizeCorner::ResizeCorner() 79{ 80 set_background_role(ColorRole::Button); 81 set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed); 82 set_preferred_size(16, 16); 83} 84 85ResizeCorner::~ResizeCorner() 86{ 87} 88 89void ResizeCorner::paint_event(PaintEvent& event) 90{ 91 Painter painter(*this); 92 painter.add_clip_rect(event.rect()); 93 painter.fill_rect(rect(), palette().color(background_role())); 94 95 if (!s_resize_corner_shadows_bitmap) 96 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(); 97 painter.draw_bitmap({ 0, 0 }, *s_resize_corner_shadows_bitmap, palette().threed_shadow1()); 98 99 if (!s_resize_corner_highlights_bitmap) 100 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(); 101 painter.draw_bitmap({ 0, 0 }, *s_resize_corner_highlights_bitmap, palette().threed_highlight()); 102 103 Widget::paint_event(event); 104} 105 106void ResizeCorner::mousedown_event(MouseEvent& event) 107{ 108 if (event.button() == MouseButton::Left) 109 window()->start_wm_resize(); 110 Widget::mousedown_event(event); 111} 112 113void ResizeCorner::enter_event(Core::Event& event) 114{ 115 window()->set_override_cursor(StandardCursor::ResizeDiagonalTLBR); 116 Widget::enter_event(event); 117} 118 119void ResizeCorner::leave_event(Core::Event& event) 120{ 121 window()->set_override_cursor(StandardCursor::None); 122 Widget::leave_event(event); 123} 124 125}