ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/truck/DashInterface/MenuList.cpp
Revision: 45
Committed: 2008-03-06T18:12:54-08:00 (17 years, 3 months ago) by douglas
File size: 3223 byte(s)
Log Message:
Beginnings of an sqlite3 api ala Menes' dbi.

File Contents

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

Properties

Name Value
svn:keywords Id