diff --git a/src/apps/haikudepot/Jamfile b/src/apps/haikudepot/Jamfile index eeac625f42..03e5ff3638 100644 --- a/src/apps/haikudepot/Jamfile +++ b/src/apps/haikudepot/Jamfile @@ -52,6 +52,7 @@ Application HaikuDepot : PackageListView.cpp PackageManager.cpp RatePackageWindow.cpp + RatingView.cpp support.cpp UserLoginWindow.cpp WebAppInterface.cpp diff --git a/src/apps/haikudepot/PackageInfoView.cpp b/src/apps/haikudepot/PackageInfoView.cpp index 1eb0520ceb..1dd7b9c3d8 100644 --- a/src/apps/haikudepot/PackageInfoView.cpp +++ b/src/apps/haikudepot/PackageInfoView.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2013, Stephan Aßmus . + * Copyright 2013-214, Stephan Aßmus . * All rights reserved. Distributed under the terms of the MIT License. */ @@ -31,6 +31,7 @@ #include "MarkupParser.h" #include "PackageActionHandler.h" #include "PackageManager.h" +#include "RatingView.h" #include "TextDocumentView.h" #include "TextView.h" @@ -232,93 +233,6 @@ private: // #pragma mark - rating stats -class RatingView : public BView { -public: - RatingView() - : - BView("package rating view", B_WILL_DRAW), - fStarBitmap(501), - fRating(-1.0f) - { - SetViewColor(B_TRANSPARENT_COLOR); - SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - } - - virtual ~RatingView() - { - } - - virtual void AttachedToWindow() - { - BView* parent = Parent(); - if (parent != NULL) - SetLowColor(parent->ViewColor()); - } - - virtual void Draw(BRect updateRect) - { - FillRect(updateRect, B_SOLID_LOW); - - if (fRating < 0.0f) - return; - - const BBitmap* star = fStarBitmap.Bitmap(SharedBitmap::SIZE_16); - if (star == NULL) { - fprintf(stderr, "No star icon found in application resources.\n"); - return; - } - - SetDrawingMode(B_OP_OVER); - - float x = 0; - for (int i = 0; i < 5; i++) { - DrawBitmap(star, BPoint(x, 0)); - x += 16 + 2; - } - - if (fRating >= 5.0f) - return; - - SetDrawingMode(B_OP_OVER); - - BRect rect(Bounds()); - rect.left = ceilf(rect.left + (fRating / 5.0f) * rect.Width()); - - rgb_color color = LowColor(); - color.alpha = 190; - SetHighColor(color); - - SetDrawingMode(B_OP_ALPHA); - FillRect(rect, B_SOLID_HIGH); - } - - virtual BSize MinSize() - { - return BSize(16 * 5 + 2 * 4, 16 + 2); - } - - virtual BSize PreferredSize() - { - return MinSize(); - } - - virtual BSize MaxSize() - { - return MinSize(); - } - - void SetRating(float rating) - { - fRating = rating; - Invalidate(); - } - -private: - SharedBitmap fStarBitmap; - float fRating; -}; - - class DiagramBarView : public BView { public: DiagramBarView() @@ -436,7 +350,7 @@ class TransitReportingRatingView : public RatingView, public BInvoker { public: TransitReportingRatingView(BMessage* transitMessage) : - RatingView(), + RatingView("package rating view"), fTransitMessage(transitMessage) { } @@ -1024,7 +938,7 @@ public: fNameView->SetExplicitMaxSize( BSize(nameFont.StringWidth("xxxxxxxxxxxxxxxxxxxxxx"), B_SIZE_UNSET)); - fRatingView = new RatingView(); + fRatingView = new RatingView("package rating view"); fRatingView->SetRating(rating.Rating()); BString ratingLabel; diff --git a/src/apps/haikudepot/PackageInfoView.h b/src/apps/haikudepot/PackageInfoView.h index de03f5eed7..64b261892c 100644 --- a/src/apps/haikudepot/PackageInfoView.h +++ b/src/apps/haikudepot/PackageInfoView.h @@ -1,5 +1,5 @@ /* - * Copyright 2013, Stephan Aßmus . + * Copyright 2013-2014, Stephan Aßmus . * All rights reserved. Distributed under the terms of the MIT License. */ #ifndef PACKAGE_INFO_VIEW_H diff --git a/src/apps/haikudepot/RatingView.cpp b/src/apps/haikudepot/RatingView.cpp new file mode 100644 index 0000000000..af62126c6e --- /dev/null +++ b/src/apps/haikudepot/RatingView.cpp @@ -0,0 +1,108 @@ +/* + * Copyright 2013-2014, Stephan Aßmus . + * All rights reserved. Distributed under the terms of the MIT License. + */ + + +#include "RatingView.h" + + +RatingView::RatingView(const char* name) + : + BView(name, B_WILL_DRAW), + fStarBitmap(501), + fRating(-1.0f) +{ + SetViewColor(B_TRANSPARENT_COLOR); + SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR)); +} + + +RatingView::~RatingView() +{ +} + + +void +RatingView::AttachedToWindow() +{ + BView* parent = Parent(); + if (parent != NULL) + SetLowColor(parent->ViewColor()); +} + + +void +RatingView::Draw(BRect updateRect) +{ + FillRect(updateRect, B_SOLID_LOW); + + if (fRating < 0.0f) + return; + + const BBitmap* star = fStarBitmap.Bitmap(SharedBitmap::SIZE_16); + if (star == NULL) { + fprintf(stderr, "No star icon found in application resources.\n"); + return; + } + + SetDrawingMode(B_OP_OVER); + + float x = 0; + for (int i = 0; i < 5; i++) { + DrawBitmap(star, BPoint(x, 0)); + x += 16 + 2; + } + + if (fRating >= 5.0f) + return; + + SetDrawingMode(B_OP_OVER); + + BRect rect(Bounds()); + rect.left = ceilf(rect.left + (fRating / 5.0f) * rect.Width()); + + rgb_color color = LowColor(); + color.alpha = 190; + SetHighColor(color); + + SetDrawingMode(B_OP_ALPHA); + FillRect(rect, B_SOLID_HIGH); +} + + +BSize +RatingView::MinSize() +{ + return BSize(16 * 5 + 2 * 4, 16 + 2); +} + + +BSize +RatingView::PreferredSize() +{ + return MinSize(); +} + + +BSize +RatingView::MaxSize() +{ + return MinSize(); +} + + +void +RatingView::SetRating(float rating) +{ + fRating = rating; + Invalidate(); +} + + +float +RatingView::Rating() const +{ + return fRating; +} + diff --git a/src/apps/haikudepot/RatingView.h b/src/apps/haikudepot/RatingView.h new file mode 100644 index 0000000000..73eb0137ad --- /dev/null +++ b/src/apps/haikudepot/RatingView.h @@ -0,0 +1,35 @@ +/* + * Copyright 2013-2014, Stephan Aßmus . + * All rights reserved. Distributed under the terms of the MIT License. + */ +#ifndef RATING_VIEW_H +#define RATING_VIEW_H + + +#include + +#include "PackageInfo.h" + + +class RatingView : public BView { +public: + RatingView(const char* name); + virtual ~RatingView(); + + virtual void AttachedToWindow(); + virtual void Draw(BRect updateRect); + + virtual BSize MinSize(); + virtual BSize PreferredSize(); + virtual BSize MaxSize(); + + void SetRating(float rating); + float Rating() const; + +private: + SharedBitmap fStarBitmap; + float fRating; +}; + + +#endif // RATING_VIEW_H