* 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.
This commit is contained in:
plfiorini 2010-05-20 18:11:32 +00:00
parent 90a68e6002
commit b314c7abd8
4 changed files with 48 additions and 28 deletions

View File

@ -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);
}

View File

@ -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;

View File

@ -7,20 +7,24 @@
*/
#include <Bitmap.h>
#include <LayoutUtils.h>
#include <TranslationUtils.h>
#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();
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);
}

View File

@ -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();