mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 04:37:44 +00:00
LibGUI: Move Icon and FontDatabase into the GUI namespace
We also clean up some old references to the old G prefixed GUI classes This also fixes a potential bug with using: C_OBJECT_ABSTRACT(GAbstractButton) instead of C_OBJECT_ABSTRACT(AbstractButton)
This commit is contained in:
parent
57f1c919df
commit
6a3b12664a
24 changed files with 120 additions and 104 deletions
|
@ -31,7 +31,7 @@
|
|||
namespace GUI {
|
||||
|
||||
class AbstractButton : public Widget {
|
||||
C_OBJECT_ABSTRACT(GAbstractButton)
|
||||
C_OBJECT_ABSTRACT(AbstractButton)
|
||||
public:
|
||||
virtual ~AbstractButton() override;
|
||||
|
||||
|
|
|
@ -199,14 +199,14 @@ FileSystemModel::FileSystemModel(const StringView& root_path, Mode mode)
|
|||
: m_root_path(canonicalized_path(root_path))
|
||||
, m_mode(mode)
|
||||
{
|
||||
m_directory_icon = GIcon::default_icon("filetype-folder");
|
||||
m_file_icon = GIcon::default_icon("filetype-unknown");
|
||||
m_symlink_icon = GIcon::default_icon("filetype-symlink");
|
||||
m_socket_icon = GIcon::default_icon("filetype-socket");
|
||||
m_executable_icon = GIcon::default_icon("filetype-executable");
|
||||
m_filetype_image_icon = GIcon::default_icon("filetype-image");
|
||||
m_filetype_sound_icon = GIcon::default_icon("filetype-sound");
|
||||
m_filetype_html_icon = GIcon::default_icon("filetype-html");
|
||||
m_directory_icon = Icon::default_icon("filetype-folder");
|
||||
m_file_icon = Icon::default_icon("filetype-unknown");
|
||||
m_symlink_icon = Icon::default_icon("filetype-symlink");
|
||||
m_socket_icon = Icon::default_icon("filetype-socket");
|
||||
m_executable_icon = Icon::default_icon("filetype-executable");
|
||||
m_filetype_image_icon = Icon::default_icon("filetype-image");
|
||||
m_filetype_sound_icon = Icon::default_icon("filetype-sound");
|
||||
m_filetype_html_icon = Icon::default_icon("filetype-html");
|
||||
|
||||
setpwent();
|
||||
while (auto* passwd = getpwent())
|
||||
|
@ -341,7 +341,7 @@ Variant FileSystemModel::data(const ModelIndex& index, Role role) const
|
|||
auto& node = this->node(index);
|
||||
|
||||
if (role == Role::Custom) {
|
||||
// For GFileSystemModel, custom role means the full path.
|
||||
// For GUI::FileSystemModel, custom role means the full path.
|
||||
ASSERT(index.column() == Column::Name);
|
||||
return node.full_path(*this);
|
||||
}
|
||||
|
@ -409,7 +409,7 @@ Variant FileSystemModel::data(const ModelIndex& index, Role role) const
|
|||
return {};
|
||||
}
|
||||
|
||||
GIcon FileSystemModel::icon_for_file(const mode_t mode, const String& name) const
|
||||
Icon FileSystemModel::icon_for_file(const mode_t mode, const String& name) const
|
||||
{
|
||||
if (S_ISDIR(mode))
|
||||
return m_directory_icon;
|
||||
|
@ -428,14 +428,14 @@ GIcon FileSystemModel::icon_for_file(const mode_t mode, const String& name) cons
|
|||
return m_file_icon;
|
||||
}
|
||||
|
||||
GIcon FileSystemModel::icon_for(const Node& node) const
|
||||
Icon FileSystemModel::icon_for(const Node& node) const
|
||||
{
|
||||
if (node.name.to_lowercase().ends_with(".png")) {
|
||||
if (!node.thumbnail) {
|
||||
if (!const_cast<FileSystemModel*>(this)->fetch_thumbnail_for(node))
|
||||
return m_filetype_image_icon;
|
||||
}
|
||||
return GIcon(m_filetype_image_icon.bitmap_for_size(16), *node.thumbnail);
|
||||
return GUI::Icon(m_filetype_image_icon.bitmap_for_size(16), *node.thumbnail);
|
||||
}
|
||||
|
||||
return icon_for_file(node.mode, node.name);
|
||||
|
|
|
@ -109,7 +109,7 @@ public:
|
|||
ModelIndex index(const StringView& path, int column) const;
|
||||
|
||||
const Node& node(const ModelIndex& index) const;
|
||||
GIcon icon_for_file(const mode_t mode, const String& name) const;
|
||||
GUI::Icon icon_for_file(const mode_t mode, const String& name) const;
|
||||
|
||||
Function<void(int done, int total)> on_thumbnail_progress;
|
||||
Function<void()> on_root_path_change;
|
||||
|
@ -141,20 +141,20 @@ private:
|
|||
HashMap<gid_t, String> m_group_names;
|
||||
|
||||
bool fetch_thumbnail_for(const Node& node);
|
||||
GIcon icon_for(const Node& node) const;
|
||||
GUI::Icon icon_for(const Node& node) const;
|
||||
|
||||
String m_root_path;
|
||||
Mode m_mode { Invalid };
|
||||
OwnPtr<Node> m_root { nullptr };
|
||||
|
||||
GIcon m_directory_icon;
|
||||
GIcon m_file_icon;
|
||||
GIcon m_symlink_icon;
|
||||
GIcon m_socket_icon;
|
||||
GIcon m_executable_icon;
|
||||
GIcon m_filetype_image_icon;
|
||||
GIcon m_filetype_sound_icon;
|
||||
GIcon m_filetype_html_icon;
|
||||
GUI::Icon m_directory_icon;
|
||||
GUI::Icon m_file_icon;
|
||||
GUI::Icon m_symlink_icon;
|
||||
GUI::Icon m_socket_icon;
|
||||
GUI::Icon m_executable_icon;
|
||||
GUI::Icon m_filetype_image_icon;
|
||||
GUI::Icon m_filetype_sound_icon;
|
||||
GUI::Icon m_filetype_html_icon;
|
||||
|
||||
unsigned m_thumbnail_progress { 0 };
|
||||
unsigned m_thumbnail_progress_total { 0 };
|
||||
|
|
|
@ -32,16 +32,18 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static GFontDatabase* s_the;
|
||||
namespace GUI {
|
||||
|
||||
GFontDatabase& GFontDatabase::the()
|
||||
static FontDatabase* s_the;
|
||||
|
||||
FontDatabase& FontDatabase::the()
|
||||
{
|
||||
if (!s_the)
|
||||
s_the = new GFontDatabase;
|
||||
s_the = new FontDatabase;
|
||||
return *s_the;
|
||||
}
|
||||
|
||||
GFontDatabase::GFontDatabase()
|
||||
FontDatabase::FontDatabase()
|
||||
{
|
||||
Core::DirIterator di("/res/fonts", Core::DirIterator::SkipDots);
|
||||
if (di.has_error()) {
|
||||
|
@ -61,11 +63,11 @@ GFontDatabase::GFontDatabase()
|
|||
}
|
||||
}
|
||||
|
||||
GFontDatabase::~GFontDatabase()
|
||||
FontDatabase::~FontDatabase()
|
||||
{
|
||||
}
|
||||
|
||||
void GFontDatabase::for_each_font(Function<void(const StringView&)> callback)
|
||||
void FontDatabase::for_each_font(Function<void(const StringView&)> callback)
|
||||
{
|
||||
Vector<String> names;
|
||||
names.ensure_capacity(m_name_to_metadata.size());
|
||||
|
@ -76,7 +78,7 @@ void GFontDatabase::for_each_font(Function<void(const StringView&)> callback)
|
|||
callback(name);
|
||||
}
|
||||
|
||||
void GFontDatabase::for_each_fixed_width_font(Function<void(const StringView&)> callback)
|
||||
void FontDatabase::for_each_fixed_width_font(Function<void(const StringView&)> callback)
|
||||
{
|
||||
Vector<String> names;
|
||||
names.ensure_capacity(m_name_to_metadata.size());
|
||||
|
@ -89,10 +91,12 @@ void GFontDatabase::for_each_fixed_width_font(Function<void(const StringView&)>
|
|||
callback(name);
|
||||
}
|
||||
|
||||
RefPtr<Gfx::Font> GFontDatabase::get_by_name(const StringView& name)
|
||||
RefPtr<Gfx::Font> FontDatabase::get_by_name(const StringView& name)
|
||||
{
|
||||
auto it = m_name_to_metadata.find(name);
|
||||
if (it == m_name_to_metadata.end())
|
||||
return nullptr;
|
||||
return Gfx::Font::load_from_file((*it).value.path);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -31,15 +31,17 @@
|
|||
#include <AK/String.h>
|
||||
#include <LibGfx/Forward.h>
|
||||
|
||||
namespace GUI {
|
||||
|
||||
struct Metadata {
|
||||
String path;
|
||||
bool is_fixed_width;
|
||||
int glyph_height;
|
||||
};
|
||||
|
||||
class GFontDatabase {
|
||||
class FontDatabase {
|
||||
public:
|
||||
static GFontDatabase& the();
|
||||
static FontDatabase& the();
|
||||
|
||||
RefPtr<Gfx::Font> get_by_name(const StringView&);
|
||||
void for_each_font(Function<void(const StringView&)>);
|
||||
|
@ -51,8 +53,10 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
GFontDatabase();
|
||||
~GFontDatabase();
|
||||
FontDatabase();
|
||||
~FontDatabase();
|
||||
|
||||
HashMap<String, Metadata> m_name_to_metadata;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -28,23 +28,25 @@
|
|||
#include <LibGUI/Icon.h>
|
||||
#include <LibGfx/Bitmap.h>
|
||||
|
||||
GIcon::GIcon()
|
||||
: m_impl(GIconImpl::create())
|
||||
namespace GUI {
|
||||
|
||||
Icon::Icon()
|
||||
: m_impl(IconImpl::create())
|
||||
{
|
||||
}
|
||||
|
||||
GIcon::GIcon(const GIconImpl& impl)
|
||||
: m_impl(const_cast<GIconImpl&>(impl))
|
||||
Icon::Icon(const IconImpl& impl)
|
||||
: m_impl(const_cast<IconImpl&>(impl))
|
||||
{
|
||||
}
|
||||
|
||||
GIcon::GIcon(const GIcon& other)
|
||||
Icon::Icon(const Icon& other)
|
||||
: m_impl(other.m_impl)
|
||||
{
|
||||
}
|
||||
|
||||
GIcon::GIcon(RefPtr<Gfx::Bitmap>&& bitmap)
|
||||
: GIcon()
|
||||
Icon::Icon(RefPtr<Gfx::Bitmap>&& bitmap)
|
||||
: Icon()
|
||||
{
|
||||
if (bitmap) {
|
||||
ASSERT(bitmap->width() == bitmap->height());
|
||||
|
@ -53,8 +55,8 @@ GIcon::GIcon(RefPtr<Gfx::Bitmap>&& bitmap)
|
|||
}
|
||||
}
|
||||
|
||||
GIcon::GIcon(RefPtr<Gfx::Bitmap>&& bitmap1, RefPtr<Gfx::Bitmap>&& bitmap2)
|
||||
: GIcon(move(bitmap1))
|
||||
Icon::Icon(RefPtr<Gfx::Bitmap>&& bitmap1, RefPtr<Gfx::Bitmap>&& bitmap2)
|
||||
: Icon(move(bitmap1))
|
||||
{
|
||||
if (bitmap2) {
|
||||
ASSERT(bitmap2->width() == bitmap2->height());
|
||||
|
@ -63,7 +65,7 @@ GIcon::GIcon(RefPtr<Gfx::Bitmap>&& bitmap1, RefPtr<Gfx::Bitmap>&& bitmap2)
|
|||
}
|
||||
}
|
||||
|
||||
const Gfx::Bitmap* GIconImpl::bitmap_for_size(int size) const
|
||||
const Gfx::Bitmap* IconImpl::bitmap_for_size(int size) const
|
||||
{
|
||||
auto it = m_bitmaps.find(size);
|
||||
if (it != m_bitmaps.end())
|
||||
|
@ -81,7 +83,7 @@ const Gfx::Bitmap* GIconImpl::bitmap_for_size(int size) const
|
|||
return best_fit;
|
||||
}
|
||||
|
||||
void GIconImpl::set_bitmap_for_size(int size, RefPtr<Gfx::Bitmap>&& bitmap)
|
||||
void IconImpl::set_bitmap_for_size(int size, RefPtr<Gfx::Bitmap>&& bitmap)
|
||||
{
|
||||
if (!bitmap) {
|
||||
m_bitmaps.remove(size);
|
||||
|
@ -90,9 +92,11 @@ void GIconImpl::set_bitmap_for_size(int size, RefPtr<Gfx::Bitmap>&& bitmap)
|
|||
m_bitmaps.set(size, move(bitmap));
|
||||
}
|
||||
|
||||
GIcon GIcon::default_icon(const StringView& name)
|
||||
Icon Icon::default_icon(const StringView& name)
|
||||
{
|
||||
auto bitmap16 = Gfx::Bitmap::load_from_file(String::format("/res/icons/16x16/%s.png", String(name).characters()));
|
||||
auto bitmap32 = Gfx::Bitmap::load_from_file(String::format("/res/icons/32x32/%s.png", String(name).characters()));
|
||||
return GIcon(move(bitmap16), move(bitmap32));
|
||||
return Icon(move(bitmap16), move(bitmap32));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -31,31 +31,33 @@
|
|||
#include <AK/RefCounted.h>
|
||||
#include <LibGfx/Forward.h>
|
||||
|
||||
class GIconImpl : public RefCounted<GIconImpl> {
|
||||
namespace GUI {
|
||||
|
||||
class IconImpl : public RefCounted<IconImpl> {
|
||||
public:
|
||||
static NonnullRefPtr<GIconImpl> create() { return adopt(*new GIconImpl); }
|
||||
~GIconImpl() {}
|
||||
static NonnullRefPtr<IconImpl> create() { return adopt(*new IconImpl); }
|
||||
~IconImpl() {}
|
||||
|
||||
const Gfx::Bitmap* bitmap_for_size(int) const;
|
||||
void set_bitmap_for_size(int, RefPtr<Gfx::Bitmap>&&);
|
||||
|
||||
private:
|
||||
GIconImpl() {}
|
||||
IconImpl() {}
|
||||
HashMap<int, RefPtr<Gfx::Bitmap>> m_bitmaps;
|
||||
};
|
||||
|
||||
class GIcon {
|
||||
class Icon {
|
||||
public:
|
||||
GIcon();
|
||||
explicit GIcon(RefPtr<Gfx::Bitmap>&&);
|
||||
explicit GIcon(RefPtr<Gfx::Bitmap>&&, RefPtr<Gfx::Bitmap>&&);
|
||||
explicit GIcon(const GIconImpl&);
|
||||
GIcon(const GIcon&);
|
||||
~GIcon() {}
|
||||
Icon();
|
||||
explicit Icon(RefPtr<Gfx::Bitmap>&&);
|
||||
explicit Icon(RefPtr<Gfx::Bitmap>&&, RefPtr<Gfx::Bitmap>&&);
|
||||
explicit Icon(const IconImpl&);
|
||||
Icon(const Icon&);
|
||||
~Icon() {}
|
||||
|
||||
static GIcon default_icon(const StringView&);
|
||||
static Icon default_icon(const StringView&);
|
||||
|
||||
GIcon& operator=(const GIcon& other)
|
||||
Icon& operator=(const Icon& other)
|
||||
{
|
||||
if (this != &other)
|
||||
m_impl = other.m_impl;
|
||||
|
@ -65,8 +67,10 @@ public:
|
|||
const Gfx::Bitmap* bitmap_for_size(int size) const { return m_impl->bitmap_for_size(size); }
|
||||
void set_bitmap_for_size(int size, RefPtr<Gfx::Bitmap>&& bitmap) { m_impl->set_bitmap_for_size(size, move(bitmap)); }
|
||||
|
||||
const GIconImpl& impl() const { return *m_impl; }
|
||||
const IconImpl& impl() const { return *m_impl; }
|
||||
|
||||
private:
|
||||
NonnullRefPtr<GIconImpl> m_impl;
|
||||
NonnullRefPtr<IconImpl> m_impl;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ TextEditor::TextEditor(Type type)
|
|||
set_foreground_role(ColorRole::BaseText);
|
||||
set_document(TextDocument::create());
|
||||
set_scrollbars_enabled(is_multi_line());
|
||||
set_font(GFontDatabase::the().get_by_name("Csilla Thin"));
|
||||
set_font(FontDatabase::the().get_by_name("Csilla Thin"));
|
||||
// FIXME: Recompute vertical scrollbar step size on font change.
|
||||
vertical_scrollbar().set_step(line_height());
|
||||
m_cursor = { 0, 0 };
|
||||
|
|
|
@ -190,10 +190,10 @@ Variant::Variant(const Gfx::Bitmap& value)
|
|||
AK::ref_if_not_null(m_value.as_bitmap);
|
||||
}
|
||||
|
||||
Variant::Variant(const GIcon& value)
|
||||
Variant::Variant(const GUI::Icon& value)
|
||||
: m_type(Type::Icon)
|
||||
{
|
||||
m_value.as_icon = &const_cast<GIconImpl&>(value.impl());
|
||||
m_value.as_icon = &const_cast<GUI::IconImpl&>(value.impl());
|
||||
AK::ref_if_not_null(m_value.as_icon);
|
||||
}
|
||||
|
||||
|
@ -398,7 +398,7 @@ String Variant::to_string() const
|
|||
case Type::Bitmap:
|
||||
return "[Gfx::Bitmap]";
|
||||
case Type::Icon:
|
||||
return "[GIcon]";
|
||||
return "[GUI::Icon]";
|
||||
case Type::Color:
|
||||
return as_color().to_string();
|
||||
case Type::Point:
|
||||
|
|
|
@ -44,7 +44,7 @@ public:
|
|||
Variant(const char*);
|
||||
Variant(const String&);
|
||||
Variant(const Gfx::Bitmap&);
|
||||
Variant(const GIcon&);
|
||||
Variant(const GUI::Icon&);
|
||||
Variant(const Gfx::Point&);
|
||||
Variant(const Gfx::Size&);
|
||||
Variant(const Gfx::Rect&);
|
||||
|
@ -207,10 +207,10 @@ public:
|
|||
return *m_value.as_bitmap;
|
||||
}
|
||||
|
||||
GIcon as_icon() const
|
||||
GUI::Icon as_icon() const
|
||||
{
|
||||
ASSERT(type() == Type::Icon);
|
||||
return GIcon(*m_value.as_icon);
|
||||
return GUI::Icon(*m_value.as_icon);
|
||||
}
|
||||
|
||||
Color as_color() const
|
||||
|
@ -263,7 +263,7 @@ private:
|
|||
union {
|
||||
StringImpl* as_string;
|
||||
Gfx::Bitmap* as_bitmap;
|
||||
GIconImpl* as_icon;
|
||||
GUI::IconImpl* as_icon;
|
||||
Gfx::Font* as_font;
|
||||
bool as_bool;
|
||||
i32 as_i32;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue