-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCoverView.cpp
More file actions
58 lines (50 loc) · 1.21 KB
/
CoverView.cpp
File metadata and controls
58 lines (50 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "CoverView.h"
#include "Debug.h"
#include <Bitmap.h>
#include <cstdio>
CoverView::CoverView(const char *name)
: BView(name, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE) {
SetViewColor(B_TRANSPARENT_COLOR);
}
CoverView::~CoverView() {
delete fBitmap;
fBitmap = nullptr;
}
/**
* @brief Updates the displayed cover image.
* Makes a defensive copy of the provided bitmap.
*
* @param bmp The new bitmap to display (can be nullptr to clear).
*/
void CoverView::SetBitmap(BBitmap *bmp) {
if (fBitmap == nullptr && bmp == nullptr)
return;
BBitmap *clone = nullptr;
if (bmp && bmp->IsValid()) {
clone = new BBitmap(bmp);
if (!clone->IsValid()) {
delete clone;
clone = nullptr;
}
}
delete fBitmap;
fBitmap = clone;
Invalidate();
}
/**
* @brief Draws the cover scaled to fit the view bounds.
*/
void CoverView::Draw(BRect) {
SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR));
FillRect(Bounds());
if (!fBitmap || !fBitmap->IsValid()) {
return;
}
DrawBitmapAsync(fBitmap, fBitmap->Bounds(), Bounds());
}
void CoverView::GetPreferredSize(float *w, float *h) {
if (w)
*w = 200;
if (h)
*h = 200;
}