| 808 |
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);
|
|
|
42 |
rendertext(framebuf, 299, 229, 320, 0xffffcccc, 0, buf);
|
|
|
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, 80), LIBUI_POINT(0, 0)),
|
|
|
51 |
LIBUI_POINT(80, 80)),
|
|
|
52 |
.icon_selected = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 80), LIBUI_POINT(0, 0)),
|
|
|
53 |
LIBUI_POINT(80, 80)),
|
|
|
54 |
.text = "Power off",
|
|
|
55 |
.text_color = 0xffffcccc,
|
| 823 |
theseven |
56 |
.render = NULL
|
| 808 |
theseven |
57 |
};
|
|
|
58 |
|
|
|
59 |
static struct chooser_renderer_iconflow_itemdata mainchooser_rparams_rockbox =
|
|
|
60 |
{
|
|
|
61 |
.icon = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 80), LIBUI_POINT(0, 80)),
|
|
|
62 |
LIBUI_POINT(80, 80)),
|
|
|
63 |
.icon_selected = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 80), LIBUI_POINT(0, 80)),
|
|
|
64 |
LIBUI_POINT(80, 80)),
|
|
|
65 |
.text = "Rockbox",
|
|
|
66 |
.text_color = 0xffffcccc,
|
| 823 |
theseven |
67 |
.render = NULL
|
| 808 |
theseven |
68 |
};
|
|
|
69 |
|
|
|
70 |
static struct chooser_renderer_iconflow_itemdata mainchooser_rparams_console =
|
|
|
71 |
{
|
|
|
72 |
.icon = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 80), LIBUI_POINT(0, 160)),
|
|
|
73 |
LIBUI_POINT(80, 80)),
|
|
|
74 |
.icon_selected = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 80), LIBUI_POINT(0, 160)),
|
|
|
75 |
LIBUI_POINT(80, 80)),
|
|
|
76 |
.text = "emCORE console",
|
|
|
77 |
.text_color = 0xffffcccc,
|
| 823 |
theseven |
78 |
.render = NULL
|
| 808 |
theseven |
79 |
};
|
|
|
80 |
|
|
|
81 |
static struct chooser_renderer_iconflow_itemdata mainchooser_rparams_toolchooser =
|
|
|
82 |
{
|
|
|
83 |
.icon = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 80), LIBUI_POINT(0, 240)),
|
|
|
84 |
LIBUI_POINT(80, 80)),
|
|
|
85 |
.icon_selected = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 80), LIBUI_POINT(0, 240)),
|
|
|
86 |
LIBUI_POINT(80, 80)),
|
|
|
87 |
.text = "Tools",
|
|
|
88 |
.text_color = 0xffffcccc,
|
| 823 |
theseven |
89 |
.render = NULL
|
| 808 |
theseven |
90 |
};
|
|
|
91 |
|
|
|
92 |
static struct chooser_renderer_iconflow_params mainchooser_rparams =
|
|
|
93 |
{
|
|
|
94 |
.version = CHOOSER_RENDERER_ICONFLOW_PARAMS_VERSION,
|
|
|
95 |
.copy_dest = LIBUI_LOCATION(LIBUI_BUFFER(NULL, 320), LIBUI_POINT(0, 0)),
|
|
|
96 |
.copy_src = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 320), LIBUI_POINT(0, 0)),
|
|
|
97 |
LIBUI_POINT(320, 240)),
|
| 823 |
theseven |
98 |
.bg_dest = LIBUI_LOCATION_NULL,
|
|
|
99 |
.bg_src = LIBUI_SURFACE_NULL,
|
| 808 |
theseven |
100 |
.bg_opacity = 0,
|
| 823 |
theseven |
101 |
.fill_dest = LIBUI_SURFACE_NULL,
|
| 808 |
theseven |
102 |
.fill_color = 0,
|
|
|
103 |
.viewport = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 320), LIBUI_POINT(0, 30)),
|
|
|
104 |
LIBUI_POINT(320, 130)),
|
|
|
105 |
.text_pos = LIBUI_POINT(160, 215),
|
|
|
106 |
.blit_dest = LIBUI_POINT(0, 0),
|
|
|
107 |
.blit_src = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 320), LIBUI_POINT(0, 0)),
|
|
|
108 |
LIBUI_POINT(320, 240)),
|
|
|
109 |
.smoothness = 500000,
|
|
|
110 |
.startposition = -3,
|
|
|
111 |
.iconsinview = 4,
|
|
|
112 |
.preblit = mainchooser_preblit,
|
|
|
113 |
.postblit = NULL
|
|
|
114 |
};
|
|
|
115 |
|
|
|
116 |
static struct chooser_action_handler_wheel_params mainchooser_aparams =
|
|
|
117 |
{
|
|
|
118 |
.version = CHOOSER_ACTION_HANDLER_WHEEL_PARAMS_VERSION,
|
|
|
119 |
.stepsperitem = 512,
|
|
|
120 |
.eventfilter = NULL,
|
|
|
121 |
.timeout_initial = 0,
|
|
|
122 |
.timeout_idle = 0,
|
|
|
123 |
.timeout_item = CHOOSER_ACTION_HANDLER_WHEEL_TIMEOUT_ITEM_NULL,
|
|
|
124 |
.tick_force_redraw = true,
|
|
|
125 |
.buttoncount = 3,
|
|
|
126 |
.buttonmap =
|
|
|
127 |
{
|
|
|
128 |
CHOOSER_ACTION_HANDLER_WHEEL_ACTION_SELECT,
|
|
|
129 |
CHOOSER_ACTION_HANDLER_WHEEL_ACTION_NEXT,
|
|
|
130 |
CHOOSER_ACTION_HANDLER_WHEEL_ACTION_PREV
|
|
|
131 |
}
|
|
|
132 |
};
|
|
|
133 |
|
|
|
134 |
static struct chooser_info mainchooser =
|
|
|
135 |
{
|
|
|
136 |
.version = CHOOSER_INFO_VERSION,
|
|
|
137 |
.actionhandler = NULL,
|
|
|
138 |
.actionhandlerparams = &mainchooser_aparams,
|
|
|
139 |
.renderer = NULL,
|
|
|
140 |
.rendererparams = &mainchooser_rparams,
|
|
|
141 |
.userparams = NULL,
|
|
|
142 |
.tickinterval = 990000,
|
|
|
143 |
.itemcount = 4,
|
|
|
144 |
.defaultitem = 0,
|
|
|
145 |
.items =
|
|
|
146 |
{
|
|
|
147 |
{
|
|
|
148 |
.user = run_powerdown,
|
|
|
149 |
.actionparams = NULL,
|
|
|
150 |
.renderparams = &mainchooser_rparams_powerdown
|
|
|
151 |
},
|
|
|
152 |
{
|
|
|
153 |
.user = run_rockbox,
|
|
|
154 |
.actionparams = NULL,
|
|
|
155 |
.renderparams = &mainchooser_rparams_rockbox
|
|
|
156 |
},
|
|
|
157 |
{
|
|
|
158 |
.user = NULL,
|
|
|
159 |
.actionparams = NULL,
|
|
|
160 |
.renderparams = &mainchooser_rparams_console
|
|
|
161 |
},
|
|
|
162 |
{
|
|
|
163 |
.user = run_toolchooser,
|
|
|
164 |
.actionparams = NULL,
|
|
|
165 |
.renderparams = &mainchooser_rparams_toolchooser
|
|
|
166 |
}
|
|
|
167 |
}
|
|
|
168 |
};
|
|
|
169 |
|
|
|
170 |
void run_mainchooser(void** firmware, void** app, int* size)
|
|
|
171 |
{
|
|
|
172 |
while (!*firmware && !*app)
|
|
|
173 |
{
|
|
|
174 |
const struct chooser_item* result = ui->chooser_run(&mainchooser);
|
|
|
175 |
if (!result)
|
|
|
176 |
switch(settings.timeout_item)
|
|
|
177 |
{
|
|
|
178 |
case 0:
|
|
|
179 |
run_powerdown(firmware, app, size);
|
|
|
180 |
break;
|
|
|
181 |
|
|
|
182 |
case 1:
|
|
|
183 |
run_rockbox(firmware, app, size);
|
|
|
184 |
break;
|
|
|
185 |
|
|
|
186 |
case 2:
|
|
|
187 |
run_umsboot(firmware, app, size);
|
|
|
188 |
break;
|
|
|
189 |
|
|
|
190 |
case 3:
|
|
|
191 |
return;
|
|
|
192 |
}
|
|
|
193 |
if (!result->user) return;
|
|
|
194 |
void (*selected_function)(void** firmware, void** app, int* size);
|
|
|
195 |
selected_function = (void(*)(void** firmware, void** app, int* size))(result->user);
|
|
|
196 |
selected_function(firmware, app, size);
|
|
|
197 |
}
|
|
|
198 |
}
|
|
|
199 |
|
|
|
200 |
void mainchooser_init()
|
|
|
201 |
{
|
|
|
202 |
mainchooser.actionhandler = ui->chooser_action_handler_wheel;
|
|
|
203 |
mainchooser.renderer = ui->chooser_renderer_iconflow;
|
|
|
204 |
mainchooser_rparams.copy_dest.buf.addr = framebuf;
|
|
|
205 |
mainchooser_rparams.copy_src.loc.buf.addr = bg;
|
|
|
206 |
mainchooser_rparams.viewport.loc.buf.addr = framebuf;
|
|
|
207 |
mainchooser_rparams.blit_src.loc.buf.addr = framebuf;
|
|
|
208 |
mainchooser_rparams_powerdown.icon.loc.buf.addr = icons;
|
|
|
209 |
mainchooser_rparams_powerdown.icon_selected.loc.buf.addr = icons;
|
|
|
210 |
mainchooser_rparams_rockbox.icon.loc.buf.addr = icons;
|
|
|
211 |
mainchooser_rparams_rockbox.icon_selected.loc.buf.addr = icons;
|
|
|
212 |
mainchooser_rparams_console.icon.loc.buf.addr = icons;
|
|
|
213 |
mainchooser_rparams_console.icon_selected.loc.buf.addr = icons;
|
|
|
214 |
mainchooser_rparams_toolchooser.icon.loc.buf.addr = icons;
|
|
|
215 |
mainchooser_rparams_toolchooser.icon_selected.loc.buf.addr = icons;
|
|
|
216 |
}
|
|
|
217 |
|
|
|
218 |
void mainchooser_apply_settings()
|
|
|
219 |
{
|
|
|
220 |
mainchooser.defaultitem = settings.default_item;
|
| 823 |
theseven |
221 |
if (settings.timeout_initial < SETTINGS_TIMEOUT_CUTOFF)
|
|
|
222 |
mainchooser_aparams.timeout_initial = TIMEOUT_BLOCK;
|
| 808 |
theseven |
223 |
else mainchooser_aparams.timeout_initial = settings.timeout_initial + 500000;
|
| 823 |
theseven |
224 |
if (settings.timeout_idle < SETTINGS_TIMEOUT_CUTOFF)
|
|
|
225 |
mainchooser_aparams.timeout_idle = TIMEOUT_BLOCK;
|
| 808 |
theseven |
226 |
else mainchooser_aparams.timeout_idle = settings.timeout_idle + 500000;
|
|
|
227 |
}
|