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 {
|
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:
|
public:
|
||||||
BControl(BRect frame, const char* name,
|
BControl(BRect frame, const char* name,
|
||||||
const char* label, BMessage* message,
|
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;
|
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);
|
status_t get_deskbar_frame(BRect* frame);
|
||||||
|
|
||||||
const color_map* system_colors();
|
const color_map* system_colors();
|
||||||
|
|||||||
@@ -123,8 +123,9 @@ BButton::Draw(BRect updateRect)
|
|||||||
rect.InsetBy(kLabelMargin, kLabelMargin);
|
rect.InsetBy(kLabelMargin, kLabelMargin);
|
||||||
|
|
||||||
const BBitmap* icon = IconBitmap(
|
const BBitmap* icon = IconBitmap(
|
||||||
(Value() == B_CONTROL_OFF ? B_OFF_BITMAP : B_ON_BITMAP)
|
(Value() == B_CONTROL_OFF
|
||||||
| (IsEnabled() ? 0 : B_DISABLED_BITMAP));
|
? B_INACTIVE_ICON_BITMAP : B_ACTIVE_ICON_BITMAP)
|
||||||
|
| (IsEnabled() ? 0 : B_DISABLED_ICON_BITMAP));
|
||||||
be_control_look->DrawLabel(this, Label(), icon, rect, updateRect,
|
be_control_look->DrawLabel(this, Label(), icon, rect, updateRect,
|
||||||
base, flags, BAlignment(B_ALIGN_CENTER, B_ALIGN_MIDDLE));
|
base, flags, BAlignment(B_ALIGN_CENTER, B_ALIGN_MIDDLE));
|
||||||
}
|
}
|
||||||
@@ -484,7 +485,7 @@ status_t
|
|||||||
BButton::SetIcon(const BBitmap* icon, uint32 flags)
|
BButton::SetIcon(const BBitmap* icon, uint32 flags)
|
||||||
{
|
{
|
||||||
return BControl::SetIcon(icon,
|
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));
|
width += (float)ceil(StringWidth(label));
|
||||||
}
|
}
|
||||||
|
|
||||||
const BBitmap* icon = IconBitmap(B_OFF_BITMAP);
|
const BBitmap* icon = IconBitmap(B_INACTIVE_ICON_BITMAP);
|
||||||
if (icon != NULL)
|
if (icon != NULL)
|
||||||
width += icon->Bounds().Width() + 1;
|
width += icon->Bounds().Width() + 1;
|
||||||
|
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ BCheckBox::Draw(BRect updateRect)
|
|||||||
+ be_control_look->DefaultLabelSpacing();
|
+ be_control_look->DefaultLabelSpacing();
|
||||||
|
|
||||||
const BBitmap* icon = IconBitmap(
|
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,
|
be_control_look->DrawLabel(this, Label(), icon, labelRect, updateRect,
|
||||||
base, flags);
|
base, flags);
|
||||||
@@ -456,7 +456,7 @@ BCheckBox::Perform(perform_code code, void* _data)
|
|||||||
status_t
|
status_t
|
||||||
BCheckBox::SetIcon(const BBitmap* icon, uint32 flags)
|
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 width = rect.right + rect.left;
|
||||||
float height = rect.bottom + rect.top;
|
float height = rect.bottom + rect.top;
|
||||||
|
|
||||||
const BBitmap* icon = IconBitmap(B_OFF_BITMAP);
|
const BBitmap* icon = IconBitmap(B_INACTIVE_ICON_BITMAP);
|
||||||
if (icon != NULL) {
|
if (icon != NULL) {
|
||||||
width += be_control_look->DefaultLabelSpacing()
|
width += be_control_look->DefaultLabelSpacing()
|
||||||
+ icon->Bounds().Width() + 1;
|
+ icon->Bounds().Width() + 1;
|
||||||
|
|||||||
@@ -89,9 +89,9 @@ public:
|
|||||||
|
|
||||||
bool SetBitmap(BBitmap* bitmap, uint32 which)
|
bool SetBitmap(BBitmap* bitmap, uint32 which)
|
||||||
{
|
{
|
||||||
IconList& list = (which & B_DISABLED_BITMAP) == 0
|
IconList& list = (which & B_DISABLED_ICON_BITMAP) == 0
|
||||||
? fEnabledBitmaps : fDisabledBitmaps;
|
? fEnabledBitmaps : fDisabledBitmaps;
|
||||||
which &= ~uint32(B_DISABLED_BITMAP);
|
which &= ~uint32(B_DISABLED_ICON_BITMAP);
|
||||||
|
|
||||||
int32 count = list.CountItems();
|
int32 count = list.CountItems();
|
||||||
if ((int32)which < count) {
|
if ((int32)which < count) {
|
||||||
@@ -109,9 +109,9 @@ public:
|
|||||||
|
|
||||||
BBitmap* Bitmap(uint32 which) const
|
BBitmap* Bitmap(uint32 which) const
|
||||||
{
|
{
|
||||||
const IconList& list = (which & B_DISABLED_BITMAP) == 0
|
const IconList& list = (which & B_DISABLED_ICON_BITMAP) == 0
|
||||||
? fEnabledBitmaps : fDisabledBitmaps;
|
? fEnabledBitmaps : fDisabledBitmaps;
|
||||||
return list.ItemAt(which & ~uint32(B_DISABLED_BITMAP));
|
return list.ItemAt(which & ~uint32(B_DISABLED_ICON_BITMAP));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeleteBitmaps()
|
void DeleteBitmaps()
|
||||||
@@ -651,16 +651,17 @@ BControl::SetIcon(const BBitmap* bitmap, uint32 flags)
|
|||||||
|
|
||||||
// trim the bitmap, if requested and the bitmap actually has alpha
|
// trim the bitmap, if requested and the bitmap actually has alpha
|
||||||
status_t error;
|
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) {
|
&& hasAlpha) {
|
||||||
if (bitmap->ColorSpace() == B_RGBA32) {
|
if (bitmap->ColorSpace() == B_RGBA32) {
|
||||||
error = _TrimBitmap(bitmap,
|
error = _TrimBitmap(bitmap,
|
||||||
(flags & B_TRIM_BITMAP_KEEP_ASPECT) != 0, trimmedBitmap);
|
(flags & B_TRIM_ICON_BITMAP_KEEP_ASPECT) != 0, trimmedBitmap);
|
||||||
} else {
|
} else {
|
||||||
BBitmap* rgb32Bitmap = _ConvertToRGB32(bitmap, true);
|
BBitmap* rgb32Bitmap = _ConvertToRGB32(bitmap, true);
|
||||||
if (rgb32Bitmap != NULL) {
|
if (rgb32Bitmap != NULL) {
|
||||||
error = _TrimBitmap(rgb32Bitmap,
|
error = _TrimBitmap(rgb32Bitmap,
|
||||||
(flags & B_TRIM_BITMAP_KEEP_ASPECT) != 0, trimmedBitmap);
|
(flags & B_TRIM_ICON_BITMAP_KEEP_ASPECT) != 0,
|
||||||
|
trimmedBitmap);
|
||||||
delete rgb32Bitmap;
|
delete rgb32Bitmap;
|
||||||
} else
|
} else
|
||||||
error = B_NO_MEMORY;
|
error = B_NO_MEMORY;
|
||||||
@@ -707,7 +708,7 @@ BControl::SetIconBitmap(const BBitmap* bitmap, uint32 which, uint32 flags)
|
|||||||
if (!bitmap->IsValid())
|
if (!bitmap->IsValid())
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
if ((flags & B_KEEP_BITMAP) != 0) {
|
if ((flags & B_KEEP_ICON_BITMAP) != 0) {
|
||||||
ourBitmap = const_cast<BBitmap*>(bitmap);
|
ourBitmap = const_cast<BBitmap*>(bitmap);
|
||||||
} else {
|
} else {
|
||||||
ourBitmap = _ConvertToRGB32(bitmap);
|
ourBitmap = _ConvertToRGB32(bitmap);
|
||||||
@@ -869,21 +870,23 @@ BControl::_MakeBitmaps(const BBitmap* bitmap, uint32 flags)
|
|||||||
ObjectDeleter<IconData> iconDataDeleter(iconData);
|
ObjectDeleter<IconData> iconDataDeleter(iconData);
|
||||||
|
|
||||||
color_space format = bitmap->ColorSpace();
|
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)
|
if (normalBitmap == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
BBitmap* disabledBitmap = NULL;
|
BBitmap* disabledBitmap = NULL;
|
||||||
if ((flags & B_CREATE_DISABLED_BITMAPS) != 0) {
|
if ((flags & B_CREATE_DISABLED_ICON_BITMAPS) != 0) {
|
||||||
disabledBitmap = iconData->CreateBitmap(b, format,
|
disabledBitmap = iconData->CreateBitmap(b, format,
|
||||||
B_OFF_BITMAP | B_DISABLED_BITMAP);
|
B_INACTIVE_ICON_BITMAP | B_DISABLED_ICON_BITMAP);
|
||||||
if (disabledBitmap == NULL)
|
if (disabledBitmap == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
BBitmap* clickedBitmap = NULL;
|
BBitmap* clickedBitmap = NULL;
|
||||||
if ((flags & (B_CREATE_ON_BITMAP | B_CREATE_PARTIALLY_ON_BITMAP)) != 0) {
|
if ((flags & (B_CREATE_ACTIVE_ICON_BITMAP
|
||||||
clickedBitmap = iconData->CreateBitmap(b, format, B_ON_BITMAP);
|
| B_CREATE_PARTIALLY_ACTIVE_ICON_BITMAP)) != 0) {
|
||||||
|
clickedBitmap = iconData->CreateBitmap(b, format, B_ACTIVE_ICON_BITMAP);
|
||||||
if (clickedBitmap == NULL)
|
if (clickedBitmap == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
}
|
}
|
||||||
@@ -891,7 +894,7 @@ BControl::_MakeBitmaps(const BBitmap* bitmap, uint32 flags)
|
|||||||
BBitmap* disabledClickedBitmap = NULL;
|
BBitmap* disabledClickedBitmap = NULL;
|
||||||
if (disabledBitmap != NULL && clickedBitmap != NULL) {
|
if (disabledBitmap != NULL && clickedBitmap != NULL) {
|
||||||
disabledClickedBitmap = iconData->CreateBitmap(b, format,
|
disabledClickedBitmap = iconData->CreateBitmap(b, format,
|
||||||
B_ON_BITMAP | B_DISABLED_BITMAP);
|
B_ACTIVE_ICON_BITMAP | B_DISABLED_ICON_BITMAP);
|
||||||
if (disabledClickedBitmap == NULL)
|
if (disabledClickedBitmap == NULL)
|
||||||
return B_NO_MEMORY;
|
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
|
// make the partially-on bitmaps a copy of the on bitmaps
|
||||||
if ((flags & B_CREATE_PARTIALLY_ON_BITMAP) != 0) {
|
if ((flags & B_CREATE_PARTIALLY_ACTIVE_ICON_BITMAP) != 0) {
|
||||||
if (iconData->CopyBitmap(clickedBitmap, B_PARTIALLY_ON_BITMAP) == NULL)
|
if (iconData->CopyBitmap(clickedBitmap,
|
||||||
|
B_PARTIALLY_ACTIVATE_ICON_BITMAP) == NULL) {
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
if ((flags & B_CREATE_DISABLED_BITMAPS) != 0) {
|
}
|
||||||
|
if ((flags & B_CREATE_DISABLED_ICON_BITMAPS) != 0) {
|
||||||
if (iconData->CopyBitmap(disabledClickedBitmap,
|
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;
|
return B_NO_MEMORY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user