2 * Copyright 2013-2014, Stephan Aßmus <superstippi@gmx.de>.
3 * All rights reserved. Distributed under the terms of the MIT License.
7 #include "RatingView.h"
11 #include <LayoutUtils.h>
14 RatingView::RatingView(const char* name
)
16 BView(name
, B_WILL_DRAW
),
20 SetViewUIColor(B_PANEL_BACKGROUND_COLOR
);
21 SetLowUIColor(ViewUIColor());
25 RatingView::~RatingView()
31 RatingView::AttachedToWindow()
38 RatingView::Draw(BRect updateRect
)
40 FillRect(updateRect
, B_SOLID_LOW
);
45 const BBitmap
* star
= fStarBitmap
.Bitmap(SharedBitmap::SIZE_16
);
47 fprintf(stderr
, "No star icon found in application resources.\n");
51 SetDrawingMode(B_OP_OVER
);
54 for (int i
= 0; i
< 5; i
++) {
55 DrawBitmap(star
, BPoint(x
, 0));
62 SetDrawingMode(B_OP_OVER
);
66 rect
.left
= ceilf(rect
.left
+ (fRating
/ 5.0f
) * rect
.Width());
68 rgb_color color
= LowColor();
72 SetDrawingMode(B_OP_ALPHA
);
73 FillRect(rect
, B_SOLID_HIGH
);
80 BSize
size(16 * 5 + 2 * 4, 16 + 2);
81 return BLayoutUtils::ComposeSize(ExplicitMinSize(), size
);
86 RatingView::PreferredSize()
88 return BLayoutUtils::ComposeSize(ExplicitPreferredSize(), MinSize());
95 return BLayoutUtils::ComposeSize(ExplicitMaxSize(), MinSize());
100 RatingView::SetRating(float rating
)
108 RatingView::Rating() const