vfs: check userland buffers before reading them.
[haiku.git] / src / apps / softwareupdater / StripeView.cpp
blob6256e669d53d901d3137a594d395f95665100b3e
1 /*
2 * Copyright 2007-2016 Haiku, Inc.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Ryan Leavengood <leavengood@gmail.com>
7 * John Scipione <jscipione@gmail.com>
8 * Joseph Groover <looncraz@looncraz.net>
9 * Brian Hill <supernova@tycho.email>
13 #include "StripeView.h"
15 #include <LayoutUtils.h>
18 static const float kTopOffset = 10.0f;
19 static const int kIconStripeWidth = 30;
22 StripeView::StripeView(BBitmap& icon)
24 BView("StripeView", B_WILL_DRAW),
25 fIcon(icon),
26 fIconSize(0.0),
27 fPreferredWidth(0.0),
28 fPreferredHeight(0.0)
30 SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
32 if (fIcon.IsValid()) {
33 fIconSize = fIcon.Bounds().Width();
34 // Use the same scaling as a BAlert
35 int32 scale = icon_layout_scale();
36 fPreferredWidth = 18 * scale + fIcon.Bounds().Width();
37 fPreferredHeight = 6 * scale + fIcon.Bounds().Height();
42 void
43 StripeView::Draw(BRect updateRect)
45 if (fIconSize == 0)
46 return;
48 SetHighColor(ViewColor());
49 FillRect(updateRect);
51 BRect stripeRect = Bounds();
52 int32 iconLayoutScale = icon_layout_scale();
53 stripeRect.right = kIconStripeWidth * iconLayoutScale;
54 SetHighColor(tint_color(ViewColor(), B_DARKEN_1_TINT));
55 FillRect(stripeRect);
57 SetDrawingMode(B_OP_ALPHA);
58 SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY);
59 DrawBitmapAsync(&fIcon, BPoint(stripeRect.right - (fIconSize / 2.0),
60 6 * iconLayoutScale));
64 BSize
65 StripeView::PreferredSize()
67 return BSize(fPreferredWidth, B_SIZE_UNSET);
71 void
72 StripeView::GetPreferredSize(float* _width, float* _height)
74 if (_width != NULL)
75 *_width = fPreferredWidth;
77 if (_height != NULL)
78 *_height = fPreferredHeight;
82 BSize
83 StripeView::MaxSize()
85 return BLayoutUtils::ComposeSize(ExplicitMaxSize(),
86 BSize(fPreferredWidth, B_SIZE_UNLIMITED));