Subversion Repositories freemyipod

Rev

Rev 838 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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 "toolchooser.h"
27
#include "boot.h"
28
#include "tools.h"
29
#include "main.h"
30
#include "util.h"
838 theseven 31
#include "settings.h"
828 theseven 32
#include "settingchooser.h"
33
 
34
 
35
static struct chooser_renderer_list_itemdata toolchooser_rparams_mainchooser =
36
{
37
    .size = LIBUI_POINT(164, 10),
38
    .fill_box = LIBUI_BOX(LIBUI_POINT(0, 0), LIBUI_POINT(164, 10)),
39
    .fill_color = 0xa0000000,
843 theseven 40
    .fill_color_selected = 0x60ffffff,
828 theseven 41
    .icon_pos = LIBUI_POINT_NULL,
42
    .icon = LIBUI_SURFACE_NULL,
43
    .icon_opacity = 0,
44
    .icon_selected = LIBUI_SURFACE_NULL,
45
    .icon_selected_opacity = 0,
46
    .text = "Return to main menu",
47
    .text_pos = LIBUI_POINT(1, 1),
48
    .text_color = 0xffffffff,
49
    .text_color_selected = 0xff7fffff,
50
    .render = NULL
51
};
52
 
53
static struct chooser_renderer_list_itemdata toolchooser_rparams_umsboot =
54
{
55
    .size = LIBUI_POINT(164, 10),
56
    .fill_box = LIBUI_BOX(LIBUI_POINT(0, 0), LIBUI_POINT(164, 10)),
57
    .fill_color = 0xa0000000,
843 theseven 58
    .fill_color_selected = 0x60ffffff,
828 theseven 59
    .icon_pos = LIBUI_POINT_NULL,
60
    .icon = LIBUI_SURFACE_NULL,
61
    .icon_opacity = 0,
62
    .icon_selected = LIBUI_SURFACE_NULL,
63
    .icon_selected_opacity = 0,
64
    .text = "Run UMSboot",
65
    .text_pos = LIBUI_POINT(1, 1),
66
    .text_color = 0xffffffff,
67
    .text_color_selected = 0xff7fffff,
68
    .render = NULL
69
};
70
 
71
struct chooser_renderer_list_itemdata toolchooser_rparams_diagmode =
72
{
73
    .size = LIBUI_POINT(164, 10),
74
    .fill_box = LIBUI_BOX(LIBUI_POINT(0, 0), LIBUI_POINT(164, 10)),
75
    .fill_color = 0xa0000000,
843 theseven 76
    .fill_color_selected = 0x60ffffff,
828 theseven 77
    .icon_pos = LIBUI_POINT_NULL,
78
    .icon = LIBUI_SURFACE_NULL,
79
    .icon_opacity = 0,
80
    .icon_selected = LIBUI_SURFACE_NULL,
81
    .icon_selected_opacity = 0,
82
    .text = "Run diagnostics mode",
83
    .text_pos = LIBUI_POINT(1, 1),
84
    .text_color = 0xffffffff,
85
    .text_color_selected = 0xff7fffff,
86
    .render = NULL
87
};
88
 
89
static struct chooser_renderer_list_itemdata toolchooser_rparams_rockbox_fallback =
90
{
91
    .size = LIBUI_POINT(164, 10),
92
    .fill_box = LIBUI_BOX(LIBUI_POINT(0, 0), LIBUI_POINT(164, 10)),
93
    .fill_color = 0xa0000000,
843 theseven 94
    .fill_color_selected = 0x60ffffff,
828 theseven 95
    .icon_pos = LIBUI_POINT_NULL,
96
    .icon = LIBUI_SURFACE_NULL,
97
    .icon_opacity = 0,
98
    .icon_selected = LIBUI_SURFACE_NULL,
99
    .icon_selected_opacity = 0,
100
    .text = "Run Rockbox fallback image",
101
    .text_pos = LIBUI_POINT(1, 1),
102
    .text_color = 0xffffffff,
103
    .text_color_selected = 0xff7fffff,
104
    .render = NULL
105
};
106
 
107
static struct chooser_renderer_list_itemdata toolchooser_rparams_clearcfg =
108
{
109
    .size = LIBUI_POINT(164, 10),
110
    .fill_box = LIBUI_BOX(LIBUI_POINT(0, 0), LIBUI_POINT(164, 10)),
111
    .fill_color = 0xa0000000,
843 theseven 112
    .fill_color_selected = 0x60ffffff,
828 theseven 113
    .icon_pos = LIBUI_POINT_NULL,
114
    .icon = LIBUI_SURFACE_NULL,
115
    .icon_opacity = 0,
116
    .icon_selected = LIBUI_SURFACE_NULL,
117
    .icon_selected_opacity = 0,
118
    .text = "Clear Rockbox configuration",
119
    .text_pos = LIBUI_POINT(1, 1),
120
    .text_color = 0xffffffff,
121
    .text_color_selected = 0xff7fffff,
122
    .render = NULL
123
};
124
 
