* 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 ;
}
UseLibraryHeaders icon ;
UsePrivateHeaders media ;
Preference Media :
+88 -115
View File
@@ -1,188 +1,161 @@
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
//
// Copyright (c) 2003, OpenBeOS
//
// This software is part of the OpenBeOS distribution and is covered
// by the OpenBeOS license.
//
//
// File: MediaAlert.cpp
// Author: Jérôme Duval
// Description: Media Preferences
// Created : June 25, 2003
//
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
/*
* Copyright 2003-2008 Haiku Inc.
* Distributed under the terms of the MIT License.
*
* Authors:
* Jérôme Duval
*/
// Standard Includes -----------------------------------------------------------
#include <string.h>
// System Includes -------------------------------------------------------------
#include "MediaAlert.h"
#include <Screen.h>
#include <View.h>
#include <string.h>
#include <File.h>
#include <FindDirectory.h>
#include <IconUtils.h>
#include <Path.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;
const int kIconStripeWidth = 30;
const int kTextIconOffset = kWindowIconOffset + kIconStripeWidth - 2;
const int kTextTopOffset = 6;
void SetBitmap(BBitmap* Icon) { fIconBitmap = Icon; }
BBitmap* Bitmap() { return fIconBitmap; }
//------------------------------------------------------------------------------
class TAlertView : public BView
{
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;
private:
BBitmap* fIconBitmap;
};
//------------------------------------------------------------------------------
MediaAlert::MediaAlert(BRect _rect, const char* title, const char* text)
: BWindow(_rect, title, B_MODAL_WINDOW,
B_NOT_CLOSABLE | B_NOT_RESIZABLE)
: BWindow(_rect, title, B_MODAL_WINDOW, B_NOT_CLOSABLE | B_NOT_RESIZABLE)
{
fTextView = NULL;
// Set up the "_master_" view
TAlertView* MasterView = new TAlertView(Bounds());
MasterView->SetBitmap(InitIcon());
AddChild(MasterView);
TAlertView* masterView = new TAlertView(Bounds());
masterView->SetBitmap(InitIcon());
AddChild(masterView);
// Set up the text view
BRect TextViewRect(kTextIconOffset, kTextTopOffset,
BRect textViewRect(kTextIconOffset, kTextTopOffset,
Bounds().right, Bounds().bottom);
BRect rect = TextViewRect;
BRect rect = textViewRect;
rect.OffsetTo(B_ORIGIN);
rect.InsetBy(4,2);
fTextView = new BTextView(TextViewRect, "_tv_",
rect,
B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW);
rect.InsetBy(4, 2);
fTextView = new BTextView(textViewRect, "_tv_", rect,
B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW);
fTextView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
fTextView->SetText(text, strlen(text));
fTextView->MakeEditable(false);
fTextView->MakeSelectable(false);
fTextView->SetWordWrap(true);
fTextView->SetFontAndColor(be_bold_font);
MasterView->AddChild(fTextView);
BRect screenFrame = (BScreen(B_MAIN_SCREEN_ID).Frame());
BPoint pt;
pt.x = screenFrame.Width()/2 - Bounds().Width()/2;
pt.y = screenFrame.Height()/2 - Bounds().Height()/2;
masterView->AddChild(fTextView);
BRect screenFrame = BScreen(B_MAIN_SCREEN_ID).Frame();
BPoint pt;
pt.x = screenFrame.Width() / 2 - Bounds().Width() / 2;
pt.y = screenFrame.Height() / 2 - Bounds().Height() / 2;
if (screenFrame.Contains(pt))
MoveTo(pt);
}
//------------------------------------------------------------------------------
MediaAlert::~MediaAlert()
{
}
//------------------------------------------------------------------------------
BTextView* MediaAlert::TextView() const
BTextView*
MediaAlert::TextView() const
{
return fTextView;
}
//------------------------------------------------------------------------------
BBitmap* MediaAlert::InitIcon()
BBitmap*
MediaAlert::InitIcon()
{
// After a bit of a search, I found the icons in app_server. =P
BBitmap* Icon = NULL;
BPath Path;
if (find_directory(B_BEOS_SERVERS_DIRECTORY, &Path) == B_OK)
{
Path.Append("app_server");
BFile File;
if (File.SetTo(Path.Path(), B_READ_ONLY) == B_OK)
{
BResources Resources;
if (Resources.SetTo(&File) == B_OK)
{
// The alert icons are in the app_server resources
BBitmap* icon = NULL;
BPath path;
if (find_directory(B_BEOS_SERVERS_DIRECTORY, &path) == B_OK) {
path.Append("app_server");
BFile file;
if (file.SetTo(path.Path(), B_READ_ONLY) == B_OK) {
BResources resources;
if (resources.SetTo(&file) == B_OK) {
// Which icon are we trying to load?
const char* iconName = "warn";
// Load the raw icon data
size_t size;
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
Icon = new BBitmap(BRect(0, 0, 31, 31), B_CMAP8);
Icon->SetBits(rawIcon, size, 0, B_CMAP8);
icon = new BBitmap(BRect(0, 0, 31, 31), B_RGBA32);
if (BIconUtils::GetVectorIcon((const uint8*)rawIcon, size,
icon) != B_OK) {
delete icon;
return NULL;
}
}
}
}
}
return Icon;
return icon;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// #pragma mark -
// #pragma mark TAlertView
// #pragma mark -
//------------------------------------------------------------------------------
// #pragma mark - TAlertView
TAlertView::TAlertView(BRect frame)
: BView(frame, "TAlertView", B_FOLLOW_ALL_SIDES, B_WILL_DRAW),
fIconBitmap(NULL)
: BView(frame, "TAlertView", B_FOLLOW_ALL_SIDES, B_WILL_DRAW),
fIconBitmap(NULL)
{
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
}
//------------------------------------------------------------------------------
TAlertView::~TAlertView()
{
if (fIconBitmap)
{
delete fIconBitmap;
}
delete fIconBitmap;
}
//------------------------------------------------------------------------------
void TAlertView::Draw(BRect updateRect)
void
TAlertView::Draw(BRect updateRect)
{
// Here's the fun stuff
if (fIconBitmap)
{
BRect StripeRect = Bounds();
StripeRect.right = kIconStripeWidth;
if (fIconBitmap) {
BRect stripeRect = Bounds();
stripeRect.right = kIconStripeWidth;
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));
SetDrawingMode(B_OP_COPY);
}
}
//------------------------------------------------------------------------------
+16 -9
View File
@@ -18,6 +18,7 @@
#include <StringView.h>
#include <String.h>
#include <IconUtils.h>
#include <FindDirectory.h>
#include <Resources.h>
#include <File.h>
@@ -64,7 +65,8 @@ AlertView::AlertView(BRect frame, char *name)
if (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);
keepButton->MoveTo(Bounds().Width() - 8 - keepButton->Bounds().Width(),
@@ -79,7 +81,8 @@ AlertView::AlertView(BRect frame, char *name)
void
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);
// every second
@@ -90,7 +93,8 @@ AlertView::AttachedToWindow()
void
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);
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()
{
BString string;
@@ -142,13 +146,16 @@ AlertView::InitIcon()
BFile file;
if (file.SetTo(path.Path(), B_READ_ONLY) == B_OK
&& resources.SetTo(&file) == B_OK) {
// Load the raw icon data
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) {
// Now build the bitmap
icon = new BBitmap(BRect(0, 0, 31, 31), 0, B_CMAP8);
icon->SetBits(data, size, 0, B_CMAP8);
icon = new BBitmap(BRect(0, 0, 31, 31), 0, B_RGBA32);
if (BIconUtils::GetVectorIcon((const uint8*)data, size, icon)
!= B_OK) {
delete icon;
icon = NULL;
}
}
}
}
+1
View File
@@ -3,6 +3,7 @@ SubDir HAIKU_TOP src preferences screen ;
SetSubDirSupportedPlatformsBeOSCompatible ;
AddSubDirSupportedPlatforms libbe_test ;
UseLibraryHeaders icon ;
UsePrivateHeaders [ FDirName graphics radeon ] ;
Preference Screen :