diff --git a/src/preferences/media/Jamfile b/src/preferences/media/Jamfile index 6c70d3437d..ee1009ad2c 100644 --- a/src/preferences/media/Jamfile +++ b/src/preferences/media/Jamfile @@ -6,6 +6,7 @@ if ! $(TARGET_PLATFORM_HAIKU_COMPATIBLE) { SubDirC++Flags -fmultiple-symbol-spaces ; } +UseLibraryHeaders icon ; UsePrivateHeaders media ; Preference Media : diff --git a/src/preferences/media/MediaAlert.cpp b/src/preferences/media/MediaAlert.cpp index 4a0420edac..622d2d28dd 100644 --- a/src/preferences/media/MediaAlert.cpp +++ b/src/preferences/media/MediaAlert.cpp @@ -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 - -// System Includes ------------------------------------------------------------- #include "MediaAlert.h" -#include -#include + +#include #include #include +#include #include #include +#include +#include -// 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); } } -//------------------------------------------------------------------------------ - - - diff --git a/src/preferences/screen/AlertView.cpp b/src/preferences/screen/AlertView.cpp index 804bb25fc7..47fc6e0360 100644 --- a/src/preferences/screen/AlertView.cpp +++ b/src/preferences/screen/AlertView.cpp @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -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; + } } } } diff --git a/src/preferences/screen/Jamfile b/src/preferences/screen/Jamfile index 47a9e6c9bc..00b459b877 100644 --- a/src/preferences/screen/Jamfile +++ b/src/preferences/screen/Jamfile @@ -3,6 +3,7 @@ SubDir HAIKU_TOP src preferences screen ; SetSubDirSupportedPlatformsBeOSCompatible ; AddSubDirSupportedPlatforms libbe_test ; +UseLibraryHeaders icon ; UsePrivateHeaders [ FDirName graphics radeon ] ; Preference Screen :