1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
25 #include "skin_engine.h"
26 #include "wps_internals.h"
28 #include "option_select.h"
30 #include "settings_list.h"
37 /** Disarms all touchregions. */
38 void skin_disarm_touchregions(struct wps_data
*data
)
40 struct skin_token_list
*regions
= data
->touchregions
;
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
;
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
;
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
;
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 */
93 case ACTION_TOUCH_SCROLLBAR
:
94 case ACTION_TOUCH_VOLUME
:
97 if(r
->width
> r
->height
)
98 *edge_offset
= vx
*100/r
->width
;
100 *edge_offset
= vy
*100/r
->height
;
102 *edge_offset
= 100 - *edge_offset
;
105 returncode
= r
->action
;
108 if (r
->armed
&& ((repeated
&& needs_repeat
) ||
109 (released
&& !needs_repeat
)))
111 returncode
= r
->action
;
117 r
->last_press
= current_tick
;
123 regions
= regions
->next
;
126 /* On release, all regions are disarmed. */
128 skin_disarm_touchregions(data
);
129 if (retregion
&& temp
)
131 if (temp
&& temp
->press_length
== LONG_PRESS
)
134 if (returncode
!= ACTION_NONE
)
136 if (global_settings
.party_mode
)
140 case ACTION_WPS_PLAY
:
141 case ACTION_WPS_SKIPPREV
:
142 case ACTION_WPS_SKIPNEXT
:
143 case ACTION_WPS_STOP
:
144 returncode
= ACTION_NONE
;
152 case ACTION_WPS_PLAY
:
155 if ( global_status
.resume_index
!= -1 )
157 if (playlist_resume() != -1)
159 playlist_start(global_status
.resume_index
,
160 global_status
.resume_offset
);
165 splash(HZ
*2, ID2P(LANG_NOTHING_TO_RESUME
));
170 wps_do_playpause(false);
172 returncode
= ACTION_REDRAW
;
174 case ACTION_WPS_SKIPPREV
:
176 returncode
= ACTION_REDRAW
;
178 case ACTION_WPS_SKIPNEXT
:
180 returncode
= ACTION_REDRAW
;
182 case ACTION_WPS_STOP
:
184 returncode
= ACTION_REDRAW
;
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
,
194 returncode
= ACTION_REDRAW
;
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
)
206 ->load_from_cfg(s
->setting
, data
->value
.text
);
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
;
216 f
= s
->int_setting
->option_callback
;
219 f(data
->value
.number
);
222 *(bool*)s
->setting
= data
->value
.number
? true : false;
223 if (s
->bool_setting
->option_callback
)
225 ->option_callback(data
->value
.number
? true : false);
228 returncode
= ACTION_REDRAW
;
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
;
238 temp
->value
= global_settings
.volume
;
239 global_settings
.volume
= min_vol
;
242 returncode
= ACTION_REDRAW
;
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();
252 if (global_settings
.playlist_shuffle
)
253 playlist_randomise(NULL
, current_tick
, true);
255 playlist_sort(NULL
, true);
256 returncode
= ACTION_REDRAW
;
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
;
272 return ACTION_TOUCHSCREEN
;