1 |
douglas |
42 |
// Menu List |
2 |
|
|
// |
3 |
|
|
// Douglas Thrift |
4 |
|
|
// |
5 |
|
|
// $Id$ |
6 |
|
|
|
7 |
douglas |
46 |
#include <iostream> |
8 |
|
|
|
9 |
douglas |
42 |
#include <foreach.hpp> |
10 |
|
|
|
11 |
|
|
#include "MenuList.hpp" |
12 |
|
|
|
13 |
|
|
MenuList *MenuList::previous; |
14 |
|
|
|
15 |
|
|
MenuList::MenuItem::MenuItem(MenuList *list) : list(list) |
16 |
|
|
{ |
17 |
|
|
} |
18 |
|
|
|
19 |
douglas |
44 |
MenuList::MenuList(MenuList *parent, Display &display, size_t size) : parent(parent), display(display), cursor(0), list(size) |
20 |
douglas |
42 |
{ |
21 |
|
|
} |
22 |
|
|
|
23 |
douglas |
47 |
MenuList::MenuList(MenuList *parent) : parent(parent), display(parent->display), cursor(0), list(1) |
24 |
|
|
{ |
25 |
|
|
} |
26 |
|
|
|
27 |
douglas |
42 |
MenuList::~MenuList() |
28 |
|
|
{ |
29 |
|
|
_foreach (std::vector<MenuItem *>, item, list) |
30 |
|
|
delete *item; |
31 |
douglas |
47 |
|
32 |
|
|
if (parent != NULL && parent != this) |
33 |
|
|
delete parent; |
34 |
douglas |
42 |
} |
35 |
|
|
|
36 |
|
|
MenuList *MenuList::Enter() |
37 |
|
|
{ |
38 |
|
|
return list[state.item]->Select(); |
39 |
|
|
} |
40 |
|
|
|
41 |
|
|
MenuList *MenuList::Right() |
42 |
|
|
{ |
43 |
|
|
MenuItem *item(list[state.item]); |
44 |
|
|
|
45 |
|
|
if (dynamic_cast<SubItem *>(item)) |
46 |
|
|
return item->Select(); |
47 |
|
|
|
48 |
|
|
return this; |
49 |
|
|
} |
50 |
|
|
|
51 |
|
|
MenuList *MenuList::Left() |
52 |
|
|
{ |
53 |
douglas |
47 |
MenuList *parent(this->parent); |
54 |
|
|
|
55 |
|
|
if (parent != this) |
56 |
|
|
{ |
57 |
|
|
this->parent = NULL; |
58 |
|
|
|
59 |
|
|
delete this; |
60 |
|
|
} |
61 |
|
|
|
62 |
douglas |
42 |
return parent; |
63 |
|
|
} |
64 |
|
|
|
65 |
|
|
void MenuList::Render() |
66 |
|
|
{ |
67 |
douglas |
44 |
display.SetCursorPosition(19, cursor); |
68 |
|
|
|
69 |
douglas |
46 |
size_t size(list.size()); |
70 |
|
|
|
71 |
douglas |
42 |
if (this != previous || state != old) |
72 |
|
|
{ |
73 |
douglas |
46 |
display.Set(0, 0, (state.top != 0 ? '\x1a' : ' ')); |
74 |
douglas |
44 |
display.Set(0, 1, '\x12'); |
75 |
|
|
display.Set(0, 2, '\x13'); |
76 |
douglas |
46 |
display.Set(0, 3, (state.bottom < size ? '\x1b' : ' ')); |
77 |
douglas |
42 |
|
78 |
douglas |
46 |
_forall (size_t, index, state.top, state.bottom) |
79 |
|
|
if (index < size) |
80 |
|
|
{ |
81 |
|
|
MenuItem *item(list[index]); |
82 |
|
|
std::string value(*item); |
83 |
douglas |
42 |
|
84 |
douglas |
46 |
value.resize(18, ' '); |
85 |
douglas |
42 |
|
86 |
douglas |
46 |
if (BoolItem *item_ = dynamic_cast<BoolItem *>(item)) |
87 |
|
|
value += (*item_ ? '\x94' : '\xcf'); |
88 |
|
|
else if (dynamic_cast<SubItem *>(item)) |
89 |
|
|
value += '\x10'; |
90 |
|
|
else |
91 |
|
|
value += ' '; |
92 |
|
|
|
93 |
|
|
display.Set(1, _index, value); |
94 |
|
|
} |
95 |
douglas |
42 |
else |
96 |
douglas |
47 |
display.Set(1, _index, std::string(19, ' ')); |
97 |
douglas |
42 |
} |
98 |
|
|
else |
99 |
douglas |
46 |
_forall (size_t, index, state.top, size < state.bottom ? size : state.bottom) |
100 |
douglas |
42 |
if (BoolItem *item = dynamic_cast<BoolItem *>(list[index])) |
101 |
|
|
display.Set(19, _index, (*item ? _B("\x94") : _B("\xcf"))); |
102 |
|
|
} |
103 |
|
|
|
104 |
|
|
MenuList &MenuList::operator ++() |
105 |
|
|
{ |
106 |
douglas |
44 |
old = state; |
107 |
|
|
|
108 |
douglas |
42 |
size_t next(state.item + 1); |
109 |
|
|
|
110 |
|
|
if (next != list.size()) |
111 |
|
|
{ |
112 |
|
|
if (next == state.bottom) |
113 |
|
|
++state.top, ++state.bottom; |
114 |
|
|
else |
115 |
douglas |
44 |
++cursor; |
116 |
douglas |
42 |
|
117 |
|
|
state.item = next; |
118 |
|
|
} |
119 |
|
|
|
120 |
|
|
return *this; |
121 |
|
|
} |
122 |
|
|
|
123 |
|
|
MenuList &MenuList::operator --() |
124 |
|
|
{ |
125 |
douglas |
44 |
old = state; |
126 |
|
|
|
127 |
douglas |
42 |
if (state.item != 0) |
128 |
|
|
if (state.item-- == state.top) |
129 |
|
|
--state.top, --state.bottom; |
130 |
|
|
else |
131 |
douglas |
44 |
--cursor; |
132 |
douglas |
42 |
|
133 |
|
|
return *this; |
134 |
|
|
} |
135 |
|
|
|
136 |
|
|
TopList::AppendItem::AppendItem(MenuList *list, bool &append) : MenuItem(list), append(append) |
137 |
|
|
{ |
138 |
|
|
} |
139 |
|
|
|
140 |
|
|
MenuList *TopList::AppendItem::Select() |
141 |
|
|
{ |
142 |
|
|
append = !append; |
143 |
|
|
|
144 |
|
|
return list; |
145 |
|
|
} |
146 |
|
|
|
147 |
|
|
TopList::AppendItem::operator std::string() const |
148 |
|
|
{ |
149 |
douglas |
46 |
return _B("Playlist Append"); |
150 |
douglas |
42 |
} |
151 |
|
|
|
152 |
|
|
TopList::AppendItem::operator bool() const |
153 |
|
|
{ |
154 |
|
|
return append; |
155 |
|
|
} |
156 |
|
|
|
157 |
|
|
TopList::ShuffleItem::ShuffleItem(MenuList *list, Audacious::Audacious &audacious) : MenuItem(list), audacious(audacious) |
158 |
|
|
{ |
159 |
|
|
} |
160 |
|
|
|
161 |
|
|
MenuList *TopList::ShuffleItem::Select() |
162 |
|
|
{ |
163 |
|
|
if (audacious.IsRunning()) |
164 |
|
|
audacious.ToggleShuffle(); |
165 |
|
|
|
166 |
|
|
return list; |
167 |
|
|
} |
168 |
|
|
|
169 |
|
|
TopList::ShuffleItem::operator std::string() const |
170 |
|
|
{ |
171 |
|
|
return _B("Shuffle"); |
172 |
|
|
} |
173 |
|
|
|
174 |
|
|
TopList::ShuffleItem::operator bool() const |
175 |
|
|
{ |
176 |
|
|
return audacious.IsRunning() ? audacious.IsShuffle() : false; |
177 |
|
|
} |
178 |
|
|
|
179 |
douglas |
47 |
TopList::MusicItem::MusicItem(MenuList *list, Audacious::Audacious &audacious, bool &append, MusicLibrary::Library &library) : MenuItem(list), audacious(audacious), append(append), library(library) |
180 |
douglas |
43 |
{ |
181 |
|
|
} |
182 |
|
|
|
183 |
|
|
MenuList *TopList::MusicItem::Select() |
184 |
|
|
{ |
185 |
douglas |
47 |
return new ArtistList(list, audacious, append, library); |
186 |
douglas |
43 |
} |
187 |
|
|
|
188 |
|
|
TopList::MusicItem::operator std::string() const |
189 |
|
|
{ |
190 |
|
|
return _B("Music"); |
191 |
|
|
} |
192 |
|
|
|
193 |
douglas |
47 |
TopList::TopList(Display &display, Audacious::Audacious &audacious, bool &append, MusicLibrary::Library &library) : MenuList(this, display, 3) |
194 |
douglas |
42 |
{ |
195 |
|
|
previous = NULL; |
196 |
|
|
list[0] = new AppendItem(this, append); |
197 |
|
|
list[1] = new ShuffleItem(this, audacious); |
198 |
douglas |
47 |
list[2] = new MusicItem(this, audacious, append, library); |
199 |
douglas |
42 |
} |
200 |
douglas |
47 |
|
201 |
|
|
ArtistList::ArtistList(MenuList *parent, Audacious::Audacious &audacious, bool &append, MusicLibrary::Library &library) : MenuList(parent) |
202 |
|
|
{ |
203 |
|
|
list[0] = new AllItem(this, audacious, append, library); |
204 |
|
|
} |
205 |
|
|
|
206 |
|
|
ArtistList::AllItem::AllItem(MenuList *list, Audacious::Audacious &audacious, bool &append, MusicLibrary::Library &library) : MenuItem(list), audacious(audacious), append(append), library(library) |
207 |
|
|
{ |
208 |
|
|
} |
209 |
|
|
|
210 |
|
|
MenuList *ArtistList::AllItem::Select() |
211 |
|
|
{ |
212 |
|
|
std::cerr << _B("All Artists!") << std::endl; |
213 |
|
|
|
214 |
|
|
return list; |
215 |
|
|
} |
216 |
|
|
|
217 |
|
|
ArtistList::AllItem::operator std::string() const |
218 |
|
|
{ |
219 |
|
|
return _B("All Artists"); |
220 |
|
|
} |