mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 20:28:11 +00:00
Libraries: Create top level directory for libraries.
Things were getting a little crowded in the project root, so this patch moves the Lib*/ directories into Libraries/.
This commit is contained in:
parent
63814ffebf
commit
04b9dc2d30
328 changed files with 36 additions and 36 deletions
70
Libraries/LibGUI/GIcon.cpp
Normal file
70
Libraries/LibGUI/GIcon.cpp
Normal file
|
@ -0,0 +1,70 @@
|
|||
#include <LibGUI/GIcon.h>
|
||||
|
||||
GIcon::GIcon()
|
||||
: m_impl(GIconImpl::create())
|
||||
{
|
||||
}
|
||||
|
||||
GIcon::GIcon(const GIconImpl& impl)
|
||||
: m_impl(const_cast<GIconImpl&>(impl))
|
||||
{
|
||||
}
|
||||
|
||||
GIcon::GIcon(const GIcon& other)
|
||||
: m_impl(other.m_impl.copy_ref())
|
||||
{
|
||||
}
|
||||
|
||||
GIcon::GIcon(RefPtr<GraphicsBitmap>&& bitmap)
|
||||
: GIcon()
|
||||
{
|
||||
if (bitmap) {
|
||||
ASSERT(bitmap->width() == bitmap->height());
|
||||
int size = bitmap->width();
|
||||
set_bitmap_for_size(size, move(bitmap));
|
||||
}
|
||||
}
|
||||
|
||||
GIcon::GIcon(RefPtr<GraphicsBitmap>&& bitmap1, RefPtr<GraphicsBitmap>&& bitmap2)
|
||||
: GIcon(move(bitmap1))
|
||||
{
|
||||
if (bitmap2) {
|
||||
ASSERT(bitmap2->width() == bitmap2->height());
|
||||
int size = bitmap2->width();
|
||||
set_bitmap_for_size(size, move(bitmap2));
|
||||
}
|
||||
}
|
||||
|
||||
const GraphicsBitmap* GIconImpl::bitmap_for_size(int size) const
|
||||
{
|
||||
auto it = m_bitmaps.find(size);
|
||||
if (it != m_bitmaps.end())
|
||||
return it->value.ptr();
|
||||
|
||||
int best_diff_so_far = INT32_MAX;
|
||||
const GraphicsBitmap* best_fit = nullptr;
|
||||
for (auto& it : m_bitmaps) {
|
||||
int abs_diff = abs(it.key - size);
|
||||
if (abs_diff < best_diff_so_far) {
|
||||
best_diff_so_far = abs_diff;
|
||||
best_fit = it.value.ptr();
|
||||
}
|
||||
}
|
||||
return best_fit;
|
||||
}
|
||||
|
||||
void GIconImpl::set_bitmap_for_size(int size, RefPtr<GraphicsBitmap>&& bitmap)
|
||||
{
|
||||
if (!bitmap) {
|
||||
m_bitmaps.remove(size);
|
||||
return;
|
||||
}
|
||||
m_bitmaps.set(size, move(bitmap));
|
||||
}
|
||||
|
||||
GIcon GIcon::default_icon(const StringView& 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));
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue