Subversion Repositories freemyipod

Rev

Rev 833 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
830 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 "confirmchooser.h"
27
#include "main.h"
28
#include "util.h"
29
 
30
 
31
static struct chooser_renderer_list_itemdata confirmchooser_rparams_yes =
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 = 0xa00000ff,
37
    .icon_pos = LIBUI_POINT_NULL,
38
    .icon = LIBUI_SURFACE_NULL,
39
    .icon_opacity = 0,
40
    .icon_selected = LIBUI_SURFACE_NULL,
41
    .icon_selected_opacity = 0,
42
    .text = "Yes",
43
    .text_pos = LIBUI_POINT(1, 1),
44
    .text_color = 0xff0000ff,
45
    .text_color_selected = 0xff3f7fff,
46
    .render = NULL
47
};
48
 
49
static struct chooser_renderer_list_itemdata confirmchooser_rparams_no =
50
{
51
    .size = LIBUI_POINT(260, 10),
52
    .fill_box = LIBUI_BOX(LIBUI_POINT(0, 0), LIBUI_POINT(260, 10)),
53
    .fill_color = 0xa0000000,
54
    .fill_color_selected = 0x60ffffff,
55
    .icon_pos = LIBUI_POINT_NULL,
56
    .icon = LIBUI_SURFACE_NULL,
57
    .icon_opacity = 0,
58
    .icon_selected = LIBUI_SURFACE_NULL,
59
    .icon_selected_opacity = 0,
60
    .text = "No",
61
    .text_pos = LIBUI_POINT(1, 1),
62
    .text_color = 0xffffffff,
63
    .text_color_selected = 0xff7fffff,
64
    .render = NULL
65
};
66
 
67
static struct chooser_renderer_list_params confirmchooser_rparams =
68
{
69
    .version = CHOOSER_RENDERER_LIST_PARAMS_VERSION,
70
    .copy_dest = LIBUI_LOCATION(LIBUI_BUFFER(NULL, 320), LIBUI_POINT(0, 0)),
71
    .copy_src = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 320), LIBUI_POINT(0, 0)),
72
                              LIBUI_POINT(320, 240)),
73
    .bg_dest = LIBUI_LOCATION_NULL,
74
    .bg_src = LIBUI_SURFACE_NULL,
75
    .bg_opacity = 0,
76
    .fill_dest = LIBUI_SURFACE_NULL,
77
    .fill_color = 0,
78
    .viewport = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 320), LIBUI_POINT(30, 70)),
79
                              LIBUI_POINT(260, 140)),
80
    .blit_dest = LIBUI_POINT(0, 0),
81
    .blit_src = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 320), LIBUI_POINT(0, 0)),
82
                              LIBUI_POINT(320, 240)),
83
    .preblit = update_display,
84
    .postblit = NULL
85
};
86
 
87
static struct chooser_action_handler_wheel_params confirmchooser_aparams =
88
{
89
    .version = CHOOSER_ACTION_HANDLER_WHEEL_PARAMS_VERSION,
90
    .stepsperitem = 128,
91
    .eventfilter = NULL,
92
    .timeout_initial = TIMEOUT_BLOCK,
93
    .timeout_idle = TIMEOUT_BLOCK,
94
    .timeout_item = 0,
95
    .tick_force_redraw = true,
96
    .buttoncount = 5,
97
    .buttonmap =
98
    {
99
        CHOOSER_ACTION_HANDLER_WHEEL_ACTION_SELECT,
100
        CHOOSER_ACTION_HANDLER_WHEEL_ACTION_SELECT,
101
        CHOOSER_ACTION_HANDLER_WHEEL_ACTION_CANCEL,
102
        CHOOSER_ACTION_HANDLER_WHEEL_ACTION_NEXT,
103
        CHOOSER_ACTION_HANDLER_WHEEL_ACTION_PREV
104
    }
105
};
106
 
107
static struct chooser_info confirmchooser =
108
{
109
    .version = CHOOSER_INFO_VERSION,
110
    .actionhandler = NULL,
111
    .actionhandlerparams = &confirmchooser_aparams,
112
    .renderer = NULL,
113
    .rendererparams = &confirmchooser_rparams,
114
    .userparams = NULL,
115
    .tickinterval = 10000000,
116
    .itemcount = 14,
117
    .defaultitem = 0,
118
    .items =
119
    {
120
        {
121
            .user = NULL,
122
            .actionparams = NULL,
123
            .renderparams = &confirmchooser_rparams_no
124
        },
125
        {
126
            .user = NULL,
127
            .actionparams = NULL,
128
            .renderparams = &confirmchooser_rparams_no
129
        },
130
        {
131
            .user = NULL,
132
            .actionparams = NULL,
133
            .renderparams = &confirmchooser_rparams_no
134
        },
135
        {
136
            .user = NULL,
137
            .actionparams = NULL,
138
            .renderparams = &confirmchooser_rparams_no
139
        },
140
        {
141
            .user = NULL,
142
            .actionparams = NULL,
143
            .renderparams = &confirmchooser_rparams_no
144
        },
145
        {
146
            .user = NULL,
147
            .actionparams = NULL,
148
            .renderparams = &confirmchooser_rparams_no
149
        },
150
        {
151
            .user = NULL,
152
            .actionparams = NULL,
153
            .renderparams = &confirmchooser_rparams_no
154
        },
155
        {
156
            .user = NULL,
157
            .actionparams = NULL,
158
            .renderparams = &confirmchooser_rparams_no
159
        },
160
        {
161
            .user = NULL,
162
            .actionparams = NULL,
163
            .renderparams = &confirmchooser_rparams_no
164
        },
165
        {
166
            .user = (void*)1,
167
            .actionparams = NULL,
168
            .renderparams = &confirmchooser_rparams_yes
169
        },
170
        {
171
            .user = NULL,
172
            .actionparams = NULL,
173
            .renderparams = &confirmchooser_rparams_no
174
        },
175
        {
176
            .user = NULL,
177
            .actionparams = NULL,
178
            .renderparams = &confirmchooser_rparams_no
179
        },
180
        {
181
            .user = NULL,
182
            .actionparams = NULL,
183
            .renderparams = &confirmchooser_rparams_no
184
        },
185
        {
186
            .user = NULL,
187
            .actionparams = NULL,
188
            .renderparams = &confirmchooser_rparams_no
189
        }
190
    }
191
};
192
 
193
bool run_confirmchooser(const char* message)
194
{
195
    memcpy(framebuf2, bg, 320 * 240 * 3);
196
    ui->blendcolor(260, 20, 0xa0000000, framebuf2, 30, 50, 320, framebuf2, 30, 50, 320);
197
    rendertext(framebuf2, 31, 51, 320, 0xff3333ff, 0, message);
198
    const struct chooser_item* result = ui->chooser_run(&confirmchooser);
199
    if (!result || !result->user) return false;
200
    return true;
201
}
202
 
203
void confirmchooser_init()
204
{
205
    confirmchooser.actionhandler = ui->chooser_action_handler_wheel;
206
    confirmchooser.renderer = ui->chooser_renderer_list;
207
    confirmchooser_rparams.copy_dest.buf.addr = framebuf;
208
    confirmchooser_rparams.copy_src.loc.buf.addr = framebuf2;
209
    confirmchooser_rparams.viewport.loc.buf.addr = framebuf;
210
    confirmchooser_rparams.blit_src.loc.buf.addr = framebuf;
211
    confirmchooser_rparams_yes.render = ui->chooser_renderer_list_show_arrow_right;
212
    confirmchooser_rparams_no.render = ui->chooser_renderer_list_show_arrow_left;
213
}