Chat-O-Matic/libs/libinterface/PictureView.cpp

86 lines
1.2 KiB
C++
Raw Normal View History

/*
* Copyright 2009, Pier Luigi Fiorini. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Pier Luigi Fiorini, pierluigi.fiorini@gmail.com
*/
#include <Bitmap.h>
#include <TranslationUtils.h>
#include "PictureView.h"
PictureView::PictureView(const char* name, const char* filename, uint32 flags)
: BView(name, flags),
fBitmap(NULL),
fWidth(0.0f),
fHeight(0.0f)
{
// Set transparent
SetViewColor(B_TRANSPARENT_COLOR);
// Try to get the image
fBitmap = BTranslationUtils::GetBitmap(filename);
if (fBitmap) {
BRect frame(fBitmap->Bounds());
fWidth = frame.Width();
fHeight = frame.Height();
} else
return;
ResizeTo(fWidth, fHeight);
}
PictureView::~PictureView()
{
delete fBitmap;
fBitmap = NULL;
}
status_t
PictureView::InitCheck()
{
if (fBitmap != NULL)
return B_OK;
return B_ERROR;
}
BSize
PictureView::MinSize()
{
return BSize(fWidth, fHeight);
}
BSize
PictureView::MaxSize()
{
return MinSize();
}
BSize
PictureView::PreferredSize()
{
return MinSize();
}
void
PictureView::Draw(BRect frame)
{
2010-05-10 17:42:54 -05:00
if (fBitmap) {
SetDrawingMode(B_OP_ALPHA);
SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY);
DrawBitmap(fBitmap, fBitmap->Bounds(),
Bounds(), B_FILTER_BITMAP_BILINEAR);
}
}