-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAlbumWindow.cpp
118 lines (95 loc) · 2.68 KB
/
AlbumWindow.cpp
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
* Code for the album selection window. This window has First, previous, Next and Last buttons
* to scroll through the list of albums. The album art and album name are displayed for the
* currently selected album, and clicking on the album art image plays it.
* This window also accepts steering wheel controls:
* > Select next album
* < Select previous album
* O Play selected album
* ^ Cancel selection
*/
#include "AlbumWindow.h"
AlbumWindow::AlbumWindow(BaseObjectType* cobject, Glib::RefPtr<Gtk::Builder> &builder): Gtk::Window(cobject)
{
signal_show().connect(sigc::mem_fun(*this, &AlbumWindow::onShow));
builder->get_widget("AwAlbumNameLabel", albumLabel);
builder->get_widget("AwAlbumImage", albumImage);
builder->get_widget("AwMainEb", mainEb);
builder->get_widget("AwAlbumEb", imageEb);
mainEb->set_events(Gdk::BUTTON_PRESS_MASK);
imageEb->set_events(Gdk::BUTTON_PRESS_MASK);
mainEb->signal_button_press_event().connect(sigc::mem_fun(*this, &AlbumWindow::mouseClick));
imageEb->signal_button_press_event().connect(sigc::mem_fun(*this, &AlbumWindow::imageClick));
}
void AlbumWindow::onShow()
{
get_window()->set_cursor(Gdk::Cursor::create(Gdk::BLANK_CURSOR));
albumIndex = player->GetCurrentAlbumIndex();
SetAlbumControls();
}
void AlbumWindow::SetAlbumControls()
{
// Sets the label and image based on the currently selected album
const char* format = "<span foreground=\"#ffba00\" font=\"LCARS 16\">%s</span>";
string name = player->GetAlbumName(albumIndex);
albumLabel->set_markup(Glib::ustring(g_markup_printf_escaped(format, name.c_str())));
string imagePath = player->GetAlbumArt(albumIndex);
Glib::RefPtr<Gdk::Pixbuf> pb = Gdk::Pixbuf::create_from_file(imagePath, 160, 160, true);
albumImage->set(pb);
}
bool AlbumWindow::imageClick(GdkEventButton* event)
{
SelectAlbum();
}
void AlbumWindow::NextAlbum()
{
unsigned int count = player->GetAlbumCount();
if (albumIndex == (count - 1))
{
return;
}
albumIndex++;
SetAlbumControls();
}
void AlbumWindow::PreviousAlbum()
{
unsigned int count = player->GetAlbumCount();
if (albumIndex == 0)
{
return;
}
albumIndex--;
SetAlbumControls();
}
void AlbumWindow::SelectAlbum()
{
player->SwitchAlbum(albumIndex);
hide();
}
void AlbumWindow::Cancel()
{
hide();
}
bool AlbumWindow::mouseClick(GdkEventButton* event)
{
if (RectHit(nextButton, event->x, event->y))
{
NextAlbum();
}
if (RectHit(prevButton, event->x, event->y))
{
PreviousAlbum();
}
if (RectHit(firstButton, event->x, event->y))
{
albumIndex = 0;
SetAlbumControls();
}
if (RectHit(lastButton, event->x, event->y))
{
unsigned int count = player->GetAlbumCount();
albumIndex = count - 1;
SetAlbumControls();
}
return true;
}