1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-28 10:35:09 +00:00

tiled backgrounds no longer has strange off-by-one pixel errors

This commit is contained in:
Christopher Dumas 2019-05-26 19:36:16 -07:00 committed by Andreas Kling
parent c23882dde1
commit aa50e5bb13
9 changed files with 346 additions and 16 deletions

50
Demos/PaintTest/main.cpp Normal file
View file

@ -0,0 +1,50 @@
#include <LibGUI/GApplication.h>
#include <LibGUI/GWindow.h>
#include <LibGUI/GWidget.h>
#include <LibGUI/GPainter.h>
#include <SharedGraphics/PNGLoader.h>
class TestWidget final : public GWidget {
public:
TestWidget(GWidget* parent) : GWidget(parent) { }
virtual ~TestWidget() override { }
void set_bitmap(RetainPtr<GraphicsBitmap>&& bitmap)
{
m_bitmap = move(bitmap);
update();
}
private:
virtual void paint_event(GPaintEvent&) override
{
GPainter painter(*this);
painter.fill_rect(rect(), Color::LightGray);
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());
}
RetainPtr<GraphicsBitmap> m_bitmap;
};
int main(int argc, char** argv)
{
GApplication app(argc, argv);
auto* window = new GWindow;
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();
}