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 SetMarked(bool mark);
private:
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:
BBitmap* fDeviceIcon;
+15 -13
View File
@@ -112,7 +112,7 @@ namespace BPrivate {
class DraggableContainerIcon : public BView {
public:
DraggableContainerIcon();
DraggableContainerIcon(BSize iconSize);
virtual void MouseDown(BPoint where);
virtual void MouseUp(BPoint);
@@ -120,6 +120,7 @@ class DraggableContainerIcon : public BView {
virtual void Draw(BRect updateRect);
private:
BSize fIconSize;
uint32 fDragButton;
BPoint fClickPoint;
bool fDragStarted;
@@ -386,12 +387,15 @@ AddMimeTypeString(BStringList& list, Model* model)
// #pragma mark - DraggableContainerIcon
DraggableContainerIcon::DraggableContainerIcon()
DraggableContainerIcon::DraggableContainerIcon(BSize iconSize)
:
BView("DraggableContainerIcon", B_WILL_DRAW),
fIconSize(iconSize),
fDragButton(0),
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);
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
fDragButton = buttons
& (B_PRIMARY_MOUSE_BUTTON | B_SECONDARY_MOUSE_BUTTON);
@@ -483,7 +487,7 @@ DraggableContainerIcon::MouseMoved(BPoint where, uint32, const BMessage*)
// Draw the icon
float hIconOffset = (rect.Width() - Bounds().Width()) / 2;
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
BString nameString = model->Name();
@@ -542,10 +546,11 @@ DraggableContainerIcon::Draw(BRect updateRect)
// Draw the icon, straddling the border
SetDrawingMode(B_OP_ALPHA);
SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY);
float iconOffsetX = (Bounds().Width() - B_MINI_ICON) / 2;
float iconOffsetY = (Bounds().Height() - B_MINI_ICON) / 2;
float iconOffsetX = (Bounds().Width() - fIconSize.Width()) / 2;
float iconOffsetY = (Bounds().Height() - fIconSize.Height()) / 2;
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)
iconSize = 16;
fDraggableIcon = new(std::nothrow) DraggableContainerIcon();
fDraggableIcon = new(std::nothrow)
DraggableContainerIcon(be_control_look->ComposeIconSize(iconSize));
if (fDraggableIcon != NULL) {
BLayoutItem* item = fMenuContainer->GroupLayout()->AddView(
fDraggableIcon);
item->SetExplicitMinSize(BSize(iconSize + 5, iconSize));
item->SetExplicitMaxSize(BSize(iconSize + 5, item->MaxSize().Height()));
fMenuContainer->GroupLayout()->AddView(fDraggableIcon);
fMenuBar->SetBorders(
BControlLook::B_ALL_BORDERS & ~BControlLook::B_RIGHT_BORDER);
}
+20 -15
View File
@@ -126,7 +126,7 @@ ModelMenuItem::DrawContent()
{
if (fDrawText) {
BPoint drawPoint(ContentLocation());
drawPoint.x += ListIconSize() + ListIconSize() / 4
drawPoint.x += ListIconSize() + (ListIconSize() / 4)
+ (fExtraPad ? 6 : 0);
if (fHeightDelta > 0)
drawPoint.y += ceil(fHeightDelta / 2);
@@ -181,7 +181,8 @@ void
ModelMenuItem::GetContentSize(float* width, float* height)
{
_inherited::GetContentSize(width, height);
float iconSize = ListIconSize();
const float iconSize = ListIconSize();
fHeightDelta = iconSize - *height;
if (*height < iconSize)
*height = iconSize;
@@ -280,10 +281,11 @@ IconMenuItem::IconMenuItem(const char* label, BMessage* message,
fWhich(which)
{
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);
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;
fDeviceIcon = NULL;
}
@@ -304,7 +306,7 @@ IconMenuItem::IconMenuItem(const char* label, BMessage* message,
fWhich(which)
{
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);
if (mime.GetIcon(fDeviceIcon, which) != B_OK) {
@@ -331,7 +333,7 @@ IconMenuItem::IconMenuItem(BMenu* submenu, BMessage* message,
fWhich(which)
{
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);
if (mime.GetIcon(fDeviceIcon, which) != B_OK) {
@@ -359,7 +361,7 @@ IconMenuItem::IconMenuItem(BMessage* data)
if (data != NULL) {
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);
if (data->HasData("_deviceIconBits", B_RAW_TYPE)) {
@@ -417,9 +419,13 @@ IconMenuItem::GetContentSize(float* width, float* height)
{
_inherited::GetContentSize(width, height);
fHeightDelta = 16 - *height;
if (*height < 16)
*height = 16;
int32 iconHeight = fWhich;
if (fDeviceIcon != NULL)
iconHeight = fDeviceIcon->Bounds().Height() + 1;
fHeightDelta = iconHeight - *height;
if (*height < iconHeight)
*height = iconHeight;
*width += 20;
}
@@ -430,7 +436,7 @@ IconMenuItem::DrawContent()
{
BPoint drawPoint(ContentLocation());
if (fDeviceIcon != NULL)
drawPoint.x += (float)fWhich + 4.0f;
drawPoint.x += (fDeviceIcon->Bounds().Width() + 1) + 4.0f;
if (fHeightDelta > 0)
drawPoint.y += ceilf(fHeightDelta / 2);
@@ -518,10 +524,9 @@ IconMenuItem::SetIcon(BBitmap* icon)
if (fDeviceIcon != NULL)
delete fDeviceIcon;
fDeviceIcon = new BBitmap(BRect(0, 0, fWhich - 1, fWhich - 1),
icon->ColorSpace());
fDeviceIcon->SetBits(icon->Bits(), icon->BitsLength(), 0,
icon->ColorSpace());
fDeviceIcon = new BBitmap(BRect(BPoint(0, 0),
be_control_look->ComposeIconSize(fWhich)), icon->ColorSpace());
fDeviceIcon->ImportBits(icon);
} else {
delete fDeviceIcon;
fDeviceIcon = NULL;
+9 -9
View File
@@ -85,24 +85,24 @@ BNavigator::~BNavigator()
void
BNavigator::AttachedToWindow()
{
const BRect iconRect(BPoint(0, 0),
be_control_look->ComposeIconSize(20));
// Set up toolbar items
BBitmap* bmpBack = new BBitmap(BRect(0, 0, 19, 19), B_RGBA32);
GetTrackerResources()->GetIconResource(R_ResBackNav, B_MINI_ICON,
bmpBack);
BBitmap* bmpBack = new BBitmap(iconRect, B_RGBA32);
GetTrackerResources()->GetIconResource(R_ResBackNav, B_MINI_ICON, bmpBack);
AddAction(kNavigatorCommandBackward, this, bmpBack);
SetActionEnabled(kNavigatorCommandBackward, false);
delete bmpBack;
BBitmap* bmpForw = new BBitmap(BRect(0, 0, 19, 19), B_RGBA32);
GetTrackerResources()->GetIconResource(R_ResForwNav, B_MINI_ICON,
bmpForw);
BBitmap* bmpForw = new BBitmap(iconRect, B_RGBA32);
GetTrackerResources()->GetIconResource(R_ResForwNav, B_MINI_ICON, bmpForw);
AddAction(kNavigatorCommandForward, this, bmpForw);
SetActionEnabled(kNavigatorCommandForward, false);
delete bmpForw;
BBitmap* bmpUp = new BBitmap(BRect(0, 0, 19, 19), B_RGBA32);
GetTrackerResources()->GetIconResource(R_ResUpNav, B_MINI_ICON,
bmpUp);
BBitmap* bmpUp = new BBitmap(iconRect, B_RGBA32);
GetTrackerResources()->GetIconResource(R_ResUpNav, B_MINI_ICON, bmpUp);
AddAction(kNavigatorCommandUp, this, bmpUp);
SetActionEnabled(kNavigatorCommandUp, false);
delete bmpUp;
+3 -2
View File
@@ -45,6 +45,7 @@ All rights reserved.
#include <BitmapStream.h>
#include <Catalog.h>
#include <ControlLook.h>
#include <Debug.h>
#include <Font.h>
#include <IconUtils.h>
@@ -1260,8 +1261,8 @@ StringToScalar(const char* text)
int32
ListIconSize()
{
static int32 sIconSize = std::max((int32)B_MINI_ICON,
(int32)ceilf(B_MINI_ICON * be_plain_font->Size() / 12));
static int32 sIconSize = be_control_look->ComposeIconSize(B_MINI_ICON)
.IntegerWidth() + 1;
return sIconSize;
}