summaryrefslogtreecommitdiff
path: root/LibGUI
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-03-25 14:46:37 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-03-25 14:46:37 +0100
commitbe604652aef06c4fb463080020132512443f8d28 (patch)
treeddb2e6558c545ee454e0a48c8fc54f3d43f28237 /LibGUI
parent43bb7aad4c98df76c28d212d4165c9b66eec3351 (diff)
downloadserenity-be604652aef06c4fb463080020132512443f8d28.zip
LibGUI: Add GIcon::default_icon(name).
This is a convenience helper to instantiate a GIcon like so: auto icon = GIcon::default_icon("filetype-image"); This will give you the "filetype-image" icon in both 16x16 and 32x32 sizes.
Diffstat (limited to 'LibGUI')
-rw-r--r--LibGUI/GIcon.cpp7
-rw-r--r--LibGUI/GIcon.h2
2 files changed, 9 insertions, 0 deletions
diff --git a/LibGUI/GIcon.cpp b/LibGUI/GIcon.cpp
index 16224f1a97..0a2955ee7f 100644
--- a/LibGUI/GIcon.cpp
+++ b/LibGUI/GIcon.cpp
@@ -61,3 +61,10 @@ void GIconImpl::set_bitmap_for_size(int size, RetainPtr<GraphicsBitmap>&& bitmap
}
m_bitmaps.set(size, move(bitmap));
}
+
+GIcon GIcon::default_icon(const String& name)
+{
+ auto bitmap16 = GraphicsBitmap::load_from_file(String::format("/res/icons/16x16/%s.png", name.characters()));
+ auto bitmap32 = GraphicsBitmap::load_from_file(String::format("/res/icons/32x32/%s.png", name.characters()));
+ return GIcon(move(bitmap16), move(bitmap32));
+}
diff --git a/LibGUI/GIcon.h b/LibGUI/GIcon.h
index bfb48496ba..c0b3d15cdf 100644
--- a/LibGUI/GIcon.h
+++ b/LibGUI/GIcon.h
@@ -25,6 +25,8 @@ public:
GIcon(const GIcon&);
~GIcon() { }
+ static GIcon default_icon(const String&);
+
GIcon& operator=(const GIcon& other)
{
m_impl = other.m_impl.copy_ref();