2010-05-07 04:47:10 -05:00
|
|
|
/*
|
2010-05-27 20:08:18 -05:00
|
|
|
* Copyright 2009-2010, Pier Luigi Fiorini. All rights reserved.
|
2010-05-07 04:47:10 -05:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Pier Luigi Fiorini, pierluigi.fiorini@gmail.com
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <Bitmap.h>
|
2010-05-20 13:11:32 -05:00
|
|
|
#include <LayoutUtils.h>
|
2010-05-07 04:47:10 -05:00
|
|
|
#include <TranslationUtils.h>
|
|
|
|
|
|
|
|
#include "BitmapView.h"
|
|
|
|
|
2010-05-27 20:08:18 -05:00
|
|
|
const float kMinWidth = 32.0f;
|
|
|
|
const float kMinHeight = 32.0f;
|
2010-05-20 13:11:32 -05:00
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
|
|
|
|
BitmapView::BitmapView(const char* name, uint32 flags)
|
2010-05-20 13:11:32 -05:00
|
|
|
:
|
|
|
|
BView(name, flags | B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE),
|
2010-05-07 04:47:10 -05:00
|
|
|
fBitmap(NULL),
|
2010-05-20 13:11:32 -05:00
|
|
|
fWidth(kMinWidth),
|
|
|
|
fHeight(kMinHeight)
|
2010-05-07 04:47:10 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BitmapView::~BitmapView()
|
|
|
|
{
|
|
|
|
delete fBitmap;
|
|
|
|
fBitmap = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-29 23:24:53 -05:00
|
|
|
void
|
|
|
|
BitmapView::AttachedToWindow()
|
|
|
|
{
|
|
|
|
// Set view color to parent's view color
|
|
|
|
SetViewColor(Parent()->ViewColor());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
status_t
|
|
|
|
BitmapView::InitCheck()
|
|
|
|
{
|
|
|
|
if (fBitmap != NULL)
|
|
|
|
return B_OK;
|
|
|
|
return B_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-20 13:11:32 -05:00
|
|
|
BBitmap*
|
|
|
|
BitmapView::Bitmap() const
|
|
|
|
{
|
|
|
|
return fBitmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-27 19:47:00 -05:00
|
|
|
void
|
|
|
|
BitmapView::SetBitmap(const char* filename)
|
|
|
|
{
|
|
|
|
delete fBitmap;
|
|
|
|
fBitmap = BTranslationUtils::GetBitmap(filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
void
|
|
|
|
BitmapView::SetBitmap(BBitmap* bitmap)
|
|
|
|
{
|
|
|
|
delete fBitmap;
|
|
|
|
fBitmap = bitmap;
|
|
|
|
|
2010-05-20 13:11:32 -05:00
|
|
|
if (fBitmap) {
|
2010-05-07 04:47:10 -05:00
|
|
|
BRect frame(fBitmap->Bounds());
|
|
|
|
|
2010-05-20 13:11:32 -05:00
|
|
|
fWidth = frame.Width();
|
2010-05-07 04:47:10 -05:00
|
|
|
fHeight = frame.Height();
|
|
|
|
|
2010-05-20 13:11:32 -05:00
|
|
|
Invalidate();
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BSize
|
|
|
|
BitmapView::MinSize()
|
|
|
|
{
|
2010-05-20 13:11:32 -05:00
|
|
|
return BLayoutUtils::ComposeSize(ExplicitMinSize(),
|
|
|
|
BSize(kMinWidth, kMinHeight));
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BSize
|
|
|
|
BitmapView::MaxSize()
|
|
|
|
{
|
2010-05-20 13:11:32 -05:00
|
|
|
return BLayoutUtils::ComposeSize(ExplicitMaxSize(),
|
|
|
|
BSize(fWidth, fHeight));
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BSize
|
|
|
|
BitmapView::PreferredSize()
|
|
|
|
{
|
2010-05-20 13:11:32 -05:00
|
|
|
return BLayoutUtils::ComposeSize(ExplicitPreferredSize(),
|
|
|
|
BSize(fWidth, fHeight));
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
BitmapView::Draw(BRect frame)
|
|
|
|
{
|
2010-05-20 13:11:32 -05:00
|
|
|
if (!fBitmap)
|
|
|
|
return;
|
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
SetDrawingMode(B_OP_ALPHA);
|
|
|
|
SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY);
|
|
|
|
|
2010-05-20 13:11:32 -05:00
|
|
|
DrawBitmap(fBitmap, fBitmap->Bounds(),
|
|
|
|
Bounds(), B_FILTER_BITMAP_BILINEAR);
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|