* implemented loading and displaying of vector icons for

the alert bitmaps
* a little clean up



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21236 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2007-05-25 08:06:35 +00:00
parent a8745d98e9
commit 8127593e85
2 changed files with 99 additions and 56 deletions
+69 -27
View File
@@ -16,6 +16,7 @@
#include <Button.h> #include <Button.h>
#include <File.h> #include <File.h>
#include <FindDirectory.h> #include <FindDirectory.h>
#include <IconUtils.h>
#include <Invoker.h> #include <Invoker.h>
#include <Looper.h> #include <Looper.h>
#include <Message.h> #include <Message.h>
@@ -545,21 +546,41 @@ BAlert::_InitObject(const char* text, const char* button0, const char* button1,
BBitmap* BBitmap*
BAlert::_InitIcon() BAlert::_InitIcon()
{ {
// Save the desired alert type and set it to "empty" until
// loading the icon was successful
alert_type alertType = fMsgType;
fMsgType = B_EMPTY_ALERT;
// After a bit of a search, I found the icons in app_server. =P // After a bit of a search, I found the icons in app_server. =P
BBitmap* icon = NULL; BBitmap* icon = NULL;
BPath path; BPath path;
status_t status = find_directory(B_BEOS_SERVERS_DIRECTORY, &path); status_t status = find_directory(B_BEOS_SERVERS_DIRECTORY, &path);
if (status >= B_OK) { if (status < B_OK) {
FTRACE((stderr, "BAlert::_InitIcon() - find_directory failed: %s\n",
strerror(status)));
return NULL;
}
path.Append("app_server"); path.Append("app_server");
BFile file; BFile file;
status = file.SetTo(path.Path(), B_READ_ONLY); status = file.SetTo(path.Path(), B_READ_ONLY);
if (status >= B_OK) { if (status < B_OK) {
FTRACE((stderr, "BAlert::_InitIcon() - BFile init failed: %s\n",
strerror(status)));
return NULL;
}
BResources resources; BResources resources;
status = resources.SetTo(&file); status = resources.SetTo(&file);
if (status >= B_OK) { if (status < B_OK) {
FTRACE((stderr, "BAlert::_InitIcon() - BResources init failed: %s\n",
strerror(status)));
return NULL;
}
// Which icon are we trying to load? // Which icon are we trying to load?
const char* iconName = ""; // Don't want any seg faults const char* iconName = ""; // Don't want any seg faults
switch (fMsgType) { switch (alertType) {
case B_INFO_ALERT: case B_INFO_ALERT:
iconName = "info"; iconName = "info";
break; break;
@@ -579,33 +600,54 @@ BAlert::_InitIcon()
return NULL; return NULL;
} }
int32 iconSize = 32;
// Allocate the icon bitmap
icon = new (std::nothrow) BBitmap(BRect(0, 0, iconSize - 1, iconSize - 1),
0, B_RGBA32);
if (icon == NULL || icon->InitCheck() < B_OK) {
FTRACE((stderr, "BAlert::_InitIcon() - No memory for bitmap\n"));
delete icon;
return NULL;
}
// Load the raw icon data // Load the raw icon data
size_t size; size_t size = 0;
const void* rawIcon = const uint8* rawIcon;
resources.LoadResource('ICON', iconName, &size);
if (rawIcon) { #ifdef __HAIKU__
// Now build the bitmap // Try to load vector icon
icon = new (std::nothrow) BBitmap(BRect(0, 0, 31, 31), 0, B_CMAP8); rawIcon = (const uint8*)resources.LoadResource(B_VECTOR_ICON_TYPE,
if (icon != NULL) iconName, &size);
icon->SetBits(rawIcon, size, 0, B_CMAP8); if (rawIcon != NULL
} else { && BIconUtils::GetVectorIcon(rawIcon, size, icon) == B_OK) {
FTRACE((stderr, "BAlert::InitIcon() - Icon resource not found\n")); // We have an icon, restore the saved alert type
fMsgType = alertType;
return icon;
} }
} else { #endif
FTRACE((stderr, "BAlert::InitIcon() - BResources init failed: %s\n", strerror(status)));
} // Fall back to bitmap icon
} else { rawIcon = (const uint8*)resources.LoadResource(B_LARGE_ICON_TYPE,
FTRACE((stderr, "BAlert::InitIcon() - BFile init failed: %s\n", strerror(status))); iconName, &size);
} if (rawIcon == NULL) {
} else { FTRACE((stderr, "BAlert::_InitIcon() - Icon resource not found\n"));
FTRACE((stderr, "BAlert::InitIcon() - find_directory failed: %s\n", strerror(status))); delete icon;
return NULL;
} }
if (icon == NULL) { // Handle color space conversion
// If there's no icon, it's an empty alert indeed. #ifdef __HAIKU__
fMsgType = B_EMPTY_ALERT; if (icon->ColorSpace() != B_CMAP8) {
BIconUtils::ConvertFromCMAP8(rawIcon, iconSize, iconSize,
iconSize, icon);
} }
#else
icon->SetBits(rawIcon, iconSize, 0, B_CMAP8);
#endif
// We have an icon, restore the saved alert type
fMsgType = alertType;
return icon; return icon;
} }
@@ -697,9 +739,9 @@ TAlertView::Draw(BRect updateRect)
SetHighColor(tint_color(ViewColor(), B_DARKEN_1_TINT)); SetHighColor(tint_color(ViewColor(), B_DARKEN_1_TINT));
FillRect(stripeRect); FillRect(stripeRect);
SetDrawingMode(B_OP_OVER); SetDrawingMode(B_OP_ALPHA);
SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY);
DrawBitmapAsync(fIconBitmap, BPoint(18, 6)); DrawBitmapAsync(fIconBitmap, BPoint(18, 6));
SetDrawingMode(B_OP_COPY);
} }
} }
+1
View File
@@ -26,6 +26,7 @@ if ! $(HAIKU_COMPATIBLE) {
SetSubDirSupportedPlatforms haiku libbe_test ; SetSubDirSupportedPlatforms haiku libbe_test ;
UsePrivateHeaders app input interface shared tracker ; UsePrivateHeaders app input interface shared tracker ;
UseLibraryHeaders icon ;
# qoca headers # qoca headers
SubDirSysHdrs $(SUBDIR) ; SubDirSysHdrs $(SUBDIR) ;