Interface Kit: introduce B_TRANSPARENT_BACKGROUND flag

BeOS didn't support transparent views. As documented in the Be Book,
SetViewColor(B_TRANSPARENT_COLOR) only effect is to not fill the
invalidated areas with the view color before calling Draw() (it avoids
flickering, especially when combined with B_FULL_UPDATE_ON_RESIZE).

A previous change made B_TRANSPARENT_COLOR actually make the view
transparent (that is, additionally to the above, the underlying view is
drawn before the transparent children), but it creates compatibility
issues.

In order to keep the API compatible with BeOS, the new behavior is now
enabled explicitly using the B_TRANSPARENT_VIEW flag. This also opens
for future developments like allowing a view color with an alpha
channel (not supported yet).

Adjust programs that require transparent views.

Fixes #15744, #15745.
Helps with #15645.

Change-Id: I529574ea23db0a23579521b263bc8d572775e35a
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2275
Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>
This commit is contained in:
X512 2020-02-25 01:44:55 +09:00 committed by waddlesplash
parent 23177782fd
commit 47102c0742
8 changed files with 22 additions and 22 deletions

View File

@ -80,6 +80,7 @@ const uint32 B_INPUT_METHOD_AWARE = 0x00400000UL; /* 23 */
const uint32 B_SCROLL_VIEW_AWARE = 0x00200000UL; /* 22 */
const uint32 B_SUPPORTS_LAYOUT = 0x00100000UL; /* 21 */
const uint32 B_INVALIDATE_AFTER_LAYOUT = 0x00080000UL; /* 20 */
const uint32 B_TRANSPARENT_BACKGROUND = 0x00040000UL; /* 19 */
#define _RESIZE_MASK_ (0xffff)

View File

@ -613,6 +613,7 @@ ActivityView::_Init(const BMessage* settings)
fLegendLayoutItem = NULL;
#endif
SetViewColor(B_TRANSPARENT_COLOR);
SetFlags(Flags() | B_TRANSPARENT_BACKGROUND);
fLastRefresh = 0;
fDrawResolution = 1;

View File

@ -94,7 +94,7 @@ signal_strength_compare(const wireless_network &a,
NetworkStatusView::NetworkStatusView(BRect frame, int32 resizingMode,
bool inDeskbar)
: BView(frame, kDeskbarItemName, resizingMode,
B_WILL_DRAW | B_FRAME_EVENTS),
B_WILL_DRAW | B_TRANSPARENT_BACKGROUND | B_FRAME_EVENTS),
fInDeskbar(inDeskbar)
{
_Init();

View File

@ -66,7 +66,7 @@ PowerStatusView::PowerStatusView(PowerStatusDriverInterface* interface,
BRect frame, int32 resizingMode, int batteryID, bool inDeskbar)
:
BView(frame, kDeskbarItemName, resizingMode,
B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE),
B_WILL_DRAW | B_TRANSPARENT_BACKGROUND | B_FULL_UPDATE_ON_RESIZE),
fDriverInterface(interface),
fBatteryID(batteryID),
fInDeskbar(inDeskbar)

View File

@ -227,6 +227,7 @@ BDragger::AttachedToWindow()
SetLowColor(kZombieColor);
SetViewColor(kZombieColor);
} else {
SetFlags(Flags() | B_TRANSPARENT_BACKGROUND);
SetLowColor(B_TRANSPARENT_COLOR);
SetViewColor(B_TRANSPARENT_COLOR);
}

View File

@ -1050,7 +1050,8 @@ BView::SetFlags(uint32 flags)
uint32 changesFlags = flags ^ fFlags;
if (changesFlags & (B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE
| B_FRAME_EVENTS | B_SUBPIXEL_PRECISE)) {
| B_FRAME_EVENTS | B_SUBPIXEL_PRECISE
| B_TRANSPARENT_BACKGROUND)) {
_CheckLockAndSwitchCurrent();
fOwner->fLink->StartMessage(AS_VIEW_SET_FLAGS);

View File

@ -486,7 +486,18 @@ View::SetName(const char* string)
void
View::SetFlags(uint32 flags)
{
uint32 oldFlags = fFlags;
fFlags = flags;
// Child view with B_TRANSPARENT_BACKGROUND flag change clipping of
// parent view.
if (fParent != NULL
&& IsVisible()
&& (((oldFlags & B_TRANSPARENT_BACKGROUND) != 0)
!= ((fFlags & B_TRANSPARENT_BACKGROUND) != 0))) {
fParent->RebuildClipping(false);
}
fDrawState->SetSubPixelPrecise(fFlags & B_SUBPIXEL_PRECISE);
}
@ -717,7 +728,7 @@ View::ResizeBy(int32 x, int32 y, BRegion* dirtyRegion)
for (View* child = FirstChild(); child;
child = child->NextSibling()) {
if (!child->IsVisible()
|| child->fViewColor == B_TRANSPARENT_COLOR) {
|| (child->fFlags & B_TRANSPARENT_BACKGROUND) != 0) {
continue;
}
IntRect previousChildVisible(
@ -923,22 +934,6 @@ View::CopyBits(IntRect src, IntRect dst, BRegion& windowContentClipping)
// #pragma mark -
void
View::SetViewColor(const rgb_color& color)
{
rgb_color oldColor = fViewColor;
fViewColor = color;
// Child view with B_TRANSPARENT_COLOR view color change clipping of
// parent view.
if (fParent != NULL
&& IsVisible()
&& ((oldColor == B_TRANSPARENT_COLOR)
!= (color == B_TRANSPARENT_COLOR))) {
fParent->RebuildClipping(false);
}
}
void
View::ColorUpdated(color_which which, rgb_color color)
{
@ -1419,7 +1414,7 @@ View::RebuildClipping(bool deep)
for (; child; child = child->NextSibling()) {
if (child->IsVisible()
&& child->fViewColor != B_TRANSPARENT_COLOR) {
&& (child->fFlags & B_TRANSPARENT_BACKGROUND) == 0) {
childrenRegion->Include((clipping_rect)child->Frame());
}
}

View File

@ -135,7 +135,8 @@ public:
const rgb_color& ViewColor() const
{ return fViewColor; }
void SetViewColor(const rgb_color& color);
void SetViewColor(const rgb_color& color)
{ fViewColor = color; }
void ColorUpdated(color_which which, rgb_color color);
void SetViewUIColor(color_which which, float tint);