* Implemented changing the icons size (several ones are supported from
16 x 16 to 64 x 64). * Changed the layout code to have dynamic padding depending on main icon size. * Fixed a problem with the "Auto Raise" feature where, when the pad was along the bottom, you had to tip the top of the screen with the mouse for the pad to raise... git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28096 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
8eeb005f20
commit
a6099ca9e5
|
@ -237,25 +237,42 @@ IconButton::GetPreferredSize(float* width, float* height)
|
|||
if (IsValid()) {
|
||||
minWidth += fNormalBitmap->Bounds().IntegerWidth() + 1.0;
|
||||
minHeight += fNormalBitmap->Bounds().IntegerHeight() + 1.0;
|
||||
} else {
|
||||
minWidth += MIN_SPACE;
|
||||
minHeight += MIN_SPACE;
|
||||
}
|
||||
if (minWidth < MIN_SPACE)
|
||||
minWidth = MIN_SPACE;
|
||||
if (minHeight < MIN_SPACE)
|
||||
minHeight = MIN_SPACE;
|
||||
|
||||
float hPadding = max_c(4.0, ceilf(minHeight / 4.0));
|
||||
float vPadding = max_c(4.0, ceilf(minWidth / 4.0));
|
||||
|
||||
if (fLabel.CountChars() > 0) {
|
||||
font_height fh;
|
||||
GetFontHeight(&fh);
|
||||
minHeight += ceilf(fh.ascent + fh.descent) + 4.0;
|
||||
minWidth += StringWidth(fLabel.String()) + 4.0;
|
||||
minHeight += ceilf(fh.ascent + fh.descent) + vPadding;
|
||||
minWidth += StringWidth(fLabel.String()) + vPadding;
|
||||
}
|
||||
|
||||
if (width)
|
||||
*width = minWidth + 4.0;
|
||||
*width = minWidth + hPadding;
|
||||
if (height)
|
||||
*height = minHeight + 4.0;
|
||||
*height = minHeight + vPadding;
|
||||
}
|
||||
|
||||
// MinSize
|
||||
BSize
|
||||
IconButton::MinSize()
|
||||
{
|
||||
BSize size;
|
||||
GetPreferredSize(&size.width, &size.height);
|
||||
return size;
|
||||
}
|
||||
|
||||
// MaxSize
|
||||
BSize
|
||||
IconButton::MaxSize()
|
||||
{
|
||||
return MinSize();
|
||||
}
|
||||
|
||||
// Invoke
|
||||
|
|
|
@ -43,6 +43,9 @@ class IconButton : public BView, public BInvoker {
|
|||
const BMessage* message);
|
||||
virtual void GetPreferredSize(float* width,
|
||||
float* height);
|
||||
virtual BSize MinSize();
|
||||
virtual BSize MaxSize();
|
||||
|
||||
|
||||
// BInvoker interface
|
||||
virtual status_t Invoke(BMessage* message = NULL);
|
||||
|
|
|
@ -34,28 +34,24 @@ LaunchButton::fClickSpeed = 0;
|
|||
|
||||
// constructor
|
||||
LaunchButton::LaunchButton(const char* name, uint32 id, const char* label,
|
||||
BMessage* message, BHandler* target)
|
||||
BMessage* message, BHandler* target)
|
||||
: IconButton(name, id, label, message, target),
|
||||
fRef(NULL),
|
||||
fAppSig(NULL),
|
||||
fDescription(""),
|
||||
fAnticipatingDrop(false),
|
||||
fLastClickTime(0)
|
||||
fLastClickTime(0),
|
||||
fIconSize(DEFAULT_ICON_SIZE)
|
||||
{
|
||||
if (fClickSpeed == 0 || get_click_speed(&fClickSpeed) < B_OK)
|
||||
fClickSpeed = 500000;
|
||||
|
||||
BSize size(32.0 + 8.0, 32.0 + 8.0);
|
||||
SetExplicitMinSize(size);
|
||||
SetExplicitMaxSize(size);
|
||||
}
|
||||
|
||||
// destructor
|
||||
LaunchButton::~LaunchButton()
|
||||
{
|
||||
delete fRef;
|
||||
if (fAppSig)
|
||||
free(fAppSig);
|
||||
free(fAppSig);
|
||||
}
|
||||
|
||||
// AttachedToWindow
|
||||
|
@ -290,8 +286,7 @@ void
|
|||
LaunchButton::SetTo(const char* appSig, bool updateIcon)
|
||||
{
|
||||
if (appSig) {
|
||||
if (fAppSig)
|
||||
free(fAppSig);
|
||||
free(fAppSig);
|
||||
fAppSig = strdup(appSig);
|
||||
if (updateIcon) {
|
||||
entry_ref ref;
|
||||
|
@ -310,6 +305,22 @@ LaunchButton::SetDescription(const char* text)
|
|||
_UpdateToolTip();
|
||||
}
|
||||
|
||||
// SetIconSize
|
||||
void
|
||||
LaunchButton::SetIconSize(uint32 size)
|
||||
{
|
||||
if (fIconSize == size)
|
||||
return;
|
||||
|
||||
fIconSize = size;
|
||||
_UpdateIcon(fRef);
|
||||
|
||||
InvalidateLayout();
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
// _UpdateToolTip
|
||||
void
|
||||
LaunchButton::_UpdateToolTip()
|
||||
|
@ -339,8 +350,11 @@ LaunchButton::_UpdateToolTip()
|
|||
void
|
||||
LaunchButton::_UpdateIcon(const entry_ref* ref)
|
||||
{
|
||||
BBitmap* icon = new BBitmap(BRect(0.0, 0.0, 31.0, 31.0), B_RGBA32);
|
||||
if (BNodeInfo::GetTrackerIcon(ref, icon, B_LARGE_ICON) >= B_OK)
|
||||
BBitmap* icon = new BBitmap(BRect(0.0, 0.0, fIconSize - 1,
|
||||
fIconSize - 1), B_RGBA32);
|
||||
// NOTE: passing an invalid/unknown icon_size argument will cause
|
||||
// the BNodeInfo to ignore it and just use the bitmap bounds.
|
||||
if (BNodeInfo::GetTrackerIcon(ref, icon, (icon_size)fIconSize) >= B_OK)
|
||||
SetIcon(icon);
|
||||
|
||||
delete icon;
|
||||
|
|
|
@ -52,6 +52,10 @@ class LaunchButton : public IconButton {
|
|||
const char* Description() const
|
||||
{ return fDescription.String(); }
|
||||
|
||||
void SetIconSize(uint32 size);
|
||||
uint32 IconSize() const
|
||||
{ return fIconSize; }
|
||||
|
||||
private:
|
||||
void _UpdateToolTip();
|
||||
void _UpdateIcon(const entry_ref* ref);
|
||||
|
@ -64,6 +68,8 @@ class LaunchButton : public IconButton {
|
|||
bigtime_t fLastClickTime;
|
||||
BPoint fDragStart;
|
||||
|
||||
uint32 fIconSize;
|
||||
|
||||
static bigtime_t fClickSpeed;
|
||||
};
|
||||
|
||||
|
|
|
@ -357,6 +357,11 @@ MainWindow::LoadSettings(const BMessage* message)
|
|||
if (message->FindInt32("orientation", &orientation) == B_OK)
|
||||
fPadView->SetOrientation((enum orientation)orientation);
|
||||
|
||||
// restore icon size
|
||||
int32 iconSize;
|
||||
if (message->FindInt32("icon size", &iconSize) == B_OK)
|
||||
fPadView->SetIconSize(iconSize);
|
||||
|
||||
// restore buttons
|
||||
const char* path;
|
||||
bool buttonAdded = false;
|
||||
|
@ -430,6 +435,10 @@ MainWindow::SaveSettings(BMessage* message)
|
|||
(int32)fPadView->Orientation()) != B_OK)
|
||||
message->AddInt32("orientation", (int32)fPadView->Orientation());
|
||||
|
||||
// store icon size
|
||||
if (message->ReplaceInt32("icon size", fPadView->IconSize()) != B_OK)
|
||||
message->AddInt32("icon size", fPadView->IconSize());
|
||||
|
||||
// store buttons
|
||||
message->RemoveName("path");
|
||||
message->RemoveName("description");
|
||||
|
|
|
@ -22,10 +22,12 @@
|
|||
#include "LaunchButton.h"
|
||||
#include "MainWindow.h"
|
||||
|
||||
bigtime_t kActivationDelay = 40000;
|
||||
static bigtime_t sActivationDelay = 40000;
|
||||
static const uint32 kIconSizes[] = { 16, 20, 24, 32, 40, 48, 64 };
|
||||
|
||||
enum {
|
||||
MSG_TOGGLE_LAYOUT = 'tgll'
|
||||
MSG_TOGGLE_LAYOUT = 'tgll',
|
||||
MSG_SET_ICON_SIZE = 'stis'
|
||||
};
|
||||
|
||||
// constructor
|
||||
|
@ -33,11 +35,12 @@ PadView::PadView(const char* name)
|
|||
: BView(name, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE, NULL),
|
||||
fDragging(false),
|
||||
fClickTime(0),
|
||||
fButtonLayout(new BGroupLayout(B_VERTICAL, 4))
|
||||
fButtonLayout(new BGroupLayout(B_VERTICAL, 4)),
|
||||
fIconSize(DEFAULT_ICON_SIZE)
|
||||
{
|
||||
SetViewColor(B_TRANSPARENT_32_BIT);
|
||||
SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||
get_click_speed(&kActivationDelay);
|
||||
get_click_speed(&sActivationDelay);
|
||||
|
||||
fButtonLayout->SetInsets(2, 7, 2, 2);
|
||||
SetLayout(fButtonLayout);
|
||||
|
@ -138,6 +141,11 @@ PadView::MessageReceived(BMessage* message)
|
|||
fButtonLayout->SetOrientation(B_HORIZONTAL);
|
||||
}
|
||||
break;
|
||||
case MSG_SET_ICON_SIZE:
|
||||
uint32 size;
|
||||
if (message->FindInt32("size", (int32*)&size) == B_OK)
|
||||
SetIconSize(size);
|
||||
break;
|
||||
default:
|
||||
BView::MessageReceived(message);
|
||||
break;
|
||||
|
@ -184,7 +192,7 @@ PadView::MouseDown(BPoint where)
|
|||
window->Activate(false);
|
||||
}
|
||||
} else {
|
||||
if (system_time() - fClickTime < kActivationDelay) {
|
||||
if (system_time() - fClickTime < sActivationDelay) {
|
||||
window->Minimize(true);
|
||||
fClickTime = 0;
|
||||
} else {
|
||||
|
@ -205,7 +213,7 @@ PadView::MouseUp(BPoint where)
|
|||
uint32 buttons;
|
||||
window->CurrentMessage()->FindInt32("buttons", (int32*)&buttons);
|
||||
if (buttons & B_PRIMARY_MOUSE_BUTTON
|
||||
&& system_time() - fClickTime < kActivationDelay
|
||||
&& system_time() - fClickTime < sActivationDelay
|
||||
&& window->IsActive())
|
||||
window->Activate();
|
||||
}
|
||||
|
@ -244,7 +252,7 @@ PadView::MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage)
|
|||
if (where.x >= windowFrame.left && where.x <= windowFrame.right) {
|
||||
if (position.y < 0.5 && where.y == frame.top)
|
||||
raise = true;
|
||||
else if (position.y > 0.5 && where.y == frame.top)
|
||||
else if (position.y > 0.5 && where.y == frame.bottom)
|
||||
raise = true;
|
||||
}
|
||||
}
|
||||
|
@ -258,6 +266,8 @@ PadView::MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage)
|
|||
void
|
||||
PadView::AddButton(LaunchButton* button, LaunchButton* beforeButton)
|
||||
{
|
||||
button->SetIconSize(fIconSize);
|
||||
|
||||
if (beforeButton)
|
||||
fButtonLayout->AddView(fButtonLayout->IndexOfView(beforeButton), button);
|
||||
else
|
||||
|
@ -338,6 +348,20 @@ PadView::DisplayMenu(BPoint where, LaunchButton* button) const
|
|||
item->SetTarget(this);
|
||||
settingsM->AddItem(item);
|
||||
|
||||
BMenu* iconSizeM = new BMenu("Icon size");
|
||||
for (uint32 i = 0; i < sizeof(kIconSizes) / sizeof(uint32); i++) {
|
||||
uint32 iconSize = kIconSizes[i];
|
||||
message = new BMessage(MSG_SET_ICON_SIZE);
|
||||
message->AddInt32("size", iconSize);
|
||||
BString label;
|
||||
label << iconSize << " x " << iconSize;
|
||||
item = new BMenuItem(label.String(), message);
|
||||
item->SetTarget(this);
|
||||
item->SetMarked(IconSize() == iconSize);
|
||||
iconSizeM->AddItem(item);
|
||||
}
|
||||
settingsM->AddItem(iconSizeM);
|
||||
|
||||
uint32 what = window->Look() == B_BORDERED_WINDOW_LOOK ? MSG_SHOW_BORDER : MSG_HIDE_BORDER;
|
||||
item = new BMenuItem("Show Window Border", new BMessage(what));
|
||||
item->SetTarget(window);
|
||||
|
@ -416,4 +440,24 @@ PadView::Orientation() const
|
|||
return fButtonLayout->Orientation();
|
||||
}
|
||||
|
||||
// SetIconSize
|
||||
void
|
||||
PadView::SetIconSize(uint32 size)
|
||||
{
|
||||
if (size == fIconSize)
|
||||
return;
|
||||
|
||||
fIconSize = size;
|
||||
|
||||
for (int32 i = 0; LaunchButton* button = ButtonAt(i); i++)
|
||||
button->SetIconSize(fIconSize);
|
||||
}
|
||||
|
||||
// IconSize
|
||||
uint32
|
||||
PadView::IconSize() const
|
||||
{
|
||||
return fIconSize;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
class BGroupLayout;
|
||||
class LaunchButton;
|
||||
|
||||
#define DEFAULT_ICON_SIZE 32
|
||||
|
||||
class PadView : public BView {
|
||||
public:
|
||||
PadView(const char* name);
|
||||
|
@ -39,11 +41,15 @@ class PadView : public BView {
|
|||
void SetOrientation(enum orientation orientation);
|
||||
enum orientation Orientation() const;
|
||||
|
||||
void SetIconSize(uint32 size);
|
||||
uint32 IconSize() const;
|
||||
|
||||
private:
|
||||
BPoint fDragOffset;
|
||||
bool fDragging;
|
||||
bigtime_t fClickTime;
|
||||
BGroupLayout* fButtonLayout;
|
||||
uint32 fIconSize;
|
||||
};
|
||||
|
||||
#endif // PAD_VIEW_H
|
||||
|
|
Loading…
Reference in New Issue