33 lines
866 B
C
33 lines
866 B
C
|
#pragma once
|
||
|
#include <Bitmap.h>
|
||
|
#include <Rect.h>
|
||
|
#include <Application.h>
|
||
|
#include <IconUtils.h>
|
||
|
#include <SupportDefs.h>
|
||
|
#include <TypeConstants.h>
|
||
|
#include <Resources.h>
|
||
|
inline BBitmap *load_icon(int32 id, BRect rect = BRect(0, 0, 16, 16)) {
|
||
|
const void *data = NULL;
|
||
|
size_t size = 0;
|
||
|
data = BApplication::AppResources()->LoadResource(B_VECTOR_ICON_TYPE, id, &size);
|
||
|
if (data != NULL) {
|
||
|
BBitmap *icon = new BBitmap(rect, B_RGBA32);
|
||
|
if (icon->InitCheck() == B_OK && BIconUtils::GetVectorIcon((const uint8 *)data, size, icon) == B_OK) {
|
||
|
return icon;
|
||
|
} else {
|
||
|
delete icon;
|
||
|
}
|
||
|
}
|
||
|
return nullptr;
|
||
|
}
|
||
|
inline BBitmap *make_empty_icon() {
|
||
|
return new BBitmap(BRect(0, 0, 0, 0), B_RGBA32);
|
||
|
}
|
||
|
inline BBitmap *get_empty_icon() {
|
||
|
static BBitmap *empty_icon = nullptr;
|
||
|
if (empty_icon == nullptr) {
|
||
|
empty_icon = make_empty_icon();
|
||
|
}
|
||
|
return empty_icon;
|
||
|
}
|