BAlert: Make use of the new BControlLook::ComposeIconSize().

While we're at it, also use DefaultLabelSpacing instead of
the icon size scaling factor.
This commit is contained in:
Augustin Cavalier
2022-08-25 16:46:35 -04:00
parent 874a2a7287
commit 56d76d9a0a
+17 -25
View File
@@ -84,20 +84,12 @@ static const int kSemTimeOut = 50000;
static const int kButtonOffsetSpacing = 62; static const int kButtonOffsetSpacing = 62;
static const int kButtonUsualWidth = 55; static const int kButtonUsualWidth = 55;
static const int kIconStripeWidth = 30; static const int kIconStripeWidthFactor = 5;
static const int kWindowMinWidth = 310; static const int kWindowMinWidth = 310;
static const int kWindowOffsetMinWidth = 335; static const int kWindowOffsetMinWidth = 335;
static inline float
icon_layout_scale()
{
float scale = be_plain_font->Size() / 12;
return max_c(1, scale);
}
// #pragma mark - // #pragma mark -
@@ -585,9 +577,8 @@ BAlert::_CreateTypeIcon()
return NULL; return NULL;
} }
int32 iconSize = (int32)(32 * icon_layout_scale());
// Allocate the icon bitmap // Allocate the icon bitmap
icon = new(std::nothrow) BBitmap(BRect(0, 0, iconSize - 1, iconSize - 1), icon = new(std::nothrow) BBitmap(BRect(BPoint(0, 0), be_control_look->ComposeIconSize(32)),
0, B_RGBA32); 0, B_RGBA32);
if (icon == NULL || icon->InitCheck() < B_OK) { if (icon == NULL || icon->InitCheck() < B_OK) {
FTRACE((stderr, "BAlert::_CreateTypeIcon() - No memory for bitmap\n")); FTRACE((stderr, "BAlert::_CreateTypeIcon() - No memory for bitmap\n"));
@@ -618,8 +609,8 @@ BAlert::_CreateTypeIcon()
// Handle color space conversion // Handle color space conversion
if (icon->ColorSpace() != B_CMAP8) { if (icon->ColorSpace() != B_CMAP8) {
BIconUtils::ConvertFromCMAP8(rawIcon, iconSize, iconSize, BIconUtils::ConvertFromCMAP8(rawIcon, B_LARGE_ICON, B_LARGE_ICON,
iconSize, icon); B_LARGE_ICON, icon);
} }
return icon; return icon;
@@ -757,20 +748,22 @@ TAlertView::Archive(BMessage* archive, bool deep) const
void void
TAlertView::GetPreferredSize(float* _width, float* _height) TAlertView::GetPreferredSize(float* _width, float* _height)
{ {
float scale = icon_layout_scale();
if (_width != NULL) { if (_width != NULL) {
if (fIconBitmap != NULL) if (fIconBitmap != NULL) {
*_width = 18 * scale + fIconBitmap->Bounds().Width(); *_width = (be_control_look->DefaultLabelSpacing() * 2)
else + fIconBitmap->Bounds().Width();
} else {
*_width = 0; *_width = 0;
} }
}
if (_height != NULL) { if (_height != NULL) {
if (fIconBitmap != NULL) if (fIconBitmap != NULL) {
*_height = 6 * scale + fIconBitmap->Bounds().Height(); *_height = be_control_look->DefaultLabelSpacing()
else + fIconBitmap->Bounds().Height();
} else {
*_height = 0; *_height = 0;
} }
}
} }
@@ -789,15 +782,14 @@ TAlertView::Draw(BRect updateRect)
// Here's the fun stuff // Here's the fun stuff
BRect stripeRect = Bounds(); BRect stripeRect = Bounds();
float iconLayoutScale = icon_layout_scale(); stripeRect.right = kIconStripeWidthFactor * be_control_look->DefaultLabelSpacing();
stripeRect.right = kIconStripeWidth * iconLayoutScale;
SetHighColor(tint_color(ViewColor(), B_DARKEN_1_TINT)); SetHighColor(tint_color(ViewColor(), B_DARKEN_1_TINT));
FillRect(stripeRect); FillRect(stripeRect);
SetDrawingMode(B_OP_ALPHA); SetDrawingMode(B_OP_ALPHA);
SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY); SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY);
DrawBitmapAsync(fIconBitmap, BPoint(18 * iconLayoutScale, DrawBitmapAsync(fIconBitmap, BPoint(be_control_look->DefaultLabelSpacing() * 3,
6 * iconLayoutScale)); be_control_look->DefaultLabelSpacing()));
} }