⛏️ index : haiku.git

author John Scipione <jscipione@gmail.com> 2023-04-20 10:29:27.0 -04:00:00
committer waddlesplash <waddlesplash@gmail.com> 2023-05-11 15:48:24.0 +00:00:00
commit
83297df03ee0625e498a0174dfb0ea8bd424baf1 [patch]
tree
73a3ad742f31a6f88ead570a5d38d35f5512ea3e
parent
44cb8f360178c141dc780a2247f5ebe24e012ee8
download
83297df03ee0625e498a0174dfb0ea8bd424baf1.tar.gz

BeControlLook: fix clipping rect, part of #12890

Change-Id: Ib3c29dd1ffba1f0456a5043b62d943123335e966
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6366
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
(cherry picked from commit c7cd1bae689d6adaa0920661c501d10cd9b4f2e2)
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6341

Diff

 src/add-ons/control_look/BeControlLook/BeControlLook.cpp | 123 ++++++++++++++++++++++++++++++--------------------------------------------------
 1 file changed, 46 insertions(+), 77 deletions(-)

diff --git a/src/add-ons/control_look/BeControlLook/BeControlLook.cpp b/src/add-ons/control_look/BeControlLook/BeControlLook.cpp
index 7489dea..c7a9a76 100644
--- a/src/add-ons/control_look/BeControlLook/BeControlLook.cpp
+++ b/src/add-ons/control_look/BeControlLook/BeControlLook.cpp
@@ -1,5 +1,5 @@
/*
 * Copyright 2003-2020 Haiku, Inc. All rights reserved.
 * Copyright 2003-2023 Haiku, Inc. All rights reserved.
 * Distributed under the terms of the MIT License.
 *
 * Authors:
@@ -301,7 +301,7 @@
BeControlLook::DrawRadioButton(BView* view, BRect& rect,
	const BRect& updateRect, const rgb_color& base, uint32 flags)
{
	if (!rect.IsValid() || !rect.Intersects(updateRect))
	if (!ShouldDraw(view, rect, updateRect))
		return;

	bool isEnabled = (flags & B_DISABLED) == 0;
@@ -401,14 +401,12 @@
	const BRect& updateRect, const rgb_color& base, uint32 flags,
	orientation orientation)
{
	if (!rect.IsValid() || !rect.Intersects(updateRect))
	if (!ShouldDraw(view, rect, updateRect))
		return;

	view->PushState();

	// set clipping constraints to updateRect
	BRegion clipping(updateRect);
	view->ConstrainClippingRegion(&clipping);
	view->ClipToRect(rect);

	bool isEnabled = (flags & B_DISABLED) == 0;
	bool isFocused = (flags & B_FOCUSED) != 0;
@@ -575,14 +573,12 @@
	const BRect& updateRect, const rgb_color& base, uint32 flags,
	orientation orientation, uint32 knobStyle)
{
	if (!rect.IsValid() || !rect.Intersects(updateRect))
	if (!ShouldDraw(view, rect, updateRect))
		return;

	view->PushState();

	// set clipping constraints to updateRect
	BRegion clipping(updateRect);
	view->ConstrainClippingRegion(&clipping);
	view->ClipToRect(rect);

	bool isEnabled = (flags & B_DISABLED) == 0;

@@ -747,7 +743,7 @@
BeControlLook::DrawArrowShape(BView* view, BRect& rect, const BRect& updateRect,
	const rgb_color& base, uint32 direction, uint32 flags, float tint)
{
	if (!rect.IsValid() || !rect.Intersects(updateRect))
	if (!ShouldDraw(view, rect, updateRect))
		return;

	view->PushState();
@@ -811,7 +807,7 @@
	const BRect& updateRect, const rgb_color& base, uint32 flags,
	uint32 borders)
{
	if (!rect.IsValid() || !rect.Intersects(updateRect))
	if (!ShouldDraw(view, rect, updateRect))
		return;

	view->PushState();
@@ -863,7 +859,7 @@
	const BRect& updateRect, float, float, float, float, const rgb_color& base,
	const rgb_color& background, uint32 flags, uint32 borders)
{
	if (!rect.IsValid() || !rect.Intersects(updateRect))
	if (!ShouldDraw(view, rect, updateRect))
		return;

	bool isEnabled = (flags & B_DISABLED) == 0;
@@ -940,7 +936,7 @@
	const BRect& updateRect, const rgb_color& base, uint32 flags,
	uint32 borders)
{
	if (!rect.IsValid() || !rect.Intersects(updateRect))
	if (!ShouldDraw(view, rect, updateRect))
		return;

	view->PushState();
@@ -957,7 +953,7 @@
	const BRect& updateRect, const rgb_color& base, uint32 flags,
	uint32 borders)
{
	if (!rect.IsValid() || !rect.Intersects(updateRect))
	if (!ShouldDraw(view, rect, updateRect))
		return;

	view->PushState();
@@ -973,7 +969,7 @@
BeControlLook::DrawStatusBar(BView* view, BRect& rect, const BRect& updateRect,
	const rgb_color& base, const rgb_color& barColor, float progressPosition)
{
	if (!rect.IsValid() || !rect.Intersects(updateRect))
	if (!ShouldDraw(view, rect, updateRect))
		return;

	view->PushState();
@@ -997,11 +993,9 @@
	const rgb_color& base, rgb_color leftFillColor, rgb_color rightFillColor,
	float sliderScale, uint32 flags, orientation orientation)
{
	if (!rect.IsValid() || !rect.Intersects(updateRect))
	if (!ShouldDraw(view, rect, updateRect))
		return;

	view->PushState();

	// separate the bar in two sides
	float sliderPosition;
	BRect leftBarSide = rect;
@@ -1020,29 +1014,18 @@
		rightBarSide.bottom = sliderPosition - 1;
	}

	// fill the background for the corners, exclude the middle bar for now
	BRegion region(rect);
	region.Exclude(rightBarSide);
	view->ConstrainClippingRegion(&region);

	view->PushState();
	view->ClipToRect(leftBarSide);

	DrawSliderBar(view, rect, updateRect, base, leftFillColor, flags,
		orientation);

	view->PopState();

	region.Set(rect);
	region.Exclude(leftBarSide);
	view->ConstrainClippingRegion(&region);

	view->PushState();
	view->ClipToRect(rightBarSide);

	DrawSliderBar(view, rect, updateRect, base, rightFillColor, flags,
		orientation);

	view->PopState();

	view->PopState();
}

@@ -1052,7 +1035,7 @@
	const rgb_color& base, rgb_color fillColor, uint32 flags,
	orientation orientation)
{
	if (!rect.IsValid() || !rect.Intersects(updateRect))
	if (!ShouldDraw(view, rect, updateRect))
		return;

	view->SetHighColor(fillColor);
@@ -1097,7 +1080,7 @@
BeControlLook::DrawSliderThumb(BView* view, BRect& rect, const BRect& updateRect,
	const rgb_color& base, uint32 flags, orientation orientation)
{
	if (!rect.IsValid() || !rect.Intersects(updateRect))
	if (!ShouldDraw(view, rect, updateRect))
		return;

	rgb_color lighten2 = tint_color(base, B_LIGHTEN_2_TINT);
@@ -1185,7 +1168,7 @@
	const BRect& updateRect, const rgb_color& base, const rgb_color& fill,
	uint32 flags, orientation orientation)
{
	if (!rect.IsValid() || !rect.Intersects(updateRect))
	if (!ShouldDraw(view, rect, updateRect))
		return;

	rgb_color lighten1 = tint_color(base, B_LIGHTEN_1_TINT);
@@ -1247,7 +1230,7 @@
	const BRect& updateRect, const rgb_color& base, int32 count,
	hash_mark_location location, uint32 flags, orientation orientation)
{
	if (!rect.IsValid() || !rect.Intersects(updateRect))
	if (!ShouldDraw(view, rect, updateRect))
		return;

	rgb_color lightColor;
@@ -1376,14 +1359,13 @@
	const BRect& updateRect, const rgb_color& base, uint32 flags,
	uint32 borders, uint32 side, int32, int32, int32, int32)
{
	if (!rect.IsValid() || !rect.Intersects(updateRect))
	if (!ShouldDraw(view, rect, updateRect))
		return;

	view->PushState();

	// set clipping constraints to updateRect plus 2px extra
	BRegion clipping(updateRect.InsetByCopy(-2, -2));
	view->ConstrainClippingRegion(&clipping);
	// clip draw rect to rect plus 2px
	view->ClipToRect(rect.InsetByCopy(-2, -2));

	// set colors and draw

@@ -1599,7 +1581,7 @@
	uint32 borders, uint32 side, int32 index, int32 selected,
	int32 first, int32 last)
{
	if (!rect.IsValid() || !rect.Intersects(updateRect))
	if (!ShouldDraw(view, rect, updateRect))
		return;

	bool isFirst = index == first;
@@ -1607,9 +1589,8 @@

	view->PushState();

	// set clipping constraints to updateRect plus 2px extra
	BRegion clipping(updateRect.InsetByCopy(-2, -2));
	view->ConstrainClippingRegion(&clipping);
	// clip draw rect to rect plus 2px
	view->ClipToRect(rect.InsetByCopy(-2, -2));

	// set colors and draw

@@ -1815,7 +1796,7 @@
	const rgb_color& base, orientation orientation, uint32 flags,
	uint32 borders)
{
	if (!rect.IsValid() || !rect.Intersects(updateRect))
	if (!ShouldDraw(view, rect, updateRect))
		return;

	rgb_color background;
@@ -1933,13 +1914,12 @@
	if (borderStyle == B_NO_BORDER)
		return;

	if (!rect.IsValid() || !rect.Intersects(updateRect))
	if (!ShouldDraw(view, rect, updateRect))
		return;

	view->PushState();

	BRegion clipping(updateRect);
	view->ConstrainClippingRegion(&clipping);
	view->ClipToRect(rect);

	rgb_color lightColor;
	rgb_color shadowColor;
@@ -2034,13 +2014,12 @@
	const BRect& updateRect, const rgb_color& base, uint32 flags,
	uint32 borders)
{
	if (!rect.IsValid() || !rect.Intersects(updateRect))
	if (!ShouldDraw(view, rect, updateRect))
		return;

	view->PushState();

	BRegion clipping(updateRect);
	view->ConstrainClippingRegion(&clipping);
	view->ClipToRect(rect);

	rgb_color lightColor;
	rgb_color shadowColor;
@@ -2100,13 +2079,12 @@
	const BRect& updateRect, const rgb_color& base, uint32 flags,
	uint32 borders)
{
	if (!rect.IsValid() || !rect.Intersects(updateRect))
	if (!ShouldDraw(view, rect, updateRect))
		return;

	view->PushState();

	BRegion clipping(updateRect);
	view->ConstrainClippingRegion(&clipping);
	view->ClipToRect(rect);

	rgb_color lighten1 = tint_color(base, B_LIGHTEN_1_TINT);
	rgb_color lightenmax = tint_color(base, B_LIGHTEN_MAX_TINT);
@@ -2354,7 +2332,7 @@
	BRect rect, const BRect& updateRect, const rgb_color& base, uint32 flags,
	const BAlignment& alignment, const rgb_color* textColor)
{
	if (!rect.IsValid() || !rect.Intersects(updateRect))
	if (!ShouldDraw(view, rect, updateRect))
		return;

	if (label == NULL && icon == NULL)
@@ -2548,14 +2526,12 @@
	const rgb_color& background, float contrast, float brightness,
	uint32 flags, uint32 borders)
{
	if (!rect.IsValid() || !rect.Intersects(updateRect))
	if (!ShouldDraw(view, rect, updateRect))
		return;

	view->PushState();

	// set clipping constraints to updateRect
	BRegion clipping(updateRect);
	view->ConstrainClippingRegion(&clipping);
	view->ClipToRect(rect);

	// flags
	bool isEnabled = (flags & B_DISABLED) == 0;
@@ -2770,7 +2746,7 @@
	const BRect& updateRect, float, float, float, float, const rgb_color& base,
	bool popupIndicator, uint32 flags, uint32 borders, orientation orientation)
{
	if (!rect.IsValid() || !rect.Intersects(updateRect))
	if (!ShouldDraw(view, rect, updateRect))
		return;

	// fill the button area
@@ -2782,12 +2758,9 @@

	if (isEnabled && isActivated) {
		// invert if clicked without altering rect
		BRect invertRect(rect);
		invertRect.left -= 3;
		invertRect.top -= 3;
		invertRect.right += 3;
		invertRect.bottom += 3;
		view->InvertRect(invertRect);
		BRect invertRect(rect.InsetByCopy(-3, -3));
		view->SetDrawingMode(B_OP_INVERT);
		view->FillRect(invertRect);
	}
}

@@ -2823,7 +2796,7 @@
	const BRect& updateRect, float, float, float, float, const rgb_color& base,
	bool popupIndicator, uint32 flags)
{
	if (!rect.IsValid() || !rect.Intersects(updateRect))
	if (!ShouldDraw(view, rect, updateRect))
		return;

	// BeControlLook does not support rounded corners and it never will
@@ -2846,14 +2819,12 @@
	const BRect& updateRect, float, float, float, float, const rgb_color& base,
	uint32 flags, uint32 borders)
{
	if (!rect.IsValid() || !rect.Intersects(updateRect))
	if (!ShouldDraw(view, rect, updateRect))
		return;

	view->PushState();

	// set clipping constraints to updateRect
	BRegion clipping(updateRect);
	view->ConstrainClippingRegion(&clipping);
	view->ClipToRect(rect);

	// flags
	bool isEnabled = (flags & B_DISABLED) == 0;
@@ -2925,13 +2896,12 @@
	const BRect& updateRect, const rgb_color& base, uint32 flags,
	orientation orientation)
{
	if (!rect.IsValid() || !rect.Intersects(updateRect))
	if (!ShouldDraw(view, rect, updateRect))
		return;

	view->PushState();

	BRegion clipping(updateRect);
	view->ConstrainClippingRegion(&clipping);
	view->ClipToRect(rect);

	bool isEnabled = (flags & B_DISABLED) == 0;
	BRect orig(rect);
@@ -3020,13 +2990,12 @@
	const BRect& updateRect, const rgb_color& base, uint32 flags,
	orientation orientation)
{
	if (!rect.IsValid() || !rect.Intersects(updateRect))
	if (!ShouldDraw(view, rect, updateRect))
		return;

	view->PushState();

	BRegion clipping(updateRect);
	view->ConstrainClippingRegion(&clipping);
	view->ClipToRect(rect);

	bool isEnabled = (flags & B_DISABLED) == 0;