Subversion Repositories freemyipod

Rev

Rev 823 | Go to most recent revision | Details | Last modification | View Log | RSS feed

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