1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-20 13:35:07 +00:00

Rename all the LibGUI classes to GClassName.

This commit is contained in:
Andreas Kling 2019-01-20 04:49:48 +01:00
parent a026da47e7
commit b91479d9b9
33 changed files with 623 additions and 581 deletions

102
LibGUI/GCheckBox.cpp Normal file
View file

@ -0,0 +1,102 @@
#include "GCheckBox.h"
#include <SharedGraphics/Painter.h>
#include <SharedGraphics/CharacterBitmap.h>
GCheckBox::GCheckBox(GWidget* parent)
: GWidget(parent)
{
}
GCheckBox::~GCheckBox()
{
}
void GCheckBox::setCaption(String&& caption)
{
if (caption == m_caption)
return;
m_caption = move(caption);
update();
}
void GCheckBox::setIsChecked(bool b)
{
if (m_isChecked == b)
return;
m_isChecked = b;
update();
}
static const char* uncheckedBitmap = {
"###########"
"# #"
"# #"
"# #"
"# #"
"# #"
"# #"
"# #"
"# #"
"# #"
"###########"
};
#if 0
static const char* checkedBitmap = {
"############"
"# #"
"# ## #"
"# ## #"
"# ## #"
"# ## #"
"# ## #"
"# ## ## #"
"# ## ## #"
"# ### #"
"# #"
"############"
};
#endif
static const char* checkedBitmap = {
"###########"
"## ##"
"# # # #"
"# # # #"
"# # # #"
"# # #"
"# # # #"
"# # # #"
"# # # #"
"## ##"
"###########"
};
void GCheckBox::paintEvent(GPaintEvent&)
{
Painter painter(*this);
auto bitmap = CharacterBitmap::create_from_ascii(isChecked() ? checkedBitmap : uncheckedBitmap, 11, 11);
auto textRect = rect();
textRect.set_left(bitmap->width() + 4);
textRect.set_top(height() / 2 - font().glyph_height() / 2);
Point bitmapPosition;
bitmapPosition.set_x(2);
bitmapPosition.set_y(height() / 2 - bitmap->height() / 2 - 1);
painter.fill_rect(rect(), backgroundColor());
painter.draw_bitmap(bitmapPosition, *bitmap, foregroundColor());
if (!caption().is_empty()) {
painter.draw_text(textRect, caption(), Painter::TextAlignment::TopLeft, foregroundColor());
}
}
void GCheckBox::mouseDownEvent(GMouseEvent& event)
{
dbgprintf("GCheckBox::mouseDownEvent: x=%d, y=%d, button=%u\n", event.x(), event.y(), (unsigned)event.button());
setIsChecked(!isChecked());
}