1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 07:07:44 +00:00

Minor GUI API things + make Button corners properly transparent.

This commit is contained in:
Andreas Kling 2019-01-13 06:25:30 +01:00
parent f7261d7b26
commit 1d914cbd84
5 changed files with 10 additions and 14 deletions

View file

@ -23,8 +23,7 @@ int main(int argc, char** argv)
GUI_CreateWidgetParameters label_params;
label_params.type = GUI_WidgetType::Label;
label_params.rect = { 20, 20, 260, 20 };
label_params.background_color = 0xffffff;
label_params.opaque = true;
label_params.opaque = false;
strcpy(label_params.text, "Hello World!");
int label_id = syscall(SC_gui_create_widget, window_id, &label_params);
if (label_id < 0) {
@ -35,8 +34,6 @@ int main(int argc, char** argv)
GUI_CreateWidgetParameters button_params;
button_params.type = GUI_WidgetType::Button;
button_params.rect = { 60, 60, 120, 20 };
button_params.background_color = 0xffffff;
button_params.opaque = true;
strcpy(button_params.text, "I'm a button!");
int button_id = syscall(SC_gui_create_widget, window_id, &button_params);
if (button_id < 0) {

View file

@ -4,6 +4,7 @@
Button::Button(Widget* parent)
: Widget(parent)
{
setFillWithBackgroundColor(false);
}
Button::~Button()
@ -26,11 +27,6 @@ void Button::paintEvent(PaintEvent&)
Painter painter(*this);
painter.set_pixel({ 0, 0 }, backgroundColor());
painter.set_pixel({ width() - 1, 0 }, backgroundColor());
painter.set_pixel({ 0, height() - 1 }, backgroundColor());
painter.set_pixel({ width() - 1, height() - 1 }, backgroundColor());
painter.draw_line({ 1, 0 }, { width() - 2, 0 }, Color::Black);
painter.draw_line({ 1, height() - 1 }, { width() - 2, height() - 1}, Color::Black);
painter.draw_line({ 0, 1 }, { 0, height() - 2 }, Color::Black);

View file

@ -21,7 +21,8 @@ void Label::setText(String&& text)
void Label::paintEvent(PaintEvent&)
{
Painter painter(*this);
painter.fill_rect({ 0, 0, width(), height() }, backgroundColor());
if (fillWithBackgroundColor())
painter.fill_rect({ 0, 0, width(), height() }, backgroundColor());
if (!text().is_empty())
painter.draw_text({ 4, 4, width(), height() }, text(), Painter::TextAlignment::TopLeft, foregroundColor());
}

View file

@ -25,7 +25,9 @@ Painter::Painter(Widget& widget)
m_clip_rect = widget.relativeRect();
#ifdef DEBUG_WIDGET_UNDERDRAW
fill_rect(widget.rect(), Color::Red);
// If the widget is not opaque, let's not mess it up with debugging color.
if (widget.fillWithBackgroundColor())
fill_rect(widget.rect(), Color::Red);
#endif
}

View file

@ -90,10 +90,10 @@ private:
Window* m_window { nullptr };
Rect m_relativeRect;
Color m_backgroundColor;
Color m_foregroundColor;
Color m_backgroundColor { 0xffffff };
Color m_foregroundColor { 0x000000 };
RetainPtr<Font> m_font;
bool m_hasPendingPaintEvent { false };
bool m_fillWithBackgroundColor { false };
bool m_fillWithBackgroundColor { true };
};