提交 010cec20 编写于 作者: B bernard.xiong

add radio player UI

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@171 bbd45198-f89e-11dd-88c7-29a3b14d5316
上级 c1e1d638
...@@ -42,10 +42,31 @@ ...@@ -42,10 +42,31 @@
#endif #endif
#ifdef RT_USING_RTGUI #ifdef RT_USING_RTGUI
#include <rtgui/rtgui.h> extern void radio_rtgui_init(void);
#include <rtgui/rtgui_system.h>
#endif #endif
void sram_test_entry(void* parameter)
{
rt_uint32_t *ptr;
rt_uint32_t index;
ptr = (rt_uint32_t*)STM32_EXT_SRAM_BEGIN;
index = 0;
while (1)
{
*ptr = index;
ptr ++; index ++;
if (ptr == (rt_uint32_t*)STM32_EXT_SRAM_END)
{
ptr = (rt_uint32_t*)STM32_EXT_SRAM_BEGIN;
rt_kprintf("test passed\n");
rt_thread_delay(50);
}
}
}
/* thread phase init */ /* thread phase init */
void rt_init_thread_entry(void *parameter) void rt_init_thread_entry(void *parameter)
{ {
...@@ -76,11 +97,27 @@ void rt_init_thread_entry(void *parameter) ...@@ -76,11 +97,27 @@ void rt_init_thread_entry(void *parameter)
} }
#endif #endif
/* RTGUI Initialization */
#ifdef RT_USING_RTGUI
{
radio_rtgui_init();
rt_hw_key_init();
}
#endif
/* LwIP Initialization */ /* LwIP Initialization */
#ifdef RT_USING_LWIP #ifdef RT_USING_LWIP
{ {
extern void lwip_sys_init(void); extern void lwip_sys_init(void);
#ifdef RT_USING_LWIP
eth_system_device_init();
/* register ethernetif device */
rt_hw_dm9000_init();
/* init all device */
rt_device_init_all();
#endif
/* init lwip system */ /* init lwip system */
lwip_sys_init(); lwip_sys_init();
rt_kprintf("TCP/IP initialized!\n"); rt_kprintf("TCP/IP initialized!\n");
...@@ -92,32 +129,14 @@ void rt_init_thread_entry(void *parameter) ...@@ -92,32 +129,14 @@ void rt_init_thread_entry(void *parameter)
net_buf_init(320 * 1024); net_buf_init(320 * 1024);
#endif #endif
/* RTGUI Initialization */ #if 0
#ifdef RT_USING_RTGUI
{ {
rtgui_rect_t rect; rt_thread_t tid;
rtgui_system_server_init(); tid = rt_thread_create("sram",
sram_test_entry, RT_NULL,
/* register dock panel */ 512, 30, 5);
rect.x1 = 0; if (tid != RT_NULL) rt_thread_startup(tid);
rect.y1 = 0;
rect.x2 = 240;
rect.y2 = 25;
rtgui_panel_register("info", &rect);
/* register main panel */
rect.x1 = 0;
rect.y1 = 25;
rect.x2 = 240;
rect.y2 = 320;
rtgui_panel_register("main", &rect);
rt_hw_lcd_init();
info_init();
today_init();
} }
#endif #endif
} }
...@@ -139,8 +158,6 @@ int rt_application_init() ...@@ -139,8 +158,6 @@ int rt_application_init()
#endif #endif
if (init_thread != RT_NULL) rt_thread_startup(init_thread); if (init_thread != RT_NULL) rt_thread_startup(init_thread);
rt_hw_key_init();
return 0; return 0;
} }
......
#include <rtgui/rtgui.h>
#include <rtgui/rtgui_system.h>
#include <stdio.h>
#include <stdlib.h>
#include <rtgui/widgets/view.h>
#include <rtgui/widgets/workbench.h>
#include <stm32f10x_dbgmcu.h>
#ifdef RT_USING_LWIP
#include <lwip/err.h>
#include <lwip/dns.h>
#include <lwip/netif.h>
#endif
static struct rtgui_view* device_view = RT_NULL;
int get_thread_cnt()
{
int cnt = 0;
struct rt_list_node *list, *node;
extern struct rt_object_information rt_object_container[];
list = &rt_object_container[RT_Object_Class_Thread].object_list;
for (node = list->next; node != list; node = node->next)
{
cnt ++;
}
return cnt;
}
const static char *stm32_devname[] =
{
"STM32 MD", /* 0x410 */
"STM32 LD", /* 0x412 */
"STM32 HD", /* 0x414 */
"Unknown" , /* 0x416 */
"STM32 CL", /* 0x418 */
};
const static char *stm32_revname[] =
{
"Rev A",
"Rev B",
"Rev Z",
"Rev Y",
"Rev Unknown"
};
/*
* Device Information View
* Device: Win32 or Cortex-M3 etc
* Memory:
* Thread:
* IP Address:
* Gateway:
* DNS:
*/
static rt_bool_t view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
{
switch (event->type)
{
case RTGUI_EVENT_PAINT:
{
struct rtgui_dc* dc;
struct rtgui_rect rect;
char* line;
rt_uint32_t total, used, max_used;
line = rtgui_malloc(256);
if (line == RT_NULL) return RT_FALSE;
dc = rtgui_dc_begin_drawing(widget);
if (dc == RT_NULL)
{
rtgui_free(line);
return RT_FALSE;
}
rtgui_widget_get_rect(widget, &rect);
/* fill background */
rtgui_dc_fill_rect(dc, &rect);
rect.y2 = rect.y1 + 18;
{
rt_uint32_t dev_index, rev_index;
dev_index = DBGMCU_GetDEVID();
dev_index = (dev_index - 0x410)/2;
rev_index = DBGMCU_GetREVID();
switch (rev_index)
{
case 0x1000:
case 0x0000:
rev_index = 0; /* Revision A */
break;
case 0x1001:
case 0x2001:
rev_index = 3; /* Revision Z */
break;
case 0x2000:
rev_index = 1; /* Revision B */
break;
case 0x2002:
rev_index = 2; /* Revision Y */
break;
default:
rev_index = 4; /* Unknown */
break;
};
/* check device index */
if (dev_index < 0 || dev_index > 4) dev_index = 3;
/* draw each information */
sprintf(line, "设备: %s %s",
stm32_devname[dev_index],
stm32_revname[rev_index]);
rtgui_dc_draw_text(dc, line, &rect); rect.y1 += 16; rect.y2 += 16;
}
rt_memory_info(&total, &used, &max_used);
sprintf(line, "内存: 当前使用 %d 字节", used);
rtgui_dc_draw_text(dc, line, &rect); rect.y1 += 16; rect.y2 += 16;
{
rt_uint16_t rect_width;
rtgui_color_t saved;
rtgui_rect_t mem_rect = rect;
rtgui_rect_inflate(&mem_rect, -2);
rtgui_dc_draw_rect(dc, &mem_rect);
rtgui_rect_inflate(&mem_rect, -1);
rect_width = rtgui_rect_width(mem_rect);
saved = RTGUI_WIDGET_BACKGROUND(widget);
RTGUI_WIDGET_BACKGROUND(widget) = light_grey;
mem_rect.x2 = mem_rect.x1 + (max_used * rect_width / total);
rtgui_dc_fill_rect(dc, &mem_rect);
RTGUI_WIDGET_BACKGROUND(widget) = blue;
mem_rect.x2 = mem_rect.x1 + (used * rect_width / total);
rtgui_dc_fill_rect(dc, &mem_rect);
/* restore color */
RTGUI_WIDGET_BACKGROUND(widget) = saved;
}
rect.y1 += 18; rect.y2 += 18;
sprintf(line, "线程数: %d", get_thread_cnt());
rtgui_dc_draw_text(dc, line, &rect); rect.y1 += 16; rect.y2 += 16;
#ifdef RT_USING_LWIP
{
struct ip_addr ip_addr;
struct _ip_addr
{
rt_uint8_t addr0, addr1, addr2, addr3;
} *addr;
addr = (struct _ip_addr*)&netif_default->ip_addr.addr;
sprintf(line, "IP地址 : %d.%d.%d.%d", addr->addr0, addr->addr1, addr->addr2, addr->addr3);
rtgui_dc_draw_text(dc, line, &rect); rect.y1 += 16; rect.y2 += 16;
addr = (struct _ip_addr*)&netif_default->gw.addr;
sprintf(line, "网关地址: %d.%d.%d.%d", addr->addr0, addr->addr1, addr->addr2, addr->addr3);
rtgui_dc_draw_text(dc, line, &rect); rect.y1 += 16; rect.y2 += 16;
addr = (struct _ip_addr*)&netif_default->netmask.addr;
sprintf(line, "网络掩码: %d.%d.%d.%d", addr->addr0, addr->addr1, addr->addr2, addr->addr3);
rtgui_dc_draw_text(dc, line, &rect); rect.y1 += 16; rect.y2 += 16;
#if LWIP_DNS
ip_addr = dns_getserver(0);
addr = (struct _ip_addr*)&ip_addr;
sprintf(line, "DNS地址 : %d.%d.%d.%d", addr->addr0, addr->addr1, addr->addr2, addr->addr3);
rtgui_dc_draw_text(dc, line, &rect); rect.y1 += 16; rect.y2 += 16;
#endif
}
#endif
rtgui_dc_end_drawing(dc);
rtgui_free(line);
return RT_FALSE;
}
case RTGUI_EVENT_KBD:
{
struct rtgui_event_kbd* ekbd;
ekbd = (struct rtgui_event_kbd*)event;
if (ekbd->type == RTGUI_KEYDOWN && ekbd->key == RTGUIK_RETURN)
{
rtgui_workbench_t* workbench;
workbench = RTGUI_WORKBENCH(RTGUI_WIDGET(device_view)->parent);
rtgui_workbench_remove_view(workbench, device_view);
rtgui_view_destroy(device_view);
device_view = RT_NULL;
}
}
return RT_FALSE;
}
/* use parent event handler */
return rtgui_view_event_handler(widget, event);
}
rtgui_view_t *device_view_create(rtgui_workbench_t* workbench)
{
if (device_view != RT_NULL)
{
rtgui_view_show(device_view, RT_FALSE);
}
else
{
/* create a view */
device_view = rtgui_view_create("Device Info");
/* set view event handler */
rtgui_widget_set_event_handler(RTGUI_WIDGET(device_view), view_event_handler);
/* this view can be focused */
RTGUI_WIDGET(device_view)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
/* add view to workbench */
rtgui_workbench_add_view(workbench, device_view);
}
return device_view;
}
...@@ -276,7 +276,7 @@ static rt_err_t rt_dm9000_init(rt_device_t dev) ...@@ -276,7 +276,7 @@ static rt_err_t rt_dm9000_init(rt_device_t dev)
while (!(phy_read(1) & 0x20)) while (!(phy_read(1) & 0x20))
{ {
/* autonegation complete bit */ /* autonegation complete bit */
delay_ms(10); rt_thread_delay(10);
i++; i++;
if (i == 10000) if (i == 10000)
{ {
......
此差异已折叠。
#ifndef __FILE_LIST_VIEW_H__ #ifndef __FILE_LIST_VIEW_H__
#define __FILE_LIST_VIEW_H__ #define __FILE_LIST_VIEW_H__
#include <rtgui/widgets/view.h>
#define FITEM_FILE 0x0 #define FITEM_FILE 0x0
#define FITEM_DIR 0x1 #define FITEM_DIR 0x1
struct file_item struct file_item
{ {
char* name; rt_uint8_t* name;
rt_uint32_t type; rt_uint32_t type;
rt_uint32_t size; rt_uint32_t size;
/* files under same directory */
rtgui_list_t list;
}; };
/** Gets the type of a filelist view */ /** Gets the type of a filelist view */
...@@ -27,22 +26,30 @@ struct filelist_view ...@@ -27,22 +26,30 @@ struct filelist_view
/* widget private data */ /* widget private data */
/* total number of items */
rt_uint32_t count;
/* the selected item */
struct file_item* selected;
/* current directory */ /* current directory */
rt_uint8_t* current_directory; rt_uint8_t* current_directory;
rt_uint8_t* pattern; rt_uint8_t* 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;
rt_uint16_t items_count;
/* item_list */ /* the selected item */
rtgui_list_t item_list; rt_uint16_t current_item;
/* items array */
struct file_item *items;
}; };
typedef struct filelist_view filelist_view_t; typedef struct filelist_view filelist_view_t;
#endif rtgui_type_t *filelist_view_type_get(void);
\ No newline at end of file
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
#include <ctype.h>
#include <fnmatch.h>
#include <string.h>
#define NOTFIRST 128
#define STRUCT_CHARCLASS(c) { #c , is##c }
static struct charclass {
char * class;
int (*istype)(int);
} allclasses[] = {
STRUCT_CHARCLASS(alnum),
STRUCT_CHARCLASS(alpha),
STRUCT_CHARCLASS(blank),
STRUCT_CHARCLASS(cntrl),
STRUCT_CHARCLASS(digit),
STRUCT_CHARCLASS(graph),
STRUCT_CHARCLASS(lower),
STRUCT_CHARCLASS(print),
STRUCT_CHARCLASS(punct),
STRUCT_CHARCLASS(space),
STRUCT_CHARCLASS(upper),
STRUCT_CHARCLASS(xdigit),
};
/* look for "class:]" in pattern */
static struct charclass *charclass_lookup(const char *pattern) {
unsigned int i;
for (i = 0; i< sizeof(allclasses)/sizeof(*allclasses); i++) {
int len = strlen(allclasses[i].class);
if (!strncmp(pattern, allclasses[i].class, len)) {
pattern += len;
if (strncmp(pattern, ":]", 2)) goto noclass;
return &allclasses[i];
}
}
noclass:
return NULL;
}
static int match(char c,char d,int flags) {
if (flags&FNM_CASEFOLD)
return (tolower(c)==tolower(d));
else
return (c==d);
}
int fnmatch(const char *pattern, const char *string, int flags) {
if (*string==0) {
while (*pattern=='*') ++pattern;
return (!!*pattern);
}
if (*string=='.' && *pattern!='.' && (flags&FNM_PERIOD)) {
/* don't match if FNM_PERIOD and this is the first char */
if (!(flags&NOTFIRST))
return FNM_NOMATCH;
/* don't match if FNM_PERIOD and FNM_PATHNAME and previous was '/' */
if ((flags&(FNM_PATHNAME)) && string[-1]=='/')
return FNM_NOMATCH;
}
flags|=NOTFIRST;
switch (*pattern) {
case '[':
{
int neg=0;
const char* start; /* first member of character class */
++pattern;
if (*string=='/' && flags&FNM_PATHNAME) return FNM_NOMATCH;
if (*pattern=='!') { neg=1; ++pattern; }
start=pattern;
while (*pattern) {
int res=0;
if (*pattern==']' && pattern!=start) break;
if (*pattern=='[' && pattern[1]==':') {
/* MEMBER - stupid POSIX char classes */
const struct charclass *cc;
if (!(cc = charclass_lookup(pattern+2))) goto invalidclass;
pattern += strlen(cc->class) + 4;
if (flags&FNM_CASEFOLD
&& (cc->istype == isupper || cc->istype == islower)) {
res = islower(tolower(*string));
} else {
res = ((*(cc->istype))(*string));
}
} else {
invalidclass:
if (pattern[1]=='-' && pattern[2]!=']') {
/* MEMBER - character range */
if (*string>=*pattern && *string<=pattern[2]) res=1;
if (flags&FNM_CASEFOLD) {
if (tolower(*string)>=tolower(*pattern) && tolower(*string)<=tolower(pattern[2])) res=1;
}
pattern+=3;
} else {
/* MEMBER - literal character match */
res=match(*pattern,*string,flags);
++pattern;
}
}
if ((res&&!neg) || ((neg&&!res) && *pattern==']')) {
while (*pattern && *pattern!=']') ++pattern;
return fnmatch(pattern+!!*pattern,string+1,flags);
} else if (res && neg)
return FNM_NOMATCH;
}
}
break;
case '\\':
if (flags&FNM_NOESCAPE) {
if (*string=='\\')
return fnmatch(pattern+1,string+1,flags);
} else {
if (*string==pattern[1])
return fnmatch(pattern+2,string+1,flags);
}
break;
case '*':
if ((*string=='/' && flags&FNM_PATHNAME) || fnmatch(pattern,string+1,flags))
return fnmatch(pattern+1,string,flags);
return 0;
case 0:
if (*string==0 || (*string=='/' && (flags&FNM_LEADING_DIR)))
return 0;
break;
case '?':
if (*string=='/' && flags&FNM_PATHNAME) break;
return fnmatch(pattern+1,string+1,flags);
default:
if (match(*pattern,*string,flags))
return fnmatch(pattern+1,string+1,flags);
break;
}
return FNM_NOMATCH;
}
#ifndef _FNMATCH_H
#define _FNMATCH_H
#include <sys/cdefs.h>
__BEGIN_DECLS
int fnmatch(const char *pattern, const char *string, int flags) __THROW;
#define FNM_NOESCAPE 1
#define FNM_PATHNAME 2
#define FNM_FILE_NAME 2
#define FNM_PERIOD 4
#define FNM_LEADING_DIR 8
#define FNM_CASEFOLD 16
#define FNM_NOMATCH 1
__END_DECLS
#endif
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "network.xpm" #include "network.xpm"
static rtgui_image_t *rtt_image = RT_NULL;
static rtgui_image_t *network_image = RT_NULL; static rtgui_image_t *network_image = RT_NULL;
static rtgui_image_t *usb_image = RT_NULL; static rtgui_image_t *usb_image = RT_NULL;
static rtgui_image_t *power_image = RT_NULL; static rtgui_image_t *power_image = RT_NULL;
...@@ -23,7 +24,19 @@ static rt_bool_t view_event_handler(struct rtgui_widget* widget, struct rtgui_ev ...@@ -23,7 +24,19 @@ static rt_bool_t view_event_handler(struct rtgui_widget* widget, struct rtgui_ev
rtgui_widget_get_rect(widget, &rect); rtgui_widget_get_rect(widget, &rect);
rtgui_dc_fill_rect(dc, &rect); rtgui_dc_fill_rect(dc, &rect);
rtgui_dc_draw_hline(dc, rect.x1, rect.x2, rect.y2 - 1);
/* draw RT-Thread logo */
rtt_image = rtgui_image_create_from_file("hdc",
"/resource/RTT.hdc", RT_FALSE);
if (rtt_image != RT_NULL)
{
rtgui_image_blit(rtt_image, dc, &rect);
rtgui_image_destroy(rtt_image);
rtt_image = RT_NULL;
}
if (network_image != RT_NULL) if (network_image != RT_NULL)
{ {
rect.x1 = rect.x2 - (network_image->w + 2); rect.x1 = rect.x2 - (network_image->w + 2);
...@@ -48,7 +61,7 @@ static void info_entry(void* parameter) ...@@ -48,7 +61,7 @@ static void info_entry(void* parameter)
rtgui_thread_register(rt_thread_self(), mq); rtgui_thread_register(rt_thread_self(), mq);
network_image = rtgui_image_create_from_mem("xpm", network_image = rtgui_image_create_from_mem("xpm",
network_xpm, sizeof(network_xpm)); (rt_uint8_t*)network_xpm, sizeof(network_xpm));
workbench = rtgui_workbench_create("info", "workbench"); workbench = rtgui_workbench_create("info", "workbench");
if (workbench == RT_NULL) return; if (workbench == RT_NULL) return;
...@@ -57,7 +70,7 @@ static void info_entry(void* parameter) ...@@ -57,7 +70,7 @@ static void info_entry(void* parameter)
rtgui_workbench_add_view(workbench, view); rtgui_workbench_add_view(workbench, view);
rtgui_view_show(view); rtgui_view_show(view, RT_FALSE);
rtgui_workbench_event_loop(workbench); rtgui_workbench_event_loop(workbench);
......
...@@ -42,6 +42,8 @@ static void key_thread_entry(void *parameter) ...@@ -42,6 +42,8 @@ static void key_thread_entry(void *parameter)
while (1) while (1)
{ {
next_delay = 20; next_delay = 20;
kbd_event.key = RTGUIK_UNKNOWN;
kbd_event.type = RTGUI_KEYDOWN; kbd_event.type = RTGUI_KEYDOWN;
if ( key_enter_GETVALUE() == 0 ) if ( key_enter_GETVALUE() == 0 )
{ {
...@@ -58,6 +60,7 @@ static void key_thread_entry(void *parameter) ...@@ -58,6 +60,7 @@ static void key_thread_entry(void *parameter)
kbd_event.key = RTGUIK_RETURN; kbd_event.key = RTGUIK_RETURN;
} }
} }
if ( key_down_GETVALUE() == 0 ) if ( key_down_GETVALUE() == 0 )
{ {
rt_kprintf("key_down\n"); rt_kprintf("key_down\n");
...@@ -81,15 +84,23 @@ static void key_thread_entry(void *parameter) ...@@ -81,15 +84,23 @@ static void key_thread_entry(void *parameter)
rt_kprintf("key_left\n"); rt_kprintf("key_left\n");
kbd_event.key = RTGUIK_LEFT; kbd_event.key = RTGUIK_LEFT;
} }
/* post down event */
rtgui_server_post_event(&(kbd_event.parent), sizeof(kbd_event)); if (kbd_event.key != RTGUIK_UNKNOWN)
{
/* post down event */
rtgui_server_post_event(&(kbd_event.parent), sizeof(kbd_event));
next_delay = 10;
/* delay to post up event */
rt_thread_delay(next_delay);
/* post up event */
kbd_event.type = RTGUI_KEYUP;
rtgui_server_post_event(&(kbd_event.parent), sizeof(kbd_event));
}
/* wait next key press */ /* wait next key press */
rt_thread_delay(next_delay); rt_thread_delay(next_delay);
/* post up event */
kbd_event.type = RTGUI_KEYUP;
rtgui_server_post_event(&(kbd_event.parent), sizeof(kbd_event));
} }
} }
......
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
#include "fmt0371/FMT0371.h" #include "fmt0371/FMT0371.h"
#include <rtgui/rtgui.h> #include <rtgui/rtgui.h>
#include <rtgui/driver.h> #include <rtgui/driver.h>
#include <rtgui/rtgui_server.h>
#include <rtgui/rtgui_system.h>
void rt_hw_lcd_update(rtgui_rect_t *rect); void rt_hw_lcd_update(rtgui_rect_t *rect);
rt_uint8_t * rt_hw_lcd_get_framebuffer(void); rt_uint8_t * rt_hw_lcd_get_framebuffer(void);
...@@ -10,6 +12,7 @@ void rt_hw_lcd_set_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y); ...@@ -10,6 +12,7 @@ void rt_hw_lcd_set_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y);
void rt_hw_lcd_get_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y); void rt_hw_lcd_get_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y);
void rt_hw_lcd_draw_hline(rtgui_color_t *c, rt_base_t x1, rt_base_t x2, rt_base_t y); void rt_hw_lcd_draw_hline(rtgui_color_t *c, rt_base_t x1, rt_base_t x2, rt_base_t y);
void rt_hw_lcd_draw_vline(rtgui_color_t *c, rt_base_t x, rt_base_t y1, rt_base_t y2); void rt_hw_lcd_draw_vline(rtgui_color_t *c, rt_base_t x, rt_base_t y1, rt_base_t y2);
void rt_hw_lcd_draw_raw_hline(rt_uint8_t *pixels, rt_base_t x1, rt_base_t x2, rt_base_t y);
struct rtgui_graphic_driver _rtgui_lcd_driver = struct rtgui_graphic_driver _rtgui_lcd_driver =
{ {
...@@ -22,7 +25,8 @@ struct rtgui_graphic_driver _rtgui_lcd_driver = ...@@ -22,7 +25,8 @@ struct rtgui_graphic_driver _rtgui_lcd_driver =
rt_hw_lcd_set_pixel, rt_hw_lcd_set_pixel,
rt_hw_lcd_get_pixel, rt_hw_lcd_get_pixel,
rt_hw_lcd_draw_hline, rt_hw_lcd_draw_hline,
rt_hw_lcd_draw_vline rt_hw_lcd_draw_vline,
rt_hw_lcd_draw_raw_hline
}; };
void rt_hw_lcd_update(rtgui_rect_t *rect) void rt_hw_lcd_update(rtgui_rect_t *rect)
...@@ -123,6 +127,30 @@ void rt_hw_lcd_draw_vline(rtgui_color_t *c, rt_base_t x, rt_base_t y1, rt_base_t ...@@ -123,6 +127,30 @@ void rt_hw_lcd_draw_vline(rtgui_color_t *c, rt_base_t x, rt_base_t y1, rt_base_t
} }
} }
void rt_hw_lcd_draw_raw_hline(rt_uint8_t *pixels, rt_base_t x1, rt_base_t x2, rt_base_t y)
{
rt_uint16_t *ptr;
/* get pixel */
ptr = (rt_uint16_t*) pixels;
/* set X point */
LCD_ADDR = 0x02;
LCD_DATA = x1;
/* set Y point */
LCD_ADDR = 0x03;
LCD_DATA16( y );
/* write pixel */
LCD_ADDR = 0x0E;
while (x1 < x2)
{
LCD_DATA16(*ptr);
x1 ++; ptr ++;
}
}
rt_err_t rt_hw_lcd_init(void) rt_err_t rt_hw_lcd_init(void)
{ {
GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitTypeDef GPIO_InitStructure;
...@@ -145,6 +173,33 @@ rt_err_t rt_hw_lcd_init(void) ...@@ -145,6 +173,33 @@ rt_err_t rt_hw_lcd_init(void)
return RT_EOK; return RT_EOK;
} }
void radio_rtgui_init()
{
rtgui_rect_t rect;
rtgui_system_server_init();
/* register dock panel */
rect.x1 = 0;
rect.y1 = 0;
rect.x2 = 240;
rect.y2 = 25;
rtgui_panel_register("info", &rect);
/* register main panel */
rect.x1 = 0;
rect.y1 = 25;
rect.x2 = 320;
rect.y2 = 320;
rtgui_panel_register("main", &rect);
rtgui_panel_set_default_focused("main");
rt_hw_lcd_init();
info_init();
player_init();
}
#include <finsh.h> #include <finsh.h>
void hline(rt_base_t x1, rt_base_t x2, rt_base_t y, rt_uint32_t pixel) void hline(rt_base_t x1, rt_base_t x2, rt_base_t y, rt_uint32_t pixel)
......
#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));
}
#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
#include <rtgui/rtgui.h>
#include <rtgui/image.h>
#include <rtgui/rtgui_system.h>
#include <rtgui/widgets/view.h>
#include <rtgui/widgets/workbench.h>
#include <string.h>
#include "listview.h"
static rtgui_image_t *background = RT_NULL;
static struct rtgui_view* function_view;
static struct rtgui_view* home_view;
static struct rtgui_workbench* workbench;
void function_filelist(void* parameter)
{
rtgui_rect_t rect;
rtgui_view_t *view;
extern rtgui_view_t* filelist_view_create(rtgui_workbench_t* workbench,
const char* directory, const char* pattern, rtgui_rect_t* rect);
rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect);
view = (rtgui_view_t*)filelist_view_create(workbench, "/", "*.*", &rect);
if (view != RT_NULL)
{
rtgui_view_show(view, RT_FALSE);
}
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;
}
void function_action(void* parameter)
{
rt_kprintf("item action!\n");
return;
}
struct list_item function_list[] =
{
{"选择电台", RT_NULL, function_action, RT_NULL},
{"更新电台", RT_NULL, function_action, RT_NULL},
{"播放文件", RT_NULL, function_filelist, RT_NULL},
{"设备信息", RT_NULL, function_device, RT_NULL},
{"返回播放器", RT_NULL, function_player, RT_NULL},
};
static rt_bool_t home_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);
/* draw background */
background = rtgui_image_create_from_file("hdc",
"/resource/bg.hdc", RT_FALSE);
if (background != RT_NULL)
{
rtgui_image_blit(background, dc, &rect);
rtgui_image_destroy(background);
background = RT_NULL;
}
else
{
rtgui_dc_fill_rect(dc, &rect);
}
rtgui_dc_end_drawing(dc);
return RT_FALSE;
}
else if (event->type == RTGUI_EVENT_KBD)
{
struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event;
if (ekbd->type == RTGUI_KEYDOWN)
{
switch (ekbd->key)
{
case RTGUIK_RIGHT:
case RTGUIK_LEFT:
break;
case RTGUIK_DOWN:
rtgui_view_show(function_view, RT_FALSE);
break;
}
}
return RT_FALSE;
}
return rtgui_view_event_handler(widget, event);
}
rt_bool_t today_workbench_event_handler(rtgui_widget_t *widget, rtgui_event_t *event)
{
if (event->type == RTGUI_EVENT_KBD)
{
struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event;
if ((ekbd->type == RTGUI_KEYUP) && ekbd->key == RTGUIK_HOME)
{
/* active home view */
if (workbench->current_view != home_view)
{
rtgui_view_show(home_view, RT_FALSE);
return RT_FALSE;
}
}
}
return rtgui_workbench_event_handler(widget, event);
}
static void player_entry(void* parameter)
{
rt_mq_t mq;
rtgui_rect_t rect;
mq = rt_mq_create("qPlayer", 256, 4, RT_IPC_FLAG_FIFO);
rtgui_thread_register(rt_thread_self(), mq);
workbench = rtgui_workbench_create("main", "workbench");
if (workbench == RT_NULL) return;
rtgui_widget_set_event_handler(RTGUI_WIDGET(workbench), today_workbench_event_handler);
/* add home view */
home_view = rtgui_view_create("Home");
rtgui_widget_set_event_handler(RTGUI_WIDGET(home_view), home_view_event_handler);
rtgui_workbench_add_view(workbench, home_view);
/* this view can be focused */
RTGUI_WIDGET(home_view)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
/* set widget focus */
rtgui_widget_focus(RTGUI_WIDGET(home_view));
rtgui_view_show(home_view, RT_FALSE);
/* add function view */
rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect);
function_view = (struct rtgui_view*)list_view_create(function_list,
sizeof(function_list)/sizeof(struct list_item),
&rect);
rtgui_workbench_add_view(workbench, function_view);
rtgui_workbench_event_loop(workbench);
rtgui_thread_deregister(rt_thread_self());
rt_mq_delete(mq);
}
void player_init()
{
rt_thread_t tid;
tid = rt_thread_create("player",
player_entry, RT_NULL,
2048, 25, 10);
if (tid != RT_NULL) rt_thread_startup(tid);
}
此差异已折叠。
...@@ -34,10 +34,12 @@ File 1,1,<.\lcd.c><lcd.c> ...@@ -34,10 +34,12 @@ File 1,1,<.\lcd.c><lcd.c>
File 1,1,<.\mp3.c><mp3.c> File 1,1,<.\mp3.c><mp3.c>
File 1,1,<.\wav.c><wav.c> File 1,1,<.\wav.c><wav.c>
File 1,1,<.\netbuffer.c><netbuffer.c> File 1,1,<.\netbuffer.c><netbuffer.c>
File 1,1,<.\gui.c><gui.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,<.\today.c><today.c> File 1,1,<E:\Projects\opensvn\rt-thread\google\bsp\stm32_radio\player.c><player.c>
File 1,1,<.\filelist.c><filelist.c>
File 1,1,<.\device_info.c><device_info.c>
File 1,1,<.\listview.c><listview.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>
...@@ -198,6 +200,9 @@ File 10,1,<..\..\rtgui\widgets\toplevel.c><toplevel.c> ...@@ -198,6 +200,9 @@ File 10,1,<..\..\rtgui\widgets\toplevel.c><toplevel.c>
File 10,1,<..\..\rtgui\server\mouse.c><mouse.c> File 10,1,<..\..\rtgui\server\mouse.c><mouse.c>
File 10,1,<..\..\rtgui\server\topwin.c><topwin.c> File 10,1,<..\..\rtgui\server\topwin.c><topwin.c>
File 10,1,<..\..\rtgui\common\caret.c><caret.c> File 10,1,<..\..\rtgui\common\caret.c><caret.c>
File 10,1,<..\..\rtgui\common\font_hz_file.c><font_hz_file.c>
File 10,1,<..\..\rtgui\common\hz16font.c><hz16font.c>
File 10,1,<..\..\rtgui\common\hz12font.c><hz12font.c>
Options 1,0,0 // Target 'RT-Thread STM32 Radio' Options 1,0,0 // Target 'RT-Thread STM32 Radio'
...@@ -312,93 +317,3 @@ Options 1,9,0 // Group 'mp3' ...@@ -312,93 +317,3 @@ Options 1,9,0 // Group 'mp3'
ADSAINCD () ADSAINCD ()
EndOpt EndOpt
Options 1,10,0 // Group 'RTGUI'
PropFld { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
IncBld=2
AlwaysBuild=2
GenAsm=2
AsmAsm=2
PublicsOnly=2
StopCode=11
CustArgs ()
LibMods ()
ADSCCFLG { 2,84,85,33,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
ADSCMISC (--gnu)
ADSCDEFN ()
ADSCUDEF ()
ADSCINCD ()
ADSASFLG { 170,42,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
ADSAMISC ()
ADSADEFN ()
ADSAUDEF ()
ADSAINCD ()
EndOpt
Options 1,1,21 // File 'gui.c'
PropFld { 2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
IncBld=2
AlwaysBuild=2
GenAsm=2
AsmAsm=2
PublicsOnly=2
StopCode=11
CustArgs ()
LibMods ()
ADSCCFLG { 2,84,85,33,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
ADSCMISC (--gnu)
ADSCDEFN ()
ADSCUDEF ()
ADSCINCD ()
EndOpt
Options 1,1,22 // File 'key.c'
PropFld { 2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
IncBld=2
AlwaysBuild=2
GenAsm=2
AsmAsm=2
PublicsOnly=2
StopCode=11
CustArgs ()
LibMods ()
ADSCCFLG { 2,84,85,33,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
ADSCMISC (--gnu)
ADSCDEFN ()
ADSCUDEF ()
ADSCINCD ()
EndOpt
Options 1,1,23 // File 'info.c'
PropFld { 2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
IncBld=2
AlwaysBuild=2
GenAsm=2
AsmAsm=2
PublicsOnly=2
StopCode=11
CustArgs ()
LibMods ()
ADSCCFLG { 2,84,85,33,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
ADSCMISC (--gnu)
ADSCDEFN ()
ADSCUDEF ()
ADSCINCD ()
EndOpt
Options 1,1,24 // File 'today.c'
PropFld { 2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
IncBld=2
AlwaysBuild=2
GenAsm=2
AsmAsm=2
PublicsOnly=2
StopCode=11
CustArgs ()
LibMods ()
ADSCCFLG { 2,84,85,33,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
ADSCMISC (--gnu)
ADSCDEFN ()
ADSCUDEF ()
ADSCINCD ()
EndOpt
...@@ -80,12 +80,13 @@ ...@@ -80,12 +80,13 @@
#define RT_USING_DFS #define RT_USING_DFS
#define RT_USING_DFS_EFSL #define RT_USING_DFS_EFSL
// #define RT_USING_DFS_ELMFAT // #define RT_USING_DFS_ELMFAT
#define DFS_EFLS_USING_STATIC_CACHE
/* SECTION: DFS options */ /* SECTION: DFS options */
/* the max number of mounted filesystem */ /* the max number of mounted filesystem */
#define DFS_FILESYSTEMS_MAX 1 #define DFS_FILESYSTEMS_MAX 1
/* the max number of opened files */ /* the max number of opened files */
#define DFS_FD_MAX 2 #define DFS_FD_MAX 8
/* the max number of cached sector */ /* the max number of cached sector */
#define DFS_CACHE_MAX_NUM 4 #define DFS_CACHE_MAX_NUM 4
...@@ -118,7 +119,7 @@ ...@@ -118,7 +119,7 @@
/* #define RT_LWIP_SNMP */ /* #define RT_LWIP_SNMP */
/* Using DHCP */ /* Using DHCP */
/* #define RT_LWIP_DHCP */ #define RT_LWIP_DHCP
/* Using DNS */ /* Using DNS */
#define RT_LWIP_DNS #define RT_LWIP_DNS
......
...@@ -3061,7 +3061,7 @@ void rt_hw_sdcard_init() ...@@ -3061,7 +3061,7 @@ void rt_hw_sdcard_init()
SD_Error status; SD_Error status;
rt_uint8_t *sector; rt_uint8_t *sector;
SD_EnableWideBusOperation(SDIO_BusWide_4b); SD_EnableWideBusOperation(SDIO_BusWide_1b);
status = SD_GetCardInfo(&SDCardInfo); status = SD_GetCardInfo(&SDCardInfo);
if (status != SD_OK) goto __return; if (status != SD_OK) goto __return;
......
...@@ -103,13 +103,6 @@ void rtthread_startup(void) ...@@ -103,13 +103,6 @@ void rtthread_startup(void)
/* init scheduler system */ /* init scheduler system */
rt_system_scheduler_init(); rt_system_scheduler_init();
#ifdef RT_USING_LWIP
eth_system_device_init();
/* register ethernetif device */
rt_hw_dm9000_init();
#endif
wm8753_hw_init(); wm8753_hw_init();
/* init hardware serial device */ /* init hardware serial device */
......
...@@ -36,6 +36,7 @@ void wav(char* filename) ...@@ -36,6 +36,7 @@ void wav(char* filename)
buf = sbuf_alloc(); buf = sbuf_alloc();
len = read(fd, (char*)buf, block_size); len = read(fd, (char*)buf, block_size);
if (len > 0) rt_device_write(device, 0, buf, len); if (len > 0) rt_device_write(device, 0, buf, len);
else sbuf_release(buf);
} while (len != 0); } while (len != 0);
/* close device and file */ /* close device and file */
......
...@@ -42,7 +42,8 @@ void lwip_sys_init() ...@@ -42,7 +42,8 @@ void lwip_sys_init()
/* use DHCP client */ /* use DHCP client */
dhcp_start(netif_default); dhcp_start(netif_default);
while (1) { while (netif_default->ip_addr.addr == 0)
{
rt_thread_delay(DHCP_FINE_TIMER_MSECS); rt_thread_delay(DHCP_FINE_TIMER_MSECS);
dhcp_fine_tmr(); dhcp_fine_tmr();
...@@ -52,7 +53,13 @@ void lwip_sys_init() ...@@ -52,7 +53,13 @@ void lwip_sys_init()
dhcp_coarse_tmr(); dhcp_coarse_tmr();
mscnt = 0; mscnt = 0;
} }
} }
rt_kprintf("Acquired IP address from DHCP server:");
rt_kprintf("%d.%d.%d.%d\n", netif_default->ip_addr.addr & 0xff,
(netif_default->ip_addr.addr>>8) & 0xff,
(netif_default->ip_addr.addr>>16) & 0xff,
(netif_default->ip_addr.addr>>24) & 0xff);
#endif #endif
#if defined(RT_USING_FINSH) && (LWIP_STATS_DISPLAY) #if defined(RT_USING_FINSH) && (LWIP_STATS_DISPLAY)
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* 2009-10-16 Bernard first version * 2009-10-16 Bernard first version
*/ */
#include <rtgui/font.h> #include <rtgui/font.h>
#ifdef RTGUI_USING_FONT16 #ifdef RTGUI_USING_FONT16
const unsigned char asc16_font[] = { const unsigned char asc16_font[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
...@@ -292,4 +292,4 @@ struct rtgui_font rtgui_font_asc16 = ...@@ -292,4 +292,4 @@ struct rtgui_font rtgui_font_asc16 =
}; };
/* size = 4096 bytes */ /* size = 4096 bytes */
#endif #endif
...@@ -12,10 +12,10 @@ ...@@ -12,10 +12,10 @@
* 2009-10-16 Bernard first version * 2009-10-16 Bernard first version
*/ */
#include <rtgui/dc.h> #include <rtgui/dc.h>
#include <rtgui/rtgui_system.h> #include <rtgui/rtgui_system.h>
#include <string.h> /* for strlen */ #include <string.h> /* for strlen */
#include <stdlib.h> /* fir qsort */ #include <stdlib.h> /* fir qsort */
/* for sin/cos etc */ /* for sin/cos etc */
#include <math.h> #include <math.h>
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include <rtgui/rtgui.h> #include <rtgui/rtgui.h>
#include <rtgui/dc.h> #include <rtgui/dc.h>
#include <rtgui/color.h> #include <rtgui/color.h>
#include <rtgui/rtgui_system.h> #include <rtgui/rtgui_system.h>
struct rtgui_dc_buffer struct rtgui_dc_buffer
{ {
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
*/ */
#include <rtgui/dc.h> #include <rtgui/dc.h>
#include <rtgui/driver.h> #include <rtgui/driver.h>
#include <rtgui/rtgui_system.h> #include <rtgui/rtgui_system.h>
#include <rtgui/widgets/view.h> #include <rtgui/widgets/view.h>
#include <rtgui/widgets/window.h> #include <rtgui/widgets/window.h>
#include <rtgui/widgets/workbench.h> #include <rtgui/widgets/workbench.h>
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#include <rtgui/filerw.h> #include <rtgui/filerw.h>
#include <rtgui/rtgui_system.h> #include <rtgui/rtgui_system.h>
#ifdef RT_USING_DFS_FILERW #ifdef RTGUI_USING_DFS_FILERW
#include <dfs_posix.h> #include <dfs_posix.h>
/* standard file read/write */ /* standard file read/write */
...@@ -95,7 +95,7 @@ static int stdio_close(struct rtgui_filerw *context) ...@@ -95,7 +95,7 @@ static int stdio_close(struct rtgui_filerw *context)
return -1; return -1;
} }
#elif RT_USING_STDIO_FILERW #elif defined(RTGUI_USING_STDIO_FILERW)
#include <stdio.h> #include <stdio.h>
/* standard file read/write */ /* standard file read/write */
...@@ -302,26 +302,26 @@ rt_uint8_t* rtgui_filerw_mem_getdata(struct rtgui_filerw* context) ...@@ -302,26 +302,26 @@ rt_uint8_t* rtgui_filerw_mem_getdata(struct rtgui_filerw* context)
} }
/* file read/write public interface */ /* file read/write public interface */
#ifdef RT_USING_DFS_FILERW #ifdef RTGUI_USING_DFS_FILERW
static int parse_mode(const char *mode) static int parse_mode(const char *mode)
{ {
int f=0; int f=0;
for (;;) for (;;)
{ {
switch (*mode) switch (*mode)
{ {
case 0: return f; case 0: return f;
case 'b': break; case 'b': break;
case 'r': f=O_RDONLY; break; case 'r': f=O_RDONLY; break;
case 'w': f=O_WRONLY|O_CREAT|O_TRUNC; break; case 'w': f=O_WRONLY|O_CREAT|O_TRUNC; break;
case 'a': f=O_WRONLY|O_CREAT|O_APPEND; break; case 'a': f=O_WRONLY|O_CREAT|O_APPEND; break;
case '+': f=(f&(~O_WRONLY))|O_RDWR; break; case '+': f=(f&(~O_WRONLY))|O_RDWR; break;
} }
++mode; ++mode;
} }
} }
struct rtgui_filerw* rtgui_filerw_create_file(const char* filename, const char* mode) struct rtgui_filerw* rtgui_filerw_create_file(const char* filename, const char* mode)
{ {
...@@ -352,7 +352,7 @@ struct rtgui_filerw* rtgui_filerw_create_file(const char* filename, const char* ...@@ -352,7 +352,7 @@ struct rtgui_filerw* rtgui_filerw_create_file(const char* filename, const char*
return &(rw->parent); return &(rw->parent);
} }
#elif RT_USING_STDIO_FILERW #elif defined(RTGUI_USING_STDIO_FILERW)
struct rtgui_filerw* rtgui_filerw_create_file(const char* filename, const char* mode) struct rtgui_filerw* rtgui_filerw_create_file(const char* filename, const char* mode)
{ {
FILE *fp; FILE *fp;
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <rtgui/font.h> #include <rtgui/font.h>
#include <rtgui/tree.h> #include <rtgui/tree.h>
#include <rtgui/rtgui_system.h> #include <rtgui/rtgui_system.h>
#ifdef RTGUI_USING_HZ_FILE
#include <dfs_posix.h> #include <dfs_posix.h>
#define HZ_CACHE_MAX 64 #define HZ_CACHE_MAX 64
...@@ -64,7 +65,7 @@ static rt_uint8_t* _font_cache_get(struct rtgui_hz_file_font* font, rt_uint16_t ...@@ -64,7 +65,7 @@ static rt_uint8_t* _font_cache_get(struct rtgui_hz_file_font* font, rt_uint16_t
} }
/* insert to cache */ /* insert to cache */
SPLAY_INSERT(cache_tree, &(font->cache_root), cache); SPLAY_INSERT(cache_tree, &(font->cache_root), cache);
font->cache_size ++; font->cache_size ++;
if (font->cache_size > HZ_CACHE_MAX) if (font->cache_size > HZ_CACHE_MAX)
...@@ -75,7 +76,7 @@ static rt_uint8_t* _font_cache_get(struct rtgui_hz_file_font* font, rt_uint16_t ...@@ -75,7 +76,7 @@ static rt_uint8_t* _font_cache_get(struct rtgui_hz_file_font* font, rt_uint16_t
while (SPLAY_LEFT(left, hz_node) != RT_NULL) left = SPLAY_LEFT(left, hz_node); while (SPLAY_LEFT(left, hz_node) != RT_NULL) left = SPLAY_LEFT(left, hz_node);
/* remove the left node */ /* remove the left node */
SPLAY_REMOVE(cache_tree, &(font->cache_root), left); SPLAY_REMOVE(cache_tree, &(font->cache_root), left);
font->cache_size --; font->cache_size --;
} }
...@@ -142,3 +143,4 @@ static void rtgui_hz_file_font_get_metrics(struct rtgui_font* font, const rt_uin ...@@ -142,3 +143,4 @@ static void rtgui_hz_file_font_get_metrics(struct rtgui_font* font, const rt_uin
rect->x2 = (rt_int16_t)(hz_file_font->font_size/2 * rt_strlen((const char*)text)); rect->x2 = (rt_int16_t)(hz_file_font->font_size/2 * rt_strlen((const char*)text));
rect->y2 = hz_file_font->font_size; rect->y2 = hz_file_font->font_size;
} }
#endif
#include <rtgui/font.h> #include <rtgui/font.h>
#ifdef RTGUI_USING_FONT12 #ifdef RTGUI_USING_FONT12
#ifndef RTGUI_USING_HZ_FILE #ifndef RTGUI_USING_HZ_FILE
const unsigned char hz12_font[] = { const unsigned char hz12_font[] = {
...@@ -12295,21 +12295,21 @@ struct rtgui_font rtgui_font_hz12 = ...@@ -12295,21 +12295,21 @@ struct rtgui_font rtgui_font_hz12 =
#else #else
const struct rtgui_hz_file_font hz12 = const struct rtgui_hz_file_font hz12 =
{ {
{RT_NULL}, /* cache root */ {RT_NULL}, /* cache root */
0, /* cache_size */ 0, /* cache size */
12, /* font_size */ 12, /* font size */
-1, /* fd */ 32, /* font data size */
"/resource/hz12" /* font_fn */ -1, /* fd */
"/resource/hzk12.fnt" /* font_fn */
}; };
extern struct rtgui_hz_file_font_engine hz_file_font_engine;
struct rtgui_font rtgui_font_hz12 = struct rtgui_font rtgui_font_hz12 =
{ {
"hz", /* family */ "hz", /* family */
12, /* height */ 12, /* height */
1, /* refer count */ 1, /* refer count */
&hz_file_font_engine,/* font engine */ &rtgui_hz_file_font_engine,/* font engine */
(void*)&hz12, /* font private data */ (void*)&hz12, /* font private data */
}; };
#endif #endif
#endif #endif
#include <rtgui/font.h> #include <rtgui/font.h>
#ifdef RTGUI_USING_FONT16 #ifdef RTGUI_USING_FONT16
#ifndef RTGUI_USING_HZ_FILE #ifndef RTGUI_USING_HZ_FILE
...@@ -16740,7 +16740,7 @@ const struct rtgui_font_bitmap hz16 = ...@@ -16740,7 +16740,7 @@ const struct rtgui_font_bitmap hz16 =
}; };
extern struct rtgui_font_engine hz_bmp_font_engine; extern struct rtgui_font_engine hz_bmp_font_engine;
const struct rtgui_font rtgui_font_hz16 = struct rtgui_font rtgui_font_hz16 =
{ {
"hz", /* family */ "hz", /* family */
16, /* height */ 16, /* height */
...@@ -16755,7 +16755,7 @@ struct rtgui_hz_file_font hz16 = ...@@ -16755,7 +16755,7 @@ struct rtgui_hz_file_font hz16 =
{ {
{RT_NULL}, /* cache root */ {RT_NULL}, /* cache root */
0, /* cache size */ 0, /* cache size */
16, /* font size */ 16, /* font size */
32, /* font data size */ 32, /* font data size */
-1, /* fd */ -1, /* fd */
"/resource/hzk16.fnt" /* font_fn */ "/resource/hzk16.fnt" /* font_fn */
...@@ -16770,4 +16770,4 @@ struct rtgui_font rtgui_font_hz16 = ...@@ -16770,4 +16770,4 @@ struct rtgui_font rtgui_font_hz16 =
(void*)&hz16, /* font private data */ (void*)&hz16, /* font private data */
}; };
#endif #endif
#endif #endif
...@@ -12,11 +12,11 @@ ...@@ -12,11 +12,11 @@
* 2009-10-16 Bernard first version * 2009-10-16 Bernard first version
*/ */
#include <rtthread.h> #include <rtthread.h>
#include <rtgui/image.h> #include <rtgui/image.h>
#include <rtgui/image_xpm.h> #include <rtgui/image_xpm.h>
#include <rtgui/image_hdc.h> #include <rtgui/image_hdc.h>
#include <rtgui/rtgui_system.h> #include <rtgui/rtgui_system.h>
#include <string.h> #include <string.h>
...@@ -37,7 +37,7 @@ void rtgui_system_image_init(void) ...@@ -37,7 +37,7 @@ void rtgui_system_image_init(void)
{ {
/* always support XPM image */ /* always support XPM image */
rtgui_image_xpm_init(); rtgui_image_xpm_init();
rtgui_image_hdc_init(); rtgui_image_hdc_init();
#ifdef RTGUI_IMAGE_BMP #ifdef RTGUI_IMAGE_BMP
rtgui_image_bmp_init(); rtgui_image_bmp_init();
......
...@@ -77,7 +77,7 @@ static rt_bool_t rtgui_image_hdc_load(struct rtgui_image* image, struct rtgui_fi ...@@ -77,7 +77,7 @@ static rt_bool_t rtgui_image_hdc_load(struct rtgui_image* image, struct rtgui_fi
rtgui_filerw_read(file, (char*)&header, 1, sizeof(header)); rtgui_filerw_read(file, (char*)&header, 1, sizeof(header));
/* set image information */ /* set image information */
image->w = header[1]; image->h = header[2]; image->w = (rt_uint16_t)header[1]; image->h = (rt_uint16_t)header[2];
image->engine = &rtgui_image_hdc_engine; image->engine = &rtgui_image_hdc_engine;
image->data = hdc; image->data = hdc;
hdc->filerw = file; hdc->filerw = file;
...@@ -104,8 +104,8 @@ static rt_bool_t rtgui_image_hdc_load(struct rtgui_image* image, struct rtgui_fi ...@@ -104,8 +104,8 @@ static rt_bool_t rtgui_image_hdc_load(struct rtgui_image* image, struct rtgui_fi
else else
{ {
hdc->pixels = RT_NULL; hdc->pixels = RT_NULL;
} }
return RT_TRUE; return RT_TRUE;
} }
...@@ -129,18 +129,60 @@ static void rtgui_image_hdc_unload(struct rtgui_image* image) ...@@ -129,18 +129,60 @@ static void rtgui_image_hdc_unload(struct rtgui_image* image)
} }
} }
static void rtgui_image_hdc_raw_hline(struct rtgui_dc_hw* dc, rt_uint8_t* raw_ptr, int x1, int x2, int y)
{
register rt_base_t index;
register rt_base_t bpp;
/* convert logic to device */
x1 = x1 + dc->owner->extent.x1;
x2 = x2 + dc->owner->extent.x1;
y = y + dc->owner->extent.y1;
bpp = dc->device->byte_per_pixel;
if (dc->owner->clip.data == RT_NULL)
{
rtgui_rect_t* prect;
prect = &(dc->owner->clip.extents);
/* calculate hline intersect */
if (prect->y1 > y || prect->y2 <= y ) return;
if (prect->x2 <= x1 || prect->x1 > x2) return;
if (prect->x1 > x1) x1 = prect->x1;
if (prect->x2 < x2) x2 = prect->x2;
/* draw raw hline */
dc->device->draw_raw_hline(raw_ptr, x1, x2, y);
}
else for (index = 0; index < rtgui_region_num_rects(&(dc->owner->clip)); index ++)
{
rtgui_rect_t* prect;
register rt_base_t draw_x1, draw_x2;
prect = ((rtgui_rect_t *)(dc->owner->clip.data + index + 1));
draw_x1 = x1;
draw_x2 = x2;
/* calculate hline clip */
if (prect->y1 > y || prect->y2 <= y ) continue;
if (prect->x2 <= x1 || prect->x1 > x2) continue;
if (prect->x1 > x1) draw_x1 = prect->x1;
if (prect->x2 < x2) draw_x2 = prect->x2;
/* draw raw hline */
dc->device->draw_raw_hline(raw_ptr + (draw_x1 - x1) * bpp, draw_x1, draw_x2, y);
}
}
static void rtgui_image_hdc_blit(struct rtgui_image* image, struct rtgui_dc* dc, struct rtgui_rect* dst_rect) static void rtgui_image_hdc_blit(struct rtgui_image* image, struct rtgui_dc* dc, struct rtgui_rect* dst_rect)
{ {
rt_uint16_t y, w, h; rt_uint16_t y, w, h;
rtgui_color_t foreground;
struct rtgui_image_hdc* hdc; struct rtgui_image_hdc* hdc;
rt_uint16_t rect_pitch, hw_pitch;
rtgui_rect_t dc_rect, _rect, *rect;
RT_ASSERT(image != RT_NULL || dc != RT_NULL || dst_rect != RT_NULL);
_rect = *dst_rect; RT_ASSERT(image != RT_NULL || dc != RT_NULL || dst_rect != RT_NULL);
rect = &_rect;
/* this dc is not visible */ /* this dc is not visible */
if (dc->get_visible(dc) != RT_TRUE) return; if (dc->get_visible(dc) != RT_TRUE) return;
...@@ -148,107 +190,47 @@ static void rtgui_image_hdc_blit(struct rtgui_image* image, struct rtgui_dc* dc, ...@@ -148,107 +190,47 @@ static void rtgui_image_hdc_blit(struct rtgui_image* image, struct rtgui_dc* dc,
hdc = (struct rtgui_image_hdc*) image->data; hdc = (struct rtgui_image_hdc*) image->data;
RT_ASSERT(hdc != RT_NULL); RT_ASSERT(hdc != RT_NULL);
/* transfer logic coordinate to physical coordinate */ if (dc->type != RTGUI_DC_HW) return;
if (dc->type == RTGUI_DC_HW)
{
dc_rect = ((struct rtgui_dc_hw*)dc)->owner->extent;
}
else rtgui_dc_get_rect(dc, &dc_rect);
rtgui_rect_moveto(rect, dc_rect.x1, dc_rect.y1);
/* the minimum rect */ /* the minimum rect */
if (image->w < rtgui_rect_width(*rect)) w = image->w; if (image->w < rtgui_rect_width(*dst_rect)) w = image->w;
else w = rtgui_rect_width(*rect); else w = rtgui_rect_width(*dst_rect);
if (image->h < rtgui_rect_height(*rect)) h = image->h; if (image->h < rtgui_rect_height(*dst_rect)) h = image->h;
else h = rtgui_rect_height(*rect); else h = rtgui_rect_height(*dst_rect);
/* get rect pitch */
rect_pitch = w * hdc->byte_per_pixel;
hw_pitch = hdc->hw_driver->width * hdc->hw_driver->byte_per_pixel;
/* save foreground color */
foreground = rtgui_dc_get_color(dc);
if (hdc->pixels != RT_NULL) if (hdc->pixels != RT_NULL)
{ {
if (hdc->hw_driver->get_framebuffer() != RT_NULL) rt_uint8_t* ptr;
{
rt_uint8_t* rect_ptr;
rt_uint8_t* hw_ptr;
/* get pixel pointer */
hw_ptr = hdc->hw_driver->get_framebuffer();
rect_ptr = hdc->pixels;
/* move hardware pixel pointer */
hw_ptr += rect->y1 * hdc->pitch + rect->x1 * hdc->byte_per_pixel;
for (y = 0; y < h; y ++)
{
rt_memcpy(hw_ptr, rect_ptr, rect_pitch);
hw_ptr += hw_pitch;
rect_ptr += rect_pitch;
}
}
else
{
rt_uint8_t* rect_ptr;
/* get pixel pointer */ /* get pixel pointer */
rect_ptr = hdc->pixels; ptr = hdc->pixels;
for (y = 0; y < h; y ++) for (y = 0; y < h; y ++)
{ {
hdc->hw_driver->draw_raw_hline(rect_ptr, rect->x1, rect->x1 + w, rect->y1 + y); rtgui_image_hdc_raw_hline((struct rtgui_dc_hw*)dc, ptr, dst_rect->x1, dst_rect->x2, dst_rect->y1 + y);
rect_ptr += hdc->pitch; ptr += hdc->pitch;
}
} }
} }
else else
{ {
rt_uint8_t* rect_ptr; rt_uint8_t* ptr;
rect_ptr = rtgui_malloc(hdc->pitch); ptr = rtgui_malloc(hdc->pitch);
if (rect_ptr == RT_NULL) return; /* no memory */ if (ptr == RT_NULL) return; /* no memory */
/* seek to the begin of pixel data */ /* seek to the begin of pixel data */
rtgui_filerw_seek(hdc->filerw, hdc->pixel_offset, RTGUI_FILE_SEEK_SET); rtgui_filerw_seek(hdc->filerw, hdc->pixel_offset, RTGUI_FILE_SEEK_SET);
if (hdc->hw_driver->get_framebuffer() != RT_NULL) for (y = 0; y < h; y ++)
{ {
rt_uint8_t* hw_ptr; /* read pixel data */
if (rtgui_filerw_read(hdc->filerw, ptr, 1, hdc->pitch) != hdc->pitch)
/* get pixel pointer */ break; /* read data failed */
hw_ptr = hdc->hw_driver->get_framebuffer();
/* move hardware pixel pointer */ rtgui_image_hdc_raw_hline((struct rtgui_dc_hw*)dc, ptr, dst_rect->x1, dst_rect->x1 + w, dst_rect->y1 + y);
hw_ptr += rect->y1 * hdc->pitch + rect->x1 * hdc->byte_per_pixel;
for (y = 0; y < h; y ++)
{
/* read pixel data */
if (rtgui_filerw_read(hdc->filerw, rect_ptr, 1, hdc->pitch) != hdc->pitch)
break; /* read data failed */
rt_memcpy(hw_ptr, rect_ptr, rect_pitch);
hw_ptr += hw_pitch;
}
}
else
{
for (y = 0; y < h; y ++)
{
/* read pixel data */
if (rtgui_filerw_read(hdc->filerw, rect_ptr, 1, hdc->pitch) != hdc->pitch)
break; /* read data failed */
hdc->hw_driver->draw_raw_hline(rect_ptr, rect->x1, rect->x1 + w, rect->y1 + y);
}
} }
rtgui_free(rect_ptr); rtgui_free(ptr);
} }
/* restore foreground */
rtgui_dc_set_color(dc, foreground);
} }
void rtgui_image_hdc_init() void rtgui_image_hdc_init()
......
...@@ -199,8 +199,8 @@ static rt_bool_t rtgui_image_png_load(struct rtgui_image* image, struct rtgui_fi ...@@ -199,8 +199,8 @@ static rt_bool_t rtgui_image_png_load(struct rtgui_image* image, struct rtgui_fi
else else
{ {
png->pixels = RT_NULL; png->pixels = RT_NULL;
} }
return RT_TRUE; return RT_TRUE;
} }
......
...@@ -565,7 +565,7 @@ color_none: ...@@ -565,7 +565,7 @@ color_none:
} }
} }
free_colorhash(colors_table); free_colorhash(colors_table);
rtgui_filerw_close(file); rtgui_filerw_close(file);
return RT_TRUE; return RT_TRUE;
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
*/ */
#include <rtgui/rtgui_object.h> #include <rtgui/rtgui_object.h>
#include <rtgui/rtgui_system.h> #include <rtgui/rtgui_system.h>
static void _rtgui_object_constructor(rtgui_object_t *object) static void _rtgui_object_constructor(rtgui_object_t *object)
{ {
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <rtgui/rtgui.h> #include <rtgui/rtgui.h>
#include <rtgui/driver.h> #include <rtgui/driver.h>
#include <rtgui/image.h> #include <rtgui/image.h>
#include <rtgui/rtgui_theme.h>
#include <rtgui/rtgui_system.h> #include <rtgui/rtgui_system.h>
#include <rtgui/rtgui_server.h> #include <rtgui/rtgui_server.h>
#include <rtgui/widgets/window.h> #include <rtgui/widgets/window.h>
...@@ -31,6 +32,9 @@ void rtgui_system_server_init() ...@@ -31,6 +32,9 @@ void rtgui_system_server_init()
/* init rtgui_thread */ /* init rtgui_thread */
rtgui_thread_system_init(); rtgui_thread_system_init();
/* init theme */
rtgui_system_theme_init();
/* init image */ /* init image */
rtgui_system_image_init(); rtgui_system_image_init();
/* init font */ /* init font */
...@@ -257,7 +261,6 @@ rtgui_thread_t* rtgui_thread_register(rt_thread_t tid, rt_mq_t mq) ...@@ -257,7 +261,6 @@ rtgui_thread_t* rtgui_thread_register(rt_thread_t tid, rt_mq_t mq)
thread->tid = tid; thread->tid = tid;
thread->mq = mq; thread->mq = mq;
thread->widget = RT_NULL; thread->widget = RT_NULL;
thread->is_quit = RT_FALSE;
/* take semaphore */ /* take semaphore */
rt_sem_take(&_rtgui_thread_hash_semaphore, RT_WAITING_FOREVER); rt_sem_take(&_rtgui_thread_hash_semaphore, RT_WAITING_FOREVER);
......
此差异已折叠。
...@@ -18,9 +18,9 @@ ...@@ -18,9 +18,9 @@
typedef unsigned long rtgui_color_t; typedef unsigned long rtgui_color_t;
#define RTGUI_ARGB(a, r, g, b) \ #define RTGUI_ARGB(a, r, g, b) \
((rtgui_color_t)(((rt_uint8_t)(r)|\ ((rtgui_color_t)(((rt_uint8_t)(r)|\
(((unsigned)(rt_uint8_t)(g))<<8))|\ (((unsigned)(rt_uint8_t)(g))<<8))|\
(((unsigned long)(rt_uint8_t)(b))<<16)|\ (((unsigned long)(rt_uint8_t)(b))<<16)|\
(((unsigned long)(rt_uint8_t)(a))<<24))) (((unsigned long)(rt_uint8_t)(a))<<24)))
#define RTGUI_RGB(r, g, b) RTGUI_ARGB(255, (r), (g), (b)) #define RTGUI_RGB(r, g, b) RTGUI_ARGB(255, (r), (g), (b))
...@@ -51,7 +51,7 @@ rt_inline rt_uint16_t rtgui_color_to_565(rtgui_color_t c) ...@@ -51,7 +51,7 @@ rt_inline rt_uint16_t rtgui_color_to_565(rtgui_color_t c)
{ {
rt_uint16_t pixel; rt_uint16_t pixel;
pixel = ((RTGUI_RGB_B(c)>> 3) << 11) | ((RTGUI_RGB_G(c) >> 2) << 5) | (RTGUI_RGB_R(c) >> 3); pixel = (rt_uint16_t)(((RTGUI_RGB_B(c)>> 3) << 11) | ((RTGUI_RGB_G(c) >> 2) << 5) | (RTGUI_RGB_R(c) >> 3));
return pixel; return pixel;
} }
...@@ -75,7 +75,7 @@ rt_inline rt_uint16_t rtgui_color_to_565p(rtgui_color_t c) ...@@ -75,7 +75,7 @@ rt_inline rt_uint16_t rtgui_color_to_565p(rtgui_color_t c)
{ {
rt_uint16_t pixel; rt_uint16_t pixel;
pixel = ((RTGUI_RGB_R(c) >> 3) << 11) | ((RTGUI_RGB_G(c) >> 2) << 5) | (RTGUI_RGB_B(c)>> 3); pixel = (rt_uint16_t)(((RTGUI_RGB_R(c) >> 3) << 11) | ((RTGUI_RGB_G(c) >> 2) << 5) | (RTGUI_RGB_B(c)>> 3));
return pixel; return pixel;
} }
......
...@@ -213,7 +213,7 @@ struct rtgui_event_win_resize ...@@ -213,7 +213,7 @@ struct rtgui_event_win_resize
#define rtgui_event_win_activate rtgui_event_win #define rtgui_event_win_activate rtgui_event_win
#define rtgui_event_win_deactivate rtgui_event_win #define rtgui_event_win_deactivate rtgui_event_win
#define rtgui_event_win_close rtgui_event_win #define rtgui_event_win_close rtgui_event_win
/* window event init */ /* window event init */
#define RTGUI_EVENT_WIN_CREATE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_CREATE) #define RTGUI_EVENT_WIN_CREATE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_CREATE)
#define RTGUI_EVENT_WIN_DESTROY_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_DESTROY) #define RTGUI_EVENT_WIN_DESTROY_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_DESTROY)
...@@ -296,9 +296,9 @@ struct rtgui_event_clip_info ...@@ -296,9 +296,9 @@ struct rtgui_event_clip_info
/* the number of rects */ /* the number of rects */
rt_uint32_t num_rect; rt_uint32_t num_rect;
struct rtgui_rect rects[0]; /* rtgui_rect_t *rects */
}; };
#define RTGUI_EVENT_GET_RECT(e, i) (&(e->rects[0]) + i) #define RTGUI_EVENT_GET_RECT(e, i) &(((rtgui_rect_t*)(e + 1))[i])
#define RTGUI_EVENT_UPDATE_BEGIN_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_UPDATE_BEGIN) #define RTGUI_EVENT_UPDATE_BEGIN_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_UPDATE_BEGIN)
#define RTGUI_EVENT_UPDATE_END_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_UPDATE_END) #define RTGUI_EVENT_UPDATE_END_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_UPDATE_END)
...@@ -420,5 +420,5 @@ struct rtgui_event_resize ...@@ -420,5 +420,5 @@ struct rtgui_event_resize
rt_int16_t w, h; rt_int16_t w, h;
}; };
#define RTGUI_EVENT_RESIZE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_RESIZE) #define RTGUI_EVENT_RESIZE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_RESIZE)
#endif #endif
...@@ -16,4 +16,6 @@ ...@@ -16,4 +16,6 @@
#include <rtgui/image.h> #include <rtgui/image.h>
void rtgui_image_png_init(void);
#endif #endif
...@@ -28,7 +28,7 @@ struct rtgui_widget; ...@@ -28,7 +28,7 @@ struct rtgui_widget;
struct rtgui_win; struct rtgui_win;
typedef struct rtgui_panel rtgui_panel_t; typedef struct rtgui_panel rtgui_panel_t;
typedef struct rtgui_win rtgui_win_t; typedef struct rtgui_win rtgui_win_t;
typedef struct rtgui_workbench rtgui_workbench_t; typedef struct rtgui_workbench rtgui_workbench_t;
typedef rt_bool_t (*rtgui_event_handler_ptr)(struct rtgui_widget* widget, struct rtgui_event* event); typedef rt_bool_t (*rtgui_event_handler_ptr)(struct rtgui_widget* widget, struct rtgui_event* event);
...@@ -95,6 +95,13 @@ enum RTGUI_ARRAW ...@@ -95,6 +95,13 @@ enum RTGUI_ARRAW
RTGUI_ARRAW_RIGHT RTGUI_ARRAW_RIGHT
}; };
enum RTGUI_MODAL_CODE
{
RTGUI_MODAL_OK,
RTGUI_MODAL_CANCEL
};
typedef enum RTGUI_MODAL_CODE rtgui_modal_code_t;
#include <rtgui/rtgui_object.h> #include <rtgui/rtgui_object.h>
#endif #endif
...@@ -22,18 +22,23 @@ ...@@ -22,18 +22,23 @@
/* #define RTGUI_USING_MOUSE_CURSOR */ /* #define RTGUI_USING_MOUSE_CURSOR */
/* #define RTGUI_USING_FONT12 */
#define RTGUI_USING_FONT16 #define RTGUI_USING_FONT16
#define RTGUI_USING_FONTHZ #define RTGUI_USING_FONTHZ
#ifdef _WIN32
#define RTGUI_USING_STDIO_FILERW
#define RTGUI_IMAGE_PNG
#define RTGUI_IMAGE_JPG
#else
#define RTGUI_USING_DFS_FILERW
#define RTGUI_USING_HZ_FILE #define RTGUI_USING_HZ_FILE
#endif
// #define RT_USING_STDIO_FILERW
#define RT_USING_DFS_FILERW
// #define RTGUI_IMAGE_PNG
// #define RTGUI_IMAGE_JPG
#define RTGUI_SVR_THREAD_PRIORITY 15 #define RTGUI_SVR_THREAD_PRIORITY 15
#define RTGUI_SVR_THREAD_TIMESLICE 5 #define RTGUI_SVR_THREAD_TIMESLICE 5
#define RTGUI_SVR_THREAD_STACK_SIZE 2048
#define RTGUI_APP_THREAD_PRIORITY 25 #define RTGUI_APP_THREAD_PRIORITY 25
#define RTGUI_APP_THREAD_TIMESLICE 8 #define RTGUI_APP_THREAD_TIMESLICE 8
......
...@@ -88,7 +88,6 @@ struct rtgui_object ...@@ -88,7 +88,6 @@ struct rtgui_object
/* object type */ /* object type */
rtgui_type_t* type; rtgui_type_t* type;
char *name;
rt_bool_t is_static; rt_bool_t is_static;
}; };
rtgui_type_t *rtgui_object_type_get(void); rtgui_type_t *rtgui_object_type_get(void);
......
...@@ -31,9 +31,6 @@ struct rtgui_thread ...@@ -31,9 +31,6 @@ struct rtgui_thread
/* the owner of thread */ /* the owner of thread */
struct rtgui_widget* widget; struct rtgui_widget* widget;
/* quit of thread */
rt_bool_t is_quit;
}; };
typedef struct rtgui_thread rtgui_thread_t; typedef struct rtgui_thread rtgui_thread_t;
struct rtgui_timer; struct rtgui_timer;
......
...@@ -26,12 +26,17 @@ ...@@ -26,12 +26,17 @@
extern "C" { extern "C" {
#endif #endif
void rtgui_system_theme_init(void);
void rtgui_theme_draw_win(struct rtgui_topwin* win); void rtgui_theme_draw_win(struct rtgui_topwin* win);
void rtgui_theme_draw_button(rtgui_button_t* btn); void rtgui_theme_draw_button(rtgui_button_t* btn);
void rtgui_theme_draw_label(rtgui_label_t* label); void rtgui_theme_draw_label(rtgui_label_t* label);
void rtgui_theme_draw_textbox(rtgui_textbox_t* box); void rtgui_theme_draw_textbox(rtgui_textbox_t* box);
void rtgui_theme_draw_iconbox(rtgui_iconbox_t* iconbox); void rtgui_theme_draw_iconbox(rtgui_iconbox_t* iconbox);
rt_uint16_t rtgui_theme_get_selected_height(void);
void rtgui_theme_draw_selected(struct rtgui_dc* dc, rtgui_rect_t *rect);
rtgui_color_t rtgui_theme_default_bc(void); rtgui_color_t rtgui_theme_default_bc(void);
rtgui_color_t rtgui_theme_default_fc(void); rtgui_color_t rtgui_theme_default_fc(void);
......
...@@ -28,6 +28,7 @@ struct rtgui_container ...@@ -28,6 +28,7 @@ struct rtgui_container
/* inherit from widget */ /* inherit from widget */
struct rtgui_widget parent; struct rtgui_widget parent;
struct rtgui_widget* focused;
rtgui_list_t children; rtgui_list_t children;
}; };
typedef struct rtgui_container rtgui_container_t; typedef struct rtgui_container rtgui_container_t;
......
...@@ -37,9 +37,6 @@ struct rtgui_toplevel ...@@ -37,9 +37,6 @@ struct rtgui_toplevel
/* server thread id */ /* server thread id */
rt_thread_t server; rt_thread_t server;
/* current focus widget */
rtgui_widget_t* focus;
}; };
typedef struct rtgui_toplevel rtgui_toplevel_t; typedef struct rtgui_toplevel rtgui_toplevel_t;
...@@ -51,7 +48,4 @@ void rtgui_toplevel_handle_clip(struct rtgui_toplevel* top, ...@@ -51,7 +48,4 @@ void rtgui_toplevel_handle_clip(struct rtgui_toplevel* top,
struct rtgui_event_clip_info* info); struct rtgui_event_clip_info* info);
void rtgui_toplevel_update_clip(rtgui_toplevel_t* top); void rtgui_toplevel_update_clip(rtgui_toplevel_t* top);
void rtgui_toplevel_set_focus(struct rtgui_toplevel* top, rtgui_widget_t* focus);
rtgui_widget_t* rtgui_toplevel_get_focus(struct rtgui_toplevel* top);
#endif #endif
...@@ -50,8 +50,9 @@ rt_bool_t rtgui_view_event_handler(struct rtgui_widget* widget, struct rtgui_eve ...@@ -50,8 +50,9 @@ rt_bool_t rtgui_view_event_handler(struct rtgui_widget* widget, struct rtgui_eve
void rtgui_view_set_box(rtgui_view_t* view, rtgui_box_t* box); void rtgui_view_set_box(rtgui_view_t* view, rtgui_box_t* box);
void rtgui_view_show(rtgui_view_t* view); rtgui_modal_code_t rtgui_view_show(rtgui_view_t* view, rt_bool_t is_modal);
void rtgui_view_hide(rtgui_view_t* view); void rtgui_view_hide(rtgui_view_t* view);
void rtgui_view_end_modal(rtgui_view_t* view, rtgui_modal_code_t modal_code);
char* rtgui_view_get_title(rtgui_view_t* view); char* rtgui_view_get_title(rtgui_view_t* view);
void rtgui_view_set_title(rtgui_view_t* view, const char* title); void rtgui_view_set_title(rtgui_view_t* view, const char* title);
......
...@@ -27,18 +27,18 @@ ...@@ -27,18 +27,18 @@
/** Checks if the object is an rtgui_win */ /** Checks if the object is an rtgui_win */
#define RTGUI_IS_WIN(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_WIN_TYPE)) #define RTGUI_IS_WIN(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_WIN_TYPE))
#define RTGUI_WIN_STYLE_MODAL 0x00 #define RTGUI_WIN_STYLE_MODAL 0x01 /* modal mode window */
#define RTGUI_WIN_STYLE_MODAL_LESS 0x01 #define RTGUI_WIN_STYLE_CLOSED 0x02 /* window is closed */
#define RTGUI_WIN_STYLE_NO_TITLE 0x02 #define RTGUI_WIN_STYLE_ACTIVATE 0x04 /* window is activated */
#define RTGUI_WIN_STYLE_NO_BORDER 0x04 #define RTGUI_WIN_STYLE_NO_FOCUS 0x08 /* non-focused window */
#define RTGUI_WIN_STYLE_SHOW 0x08
#define RTGUI_WIN_STYLE_CLOSEBOX 0x10 #define RTGUI_WIN_STYLE_NO_TITLE 0x10 /* no title window */
#define RTGUI_WIN_STYLE_MINIBOX 0x20 #define RTGUI_WIN_STYLE_NO_BORDER 0x20 /* no border window */
#define RTGUI_WIN_STYLE_ACTIVATE 0x40 #define RTGUI_WIN_STYLE_CLOSEBOX 0x40 /* window has the close button */
#define RTGUI_WIN_STYLE_NO_FOCUS 0x80 #define RTGUI_WIN_STYLE_MINIBOX 0x80 /* window has the mini button */
#define RTGUI_WIN_STYLE_DEFAULT (RTGUI_WIN_STYLE_CLOSEBOX | RTGUI_WIN_STYLE_MINIBOX) #define RTGUI_WIN_STYLE_DEFAULT (RTGUI_WIN_STYLE_CLOSEBOX | RTGUI_WIN_STYLE_MINIBOX)
struct rtgui_win_title; struct rtgui_win_title;
struct rtgui_win_area; struct rtgui_win_area;
...@@ -51,18 +51,19 @@ struct rtgui_win ...@@ -51,18 +51,19 @@ struct rtgui_win
rtgui_toplevel_t* parent_toplevel; rtgui_toplevel_t* parent_toplevel;
/* top window style */ /* top window style */
rt_uint32_t style; rt_uint8_t style;
rtgui_modal_code_t modal_code;
/* window title */ /* window title */
char* title; char* title;
/* call back */ /* call back */
rt_bool_t (*on_activate) (struct rtgui_widget* widget, struct rtgui_event* event); rt_bool_t (*on_activate) (struct rtgui_widget* widget, struct rtgui_event* event);
rt_bool_t (*on_deactivate) (struct rtgui_widget* widget, struct rtgui_event* event); rt_bool_t (*on_deactivate) (struct rtgui_widget* widget, struct rtgui_event* event);
rt_bool_t (*on_close) (struct rtgui_widget* widget, struct rtgui_event* event); rt_bool_t (*on_close) (struct rtgui_widget* widget, struct rtgui_event* event);
/* reserved user data */ /* reserved user data */
rt_uint32_t user_data; rt_uint32_t user_data;
}; };
rtgui_type_t *rtgui_win_type_get(void); rtgui_type_t *rtgui_win_type_get(void);
...@@ -71,8 +72,10 @@ rtgui_win_t* rtgui_win_create(rtgui_toplevel_t* parent_toplevel, const char* tit ...@@ -71,8 +72,10 @@ rtgui_win_t* rtgui_win_create(rtgui_toplevel_t* parent_toplevel, const char* tit
rtgui_rect_t *rect, rt_uint32_t flag); rtgui_rect_t *rect, rt_uint32_t flag);
void rtgui_win_destroy(rtgui_win_t* win); void rtgui_win_destroy(rtgui_win_t* win);
void rtgui_win_show(rtgui_win_t* win); rtgui_modal_code_t rtgui_win_show(rtgui_win_t* win, rt_bool_t is_modal);
void rtgui_win_hiden(rtgui_win_t* win); void rtgui_win_hiden(rtgui_win_t* win);
void rtgui_win_end_modal(rtgui_win_t* win, rtgui_modal_code_t modal_code);
rt_bool_t rtgui_win_is_activated(struct rtgui_win* win); rt_bool_t rtgui_win_is_activated(struct rtgui_win* win);
void rtgui_win_move(struct rtgui_win* win, int x, int y); void rtgui_win_move(struct rtgui_win* win, int x, int y);
......
...@@ -22,12 +22,14 @@ ...@@ -22,12 +22,14 @@
#include <rtgui/widgets/view.h> #include <rtgui/widgets/view.h>
#include <rtgui/widgets/toplevel.h> #include <rtgui/widgets/toplevel.h>
#define RTGUI_WORKBENCH_FLAG_VISIBLE 0x00 #define RTGUI_WORKBENCH_FLAG_VISIBLE 0x00 /* workbench is visible */
#define RTGUI_WORKBENCH_FLAG_INVISIBLE 0x01 #define RTGUI_WORKBENCH_FLAG_INVISIBLE 0x01 /* workbench is invisible */
#define RTGUI_WORKBENCH_FLAG_FULLSCREEN 0x02 #define RTGUI_WORKBENCH_FLAG_FULLSCREEN 0x02 /* workbench is full screen */
#define RTGUI_WORKBENCH_FLAG_MODAL_MODE 0x04 /* workbench is modal mode showing */
#define RTGUI_WORKBENCH_FLAG_CLOSEBLE 0x00 #define RTGUI_WORKBENCH_FLAG_CLOSEBLE 0x00
#define RTGUI_WORKBENCH_FLAG_UNCLOSEBLE 0x10 #define RTGUI_WORKBENCH_FLAG_UNCLOSEBLE 0x10
#define RTGUI_WORKBENCH_FLAG_CLOSED 0x20
#define RTGUI_WORKBENCH_FLAG_DEFAULT RTGUI_WORKBENCH_FLAG_VISIBLE | RTGUI_WORKBENCH_FLAG_CLOSEBLE #define RTGUI_WORKBENCH_FLAG_DEFAULT RTGUI_WORKBENCH_FLAG_VISIBLE | RTGUI_WORKBENCH_FLAG_CLOSEBLE
...@@ -48,6 +50,7 @@ struct rtgui_workbench ...@@ -48,6 +50,7 @@ struct rtgui_workbench
/* workbench flag */ /* workbench flag */
rt_uint8_t flag; rt_uint8_t flag;
rtgui_modal_code_t modal_code;
/* workbench title */ /* workbench title */
unsigned char* title; unsigned char* title;
...@@ -63,7 +66,7 @@ rt_bool_t rtgui_workbench_event_handler(rtgui_widget_t* widget, rtgui_event_t* e ...@@ -63,7 +66,7 @@ rt_bool_t rtgui_workbench_event_handler(rtgui_widget_t* widget, rtgui_event_t* e
void rtgui_workbench_set_flag(rtgui_workbench_t* workbench, rt_uint8_t flag); void rtgui_workbench_set_flag(rtgui_workbench_t* workbench, rt_uint8_t flag);
void rtgui_workbench_event_loop(rtgui_workbench_t* workbench); rt_bool_t rtgui_workbench_event_loop(rtgui_workbench_t* workbench);
rt_err_t rtgui_workbench_show (rtgui_workbench_t* workbench); rt_err_t rtgui_workbench_show (rtgui_workbench_t* workbench);
rt_err_t rtgui_workbench_hide (rtgui_workbench_t* workbench); rt_err_t rtgui_workbench_hide (rtgui_workbench_t* workbench);
......
/* /*
* File : driver.c * File : driver.c
* This file is part of RTGUI in RT-Thread RTOS * This file is part of RTGUI in RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* *
* The license and distribution terms for this file may be * The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at * found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE * http://www.rt-thread.org/license/LICENSE
* *
* Change Logs: * Change Logs:
* Date Author Notes * Date Author Notes
* 2009-10-04 Bernard first version * 2009-10-04 Bernard first version
*/ */
#include <rtgui/driver.h> #include <rtgui/driver.h>
struct rtgui_list_node _rtgui_graphic_driver_list = {RT_NULL}; struct rtgui_list_node _rtgui_graphic_driver_list = {RT_NULL};
void rtgui_graphic_driver_add(struct rtgui_graphic_driver* driver) void rtgui_graphic_driver_add(struct rtgui_graphic_driver* driver)
{ {
rtgui_list_insert(&_rtgui_graphic_driver_list, &(driver->list)); rtgui_list_insert(&_rtgui_graphic_driver_list, &(driver->list));
} }
void rtgui_graphic_driver_remove(struct rtgui_graphic_driver* driver) void rtgui_graphic_driver_remove(struct rtgui_graphic_driver* driver)
{ {
rtgui_list_remove(&_rtgui_graphic_driver_list, &(driver->list)); rtgui_list_remove(&_rtgui_graphic_driver_list, &(driver->list));
} }
struct rtgui_graphic_driver* rtgui_graphic_driver_find(char* name) struct rtgui_graphic_driver* rtgui_graphic_driver_find(char* name)
{ {
struct rtgui_list_node* node; struct rtgui_list_node* node;
struct rtgui_graphic_driver* driver; struct rtgui_graphic_driver* driver;
/* search in list */ /* search in list */
rtgui_list_foreach(node, &(_rtgui_graphic_driver_list)) rtgui_list_foreach(node, &(_rtgui_graphic_driver_list))
{ {
driver = rtgui_list_entry(node, struct rtgui_graphic_driver, list); driver = rtgui_list_entry(node, struct rtgui_graphic_driver, list);
/* find it */ /* find it */
if (rt_strncmp(driver->name, name, RTGUI_NAME_MAX) == 0) if (rt_strncmp(driver->name, name, RTGUI_NAME_MAX) == 0)
{ {
return driver; return driver;
} }
} }
return RT_NULL; return RT_NULL;
} }
struct rtgui_graphic_driver* rtgui_graphic_driver_get_default() struct rtgui_graphic_driver* rtgui_graphic_driver_get_default()
{ {
return rtgui_list_entry(_rtgui_graphic_driver_list.next, return rtgui_list_entry(_rtgui_graphic_driver_list.next,
struct rtgui_graphic_driver, list); struct rtgui_graphic_driver, list);
} }
void rtgui_graphic_driver_get_rect(struct rtgui_graphic_driver *driver, rtgui_rect_t *rect) void rtgui_graphic_driver_get_rect(struct rtgui_graphic_driver *driver, rtgui_rect_t *rect)
{ {
if (rect == RT_NULL || driver == RT_NULL) return; if (rect == RT_NULL || driver == RT_NULL) return;
rect->x1 = rect->y1 = 0; rect->x1 = rect->y1 = 0;
rect->x2 = driver->width; rect->x2 = driver->width;
rect->y2 = driver->height; rect->y2 = driver->height;
} }
void rtgui_graphic_driver_get_default_rect(rtgui_rect_t *rect) void rtgui_graphic_driver_get_default_rect(rtgui_rect_t *rect)
{ {
/* return default the extent of default driver */ /* return default the extent of default driver */
rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(), rect); rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(), rect);
} }
/* /*
* File : panel.c * File : panel.c
* This file is part of RTGUI in RT-Thread RTOS * This file is part of RTGUI in RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* *
* The license and distribution terms for this file may be * The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at * found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE * http://www.rt-thread.org/license/LICENSE
* *
* Change Logs: * Change Logs:
* Date Author Notes * Date Author Notes
* 2009-10-04 Bernard first version * 2009-10-04 Bernard first version
*/ */
#include "panel.h" #include "panel.h"
#include "mouse.h" #include "mouse.h"
#include <rtgui/rtgui_system.h> #include <rtgui/rtgui_system.h>
/* the global parameter */ /* the global parameter */
struct rtgui_list_node _rtgui_panel_list; struct rtgui_list_node _rtgui_panel_list;
void rtgui_panel_init() void rtgui_panel_init()
{ {
rtgui_list_init(&_rtgui_panel_list); rtgui_list_init(&_rtgui_panel_list);
} }
void rtgui_panel_register(char* name, rtgui_rect_t* extent) void rtgui_panel_register(char* name, rtgui_rect_t* extent)
{ {
register rt_base_t temp; register rt_base_t temp;
struct rtgui_panel* panel; struct rtgui_panel* panel;
panel = rtgui_panel_find(name); panel = rtgui_panel_find(name);
if (panel != RT_NULL ) if (panel != RT_NULL )
{ {
/* there are already a same named panel exist. */ /* there are already a same named panel exist. */
return; return;
} }
panel = rtgui_malloc(sizeof(struct rtgui_panel)); panel = rtgui_malloc(sizeof(struct rtgui_panel));
if (panel == RT_NULL) if (panel == RT_NULL)
{ {
/* can't alloc memory */ /* can't alloc memory */
return; return;
} }
/* copy name */ /* copy name */
for (temp = 0; temp < RTGUI_NAME_MAX; temp ++) for (temp = 0; temp < RTGUI_NAME_MAX; temp ++)
{ {
panel->name[temp] = name[temp]; panel->name[temp] = name[temp];
} }
/* copy extent */ /* copy extent */
panel->extent = *extent; panel->extent = *extent;
panel->wm_thread = RT_NULL; panel->wm_thread = RT_NULL;
/* init list */ /* init list */
rtgui_list_init(&(panel->sibling)); rtgui_list_init(&(panel->sibling));
rtgui_list_init(&(panel->thread_list)); rtgui_list_init(&(panel->thread_list));
/* add panel to panel list */ /* add panel to panel list */
rtgui_list_insert(&_rtgui_panel_list, &(panel->sibling)); rtgui_list_insert(&_rtgui_panel_list, &(panel->sibling));
} }
void rtgui_panel_deregister(char* name) void rtgui_panel_deregister(char* name)
{ {
struct rtgui_panel* panel; struct rtgui_panel* panel;
panel = rtgui_panel_find(name); panel = rtgui_panel_find(name);
if (panel != RT_NULL) if (panel != RT_NULL)
{ {
rtgui_list_remove(&_rtgui_panel_list, &(panel->sibling)); rtgui_list_remove(&_rtgui_panel_list, &(panel->sibling));
/* free pane node */ /* free pane node */
rtgui_free(panel); rtgui_free(panel);
} }
} }
/* set default focused panel, please use it after registered panel */ /* set default focused panel, please use it after registered panel */
void rtgui_panel_set_default_focused(char* name) void rtgui_panel_set_default_focused(char* name)
{ {
extern struct rtgui_panel* rtgui_server_focus_panel; extern struct rtgui_panel* rtgui_server_focus_panel;
struct rtgui_panel* panel; struct rtgui_panel* panel;
panel = rtgui_panel_find(name); panel = rtgui_panel_find(name);
if (panel != RT_NULL) if (panel != RT_NULL)
{ {
rtgui_server_focus_panel = panel; rtgui_server_focus_panel = panel;
} }
} }
struct rtgui_panel* rtgui_panel_find(char* name) struct rtgui_panel* rtgui_panel_find(char* name)
{ {
struct rtgui_list_node* node; struct rtgui_list_node* node;
struct rtgui_panel* panel; struct rtgui_panel* panel;
rtgui_list_foreach(node, &_rtgui_panel_list) rtgui_list_foreach(node, &_rtgui_panel_list)
{ {
panel = rtgui_list_entry(node, struct rtgui_panel, sibling); panel = rtgui_list_entry(node, struct rtgui_panel, sibling);
if (rt_strncmp(panel->name, name, RTGUI_NAME_MAX) == 0) if (rt_strncmp(panel->name, name, RTGUI_NAME_MAX) == 0)
{ {
return panel; return panel;
} }
} }
return RT_NULL; return RT_NULL;
} }
struct rtgui_panel* rtgui_panel_thread_add(char* name, rt_thread_t tid) struct rtgui_panel* rtgui_panel_thread_add(char* name, rt_thread_t tid)
{ {
struct rtgui_panel* panel; struct rtgui_panel* panel;
panel = rtgui_panel_find(name); panel = rtgui_panel_find(name);
if (panel != RT_NULL ) if (panel != RT_NULL )
{ {
struct rtgui_panel_thread* thread; struct rtgui_panel_thread* thread;
/* allocate panel thread node */ /* allocate panel thread node */
thread = rtgui_malloc(sizeof(struct rtgui_panel_thread)); thread = rtgui_malloc(sizeof(struct rtgui_panel_thread));
if (thread == RT_NULL) if (thread == RT_NULL)
{ {
return RT_NULL; return RT_NULL;
} }
/* construct panel thread node */ /* construct panel thread node */
thread->tid = tid; thread->tid = tid;
/* init list */ /* init list */
rtgui_list_init(&(thread->list)); rtgui_list_init(&(thread->list));
rtgui_list_init(&(thread->monitor_list)); rtgui_list_init(&(thread->monitor_list));
/* append thread to the list */ /* append thread to the list */
rtgui_list_append(&(panel->thread_list), &(thread->list)); rtgui_list_append(&(panel->thread_list), &(thread->list));
} }
return panel; return panel;
} }
void rtgui_panel_thread_remove(rtgui_panel_t* panel, rt_thread_t tid) void rtgui_panel_thread_remove(rtgui_panel_t* panel, rt_thread_t tid)
{ {
if (panel != RT_NULL ) if (panel != RT_NULL )
{ {
struct rtgui_list_node* node; struct rtgui_list_node* node;
struct rtgui_panel_thread* thread; struct rtgui_panel_thread* thread;
rtgui_list_foreach(node, &(panel->thread_list)) rtgui_list_foreach(node, &(panel->thread_list))
{ {
thread = rtgui_list_entry(node, struct rtgui_panel_thread, list); thread = rtgui_list_entry(node, struct rtgui_panel_thread, list);
if (thread->tid == tid) if (thread->tid == tid)
{ {
/* remove node from list */ /* remove node from list */
rtgui_list_remove(&(panel->thread_list), &(thread->list)); rtgui_list_remove(&(panel->thread_list), &(thread->list));
/* free the panel thread node */ /* free the panel thread node */
rtgui_free(thread); rtgui_free(thread);
return; return;
} }
} }
} }
} }
rt_thread_t rtgui_panel_get_active_thread(rtgui_panel_t* panel) rt_thread_t rtgui_panel_get_active_thread(rtgui_panel_t* panel)
{ {
if (panel != RT_NULL) if (panel != RT_NULL)
{ {
if (panel->thread_list.next != RT_NULL) if (panel->thread_list.next != RT_NULL)
{ {
struct rtgui_panel_thread* thread; struct rtgui_panel_thread* thread;
thread = rtgui_list_entry(panel->thread_list.next, struct rtgui_panel_thread, list); thread = rtgui_list_entry(panel->thread_list.next, struct rtgui_panel_thread, list);
return thread->tid; return thread->tid;
} }
} }
return RT_NULL; return RT_NULL;
} }
void rtgui_panel_set_active_thread(rtgui_panel_t* panel, rt_thread_t tid) void rtgui_panel_set_active_thread(rtgui_panel_t* panel, rt_thread_t tid)
{ {
/* get old active thread */ /* get old active thread */
rt_thread_t prev_actived = rtgui_panel_get_active_thread(panel); rt_thread_t prev_actived = rtgui_panel_get_active_thread(panel);
if (prev_actived != tid) if (prev_actived != tid)
{ {
/* de-active old active workbench */ /* de-active old active workbench */
struct rtgui_event_panel_hide ehide; struct rtgui_event_panel_hide ehide;
RTGUI_EVENT_PANEL_HIDE_INIT(&ehide); RTGUI_EVENT_PANEL_HIDE_INIT(&ehide);
ehide.panel = panel; ehide.panel = panel;
ehide.workbench = RT_NULL; ehide.workbench = RT_NULL;
rtgui_thread_send_urgent(prev_actived, &(ehide.parent), sizeof (ehide)); rtgui_thread_send_urgent(prev_actived, &(ehide.parent), sizeof (ehide));
} }
if (panel != RT_NULL ) if (panel != RT_NULL )
{ {
struct rtgui_list_node* node; struct rtgui_list_node* node;
struct rtgui_panel_thread* thread; struct rtgui_panel_thread* thread;
rtgui_list_foreach(node, &(panel->thread_list)) rtgui_list_foreach(node, &(panel->thread_list))
{ {
thread = rtgui_list_entry(node, struct rtgui_panel_thread, list); thread = rtgui_list_entry(node, struct rtgui_panel_thread, list);
if (thread->tid == tid) if (thread->tid == tid)
{ {
/* remove node from list */ /* remove node from list */
rtgui_list_remove(&(panel->thread_list), &(thread->list)); rtgui_list_remove(&(panel->thread_list), &(thread->list));
/* insert node to the header */ /* insert node to the header */
rtgui_list_insert(&(panel->thread_list), &(thread->list)); rtgui_list_insert(&(panel->thread_list), &(thread->list));
return; return;
} }
} }
} }
} }
/* deactivate current activated thread -- move it to the end of list */ /* deactivate current activated thread -- move it to the end of list */
void rtgui_panel_deactive_thread(rtgui_panel_t* panel) void rtgui_panel_deactive_thread(rtgui_panel_t* panel)
{ {
RT_ASSERT(panel == RT_NULL); RT_ASSERT(panel == RT_NULL);
if (panel->thread_list.next != RT_NULL) if (panel->thread_list.next != RT_NULL)
{ {
struct rtgui_panel_thread* thread; struct rtgui_panel_thread* thread;
thread = rtgui_list_entry(panel->thread_list.next, struct rtgui_panel_thread, list); thread = rtgui_list_entry(panel->thread_list.next, struct rtgui_panel_thread, list);
/* remove it */ /* remove it */
panel->thread_list.next = thread->list.next; panel->thread_list.next = thread->list.next;
/* append to the tail of thread list */ /* append to the tail of thread list */
rtgui_list_append(&(panel->thread_list), &(thread->list)); rtgui_list_append(&(panel->thread_list), &(thread->list));
} }
} }
/** /**
* get the panel which contains a point(x, y) * get the panel which contains a point(x, y)
*/ */
rtgui_panel_t* rtgui_panel_get_contain(int x, int y) rtgui_panel_t* rtgui_panel_get_contain(int x, int y)
{ {
struct rtgui_list_node* node; struct rtgui_list_node* node;
struct rtgui_panel* panel; struct rtgui_panel* panel;
rtgui_list_foreach(node, &(_rtgui_panel_list)) rtgui_list_foreach(node, &(_rtgui_panel_list))
{ {
panel = rtgui_list_entry(node, struct rtgui_panel, sibling); panel = rtgui_list_entry(node, struct rtgui_panel, sibling);
if (rtgui_rect_contains_point(&(panel->extent), x, y) == RT_EOK) if (rtgui_rect_contains_point(&(panel->extent), x, y) == RT_EOK)
{ {
return panel; return panel;
} }
} }
return RT_NULL; return RT_NULL;
} }
/** /**
* append a rect to panel mouse monitor rect list * append a rect to panel mouse monitor rect list
*/ */
void rtgui_panel_append_monitor_rect(rtgui_panel_t* panel, rt_thread_t tid, rtgui_rect_t* rect) void rtgui_panel_append_monitor_rect(rtgui_panel_t* panel, rt_thread_t tid, rtgui_rect_t* rect)
{ {
if (panel != RT_NULL ) if (panel != RT_NULL )
{ {
struct rtgui_list_node* node; struct rtgui_list_node* node;
struct rtgui_panel_thread* thread; struct rtgui_panel_thread* thread;
rtgui_list_foreach(node, &(panel->thread_list)) rtgui_list_foreach(node, &(panel->thread_list))
{ {
thread = rtgui_list_entry(node, struct rtgui_panel_thread, list); thread = rtgui_list_entry(node, struct rtgui_panel_thread, list);
if (thread->tid == tid) if (thread->tid == tid)
{ {
/* add the monitor rect to list */ /* add the monitor rect to list */
rtgui_mouse_monitor_append(&(thread->monitor_list), rect); rtgui_mouse_monitor_append(&(thread->monitor_list), rect);
return; return;
} }
} }
} }
} }
/** /**
* remove a rect from panel mouse monitor rect list * remove a rect from panel mouse monitor rect list
*/ */
void rtgui_panel_remove_monitor_rect(rtgui_panel_t* panel, rt_thread_t tid, rtgui_rect_t* rect) void rtgui_panel_remove_monitor_rect(rtgui_panel_t* panel, rt_thread_t tid, rtgui_rect_t* rect)
{ {
if (panel != RT_NULL ) if (panel != RT_NULL )
{ {
struct rtgui_list_node* node; struct rtgui_list_node* node;
struct rtgui_panel_thread* thread; struct rtgui_panel_thread* thread;
rtgui_list_foreach(node, &(panel->thread_list)) rtgui_list_foreach(node, &(panel->thread_list))
{ {
thread = rtgui_list_entry(node, struct rtgui_panel_thread, list); thread = rtgui_list_entry(node, struct rtgui_panel_thread, list);
if (thread->tid == tid) if (thread->tid == tid)
{ {
/* remove the monitor rect from list */ /* remove the monitor rect from list */
rtgui_mouse_monitor_remove(&(thread->monitor_list), rect); rtgui_mouse_monitor_remove(&(thread->monitor_list), rect);
return; return;
} }
} }
} }
} }
void rtgui_panel_set_wm(rtgui_panel_t* panel, rt_thread_t wm) void rtgui_panel_set_wm(rtgui_panel_t* panel, rt_thread_t wm)
{ {
RT_ASSERT(wm != RT_NULL); RT_ASSERT(wm != RT_NULL);
RT_ASSERT(panel != RT_NULL); RT_ASSERT(panel != RT_NULL);
panel->wm_thread = wm; panel->wm_thread = wm;
} }
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册