Move icon related constants to InterfaceDefs.h
There will be non-BControl views to use those as well.
This commit is contained in:
@@ -21,37 +21,6 @@ class BWindow;
|
||||
|
||||
|
||||
class BControl : public BView, public BInvoker {
|
||||
public:
|
||||
// Values for [Set]IconBitmap(). Not all types are applicable for
|
||||
// all controls.
|
||||
enum {
|
||||
B_OFF_BITMAP = 0x00,
|
||||
B_ON_BITMAP = 0x01,
|
||||
B_PARTIALLY_ON_BITMAP = 0x02,
|
||||
|
||||
// flag, can be combined with any of the above
|
||||
B_DISABLED_BITMAP = 0x80,
|
||||
// disabled version of the specified bitmap
|
||||
};
|
||||
|
||||
// flags for SetIconBitmap()
|
||||
enum {
|
||||
B_KEEP_BITMAP = 0x0001,
|
||||
// transfer bitmap ownership to BControl object
|
||||
};
|
||||
|
||||
// flags for SetIcon()
|
||||
enum {
|
||||
B_TRIM_BITMAP = 0x0100,
|
||||
// crop the bitmap to the not fully transparent area, may
|
||||
// change the icon size
|
||||
B_TRIM_BITMAP_KEEP_ASPECT = 0x0200,
|
||||
// like B_TRIM_BITMAP, but keeps the aspect ratio
|
||||
B_CREATE_ON_BITMAP = 0x0400,
|
||||
B_CREATE_PARTIALLY_ON_BITMAP = 0x0800,
|
||||
B_CREATE_DISABLED_BITMAPS = 0x1000,
|
||||
};
|
||||
|
||||
public:
|
||||
BControl(BRect frame, const char* name,
|
||||
const char* label, BMessage* message,
|
||||
|
||||
@@ -357,6 +357,39 @@ const float B_HIGHLIGHT_BACKGROUND_TINT = B_DARKEN_2_TINT;
|
||||
const float B_DISABLED_MARK_TINT = B_LIGHTEN_2_TINT;
|
||||
|
||||
|
||||
// Icon related constants
|
||||
|
||||
// Values for [Set]IconBitmap() of various view classes. Not all types are
|
||||
// applicable for all views.
|
||||
enum {
|
||||
B_INACTIVE_ICON_BITMAP = 0x00,
|
||||
B_ACTIVE_ICON_BITMAP = 0x01,
|
||||
B_PARTIALLY_ACTIVATE_ICON_BITMAP = 0x02,
|
||||
|
||||
// flag, can be combined with any of the above
|
||||
B_DISABLED_ICON_BITMAP = 0x80,
|
||||
// disabled version of the specified bitmap
|
||||
};
|
||||
|
||||
// flags for SetIconBitmap() of various view classes
|
||||
enum {
|
||||
B_KEEP_ICON_BITMAP = 0x0001,
|
||||
// transfer bitmap ownership to the view
|
||||
};
|
||||
|
||||
// flags for SetIcon() of various view classes
|
||||
enum {
|
||||
B_TRIM_ICON_BITMAP = 0x0100,
|
||||
// crop the bitmap to the not fully transparent area; may change the
|
||||
// icon size
|
||||
B_TRIM_ICON_BITMAP_KEEP_ASPECT = 0x0200,
|
||||
// like B_TRIM_BITMAP, but keeps the aspect ratio
|
||||
B_CREATE_ACTIVE_ICON_BITMAP = 0x0400,
|
||||
B_CREATE_PARTIALLY_ACTIVE_ICON_BITMAP = 0x0800,
|
||||
B_CREATE_DISABLED_ICON_BITMAPS = 0x1000,
|
||||
};
|
||||
|
||||
|
||||
status_t get_deskbar_frame(BRect* frame);
|
||||
|
||||
const color_map* system_colors();
|
||||
|
||||
@@ -123,8 +123,9 @@ BButton::Draw(BRect updateRect)
|
||||
rect.InsetBy(kLabelMargin, kLabelMargin);
|
||||
|
||||
const BBitmap* icon = IconBitmap(
|
||||
(Value() == B_CONTROL_OFF ? B_OFF_BITMAP : B_ON_BITMAP)
|
||||
| (IsEnabled() ? 0 : B_DISABLED_BITMAP));
|
||||
(Value() == B_CONTROL_OFF
|
||||
? B_INACTIVE_ICON_BITMAP : B_ACTIVE_ICON_BITMAP)
|
||||
| (IsEnabled() ? 0 : B_DISABLED_ICON_BITMAP));
|
||||
be_control_look->DrawLabel(this, Label(), icon, rect, updateRect,
|
||||
base, flags, BAlignment(B_ALIGN_CENTER, B_ALIGN_MIDDLE));
|
||||
}
|
||||
@@ -484,7 +485,7 @@ status_t
|
||||
BButton::SetIcon(const BBitmap* icon, uint32 flags)
|
||||
{
|
||||
return BControl::SetIcon(icon,
|
||||
flags | B_CREATE_ON_BITMAP | B_CREATE_DISABLED_BITMAPS);
|
||||
flags | B_CREATE_ACTIVE_ICON_BITMAP | B_CREATE_DISABLED_ICON_BITMAPS);
|
||||
}
|
||||
|
||||
|
||||
@@ -527,7 +528,7 @@ BButton::_ValidatePreferredSize()
|
||||
width += (float)ceil(StringWidth(label));
|
||||
}
|
||||
|
||||
const BBitmap* icon = IconBitmap(B_OFF_BITMAP);
|
||||
const BBitmap* icon = IconBitmap(B_INACTIVE_ICON_BITMAP);
|
||||
if (icon != NULL)
|
||||
width += icon->Bounds().Width() + 1;
|
||||
|
||||
|
||||
@@ -117,7 +117,7 @@ BCheckBox::Draw(BRect updateRect)
|
||||
+ be_control_look->DefaultLabelSpacing();
|
||||
|
||||
const BBitmap* icon = IconBitmap(
|
||||
B_OFF_BITMAP | (IsEnabled() ? 0 : B_DISABLED_BITMAP));
|
||||
B_INACTIVE_ICON_BITMAP | (IsEnabled() ? 0 : B_DISABLED_ICON_BITMAP));
|
||||
|
||||
be_control_look->DrawLabel(this, Label(), icon, labelRect, updateRect,
|
||||
base, flags);
|
||||
@@ -456,7 +456,7 @@ BCheckBox::Perform(perform_code code, void* _data)
|
||||
status_t
|
||||
BCheckBox::SetIcon(const BBitmap* icon, uint32 flags)
|
||||
{
|
||||
return BControl::SetIcon(icon, flags | B_CREATE_DISABLED_BITMAPS);
|
||||
return BControl::SetIcon(icon, flags | B_CREATE_DISABLED_ICON_BITMAPS);
|
||||
}
|
||||
|
||||
|
||||
@@ -518,7 +518,7 @@ BCheckBox::_ValidatePreferredSize()
|
||||
float width = rect.right + rect.left;
|
||||
float height = rect.bottom + rect.top;
|
||||
|
||||
const BBitmap* icon = IconBitmap(B_OFF_BITMAP);
|
||||
const BBitmap* icon = IconBitmap(B_INACTIVE_ICON_BITMAP);
|
||||
if (icon != NULL) {
|
||||
width += be_control_look->DefaultLabelSpacing()
|
||||
+ icon->Bounds().Width() + 1;
|
||||
|
||||
@@ -89,9 +89,9 @@ public:
|
||||
|
||||
bool SetBitmap(BBitmap* bitmap, uint32 which)
|
||||
{
|
||||
IconList& list = (which & B_DISABLED_BITMAP) == 0
|
||||
IconList& list = (which & B_DISABLED_ICON_BITMAP) == 0
|
||||
? fEnabledBitmaps : fDisabledBitmaps;
|
||||
which &= ~uint32(B_DISABLED_BITMAP);
|
||||
which &= ~uint32(B_DISABLED_ICON_BITMAP);
|
||||
|
||||
int32 count = list.CountItems();
|
||||
if ((int32)which < count) {
|
||||
@@ -109,9 +109,9 @@ public:
|
||||
|
||||
BBitmap* Bitmap(uint32 which) const
|
||||
{
|
||||
const IconList& list = (which & B_DISABLED_BITMAP) == 0
|
||||
const IconList& list = (which & B_DISABLED_ICON_BITMAP) == 0
|
||||
? fEnabledBitmaps : fDisabledBitmaps;
|
||||
return list.ItemAt(which & ~uint32(B_DISABLED_BITMAP));
|
||||
return list.ItemAt(which & ~uint32(B_DISABLED_ICON_BITMAP));
|
||||
}
|
||||
|
||||
void DeleteBitmaps()
|
||||
@@ -651,16 +651,17 @@ BControl::SetIcon(const BBitmap* bitmap, uint32 flags)
|
||||
|
||||
// trim the bitmap, if requested and the bitmap actually has alpha
|
||||
status_t error;
|
||||
if ((flags & (B_TRIM_BITMAP | B_TRIM_BITMAP_KEEP_ASPECT)) != 0
|
||||
if ((flags & (B_TRIM_ICON_BITMAP | B_TRIM_ICON_BITMAP_KEEP_ASPECT)) != 0
|
||||
&& hasAlpha) {
|
||||
if (bitmap->ColorSpace() == B_RGBA32) {
|
||||
error = _TrimBitmap(bitmap,
|
||||
(flags & B_TRIM_BITMAP_KEEP_ASPECT) != 0, trimmedBitmap);
|
||||
(flags & B_TRIM_ICON_BITMAP_KEEP_ASPECT) != 0, trimmedBitmap);
|
||||
} else {
|
||||
BBitmap* rgb32Bitmap = _ConvertToRGB32(bitmap, true);
|
||||
if (rgb32Bitmap != NULL) {
|
||||
error = _TrimBitmap(rgb32Bitmap,
|
||||
(flags & B_TRIM_BITMAP_KEEP_ASPECT) != 0, trimmedBitmap);
|
||||
(flags & B_TRIM_ICON_BITMAP_KEEP_ASPECT) != 0,
|
||||
trimmedBitmap);
|
||||
delete rgb32Bitmap;
|
||||
} else
|
||||
error = B_NO_MEMORY;
|
||||
@@ -707,7 +708,7 @@ BControl::SetIconBitmap(const BBitmap* bitmap, uint32 which, uint32 flags)
|
||||
if (!bitmap->IsValid())
|
||||
return B_BAD_VALUE;
|
||||
|
||||
if ((flags & B_KEEP_BITMAP) != 0) {
|
||||
if ((flags & B_KEEP_ICON_BITMAP) != 0) {
|
||||
ourBitmap = const_cast<BBitmap*>(bitmap);
|
||||
} else {
|
||||
ourBitmap = _ConvertToRGB32(bitmap);
|
||||
@@ -869,21 +870,23 @@ BControl::_MakeBitmaps(const BBitmap* bitmap, uint32 flags)
|
||||
ObjectDeleter<IconData> iconDataDeleter(iconData);
|
||||
|
||||
color_space format = bitmap->ColorSpace();
|
||||
BBitmap* normalBitmap = iconData->CreateBitmap(b, format, B_OFF_BITMAP);
|
||||
BBitmap* normalBitmap = iconData->CreateBitmap(b, format,
|
||||
B_INACTIVE_ICON_BITMAP);
|
||||
if (normalBitmap == NULL)
|
||||
return B_NO_MEMORY;
|
||||
|
||||
BBitmap* disabledBitmap = NULL;
|
||||
if ((flags & B_CREATE_DISABLED_BITMAPS) != 0) {
|
||||
if ((flags & B_CREATE_DISABLED_ICON_BITMAPS) != 0) {
|
||||
disabledBitmap = iconData->CreateBitmap(b, format,
|
||||
B_OFF_BITMAP | B_DISABLED_BITMAP);
|
||||
B_INACTIVE_ICON_BITMAP | B_DISABLED_ICON_BITMAP);
|
||||
if (disabledBitmap == NULL)
|
||||
return B_NO_MEMORY;
|
||||
}
|
||||
|
||||
BBitmap* clickedBitmap = NULL;
|
||||
if ((flags & (B_CREATE_ON_BITMAP | B_CREATE_PARTIALLY_ON_BITMAP)) != 0) {
|
||||
clickedBitmap = iconData->CreateBitmap(b, format, B_ON_BITMAP);
|
||||
if ((flags & (B_CREATE_ACTIVE_ICON_BITMAP
|
||||
| B_CREATE_PARTIALLY_ACTIVE_ICON_BITMAP)) != 0) {
|
||||
clickedBitmap = iconData->CreateBitmap(b, format, B_ACTIVE_ICON_BITMAP);
|
||||
if (clickedBitmap == NULL)
|
||||
return B_NO_MEMORY;
|
||||
}
|
||||
@@ -891,7 +894,7 @@ BControl::_MakeBitmaps(const BBitmap* bitmap, uint32 flags)
|
||||
BBitmap* disabledClickedBitmap = NULL;
|
||||
if (disabledBitmap != NULL && clickedBitmap != NULL) {
|
||||
disabledClickedBitmap = iconData->CreateBitmap(b, format,
|
||||
B_ON_BITMAP | B_DISABLED_BITMAP);
|
||||
B_ACTIVE_ICON_BITMAP | B_DISABLED_ICON_BITMAP);
|
||||
if (disabledClickedBitmap == NULL)
|
||||
return B_NO_MEMORY;
|
||||
}
|
||||
@@ -1020,12 +1023,15 @@ BControl::_MakeBitmaps(const BBitmap* bitmap, uint32 flags)
|
||||
}
|
||||
|
||||
// make the partially-on bitmaps a copy of the on bitmaps
|
||||
if ((flags & B_CREATE_PARTIALLY_ON_BITMAP) != 0) {
|
||||
if (iconData->CopyBitmap(clickedBitmap, B_PARTIALLY_ON_BITMAP) == NULL)
|
||||
if ((flags & B_CREATE_PARTIALLY_ACTIVE_ICON_BITMAP) != 0) {
|
||||
if (iconData->CopyBitmap(clickedBitmap,
|
||||
B_PARTIALLY_ACTIVATE_ICON_BITMAP) == NULL) {
|
||||
return B_NO_MEMORY;
|
||||
if ((flags & B_CREATE_DISABLED_BITMAPS) != 0) {
|
||||
}
|
||||
if ((flags & B_CREATE_DISABLED_ICON_BITMAPS) != 0) {
|
||||
if (iconData->CopyBitmap(disabledClickedBitmap,
|
||||
B_PARTIALLY_ON_BITMAP | B_DISABLED_BITMAP) == NULL) {
|
||||
B_PARTIALLY_ACTIVATE_ICON_BITMAP | B_DISABLED_ICON_BITMAP)
|
||||
== NULL) {
|
||||
return B_NO_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user