1
0
Fork 0
forked from len0rd/rockbox

Some changes to the remote code : some one lines function turned into macros ; changed pre-increment to post-increment since it's clearer that way ; added a data pointer to the list callback (global variables are baaaad) ; some more documentation of the API and minor cleanups

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7681 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Kevin Ferrare 2005-10-29 02:33:19 +00:00
parent dff9352430
commit e75cbdd2a8
8 changed files with 130 additions and 98 deletions

View file

@ -24,9 +24,9 @@
/* Defines a type for the icons since it's not the same thing on
* char-based displays and bitmap displays */
#ifdef HAVE_LCD_BITMAP
#define ICON const unsigned char *
typedef const unsigned char * ICON;
#else
#define ICON unsigned short
typedef unsigned short ICON;
#endif
#define CURSOR_CHAR 0x92

View file

@ -39,8 +39,12 @@
void gui_list_init(struct gui_list * gui_list,
void (*callback_get_item_icon)(int selected_item, ICON * icon),
char * (*callback_get_item_name)(int selected_item, char *buffer))
void (*callback_get_item_icon)
(int selected_item, void * data, ICON * icon),
char * (*callback_get_item_name)
(int selected_item, void * data, char *buffer),
void * data
)
{
gui_list->callback_get_item_icon = callback_get_item_icon;
gui_list->callback_get_item_name = callback_get_item_name;
@ -48,12 +52,8 @@ void gui_list_init(struct gui_list * gui_list,
gui_list_set_nb_items(gui_list, 0);
gui_list->selected_item = 0;
gui_list->start_item = 0;
gui_list->limit_scroll=false;
}
inline void gui_list_set_nb_items(struct gui_list * gui_list, int nb_items)
{
gui_list->nb_items = nb_items;
gui_list->limit_scroll = false;
gui_list->data=data;
}
void gui_list_set_display(struct gui_list * gui_list, struct screen * display)
@ -70,30 +70,25 @@ void gui_list_set_display(struct gui_list * gui_list, struct screen * display)
void gui_list_put_selection_in_screen(struct gui_list * gui_list,
bool put_from_end)
{
struct screen * display = gui_list->display;
int nb_lines=gui_list->display->nb_lines;
if(put_from_end)
{
int list_end = gui_list->selected_item + SCROLL_LIMIT - 1;
if(list_end > gui_list->nb_items)
list_end = gui_list->nb_items;
gui_list->start_item = list_end - display->nb_lines;
list_end = nb_lines;
gui_list->start_item = list_end - nb_lines;
}
else
{
int list_start = gui_list->selected_item - SCROLL_LIMIT + 1;
if(list_start + display->nb_lines > gui_list->nb_items)
list_start = gui_list->nb_items - display->nb_lines;
if(list_start + nb_lines > gui_list->nb_items)
list_start = gui_list->nb_items - nb_lines;
gui_list->start_item = list_start;
}
if(gui_list->start_item < 0)
gui_list->start_item = 0;
}
inline int gui_list_get_sel_pos(struct gui_list * gui_list)
{
return gui_list->selected_item;
}
void gui_list_draw(struct gui_list * gui_list)
{
struct screen * display=gui_list->display;
@ -117,13 +112,13 @@ void gui_list_draw(struct gui_list * gui_list)
text_pos = 0; /* here it's in pixels */
if(draw_scrollbar)
{
++cursor_pos;
++icon_pos;
cursor_pos++;
icon_pos++;
text_pos += SCROLLBAR_WIDTH;
}
if(!draw_cursor)
{
--icon_pos;
icon_pos--;
}
else
text_pos += CURSOR_WIDTH;
@ -165,6 +160,7 @@ void gui_list_draw(struct gui_list * gui_list)
if(current_item >= gui_list->nb_items)
break;
entry_name = gui_list->callback_get_item_name(current_item,
gui_list->data,
entry_buffer);
if(current_item == gui_list->selected_item)
{
@ -193,7 +189,9 @@ void gui_list_draw(struct gui_list * gui_list)
if(draw_icons)
{
ICON icon;
gui_list->callback_get_item_icon(current_item, &icon);
gui_list->callback_get_item_icon(current_item,
gui_list->data,
&icon);
screen_put_iconxy(display, icon_pos, i, icon);
}
}
@ -234,7 +232,7 @@ void gui_list_select_next(struct gui_list * gui_list)
{
if(gui_list->limit_scroll)
return;
++gui_list->selected_item;
gui_list->selected_item++;
/* we have already reached the bottom of the list */
gui_list->selected_item = 0;
gui_list->start_item = 0;
@ -242,14 +240,14 @@ void gui_list_select_next(struct gui_list * gui_list)
else
{
int nb_lines = gui_list->display->nb_lines;
++gui_list->selected_item;
gui_list->selected_item++;
item_pos = gui_list->selected_item - gui_list->start_item;
end_item = gui_list->start_item + nb_lines;
/* we start scrolling vertically when reaching the line
* (nb_lines-SCROLL_LIMIT)
* and when we are not in the last part of the list*/
if( item_pos > nb_lines-SCROLL_LIMIT && end_item < gui_list->nb_items )
++gui_list->start_item;
gui_list->start_item++;
}
}
@ -262,7 +260,7 @@ void gui_list_select_previous(struct gui_list * gui_list)
{
if(gui_list->limit_scroll)
return;
--gui_list->selected_item;
gui_list->selected_item--;
/* we have aleady reached the top of the list */
int start;
gui_list->selected_item = gui_list->nb_items-1;
@ -274,10 +272,10 @@ void gui_list_select_previous(struct gui_list * gui_list)
}
else
{
--gui_list->selected_item;
gui_list->selected_item--;
item_pos = gui_list->selected_item - gui_list->start_item;
if( item_pos < SCROLL_LIMIT-1 && gui_list->start_item > 0 )
--gui_list->start_item;
gui_list->start_item--;
}
}
@ -317,7 +315,7 @@ void gui_list_select_previous_page(struct gui_list * gui_list, int nb_lines)
void gui_list_add_item(struct gui_list * gui_list)
{
++gui_list->nb_items;
gui_list->nb_items++;
/* if only one item in the list, select it */
if(gui_list->nb_items == 1)
gui_list->selected_item = 0;
@ -337,34 +335,35 @@ void gui_list_del_item(struct gui_list * gui_list)
{
/* Oops we are removing the selected item,
select the previous one */
--gui_list->selected_item;
gui_list->selected_item--;
}
--gui_list->nb_items;
gui_list->nb_items--;
/* scroll the list if needed */
if( (dist_start_from_end < nb_lines) && (gui_list->start_item != 0) )
--gui_list->start_item;
gui_list->start_item--;
}
}
inline void gui_list_limit_scroll(struct gui_list * gui_list, bool scroll)
{
gui_list->limit_scroll=scroll;
}
/*
* Synchronized lists stuffs
*/
void gui_synclist_init(
struct gui_synclist * lists,
void (*callback_get_item_icon)(int selected_item, ICON * icon),
char * (*callback_get_item_name)(int selected_item, char *buffer)
void (*callback_get_item_icon)
(int selected_item, void * data, ICON * icon),
char * (*callback_get_item_name)
(int selected_item, void * data, char *buffer),
void * data
)
{
int i;
for(i = 0;i < NB_SCREENS;i++)
{
gui_list_init(&(lists->gui_list[i]), callback_get_item_icon,
callback_get_item_name);
gui_list_init(&(lists->gui_list[i]),
callback_get_item_icon,
callback_get_item_name,
data);
gui_list_set_display(&(lists->gui_list[i]), &(screens[i]));
}
}
@ -378,11 +377,6 @@ void gui_synclist_set_nb_items(struct gui_synclist * lists, int nb_items)
}
}
int gui_synclist_get_sel_pos(struct gui_synclist * lists)
{
return gui_list_get_sel_pos(&(lists->gui_list[0]));
}
void gui_synclist_draw(struct gui_synclist * lists)
{
int i;

View file

@ -63,21 +63,50 @@
#define LIST_PGDN (BUTTON_ON | BUTTON_DOWN)
#endif
/*
* The gui_list is based on callback functions, if you want the list
* to display something you have to provide it a function that
* tells it what to display.
* There are two callback function :
* one to get the text and one to get the icon
* Callback interface :
*
* Text callback
* - selected_item : an integer that tells the number of the item to display
* - data : a void pointer to the data you gave to the list when
* you initialized it
* - buffer : a buffer to put the resulting text on it
* (The content of the buffer may not be used by the list, we use
* the return value of the function in all cases to avoid filling
* a buffer when it's not necessary)
* Returns a pointer to a string that contains the text to display
*
* Icon callback
* - selected_item : an integer that tells the number of the item to display
* - data : a void pointer to the data you gave to the list when
* you initialized it
* - icon : a pointer to the icon, the value inside it is used to display
* the icon after the function returns.
* Note : we use the ICON type because the real type depends of the plateform
*/
struct gui_list
{
int nb_items;
int selected_item;
int start_item; /* the item that is displayed at the top of the screen */
void (*callback_get_item_icon)(int selected_item, ICON * icon);
char * (*callback_get_item_name)(int selected_item, char *buffer);
void (*callback_get_item_icon)
(int selected_item, void * data, ICON * icon);
char * (*callback_get_item_name)
(int selected_item, void * data, char *buffer);
struct screen * display;
int line_scroll_limit;
/* defines wether the list should stop when reaching the top/bottom
* or should continue (by going to bottom/top) */
bool limit_scroll;
/* The data that will be passed to the callback function YOU implement */
void * data;
};
/*
@ -89,9 +118,12 @@ struct gui_list
* to a given item number
*/
extern void gui_list_init(struct gui_list * gui_list,
void (*callback_get_item_icon)(int selected_item, ICON * icon),
char * (*callback_get_item_name)(int selected_item, char *buffer)
);
void (*callback_get_item_icon)
(int selected_item, void * data, ICON * icon),
char * (*callback_get_item_name)
(int selected_item, void * data, char *buffer),
void * data
);
/*
* Sets the numbers of items the list can currently display
@ -99,7 +131,8 @@ extern void gui_list_init(struct gui_list * gui_list,
* - gui_list : the list structure to initialize
* - nb_items : the numbers of items you want
*/
extern inline void gui_list_set_nb_items(struct gui_list * gui_list, int nb_items);
#define gui_list_set_nb_items(gui_list, nb) \
(gui_list)->nb_items = nb
/*
* Puts the selection in the screen
@ -125,7 +158,8 @@ extern void gui_list_set_display(struct gui_list * gui_list,
* - gui_list : the list structure
* Returns the position
*/
extern inline int gui_list_get_sel_pos(struct gui_list * gui_list);
#define gui_list_get_sel_pos(gui_list) \
(gui_list)->selected_item
/*
* Selects an item in the list
@ -190,7 +224,8 @@ extern void gui_list_del_item(struct gui_list * gui_list);
* - true : stops when reaching top/bottom
* - false : continues to go to bottom/top when reaching top/bottom
*/
extern inline void gui_list_limit_scroll(struct gui_list * gui_list, bool scroll);
#define gui_list_limit_scroll(gui_list, scroll) \
(gui_list)->limit_scroll=scroll
/*
* This part handles as many lists as there are connected screens
@ -206,13 +241,21 @@ struct gui_synclist
struct gui_list gui_list[NB_SCREENS];
};
extern void gui_synclist_init(struct gui_synclist * lists,
void (*callback_get_item_icon)(int selected_item, ICON * icon),
char * (*callback_get_item_name)(int selected_item, char *buffer)
);
extern void gui_synclist_init(
struct gui_synclist * lists,
void (*callback_get_item_icon)
(int selected_item, void * data, ICON * icon),
char * (*callback_get_item_name)
(int selected_item, void * data, char *buffer),
void * data
);
extern void gui_synclist_set_nb_items(struct gui_synclist * lists, int nb_items);
extern int gui_synclist_get_sel_pos(struct gui_synclist * lists);
#define gui_synclist_get_sel_pos(lists) \
gui_list_get_sel_pos(&((lists)->gui_list[0]))
extern void gui_synclist_draw(struct gui_synclist * lists);
extern void gui_synclist_select_item(struct gui_synclist * lists,
int item_number);

View file

@ -40,9 +40,7 @@
/* FIXME: should be removed from icon.h to avoid redefinition,
but still needed for compatibility with old system */
#define STATUSBAR_X_POS 0
#define STATUSBAR_Y_POS 0 /* MUST be a multiple of 8 */
#define STATUSBAR_HEIGHT 8
#define STATUSBAR_BATTERY_X_POS 0
#define STATUSBAR_BATTERY_WIDTH 18
#define STATUSBAR_PLUG_X_POS STATUSBAR_X_POS + \
@ -115,7 +113,7 @@ void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw)
struct tm* tm; /* For Time */
#endif
#ifndef HAVE_LCD_BITMAP
#ifdef HAVE_LCD_CHARCELLS
(void)force_redraw; /* players always "redraw" */
#endif
@ -259,7 +257,7 @@ void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw)
}
#ifndef HAVE_LCD_BITMAP
#ifdef HAVE_LCD_CHARCELLS
if (bar->info.battlevel > -1)
display->icon(ICON_BATTERY, battery_state);
display->icon(ICON_BATTERY_1, bar->info.battlevel > 25);

