Subversion Repositories freemyipod

Rev

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 "bootoptionchooser.h"
27
#include "main.h"
28
#include "util.h"
29
 
30
 
31
static struct chooser_renderer_list_itemdata bootoptionchooser_rparams_cancel =
32
{
33
    .size = LIBUI_POINT(260, 10),
34
    .fill_box = LIBUI_BOX(LIBUI_POINT(0, 0), LIBUI_POINT(260, 10)),
35
    .fill_color = 0xa0000000,
36
    .fill_color_selected = 0x60ffffff,
37
    .icon_pos = LIBUI_POINT(0, 0),
38
    .icon = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
39
                          LIBUI_POINT(0, 0)),
40
    .icon_opacity = 0,
41
    .icon_selected = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
42
                                   LIBUI_POINT(0, 0)),
43
    .icon_selected_opacity = 0,
44
    .text = "Cancel",
45
    .text_pos = LIBUI_POINT(1, 1),
46
    .text_color = 0xffffffff,
47
    .text_color_selected = 0xff7fffff
48
};
49
 
50
static struct chooser_renderer_list_itemdata bootoptionchooser_rparams_option_0 =
51
{
52
    .size = LIBUI_POINT(260, 10),
53
    .fill_box = LIBUI_BOX(LIBUI_POINT(0, 0), LIBUI_POINT(260, 10)),
54
    .fill_color = 0xa0000000,
55
    .fill_color_selected = 0x60ffffff,
56
    .icon_pos = LIBUI_POINT(0, 0),
57
    .icon = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
58
                          LIBUI_POINT(0, 0)),
59
    .icon_opacity = 0,
60
    .icon_selected = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
61
                                   LIBUI_POINT(0, 0)),
62
    .icon_selected_opacity = 0,
63
    .text = NULL,
64
    .text_pos = LIBUI_POINT(1, 1),
65
    .text_color = 0xffffffff,
66
    .text_color_selected = 0xff7fffff
67
};
68
 
69
static struct chooser_renderer_list_itemdata bootoptionchooser_rparams_option_1 =
70
{
71
    .size = LIBUI_POINT(260, 10),
72
    .fill_box = LIBUI_BOX(LIBUI_POINT(0, 0), LIBUI_POINT(260, 10)),
73
    .fill_color = 0xa0000000,
74
    .fill_color_selected = 0x60ffffff,
75
    .icon_pos = LIBUI_POINT(0, 0),
76
    .icon = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
77
                          LIBUI_POINT(0, 0)),
78
    .icon_opacity = 0,
79
    .icon_selected = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
80
                                   LIBUI_POINT(0, 0)),
81
    .icon_selected_opacity = 0,
82
    .text = NULL,
83
    .text_pos = LIBUI_POINT(1, 1),
84
    .text_color = 0xffffffff,
85
    .text_color_selected = 0xff7fffff
86
};
87
 
88
static struct chooser_renderer_list_itemdata bootoptionchooser_rparams_option_2 =
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,
94
    .icon_pos = LIBUI_POINT(0, 0),
95
    .icon = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
96
                          LIBUI_POINT(0, 0)),
97
    .icon_opacity = 0,
98
    .icon_selected = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
99
                                   LIBUI_POINT(0, 0)),
100
    .icon_selected_opacity = 0,
101
    .text = NULL,
102
    .text_pos = LIBUI_POINT(1, 1),
103
    .text_color = 0xffffffff,
104
    .text_color_selected = 0xff7fffff
105
};
106
 
107
static struct chooser_renderer_list_itemdata bootoptionchooser_rparams_option_3 =
108
{
109
    .size = LIBUI_POINT(260, 10),
110
    .fill_box = LIBUI_BOX(LIBUI_POINT(0, 0), LIBUI_POINT(260, 10)),
111
    .fill_color = 0xa0000000,
112
    .fill_color_selected = 0x60ffffff,
113
    .icon_pos = LIBUI_POINT(0, 0),
114
    .icon = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
115
                          LIBUI_POINT(0, 0)),
116
    .icon_opacity = 0,
117
    .icon_selected = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
118
                                   LIBUI_POINT(0, 0)),
119
    .icon_selected_opacity = 0,
120
    .text = NULL,
121
    .text_pos = LIBUI_POINT(1, 1),
122
    .text_color = 0xffffffff,
123
    .text_color_selected = 0xff7fffff
124
};
125
 