125
static struct chooser_renderer_list_itemdata toolchooser_rparams_cleardb =
126
{
127
    .size = LIBUI_POINT(164, 10),
128
    .fill_box = LIBUI_BOX(LIBUI_POINT(0, 0), LIBUI_POINT(164, 10)),
129
    .fill_color = 0xa0000000,
843 theseven 130
    .fill_color_selected = 0x60ffffff,
828 theseven 131
    .icon_pos = LIBUI_POINT_NULL,
132
    .icon = LIBUI_SURFACE_NULL,
133
    .icon_opacity = 0,
134
    .icon_selected = LIBUI_SURFACE_NULL,
135
    .icon_selected_opacity = 0,
136
    .text = "Clear Rockbox database",
137
    .text_pos = LIBUI_POINT(1, 1),
138
    .text_color = 0xffffffff,
139
    .text_color_selected = 0xff7fffff,
140
    .render = NULL
141
};
142
 
143
static struct chooser_renderer_list_itemdata toolchooser_rparams_reformat =
144
{
145
    .size = LIBUI_POINT(164, 10),
146
    .fill_box = LIBUI_BOX(LIBUI_POINT(0, 0), LIBUI_POINT(164, 10)),
147
    .fill_color = 0xa0000000,
843 theseven 148
    .fill_color_selected = 0x60ffffff,
828 theseven 149
    .icon_pos = LIBUI_POINT_NULL,
150
    .icon = LIBUI_SURFACE_NULL,
151
    .icon_opacity = 0,
152
    .icon_selected = LIBUI_SURFACE_NULL,
153
    .icon_selected_opacity = 0,
154
    .text = "Reformat data partition",
155
    .text_pos = LIBUI_POINT(1, 1),
156
    .text_color = 0xffffffff,
157
    .text_color_selected = 0xff7fffff,
158
    .render = NULL
159
};
160
 
161
struct chooser_renderer_list_itemdata toolchooser_rparams_uninstaller =
162
{
163
    .size = LIBUI_POINT(164, 10),
164
    .fill_box = LIBUI_BOX(LIBUI_POINT(0, 0), LIBUI_POINT(164, 10)),
165
    .fill_color = 0xa0000000,
843 theseven 166
    .fill_color_selected = 0x60ffffff,
828 theseven 167
    .icon_pos = LIBUI_POINT_NULL,
168
    .icon = LIBUI_SURFACE_NULL,
169
    .icon_opacity = 0,
170
    .icon_selected = LIBUI_SURFACE_NULL,
171
    .icon_selected_opacity = 0,
172
    .text = "Uninstall emCORE",
173
    .text_pos = LIBUI_POINT(1, 1),
174
    .text_color = 0xffffffff,
175
    .text_color_selected = 0xff7fffff,
176
    .render = NULL
177
};
178
static struct chooser_renderer_list_itemdata toolchooser_rparams_settingchooser =
179
{
180
    .size = LIBUI_POINT(164, 10),
181
    .fill_box = LIBUI_BOX(LIBUI_POINT(0, 0), LIBUI_POINT(164, 10)),
182
    .fill_color = 0xa0000000,
843 theseven 183
    .fill_color_selected = 0x60ffffff,
828 theseven 184
    .icon_pos = LIBUI_POINT_NULL,
185
    .icon = LIBUI_SURFACE_NULL,
186
    .icon_opacity = 0,
187
    .icon_selected = LIBUI_SURFACE_NULL,
188
    .icon_selected_opacity = 0,
189
    .text = "Settings",
190
    .text_pos = LIBUI_POINT(1, 1),
191
    .text_color = 0xffffffff,
192
    .text_color_selected = 0xff7fffff,
193
    .render = NULL
194
};
195
 
196
 
197
static struct chooser_renderer_list_params toolchooser_rparams =
198
{
199
    .version = CHOOSER_RENDERER_LIST_PARAMS_VERSION,
200
    .copy_dest = LIBUI_LOCATION(LIBUI_BUFFER(NULL, 176), LIBUI_POINT(0, 0)),
201
    .copy_src = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 176), LIBUI_POINT(0, 0)),
202
                              LIBUI_POINT(176, 132)),
203
    .bg_dest = LIBUI_LOCATION_NULL,
204
    .bg_src = LIBUI_SURFACE_NULL,
205
    .bg_opacity = 0,
