2006-08-15 12:27:07 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
2006-08-16 08:07:59 +00:00
|
|
|
* $Id$
|
2006-08-15 12:27:07 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Jonathan Gordon
|
2008-01-21 09:48:44 +00:00
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2006-08-15 12:27:07 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "config.h"
|
2006-08-17 13:31:34 +00:00
|
|
|
#include "lang.h"
|
|
|
|
|
2009-01-05 09:59:11 +00:00
|
|
|
#include "appevents.h"
|
2006-08-15 12:27:07 +00:00
|
|
|
#include "button.h"
|
|
|
|
#include "action.h"
|
|
|
|
#include "kernel.h"
|
|
|
|
#include "debug.h"
|
2006-08-17 12:33:36 +00:00
|
|
|
#include "splash.h"
|
2008-01-21 09:48:44 +00:00
|
|
|
#include "settings.h"
|
|
|
|
#include "pcmbuf.h"
|
2009-06-11 20:36:02 +00:00
|
|
|
#include "misc.h"
|
2009-10-05 17:17:30 +00:00
|
|
|
#if defined(HAVE_LCD_BITMAP) && !defined(BOOTLOADER)
|
|
|
|
#include "language.h"
|
|
|
|
#endif
|
2009-10-11 20:11:48 +00:00
|
|
|
#include "viewport.h"
|
2010-06-21 06:04:19 +00:00
|
|
|
#ifdef HAVE_TOUCHSCREEN
|
|
|
|
#include "statusbar-skinned.h"
|
|
|
|
#endif
|
2006-08-15 12:27:07 +00:00
|
|
|
|
2008-01-21 09:48:44 +00:00
|
|
|
static int last_button = BUTTON_NONE|BUTTON_REL; /* allow the ipod wheel to
|
2007-07-22 06:05:53 +00:00
|
|
|
work on startup */
|
2007-07-22 21:02:24 +00:00
|
|
|
static intptr_t last_data = 0;
|
2007-03-04 07:45:12 +00:00
|
|
|
static int last_action = ACTION_NONE;
|
|
|
|
static bool repeated = false;
|
2009-07-03 05:08:33 +00:00
|
|
|
static bool wait_for_release = false;
|
2006-08-17 12:33:36 +00:00
|
|
|
|
2008-08-23 09:46:38 +00:00
|
|
|
#ifdef HAVE_TOUCHSCREEN
|
2007-10-22 12:26:53 +00:00
|
|
|
static bool short_press = false;
|
|
|
|
#endif
|
|
|
|
|
2011-03-24 18:42:27 +00:00
|
|
|
#define REPEAT_WINDOW_TICKS HZ/4
|
2007-06-04 13:52:02 +00:00
|
|
|
static int last_action_tick = 0;
|
|
|
|
|
2006-08-17 12:33:36 +00:00
|
|
|
/* software keylock stuff */
|
|
|
|
#ifndef HAS_BUTTON_HOLD
|
2006-12-12 07:55:17 +00:00
|
|
|
static bool keys_locked = false;
|
|
|
|
static int unlock_combo = BUTTON_NONE;
|
|
|
|
static bool screen_has_lock = false;
|
2006-08-17 12:33:36 +00:00
|
|
|
#endif /* HAVE_SOFTWARE_KEYLOCK */
|
|
|
|
|
2006-08-15 12:27:07 +00:00
|
|
|
/*
|
|
|
|
* do_button_check is the worker function for get_default_action.
|
|
|
|
* returns ACTION_UNKNOWN or the requested return value from the list.
|
|
|
|
*/
|
2006-12-12 07:55:17 +00:00
|
|
|
static inline int do_button_check(const struct button_mapping *items,
|
|
|
|
int button, int last_button, int *start)
|
2006-08-15 12:27:07 +00:00
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
int ret = ACTION_UNKNOWN;
|
|
|
|
|
|
|
|
while (items[i].button_code != BUTTON_NONE)
|
|
|
|
{
|
2008-01-21 09:48:44 +00:00
|
|
|
if (items[i].button_code == button)
|
2006-08-15 12:27:07 +00:00
|
|
|
{
|
2006-08-16 00:32:45 +00:00
|
|
|
if ((items[i].pre_button_code == BUTTON_NONE)
|
|
|
|
|| (items[i].pre_button_code == last_button))
|
2006-08-15 12:27:07 +00:00
|
|
|
{
|
|
|
|
ret = items[i].action_code;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
*start = i;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-10-05 17:53:45 +00:00
|
|
|
#if defined(HAVE_LCD_BITMAP) && !defined(BOOTLOADER)
|
|
|
|
/*
|
|
|
|
* button is horizontally inverted to support RTL language if the given language
|
|
|
|
* and context combination require that
|
|
|
|
*/
|
|
|
|
static int button_flip_horizontally(int context, int button)
|
|
|
|
{
|
|
|
|
int newbutton;
|
|
|
|
|
|
|
|
if (!(lang_is_rtl() && ((context == CONTEXT_STD) ||
|
2009-10-08 22:19:36 +00:00
|
|
|
(context == CONTEXT_TREE) || (context == CONTEXT_LIST) ||
|
|
|
|
(context == CONTEXT_MAINMENU))))
|
2009-10-05 17:53:45 +00:00
|
|
|
{
|
|
|
|
return button;
|
|
|
|
}
|
|
|
|
|
|
|
|
newbutton = button &
|
|
|
|
~(BUTTON_LEFT | BUTTON_RIGHT
|
2009-10-06 18:01:05 +00:00
|
|
|
#if defined(BUTTON_SCROLL_BACK) && defined(BUTTON_SCROLL_FWD) && \
|
|
|
|
!defined(SIMULATOR)
|
2009-10-05 17:53:45 +00:00
|
|
|
| BUTTON_SCROLL_BACK | BUTTON_SCROLL_FWD
|
2009-12-05 15:54:05 +00:00
|
|
|
#endif
|
|
|
|
#if defined(BUTTON_MINUS) && defined(BUTTON_PLUS) && \
|
|
|
|
!defined(SIMULATOR)
|
|
|
|
| BUTTON_MINUS | BUTTON_PLUS
|
2009-10-05 17:53:45 +00:00
|
|
|
#endif
|
|
|
|
);
|
|
|
|
|
|
|
|
if (button & BUTTON_LEFT)
|
|
|
|
newbutton |= BUTTON_RIGHT;
|
|
|
|
if (button & BUTTON_RIGHT)
|
|
|
|
newbutton |= BUTTON_LEFT;
|
2009-10-06 18:01:05 +00:00
|
|
|
#if defined(BUTTON_SCROLL_BACK) && defined(BUTTON_SCROLL_FWD) && \
|
|
|
|
!defined(SIMULATOR)
|
2009-10-05 17:53:45 +00:00
|
|
|
if (button & BUTTON_SCROLL_BACK)
|
|
|
|
newbutton |= BUTTON_SCROLL_FWD;
|
|
|
|
if (button & BUTTON_SCROLL_FWD)
|
|
|
|
newbutton |= BUTTON_SCROLL_BACK;
|
|
|
|
#endif
|
2009-12-05 15:54:05 +00:00
|
|
|
#if defined(BUTTON_MINUS) && defined(BUTTON_PLUS) && \
|
|
|
|
!defined(SIMULATOR)
|
|
|
|
if (button & BUTTON_MINUS)
|
|
|
|
newbutton |= BUTTON_PLUS;
|
|
|
|
if (button & BUTTON_PLUS)
|
|
|
|
newbutton |= BUTTON_MINUS;
|
|
|
|
#endif
|
2009-10-05 17:53:45 +00:00
|
|
|
|
|
|
|
return newbutton;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-12-12 07:55:17 +00:00
|
|
|
static inline int get_next_context(const struct button_mapping *items, int i)
|
2006-08-15 12:27:07 +00:00
|
|
|
{
|
|
|
|
while (items[i].button_code != BUTTON_NONE)
|
|
|
|
i++;
|
2008-01-21 09:48:44 +00:00
|
|
|
return (items[i].action_code == ACTION_NONE ) ?
|
|
|
|
CONTEXT_STD :
|
2006-08-15 12:27:07 +00:00
|
|
|
items[i].action_code;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* int get_action_worker(int context, struct button_mapping *user_mappings,
|
|
|
|
int timeout)
|
|
|
|
This function searches the button list for the given context for the just
|
|
|
|
pressed button.
|
|
|
|
If there is a match it returns the value from the list.
|
|
|
|
If there is no match..
|
|
|
|
the last item in the list "points" to the next context in a chain
|
|
|
|
so the "chain" is followed until the button is found.
|
|
|
|
putting ACTION_NONE will get CONTEXT_STD which is always the last list checked.
|
2008-01-21 09:48:44 +00:00
|
|
|
|
2006-08-15 12:27:07 +00:00
|
|
|
Timeout can be TIMEOUT_NOBLOCK to return immediatly
|
|
|
|
TIMEOUT_BLOCK to wait for a button press
|
2008-01-21 09:48:44 +00:00
|
|
|
Any number >0 to wait that many ticks for a press
|
2006-08-15 12:27:07 +00:00
|
|
|
*/
|
2006-12-12 07:55:17 +00:00
|
|
|
static int get_action_worker(int context, int timeout,
|
|
|
|
const struct button_mapping* (*get_context_map)(int) )
|
2006-08-15 12:27:07 +00:00
|
|
|
{
|
2006-08-16 00:32:45 +00:00
|
|
|
const struct button_mapping *items = NULL;
|
2006-08-15 12:27:07 +00:00
|
|
|
int button;
|
|
|
|
int i=0;
|
|
|
|
int ret = ACTION_UNKNOWN;
|
2007-07-22 06:05:53 +00:00
|
|
|
static int last_context = CONTEXT_STD;
|
2009-01-05 09:59:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
send_event(GUI_EVENT_ACTIONUPDATE, NULL);
|
2008-01-21 09:48:44 +00:00
|
|
|
|
2006-08-15 12:27:07 +00:00
|
|
|
if (timeout == TIMEOUT_NOBLOCK)
|
|
|
|
button = button_get(false);
|
|
|
|
else if (timeout == TIMEOUT_BLOCK)
|
|
|
|
button = button_get(true);
|
|
|
|
else
|
|
|
|
button = button_get_w_tmo(timeout);
|
|
|
|
|
2010-10-31 15:32:57 +00:00
|
|
|
/* Data from sys events can be pulled with button_get_data
|
|
|
|
* multimedia button presses don't go through the action system */
|
|
|
|
if (button == BUTTON_NONE || button & (SYS_EVENT|BUTTON_MULTIMEDIA))
|
2006-08-15 12:27:07 +00:00
|
|
|
return button;
|
2009-07-03 05:08:33 +00:00
|
|
|
/* Don't send any buttons through untill we see the release event */
|
|
|
|
if (wait_for_release)
|
|
|
|
{
|
|
|
|
if (button&BUTTON_REL)
|
|
|
|
{
|
2011-02-02 18:30:10 +00:00
|
|
|
/* remember the button for the below button eating on context
|
|
|
|
* change */
|
|
|
|
last_button = button;
|
2009-07-03 05:08:33 +00:00
|
|
|
wait_for_release = false;
|
|
|
|
}
|
|
|
|
return ACTION_NONE;
|
|
|
|
}
|
|
|
|
|
2008-01-21 09:48:44 +00:00
|
|
|
|
|
|
|
#if CONFIG_CODEC == SWCODEC
|
|
|
|
/* Produce keyclick */
|
2011-07-08 22:31:15 +00:00
|
|
|
keyclick_click(button);
|
2008-01-21 09:48:44 +00:00
|
|
|
#endif
|
|
|
|
|
2010-11-14 13:13:06 +00:00
|
|
|
if ((context != last_context) && ((last_button & BUTTON_REL) == 0)
|
|
|
|
#ifdef HAVE_SCROLLWHEEL
|
|
|
|
/* Scrollwheel doesn't generate release events */
|
|
|
|
&& !(last_button & (BUTTON_SCROLL_BACK | BUTTON_SCROLL_FWD))
|
|
|
|
#endif
|
|
|
|
)
|
2006-08-15 12:27:07 +00:00
|
|
|
{
|
2008-01-21 09:48:44 +00:00
|
|
|
if (button & BUTTON_REL)
|
2006-08-15 12:27:07 +00:00
|
|
|
{
|
2007-07-22 06:05:53 +00:00
|
|
|
last_button = button;
|
|
|
|
last_action = ACTION_NONE;
|
2006-08-15 12:27:07 +00:00
|
|
|
}
|
2007-07-22 06:05:53 +00:00
|
|
|
/* eat all buttons until the previous button was |BUTTON_REL
|
|
|
|
(also eat the |BUTTON_REL button) */
|
2006-08-17 09:28:04 +00:00
|
|
|
return ACTION_NONE; /* "safest" return value */
|
2006-08-15 12:27:07 +00:00
|
|
|
}
|
2007-07-22 06:05:53 +00:00
|
|
|
last_context = context;
|
2006-08-17 12:33:36 +00:00
|
|
|
#ifndef HAS_BUTTON_HOLD
|
2008-01-21 09:48:44 +00:00
|
|
|
screen_has_lock = ((context & ALLOW_SOFTLOCK) == ALLOW_SOFTLOCK);
|
2009-05-21 14:15:24 +00:00
|
|
|
if (screen_has_lock && keys_locked)
|
2006-08-15 12:27:07 +00:00
|
|
|
{
|
2008-01-21 09:48:44 +00:00
|
|
|
if (button == unlock_combo)
|
2006-08-17 12:33:36 +00:00
|
|
|
{
|
|
|
|
last_button = BUTTON_NONE;
|
|
|
|
keys_locked = false;
|
2008-08-15 08:27:39 +00:00
|
|
|
splash(HZ/2, str(LANG_KEYLOCK_OFF));
|
2006-08-17 12:33:36 +00:00
|
|
|
return ACTION_REDRAW;
|
2008-01-21 09:48:44 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
#if (BUTTON_REMOTE != 0)
|
|
|
|
if ((button & BUTTON_REMOTE) == 0)
|
2006-08-16 08:07:59 +00:00
|
|
|
#endif
|
2006-08-17 12:33:36 +00:00
|
|
|
{
|
2008-01-21 09:48:44 +00:00
|
|
|
if ((button & BUTTON_REL))
|
2008-08-15 08:27:39 +00:00
|
|
|
splash(HZ/2, str(LANG_KEYLOCK_ON));
|
2006-08-17 12:33:36 +00:00
|
|
|
return ACTION_REDRAW;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
context &= ~ALLOW_SOFTLOCK;
|
|
|
|
#endif /* HAS_BUTTON_HOLD */
|
2008-01-21 09:48:44 +00:00
|
|
|
|
2009-10-28 21:36:24 +00:00
|
|
|
#ifdef HAVE_TOUCHSCREEN
|
|
|
|
if (button & BUTTON_TOUCHSCREEN)
|
|
|
|
{
|
|
|
|
repeated = false;
|
|
|
|
short_press = false;
|
|
|
|
if (last_button & BUTTON_TOUCHSCREEN)
|
|
|
|
{
|
|
|
|
if ((button & BUTTON_REL) &&
|
|
|
|
((last_button & BUTTON_REPEAT)==0))
|
|
|
|
{
|
|
|
|
short_press = true;
|
|
|
|
}
|
|
|
|
else if (button & BUTTON_REPEAT)
|
|
|
|
repeated = true;
|
|
|
|
}
|
|
|
|
last_button = button;
|
|
|
|
return ACTION_TOUCHSCREEN;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-10-05 17:17:30 +00:00
|
|
|
#if defined(HAVE_LCD_BITMAP) && !defined(BOOTLOADER)
|
2009-10-05 17:53:45 +00:00
|
|
|
button = button_flip_horizontally(context, button);
|
2009-10-05 17:17:30 +00:00
|
|
|
#endif
|
|
|
|
|
2006-08-15 12:27:07 +00:00
|
|
|
/* logf("%x,%x",last_button,button); */
|
2009-02-03 10:55:30 +00:00
|
|
|
while (1)
|
2006-08-15 12:27:07 +00:00
|
|
|
{
|
|
|
|
/* logf("context = %x",context); */
|
|
|
|
#if (BUTTON_REMOTE != 0)
|
2008-01-21 09:48:44 +00:00
|
|
|
if (button & BUTTON_REMOTE)
|
2006-08-15 12:27:07 +00:00
|
|
|
context |= CONTEXT_REMOTE;
|
|
|
|
#endif
|
2009-05-31 17:47:56 +00:00
|
|
|
if ((context & CONTEXT_PLUGIN) && get_context_map)
|
2006-08-15 12:27:07 +00:00
|
|
|
items = get_context_map(context);
|
|
|
|
else
|
|
|
|
items = get_context_mapping(context);
|
2008-01-21 09:48:44 +00:00
|
|
|
|
2009-02-03 10:55:30 +00:00
|
|
|
if (items == NULL)
|
2006-08-21 11:28:29 +00:00
|
|
|
break;
|
2008-01-21 09:48:44 +00:00
|
|
|
|
2009-02-03 10:55:30 +00:00
|
|
|
ret = do_button_check(items,button,last_button,&i);
|
|
|
|
|
|
|
|
if (ret == ACTION_UNKNOWN)
|
2006-08-15 12:27:07 +00:00
|
|
|
{
|
|
|
|
context = get_next_context(items,i);
|
2009-02-03 10:55:30 +00:00
|
|
|
|
|
|
|
if (context != (int)CONTEXT_STOPSEARCHING)
|
|
|
|
{
|
|
|
|
i = 0;
|
|
|
|
continue;
|
|
|
|
}
|
2006-08-15 12:27:07 +00:00
|
|
|
}
|
2009-02-03 10:55:30 +00:00
|
|
|
|
|
|
|
/* Action was found or STOPSEARCHING was specified */
|
|
|
|
break;
|
|
|
|
}
|
2006-08-15 12:27:07 +00:00
|
|
|
/* DEBUGF("ret = %x\n",ret); */
|
2006-08-17 12:33:36 +00:00
|
|
|
#ifndef HAS_BUTTON_HOLD
|
|
|
|
if (screen_has_lock && (ret == ACTION_STD_KEYLOCK))
|
2008-01-21 09:48:44 +00:00
|
|
|
{
|
2006-08-17 12:33:36 +00:00
|
|
|
unlock_combo = button;
|
|
|
|
keys_locked = true;
|
2008-08-15 08:27:39 +00:00
|
|
|
splash(HZ/2, str(LANG_KEYLOCK_ON));
|
2008-01-21 09:48:44 +00:00
|
|
|
|
2006-08-17 12:33:36 +00:00
|
|
|
button_clear_queue();
|
|
|
|
return ACTION_REDRAW;
|
2006-08-15 12:27:07 +00:00
|
|
|
}
|
2006-08-17 12:33:36 +00:00
|
|
|
#endif
|
2008-01-21 09:48:44 +00:00
|
|
|
if ((current_tick - last_action_tick < REPEAT_WINDOW_TICKS)
|
2007-06-04 13:52:02 +00:00
|
|
|
&& (ret == last_action))
|
2007-03-04 07:45:12 +00:00
|
|
|
repeated = true;
|
2008-01-21 09:48:44 +00:00
|
|
|
else
|
2007-03-04 07:45:12 +00:00
|
|
|
repeated = false;
|
|
|
|
|
2006-08-15 12:27:07 +00:00
|
|
|
last_button = button;
|
2007-03-11 12:32:29 +00:00
|
|
|
last_action = ret;
|
2007-07-22 21:02:24 +00:00
|
|
|
last_data = button_get_data();
|
2007-06-04 13:52:02 +00:00
|
|
|
last_action_tick = current_tick;
|
2006-08-15 12:27:07 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int get_action(int context, int timeout)
|
|
|
|
{
|
2010-06-21 06:04:19 +00:00
|
|
|
int button = get_action_worker(context,timeout,NULL);
|
|
|
|
#ifdef HAVE_TOUCHSCREEN
|
|
|
|
if (button == ACTION_TOUCHSCREEN)
|
|
|
|
button = sb_touch_to_button(context);
|
|
|
|
#endif
|
|
|
|
return button;
|
2006-08-15 12:27:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int get_custom_action(int context,int timeout,
|
2006-08-16 00:32:45 +00:00
|
|
|
const struct button_mapping* (*get_context_map)(int))
|
2006-08-15 12:27:07 +00:00
|
|
|
{
|
|
|
|
return get_action_worker(context,timeout,get_context_map);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool action_userabort(int timeout)
|
|
|
|
{
|
|
|
|
int action = get_action_worker(CONTEXT_STD,timeout,NULL);
|
|
|
|
bool ret = (action == ACTION_STD_CANCEL);
|
2009-06-11 20:36:02 +00:00
|
|
|
if(!ret)
|
|
|
|
{
|
|
|
|
default_event_handler(action);
|
|
|
|
}
|
2006-08-15 12:27:07 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-08-17 12:33:36 +00:00
|
|
|
#ifndef HAS_BUTTON_HOLD
|
|
|
|
bool is_keys_locked(void)
|
2006-08-15 12:27:07 +00:00
|
|
|
{
|
2009-05-21 14:15:24 +00:00
|
|
|
return (screen_has_lock && keys_locked);
|
2006-08-15 12:27:07 +00:00
|
|
|
}
|
2006-08-17 12:33:36 +00:00
|
|
|
#endif
|
2007-03-04 07:45:12 +00:00
|
|
|
|
2007-07-22 21:02:24 +00:00
|
|
|
intptr_t get_action_data(void)
|
|
|
|
{
|
|
|
|
return last_data;
|
|
|
|
}
|
|
|
|
|
2007-03-04 07:45:12 +00:00
|
|
|
int get_action_statuscode(int *button)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
if (button)
|
|
|
|
*button = last_button;
|
|
|
|
|
2008-01-21 09:48:44 +00:00
|
|
|
if (last_button & BUTTON_REMOTE)
|
2007-03-04 07:45:12 +00:00
|
|
|
ret |= ACTION_REMOTE;
|
|
|
|
if (repeated)
|
|
|
|
ret |= ACTION_REPEAT;
|
|
|
|
return ret;
|
|
|
|
}
|
2007-10-22 12:26:53 +00:00
|
|
|
|
2008-08-23 09:46:38 +00:00
|
|
|
#ifdef HAVE_TOUCHSCREEN
|
2008-06-02 16:08:01 +00:00
|
|
|
/* return BUTTON_NONE on error
|
|
|
|
* BUTTON_REPEAT if repeated press
|
|
|
|
* BUTTON_REPEAT|BUTTON_REL if release after repeated press
|
2010-04-19 19:49:42 +00:00
|
|
|
* BUTTON_REL if it's a short press = release after press
|
2008-08-23 09:46:38 +00:00
|
|
|
* BUTTON_TOUCHSCREEN if press
|
2008-06-02 16:08:01 +00:00
|
|
|
*/
|
2008-08-23 09:46:38 +00:00
|
|
|
int action_get_touchscreen_press(short *x, short *y)
|
2007-10-22 12:26:53 +00:00
|
|
|
{
|
|
|
|
static int last_data = 0;
|
|
|
|
int data;
|
2008-08-23 09:46:38 +00:00
|
|
|
if ((last_button & BUTTON_TOUCHSCREEN) == 0)
|
2007-10-22 12:26:53 +00:00
|
|
|
return BUTTON_NONE;
|
|
|
|
data = button_get_data();
|
2008-01-21 09:48:44 +00:00
|
|
|
if (last_button & BUTTON_REL)
|
2007-10-22 12:26:53 +00:00
|
|
|
{
|
|
|
|
*x = (last_data&0xffff0000)>>16;
|
|
|
|
*y = (last_data&0xffff);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*x = (data&0xffff0000)>>16;
|
|
|
|
*y = (data&0xffff);
|
|
|
|
}
|
|
|
|
last_data = data;
|
|
|
|
if (repeated)
|
|
|
|
return BUTTON_REPEAT;
|
|
|
|
if (short_press)
|
|
|
|
return BUTTON_REL;
|
2008-06-02 16:08:01 +00:00
|
|
|
/* This is to return a BUTTON_REL after a BUTTON_REPEAT. */
|
2008-05-30 22:55:24 +00:00
|
|
|
if (last_button & BUTTON_REL)
|
2008-06-01 13:56:34 +00:00
|
|
|
return BUTTON_REPEAT|BUTTON_REL;
|
2008-08-23 09:46:38 +00:00
|
|
|
return BUTTON_TOUCHSCREEN;
|
2007-10-22 12:26:53 +00:00
|
|
|
}
|
2009-10-11 20:11:48 +00:00
|
|
|
|
|
|
|
int action_get_touchscreen_press_in_vp(short *x1, short *y1, struct viewport *vp)
|
|
|
|
{
|
|
|
|
short x, y;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = action_get_touchscreen_press(&x, &y);
|
|
|
|
|
|
|
|
if (ret != BUTTON_NONE && viewport_point_within_vp(vp, x, y))
|
|
|
|
{
|
|
|
|
*x1 = x - vp->x;
|
|
|
|
*y1 = y - vp->y;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
if (ret & BUTTON_TOUCHSCREEN)
|
|
|
|
return ACTION_UNKNOWN;
|
|
|
|
return BUTTON_NONE;
|
|
|
|
}
|
2007-10-22 12:26:53 +00:00
|
|
|
#endif
|
2009-07-03 05:08:33 +00:00
|
|
|
|
2010-05-04 21:02:32 +00:00
|
|
|
/* Don't let get_action*() return any ACTION_* values until the current buttons
|
|
|
|
* have been released. SYS_* and BUTTON_NONE will go through.
|
|
|
|
* Any actions relying on _RELEASE won't get seen.
|
2009-07-03 05:08:33 +00:00
|
|
|
*/
|
|
|
|
void action_wait_for_release(void)
|
|
|
|
{
|
|
|
|
wait_for_release = true;
|
|
|
|
}
|
|
|
|
|