Tracker: Use BControlLook::ComposeIconSize.

One computation was functionally equivalent to the new method,
other places were not scaling icons at all.

Fixes #13177.
This commit is contained in:
Augustin Cavalier
2022-08-25 16:48:56 -04:00
parent 56d76d9a0a
commit 3efde1bfba
5 changed files with 48 additions and 43 deletions
+1 -4
View File
@@ -69,11 +69,8 @@ class IconMenuItem : public PositionPassingMenuItem {
virtual void DrawContent(); virtual void DrawContent();
virtual void SetMarked(bool mark); virtual void SetMarked(bool mark);
private:
virtual void SetIcon(BBitmap* icon); virtual void SetIcon(BBitmap* icon);
BBitmap* Icon() const { return fDeviceIcon; };
virtual void SetIconSize(icon_size which) { fWhich = which; };
icon_size IconSize() const { return fWhich; };
private: private:
BBitmap* fDeviceIcon; BBitmap* fDeviceIcon;
+15 -13
View File
@@ -112,7 +112,7 @@ namespace BPrivate {
class DraggableContainerIcon : public BView { class DraggableContainerIcon : public BView {
public: public:
DraggableContainerIcon(); DraggableContainerIcon(BSize iconSize);
virtual void MouseDown(BPoint where); virtual void MouseDown(BPoint where);
virtual void MouseUp(BPoint); virtual void MouseUp(BPoint);
@@ -120,6 +120,7 @@ class DraggableContainerIcon : public BView {
virtual void Draw(BRect updateRect); virtual void Draw(BRect updateRect);
private: private:
BSize fIconSize;
uint32 fDragButton; uint32 fDragButton;
BPoint fClickPoint; BPoint fClickPoint;
bool fDragStarted; bool fDragStarted;
@@ -386,12 +387,15 @@ AddMimeTypeString(BStringList& list, Model* model)
// #pragma mark - DraggableContainerIcon // #pragma mark - DraggableContainerIcon
DraggableContainerIcon::DraggableContainerIcon() DraggableContainerIcon::DraggableContainerIcon(BSize iconSize)
: :
BView("DraggableContainerIcon", B_WILL_DRAW), BView("DraggableContainerIcon", B_WILL_DRAW),
fIconSize(iconSize),
fDragButton(0), fDragButton(0),
fDragStarted(false) fDragStarted(false)
{ {
SetExplicitMinSize(BSize(iconSize.Width() + 5, iconSize.Height()));
SetExplicitMaxSize(BSize(iconSize.Width() + 5, B_SIZE_UNSET));
} }
@@ -410,7 +414,7 @@ DraggableContainerIcon::MouseDown(BPoint where)
window->CurrentMessage()->FindInt32("buttons", (int32*)&buttons); window->CurrentMessage()->FindInt32("buttons", (int32*)&buttons);
if (IconCache::sIconCache->IconHitTest(where, window->TargetModel(), if (IconCache::sIconCache->IconHitTest(where, window->TargetModel(),
kNormalIcon, B_MINI_ICON)) { kNormalIcon, (icon_size)(fIconSize.IntegerWidth() + 1))) {
// The click hit the icon, initiate a drag // The click hit the icon, initiate a drag
fDragButton = buttons fDragButton = buttons
& (B_PRIMARY_MOUSE_BUTTON | B_SECONDARY_MOUSE_BUTTON); & (B_PRIMARY_MOUSE_BUTTON | B_SECONDARY_MOUSE_BUTTON);
@@ -483,7 +487,7 @@ DraggableContainerIcon::MouseMoved(BPoint where, uint32, const BMessage*)
// Draw the icon // Draw the icon
float hIconOffset = (rect.Width() - Bounds().Width()) / 2; float hIconOffset = (rect.Width() - Bounds().Width()) / 2;
IconCache::sIconCache->Draw(model, view, BPoint(hIconOffset, 0), IconCache::sIconCache->Draw(model, view, BPoint(hIconOffset, 0),
kNormalIcon, B_MINI_ICON, true); kNormalIcon, (icon_size)(fIconSize.IntegerWidth() + 1), true);
// See if we need to truncate the string // See if we need to truncate the string
BString nameString = model->Name(); BString nameString = model->Name();
@@ -542,10 +546,11 @@ DraggableContainerIcon::Draw(BRect updateRect)
// Draw the icon, straddling the border // Draw the icon, straddling the border
SetDrawingMode(B_OP_ALPHA); SetDrawingMode(B_OP_ALPHA);
SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY); SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY);
float iconOffsetX = (Bounds().Width() - B_MINI_ICON) / 2; float iconOffsetX = (Bounds().Width() - fIconSize.Width()) / 2;
float iconOffsetY = (Bounds().Height() - B_MINI_ICON) / 2; float iconOffsetY = (Bounds().Height() - fIconSize.Height()) / 2;
IconCache::sIconCache->Draw(window->TargetModel(), this, IconCache::sIconCache->Draw(window->TargetModel(), this,
BPoint(iconOffsetX, iconOffsetY), kNormalIcon, B_MINI_ICON, true); BPoint(iconOffsetX, iconOffsetY), kNormalIcon, (icon_size)(fIconSize.IntegerWidth() + 1),
true);
} }
@@ -3412,13 +3417,10 @@ BContainerWindow::_AddFolderIcon()
if (iconSize < 16) if (iconSize < 16)
iconSize = 16; iconSize = 16;
fDraggableIcon = new(std::nothrow) DraggableContainerIcon(); fDraggableIcon = new(std::nothrow)
DraggableContainerIcon(be_control_look->ComposeIconSize(iconSize));
if (fDraggableIcon != NULL) { if (fDraggableIcon != NULL) {
BLayoutItem* item = fMenuContainer->GroupLayout()->AddView( fMenuContainer->GroupLayout()->AddView(fDraggableIcon);
fDraggableIcon);
item->SetExplicitMinSize(BSize(iconSize + 5, iconSize));
item->SetExplicitMaxSize(BSize(iconSize + 5, item->MaxSize().Height()));
fMenuBar->SetBorders( fMenuBar->SetBorders(
BControlLook::B_ALL_BORDERS & ~BControlLook::B_RIGHT_BORDER); BControlLook::B_ALL_BORDERS & ~BControlLook::B_RIGHT_BORDER);
} }
+20 -15
View File
@@ -126,7 +126,7 @@ ModelMenuItem::DrawContent()
{ {
if (fDrawText) { if (fDrawText) {
BPoint drawPoint(ContentLocation()); BPoint drawPoint(ContentLocation());
drawPoint.x += ListIconSize() + ListIconSize() / 4 drawPoint.x += ListIconSize() + (ListIconSize() / 4)
+ (fExtraPad ? 6 : 0); + (fExtraPad ? 6 : 0);
if (fHeightDelta > 0) if (fHeightDelta > 0)
drawPoint.y += ceil(fHeightDelta / 2); drawPoint.y += ceil(fHeightDelta / 2);
@@ -181,7 +181,8 @@ void
ModelMenuItem::GetContentSize(float* width, float* height) ModelMenuItem::GetContentSize(float* width, float* height)
{ {
_inherited::GetContentSize(width, height); _inherited::GetContentSize(width, height);
float iconSize = ListIconSize();
const float iconSize = ListIconSize();
fHeightDelta = iconSize - *height; fHeightDelta = iconSize - *height;
if (*height < iconSize) if (*height < iconSize)
*height = iconSize; *height = iconSize;
@@ -280,10 +281,11 @@ IconMenuItem::IconMenuItem(const char* label, BMessage* message,
fWhich(which) fWhich(which)
{ {
if (nodeInfo != NULL) { if (nodeInfo != NULL) {
fDeviceIcon = new BBitmap(BRect(0, 0, which - 1, which - 1), fDeviceIcon = new BBitmap(BRect(BPoint(0, 0), be_control_look->ComposeIconSize(which)),
kDefaultIconDepth); kDefaultIconDepth);
if (nodeInfo->GetTrackerIcon(fDeviceIcon, B_MINI_ICON) != B_OK) { const icon_size size = (icon_size)(fDeviceIcon->Bounds().IntegerWidth() + 1);
if (nodeInfo->GetTrackerIcon(fDeviceIcon, size) != B_OK) {
delete fDeviceIcon; delete fDeviceIcon;
fDeviceIcon = NULL; fDeviceIcon = NULL;
} }
@@ -304,7 +306,7 @@ IconMenuItem::IconMenuItem(const char* label, BMessage* message,
fWhich(which) fWhich(which)
{ {
BMimeType mime(iconType); BMimeType mime(iconType);
fDeviceIcon = new BBitmap(BRect(0, 0, which - 1, which - 1), fDeviceIcon = new BBitmap(BRect(BPoint(0, 0), be_control_look->ComposeIconSize(which)),
kDefaultIconDepth); kDefaultIconDepth);
if (mime.GetIcon(fDeviceIcon, which) != B_OK) { if (mime.GetIcon(fDeviceIcon, which) != B_OK) {
@@ -331,7 +333,7 @@ IconMenuItem::IconMenuItem(BMenu* submenu, BMessage* message,
fWhich(which) fWhich(which)
{ {
BMimeType mime(iconType); BMimeType mime(iconType);
fDeviceIcon = new BBitmap(BRect(0, 0, which - 1, which - 1), fDeviceIcon = new BBitmap(BRect(BPoint(0, 0), be_control_look->ComposeIconSize(which)),
kDefaultIconDepth); kDefaultIconDepth);
if (mime.GetIcon(fDeviceIcon, which) != B_OK) { if (mime.GetIcon(fDeviceIcon, which) != B_OK) {
@@ -359,7 +361,7 @@ IconMenuItem::IconMenuItem(BMessage* data)
if (data != NULL) { if (data != NULL) {
fWhich = (icon_size)data->GetInt32("_which", B_MINI_ICON); fWhich = (icon_size)data->GetInt32("_which", B_MINI_ICON);
fDeviceIcon = new BBitmap(BRect(0, 0, fWhich - 1, fWhich - 1), fDeviceIcon = new BBitmap(BRect(BPoint(0, 0), be_control_look->ComposeIconSize(fWhich)),
kDefaultIconDepth); kDefaultIconDepth);
if (data->HasData("_deviceIconBits", B_RAW_TYPE)) { if (data->HasData("_deviceIconBits", B_RAW_TYPE)) {
@@ -417,9 +419,13 @@ IconMenuItem::GetContentSize(float* width, float* height)
{ {
_inherited::GetContentSize(width, height); _inherited::GetContentSize(width, height);
fHeightDelta = 16 - *height; int32 iconHeight = fWhich;
if (*height < 16) if (fDeviceIcon != NULL)
*height = 16; iconHeight = fDeviceIcon->Bounds().Height() + 1;
fHeightDelta = iconHeight - *height;
if (*height < iconHeight)
*height = iconHeight;
*width += 20; *width += 20;
} }
@@ -430,7 +436,7 @@ IconMenuItem::DrawContent()
{ {
BPoint drawPoint(ContentLocation()); BPoint drawPoint(ContentLocation());
if (fDeviceIcon != NULL) if (fDeviceIcon != NULL)
drawPoint.x += (float)fWhich + 4.0f; drawPoint.x += (fDeviceIcon->Bounds().Width() + 1) + 4.0f;
if (fHeightDelta > 0) if (fHeightDelta > 0)
drawPoint.y += ceilf(fHeightDelta / 2); drawPoint.y += ceilf(fHeightDelta / 2);
@@ -518,10 +524,9 @@ IconMenuItem::SetIcon(BBitmap* icon)
if (fDeviceIcon != NULL) if (fDeviceIcon != NULL)
delete fDeviceIcon; delete fDeviceIcon;
fDeviceIcon = new BBitmap(BRect(0, 0, fWhich - 1, fWhich - 1), fDeviceIcon = new BBitmap(BRect(BPoint(0, 0),
icon->ColorSpace()); be_control_look->ComposeIconSize(fWhich)), icon->ColorSpace());
fDeviceIcon->SetBits(icon->Bits(), icon->BitsLength(), 0, fDeviceIcon->ImportBits(icon);
icon->ColorSpace());
} else { } else {
delete fDeviceIcon; delete fDeviceIcon;
fDeviceIcon = NULL; fDeviceIcon = NULL;
+9 -9
View File
@@ -85,24 +85,24 @@ BNavigator::~BNavigator()
void void
BNavigator::AttachedToWindow() BNavigator::AttachedToWindow()
{ {
const BRect iconRect(BPoint(0, 0),
be_control_look->ComposeIconSize(20));
// Set up toolbar items // Set up toolbar items
BBitmap* bmpBack = new BBitmap(BRect(0, 0, 19, 19), B_RGBA32); BBitmap* bmpBack = new BBitmap(iconRect, B_RGBA32);
GetTrackerResources()->GetIconResource(R_ResBackNav, B_MINI_ICON, GetTrackerResources()->GetIconResource(R_ResBackNav, B_MINI_ICON, bmpBack);
bmpBack);
AddAction(kNavigatorCommandBackward, this, bmpBack); AddAction(kNavigatorCommandBackward, this, bmpBack);
SetActionEnabled(kNavigatorCommandBackward, false); SetActionEnabled(kNavigatorCommandBackward, false);
delete bmpBack; delete bmpBack;
BBitmap* bmpForw = new BBitmap(BRect(0, 0, 19, 19), B_RGBA32); BBitmap* bmpForw = new BBitmap(iconRect, B_RGBA32);
GetTrackerResources()->GetIconResource(R_ResForwNav, B_MINI_ICON, GetTrackerResources()->GetIconResource(R_ResForwNav, B_MINI_ICON, bmpForw);
bmpForw);
AddAction(kNavigatorCommandForward, this, bmpForw); AddAction(kNavigatorCommandForward, this, bmpForw);
SetActionEnabled(kNavigatorCommandForward, false); SetActionEnabled(kNavigatorCommandForward, false);
delete bmpForw; delete bmpForw;
BBitmap* bmpUp = new BBitmap(BRect(0, 0, 19, 19), B_RGBA32); BBitmap* bmpUp = new BBitmap(iconRect, B_RGBA32);
GetTrackerResources()->GetIconResource(R_ResUpNav, B_MINI_ICON, GetTrackerResources()->GetIconResource(R_ResUpNav, B_MINI_ICON, bmpUp);
bmpUp);
AddAction(kNavigatorCommandUp, this, bmpUp); AddAction(kNavigatorCommandUp, this, bmpUp);
SetActionEnabled(kNavigatorCommandUp, false); SetActionEnabled(kNavigatorCommandUp, false);
delete bmpUp; delete bmpUp;
+3 -2
View File
@@ -45,6 +45,7 @@ All rights reserved.
#include <BitmapStream.h> #include <BitmapStream.h>
#include <Catalog.h> #include <Catalog.h>
#include <ControlLook.h>
#include <Debug.h> #include <Debug.h>
#include <Font.h> #include <Font.h>
#include <IconUtils.h> #include <IconUtils.h>
@@ -1260,8 +1261,8 @@ StringToScalar(const char* text)
int32 int32
ListIconSize() ListIconSize()
{ {
static int32 sIconSize = std::max((int32)B_MINI_ICON, static int32 sIconSize = be_control_look->ComposeIconSize(B_MINI_ICON)
(int32)ceilf(B_MINI_ICON * be_plain_font->Size() / 12)); .IntegerWidth() + 1;
return sIconSize; return sIconSize;
} }