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

LibGUI: Put all classes in the GUI namespace and remove the leading G

This took me a moment. Welcome to the new world of GUI::Widget! :^)
This commit is contained in:
Andreas Kling 2020-02-02 15:07:41 +01:00
parent 2d39da5405
commit c5bd9d4ed1
337 changed files with 5400 additions and 4816 deletions

View file

@ -34,50 +34,50 @@
#include <time.h>
#include <unistd.h>
class SquareButton final : public GButton {
class SquareButton final : public GUI::Button {
public:
SquareButton(GWidget* parent)
: GButton(parent)
SquareButton(GUI::Widget* parent)
: GUI::Button(parent)
{
}
Function<void()> on_right_click;
Function<void()> on_middle_click;
virtual void mousedown_event(GMouseEvent& event) override
virtual void mousedown_event(GUI::MouseEvent& event) override
{
if (event.button() == GMouseButton::Right) {
if (event.button() == GUI::MouseButton::Right) {
if (on_right_click)
on_right_click();
}
if (event.button() == GMouseButton::Middle) {
if (event.button() == GUI::MouseButton::Middle) {
if (on_middle_click)
on_middle_click();
}
GButton::mousedown_event(event);
GUI::Button::mousedown_event(event);
}
};
class SquareLabel final : public GLabel {
class SquareLabel final : public GUI::Label {
public:
SquareLabel(Square& square, GWidget* parent)
: GLabel(parent)
SquareLabel(Square& square, GUI::Widget* parent)
: GUI::Label(parent)
, m_square(square)
{
}
Function<void()> on_chord_click;
virtual void mousedown_event(GMouseEvent& event) override
virtual void mousedown_event(GUI::MouseEvent& event) override
{
if (event.button() == GMouseButton::Right || event.button() == GMouseButton::Left) {
if (event.buttons() == (GMouseButton::Right | GMouseButton::Left) ||
if (event.button() == GUI::MouseButton::Right || event.button() == GUI::MouseButton::Left) {
if (event.buttons() == (GUI::MouseButton::Right | GUI::MouseButton::Left) ||
m_square.field->is_single_chording()) {
m_chord = true;
m_square.field->set_chord_preview(m_square, true);
}
}
if (event.button() == GMouseButton::Middle) {
if (event.button() == GUI::MouseButton::Middle) {
m_square.field->for_each_square([](auto& square) {
if (square.is_considering) {
square.is_considering = false;
@ -85,10 +85,10 @@ public:
}
});
}
GLabel::mousedown_event(event);
GUI::Label::mousedown_event(event);
}
virtual void mousemove_event(GMouseEvent& event) override
virtual void mousemove_event(GUI::MouseEvent& event) override
{
if (m_chord) {
if (rect().contains(event.position())) {
@ -97,13 +97,13 @@ public:
m_square.field->set_chord_preview(m_square, false);
}
}
GLabel::mousemove_event(event);
GUI::Label::mousemove_event(event);
}
virtual void mouseup_event(GMouseEvent& event) override
virtual void mouseup_event(GUI::MouseEvent& event) override
{
if (m_chord) {
if (event.button() == GMouseButton::Left || event.button() == GMouseButton::Right) {
if (event.button() == GUI::MouseButton::Left || event.button() == GUI::MouseButton::Right) {
if (rect().contains(event.position())) {
if (on_chord_click)
on_chord_click();
@ -112,15 +112,15 @@ public:
}
}
m_square.field->set_chord_preview(m_square, m_chord);
GLabel::mouseup_event(event);
GUI::Label::mouseup_event(event);
}
Square& m_square;
bool m_chord { false };
};
Field::Field(GLabel& flag_label, GLabel& time_label, GButton& face_button, GWidget* parent, Function<void(Size)> on_size_changed)
: GFrame(parent)
Field::Field(GUI::Label& flag_label, GUI::Label& time_label, GUI::Button& face_button, GUI::Widget* parent, Function<void(Size)> on_size_changed)
: GUI::Frame(parent)
, m_face_button(face_button)
, m_flag_label(flag_label)
, m_time_label(time_label)
@ -256,7 +256,7 @@ void Field::reset()
square.label->set_icon(square.has_mine ? m_mine_bitmap : nullptr);
if (!square.button) {
square.button = new SquareButton(this);
square.button->on_click = [this, &square](GButton&) {
square.button->on_click = [this, &square](GUI::Button&) {
on_square_clicked(square);
};
square.button->on_right_click = [this, &square] {
@ -315,10 +315,10 @@ void Field::flood_fill(Square& square)
}
}
void Field::paint_event(GPaintEvent& event)
void Field::paint_event(GUI::PaintEvent& event)
{
GFrame::paint_event(event);
GPainter painter(*this);
GUI::Frame::paint_event(event);
GUI::Painter painter(*this);
painter.add_clip_rect(event.rect());
auto inner_rect = frame_inner_rect();

View file

@ -30,9 +30,12 @@
#include <LibCore/CTimer.h>
#include <LibGUI/GFrame.h>
namespace GUI {
class Button;
class Label;
}
class Field;
class GButton;
class GLabel;
class SquareButton;
class SquareLabel;
@ -57,12 +60,12 @@ public:
void for_each_neighbor(Callback);
};
class Field final : public GFrame {
class Field final : public GUI::Frame {
C_OBJECT(Field)
friend class Square;
friend class SquareLabel;
public:
Field(GLabel& flag_label, GLabel& time_label, GButton& face_button, GWidget* parent, Function<void(Size)> on_size_changed);
Field(GUI::Label& flag_label, GUI::Label& time_label, GUI::Button& face_button, GUI::Widget* parent, Function<void(Size)> on_size_changed);
virtual ~Field() override;
int rows() const { return m_rows; }
@ -77,7 +80,7 @@ public:
void reset();
private:
virtual void paint_event(GPaintEvent&) override;
virtual void paint_event(GUI::PaintEvent&) override;
void on_square_clicked(Square&);
void on_square_right_clicked(Square&);
@ -118,9 +121,9 @@ private:
RefPtr<GraphicsBitmap> m_good_face_bitmap;
RefPtr<GraphicsBitmap> m_bad_face_bitmap;
RefPtr<GraphicsBitmap> m_number_bitmap[8];
GButton& m_face_button;
GLabel& m_flag_label;
GLabel& m_time_label;
GUI::Button& m_face_button;
GUI::Label& m_flag_label;
GUI::Label& m_time_label;
RefPtr<Core::Timer> m_timer;
int m_time_elapsed { 0 };
int m_flags_left { 0 };

View file

@ -45,7 +45,7 @@ int main(int argc, char** argv)
return 1;
}
GApplication app(argc, argv);
GUI::Application app(argc, argv);
if (pledge("stdio rpath accept wpath cpath shared_buffer", nullptr) < 0) {
perror("pledge");
@ -53,41 +53,41 @@ int main(int argc, char** argv)
}
auto window = GWindow::construct();
auto window = GUI::Window::construct();
window->set_resizable(false);
window->set_title("Minesweeper");
window->set_rect(100, 100, 139, 175);
auto widget = GWidget::construct();
auto widget = GUI::Widget::construct();
window->set_main_widget(widget);
widget->set_layout(make<GVBoxLayout>());
widget->set_layout(make<GUI::VBoxLayout>());
widget->layout()->set_spacing(0);
auto container = GWidget::construct(widget.ptr());
auto container = GUI::Widget::construct(widget.ptr());
container->set_fill_with_background_color(true);
container->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
container->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
container->set_preferred_size(0, 36);
container->set_layout(make<GHBoxLayout>());
auto flag_icon_label = GLabel::construct(container);
container->set_layout(make<GUI::HBoxLayout>());
auto flag_icon_label = GUI::Label::construct(container);
flag_icon_label->set_icon(GraphicsBitmap::load_from_file("/res/icons/minesweeper/flag.png"));
auto flag_label = GLabel::construct(container);
auto face_button = GButton::construct(container);
auto flag_label = GUI::Label::construct(container);
auto face_button = GUI::Button::construct(container);
face_button->set_button_style(ButtonStyle::CoolBar);
face_button->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
face_button->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
face_button->set_preferred_size(36, 0);
auto time_icon_label = GLabel::construct(container);
auto time_icon_label = GUI::Label::construct(container);
time_icon_label->set_icon(GraphicsBitmap::load_from_file("/res/icons/minesweeper/timer.png"));
auto time_label = GLabel::construct(container);
auto time_label = GUI::Label::construct(container);
auto field = Field::construct(*flag_label, *time_label, *face_button, widget, [&](Size size) {
size.set_height(size.height() + container->preferred_size().height());
window->resize(size);
});
auto menubar = make<GMenuBar>();
auto menubar = make<GUI::MenuBar>();
auto app_menu = GMenu::construct("Minesweeper");
auto app_menu = GUI::Menu::construct("Minesweeper");
app_menu->add_action(GAction::create("New game", { Mod_None, Key_F2 }, [&](const GAction&) {
app_menu->add_action(GUI::Action::create("New game", { Mod_None, Key_F2 }, [&](const GUI::Action&) {
field->reset();
}));
@ -95,7 +95,7 @@ int main(int argc, char** argv)
app_menu->add_separator();
NonnullRefPtr<GAction> chord_toggler_action = GAction::create("Single-click chording", [&](const GAction&) {
NonnullRefPtr<GUI::Action> chord_toggler_action = GUI::Action::create("Single-click chording", [&](const GUI::Action&) {
bool toggled = !field->is_single_chording();
field->set_single_chording(toggled);
chord_toggler_action->set_checked(toggled);
@ -106,30 +106,30 @@ int main(int argc, char** argv)
app_menu->add_action(*chord_toggler_action);
app_menu->add_separator();
app_menu->add_action(GCommonActions::make_quit_action([](auto&) {
GApplication::the().quit(0);
app_menu->add_action(GUI::CommonActions::make_quit_action([](auto&) {
GUI::Application::the().quit(0);
return;
}));
menubar->add_menu(move(app_menu));
auto difficulty_menu = GMenu::construct("Difficulty");
difficulty_menu->add_action(GAction::create("Beginner", { Mod_Ctrl, Key_B }, [&](const GAction&) {
auto difficulty_menu = GUI::Menu::construct("Difficulty");
difficulty_menu->add_action(GUI::Action::create("Beginner", { Mod_Ctrl, Key_B }, [&](const GUI::Action&) {
field->set_field_size(9, 9, 10);
}));
difficulty_menu->add_action(GAction::create("Intermediate", { Mod_Ctrl, Key_I }, [&](const GAction&) {
difficulty_menu->add_action(GUI::Action::create("Intermediate", { Mod_Ctrl, Key_I }, [&](const GUI::Action&) {
field->set_field_size(16, 16, 40);
}));
difficulty_menu->add_action(GAction::create("Expert", { Mod_Ctrl, Key_E }, [&](const GAction&) {
difficulty_menu->add_action(GUI::Action::create("Expert", { Mod_Ctrl, Key_E }, [&](const GUI::Action&) {
field->set_field_size(16, 30, 99);
}));
difficulty_menu->add_action(GAction::create("Madwoman", { Mod_Ctrl, Key_M }, [&](const GAction&) {
difficulty_menu->add_action(GUI::Action::create("Madwoman", { Mod_Ctrl, Key_M }, [&](const GUI::Action&) {
field->set_field_size(32, 60, 350);
}));
menubar->add_menu(move(difficulty_menu));
auto help_menu = GMenu::construct("Help");
help_menu->add_action(GAction::create("About", [&](const GAction&) {
GAboutDialog::show("Minesweeper", load_png("/res/icons/32x32/app-minesweeper.png"), window);
auto help_menu = GUI::Menu::construct("Help");
help_menu->add_action(GUI::Action::create("About", [&](const GUI::Action&) {
GUI::AboutDialog::show("Minesweeper", load_png("/res/icons/32x32/app-minesweeper.png"), window);
}));
menubar->add_menu(move(help_menu));

View file

@ -31,8 +31,8 @@
#include <stdlib.h>
#include <time.h>
SnakeGame::SnakeGame(GWidget* parent)
: GWidget(parent)
SnakeGame::SnakeGame(GUI::Widget* parent)
: GUI::Widget(parent)
{
set_font(GFontDatabase::the().get_by_name("Liza Regular"));
m_fruit_bitmaps.append(*GraphicsBitmap::load_from_file("/res/icons/snake/paprika.png"));
@ -161,7 +161,7 @@ void SnakeGame::timer_event(Core::TimerEvent&)
}
}
void SnakeGame::keydown_event(GKeyEvent& event)
void SnakeGame::keydown_event(GUI::KeyEvent& event)
{
switch (event.key()) {
case KeyCode::Key_A:
@ -205,9 +205,9 @@ Rect SnakeGame::cell_rect(const Coordinate& coord) const
};
}
void SnakeGame::paint_event(GPaintEvent& event)
void SnakeGame::paint_event(GUI::PaintEvent& event)
{
GPainter painter(*this);
GUI::Painter painter(*this);
painter.add_clip_rect(event.rect());
painter.fill_rect(event.rect(), Color::Black);

View file

@ -30,7 +30,7 @@
#include <AK/NonnullRefPtrVector.h>
#include <LibGUI/GWidget.h>
class SnakeGame : public GWidget {
class SnakeGame : public GUI::Widget {
C_OBJECT(SnakeGame)
public:
virtual ~SnakeGame() override;
@ -38,9 +38,9 @@ public:
void reset();
private:
explicit SnakeGame(GWidget* parent = nullptr);
virtual void paint_event(GPaintEvent&) override;
virtual void keydown_event(GKeyEvent&) override;
explicit SnakeGame(GUI::Widget* parent = nullptr);
virtual void paint_event(GUI::PaintEvent&) override;
virtual void keydown_event(GUI::KeyEvent&) override;
virtual void timer_event(Core::TimerEvent&) override;
struct Coordinate {

View file

@ -43,14 +43,14 @@ int main(int argc, char** argv)
return 1;
}
GApplication app(argc, argv);
GUI::Application app(argc, argv);
if (pledge("stdio rpath shared_buffer accept", nullptr) < 0) {
perror("pledge");
return 1;
}
auto window = GWindow::construct();
auto window = GUI::Window::construct();
window->set_double_buffering_enabled(false);
window->set_title("Snake");
@ -59,22 +59,22 @@ int main(int argc, char** argv)
auto game = SnakeGame::construct();
window->set_main_widget(game);
auto menubar = make<GMenuBar>();
auto menubar = make<GUI::MenuBar>();
auto app_menu = GMenu::construct("Snake");
auto app_menu = GUI::Menu::construct("Snake");
app_menu->add_action(GAction::create("New game", { Mod_None, Key_F2 }, [&](const GAction&) {
app_menu->add_action(GUI::Action::create("New game", { Mod_None, Key_F2 }, [&](const GUI::Action&) {
game->reset();
}));
app_menu->add_action(GCommonActions::make_quit_action([](auto&) {
GApplication::the().quit(0);
app_menu->add_action(GUI::CommonActions::make_quit_action([](auto&) {
GUI::Application::the().quit(0);
}));
menubar->add_menu(move(app_menu));
auto help_menu = GMenu::construct("Help");
help_menu->add_action(GAction::create("About", [&](const GAction&) {
GAboutDialog::show("Snake", load_png("/res/icons/32x32/app-snake.png"), window);
auto help_menu = GUI::Menu::construct("Help");
help_menu->add_action(GUI::Action::create("About", [&](const GUI::Action&) {
GUI::AboutDialog::show("Snake", load_png("/res/icons/32x32/app-snake.png"), window);
}));
menubar->add_menu(move(help_menu));