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
Notes: sideshowbarker 2024-07-19 13:53:52 +09:00
9 changed files with 346 additions and 16 deletions

View file

@ -1,6 +1,6 @@
[Screen]
Width=1920
Height=1080
Width=2560
Height=1440
[Cursor]
Arrow=/res/cursors/arrow.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

22
Demos/PaintTest/Makefile Normal file
View file

@ -0,0 +1,22 @@
include ../../Makefile.common
OBJS = \
main.o
APP = PaintTest
DEFINES += -DUSERLAND
all: $(APP)
$(APP): $(OBJS)
$(LD) -o $(APP) $(LDFLAGS) $(OBJS) -lgui -lcore -lc
.cpp.o:
@echo "CXX $<"; $(CXX) $(CXXFLAGS) -o $@ -c $<
-include $(OBJS:%.o=%.d)
clean:
@echo "CLEAN"; rm -f $(APP) $(OBJS) *.d

BIN
Demos/PaintTest/PaintTest Executable file

Binary file not shown.

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();
}

165
Demos/PaintTest/main.d Normal file
View file

@ -0,0 +1,165 @@
main.o: main.cpp /home/christopherdumas/serenity/LibGUI/GApplication.h \
/home/christopherdumas/serenity/AK/Badge.h \
/home/christopherdumas/serenity/AK/OwnPtr.h \
/home/christopherdumas/serenity/AK/StdLibExtras.h \
/home/christopherdumas/serenity/LibC/stdlib.h \
/home/christopherdumas/serenity/LibC/sys/cdefs.h \
/home/christopherdumas/serenity/LibC/sys/types.h \
/home/christopherdumas/serenity/LibC/stdint.h \
/home/christopherdumas/serenity/LibC/stddef.h \
/home/christopherdumas/serenity/LibC/string.h \
/home/christopherdumas/serenity/AK/Types.h \
/home/christopherdumas/serenity/AK/Traits.h \
/home/christopherdumas/serenity/AK/kstdio.h \
/home/christopherdumas/serenity/Kernel/kstdio.h \
/home/christopherdumas/serenity/AK/HashFunctions.h \
/home/christopherdumas/serenity/AK/HashMap.h \
/home/christopherdumas/serenity/AK/HashTable.h \
/home/christopherdumas/serenity/AK/Assertions.h \
/home/christopherdumas/serenity/LibC/assert.h \
/home/christopherdumas/serenity/AK/DoublyLinkedList.h \
/home/christopherdumas/serenity/AK/Vector.h \
/home/christopherdumas/serenity/AK/kmalloc.h \
/home/christopherdumas/serenity/LibGUI/GShortcut.h \
/home/christopherdumas/serenity/Kernel/KeyCode.h \
/home/christopherdumas/serenity/AK/AKString.h \
/home/christopherdumas/serenity/AK/ByteBuffer.h \
/home/christopherdumas/serenity/AK/Retainable.h \
/home/christopherdumas/serenity/AK/RetainPtr.h \
/home/christopherdumas/serenity/AK/Retained.h \
/home/christopherdumas/serenity/AK/StringImpl.h \
/home/christopherdumas/serenity/AK/StringView.h \
/home/christopherdumas/serenity/LibGUI/GWindow.h \
/home/christopherdumas/serenity/LibCore/CObject.h \
/home/christopherdumas/serenity/AK/Function.h \
/home/christopherdumas/serenity/AK/Weakable.h \
/home/christopherdumas/serenity/LibGUI/GWindowType.h \
/home/christopherdumas/serenity/SharedGraphics/Rect.h \
/home/christopherdumas/serenity/SharedGraphics/Point.h \
/home/christopherdumas/serenity/SharedGraphics/Size.h \
/home/christopherdumas/serenity/SharedGraphics/TextAlignment.h \
/home/christopherdumas/serenity/SharedGraphics/GraphicsBitmap.h \
/home/christopherdumas/serenity/SharedGraphics/Color.h \
/home/christopherdumas/serenity/AK/MappedFile.h \
/home/christopherdumas/serenity/LibC/SharedBuffer.h \
/home/christopherdumas/serenity/AK/WeakPtr.h \
/home/christopherdumas/serenity/LibGUI/GWidget.h \
/home/christopherdumas/serenity/LibCore/CElapsedTimer.h \
/home/christopherdumas/serenity/LibC/time.h \
/home/christopherdumas/serenity/LibGUI/GEvent.h \
/home/christopherdumas/serenity/LibCore/CEvent.h \
/home/christopherdumas/serenity/SharedGraphics/Font.h \
/home/christopherdumas/serenity/LibGUI/GPainter.h \
/home/christopherdumas/serenity/SharedGraphics/Painter.h \
/home/christopherdumas/serenity/SharedGraphics/TextElision.h \
/home/christopherdumas/serenity/SharedGraphics/PNGLoader.h
/home/christopherdumas/serenity/LibGUI/GApplication.h:
/home/christopherdumas/serenity/AK/Badge.h:
/home/christopherdumas/serenity/AK/OwnPtr.h:
/home/christopherdumas/serenity/AK/StdLibExtras.h:
/home/christopherdumas/serenity/LibC/stdlib.h:
/home/christopherdumas/serenity/LibC/sys/cdefs.h:
/home/christopherdumas/serenity/LibC/sys/types.h:
/home/christopherdumas/serenity/LibC/stdint.h:
/home/christopherdumas/serenity/LibC/stddef.h:
/home/christopherdumas/serenity/LibC/string.h:
/home/christopherdumas/serenity/AK/Types.h:
/home/christopherdumas/serenity/AK/Traits.h:
/home/christopherdumas/serenity/AK/kstdio.h:
/home/christopherdumas/serenity/Kernel/kstdio.h:
/home/christopherdumas/serenity/AK/HashFunctions.h:
/home/christopherdumas/serenity/AK/HashMap.h:
/home/christopherdumas/serenity/AK/HashTable.h:
/home/christopherdumas/serenity/AK/Assertions.h:
/home/christopherdumas/serenity/LibC/assert.h:
/home/christopherdumas/serenity/AK/DoublyLinkedList.h:
/home/christopherdumas/serenity/AK/Vector.h:
/home/christopherdumas/serenity/AK/kmalloc.h:
/home/christopherdumas/serenity/LibGUI/GShortcut.h:
/home/christopherdumas/serenity/Kernel/KeyCode.h:
/home/christopherdumas/serenity/AK/AKString.h:
/home/christopherdumas/serenity/AK/ByteBuffer.h:
/home/christopherdumas/serenity/AK/Retainable.h:
/home/christopherdumas/serenity/AK/RetainPtr.h:
/home/christopherdumas/serenity/AK/Retained.h:
/home/christopherdumas/serenity/AK/StringImpl.h:
/home/christopherdumas/serenity/AK/StringView.h:
/home/christopherdumas/serenity/LibGUI/GWindow.h:
/home/christopherdumas/serenity/LibCore/CObject.h:
/home/christopherdumas/serenity/AK/Function.h:
/home/christopherdumas/serenity/AK/Weakable.h:
/home/christopherdumas/serenity/LibGUI/GWindowType.h:
/home/christopherdumas/serenity/SharedGraphics/Rect.h:
/home/christopherdumas/serenity/SharedGraphics/Point.h:
/home/christopherdumas/serenity/SharedGraphics/Size.h:
/home/christopherdumas/serenity/SharedGraphics/TextAlignment.h:
/home/christopherdumas/serenity/SharedGraphics/GraphicsBitmap.h:
/home/christopherdumas/serenity/SharedGraphics/Color.h:
/home/christopherdumas/serenity/AK/MappedFile.h:
/home/christopherdumas/serenity/LibC/SharedBuffer.h:
/home/christopherdumas/serenity/AK/WeakPtr.h:
/home/christopherdumas/serenity/LibGUI/GWidget.h:
/home/christopherdumas/serenity/LibCore/CElapsedTimer.h:
/home/christopherdumas/serenity/LibC/time.h:
/home/christopherdumas/serenity/LibGUI/GEvent.h:
/home/christopherdumas/serenity/LibCore/CEvent.h:
/home/christopherdumas/serenity/SharedGraphics/Font.h:
/home/christopherdumas/serenity/LibGUI/GPainter.h:
/home/christopherdumas/serenity/SharedGraphics/Painter.h:
/home/christopherdumas/serenity/SharedGraphics/TextElision.h:
/home/christopherdumas/serenity/SharedGraphics/PNGLoader.h:

