1/* 2 * Copyright 2013-2014, Stephan A��mus <superstippi@gmx.de>. 3 * Copyright 2018-2020, Andrew Lindesay <apl@lindesay.co.nz>. 4 * All rights reserved. Distributed under the terms of the MIT License. 5 */ 6 7 8#include "RatingView.h" 9 10#include <stdio.h> 11 12#include <LayoutUtils.h> 13 14#include "HaikuDepotConstants.h" 15#include "RatingUtils.h" 16 17 18RatingView::RatingView(const char* name) 19 : 20 BView(name, B_WILL_DRAW), 21 fStarBlueBitmap(new SharedBitmap(RSRC_STAR_BLUE)), 22 fStarGrayBitmap(new SharedBitmap(RSRC_STAR_GREY)), 23 fRating(RATING_MISSING) 24{ 25 SetViewUIColor(B_PANEL_BACKGROUND_COLOR); 26 SetLowUIColor(ViewUIColor()); 27} 28 29 30RatingView::~RatingView() 31{ 32} 33 34 35void 36RatingView::AttachedToWindow() 37{ 38 AdoptParentColors(); 39} 40 41/*! This method will return a star image that can be used repeatedly in the 42 user interface in order to signify the rating given by a user. It could 43 be grey if no rating is assigned. 44*/ 45 46const BBitmap* 47RatingView::StarBitmap() 48{ 49 if (fRating < RATING_MIN) 50 return fStarGrayBitmap->Bitmap(BITMAP_SIZE_16); 51 return fStarBlueBitmap->Bitmap(BITMAP_SIZE_16); 52} 53 54 55void 56RatingView::Draw(BRect updateRect) 57{ 58 RatingUtils::Draw(this, BPoint(0, 0), fRating, StarBitmap()); 59} 60 61 62BSize 63RatingView::MinSize() 64{ 65 BSize size(16 * 5 + 2 * 4, 16 + 2); 66 return BLayoutUtils::ComposeSize(ExplicitMinSize(), size); 67} 68 69 70BSize 71RatingView::PreferredSize() 72{ 73 return BLayoutUtils::ComposeSize(ExplicitPreferredSize(), MinSize()); 74} 75 76 77BSize 78RatingView::MaxSize() 79{ 80 return BLayoutUtils::ComposeSize(ExplicitMaxSize(), MinSize()); 81} 82 83 84void 85RatingView::SetRating(float rating) 86{ 87 fRating = rating; 88 Invalidate(); 89} 90 91 92float 93RatingView::Rating() const 94{ 95 return fRating; 96} 97 98