summaryrefslogtreecommitdiff
path: root/Demos/PaintTest/main.cpp
blob: 3486c5f1861099cbb96fef702850bb64ea4e25f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <LibGUI/GApplication.h>
#include <LibGUI/GPainter.h>
#include <LibGUI/GWidget.h>
#include <LibGUI/GWindow.h>
#include <LibDraw/PNGLoader.h>

class TestWidget final : public GWidget {
public:
    TestWidget(GWidget* parent)
        : GWidget(parent)
    {
    }
    virtual ~TestWidget() override {}

    void set_bitmap(RefPtr<GraphicsBitmap>&& bitmap)
    {
        m_bitmap = move(bitmap);
        update();
    }

private:
    virtual void paint_event(GPaintEvent&) override
    {
        GPainter painter(*this);

        painter.fill_rect(rect(), Color::WarmGray);

        painter.blit_tiled({ 0, 0, 160, 160 }, *m_bitmap, m_bitmap->rect());

        painter.add_clip_rect({ 50, 50, 115, 95 });
        painter.blit_tiled({ 160, 160, 160, 160 }, *m_bitmap, m_bitmap->rect());
    }

    RefPtr<GraphicsBitmap> m_bitmap;
};

int main(int argc, char** argv)
{
    GApplication app(argc, argv);

    auto window = GWindow::construct();
    window->set_rect(100, 100, 400, 400);
    window->set_title("Paint test");

    auto* test_widget = new TestWidget(nullptr);
    window->set_main_widget(test_widget);

    test_widget->set_bitmap(load_png("/res/icons/gear16.png"));

    window->show();

    return app.exec();
}