206
    .fill_dest = LIBUI_SURFACE_NULL,
207
    .fill_color = 0,
208
    .viewport = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 176), LIBUI_POINT(6, 30)),
209
                              LIBUI_POINT(164, 90)),
210
    .blit_dest = LIBUI_POINT(0, 0),
211
    .blit_src = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 176), LIBUI_POINT(0, 0)),
212
                              LIBUI_POINT(176, 132)),
213
    .preblit = update_display,
214
    .postblit = NULL
215
};
216
 
217
static struct chooser_action_handler_wheel_params toolchooser_aparams =
218
{
219
    .version = CHOOSER_ACTION_HANDLER_WHEEL_PARAMS_VERSION,
220
    .stepsperitem = 128,
221
    .eventfilter = NULL,
222
    .timeout_initial = TIMEOUT_BLOCK,
223
    .timeout_idle = TIMEOUT_BLOCK,
224
    .timeout_item = 0,
225
    .tick_force_redraw = true,
226
    .buttoncount = 5,
227
    .buttonmap =
228
    {
229
        CHOOSER_ACTION_HANDLER_WHEEL_ACTION_SELECT,
230
        CHOOSER_ACTION_HANDLER_WHEEL_ACTION_SELECT,
231
        CHOOSER_ACTION_HANDLER_WHEEL_ACTION_CANCEL,
232
        CHOOSER_ACTION_HANDLER_WHEEL_ACTION_NEXT,
233
        CHOOSER_ACTION_HANDLER_WHEEL_ACTION_PREV
234
    }
235
};
236
 
237
static struct chooser_info toolchooser =
238
{
239
    .version = CHOOSER_INFO_VERSION,
240
    .actionhandler = NULL,
241
    .actionhandlerparams = &toolchooser_aparams,
242
    .renderer = NULL,
243
    .rendererparams = &toolchooser_rparams,
244
    .userparams = NULL,
245
    .tickinterval = 10000000,
246
    .itemcount = 9,
247
    .defaultitem = 0,
248
    .items =
249
    {
250
        {
251
            .user = NULL,
252
            .actionparams = NULL,
253
            .renderparams = &toolchooser_rparams_mainchooser
254
        },
255
        {
256
            .user = run_umsboot,
257
            .actionparams = NULL,
258
            .renderparams = &toolchooser_rparams_umsboot
259
        },
260
        {
261
            .user = run_diagmode,
262
            .actionparams = NULL,
263
            .renderparams = &toolchooser_rparams_diagmode
264
        },
265
        {
266
            .user = run_rockbox_fallback,
267
            .actionparams = NULL,
268
            .renderparams = &toolchooser_rparams_rockbox_fallback
269
        },
270
        {
271
            .user = run_clearcfg,
272
            .actionparams = NULL,
273
            .renderparams = &toolchooser_rparams_clearcfg
274
        },
275
        {
276
            .user = run_cleardb,
277
            .actionparams = NULL,
278
            .renderparams = &toolchooser_rparams_cleardb
279
        },
280
        {
281
            .user = run_reformat,
282
            .actionparams = NULL,
283
            .renderparams = &toolchooser_rparams_reformat
284
        },
285
        {
286
            .user = run_uninstaller,
287
            .actionparams = NULL,
288
            .renderparams = &toolchooser_rparams_uninstaller
289
        },
290
        {
291
            .user = run_settingchooser,
292
            .actionparams = NULL,
293
            .renderparams = &toolchooser_rparams_settingchooser
294
        }
295
    }
296
};
297
 
838 theseven 298
void run_toolchooser()
828 theseven 299
{
838 theseven 300
    while (!bootinfo.valid)
828 theseven 301
    {
302
        const struct chooser_item* result = ui->chooser_run(&toolchooser);
303
        if (!result || !result->user) return;
838 theseven 304
        ((void(*)())(result->user))();
828 theseven 305
    }
306
}
307
 
308
void toolchooser_init()
309
{
310
    toolchooser.actionhandler = ui->chooser_action_handler_wheel;
311
    toolchooser.renderer = ui->chooser_renderer_list;
312
    toolchooser_rparams.copy_dest.buf.addr = framebuf;
313
    toolchooser_rparams.copy_src.loc.buf.addr = bg;
314
    toolchooser_rparams.viewport.loc.buf.addr = framebuf;
315
    toolchooser_rparams.blit_src.loc.buf.addr = framebuf;
316
    toolchooser_rparams_mainchooser.render = ui->chooser_renderer_list_show_arrow_left;
317
    toolchooser_rparams_settingchooser.render = ui->chooser_renderer_list_show_arrow_right;
318
}
838 theseven 319
 
320
void toolchooser_apply_settings()
321
{
322
}