Skip to content

Commit 485e5be

Browse files
committed
CoverWindow: Added some sample covers
* Added IconView to show them. * Improved layout.
1 parent faa2c9d commit 485e5be

File tree

4 files changed

+127
-8
lines changed

4 files changed

+127
-8
lines changed

CoverWindow.cpp

+111-3
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,131 @@
55

66
#include "CoverWindow.h"
77

8+
#include <Bitmap.h>
89
#include <GridView.h>
910
#include <LayoutBuilder.h>
1011
#include <ScrollView.h>
1112
#include <TextControl.h>
13+
#include <TranslationUtils.h>
1214

1315

16+
static const uint32 kMsgAddImage = 'adIm';
17+
18+
19+
class IconView : public BView {
20+
public:
21+
IconView(BBitmap* bitmap);
22+
virtual ~IconView();
23+
24+
void SetSelected(bool selected);
25+
bool IsSelected();
26+
27+
virtual void MouseDown(BPoint where);
28+
virtual void Draw(BRect updateRect);
29+
30+
private:
31+
BBitmap* fBitmap;
32+
bool fSelected;
33+
};
34+
35+
36+
// #pragma mark - IconView
37+
38+
39+
IconView::IconView(BBitmap* bitmap)
40+
:
41+
BView("image", B_WILL_DRAW),
42+
fBitmap(bitmap),
43+
fSelected(false)
44+
{
45+
SetExplicitMaxSize(BSize(69, 69));
46+
}
47+
48+
49+
IconView::~IconView()
50+
{
51+
delete fBitmap;
52+
}
53+
54+
55+
void
56+
IconView::SetSelected(bool selected)
57+
{
58+
if (selected == fSelected)
59+
return;
60+
61+
fSelected = selected;
62+
Invalidate();
63+
}
64+
65+
66+
bool
67+
IconView::IsSelected()
68+
{
69+
return fSelected;
70+
}
71+
72+
73+
void
74+
IconView::MouseDown(BPoint where)
75+
{
76+
SetSelected(!IsSelected());
77+
}
78+
79+
80+
void
81+
IconView::Draw(BRect updateRect)
82+
{
83+
BRect rect = Bounds();
84+
rect.InsetBy(4, 4);
85+
DrawBitmap(fBitmap, rect);
86+
87+
if (IsSelected()) {
88+
SetPenSize(7);
89+
SetHighColor(140, 140, 240);
90+
// SetHighColor(ui_color(B_LIST_SELECTED_BACKGROUND_COLOR));
91+
StrokeRect(Bounds());
92+
}
93+
}
94+
95+
96+
// #pragma mark - CoverWindow
97+
1498

1599
CoverWindow::CoverWindow()
16100
:
17101
BWindow(BRect(0, 0, 600, 400), "Covers", B_DOCUMENT_WINDOW,
18102
B_AUTO_UPDATE_SIZE_LIMITS)
19103
{
20-
BTextControl* artistControl = new BTextControl("artist", "", NULL);
21-
BTextControl* titleControl = new BTextControl("title", "", NULL);
104+
BTextControl* artistControl = new BTextControl("Artist", "", NULL);
105+
BTextControl* titleControl = new BTextControl("Title", "", NULL);
22106

23107
fMainView = new BGridView("main");
108+
fMainView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED));
24109

25110
BScrollView* scrollView = new BScrollView("scroller", fMainView,
26111
B_FULL_UPDATE_ON_RESIZE, true, true);
27112

