diff options
Diffstat (limited to 'apps/gui/wps.c')
-rw-r--r-- | apps/gui/wps.c | 196 |
1 files changed, 52 insertions, 144 deletions
diff --git a/apps/gui/wps.c b/apps/gui/wps.c index 0a8ce899c5..dafc1cd278 100644 --- a/apps/gui/wps.c +++ b/apps/gui/wps.c | |||
@@ -85,10 +85,6 @@ static void wps_state_init(void); | |||
85 | static void track_changed_callback(void *param); | 85 | static void track_changed_callback(void *param); |
86 | static void nextid3available_callback(void* param); | 86 | static void nextid3available_callback(void* param); |
87 | 87 | ||
88 | #ifdef HAVE_TOUCHSCREEN | ||
89 | static void wps_disarm_touchregions(struct wps_data *data); | ||
90 | #endif | ||
91 | |||
92 | #define WPS_DEFAULTCFG WPS_DIR "/rockbox_default.wps" | 88 | #define WPS_DEFAULTCFG WPS_DIR "/rockbox_default.wps" |
93 | #ifdef HAVE_REMOTE_LCD | 89 | #ifdef HAVE_REMOTE_LCD |
94 | #define RWPS_DEFAULTCFG WPS_DIR "/rockbox_default.rwps" | 90 | #define RWPS_DEFAULTCFG WPS_DIR "/rockbox_default.rwps" |
@@ -227,6 +223,55 @@ static bool update_onvol_change(struct gui_wps * gwps) | |||
227 | } | 223 | } |
228 | 224 | ||
229 | 225 | ||
226 | #ifdef HAVE_TOUCHSCREEN | ||
227 | int skintouch_to_wps(struct wps_data *data) | ||
228 | { | ||
229 | int offset = 0; | ||
230 | int button = skin_get_touchaction(data, &offset); | ||
231 | switch (button) | ||
232 | { | ||
233 | case ACTION_STD_PREV: | ||
234 | return ACTION_WPS_SKIPPREV; | ||
235 | case ACTION_STD_PREVREPEAT: | ||
236 | return ACTION_WPS_SEEKBACK; | ||
237 | case ACTION_STD_NEXT: | ||
238 | return ACTION_WPS_SKIPNEXT; | ||
239 | case ACTION_STD_NEXTREPEAT: | ||
240 | return ACTION_WPS_SEEKFWD; | ||
241 | case ACTION_STD_MENU: | ||
242 | return ACTION_WPS_MENU; | ||
243 | case ACTION_STD_CONTEXT: | ||
244 | return ACTION_WPS_CONTEXT; | ||
245 | case ACTION_STD_QUICKSCREEN: | ||
246 | return ACTION_WPS_QUICKSCREEN; | ||
247 | case WPS_TOUCHREGION_SCROLLBAR: | ||
248 | wps_state.id3->elapsed = wps_state.id3->length*offset/100; | ||
249 | if (!wps_state.paused) | ||
250 | #if (CONFIG_CODEC == SWCODEC) | ||
251 | audio_pre_ff_rewind(); | ||
252 | #else | ||
253 | audio_pause(); | ||
254 | #endif | ||
255 | audio_ff_rewind(wps_state.id3->elapsed); | ||
256 | #if (CONFIG_CODEC != SWCODEC) | ||
257 | if (!wps_state.paused) | ||
258 | audio_resume(); | ||
259 | #endif | ||
260 | return ACTION_TOUCHSCREEN; | ||
261 | case WPS_TOUCHREGION_VOLUME: | ||
262 | { | ||
263 | const int min_vol = sound_min(SOUND_VOLUME); | ||
264 | const int max_vol = sound_max(SOUND_VOLUME); | ||
265 | global_settings.volume = (offset * (max_vol - min_vol)) / 100; | ||
266 | global_settings.volume += min_vol; | ||
267 | setvol(); | ||
268 | } | ||
269 | return ACTION_TOUCHSCREEN; | ||
270 | } | ||
271 | return button; | ||
272 | } | ||
273 | #endif | ||
274 | |||
230 | bool ffwd_rew(int button) | 275 | bool ffwd_rew(int button) |
231 | { | 276 | { |
232 | unsigned int step = 0; /* current ff/rewind step */ | 277 | unsigned int step = 0; /* current ff/rewind step */ |
@@ -359,7 +404,7 @@ bool ffwd_rew(int button) | |||
359 | button = get_action(CONTEXT_WPS|ALLOW_SOFTLOCK,TIMEOUT_BLOCK); | 404 | button = get_action(CONTEXT_WPS|ALLOW_SOFTLOCK,TIMEOUT_BLOCK); |
360 | #ifdef HAVE_TOUCHSCREEN | 405 | #ifdef HAVE_TOUCHSCREEN |
361 | if (button == ACTION_TOUCHSCREEN) | 406 | if (button == ACTION_TOUCHSCREEN) |
362 | button = wps_get_touchaction(gui_wps[SCREEN_MAIN].data); | 407 | button = skintouch_to_wps(gui_wps[SCREEN_MAIN].data); |
363 | if (button != ACTION_WPS_SEEKFWD && | 408 | if (button != ACTION_WPS_SEEKFWD && |
364 | button != ACTION_WPS_SEEKBACK) | 409 | button != ACTION_WPS_SEEKBACK) |
365 | button = ACTION_WPS_STOPSEEK; | 410 | button = ACTION_WPS_STOPSEEK; |
@@ -616,150 +661,13 @@ static void gwps_enter_wps(void) | |||
616 | skin_update(gwps, WPS_REFRESH_ALL); | 661 | skin_update(gwps, WPS_REFRESH_ALL); |
617 | 662 | ||
618 | #ifdef HAVE_TOUCHSCREEN | 663 | #ifdef HAVE_TOUCHSCREEN |
619 | wps_disarm_touchregions(gui_wps[i].data); | 664 | skin_disarm_touchregions(gui_wps[i].data); |
620 | #endif | 665 | #endif |
621 | } | 666 | } |
622 | /* force statusbar/skin update since we just cleared the whole screen */ | 667 | /* force statusbar/skin update since we just cleared the whole screen */ |
623 | send_event(GUI_EVENT_ACTIONUPDATE, (void*)1); | 668 | send_event(GUI_EVENT_ACTIONUPDATE, (void*)1); |
624 | } | 669 | } |
625 | 670 | ||
626 | #ifdef HAVE_TOUCHSCREEN | ||
627 | /** Disarms all touchregions. */ | ||
628 | static void wps_disarm_touchregions(struct wps_data *data) | ||
629 | { | ||
630 | struct skin_token_list *regions = data->touchregions; | ||
631 | while (regions) | ||
632 | { | ||
633 | ((struct touchregion *)regions->token->value.data)->armed = false; | ||
634 | regions = regions->next; | ||
635 | } | ||
636 | } | ||
637 | |||
638 | int wps_get_touchaction(struct wps_data *data) | ||
639 | { | ||
640 | int returncode = ACTION_NONE; | ||
641 | short x,y; | ||
642 | short vx, vy; | ||
643 | int type = action_get_touchscreen_press(&x, &y); | ||
644 | static int last_action = ACTION_NONE; | ||
645 | struct touchregion *r; | ||
646 | bool repeated = (type == BUTTON_REPEAT); | ||
647 | bool released = (type == BUTTON_REL); | ||
648 | bool pressed = (type == BUTTON_TOUCHSCREEN); | ||
649 | struct skin_token_list *regions = data->touchregions; | ||
650 | |||
651 | while (regions) | ||
652 | { | ||
653 | r = (struct touchregion *)regions->token->value.data; | ||
654 | /* make sure this region's viewport is visible */ | ||
655 | if (r->wvp->hidden_flags&VP_DRAW_HIDDEN) | ||
656 | { | ||
657 | regions = regions->next; | ||
658 | continue; | ||
659 | } | ||
660 | /* check if it's inside this viewport */ | ||
661 | if (viewport_point_within_vp(&(r->wvp->vp), x, y)) | ||
662 | { /* reposition the touch inside the viewport since touchregions | ||
663 | * are relative to a preceding viewport */ | ||
664 | vx = x - r->wvp->vp.x; | ||
665 | vy = y - r->wvp->vp.y; | ||
666 | /* now see if the point is inside this region */ | ||
667 | if (vx >= r->x && vx < r->x+r->width && | ||
668 | vy >= r->y && vy < r->y+r->height) | ||
669 | { | ||
670 | /* reposition the touch within the area */ | ||
671 | vx -= r->x; | ||
672 | vy -= r->y; | ||
673 | |||
674 | switch(r->type) | ||
675 | { | ||
676 | case WPS_TOUCHREGION_ACTION: | ||
677 | if (r->armed && ((repeated && r->repeat) || (released && !r->repeat))) | ||
678 | { | ||
679 | last_action = r->action; | ||
680 | returncode = r->action; | ||
681 | } | ||
682 | if (pressed) | ||
683 | r->armed = true; | ||
684 | break; | ||
685 | case WPS_TOUCHREGION_SCROLLBAR: | ||
686 | if(r->width > r->height) | ||
687 | /* landscape */ | ||
688 | wps_state.id3->elapsed = (vx * | ||
689 | wps_state.id3->length) / r->width; | ||
690 | else | ||
691 | /* portrait */ | ||
692 | wps_state.id3->elapsed = (vy * | ||
693 | wps_state.id3->length) / r->height; | ||
694 | |||
695 | if (!wps_state.paused) | ||
696 | #if (CONFIG_CODEC == SWCODEC) | ||
697 | audio_pre_ff_rewind(); | ||
698 | #else | ||
699 | audio_pause(); | ||
700 | #endif | ||
701 | audio_ff_rewind(wps_state.id3->elapsed); | ||
702 | #if (CONFIG_CODEC != SWCODEC) | ||
703 | if (!wps_state.paused) | ||
704 | audio_resume(); | ||
705 | #endif | ||
706 | break; | ||
707 | case WPS_TOUCHREGION_VOLUME: | ||
708 | { | ||
709 | const int min_vol = sound_min(SOUND_VOLUME); | ||
710 | const int max_vol = sound_max(SOUND_VOLUME); | ||
711 | if(r->width > r->height) | ||
712 | /* landscape */ | ||
713 | global_settings.volume = (vx * | ||
714 | (max_vol - min_vol)) / r->width; | ||
715 | else | ||
716 | /* portrait */ | ||
717 | global_settings.volume = ((r->height - vy) * | ||
718 | (max_vol-min_vol)) / r->height; | ||
719 | |||
720 | global_settings.volume += min_vol; | ||
721 | setvol(); | ||
722 | returncode = ACTION_REDRAW; | ||
723 | } | ||
724 | } | ||
725 | } | ||
726 | } | ||
727 | regions = regions->next; | ||
728 | } | ||
729 | |||
730 | /* On release, all regions are disarmed. */ | ||
731 | if (released) | ||
732 | wps_disarm_touchregions(data); | ||
733 | |||
734 | /* Now we need to convert buttons to the WPS context */ | ||
735 | switch (returncode) | ||
736 | { | ||
737 | case ACTION_STD_PREV: | ||
738 | return ACTION_WPS_SKIPPREV; | ||
739 | case ACTION_STD_PREVREPEAT: | ||
740 | return ACTION_WPS_SEEKBACK; | ||
741 | case ACTION_STD_NEXT: | ||
742 | return ACTION_WPS_SKIPNEXT; | ||
743 | case ACTION_STD_NEXTREPEAT: | ||
744 | return ACTION_WPS_SEEKFWD; | ||
745 | case ACTION_STD_MENU: | ||
746 | return ACTION_WPS_MENU; | ||
747 | case ACTION_STD_CONTEXT: | ||
748 | return ACTION_WPS_CONTEXT; | ||
749 | case ACTION_STD_QUICKSCREEN: | ||
750 | return ACTION_WPS_QUICKSCREEN; | ||
751 | } | ||
752 | |||
753 | if (returncode != ACTION_NONE) | ||
754 | return returncode; | ||
755 | |||
756 | |||
757 | if ((last_action == ACTION_WPS_SEEKBACK || last_action == ACTION_WPS_SEEKFWD)) | ||
758 | return ACTION_WPS_STOPSEEK; | ||
759 | last_action = ACTION_TOUCHSCREEN; | ||
760 | return ACTION_TOUCHSCREEN; | ||
761 | } | ||
762 | #endif | ||
763 | /* The WPS can be left in two ways: | 671 | /* The WPS can be left in two ways: |
764 | * a) call a function, which draws over the wps. In this case, the wps | 672 | * a) call a function, which draws over the wps. In this case, the wps |
765 | * will be still active (i.e. the below function didn't return) | 673 | * will be still active (i.e. the below function didn't return) |
@@ -818,7 +726,7 @@ long gui_wps_show(void) | |||
818 | exit = true; | 726 | exit = true; |
819 | #ifdef HAVE_TOUCHSCREEN | 727 | #ifdef HAVE_TOUCHSCREEN |
820 | if (button == ACTION_TOUCHSCREEN) | 728 | if (button == ACTION_TOUCHSCREEN) |
821 | button = wps_get_touchaction(gui_wps[SCREEN_MAIN].data); | 729 | button = skintouch_to_wps(gui_wps[SCREEN_MAIN].data); |
822 | #endif | 730 | #endif |
823 | /* The iPods/X5/M5 use a single button for the A-B mode markers, | 731 | /* The iPods/X5/M5 use a single button for the A-B mode markers, |
824 | defined as ACTION_WPSAB_SINGLE in their config files. */ | 732 | defined as ACTION_WPSAB_SINGLE in their config files. */ |