HaikuDepot: Exract RatingView into its own source and header
This commit is contained in:
@@ -52,6 +52,7 @@ Application HaikuDepot :
|
|||||||
PackageListView.cpp
|
PackageListView.cpp
|
||||||
PackageManager.cpp
|
PackageManager.cpp
|
||||||
RatePackageWindow.cpp
|
RatePackageWindow.cpp
|
||||||
|
RatingView.cpp
|
||||||
support.cpp
|
support.cpp
|
||||||
UserLoginWindow.cpp
|
UserLoginWindow.cpp
|
||||||
WebAppInterface.cpp
|
WebAppInterface.cpp
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013, Stephan Aßmus <[email protected]>.
|
* Copyright 2013-214, Stephan Aßmus <[email protected]>.
|
||||||
* All rights reserved. Distributed under the terms of the MIT License.
|
* All rights reserved. Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -31,6 +31,7 @@
|
|||||||
#include "MarkupParser.h"
|
#include "MarkupParser.h"
|
||||||
#include "PackageActionHandler.h"
|
#include "PackageActionHandler.h"
|
||||||
#include "PackageManager.h"
|
#include "PackageManager.h"
|
||||||
|
#include "RatingView.h"
|
||||||
#include "TextDocumentView.h"
|
#include "TextDocumentView.h"
|
||||||
#include "TextView.h"
|
#include "TextView.h"
|
||||||
|
|
||||||
@@ -232,93 +233,6 @@ private:
|
|||||||
// #pragma mark - rating stats
|
// #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 {
|
class DiagramBarView : public BView {
|
||||||
public:
|
public:
|
||||||
DiagramBarView()
|
DiagramBarView()
|
||||||
@@ -436,7 +350,7 @@ class TransitReportingRatingView : public RatingView, public BInvoker {
|
|||||||
public:
|
public:
|
||||||
TransitReportingRatingView(BMessage* transitMessage)
|
TransitReportingRatingView(BMessage* transitMessage)
|
||||||
:
|
:
|
||||||
RatingView(),
|
RatingView("package rating view"),
|
||||||
fTransitMessage(transitMessage)
|
fTransitMessage(transitMessage)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -1024,7 +938,7 @@ public:
|
|||||||
fNameView->SetExplicitMaxSize(
|
fNameView->SetExplicitMaxSize(
|
||||||
BSize(nameFont.StringWidth("xxxxxxxxxxxxxxxxxxxxxx"), B_SIZE_UNSET));
|
BSize(nameFont.StringWidth("xxxxxxxxxxxxxxxxxxxxxx"), B_SIZE_UNSET));
|
||||||
|
|
||||||
fRatingView = new RatingView();
|
fRatingView = new RatingView("package rating view");
|
||||||
fRatingView->SetRating(rating.Rating());
|
fRatingView->SetRating(rating.Rating());
|
||||||
|
|
||||||
BString ratingLabel;
|
BString ratingLabel;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013, Stephan Aßmus <superstippi@gmx.de>.
|
* Copyright 2013-2014, Stephan Aßmus <superstippi@gmx.de>.
|
||||||
* All rights reserved. Distributed under the terms of the MIT License.
|
* All rights reserved. Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
#ifndef PACKAGE_INFO_VIEW_H
|
#ifndef PACKAGE_INFO_VIEW_H
|
||||||
|
|||||||
@@ -0,0 +1,108 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013-2014, Stephan Aßmus <superstippi@gmx.de>.
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013-2014, Stephan Aßmus <superstippi@gmx.de>.
|
||||||
|
* All rights reserved. Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
#ifndef RATING_VIEW_H
|
||||||
|
#define RATING_VIEW_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <View.h>
|
||||||
|
|
||||||
|
#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
|
||||||
Reference in New Issue
Block a user