networkstatus: Scale icon to large and small sizes

* This gives us a nice status icon to use for
  notification messages.
This commit is contained in:
Alexander von Gluck IV
2012-03-16 04:07:42 +00:00
parent 4f3b7115be
commit e58807ed85
2 changed files with 26 additions and 12 deletions
+24 -11
View File
@@ -145,7 +145,8 @@ void
NetworkStatusView::_Init()
{
for (int i = 0; i < kStatusCount; i++) {
fBitmaps[i] = NULL;
fTrayIcons[i] = NULL;
fNotifyIcons[i] = NULL;
}
_UpdateBitmaps();
@@ -156,8 +157,10 @@ void
NetworkStatusView::_UpdateBitmaps()
{
for (int i = 0; i < kStatusCount; i++) {
delete fBitmaps[i];
fBitmaps[i] = NULL;
delete fTrayIcons[i];
delete fNotifyIcons[i];
fTrayIcons[i] = NULL;
fNotifyIcons[i] = NULL;
}
image_info info;
@@ -180,13 +183,23 @@ NetworkStatusView::_UpdateBitmaps()
data = resources.LoadResource(B_VECTOR_ICON_TYPE,
kNetworkStatusNoDevice + i, &size);
if (data != NULL) {
BBitmap* icon = new BBitmap(Bounds(), B_RGBA32);
if (icon->InitCheck() == B_OK
// Scale main tray icon
BBitmap* trayIcon = new BBitmap(Bounds(), B_RGBA32);
if (trayIcon->InitCheck() == B_OK
&& BIconUtils::GetVectorIcon((const uint8 *)data,
size, icon) == B_OK) {
fBitmaps[i] = icon;
size, trayIcon) == B_OK) {
fTrayIcons[i] = trayIcon;
} else
delete icon;
delete trayIcon;
// Scale notification icon
BBitmap* notifyIcon = new BBitmap(BRect(0, 0, 31, 31), B_RGBA32);
if (notifyIcon->InitCheck() == B_OK
&& BIconUtils::GetVectorIcon((const uint8 *)data,
size, notifyIcon) == B_OK) {
fNotifyIcons[i] = notifyIcon;
} else
delete notifyIcon;
}
}
}
@@ -313,11 +326,11 @@ NetworkStatusView::FrameResized(float width, float height)
void
NetworkStatusView::Draw(BRect updateRect)
{
if (fBitmaps[fStatus] == NULL)
if (fTrayIcons[fStatus] == NULL)
return;
SetDrawingMode(B_OP_ALPHA);
DrawBitmap(fBitmaps[fStatus]);
DrawBitmap(fTrayIcons[fStatus]);
SetDrawingMode(B_OP_COPY);
}
@@ -552,7 +565,7 @@ NetworkStatusView::_Update(bool force)
notification.SetGroup(B_TRANSLATE("Network Status"));
notification.SetTitle(interface.Name());
notification.SetMessageID(interface.Name());
notification.SetIcon(fBitmaps[fStatus]);
notification.SetIcon(fNotifyIcons[fStatus]);
if (fStatus == kStatusConnecting) {
notification.SetContent(B_TRANSLATE("Connecting..."));
notification.Send();
+2 -1
View File
@@ -59,7 +59,8 @@ class NetworkStatusView : public BView {
BObjectList<BString> fInterfaces;
bool fInDeskbar;
BBitmap* fBitmaps[kStatusCount];
BBitmap* fTrayIcons[kStatusCount];
BBitmap* fNotifyIcons[kStatusCount];
int32 fStatus;
};