* Applied patch by Marten Svanfeldt: the info alert icon was missing, as it's

now a vector resource.
* Changed bitmap icon to B_RGBA32 instead of B_CMAP8, use B_OP_ALPHA for
  drawing the bitmap.
* Style cleanup in the MediaAlert.cpp.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26978 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2008-08-15 11:47:28 +00:00
parent 8c74d99c63
commit 51bc54b1bf
4 changed files with 106 additions and 124 deletions
+1
View File
@@ -6,6 +6,7 @@ if ! $(TARGET_PLATFORM_HAIKU_COMPATIBLE) {
SubDirC++Flags -fmultiple-symbol-spaces ; SubDirC++Flags -fmultiple-symbol-spaces ;
} }
UseLibraryHeaders icon ;
UsePrivateHeaders media ; UsePrivateHeaders media ;
Preference Media : Preference Media :
+88 -115
View File
@@ -1,188 +1,161 @@
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ /*
// * Copyright 2003-2008 Haiku Inc.
// Copyright (c) 2003, OpenBeOS * Distributed under the terms of the MIT License.
// *
// This software is part of the OpenBeOS distribution and is covered * Authors:
// by the OpenBeOS license. * Jérôme Duval
// */
//
// File: MediaAlert.cpp
// Author: Jérôme Duval
// Description: Media Preferences
// Created : June 25, 2003
//
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
// Standard Includes -----------------------------------------------------------
#include <string.h>
// System Includes -------------------------------------------------------------
#include "MediaAlert.h" #include "MediaAlert.h"
#include <Screen.h>
#include <View.h> #include <string.h>
#include <File.h> #include <File.h>
#include <FindDirectory.h> #include <FindDirectory.h>
#include <IconUtils.h>
#include <Path.h> #include <Path.h>
#include <Resources.h> #include <Resources.h>
#include <Screen.h>
#include <View.h>
// Project Includes ------------------------------------------------------------
// Local Includes -------------------------------------------------------------- const int kWindowIconOffset = 27;
const int kIconStripeWidth = 30;
const int kTextIconOffset = kWindowIconOffset + kIconStripeWidth - 2;
const int kTextTopOffset = 6;
// Local Defines --------------------------------------------------------------- class TAlertView : public BView {
public:
TAlertView(BRect frame);
TAlertView(BMessage* archive);
~TAlertView();
// Globals --------------------------------------------------------------------- virtual void Draw(BRect updateRect);
const int kWindowIconOffset = 27; void SetBitmap(BBitmap* Icon) { fIconBitmap = Icon; }
const int kIconStripeWidth = 30; BBitmap* Bitmap() { return fIconBitmap; }
const int kTextIconOffset = kWindowIconOffset + kIconStripeWidth - 2;
const int kTextTopOffset = 6;
//------------------------------------------------------------------------------ private:
class TAlertView : public BView BBitmap* fIconBitmap;
{
public:
TAlertView(BRect frame);
TAlertView(BMessage* archive);
~TAlertView();
virtual void Draw(BRect updateRect);
void SetBitmap(BBitmap* Icon) { fIconBitmap = Icon; }
BBitmap* Bitmap() { return fIconBitmap; }
private:
BBitmap* fIconBitmap;
}; };
//------------------------------------------------------------------------------
MediaAlert::MediaAlert(BRect _rect, const char* title, const char* text) MediaAlert::MediaAlert(BRect _rect, const char* title, const char* text)
: BWindow(_rect, title, B_MODAL_WINDOW, : BWindow(_rect, title, B_MODAL_WINDOW, B_NOT_CLOSABLE | B_NOT_RESIZABLE)
B_NOT_CLOSABLE | B_NOT_RESIZABLE)
{ {
fTextView = NULL; fTextView = NULL;
// Set up the "_master_" view // Set up the "_master_" view
TAlertView* MasterView = new TAlertView(Bounds()); TAlertView* masterView = new TAlertView(Bounds());
MasterView->SetBitmap(InitIcon()); masterView->SetBitmap(InitIcon());
AddChild(MasterView); AddChild(masterView);
// Set up the text view // Set up the text view
BRect TextViewRect(kTextIconOffset, kTextTopOffset, BRect textViewRect(kTextIconOffset, kTextTopOffset,
Bounds().right, Bounds().bottom); Bounds().right, Bounds().bottom);
BRect rect = TextViewRect; BRect rect = textViewRect;
rect.OffsetTo(B_ORIGIN); rect.OffsetTo(B_ORIGIN);
rect.InsetBy(4,2); rect.InsetBy(4, 2);
fTextView = new BTextView(TextViewRect, "_tv_",
rect, fTextView = new BTextView(textViewRect, "_tv_", rect,
B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW); B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW);
fTextView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); fTextView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
fTextView->SetText(text, strlen(text)); fTextView->SetText(text, strlen(text));
fTextView->MakeEditable(false); fTextView->MakeEditable(false);
fTextView->MakeSelectable(false); fTextView->MakeSelectable(false);
fTextView->SetWordWrap(true); fTextView->SetWordWrap(true);
fTextView->SetFontAndColor(be_bold_font); fTextView->SetFontAndColor(be_bold_font);
MasterView->AddChild(fTextView); masterView->AddChild(fTextView);
BRect screenFrame = (BScreen(B_MAIN_SCREEN_ID).Frame()); BRect screenFrame = BScreen(B_MAIN_SCREEN_ID).Frame();
BPoint pt; BPoint pt;
pt.x = screenFrame.Width()/2 - Bounds().Width()/2; pt.x = screenFrame.Width() / 2 - Bounds().Width() / 2;
pt.y = screenFrame.Height()/2 - Bounds().Height()/2; pt.y = screenFrame.Height() / 2 - Bounds().Height() / 2;
if (screenFrame.Contains(pt)) if (screenFrame.Contains(pt))
MoveTo(pt); MoveTo(pt);
} }
//------------------------------------------------------------------------------
MediaAlert::~MediaAlert() MediaAlert::~MediaAlert()
{ {
} }
//------------------------------------------------------------------------------
BTextView* MediaAlert::TextView() const BTextView*
MediaAlert::TextView() const
{ {
return fTextView; return fTextView;
} }
//------------------------------------------------------------------------------
BBitmap* MediaAlert::InitIcon() BBitmap*
MediaAlert::InitIcon()
{ {
// After a bit of a search, I found the icons in app_server. =P // The alert icons are in the app_server resources
BBitmap* Icon = NULL; BBitmap* icon = NULL;
BPath Path; BPath path;
if (find_directory(B_BEOS_SERVERS_DIRECTORY, &Path) == B_OK) if (find_directory(B_BEOS_SERVERS_DIRECTORY, &path) == B_OK) {
{ path.Append("app_server");
Path.Append("app_server"); BFile file;
BFile File; if (file.SetTo(path.Path(), B_READ_ONLY) == B_OK) {
if (File.SetTo(Path.Path(), B_READ_ONLY) == B_OK) BResources resources;
{ if (resources.SetTo(&file) == B_OK) {
BResources Resources;
if (Resources.SetTo(&File) == B_OK)
{
// Which icon are we trying to load? // Which icon are we trying to load?
const char* iconName = "warn"; const char* iconName = "warn";
// Load the raw icon data // Load the raw icon data
size_t size; size_t size;
const void* rawIcon = const void* rawIcon =
Resources.LoadResource(B_LARGE_ICON_TYPE, iconName, &size); resources.LoadResource(B_VECTOR_ICON_TYPE, iconName, &size);
if (rawIcon) if (rawIcon != NULL) {
{
// Now build the bitmap // Now build the bitmap
Icon = new BBitmap(BRect(0, 0, 31, 31), B_CMAP8); icon = new BBitmap(BRect(0, 0, 31, 31), B_RGBA32);
Icon->SetBits(rawIcon, size, 0, B_CMAP8); if (BIconUtils::GetVectorIcon((const uint8*)rawIcon, size,
icon) != B_OK) {
delete icon;
return NULL;
}
} }
} }
} }
} }
return Icon; return icon;
} }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------ // #pragma mark - TAlertView
// #pragma mark -
// #pragma mark TAlertView
// #pragma mark -
//------------------------------------------------------------------------------
TAlertView::TAlertView(BRect frame) TAlertView::TAlertView(BRect frame)
: BView(frame, "TAlertView", B_FOLLOW_ALL_SIDES, B_WILL_DRAW), : BView(frame, "TAlertView", B_FOLLOW_ALL_SIDES, B_WILL_DRAW),
fIconBitmap(NULL) fIconBitmap(NULL)
{ {
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
} }
//------------------------------------------------------------------------------
TAlertView::~TAlertView() TAlertView::~TAlertView()
{ {
if (fIconBitmap) delete fIconBitmap;
{
delete fIconBitmap;
}
} }
//------------------------------------------------------------------------------
void TAlertView::Draw(BRect updateRect)
void
TAlertView::Draw(BRect updateRect)
{ {
// Here's the fun stuff // Here's the fun stuff
if (fIconBitmap) if (fIconBitmap) {
{ BRect stripeRect = Bounds();
BRect StripeRect = Bounds(); stripeRect.right = kIconStripeWidth;
StripeRect.right = kIconStripeWidth;
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);
DrawBitmapAsync(fIconBitmap, BPoint(18, 6)); DrawBitmapAsync(fIconBitmap, BPoint(18, 6));
SetDrawingMode(B_OP_COPY); SetDrawingMode(B_OP_COPY);
} }
} }
//------------------------------------------------------------------------------
+16 -9
View File
@@ -18,6 +18,7 @@
#include <StringView.h> #include <StringView.h>
#include <String.h> #include <String.h>
#include <IconUtils.h>
#include <FindDirectory.h> #include <FindDirectory.h>
#include <Resources.h> #include <Resources.h>
#include <File.h> #include <File.h>
@@ -64,7 +65,8 @@ AlertView::AlertView(BRect frame, char *name)
if (width < Bounds().Width()) if (width < Bounds().Width())
width = Bounds().Width(); width = Bounds().Width();
float height = fCountdownView->Frame().bottom + 24 + button->Bounds().Height(); float height
= fCountdownView->Frame().bottom + 24 + button->Bounds().Height();
ResizeTo(width, height); ResizeTo(width, height);
keepButton->MoveTo(Bounds().Width() - 8 - keepButton->Bounds().Width(), keepButton->MoveTo(Bounds().Width() - 8 - keepButton->Bounds().Width(),
@@ -79,7 +81,8 @@ AlertView::AlertView(BRect frame, char *name)
void void
AlertView::AttachedToWindow() AlertView::AttachedToWindow()
{ {
// the view displays a decrementing counter (until the user must take action) // the view displays a decrementing counter
// (until the user must take action)
Window()->SetPulseRate(1000000); Window()->SetPulseRate(1000000);
// every second // every second
@@ -90,7 +93,8 @@ AlertView::AttachedToWindow()
void void
AlertView::Draw(BRect updateRect) AlertView::Draw(BRect updateRect)
{ {
rgb_color dark = tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_DARKEN_1_TINT); rgb_color dark = tint_color(ui_color(B_PANEL_BACKGROUND_COLOR),
B_DARKEN_1_TINT);
SetHighColor(dark); SetHighColor(dark);
FillRect(BRect(0.0, 0.0, 30.0, Bounds().bottom)); FillRect(BRect(0.0, 0.0, 30.0, Bounds().bottom));
@@ -121,7 +125,7 @@ AlertView::KeyDown(const char* bytes, int32 numBytes)
} }
void void
AlertView::UpdateCountdownView() AlertView::UpdateCountdownView()
{ {
BString string; BString string;
@@ -142,13 +146,16 @@ AlertView::InitIcon()
BFile file; BFile file;
if (file.SetTo(path.Path(), B_READ_ONLY) == B_OK if (file.SetTo(path.Path(), B_READ_ONLY) == B_OK
&& resources.SetTo(&file) == B_OK) { && resources.SetTo(&file) == B_OK) {
// Load the raw icon data
size_t size; size_t size;
const void* data = resources.LoadResource(B_LARGE_ICON_TYPE, "warn", &size); const void* data = resources.LoadResource(B_VECTOR_ICON_TYPE,
"warn", &size);
if (data) { if (data) {
// Now build the bitmap icon = new BBitmap(BRect(0, 0, 31, 31), 0, B_RGBA32);
icon = new BBitmap(BRect(0, 0, 31, 31), 0, B_CMAP8); if (BIconUtils::GetVectorIcon((const uint8*)data, size, icon)
icon->SetBits(data, size, 0, B_CMAP8); != B_OK) {
delete icon;
icon = NULL;
}
} }
} }
} }
+1
View File
@@ -3,6 +3,7 @@ SubDir HAIKU_TOP src preferences screen ;
SetSubDirSupportedPlatformsBeOSCompatible ; SetSubDirSupportedPlatformsBeOSCompatible ;
AddSubDirSupportedPlatforms libbe_test ; AddSubDirSupportedPlatforms libbe_test ;
UseLibraryHeaders icon ;
UsePrivateHeaders [ FDirName graphics radeon ] ; UsePrivateHeaders [ FDirName graphics radeon ] ;
Preference Screen : Preference Screen :