Make repeat mode/shuffle work in the sbs also
[maemo-rb.git] / apps / gui / skin_engine / skin_touchsupport.c
blobe1a7d0688e7627c28f0010b99d5fc5dbca4ccc44
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 static int last_action = ACTION_NONE;
60 struct touchregion *r, *temp = NULL;
61 bool repeated = (type == BUTTON_REPEAT);
62 bool released = (type == BUTTON_REL);
63 bool pressed = (type == BUTTON_TOUCHSCREEN);
64 struct skin_token_list *regions = data->touchregions;
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 /* check if it's inside this viewport */
76 if (viewport_point_within_vp(&(r->wvp->vp), x, y))
77 { /* reposition the touch inside the viewport since touchregions
78 * are relative to a preceding viewport */
79 vx = x - r->wvp->vp.x;
80 vy = y - r->wvp->vp.y;
81 /* now see if the point is inside this region */
82 if (vx >= r->x && vx < r->x+r->width &&
83 vy >= r->y && vy < r->y+r->height)
85 /* reposition the touch within the area */
86 vx -= r->x;
87 vy -= r->y;
90 switch(r->type)
92 case WPS_TOUCHREGION_ACTION:
93 if (r->armed && ((repeated && r->repeat) || (released && !r->repeat)))
95 last_action = r->action;
96 returncode = r->action;
97 temp = r;
99 if (pressed)
101 r->armed = true;
102 r->last_press = current_tick;
104 break;
105 default:
106 if (edge_offset)
108 if(r->width > r->height)
109 *edge_offset = vx*100/r->width;
110 else
111 *edge_offset = vy*100/r->height;
112 if (r->reverse_bar)
113 *edge_offset = 100 - *edge_offset;
115 returncode = r->type;
116 temp = r;
117 break;
121 regions = regions->next;
124 /* On release, all regions are disarmed. */
125 if (released)
126 skin_disarm_touchregions(data);
127 if (retregion && temp)
128 *retregion = temp;
130 if (returncode != ACTION_NONE)
132 if (global_settings.party_mode)
134 switch (returncode)
136 case ACTION_WPS_PLAY:
137 case ACTION_WPS_SKIPPREV:
138 case ACTION_WPS_SKIPNEXT:
139 case ACTION_WPS_STOP:
140 returncode = ACTION_NONE;
141 break;
142 default:
143 break;
146 switch (returncode)
148 case ACTION_WPS_PLAY:
149 if (!audio_status())
151 if ( global_status.resume_index != -1 )
153 if (playlist_resume() != -1)
155 playlist_start(global_status.resume_index,
156 global_status.resume_offset);
159 else
161 splash(HZ*2, ID2P(LANG_NOTHING_TO_RESUME));
164 else
166 wps_do_playpause(false);
168 returncode = ACTION_REDRAW;
169 break;
170 case ACTION_WPS_SKIPPREV:
171 audio_prev();
172 returncode = ACTION_REDRAW;
173 break;
174 case ACTION_WPS_SKIPNEXT:
175 audio_next();
176 returncode = ACTION_REDRAW;
177 break;
178 case ACTION_WPS_STOP:
179 audio_stop();
180 returncode = ACTION_REDRAW;
181 break;
182 case ACTION_SETTINGS_INC:
183 case ACTION_SETTINGS_DEC:
185 const struct settings_list *setting =
186 temp->setting_data.setting;
187 option_select_next_val(setting,
188 returncode == ACTION_SETTINGS_DEC,
189 true);
190 returncode = ACTION_REDRAW;
192 break;
193 case ACTION_SETTINGS_SET:
195 struct touchsetting *data = &temp->setting_data;
196 const struct settings_list *s = data->setting;
197 void (*f)(int) = NULL;
198 switch (s->flags&F_T_MASK)
200 case F_T_CUSTOM:
201 s->custom_setting
202 ->load_from_cfg(s->setting, data->value.text);
203 break;
204 case F_T_INT:
205 case F_T_UINT:
206 *(int*)s->setting = data->value.number;
207 if (s->flags&F_CHOICE_SETTING)
208 f = s->choice_setting->option_callback;
209 else if (s->flags&F_TABLE_SETTING)
210 f = s->table_setting->option_callback;
211 else
212 f = s->int_setting->option_callback;
214 if (f)
215 f(data->value.number);
216 break;
217 case F_T_BOOL:
218 *(bool*)s->setting = data->value.number ? true : false;
219 if (s->bool_setting->option_callback)
220 s->bool_setting
221 ->option_callback(data->value.number ? true : false);
222 break;
224 returncode = ACTION_REDRAW;
226 break;
227 case ACTION_TOUCH_MUTE:
229 const int min_vol = sound_min(SOUND_VOLUME);
230 if (global_settings.volume == min_vol)
231 global_settings.volume = temp->value;
232 else
234 temp->value = global_settings.volume;
235 global_settings.volume = min_vol;
237 setvol();
238 returncode = ACTION_REDRAW;
240 break;
241 case ACTION_TOUCH_SHUFFLE: /* toggle shuffle mode */
243 global_settings.playlist_shuffle =
244 !global_settings.playlist_shuffle;
245 #if CONFIG_CODEC == SWCODEC
246 dsp_set_replaygain();
247 #endif
248 if (global_settings.playlist_shuffle)
249 playlist_randomise(NULL, current_tick, true);
250 else
251 playlist_sort(NULL, true);
252 returncode = ACTION_REDRAW;
254 break;
255 case ACTION_TOUCH_REPMODE: /* cycle the repeat mode setting */
257 const struct settings_list *rep_setting =
258 find_setting(&global_settings.repeat_mode, NULL);
259 option_select_next_val(rep_setting, false, true);
260 audio_flush_and_reload_tracks();
261 returncode = ACTION_REDRAW;
263 break;
265 return returncode;
268 last_action = ACTION_TOUCHSCREEN;
269 return ACTION_TOUCHSCREEN;