Zachary Hall
7b7d44e9d0
Some checks failed
Build / build-deb (push) Blocked by required conditions
Build / build-appimage (push) Blocked by required conditions
Build / build-android (push) Blocked by required conditions
Build / build-windows (push) Blocked by required conditions
Build / download-system-deps (push) Successful in 4m57s
Build / get-source-code (push) Has been cancelled
Build / build-gentoo (push) Failing after 1m6s
63 lines
1.4 KiB
C++
63 lines
1.4 KiB
C++
#include "image_view.h"
|
|
|
|
|
|
LImageView::LImageView(const char *name, BBitmap *bitmap, BAlignment align) : BView(name, B_SUPPORTS_LAYOUT|B_FRAME_EVENTS)
|
|
{
|
|
SetBitmap(bitmap);
|
|
SetAlignment(align);
|
|
}
|
|
void LImageView::SetBitmap(BBitmap *bitmap) {
|
|
this->bitmap = bitmap;
|
|
Invalidate();
|
|
}
|
|
void LImageView::SetAlignment(BAlignment align) {
|
|
this->align = align;
|
|
Invalidate();
|
|
}
|
|
BBitmap *LImageView::Bitmap() {
|
|
return bitmap;
|
|
}
|
|
BAlignment LImageView::Alignment() {
|
|
return align;
|
|
}
|
|
void LImageView::Draw(BRect updateRect) {
|
|
if (bitmap == NULL) return; // Handle null image.
|
|
int x = 0, y = 0;
|
|
int mw, mh;
|
|
int bw, bh;
|
|
bw = bitmap->Bounds().Width();
|
|
bh = bitmap->Bounds().Height();
|
|
mw = Bounds().Width();
|
|
mh = Bounds().Height();
|
|
switch (align.Horizontal()) {
|
|
case B_ALIGN_LEFT: {
|
|
x = 0;
|
|
} break;
|
|
case B_ALIGN_HORIZONTAL_CENTER: {
|
|
x = (mw - bw) / 2;
|
|
} break;
|
|
case B_ALIGN_RIGHT: {
|
|
x = mw - bw;
|
|
} break;
|
|
}
|
|
switch (align.Vertical()) {
|
|
case B_ALIGN_TOP: {
|
|
y = 0;
|
|
} break;
|
|
case B_ALIGN_VERTICAL_CENTER: {
|
|
y = (mh - bh) / 2;
|
|
} break;
|
|
case B_ALIGN_BOTTOM: {
|
|
y = mh - bh;
|
|
} break;
|
|
}
|
|
BRect bitmap_rect(0, 0, bw, bh);
|
|
BRect draw_rect(x, y, bw + x, bh + y);
|
|
int left = updateRect.left;
|
|
int right = updateRect.right;
|
|
int top = updateRect.top;
|
|
int bottom = updateRect.bottom;
|
|
int x2 = x + bw;
|
|
int y2 = y + bh;
|
|
DrawBitmap(bitmap, bitmap_rect, draw_rect);
|
|
}
|