* 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:
@@ -237,25 +237,42 @@ IconButton::GetPreferredSize(float* width, float* height)
|
|||||||
if (IsValid()) {
|
if (IsValid()) {
|
||||||
minWidth += fNormalBitmap->Bounds().IntegerWidth() + 1.0;
|
minWidth += fNormalBitmap->Bounds().IntegerWidth() + 1.0;
|
||||||
minHeight += fNormalBitmap->Bounds().IntegerHeight() + 1.0;
|
minHeight += fNormalBitmap->Bounds().IntegerHeight() + 1.0;
|
||||||
} else {
|
|
||||||
minWidth += MIN_SPACE;
|
|
||||||
minHeight += MIN_SPACE;
|
|
||||||
}
|
}
|
||||||
if (minWidth < MIN_SPACE)
|
if (minWidth < MIN_SPACE)
|
||||||
minWidth = MIN_SPACE;
|
minWidth = MIN_SPACE;
|
||||||
if (minHeight < MIN_SPACE)
|
if (minHeight < MIN_SPACE)
|
||||||
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) {
|
if (fLabel.CountChars() > 0) {
|
||||||
font_height fh;
|
font_height fh;
|
||||||
GetFontHeight(&fh);
|
GetFontHeight(&fh);
|
||||||
minHeight += ceilf(fh.ascent + fh.descent) + 4.0;
|
minHeight += ceilf(fh.ascent + fh.descent) + vPadding;
|
||||||
minWidth += StringWidth(fLabel.String()) + 4.0;
|
minWidth += StringWidth(fLabel.String()) + vPadding;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (width)
|
if (width)
|
||||||
*width = minWidth + 4.0;
|
*width = minWidth + hPadding;
|
||||||
if (height)
|
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
|
// Invoke
|
||||||
|
|||||||
@@ -43,6 +43,9 @@ class IconButton : public BView, public BInvoker {
|
|||||||
const BMessage* message);
|
const BMessage* message);
|
||||||
virtual void GetPreferredSize(float* width,
|
virtual void GetPreferredSize(float* width,
|
||||||
float* height);
|
float* height);
|
||||||
|
virtual BSize MinSize();
|
||||||
|
virtual BSize MaxSize();
|
||||||
|
|
||||||
|
|
||||||
// BInvoker interface
|
// BInvoker interface
|
||||||
virtual status_t Invoke(BMessage* message = NULL);
|
virtual status_t Invoke(BMessage* message = NULL);
|
||||||
|
|||||||
@@ -34,28 +34,24 @@ LaunchButton::fClickSpeed = 0;
|
|||||||
|
|
||||||
// constructor
|
// constructor
|
||||||
LaunchButton::LaunchButton(const char* name, uint32 id, const char* label,
|
LaunchButton::LaunchButton(const char* name, uint32 id, const char* label,
|
||||||
BMessage* message, BHandler* target)
|
BMessage* message, BHandler* target)
|
||||||
: IconButton(name, id, label, message, target),
|
: IconButton(name, id, label, message, target),
|
||||||
fRef(NULL),
|
fRef(NULL),
|
||||||
fAppSig(NULL),
|
fAppSig(NULL),
|
||||||
fDescription(""),
|
fDescription(""),
|
||||||
fAnticipatingDrop(false),
|
fAnticipatingDrop(false),
|
||||||
fLastClickTime(0)
|
fLastClickTime(0),
|
||||||
|
fIconSize(DEFAULT_ICON_SIZE)
|
||||||
{
|
{
|
||||||
if (fClickSpeed == 0 || get_click_speed(&fClickSpeed) < B_OK)
|
if (fClickSpeed == 0 || get_click_speed(&fClickSpeed) < B_OK)
|
||||||
fClickSpeed = 500000;
|
fClickSpeed = 500000;
|
||||||
|
|
||||||
BSize size(32.0 + 8.0, 32.0 + 8.0);
|
|
||||||
SetExplicitMinSize(size);
|
|
||||||
SetExplicitMaxSize(size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// destructor
|
// destructor
|
||||||
LaunchButton::~LaunchButton()
|
LaunchButton::~LaunchButton()
|
||||||
{
|
{
|
||||||
delete fRef;
|
delete fRef;
|
||||||
if (fAppSig)
|
free(fAppSig);
|
||||||
free(fAppSig);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// AttachedToWindow
|
// AttachedToWindow
|
||||||
@@ -290,8 +286,7 @@ void
|
|||||||
LaunchButton::SetTo(const char* appSig, bool updateIcon)
|
LaunchButton::SetTo(const char* appSig, bool updateIcon)
|
||||||
{
|
{
|
||||||
if (appSig) {
|
if (appSig) {
|
||||||
if (fAppSig)
|
free(fAppSig);
|
||||||
free(fAppSig);
|
|
||||||
fAppSig = strdup(appSig);
|
fAppSig = strdup(appSig);
|
||||||
if (updateIcon) {
|
if (updateIcon) {
|
||||||
entry_ref ref;
|
entry_ref ref;
|
||||||
@@ -310,6 +305,22 @@ LaunchButton::SetDescription(const char* text)
|
|||||||
_UpdateToolTip();
|
_UpdateToolTip();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetIconSize
|
||||||
|
void
|
||||||
|
LaunchButton::SetIconSize(uint32 size)
|
||||||
|
{
|
||||||
|
if (fIconSize == size)
|
||||||
|
return;
|
||||||
|
|
||||||
|
fIconSize = size;
|
||||||
|
_UpdateIcon(fRef);
|
||||||
|
|
||||||
|
InvalidateLayout();
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
// #pragma mark -
|
||||||
|
|
||||||
// _UpdateToolTip
|
// _UpdateToolTip
|
||||||
void
|
void
|
||||||
LaunchButton::_UpdateToolTip()
|
LaunchButton::_UpdateToolTip()
|
||||||
@@ -339,8 +350,11 @@ LaunchButton::_UpdateToolTip()
|
|||||||
void
|
void
|
||||||
LaunchButton::_UpdateIcon(const entry_ref* ref)
|
LaunchButton::_UpdateIcon(const entry_ref* ref)
|
||||||
{
|
{
|
||||||
BBitmap* icon = new BBitmap(BRect(0.0, 0.0, 31.0, 31.0), B_RGBA32);
|
BBitmap* icon = new BBitmap(BRect(0.0, 0.0, fIconSize - 1,
|
||||||
if (BNodeInfo::GetTrackerIcon(ref, icon, B_LARGE_ICON) >= B_OK)
|
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);
|
SetIcon(icon);
|
||||||
|
|
||||||
delete icon;
|
delete icon;
|
||||||
|
|||||||
@@ -52,6 +52,10 @@ class LaunchButton : public IconButton {
|
|||||||
const char* Description() const
|
const char* Description() const
|
||||||
{ return fDescription.String(); }
|
{ return fDescription.String(); }
|
||||||
|
|
||||||
|
void SetIconSize(uint32 size);
|
||||||
|
uint32 IconSize() const
|
||||||
|
{ return fIconSize; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _UpdateToolTip();
|
void _UpdateToolTip();
|
||||||
void _UpdateIcon(const entry_ref* ref);
|
void _UpdateIcon(const entry_ref* ref);
|
||||||
@@ -64,6 +68,8 @@ class LaunchButton : public IconButton {
|
|||||||
bigtime_t fLastClickTime;
|
bigtime_t fLastClickTime;
|
||||||
BPoint fDragStart;
|
BPoint fDragStart;
|
||||||
|
|
||||||
|
uint32 fIconSize;
|
||||||
|
|
||||||
static bigtime_t fClickSpeed;
|
static bigtime_t fClickSpeed;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -357,6 +357,11 @@ MainWindow::LoadSettings(const BMessage* message)
|
|||||||
if (message->FindInt32("orientation", &orientation) == B_OK)
|
if (message->FindInt32("orientation", &orientation) == B_OK)
|
||||||
fPadView->SetOrientation((enum orientation)orientation);
|
fPadView->SetOrientation((enum orientation)orientation);
|
||||||
|
|
||||||
|
// restore icon size
|
||||||
|
int32 iconSize;
|
||||||
|
if (message->FindInt32("icon size", &iconSize) == B_OK)
|
||||||
|
fPadView->SetIconSize(iconSize);
|
||||||
|
|
||||||
// restore buttons
|
// restore buttons
|
||||||
const char* path;
|
const char* path;
|
||||||
bool buttonAdded = false;
|
bool buttonAdded = false;
|
||||||
@@ -430,6 +435,10 @@ MainWindow::SaveSettings(BMessage* message)
|
|||||||
(int32)fPadView->Orientation()) != B_OK)
|
(int32)fPadView->Orientation()) != B_OK)
|
||||||
message->AddInt32("orientation", (int32)fPadView->Orientation());
|
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
|
// store buttons
|
||||||
message->RemoveName("path");
|
message->RemoveName("path");
|
||||||
message->RemoveName("description");
|
message->RemoveName("description");
|
||||||
|
|||||||
@@ -22,10 +22,12 @@
|
|||||||
#include "LaunchButton.h"
|
#include "LaunchButton.h"
|
||||||
#include "MainWindow.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 {
|
enum {
|
||||||
MSG_TOGGLE_LAYOUT = 'tgll'
|
MSG_TOGGLE_LAYOUT = 'tgll',
|
||||||
|
MSG_SET_ICON_SIZE = 'stis'
|
||||||
};
|
};
|
||||||
|
|
||||||
// constructor
|
// constructor
|
||||||
@@ -33,11 +35,12 @@ PadView::PadView(const char* name)
|
|||||||
: BView(name, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE, NULL),
|
: BView(name, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE, NULL),
|
||||||
fDragging(false),
|
fDragging(false),
|
||||||
fClickTime(0),
|
fClickTime(0),
|
||||||
fButtonLayout(new BGroupLayout(B_VERTICAL, 4))
|
fButtonLayout(new BGroupLayout(B_VERTICAL, 4)),
|
||||||
|
fIconSize(DEFAULT_ICON_SIZE)
|
||||||
{
|
{
|
||||||
SetViewColor(B_TRANSPARENT_32_BIT);
|
SetViewColor(B_TRANSPARENT_32_BIT);
|
||||||
SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
get_click_speed(&kActivationDelay);
|
get_click_speed(&sActivationDelay);
|
||||||
|
|
||||||
fButtonLayout->SetInsets(2, 7, 2, 2);
|
fButtonLayout->SetInsets(2, 7, 2, 2);
|
||||||
SetLayout(fButtonLayout);
|
SetLayout(fButtonLayout);
|
||||||
@@ -138,6 +141,11 @@ PadView::MessageReceived(BMessage* message)
|
|||||||
fButtonLayout->SetOrientation(B_HORIZONTAL);
|
fButtonLayout->SetOrientation(B_HORIZONTAL);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case MSG_SET_ICON_SIZE:
|
||||||
|
uint32 size;
|
||||||
|
if (message->FindInt32("size", (int32*)&size) == B_OK)
|
||||||
|
SetIconSize(size);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
BView::MessageReceived(message);
|
BView::MessageReceived(message);
|
||||||
break;
|
break;
|
||||||
@@ -184,7 +192,7 @@ PadView::MouseDown(BPoint where)
|
|||||||
window->Activate(false);
|
window->Activate(false);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (system_time() - fClickTime < kActivationDelay) {
|
if (system_time() - fClickTime < sActivationDelay) {
|
||||||
window->Minimize(true);
|
window->Minimize(true);
|
||||||
fClickTime = 0;
|
fClickTime = 0;
|
||||||
} else {
|
} else {
|
||||||
@@ -205,7 +213,7 @@ PadView::MouseUp(BPoint where)
|
|||||||
uint32 buttons;
|
uint32 buttons;
|
||||||
window->CurrentMessage()->FindInt32("buttons", (int32*)&buttons);
|
window->CurrentMessage()->FindInt32("buttons", (int32*)&buttons);
|
||||||
if (buttons & B_PRIMARY_MOUSE_BUTTON
|
if (buttons & B_PRIMARY_MOUSE_BUTTON
|
||||||
&& system_time() - fClickTime < kActivationDelay
|
&& system_time() - fClickTime < sActivationDelay
|
||||||
&& window->IsActive())
|
&& window->IsActive())
|
||||||
window->Activate();
|
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 (where.x >= windowFrame.left && where.x <= windowFrame.right) {
|
||||||
if (position.y < 0.5 && where.y == frame.top)
|
if (position.y < 0.5 && where.y == frame.top)
|
||||||
raise = true;
|
raise = true;
|
||||||
else if (position.y > 0.5 && where.y == frame.top)
|
else if (position.y > 0.5 && where.y == frame.bottom)
|
||||||
raise = true;
|
raise = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -258,6 +266,8 @@ PadView::MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage)
|
|||||||
void
|
void
|
||||||
PadView::AddButton(LaunchButton* button, LaunchButton* beforeButton)
|
PadView::AddButton(LaunchButton* button, LaunchButton* beforeButton)
|
||||||
{
|
{
|
||||||
|
button->SetIconSize(fIconSize);
|
||||||
|
|
||||||
if (beforeButton)
|
if (beforeButton)
|
||||||
fButtonLayout->AddView(fButtonLayout->IndexOfView(beforeButton), button);
|
fButtonLayout->AddView(fButtonLayout->IndexOfView(beforeButton), button);
|
||||||
else
|
else
|
||||||
@@ -338,6 +348,20 @@ PadView::DisplayMenu(BPoint where, LaunchButton* button) const
|
|||||||
item->SetTarget(this);
|
item->SetTarget(this);
|
||||||
settingsM->AddItem(item);
|
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;
|
uint32 what = window->Look() == B_BORDERED_WINDOW_LOOK ? MSG_SHOW_BORDER : MSG_HIDE_BORDER;
|
||||||
item = new BMenuItem("Show Window Border", new BMessage(what));
|
item = new BMenuItem("Show Window Border", new BMessage(what));
|
||||||
item->SetTarget(window);
|
item->SetTarget(window);
|
||||||
@@ -416,4 +440,24 @@ PadView::Orientation() const
|
|||||||
return fButtonLayout->Orientation();
|
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 BGroupLayout;
|
||||||
class LaunchButton;
|
class LaunchButton;
|
||||||
|
|
||||||
|
#define DEFAULT_ICON_SIZE 32
|
||||||
|
|
||||||
class PadView : public BView {
|
class PadView : public BView {
|
||||||
public:
|
public:
|
||||||
PadView(const char* name);
|
PadView(const char* name);
|
||||||
@@ -39,11 +41,15 @@ class PadView : public BView {
|
|||||||
void SetOrientation(enum orientation orientation);
|
void SetOrientation(enum orientation orientation);
|
||||||
enum orientation Orientation() const;
|
enum orientation Orientation() const;
|
||||||
|
|
||||||
|
void SetIconSize(uint32 size);
|
||||||
|
uint32 IconSize() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BPoint fDragOffset;
|
BPoint fDragOffset;
|
||||||
bool fDragging;
|
bool fDragging;
|
||||||
bigtime_t fClickTime;
|
bigtime_t fClickTime;
|
||||||
BGroupLayout* fButtonLayout;
|
BGroupLayout* fButtonLayout;
|
||||||
|
uint32 fIconSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PAD_VIEW_H
|
#endif // PAD_VIEW_H
|
||||||
|
|||||||
Reference in New Issue
Block a user