BIN
Demos/PaintTest/main.o Normal file

Binary file not shown.

92
Kernel/sync.sh.orig Executable file
View file

@ -0,0 +1,92 @@
#!/bin/bash
if [ "$1" = "-f" ]; then
rm -vf _fs_contents
fi
if [ $(id -u) != 0 ]; then
echo "This needs to be run as root"
exit 1
fi
rm -vf _fs_contents.lock
# If target filesystem image doesn't exist, create it.
if [ ! -f _fs_contents ]; then
dd if=/dev/zero of=_fs_contents bs=1M count=512
fi
mke2fs -F -I 128 _fs_contents
chown 1000:1000 _fs_contents
mkdir -vp mnt
mount -o loop _fs_contents mnt/
mkdir -vp mnt/bin
mkdir -vp mnt/etc
mkdir -vp mnt/proc
mkdir -vp mnt/tmp
chmod 1777 mnt/tmp
mkdir -vp mnt/dev
mkdir -vp mnt/dev/pts
mknod -m 666 mnt/dev/bxvga b 82 413
mknod mnt/dev/tty0 c 4 0
mknod mnt/dev/tty1 c 4 1
mknod mnt/dev/tty2 c 4 2
mknod mnt/dev/tty3 c 4 3
mknod mnt/dev/random c 1 8
mknod mnt/dev/null c 1 3
mknod mnt/dev/zero c 1 5
mknod mnt/dev/full c 1 7
mknod -m 666 mnt/dev/debuglog c 1 18
mknod mnt/dev/keyboard c 85 1
mknod mnt/dev/psaux c 10 1
mknod -m 666 mnt/dev/ptmx c 5 2
ln -s /proc/self/fd/0 mnt/dev/stdin
ln -s /proc/self/fd/1 mnt/dev/stdout
ln -s /proc/self/fd/2 mnt/dev/stderr
cp -vR ../Base/* mnt/
cp -vR ../Root/* mnt/
mkdir -vp mnt/home/anon
mkdir -vp mnt/home/nona
cp ../ReadMe.md mnt/home/anon/
chown -vR 100:100 mnt/home/anon
chown -vR 200:200 mnt/home/nona
find ../Userland/ -type f -executable -exec cp -v {} mnt/bin/ \;
chmod 4755 mnt/bin/su
cp -v ../Applications/Terminal/Terminal mnt/bin/Terminal
cp -v ../Applications/FontEditor/FontEditor mnt/bin/FontEditor
cp -v ../Applications/Launcher/Launcher mnt/bin/Launcher
cp -v ../Applications/FileManager/FileManager mnt/bin/FileManager
cp -v ../Applications/ProcessManager/ProcessManager mnt/bin/ProcessManager
cp -v ../Applications/About/About mnt/bin/About
cp -v ../Applications/TextEditor/TextEditor mnt/bin/TextEditor
cp -v ../Applications/IRCClient/IRCClient mnt/bin/IRCClient
ln -s IRCClient mnt/bin/irc
ln -s FileManager mnt/bin/fm
cp -v ../Servers/LookupServer/LookupServer mnt/bin/LookupServer
cp -v ../Servers/WindowServer/WindowServer mnt/bin/WindowServer
cp -v ../Applications/Taskbar/Taskbar mnt/bin/Taskbar
ln -s Taskbar mnt/bin/tb
cp -v ../Applications/Downloader/Downloader mnt/bin/Downloader
ln -s Downloader mnt/bin/dl
cp -v ../DevTools/VisualBuilder/VisualBuilder mnt/bin/VisualBuilder
ln -s VisualBuilder mnt/bin/vb
cp -v ../Games/Minesweeper/Minesweeper mnt/bin/Minesweeper
ln -s Minesweeper mnt/bin/ms
cp -v ../Games/Snake/Snake mnt/bin/Snake
ln -s Snake mnt/bin/sn
cp -v ../Shell/Shell mnt/bin/Shell
ln -s Shell mnt/bin/sh
cp -v kernel.map mnt/
cp -v ../Demos/HelloWorld/HelloWorld mnt/bin/HelloWorld
ln -s HelloWorld mnt/bin/hw
cp -v ../Demos/RetroFetch/RetroFetch mnt/bin/RetroFetch
cp -v ../Demos/WidgetGallery/WidgetGallery mnt/bin/WidgetGallery
ln -s WidgetGallery mnt/bin/wg
# Run local sync script, if it exists
if [ -f sync-local.sh ]; then
sh sync-local.sh
fi
umount mnt || ( sleep 0.5 && sync && umount mnt )

View file

@ -279,25 +279,26 @@ void Painter::blit_tiled(const Point& position, const GraphicsBitmap& source, co
auto clipped_rect = dst_rect.intersected(clip_rect());
if (clipped_rect.is_empty())
return;
const int first_row = clipped_rect.top() - dst_rect.top();
const int last_row = clipped_rect.bottom() - dst_rect.top();
const int first_column = clipped_rect.left() - dst_rect.left();
const int last_column = clipped_rect.right() - dst_rect.left();
const int first_row = (clipped_rect.top() - dst_rect.top());
const int last_row = (clipped_rect.bottom() - dst_rect.top());
const int first_column = (clipped_rect.left() - dst_rect.left());
RGBA32* dst = m_target->scanline(clipped_rect.y()) + clipped_rect.x();
const RGBA32* isrc = source.scanline(0) + src_rect.left() + first_column;
const RGBA32* src = source.scanline(src_rect.top() + first_row) + src_rect.left() + first_column;
const size_t dst_skip = m_target->pitch() / sizeof(RGBA32);
const size_t src_skip = source.pitch() / sizeof(RGBA32);
for (int row = first_row; row <= last_row; ++row) {
int y = (src - isrc) / src_skip % source.size().height();
src = y * src_skip + isrc;
for (int x = 0; x <= (last_column - first_column); ++x) {
dst[x] = src[x % source.size().width()];
if (source.format() == GraphicsBitmap::Format::RGB32 || source.format() == GraphicsBitmap::Format::RGBA32) {
int x_start = first_column + src_rect.left();
for (int row = first_row; row <= last_row; ++row) {
const RGBA32* sl = source.scanline((row + src_rect.top())
% source.size().height());
for (int x = x_start; x < clipped_rect.width() + x_start; ++x) {
dst[x - x_start] = sl[x % source.size().width()];
}
dst += dst_skip;
}
dst += dst_skip;
src += src_skip;
return;
}
ASSERT_NOT_REACHED();
}
void Painter::blit_with_alpha(const Point& position, const GraphicsBitmap& source, const Rect& src_rect)