Subversion Repositories freemyipod

Rev

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