HaikuDepot: Display the first screenhot in the package contents area.

* Disabled BitmapView::GetHeightForWidth() to keep aspect, it seems
   broken in the layout system, the view gets layouted completely
   elsewhere. Mabye due to the layout hierarchy being optimized?
 * Instead layout the bitmap with correct aspect in the given space,
   honor LayoutAlignment() for this.
This commit is contained in:
Stephan Aßmus
2013-08-04 22:08:36 +02:00
parent 9481e817b4
commit 0046c36dfc
2 changed files with 94 additions and 31 deletions
+1
View File
@@ -18,6 +18,7 @@ class BBitmap;
class SharedBitmap : public BReferenceable { class SharedBitmap : public BReferenceable {
public: public:
enum Size { enum Size {
SIZE_ANY = -1,
SIZE_16 = 0, SIZE_16 = 0,
SIZE_32 = 1, SIZE_32 = 1,
SIZE_64 = 2 SIZE_64 = 2
+93 -31
View File
@@ -36,7 +36,7 @@ class BitmapView : public BView {
public: public:
BitmapView(const char* name) BitmapView(const char* name)
: :
BView(name, B_WILL_DRAW), BView(name, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE),
fBitmap(NULL) fBitmap(NULL)
{ {
SetViewColor(B_TRANSPARENT_COLOR); SetViewColor(B_TRANSPARENT_COLOR);
@@ -63,7 +63,47 @@ public:
if (fBitmap == NULL) if (fBitmap == NULL)
return; return;
DrawBitmap(fBitmap, fBitmap->Bounds(), bounds); BRect bitmapBounds = fBitmap->Bounds();
if (bitmapBounds.Width() <= 0.0f || bitmapBounds.Height() <= 0.0f)
return;
float hScale = bounds.Width() / bitmapBounds.Width();
float vScale = bounds.Height() / bitmapBounds.Height();
float scale = std::min(hScale, vScale);
float width = bitmapBounds.Width() * scale;
float height = bitmapBounds.Height() * scale;
switch (LayoutAlignment().horizontal) {
case B_ALIGN_LEFT:
break;
case B_ALIGN_RIGHT:
bounds.left = floorf(bounds.right - width);
break;
default:
case B_ALIGN_HORIZONTAL_CENTER:
bounds.left = floorf(bounds.left
+ (bounds.Width() - width) / 2.0f);
break;
}
switch (LayoutAlignment().vertical) {
case B_ALIGN_TOP:
break;
case B_ALIGN_BOTTOM:
bounds.top = floorf(bounds.bottom - height);
break;
default:
case B_ALIGN_VERTICAL_CENTER:
bounds.top = floorf(bounds.top
+ (bounds.Height() - height) / 2.0f);
break;
}
bounds.right = ceilf(bounds.left + width);
bounds.bottom = ceilf(bounds.top + height);
DrawBitmap(fBitmap, bitmapBounds, bounds, B_FILTER_BITMAP_BILINEAR);
} }
virtual BSize MinSize() virtual BSize MinSize()
@@ -91,29 +131,29 @@ public:
return BLayoutUtils::ComposeSize(ExplicitMaxSize(), size); return BLayoutUtils::ComposeSize(ExplicitMaxSize(), size);
} }
virtual bool HasHeightForWidth() // virtual bool HasHeightForWidth()
{ // {
return fBitmap != NULL; // return true;
} // }
//
virtual void GetHeightForWidth(float width, float* min, float* max, // virtual void GetHeightForWidth(float width, float* min, float* max,
float* preferred) // float* preferred)
{ // {
float height = width; // float height = width;
//
if (fBitmap != NULL) { // if (fBitmap != NULL) {
BRect bounds = fBitmap->Bounds(); // BRect bounds = fBitmap->Bounds();
if (bounds.Width() > 0.0f && bounds.Height() > 0.0f) // if (bounds.Width() > 0.0f && bounds.Height() > 0.0f)
height = (width / bounds.Width()) * bounds.Height(); // height = (width / bounds.Width()) * bounds.Height();
} // }
//
if (min != NULL) // if (min != NULL)
*min = height; // *min = height;
if (max != NULL) // if (max != NULL)
*max = height; // *max = height;
if (preferred != NULL) // if (preferred != NULL)
*preferred = height; // *preferred = height;
} // }
void SetBitmap(const BBitmap* bitmap) void SetBitmap(const BBitmap* bitmap)
{ {
@@ -500,6 +540,13 @@ public:
GetFont(&smallFont); GetFont(&smallFont);
smallFont.SetSize(std::max(9.0f, ceilf(smallFont.Size() * 0.85f))); smallFont.SetSize(std::max(9.0f, ceilf(smallFont.Size() * 0.85f)));
fScreenshotView = new BitmapView("screenshot view");
fScreenshotView->SetExplicitMinSize(BSize(64.0f, 64.0f));
fScreenshotView->SetExplicitMaxSize(
BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED));
fScreenshotView->SetExplicitAlignment(
BAlignment(B_ALIGN_CENTER, B_ALIGN_TOP));
fEmailIconView = new BitmapView("email icon view"); fEmailIconView = new BitmapView("email icon view");
fEmailLinkView = new BStringView("email link view", ""); fEmailLinkView = new BStringView("email link view", "");
fEmailLinkView->SetFont(&smallFont); fEmailLinkView->SetFont(&smallFont);
@@ -510,10 +557,14 @@ public:
fWebsiteLinkView->SetFont(&smallFont); fWebsiteLinkView->SetFont(&smallFont);
fWebsiteLinkView->SetHighColor(kLightBlack); fWebsiteLinkView->SetHighColor(kLightBlack);
BGroupView* leftGroup = new BGroupView(B_VERTICAL,
B_USE_DEFAULT_SPACING);
leftGroup->SetViewColor(ViewColor());
BLayoutBuilder::Group<>(this, B_HORIZONTAL, 0.0f) BLayoutBuilder::Group<>(this, B_HORIZONTAL, 0.0f)
// .Add(BSpaceLayoutItem::CreateHorizontalStrut(32.0f)) // .Add(BSpaceLayoutItem::CreateHorizontalStrut(32.0f))
.AddGroup(B_VERTICAL, 0.0f) .AddGroup(leftGroup)
.AddGlue() .Add(fScreenshotView)
.AddGroup(B_HORIZONTAL) .AddGroup(B_HORIZONTAL)
// .AddGlue() // .AddGlue()
.AddGrid(B_USE_HALF_ITEM_SPACING, B_USE_HALF_ITEM_SPACING) .AddGrid(B_USE_HALF_ITEM_SPACING, B_USE_HALF_ITEM_SPACING)
@@ -521,17 +572,15 @@ public:
.Add(fEmailLinkView, 1, 0) .Add(fEmailLinkView, 1, 0)
.Add(fWebsiteIconView, 0, 1) .Add(fWebsiteIconView, 0, 1)
.Add(fWebsiteLinkView, 1, 1) .Add(fWebsiteLinkView, 1, 1)
.SetInsets(B_USE_DEFAULT_SPACING)
.End() .End()
.End() .End()
.SetInsets(B_USE_DEFAULT_SPACING)
.End() .End()
.Add(scrollView, 1.0f) .Add(scrollView, 1.0f)
.SetExplicitMaxSize(BSize(B_SIZE_UNSET, B_SIZE_UNLIMITED)) .SetExplicitMaxSize(BSize(B_SIZE_UNSET, B_SIZE_UNLIMITED))
.SetInsets(B_USE_DEFAULT_SPACING, -1.0f, -1.0f, -1.0f) .SetInsets(0.0f, -1.0f, -1.0f, -1.0f)
; ;
scrollView->ScrollBar(B_VERTICAL)->ResizeBy(0, -B_H_SCROLL_BAR_HEIGHT);
} }
virtual ~AboutView() virtual ~AboutView()
@@ -546,6 +595,15 @@ public:
fEmailLinkView->SetText(package.Publisher().Email()); fEmailLinkView->SetText(package.Publisher().Email());
fWebsiteIconView->SetBitmap(fWebsiteIcon.Bitmap(SharedBitmap::SIZE_16)); fWebsiteIconView->SetBitmap(fWebsiteIcon.Bitmap(SharedBitmap::SIZE_16));
fWebsiteLinkView->SetText(package.Publisher().Website()); fWebsiteLinkView->SetText(package.Publisher().Website());
const BBitmap* screenshot = NULL;
const BitmapList& screenShots = package.Screenshots();
if (screenShots.CountItems() > 0) {
const BitmapRef& bitmapRef = screenShots.ItemAtFast(0);
if (bitmapRef.Get() != NULL)
screenshot = bitmapRef->Bitmap(SharedBitmap::SIZE_ANY);
}
fScreenshotView->SetBitmap(screenshot);
} }
void Clear() void Clear()
@@ -555,11 +613,15 @@ public:
fEmailLinkView->SetText(""); fEmailLinkView->SetText("");
fWebsiteIconView->SetBitmap(NULL); fWebsiteIconView->SetBitmap(NULL);
fWebsiteLinkView->SetText(""); fWebsiteLinkView->SetText("");
fScreenshotView->SetBitmap(NULL);
} }
private: private:
BTextView* fDescriptionView; BTextView* fDescriptionView;
BitmapView* fScreenshotView;
SharedBitmap fEmailIcon; SharedBitmap fEmailIcon;
BitmapView* fEmailIconView; BitmapView* fEmailIconView;
BStringView* fEmailLinkView; BStringView* fEmailLinkView;