| 828 |
theseven |
1 |
//
|
|
|
2 |
//
|
|
|
3 |
// Copyright 2011 TheSeven
|
|
|
4 |
//
|
|
|
5 |
//
|
|
|
6 |
// This file is part of emCORE.
|
|
|
7 |
//
|
|
|
8 |
// emCORE is free software: you can redistribute it and/or
|
|
|
9 |
// modify it under the terms of the GNU General Public License as
|
|
|
10 |
// published by the Free Software Foundation, either version 2 of the
|
|
|
11 |
// License, or (at your option) any later version.
|
|
|
12 |
//
|
|
|
13 |
// emCORE is distributed in the hope that it will be useful,
|
|
|
14 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
15 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
16 |
// See the GNU General Public License for more details.
|
|
|
17 |
//
|
|
|
18 |
// You should have received a copy of the GNU General Public License along
|
|
|
19 |
// with emCORE. If not, see <http://www.gnu.org/licenses/>.
|
|
|
20 |
//
|
|
|
21 |
//
|
|
|
22 |
|
|
|
23 |
|
|
|
24 |
#include "emcoreapp.h"
|
|
|
25 |
#include "libui.h"
|
|
|
26 |
#include "mainchooser.h"
|
|
|
27 |
#include "toolchooser.h"
|
|
|
28 |
#include "settings.h"
|
|
|
29 |
#include "util.h"
|
|
|
30 |
#include "main.h"
|
|
|
31 |
#include "boot.h"
|
|
|
32 |
|
|
|
33 |
|
|
|
34 |
static bool mainchooser_preblit(struct chooser_data* data)
|
|
|
35 |
{
|
|
|
36 |
char buf[4];
|
|
|
37 |
struct chooser_action_handler_wheel_data* adata;
|
|
|
38 |
adata = (struct chooser_action_handler_wheel_data*)(data->actionhandlerdata);
|
|
|
39 |
if (adata->timeout_remaining != TIMEOUT_BLOCK)
|
|
|
40 |
{
|
|
|
41 |
snprintf(buf, sizeof(buf), "%3d", adata->timeout_remaining / 1000000);
|
| 838 |
theseven |
42 |
rendertext(framebuf, 155, 121, 176, 0xcf7f0000, 0, buf);
|
| 828 |
theseven |
43 |
}
|
|
|
44 |
update_display(data);
|
|
|
45 |
return false;
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
static struct chooser_renderer_iconflow_itemdata mainchooser_rparams_powerdown =
|
|
|
49 |
{
|
|
|
50 |
.icon = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 44), LIBUI_POINT(0, 0)),
|
|
|
51 |
LIBUI_POINT(44, 44)),
|
|
|
52 |
.icon_selected = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 44), LIBUI_POINT(0, 0)),
|
|
|
53 |
LIBUI_POINT(44, 44)),
|
|
|
54 |
.text = "Power off",
|
|
|
55 |
.text_color = 0xffffcccc,
|
| 838 |
theseven |
56 |
.text_bgcolor = 0x7f000000,
|
| 828 |
theseven |
57 |
.render = NULL
|
|
|
58 |
};
|
|
|
59 |
|
|
|
60 |
struct chooser_renderer_iconflow_itemdata mainchooser_rparams_crapple =
|
|
|
61 |
{
|
|
|
62 |
.icon = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 44), LIBUI_POINT(0, 44)),
|
|
|
63 |
LIBUI_POINT(44, 44)),
|
|
|
64 |
.icon_selected = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 44), LIBUI_POINT(0, 44)),
|
|
|
65 |
LIBUI_POINT(44, 44)),
|
|
|
66 |
.text = "Original firmware",
|
|
|
67 |
.text_color = 0xffffcccc,
|
| 838 |
theseven |
68 |
.text_bgcolor = 0x7f000000,
|
| 828 |
theseven |
69 |
.render = NULL
|
|
|
70 |
};
|
|
|
71 |
|
|
|
72 |
static struct chooser_renderer_iconflow_itemdata mainchooser_rparams_rockbox =
|
|
|
73 |
{
|
|
|
74 |
.icon = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 44), LIBUI_POINT(0, 88)),
|
|
|
75 |
LIBUI_POINT(44, 44)),
|
|
|
76 |
.icon_selected = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 44), LIBUI_POINT(0, 88)),
|
|
|
77 |
LIBUI_POINT(44, 44)),
|
|
|
78 |
.text = "Rockbox",
|
|
|
79 |
.text_color = 0xffffcccc,
|
| 838 |
theseven |
80 |
.text_bgcolor = 0x7f000000,
|
| 828 |
theseven |
81 |
.render = NULL
|
|
|
82 |
};
|
|
|
83 |
|
|
|
84 |
struct chooser_renderer_iconflow_itemdata mainchooser_rparams_diskmode =
|
|
|
85 |
{
|
|
|
86 |
.icon = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 44), LIBUI_POINT(0, 132)),
|
|
|
87 |
LIBUI_POINT(44, 44)),
|
|
|
88 |
.icon_selected = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 44), LIBUI_POINT(0, 132)),
|
|
|
89 |
LIBUI_POINT(44, 44)),
|
|
|
90 |
.text = "Disk mode",
|
|
|
91 |
.text_color = 0xffffcccc,
|
| 838 |
theseven |
92 |
.text_bgcolor = 0x7f000000,
|
| 828 |
theseven |
93 |
.render = NULL
|
|
|
94 |
};
|
|
|
95 |
|
|
|
96 |
static struct chooser_renderer_iconflow_itemdata mainchooser_rparams_console =
|
|
|
97 |
{
|
|
|
98 |
.icon = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 44), LIBUI_POINT(0, 176)),
|
|
|
99 |
LIBUI_POINT(44, 44)),
|
|
|
100 |
.icon_selected = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 44), LIBUI_POINT(0, 176)),
|
|
|
101 |
LIBUI_POINT(44, 44)),
|
|
|
102 |
.text = "emCORE console",
|
|
|
103 |
.text_color = 0xffffcccc,
|
| 838 |
theseven |
104 |
.text_bgcolor = 0x7f000000,
|
| 828 |
theseven |
105 |
.render = NULL
|
|
|
106 |
};
|
|
|
107 |
|
|
|
108 |
static struct chooser_renderer_iconflow_itemdata mainchooser_rparams_toolchooser =
|
|
|
109 |
{
|
|
|
110 |
.icon = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 44), LIBUI_POINT(0, 220)),
|
|
|
111 |
LIBUI_POINT(44, 44)),
|
|
|
112 |
.icon_selected = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 44), LIBUI_POINT(0, 220)),
|
|
|
113 |
LIBUI_POINT(44, 44)),
|
|
|
114 |
.text = "Tools",
|
|
|
115 |
.text_color = 0xffffcccc,
|
| 838 |
theseven |
116 |
.text_bgcolor = 0x7f000000,
|
| 828 |
theseven |
117 |
.render = NULL
|
|
|
118 |
};
|
|
|
119 |
|
|
|
120 |
static struct chooser_renderer_iconflow_params mainchooser_rparams =
|
|
|
121 |
{
|
|
|
122 |
.version = CHOOSER_RENDERER_ICONFLOW_PARAMS_VERSION,
|
|
|
123 |
.copy_dest = LIBUI_LOCATION(LIBUI_BUFFER(NULL, 176), LIBUI_POINT(0, 0)),
|
|
|
124 |
.copy_src = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 176), LIBUI_POINT(0, 0)),
|
|
|
125 |
LIBUI_POINT(176, 132)),
|
|
|
126 |
.bg_dest = LIBUI_LOCATION_NULL,
|
|
|
127 |
.bg_src = LIBUI_SURFACE_NULL,
|
|
|
128 |
.bg_opacity = 0,
|
|
|
129 |
.fill_dest = LIBUI_SURFACE_NULL,
|
|
|
130 |
.fill_color = 0,
|
|
|
131 |
.viewport = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 176), LIBUI_POINT(0, 16)),
|
|
|
132 |
LIBUI_POINT(176, 72)),
|
|
|
133 |
.text_pos = LIBUI_POINT(88, 118),
|
|
|
134 |
.blit_dest = LIBUI_POINT(0, 0),
|
|
|
135 |
.blit_src = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 176), LIBUI_POINT(0, 0)),
|
|
|
136 |
LIBUI_POINT(176, 132)),
|
|
|
137 |
.smoothness = 500000,
|
|
|
138 |
.startposition = -3,
|
|
|
139 |
.iconsinview = 4,
|
|
|
140 |
.preblit = mainchooser_preblit,
|
|
|
141 |
.postblit = NULL
|
|
|
142 |
};
|
|
|
143 |
|
|
|
144 |
static struct chooser_action_handler_wheel_params mainchooser_aparams =
|
|
|
145 |
{
|
|
|
146 |
.version = CHOOSER_ACTION_HANDLER_WHEEL_PARAMS_VERSION,
|
|
|
147 |
.stepsperitem = 512,
|
|
|
148 |
.eventfilter = NULL,
|
|
|
149 |
.timeout_initial = 0,
|
|
|
150 |
.timeout_idle = 0,
|
|
|
151 |
.timeout_item = CHOOSER_ACTION_HANDLER_WHEEL_TIMEOUT_ITEM_NULL,
|
|
|
152 |
.tick_force_redraw = true,
|
|
|
153 |
.buttoncount = 3,
|
|
|
154 |
.buttonmap =
|
|
|
155 |
{
|
|
|
156 |
CHOOSER_ACTION_HANDLER_WHEEL_ACTION_SELECT,
|
|
|
157 |
CHOOSER_ACTION_HANDLER_WHEEL_ACTION_NEXT,
|
|
|
158 |
CHOOSER_ACTION_HANDLER_WHEEL_ACTION_PREV
|
|
|
159 |
}
|
|
|
160 |
};
|
|
|
161 |
|
|
|
162 |
static struct chooser_info mainchooser =
|
|
|
163 |
{
|
|
|
164 |
.version = CHOOSER_INFO_VERSION,
|
|
|
165 |
.actionhandler = NULL,
|
|
|
166 |
.actionhandlerparams = &mainchooser_aparams,
|
|
|
167 |
.renderer = NULL,
|
|
|
168 |
.rendererparams = &mainchooser_rparams,
|
|
|
169 |
.userparams = NULL,
|
|
|
170 |
.tickinterval = 990000,
|
|
|
171 |
.itemcount = 6,
|
|
|
172 |
.defaultitem = 0,
|
|
|
173 |
.items =
|
|
|
174 |
{
|
|
|
175 |
{
|
|
|
176 |
.user = run_powerdown,
|
|
|
177 |
.actionparams = NULL,
|
|
|
178 |
.renderparams = &mainchooser_rparams_powerdown
|
|
|
179 |
},
|
|
|
180 |
{
|
|
|
181 |
.user = run_crapple,
|
|
|
182 |
.actionparams = NULL,
|
|
|
183 |
.renderparams = &mainchooser_rparams_crapple
|
|
|
184 |
},
|
|
|
185 |
{
|
|
|
186 |
.user = run_rockbox,
|
|
|
187 |
.actionparams = NULL,
|
|
|
188 |
.renderparams = &mainchooser_rparams_rockbox
|
|
|
189 |
},
|
|
|
190 |
{
|
|
|
191 |
.user = run_diskmode,
|
|
|
192 |
.actionparams = NULL,
|
|
|
193 |
.renderparams = &mainchooser_rparams_diskmode
|
|
|
194 |
},
|
|
|
195 |
{
|
|
|
196 |
.user = NULL,
|
|
|
197 |
.actionparams = NULL,
|
|
|
198 |
.renderparams = &mainchooser_rparams_console
|
|
|
199 |
},
|
|
|
200 |
{
|
|
|
201 |
.user = run_toolchooser,
|
|
|
202 |
.actionparams = NULL,
|
|
|
203 |
.renderparams = &mainchooser_rparams_toolchooser
|
|
|
204 |
}
|
|
|
205 |
}
|
|
|
206 |
};
|
|
|
207 |
|
| 838 |
theseven |
208 |
void run_mainchooser()
|
| 828 |
theseven |
209 |
{
|
| 838 |
theseven |
210 |
while (!bootinfo.valid)
|
| 828 |
theseven |
211 |
{
|
|
|
212 |
const struct chooser_item* result = ui->chooser_run(&mainchooser);
|
|
|
213 |
if (!result)
|
|
|
214 |
switch(settings.timeout_item)
|
|
|
215 |
{
|
|
|
216 |
case 0:
|
| 838 |
theseven |
217 |
run_powerdown();
|
| 828 |
theseven |
218 |
break;
|
|
|
219 |
|
|
|
220 |
case 1:
|
| 838 |
theseven |
221 |
run_crapple();
|
| 828 |
theseven |
222 |
break;
|
|
|
223 |
|
|
|
224 |
case 2:
|
| 838 |
theseven |
225 |
run_rockbox();
|
| 828 |
theseven |
226 |
break;
|
|
|
227 |
|
|
|
228 |
case 3:
|
| 838 |
theseven |
229 |
run_diskmode();
|
| 828 |
theseven |
230 |
break;
|
|
|
231 |
|
|
|
232 |
case 4:
|
| 838 |
theseven |
233 |
run_umsboot();
|
| 828 |
theseven |
234 |
break;
|
|
|
235 |
|
|
|
236 |
case 5:
|
|
|
237 |
return;
|
|
|
238 |
}
|
|
|
239 |
if (!result->user) return;
|
| 838 |
theseven |
240 |
((void(*)())(result->user))();
|
| 828 |
theseven |
241 |
}
|
|
|
242 |
}
|
|
|
243 |
|
|
|
244 |
void mainchooser_init()
|
|
|
245 |
{
|
|
|
246 |
mainchooser.actionhandler = ui->chooser_action_handler_wheel;
|
|
|
247 |
mainchooser.renderer = ui->chooser_renderer_iconflow;
|
|
|
248 |
mainchooser_rparams.copy_dest.buf.addr = framebuf;
|
|
|
249 |
mainchooser_rparams.copy_src.loc.buf.addr = bg;
|
|
|
250 |
mainchooser_rparams.viewport.loc.buf.addr = framebuf;
|
|
|
251 |
mainchooser_rparams.blit_src.loc.buf.addr = framebuf;
|
|
|
252 |
mainchooser_rparams_powerdown.icon.loc.buf.addr = icons;
|
|
|
253 |
mainchooser_rparams_powerdown.icon_selected.loc.buf.addr = icons;
|
|
|
254 |
mainchooser_rparams_crapple.icon.loc.buf.addr = icons;
|
|
|
255 |
mainchooser_rparams_crapple.icon_selected.loc.buf.addr = icons;
|
|
|
256 |
mainchooser_rparams_rockbox.icon.loc.buf.addr = icons;
|
|
|
257 |
mainchooser_rparams_rockbox.icon_selected.loc.buf.addr = icons;
|
|
|
258 |
mainchooser_rparams_console.icon.loc.buf.addr = icons;
|
|
|
259 |
mainchooser_rparams_console.icon_selected.loc.buf.addr = icons;
|
|
|
260 |
mainchooser_rparams_diskmode.icon.loc.buf.addr = icons;
|
|
|
261 |
mainchooser_rparams_diskmode.icon_selected.loc.buf.addr = icons;
|
|
|
262 |
mainchooser_rparams_toolchooser.icon.loc.buf.addr = icons;
|
|
|
263 |
mainchooser_rparams_toolchooser.icon_selected.loc.buf.addr = icons;
|
|
|
264 |
}
|
|
|
265 |
|
|
|
266 |
void mainchooser_apply_settings()
|
|
|
267 |
{
|
|
|
268 |
mainchooser.defaultitem = settings.default_item;
|
| 838 |
theseven |
269 |
if (settings.snow) mainchooser.tickinterval = 50000;
|
|
|
270 |
else mainchooser.tickinterval = 990000;
|
| 828 |
theseven |
271 |
if (settings.timeout_initial < SETTINGS_TIMEOUT_CUTOFF)
|
|
|
272 |
mainchooser_aparams.timeout_initial = TIMEOUT_BLOCK;
|
|
|
273 |
else mainchooser_aparams.timeout_initial = settings.timeout_initial + 500000;
|
|
|
274 |
if (settings.timeout_idle < SETTINGS_TIMEOUT_CUTOFF)
|
|
|
275 |
mainchooser_aparams.timeout_idle = TIMEOUT_BLOCK;
|
|
|
276 |
else mainchooser_aparams.timeout_idle = settings.timeout_idle + 500000;
|
|
|
277 |
}
|