ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/truck/DashInterface/MenuList.cpp
Revision: 46
Committed: 2008-03-06T19:47:57-08:00 (14 years, 6 months ago) by douglas
File size: 3594 byte(s)
Log Message:
Woo, actually tested that! Note to self: this is why you test early and often, but you knew that already.

File Contents

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

Properties

Name Value
svn:keywords Id