Subversion Repositories freemyipod

Rev

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

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