28-
BLayoutBuilder::Group<>(this, B_VERTICAL, B_USE_DEFAULT_SPACING)
113+
BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
114+
.SetInsets(-2)
29115
.AddGroup(B_HORIZONTAL, B_USE_DEFAULT_SPACING)
116+
.SetInsets(B_USE_DEFAULT_SPACING)
30117
.Add(artistControl)
31118
.Add(titleControl)
32119
.End()
33120
.Add(scrollView);
121+
122+
// TODO: for testing purposes only!
123+
const char* files[] = {"/Media/Kram/Pics/band.jpg",
124+
"/boot/home/Desktop/CD Cover/Antemasque - dto.jpg",
125+
"/boot/home/Desktop/CD Cover/Danzig - dto.jpg",
126+
"/boot/home/Desktop/CD Cover/Kate Bush - Never For Ever.jpg", NULL};
127+
for (int i = 0; files[i] != NULL; i++) {
128+
BBitmap* bitmap = BTranslationUtils::GetBitmapFile(files[i]);
129+
BMessage add(kMsgAddImage);
130+
add.AddPointer("image", bitmap);
131+
PostMessage(&add);
132+
}
34133
}
35134

36135

@@ -43,6 +142,15 @@ void
43142
CoverWindow::MessageReceived(BMessage* message)
44143
{
45144
switch (message->what) {
145+
case kMsgAddImage:
146+
{
147+
BBitmap* bitmap = (BBitmap*)message->GetPointer("image");
148+
if (bitmap != NULL) {
149+
fMainView->AddChild(new IconView(bitmap));
150+
// fMainView->GridLayout()->AddView(new IconView(bitmap), 0, 0);
151+
}
152+
break;
153+
}
46154
default:
47155
BWindow::MessageReceived(message);
48156
break;

CoverWindow.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
#include <Window.h>
99

1010

11+
class BGridView;
12+
13+
1114
class CoverWindow : public BWindow {
1215
public:
1316
CoverWindow();
@@ -16,7 +19,7 @@ class CoverWindow : public BWindow {
1619
virtual void MessageReceived(BMessage* message);
1720

1821
private:
19-
BView* fMainView;
22+
BGridView* fMainView;
2023
};
2124

2225

covers.cpp

+12-4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include <regex.h>
1414
#include <stdio.h>
1515

16+
#include "CoverWindow.h"
17+
1618

1719
#define MAX_GROUPS 10
1820
#define MAX_MATCHES 10
@@ -68,7 +70,7 @@ loadImage(int countryCode, const BString& id, const char* type)
6870

6971
const BHttpResult& result = dynamic_cast<const BHttpResult&>(
7072
request.Result());
71-
printf("Status: %d - %s\n", result.StatusCode(),
73+
printf("Status: %" B_PRId32 " d - %s\n", result.StatusCode(),
7274
result.StatusText().String());
7375

7476
listener.IO().Seek(0, SEEK_SET);
@@ -120,7 +122,7 @@ getImageFromAmazon(const char* country, int countryCode, const BString& artist,
120122

121123
const BHttpResult& result = dynamic_cast<const BHttpResult&>(
122124
request.Result());
123-
printf("Status: %d - %s\n", result.StatusCode(),
125+
printf("Status: %" B_PRId32 " - %s\n", result.StatusCode(),
124126
result.StatusText().String());
125127

126128
BString data((const char*)listener.IO().Buffer(),
@@ -136,7 +138,7 @@ getImageFromAmazon(const char* country, int countryCode, const BString& artist,
136138
BString id;
137139

138140
for (int groupIndex = 0; groupIndex < MAX_GROUPS; groupIndex++) {
139-
if (groups[groupIndex].rm_so == (size_t)-1)
141+
if (groups[groupIndex].rm_so == -1)
140142
break;
141143
if (groupIndex == 0)
142144
offset = groups[0].rm_eo;
@@ -168,5 +170,11 @@ int
168170
main()
169171
{
170172
BApplication application("application/x-vnd.pinc-covers");
171-
getImageFromAmazon("de", COUNTRY_GERMANY, "toundra", "");
173+
// getImageFromAmazon("de", COUNTRY_GERMANY, "toundra", "");
174+
175+
BWindow* window = new CoverWindow();
176+
window->CenterOnScreen();
177+
window->Show();
178+
179+
application.Run();
172180
}

covers.rsrc

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)