ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/truck/DashInterface/MenuList.cpp
Revision: 51
Committed: 2008-03-09T14:24:55-07:00 (17 years, 3 months ago) by douglas
File size: 4652 byte(s)
Log Message:
Finish the renaming!

File Contents

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

Properties

Name Value
svn:keywords Id