1 /* 2 * Copyright 2007-2016 Haiku, Inc. 3 * Distributed under the terms of the MIT License. 4 * 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> 10 */ 11 12 13 #include "StripeView.h" 14 15 #include <LayoutUtils.h> 16 17 18 static const int kIconStripeWidth = 30; 19 20 21 BStripeView::BStripeView(BBitmap& icon) 22 : 23 BView("StripeView", B_WILL_DRAW), 24 fIcon(icon), 25 fIconSize(0.0), 26 fPreferredWidth(0.0), 27 fPreferredHeight(0.0) 28 { 29 SetViewUIColor(B_PANEL_BACKGROUND_COLOR); 30 31 if (fIcon.IsValid()) { 32 fIconSize = fIcon.Bounds().Width(); 33 // Use the same scaling as a BAlert 34 int32 scale = icon_layout_scale(); 35 fPreferredWidth = 18 * scale + fIcon.Bounds().Width(); 36 fPreferredHeight = 6 * scale + fIcon.Bounds().Height(); 37 } 38 } 39 40 41 void 42 BStripeView::Draw(BRect updateRect) 43 { 44 if (fIconSize == 0) 45 return; 46 47 SetHighColor(ViewColor()); 48 FillRect(updateRect); 49 50 BRect stripeRect = Bounds(); 51 int32 iconLayoutScale = icon_layout_scale(); 52 stripeRect.right = kIconStripeWidth * iconLayoutScale; 53 SetHighColor(tint_color(ViewColor(), B_DARKEN_1_TINT)); 54 FillRect(stripeRect); 55 56 SetDrawingMode(B_OP_ALPHA); 57 SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY); 58 DrawBitmapAsync(&fIcon, BPoint(18 * iconLayoutScale, 59 6 * iconLayoutScale)); 60 } 61 62 63 BSize 64 BStripeView::PreferredSize() 65 { 66 return BSize(fPreferredWidth, B_SIZE_UNSET); 67 } 68 69 70 void 71 BStripeView::GetPreferredSize(float* _width, float* _height) 72 { 73 if (_width != NULL) 74 *_width = fPreferredWidth; 75 76 if (_height != NULL) 77 *_height = fPreferredHeight; 78 } 79 80 81 BSize 82 BStripeView::MaxSize() 83 { 84 return BLayoutUtils::ComposeSize(ExplicitMaxSize(), 85 BSize(fPreferredWidth, B_SIZE_UNLIMITED)); 86 } 87