diff options
Diffstat (limited to 'Libraries/LibDraw')
35 files changed, 300 insertions, 142 deletions
diff --git a/Libraries/LibDraw/CharacterBitmap.cpp b/Libraries/LibDraw/CharacterBitmap.cpp index 2f4c4d5880..d51ff1d080 100644 --- a/Libraries/LibDraw/CharacterBitmap.cpp +++ b/Libraries/LibDraw/CharacterBitmap.cpp @@ -26,6 +26,8 @@ #include "CharacterBitmap.h" +namespace Gfx { + CharacterBitmap::CharacterBitmap(const char* ascii_data, unsigned width, unsigned height) : m_bits(ascii_data) , m_size(width, height) @@ -40,3 +42,5 @@ NonnullRefPtr<CharacterBitmap> CharacterBitmap::create_from_ascii(const char* as { return adopt(*new CharacterBitmap(asciiData, width, height)); } + +} diff --git a/Libraries/LibDraw/CharacterBitmap.h b/Libraries/LibDraw/CharacterBitmap.h index ac7bc7b06b..0a77d123af 100644 --- a/Libraries/LibDraw/CharacterBitmap.h +++ b/Libraries/LibDraw/CharacterBitmap.h @@ -27,8 +27,10 @@ #pragma once #include "Size.h" -#include <AK/RefPtr.h> #include <AK/RefCounted.h> +#include <AK/RefPtr.h> + +namespace Gfx { class CharacterBitmap : public RefCounted<CharacterBitmap> { public: @@ -48,3 +50,5 @@ private: const char* m_bits { nullptr }; Size m_size; }; + +} diff --git a/Libraries/LibDraw/Color.h b/Libraries/LibDraw/Color.h index e851a4bbdd..395ffa4149 100644 --- a/Libraries/LibDraw/Color.h +++ b/Libraries/LibDraw/Color.h @@ -30,6 +30,8 @@ #include <AK/String.h> #include <AK/Types.h> +namespace Gfx { + enum class ColorRole; typedef u32 RGBA32; @@ -177,3 +179,7 @@ inline const LogStream& operator<<(const LogStream& stream, Color value) { return stream << value.to_string(); } + +} + +using Gfx::Color; diff --git a/Libraries/LibDraw/DisjointRectSet.cpp b/Libraries/LibDraw/DisjointRectSet.cpp index ef94b436fe..af47224f74 100644 --- a/Libraries/LibDraw/DisjointRectSet.cpp +++ b/Libraries/LibDraw/DisjointRectSet.cpp @@ -26,6 +26,8 @@ #include <LibDraw/DisjointRectSet.h> +namespace Gfx { + void DisjointRectSet::add(const Rect& new_rect) { for (auto& rect : m_rects) { @@ -69,3 +71,5 @@ void DisjointRectSet::shatter() swap(output, m_rects); } while (pass_had_intersections); } + +} diff --git a/Libraries/LibDraw/DisjointRectSet.h b/Libraries/LibDraw/DisjointRectSet.h index f0eb5d9761..9a36abb43e 100644 --- a/Libraries/LibDraw/DisjointRectSet.h +++ b/Libraries/LibDraw/DisjointRectSet.h @@ -29,6 +29,8 @@ #include <AK/Vector.h> #include <LibDraw/Rect.h> +namespace Gfx { + class DisjointRectSet { public: DisjointRectSet() {} @@ -52,3 +54,5 @@ private: Vector<Rect, 32> m_rects; }; + +} diff --git a/Libraries/LibDraw/Emoji.cpp b/Libraries/LibDraw/Emoji.cpp index 43f341b639..fe8b7e9339 100644 --- a/Libraries/LibDraw/Emoji.cpp +++ b/Libraries/LibDraw/Emoji.cpp @@ -29,9 +29,11 @@ #include <LibDraw/Emoji.h> #include <LibDraw/GraphicsBitmap.h> -static HashMap<u32, RefPtr<GraphicsBitmap>> s_emojis; +namespace Gfx { -const GraphicsBitmap* Emoji::emoji_for_codepoint(u32 codepoint) +static HashMap<u32, RefPtr<Gfx::Bitmap>> s_emojis; + +const Bitmap* Emoji::emoji_for_codepoint(u32 codepoint) { auto it = s_emojis.find(codepoint); if (it != s_emojis.end()) @@ -39,7 +41,7 @@ const GraphicsBitmap* Emoji::emoji_for_codepoint(u32 codepoint) String path = String::format("/res/emoji/U+%X.png", codepoint); - auto bitmap = GraphicsBitmap::load_from_file(path); + auto bitmap = Bitmap::load_from_file(path); if (!bitmap) { s_emojis.set(codepoint, nullptr); return nullptr; @@ -48,3 +50,5 @@ const GraphicsBitmap* Emoji::emoji_for_codepoint(u32 codepoint) s_emojis.set(codepoint, bitmap); return bitmap.ptr(); } + +} diff --git a/Libraries/LibDraw/Emoji.h b/Libraries/LibDraw/Emoji.h index a8257f08e5..094f2050d7 100644 --- a/Libraries/LibDraw/Emoji.h +++ b/Libraries/LibDraw/Emoji.h @@ -28,9 +28,13 @@ #include <AK/Types.h> -class GraphicsBitmap; +namespace Gfx { + +class Bitmap; class Emoji { public: - static const GraphicsBitmap* emoji_for_codepoint(u32 codepoint); + static const Gfx::Bitmap* emoji_for_codepoint(u32 codepoint); }; + +} diff --git a/Libraries/LibDraw/FloatPoint.h b/Libraries/LibDraw/FloatPoint.h index ecd3fb0f76..05f16c7cfc 100644 --- a/Libraries/LibDraw/FloatPoint.h +++ b/Libraries/LibDraw/FloatPoint.h @@ -26,10 +26,12 @@ #pragma once -#include <AK/String.h> #include <AK/LogStream.h> +#include <AK/String.h> #include <LibDraw/Orientation.h> +namespace Gfx { + class FloatRect; class FloatPoint { @@ -141,3 +143,7 @@ inline const LogStream& operator<<(const LogStream& stream, const FloatPoint& va { return stream << value.to_string(); } + +} + +using Gfx::FloatPoint; diff --git a/Libraries/LibDraw/FloatRect.h b/Libraries/LibDraw/FloatRect.h index 5fd4cf43ed..91ec03eee1 100644 --- a/Libraries/LibDraw/FloatRect.h +++ b/Libraries/LibDraw/FloatRect.h @@ -35,6 +35,8 @@ #include <LibDraw/TextAlignment.h> #include <math.h> +namespace Gfx { + class FloatRect { public: FloatRect() {} @@ -324,3 +326,7 @@ inline Rect enclosing_int_rect(const FloatRect& float_rect) { return { (int)float_rect.x(), (int)float_rect.y(), (int)ceilf(float_rect.width()), (int)ceilf(float_rect.height()) }; } + +} + +using Gfx::FloatRect; diff --git a/Libraries/LibDraw/FloatSize.h b/Libraries/LibDraw/FloatSize.h index f8ae8bc4d5..08376a5fc2 100644 --- a/Libraries/LibDraw/FloatSize.h +++ b/Libraries/LibDraw/FloatSize.h @@ -26,10 +26,12 @@ #pragma once -#include <AK/String.h> #include <AK/LogStream.h> +#include <AK/String.h> #include <LibDraw/Orientation.h> +namespace Gfx { + class FloatSize { public: FloatSize() {} @@ -111,3 +113,7 @@ inline const LogStream& operator<<(const LogStream& stream, const FloatSize& val { return stream << value.to_string(); } + +} + +using Gfx::FloatSize; diff --git a/Libraries/LibDraw/Font.cpp b/Libraries/LibDraw/Font.cpp index fc1c65e4f8..d8ea312793 100644 --- a/Libraries/LibDraw/Font.cpp +++ b/Libraries/LibDraw/Font.cpp @@ -25,18 +25,20 @@ */ #include "Font.h" +#include "Emoji.h" +#include "GraphicsBitmap.h" #include <AK/BufferStream.h> #include <AK/MappedFile.h> #include <AK/StdLibExtras.h> +#include <AK/Utf8View.h> #include <AK/kmalloc.h> #include <errno.h> #include <fcntl.h> -#include <sys/mman.h> #include <stdio.h> +#include <sys/mman.h> #include <unistd.h> -#include <AK/Utf8View.h> -#include "Emoji.h" -#include "GraphicsBitmap.h" + +namespace Gfx { struct [[gnu::packed]] FontFileHeader { @@ -236,3 +238,5 @@ int Font::width(const Utf8View& utf8) const return width; } + +} diff --git a/Libraries/LibDraw/Font.h b/Libraries/LibDraw/Font.h index 84d39bdbba..b164582e84 100644 --- a/Libraries/LibDraw/Font.h +++ b/Libraries/LibDraw/Font.h @@ -26,13 +26,15 @@ #pragma once -#include <AK/String.h> #include <AK/MappedFile.h> -#include <AK/RefPtr.h> #include <AK/RefCounted.h> +#include <AK/RefPtr.h> +#include <AK/String.h> #include <AK/Types.h> -#include <LibDraw/Rect.h> #include <AK/Utf8View.h> +#include <LibDraw/Rect.h> + +namespace Gfx { // FIXME: Make a MutableGlyphBitmap buddy class for FontEditor instead? class GlyphBitmap { @@ -126,3 +128,5 @@ private: bool m_fixed_width { false }; }; + +} diff --git a/Libraries/LibDraw/GIFLoader.cpp b/Libraries/LibDraw/GIFLoader.cpp index afb80f650e..2ef4ea59e8 100644 --- a/Libraries/LibDraw/GIFLoader.cpp +++ b/Libraries/LibDraw/GIFLoader.cpp @@ -31,9 +31,11 @@ #include <LibDraw/GIFLoader.h> #include <stdio.h> -static RefPtr<GraphicsBitmap> load_gif_impl(const u8*, size_t); +namespace Gfx { -RefPtr<GraphicsBitmap> load_gif(const StringView& path) +static RefPtr<Gfx::Bitmap> load_gif_impl(const u8*, size_t); + +RefPtr<Gfx::Bitmap> load_gif(const StringView& path) { MappedFile mapped_file(path); if (!mapped_file.is_valid()) @@ -44,7 +46,7 @@ RefPtr<GraphicsBitmap> load_gif(const StringView& path) return bitmap; } -RefPtr<GraphicsBitmap> load_gif_from_memory(const u8* data, size_t length) +RefPtr<Gfx::Bitmap> load_gif_from_memory(const u8* data, size_t length) { auto bitmap = load_gif_impl(data, length); if (bitmap) @@ -80,7 +82,7 @@ struct ImageDescriptor { Vector<u8> lzw_encoded_bytes; }; -RefPtr<GraphicsBitmap> load_gif_impl(const u8* data, size_t data_size) +RefPtr<Gfx::Bitmap> load_gif_impl(const u8* data, size_t data_size) { if (data_size < 32) return nullptr; @@ -259,3 +261,5 @@ RefPtr<GraphicsBitmap> load_gif_impl(const u8* data, size_t data_size) return nullptr; } + +} diff --git a/Libraries/LibDraw/GIFLoader.h b/Libraries/LibDraw/GIFLoader.h index 4360f5b7ff..06be29aa4b 100644 --- a/Libraries/LibDraw/GIFLoader.h +++ b/Libraries/LibDraw/GIFLoader.h @@ -29,8 +29,10 @@ #include <LibDraw/GraphicsBitmap.h> #include <LibDraw/ImageDecoder.h> -RefPtr<GraphicsBitmap> load_gif(const StringView& path); -RefPtr<GraphicsBitmap> load_gif_from_memory(const u8*, size_t); +namespace Gfx { + +RefPtr<Gfx::Bitmap> load_gif(const StringView& path); +RefPtr<Gfx::Bitmap> load_gif_from_memory(const u8*, size_t); struct GIFLoadingContext; @@ -40,10 +42,12 @@ public: GIFImageDecoderPlugin(const u8*, size_t); virtual Size size() override; - virtual RefPtr<GraphicsBitmap> bitmap() override; + virtual RefPtr<Gfx::Bitmap> bitmap() override; virtual void set_volatile() override; [[nodiscard]] virtual bool set_nonvolatile() override; private: OwnPtr<GIFLoadingContext> m_context; }; + +} diff --git a/Libraries/LibDraw/GraphicsBitmap.cpp b/Libraries/LibDraw/GraphicsBitmap.cpp index 0d06ee222b..7b5e00dd2b 100644 --- a/Libraries/LibDraw/GraphicsBitmap.cpp +++ b/Libraries/LibDraw/GraphicsBitmap.cpp @@ -33,17 +33,19 @@ #include <sys/mman.h> #include <unistd.h> -NonnullRefPtr<GraphicsBitmap> GraphicsBitmap::create(Format format, const Size& size) +namespace Gfx { + +NonnullRefPtr<Bitmap> Bitmap::create(Format format, const Size& size) { - return adopt(*new GraphicsBitmap(format, size, Purgeable::No)); + return adopt(*new Bitmap(format, size, Purgeable::No)); } -NonnullRefPtr<GraphicsBitmap> GraphicsBitmap::create_purgeable(Format format, const Size& size) +NonnullRefPtr<Bitmap> Bitmap::create_purgeable(Format format, const Size& size) { - return adopt(*new GraphicsBitmap(format, size, Purgeable::Yes)); + return adopt(*new Bitmap(format, size, Purgeable::Yes)); } -GraphicsBitmap::GraphicsBitmap(Format format, const Size& size, Purgeable purgeable) +Bitmap::Bitmap(Format format, const Size& size, Purgeable purgeable) : m_size(size) , m_pitch(round_up_to_power_of_two(size.width() * sizeof(RGBA32), 16)) , m_format(format) @@ -57,25 +59,25 @@ GraphicsBitmap::GraphicsBitmap(Format format, const Size& size, Purgeable purgea m_needs_munmap = true; } -NonnullRefPtr<GraphicsBitmap> GraphicsBitmap::create_wrapper(Format format, const Size& size, size_t pitch, RGBA32* data) +NonnullRefPtr<Bitmap> Bitmap::create_wrapper(Format format, const Size& size, size_t pitch, RGBA32* data) { - return adopt(*new GraphicsBitmap(format, size, pitch, data)); + return adopt(*new Bitmap(format, size, pitch, data)); } -RefPtr<GraphicsBitmap> GraphicsBitmap::load_from_file(const StringView& path) +RefPtr<Bitmap> Bitmap::load_from_file(const StringView& path) { return load_png(path); } -RefPtr<GraphicsBitmap> GraphicsBitmap::load_from_file(Format format, const StringView& path, const Size& size) +RefPtr<Bitmap> Bitmap::load_from_file(Format format, const StringView& path, const Size& size) { MappedFile mapped_file(path); if (!mapped_file.is_valid()) return nullptr; - return adopt(*new GraphicsBitmap(format, size, move(mapped_file))); + return adopt(*new Bitmap(format, size, move(mapped_file))); } -GraphicsBitmap::GraphicsBitmap(Format format, const Size& size, size_t pitch, RGBA32* data) +Bitmap::Bitmap(Format format, const Size& size, size_t pitch, RGBA32* data) : m_size(size) , m_data(data) , m_pitch(pitch) @@ -85,7 +87,7 @@ GraphicsBitmap::GraphicsBitmap(Format format, const Size& size, size_t pitch, RG m_palette = new RGBA32[256]; } -GraphicsBitmap::GraphicsBitmap(Format format, const Size& size, MappedFile&& mapped_file) +Bitmap::Bitmap(Format format, const Size& size, MappedFile&& mapped_file) : m_size(size) , m_data((RGBA32*)mapped_file.data()) , m_pitch(round_up_to_power_of_two(size.width() * sizeof(RGBA32), 16)) @@ -95,12 +97,12 @@ GraphicsBitmap::GraphicsBitmap(Format format, const Size& size, MappedFile&& map ASSERT(format != Format::Indexed8); } -NonnullRefPtr<GraphicsBitmap> GraphicsBitmap::create_with_shared_buffer(Format format, NonnullRefPtr<SharedBuffer>&& shared_buffer, const Size& size) +NonnullRefPtr<Bitmap> Bitmap::create_with_shared_buffer(Format format, NonnullRefPtr<SharedBuffer>&& shared_buffer, const Size& size) { - return adopt(*new GraphicsBitmap(format, move(shared_buffer), size)); + return adopt(*new Bitmap(format, move(shared_buffer), size)); } -GraphicsBitmap::GraphicsBitmap(Format format, NonnullRefPtr<SharedBuffer>&& shared_buffer, const Size& size) +Bitmap::Bitmap(Format format, NonnullRefPtr<SharedBuffer>&& shared_buffer, const Size& size) : m_size(size) , m_data((RGBA32*)shared_buffer->data()) , m_pitch(round_up_to_power_of_two(size.width() * sizeof(RGBA32), 16)) @@ -110,17 +112,17 @@ GraphicsBitmap::GraphicsBitmap(Format format, NonnullRefPtr<SharedBuffer>&& shar ASSERT(format != Format::Indexed8); } -NonnullRefPtr<GraphicsBitmap> GraphicsBitmap::to_shareable_bitmap() const +NonnullRefPtr<Bitmap> Bitmap::to_shareable_bitmap() const { if (m_shared_buffer) return *this; auto buffer = SharedBuffer::create_with_size(size_in_bytes()); - auto bitmap = GraphicsBitmap::create_with_shared_buffer(m_format, *buffer, m_size); + auto bitmap = Bitmap::create_with_shared_buffer(m_format, *buffer, m_size); memcpy(buffer->data(), scanline(0), size_in_bytes()); return bitmap; } -GraphicsBitmap::~GraphicsBitmap() +Bitmap::~Bitmap() { if (m_needs_munmap) { int rc = munmap(m_data, size_in_bytes()); @@ -130,22 +132,22 @@ GraphicsBitmap::~GraphicsBitmap() delete[] m_palette; } -void GraphicsBitmap::set_mmap_name(const StringView& name) +void Bitmap::set_mmap_name(const StringView& name) { ASSERT(m_needs_munmap); ::set_mmap_name(m_data, size_in_bytes(), String(name).characters()); } -void GraphicsBitmap::fill(Color color) +void Bitmap::fill(Color color) { - ASSERT(m_format == GraphicsBitmap::Format::RGB32 || m_format == GraphicsBitmap::Format::RGBA32); + ASSERT(m_format == Bitmap::Format::RGB32 || m_format == Bitmap::Format::RGBA32); for (int y = 0; y < height(); ++y) { auto* scanline = this->scanline(y); fast_u32_fill(scanline, color.value(), width()); } } -void GraphicsBitmap::set_volatile() +void Bitmap::set_volatile() { ASSERT(m_purgeable); if (m_volatile) @@ -158,7 +160,7 @@ void GraphicsBitmap::set_volatile() m_volatile = true; } -[[nodiscard]] bool GraphicsBitmap::set_nonvolatile() +[[nodiscard]] bool Bitmap::set_nonvolatile() { ASSERT(m_purgeable); if (!m_volatile) @@ -171,3 +173,5 @@ void GraphicsBitmap::set_volatile() m_volatile = false; return rc == 0; } + +} diff --git a/Libraries/LibDraw/GraphicsBitmap.h b/Libraries/LibDraw/GraphicsBitmap.h index dd3ce8805c..7c64eafd1b 100644 --- a/Libraries/LibDraw/GraphicsBitmap.h +++ b/Libraries/LibDraw/GraphicsBitmap.h @@ -36,7 +36,9 @@ #include <AK/String.h> #include <AK/StringView.h> -class GraphicsBitmap : public RefCounted<GraphicsBitmap> { +namespace Gfx { + +class Bitmap : public RefCounted<Bitmap> { public: enum class Format { Invalid, @@ -45,16 +47,16 @@ public: Indexed8 }; - static NonnullRefPtr<GraphicsBitmap> create(Format, const Size&); - static NonnullRefPtr<GraphicsBitmap> create_purgeable(Format, const Size&); - static NonnullRefPtr<GraphicsBitmap> create_wrapper(Format, const Size&, size_t pitch, RGBA32*); - static RefPtr<GraphicsBitmap> load_from_file(const StringView& path); - static RefPtr<GraphicsBitmap> load_from_file(Format, const StringView& path, const Size&); - static NonnullRefPtr<GraphicsBitmap> create_with_shared_buffer(Format, NonnullRefPtr<SharedBuffer>&&, const Size&); + static NonnullRefPtr<Bitmap> create(Format, const Size&); + static NonnullRefPtr<Bitmap> create_purgeable(Format, const Size&); + static NonnullRefPtr<Bitmap> create_wrapper(Format, const Size&, size_t pitch, RGBA32*); + static RefPtr<Bitmap> load_from_file(const StringView& path); + static RefPtr<Bitmap> load_from_file(Format, const StringView& path, const Size&); + static NonnullRefPtr<Bitmap> create_with_shared_buffer(Format, NonnullRefPtr<SharedBuffer>&&, const Size&); - NonnullRefPtr<GraphicsBitmap> to_shareable_bitmap() const; + NonnullRefPtr<Bitmap> to_shareable_bitmap() const; - ~GraphicsBitmap(); + ~Bitmap(); RGBA32* scanline(int y); const RGBA32* scanline(int y) const; @@ -137,10 +139,10 @@ public: private: enum class Purgeable { No, Yes }; - GraphicsBitmap(Format, const Size&, Purgeable); - GraphicsBitmap(Format, const Size&, size_t pitch, RGBA32*); - GraphicsBitmap(Format, const Size&, MappedFile&&); - GraphicsBitmap(Format, NonnullRefPtr<SharedBuffer>&&, const Size&); + Bitmap(Format, const Size&, Purgeable); + Bitmap(Format, const Size&, size_t pitch, RGBA32*); + Bitmap(Format, const Size&, MappedFile&&); + Bitmap(Format, NonnullRefPtr<SharedBuffer>&&, const Size&); Size m_size; RGBA32* m_data { nullptr }; @@ -154,45 +156,45 @@ private: RefPtr<SharedBuffer> m_shared_buffer; }; -inline RGBA32* GraphicsBitmap::scanline(int y) +inline RGBA32* Bitmap::scanline(int y) { return reinterpret_cast<RGBA32*>((((u8*)m_data) + (y * m_pitch))); } -inline const RGBA32* GraphicsBitmap::scanline(int y) const +inline const RGBA32* Bitmap::scanline(int y) const { return reinterpret_cast<const RGBA32*>((((const u8*)m_data) + (y * m_pitch))); } -inline const u8* GraphicsBitmap::bits(int y) const +inline const u8* Bitmap::bits(int y) const { return reinterpret_cast<const u8*>(scanline(y)); } -inline u8* GraphicsBitmap::bits(int y) +inline u8* Bitmap::bits(int y) { return reinterpret_cast<u8*>(scanline(y)); } template<> -inline Color GraphicsBitmap::get_pixel<GraphicsBitmap::Format::RGB32>(int x, int y) const +inline Color Bitmap::get_pixel<Bitmap::Format::RGB32>(int x, int y) const { return Color::from_rgb(scanline(y)[x]); } template<> -inline Color GraphicsBitmap::get_pixel<GraphicsBitmap::Format::RGBA32>(int x, int y) const +inline Color Bitmap::get_pixel<Bitmap::Format::RGBA32>(int x, int y) const { return Color::from_rgba(scanline(y)[x]); } template<> -inline Color GraphicsBitmap::get_pixel<GraphicsBitmap::Format::Indexed8>(int x, int y) const +inline Color Bitmap::get_pixel<Bitmap::Format::Indexed8>(int x, int y) const { return Color::from_rgba(m_palette[bits(y)[x]]); } -inline Color GraphicsBitmap::get_pixel(int x, int y) const +inline Color Bitmap::get_pixel(int x, int y) const { switch (m_format) { case Format::RGB32: @@ -208,18 +210,18 @@ inline Color GraphicsBitmap::get_pixel(int x, int y) const } template<> -inline void GraphicsBitmap::set_pixel<GraphicsBitmap::Format::RGB32>(int x, int y, Color color) +inline void Bitmap::set_pixel<Bitmap::Format::RGB32>(int x, int y, Color color) { scanline(y)[x] = color.value(); } template<> -inline void GraphicsBitmap::set_pixel<GraphicsBitmap::Format::RGBA32>(int x, int y, Color color) +inline void Bitmap::set_pixel<Bitmap::Format::RGBA32>(int x, int y, Color color) { scanline(y)[x] = color.value(); } -inline void GraphicsBitmap::set_pixel(int x, int y, Color color) +inline void Bitmap::set_pixel(int x, int y, Color color) { switch (m_format) { case Format::RGB32: @@ -234,3 +236,5 @@ inline void GraphicsBitmap::set_pixel(int x, int y, Color color) ASSERT_NOT_REACHED(); } } + +} diff --git a/Libraries/LibDraw/ImageDecoder.cpp b/Libraries/LibDraw/ImageDecoder.cpp index 0413783aad..aae0dbfa01 100644 --- a/Libraries/LibDraw/ImageDecoder.cpp +++ b/Libraries/LibDraw/ImageDecoder.cpp @@ -27,6 +27,8 @@ #include <LibDraw/ImageDecoder.h> #include <LibDraw/PNGLoader.h> +namespace Gfx { + ImageDecoder::ImageDecoder(const u8* data, size_t size) { m_plugin = make<PNGImageDecoderPlugin>(data, size); @@ -35,3 +37,4 @@ ImageDecoder::ImageDecoder(const u8* data, size_t size) ImageDecoder::~ImageDecoder() { } +} diff --git a/Libraries/LibDraw/ImageDecoder.h b/Libraries/LibDraw/ImageDecoder.h index 9feb29d15d..d00a90c4dd 100644 --- a/Libraries/LibDraw/ImageDecoder.h +++ b/Libraries/LibDraw/ImageDecoder.h @@ -31,14 +31,16 @@ #include <AK/RefCounted.h> #include <LibDraw/Size.h> -class GraphicsBitmap; +namespace Gfx { + +class Bitmap; class ImageDecoderPlugin { public: virtual ~ImageDecoderPlugin() {} virtual Size size() = 0; - virtual RefPtr<GraphicsBitmap> bitmap() = 0; + virtual RefPtr<Gfx::Bitmap> bitmap() = 0; virtual void set_volatile() = 0; [[nodiscard]] virtual bool set_nonvolatile() = 0; @@ -55,7 +57,7 @@ public: Size size() const { return m_plugin->size(); } int width() const { return size().width(); } int height() const { return size().height(); } - RefPtr<GraphicsBitmap> bitmap() const { return m_plugin->bitmap(); } + RefPtr<Gfx::Bitmap> bitmap() const { return m_plugin->bitmap(); } void set_volatile() { m_plugin->set_volatile(); } [[nodiscard]] bool set_nonvolatile() { return m_plugin->set_nonvolatile(); } @@ -64,3 +66,5 @@ private: mutable OwnPtr<ImageDecoderPlugin> m_plugin; }; + +} diff --git a/Libraries/LibDraw/Orientation.h b/Libraries/LibDraw/Orientation.h index 7fa33f70b5..e83af3f530 100644 --- a/Libraries/LibDraw/Orientation.h +++ b/Libraries/LibDraw/Orientation.h @@ -26,7 +26,13 @@ #pragma once +namespace Gfx { + enum class Orientation { Horizontal, Vertical }; + +} + +using Gfx::Orientation; diff --git a/Libraries/LibDraw/PNGLoader.cpp b/Libraries/LibDraw/PNGLoader.cpp index 0cc73bbbc2..68a9c585b8 100644 --- a/Libraries/LibDraw/PNGLoader.cpp +++ b/Libraries/LibDraw/PNGLoader.cpp @@ -37,6 +37,8 @@ #include <sys/stat.h> #include <unistd.h> +namespace Gfx { + static const u8 png_header[8] = { 0x89, 'P', 'N', 'G', 13, 10, 26, 10 }; struct PNG_IHDR { @@ -109,7 +111,7 @@ struct PNGLoadingContext { bool has_seen_zlib_header { false }; bool has_alpha() const { return color_type & 4 || palette_transparency_data.size() > 0; } Vector<Scanline> scanlines; - RefPtr<GraphicsBitmap> bitmap; + RefPtr<Gfx::Bitmap> bitmap; u8* decompression_buffer { nullptr }; int decompression_buffer_size { 0 }; Vector<u8> compressed_data; @@ -167,10 +169,10 @@ private: int m_size_remaining; }; -static RefPtr<GraphicsBitmap> load_png_impl(const u8*, int); +static RefPtr<Gfx::Bitmap> load_png_impl(const u8*, int); static bool process_chunk(Streamer&, PNGLoadingContext& context, bool decode_size_only); -RefPtr<GraphicsBitmap> load_png(const StringView& path) +RefPtr<Gfx::Bitmap> load_png(const StringView& path) { MappedFile mapped_file(path); if (!mapped_file.is_valid()) @@ -181,7 +183,7 @@ RefPtr<GraphicsBitmap> load_png(const StringView& path) return bitmap; } -RefPtr<GraphicsBitmap> load_png_from_memory(const u8* data, size_t length) +RefPtr<Gfx::Bitmap> load_png_from_memory(const u8* data, size_t length) { auto bitmap = load_png_impl(data, length); if (bitmap) @@ -216,7 +218,7 @@ union [[gnu::packed]] Pixel static_assert(sizeof(Pixel) == 4); template<bool has_alpha, u8 filter_type> -[[gnu::always_inline]] static inline void unfilter_impl(GraphicsBitmap& bitmap, int y, const void* dummy_scanline_data) +[[gnu::always_inline]] static inline void unfilter_impl(Gfx::Bitmap& bitmap, int y, const void* dummy_scanline_data) { auto* dummy_scanline = (const Pixel*)dummy_scanline_data; if constexpr (filter_type == 0) { @@ -517,7 +519,7 @@ static bool decode_png_bitmap(PNGLoadingContext& context) } } - context.bitmap = GraphicsBitmap::create_purgeable(context.has_alpha() ? GraphicsBitmap::Format::RGBA32 : GraphicsBitmap::Format::RGB32, { context.width, context.height }); + context.bitmap = Bitmap::create_purgeable(context.has_alpha() ? Bitmap::Format::RGBA32 : Bitmap::Format::RGB32, { context.width, context.height }); unfilter(context); @@ -529,7 +531,7 @@ static bool decode_png_bitmap(PNGLoadingContext& context) return true; } -static RefPtr<GraphicsBitmap> load_png_impl(const u8* data, int data_size) +static RefPtr<Gfx::Bitmap> load_png_impl(const u8* data, int data_size) { PNGLoadingContext context; context.data = data; @@ -687,7 +689,7 @@ Size PNGImageDecoderPlugin::size() return { m_context->width, m_context->height }; } -RefPtr<GraphicsBitmap> PNGImageDecoderPlugin::bitmap() +RefPtr<Gfx::Bitmap> PNGImageDecoderPlugin::bitmap() { if (m_context->state == PNGLoadingContext::State::Error) return nullptr; @@ -715,3 +717,5 @@ bool PNGImageDecoderPlugin::set_nonvolatile() return false; return m_context->bitmap->set_nonvolatile(); } + +} diff --git a/Libraries/LibDraw/PNGLoader.h b/Libraries/LibDraw/PNGLoader.h index 37681977a4..c3d5f8e3f8 100644 --- a/Libraries/LibDraw/PNGLoader.h +++ b/Libraries/LibDraw/PNGLoader.h @@ -29,8 +29,10 @@ #include <LibDraw/GraphicsBitmap.h> #include <LibDraw/ImageDecoder.h> -RefPtr<GraphicsBitmap> load_png(const StringView& path); -RefPtr<GraphicsBitmap> load_png_from_memory(const u8*, size_t); +namespace Gfx { + +RefPtr<Gfx::Bitmap> load_png(const StringView& path); +RefPtr<Gfx::Bitmap> load_png_from_memory(const u8*, size_t); struct PNGLoadingContext; @@ -40,10 +42,12 @@ public: PNGImageDecoderPlugin(const u8*, size_t); virtual Size size() override; - virtual RefPtr<GraphicsBitmap> bitmap() override; + virtual RefPtr<Gfx::Bitmap> bitmap() override; virtual void set_volatile() override; [[nodiscard]] virtual bool set_nonvolatile() override; private: OwnPtr<PNGLoadingContext> m_context; }; + +} diff --git a/Libraries/LibDraw/Painter.cpp b/Libraries/LibDraw/Painter.cpp index 1533f79c8f..4cc8bbc42d 100644 --- a/Libraries/LibDraw/Painter.cpp +++ b/Libraries/LibDraw/Painter.cpp @@ -49,19 +49,21 @@ #endif #endif -template<GraphicsBitmap::Format format = GraphicsBitmap::Format::Invalid> -static ALWAYS_INLINE Color get_pixel(const GraphicsBitmap& bitmap, int x, int y) +namespace Gfx { + +template<Bitmap::Format format = Bitmap::Format::Invalid> +static ALWAYS_INLINE Color get_pixel(const Gfx::Bitmap& bitmap, int x, int y) { - if constexpr (format == GraphicsBitmap::Format::Indexed8) + if constexpr (format == Bitmap::Format::Indexed8) return bitmap.palette_color(bitmap.bits(y)[x]); - if constexpr (format == GraphicsBitmap::Format::RGB32) + if constexpr (format == Bitmap::Format::RGB32) return Color::from_rgb(bitmap.scanline(y)[x]); - if constexpr (format == GraphicsBitmap::Format::RGBA32) + if constexpr (format == Bitmap::Format::RGBA32) return Color::from_rgba(bitmap.scanline(y)[x]); return bitmap.get_pixel(x, y); } -Painter::Painter(GraphicsBitmap& bitmap) +Painter::Painter(Gfx::Bitmap& bitmap) : m_target(bitmap) { m_state_stack.append(State()); @@ -286,7 +288,7 @@ void Painter::draw_bitmap(const Point& p, const GlyphBitmap& bitmap, Color color } } -void Painter::blit_scaled(const Rect& dst_rect_raw, const GraphicsBitmap& source, const Rect& src_rect, float hscale, float vscale) +void Painter::blit_scaled(const Rect& dst_rect_raw, const Gfx::Bitmap& source, const Rect& src_rect, float hscale, float vscale) { auto dst_rect = Rect(dst_rect_raw.location(), dst_rect_raw.size()).translated(translation()); auto clipped_rect = dst_rect.intersected(clip_rect()); @@ -316,7 +318,7 @@ void Painter::blit_scaled(const Rect& dst_rect_raw, const GraphicsBitmap& source return; } -void Painter::blit_with_opacity(const Point& position, const GraphicsBitmap& source, const Rect& src_rect, float opacity) +void Painter::blit_with_opacity(const Point& position, const Gfx::Bitmap& source, const Rect& src_rect, float opacity) { ASSERT(!m_target->has_alpha_channel()); @@ -354,7 +356,7 @@ void Painter::blit_with_opacity(const Point& position, const GraphicsBitmap& sou } } -void Painter::blit_dimmed(const Point& position, const GraphicsBitmap& source, const Rect& src_rect) +void Painter::blit_dimmed(const Point& position, const Gfx::Bitmap& source, const Rect& src_rect) { Rect safe_src_rect = src_rect.intersected(source.rect()); auto dst_rect = Rect(position, safe_src_rect.size()).translated(translation()); @@ -385,7 +387,7 @@ void Painter::blit_dimmed(const Point& position, const GraphicsBitmap& source, c } } -void Painter::draw_tiled_bitmap(const Rect& a_dst_rect, const GraphicsBitmap& source) +void Painter::draw_tiled_bitmap(const Rect& a_dst_rect, const Gfx::Bitmap& source) { auto dst_rect = a_dst_rect.translated(translation()); auto clipped_rect = dst_rect.intersected(clip_rect()); @@ -397,7 +399,7 @@ void Painter::draw_tiled_bitmap(const Rect& a_dst_rect, const GraphicsBitmap& so RGBA32* dst = m_target->scanline(clipped_rect.y()) + clipped_rect.x(); const size_t dst_skip = m_target->pitch() / sizeof(RGBA32); - if (source.format() == GraphicsBitmap::Format::RGB32 || source.format() == GraphicsBitmap::Format::RGBA32) { + if (source.format() == Bitmap::Format::RGB32 || source.format() == Bitmap::Format::RGBA32) { int x_start = first_column + a_dst_rect.left(); for (int row = first_row; row <= last_row; ++row) { const RGBA32* sl = source.scanline((row + a_dst_rect.top()) @@ -414,7 +416,7 @@ void Painter::draw_tiled_bitmap(const Rect& a_dst_rect, const GraphicsBitmap& so } void Painter::blit_offset(const Point& position, - const GraphicsBitmap& source, + const Gfx::Bitmap& source, const Rect& src_rect, const Point& offset) { @@ -428,7 +430,7 @@ void Painter::blit_offset(const Point& position, RGBA32* dst = m_target->scanline(clipped_rect.y()) + clipped_rect.x(); const size_t dst_skip = m_target->pitch() / sizeof(RGBA32); - if (source.format() == GraphicsBitmap::Format::RGB32 || source.format() == GraphicsBitmap::Format::RGBA32) { + if (source.format() == Bitmap::Format::RGB32 || source.format() == Bitmap::Format::RGBA32) { int x_start = first_column + src_rect.left(); for (int row = first_row; row <= last_row; ++row) { int sr = row - offset.y() + src_rect.top(); @@ -450,7 +452,7 @@ void Painter::blit_offset(const Point& position, ASSERT_NOT_REACHED(); } -void Painter::blit_with_alpha(const Point& position, const GraphicsBitmap& source, const Rect& src_rect) +void Painter::blit_with_alpha(const Point& position, const Gfx::Bitmap& source, const Rect& src_rect) { ASSERT(source.has_alpha_channel()); Rect safe_src_rect = src_rect.intersected(source.rect()); @@ -482,7 +484,7 @@ void Painter::blit_with_alpha(const Point& position, const GraphicsBitmap& sourc } } -void Painter::blit(const Point& position, const GraphicsBitmap& source, const Rect& src_rect, float opacity) +void Painter::blit(const Point& position, const Gfx::Bitmap& source, const Rect& src_rect, float opacity) { if (opacity < 1.0f) return blit_with_opacity(position, source, src_rect, opacity); @@ -500,7 +502,7 @@ void Painter::blit(const Point& position, const GraphicsBitmap& source, const Re RGBA32* dst = m_target->scanline(clipped_rect.y()) + clipped_rect.x(); const size_t dst_skip = m_target->pitch() / sizeof(RGBA32); - if (source.format() == GraphicsBitmap::Format::RGB32 || source.format() == GraphicsBitmap::Format::RGBA32) { + if (source.format() == Bitmap::Format::RGB32 || source.format() == Bitmap::Format::RGBA32) { const RGBA32* src = source.scanline(src_rect.top() + first_row) + src_rect.left() + first_column; const size_t src_skip = source.pitch() / sizeof(RGBA32); for (int row = first_row; row <= last_row; ++row) { @@ -511,7 +513,7 @@ void Painter::blit(const Point& position, const GraphicsBitmap& source, const Re return; } - if (source.format() == GraphicsBitmap::Format::Indexed8) { + if (source.format() == Bitmap::Format::Indexed8) { const u8* src = source.bits(src_rect.top() + first_row) + src_rect.left() + first_column; const size_t src_skip = source.pitch(); for (int row = first_row; row <= last_row; ++row) { @@ -527,7 +529,7 @@ void Painter::blit(const Point& position, const GraphicsBitmap& source, const Re } template<bool has_alpha_channel, typename GetPixel> -ALWAYS_INLINE static void do_draw_integer_scaled_bitmap(GraphicsBitmap& target, const Rect& dst_rect, const GraphicsBitmap& source, int hfactor, int vfactor, GetPixel get_pixel) +ALWAYS_INLINE static void do_draw_integer_scaled_bitmap(Gfx::Bitmap& target, const Rect& dst_rect, const Gfx::Bitmap& source, int hfactor, int vfactor, GetPixel get_pixel) { for (int y = source.rect().top(); y <= source.rect().bottom(); ++y) { int dst_y = dst_rect.y() + y * vfactor; @@ -548,7 +550,7 @@ ALWAYS_INLINE static void do_draw_integer_scaled_bitmap(GraphicsBitmap& target, } template<bool has_alpha_channel, typename GetPixel> -ALWAYS_INLINE static void do_draw_scaled_bitmap(GraphicsBitmap& target, const Rect& dst_rect, const Rect& clipped_rect, const GraphicsBitmap& source, const Rect& src_rect, int hscale, int vscale, GetPixel get_pixel) +ALWAYS_INLINE static void do_draw_scaled_bitmap(Gfx::Bitmap& target, const Rect& dst_rect, const Rect& clipped_rect, const Gfx::Bitmap& source, const Rect& src_rect, int hscale, int vscale, GetPixel get_pixel) { if (dst_rect == clipped_rect && !(dst_rect.width() % src_rect.width()) && !(dst_rect.height() % src_rect.height())) { int hfactor = dst_rect.width() / src_rect.width(); @@ -577,7 +579,7 @@ ALWAYS_INLINE static void do_draw_scaled_bitmap(GraphicsBitmap& target, const Re } } -void Painter::draw_scaled_bitmap(const Rect& a_dst_rect, const GraphicsBitmap& source, const Rect& src_rect) +void Painter::draw_scaled_bitmap(const Rect& a_dst_rect, const Gfx::Bitmap& source, const Rect& src_rect) { auto dst_rect = a_dst_rect; if (dst_rect.size() == src_rect.size()) @@ -595,32 +597,32 @@ void Painter::draw_scaled_bitmap(const Rect& a_dst_rect, const GraphicsBitmap& s if (source.has_alpha_channel()) { switch (source.format()) { - case GraphicsBitmap::Format::RGB32: - do_draw_scaled_bitmap<true>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<GraphicsBitmap::Format::RGB32>); + case Bitmap::Format::RGB32: + do_draw_scaled_bitmap<true>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<Bitmap::Format::RGB32>); break; - case GraphicsBitmap::Format::RGBA32: - do_draw_scaled_bitmap<true>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<GraphicsBitmap::Format::RGBA32>); + case Bitmap::Format::RGBA32: + do_draw_scaled_bitmap<true>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<Bitmap::Format::RGBA32>); break; - case GraphicsBitmap::Format::Indexed8: - do_draw_scaled_bitmap<true>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<GraphicsBitmap::Format::Indexed8>); + case Bitmap::Format::Indexed8: + do_draw_scaled_bitmap<true>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<Bitmap::Format::Indexed8>); break; default: - do_draw_scaled_bitmap<true>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<GraphicsBitmap::Format::Invalid>); + do_draw_scaled_bitmap<true>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<Bitmap::Format::Invalid>); break; } } else { switch (source.format()) { - case GraphicsBitmap::Format::RGB32: - do_draw_scaled_bitmap<false>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<GraphicsBitmap::Format::RGB32>); + case Bitmap::Format::RGB32: + do_draw_scaled_bitmap<false>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<Bitmap::Format::RGB32>); break; - case GraphicsBitmap::Format::RGBA32: - do_draw_scaled_bitmap<false>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<GraphicsBitmap::Format::RGBA32>); + case Bitmap::Format::RGBA32: + do_draw_scaled_bitmap<false>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<Bitmap::Format::RGBA32>); break; - case GraphicsBitmap::Format::Indexed8: - do_draw_scaled_bitmap<false>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<GraphicsBitmap::Format::Indexed8>); + case Bitmap::Format::Indexed8: + do_draw_scaled_bitmap<false>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<Bitmap::Format::Indexed8>); break; default: - do_draw_scaled_bitmap<false>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<GraphicsBitmap::Format::Invalid>); + do_draw_scaled_bitmap<false>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<Bitmap::Format::Invalid>); break; } } @@ -636,7 +638,7 @@ void Painter::draw_scaled_bitmap(const Rect& a_dst_rect, const GraphicsBitmap& s draw_bitmap(point, font.glyph_bitmap(ch), color); } -void Painter::draw_emoji(const Point& point, const GraphicsBitmap& emoji, const Font& font) +void Painter::draw_emoji(const Point& point, const Gfx::Bitmap& emoji, const Font& font) { if (!font.is_fixed_width()) blit(point, emoji, emoji.rect()); @@ -952,3 +954,5 @@ PainterStateSaver::~PainterStateSaver() { m_painter.restore(); } + +} diff --git a/Libraries/LibDraw/Painter.h b/Libraries/LibDraw/Painter.h index ade140241c..638ef9d30e 100644 --- a/Libraries/LibDraw/Painter.h +++ b/Libraries/LibDraw/Painter.h @@ -35,15 +35,17 @@ #include <LibDraw/TextAlignment.h> #include <LibDraw/TextElision.h> +namespace Gfx { + class CharacterBitmap; class GlyphBitmap; -class GraphicsBitmap; +class Bitmap; class Font; class Emoji; class Painter { public: - explicit Painter(GraphicsBitmap&); + explicit Painter(Gfx::Bitmap&); ~Painter(); void clear_rect(const Rect&, Color); void fill_rect(const Rect&, Color); @@ -54,17 +56,17 @@ public: void draw_ellipse_intersecting(const Rect&, Color, int thickness = 1); void set_pixel(const Point&, Color); void draw_line(const Point&, const Point&, Color, int thickness = 1, bool dotted = false); - void draw_scaled_bitmap(const Rect& dst_rect, const GraphicsBitmap&, const Rect& src_rect); - void blit(const Point&, const GraphicsBitmap&, const Rect& src_rect, float opacity = 1.0f); - void blit_dimmed(const Point&, const GraphicsBitmap&, const Rect& src_rect); - void draw_tiled_bitmap(const Rect& dst_rect, const GraphicsBitmap&); - void blit_offset(const Point&, const GraphicsBitmap&, const Rect& src_rect, const Point&); - void blit_scaled(const Rect&, const GraphicsBitmap&, const Rect&, float, float); + void draw_scaled_bitmap(const Rect& dst_rect, const Gfx::Bitmap&, const Rect& src_rect); + void blit(const Point&, const Gfx::Bitmap&, const Rect& src_rect, float opacity = 1.0f); + void blit_dimmed(const Point&, const Gfx::Bitmap&, const Rect& src_rect); + void draw_tiled_bitmap(const Rect& dst_rect, const Gfx::Bitmap&); + void blit_offset(const Point&, const Gfx::Bitmap&, const Rect& src_rect, const Point&); + void blit_scaled(const Rect&, const Gfx::Bitmap&, const Rect&, float, float); void draw_text(const Rect&, const StringView&, const Font&, TextAlignment = TextAlignment::TopLeft, Color = Color::Black, TextElision = TextElision::None); void draw_text(const Rect&, const StringView&, TextAlignment = TextAlignment::TopLeft, Color = Color::Black, TextElision = TextElision::None); void draw_glyph(const Point&, char, Color); void draw_glyph(const Point&, char, const Font&, Color); - void draw_emoji(const Point&, const GraphicsBitmap&, const Font&); + void draw_emoji(const Point&, const Gfx::Bitmap&, const Font&); void draw_glyph_or_emoji(const Point&, u32 codepoint, const Font&, Color); const Font& font() const { return *state().font; } @@ -86,7 +88,7 @@ public: Point translation() const { return state().translation; } - GraphicsBitmap* target() { return m_target.ptr(); } + Gfx::Bitmap* target() { return m_target.ptr(); } void save() { m_state_stack.append(m_state_stack.last()); } void restore() @@ -98,8 +100,8 @@ public: protected: void set_pixel_with_draw_op(u32& pixel, const Color&); void fill_rect_with_draw_op(const Rect&, Color); - void blit_with_alpha(const Point&, const GraphicsBitmap&, const Rect& src_rect); - void blit_with_opacity(const Point&, const GraphicsBitmap&, const Rect& src_rect, float opacity); + void blit_with_alpha(const Point&, const Gfx::Bitmap&, const Rect& src_rect); + void blit_with_opacity(const Point&, const Gfx::Bitmap&, const Rect& src_rect, float opacity); void draw_pixel(const Point&, Color, int thickness = 1); void draw_text_line(const Rect&, const Utf8View&, const Font&, TextAlignment, Color, TextElision); @@ -115,7 +117,7 @@ protected: const State& state() const { return m_state_stack.last(); } Rect m_clip_origin; - NonnullRefPtr<GraphicsBitmap> m_target; + NonnullRefPtr<Gfx::Bitmap> m_target; Vector<State, 4> m_state_stack; }; @@ -127,3 +129,5 @@ public: private: Painter& m_painter; }; + +} diff --git a/Libraries/LibDraw/Palette.cpp b/Libraries/LibDraw/Palette.cpp index 3356f12867..217c1c9bcf 100644 --- a/Libraries/LibDraw/Palette.cpp +++ b/Libraries/LibDraw/Palette.cpp @@ -26,6 +26,8 @@ #include <LibDraw/Palette.h> +namespace Gfx { + NonnullRefPtr<PaletteImpl> PaletteImpl::create_with_shared_buffer(SharedBuffer& buffer) { return adopt(*new PaletteImpl(buffer)); @@ -70,3 +72,5 @@ void Palette::set_color(ColorRole role, Color color) auto& theme = const_cast<SystemTheme&>(impl().theme()); theme.color[(int)role] = color; } + +} diff --git a/Libraries/LibDraw/Palette.h b/Libraries/LibDraw/Palette.h index 5c18c10263..8e05f32b5a 100644 --- a/Libraries/LibDraw/Palette.h +++ b/Libraries/LibDraw/Palette.h @@ -34,6 +34,8 @@ namespace GUI { class Application; } +namespace Gfx { + class PaletteImpl : public RefCounted<PaletteImpl> { AK_MAKE_NONCOPYABLE(PaletteImpl) AK_MAKE_NONMOVABLE(PaletteImpl) @@ -107,3 +109,7 @@ public: private: NonnullRefPtr<PaletteImpl> m_impl; }; + +} + +using Gfx::Palette; diff --git a/Libraries/LibDraw/Point.h b/Libraries/LibDraw/Point.h index b3cc0a2d82..8bdd76efbd 100644 --- a/Libraries/LibDraw/Point.h +++ b/Libraries/LibDraw/Point.h @@ -30,6 +30,8 @@ #include <AK/String.h> #include <LibDraw/Orientation.h> +namespace Gfx { + class Rect; class Point { @@ -158,3 +160,7 @@ inline const LogStream& operator<<(const LogStream& stream, const Point& value) { return stream << value.to_string(); } + +} + +using Gfx::Point; diff --git a/Libraries/LibDraw/Rect.h b/Libraries/LibDraw/Rect.h index 7acfab9a7b..3e9a1d8bfc 100644 --- a/Libraries/LibDraw/Rect.h +++ b/Libraries/LibDraw/Rect.h @@ -33,6 +33,8 @@ #include <LibDraw/Size.h> #include <LibDraw/TextAlignment.h> +namespace Gfx { + class Rect { public: Rect() {} @@ -329,3 +331,7 @@ inline const LogStream& operator<<(const LogStream& stream, const Rect& value) { return stream << value.to_string(); } + +} + +using Gfx::Rect; diff --git a/Libraries/LibDraw/Size.h b/Libraries/LibDraw/Size.h index 765b90f034..bc027617ca 100644 --- a/Libraries/LibDraw/Size.h +++ b/Libraries/LibDraw/Size.h @@ -26,10 +26,12 @@ #pragma once -#include <AK/String.h> #include <AK/LogStream.h> +#include <AK/String.h> #include <LibDraw/Orientation.h> +namespace Gfx { + class Size { public: Size() {} @@ -100,7 +102,6 @@ public: set_height(value); } - String to_string() const { return String::format("[%dx%d]", m_width, m_height); } private: @@ -112,3 +113,7 @@ inline const LogStream& operator<<(const LogStream& stream, const Size& value) { return stream << value.to_string(); } + +} + +using Gfx::Size; diff --git a/Libraries/LibDraw/StylePainter.cpp b/Libraries/LibDraw/StylePainter.cpp index 2d4198ad21..a94715c3dd 100644 --- a/Libraries/LibDraw/StylePainter.cpp +++ b/Libraries/LibDraw/StylePainter.cpp @@ -29,6 +29,8 @@ #include <LibDraw/Palette.h> #include <LibDraw/StylePainter.h> +namespace Gfx { + void StylePainter::paint_tab_button(Painter& painter, const Rect& rect, const Palette& palette, bool active, bool hovered, bool enabled) { Color base_color = palette.button(); @@ -285,12 +287,12 @@ void StylePainter::paint_progress_bar(Painter& painter, const Rect& rect, const painter.draw_text(rect.translated(0, 0), text, TextAlignment::Center, palette.base_text()); } -static RefPtr<GraphicsBitmap> s_unfilled_circle_bitmap; -static RefPtr<GraphicsBitmap> s_filled_circle_bitmap; -static RefPtr<GraphicsBitmap> s_changing_filled_circle_bitmap; -static RefPtr<GraphicsBitmap> s_changing_unfilled_circle_bitmap; +static RefPtr<Gfx::Bitmap> s_unfilled_circle_bitmap; +static RefPtr<Gfx::Bitmap> s_filled_circle_bitmap; +static RefPtr<Gfx::Bitmap> s_changing_filled_circle_bitmap; +static RefPtr<Gfx::Bitmap> s_changing_unfilled_circle_bitmap; -static const GraphicsBitmap& circle_bitmap(bool checked, bool changing) +static const Gfx::Bitmap& circle_bitmap(bool checked, bool changing) { if (changing) return checked ? *s_changing_filled_circle_bitmap : *s_changing_unfilled_circle_bitmap; @@ -300,12 +302,14 @@ static const GraphicsBitmap& circle_bitmap(bool checked, bool changing) void StylePainter::paint_radio_button(Painter& painter, const Rect& rect, const Palette&, bool is_checked, bool is_being_pressed) { if (!s_unfilled_circle_bitmap) { - s_unfilled_circle_bitmap = GraphicsBitmap::load_from_file("/res/icons/unfilled-radio-circle.png"); - s_filled_circle_bitmap = GraphicsBitmap::load_from_file("/res/icons/filled-radio-circle.png"); - s_changing_filled_circle_bitmap = GraphicsBitmap::load_from_file("/res/icons/changing-filled-radio-circle.png"); - s_changing_unfilled_circle_bitmap = GraphicsBitmap::load_from_file("/res/icons/changing-unfilled-radio-circle.png"); + s_unfilled_circle_bitmap = Bitmap::load_from_file("/res/icons/unfilled-radio-circle.png"); + s_filled_circle_bitmap = Bitmap::load_from_file("/res/icons/filled-radio-circle.png"); + s_changing_filled_circle_bitmap = Bitmap::load_from_file("/res/icons/changing-filled-radio-circle.png"); + s_changing_unfilled_circle_bitmap = Bitmap::load_from_file("/res/icons/changing-unfilled-radio-circle.png"); } auto& bitmap = circle_bitmap(is_checked, is_being_pressed); painter.blit(rect.location(), bitmap, bitmap.rect()); } + +} diff --git a/Libraries/LibDraw/StylePainter.h b/Libraries/LibDraw/StylePainter.h index 28ba3719f5..9fd7d415e7 100644 --- a/Libraries/LibDraw/StylePainter.h +++ b/Libraries/LibDraw/StylePainter.h @@ -28,6 +28,8 @@ #include <LibDraw/Color.h> +namespace Gfx { + class Painter; class Palette; class Rect; @@ -60,3 +62,5 @@ public: static void paint_progress_bar(Painter&, const Rect&, const Palette&, int min, int max, int value, const StringView& text = {}); static void paint_radio_button(Painter&, const Rect&, const Palette&, bool is_checked, bool is_being_pressed); }; + +} diff --git a/Libraries/LibDraw/SystemTheme.cpp b/Libraries/LibDraw/SystemTheme.cpp index 12538fb820..18b7922dfd 100644 --- a/Libraries/LibDraw/SystemTheme.cpp +++ b/Libraries/LibDraw/SystemTheme.cpp @@ -27,6 +27,8 @@ #include <LibCore/CConfigFile.h> #include <LibDraw/SystemTheme.h> +namespace Gfx { + static SystemTheme dummy_theme; static const SystemTheme* theme_page = &dummy_theme; static RefPtr<SharedBuffer> theme_buffer; @@ -109,3 +111,5 @@ RefPtr<SharedBuffer> load_system_theme(const String& path) return buffer; } + +} diff --git a/Libraries/LibDraw/SystemTheme.h b/Libraries/LibDraw/SystemTheme.h index 2e9bf4212b..a84afb92a1 100644 --- a/Libraries/LibDraw/SystemTheme.h +++ b/Libraries/LibDraw/SystemTheme.h @@ -30,6 +30,8 @@ #include <AK/Types.h> #include <LibDraw/Color.h> +namespace Gfx { + enum class ColorRole { NoRole, DesktopBackground, @@ -82,3 +84,7 @@ const SystemTheme& current_system_theme(); int current_system_theme_buffer_id(); void set_system_theme(SharedBuffer&); RefPtr<SharedBuffer> load_system_theme(const String& path); + +} + +using Gfx::ColorRole; diff --git a/Libraries/LibDraw/TextAlignment.h b/Libraries/LibDraw/TextAlignment.h index e1a3157267..4e527711b8 100644 --- a/Libraries/LibDraw/TextAlignment.h +++ b/Libraries/LibDraw/TextAlignment.h @@ -26,6 +26,8 @@ #pragma once +namespace Gfx { + enum class TextAlignment { TopLeft, CenterLeft, @@ -44,3 +46,5 @@ inline bool is_right_text_alignment(TextAlignment alignment) return false; } } + +} diff --git a/Libraries/LibDraw/TextElision.h b/Libraries/LibDraw/TextElision.h index d4785214c5..cf8cecc001 100644 --- a/Libraries/LibDraw/TextElision.h +++ b/Libraries/LibDraw/TextElision.h @@ -26,7 +26,11 @@ #pragma once +namespace Gfx { + enum class TextElision { None, Right, }; + +} diff --git a/Libraries/LibDraw/Triangle.h b/Libraries/LibDraw/Triangle.h index 9afb7da1f6..23aac1516e 100644 --- a/Libraries/LibDraw/Triangle.h +++ b/Libraries/LibDraw/Triangle.h @@ -26,6 +26,8 @@ #include <LibDraw/Point.h> +namespace Gfx { + class Triangle { public: Triangle(Point a, Point b, Point c) @@ -75,3 +77,5 @@ inline const LogStream& operator<<(const LogStream& stream, const Triangle& valu { return stream << value.to_string(); } + +} |