From 47102c074278637c3b33935b451d53f7ad176658 Mon Sep 17 00:00:00 2001 From: X512 Date: Tue, 25 Feb 2020 01:44:55 +0900 Subject: [PATCH] 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 --- headers/os/interface/View.h | 1 + src/apps/activitymonitor/ActivityView.cpp | 1 + src/apps/networkstatus/NetworkStatusView.cpp | 2 +- src/apps/powerstatus/PowerStatusView.cpp | 2 +- src/kits/interface/Dragger.cpp | 1 + src/kits/interface/View.cpp | 3 +- src/servers/app/View.cpp | 31 ++++++++------------ src/servers/app/View.h | 3 +- 8 files changed, 22 insertions(+), 22 deletions(-) diff --git a/headers/os/interface/View.h b/headers/os/interface/View.h index eb70e783d5..d4523e5bbe 100644 --- a/headers/os/interface/View.h +++ b/headers/os/interface/View.h @@ -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) diff --git a/src/apps/activitymonitor/ActivityView.cpp b/src/apps/activitymonitor/ActivityView.cpp index e0181f87d2..6417aeb358 100644 --- a/src/apps/activitymonitor/ActivityView.cpp +++ b/src/apps/activitymonitor/ActivityView.cpp @@ -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; diff --git a/src/apps/networkstatus/NetworkStatusView.cpp b/src/apps/networkstatus/NetworkStatusView.cpp index 633535b9d7..66f2a9fcc7 100644 --- a/src/apps/networkstatus/NetworkStatusView.cpp +++ b/src/apps/networkstatus/NetworkStatusView.cpp @@ -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(); diff --git a/src/apps/powerstatus/PowerStatusView.cpp b/src/apps/powerstatus/PowerStatusView.cpp index c3bc6d0c25..59622328a9 100644 --- a/src/apps/powerstatus/PowerStatusView.cpp +++ b/src/apps/powerstatus/PowerStatusView.cpp @@ -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) diff --git a/src/kits/interface/Dragger.cpp b/src/kits/interface/Dragger.cpp index c1b779bb38..8900a96810 100644 --- a/src/kits/interface/Dragger.cpp +++ b/src/kits/interface/Dragger.cpp @@ -227,6 +227,7 @@ BDragger::AttachedToWindow() SetLowColor(kZombieColor); SetViewColor(kZombieColor); } else { + SetFlags(Flags() | B_TRANSPARENT_BACKGROUND); SetLowColor(B_TRANSPARENT_COLOR); SetViewColor(B_TRANSPARENT_COLOR); } diff --git a/src/kits/interface/View.cpp b/src/kits/interface/View.cpp index a086b93624..7671604ac4 100644 --- a/src/kits/interface/View.cpp +++ b/src/kits/interface/View.cpp @@ -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); diff --git a/src/servers/app/View.cpp b/src/servers/app/View.cpp index 70ea9b0419..4a276c7e9f 100644 --- a/src/servers/app/View.cpp +++ b/src/servers/app/View.cpp @@ -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()); } } diff --git a/src/servers/app/View.h b/src/servers/app/View.h index 7c82cfee64..84e2b3cf16 100644 --- a/src/servers/app/View.h +++ b/src/servers/app/View.h @@ -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);