* 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:
parent
90a68e6002
commit
b314c7abd8
|
@ -63,6 +63,8 @@ StatusView::StatusView(const char* name)
|
||||||
|
|
||||||
// Icon
|
// Icon
|
||||||
fAvatar = new BitmapView("icon");
|
fAvatar = new BitmapView("icon");
|
||||||
|
fAvatar->SetExplicitMaxSize(BSize(50, 50));
|
||||||
|
fAvatar->SetExplicitPreferredSize(BSize(50, 50));
|
||||||
|
|
||||||
// Set layout
|
// Set layout
|
||||||
SetLayout(new BGroupLayout(B_VERTICAL));
|
SetLayout(new BGroupLayout(B_VERTICAL));
|
||||||
|
@ -134,6 +136,5 @@ StatusView::SetStatus(CayaStatus status)
|
||||||
void
|
void
|
||||||
StatusView::SetAvatar(BBitmap* bitmap)
|
StatusView::SetAvatar(BBitmap* bitmap)
|
||||||
{
|
{
|
||||||
BBitmap* b = RescaleBitmap(bitmap, 49, 49);
|
fAvatar->SetBitmap(bitmap);
|
||||||
fAvatar->SetBitmap(b);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,8 +29,7 @@ ReadNodeIcon(const char* name, icon_size size, bool followSymlink)
|
||||||
|
|
||||||
BNode node(BPath(&ref).Path());
|
BNode node(BPath(&ref).Path());
|
||||||
|
|
||||||
BBitmap* ret = new BBitmap(BRect(0, 0, (float)size - 1, (float)size - 1),
|
BBitmap* ret = new BBitmap(BRect(0, 0, (float)size - 1, (float)size - 1), B_RGBA32);
|
||||||
B_RGBA32);
|
|
||||||
if (BIconUtils::GetIcon(&node, BEOS_ICON_ATTRIBUTE, BEOS_MINI_ICON_ATTRIBUTE,
|
if (BIconUtils::GetIcon(&node, BEOS_ICON_ATTRIBUTE, BEOS_MINI_ICON_ATTRIBUTE,
|
||||||
BEOS_LARGE_ICON_ATTRIBUTE, size, ret) != B_OK) {
|
BEOS_LARGE_ICON_ATTRIBUTE, size, ret) != B_OK) {
|
||||||
delete ret;
|
delete ret;
|
||||||
|
@ -105,29 +104,30 @@ RescaleBitmap(const BBitmap* src, int32 width, int32 height)
|
||||||
|
|
||||||
if (height < 0) {
|
if (height < 0) {
|
||||||
float srcProp = srcSize.Height() / srcSize.Width();
|
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),
|
BBitmap* res = new BBitmap(BRect(0, 0, (float)width, (float)height),
|
||||||
src->ColorSpace());
|
src->ColorSpace());
|
||||||
|
|
||||||
float dx = (srcSize.Width() + 1) / ((float)width + 1);
|
float dx = (srcSize.Width() + 1) / (float)(width + 1);
|
||||||
float dy = (srcSize.Height() + 1) / ((float)height + 1);
|
float dy = (srcSize.Height() + 1) / (float)(height + 1);
|
||||||
uint8 bpp = (uint8)(src->BytesPerRow() / (int32)srcSize.Width());
|
uint8 bpp = (uint8)(src->BytesPerRow() / ceil(srcSize.Width()));
|
||||||
|
|
||||||
int32 srcYOff = src->BytesPerRow();
|
int srcYOff = src->BytesPerRow();
|
||||||
int32 dstYOff = res->BytesPerRow();
|
int dstYOff = res->BytesPerRow();
|
||||||
|
|
||||||
void* dstData = res->Bits();
|
void* dstData = res->Bits();
|
||||||
void* srcData = src->Bits();
|
void* srcData = src->Bits();
|
||||||
|
|
||||||
for (int32 y = 0; y <= height; y++) {
|
for (int32 y = 0; y <= height; y++) {
|
||||||
void* dstRow = (void*)((uint32)dstData + (uint32)(y * dstYOff));
|
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++)
|
for (int32 x = 0; x <= width; x++)
|
||||||
memcpy((void*)((uint32)dstRow + (x * bpp)), (void*)((uint32)srcRow +
|
memcpy((void*)((uint32)dstRow + (x * bpp)), (void*)((uint32)srcRow
|
||||||
((uint32)(x * (int32)dx) * bpp)), bpp);
|
+ ((uint32)(x * dx) * bpp)), bpp);
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|
|
@ -7,20 +7,24 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <Bitmap.h>
|
#include <Bitmap.h>
|
||||||
|
#include <LayoutUtils.h>
|
||||||
#include <TranslationUtils.h>
|
#include <TranslationUtils.h>
|
||||||
|
|
||||||
#include "BitmapView.h"
|
#include "BitmapView.h"
|
||||||
|
|
||||||
|
const float kMinWidth = 32.0f;
|
||||||
|
const float kMinHeight = 32.0f;
|
||||||
|
|
||||||
|
|
||||||
BitmapView::BitmapView(const char* name, uint32 flags)
|
BitmapView::BitmapView(const char* name, uint32 flags)
|
||||||
: BView(name, flags),
|
:
|
||||||
|
BView(name, flags | B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE),
|
||||||
fBitmap(NULL),
|
fBitmap(NULL),
|
||||||
fWidth(0.0f),
|
fWidth(kMinWidth),
|
||||||
fHeight(0.0f)
|
fHeight(kMinHeight)
|
||||||
{
|
{
|
||||||
// Set transparent
|
// Set transparent view color
|
||||||
//SetViewColor(B_TRANSPARENT_COLOR);
|
SetViewColor(B_TRANSPARENT_COLOR);
|
||||||
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,19 +44,26 @@ BitmapView::InitCheck()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BBitmap*
|
||||||
|
BitmapView::Bitmap() const
|
||||||
|
{
|
||||||
|
return fBitmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BitmapView::SetBitmap(BBitmap* bitmap)
|
BitmapView::SetBitmap(BBitmap* bitmap)
|
||||||
{
|
{
|
||||||
delete fBitmap;
|
delete fBitmap;
|
||||||
fBitmap = bitmap;
|
fBitmap = bitmap;
|
||||||
|
|
||||||
if (fBitmap != NULL) {
|
if (fBitmap) {
|
||||||
BRect frame(fBitmap->Bounds());
|
BRect frame(fBitmap->Bounds());
|
||||||
|
|
||||||
fWidth = frame.Width();
|
fWidth = frame.Width();
|
||||||
fHeight = frame.Height();
|
fHeight = frame.Height();
|
||||||
|
|
||||||
ResizeTo(fWidth, fHeight);
|
Invalidate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,30 +71,36 @@ BitmapView::SetBitmap(BBitmap* bitmap)
|
||||||
BSize
|
BSize
|
||||||
BitmapView::MinSize()
|
BitmapView::MinSize()
|
||||||
{
|
{
|
||||||
return BSize(fWidth, fHeight);
|
return BLayoutUtils::ComposeSize(ExplicitMinSize(),
|
||||||
|
BSize(kMinWidth, kMinHeight));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BSize
|
BSize
|
||||||
BitmapView::MaxSize()
|
BitmapView::MaxSize()
|
||||||
{
|
{
|
||||||
return MinSize();
|
return BLayoutUtils::ComposeSize(ExplicitMaxSize(),
|
||||||
|
BSize(fWidth, fHeight));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BSize
|
BSize
|
||||||
BitmapView::PreferredSize()
|
BitmapView::PreferredSize()
|
||||||
{
|
{
|
||||||
return MinSize();
|
return BLayoutUtils::ComposeSize(ExplicitPreferredSize(),
|
||||||
|
BSize(fWidth, fHeight));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BitmapView::Draw(BRect frame)
|
BitmapView::Draw(BRect frame)
|
||||||
{
|
{
|
||||||
|
if (!fBitmap)
|
||||||
|
return;
|
||||||
|
|
||||||
SetDrawingMode(B_OP_ALPHA);
|
SetDrawingMode(B_OP_ALPHA);
|
||||||
SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY);
|
SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY);
|
||||||
|
|
||||||
if (fBitmap != NULL)
|
DrawBitmap(fBitmap, fBitmap->Bounds(),
|
||||||
DrawBitmap(fBitmap, BPoint(0, 0));
|
Bounds(), B_FILTER_BITMAP_BILINEAR);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,11 +11,13 @@ class BBitmap;
|
||||||
|
|
||||||
class BitmapView : public BView {
|
class BitmapView : public BView {
|
||||||
public:
|
public:
|
||||||
BitmapView(const char* name, uint32 flags = B_WILL_DRAW);
|
BitmapView(const char* name, uint32 flags
|
||||||
|
= B_WILL_DRAW);
|
||||||
~BitmapView();
|
~BitmapView();
|
||||||
|
|
||||||
status_t InitCheck();
|
status_t InitCheck();
|
||||||
|
|
||||||
|
BBitmap* Bitmap() const;
|
||||||
void SetBitmap(BBitmap* bitmap);
|
void SetBitmap(BBitmap* bitmap);
|
||||||
|
|
||||||
virtual BSize MinSize();
|
virtual BSize MinSize();
|
||||||
|
|
Ŝarĝante…
Reference in New Issue