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