GCheckBox: Paint the box part as a container frame.

This commit is contained in:
Andreas Kling 2019-04-10 03:44:23 +02:00
parent 4ab0cd5d4c
commit cf8b117d97

View file

@ -1,6 +1,7 @@
#include "GCheckBox.h"
#include <LibGUI/GCheckBox.h>
#include <LibGUI/GPainter.h>
#include <SharedGraphics/CharacterBitmap.h>
#include <SharedGraphics/StylePainter.h>
#include <Kernel/KeyCode.h>
//#define GCHECKBOX_DEBUG
@ -20,8 +21,8 @@ static const char* s_checked_bitmap_data = {
static CharacterBitmap* s_checked_bitmap;
static const int s_checked_bitmap_width = 9;
static const int s_checked_bitmap_height = 9;
static const int s_box_width = 11;
static const int s_box_height = 11;
static const int s_box_width = 13;
static const int s_box_height = 13;
GCheckBox::GCheckBox(GWidget* parent)
: GWidget(parent)
@ -65,27 +66,20 @@ void GCheckBox::paint_event(GPaintEvent& event)
painter.fill_rect(rect(), background_color());
Rect box_rect {
2, height() / 2 - s_box_height / 2 - 1,
0, height() / 2 - s_box_height / 2 - 1,
s_box_width, s_box_height
};
painter.fill_rect(box_rect, Color::White);
painter.draw_rect(box_rect, Color::Black);
StylePainter::paint_frame(painter, box_rect, FrameShape::Container, FrameShadow::Sunken, 2);
if (m_being_modified)
painter.draw_rect(box_rect.shrunken(2, 2), Color::MidGray);
painter.draw_rect(box_rect.shrunken(4, 4), Color::MidGray);
if (m_checked)
painter.draw_bitmap(box_rect.shrunken(2, 2).location(), *s_checked_bitmap, foreground_color());
painter.draw_bitmap(box_rect.shrunken(4, 4).location(), *s_checked_bitmap, foreground_color());
if (!caption().is_empty())
painter.draw_text(text_rect, caption(), TextAlignment::TopLeft, foreground_color());
if (is_focused()) {
// NOTE: Painter::draw_focus_rect() will shrink(2,2) the passed rect.
auto focus_rect = box_rect;
focus_rect.inflate(4, 4);
painter.draw_focus_rect(focus_rect);
}
}
void GCheckBox::mousemove_event(GMouseEvent& event)