ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/truck/DashInterface/MenuList.cpp
Revision: 43
Committed: 2008-03-06T13:34:03-08:00 (14 years, 7 months ago) by douglas
File size: 3431 byte(s)
Log Message:
The top menu should be complete, unless I add something else.

File Contents

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

Properties

Name Value
svn:keywords Id