add radio station selection; remove list and filelist view implementation in STM32 radio; remove warning of RTGUI.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@419 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
bernard.xiong 2010-02-17 23:56:49 +00:00
parent 332d0d00e2
commit 860d1ddfd4
40 changed files with 619 additions and 1502 deletions

View File

@ -117,7 +117,7 @@ static rt_bool_t view_event_handler(struct rtgui_widget* widget, struct rtgui_ev
}; };
/* check device index */ /* check device index */
if (dev_index < 0 || dev_index > 4) dev_index = 3; if (dev_index > 4) dev_index = 3;
/* draw each information */ /* draw each information */
sprintf(line, "设备: %s %s", sprintf(line, "设备: %s %s",

View File

@ -503,7 +503,7 @@ struct pbuf *rt_dm9000_rx(rt_device_t dev)
{ {
rt_uint16_t dummy; rt_uint16_t dummy;
DM9000_TRACE("dm9000 rx: no pbuf\n"); rt_kprintf("dm9000 rx: no pbuf\n");
/* no pbuf, discard data from DM9000 */ /* no pbuf, discard data from DM9000 */
data = &dummy; data = &dummy;

View File

@ -1,676 +0,0 @@
#include <rtgui/rtgui_object.h>
#include <rtgui/rtgui_system.h>
#include <rtgui/rtgui_theme.h>
#include <rtgui/list.h>
#include <rtgui/image.h>
#include <rtgui/widgets/view.h>
#include <rtgui/widgets/workbench.h>
#include "filelist.h"
#include <dfs_posix.h>
#include <string.h>
#define FILELIST_MARGIN 5
#ifdef _WIN32
#define PATH_SEPARATOR '\\'
#define stat _stat
#else
#define PATH_SEPARATOR '/'
#endif
const static char * file_xpm[] = {
"16 16 21 1",
" c None",
". c #999999",
"+ c #818181",
"@ c #FFFFFF",
"# c #ECECEC",
"$ c #EAEAEA",
"% c #EBEBEB",
"& c #EDEDED",
"* c #F0F0F0",
"= c #C4C4C4",
"- c #C5C5C5",
"; c #C6C6C6",
"> c #C7C7C7",
", c #EEEEEE",
"' c #EDEDE5",
") c #EDEDE6",
"! c #EFEFEF",
"~ c #C8C8C8",
"{ c #F1F1F1",
"] c #F2F2F2",
"^ c #959595",
".++++++++++++ ",
"+@@@@@@@@@@@@+ ",
"+@#$$%%%##&*@+ ",
"+@$=--;;;;>*@+ ",
"+@$%%###&&,*@+ ",
"+@%-;;;;;;>*@+ ",
"+@%%##&&'#,*@+ ",
"+@%;;;;,,),*@+ ",
"+@##&&,,!!!*@+ ",
"+@#;;;>>~~~*@+ ",
"+@#&,,!!*{{{@+ ",
"+@&;>>~~~{{]@+ ",
"+@&&,!!**{]]@+ ",
"+@@@@@@@@@@@@+ ",
"^++++++++++++^ ",
" "};
const static char * folder_xpm[] = {
"16 16 121 2",
" c None",
". c #D9B434",
"+ c #E1C25E",
"@ c #E2C360",
"# c #E2C35F",
"$ c #DBB63C",
"% c #DAB336",
"& c #FEFEFD",
"* c #FFFFFE",
"= c #FFFEFE",
"- c #FFFEFD",
"; c #FBF7EA",
"> c #E4C76B",
", c #E3C76B",
"' c #E6CD79",
") c #E5CA74",
"! c #DAAF35",
"~ c #FEFCF7",
"{ c #F8E48E",
"] c #F5DE91",
"^ c #F5E09F",
"/ c #F6E1AC",
"( c #FEFBEF",
"_ c #FEFDF4",
": c #FEFCF3",
"< c #FEFCF1",
"[ c #FEFBEE",
"} c #FFFDFA",
"| c #DAAF36",
"1 c #DAAA36",
"2 c #FDFAF1",
"3 c #F5DE94",
"4 c #F4DC93",
"5 c #F2D581",
"6 c #EDCA6A",
"7 c #EACB6C",
"8 c #EFD385",
"9 c #EFD280",
"0 c #EFD07A",
"a c #EECF76",
"b c #EECF72",
"c c #FBF7E9",
"d c #DAAE34",
"e c #DAAB35",
"f c #FBF6E8",
"g c #EFD494",
"h c #EECE88",
"i c #E9C173",
"j c #F6E9C9",
"k c #FEFCF2",
"l c #FEFCF0",
"m c #DAAB36",
"n c #DAA637",
"o c #FFFDF8",
"p c #FFFDF6",
"q c #FFFCF5",
"r c #FCF6D8",
"s c #F8E694",
"t c #F7E385",
"u c #F6DF76",
"v c #F5DB68",
"w c #F4D85C",
"x c #FCF4D7",
"y c #DAA435",
"z c #DAA136",
"A c #FEFCF6",
"B c #FCF2C8",
"C c #FBEFB9",
"D c #FAECAC",
"E c #F9E89C",
"F c #F7E38B",
"G c #F6E07C",
"H c #F6DC6C",
"I c #F5D95D",
"J c #F4D64F",
"K c #F3D344",
"L c #FCF3D0",
"M c #DA9F35",
"N c #DA9A36",
"O c #FDFAF2",
"P c #FAEDB3",
"Q c #F9E9A4",
"R c #F8E695",
"S c #F7E285",
"T c #F6DE76",
"U c #F5DB65",
"V c #F4D757",
"W c #F3D449",
"X c #F2D13B",
"Y c #F1CE30",
"Z c #FBF2CC",
"` c #DA9835",
" . c #DA9435",
".. c #FEFAEF",
"+. c #F9E9A1",
"@. c #F8E591",
"#. c #F7E181",
"$. c #F6DE72",
"%. c #F5DA63",
"&. c #F4D754",
"*. c #F3D347",
"=. c #F2D039",
"-. c #F1CD2E",
";. c #F0CB26",
">. c #FBF2CA",
",. c #D98E33",
"'. c #FAF0DC",
"). c #F4DDA7",
"!. c #F4DB9E",
"~. c #F3DA96",
"{. c #F3D88E",
"]. c #F3D786",
"^. c #F2D47F",
"/. c #F2D379",
"(. c #F1D272",
"_. c #F1D06C",
":. c #F1CF69",
"<. c #F8EAC2",
"[. c #D8882D",
"}. c #D8872D",
"|. c #D8862C",
" ",
" ",
" ",
" . + @ @ @ # $ ",
" % & * = - * ; > , , , ' ) ",
" ! ~ { ] ^ / ( _ : < ( [ } | ",
" 1 2 3 4 5 6 7 8 9 0 a b c d ",
" e f g h i j k : k l ( [ * m ",
" n * o p q : r s t u v w x y ",
" z A B C D E F G H I J K L M ",
" N O P Q R S T U V W X Y Z ` ",
" ...+.@.#.$.%.&.*.=.-.;.>. . ",
" ,.'.).!.~.{.].^./.(._.:.<.,. ",
" [.}.[.[.[.[.[.[.[.[.}.[.|. ",
" ",
" "};
/* image for file and folder */
static rtgui_image_t *file_image, *folder_image;
static struct filelist_view *filelist_view = RT_NULL; /* only one view in global */
static void _filelist_view_constructor(struct filelist_view *view)
{
/* default rect */
struct rtgui_rect rect = {0, 0, 200, 200};
/* set default widget rect and set event handler */
rtgui_widget_set_event_handler(RTGUI_WIDGET(view),filelist_view_event_handler);
rtgui_widget_set_rect(RTGUI_WIDGET(view), &rect);
RTGUI_WIDGET(view)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
view->current_item = 0;
view->items_count = 0;
view->page_items = 0;
view->current_directory = RT_NULL;
view->pattern = RT_NULL;
RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(view)) = white;
RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(view)) = RTGUI_ALIGN_CENTER_VERTICAL;
file_image = rtgui_image_create_from_mem("xpm",
(rt_uint8_t*)file_xpm, sizeof(file_xpm), RT_TRUE);
folder_image = rtgui_image_create_from_mem("xpm",
(rt_uint8_t*)folder_xpm, sizeof(folder_xpm), RT_TRUE);
}
rtgui_type_t *filelist_view_type_get(void)
{
static rtgui_type_t *filelist_view_type = RT_NULL;
if (!filelist_view_type)
{
filelist_view_type = rtgui_type_create("flview", RTGUI_VIEW_TYPE,
sizeof(filelist_view_t), RTGUI_CONSTRUCTOR(_filelist_view_constructor), RT_NULL);
}
return filelist_view_type;
}
void filelist_view_ondraw(struct filelist_view* view)
{
struct rtgui_rect rect, item_rect, image_rect;
struct rtgui_dc* dc;
rt_uint16_t page_index, index;
struct file_item* item;
dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(view));
if (dc == RT_NULL) return;
rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
rtgui_dc_fill_rect(dc, &rect);
/* get item base rect */
item_rect = rect;
item_rect.y1 += 1;
item_rect.y2 = item_rect.y1 + (1 + rtgui_theme_get_selected_height());
/* get image base rect */
image_rect.x1 = FILELIST_MARGIN; image_rect.y1 = 0;
image_rect.x2 = FILELIST_MARGIN + file_image->w; image_rect.y2 = file_image->h;
rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);
/* get current page */
page_index = (view->current_item / view->page_items) * view->page_items;
for (index = 0; index < view->page_items; index ++)
{
if (page_index + index >= view->items_count) break;
item = &(view->items[page_index + index]);
if (page_index + index == view->current_item)
{
rtgui_theme_draw_selected(dc, &item_rect);
}
else
{
/* draw background */
rtgui_dc_fill_rect(dc, &item_rect);
}
/* draw item */
if (item->type == FITEM_FILE)
rtgui_image_blit(file_image, dc, &image_rect);
else
rtgui_image_blit(folder_image, dc, &image_rect);
/* draw text */
item_rect.x1 += FILELIST_MARGIN + file_image->w + 2;
rtgui_dc_draw_text(dc, item->name, &item_rect);
item_rect.x1 -= FILELIST_MARGIN + file_image->w + 2;
/* move to next item position */
item_rect.y1 += (rtgui_theme_get_selected_height() + 1);
item_rect.y2 += (rtgui_theme_get_selected_height() + 1);
image_rect.y1 += (rtgui_theme_get_selected_height() + 1);
image_rect.y2 += (rtgui_theme_get_selected_height() + 1);
}
rtgui_dc_end_drawing(dc);
}
void filelist_view_update_current(struct filelist_view* view, rt_uint16_t old_item)
{
struct rtgui_dc* dc;
struct file_item* item;
rtgui_rect_t rect, item_rect, image_rect;
if (old_item/view->page_items != view->current_item/view->page_items)
{
/* it's not a same page, update all */
rtgui_widget_update(RTGUI_WIDGET(view));
return;
}
dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(view));
if (dc == RT_NULL) return;
rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
/* get old item rect */
item_rect = rect;
item_rect.y1 += 1;
item_rect.y1 += (old_item % view->page_items) * (1 + rtgui_theme_get_selected_height());
item_rect.y2 = item_rect.y1 + (1 + rtgui_theme_get_selected_height());
/* get image rect */
image_rect.x1 = FILELIST_MARGIN; image_rect.y1 = 0;
image_rect.x2 = FILELIST_MARGIN + file_image->w; image_rect.y2 = file_image->h;
rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);
/* draw old item */
rtgui_dc_fill_rect(dc, &item_rect);
item = &(view->items[old_item]);
if (item->type == FITEM_FILE) /* draw item image */
rtgui_image_blit(file_image, dc, &image_rect);
else
rtgui_image_blit(folder_image, dc, &image_rect);
item_rect.x1 += FILELIST_MARGIN + file_image->w + 2;
rtgui_dc_draw_text(dc, item->name, &item_rect);
/* draw current item */
item_rect = rect;
item_rect.y1 += 1;
item_rect.y1 += (view->current_item % view->page_items) * (1 + rtgui_theme_get_selected_height());
item_rect.y2 = item_rect.y1 + (1 + rtgui_theme_get_selected_height());
rtgui_theme_draw_selected(dc, &item_rect);
/* get image base rect */
image_rect.x1 = FILELIST_MARGIN; image_rect.y1 = 0;
image_rect.x2 = FILELIST_MARGIN + file_image->w; image_rect.y2 = file_image->h;
rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);
item = &(view->items[view->current_item]);
if (item->type == FITEM_FILE) /* draw item image */
rtgui_image_blit(file_image, dc, &image_rect);
else
rtgui_image_blit(folder_image, dc, &image_rect);
item_rect.x1 += FILELIST_MARGIN + file_image->w + 2;
rtgui_dc_draw_text(dc, item->name, &item_rect);
rtgui_dc_end_drawing(dc);
}
rt_bool_t filelist_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
{
struct filelist_view* view = RT_NULL;
view = FILELIST_VIEW(widget);
switch (event->type)
{
case RTGUI_EVENT_PAINT:
filelist_view_ondraw(view);
return RT_FALSE;
case RTGUI_EVENT_RESIZE:
{
struct rtgui_event_resize* resize;
resize = (struct rtgui_event_resize*)event;
/* recalculate page items */
if (file_image != RT_NULL)
view->page_items = resize->h / (1 + rtgui_theme_get_selected_height());
else
view->page_items = resize->h / (2 + 14);
}
break;
case RTGUI_EVENT_KBD:
{
struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event;
if (ekbd->type == RTGUI_KEYDOWN)
{
rt_uint16_t old_item;
old_item = view->current_item;
switch (ekbd->key)
{
case RTGUIK_UP:
if (view->current_item > 0)
view->current_item --;
filelist_view_update_current(view, old_item);
return RT_FALSE;
case RTGUIK_DOWN:
if (view->current_item < view->items_count - 1)
view->current_item ++;
filelist_view_update_current(view, old_item);
return RT_FALSE;
case RTGUIK_LEFT:
if (view->current_item - view->page_items >= 0)
view->current_item -= view->page_items;
filelist_view_update_current(view, old_item);
return RT_FALSE;
case RTGUIK_RIGHT:
if (view->current_item + view->page_items < view->items_count - 1)
view->current_item += view->page_items;
filelist_view_update_current(view, old_item);
return RT_FALSE;
case RTGUIK_RETURN:
if (view->items[view->current_item].type == FITEM_DIR)
{
char new_path[64];
if (strcmp(view->items[view->current_item].name, ".") == 0) return RT_FALSE;
if (strcmp(view->items[view->current_item].name, "..") == 0)
{
char *ptr;
ptr = strrchr(view->current_directory, PATH_SEPARATOR);
if (ptr == RT_NULL) return RT_FALSE;
if (ptr == &(view->current_directory[0]))
{
/* it's root directory */
new_path[0] = PATH_SEPARATOR;
new_path[1] = '\0';
}
else
{
strncpy(new_path, view->current_directory, ptr - view->current_directory + 1);
new_path[ptr - view->current_directory] = '\0';
}
}
else if (view->current_item == 0 &&
(view->current_directory[0] == '/') && (view->current_directory[1] == '\0'))
{
if (RTGUI_VIEW(view)->modal_show == RT_TRUE)
{
rtgui_view_end_modal(RTGUI_VIEW(view), RTGUI_MODAL_CANCEL);
}
else
{
filelist_view_destroy(view);
}
return RT_FALSE;
}
else
{
if (view->current_directory[strlen(view->current_directory) - 1] != PATH_SEPARATOR)
sprintf(new_path, "%s%c%s",view->current_directory, PATH_SEPARATOR,
view->items[view->current_item].name);
else
sprintf(new_path, "%s%s",view->current_directory,
view->items[view->current_item].name);
}
filelist_view_set_directory(view, new_path);
}
else
{
if (RTGUI_VIEW(view)->modal_show == RT_TRUE)
{
rtgui_view_end_modal(RTGUI_VIEW(view), RTGUI_MODAL_OK);
}
}
return RT_FALSE;
default:
break;
}
}
}
return RT_FALSE;
}
/* use view event handler */
return rtgui_view_event_handler(widget, event);
}
filelist_view_t* filelist_view_create(rtgui_workbench_t* workbench, const char* directory, const char* pattern, const rtgui_rect_t* rect)
{
struct filelist_view* view = RT_NULL;
if (filelist_view != RT_NULL)
{
rtgui_view_show(RTGUI_VIEW(filelist_view), RT_FALSE);
}
else
{
/* create a new view */
view = (struct filelist_view*) rtgui_widget_create(FILELIST_VIEW_TYPE);
if (view != RT_NULL)
{
view->items = RT_NULL;
view->pattern = rt_strdup(pattern);
view->page_items = rtgui_rect_height(*rect) / (1 + rtgui_theme_get_selected_height());
filelist_view_set_directory(view, directory);
rtgui_workbench_add_view(workbench, RTGUI_VIEW(view));
}
filelist_view = view;
}
return view;
}
void filelist_view_destroy(filelist_view_t* view)
{
/* delete all file items */
filelist_view_clear(view);
/* delete current directory and pattern */
rtgui_free(view->current_directory); view->current_directory = RT_NULL;
rtgui_free(view->pattern); view->pattern = RT_NULL;
/* delete image */
rtgui_image_destroy(file_image);
rtgui_image_destroy(folder_image);
filelist_view = RT_NULL;
/* destroy view */
rtgui_widget_destroy(RTGUI_WIDGET(view));
}
/* clear all file items */
void filelist_view_clear(filelist_view_t* view)
{
rt_uint32_t index;
struct file_item* item;
for (index = 0; index < view->items_count; index ++)
{
item = &(view->items[index]);
/* release item name */
rt_free(item->name);
item->name = RT_NULL;
}
/* release items */
rtgui_free(view->items);
view->items = RT_NULL;
view->items_count = 0;
view->current_item = 0;
}
void filelist_view_set_directory(filelist_view_t* view, const char* directory)
{
rt_uint8_t fullpath[256];
struct file_item *item;
RT_ASSERT(view != RT_NULL);
/* clear file items firstly */
filelist_view_clear(view);
if (directory != RT_NULL)
{
DIR* dir;
struct stat s;
rt_uint32_t index;
struct dirent* dirent;
view->items_count = 0;
dir = opendir(directory);
if (dir == RT_NULL) goto __return;
/* current directory exists, set it */
if (view->current_directory != RT_NULL) rt_free(view->current_directory);
view->current_directory = rt_strdup(directory);
do
{
dirent = readdir(dir);
if (dirent == RT_NULL) break;
if (strcmp(dirent->d_name, ".") == 0) continue;
if (strcmp(dirent->d_name, "..") == 0) continue;
view->items_count ++;
} while (dirent != RT_NULL);
closedir(dir);
view->items_count ++; /* root directory for [x] exit, others for .. */
view->items = (struct file_item*) rtgui_malloc(sizeof(struct file_item) * view->items_count);
if (view->items == RT_NULL) return; /* no memory */
index = 0;
if (directory[0] == '/' && directory[1] != '\0')
{
item = &(view->items[0]);
/* add .. directory */
item->name = rt_strdup("..");
item->type = FITEM_DIR;
item->size = 0;
index ++;
}
else
{
item = &(view->items[0]);
/* add .. directory */
item->name = rt_strdup("Í˳öÎļþä¯ÀÀ");
item->type = FITEM_DIR;
item->size = 0;
index ++;
}
/* reopen directory */
dir = opendir(directory);
for (; index < view->items_count; index ++)
{
dirent = readdir(dir);
if (dirent == RT_NULL) break;
item = &(view->items[index]);
item->name = rt_strdup(dirent->d_name);
rt_memset(&s, 0, sizeof(struct stat));
/* build full path for the file */
if (directory[strlen(directory) - 1] != PATH_SEPARATOR)
sprintf(fullpath, "%s%c%s", directory, PATH_SEPARATOR, dirent->d_name);
else
sprintf(fullpath, "%s%s", directory, dirent->d_name);
stat(fullpath, &s);
if ( s.st_mode & S_IFDIR )
{
item->type = FITEM_DIR;
item->size = 0;
}
else
{
item->type = FITEM_FILE;
item->size = s.st_size;
}
}
closedir(dir);
}
view->current_item = 0;
__return:
/* update view */
rtgui_widget_update(RTGUI_WIDGET(view));
}

View File

@ -1,55 +0,0 @@
#ifndef __FILE_LIST_VIEW_H__
#define __FILE_LIST_VIEW_H__
#include <rtgui/widgets/view.h>
#define FITEM_FILE 0x0
#define FITEM_DIR 0x1
struct file_item
{
rt_uint8_t* name;
rt_uint32_t type;
rt_uint32_t size;
};
/** Gets the type of a filelist view */
#define FILELIST_VIEW_TYPE (filelist_view_type_get())
/** Casts the object to a filelist */
#define FILELIST_VIEW(obj) (RTGUI_OBJECT_CAST((obj), FILELIST_VIEW_TYPE, filelist_view_t))
/** Checks if the object is a filelist view */
#define IS_FILELIST_VIEW(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), FILELIST_VIEW_TYPE))
struct filelist_view
{
struct rtgui_view parent;
/* widget private data */
/* current directory */
rt_uint8_t* current_directory;
rt_uint8_t* pattern;
/* the number of item in a page */
rt_uint16_t page_items;
rt_uint16_t items_count;
/* the selected item */
rt_uint16_t current_item;
/* items array */
struct file_item *items;
};
typedef struct filelist_view filelist_view_t;
rtgui_type_t *filelist_view_type_get(void);
filelist_view_t* filelist_view_create(rtgui_workbench_t* workbench, const char* directory, const char* pattern, const rtgui_rect_t* rect);
void filelist_view_destroy(filelist_view_t* view);
void filelist_view_clear(filelist_view_t* view);
rt_bool_t filelist_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event);
void filelist_view_set_directory(filelist_view_t* view, const char* directory);
#endif

View File

@ -8,12 +8,7 @@
#include <lwip/sockets.h> #include <lwip/sockets.h>
#include <lwip/netdb.h> #include <lwip/netdb.h>
const char _http_get[] = "GET "; const char _http_get[] = "GET %s HTTP/1.0\r\nHost: %s:%d\r\nUser-Agent: RT-Thread HTTP Agent\r\n\r\n";
const char _http_host[] = "Host: ";
const char _http_getend[] = " HTTP/1.0\r\n";
const char _http_user_agent[] = "User-Agent: RT-Thread HTTP Agent\r\n";
const char _http_endheader[] = "\r\n";
const char _shoutcast_get[] = "GET %s HTTP/1.0\r\nHost: %s:%d\r\nUser-Agent: RT-Thread HTTP Agent\r\nIcy-MetaData: 1\r\nConnection: close\r\n\r\n"; const char _shoutcast_get[] = "GET %s HTTP/1.0\r\nHost: %s:%d\r\nUser-Agent: RT-Thread HTTP Agent\r\nIcy-MetaData: 1\r\nConnection: close\r\n\r\n";
extern long int strtol(const char *nptr, char **endptr, int base); extern long int strtol(const char *nptr, char **endptr, int base);
@ -167,7 +162,6 @@ const char *http_resolve_address( struct sockaddr_in *server, const char * url,
port[w] = url[w + i + 1]; port[w] = url[w + i + 1];
port[w] = '\0'; port[w] = '\0';
rt_kprintf("HTTP: using port %s for connection\n", port);
break; break;
} }
else is_domain = 1; else is_domain = 1;
@ -225,51 +219,19 @@ static int http_connect(struct http_session* session,
return -1; return -1;
} }
// Needs more error checking here.....
#if 0
rc = send( peer_handle, _http_get, sizeof( _http_get ) - 1, 0 );
rc = send( peer_handle, (void*) url, strlen( url ), 0 );
rc = send( peer_handle, _http_getend, sizeof( _http_getend ) - 1, 0 );
rc = send( peer_handle, _http_host, sizeof( _http_host ) - 1, 0 );
rc = send( peer_handle, host_addr, strlen( host_addr ), 0 );
rc = send( peer_handle, _http_endheader, sizeof( _http_endheader ) - 1, 0 ); // "\r\n"
rc = send( peer_handle, _http_user_agent, sizeof( _http_user_agent ) - 1, 0 );
rc = send( peer_handle, _http_endheader, sizeof( _http_endheader ) - 1, 0 );
#else
{ {
rt_uint8_t *ptr, *buf; char *buf;
rt_uint32_t length;
buf = rt_malloc (512); buf = rt_malloc (512);
ptr = buf; length = rt_snprintf(buf, 512, _http_get, url, host_addr, server->sin_port);
rt_memcpy(ptr, _http_get, sizeof(_http_get) - 1);
ptr += sizeof(_http_get) - 1;
rt_memcpy(ptr, url, strlen(url)); rc = send(peer_handle, buf, length, 0);
ptr += strlen(url); rt_kprintf("HTTP request:\n%s", buf);
rt_memcpy(ptr, _http_getend, sizeof(_http_getend) - 1); /* release buffer */
ptr += sizeof(_http_getend) - 1; rt_free(buf);
rt_memcpy(ptr, _http_host, sizeof(_http_host) - 1);
ptr += sizeof(_http_host) - 1;
rt_memcpy(ptr, host_addr, strlen(host_addr));
ptr += strlen(host_addr);
rt_memcpy(ptr, _http_endheader, sizeof(_http_endheader) - 1);
ptr += sizeof(_http_endheader) - 1;
rt_memcpy(ptr, _http_user_agent, sizeof(_http_user_agent) - 1);
ptr += sizeof(_http_user_agent) - 1;
rt_memcpy(ptr, _http_endheader, sizeof(_http_endheader) - 1);
ptr += sizeof(_http_endheader) - 1;
rc = send(peer_handle, buf,
(rt_uint32_t)ptr - (rt_uint32_t)buf, 0);
} }
#endif
// We now need to read the header information // We now need to read the header information
while ( 1 ) while ( 1 )
@ -425,7 +387,7 @@ static int shoutcast_connect(struct shoutcast_session* session,
} }
{ {
rt_uint8_t *buf; char *buf;
rt_uint32_t length; rt_uint32_t length;
buf = rt_malloc (512); buf = rt_malloc (512);
@ -574,7 +536,12 @@ rt_size_t shoutcast_session_read(struct shoutcast_session* session, rt_uint8_t *
do do
{ {
bytesRead = recv(session->socket, buffer + totalRead, left, 0); bytesRead = recv(session->socket, buffer + totalRead, left, 0);
if(bytesRead <= 0) break; if(bytesRead <= 0)
{
rt_kprintf("no data on recv, len %d,err %d\n", bytesRead,
lwip_get_error(session->socket));
break;
}
left -= bytesRead; left -= bytesRead;
totalRead += bytesRead; totalRead += bytesRead;
@ -645,7 +612,7 @@ void http_test(char* url)
do do
{ {
rt_memset(buffer, 0, sizeof(buffer)); rt_memset(buffer, 0, sizeof(buffer));
length = http_session_read(session, buffer, sizeof(buffer)); length = http_session_read(session, (rt_uint8_t*)buffer, sizeof(buffer));
rt_kprintf(buffer);rt_kprintf("\n"); rt_kprintf(buffer);rt_kprintf("\n");
} while (length > 0); } while (length > 0);
@ -668,3 +635,4 @@ void shoutcast_test(char* url)
shoutcast_session_close(session); shoutcast_session_close(session);
} }
FINSH_FUNCTION_EXPORT(shoutcast_test, shoutcast client test); FINSH_FUNCTION_EXPORT(shoutcast_test, shoutcast client test);

View File

@ -1,245 +0,0 @@
#include "listview.h"
#include <rtgui/rtgui_theme.h>
#define LIST_MARGIN 5
static void _list_view_constructor(struct list_view *view)
{
/* default rect */
struct rtgui_rect rect = {0, 0, 200, 200};
/* set default widget rect and set event handler */
rtgui_widget_set_event_handler(RTGUI_WIDGET(view),list_view_event_handler);
rtgui_widget_set_rect(RTGUI_WIDGET(view), &rect);
RTGUI_WIDGET(view)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
view->current_item = 0;
view->items_count = 0;
view->page_items = 0;
RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(view)) = white;
RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(view)) = RTGUI_ALIGN_CENTER_VERTICAL;
}
rtgui_type_t *list_view_type_get(void)
{
static rtgui_type_t *list_view_type = RT_NULL;
if (!list_view_type)
{
list_view_type = rtgui_type_create("listview", RTGUI_VIEW_TYPE,
sizeof(list_view_t), RTGUI_CONSTRUCTOR(_list_view_constructor), RT_NULL);
}
return list_view_type;
}
void list_view_ondraw(struct list_view* view)
{
struct rtgui_rect rect, item_rect;
struct rtgui_dc* dc;
rt_uint16_t page_index, index;
struct list_item* item;
dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(view));
if (dc == RT_NULL) return;
rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
rtgui_dc_fill_rect(dc, &rect);
/* get item base rect */
item_rect = rect;
item_rect.y1 += 2;
item_rect.y2 = item_rect.y1 + (2 + rtgui_theme_get_selected_height());
/* get current page */
page_index = (view->current_item / view->page_items) * view->page_items;
for (index = 0; index < view->page_items; index ++)
{
if (page_index + index >= view->items_count) break;
item = &(view->items[page_index + index]);
if (page_index + index == view->current_item)
{
rtgui_theme_draw_selected(dc, &item_rect);
}
item_rect.x1 += LIST_MARGIN;
if (item->image != RT_NULL)
{
rtgui_image_blit(item->image, dc, &item_rect);
item_rect.x1 += item->image->w + 2;
}
/* draw text */
rtgui_dc_draw_text(dc, item->name, &item_rect);
if (item->image != RT_NULL)
item_rect.x1 -= (item->image->w + 2);
item_rect.x1 -= LIST_MARGIN;
/* move to next item position */
item_rect.y1 += (rtgui_theme_get_selected_height() + 2);
item_rect.y2 += (rtgui_theme_get_selected_height() + 2);
}
rtgui_dc_end_drawing(dc);
}
void list_view_update_current(struct list_view* view, rt_uint16_t old_item)
{
struct rtgui_dc* dc;
struct list_item* item;
rtgui_rect_t rect, item_rect;
if (old_item/view->page_items != view->current_item/view->page_items)
{
/* it's not a same page, update all */
rtgui_widget_update(RTGUI_WIDGET(view));
return;
}
dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(view));
if (dc == RT_NULL) return;
rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
item_rect = rect;
/* get old item's rect */
item_rect.y1 += 2;
item_rect.y1 += (old_item % view->page_items) * (2 + rtgui_theme_get_selected_height());
item_rect.y2 = item_rect.y1 + (2 + rtgui_theme_get_selected_height());
/* draw old item */
rtgui_dc_fill_rect(dc, &item_rect);
item_rect.x1 += LIST_MARGIN;
item = &(view->items[old_item]);
if (item->image != RT_NULL)
{
rtgui_image_blit(item->image, dc, &item_rect);
item_rect.x1 += item->image->w + 2;
}
rtgui_dc_draw_text(dc, item->name, &item_rect);
/* draw current item */
item_rect = rect;
/* get current item's rect */
item_rect.y1 += 2;
item_rect.y1 += (view->current_item % view->page_items) * (2 + rtgui_theme_get_selected_height());
item_rect.y2 = item_rect.y1 + (2 + rtgui_theme_get_selected_height());
/* draw current item */
rtgui_theme_draw_selected(dc, &item_rect);
item_rect.x1 += LIST_MARGIN;
item = &(view->items[view->current_item]);
if (item->image != RT_NULL)
{
rtgui_image_blit(item->image, dc, &item_rect);
item_rect.x1 += (item->image->w + 2);
}
rtgui_dc_draw_text(dc, item->name, &item_rect);
rtgui_dc_end_drawing(dc);
}
rt_bool_t list_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
{
struct list_view* view = RT_NULL;
view = LIST_VIEW(widget);
switch (event->type)
{
case RTGUI_EVENT_PAINT:
list_view_ondraw(view);
return RT_FALSE;
case RTGUI_EVENT_RESIZE:
{
struct rtgui_event_resize* resize;
resize = (struct rtgui_event_resize*)event;
/* recalculate page items */
view->page_items = resize->h / (2 + rtgui_theme_get_selected_height());
}
break;
case RTGUI_EVENT_KBD:
{
struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event;
if (ekbd->type == RTGUI_KEYDOWN)
{
rt_uint16_t old_item;
old_item = view->current_item;
switch (ekbd->key)
{
case RTGUIK_LEFT:
if (view->current_item - view->page_items >= 0)
view->current_item -= view->page_items;
list_view_update_current(view, old_item);
return RT_FALSE;
case RTGUIK_UP:
if (view->current_item > 0)
view->current_item --;
list_view_update_current(view, old_item);
return RT_FALSE;
case RTGUIK_RIGHT:
if (view->current_item + view->page_items < view->items_count - 1)
view->current_item += view->page_items;
list_view_update_current(view, old_item);
return RT_FALSE;
case RTGUIK_DOWN:
if (view->current_item < view->items_count - 1)
view->current_item ++;
list_view_update_current(view, old_item);
return RT_FALSE;
case RTGUIK_RETURN:
if (view->items[view->current_item].action != RT_NULL)
{
view->items[view->current_item].action(view->items[view->current_item].parameter);
}
return RT_FALSE;
default:
break;
}
}
}
return RT_FALSE;
}
/* use view event handler */
return rtgui_view_event_handler(widget, event);
}
list_view_t* list_view_create(struct list_item* items, rt_uint16_t count, rtgui_rect_t *rect)
{
struct list_view* view = RT_NULL;
view = (struct list_view*) rtgui_widget_create(LIST_VIEW_TYPE);
if (view != RT_NULL)
{
view->items = items;
view->items_count = count;
view->page_items = rtgui_rect_height(*rect) / (2 + rtgui_theme_get_selected_height());
}
return view;
}
void list_view_destroy(list_view_t* view)
{
/* destroy view */
rtgui_widget_destroy(RTGUI_WIDGET(view));
}

View File

@ -1,53 +0,0 @@
#ifndef __RTGUI_LIST_VIEW_H__
#define __RTGUI_LIST_VIEW_H__
#include <rtgui/rtgui.h>
#include <rtgui/image.h>
#include <rtgui/rtgui_system.h>
#include <rtgui/widgets/view.h>
typedef void (*item_action)(void* parameter);
struct list_item
{
char* name;
rtgui_image_t *image;
item_action action;
void *parameter;
};
/** Gets the type of a list view */
#define LIST_VIEW_TYPE (list_view_type_get())
/** Casts the object to a filelist */
#define LIST_VIEW(obj) (RTGUI_OBJECT_CAST((obj), LIST_VIEW_TYPE, list_view_t))
/** Checks if the object is a filelist view */
#define IS_LIST_VIEW(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), LIST_VIEW_TYPE))
struct list_view
{
struct rtgui_view parent;
/* widget private data */
/* list item */
struct list_item* items;
/* total number of items */
rt_uint16_t items_count;
/* the number of item in a page */
rt_uint16_t page_items;
/* current item */
rt_uint16_t current_item;
};
typedef struct list_view list_view_t;
rtgui_type_t *list_view_type_get(void);
list_view_t* list_view_create(struct list_item* items, rt_uint16_t count,
rtgui_rect_t *rect);
void list_view_clear(list_view_t* view);
rt_bool_t list_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event);
#endif

View File

@ -523,8 +523,7 @@ void http_mp3(char* url)
} }
FINSH_FUNCTION_EXPORT(http_mp3, http mp3 decode test); FINSH_FUNCTION_EXPORT(http_mp3, http mp3 decode test);
/* http mp3 */ /* ice mp3 */
#include "http.h"
static rt_size_t ice_fetch(rt_uint8_t* ptr, rt_size_t len, void* parameter) static rt_size_t ice_fetch(rt_uint8_t* ptr, rt_size_t len, void* parameter)
{ {
struct shoutcast_session* session = (struct shoutcast_session*)parameter; struct shoutcast_session* session = (struct shoutcast_session*)parameter;
@ -577,15 +576,4 @@ void ice_mp3(char* url)
} }
FINSH_FUNCTION_EXPORT(ice_mp3, shoutcast mp3 decode test); FINSH_FUNCTION_EXPORT(ice_mp3, shoutcast mp3 decode test);
char ice_url[] = "http://192.168.1.5:8000/stream";
void ice()
{
rt_thread_t tid;
tid = rt_thread_create("ice", ice_mp3, (void*)ice_url,
4096, 0x08, 5);
if (tid != RT_NULL) rt_thread_startup(tid);
}
FINSH_FUNCTION_EXPORT(ice, shoutcast thread test);
#endif #endif

12
bsp/stm32_radio/mp3.h Normal file
View File

@ -0,0 +1,12 @@
#ifndef __MP3_H__
#define __MP3_H__
#include "player_ui.h"
void mp3_get_info(const char* filename, struct tag_info* info);
void mp3(char* filename);
void http_mp3(char* url);
void ice_mp3(char* url);
#endif

View File

@ -2,6 +2,7 @@
#include <rtthread.h> #include <rtthread.h>
#include "netbuffer.h" #include "netbuffer.h"
#include "player_ui.h"
#define MP3_DECODE_MP_CNT 2 #define MP3_DECODE_MP_CNT 2
#define MP3_DECODE_MP_SZ 2560 #define MP3_DECODE_MP_SZ 2560

View File

@ -1,5 +1,7 @@
#include "play_list.h" #include "play_list.h"
#include "player_ui.h" #include "player_ui.h"
#include "mp3.h"
#include <string.h> #include <string.h>
static struct play_item **play_list = RT_NULL; static struct play_item **play_list = RT_NULL;

View File

@ -1,5 +1,6 @@
#include "player_bg.h" #include "player_bg.h"
#include "player_ui.h" #include "player_ui.h"
#include "mp3.h"
#include <string.h> #include <string.h>
@ -23,17 +24,7 @@ void player_play_req(const char* fn)
rt_mq_send(player_thread_mq, (void*)&request, sizeof(struct player_request)); rt_mq_send(player_thread_mq, (void*)&request, sizeof(struct player_request));
} }
#ifdef RT_USING_FINSH void player_stop_req()
#include <finsh.h>
static const char _fn[] = "/005.mp3";
void play()
{
player_play_file(_fn);
}
FINSH_FUNCTION_EXPORT(play, play mp3 file test);
#endif
void player_stop()
{ {
is_playing = RT_FALSE; is_playing = RT_FALSE;
} }
@ -109,3 +100,4 @@ void player_init()
player_ui_init(); player_ui_init();
} }
} }

View File

@ -8,21 +8,23 @@ enum PLAYER_REQUEST_TYPE
PLAYER_REQUEST_PLAY_SINGLE_FILE, PLAYER_REQUEST_PLAY_SINGLE_FILE,
PLAYER_REQUEST_PLAY_LIST, PLAYER_REQUEST_PLAY_LIST,
PLAYER_REQUEST_STOP, PLAYER_REQUEST_STOP,
PLAYER_REQUEST_NEXT,
PLAYER_REQUEST_PREV,
}; };
struct player_request struct player_request
{ {
enum PLAYER_REQUEST_TYPE type; enum PLAYER_REQUEST_TYPE type;
char fn[64]; char fn[64];
}; };
/* get player background status */
rt_bool_t player_is_playing(void); rt_bool_t player_is_playing(void);
void player_stop(void); /* player background thread init */
void player_init(void);
void player_play_list(const char** list); /* send a stop request to player background thread */
void player_play_file(const char* fn); void player_stop_req(void);
/* send a play request to player background thread */
void player_play_req(const char* fn);
#endif #endif

View File

@ -3,25 +3,27 @@
#include <rtgui/rtgui_system.h> #include <rtgui/rtgui_system.h>
#include <rtgui/widgets/view.h> #include <rtgui/widgets/view.h>
#include <rtgui/widgets/list_view.h>
#include <rtgui/widgets/workbench.h> #include <rtgui/widgets/workbench.h>
#include <string.h> #include <rtgui/widgets/filelist_view.h>
#include <string.h>
#include <dfs_posix.h> #include <dfs_posix.h>
#include "mp3.h"
#include "picture.h"
#include "player_ui.h" #include "player_ui.h"
#include "player_bg.h" #include "player_bg.h"
#include "play_list.h" #include "play_list.h"
#include "station_list.h"
#include "listview.h"
#include "filelist.h"
#include "play.hdh" #include "play.hdh"
#include "stop.hdh" #include "stop.hdh"
static rtgui_image_t *background = RT_NULL; #define RADIO_FN "/radio.pls"
static struct rtgui_view* function_view;
static struct rtgui_view* home_view; static struct rtgui_view* home_view;
static struct rtgui_list_view* function_view;
static struct rtgui_workbench* workbench; static struct rtgui_workbench* workbench;
static rtgui_timer_t* info_timer; static rtgui_timer_t* info_timer;
static rt_thread_t player_ui_tid = RT_NULL; static rt_thread_t player_ui_tid = RT_NULL;
@ -29,32 +31,10 @@ static enum PLAYER_MODE player_mode = PLAYER_STOP;
static enum PLAYER_STEP next_step = PLAYER_STEP_STOP; static enum PLAYER_STEP next_step = PLAYER_STEP_STOP;
static struct tag_info tinfo; static struct tag_info tinfo;
void player_set_position(rt_uint32_t position) void player_play_file(const char* fn);
{ void player_play_url(const char* url);
if (player_mode != PLAYER_PLAY_RADIO)
{
tinfo.position = position / (tinfo.bit_rate / 8);
}
else
{
tinfo.position = position;
}
}
void player_set_title(const char* title) static void info_timer_timeout(rtgui_timer_t* timer, void* parameter)
{
strncpy(tinfo.title, title, 40);
}
void player_set_buffer_status(rt_bool_t buffering)
{
if (buffering == RT_TRUE)
strncpy(tinfo.artist, "缓冲中...", 40);
else
strncpy(tinfo.artist, "播放中...", 40);
}
void info_timer_timeout(rtgui_timer_t* timer, void* parameter)
{ {
struct rtgui_dc* dc; struct rtgui_dc* dc;
rtgui_color_t saved; rtgui_color_t saved;
@ -68,7 +48,7 @@ void info_timer_timeout(rtgui_timer_t* timer, void* parameter)
rtgui_dc_draw_hline(dc, 14, 14 + (tinfo.position * 212)/ tinfo.duration, rtgui_dc_draw_hline(dc, 14, 14 + (tinfo.position * 212)/ tinfo.duration,
75); 75);
if (player_mode == PLAYER_PLAY_RADIO) if ((player_mode == PLAYER_PLAY_RADIO) && ((tinfo.position * 212 + 14)/tinfo.duration) < 226)
{ {
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(home_view)) = RTGUI_RGB(82, 199, 16); RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(home_view)) = RTGUI_RGB(82, 199, 16);
rtgui_dc_draw_hline(dc, 14 + (tinfo.position * 212)/ tinfo.duration, 226, 75); rtgui_dc_draw_hline(dc, 14 + (tinfo.position * 212)/ tinfo.duration, 226, 75);
@ -78,43 +58,12 @@ void info_timer_timeout(rtgui_timer_t* timer, void* parameter)
rtgui_dc_end_drawing(dc); rtgui_dc_end_drawing(dc);
} }
static rt_uint32_t read_line(int fd, char* line, rt_uint32_t line_size)
{
char *pos, *next;
rt_uint32_t length;
length = read(fd, line, line_size);
if (length > 0)
{
pos = strstr(line, "\r\n");
if (pos == RT_NULL)
{
pos = strstr(line, "\n");
next = pos ++;
}
else next = pos + 2;
if (pos != RT_NULL)
{
*pos = '\0';
/* move back */
lseek(fd, -(length - (next - line)), SEEK_CUR);
length = pos - line;
}
else length = 0;
}
rt_kprintf("line %s\n", line);
return length;
}
static void player_update_tag_info(struct rtgui_dc* dc) static void player_update_tag_info(struct rtgui_dc* dc)
{ {
rtgui_rect_t rect; rtgui_rect_t rect;
char line[32]; char line[32];
rtgui_color_t saved; rtgui_color_t saved;
rtgui_image_t *background;
saved = rtgui_dc_get_color(dc); saved = rtgui_dc_get_color(dc);
rtgui_dc_set_color(dc, black); rtgui_dc_set_color(dc, black);
@ -170,6 +119,222 @@ static void player_update_tag_info(struct rtgui_dc* dc)
rtgui_dc_set_color(dc, saved); rtgui_dc_set_color(dc, saved);
} }
static rt_uint32_t read_line(int fd, char* line, rt_uint32_t line_size)
{
char *pos, *next;
rt_uint32_t length;
length = read(fd, line, line_size);
if (length > 0)
{
pos = strstr(line, "\r\n");
if (pos == RT_NULL)
{
pos = strstr(line, "\n");
next = pos ++;
}
else next = pos + 2;
if (pos != RT_NULL)
{
*pos = '\0';
/* move back */
lseek(fd, -(length - (next - line)), SEEK_CUR);
length = pos - line;
}
else length = 0;
}
return length;
}
static void function_play_radio(void* parameter)
{
struct station_list* list;
struct station_item* item;
list = station_list_create(RADIO_FN);
if (list != RT_NULL)
{
item = station_list_select(list, workbench);
if (item != RT_NULL)
{
player_play_url(item->url);
}
station_list_destroy(list);
}
}
static void function_filelist(void* parameter)
{
rtgui_rect_t rect;
rtgui_filelist_view_t *view;
rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect);
view = rtgui_filelist_view_create(workbench, "/", "*.*", &rect);
if (view != RT_NULL)
{
if (rtgui_view_show(RTGUI_VIEW(view), RT_TRUE) == RTGUI_MODAL_OK)
{
char fn[64];
/* get open file */
rt_snprintf(fn, 64, "%s/%s", view->current_directory,
view->items[view->current_item].name);
if (strstr(view->items[view->current_item].name , ".mp3") != RT_NULL ||
strstr(view->items[view->current_item].name , ".MP3") != RT_NULL ||
strstr(view->items[view->current_item].name , ".wav") != RT_NULL ||
strstr(view->items[view->current_item].name , ".WAV") != RT_NULL)
{
/* clear old play list */
play_list_clear();
play_list_append(fn);
player_mode = PLAYER_PLAY_FILE;
next_step = PLAYER_STEP_STOP;
player_play_file(play_list_start());
}
else if (strstr(view->items[view->current_item].name , ".m3u") != RT_NULL ||
strstr(view->items[view->current_item].name , ".M3U") != RT_NULL)
{
/* read all of music filename to a list */
int fd;
char line[64];
fd = open(fn, O_RDONLY, 0);
if (fd >= 0)
{
rt_uint32_t length;
length = read_line(fd, line, sizeof(line));
/* clear old play list */
play_list_clear();
do
{
length = read_line(fd, line, sizeof(line));
if (length > 0)
{
if (strstr(line, "http:") != RT_NULL)
{
play_list_append(line);
}
else if (line[0] != '/')
{
rt_snprintf(fn, sizeof(fn),
"%s/%s", view->current_directory, line);
play_list_append(fn);
}
else play_list_append(line);
}
} while (length > 0);
close(fd);
if (play_list_items() > 0)
{
player_mode = PLAYER_PLAY_FILE;
next_step = PLAYER_STEP_NEXT;
player_play_file(play_list_start());
}
}
}
}
/* destroy view */
rtgui_filelist_view_destroy(view);
}
return;
}
static void function_device(void* parameter)
{
rtgui_view_t *view;
extern rtgui_view_t* device_view_create(rtgui_workbench_t* workbench);
view = device_view_create(workbench);
if (view != RT_NULL)
{
rtgui_view_show(view, RT_FALSE);
}
return;
}
static void function_player(void* parameter)
{
rtgui_view_show(home_view, RT_FALSE);
return;
}
static void function_show_picure(void* parameter)
{
rtgui_view_t *view;
view = picture_view_create(workbench);
if (view != RT_NULL)
{
rtgui_view_show(view, RT_TRUE);
rtgui_view_destroy(view);
}
return;
}
void function_action(void* parameter)
{
rt_kprintf("item action!\n");
return;
}
void function_cable(void* parameter)
{
extern void USB_cable(void);
USB_cable();
}
const struct rtgui_list_item function_list[] =
{
{"选择电台", RT_NULL, function_play_radio, RT_NULL},
{"更新电台", RT_NULL, function_action, RT_NULL},
{"播放文件", RT_NULL, function_filelist, RT_NULL},
{"浏览图片", RT_NULL, function_show_picure, RT_NULL},
{"设备信息", RT_NULL, function_device, RT_NULL},
{"选项设置", RT_NULL, function_action, RT_NULL},
{"USB 联机", RT_NULL, function_cable, RT_NULL},
{"返回播放器", RT_NULL, function_player, RT_NULL},
};
void player_set_position(rt_uint32_t position)
{
if (player_mode != PLAYER_PLAY_RADIO)
{
tinfo.position = position / (tinfo.bit_rate / 8);
}
else
{
tinfo.position = position;
}
}
void player_set_title(const char* title)
{
strncpy(tinfo.title, title, 40);
}
void player_set_buffer_status(rt_bool_t buffering)
{
if (buffering == RT_TRUE)
strncpy(tinfo.artist, "缓冲中...", 40);
else
strncpy(tinfo.artist, "播放中...", 40);
}
void player_play_file(const char* fn) void player_play_file(const char* fn)
{ {
struct rtgui_dc* dc; struct rtgui_dc* dc;
@ -233,7 +398,6 @@ void player_play_file(const char* fn)
rtgui_view_show(home_view, RT_FALSE); rtgui_view_show(home_view, RT_FALSE);
rt_kprintf("play file: %s\n", fn);
player_play_req(fn); player_play_req(fn);
} }
@ -271,157 +435,9 @@ void player_play_url(const char* url)
rtgui_view_show(home_view, RT_FALSE); rtgui_view_show(home_view, RT_FALSE);
rt_kprintf("play radio url: %s\n", url);
player_play_req(url); player_play_req(url);
} }
void function_play_radio(void* parameter)
{
next_step = PLAYER_STEP_STOP;
player_play_url("http://syragon.com:8000/ices");
// player_play_url("http://192.168.1.6:8000/stream");
// player_play_url("http://radio.aozima.com:8000/stream");
}
void function_filelist(void* parameter)
{
rtgui_rect_t rect;
filelist_view_t *view;
rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect);
view = filelist_view_create(workbench, "/", "*.*", &rect);
if (view != RT_NULL)
{
if (rtgui_view_show(RTGUI_VIEW(view), RT_TRUE) == RTGUI_MODAL_OK)
{
char fn[64];
/* get open file */
rt_snprintf(fn, 64, "%s/%s", view->current_directory,
view->items[view->current_item].name);
if (strstr(view->items[view->current_item].name , ".mp3") != RT_NULL ||
strstr(view->items[view->current_item].name , ".MP3") != RT_NULL ||
strstr(view->items[view->current_item].name , ".wav") != RT_NULL ||
strstr(view->items[view->current_item].name , ".WAV") != RT_NULL)
{
/* clear old play list */
play_list_clear();
play_list_append(fn);
player_mode = PLAYER_PLAY_FILE;
next_step = PLAYER_STEP_STOP;
player_play_file(play_list_start());
}
else if (strstr(view->items[view->current_item].name , ".m3u") != RT_NULL ||
strstr(view->items[view->current_item].name , ".M3U") != RT_NULL)
{
/* read all of music filename to a list */
int fd;
char line[64];
fd = open(fn, O_RDONLY, 0);
if (fd >= 0)
{
rt_uint32_t length;
length = read_line(fd, line, sizeof(line));
/* clear old play list */
play_list_clear();
do
{
length = read_line(fd, line, sizeof(line));
if (length > 0)
{
if (line[0] != '/')
{
rt_snprintf(fn, sizeof(fn),
"%s/%s", view->current_directory, line);
play_list_append(fn);
}
else play_list_append(line);
}
} while (length > 0);
close(fd);
if (play_list_items() > 0)
{
player_mode = PLAYER_PLAY_FILE;
next_step = PLAYER_STEP_NEXT;
player_play_file(play_list_start());
}
}
}
}
/* destroy view */
filelist_view_destroy(view);
}
return;
}
void function_device(void* parameter)
{
rtgui_view_t *view;
extern rtgui_view_t* device_view_create(rtgui_workbench_t* workbench);
view = device_view_create(workbench);
if (view != RT_NULL)
{
rtgui_view_show(view, RT_FALSE);
}
return;
}
void function_player(void* parameter)
{
rtgui_view_show(home_view, RT_FALSE);
return;
}
#include "picture.h"
void function_show_picure(void* parameter)
{
rtgui_view_t *view;
view = picture_view_create(workbench);
if (view != RT_NULL)
{
rtgui_view_show(view, RT_TRUE);
rtgui_view_destroy(view);
}
return;
}
void function_action(void* parameter)
{
rt_kprintf("item action!\n");
return;
}
extern void USB_cable(void);
void function_cable(void)
{
USB_cable();
}
struct list_item function_list[] =
{
{"选择电台", RT_NULL, function_play_radio, RT_NULL},
{"更新电台", RT_NULL, function_action, RT_NULL},
{"播放文件", RT_NULL, function_filelist, RT_NULL},
{"浏览图片", RT_NULL, function_show_picure, RT_NULL},
{"设备信息", RT_NULL, function_device, RT_NULL},
{"选项设置", RT_NULL, function_action, RT_NULL},
{"USB 联机", RT_NULL, function_cable, RT_NULL},
{"返回播放器", RT_NULL, function_player, RT_NULL},
};
static rt_bool_t home_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event) static rt_bool_t home_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
{ {
if (event->type == RTGUI_EVENT_PAINT) if (event->type == RTGUI_EVENT_PAINT)
@ -429,6 +445,7 @@ static rt_bool_t home_view_event_handler(struct rtgui_widget* widget, struct rtg
struct rtgui_dc* dc; struct rtgui_dc* dc;
struct rtgui_rect rect; struct rtgui_rect rect;
rtgui_color_t saved; rtgui_color_t saved;
rtgui_image_t *background;
dc = rtgui_dc_begin_drawing(widget); dc = rtgui_dc_begin_drawing(widget);
if (dc == RT_NULL) return RT_FALSE; if (dc == RT_NULL) return RT_FALSE;
@ -544,14 +561,14 @@ static rt_bool_t home_view_event_handler(struct rtgui_widget* widget, struct rtg
case RTGUIK_RIGHT: case RTGUIK_RIGHT:
if (player_mode == PLAYER_PLAY_FILE && play_list_items() > 0) if (player_mode == PLAYER_PLAY_FILE && play_list_items() > 0)
{ {
player_stop(); player_stop_req();
next_step = PLAYER_STEP_NEXT; next_step = PLAYER_STEP_NEXT;
} }
break; break;
case RTGUIK_LEFT: case RTGUIK_LEFT:
if (player_mode == PLAYER_PLAY_FILE && play_list_items() > 0) if (player_mode == PLAYER_PLAY_FILE && play_list_items() > 0)
{ {
player_stop(); player_stop_req();
next_step = PLAYER_STEP_PREV; next_step = PLAYER_STEP_PREV;
} }
break; break;
@ -559,7 +576,7 @@ static rt_bool_t home_view_event_handler(struct rtgui_widget* widget, struct rtg
case RTGUIK_RETURN: case RTGUIK_RETURN:
if (player_is_playing() == RT_TRUE) if (player_is_playing() == RT_TRUE)
{ {
player_stop(); player_stop_req();
next_step = PLAYER_STEP_STOP; next_step = PLAYER_STEP_STOP;
} }
else else
@ -573,7 +590,7 @@ static rt_bool_t home_view_event_handler(struct rtgui_widget* widget, struct rtg
break; break;
case RTGUIK_DOWN: case RTGUIK_DOWN:
rtgui_view_show(function_view, RT_FALSE); rtgui_view_show(RTGUI_VIEW(function_view), RT_FALSE);
break; break;
} }
} }
@ -735,10 +752,10 @@ static void player_entry(void* parameter)
/* add function view */ /* add function view */
rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect); rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect);
function_view = (struct rtgui_view*)list_view_create(function_list, function_view = rtgui_list_view_create(function_list,
sizeof(function_list)/sizeof(struct list_item), sizeof(function_list)/sizeof(struct rtgui_list_item),
&rect); &rect);
rtgui_workbench_add_view(workbench, function_view); rtgui_workbench_add_view(workbench, RTGUI_VIEW(function_view));
rtgui_workbench_event_loop(workbench); rtgui_workbench_event_loop(workbench);
@ -769,7 +786,8 @@ void player_notify_stop()
void player_ui_init() void player_ui_init()
{ {
player_ui_tid = rt_thread_create("ply_ui", player_entry, RT_NULL, player_ui_tid = rt_thread_create("ply_ui", player_entry, RT_NULL,
4096, 25, 5); 0x800, 25, 5);
if (player_ui_tid != RT_NULL) if (player_ui_tid != RT_NULL)
rt_thread_startup(player_ui_tid); rt_thread_startup(player_ui_tid);
} }

View File

@ -37,11 +37,16 @@ enum PLAYER_STEP
PLAYER_STEP_NEXT, PLAYER_STEP_NEXT,
}; };
/* init player ui */
void player_ui_init(void); void player_ui_init(void);
/* notification function, which invoked by player background thread */
void player_notify_play(void); void player_notify_play(void);
void player_notify_stop(void); void player_notify_stop(void);
/* set player information */
void player_set_position(rt_uint32_t position); void player_set_position(rt_uint32_t position);
void player_set_title(const char* title);
void player_set_buffer_status(rt_bool_t buffering);
#endif #endif

View File

@ -37,9 +37,7 @@ File 1,1,<.\wav.c><wav.c>
File 1,1,<.\netbuffer.c><netbuffer.c> File 1,1,<.\netbuffer.c><netbuffer.c>
File 1,1,<.\key.c><key.c> File 1,1,<.\key.c><key.c>
File 1,1,<.\info.c><info.c> File 1,1,<.\info.c><info.c>
File 1,1,<.\filelist.c><filelist.c>
File 1,1,<.\device_info.c><device_info.c> File 1,1,<.\device_info.c><device_info.c>
File 1,1,<.\listview.c><listview.c>
File 1,1,<.\player_ui.c><player_ui.c> File 1,1,<.\player_ui.c><player_ui.c>
File 1,1,<.\player_bg.c><player_bg.c> File 1,1,<.\player_bg.c><player_bg.c>
File 1,1,<.\play_list.c><play_list.c> File 1,1,<.\play_list.c><play_list.c>
@ -48,6 +46,7 @@ File 1,1,<.\codec.c><codec.c>
File 1,1,<.\spi_flash.c><spi_flash.c> File 1,1,<.\spi_flash.c><spi_flash.c>
File 1,1,<.\remote.c><remote.c> File 1,1,<.\remote.c><remote.c>
File 1,1,<.\picture.c><picture.c> File 1,1,<.\picture.c><picture.c>
File 1,1,<.\station_list.c><station_list.c>
File 2,1,<..\..\src\clock.c><clock.c> File 2,1,<..\..\src\clock.c><clock.c>
File 2,1,<..\..\src\idle.c><idle.c> File 2,1,<..\..\src\idle.c><idle.c>
File 2,1,<..\..\src\ipc.c><ipc.c> File 2,1,<..\..\src\ipc.c><ipc.c>
@ -210,6 +209,8 @@ File 11,1,<..\..\rtgui\server\topwin.c><topwin.c>
File 11,1,<..\..\rtgui\common\font_hz_file.c><font_hz_file.c> File 11,1,<..\..\rtgui\common\font_hz_file.c><font_hz_file.c>
File 11,1,<..\..\rtgui\common\hz16font.c><hz16font.c> File 11,1,<..\..\rtgui\common\hz16font.c><hz16font.c>
File 11,1,<..\..\rtgui\common\hz12font.c><hz12font.c> File 11,1,<..\..\rtgui\common\hz12font.c><hz12font.c>
File 11,1,<..\..\rtgui\widgets\list_view.c><list_view.c>
File 11,1,<..\..\rtgui\widgets\filelist_view.c><filelist_view.c>
File 12,1,<.\Libraries\Mass_Storage\src\hw_config.c><hw_config.c> File 12,1,<.\Libraries\Mass_Storage\src\hw_config.c><hw_config.c>
File 12,1,<.\Libraries\Mass_Storage\src\mass_mal.c><mass_mal.c> File 12,1,<.\Libraries\Mass_Storage\src\mass_mal.c><mass_mal.c>
File 12,1,<.\Libraries\Mass_Storage\src\memory.c><memory.c> File 12,1,<.\Libraries\Mass_Storage\src\memory.c><memory.c>
@ -279,7 +280,7 @@ Options 1,0,0 // Target 'RT-Thread STM32 Radio'
OCR_RVCT { 1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,8,0,0,8,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,1,0,0,0,0,0,0,0,0,0,0 } OCR_RVCT { 1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,8,0,0,8,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,1,0,0,0,0,0,0,0,0,0,0 }
RV_STAVEC () RV_STAVEC ()
ADSCCFLG { 5,32,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } ADSCCFLG { 5,32,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
ADSCMISC () ADSCMISC (--diag_suppress=870)
ADSCDEFN (USE_STDPERIPH_DRIVER, STM32F10X_HD,) ADSCDEFN (USE_STDPERIPH_DRIVER, STM32F10X_HD,)
ADSCUDEF () ADSCUDEF ()
ADSCINCD (.;.\Libraries\STM32F10x_StdPeriph_Driver\inc;.\Libraries\CMSIS\Core\CM3;..\..\include;..\..\libcpu\arm\stm32;..\..\finsh;..\..\net\lwip\src;..\..\net\lwip\src\include;..\..\net\lwip\src\arch\include;..\..\net\lwip\src\include\ipv4;..\..\filesystem\dfs;..\..\filesystem\dfs\include;..\..\filesystem\dfs\filesystems\efsl\src\include;..\..\filesystem\dfs\filesystems\efsl\src\base\include;..\..\filesystem\dfs\filesystems\efsl\src\fs\vfat\include;..\..\rtgui\include;..\..\rtgui\common\libz) ADSCINCD (.;.\Libraries\STM32F10x_StdPeriph_Driver\inc;.\Libraries\CMSIS\Core\CM3;..\..\include;..\..\libcpu\arm\stm32;..\..\finsh;..\..\net\lwip\src;..\..\net\lwip\src\include;..\..\net\lwip\src\arch\include;..\..\net\lwip\src\include\ipv4;..\..\filesystem\dfs;..\..\filesystem\dfs\include;..\..\filesystem\dfs\filesystems\efsl\src\include;..\..\filesystem\dfs\filesystems\efsl\src\base\include;..\..\filesystem\dfs\filesystems\efsl\src\fs\vfat\include;..\..\rtgui\include;..\..\rtgui\common\libz)

View File

@ -121,7 +121,7 @@
#define RT_LWIP_TCP_SND_BUF 2048 #define RT_LWIP_TCP_SND_BUF 2048
/* TCP Window Size */ /* TCP Window Size */
#define RT_LWIP_TCP_WND (1024 * 2) #define RT_LWIP_TCP_WND (1024 * 20)
/* Enable SNMP protocol */ /* Enable SNMP protocol */
/* #define RT_LWIP_SNMP */ /* #define RT_LWIP_SNMP */

View File

@ -0,0 +1,219 @@
#include <string.h>
#include <dfs_posix.h>
#include "station_list.h"
static rt_uint32_t read_line(int fd, char* line, rt_uint32_t line_size)
{
char *pos, *next;
rt_uint32_t length;
length = read(fd, line, line_size);
if (length > 0)
{
pos = strstr(line, "\r\n");
if (pos == RT_NULL)
{
pos = strstr(line, "\n");
next = pos ++;
}
else next = pos + 2;
if (pos != RT_NULL)
{
*pos = '\0';
/* move back */
lseek(fd, -(length - (next - line)), SEEK_CUR);
length = pos - line;
}
else length = 0;
}
return length;
}
static char *strncasestr(const char *haystack, const char *needle)
{
size_t nl=strlen(needle);
size_t hl=strlen(haystack);
size_t i;
if (!nl) goto found;
if (nl>hl) return 0;
for (i=hl-nl+1; i; --i)
{
if (*haystack==*needle && !strncasecmp(haystack,needle,nl))
found:
return (char*)haystack;
++haystack;
}
return 0;
}
/*
station list file format:
[playlist]
numberofentries=1
File1=http://67.159.5.47:8110
Title1=(#1 - 7/500) The Dominican.net Radio
*/
struct station_list* station_list_create(const char* fn)
{
int fd;
rt_uint32_t length, index;
struct station_list* list;
char *line, *pos, prefix[8];
list = (struct station_list*)rt_malloc(sizeof(struct station_list));
if (list == RT_NULL) goto _return0; /* no memory */
list->count = 0; list->items = RT_NULL;
#define LINE_BUFFER_SIZE 128
line = rt_malloc(LINE_BUFFER_SIZE);
if (line == RT_NULL)
goto _return1; /* no memory */
fd = open(fn, O_RDONLY, 0);
if (fd < 0) goto _return2; /* open file failed */
length = read_line(fd, line, LINE_BUFFER_SIZE);
pos = strncasestr(line, "[playlist]");
if (pos == RT_NULL)
{
station_list_destroy(list);
list = RT_NULL;
goto _return2;
}
length = read_line(fd, line, LINE_BUFFER_SIZE);
pos = strncasestr(line, "numberofentries=");
if (pos != RT_NULL)
{
list->count = (int)strtol(pos + strlen("numberofentries="), RT_NULL, 10);
if (list->count > 0)
{
list->items = (struct station_item*) rt_malloc (sizeof(struct station_item) * list->count);
rt_memset(list->items, 0, sizeof(struct station_item) * list->count);
}
}
else
{
station_list_destroy(list);
list = RT_NULL;
goto _return2;
}
if (list->items == RT_NULL)
{
station_list_destroy(list);
list = RT_NULL;
goto _return2;
}
index = 0;
while (index < list->count)
{
length = read_line(fd, line, LINE_BUFFER_SIZE);
if (length > 0)
{
rt_snprintf(prefix, sizeof(prefix), "File%d", index + 1);
pos = strncasestr(line, prefix);
if (pos != RT_NULL)
strncpy(list->items[index].url, pos + strlen(prefix) + 1, 128);
rt_snprintf(prefix, sizeof(prefix), "Title%d", index + 1);
pos = strncasestr(line, prefix);
if (pos != RT_NULL)
{
strncpy(list->items[index].title, pos + strlen(prefix) + 1, 40);
index ++;
}
}
else break;
}
_return2:
close(fd);
_return1:
rt_free(line);
_return0:
return list;
}
void station_list_destroy(struct station_list* list)
{
/* release memory */
rt_free(list->items);
rt_free(list);
}
/* update station list file from network */
void station_list_update(struct rtgui_workbench* workbench)
{
}
static void station_list_selected(void* parameter)
{
rtgui_list_view_t *view;
view = RTGUI_LIST_VIEW(parameter);
if (view->current_item != 0)
rtgui_view_end_modal(RTGUI_VIEW(view), RTGUI_MODAL_OK);
else
rtgui_view_end_modal(RTGUI_VIEW(view), RTGUI_MODAL_CANCEL);
}
/* select a station from list */
struct station_item* station_list_select(struct station_list* list, struct rtgui_workbench* workbench)
{
rt_size_t index;
rtgui_rect_t rect;
rtgui_list_view_t *view;
struct rtgui_list_item* items;
struct station_item* station;
char exit_str[] = "·µ»Ø..";
RT_ASSERT(list != RT_NULL);
RT_ASSERT(workbench != RT_NULL);
station = RT_NULL;
items = (struct rtgui_list_item*) rt_malloc (sizeof(struct rtgui_list_item) * (list->count + 1));
if (items == RT_NULL) return RT_NULL; /* no memory */
/* create view */
rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect);
view = rtgui_list_view_create(items, list->count + 1, &rect);
items[0].image = RT_NULL;
items[0].action = station_list_selected;
items[0].name = exit_str;
items[0].parameter = view;
for (index = 1; index < list->count + 1; index ++)
{
items[index].image = RT_NULL;
items[index].action = station_list_selected;
items[index].name = list->items[index - 1].title;
items[index].parameter = view;
}
/* add view to workbench */
rtgui_workbench_add_view(workbench, RTGUI_VIEW(view));
/* show view as modal */
if (rtgui_view_show(RTGUI_VIEW(view), RT_TRUE) == RTGUI_MODAL_OK)
{
station = &list->items[view->current_item - 1];
}
/* destroy view */
rtgui_list_view_destroy(view);
return station;
}

View File

@ -0,0 +1,31 @@
#ifndef __STATION_LIST_H__
#define __STATION_LIST_H__
#include <rtthread.h>
#include <rtgui/rtgui.h>
#include <rtgui/widgets/list_view.h>
#include <rtgui/widgets/workbench.h>
struct station_item
{
char title[40];
char url[128];
};
struct station_list
{
rt_uint32_t count;
struct station_item* items;
};
struct station_list* station_list_create(const char* fn);
void station_list_destroy(struct station_list* list);
/* update station list file from network */
void station_list_update(struct rtgui_workbench* workbench);
/* select a station from list */
struct station_item* station_list_select(struct station_list* list, struct rtgui_workbench* workbench);
#endif

View File

@ -1,95 +0,0 @@
#include <rtgui/rtgui.h>
#include <rtgui/rtgui_system.h>
#include <rtgui/widgets/view.h>
#include <rtgui/widgets/workbench.h>
static rt_bool_t view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
{
/* 我们目前只对绘制事件感兴趣 */
if (event->type == RTGUI_EVENT_PAINT)
{
struct rtgui_dc* dc;
struct rtgui_rect rect;
/* 获得一个设备上下文 */
dc = rtgui_dc_begin_drawing(widget);
if (dc == RT_NULL) return RT_FALSE; /* 如果获取失败代表什么?这个控件是隐藏的或... */
rtgui_widget_get_rect(widget, &rect); /* 获得控件的可视区域 */
/* 先对所在可视区域全部填充为背景色 */
rtgui_dc_fill_rect(dc, &rect);
/* 绘制一个hello! */
rtgui_dc_draw_text(dc, "hello world", &rect);
/* 通知RTGUI绘制结束 */
rtgui_dc_end_drawing(dc);
return RT_FALSE;
}
/* 如果不是绘制事件使用view原来的事件处理函数处理 */
return rtgui_view_event_handler(widget, event);
}
static void workbench_entry(void* parameter)
{
rt_mq_t mq;
struct rtgui_view* view;
struct rtgui_workbench* workbench;
/* 创建GUI应用需要的消息队列 */
mq = rt_mq_create("qWB", 256, 4, RT_IPC_FLAG_FIFO);
/* 注册当前线程为GUI线程 */
rtgui_thread_register(rt_thread_self(), mq);
/* 创建一个工作台 */
workbench = rtgui_workbench_create("main", "workbench");
if (workbench == RT_NULL) return;
/* 创建一个工作台上的一个视图 */
view = rtgui_view_create("view");
rtgui_widget_set_event_handler(RTGUI_WIDGET(view), view_event_handler);
/* 在工作台上添加一个视图 */
rtgui_workbench_add_view(workbench, view);
/* 显示这个视图 */
rtgui_view_show(view);
/* 执行工作台事件循环 */
rtgui_workbench_event_loop(workbench);
/* 去注册GUI线程 */
rtgui_thread_deregister(rt_thread_self());
rt_mq_delete(mq);
}
void workbench_init()
{
static rt_bool_t inited = RT_FALSE;
if (inited == RT_FALSE) /* 避免重复初始化而做的保护 */
{
rt_thread_t tid;
tid = rt_thread_create("wb",
workbench_entry, RT_NULL,
2048, 25, 10);
if (tid != RT_NULL) rt_thread_startup(tid);
inited = RT_TRUE;
}
}
#ifdef RT_USING_RTGUI
#include <finsh.h>
void workbench()
{
workbench_init();
}
/* finsh的命令输出可以直接执行workbench()函数以执行上面的函数 */
FINSH_FUNCTION_EXPORT(workbench, workbench demo)
#endif

View File

@ -167,7 +167,7 @@ void rtgui_dc_blit(struct rtgui_dc* dc, struct rtgui_point* dc_point, struct rtg
dc->blit(dc, dc_point, dest, rect); dc->blit(dc, dc_point, dest, rect);
} }
void rtgui_dc_draw_text (struct rtgui_dc* dc, const rt_uint8_t* text, struct rtgui_rect* rect) void rtgui_dc_draw_text (struct rtgui_dc* dc, const char* text, struct rtgui_rect* rect)
{ {
rt_uint32_t len; rt_uint32_t len;
struct rtgui_font *font; struct rtgui_font *font;

View File

@ -120,7 +120,7 @@ void rtgui_font_derefer(struct rtgui_font* font)
} }
/* draw a text */ /* draw a text */
void rtgui_font_draw(struct rtgui_font* font, struct rtgui_dc* dc, const rt_uint8_t* text, rt_ubase_t len, struct rtgui_rect* rect) void rtgui_font_draw(struct rtgui_font* font, struct rtgui_dc* dc, const char* text, rt_ubase_t len, struct rtgui_rect* rect)
{ {
RT_ASSERT(font != RT_NULL); RT_ASSERT(font != RT_NULL);
@ -131,7 +131,7 @@ void rtgui_font_draw(struct rtgui_font* font, struct rtgui_dc* dc, const rt_uint
} }
} }
int rtgui_font_get_string_width(struct rtgui_font* font, const rt_uint8_t* text) int rtgui_font_get_string_width(struct rtgui_font* font, const char* text)
{ {
rtgui_rect_t rect; rtgui_rect_t rect;
@ -141,7 +141,7 @@ int rtgui_font_get_string_width(struct rtgui_font* font, const rt_uint8_t* text)
return rect.x2 - rect.x1; return rect.x2 - rect.x1;
} }
void rtgui_font_get_metrics(struct rtgui_font* font, const rt_uint8_t* text, rtgui_rect_t* rect) void rtgui_font_get_metrics(struct rtgui_font* font, const char* text, rtgui_rect_t* rect)
{ {
RT_ASSERT(font != RT_NULL); RT_ASSERT(font != RT_NULL);
@ -157,8 +157,8 @@ void rtgui_font_get_metrics(struct rtgui_font* font, const rt_uint8_t* text, rtg
} }
} }
static void rtgui_bitmap_font_draw_text(struct rtgui_font* font, struct rtgui_dc* dc, const rt_uint8_t* text, rt_ubase_t len, struct rtgui_rect* rect); static void rtgui_bitmap_font_draw_text(struct rtgui_font* font, struct rtgui_dc* dc, const char* text, rt_ubase_t len, struct rtgui_rect* rect);
static void rtgui_bitmap_font_get_metrics(struct rtgui_font* font, const rt_uint8_t* text, rtgui_rect_t* rect); static void rtgui_bitmap_font_get_metrics(struct rtgui_font* font, const char* text, rtgui_rect_t* rect);
struct rtgui_font_engine bmp_font_engine = struct rtgui_font_engine bmp_font_engine =
{ {
RT_NULL, RT_NULL,
@ -197,7 +197,7 @@ void rtgui_bitmap_font_draw_char(struct rtgui_font_bitmap* font, struct rtgui_dc
} }
} }
static void rtgui_bitmap_font_draw_text(struct rtgui_font* font, struct rtgui_dc* dc, const rt_uint8_t* text, rt_ubase_t len, struct rtgui_rect* rect) static void rtgui_bitmap_font_draw_text(struct rtgui_font* font, struct rtgui_dc* dc, const char* text, rt_ubase_t len, struct rtgui_rect* rect)
{ {
struct rtgui_font_bitmap* bmp_font = (struct rtgui_font_bitmap*)(font->data); struct rtgui_font_bitmap* bmp_font = (struct rtgui_font_bitmap*)(font->data);
@ -213,7 +213,7 @@ static void rtgui_bitmap_font_draw_text(struct rtgui_font* font, struct rtgui_dc
} }
} }
static void rtgui_bitmap_font_get_metrics(struct rtgui_font* font, const rt_uint8_t* text, rtgui_rect_t* rect) static void rtgui_bitmap_font_get_metrics(struct rtgui_font* font, const char* text, rtgui_rect_t* rect)
{ {
struct rtgui_font_bitmap* bmp_font = (struct rtgui_font_bitmap*)(font->data); struct rtgui_font_bitmap* bmp_font = (struct rtgui_font_bitmap*)(font->data);

View File

@ -4,8 +4,8 @@
#ifdef RTGUI_USING_HZ_BMP #ifdef RTGUI_USING_HZ_BMP
static void rtgui_hz_bitmap_font_draw_text(struct rtgui_font* font, struct rtgui_dc* dc, const rt_uint8_t* text, rt_ubase_t len, struct rtgui_rect* rect); static void rtgui_hz_bitmap_font_draw_text(struct rtgui_font* font, struct rtgui_dc* dc, const char* text, rt_ubase_t len, struct rtgui_rect* rect);
static void rtgui_hz_bitmap_font_get_metrics(struct rtgui_font* font, const rt_uint8_t* text, rtgui_rect_t* rect); static void rtgui_hz_bitmap_font_get_metrics(struct rtgui_font* font, const char* text, rtgui_rect_t* rect);
struct rtgui_font_engine hz_bmp_font_engine = struct rtgui_font_engine hz_bmp_font_engine =
{ {
RT_NULL, RT_NULL,
@ -14,7 +14,7 @@ struct rtgui_font_engine hz_bmp_font_engine =
rtgui_hz_bitmap_font_get_metrics rtgui_hz_bitmap_font_get_metrics
}; };
static void rtgui_hz_bitmap_font_draw_text(struct rtgui_font* font, struct rtgui_dc* dc, const rt_uint8_t* text, rt_ubase_t len, struct rtgui_rect* rect) static void rtgui_hz_bitmap_font_draw_text(struct rtgui_font* font, struct rtgui_dc* dc, const char* text, rt_ubase_t len, struct rtgui_rect* rect)
{ {
rt_base_t h; rt_base_t h;
rt_uint8_t* str; rt_uint8_t* str;
@ -61,7 +61,7 @@ static void rtgui_hz_bitmap_font_draw_text(struct rtgui_font* font, struct rtgui
} }
} }
static void rtgui_hz_bitmap_font_get_metrics(struct rtgui_font* font, const rt_uint8_t* text, rtgui_rect_t* rect) static void rtgui_hz_bitmap_font_get_metrics(struct rtgui_font* font, const char* text, rtgui_rect_t* rect)
{ {
struct rtgui_font_bitmap* bmp_font = (struct rtgui_font_bitmap*)(font->data); struct rtgui_font_bitmap* bmp_font = (struct rtgui_font_bitmap*)(font->data);

View File

@ -13,8 +13,8 @@
static int _font_cache_compare(struct hz_cache* node1, struct hz_cache* node2); static int _font_cache_compare(struct hz_cache* node1, struct hz_cache* node2);
static void rtgui_hz_file_font_load(struct rtgui_font* font); static void rtgui_hz_file_font_load(struct rtgui_font* font);
static void rtgui_hz_file_font_draw_text(struct rtgui_font* font, struct rtgui_dc* dc, const rt_uint8_t* text, rt_ubase_t len, struct rtgui_rect* rect); static void rtgui_hz_file_font_draw_text(struct rtgui_font* font, struct rtgui_dc* dc, const char* text, rt_ubase_t len, struct rtgui_rect* rect);
static void rtgui_hz_file_font_get_metrics(struct rtgui_font* font, const rt_uint8_t* text, rtgui_rect_t* rect); static void rtgui_hz_file_font_get_metrics(struct rtgui_font* font, const char* text, rtgui_rect_t* rect);
struct rtgui_font_engine rtgui_hz_file_font_engine = struct rtgui_font_engine rtgui_hz_file_font_engine =
{ {
RT_NULL, RT_NULL,
@ -91,7 +91,7 @@ static void rtgui_hz_file_font_load(struct rtgui_font* font)
hz_file_font->fd = open(hz_file_font->font_fn, O_RDONLY, 0); hz_file_font->fd = open(hz_file_font->font_fn, O_RDONLY, 0);
} }
static void rtgui_hz_file_font_draw_text(struct rtgui_font* font, struct rtgui_dc* dc, const rt_uint8_t* text, rt_ubase_t len, struct rtgui_rect* rect) static void rtgui_hz_file_font_draw_text(struct rtgui_font* font, struct rtgui_dc* dc, const char* text, rt_ubase_t len, struct rtgui_rect* rect)
{ {
rt_base_t h; rt_base_t h;
rt_uint8_t* str; rt_uint8_t* str;
@ -133,7 +133,7 @@ static void rtgui_hz_file_font_draw_text(struct rtgui_font* font, struct rtgui_d
} }
} }
static void rtgui_hz_file_font_get_metrics(struct rtgui_font* font, const rt_uint8_t* text, rtgui_rect_t* rect) static void rtgui_hz_file_font_get_metrics(struct rtgui_font* font, const char* text, rtgui_rect_t* rect)
{ {
struct rtgui_hz_file_font* hz_file_font = (struct rtgui_hz_file_font*)font->data; struct rtgui_hz_file_font* hz_file_font = (struct rtgui_hz_file_font*)font->data;
RT_ASSERT(hz_file_font != RT_NULL); RT_ASSERT(hz_file_font != RT_NULL);

View File

@ -106,7 +106,7 @@ void rtgui_dc_draw_line (struct rtgui_dc* dc, int x1, int y1, int x2, int y2);
void rtgui_dc_draw_rect (struct rtgui_dc* dc, struct rtgui_rect* rect); void rtgui_dc_draw_rect (struct rtgui_dc* dc, struct rtgui_rect* rect);
void rtgui_dc_draw_round_rect(struct rtgui_dc* dc, struct rtgui_rect* rect); void rtgui_dc_draw_round_rect(struct rtgui_dc* dc, struct rtgui_rect* rect);
void rtgui_dc_draw_text (struct rtgui_dc* dc, const rt_uint8_t* text, struct rtgui_rect* rect); void rtgui_dc_draw_text (struct rtgui_dc* dc, const char* text, struct rtgui_rect* rect);
void rtgui_dc_draw_byte(struct rtgui_dc*dc, int x, int y, int h, const rt_uint8_t* data); void rtgui_dc_draw_byte(struct rtgui_dc*dc, int x, int y, int h, const rt_uint8_t* data);
void rtgui_dc_draw_word(struct rtgui_dc*dc, int x, int y, int h, const rt_uint8_t* data); void rtgui_dc_draw_word(struct rtgui_dc*dc, int x, int y, int h, const rt_uint8_t* data);

View File

@ -27,9 +27,9 @@ struct rtgui_font_engine
void (*font_init)(struct rtgui_font* font); void (*font_init)(struct rtgui_font* font);
void (*font_load)(struct rtgui_font* font); void (*font_load)(struct rtgui_font* font);
void (*font_draw_text)(struct rtgui_font* font, struct rtgui_dc* dc, const rt_uint8_t* text, void (*font_draw_text)(struct rtgui_font* font, struct rtgui_dc* dc, const char* text,
rt_ubase_t len, struct rtgui_rect* rect); rt_ubase_t len, struct rtgui_rect* rect);
void (*font_get_metrics)(struct rtgui_font* font, const rt_uint8_t* text, struct rtgui_rect* rect); void (*font_get_metrics)(struct rtgui_font* font, const char* text, struct rtgui_rect* rect);
}; };
/* /*
@ -107,8 +107,8 @@ struct rtgui_font* rtgui_font_refer(const rt_uint8_t* family, rt_uint16_t height
void rtgui_font_derefer(struct rtgui_font* font); void rtgui_font_derefer(struct rtgui_font* font);
/* draw a text */ /* draw a text */
void rtgui_font_draw(struct rtgui_font* font, struct rtgui_dc* dc, const rt_uint8_t* text, rt_ubase_t len, struct rtgui_rect* rect); void rtgui_font_draw(struct rtgui_font* font, struct rtgui_dc* dc, const char* text, rt_ubase_t len, struct rtgui_rect* rect);
int rtgui_font_get_string_width(struct rtgui_font* font, const rt_uint8_t* text); int rtgui_font_get_string_width(struct rtgui_font* font, const char* text);
void rtgui_font_get_metrics(struct rtgui_font* font, const rt_uint8_t* text, struct rtgui_rect* rect); void rtgui_font_get_metrics(struct rtgui_font* font, const char* text, struct rtgui_rect* rect);
#endif #endif

View File

@ -62,8 +62,8 @@ typedef void (*rtgui_onbutton_func_t)(struct rtgui_widget* widget, rtgui_event_t
rtgui_type_t *rtgui_button_type_get(void); rtgui_type_t *rtgui_button_type_get(void);
rtgui_button_t* rtgui_button_create(unsigned char* text); rtgui_button_t* rtgui_button_create(char* text);
rtgui_button_t* rtgui_pushbutton_create(unsigned char* text); rtgui_button_t* rtgui_pushbutton_create(char* text);
void rtgui_button_destroy(rtgui_button_t* btn); void rtgui_button_destroy(rtgui_button_t* btn);
void rtgui_button_set_pressed_image(rtgui_button_t* btn, rtgui_image_t* image); void rtgui_button_set_pressed_image(rtgui_button_t* btn, rtgui_image_t* image);

View File

@ -7,7 +7,7 @@
#define RTGUI_FITEM_DIR 0x1 #define RTGUI_FITEM_DIR 0x1
struct rtgui_file_item struct rtgui_file_item
{ {
rt_uint8_t* name; char* name;
rt_uint32_t type; rt_uint32_t type;
rt_uint32_t size; rt_uint32_t size;
@ -27,8 +27,8 @@ struct rtgui_filelist_view
/* widget private data */ /* widget private data */
/* current directory */ /* current directory */
rt_uint8_t* current_directory; char* current_directory;
rt_uint8_t* pattern; char* pattern;
/* the number of item in a page */ /* the number of item in a page */
rt_uint16_t page_items; rt_uint16_t page_items;

View File

@ -37,7 +37,7 @@ struct rtgui_iconbox
/* widget private data */ /* widget private data */
struct rtgui_image* image; struct rtgui_image* image;
unsigned char *text; char *text;
rt_ubase_t text_position; rt_ubase_t text_position;
rt_bool_t selected; rt_bool_t selected;
@ -46,7 +46,7 @@ typedef struct rtgui_iconbox rtgui_iconbox_t;
rtgui_type_t *rtgui_iconbox_type_get(void); rtgui_type_t *rtgui_iconbox_type_get(void);
struct rtgui_iconbox* rtgui_iconbox_create(struct rtgui_image* image, const unsigned char* text, int position); struct rtgui_iconbox* rtgui_iconbox_create(struct rtgui_image* image, const char* text, int position);
void rtgui_iconbox_destroy(struct rtgui_iconbox* iconbox); void rtgui_iconbox_destroy(struct rtgui_iconbox* iconbox);
rt_bool_t rtgui_iconbox_event_handler(struct rtgui_widget* widget, struct rtgui_event* event); rt_bool_t rtgui_iconbox_event_handler(struct rtgui_widget* widget, struct rtgui_event* event);

View File

@ -32,18 +32,18 @@ struct rtgui_label
struct rtgui_widget parent; struct rtgui_widget parent;
/* label */ /* label */
unsigned char* text; char* text;
}; };
typedef struct rtgui_label rtgui_label_t; typedef struct rtgui_label rtgui_label_t;
rtgui_type_t *rtgui_label_type_get(void); rtgui_type_t *rtgui_label_type_get(void);
rtgui_label_t* rtgui_label_create(const unsigned char* text); rtgui_label_t* rtgui_label_create(const char* text);
void rtgui_label_destroy(rtgui_label_t* label); void rtgui_label_destroy(rtgui_label_t* label);
rt_bool_t rtgui_label_event_handler(struct rtgui_widget* widget, struct rtgui_event* event); rt_bool_t rtgui_label_event_handler(struct rtgui_widget* widget, struct rtgui_event* event);
void rtgui_label_set_text(rtgui_label_t* label, const unsigned char* text); void rtgui_label_set_text(rtgui_label_t* label, const char* text);
unsigned char* rtgui_label_get_text(rtgui_label_t* label); char* rtgui_label_get_text(rtgui_label_t* label);
#endif #endif

View File

@ -44,7 +44,7 @@ struct rtgui_list_view
/* widget private data */ /* widget private data */
/* list item */ /* list item */
struct rtgui_list_item* items; const struct rtgui_list_item* items;
/* total number of items */ /* total number of items */
rt_uint16_t items_count; rt_uint16_t items_count;
@ -57,10 +57,13 @@ typedef struct rtgui_list_view rtgui_list_view_t;
rtgui_type_t *rtgui_list_view_type_get(void); rtgui_type_t *rtgui_list_view_type_get(void);
rtgui_list_view_t* rtgui_list_view_create(struct rtgui_list_item* items, rt_uint16_t count, rtgui_list_view_t* rtgui_list_view_create(const struct rtgui_list_item* items, rt_uint16_t count,
rtgui_rect_t *rect); rtgui_rect_t *rect);
void rtgui_list_view_destroy(rtgui_list_view_t* view);
void rtgui_list_view_clear(rtgui_list_view_t* view); void rtgui_list_view_clear(rtgui_list_view_t* view);
rt_bool_t rtgui_list_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event); rt_bool_t rtgui_list_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event);
#endif #endif

View File

@ -35,7 +35,7 @@
struct rtgui_textbox_line struct rtgui_textbox_line
{ {
rt_uint8_t* line_text; char* line_text;
struct rtgui_textbox_line *prev, *next; struct rtgui_textbox_line *prev, *next;
}; };
@ -51,7 +51,7 @@ struct rtgui_textbox
/* current line and position */ /* current line and position */
rt_uint16_t line, line_begin, position, line_length; rt_uint16_t line, line_begin, position, line_length;
rt_uint8_t* text; char* text;
rt_size_t font_width; rt_size_t font_width;
struct rtgui_timer* caret_timer; struct rtgui_timer* caret_timer;

View File

@ -28,18 +28,18 @@ struct rtgui_wintitle
struct rtgui_toplevel parent; struct rtgui_toplevel parent;
/* title */ /* title */
rt_uint8_t* title; char* title;
}; };
typedef struct rtgui_wintitle rtgui_wintitle_t; typedef struct rtgui_wintitle rtgui_wintitle_t;
rtgui_type_t* rtgui_wintitle_type_get(void); rtgui_type_t* rtgui_wintitle_type_get(void);
rtgui_wintitle_t* rtgui_wintitle_create(const rt_uint8_t* title); rtgui_wintitle_t* rtgui_wintitle_create(const char* title);
void rtgui_wintitle_destroy(rtgui_wintitle_t* wintitle); void rtgui_wintitle_destroy(rtgui_wintitle_t* wintitle);
rt_bool_t rtgui_wintile_event_handler(rtgui_widget_t* widget, rtgui_event_t* event); rt_bool_t rtgui_wintile_event_handler(rtgui_widget_t* widget, rtgui_event_t* event);
void rtgui_wintitle_set_title(rtgui_wintitle_t* wintitle, const rt_uint8_t* title); void rtgui_wintitle_set_title(rtgui_wintitle_t* wintitle, const char* title);
rt_uint8_t *rtgui_wintitle_get_title(rtgui_wintitle_t* wintitle); char *rtgui_wintitle_get_title(rtgui_wintitle_t* wintitle);
#endif #endif

View File

@ -188,7 +188,7 @@ rt_bool_t rtgui_button_event_handler(struct rtgui_widget* widget, struct rtgui_e
return RT_FALSE; return RT_FALSE;
} }
rtgui_button_t* rtgui_button_create(unsigned char* text) rtgui_button_t* rtgui_button_create(char* text)
{ {
struct rtgui_button* btn; struct rtgui_button* btn;
@ -208,7 +208,7 @@ rtgui_button_t* rtgui_button_create(unsigned char* text)
return btn; return btn;
} }
rtgui_button_t* rtgui_pushbutton_create(unsigned char* text) rtgui_button_t* rtgui_pushbutton_create(char* text)
{ {
rtgui_button_t* btn; rtgui_button_t* btn;

View File

@ -219,7 +219,6 @@ const static char * folder_xpm[] = {
/* image for file and folder */ /* image for file and folder */
static rtgui_image_t *file_image, *folder_image; static rtgui_image_t *file_image, *folder_image;
static struct rtgui_filelist_view *filelist_view = RT_NULL; /* only one view in global */
static void _rtgui_filelist_view_constructor(struct rtgui_filelist_view *view) static void _rtgui_filelist_view_constructor(struct rtgui_filelist_view *view)
{ {
@ -489,7 +488,7 @@ rt_bool_t rtgui_filelist_view_event_handler(struct rtgui_widget* widget, struct
if (strcmp(view->items[view->current_item].name, ".") == 0) return RT_FALSE; if (strcmp(view->items[view->current_item].name, ".") == 0) return RT_FALSE;
if (strcmp(view->items[view->current_item].name, "..") == 0) if (strcmp(view->items[view->current_item].name, "..") == 0)
{ {
rt_uint8_t *ptr; char *ptr;
ptr = strrchr(view->current_directory, PATH_SEPARATOR); ptr = strrchr(view->current_directory, PATH_SEPARATOR);
if (ptr == RT_NULL) return RT_FALSE; if (ptr == RT_NULL) return RT_FALSE;
@ -526,10 +525,10 @@ rt_bool_t rtgui_filelist_view_event_handler(struct rtgui_widget* widget, struct
else else
{ {
if (view->current_directory[strlen(view->current_directory) - 1] != PATH_SEPARATOR) if (view->current_directory[strlen(view->current_directory) - 1] != PATH_SEPARATOR)
sprintf(new_path, "%s%c%s",view->current_directory, PATH_SEPARATOR, rt_snprintf(new_path, sizeof(new_path), "%s%c%s",view->current_directory, PATH_SEPARATOR,
view->items[view->current_item].name); view->items[view->current_item].name);
else else
sprintf(new_path, "%s%s",view->current_directory, rt_snprintf(new_path, sizeof(new_path), "%s%s",view->current_directory,
view->items[view->current_item].name); view->items[view->current_item].name);
} }
rtgui_filelist_view_set_directory(view, new_path); rtgui_filelist_view_set_directory(view, new_path);
@ -616,7 +615,7 @@ void rtgui_filelist_view_clear(rtgui_filelist_view_t* view)
void rtgui_filelist_view_set_directory(rtgui_filelist_view_t* view, const char* directory) void rtgui_filelist_view_set_directory(rtgui_filelist_view_t* view, const char* directory)
{ {
rt_uint8_t fullpath[256]; char fullpath[256];
struct rtgui_file_item *item; struct rtgui_file_item *item;
RT_ASSERT(view != RT_NULL); RT_ASSERT(view != RT_NULL);
@ -693,9 +692,9 @@ void rtgui_filelist_view_set_directory(rtgui_filelist_view_t* view, const char*
/* build full path for the file */ /* build full path for the file */
if (directory[strlen(directory) - 1] != PATH_SEPARATOR) if (directory[strlen(directory) - 1] != PATH_SEPARATOR)
sprintf(fullpath, "%s%c%s", directory, PATH_SEPARATOR, dirent->d_name); rt_sprintf(fullpath, "%s%c%s", directory, PATH_SEPARATOR, dirent->d_name);
else else
sprintf(fullpath, "%s%s", directory, dirent->d_name); rt_sprintf(fullpath, "%s%s", directory, dirent->d_name);
stat(fullpath, &s); stat(fullpath, &s);
if ( s.st_mode & S_IFDIR ) if ( s.st_mode & S_IFDIR )

View File

@ -76,7 +76,7 @@ rt_bool_t rtgui_iconbox_event_handler(struct rtgui_widget* widget, struct rtgui_
} }
struct rtgui_iconbox* rtgui_iconbox_create(struct rtgui_image* image, struct rtgui_iconbox* rtgui_iconbox_create(struct rtgui_image* image,
const unsigned char* text, const char* text,
int position) int position)
{ {
struct rtgui_iconbox* iconbox; struct rtgui_iconbox* iconbox;
@ -115,7 +115,7 @@ struct rtgui_iconbox* rtgui_iconbox_create(struct rtgui_image* image,
/* set image and text position */ /* set image and text position */
iconbox->image = image; iconbox->image = image;
iconbox->text = (unsigned char*)rt_strdup((const char*)text); iconbox->text = (char*)rt_strdup((const char*)text);
iconbox->text_position = position; iconbox->text_position = position;
} }

View File

@ -64,7 +64,7 @@ rt_bool_t rtgui_label_event_handler(struct rtgui_widget* widget, struct rtgui_ev
return RT_FALSE; return RT_FALSE;
} }
rtgui_label_t* rtgui_label_create(const unsigned char* text) rtgui_label_t* rtgui_label_create(const char* text)
{ {
struct rtgui_label* label; struct rtgui_label* label;
@ -80,7 +80,7 @@ rtgui_label_t* rtgui_label_create(const unsigned char* text)
rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
/* set text */ /* set text */
label->text = (unsigned char*)rt_strdup((const char*)text); label->text = (char*)rt_strdup((const char*)text);
} }
return label; return label;
@ -91,14 +91,14 @@ void rtgui_label_destroy(rtgui_label_t* label)
rtgui_widget_destroy(RTGUI_WIDGET(label)); rtgui_widget_destroy(RTGUI_WIDGET(label));
} }
unsigned char* rtgui_label_get_text(rtgui_label_t* label) char* rtgui_label_get_text(rtgui_label_t* label)
{ {
RT_ASSERT(label != RT_NULL); RT_ASSERT(label != RT_NULL);
return label->text; return label->text;
} }
void rtgui_label_set_text(rtgui_label_t* label, const unsigned char* text) void rtgui_label_set_text(rtgui_label_t* label, const char* text)
{ {
RT_ASSERT(label != RT_NULL); RT_ASSERT(label != RT_NULL);
@ -108,7 +108,7 @@ void rtgui_label_set_text(rtgui_label_t* label, const unsigned char* text)
rt_free(label->text); rt_free(label->text);
} }
if (text != RT_NULL) label->text = (unsigned char*)rt_strdup((const char*)text); if (text != RT_NULL) label->text = (char*)rt_strdup((const char*)text);
else label->text = RT_NULL; else label->text = RT_NULL;
/* update widget */ /* update widget */

View File

@ -54,7 +54,7 @@ void rtgui_list_view_ondraw(struct rtgui_list_view* view)
struct rtgui_rect rect, item_rect; struct rtgui_rect rect, item_rect;
struct rtgui_dc* dc; struct rtgui_dc* dc;
rt_uint16_t page_index, index; rt_uint16_t page_index, index;
struct rtgui_list_item* item; const struct rtgui_list_item* item;
dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(view)); dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(view));
if (dc == RT_NULL) return; if (dc == RT_NULL) return;
@ -103,7 +103,7 @@ void rtgui_list_view_ondraw(struct rtgui_list_view* view)
void rtgui_list_view_update_current(struct rtgui_list_view* view, rt_uint16_t old_item) void rtgui_list_view_update_current(struct rtgui_list_view* view, rt_uint16_t old_item)
{ {
struct rtgui_dc* dc; struct rtgui_dc* dc;
struct rtgui_list_item* item; const struct rtgui_list_item* item;
rtgui_rect_t rect, item_rect; rtgui_rect_t rect, item_rect;
if (old_item/view->page_items != view->current_item/view->page_items) if (old_item/view->page_items != view->current_item/view->page_items)
@ -267,7 +267,7 @@ rt_bool_t rtgui_list_view_event_handler(struct rtgui_widget* widget, struct rtgu
return rtgui_view_event_handler(widget, event); return rtgui_view_event_handler(widget, event);
} }
rtgui_list_view_t* rtgui_list_view_create(struct rtgui_list_item* items, rt_uint16_t count, rtgui_rect_t *rect) rtgui_list_view_t* rtgui_list_view_create(const struct rtgui_list_item* items, rt_uint16_t count, rtgui_rect_t *rect)
{ {
struct rtgui_list_view* view = RT_NULL; struct rtgui_list_view* view = RT_NULL;

View File

@ -156,7 +156,7 @@ static void rtgui_textbox_onkey(struct rtgui_textbox* box, struct rtgui_event_kb
} }
else else
{ {
unsigned char *c; char *c;
/* remove character */ /* remove character */
for (c = &box->text[box->position]; c[1] != '\0'; c++) for (c = &box->text[box->position]; c[1] != '\0'; c++)
@ -176,7 +176,7 @@ static void rtgui_textbox_onkey(struct rtgui_textbox* box, struct rtgui_event_kb
/* remove current character */ /* remove current character */
if (box->position != 0) if (box->position != 0)
{ {
unsigned char *c; char *c;
/* remove character */ /* remove character */
for (c = &box->text[box->position - 1]; c[1] != '\0'; c++) for (c = &box->text[box->position - 1]; c[1] != '\0'; c++)
@ -218,7 +218,7 @@ static void rtgui_textbox_onkey(struct rtgui_textbox* box, struct rtgui_event_kb
if (box->position < length - 1) if (box->position < length - 1)
{ {
unsigned char* c; char* c;
for (c = &box->text[length]; c != &box->text[box->position]; c--) for (c = &box->text[length]; c != &box->text[box->position]; c--)
*c = *(c-1); *c = *(c-1);

View File

@ -43,7 +43,7 @@ rtgui_type_t* rtgui_wintitle_type_get()
return wintitle_type; return wintitle_type;
} }
rtgui_wintitle_t* rtgui_wintitle_create(const rt_uint8_t* title) rtgui_wintitle_t* rtgui_wintitle_create(const char* title)
{ {
rtgui_wintitle_t* wintitle; rtgui_wintitle_t* wintitle;
@ -61,7 +61,7 @@ void rtgui_wintitle_destroy(rtgui_wintitle_t* wintitle)
rtgui_widget_destroy(RTGUI_WIDGET(wintitle)); rtgui_widget_destroy(RTGUI_WIDGET(wintitle));
} }
void rtgui_wintitle_set_title(rtgui_wintitle_t* wintitle, const rt_uint8_t* title) void rtgui_wintitle_set_title(rtgui_wintitle_t* wintitle, const char* title)
{ {
RT_ASSERT(wintitle != RT_NULL); RT_ASSERT(wintitle != RT_NULL);
@ -70,11 +70,11 @@ void rtgui_wintitle_set_title(rtgui_wintitle_t* wintitle, const rt_uint8_t* titl
rtgui_free(wintitle->title); rtgui_free(wintitle->title);
} }
if (title != RT_NULL) wintitle->title = (unsigned char*)rt_strdup((const char*)title); if (title != RT_NULL) wintitle->title = (char*)rt_strdup((const char*)title);
else wintitle->title = RT_NULL; else wintitle->title = RT_NULL;
} }
rt_uint8_t *rtgui_wintitle_get_title(rtgui_wintitle_t* wintitle) char *rtgui_wintitle_get_title(rtgui_wintitle_t* wintitle)
{ {
RT_ASSERT(wintitle != RT_NULL); RT_ASSERT(wintitle != RT_NULL);