Fix some residual 'defined but not used' warnings by GCC 4.6.0 for touchscreen targets.
[kugel-rb.git] / apps / gui / skin_engine / skin_touchsupport.c
blobfb4780c22d94158b9596fefde0d4161d4d2b67be
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2009 - Jonathan Gordon
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include "config.h"
23 #include <stdio.h>
24 #include "action.h"
25 #include "skin_engine.h"
26 #include "wps_internals.h"
27 #include "misc.h"
28 #include "option_select.h"
29 #include "sound.h"
30 #include "settings_list.h"
31 #include "wps.h"
32 #include "lang.h"
33 #include "splash.h"
34 #include "playlist.h"
35 #include "dsp.h"
37 /** Disarms all touchregions. */
38 void skin_disarm_touchregions(struct wps_data *data)
40 struct skin_token_list *regions = data->touchregions;
41 while (regions)
43 ((struct touchregion *)regions->token->value.data)->armed = false;
44 regions = regions->next;
48 /* Get the touched action.
49 * egde_offset is a percentage value for the position of the touch
50 * inside the bar for regions which arnt WPS_TOUCHREGION_ACTION type.
52 int skin_get_touchaction(struct wps_data *data, int* edge_offset,
53 struct touchregion **retregion)
55 int returncode = ACTION_NONE;
56 short x,y;
57 short vx, vy;
58 int type = action_get_touchscreen_press(&x, &y);
59 struct touchregion *r, *temp = NULL;
60 bool repeated = (type == BUTTON_REPEAT);
61 bool released = (type == BUTTON_REL);
62 bool pressed = (type == BUTTON_TOUCHSCREEN);
63 struct skin_token_list *regions = data->touchregions;
64 bool needs_repeat;
66 while (regions)
68 r = (struct touchregion *)regions->token->value.data;
69 /* make sure this region's viewport is visible */
70 if (r->wvp->hidden_flags&VP_DRAW_HIDDEN)
72 regions = regions->next;
73 continue;
75 needs_repeat = r->press_length != PRESS;
76 /* check if it's inside this viewport */
77 if (viewport_point_within_vp(&(r->wvp->vp), x, y))
78 { /* reposition the touch inside the viewport since touchregions
79 * are relative to a preceding viewport */
80 vx = x - r->wvp->vp.x;
81 vy = y - r->wvp->vp.y;
82 /* now see if the point is inside this region */
83 if (vx >= r->x && vx < r->x+r->width &&
84 vy >= r->y && vy < r->y+r->height)
86 /* reposition the touch within the area */
87 vx -= r->x;
88 vy -= r->y;
91 switch(r->action)
93 case ACTION_TOUCH_SCROLLBAR:
94 case ACTION_TOUCH_VOLUME:
95 if (edge_offset)
97 if(r->width > r->height)
98 *edge_offset = vx*100/r->width;
99 else
100 *edge_offset = vy*100/r->height;
101 if (r->reverse_bar)
102 *edge_offset = 100 - *edge_offset;
104 temp = r;
105 returncode = r->action;
106 break;
107 default:
108 if (r->armed && ((repeated && needs_repeat) ||
109 (released && !needs_repeat)))
111 returncode = r->action;
112 temp = r;
114 if (pressed)
116 r->armed = true;
117 r->last_press = current_tick;
119 break;
123 regions = regions->next;
126 /* On release, all regions are disarmed. */
127 if (released)
128 skin_disarm_touchregions(data);
129 if (retregion && temp)
130 *retregion = temp;
131 if (temp && temp->press_length == LONG_PRESS)
132 temp->armed = false;
134 if (returncode != ACTION_NONE)
136 if (global_settings.party_mode)
138 switch (returncode)
140 case ACTION_WPS_PLAY:
141 case ACTION_WPS_SKIPPREV:
142 case ACTION_WPS_SKIPNEXT:
143 case ACTION_WPS_STOP:
144 returncode = ACTION_NONE;
145 break;
146 default:
147 break;
150 switch (returncode)
152 case ACTION_WPS_PLAY:
153 if (!audio_status())
155 if ( global_status.resume_index != -1 )
157 if (playlist_resume() != -1)
159 playlist_start(global_status.resume_index,
160 global_status.resume_offset);
163 else
165 splash(HZ*2, ID2P(LANG_NOTHING_TO_RESUME));
168 else
170 wps_do_playpause(false);
172 returncode = ACTION_REDRAW;
173 break;
174 case ACTION_WPS_SKIPPREV:
175 audio_prev();
176 returncode = ACTION_REDRAW;
177 break;
178 case ACTION_WPS_SKIPNEXT:
179 audio_next();
180 returncode = ACTION_REDRAW;
181 break;
182 case ACTION_WPS_STOP:
183 audio_stop();
184 returncode = ACTION_REDRAW;
185 break;
186 case ACTION_SETTINGS_INC:
187 case ACTION_SETTINGS_DEC:
189 const struct settings_list *setting =
190 temp->setting_data.setting;
191 option_select_next_val(setting,
192 returncode == ACTION_SETTINGS_DEC,
193 true);
194 returncode = ACTION_REDRAW;
196 break;
197 case ACTION_SETTINGS_SET:
199 struct touchsetting *data = &temp->setting_data;
200 const struct settings_list *s = data->setting;
201 void (*f)(int) = NULL;
202 switch (s->flags&F_T_MASK)
204 case F_T_CUSTOM:
205 s->custom_setting
206 ->load_from_cfg(s->setting, data->value.text);
207 break;
208 case F_T_INT:
209 case F_T_UINT:
210 *(int*)s->setting = data->value.number;
211 if (s->flags&F_CHOICE_SETTING)
212 f = s->choice_setting->option_callback;
213 else if (s->flags&F_TABLE_SETTING)
214 f = s->table_setting->option_callback;
215 else
216 f = s->int_setting->option_callback;
218 if (f)
219 f(data->value.number);
220 break;
221 case F_T_BOOL:
222 *(bool*)s->setting = data->value.number ? true : false;
223 if (s->bool_setting->option_callback)
224 s->bool_setting
225 ->option_callback(data->value.number ? true : false);
226 break;
228 returncode = ACTION_REDRAW;
230 break;
231 case ACTION_TOUCH_MUTE:
233 const int min_vol = sound_min(SOUND_VOLUME);
234 if (global_settings.volume == min_vol)
235 global_settings.volume = temp->value;
236 else
238 temp->value = global_settings.volume;
239 global_settings.volume = min_vol;
241 setvol();
242 returncode = ACTION_REDRAW;
244 break;
245 case ACTION_TOUCH_SHUFFLE: /* toggle shuffle mode */
247 global_settings.playlist_shuffle =
248 !global_settings.playlist_shuffle;
249 #if CONFIG_CODEC == SWCODEC
250 dsp_set_replaygain();
251 #endif
252 if (global_settings.playlist_shuffle)
253 playlist_randomise(NULL, current_tick, true);
254 else
255 playlist_sort(NULL, true);
256 returncode = ACTION_REDRAW;
258 break;
259 case ACTION_TOUCH_REPMODE: /* cycle the repeat mode setting */
261 const struct settings_list *rep_setting =
262 find_setting(&global_settings.repeat_mode, NULL);
263 option_select_next_val(rep_setting, false, true);
264 audio_flush_and_reload_tracks();
265 returncode = ACTION_REDRAW;
267 break;
269 return returncode;
272 return ACTION_TOUCHSCREEN;