Subversion Repositories freemyipod

Rev

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