Moved IconButton from LaunchBox (actually the updated version from WebPositive)
into libshared.a as BPrivate::BIconButton. Removed some outdated functionality as well (now only uses BControlLook for drawing, cleaned up custom drawing). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40587 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,42 +1,55 @@
|
||||
/*
|
||||
* Copyright 2006, Haiku.
|
||||
* Copyright 2006-2011, Haiku.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Stephan Aßmus <superstippi@gmx.de>
|
||||
*/
|
||||
|
||||
/** gui class that loads an image from disk and shows it
|
||||
as clickable button */
|
||||
|
||||
// TODO: inherit from BControl?
|
||||
|
||||
// NOTE: this file is a duplicate of the version in Icon-O-Matic/generic
|
||||
// it should be placed into a common folder for generic useful stuff
|
||||
|
||||
#ifndef ICON_BUTTON_H
|
||||
#define ICON_BUTTON_H
|
||||
|
||||
|
||||
//! GUI class that loads an image from disk and shows it as clickable button.
|
||||
|
||||
// TODO: inherit from BControl
|
||||
|
||||
|
||||
#include <Invoker.h>
|
||||
#include <String.h>
|
||||
#include <View.h>
|
||||
|
||||
|
||||
class BBitmap;
|
||||
class BMimeType;
|
||||
|
||||
class IconButton : public BView, public BInvoker {
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
|
||||
class BIconButton : public BView, public BInvoker {
|
||||
public:
|
||||
IconButton(const char* name,
|
||||
BIconButton(const char* name,
|
||||
uint32 id,
|
||||
const char* label = NULL,
|
||||
BMessage* message = NULL,
|
||||
BHandler* target = NULL);
|
||||
virtual ~IconButton();
|
||||
virtual ~BIconButton();
|
||||
|
||||
// BView interface
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
virtual void AttachedToWindow();
|
||||
|
||||
virtual void Draw(BRect updateRect);
|
||||
virtual bool ShouldDrawBorder() const;
|
||||
virtual void DrawBorder(BRect& frame,
|
||||
const BRect& updateRect,
|
||||
const rgb_color& backgroundColor,
|
||||
uint32 controlLookFlags);
|
||||
virtual void DrawBackground(BRect& frame,
|
||||
const BRect& updateRect,
|
||||
const rgb_color& backgroundColor,
|
||||
uint32 controlLookFlags);
|
||||
|
||||
virtual void MouseDown(BPoint where);
|
||||
virtual void MouseUp(BPoint where);
|
||||
virtual void MouseMoved(BPoint where, uint32 transit,
|
||||
@@ -50,7 +63,7 @@ public:
|
||||
// BInvoker interface
|
||||
virtual status_t Invoke(BMessage* message = NULL);
|
||||
|
||||
// IconButton
|
||||
// BIconButton
|
||||
bool IsValid() const;
|
||||
|
||||
virtual int32 Value() const;
|
||||
@@ -64,6 +77,7 @@ public:
|
||||
uint32 ID() const
|
||||
{ return fID; }
|
||||
|
||||
status_t SetIcon(int32 resourceID);
|
||||
status_t SetIcon(const char* pathToBitmap);
|
||||
status_t SetIcon(const BBitmap* bitmap);
|
||||
status_t SetIcon(const BMimeType* fileType,
|
||||
@@ -73,23 +87,11 @@ public:
|
||||
color_space format,
|
||||
bool convertToBW = false);
|
||||
void ClearIcon();
|
||||
void TrimIcon(bool keepAspect = true);
|
||||
|
||||
BBitmap* Bitmap() const;
|
||||
// caller has to delete the returned bitmap
|
||||
|
||||
virtual bool DrawBorder() const;
|
||||
virtual void DrawNormalBorder(BRect r,
|
||||
rgb_color background,
|
||||
rgb_color shadow,
|
||||
rgb_color darkShadow,
|
||||
rgb_color lightShadow,
|
||||
rgb_color light);
|
||||
virtual void DrawPressedBorder(BRect r,
|
||||
rgb_color background,
|
||||
rgb_color shadow,
|
||||
rgb_color darkShadow,
|
||||
rgb_color lightShadow,
|
||||
rgb_color light);
|
||||
const BString& Label() const;
|
||||
|
||||
protected:
|
||||
enum {
|
||||
@@ -105,19 +107,14 @@ protected:
|
||||
void _ClearFlags(uint32 flags);
|
||||
bool _HasFlags(uint32 flags) const;
|
||||
|
||||
void _DrawFrame(BRect frame,
|
||||
rgb_color col1,
|
||||
rgb_color col2,
|
||||
rgb_color col3,
|
||||
rgb_color col4);
|
||||
|
||||
// private:
|
||||
private:
|
||||
BBitmap* _ConvertToRGB32(const BBitmap* bitmap) const;
|
||||
status_t _MakeBitmaps(const BBitmap* bitmap);
|
||||
void _DeleteBitmaps();
|
||||
void _SendMessage() const;
|
||||
void _Update();
|
||||
|
||||
private:
|
||||
uint32 fButtonState;
|
||||
int32 fID;
|
||||
BBitmap* fNormalBitmap;
|
||||
@@ -129,4 +126,11 @@ protected:
|
||||
BHandler* fTargetCache;
|
||||
};
|
||||
|
||||
|
||||
} // namespac BPrivate
|
||||
|
||||
|
||||
using BPrivate::BIconButton;
|
||||
|
||||
|
||||
#endif // ICON_BUTTON_H
|
||||
@@ -4,7 +4,6 @@ UsePrivateHeaders shared ;
|
||||
|
||||
Application LaunchBox :
|
||||
App.cpp
|
||||
IconButton.cpp
|
||||
LaunchButton.cpp
|
||||
main.cpp
|
||||
MainWindow.cpp
|
||||
@@ -20,7 +19,6 @@ DoCatalogs LaunchBox :
|
||||
x-vnd.Haiku-LaunchBox
|
||||
:
|
||||
App.cpp
|
||||
IconButton.cpp
|
||||
LaunchButton.cpp
|
||||
MainWindow.cpp
|
||||
NamePanel.cpp
|
||||
|
||||
@@ -42,7 +42,7 @@ LaunchButton::sIgnoreDoubleClick = true;
|
||||
LaunchButton::LaunchButton(const char* name, uint32 id, const char* label,
|
||||
BMessage* message, BHandler* target)
|
||||
:
|
||||
IconButton(name, id, label, message, target),
|
||||
BIconButton(name, id, label, message, target),
|
||||
fRef(NULL),
|
||||
fAppSig(NULL),
|
||||
fDescription(""),
|
||||
@@ -65,7 +65,7 @@ LaunchButton::~LaunchButton()
|
||||
void
|
||||
LaunchButton::AttachedToWindow()
|
||||
{
|
||||
IconButton::AttachedToWindow();
|
||||
BIconButton::AttachedToWindow();
|
||||
_UpdateToolTip();
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ LaunchButton::Draw(BRect updateRect)
|
||||
ConstrainClippingRegion(®ion);
|
||||
}
|
||||
if (IsValid()) {
|
||||
IconButton::Draw(updateRect);
|
||||
BIconButton::Draw(updateRect);
|
||||
} else {
|
||||
rgb_color background = LowColor();
|
||||
rgb_color lightShadow = tint_color(background,
|
||||
@@ -149,7 +149,7 @@ LaunchButton::MessageReceived(BMessage* message)
|
||||
case B_PASTE:
|
||||
case B_MODIFIERS_CHANGED:
|
||||
default:
|
||||
IconButton::MessageReceived(message);
|
||||
BIconButton::MessageReceived(message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -177,7 +177,7 @@ LaunchButton::MouseDown(BPoint where)
|
||||
}
|
||||
}
|
||||
if (callInherited)
|
||||
IconButton::MouseDown(where);
|
||||
BIconButton::MouseDown(where);
|
||||
}
|
||||
|
||||
|
||||
@@ -188,7 +188,7 @@ LaunchButton::MouseUp(BPoint where)
|
||||
fAnticipatingDrop = false;
|
||||
Invalidate();
|
||||
}
|
||||
IconButton::MouseUp(where);
|
||||
BIconButton::MouseUp(where);
|
||||
}
|
||||
|
||||
|
||||
@@ -238,11 +238,12 @@ LaunchButton::MouseMoved(BPoint where, uint32 transit,
|
||||
BMessage message(B_SIMPLE_DATA);
|
||||
message.AddPointer("button", this);
|
||||
message.AddRef("refs", fRef);
|
||||
// DragMessage takes ownership of the bitmap.
|
||||
DragMessage(&message, bitmap, B_OP_ALPHA, fDragStart);
|
||||
}
|
||||
}
|
||||
}
|
||||
IconButton::MouseMoved(where, transit, dragMessage);
|
||||
BIconButton::MouseMoved(where, transit, dragMessage);
|
||||
}
|
||||
|
||||
|
||||
@@ -262,11 +263,11 @@ LaunchButton::PreferredSize()
|
||||
float hPadding = max_c(6.0, ceilf(minHeight / 3.0));
|
||||
float vPadding = max_c(6.0, ceilf(minWidth / 3.0));
|
||||
|
||||
if (fLabel.CountChars() > 0) {
|
||||
if (Label().CountChars() > 0) {
|
||||
font_height fh;
|
||||
GetFontHeight(&fh);
|
||||
minHeight += ceilf(fh.ascent + fh.descent) + vPadding;
|
||||
minWidth += StringWidth(fLabel.String()) + vPadding;
|
||||
minWidth += StringWidth(Label().String()) + vPadding;
|
||||
}
|
||||
|
||||
return BSize(minWidth + hPadding, minHeight + vPadding);
|
||||
@@ -427,3 +428,21 @@ LaunchButton::_NotifySettingsChanged()
|
||||
{
|
||||
be_app->PostMessage(MSG_SETTINGS_CHANGED);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
LaunchButton::_DrawFrame(BRect r, rgb_color col1, rgb_color col2,
|
||||
rgb_color col3, rgb_color col4)
|
||||
{
|
||||
BeginLineArray(8);
|
||||
AddLine(BPoint(r.left, r.bottom), BPoint(r.left, r.top), col1);
|
||||
AddLine(BPoint(r.left + 1.0, r.top), BPoint(r.right, r.top), col1);
|
||||
AddLine(BPoint(r.right, r.top + 1.0), BPoint(r.right, r.bottom), col2);
|
||||
AddLine(BPoint(r.right - 1.0, r.bottom), BPoint(r.left + 1.0, r.bottom), col2);
|
||||
r.InsetBy(1.0, 1.0);
|
||||
AddLine(BPoint(r.left, r.bottom), BPoint(r.left, r.top), col3);
|
||||
AddLine(BPoint(r.left + 1.0, r.top), BPoint(r.right, r.top), col3);
|
||||
AddLine(BPoint(r.right, r.top + 1.0), BPoint(r.right, r.bottom), col4);
|
||||
AddLine(BPoint(r.right - 1.0, r.bottom), BPoint(r.left + 1.0, r.bottom), col4);
|
||||
EndLineArray();
|
||||
}
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
/*
|
||||
* Copyright 2006-2009, Stephan Aßmus <[email protected]>
|
||||
* Copyright 2006-2011, Stephan Aßmus <[email protected]>
|
||||
* All rights reserved. Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef LAUNCH_BUTTON_H
|
||||
#define LAUNCH_BUTTON_H
|
||||
|
||||
|
||||
#include <IconButton.h>
|
||||
#include <List.h>
|
||||
#include <String.h>
|
||||
|
||||
#include "IconButton.h"
|
||||
|
||||
enum {
|
||||
MSG_ADD_SLOT = 'adsl',
|
||||
@@ -17,7 +18,8 @@ enum {
|
||||
MSG_LAUNCH = 'lnch',
|
||||
};
|
||||
|
||||
class LaunchButton : public IconButton {
|
||||
|
||||
class LaunchButton : public BIconButton {
|
||||
public:
|
||||
LaunchButton(const char* name, uint32 id,
|
||||
const char* label = NULL,
|
||||
@@ -25,7 +27,7 @@ public:
|
||||
BHandler* target = NULL);
|
||||
virtual ~LaunchButton();
|
||||
|
||||
// IconButton interface
|
||||
// BIconButton interface
|
||||
virtual void AttachedToWindow();
|
||||
virtual void Draw(BRect updateRect);
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
@@ -64,6 +66,11 @@ private:
|
||||
|
||||
void _NotifySettingsChanged();
|
||||
|
||||
void _DrawFrame(BRect frame,
|
||||
rgb_color left, rgb_color top,
|
||||
rgb_color right, rgb_color bottom);
|
||||
|
||||
private:
|
||||
entry_ref* fRef;
|
||||
char* fAppSig;
|
||||
BString fDescription;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -3,7 +3,7 @@ SubDir HAIKU_TOP src kits shared ;
|
||||
SetSubDirSupportedPlatformsBeOSCompatible ;
|
||||
AddSubDirSupportedPlatforms libbe_test ;
|
||||
|
||||
UseLibraryHeaders agg ;
|
||||
UseLibraryHeaders agg icon ;
|
||||
UsePrivateHeaders shared libbe ;
|
||||
UseHeaders [ FDirName $(HAIKU_COMMON_DEBUG_OBJECT_DIR) servers input ] ;
|
||||
UseHeaders [ FDirName $(HAIKU_TOP) src kits ] ;
|
||||
@@ -19,6 +19,7 @@ StaticLibrary libshared.a :
|
||||
CommandPipe.cpp
|
||||
DragTrackingFilter.cpp
|
||||
HashString.cpp
|
||||
IconButton.cpp
|
||||
Keymap.cpp
|
||||
NaturalCompare.cpp
|
||||
QueryFile.cpp
|
||||
|
||||
Reference in New Issue
Block a user