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