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