From b314c7abd8c3361cdb16d748d783d2f4ae326b44 Mon Sep 17 00:00:00 2001 From: plfiorini Date: Thu, 20 May 2010 18:11:32 +0000 Subject: [PATCH] * Rewrote BitmapView's MinSize(), MaxSize() and PreferredSize() methods. * Added BitmapView::Bitmap() method. * BitmapView::SetBitmap() now doesn't resize the view anymore. * BitmapView has now a minimum size of 32x32. * Draw bitmap on BitmapView using B_FILTER_BITMAP_BILINEAR. * StatusView sets now explicit max and preferred size to 50x50 for the avatar icon view and doesn't resize the bitmap explicitely. * Small style violation fixes. --- application/views/StatusView.cpp | 5 ++-- libs/libinterface/BitmapUtils.cpp | 22 +++++++-------- libs/libinterface/BitmapView.cpp | 45 +++++++++++++++++++++---------- libs/libinterface/BitmapView.h | 4 ++- 4 files changed, 48 insertions(+), 28 deletions(-) diff --git a/application/views/StatusView.cpp b/application/views/StatusView.cpp index b96c936..e75cb81 100644 --- a/application/views/StatusView.cpp +++ b/application/views/StatusView.cpp @@ -63,6 +63,8 @@ StatusView::StatusView(const char* name) // Icon fAvatar = new BitmapView("icon"); + fAvatar->SetExplicitMaxSize(BSize(50, 50)); + fAvatar->SetExplicitPreferredSize(BSize(50, 50)); // Set layout SetLayout(new BGroupLayout(B_VERTICAL)); @@ -134,6 +136,5 @@ StatusView::SetStatus(CayaStatus status) void StatusView::SetAvatar(BBitmap* bitmap) { - BBitmap* b = RescaleBitmap(bitmap, 49, 49); - fAvatar->SetBitmap(b); + fAvatar->SetBitmap(bitmap); } diff --git a/libs/libinterface/BitmapUtils.cpp b/libs/libinterface/BitmapUtils.cpp index 29ad92c..83ce8bd 100644 --- a/libs/libinterface/BitmapUtils.cpp +++ b/libs/libinterface/BitmapUtils.cpp @@ -29,8 +29,7 @@ ReadNodeIcon(const char* name, icon_size size, bool followSymlink) BNode node(BPath(&ref).Path()); - BBitmap* ret = new BBitmap(BRect(0, 0, (float)size - 1, (float)size - 1), - B_RGBA32); + BBitmap* ret = new BBitmap(BRect(0, 0, (float)size - 1, (float)size - 1), B_RGBA32); if (BIconUtils::GetIcon(&node, BEOS_ICON_ATTRIBUTE, BEOS_MINI_ICON_ATTRIBUTE, BEOS_LARGE_ICON_ATTRIBUTE, size, ret) != B_OK) { delete ret; @@ -105,29 +104,30 @@ RescaleBitmap(const BBitmap* src, int32 width, int32 height) if (height < 0) { float srcProp = srcSize.Height() / srcSize.Width(); - height = (width * (int32)srcProp); + height = (int32)(width * ceil(srcProp)); } BBitmap* res = new BBitmap(BRect(0, 0, (float)width, (float)height), src->ColorSpace()); - float dx = (srcSize.Width() + 1) / ((float)width + 1); - float dy = (srcSize.Height() + 1) / ((float)height + 1); - uint8 bpp = (uint8)(src->BytesPerRow() / (int32)srcSize.Width()); + float dx = (srcSize.Width() + 1) / (float)(width + 1); + float dy = (srcSize.Height() + 1) / (float)(height + 1); + uint8 bpp = (uint8)(src->BytesPerRow() / ceil(srcSize.Width())); - int32 srcYOff = src->BytesPerRow(); - int32 dstYOff = res->BytesPerRow(); + int srcYOff = src->BytesPerRow(); + int dstYOff = res->BytesPerRow(); void* dstData = res->Bits(); void* srcData = src->Bits(); for (int32 y = 0; y <= height; y++) { void* dstRow = (void*)((uint32)dstData + (uint32)(y * dstYOff)); - void* srcRow = (void*)((uint32)srcData + ((uint32)(y * (int32)dy) * srcYOff)); + void* srcRow = (void*)((uint32)srcData + ((uint32)(y * dy) + * srcYOff)); for (int32 x = 0; x <= width; x++) - memcpy((void*)((uint32)dstRow + (x * bpp)), (void*)((uint32)srcRow + - ((uint32)(x * (int32)dx) * bpp)), bpp); + memcpy((void*)((uint32)dstRow + (x * bpp)), (void*)((uint32)srcRow + + ((uint32)(x * dx) * bpp)), bpp); } return res; diff --git a/libs/libinterface/BitmapView.cpp b/libs/libinterface/BitmapView.cpp index f5a0b80..d3b2c26 100644 --- a/libs/libinterface/BitmapView.cpp +++ b/libs/libinterface/BitmapView.cpp @@ -7,20 +7,24 @@ */ #include +#include #include #include "BitmapView.h" +const float kMinWidth = 32.0f; +const float kMinHeight = 32.0f; + BitmapView::BitmapView(const char* name, uint32 flags) - : BView(name, flags), + : + BView(name, flags | B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE), fBitmap(NULL), - fWidth(0.0f), - fHeight(0.0f) + fWidth(kMinWidth), + fHeight(kMinHeight) { - // Set transparent - //SetViewColor(B_TRANSPARENT_COLOR); - SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + // Set transparent view color + SetViewColor(B_TRANSPARENT_COLOR); } @@ -40,19 +44,26 @@ BitmapView::InitCheck() } +BBitmap* +BitmapView::Bitmap() const +{ + return fBitmap; +} + + void BitmapView::SetBitmap(BBitmap* bitmap) { delete fBitmap; fBitmap = bitmap; - if (fBitmap != NULL) { + if (fBitmap) { BRect frame(fBitmap->Bounds()); - fWidth = frame.Width(); + fWidth = frame.Width(); fHeight = frame.Height(); - ResizeTo(fWidth, fHeight); + Invalidate(); } } @@ -60,30 +71,36 @@ BitmapView::SetBitmap(BBitmap* bitmap) BSize BitmapView::MinSize() { - return BSize(fWidth, fHeight); + return BLayoutUtils::ComposeSize(ExplicitMinSize(), + BSize(kMinWidth, kMinHeight)); } BSize BitmapView::MaxSize() { - return MinSize(); + return BLayoutUtils::ComposeSize(ExplicitMaxSize(), + BSize(fWidth, fHeight)); } BSize BitmapView::PreferredSize() { - return MinSize(); + return BLayoutUtils::ComposeSize(ExplicitPreferredSize(), + BSize(fWidth, fHeight)); } void BitmapView::Draw(BRect frame) { + if (!fBitmap) + return; + SetDrawingMode(B_OP_ALPHA); SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY); - if (fBitmap != NULL) - DrawBitmap(fBitmap, BPoint(0, 0)); + DrawBitmap(fBitmap, fBitmap->Bounds(), + Bounds(), B_FILTER_BITMAP_BILINEAR); } diff --git a/libs/libinterface/BitmapView.h b/libs/libinterface/BitmapView.h index 147e4f1..4ed8248 100644 --- a/libs/libinterface/BitmapView.h +++ b/libs/libinterface/BitmapView.h @@ -11,11 +11,13 @@ class BBitmap; class BitmapView : public BView { public: - BitmapView(const char* name, uint32 flags = B_WILL_DRAW); + BitmapView(const char* name, uint32 flags + = B_WILL_DRAW); ~BitmapView(); status_t InitCheck(); + BBitmap* Bitmap() const; void SetBitmap(BBitmap* bitmap); virtual BSize MinSize();