|
5 | 5 |
|
6 | 6 | #include "CoverWindow.h"
|
7 | 7 |
|
| 8 | +#include <Bitmap.h> |
8 | 9 | #include <GridView.h>
|
9 | 10 | #include <LayoutBuilder.h>
|
10 | 11 | #include <ScrollView.h>
|
11 | 12 | #include <TextControl.h>
|
| 13 | +#include <TranslationUtils.h> |
12 | 14 |
|
13 | 15 |
|
| 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 | + |
14 | 98 |
|
15 | 99 | CoverWindow::CoverWindow()
|
16 | 100 | :
|
17 | 101 | BWindow(BRect(0, 0, 600, 400), "Covers", B_DOCUMENT_WINDOW,
|
18 | 102 | B_AUTO_UPDATE_SIZE_LIMITS)
|
19 | 103 | {
|
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); |
22 | 106 |
|
23 | 107 | fMainView = new BGridView("main");
|
| 108 | + fMainView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED)); |
24 | 109 |
|
25 | 110 | BScrollView* scrollView = new BScrollView("scroller", fMainView,
|
26 | 111 | B_FULL_UPDATE_ON_RESIZE, true, true);
|
27 | 112 |
|
28 |
| - BLayoutBuilder::Group<>(this, B_VERTICAL, B_USE_DEFAULT_SPACING) |
| 113 | + BLayoutBuilder::Group<>(this, B_VERTICAL, 0) |
| 114 | + .SetInsets(-2) |
29 | 115 | .AddGroup(B_HORIZONTAL, B_USE_DEFAULT_SPACING)
|
| 116 | + .SetInsets(B_USE_DEFAULT_SPACING) |
30 | 117 | .Add(artistControl)
|
31 | 118 | .Add(titleControl)
|
32 | 119 | .End()
|
33 | 120 | .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 | + } |
34 | 133 | }
|
35 | 134 |
|
36 | 135 |
|
|
43 | 142 | CoverWindow::MessageReceived(BMessage* message)
|
44 | 143 | {
|
45 | 144 | 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 | + } |
46 | 154 | default:
|
47 | 155 | BWindow::MessageReceived(message);
|
48 | 156 | break;
|
|
0 commit comments