mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:57:43 +00:00
CatDog: Help the user debug their programs
This adds helpful speech bubbles to CatDog. CatDog just wants to help, that's all.
This commit is contained in:
parent
da5923bc54
commit
e0fe38ea25
6 changed files with 132 additions and 0 deletions
40
Userland/Demos/CatDog/SpeechBubble.cpp
Normal file
40
Userland/Demos/CatDog/SpeechBubble.cpp
Normal file
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Gunnar Beutner <gunnar@beutner.name>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "SpeechBubble.h"
|
||||
#include <LibGUI/Painter.h>
|
||||
#include <LibGfx/Palette.h>
|
||||
|
||||
void SpeechBubble::paint_event(GUI::PaintEvent&)
|
||||
{
|
||||
GUI::Painter painter(*this);
|
||||
painter.clear_rect(rect(), Gfx::Color());
|
||||
|
||||
constexpr auto background_color = Gfx::Color::from_rgb(0xeaf688);
|
||||
|
||||
auto text_area = rect();
|
||||
text_area.set_height(text_area.height() - 10);
|
||||
painter.draw_rect(text_area, palette().active_window_border1());
|
||||
text_area.shrink(2, 2);
|
||||
painter.fill_rect(text_area, background_color);
|
||||
|
||||
auto connector_top_left = Gfx::IntPoint { rect().width() / 2 - 5, text_area.height() + 1 };
|
||||
auto connector_top_right = Gfx::IntPoint { rect().width() / 2 + 5, text_area.height() + 1 };
|
||||
auto connector_bottom = Gfx::IntPoint { rect().width() / 2 + 10, rect().height() };
|
||||
painter.draw_triangle(connector_top_left, connector_top_right, connector_bottom, background_color);
|
||||
painter.draw_line(connector_top_left, Gfx::IntPoint { connector_bottom.x() - 1, connector_bottom.y() }, palette().active_window_border1());
|
||||
painter.draw_line(connector_top_right, connector_bottom, palette().active_window_border1());
|
||||
|
||||
painter.draw_text(text_area, "It looks like you're trying to debug\na program. Would you like some help?", Gfx::TextAlignment::Center);
|
||||
}
|
||||
|
||||
void SpeechBubble::mousedown_event(GUI::MouseEvent& event)
|
||||
{
|
||||
if (event.button() != GUI::MouseButton::Left)
|
||||
return;
|
||||
if (on_dismiss)
|
||||
on_dismiss();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue