summaryrefslogtreecommitdiffstats
path: root/apps/gui
diff options
context:
space:
mode:
Diffstat (limited to 'apps/gui')
-rw-r--r--apps/gui/icon.h4
-rw-r--r--apps/gui/list.c84
-rw-r--r--apps/gui/list.h69
-rw-r--r--apps/gui/statusbar.c8
-rw-r--r--apps/gui/statusbar.h4
5 files changed, 104 insertions, 65 deletions
diff --git a/apps/gui/icon.h b/apps/gui/icon.h
index 119ee3cc47..8fe7262ffe 100644
--- a/apps/gui/icon.h
+++ b/apps/gui/icon.h
@@ -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
diff --git a/apps/gui/list.c b/apps/gui/list.c
index 1a83a65e64..ed26f1c9a8 100644
--- a/apps/gui/list.c
+++ b/apps/gui/list.c
@@ -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;
diff --git a/apps/gui/list.h b/apps/gui/list.h
index e47f260a1b..4472fadbf8 100644
--- a/apps/gui/list.h
+++ b/apps/gui/list.h
@@ -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);
diff --git a/apps/gui/statusbar.c b/apps/gui/statusbar.c
index 0e7210218e..0f24208d33 100644
--- a/apps/gui/statusbar.c
+++ b/apps/gui/statusbar.c
@@ -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);
diff --git a/apps/gui/statusbar.h b/apps/gui/statusbar.h
index d3acbec8e5..d80968ff5e 100644
--- a/apps/gui/statusbar.h
+++ b/apps/gui/statusbar.h
@@ -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;