2011-09-06 13:53:46 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011 by Jonathan Gordon
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "config.h"
|
2012-03-27 23:52:15 +00:00
|
|
|
#include "system.h"
|
2011-09-06 13:53:46 +00:00
|
|
|
#include "lcd.h"
|
|
|
|
#include "font.h"
|
|
|
|
#include "button.h"
|
|
|
|
#include "string.h"
|
|
|
|
#include "settings.h"
|
|
|
|
#include "kernel.h"
|
|
|
|
#include "file.h"
|
|
|
|
|
|
|
|
#include "action.h"
|
|
|
|
#include "screen_access.h"
|
|
|
|
#include "list.h"
|
|
|
|
#include "scrollbar.h"
|
|
|
|
#include "lang.h"
|
|
|
|
#include "sound.h"
|
|
|
|
#include "misc.h"
|
|
|
|
#include "viewport.h"
|
|
|
|
#include "statusbar-skinned.h"
|
|
|
|
#include "skin_engine/skin_engine.h"
|
|
|
|
#include "skin_engine/skin_display.h"
|
|
|
|
#include "appevents.h"
|
|
|
|
|
|
|
|
static struct listitem_viewport_cfg *listcfg[NB_SCREENS] = {NULL};
|
2012-02-19 11:12:40 +00:00
|
|
|
static struct gui_synclist *current_list;
|
2011-09-11 10:44:17 +00:00
|
|
|
|
2012-02-25 01:34:23 +00:00
|
|
|
static int current_row;
|
|
|
|
static int current_column;
|
|
|
|
|
2011-09-06 13:53:46 +00:00
|
|
|
void skinlist_set_cfg(enum screen_type screen,
|
|
|
|
struct listitem_viewport_cfg *cfg)
|
|
|
|
{
|
|
|
|
if (listcfg[screen] != cfg)
|
|
|
|
{
|
|
|
|
if (listcfg[screen])
|
2013-04-03 14:33:23 +00:00
|
|
|
screens[screen].scroll_stop_viewport(&listcfg[screen]->selected_item_vp.vp);
|
2011-09-06 13:53:46 +00:00
|
|
|
listcfg[screen] = cfg;
|
2011-09-11 10:44:17 +00:00
|
|
|
current_list = NULL;
|
2012-03-01 17:38:57 +00:00
|
|
|
current_column = -1;
|
|
|
|
current_row = -1;
|
2011-09-06 13:53:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool skinlist_is_configured(enum screen_type screen,
|
|
|
|
struct gui_synclist *list)
|
|
|
|
{
|
|
|
|
return (listcfg[screen] != NULL) &&
|
|
|
|
(!list || (list && list->selected_size == 1));
|
|
|
|
}
|
2011-09-11 10:44:17 +00:00
|
|
|
static int current_drawing_line;
|
|
|
|
static int offset_to_item(int offset, bool wrap)
|
|
|
|
{
|
|
|
|
int item = current_drawing_line + offset;
|
2012-02-21 00:29:12 +00:00
|
|
|
if (!current_list || current_list->nb_items == 0)
|
2011-09-11 10:44:17 +00:00
|
|
|
return -1;
|
|
|
|
if (item < 0)
|
|
|
|
{
|
|
|
|
if (!wrap)
|
|
|
|
return -1;
|
|
|
|
else
|
|
|
|
item = (item + current_list->nb_items) % current_list->nb_items;
|
|
|
|
}
|
|
|
|
else if (item >= current_list->nb_items && !wrap)
|
|
|
|
return -1;
|
|
|
|
else
|
|
|
|
item = item % current_list->nb_items;
|
|
|
|
return item;
|
|
|
|
}
|
2011-09-18 12:35:32 +00:00
|
|
|
|
|
|
|
int skinlist_get_item_number()
|
|
|
|
{
|
|
|
|
return current_drawing_line;
|
|
|
|
}
|
|
|
|
|
2012-02-25 01:34:23 +00:00
|
|
|
int skinlist_get_item_row()
|
|
|
|
{
|
|
|
|
return current_row;
|
|
|
|
}
|
|
|
|
|
|
|
|
int skinlist_get_item_column()
|
|
|
|
{
|
|
|
|
return current_column;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-11 10:44:17 +00:00
|
|
|
const char* skinlist_get_item_text(int offset, bool wrap, char* buf, size_t buf_size)
|
2011-09-06 13:53:46 +00:00
|
|
|
{
|
2011-09-11 10:44:17 +00:00
|
|
|
int item = offset_to_item(offset, wrap);
|
|
|
|
if (item < 0 || !current_list)
|
|
|
|
return NULL;
|
|
|
|
const char* ret = current_list->callback_get_item_name(
|
|
|
|
item, current_list->data, buf, buf_size);
|
|
|
|
return P2STR((unsigned char*)ret);
|
2011-09-06 13:53:46 +00:00
|
|
|
}
|
2011-09-11 10:44:17 +00:00
|
|
|
|
|
|
|
enum themable_icons skinlist_get_item_icon(int offset, bool wrap)
|
2011-09-06 13:53:46 +00:00
|
|
|
{
|
2011-09-11 10:44:17 +00:00
|
|
|
int item = offset_to_item(offset, wrap);
|
|
|
|
if (item < 0 || !current_list || current_list->callback_get_item_icon == NULL)
|
|
|
|
return Icon_NOICON;
|
|
|
|
return current_list->callback_get_item_icon(item, current_list->data);
|
2011-09-06 13:53:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool is_selected = false;
|
|
|
|
bool skinlist_is_selected_item(void)
|
|
|
|
{
|
|
|
|
return is_selected;
|
|
|
|
}
|
|
|
|
|
|
|
|
int skinlist_get_line_count(enum screen_type screen, struct gui_synclist *list)
|
|
|
|
{
|
|
|
|
struct viewport *parent = (list->parent[screen]);
|
|
|
|
if (!skinlist_is_configured(screen, list))
|
|
|
|
return -1;
|
|
|
|
if (listcfg[screen]->tile == true)
|
|
|
|
{
|
|
|
|
int rows = (parent->height / listcfg[screen]->height);
|
|
|
|
int cols = (parent->width / listcfg[screen]->width);
|
|
|
|
return rows*cols;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return (parent->height / listcfg[screen]->height);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int current_item;
|
|
|
|
static int current_nbitems;
|
|
|
|
static bool needs_scrollbar[NB_SCREENS];
|
|
|
|
bool skinlist_needs_scrollbar(enum screen_type screen)
|
|
|
|
{
|
|
|
|
return needs_scrollbar[screen];
|
|
|
|
}
|
|
|
|
|
|
|
|
void skinlist_get_scrollbar(int* nb_item, int* first_shown, int* last_shown)
|
|
|
|
{
|
|
|
|
if (!skinlist_is_configured(0, NULL))
|
|
|
|
{
|
|
|
|
*nb_item = 0;
|
|
|
|
*first_shown = 0;
|
|
|
|
*last_shown = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*nb_item = current_item;
|
|
|
|
*first_shown = 0;
|
|
|
|
*last_shown = current_nbitems;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-13 21:07:49 +00:00
|
|
|
bool skinlist_get_item(struct screen *display, struct gui_synclist *list, int x, int y, int *item)
|
|
|
|
{
|
|
|
|
const int screen = display->screen_type;
|
|
|
|
if (!skinlist_is_configured(screen, list))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
int row = y / listcfg[screen]->height;
|
|
|
|
int column = x / listcfg[screen]->width;
|
|
|
|
struct viewport *parent = (list->parent[screen]);
|
|
|
|
int cols = (parent->width / listcfg[screen]->width);
|
|
|
|
*item = row * cols+ column;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-09-06 13:53:46 +00:00
|
|
|
bool skinlist_draw(struct screen *display, struct gui_synclist *list)
|
|
|
|
{
|
|
|
|
int cur_line, display_lines;
|
|
|
|
const int screen = display->screen_type;
|
|
|
|
struct viewport *parent = (list->parent[screen]);
|
|
|
|
char* label = NULL;
|
|
|
|
const int list_start_item = list->start_item[screen];
|
|
|
|
struct gui_wps wps;
|
|
|
|
if (!skinlist_is_configured(screen, list))
|
|
|
|
return false;
|
2012-05-17 19:25:50 +00:00
|
|
|
|
2011-09-11 10:44:17 +00:00
|
|
|
current_list = list;
|
2011-09-06 13:53:46 +00:00
|
|
|
wps.display = display;
|
|
|
|
wps.data = listcfg[screen]->data;
|
|
|
|
display_lines = skinlist_get_line_count(screen, list);
|
2012-02-21 13:33:42 +00:00
|
|
|
label = (char *)SKINOFFSETTOPTR(get_skin_buffer(wps.data), listcfg[screen]->label);
|
2011-09-06 13:53:46 +00:00
|
|
|
display->set_viewport(parent);
|
|
|
|
display->clear_viewport();
|
|
|
|
current_item = list->selected_item;
|
|
|
|
current_nbitems = list->nb_items;
|
|
|
|
needs_scrollbar[screen] = list->nb_items > display_lines;
|
|
|
|
|
|
|
|
for (cur_line = 0; cur_line < display_lines; cur_line++)
|
|
|
|
{
|
|
|
|
struct skin_element* viewport;
|
2011-11-15 14:11:08 +00:00
|
|
|
struct skin_viewport* skin_viewport = NULL;
|
2011-09-06 13:53:46 +00:00
|
|
|
if (list_start_item+cur_line+1 > list->nb_items)
|
|
|
|
break;
|
2011-09-11 10:44:17 +00:00
|
|
|
current_drawing_line = list_start_item+cur_line;
|
2011-09-06 13:53:46 +00:00
|
|
|
is_selected = list->show_selection_marker &&
|
|
|
|
list_start_item+cur_line == list->selected_item;
|
2012-02-25 01:34:23 +00:00
|
|
|
|
2011-11-15 14:11:08 +00:00
|
|
|
for (viewport = SKINOFFSETTOPTR(get_skin_buffer(wps.data), listcfg[screen]->data->tree);
|
2011-09-06 13:53:46 +00:00
|
|
|
viewport;
|
2011-11-15 14:11:08 +00:00
|
|
|
viewport = SKINOFFSETTOPTR(get_skin_buffer(wps.data), viewport->next))
|
2011-09-06 13:53:46 +00:00
|
|
|
{
|
2012-02-25 21:02:09 +00:00
|
|
|
int original_x, original_y;
|
2012-02-19 19:52:06 +00:00
|
|
|
skin_viewport = SKINOFFSETTOPTR(get_skin_buffer(wps.data), viewport->data);
|
2011-11-15 14:11:08 +00:00
|
|
|
char *viewport_label = SKINOFFSETTOPTR(get_skin_buffer(wps.data), skin_viewport->label);
|
|
|
|
if (viewport->children == 0 || !viewport_label ||
|
|
|
|
(skin_viewport->label && strcmp(label, viewport_label))
|
2011-09-06 13:53:46 +00:00
|
|
|
)
|
|
|
|
continue;
|
|
|
|
if (is_selected)
|
|
|
|
{
|
|
|
|
memcpy(&listcfg[screen]->selected_item_vp, skin_viewport, sizeof(struct skin_viewport));
|
|
|
|
skin_viewport = &listcfg[screen]->selected_item_vp;
|
|
|
|
}
|
2012-02-25 21:02:09 +00:00
|
|
|
original_x = skin_viewport->vp.x;
|
|
|
|
original_y = skin_viewport->vp.y;
|
2011-09-06 13:53:46 +00:00
|
|
|
if (listcfg[screen]->tile)
|
|
|
|
{
|
|
|
|
int cols = (parent->width / listcfg[screen]->width);
|
2012-02-25 01:34:23 +00:00
|
|
|
current_column = (cur_line)%cols;
|
|
|
|
current_row = (cur_line)/cols;
|
2020-07-17 14:31:31 +00:00
|
|
|
|
2012-02-25 21:02:09 +00:00
|
|
|
skin_viewport->vp.x = parent->x + listcfg[screen]->width*current_column + original_x;
|
|
|
|
skin_viewport->vp.y = parent->y + listcfg[screen]->height*current_row + original_y;
|
2011-09-06 13:53:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-01 17:38:57 +00:00
|
|
|
current_column = 1;
|
2012-02-25 01:34:23 +00:00
|
|
|
current_row = cur_line;
|
2012-02-25 21:02:09 +00:00
|
|
|
skin_viewport->vp.x = parent->x + original_x;
|
|
|
|
skin_viewport->vp.y = parent->y + original_y +
|
2011-09-06 13:53:46 +00:00
|
|
|
(listcfg[screen]->height*cur_line);
|
|
|
|
}
|
|
|
|
display->set_viewport(&skin_viewport->vp);
|
|
|
|
/* Set images to not to be displayed */
|
2011-11-15 14:11:08 +00:00
|
|
|
struct skin_token_list *imglist = SKINOFFSETTOPTR(get_skin_buffer(wps.data), wps.data->images);
|
2011-09-06 13:53:46 +00:00
|
|
|
while (imglist)
|
|
|
|
{
|
2011-11-15 14:11:08 +00:00
|
|
|
struct wps_token *token = SKINOFFSETTOPTR(get_skin_buffer(wps.data), imglist->token);
|
|
|
|
struct gui_img *img = SKINOFFSETTOPTR(get_skin_buffer(wps.data), token->value.data);
|
2011-09-06 13:53:46 +00:00
|
|
|
img->display = -1;
|
2011-11-15 14:11:08 +00:00
|
|
|
imglist = SKINOFFSETTOPTR(get_skin_buffer(wps.data), imglist->next);
|
2011-09-06 13:53:46 +00:00
|
|
|
}
|
2011-11-15 14:11:08 +00:00
|
|
|
struct skin_element** children = SKINOFFSETTOPTR(get_skin_buffer(wps.data), viewport->children);
|
2012-02-19 20:06:03 +00:00
|
|
|
skin_render_viewport(SKINOFFSETTOPTR(get_skin_buffer(wps.data), (intptr_t)children[0]),
|
2011-09-06 13:53:46 +00:00
|
|
|
&wps, skin_viewport, SKIN_REFRESH_ALL);
|
|
|
|
wps_display_images(&wps, &skin_viewport->vp);
|
|
|
|
/* force disableing scroll because it breaks later */
|
|
|
|
if (!is_selected)
|
|
|
|
{
|
2013-04-03 14:33:23 +00:00
|
|
|
display->scroll_stop_viewport(&skin_viewport->vp);
|
2012-02-25 21:02:09 +00:00
|
|
|
skin_viewport->vp.x = original_x;
|
|
|
|
skin_viewport->vp.y = original_y;
|
2011-09-06 13:53:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-01 17:38:57 +00:00
|
|
|
current_column = -1;
|
|
|
|
current_row = -1;
|
2011-09-06 13:53:46 +00:00
|
|
|
display->set_viewport(parent);
|
|
|
|
display->update_viewport();
|
2011-09-11 10:44:17 +00:00
|
|
|
current_drawing_line = list->selected_item;
|
2011-09-06 13:53:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|