View file

@ -23,6 +23,10 @@
#include "config.h"
#include "status.h"
#define STATUSBAR_X_POS 0
#define STATUSBAR_Y_POS 0 /* MUST be a multiple of 8 */
#define STATUSBAR_HEIGHT 8
struct status_info {
int battlevel;
int volume;

View file

@ -171,24 +171,6 @@ void screen_update_nblines(struct screen * screen)
}
#ifdef HAVE_LCD_BITMAP
int screen_get_text_y_start(struct screen * screen)
{
screen=0;/* Avoid warning, this parameter is here for api integrity */
return(global_settings.statusbar?STATUSBAR_HEIGHT:0);
}
int screen_get_text_y_end(struct screen * screen)
{
#ifdef HAS_BUTTONBAR
return( screen->height - (global_settings.buttonbar?BUTTONBAR_HEIGHT:0) );
#else
return( screen->height );
#endif
}
#endif
void screen_access_init(void)
{
screen_init(&screens[0], SCREEN_MAIN);

View file

@ -7,7 +7,7 @@
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2005 by Kévin FERRARE
* Copyright (C) 2005 by K<EFBFBD>in FERRARE
*
* All files in this archive are subject to the GNU General Public License.
* See the file COPYING in the source tree root for full license agreement.
@ -34,7 +34,7 @@ enum screen_type {
#define NB_SCREENS 1
#endif
#ifndef HAVE_LCD_BITMAP
#ifdef HAVE_LCD_CHARCELLS
#define MAX_LINES_ON_SCREEN 2
#endif
@ -113,15 +113,23 @@ extern void screen_update_nblines(struct screen * screen);
* - screen : the screen structure
* Returns the number of pixels
*/
extern int screen_get_text_y_start(struct screen * screen);
#define screen_get_text_y_start(screen) \
(global_settings.statusbar?STATUSBAR_HEIGHT:0)
/*
* Compute the number of pixels below which text can't be displayed
* - screen : the screen structure
* Returns the number of pixels
*/
extern int screen_get_text_y_end(struct screen * screen);
#endif
#ifdef HAS_BUTTONBAR
#define screen_get_text_y_end(screen) \
( (screen)->height - (global_settings.buttonbar?BUTTONBAR_HEIGHT:0) )
#else
#define screen_get_text_y_end(screen) \
( (screen)->height )
#endif /* HAS_BUTTONBAR */
#endif /* HAVE_LCD_BITMAP */
/*
* Initializes the whole screen_access api

View file

@ -146,16 +146,18 @@ char * strip_extension(char * filename, char * buffer)
else
return(filename);
}
char * tree_get_filename(int selected_item, char *buffer)
char * tree_get_filename(int selected_item, void * data, char *buffer)
{
struct tree_context * local_tc=(struct tree_context *)data;
char *name;
int attr=0;
bool id3db = *tc.dirfilter == SHOW_ID3DB;
bool id3db = *(local_tc->dirfilter) == SHOW_ID3DB;
if (id3db) {
name = ((char**)tc.dircache)[selected_item * tc.dentry_size];
name = ((char**)local_tc->dircache)[selected_item * local_tc->dentry_size];
}
else {
struct entry* dc = tc.dircache;
struct entry* dc = local_tc->dircache;
struct entry* e = &dc[selected_item];
name = e->name;
attr = e->attr;
@ -163,8 +165,8 @@ char * tree_get_filename(int selected_item, char *buffer)
/* if any file filter is on, and if it's not a directory,
* strip the extension */
if ( (*tc.dirfilter != SHOW_ID3DB) && !(attr & ATTR_DIRECTORY)
&& (*tc.dirfilter != SHOW_ALL) )
if ( (*(local_tc->dirfilter) != SHOW_ID3DB) && !(attr & ATTR_DIRECTORY)
&& (*(local_tc->dirfilter) != SHOW_ALL) )
{
return(strip_extension(name, buffer));
}
@ -172,14 +174,15 @@ char * tree_get_filename(int selected_item, char *buffer)
}
void tree_get_fileicon(int selected_item, ICON * icon)
void tree_get_fileicon(int selected_item, void * data, ICON * icon)
{
bool id3db = *tc.dirfilter == SHOW_ID3DB;
struct tree_context * local_tc=(struct tree_context *)data;
bool id3db = *(local_tc->dirfilter) == SHOW_ID3DB;
if (id3db) {
*icon = db_get_icon(&tc);
}
else {
struct entry* dc = tc.dircache;
struct entry* dc = local_tc->dircache;
struct entry* e = &dc[selected_item];
*icon = filetype_get_icon(e->attr);
}
@ -224,7 +227,7 @@ void browse_root(void)
gui_buttonbar_set_display(&tree_buttonbar, &(screens[SCREEN_MAIN]) );
#endif
gui_syncstatusbar_init(&statusbars);
gui_synclist_init(&tree_lists, &tree_get_fileicon, &tree_get_filename);
gui_synclist_init(&tree_lists, &tree_get_fileicon, &tree_get_filename, &tc);
#ifndef SIMULATOR
dirbrowse();
#else