Deskbar: Scale cut-off leaf icon in horizontal mode
Fixes #8505 restoring the aesthetic integrity of the cut-off leaf. Add vertically & horizontally centered, whole vector icon to rdef. Reformat BarMenuTitle.h rename header guard from BARMENUTITLEH to BAR_MENU_TITLE_H. Created TDeskbarMenuTitle subclass which deals with Deskbar menu item stuff like getting the icon from vector data and pushing the leaf down a few pixels to cut off the leaf (maintaining its aesthetic integrity). Made TBarMenuTitle methods virtual. Remove unused expando constructor parameter and private variable. Add a TODO to scale the bitmap if we can't find any vector icon data. With non-vector bitmap it behaves same as before this commit in horizontal mode. Adjust kMinimumTrayWidth to restore Deskbar's minimum width to its classic value since days of yore, 143px. This, perhaps not coincidently, is exactly the amount fit 7 replicant icons. Update constants in the code to reflect this reality. Adjustable width coming soon. replace dynamic_cast<TBarApp*>(be_app) with a static_cast in 1 place.
This commit is contained in:
@@ -66,7 +66,6 @@ All rights reserved.
|
||||
#include "Switcher.h"
|
||||
#include "Utilities.h"
|
||||
|
||||
#include "icons.h"
|
||||
#include "tracker_private.h"
|
||||
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ All rights reserved.
|
||||
|
||||
#include "icons.h"
|
||||
|
||||
#include "BarApp.h"
|
||||
#include "BarMenuTitle.h"
|
||||
#include "BarView.h"
|
||||
#include "BarWindow.h"
|
||||
@@ -108,8 +109,9 @@ TBarMenuBar::TBarMenuBar(BRect frame, const char* name, TBarView* barView)
|
||||
TDeskbarMenu* beMenu = new TDeskbarMenu(barView);
|
||||
TBarWindow::SetDeskbarMenu(beMenu);
|
||||
|
||||
fDeskbarMenuItem = new TBarMenuTitle(0.0f, 0.0f,
|
||||
AppResSet()->FindBitmap(B_MESSAGE_TYPE, R_LeafLogoBitmap), beMenu);
|
||||
fDeskbarMenuItem = new TDeskbarMenuTitle(frame.Width(), frame.Height(),
|
||||
NULL, beMenu);
|
||||
fDeskbarMenuItem->FetchIcon();
|
||||
AddItem(fDeskbarMenuItem);
|
||||
}
|
||||
|
||||
@@ -141,6 +143,8 @@ TBarMenuBar::SmartResize(float width, float height)
|
||||
fAppListMenuItem->SetContentSize(width / count, height);
|
||||
}
|
||||
|
||||
fDeskbarMenuItem->FetchIcon();
|
||||
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
|
||||
@@ -47,6 +47,7 @@ All rights reserved.
|
||||
|
||||
class TBarMenuTitle;
|
||||
class TBarView;
|
||||
class TDeskbarMenuTitle;
|
||||
|
||||
class TSeparatorItem : public BSeparatorItem {
|
||||
public:
|
||||
@@ -63,9 +64,10 @@ public:
|
||||
|
||||
virtual void MouseMoved(BPoint where, uint32 code,
|
||||
const BMessage* message);
|
||||
virtual void Draw(BRect);
|
||||
|
||||
virtual void Draw(BRect);
|
||||
void DrawBackground(BRect);
|
||||
|
||||
void SmartResize(float width = -1.0f,
|
||||
float height = -1.0f);
|
||||
|
||||
@@ -79,9 +81,11 @@ public:
|
||||
bool (* hookfunction)(BMenu*, void*),
|
||||
void* state, bool both = false);
|
||||
|
||||
TDeskbarMenuTitle* DeskbarMenuTitle() { return fDeskbarMenuItem; };
|
||||
|
||||
private:
|
||||
TBarView* fBarView;
|
||||
TBarMenuTitle* fDeskbarMenuItem;
|
||||
TDeskbarMenuTitle* fDeskbarMenuItem;
|
||||
TBarMenuTitle* fAppListMenuItem;
|
||||
TSeparatorItem* fSeparatorItem;
|
||||
};
|
||||
|
||||
@@ -36,22 +36,28 @@ All rights reserved.
|
||||
|
||||
#include "BarMenuTitle.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <Bitmap.h>
|
||||
#include <ControlLook.h>
|
||||
#include <Debug.h>
|
||||
#include <IconUtils.h>
|
||||
|
||||
#include "BarApp.h"
|
||||
#include "BarView.h"
|
||||
#include "BarWindow.h"
|
||||
#include "ResourceSet.h"
|
||||
#include "StatusView.h"
|
||||
|
||||
#include "icons.h"
|
||||
|
||||
|
||||
TBarMenuTitle::TBarMenuTitle(float width, float height, const BBitmap* icon,
|
||||
BMenu* menu, bool expando)
|
||||
BMenu* menu)
|
||||
:
|
||||
BMenuItem(menu, new BMessage(B_REFS_RECEIVED)),
|
||||
fWidth(width),
|
||||
fHeight(height),
|
||||
fInExpando(expando),
|
||||
fIcon(icon)
|
||||
{
|
||||
}
|
||||
@@ -123,7 +129,7 @@ TBarMenuTitle::DrawContent()
|
||||
|
||||
float widthOffset = rintf((frame.Width() - iconRect.Width()) / 2);
|
||||
float heightOffset = rintf((frame.Height() - iconRect.Height()) / 2);
|
||||
iconRect.OffsetBy(widthOffset - 1.0f, heightOffset + 2.0f);
|
||||
iconRect.OffsetBy(widthOffset - 1, heightOffset - 1);
|
||||
|
||||
menu->DrawBitmapAsync(fIcon, iconRect);
|
||||
}
|
||||
@@ -144,3 +150,97 @@ TBarMenuTitle::Invoke(BMessage* message)
|
||||
|
||||
return BMenuItem::Invoke(message);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TBarMenuTitle::SetIcon(const BBitmap* icon)
|
||||
{
|
||||
delete fIcon;
|
||||
fIcon = icon;
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark - TDeskbarMenuTitle
|
||||
|
||||
|
||||
const int32 kIconSizeCutoff = 48;
|
||||
// icon size to stop increasing logo width in horizontal mode
|
||||
|
||||
|
||||
TDeskbarMenuTitle::TDeskbarMenuTitle(float width, float height,
|
||||
const BBitmap* icon, BMenu* menu)
|
||||
:
|
||||
TBarMenuTitle(width, height, icon, menu),
|
||||
fVectorIconData(NULL),
|
||||
fVectorIconSize(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TDeskbarMenuTitle::DrawContent()
|
||||
{
|
||||
if (fIcon == NULL)
|
||||
return;
|
||||
|
||||
BMenu* menu = Menu();
|
||||
BRect frame(Frame());
|
||||
BRect iconRect(fIcon->Bounds());
|
||||
|
||||
menu->SetDrawingMode(B_OP_ALPHA);
|
||||
iconRect.OffsetTo(frame.LeftTop());
|
||||
|
||||
float widthOffset = rintf((frame.Width() - iconRect.Width()) / 2);
|
||||
float heightOffset = rintf((frame.Height() - iconRect.Height()) / 2);
|
||||
|
||||
// move bitmap down a few pixels so leaf gets cut off
|
||||
heightOffset += 3;
|
||||
|
||||
iconRect.OffsetBy(widthOffset - 1, heightOffset - 1);
|
||||
|
||||
menu->DrawBitmapAsync(fIcon, iconRect);
|
||||
}
|
||||
|
||||
|
||||
const BBitmap*
|
||||
TDeskbarMenuTitle::FetchIcon()
|
||||
{
|
||||
if (fVectorIconData == NULL || fVectorIconSize == 0) {
|
||||
// haven't fetched vector icon data yet, fetch it
|
||||
fVectorIconData = (const uint8*)AppResSet()->FindResource(
|
||||
B_VECTOR_ICON_TYPE, R_LeafLogoVector, &fVectorIconSize);
|
||||
}
|
||||
|
||||
float width = CalcIconWidth();
|
||||
BBitmap* icon = new BBitmap(BRect(0, 0, width - 1, width - 1),
|
||||
B_RGBA32);
|
||||
if (fVectorIconData != NULL && fVectorIconSize > 0
|
||||
&& BIconUtils::GetVectorIcon(fVectorIconData, fVectorIconSize, icon)
|
||||
== B_OK) {
|
||||
// rasterized vector icon into a bitmap
|
||||
fIcon = icon;
|
||||
} else {
|
||||
// fetched bitmap instead
|
||||
fIcon = AppResSet()->FindBitmap(B_MESSAGE_TYPE, R_LeafLogoBitmap);
|
||||
// TODO: scale the bitmap into icon
|
||||
delete icon;
|
||||
}
|
||||
|
||||
return fIcon;
|
||||
}
|
||||
|
||||
|
||||
float
|
||||
TDeskbarMenuTitle::CalcIconWidth()
|
||||
{
|
||||
TBarApp* barApp = static_cast<TBarApp*>(be_app);
|
||||
bool isVertical = barApp->BarView()->Vertical();
|
||||
bool hasBitmapIcon = fVectorIconData == NULL;
|
||||
|
||||
float m = 3;
|
||||
float x = (isVertical || hasBitmapIcon) ? kMinimumIconSize
|
||||
: std::min(barApp->IconSize(), kIconSizeCutoff);
|
||||
float b = kMinimumIconSize;
|
||||
|
||||
return m * x + b;
|
||||
}
|
||||
|
||||
@@ -32,8 +32,8 @@ brand product names are registered trademarks or trademarks of their respective
|
||||
holders.
|
||||
All rights reserved.
|
||||
*/
|
||||
#ifndef BARMENUTITLE_H
|
||||
#define BARMENUTITLE_H
|
||||
#ifndef BAR_MENU_TITLE_H
|
||||
#define BAR_MENU_TITLE_H
|
||||
|
||||
|
||||
//
|
||||
@@ -47,27 +47,45 @@ All rights reserved.
|
||||
class BBitmap;
|
||||
class BMenu;
|
||||
|
||||
|
||||
class TBarMenuTitle : public BMenuItem {
|
||||
public:
|
||||
TBarMenuTitle(float width, float height, const BBitmap* icon,
|
||||
BMenu* menu, bool expando = false);
|
||||
virtual ~TBarMenuTitle();
|
||||
TBarMenuTitle(float width, float height,
|
||||
const BBitmap* icon, BMenu* menu);
|
||||
virtual ~TBarMenuTitle();
|
||||
|
||||
void SetContentSize(float width, float height);
|
||||
void Draw();
|
||||
virtual void SetContentSize(float width, float height);
|
||||
virtual void Draw();
|
||||
|
||||
status_t Invoke(BMessage* message);
|
||||
virtual status_t Invoke(BMessage* message);
|
||||
|
||||
const BBitmap* Icon() { return fIcon; };
|
||||
virtual void SetIcon(const BBitmap* icon);
|
||||
|
||||
protected:
|
||||
void DrawContent();
|
||||
void GetContentSize(float* width, float* height);
|
||||
virtual void DrawContent();
|
||||
virtual void GetContentSize(float* width, float* height);
|
||||
|
||||
private:
|
||||
float fWidth;
|
||||
float fHeight;
|
||||
bool fInExpando;
|
||||
const BBitmap* fIcon;
|
||||
float fWidth;
|
||||
float fHeight;
|
||||
const BBitmap* fIcon;
|
||||
};
|
||||
|
||||
|
||||
#endif // BARMENUTITLE_H
|
||||
class TDeskbarMenuTitle : public TBarMenuTitle {
|
||||
public:
|
||||
TDeskbarMenuTitle(float width, float height,
|
||||
const BBitmap* icon, BMenu* menu);
|
||||
|
||||
virtual void DrawContent();
|
||||
|
||||
const BBitmap* FetchIcon();
|
||||
float CalcIconWidth();
|
||||
|
||||
private:
|
||||
const uint8* fVectorIconData;
|
||||
size_t fVectorIconSize;
|
||||
};
|
||||
|
||||
|
||||
#endif // BAR_MENU_TITLE_H
|
||||
|
||||
@@ -49,6 +49,7 @@ All rights reserved.
|
||||
#include "icons.h"
|
||||
#include "BarApp.h"
|
||||
#include "BarMenuBar.h"
|
||||
#include "BarMenuTitle.h"
|
||||
#include "BarWindow.h"
|
||||
#include "DeskbarMenu.h"
|
||||
#include "DeskbarUtils.h"
|
||||
@@ -394,8 +395,10 @@ TBarView::PlaceDeskbarMenu()
|
||||
width += 1;
|
||||
} else {
|
||||
// shows apps to the right of bemenu
|
||||
width = fBarMenuBar->DeskbarMenuTitle()->CalcIconWidth()
|
||||
+ kMinimumIconSize;
|
||||
fBarMenuBar->AddSeparatorItem();
|
||||
width = floorf(width) / 2 + kSepItemWidth;
|
||||
width += kSepItemWidth;
|
||||
}
|
||||
loc = Bounds().LeftTop();
|
||||
} else {
|
||||
|
||||
@@ -55,6 +55,7 @@ All rights reserved.
|
||||
#include "icons.h"
|
||||
|
||||
#include "BarApp.h"
|
||||
#include "BarMenuBar.h"
|
||||
#include "BarMenuTitle.h"
|
||||
#include "BarView.h"
|
||||
#include "BarWindow.h"
|
||||
@@ -95,7 +96,6 @@ TExpandoMenuBar::TExpandoMenuBar(TBarView* barView, bool vertical)
|
||||
fVertical(vertical),
|
||||
fOverflow(false),
|
||||
fFirstBuild(true),
|
||||
fDeskbarMenuWidth(kMinMenuItemWidth),
|
||||
fPreviousDragTargetItem(NULL),
|
||||
fLastMousedOverItem(NULL),
|
||||
fLastClickedItem(NULL)
|
||||
@@ -103,13 +103,6 @@ TExpandoMenuBar::TExpandoMenuBar(TBarView* barView, bool vertical)
|
||||
SetItemMargins(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
SetFont(be_plain_font);
|
||||
SetMaxItemWidth();
|
||||
|
||||
// top or bottom mode, add deskbar menu and sep for menubar tracking
|
||||
// consistency
|
||||
const BBitmap* logoBitmap = AppResSet()->FindBitmap(B_MESSAGE_TYPE,
|
||||
R_LeafLogoBitmap);
|
||||
if (logoBitmap != NULL)
|
||||
fDeskbarMenuWidth = logoBitmap->Bounds().Width() + 16;
|
||||
}
|
||||
|
||||
|
||||
@@ -369,7 +362,7 @@ TExpandoMenuBar::MouseMoved(BPoint where, uint32 code, const BMessage* message)
|
||||
break;
|
||||
}
|
||||
|
||||
if (!dynamic_cast<TBarApp*>(be_app)->Settings()->hideLabels) {
|
||||
if (!static_cast<TBarApp*>(be_app)->Settings()->hideLabels) {
|
||||
// item has a visible label, set tool tip if truncated
|
||||
fLastMousedOverItem = menuItem;
|
||||
if (strcasecmp(item->TruncatedLabel(), item->Label()) > 0) {
|
||||
@@ -741,8 +734,11 @@ TExpandoMenuBar::CheckItemSizes(int32 delta)
|
||||
|
||||
bool drawLabels = !static_cast<TBarApp*>(be_app)->Settings()->hideLabels;
|
||||
|
||||
float deskbarMenuWidth
|
||||
= fBarView->BarMenuBar()->DeskbarMenuTitle()->CalcIconWidth();
|
||||
|
||||
float maxWidth = fBarView->DragRegion()->Frame().left
|
||||
- fDeskbarMenuWidth - kSepItemWidth;
|
||||
- deskbarMenuWidth - kSepItemWidth;
|
||||
int32 iconSize = static_cast<TBarApp*>(be_app)->IconSize();
|
||||
float iconOnlyWidth = kIconPadding + iconSize + kIconPadding;
|
||||
float minItemWidth = drawLabels
|
||||
@@ -751,7 +747,7 @@ TExpandoMenuBar::CheckItemSizes(int32 delta)
|
||||
float maxItemWidth = drawLabels
|
||||
? gMinimumWindowWidth + iconSize - kMinimumIconSize
|
||||
: iconOnlyWidth;
|
||||
float menuWidth = maxItemWidth * CountItems() + fDeskbarMenuWidth
|
||||
float menuWidth = maxItemWidth * CountItems() + deskbarMenuWidth
|
||||
+ kSepItemWidth;
|
||||
|
||||
bool reset = false;
|
||||
@@ -881,10 +877,12 @@ TExpandoMenuBar::CheckForSizeOverrun()
|
||||
float minItemWidth = !static_cast<TBarApp*>(be_app)->Settings()->hideLabels
|
||||
? iconOnlyWidth + kMinMenuItemWidth
|
||||
: iconOnlyWidth - kIconPadding;
|
||||
float menuWidth = minItemWidth * CountItems() + fDeskbarMenuWidth
|
||||
float deskbarMenuWidth
|
||||
= fBarView->BarMenuBar()->DeskbarMenuTitle()->CalcIconWidth();
|
||||
float menuWidth = minItemWidth * CountItems() + deskbarMenuWidth
|
||||
+ kSepItemWidth;
|
||||
float maxWidth = fBarView->DragRegion()->Frame().left
|
||||
- fDeskbarMenuWidth - kSepItemWidth;
|
||||
- deskbarMenuWidth - kSepItemWidth;
|
||||
|
||||
return menuWidth > maxWidth;
|
||||
}
|
||||
|
||||
@@ -116,7 +116,6 @@ private:
|
||||
bool fOverflow : 1;
|
||||
bool fFirstBuild : 1;
|
||||
|
||||
float fDeskbarMenuWidth;
|
||||
TTeamMenuItem* fPreviousDragTargetItem;
|
||||
BMenuItem* fLastMousedOverItem;
|
||||
BMenuItem* fLastClickedItem;
|
||||
|
||||
@@ -69,6 +69,8 @@ All rights reserved.
|
||||
#include "icons.h"
|
||||
|
||||
#include "BarApp.h"
|
||||
#include "BarMenuBar.h"
|
||||
#include "BarMenuTitle.h"
|
||||
#include "DeskbarUtils.h"
|
||||
#include "ResourceSet.h"
|
||||
#include "StatusViewShelf.h"
|
||||
@@ -138,15 +140,8 @@ TReplicantTray::TReplicantTray(TBarView* parent, bool vertical)
|
||||
fMinimumTrayWidth(kMinimumTrayWidth),
|
||||
fAlignmentSupport(false)
|
||||
{
|
||||
// init the minimum window width according to the logo.
|
||||
const BBitmap* logoBitmap = AppResSet()->FindBitmap(B_MESSAGE_TYPE,
|
||||
R_LeafLogoBitmap);
|
||||
if (logoBitmap != NULL) {
|
||||
gMinimumWindowWidth = std::max(gMinimumWindowWidth,
|
||||
2 * (logoBitmap->Bounds().Width() + 8));
|
||||
}
|
||||
gMinimumWindowWidth = std::max(gMinimumWindowWidth,
|
||||
be_plain_font->StringWidth("WWWWWWWWW") + 20);
|
||||
be_plain_font->StringWidth("WWWWWWWWW") + 20);
|
||||
if (vertical)
|
||||
fMinimumTrayWidth = gMinimumWindowWidth - kGutter - kDragRegionWidth;
|
||||
|
||||
|
||||
@@ -48,17 +48,15 @@ All rights reserved.
|
||||
|
||||
const float kMaxReplicantHeight = 16.0f;
|
||||
const float kMaxReplicantWidth = 16.0f;
|
||||
const int32 kMinimumReplicantCount = 6;
|
||||
const int32 kMinimumReplicantCount = 7;
|
||||
const int32 kIconGap = 2;
|
||||
const int32 kGutter = 1;
|
||||
const int32 kDragRegionWidth = 6;
|
||||
|
||||
// 1 pixel for left gutter
|
||||
// space for replicant tray (6 items)
|
||||
// 6 pixel drag region
|
||||
const float kMinimumTrayWidth = kIconGap
|
||||
+ (kMinimumReplicantCount * kIconGap)
|
||||
+ (kMinimumReplicantCount * kMaxReplicantWidth) + kGutter;
|
||||
// space for replicant tray with gap on each side (7 items)
|
||||
// minus 6 pixel drag region
|
||||
const float kMinimumTrayWidth = kMinimumReplicantCount
|
||||
* (kIconGap + kMaxReplicantWidth + kIconGap) - kDragRegionWidth;
|
||||
const float kMinimumTrayHeight = kGutter + kMaxReplicantHeight + kGutter;
|
||||
|
||||
extern float gMinimumWindowWidth;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
enum {
|
||||
R_LeafLogoBitmap = 14,
|
||||
R_LeafLogoVector = 15,
|
||||
R_LargeNewGroupIcon = 16,
|
||||
R_SmallNewGroupIcon = 17,
|
||||
R_TeamIcon = 18,
|
||||
|
||||
@@ -192,6 +192,19 @@ resource(R_LeafLogoBitmap) archive(, 0x00000000) BBitmap {
|
||||
}
|
||||
};
|
||||
|
||||
resource(R_LeafLogoVector) #'VICN' array {
|
||||
$"6E6369660102010602407715BE05F73AC66F3D61964A3C0A4C40170000AAFFFF"
|
||||
$"00337F010216B9CBCB3DB9CBCB3DBC63CDC0C1BACE05BF13CE7BC14B63C0EACC"
|
||||
$"FAC116CD4DC3DFCEAEC644CBE0C55BCC8FC5F4CB9FC4F0CB0CC592CBD1C5BFCB"
|
||||
$"29C704CB1CC646CB1DC77DCAACC8A0C9CEC831CA54C929C92BCA66C78FC9D7C8"
|
||||
$"4ACA0BC757C9D5C6DEC9F8C725CA29C6F4CAD1C6FCCA7EC6FECB42C624CC6EC5"
|
||||
$"62CBF6C59CCA78C4B2C625C52AC7F6C4CAC58AC5B0C55DC77DC58EC65EC4FBC6"
|
||||
$"FCC509C57DC4D0C65CC3C1C5E4C14FC703C283C671C0D8C73BBF09C852BFB3C8"
|
||||
$"10BEB8C8CCBE3DC9B2BE74C943BE3AC94BBE32C87BBE2AC8E5BBFFC8D4B96CCA"
|
||||
$"A7BACBC96BB67CCAA9B337C8EFB331C964B337C8EFB328CA02B328CA02B328CA"
|
||||
$"02B9CDCB3EB6D2CB6AB9CDCB3E010A000100202009"
|
||||
};
|
||||
|
||||
resource(R_LargeNewGroupIcon) archive(, 0x00000000) BBitmap {
|
||||
"_frame" = rect { 0.0, 0.0, 31.0, 31.0 },
|
||||
"_cspace" = 4,
|
||||
|
||||
Reference in New Issue
Block a user