Now center the picture in the frame.
Don't keep any storage reference, user should now called Update(entry_ref) when it changes. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40646 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -9,12 +9,15 @@
|
|||||||
|
|
||||||
#include "PictureView.h"
|
#include "PictureView.h"
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#include <Bitmap.h>
|
#include <Bitmap.h>
|
||||||
#include <IconUtils.h>
|
#include <IconUtils.h>
|
||||||
|
#include <LayoutUtils.h>
|
||||||
#include <MimeType.h>
|
#include <MimeType.h>
|
||||||
#include <TranslationUtils.h>
|
#include <TranslationUtils.h>
|
||||||
|
|
||||||
#include "PeopleApp.h"
|
#include "PeopleApp.h" // for B_PERSON_MIMETYPE
|
||||||
|
|
||||||
|
|
||||||
const float kPictureMargin = 6.0;
|
const float kPictureMargin = 6.0;
|
||||||
@@ -24,8 +27,7 @@ PictureView::PictureView(float width, float height, const entry_ref* ref)
|
|||||||
BView("pictureview", B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE),
|
BView("pictureview", B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE),
|
||||||
fPicture(NULL),
|
fPicture(NULL),
|
||||||
fOriginalPicture(NULL),
|
fOriginalPicture(NULL),
|
||||||
fDefaultPicture(NULL),
|
fDefaultPicture(NULL)
|
||||||
fRef(ref)
|
|
||||||
{
|
{
|
||||||
SetViewColor(255, 255, 255);
|
SetViewColor(255, 255, 255);
|
||||||
|
|
||||||
@@ -33,12 +35,12 @@ PictureView::PictureView(float width, float height, const entry_ref* ref)
|
|||||||
SetExplicitMinSize(size);
|
SetExplicitMinSize(size);
|
||||||
SetExplicitMaxSize(size);
|
SetExplicitMaxSize(size);
|
||||||
|
|
||||||
BMimeType mime;
|
BMimeType mime(B_PERSON_MIMETYPE);
|
||||||
mime.SetType(B_PERSON_MIMETYPE);
|
|
||||||
uint8* iconData;
|
uint8* iconData;
|
||||||
size_t iconDataSize;
|
size_t iconDataSize;
|
||||||
if (mime.GetIcon(&iconData, &iconDataSize) == B_OK) {
|
if (mime.GetIcon(&iconData, &iconDataSize) == B_OK) {
|
||||||
fDefaultPicture = new BBitmap(BRect(0, 0, width - 1, height - 1),
|
float size = width < height ? width : height;
|
||||||
|
fDefaultPicture = new BBitmap(BRect(0, 0, size, size),
|
||||||
B_RGB32);
|
B_RGB32);
|
||||||
if (fDefaultPicture->InitCheck() != B_OK
|
if (fDefaultPicture->InitCheck() != B_OK
|
||||||
|| BIconUtils::GetVectorIcon(iconData, iconDataSize,
|
|| BIconUtils::GetVectorIcon(iconData, iconDataSize,
|
||||||
@@ -48,7 +50,7 @@ PictureView::PictureView(float width, float height, const entry_ref* ref)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Update();
|
Update(ref);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -86,20 +88,18 @@ PictureView::Revert()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PictureView::Update()
|
PictureView::Update(const entry_ref* ref)
|
||||||
{
|
{
|
||||||
fOriginalPicture = BTranslationUtils::GetBitmap(fRef);
|
fOriginalPicture = BTranslationUtils::GetBitmap(ref);
|
||||||
if (fOriginalPicture != NULL)
|
if (fOriginalPicture != NULL)
|
||||||
fPicture = fOriginalPicture;
|
fPicture = fOriginalPicture;
|
||||||
else
|
|
||||||
fPicture = fDefaultPicture;
|
|
||||||
|
|
||||||
Invalidate();
|
Invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BBitmap*
|
BBitmap*
|
||||||
PictureView::Picture()
|
PictureView::Bitmap()
|
||||||
{
|
{
|
||||||
return fPicture != fDefaultPicture ? fPicture : NULL;
|
return fPicture != fDefaultPicture ? fPicture : NULL;
|
||||||
}
|
}
|
||||||
@@ -139,17 +139,33 @@ void
|
|||||||
PictureView::Draw(BRect updateRect)
|
PictureView::Draw(BRect updateRect)
|
||||||
{
|
{
|
||||||
BRect rect = Bounds();
|
BRect rect = Bounds();
|
||||||
if (fPicture != NULL) {
|
|
||||||
if (fPicture == fDefaultPicture) {
|
BBitmap* picture = fPicture ? fPicture : fDefaultPicture;
|
||||||
|
if (picture != NULL) {
|
||||||
|
if (picture == fDefaultPicture) {
|
||||||
SetDrawingMode(B_OP_ALPHA);
|
SetDrawingMode(B_OP_ALPHA);
|
||||||
SetBlendingMode(B_CONSTANT_ALPHA, B_ALPHA_OVERLAY);
|
SetBlendingMode(B_CONSTANT_ALPHA, B_ALPHA_OVERLAY);
|
||||||
SetHighColor(0, 0, 0, 24);
|
SetHighColor(0, 0, 0, 24);
|
||||||
}
|
}
|
||||||
DrawBitmapAsync(fPicture, fPicture->Bounds(),
|
|
||||||
rect.InsetByCopy(kPictureMargin, kPictureMargin),
|
// scale to fit and center picture in frame
|
||||||
B_FILTER_BITMAP_BILINEAR);
|
BRect frame = rect.InsetByCopy(kPictureMargin, kPictureMargin);
|
||||||
|
BRect srcRect = picture->Bounds();
|
||||||
|
BSize size = frame.Size();
|
||||||
|
if (srcRect.Width() > srcRect.Height())
|
||||||
|
size.height = srcRect.Height() * size.width / srcRect.Width();
|
||||||
|
else
|
||||||
|
size.width = srcRect.Width() * size.height / srcRect.Height();
|
||||||
|
BRect dstRect = BLayoutUtils::AlignInFrame(frame, size,
|
||||||
|
BAlignment(B_ALIGN_HORIZONTAL_CENTER, B_ALIGN_VERTICAL_CENTER));
|
||||||
|
|
||||||
|
DrawBitmapAsync(picture, srcRect, dstRect, B_FILTER_BITMAP_BILINEAR);
|
||||||
|
|
||||||
|
if (picture == fDefaultPicture)
|
||||||
|
SetDrawingMode(B_OP_OVER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Draw the outer frame
|
||||||
rgb_color black = {0, 0, 0, 255};
|
rgb_color black = {0, 0, 0, 255};
|
||||||
SetHighColor(tint_color(black, B_LIGHTEN_2_TINT));
|
SetHighColor(tint_color(black, B_LIGHTEN_2_TINT));
|
||||||
StrokeRect(rect);
|
StrokeRect(rect);
|
||||||
|
|||||||
@@ -24,9 +24,9 @@ public:
|
|||||||
|
|
||||||
bool HasChanged();
|
bool HasChanged();
|
||||||
void Revert();
|
void Revert();
|
||||||
void Update();
|
void Update(const entry_ref* ref);
|
||||||
|
|
||||||
BBitmap* Picture();
|
BBitmap* Bitmap();
|
||||||
|
|
||||||
virtual void MessageReceived(BMessage* message);
|
virtual void MessageReceived(BMessage* message);
|
||||||
virtual void Draw(BRect updateRect);
|
virtual void Draw(BRect updateRect);
|
||||||
@@ -35,7 +35,6 @@ private:
|
|||||||
BBitmap* fPicture;
|
BBitmap* fPicture;
|
||||||
BBitmap* fOriginalPicture;
|
BBitmap* fOriginalPicture;
|
||||||
BBitmap* fDefaultPicture;
|
BBitmap* fDefaultPicture;
|
||||||
const entry_ref* fRef;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user