2005-10-28 00:00:00 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
2005-10-30 01:24:35 +00:00
|
|
|
* Copyright (C) 2005 by Kevin Ferrare
|
2005-10-28 00:00:00 +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.
|
2005-10-28 00:00:00 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2010-05-06 21:04:40 +00:00
|
|
|
#include <stdarg.h>
|
2010-05-06 22:33:57 +00:00
|
|
|
#include <stdio.h>
|
2005-10-28 00:00:00 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include "lcd.h"
|
|
|
|
#include "font.h"
|
|
|
|
#include "button.h"
|
2006-08-15 08:14:46 +00:00
|
|
|
#include "string.h"
|
2005-10-28 00:00:00 +00:00
|
|
|
#include "settings.h"
|
|
|
|
#include "kernel.h"
|
2007-06-05 02:57:43 +00:00
|
|
|
#include "system.h"
|
2005-10-28 00:00:00 +00:00
|
|
|
|
2006-08-15 12:27:07 +00:00
|
|
|
#include "action.h"
|
2005-10-28 00:00:00 +00:00
|
|
|
#include "screen_access.h"
|
|
|
|
#include "list.h"
|
|
|
|
#include "scrollbar.h"
|
2007-03-05 00:32:33 +00:00
|
|
|
#include "lang.h"
|
2007-04-08 01:33:01 +00:00
|
|
|
#include "sound.h"
|
2007-05-30 18:08:29 +00:00
|
|
|
#include "misc.h"
|
2007-10-21 00:20:10 +00:00
|
|
|
#include "talk.h"
|
2008-03-05 09:58:30 +00:00
|
|
|
#include "viewport.h"
|
2009-09-07 17:37:06 +00:00
|
|
|
#include "appevents.h"
|
2010-02-26 03:45:41 +00:00
|
|
|
#include "statusbar-skinned.h"
|
2005-10-28 00:00:00 +00:00
|
|
|
|
2007-03-11 10:52:36 +00:00
|
|
|
/* The minimum number of pending button events in queue before starting
|
|
|
|
* to limit list drawing interval.
|
|
|
|
*/
|
|
|
|
#define FRAMEDROP_TRIGGER 6
|
|
|
|
|
2008-12-31 05:59:26 +00:00
|
|
|
void list_draw(struct screen *display, struct gui_synclist *list);
|
2008-03-05 09:58:30 +00:00
|
|
|
|
2011-10-07 17:22:49 +00:00
|
|
|
static long last_dirty_tick;
|
2009-09-07 17:37:06 +00:00
|
|
|
static struct viewport parent[NB_SCREENS];
|
|
|
|
|
2011-10-07 17:28:27 +00:00
|
|
|
static bool list_is_dirty(struct gui_synclist *list)
|
|
|
|
{
|
|
|
|
return TIME_BEFORE(list->dirty_tick, last_dirty_tick);
|
|
|
|
}
|
|
|
|
|
2014-03-14 22:15:16 +00:00
|
|
|
static void list_force_reinit(unsigned short id, void *param, void *last_dirty_tick)
|
2009-09-07 17:37:06 +00:00
|
|
|
{
|
2014-03-14 22:15:16 +00:00
|
|
|
(void)id;
|
2009-09-07 17:37:06 +00:00
|
|
|
(void)param;
|
2014-03-14 22:15:16 +00:00
|
|
|
*(int *)last_dirty_tick = current_tick;
|
2009-09-07 17:37:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void list_init(void)
|
|
|
|
{
|
2011-10-07 17:22:49 +00:00
|
|
|
last_dirty_tick = current_tick;
|
2014-03-14 22:15:16 +00:00
|
|
|
add_event_ex(GUI_EVENT_THEME_CHANGED, false, list_force_reinit, &last_dirty_tick);
|
2009-09-07 17:37:06 +00:00
|
|
|
}
|
|
|
|
|
2009-08-16 22:20:11 +00:00
|
|
|
static void list_init_viewports(struct gui_synclist *list)
|
2008-03-05 09:58:30 +00:00
|
|
|
{
|
2011-10-22 10:06:48 +00:00
|
|
|
bool parent_used = (*list->parent == &parent[SCREEN_MAIN]);
|
2009-09-07 17:37:06 +00:00
|
|
|
|
2011-10-22 10:06:48 +00:00
|
|
|
if (parent_used)
|
2008-03-05 09:58:30 +00:00
|
|
|
{
|
2009-08-16 22:20:11 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
2009-09-07 17:37:06 +00:00
|
|
|
{
|
2011-10-22 10:09:23 +00:00
|
|
|
gui_synclist_set_viewport_defaults(list->parent[i], i);
|
2009-09-07 17:37:06 +00:00
|
|
|
}
|
|
|
|
}
|
2011-10-07 17:31:15 +00:00
|
|
|
list->dirty_tick = current_tick;
|
2009-08-16 22:20:11 +00:00
|
|
|
}
|
|
|
|
|
2013-12-20 22:34:28 +00:00
|
|
|
static int list_nb_lines(struct gui_synclist *list, enum screen_type screen)
|
|
|
|
{
|
|
|
|
struct viewport *vp = list->parent[screen];
|
|
|
|
return vp->height / list->line_height[screen];
|
|
|
|
}
|
|
|
|
|
2009-08-16 22:20:11 +00:00
|
|
|
bool list_display_title(struct gui_synclist *list, enum screen_type screen)
|
|
|
|
{
|
2018-12-16 00:15:28 +00:00
|
|
|
return list->title != NULL &&
|
2010-02-26 06:45:50 +00:00
|
|
|
!sb_set_title_text(list->title, list->title_icon, screen) &&
|
2013-12-20 22:34:28 +00:00
|
|
|
list_nb_lines(list, screen) > 2;
|
2009-10-27 13:18:54 +00:00
|
|
|
}
|
|
|
|
|
2013-12-20 22:34:28 +00:00
|
|
|
int list_get_nb_lines(struct gui_synclist *list, enum screen_type screen)
|
2009-10-27 13:18:54 +00:00
|
|
|
{
|
2011-10-17 17:38:10 +00:00
|
|
|
int lines = skinlist_get_line_count(screen, list);
|
|
|
|
if (lines < 0)
|
|
|
|
{
|
2013-12-20 22:34:28 +00:00
|
|
|
lines = list_nb_lines(list, screen);
|
2011-10-17 17:38:10 +00:00
|
|
|
if (list_display_title(list, screen))
|
|
|
|
lines -= 1;
|
|
|
|
}
|
|
|
|
return lines;
|
2008-03-05 09:58:30 +00:00
|
|
|
}
|
2013-12-20 22:34:28 +00:00
|
|
|
|
|
|
|
void list_init_item_height(struct gui_synclist *list, enum screen_type screen)
|
|
|
|
{
|
|
|
|
struct viewport *vp = list->parent[screen];
|
|
|
|
#ifdef HAVE_TOUCHSCREEN
|
|
|
|
/* the 4/12 factor is designed for reasonable item size on a 160dpi screen */
|
|
|
|
if (global_settings.list_line_padding == -1)
|
|
|
|
list->line_height[screen] = MAX(lcd_get_dpi()*4/12, (int)font_get(vp->font)->height);
|
|
|
|
else
|
|
|
|
list->line_height[screen] = font_get(vp->font)->height + global_settings.list_line_padding;
|
|
|
|
#else
|
|
|
|
list->line_height[screen] = font_get(vp->font)->height;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-04-10 21:15:22 +00:00
|
|
|
void gui_synclist_init_display_settings(struct gui_synclist * list)
|
|
|
|
{
|
|
|
|
struct user_settings *gs = &global_settings;
|
|
|
|
list->scrollbar = gs->scrollbar;
|
|
|
|
list->show_icons = gs->show_icons;
|
|
|
|
list->scroll_paginated = gs->scroll_paginated;
|
|
|
|
list->keyclick = gs->keyclick;
|
|
|
|
list->talk_menu = gs->talk_menu;
|
|
|
|
list->wraparound = gs->list_wraparound;
|
|
|
|
list->cursor_style = gs->cursor_style;
|
|
|
|
}
|
|
|
|
|
2007-02-23 21:52:45 +00:00
|
|
|
/*
|
|
|
|
* Initializes a scrolling list
|
|
|
|
* - gui_list : the list structure to initialize
|
|
|
|
* - callback_get_item_name : pointer to a function that associates a label
|
|
|
|
* to a given item number
|
|
|
|
* - data : extra data passed to the list callback
|
2018-12-16 00:15:28 +00:00
|
|
|
* - scroll_all :
|
|
|
|
* - selected_size :
|
2008-03-26 03:35:24 +00:00
|
|
|
* - parent : the parent viewports to use. NULL means the full screen minus
|
|
|
|
* statusbar if enabled. NOTE: new screens should NOT set this to NULL.
|
2007-02-23 21:52:45 +00:00
|
|
|
*/
|
2007-12-17 02:37:21 +00:00
|
|
|
void gui_synclist_init(struct gui_synclist * gui_list,
|
2005-11-16 02:12:25 +00:00
|
|
|
list_get_name callback_get_item_name,
|
2006-07-02 12:28:27 +00:00
|
|
|
void * data,
|
|
|
|
bool scroll_all,
|
2008-03-26 03:35:24 +00:00
|
|
|
int selected_size, struct viewport list_parent[NB_SCREENS]
|
2005-10-29 02:33:19 +00:00
|
|
|
)
|
2005-10-28 00:00:00 +00:00
|
|
|
{
|
2005-11-16 17:23:49 +00:00
|
|
|
gui_list->callback_get_item_icon = NULL;
|
2005-10-28 00:00:00 +00:00
|
|
|
gui_list->callback_get_item_name = callback_get_item_name;
|
2007-10-21 00:20:10 +00:00
|
|
|
gui_list->callback_speak_item = NULL;
|
2021-12-15 05:37:04 +00:00
|
|
|
gui_list->callback_draw_item = NULL;
|
2008-03-05 09:58:30 +00:00
|
|
|
gui_list->nb_items = 0;
|
2005-10-28 00:00:00 +00:00
|
|
|
gui_list->selected_item = 0;
|
2022-04-10 21:15:22 +00:00
|
|
|
gui_synclist_init_display_settings(gui_list);
|
|
|
|
|
2021-08-22 00:46:28 +00:00
|
|
|
#ifdef HAVE_TOUCHSCREEN
|
|
|
|
gui_list->y_pos = 0;
|
|
|
|
#endif
|
2007-12-17 02:37:21 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
{
|
|
|
|
gui_list->start_item[i] = 0;
|
|
|
|
gui_list->offset_position[i] = 0;
|
2008-03-26 03:35:24 +00:00
|
|
|
if (list_parent)
|
|
|
|
gui_list->parent[i] = &list_parent[i];
|
|
|
|
else
|
2009-09-07 17:37:06 +00:00
|
|
|
gui_list->parent[i] = &parent[i];
|
2007-12-17 02:37:21 +00:00
|
|
|
}
|
2008-03-26 09:05:42 +00:00
|
|
|
list_init_viewports(gui_list);
|
2013-12-20 22:34:28 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
list_init_item_height(gui_list, i);
|
2009-10-27 13:18:54 +00:00
|
|
|
gui_list->data = data;
|
|
|
|
gui_list->scroll_all = scroll_all;
|
|
|
|
gui_list->selected_size = selected_size;
|
2006-08-15 08:14:46 +00:00
|
|
|
gui_list->title = NULL;
|
2007-04-16 09:14:36 +00:00
|
|
|
gui_list->title_icon = Icon_NOICON;
|
2007-03-11 10:52:36 +00:00
|
|
|
|
2007-10-21 00:20:10 +00:00
|
|
|
gui_list->scheduled_talk_tick = gui_list->last_talked_tick = 0;
|
2011-10-07 17:22:49 +00:00
|
|
|
gui_list->dirty_tick = current_tick;
|
2007-06-17 21:16:34 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_LCD_COLOR
|
|
|
|
gui_list->title_color = -1;
|
|
|
|
gui_list->callback_get_item_color = NULL;
|
2019-11-02 11:15:01 +00:00
|
|
|
gui_list->selection_color = NULL;
|
2007-06-17 21:16:34 +00:00
|
|
|
#endif
|
2007-06-07 12:14:31 +00:00
|
|
|
}
|
|
|
|
|
2008-12-31 05:59:26 +00:00
|
|
|
int gui_list_get_item_offset(struct gui_synclist * gui_list,
|
|
|
|
int item_width,
|
|
|
|
int text_pos,
|
|
|
|
struct screen * display,
|
|
|
|
struct viewport *vp)
|
2006-08-23 20:02:06 +00:00
|
|
|
{
|
|
|
|
int item_offset;
|
2007-03-11 10:52:36 +00:00
|
|
|
|
2022-09-19 10:38:09 +00:00
|
|
|
if (global_settings.offset_out_of_view)
|
2006-08-23 20:02:06 +00:00
|
|
|
{
|
2007-12-17 02:37:21 +00:00
|
|
|
item_offset = gui_list->offset_position[display->screen_type];
|
2006-08-23 20:02:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-10-27 13:18:54 +00:00
|
|
|
/* if text is smaller than view */
|
2008-03-05 09:58:30 +00:00
|
|
|
if (item_width <= vp->width - text_pos)
|
2006-08-23 20:02:06 +00:00
|
|
|
{
|
|
|
|
item_offset = 0;
|
|
|
|
}
|
2009-10-27 13:18:54 +00:00
|
|
|
/* if text got out of view */
|
|
|
|
else if (gui_list->offset_position[display->screen_type] >
|
2008-03-05 09:58:30 +00:00
|
|
|
item_width - (vp->width - text_pos))
|
2009-10-27 13:18:54 +00:00
|
|
|
{
|
|
|
|
item_offset = item_width - (vp->width - text_pos);
|
2006-08-23 20:02:06 +00:00
|
|
|
}
|
2009-10-27 13:18:54 +00:00
|
|
|
else
|
|
|
|
item_offset = gui_list->offset_position[display->screen_type];
|
2006-08-23 20:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return item_offset;
|
|
|
|
}
|
2009-10-27 13:18:54 +00:00
|
|
|
|
2007-03-11 10:52:36 +00:00
|
|
|
/*
|
|
|
|
* Force a full screen update.
|
|
|
|
*/
|
2007-12-17 02:37:21 +00:00
|
|
|
void gui_synclist_draw(struct gui_synclist *gui_list)
|
2007-03-11 10:52:36 +00:00
|
|
|
{
|
2011-10-07 17:28:27 +00:00
|
|
|
if (list_is_dirty(gui_list))
|
2007-12-17 02:37:21 +00:00
|
|
|
{
|
2008-03-26 09:05:42 +00:00
|
|
|
list_init_viewports(gui_list);
|
2013-12-20 22:34:28 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
list_init_item_height(gui_list, i);
|
2008-10-13 12:16:06 +00:00
|
|
|
gui_synclist_select_item(gui_list, gui_list->selected_item);
|
2008-03-09 09:37:39 +00:00
|
|
|
}
|
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
{
|
Lists can now be completly draw using the skin engine!
due to lack of user feedback the actual tags may change, hopefully not though.
The way it works is the skin specifies a rectangle and a viewport label. For each item in the list that is being displayed all viewports with the specified label are drawn. However, instead of the viewport x/y position being offset from the top left corner like normal they are offset from the rectangle position in the list (so think of them as child-viewports of the rectangle which moves).
Normally the rectangle will move down the screen to show a normal list, this can be changed to move across the screen in a grid pattern.
The UI viewport is used to bound the items (i.e %Vi() )
Scrolling is completly disabled in all items except the currently selected item.
This works well in combination with the %cs tag to show differently styled lists based on the current screen :)
New tags:
%LT - Get the current items text
%LI - Get the current items icon number
%Lc - Use as a conditional to determine if the current item is the selected item
%LB - BAR TAG to show the scroll bar, params/options like other bar types. It still needs a bit of work though. Use as a conditional to find out if the bar is actually needed
%Lb(viewport, width, height [,tile]) - specify the viewport label to draw for each item and the size of each item. if the last param is 'tile' it will form a grid instead of a list
example.sbs:
%?cs<%Lb(a,100,20)|>
%V(0,0,10,-,1)%Vf(aabbcc)
%?LB<%LB(0,0,10,185, invert)>
%Vi(-,10,0,-,-35,1)
%Vl(a,5,5,160,12,1)
%s%?Lc<%Vg(00ffaa, ff0000, 000000)%Vs(gradient)%>%>%>%ac>zzzzzzz %LT zzzzz%s%?Lc<%ar%<%<%<>
%V(0,185,-,-,1)
%s%LT
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30461 a1c6a512-1295-4272-9138-f99709370657
2011-09-06 13:49:41 +00:00
|
|
|
if (!skinlist_draw(&screens[i], gui_list))
|
|
|
|
list_draw(&screens[i], gui_list);
|
2007-12-17 02:37:21 +00:00
|
|
|
}
|
2007-03-11 10:52:36 +00:00
|
|
|
}
|
|
|
|
|
2007-12-17 02:37:21 +00:00
|
|
|
/* sets up the list so the selection is shown correctly on the screen */
|
|
|
|
static void gui_list_put_selection_on_screen(struct gui_synclist * gui_list,
|
|
|
|
enum screen_type screen)
|
2007-03-11 10:52:36 +00:00
|
|
|
{
|
2009-10-27 13:18:54 +00:00
|
|
|
int nb_lines = list_get_nb_lines(gui_list, screen);
|
|
|
|
int bottom = MAX(0, gui_list->nb_items - nb_lines);
|
|
|
|
int new_start_item = gui_list->start_item[screen];
|
2007-12-17 02:37:21 +00:00
|
|
|
int difference = gui_list->selected_item - gui_list->start_item[screen];
|
2010-01-07 12:51:57 +00:00
|
|
|
const int scroll_limit_up = (nb_lines < gui_list->selected_size+2 ? 0:1);
|
|
|
|
const int scroll_limit_down = (scroll_limit_up+gui_list->selected_size);
|
2009-10-27 13:18:54 +00:00
|
|
|
|
2022-09-19 10:10:54 +00:00
|
|
|
if (gui_list->selected_size >= nb_lines)
|
2007-03-11 10:52:36 +00:00
|
|
|
{
|
2010-01-07 12:51:57 +00:00
|
|
|
new_start_item = gui_list->selected_item;
|
2007-06-05 02:57:43 +00:00
|
|
|
}
|
2022-04-10 21:15:22 +00:00
|
|
|
else if (gui_list->scroll_paginated)
|
2007-06-05 02:57:43 +00:00
|
|
|
{
|
2010-01-07 12:51:57 +00:00
|
|
|
nb_lines -= nb_lines%gui_list->selected_size;
|
|
|
|
if (difference < 0 || difference >= nb_lines)
|
2007-03-11 10:52:36 +00:00
|
|
|
{
|
2010-01-07 12:51:57 +00:00
|
|
|
new_start_item = gui_list->selected_item -
|
|
|
|
(gui_list->selected_item%nb_lines);
|
2007-03-11 10:52:36 +00:00
|
|
|
}
|
|
|
|
}
|
2010-01-07 12:51:57 +00:00
|
|
|
else if (difference <= scroll_limit_up) /* list moved up */
|
2007-06-07 12:14:31 +00:00
|
|
|
{
|
2010-01-07 12:51:57 +00:00
|
|
|
new_start_item = gui_list->selected_item - scroll_limit_up;
|
|
|
|
}
|
|
|
|
else if (difference > nb_lines - scroll_limit_down) /* list moved down */
|
|
|
|
{
|
|
|
|
new_start_item = gui_list->selected_item + scroll_limit_down - nb_lines;
|
2005-10-28 00:00:00 +00:00
|
|
|
}
|
2009-10-27 13:18:54 +00:00
|
|
|
if (new_start_item < 0)
|
|
|
|
gui_list->start_item[screen] = 0;
|
|
|
|
else if (new_start_item > bottom)
|
|
|
|
gui_list->start_item[screen] = bottom;
|
|
|
|
else
|
|
|
|
gui_list->start_item[screen] = new_start_item;
|
2021-08-22 00:46:28 +00:00
|
|
|
#ifdef HAVE_TOUCHSCREEN
|
|
|
|
gui_list->y_pos = gui_list->start_item[SCREEN_MAIN] * gui_list->line_height[SCREEN_MAIN];
|
|
|
|
#endif
|
2007-12-17 02:37:21 +00:00
|
|
|
}
|
2009-10-27 13:18:54 +00:00
|
|
|
|
2018-12-16 00:15:28 +00:00
|
|
|
static void edge_beep(struct gui_synclist * gui_list, bool wrap)
|
|
|
|
{
|
2022-04-10 21:15:22 +00:00
|
|
|
if (gui_list->keyclick)
|
2018-12-16 00:15:28 +00:00
|
|
|
{
|
|
|
|
list_speak_item *cb = gui_list->callback_speak_item;
|
|
|
|
if (!wrap) /* a bounce */
|
|
|
|
{
|
|
|
|
static long last_bounce_tick = 0;
|
|
|
|
if(TIME_BEFORE(current_tick, last_bounce_tick+HZ/4))
|
|
|
|
return;
|
|
|
|
last_bounce_tick = current_tick;
|
|
|
|
}
|
|
|
|
/* Next thing the list code will do is go speak the item, doing
|
|
|
|
a talk_shutup() first. Shutup now so the beep is clearer, and
|
|
|
|
make sure the subsequent shutup is skipped because otherwise
|
|
|
|
it'd kill the pcm buffer. */
|
|
|
|
if (cb) {
|
|
|
|
talk_shutup();
|
|
|
|
talk_force_enqueue_next();
|
|
|
|
}
|
|
|
|
system_sound_play(wrap ? SOUND_LIST_EDGE_BEEP_WRAP : SOUND_LIST_EDGE_BEEP_NOWRAP);
|
|
|
|
if (cb) {
|
|
|
|
/* On at least x5: if, instead of the above shutup, I insert a
|
|
|
|
sleep just after the beep_play() call, to delay the subsequent
|
|
|
|
shutup and talk, then in some cases the beep is not played: if
|
|
|
|
the end of a previous utterance is still playing from the pcm buf,
|
|
|
|
the beep fails, even if there would seem to remain enough time
|
|
|
|
to the utterance to mix in the beep. */
|
|
|
|
|
|
|
|
/* Somehow, the following voice utterance is suppressed on e200,
|
|
|
|
but not on x5. Work around... */
|
|
|
|
sleep((40*HZ +999)/1000); // FIXME: Is this really needed?
|
|
|
|
talk_force_shutup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-15 07:08:35 +00:00
|
|
|
static void _gui_synclist_speak_item(struct gui_synclist *lists)
|
|
|
|
{
|
|
|
|
list_speak_item *cb = lists->callback_speak_item;
|
|
|
|
if (cb && lists->nb_items != 0)
|
|
|
|
{
|
|
|
|
talk_shutup();
|
|
|
|
/* If we have just very recently started talking, then we want
|
|
|
|
to stay silent for a while until things settle. Likewise if
|
|
|
|
we already had a pending scheduled announcement not yet due
|
|
|
|
we need to reschedule it. */
|
2018-12-16 00:15:28 +00:00
|
|
|
if ((lists->scheduled_talk_tick &&
|
2010-06-15 07:08:35 +00:00
|
|
|
TIME_BEFORE(current_tick, lists->scheduled_talk_tick)) ||
|
2018-12-16 00:15:28 +00:00
|
|
|
(lists->last_talked_tick &&
|
2010-06-15 07:08:35 +00:00
|
|
|
TIME_BEFORE(current_tick, lists->last_talked_tick + HZ/5)))
|
|
|
|
{
|
|
|
|
lists->scheduled_talk_tick = current_tick + HZ/5;
|
2018-12-16 00:15:28 +00:00
|
|
|
}
|
2010-06-15 07:08:35 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
lists->scheduled_talk_tick = 0; /* work done */
|
|
|
|
cb(lists->selected_item, lists->data);
|
|
|
|
lists->last_talked_tick = current_tick;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void gui_synclist_speak_item(struct gui_synclist *lists)
|
|
|
|
{
|
2022-04-10 21:15:22 +00:00
|
|
|
if (lists->talk_menu)
|
2010-06-15 07:08:35 +00:00
|
|
|
{
|
|
|
|
if (lists->nb_items == 0)
|
|
|
|
talk_id(VOICE_EMPTY_LIST, true);
|
|
|
|
else
|
|
|
|
_gui_synclist_speak_item(lists);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-17 02:37:21 +00:00
|
|
|
/*
|
|
|
|
* Selects an item in the list
|
|
|
|
* - gui_list : the list structure
|
|
|
|
* - item_number : the number of the item which will be selected
|
|
|
|
*/
|
|
|
|
void gui_synclist_select_item(struct gui_synclist * gui_list, int item_number)
|
|
|
|
{
|
2009-10-27 13:18:54 +00:00
|
|
|
if (item_number >= gui_list->nb_items || item_number < 0)
|
2007-12-17 02:37:21 +00:00
|
|
|
return;
|
2010-06-15 07:08:35 +00:00
|
|
|
if (item_number != gui_list->selected_item)
|
|
|
|
{
|
|
|
|
gui_list->selected_item = item_number;
|
|
|
|
_gui_synclist_speak_item(gui_list);
|
|
|
|
}
|
2007-12-17 02:37:21 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
gui_list_put_selection_on_screen(gui_list, i);
|
2007-06-05 02:57:43 +00:00
|
|
|
}
|
|
|
|
|
2007-12-17 02:37:21 +00:00
|
|
|
static void gui_list_select_at_offset(struct gui_synclist * gui_list,
|
2022-09-19 12:12:14 +00:00
|
|
|
int offset, bool allow_wrap)
|
2007-06-05 02:57:43 +00:00
|
|
|
{
|
2008-01-21 22:28:25 +00:00
|
|
|
int new_selection;
|
2007-06-05 02:57:43 +00:00
|
|
|
if (gui_list->selected_size > 1)
|
|
|
|
{
|
|
|
|
offset *= gui_list->selected_size;
|
|
|
|
}
|
2010-01-07 12:51:57 +00:00
|
|
|
|
2008-01-21 22:28:25 +00:00
|
|
|
new_selection = gui_list->selected_item + offset;
|
2010-01-07 12:51:57 +00:00
|
|
|
|
2007-12-17 02:37:21 +00:00
|
|
|
if (new_selection >= gui_list->nb_items)
|
2007-06-09 09:41:13 +00:00
|
|
|
{
|
2022-09-19 12:12:14 +00:00
|
|
|
new_selection = allow_wrap ? 0 : gui_list->nb_items - gui_list->selected_size;
|
|
|
|
edge_beep(gui_list, allow_wrap);
|
2007-06-09 09:41:13 +00:00
|
|
|
}
|
2007-12-17 02:37:21 +00:00
|
|
|
else if (new_selection < 0)
|
|
|
|
{
|
2022-09-19 12:12:14 +00:00
|
|
|
new_selection = allow_wrap ? gui_list->nb_items - gui_list->selected_size : 0;
|
|
|
|
edge_beep(gui_list, allow_wrap);
|
2007-12-17 02:37:21 +00:00
|
|
|
}
|
2021-08-22 00:46:28 +00:00
|
|
|
|
2010-06-15 07:08:35 +00:00
|
|
|
gui_synclist_select_item(gui_list, new_selection);
|
2005-10-28 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2007-02-23 21:52:45 +00:00
|
|
|
/*
|
|
|
|
* Adds an item to the list (the callback will be asked for one more item)
|
|
|
|
* - gui_list : the list structure
|
|
|
|
*/
|
2007-12-17 02:37:21 +00:00
|
|
|
void gui_synclist_add_item(struct gui_synclist * gui_list)
|
2005-10-28 00:00:00 +00:00
|
|
|
{
|
2005-10-29 02:33:19 +00:00
|
|
|
gui_list->nb_items++;
|
2005-10-28 00:00:00 +00:00
|
|
|
/* if only one item in the list, select it */
|
2009-10-27 13:18:54 +00:00
|
|
|
if (gui_list->nb_items == 1)
|
2005-10-28 00:00:00 +00:00
|
|
|
gui_list->selected_item = 0;
|
|
|
|
}
|
|
|
|
|
2007-02-23 21:52:45 +00:00
|
|
|
/*
|
|
|
|
* Removes an item to the list (the callback will be asked for one less item)
|
|
|
|
* - gui_list : the list structure
|
|
|
|
*/
|
2007-12-17 02:37:21 +00:00
|
|
|
void gui_synclist_del_item(struct gui_synclist * gui_list)
|
2005-10-28 00:00:00 +00:00
|
|
|
{
|
2009-10-27 13:18:54 +00:00
|
|
|
if (gui_list->nb_items > 0)
|
2005-10-28 00:00:00 +00:00
|
|
|
{
|
2007-12-17 02:37:21 +00:00
|
|
|
if (gui_list->selected_item == gui_list->nb_items-1)
|
2005-10-29 02:33:19 +00:00
|
|
|
gui_list->selected_item--;
|
|
|
|
gui_list->nb_items--;
|
2008-03-05 09:58:30 +00:00
|
|
|
gui_synclist_select_item(gui_list, gui_list->selected_item);
|
2005-10-28 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-27 13:18:54 +00:00
|
|
|
/*
|
2007-02-23 21:52:45 +00:00
|
|
|
* Set the title and title icon of the list. Setting title to NULL disables
|
|
|
|
* both the title and icon. Use NOICON if there is no icon.
|
|
|
|
*/
|
2009-10-27 13:18:54 +00:00
|
|
|
void gui_synclist_set_title(struct gui_synclist * gui_list,
|
2022-09-18 19:07:12 +00:00
|
|
|
const char * title, enum themable_icons icon)
|
2006-08-15 08:14:46 +00:00
|
|
|
{
|
|
|
|
gui_list->title = title;
|
2006-08-23 20:02:06 +00:00
|
|
|
gui_list->title_icon = icon;
|
2010-02-26 03:45:41 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
sb_set_title_text(title, icon, i);
|
|
|
|
send_event(GUI_EVENT_ACTIONUPDATE, (void*)1);
|
2006-08-15 08:14:46 +00:00
|
|
|
}
|
2006-08-15 12:23:55 +00:00
|
|
|
|
2005-10-28 00:00:00 +00:00
|
|
|
void gui_synclist_set_nb_items(struct gui_synclist * lists, int nb_items)
|
|
|
|
{
|
2007-12-17 02:37:21 +00:00
|
|
|
lists->nb_items = nb_items;
|
2005-11-09 22:47:15 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
2005-10-28 00:00:00 +00:00
|
|
|
{
|
2007-12-17 02:37:21 +00:00
|
|
|
lists->offset_position[i] = 0;
|
2005-10-28 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
2006-04-03 08:51:08 +00:00
|
|
|
int gui_synclist_get_nb_items(struct gui_synclist * lists)
|
|
|
|
{
|
2007-12-17 02:37:21 +00:00
|
|
|
return lists->nb_items;
|
2006-04-03 08:51:08 +00:00
|
|
|
}
|
|
|
|
int gui_synclist_get_sel_pos(struct gui_synclist * lists)
|
|
|
|
{
|
2007-12-17 02:37:21 +00:00
|
|
|
return lists->selected_item;
|
2006-04-03 08:51:08 +00:00
|
|
|
}
|
2006-12-09 10:02:09 +00:00
|
|
|
void gui_synclist_set_icon_callback(struct gui_synclist * lists,
|
|
|
|
list_get_icon icon_callback)
|
2005-11-16 17:23:49 +00:00
|
|
|
{
|
2007-12-17 02:37:21 +00:00
|
|
|
lists->callback_get_item_icon = icon_callback;
|
2005-11-16 17:23:49 +00:00
|
|
|
}
|
2005-10-28 00:00:00 +00:00
|
|
|
|
2007-10-21 00:20:10 +00:00
|
|
|
void gui_synclist_set_voice_callback(struct gui_synclist * lists,
|
2009-10-27 13:18:54 +00:00
|
|
|
list_speak_item voice_callback)
|
2007-10-21 00:20:10 +00:00
|
|
|
{
|
2007-12-17 02:37:21 +00:00
|
|
|
lists->callback_speak_item = voice_callback;
|
2005-10-28 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2011-10-22 10:09:23 +00:00
|
|
|
void gui_synclist_set_viewport_defaults(struct viewport *vp,
|
|
|
|
enum screen_type screen)
|
|
|
|
{
|
2011-10-23 11:05:27 +00:00
|
|
|
viewport_set_defaults(vp, screen);
|
2011-10-22 10:09:23 +00:00
|
|
|
}
|
|
|
|
|
2008-03-05 09:58:30 +00:00
|
|
|
#ifdef HAVE_LCD_COLOR
|
|
|
|
void gui_synclist_set_color_callback(struct gui_synclist * lists,
|
2009-10-27 13:18:54 +00:00
|
|
|
list_get_color color_callback)
|
2008-03-05 09:58:30 +00:00
|
|
|
{
|
|
|
|
lists->callback_get_item_color = color_callback;
|
|
|
|
}
|
2019-11-02 11:15:01 +00:00
|
|
|
|
|
|
|
void gui_synclist_set_sel_color(struct gui_synclist * lists,
|
|
|
|
struct list_selection_color *list_sel_color)
|
|
|
|
{
|
|
|
|
lists->selection_color = list_sel_color;
|
|
|
|
if(list_sel_color)
|
|
|
|
{
|
|
|
|
FOR_NB_SCREENS(i) /* might need to be only SCREEN_MAIN */
|
|
|
|
{
|
|
|
|
lists->parent[i]->fg_pattern = list_sel_color->fg_color;
|
|
|
|
lists->parent[i]->bg_pattern = list_sel_color->bg_color;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
list_init_viewports(lists);
|
|
|
|
}
|
2008-03-05 09:58:30 +00:00
|
|
|
#endif
|
|
|
|
|
2007-02-23 21:52:45 +00:00
|
|
|
static void gui_synclist_select_next_page(struct gui_synclist * lists,
|
2022-09-19 12:12:14 +00:00
|
|
|
enum screen_type screen,
|
|
|
|
bool allow_wrap)
|
2005-10-28 00:00:00 +00:00
|
|
|
{
|
2009-10-27 13:18:54 +00:00
|
|
|
int nb_lines = list_get_nb_lines(lists, screen);
|
2010-01-07 12:51:57 +00:00
|
|
|
if (lists->selected_size > 1)
|
|
|
|
nb_lines = MAX(1, nb_lines/lists->selected_size);
|
2022-09-19 12:12:14 +00:00
|
|
|
|
|
|
|
gui_list_select_at_offset(lists, nb_lines, allow_wrap);
|
2005-10-28 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2007-02-23 21:52:45 +00:00
|
|
|
static void gui_synclist_select_previous_page(struct gui_synclist * lists,
|
2022-09-19 12:12:14 +00:00
|
|
|
enum screen_type screen,
|
|
|
|
bool allow_wrap)
|
2005-10-28 00:00:00 +00:00
|
|
|
{
|
2009-10-27 13:18:54 +00:00
|
|
|
int nb_lines = list_get_nb_lines(lists, screen);
|
2010-01-07 12:51:57 +00:00
|
|
|
if (lists->selected_size > 1)
|
|
|
|
nb_lines = MAX(1, nb_lines/lists->selected_size);
|
2022-09-19 12:12:14 +00:00
|
|
|
|
|
|
|
gui_list_select_at_offset(lists, -nb_lines, allow_wrap);
|
2005-10-28 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2007-12-17 02:37:21 +00:00
|
|
|
/*
|
|
|
|
* Makes all the item in the list scroll by one step to the right.
|
2018-12-16 00:15:28 +00:00
|
|
|
* Should stop increasing the value when reaching the widest item value
|
2007-12-17 02:37:21 +00:00
|
|
|
* in the list.
|
|
|
|
*/
|
2007-02-23 21:52:45 +00:00
|
|
|
static void gui_synclist_scroll_right(struct gui_synclist * lists)
|
2006-01-22 04:24:26 +00:00
|
|
|
{
|
|
|
|
FOR_NB_SCREENS(i)
|
2007-12-17 02:37:21 +00:00
|
|
|
{
|
|
|
|
/* FIXME: This is a fake right boundry limiter. there should be some
|
|
|
|
* callback function to find the longest item on the list in pixels,
|
|
|
|
* to stop the list from scrolling past that point */
|
2022-09-19 10:38:09 +00:00
|
|
|
lists->offset_position[i] += global_settings.screen_scroll_step;
|
2007-12-17 02:37:21 +00:00
|
|
|
if (lists->offset_position[i] > 1000)
|
|
|
|
lists->offset_position[i] = 1000;
|
|
|
|
}
|
2006-01-22 04:24:26 +00:00
|
|
|
}
|
|
|
|
|
2007-12-17 02:37:21 +00:00
|
|
|
/*
|
|
|
|
* Makes all the item in the list scroll by one step to the left.
|
|
|
|
* stops at starting position.
|
|
|
|
*/
|
2007-02-23 21:52:45 +00:00
|
|
|
static void gui_synclist_scroll_left(struct gui_synclist * lists)
|
2006-01-22 04:24:26 +00:00
|
|
|
{
|
|
|
|
FOR_NB_SCREENS(i)
|
2007-12-17 02:37:21 +00:00
|
|
|
{
|
2022-09-19 10:38:09 +00:00
|
|
|
lists->offset_position[i] -= global_settings.screen_scroll_step;
|
2007-12-17 02:37:21 +00:00
|
|
|
if (lists->offset_position[i] < 0)
|
|
|
|
lists->offset_position[i] = 0;
|
|
|
|
}
|
2006-01-22 04:24:26 +00:00
|
|
|
}
|
|
|
|
|
2012-01-12 11:28:36 +00:00
|
|
|
bool gui_synclist_keyclick_callback(int action, void* data)
|
|
|
|
{
|
|
|
|
struct gui_synclist *lists = (struct gui_synclist *)data;
|
|
|
|
|
2022-09-19 12:12:14 +00:00
|
|
|
/* Block the beep if we're at the end of the list and we're not wrapping. */
|
2012-01-12 11:28:36 +00:00
|
|
|
if (lists->selected_item == 0)
|
2022-09-19 12:12:14 +00:00
|
|
|
{
|
|
|
|
if (action == ACTION_STD_PREVREPEAT)
|
|
|
|
return false;
|
|
|
|
if (action == ACTION_STD_PREV && !lists->wraparound)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-01-12 11:28:36 +00:00
|
|
|
if (lists->selected_item == lists->nb_items - lists->selected_size)
|
2022-09-19 12:12:14 +00:00
|
|
|
{
|
|
|
|
if (action == ACTION_STD_NEXTREPEAT)
|
|
|
|
return false;
|
|
|
|
if (action == ACTION_STD_NEXT && !lists->wraparound)
|
|
|
|
return false;
|
|
|
|
}
|
2012-01-12 11:28:36 +00:00
|
|
|
|
|
|
|
return action != ACTION_NONE;
|
|
|
|
}
|
2010-10-31 11:11:46 +00:00
|
|
|
|
2012-03-20 10:27:33 +00:00
|
|
|
/*
|
|
|
|
* Magic to make sure the list gets updated correctly if the skin does
|
|
|
|
* something naughty like a full screen update when we are in a button
|
|
|
|
* loop.
|
|
|
|
*
|
|
|
|
* The GUI_EVENT_NEED_UI_UPDATE event is registered for in list_do_action_timeout()
|
|
|
|
* and unregistered in gui_synclict_do_button(). This is done because
|
|
|
|
* if something is using the list UI they *must* be calling those
|
|
|
|
* two functions in the correct order or the list wont work.
|
|
|
|
*/
|
|
|
|
static struct gui_synclist *current_lists;
|
|
|
|
static bool ui_update_event_registered = false;
|
2014-03-14 22:15:16 +00:00
|
|
|
static void _lists_uiviewport_update_callback(unsigned short id, void *data)
|
2012-03-20 10:27:33 +00:00
|
|
|
{
|
2014-03-14 22:15:16 +00:00
|
|
|
(void)id;
|
2012-03-20 10:27:33 +00:00
|
|
|
(void)data;
|
|
|
|
if (current_lists)
|
|
|
|
gui_synclist_draw(current_lists);
|
|
|
|
}
|
|
|
|
|
2022-09-19 11:48:15 +00:00
|
|
|
bool gui_synclist_do_button(struct gui_synclist * lists, int *actionptr)
|
2005-10-28 00:00:00 +00:00
|
|
|
{
|
2007-09-17 10:08:50 +00:00
|
|
|
int action = *actionptr;
|
2015-10-20 22:11:44 +00:00
|
|
|
static bool pgleft_allow_cancel = false;
|
2007-07-22 21:02:24 +00:00
|
|
|
|
2009-03-02 19:25:50 +00:00
|
|
|
#ifdef HAVE_WHEEL_ACCELERATION
|
2007-11-19 11:05:54 +00:00
|
|
|
int next_item_modifier = button_apply_acceleration(get_action_data());
|
2007-07-22 21:02:24 +00:00
|
|
|
#else
|
2007-05-27 15:08:56 +00:00
|
|
|
static int next_item_modifier = 1;
|
|
|
|
static int last_accel_tick = 0;
|
|
|
|
|
2010-10-31 11:11:46 +00:00
|
|
|
if (action != ACTION_TOUCHSCREEN)
|
|
|
|
{
|
|
|
|
if (global_settings.list_accel_start_delay)
|
2007-05-27 15:08:56 +00:00
|
|
|
{
|
2011-03-22 21:29:05 +00:00
|
|
|
int start_delay = global_settings.list_accel_start_delay * HZ;
|
|
|
|
int accel_wait = global_settings.list_accel_wait * HZ;
|
2010-10-31 11:11:46 +00:00
|
|
|
|
|
|
|
if (get_action_statuscode(NULL)&ACTION_REPEAT)
|
2007-05-27 15:08:56 +00:00
|
|
|
{
|
2010-10-31 11:11:46 +00:00
|
|
|
if (!last_accel_tick)
|
|
|
|
last_accel_tick = current_tick + start_delay;
|
|
|
|
else if (TIME_AFTER(current_tick, last_accel_tick + accel_wait))
|
|
|
|
{
|
|
|
|
last_accel_tick = current_tick;
|
|
|
|
next_item_modifier++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (last_accel_tick)
|
|
|
|
{
|
|
|
|
next_item_modifier = 1;
|
|
|
|
last_accel_tick = 0;
|
2007-05-27 15:08:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-07-22 21:02:24 +00:00
|
|
|
#endif
|
2008-08-23 09:46:38 +00:00
|
|
|
#if defined(HAVE_TOUCHSCREEN)
|
|
|
|
if (action == ACTION_TOUCHSCREEN)
|
2008-12-31 05:59:26 +00:00
|
|
|
action = *actionptr = gui_synclist_do_touchscreen(lists);
|
2010-10-31 11:11:46 +00:00
|
|
|
else if (action > ACTION_TOUCHSCREEN_MODE)
|
|
|
|
/* cancel kinetic if we got a normal button event */
|
2021-08-22 00:46:28 +00:00
|
|
|
_gui_synclist_stop_kinetic_scrolling(lists);
|
2007-10-22 12:26:53 +00:00
|
|
|
#endif
|
2006-09-25 10:56:38 +00:00
|
|
|
|
2012-03-20 10:27:33 +00:00
|
|
|
/* Disable the skin redraw callback */
|
|
|
|
current_lists = NULL;
|
2022-09-19 11:48:15 +00:00
|
|
|
|
|
|
|
/* Prevent list wraparound by repeating actions */
|
2022-09-19 12:12:14 +00:00
|
|
|
bool allow_wrap = lists->wraparound;
|
2022-09-19 11:48:15 +00:00
|
|
|
if (action == ACTION_STD_PREVREPEAT ||
|
|
|
|
action == ACTION_STD_NEXTREPEAT ||
|
|
|
|
action == ACTION_LISTTREE_PGUP ||
|
|
|
|
action == ACTION_LISTTREE_PGDOWN)
|
2022-09-19 12:12:14 +00:00
|
|
|
allow_wrap = false;
|
2007-03-11 10:52:36 +00:00
|
|
|
|
2007-09-17 10:08:50 +00:00
|
|
|
switch (action)
|
2005-10-28 00:00:00 +00:00
|
|
|
{
|
2007-10-22 12:26:53 +00:00
|
|
|
case ACTION_REDRAW:
|
|
|
|
gui_synclist_draw(lists);
|
|
|
|
return true;
|
2009-10-27 13:18:54 +00:00
|
|
|
|
2007-04-08 01:33:01 +00:00
|
|
|
#ifdef HAVE_VOLUME_IN_LIST
|
|
|
|
case ACTION_LIST_VOLUP:
|
2018-06-23 09:27:18 +00:00
|
|
|
global_settings.volume += sound_steps(SOUND_VOLUME);
|
|
|
|
setvol();
|
|
|
|
return true;
|
2007-04-08 01:33:01 +00:00
|
|
|
case ACTION_LIST_VOLDOWN:
|
2018-06-23 09:27:18 +00:00
|
|
|
global_settings.volume -= sound_steps(SOUND_VOLUME);
|
2007-05-30 17:57:32 +00:00
|
|
|
setvol();
|
2007-09-17 10:08:50 +00:00
|
|
|
return true;
|
2007-04-08 01:33:01 +00:00
|
|
|
#endif
|
2006-08-15 12:27:07 +00:00
|
|
|
case ACTION_STD_PREV:
|
|
|
|
case ACTION_STD_PREVREPEAT:
|
2022-09-19 12:12:14 +00:00
|
|
|
gui_list_select_at_offset(lists, -next_item_modifier, allow_wrap);
|
2009-03-02 19:25:50 +00:00
|
|
|
#ifndef HAVE_WHEEL_ACCELERATION
|
2008-05-20 19:41:48 +00:00
|
|
|
if (button_queue_count() < FRAMEDROP_TRIGGER)
|
2007-07-22 21:02:24 +00:00
|
|
|
#endif
|
2007-03-11 10:52:36 +00:00
|
|
|
gui_synclist_draw(lists);
|
2006-02-19 13:34:12 +00:00
|
|
|
yield();
|
2007-09-17 10:08:50 +00:00
|
|
|
*actionptr = ACTION_STD_PREV;
|
|
|
|
return true;
|
2005-10-28 00:00:00 +00:00
|
|
|
|
2006-08-15 12:27:07 +00:00
|
|
|
case ACTION_STD_NEXT:
|
|
|
|
case ACTION_STD_NEXTREPEAT:
|
2022-09-19 12:12:14 +00:00
|
|
|
gui_list_select_at_offset(lists, next_item_modifier, allow_wrap);
|
2009-03-02 19:25:50 +00:00
|
|
|
#ifndef HAVE_WHEEL_ACCELERATION
|
2008-05-20 19:41:48 +00:00
|
|
|
if (button_queue_count() < FRAMEDROP_TRIGGER)
|
2007-07-22 21:02:24 +00:00
|
|
|
#endif
|
2007-03-11 10:52:36 +00:00
|
|
|
gui_synclist_draw(lists);
|
2006-02-19 13:34:12 +00:00
|
|
|
yield();
|
2007-09-17 10:08:50 +00:00
|
|
|
*actionptr = ACTION_STD_NEXT;
|
|
|
|
return true;
|
2006-01-22 04:24:26 +00:00
|
|
|
|
2007-07-25 12:37:09 +00:00
|
|
|
case ACTION_TREE_PGRIGHT:
|
|
|
|
gui_synclist_scroll_right(lists);
|
|
|
|
gui_synclist_draw(lists);
|
2007-09-17 10:08:50 +00:00
|
|
|
return true;
|
2006-09-25 10:56:38 +00:00
|
|
|
case ACTION_TREE_ROOT_INIT:
|
2006-12-09 10:02:09 +00:00
|
|
|
/* After this button press ACTION_TREE_PGLEFT is allowed
|
|
|
|
to skip to root. ACTION_TREE_ROOT_INIT must be defined in the
|
|
|
|
keymaps as a repeated button press (the same as the repeated
|
|
|
|
ACTION_TREE_PGLEFT) with the pre condition being the non-repeated
|
2015-10-20 22:11:44 +00:00
|
|
|
button press. Leave out ACTION_TREE_ROOT_INIT in your keymaps to
|
|
|
|
disable cancel action by PGLEFT key (e.g. if PGLEFT and CANCEL
|
|
|
|
are mapped to different keys) */
|
2007-12-17 02:37:21 +00:00
|
|
|
if (lists->offset_position[0] == 0)
|
2006-09-25 10:56:38 +00:00
|
|
|
{
|
2015-10-20 22:11:44 +00:00
|
|
|
pgleft_allow_cancel = true;
|
2021-10-23 21:57:22 +00:00
|
|
|
*actionptr = ACTION_STD_MENU;
|
2007-09-17 10:08:50 +00:00
|
|
|
return true;
|
2006-09-25 10:56:38 +00:00
|
|
|
}
|
2007-09-17 10:08:50 +00:00
|
|
|
*actionptr = ACTION_TREE_PGLEFT;
|
2021-07-24 14:39:01 +00:00
|
|
|
/* fallthrough */
|
2006-08-15 12:27:07 +00:00
|
|
|
case ACTION_TREE_PGLEFT:
|
2015-10-20 22:11:44 +00:00
|
|
|
if(pgleft_allow_cancel && (lists->offset_position[0] == 0))
|
2007-09-17 10:08:50 +00:00
|
|
|
{
|
|
|
|
*actionptr = ACTION_STD_CANCEL;
|
|
|
|
return false;
|
|
|
|
}
|
2006-07-02 12:28:27 +00:00
|
|
|
gui_synclist_scroll_left(lists);
|
|
|
|
gui_synclist_draw(lists);
|
2015-10-20 22:11:44 +00:00
|
|
|
pgleft_allow_cancel = false; /* stop ACTION_TREE_PAGE_LEFT
|
|
|
|
skipping to root */
|
2007-09-17 10:08:50 +00:00
|
|
|
return true;
|
2006-12-09 10:02:09 +00:00
|
|
|
/* for pgup / pgdown, we are obliged to have a different behaviour depending
|
|
|
|
* on the screen for which the user pressed the key since for example, remote
|
|
|
|
* and main screen doesn't have the same number of lines */
|
2006-08-15 12:27:07 +00:00
|
|
|
case ACTION_LISTTREE_PGUP:
|
2007-03-04 07:45:12 +00:00
|
|
|
{
|
|
|
|
int screen =
|
2007-03-04 08:35:20 +00:00
|
|
|
#ifdef HAVE_REMOTE_LCD
|
2007-03-04 07:45:12 +00:00
|
|
|
get_action_statuscode(NULL)&ACTION_REMOTE ?
|
2018-12-16 00:15:28 +00:00
|
|
|
SCREEN_REMOTE :
|
2007-03-04 07:45:12 +00:00
|
|
|
#endif
|
|
|
|
SCREEN_MAIN;
|
2022-09-19 12:12:14 +00:00
|
|
|
gui_synclist_select_previous_page(lists, screen, allow_wrap);
|
2005-10-28 00:00:00 +00:00
|
|
|
gui_synclist_draw(lists);
|
2006-06-04 17:14:17 +00:00
|
|
|
yield();
|
2007-09-17 10:08:50 +00:00
|
|
|
*actionptr = ACTION_STD_NEXT;
|
2007-03-04 07:45:12 +00:00
|
|
|
}
|
2007-09-17 10:08:50 +00:00
|
|
|
return true;
|
2007-03-04 07:45:12 +00:00
|
|
|
|
2006-08-15 12:27:07 +00:00
|
|
|
case ACTION_LISTTREE_PGDOWN:
|
2007-03-04 07:45:12 +00:00
|
|
|
{
|
|
|
|
int screen =
|
2007-03-04 08:35:20 +00:00
|
|
|
#ifdef HAVE_REMOTE_LCD
|
2007-03-04 07:45:12 +00:00
|
|
|
get_action_statuscode(NULL)&ACTION_REMOTE ?
|
2018-12-16 00:15:28 +00:00
|
|
|
SCREEN_REMOTE :
|
2007-03-04 07:45:12 +00:00
|
|
|
#endif
|
|
|
|
SCREEN_MAIN;
|
2022-09-19 12:12:14 +00:00
|
|
|
gui_synclist_select_next_page(lists, screen, allow_wrap);
|
2005-10-28 00:00:00 +00:00
|
|
|
gui_synclist_draw(lists);
|
2006-06-04 17:14:17 +00:00
|
|
|
yield();
|
2007-09-17 10:08:50 +00:00
|
|
|
*actionptr = ACTION_STD_PREV;
|
2007-03-04 07:45:12 +00:00
|
|
|
}
|
2007-09-17 10:08:50 +00:00
|
|
|
return true;
|
2005-10-28 00:00:00 +00:00
|
|
|
}
|
2007-12-17 02:37:21 +00:00
|
|
|
if(lists->scheduled_talk_tick
|
|
|
|
&& TIME_AFTER(current_tick, lists->scheduled_talk_tick))
|
2007-10-21 00:20:10 +00:00
|
|
|
/* scheduled postponed item announcement is due */
|
2010-06-15 07:08:35 +00:00
|
|
|
_gui_synclist_speak_item(lists);
|
2007-09-17 10:08:50 +00:00
|
|
|
return false;
|
2005-10-28 00:00:00 +00:00
|
|
|
}
|
2007-10-20 12:32:55 +00:00
|
|
|
|
2007-10-21 00:20:10 +00:00
|
|
|
int list_do_action_timeout(struct gui_synclist *lists, int timeout)
|
|
|
|
/* Returns the lowest of timeout or the delay until a postponed
|
|
|
|
scheduled announcement is due (if any). */
|
|
|
|
{
|
2012-03-20 10:27:33 +00:00
|
|
|
if (lists != current_lists)
|
|
|
|
{
|
|
|
|
if (!ui_update_event_registered)
|
2018-12-16 00:15:28 +00:00
|
|
|
ui_update_event_registered =
|
2014-03-14 22:15:16 +00:00
|
|
|
add_event(GUI_EVENT_NEED_UI_UPDATE, _lists_uiviewport_update_callback);
|
2012-03-20 10:27:33 +00:00
|
|
|
current_lists = lists;
|
|
|
|
}
|
2007-12-17 02:37:21 +00:00
|
|
|
if(lists->scheduled_talk_tick)
|
2007-10-21 00:20:10 +00:00
|
|
|
{
|
2007-12-17 02:37:21 +00:00
|
|
|
long delay = lists->scheduled_talk_tick -current_tick +1;
|
2007-10-21 00:20:10 +00:00
|
|
|
/* +1 because the trigger condition uses TIME_AFTER(), which
|
|
|
|
is implemented as strictly greater than. */
|
|
|
|
if(delay < 0)
|
|
|
|
delay = 0;
|
|
|
|
if(timeout > delay || timeout == TIMEOUT_BLOCK)
|
|
|
|
timeout = delay;
|
|
|
|
}
|
|
|
|
return timeout;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool list_do_action(int context, int timeout,
|
2022-09-19 11:48:15 +00:00
|
|
|
struct gui_synclist *lists, int *action)
|
2007-10-21 00:20:10 +00:00
|
|
|
/* Combines the get_action() (with possibly overridden timeout) and
|
|
|
|
gui_synclist_do_button() calls. Returns the list action from
|
|
|
|
do_button, and places the action from get_action in *action. */
|
|
|
|
{
|
|
|
|
timeout = list_do_action_timeout(lists, timeout);
|
2012-01-12 11:28:36 +00:00
|
|
|
keyclick_set_callback(gui_synclist_keyclick_callback, lists);
|
2007-10-21 00:20:10 +00:00
|
|
|
*action = get_action(context, timeout);
|
2022-09-19 11:48:15 +00:00
|
|
|
return gui_synclist_do_button(lists, action);
|
2007-10-21 00:20:10 +00:00
|
|
|
}
|
|
|
|
|
2007-10-20 12:32:55 +00:00
|
|
|
/* Simple use list implementation */
|
2013-02-12 09:35:11 +00:00
|
|
|
static int simplelist_line_count = 0, simplelist_line_remaining;
|
|
|
|
static int simplelist_line_pos;
|
|
|
|
static char simplelist_buffer[SIMPLELIST_MAX_LINES * SIMPLELIST_MAX_LINELENGTH];
|
|
|
|
static char *simplelist_text[SIMPLELIST_MAX_LINES];
|
2007-10-20 12:32:55 +00:00
|
|
|
/* set the amount of lines shown in the list */
|
|
|
|
void simplelist_set_line_count(int lines)
|
|
|
|
{
|
2013-02-12 09:35:11 +00:00
|
|
|
if (lines <= 0) {
|
|
|
|
simplelist_line_pos = 0;
|
|
|
|
simplelist_line_remaining = sizeof(simplelist_buffer);
|
2008-04-21 13:32:10 +00:00
|
|
|
simplelist_line_count = 0;
|
2013-02-12 09:35:11 +00:00
|
|
|
}
|
2013-03-27 11:43:40 +00:00
|
|
|
else if (lines < simplelist_line_count) {
|
|
|
|
char *end = simplelist_text[lines];
|
|
|
|
simplelist_line_pos = end - simplelist_buffer;
|
|
|
|
simplelist_line_remaining = sizeof(simplelist_buffer) - simplelist_line_pos;
|
|
|
|
simplelist_line_count = lines;
|
|
|
|
}
|
2007-10-20 12:32:55 +00:00
|
|
|
}
|
|
|
|
/* get the current amount of lines shown */
|
|
|
|
int simplelist_get_line_count(void)
|
|
|
|
{
|
|
|
|
return simplelist_line_count;
|
|
|
|
}
|
|
|
|
/* add/edit a line in the list.
|
2009-10-27 13:18:54 +00:00
|
|
|
if line_number > number of lines shown it adds the line,
|
|
|
|
else it edits the line */
|
2013-02-12 09:35:11 +00:00
|
|
|
void simplelist_addline(const char *fmt, ...)
|
2007-10-20 12:32:55 +00:00
|
|
|
{
|
|
|
|
va_list ap;
|
2013-02-12 09:35:11 +00:00
|
|
|
size_t len = simplelist_line_remaining;
|
|
|
|
int line_number = simplelist_line_count++;
|
2007-10-20 12:32:55 +00:00
|
|
|
|
2013-02-12 09:35:11 +00:00
|
|
|
simplelist_text[line_number] = &simplelist_buffer[simplelist_line_pos];
|
2007-10-20 12:32:55 +00:00
|
|
|
va_start(ap, fmt);
|
2013-02-12 09:35:11 +00:00
|
|
|
len = vsnprintf(simplelist_text[line_number], simplelist_line_remaining, fmt, ap);
|
2007-10-20 12:32:55 +00:00
|
|
|
va_end(ap);
|
2013-02-12 09:35:11 +00:00
|
|
|
len++;
|
|
|
|
simplelist_line_remaining -= len;
|
|
|
|
simplelist_line_pos += len;
|
2007-10-20 12:32:55 +00:00
|
|
|
}
|
|
|
|
|
2009-08-20 16:47:44 +00:00
|
|
|
static const char* simplelist_static_getname(int item,
|
|
|
|
void * data,
|
|
|
|
char *buffer,
|
|
|
|
size_t buffer_len)
|
2007-10-20 12:32:55 +00:00
|
|
|
{
|
2008-04-09 15:25:17 +00:00
|
|
|
(void)data; (void)buffer; (void)buffer_len;
|
2007-10-20 12:32:55 +00:00
|
|
|
return simplelist_text[item];
|
|
|
|
}
|
2008-04-09 15:25:17 +00:00
|
|
|
|
2007-10-20 12:32:55 +00:00
|
|
|
bool simplelist_show_list(struct simplelist_info *info)
|
|
|
|
{
|
|
|
|
struct gui_synclist lists;
|
2011-10-15 19:35:02 +00:00
|
|
|
int action, old_line_count = simplelist_line_count;
|
2010-04-10 21:11:19 +00:00
|
|
|
list_get_name *getname;
|
2007-10-20 12:32:55 +00:00
|
|
|
if (info->get_name)
|
|
|
|
getname = info->get_name;
|
|
|
|
else
|
|
|
|
getname = simplelist_static_getname;
|
2010-01-07 12:51:57 +00:00
|
|
|
|
2009-12-09 07:25:46 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
2019-11-02 11:15:01 +00:00
|
|
|
viewportmanager_theme_enable(i, !info->hide_theme, NULL);
|
2010-01-07 12:51:57 +00:00
|
|
|
|
2018-12-16 00:15:28 +00:00
|
|
|
gui_synclist_init(&lists, getname, info->callback_data,
|
2009-01-07 07:52:32 +00:00
|
|
|
info->scroll_all, info->selection_size, NULL);
|
2009-10-27 13:18:54 +00:00
|
|
|
|
2007-10-20 12:32:55 +00:00
|
|
|
if (info->title)
|
2011-09-03 13:24:56 +00:00
|
|
|
gui_synclist_set_title(&lists, info->title, info->title_icon);
|
2007-10-20 12:32:55 +00:00
|
|
|
if (info->get_icon)
|
|
|
|
gui_synclist_set_icon_callback(&lists, info->get_icon);
|
2007-10-21 01:27:17 +00:00
|
|
|
if (info->get_talk)
|
|
|
|
gui_synclist_set_voice_callback(&lists, info->get_talk);
|
2011-09-03 13:24:56 +00:00
|
|
|
#ifdef HAVE_LCD_COLOR
|
|
|
|
if (info->get_color)
|
|
|
|
gui_synclist_set_color_callback(&lists, info->get_color);
|
2019-11-02 11:15:01 +00:00
|
|
|
if (info->selection_color)
|
|
|
|
gui_synclist_set_sel_color(&lists, info->selection_color);
|
2011-09-03 13:24:56 +00:00
|
|
|
#endif
|
2009-10-27 13:18:54 +00:00
|
|
|
|
2007-10-20 12:32:55 +00:00
|
|
|
if (info->action_callback)
|
|
|
|
info->action_callback(ACTION_REDRAW, &lists);
|
|
|
|
|
|
|
|
if (info->get_name == NULL)
|
2009-10-27 13:18:54 +00:00
|
|
|
gui_synclist_set_nb_items(&lists,
|
|
|
|
simplelist_line_count*info->selection_size);
|
2007-10-20 12:32:55 +00:00
|
|
|
else
|
|
|
|
gui_synclist_set_nb_items(&lists, info->count*info->selection_size);
|
2009-10-27 13:18:54 +00:00
|
|
|
|
2008-09-25 07:56:34 +00:00
|
|
|
gui_synclist_select_item(&lists, info->selection);
|
2009-10-27 13:18:54 +00:00
|
|
|
|
2007-10-20 12:32:55 +00:00
|
|
|
gui_synclist_draw(&lists);
|
2019-11-02 11:15:01 +00:00
|
|
|
|
|
|
|
if (info->speak_onshow)
|
|
|
|
gui_synclist_speak_item(&lists);
|
2007-10-20 12:32:55 +00:00
|
|
|
|
|
|
|
while(1)
|
|
|
|
{
|
2022-09-19 11:48:15 +00:00
|
|
|
list_do_action(CONTEXT_LIST, info->timeout, &lists, &action);
|
2007-10-26 23:11:18 +00:00
|
|
|
|
|
|
|
/* We must yield in this case or no other thread can run */
|
2007-10-26 18:04:42 +00:00
|
|
|
if (info->timeout == TIMEOUT_NOBLOCK)
|
2007-10-26 23:11:18 +00:00
|
|
|
yield();
|
|
|
|
|
2007-10-20 12:32:55 +00:00
|
|
|
if (info->action_callback)
|
|
|
|
{
|
2008-09-25 08:12:25 +00:00
|
|
|
bool stdok = action==ACTION_STD_OK;
|
2007-10-20 12:32:55 +00:00
|
|
|
action = info->action_callback(action, &lists);
|
2008-12-31 05:59:26 +00:00
|
|
|
if (stdok && action == ACTION_STD_CANCEL)
|
2008-09-25 08:12:25 +00:00
|
|
|
{
|
2008-12-31 05:59:26 +00:00
|
|
|
/* callback asked us to exit */
|
2008-09-25 08:12:25 +00:00
|
|
|
info->selection = gui_synclist_get_sel_pos(&lists);
|
|
|
|
break;
|
|
|
|
}
|
2009-10-27 13:18:54 +00:00
|
|
|
|
2007-10-20 12:32:55 +00:00
|
|
|
if (info->get_name == NULL)
|
2008-12-31 05:59:26 +00:00
|
|
|
gui_synclist_set_nb_items(&lists,
|
|
|
|
simplelist_line_count*info->selection_size);
|
2007-10-20 12:32:55 +00:00
|
|
|
}
|
|
|
|
if (action == ACTION_STD_CANCEL)
|
2008-09-25 08:12:25 +00:00
|
|
|
{
|
|
|
|
info->selection = -1;
|
2007-10-20 12:32:55 +00:00
|
|
|
break;
|
2008-09-25 08:12:25 +00:00
|
|
|
}
|
2019-11-02 11:15:01 +00:00
|
|
|
else if (action == ACTION_STD_OK)
|
|
|
|
{
|
|
|
|
info->selection = gui_synclist_get_sel_pos(&lists);
|
|
|
|
break;
|
|
|
|
}
|
2008-02-25 07:41:30 +00:00
|
|
|
else if ((action == ACTION_REDRAW) ||
|
2012-03-22 19:59:01 +00:00
|
|
|
(list_is_dirty(&lists)) ||
|
2007-11-04 01:04:10 +00:00
|
|
|
(old_line_count != simplelist_line_count))
|
2007-10-20 12:32:55 +00:00
|
|
|
{
|
|
|
|
if (info->get_name == NULL)
|
2008-12-31 05:59:26 +00:00
|
|
|
{
|
|
|
|
gui_synclist_set_nb_items(&lists,
|
|
|
|
simplelist_line_count*info->selection_size);
|
|
|
|
}
|
2007-10-20 12:32:55 +00:00
|
|
|
gui_synclist_draw(&lists);
|
2007-10-21 11:06:30 +00:00
|
|
|
old_line_count = simplelist_line_count;
|
2007-10-20 12:32:55 +00:00
|
|
|
}
|
|
|
|
else if(default_event_handler(action) == SYS_USB_CONNECTED)
|
|
|
|
return true;
|
|
|
|
}
|
2007-10-23 05:19:03 +00:00
|
|
|
talk_shutup();
|
2019-11-02 11:15:01 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_LCD_COLOR
|
|
|
|
if (info->selection_color)
|
|
|
|
gui_synclist_set_sel_color(&lists, NULL);
|
|
|
|
#endif
|
|
|
|
|
2009-12-09 07:25:46 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
2010-01-07 12:51:57 +00:00
|
|
|
viewportmanager_theme_undo(i, false);
|
2007-10-20 12:32:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-10-21 01:27:17 +00:00
|
|
|
void simplelist_info_init(struct simplelist_info *info, char* title,
|
2007-10-21 06:42:52 +00:00
|
|
|
int count, void* data)
|
2007-10-21 01:27:17 +00:00
|
|
|
{
|
|
|
|
info->title = title;
|
|
|
|
info->count = count;
|
2007-10-21 06:42:52 +00:00
|
|
|
info->selection_size = 1;
|
2007-10-21 01:27:17 +00:00
|
|
|
info->scroll_all = false;
|
2019-11-02 11:15:01 +00:00
|
|
|
info->hide_theme = false;
|
|
|
|
info->speak_onshow = true;
|
2007-10-21 13:47:43 +00:00
|
|
|
info->timeout = HZ/10;
|
2008-09-25 07:56:34 +00:00
|
|
|
info->selection = 0;
|
2007-10-21 01:27:17 +00:00
|
|
|
info->action_callback = NULL;
|
2011-09-03 13:24:56 +00:00
|
|
|
info->title_icon = Icon_NOICON;
|
2007-10-21 01:27:17 +00:00
|
|
|
info->get_icon = NULL;
|
|
|
|
info->get_name = NULL;
|
|
|
|
info->get_talk = NULL;
|
2011-09-03 13:24:56 +00:00
|
|
|
#ifdef HAVE_LCD_COLOR
|
|
|
|
info->get_color = NULL;
|
2019-11-02 11:15:01 +00:00
|
|
|
info->selection_color = NULL;
|
2011-09-03 13:24:56 +00:00
|
|
|
#endif
|
2007-10-21 01:27:17 +00:00
|
|
|
info->callback_data = data;
|
2010-04-10 20:25:23 +00:00
|
|
|
simplelist_line_count = 0;
|
2007-10-21 01:27:17 +00:00
|
|
|
}
|