mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 09:51:57 -05:00
GCheckBox: Paint the box part as a container frame.
This commit is contained in:
parent
4ab0cd5d4c
commit
cf8b117d97
1 changed files with 8 additions and 14 deletions
|
@ -1,6 +1,7 @@
|
||||||
#include "GCheckBox.h"
|
#include <LibGUI/GCheckBox.h>
|
||||||
#include <LibGUI/GPainter.h>
|
#include <LibGUI/GPainter.h>
|
||||||
#include <SharedGraphics/CharacterBitmap.h>
|
#include <SharedGraphics/CharacterBitmap.h>
|
||||||
|
#include <SharedGraphics/StylePainter.h>
|
||||||
#include <Kernel/KeyCode.h>
|
#include <Kernel/KeyCode.h>
|
||||||
|
|
||||||
//#define GCHECKBOX_DEBUG
|
//#define GCHECKBOX_DEBUG
|
||||||
|
@ -20,8 +21,8 @@ static const char* s_checked_bitmap_data = {
|
||||||
static CharacterBitmap* s_checked_bitmap;
|
static CharacterBitmap* s_checked_bitmap;
|
||||||
static const int s_checked_bitmap_width = 9;
|
static const int s_checked_bitmap_width = 9;
|
||||||
static const int s_checked_bitmap_height = 9;
|
static const int s_checked_bitmap_height = 9;
|
||||||
static const int s_box_width = 11;
|
static const int s_box_width = 13;
|
||||||
static const int s_box_height = 11;
|
static const int s_box_height = 13;
|
||||||
|
|
||||||
GCheckBox::GCheckBox(GWidget* parent)
|
GCheckBox::GCheckBox(GWidget* parent)
|
||||||
: GWidget(parent)
|
: GWidget(parent)
|
||||||
|
@ -65,27 +66,20 @@ void GCheckBox::paint_event(GPaintEvent& event)
|
||||||
painter.fill_rect(rect(), background_color());
|
painter.fill_rect(rect(), background_color());
|
||||||
|
|
||||||
Rect box_rect {
|
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
|
s_box_width, s_box_height
|
||||||
};
|
};
|
||||||
painter.fill_rect(box_rect, Color::White);
|
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)
|
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)
|
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())
|
if (!caption().is_empty())
|
||||||
painter.draw_text(text_rect, caption(), TextAlignment::TopLeft, foreground_color());
|
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)
|
void GCheckBox::mousemove_event(GMouseEvent& event)
|
||||||
|
|
Loading…
Add table
Reference in a new issue