126
static struct chooser_renderer_list_params bootoptionchooser_rparams =
127
{
128
    .version = CHOOSER_RENDERER_LIST_PARAMS_VERSION,
129
    .copy_dest = LIBUI_LOCATION(LIBUI_BUFFER(NULL, 320), LIBUI_POINT(0, 0)),
130
    .copy_src = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 320), LIBUI_POINT(0, 0)),
131
                              LIBUI_POINT(320, 240)),
132
    .bg_dest = LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
133
    .bg_src = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
134
                            LIBUI_POINT(0, 0)),
135
    .bg_opacity = 0,
136
    .fill_dest = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
137
                               LIBUI_POINT(0, 0)),
138
    .fill_color = 0,
139
    .viewport = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 320), LIBUI_POINT(30, 50)),
140
                              LIBUI_POINT(260, 160)),
141
    .blit_dest = LIBUI_POINT(0, 0),
142
    .blit_src = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 320), LIBUI_POINT(0, 0)),
143
                              LIBUI_POINT(320, 240)),
144
    .preblit = update_display,
145
    .postblit = NULL
146
};
147
 
148
static struct chooser_action_handler_wheel_params bootoptionchooser_aparams =
149
{
150
    .version = CHOOSER_ACTION_HANDLER_WHEEL_PARAMS_VERSION,
151
    .stepsperitem = 128,
152
    .eventfilter = NULL,
153
    .timeout_initial = TIMEOUT_BLOCK,
154
    .timeout_idle = TIMEOUT_BLOCK,
155
    .timeout_item = 0,
156
    .tick_force_redraw = false,
157
    .buttoncount = 5,
158
    .buttonmap =
159
    {
160
        CHOOSER_ACTION_HANDLER_WHEEL_ACTION_SELECT,
161
        CHOOSER_ACTION_HANDLER_WHEEL_ACTION_NONE,
162
        CHOOSER_ACTION_HANDLER_WHEEL_ACTION_CANCEL,
163
        CHOOSER_ACTION_HANDLER_WHEEL_ACTION_NEXT,
164
        CHOOSER_ACTION_HANDLER_WHEEL_ACTION_PREV
165
    }
166
};
167
 
168
static struct chooser_info bootoptionchooser =
169
{
170
    .version = CHOOSER_INFO_VERSION,
171
    .actionhandler = NULL,
172
    .actionhandlerparams = &bootoptionchooser_aparams,
173
    .renderer = NULL,
174
    .rendererparams = &bootoptionchooser_rparams,
175
    .userparams = NULL,
176
    .tickinterval = 10000000,
177
    .itemcount = 5,
178
    .defaultitem = 0,
179
    .items =
180
    {
181
        {
182
            .user = (void*)-1,
183
            .actionparams = NULL,
184
            .renderparams = &bootoptionchooser_rparams_cancel
185
        },
186
        {
187
            .user = (void*)0,
188
            .actionparams = NULL,
189
            .renderparams = &bootoptionchooser_rparams_option_0
190
        },
191
        {
192
            .user = (void*)1,
193
            .actionparams = NULL,
194
            .renderparams = &bootoptionchooser_rparams_option_1
195
        },
196
        {
197
            .user = (void*)2,
198
            .actionparams = NULL,
199
            .renderparams = &bootoptionchooser_rparams_option_2
200
        },
201
        {
202
            .user = (void*)3,
203
            .actionparams = NULL,
204
            .renderparams = &bootoptionchooser_rparams_option_3
205
        }
206
    }
207
};
208
 
209
int run_bootoptionchooser(int selected_index, const char* n0, const char* n1,
210
                          const char* n2, const char* n3)
211
{
212
    bootoptionchooser.defaultitem = selected_index + 1;
213
    bootoptionchooser_rparams_option_0.text = n0;
214
    bootoptionchooser_rparams_option_1.text = n1;
215
    bootoptionchooser_rparams_option_2.text = n2;
216
    bootoptionchooser_rparams_option_3.text = n3;
217
    const struct chooser_item* result = ui->chooser_run(&bootoptionchooser);
218
    if (!result) return -1;
219
    return (int)result->user;
220
}
221
 
222
void bootoptionchooser_init()
223
{
224
    bootoptionchooser.actionhandler = ui->chooser_action_handler_wheel;
225
    bootoptionchooser.renderer = ui->chooser_renderer_list;
226
    bootoptionchooser_rparams.copy_dest.buf.addr = framebuf;
227
    bootoptionchooser_rparams.copy_src.loc.buf.addr = bg;
228
    bootoptionchooser_rparams.viewport.loc.buf.addr = framebuf;
229
    bootoptionchooser_rparams.blit_src.loc.buf.addr = framebuf;
230
}