2010-05-07 04:47:10 -05:00
|
|
|
/*
|
2011-12-03 16:38:03 -06:00
|
|
|
* Copyright 2009-2011, Andrea Anzani. All rights reserved.
|
2021-06-13 17:34:30 -05:00
|
|
|
* Copyright 2021, Jaidyn Levesque. All rights reserved.
|
2010-05-07 04:47:10 -05:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Andrea Anzani, andrea.anzani@gmail.com
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ImageCache.h"
|
|
|
|
|
|
|
|
#include <AppDefs.h>
|
|
|
|
#include <Bitmap.h>
|
|
|
|
#include <Debug.h>
|
2021-06-13 17:34:30 -05:00
|
|
|
#include <Resources.h>
|
2010-05-07 04:47:10 -05:00
|
|
|
#include <TranslationUtils.h>
|
|
|
|
|
2021-06-13 17:34:30 -05:00
|
|
|
#include <libinterface/BitmapUtils.h>
|
|
|
|
|
|
|
|
#include "CayaResources.h"
|
|
|
|
#include "CayaUtils.h"
|
|
|
|
|
|
|
|
|
2010-05-20 16:31:55 -05:00
|
|
|
ImageCache* ImageCache::fInstance = NULL;
|
2010-05-07 04:47:10 -05:00
|
|
|
|
|
|
|
|
|
|
|
ImageCache::ImageCache()
|
|
|
|
{
|
2021-06-13 17:34:30 -05:00
|
|
|
_LoadResource(kPersonIcon, "kPersonIcon");
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ImageCache::~ImageCache()
|
|
|
|
{
|
2010-05-20 16:31:55 -05:00
|
|
|
while (fBitmaps.CountItems()) {
|
|
|
|
BBitmap* bit = fBitmaps.ValueFor(0);
|
2010-05-07 04:47:10 -05:00
|
|
|
delete bit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-13 17:34:30 -05:00
|
|
|
ImageCache*
|
|
|
|
ImageCache::Get()
|
2010-05-07 04:47:10 -05:00
|
|
|
{
|
2021-06-13 17:34:30 -05:00
|
|
|
if (fInstance == NULL) {
|
2010-05-20 16:31:55 -05:00
|
|
|
fInstance = new ImageCache();
|
2021-06-13 17:34:30 -05:00
|
|
|
}
|
|
|
|
return fInstance;
|
|
|
|
}
|
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
|
2021-06-13 17:34:30 -05:00
|
|
|
BBitmap*
|
|
|
|
ImageCache::GetImage(const char* keyName)
|
|
|
|
{
|
2010-05-07 04:47:10 -05:00
|
|
|
// Loads the bitmap if found
|
|
|
|
bool found;
|
2021-06-13 17:34:30 -05:00
|
|
|
BBitmap* bitmap = fBitmaps.ValueFor(BString(keyName), &found);
|
2010-05-07 04:47:10 -05:00
|
|
|
|
2021-06-13 17:34:30 -05:00
|
|
|
if (found == true)
|
2010-05-07 04:47:10 -05:00
|
|
|
return bitmap;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
ImageCache::AddImage(BString name, BBitmap* which)
|
|
|
|
{
|
2021-06-13 17:34:30 -05:00
|
|
|
fBitmaps.AddItem(name, which);
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
ImageCache::DeleteImage(BString name)
|
|
|
|
{
|
2021-06-13 17:34:30 -05:00
|
|
|
BBitmap* bitmap = fBitmaps.ValueFor(name);
|
2010-05-20 16:31:55 -05:00
|
|
|
if (bitmap) {
|
2021-06-13 17:34:30 -05:00
|
|
|
fBitmaps.RemoveItemFor(name);
|
2010-05-07 04:47:10 -05:00
|
|
|
delete bitmap;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
ImageCache::Release()
|
|
|
|
{
|
2010-05-20 16:31:55 -05:00
|
|
|
if (fInstance != NULL) {
|
|
|
|
delete fInstance;
|
|
|
|
fInstance = NULL;
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-13 17:34:30 -05:00
|
|
|
void
|
|
|
|
ImageCache::_LoadResource(int identifier, const char* key)
|
2010-05-07 04:47:10 -05:00
|
|
|
{
|
2021-06-13 17:34:30 -05:00
|
|
|
BResources* res = CayaResources();
|
|
|
|
BBitmap* bitmap = IconFromResources(res, identifier, B_LARGE_ICON);
|
|
|
|
if (bitmap != NULL && bitmap->IsValid() == true)
|
|
|
|
fBitmaps.AddItem(BString(key), bitmap);
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|
2021-06-13 17:34:30 -05:00
|
|
|
|
|
|
|
|