mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-06-13 12:43:56 +08:00
remove RT-Thread GUI from RT-Thread temporary
This commit is contained in:
@@ -1,2 +0,0 @@
|
||||
common/font_cmp_hz*.c
|
||||
doc/doxygened/
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,94 +0,0 @@
|
||||
import os
|
||||
from building import *
|
||||
|
||||
common_src = Split("""
|
||||
common/blit.c
|
||||
common/color.c
|
||||
common/region.c
|
||||
common/rtgui_object.c
|
||||
common/rtgui_system.c
|
||||
common/rtgui_theme.c
|
||||
common/rtgui_xml.c
|
||||
common/rtgui_app.c
|
||||
common/dc.c
|
||||
common/dc_hw.c
|
||||
common/dc_buffer.c
|
||||
common/dc_client.c
|
||||
common/filerw.c
|
||||
common/image.c
|
||||
common/image_xpm.c
|
||||
common/image_hdc.c
|
||||
common/image_bmp.c
|
||||
common/image_png.c
|
||||
common/image_jpg.c
|
||||
common/image_container.c
|
||||
common/font.c
|
||||
common/font_bmp.c
|
||||
common/font_hz_file.c
|
||||
common/font_hz_bmp.c
|
||||
common/asc12font.c
|
||||
common/asc16font.c
|
||||
common/hz12font.c
|
||||
common/hz16font.c
|
||||
common/framebuffer_driver.c
|
||||
common/pixel_driver.c
|
||||
common/rtgui_mv_model.c
|
||||
""")
|
||||
|
||||
server_src = Split("""
|
||||
server/driver.c
|
||||
server/mouse.c
|
||||
server/server.c
|
||||
server/topwin.c
|
||||
""")
|
||||
|
||||
widgets_src = Split("""
|
||||
widgets/box.c
|
||||
widgets/button.c
|
||||
widgets/checkbox.c
|
||||
widgets/combobox.c
|
||||
widgets/iconbox.c
|
||||
widgets/label.c
|
||||
widgets/textview.c
|
||||
widgets/listctrl.c
|
||||
widgets/menu.c
|
||||
widgets/progressbar.c
|
||||
widgets/radiobox.c
|
||||
widgets/slider.c
|
||||
widgets/scrollbar.c
|
||||
widgets/staticline.c
|
||||
widgets/textbox.c
|
||||
widgets/listbox.c
|
||||
widgets/title.c
|
||||
widgets/notebook.c
|
||||
widgets/container.c
|
||||
widgets/list_view.c
|
||||
widgets/filelist_view.c
|
||||
widgets/widget.c
|
||||
widgets/window.c
|
||||
widgets/panel.c
|
||||
widgets/groupbox.c
|
||||
widgets/edit.c
|
||||
widgets/mv_view.c
|
||||
widgets/plot.c
|
||||
widgets/plot_curve.c
|
||||
widgets/digtube.c
|
||||
widgets/digfont.c
|
||||
""")
|
||||
|
||||
if GetDepend('RTGUI_USING_FONT_COMPACT'):
|
||||
import stract_cjk
|
||||
common_src.append('common/font_cmp_hz16.c')
|
||||
common_src.append('common/font_cmp_hz12.c')
|
||||
RegisterPreBuildingAction(stract_cjk.gen_cmp_font_file)
|
||||
|
||||
# The set of source files associated with this SConscript file.
|
||||
src = common_src + server_src + widgets_src
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
dirs = ['include', 'common', 'server', 'widgets']
|
||||
path = [os.path.join(cwd, i) for i in dirs]
|
||||
|
||||
group = DefineGroup('RTGUI', src, depend = ['RT_USING_RTGUI'], CPPPATH = path)
|
||||
|
||||
Return('group')
|
||||
@@ -1,133 +0,0 @@
|
||||
/*
|
||||
* File : asc12font.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rt-thread.org/license/LICENSE
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2009-10-16 Bernard first version
|
||||
*/
|
||||
#include <rtgui/font.h>
|
||||
|
||||
const rt_uint8_t asc12_font[] =
|
||||
{
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",0*/
|
||||
0x00,0x00,0x20,0x20,0x20,0x20,0x20,0x20,0x00,0x20,0x00,0x00,/*"!",1*/
|
||||
0x00,0x28,0x50,0x50,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*""",2*/
|
||||
0x00,0x00,0x28,0x28,0xFC,0x28,0x50,0xFC,0x50,0x50,0x00,0x00,/*"#",3*/
|
||||
0x00,0x20,0x78,0xA8,0xA0,0x60,0x30,0x28,0xA8,0xF0,0x20,0x00,/*"$",4*/
|
||||
0x00,0x00,0x48,0xA8,0xB0,0x50,0x28,0x34,0x54,0x48,0x00,0x00,/*"%",5*/
|
||||
0x00,0x00,0x20,0x50,0x50,0x78,0xA8,0xA8,0x90,0x6C,0x00,0x00,/*"&",6*/
|
||||
0x00,0x40,0x40,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"'",7*/
|
||||
0x00,0x04,0x08,0x10,0x10,0x10,0x10,0x10,0x10,0x08,0x04,0x00,/*"(",8*/
|
||||
0x00,0x40,0x20,0x10,0x10,0x10,0x10,0x10,0x10,0x20,0x40,0x00,/*")",9*/
|
||||
0x00,0x00,0x00,0x20,0xA8,0x70,0x70,0xA8,0x20,0x00,0x00,0x00,/*"*",10*/
|
||||
0x00,0x00,0x20,0x20,0x20,0xF8,0x20,0x20,0x20,0x00,0x00,0x00,/*"+",11*/
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x40,0x80,/*",",12*/
|
||||
0x00,0x00,0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,/*"-",13*/
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,/*".",14*/
|
||||
0x00,0x08,0x10,0x10,0x10,0x20,0x20,0x40,0x40,0x40,0x80,0x00,/*"/",15*/
|
||||
0x00,0x00,0x70,0x88,0x88,0x88,0x88,0x88,0x88,0x70,0x00,0x00,/*"0",16*/
|
||||
0x00,0x00,0x20,0x60,0x20,0x20,0x20,0x20,0x20,0x70,0x00,0x00,/*"1",17*/
|
||||
0x00,0x00,0x70,0x88,0x88,0x10,0x20,0x40,0x80,0xF8,0x00,0x00,/*"2",18*/
|
||||
0x00,0x00,0x70,0x88,0x08,0x30,0x08,0x08,0x88,0x70,0x00,0x00,/*"3",19*/
|
||||
0x00,0x00,0x10,0x30,0x50,0x50,0x90,0x78,0x10,0x18,0x00,0x00,/*"4",20*/
|
||||
0x00,0x00,0xF8,0x80,0x80,0xF0,0x08,0x08,0x88,0x70,0x00,0x00,/*"5",21*/
|
||||
0x00,0x00,0x70,0x90,0x80,0xF0,0x88,0x88,0x88,0x70,0x00,0x00,/*"6",22*/
|
||||
0x00,0x00,0xF8,0x90,0x10,0x20,0x20,0x20,0x20,0x20,0x00,0x00,/*"7",23*/
|
||||
0x00,0x00,0x70,0x88,0x88,0x70,0x88,0x88,0x88,0x70,0x00,0x00,/*"8",24*/
|
||||
0x00,0x00,0x70,0x88,0x88,0x88,0x78,0x08,0x48,0x70,0x00,0x00,/*"9",25*/
|
||||
0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x20,0x00,0x00,/*":",26*/
|
||||
0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x20,0x20,0x00,/*";",27*/
|
||||
0x00,0x04,0x08,0x10,0x20,0x40,0x20,0x10,0x08,0x04,0x00,0x00,/*"<",28*/
|
||||
0x00,0x00,0x00,0x00,0xF8,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,/*"=",29*/
|
||||
0x00,0x40,0x20,0x10,0x08,0x04,0x08,0x10,0x20,0x40,0x00,0x00,/*">",30*/
|
||||
0x00,0x00,0x70,0x88,0x88,0x10,0x20,0x20,0x00,0x20,0x00,0x00,/*"?",31*/
|
||||
0x00,0x00,0x70,0x88,0x98,0xA8,0xA8,0xB8,0x80,0x78,0x00,0x00,/*"@",32*/
|
||||
0x00,0x00,0x20,0x20,0x30,0x50,0x50,0x78,0x48,0xCC,0x00,0x00,/*"A",33*/
|
||||
0x00,0x00,0xF0,0x48,0x48,0x70,0x48,0x48,0x48,0xF0,0x00,0x00,/*"B",34*/
|
||||
0x00,0x00,0x78,0x88,0x80,0x80,0x80,0x80,0x88,0x70,0x00,0x00,/*"C",35*/
|
||||
0x00,0x00,0xF0,0x48,0x48,0x48,0x48,0x48,0x48,0xF0,0x00,0x00,/*"D",36*/
|
||||
0x00,0x00,0xF8,0x48,0x50,0x70,0x50,0x40,0x48,0xF8,0x00,0x00,/*"E",37*/
|
||||
0x00,0x00,0xF8,0x48,0x50,0x70,0x50,0x40,0x40,0xE0,0x00,0x00,/*"F",38*/
|
||||
0x00,0x00,0x38,0x48,0x80,0x80,0x9C,0x88,0x48,0x30,0x00,0x00,/*"G",39*/
|
||||
0x00,0x00,0xCC,0x48,0x48,0x78,0x48,0x48,0x48,0xCC,0x00,0x00,/*"H",40*/
|
||||
0x00,0x00,0xF8,0x20,0x20,0x20,0x20,0x20,0x20,0xF8,0x00,0x00,/*"I",41*/
|
||||
0x00,0x00,0x7C,0x10,0x10,0x10,0x10,0x10,0x10,0x90,0xE0,0x00,/*"J",42*/
|
||||
0x00,0x00,0xEC,0x48,0x50,0x60,0x50,0x50,0x48,0xEC,0x00,0x00,/*"K",43*/
|
||||
0x00,0x00,0xE0,0x40,0x40,0x40,0x40,0x40,0x44,0xFC,0x00,0x00,/*"L",44*/
|
||||
0x00,0x00,0xD8,0xD8,0xD8,0xD8,0xA8,0xA8,0xA8,0xA8,0x00,0x00,/*"M",45*/
|
||||
0x00,0x00,0xDC,0x48,0x68,0x68,0x58,0x58,0x48,0xE8,0x00,0x00,/*"N",46*/
|
||||
0x00,0x00,0x70,0x88,0x88,0x88,0x88,0x88,0x88,0x70,0x00,0x00,/*"O",47*/
|
||||
0x00,0x00,0xF0,0x48,0x48,0x70,0x40,0x40,0x40,0xE0,0x00,0x00,/*"P",48*/
|
||||
0x00,0x00,0x70,0x88,0x88,0x88,0x88,0xE8,0x98,0x70,0x18,0x00,/*"Q",49*/
|
||||
0x00,0x00,0xF0,0x48,0x48,0x70,0x50,0x48,0x48,0xEC,0x00,0x00,/*"R",50*/
|
||||
0x00,0x00,0x78,0x88,0x80,0x60,0x10,0x08,0x88,0xF0,0x00,0x00,/*"S",51*/
|
||||
0x00,0x00,0xF8,0xA8,0x20,0x20,0x20,0x20,0x20,0x70,0x00,0x00,/*"T",52*/
|
||||
0x00,0x00,0xCC,0x48,0x48,0x48,0x48,0x48,0x48,0x30,0x00,0x00,/*"U",53*/
|
||||
0x00,0x00,0xCC,0x48,0x48,0x50,0x50,0x30,0x20,0x20,0x00,0x00,/*"V",54*/
|
||||
0x00,0x00,0xA8,0xA8,0xA8,0x70,0x50,0x50,0x50,0x50,0x00,0x00,/*"W",55*/
|
||||
0x00,0x00,0xD8,0x50,0x50,0x20,0x20,0x50,0x50,0xD8,0x00,0x00,/*"X",56*/
|
||||
0x00,0x00,0xD8,0x50,0x50,0x20,0x20,0x20,0x20,0x70,0x00,0x00,/*"Y",57*/
|
||||
0x00,0x00,0xF8,0x90,0x10,0x20,0x20,0x40,0x48,0xF8,0x00,0x00,/*"Z",58*/
|
||||
0x00,0x38,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x38,0x00,/*"[",59*/
|
||||
0x00,0x40,0x40,0x40,0x20,0x20,0x10,0x10,0x10,0x08,0x00,0x00,/*"\",60*/
|
||||
0x00,0x70,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x70,0x00,/*"]",61*/
|
||||
0x00,0x20,0x50,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"^",62*/
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFC,/*"_",63*/
|
||||
0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"`",64*/
|
||||
0x00,0x00,0x00,0x00,0x00,0x30,0x48,0x38,0x48,0x3C,0x00,0x00,/*"a",65*/
|
||||
0x00,0x00,0xC0,0x40,0x40,0x70,0x48,0x48,0x48,0x70,0x00,0x00,/*"b",66*/
|
||||
0x00,0x00,0x00,0x00,0x00,0x38,0x48,0x40,0x40,0x38,0x00,0x00,/*"c",67*/
|
||||
0x00,0x00,0x18,0x08,0x08,0x38,0x48,0x48,0x48,0x3C,0x00,0x00,/*"d",68*/
|
||||
0x00,0x00,0x00,0x00,0x00,0x30,0x48,0x78,0x40,0x38,0x00,0x00,/*"e",69*/
|
||||
0x00,0x00,0x1C,0x20,0x20,0x78,0x20,0x20,0x20,0x78,0x00,0x00,/*"f",70*/
|
||||
0x00,0x00,0x00,0x00,0x00,0x3C,0x48,0x30,0x40,0x78,0x44,0x38,/*"g",71*/
|
||||
0x00,0x00,0xC0,0x40,0x40,0x70,0x48,0x48,0x48,0xEC,0x00,0x00,/*"h",72*/
|
||||
0x00,0x00,0x20,0x00,0x00,0x60,0x20,0x20,0x20,0x70,0x00,0x00,/*"i",73*/
|
||||
0x00,0x00,0x10,0x00,0x00,0x30,0x10,0x10,0x10,0x10,0x10,0xE0,/*"j",74*/
|
||||
0x00,0x00,0xC0,0x40,0x40,0x5C,0x50,0x70,0x48,0xEC,0x00,0x00,/*"k",75*/
|
||||
0x00,0x00,0xE0,0x20,0x20,0x20,0x20,0x20,0x20,0xF8,0x00,0x00,/*"l",76*/
|
||||
0x00,0x00,0x00,0x00,0x00,0xF0,0xA8,0xA8,0xA8,0xA8,0x00,0x00,/*"m",77*/
|
||||
0x00,0x00,0x00,0x00,0x00,0xF0,0x48,0x48,0x48,0xEC,0x00,0x00,/*"n",78*/
|
||||
0x00,0x00,0x00,0x00,0x00,0x30,0x48,0x48,0x48,0x30,0x00,0x00,/*"o",79*/
|
||||
0x00,0x00,0x00,0x00,0x00,0xF0,0x48,0x48,0x48,0x70,0x40,0xE0,/*"p",80*/
|
||||
0x00,0x00,0x00,0x00,0x00,0x38,0x48,0x48,0x48,0x38,0x08,0x1C,/*"q",81*/
|
||||
0x00,0x00,0x00,0x00,0x00,0xD8,0x60,0x40,0x40,0xE0,0x00,0x00,/*"r",82*/
|
||||
0x00,0x00,0x00,0x00,0x00,0x78,0x40,0x30,0x08,0x78,0x00,0x00,/*"s",83*/
|
||||
0x00,0x00,0x00,0x20,0x20,0x70,0x20,0x20,0x20,0x18,0x00,0x00,/*"t",84*/
|
||||
0x00,0x00,0x00,0x00,0x00,0xD8,0x48,0x48,0x48,0x3C,0x00,0x00,/*"u",85*/
|
||||
0x00,0x00,0x00,0x00,0x00,0xEC,0x48,0x50,0x30,0x20,0x00,0x00,/*"v",86*/
|
||||
0x00,0x00,0x00,0x00,0x00,0xA8,0xA8,0x70,0x50,0x50,0x00,0x00,/*"w",87*/
|
||||
0x00,0x00,0x00,0x00,0x00,0xD8,0x50,0x20,0x50,0xD8,0x00,0x00,/*"x",88*/
|
||||
0x00,0x00,0x00,0x00,0x00,0xEC,0x48,0x50,0x30,0x20,0x20,0xC0,/*"y",89*/
|
||||
0x00,0x00,0x00,0x00,0x00,0x78,0x10,0x20,0x20,0x78,0x00,0x00,/*"z",90*/
|
||||
0x00,0x18,0x10,0x10,0x10,0x20,0x10,0x10,0x10,0x10,0x18,0x00,/*"{",91*/
|
||||
0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,/*"|",92*/
|
||||
0x00,0x60,0x20,0x20,0x20,0x10,0x20,0x20,0x20,0x20,0x60,0x00,/*"}",93*/
|
||||
0x40,0xA4,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"~",94*/
|
||||
};
|
||||
|
||||
const struct rtgui_font_bitmap asc12 =
|
||||
{
|
||||
asc12_font, /* bmp */
|
||||
RT_NULL, /* each character width, NULL for fixed font */
|
||||
RT_NULL, /* offset for each character */
|
||||
6, /* width */
|
||||
12, /* height */
|
||||
32, /* first char */
|
||||
127 /* last char */
|
||||
};
|
||||
|
||||
struct rtgui_font rtgui_font_asc12 =
|
||||
{
|
||||
"asc", /* family */
|
||||
12, /* height */
|
||||
1, /* refer count */
|
||||
&bmp_font_engine, /* font engine */
|
||||
(struct rtgui_font_bitmap *) &asc12, /* font private data */
|
||||
};
|
||||
@@ -1,136 +0,0 @@
|
||||
/*
|
||||
* File : asc16font.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rt-thread.org/license/LICENSE
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2009-10-16 Bernard first version
|
||||
*/
|
||||
#include <rtgui/font.h>
|
||||
|
||||
#ifdef RTGUI_USING_FONT16
|
||||
const unsigned char asc16_font[] =
|
||||
{
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",0*/
|
||||
0x00,0x00,0x00,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00,0x18,0x18,0x00,0x00,/*"!",1*/
|
||||
0x00,0x12,0x36,0x24,0x48,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*""",2*/
|
||||
0x00,0x00,0x00,0x24,0x24,0x24,0xFE,0x48,0x48,0x48,0xFE,0x48,0x48,0x48,0x00,0x00,/*"#",3*/
|
||||
0x00,0x00,0x10,0x38,0x54,0x54,0x50,0x30,0x18,0x14,0x14,0x54,0x54,0x38,0x10,0x10,/*"$",4*/
|
||||
0x00,0x00,0x00,0x44,0xA4,0xA8,0xA8,0xA8,0x54,0x1A,0x2A,0x2A,0x2A,0x44,0x00,0x00,/*"%",5*/
|
||||
0x00,0x00,0x00,0x30,0x48,0x48,0x48,0x50,0x6E,0xA4,0x94,0x88,0x89,0x76,0x00,0x00,/*"&",6*/
|
||||
0x00,0x60,0x60,0x20,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"'",7*/
|
||||
0x00,0x02,0x04,0x08,0x08,0x10,0x10,0x10,0x10,0x10,0x10,0x08,0x08,0x04,0x02,0x00,/*"(",8*/
|
||||
0x00,0x40,0x20,0x10,0x10,0x08,0x08,0x08,0x08,0x08,0x08,0x10,0x10,0x20,0x40,0x00,/*")",9*/
|
||||
0x00,0x00,0x00,0x00,0x10,0x10,0xD6,0x38,0x38,0xD6,0x10,0x10,0x00,0x00,0x00,0x00,/*"*",10*/
|
||||
0x00,0x00,0x00,0x00,0x10,0x10,0x10,0x10,0xFE,0x10,0x10,0x10,0x10,0x00,0x00,0x00,/*"+",11*/
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x60,0x20,0xC0,/*",",12*/
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"-",13*/
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x60,0x00,0x00,/*".",14*/
|
||||
0x00,0x00,0x01,0x02,0x02,0x04,0x04,0x08,0x08,0x10,0x10,0x20,0x20,0x40,0x40,0x00,/*"/",15*/
|
||||
0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x18,0x00,0x00,/*"0",16*/
|
||||
0x00,0x00,0x00,0x10,0x70,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x7C,0x00,0x00,/*"1",17*/
|
||||
0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x04,0x04,0x08,0x10,0x20,0x42,0x7E,0x00,0x00,/*"2",18*/
|
||||
0x00,0x00,0x00,0x3C,0x42,0x42,0x04,0x18,0x04,0x02,0x02,0x42,0x44,0x38,0x00,0x00,/*"3",19*/
|
||||
0x00,0x00,0x00,0x04,0x0C,0x14,0x24,0x24,0x44,0x44,0x7E,0x04,0x04,0x1E,0x00,0x00,/*"4",20*/
|
||||
0x00,0x00,0x00,0x7E,0x40,0x40,0x40,0x58,0x64,0x02,0x02,0x42,0x44,0x38,0x00,0x00,/*"5",21*/
|
||||
0x00,0x00,0x00,0x1C,0x24,0x40,0x40,0x58,0x64,0x42,0x42,0x42,0x24,0x18,0x00,0x00,/*"6",22*/
|
||||
0x00,0x00,0x00,0x7E,0x44,0x44,0x08,0x08,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00,/*"7",23*/
|
||||
0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x24,0x18,0x24,0x42,0x42,0x42,0x3C,0x00,0x00,/*"8",24*/
|
||||
0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x26,0x1A,0x02,0x02,0x24,0x38,0x00,0x00,/*"9",25*/
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,/*":",26*/
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x10,0x10,0x20,/*";",27*/
|
||||
0x00,0x00,0x00,0x02,0x04,0x08,0x10,0x20,0x40,0x20,0x10,0x08,0x04,0x02,0x00,0x00,/*"<",28*/
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x00,0x00,0x00,0xFE,0x00,0x00,0x00,0x00,0x00,/*"=",29*/
|
||||
0x00,0x00,0x00,0x40,0x20,0x10,0x08,0x04,0x02,0x04,0x08,0x10,0x20,0x40,0x00,0x00,/*">",30*/
|
||||
0x00,0x00,0x00,0x3C,0x42,0x42,0x62,0x02,0x04,0x08,0x08,0x00,0x18,0x18,0x00,0x00,/*"?",31*/
|
||||
0x00,0x00,0x00,0x38,0x44,0x5A,0xAA,0xAA,0xAA,0xAA,0xB4,0x42,0x44,0x38,0x00,0x00,/*"@",32*/
|
||||
0x00,0x00,0x00,0x10,0x10,0x18,0x28,0x28,0x24,0x3C,0x44,0x42,0x42,0xE7,0x00,0x00,/*"A",33*/
|
||||
0x00,0x00,0x00,0xF8,0x44,0x44,0x44,0x78,0x44,0x42,0x42,0x42,0x44,0xF8,0x00,0x00,/*"B",34*/
|
||||
0x00,0x00,0x00,0x3E,0x42,0x42,0x80,0x80,0x80,0x80,0x80,0x42,0x44,0x38,0x00,0x00,/*"C",35*/
|
||||
0x00,0x00,0x00,0xF8,0x44,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x44,0xF8,0x00,0x00,/*"D",36*/
|
||||
0x00,0x00,0x00,0xFC,0x42,0x48,0x48,0x78,0x48,0x48,0x40,0x42,0x42,0xFC,0x00,0x00,/*"E",37*/
|
||||
0x00,0x00,0x00,0xFC,0x42,0x48,0x48,0x78,0x48,0x48,0x40,0x40,0x40,0xE0,0x00,0x00,/*"F",38*/
|
||||
0x00,0x00,0x00,0x3C,0x44,0x44,0x80,0x80,0x80,0x8E,0x84,0x44,0x44,0x38,0x00,0x00,/*"G",39*/
|
||||
0x00,0x00,0x00,0xE7,0x42,0x42,0x42,0x42,0x7E,0x42,0x42,0x42,0x42,0xE7,0x00,0x00,/*"H",40*/
|
||||
0x00,0x00,0x00,0x7C,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x7C,0x00,0x00,/*"I",41*/
|
||||
0x00,0x00,0x00,0x3E,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x88,0xF0,/*"J",42*/
|
||||
0x00,0x00,0x00,0xEE,0x44,0x48,0x50,0x70,0x50,0x48,0x48,0x44,0x44,0xEE,0x00,0x00,/*"K",43*/
|
||||
0x00,0x00,0x00,0xE0,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x42,0xFE,0x00,0x00,/*"L",44*/
|
||||
0x00,0x00,0x00,0xEE,0x6C,0x6C,0x6C,0x6C,0x54,0x54,0x54,0x54,0x54,0xD6,0x00,0x00,/*"M",45*/
|
||||
0x00,0x00,0x00,0xC7,0x62,0x62,0x52,0x52,0x4A,0x4A,0x4A,0x46,0x46,0xE2,0x00,0x00,/*"N",46*/
|
||||
0x00,0x00,0x00,0x38,0x44,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x44,0x38,0x00,0x00,/*"O",47*/
|
||||
0x00,0x00,0x00,0xFC,0x42,0x42,0x42,0x42,0x7C,0x40,0x40,0x40,0x40,0xE0,0x00,0x00,/*"P",48*/
|
||||
0x00,0x00,0x00,0x38,0x44,0x82,0x82,0x82,0x82,0x82,0xB2,0xCA,0x4C,0x38,0x06,0x00,/*"Q",49*/
|
||||
0x00,0x00,0x00,0xFC,0x42,0x42,0x42,0x7C,0x48,0x48,0x44,0x44,0x42,0xE3,0x00,0x00,/*"R",50*/
|
||||
0x00,0x00,0x00,0x3E,0x42,0x42,0x40,0x20,0x18,0x04,0x02,0x42,0x42,0x7C,0x00,0x00,/*"S",51*/
|
||||
0x00,0x00,0x00,0xFE,0x92,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x38,0x00,0x00,/*"T",52*/
|
||||
0x00,0x00,0x00,0xE7,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x3C,0x00,0x00,/*"U",53*/
|
||||
0x00,0x00,0x00,0xE7,0x42,0x42,0x44,0x24,0x24,0x28,0x28,0x18,0x10,0x10,0x00,0x00,/*"V",54*/
|
||||
0x00,0x00,0x00,0xD6,0x92,0x92,0x92,0x92,0xAA,0xAA,0x6C,0x44,0x44,0x44,0x00,0x00,/*"W",55*/
|
||||
0x00,0x00,0x00,0xE7,0x42,0x24,0x24,0x18,0x18,0x18,0x24,0x24,0x42,0xE7,0x00,0x00,/*"X",56*/
|
||||
0x00,0x00,0x00,0xEE,0x44,0x44,0x28,0x28,0x10,0x10,0x10,0x10,0x10,0x38,0x00,0x00,/*"Y",57*/
|
||||
0x00,0x00,0x00,0x7E,0x84,0x04,0x08,0x08,0x10,0x20,0x20,0x42,0x42,0xFC,0x00,0x00,/*"Z",58*/
|
||||
0x00,0x1E,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x1E,0x00,/*"[",59*/
|
||||
0x00,0x00,0x40,0x40,0x20,0x20,0x10,0x10,0x10,0x08,0x08,0x04,0x04,0x04,0x02,0x02,/*"\",60*/
|
||||
0x00,0x78,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x78,0x00,/*"]",61*/
|
||||
0x00,0x1C,0x22,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"^",62*/
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,/*"_",63*/
|
||||
0x00,0x60,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"`",64*/
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x1E,0x22,0x42,0x42,0x3F,0x00,0x00,/*"a",65*/
|
||||
0x00,0x00,0x00,0xC0,0x40,0x40,0x40,0x58,0x64,0x42,0x42,0x42,0x64,0x58,0x00,0x00,/*"b",66*/
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x22,0x40,0x40,0x40,0x22,0x1C,0x00,0x00,/*"c",67*/
|
||||
0x00,0x00,0x00,0x06,0x02,0x02,0x02,0x1E,0x22,0x42,0x42,0x42,0x26,0x1B,0x00,0x00,/*"d",68*/
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x7E,0x40,0x40,0x42,0x3C,0x00,0x00,/*"e",69*/
|
||||
0x00,0x00,0x00,0x0F,0x11,0x10,0x10,0x7E,0x10,0x10,0x10,0x10,0x10,0x7C,0x00,0x00,/*"f",70*/
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3E,0x44,0x44,0x38,0x40,0x3C,0x42,0x42,0x3C,/*"g",71*/
|
||||
0x00,0x00,0x00,0xC0,0x40,0x40,0x40,0x5C,0x62,0x42,0x42,0x42,0x42,0xE7,0x00,0x00,/*"h",72*/
|
||||
0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x70,0x10,0x10,0x10,0x10,0x10,0x7C,0x00,0x00,/*"i",73*/
|
||||
0x00,0x00,0x00,0x0C,0x0C,0x00,0x00,0x1C,0x04,0x04,0x04,0x04,0x04,0x04,0x44,0x78,/*"j",74*/
|
||||
0x00,0x00,0x00,0xC0,0x40,0x40,0x40,0x4E,0x48,0x50,0x68,0x48,0x44,0xEE,0x00,0x00,/*"k",75*/
|
||||
0x00,0x00,0x00,0x70,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x7C,0x00,0x00,/*"l",76*/
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x49,0x49,0x49,0x49,0x49,0xED,0x00,0x00,/*"m",77*/
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xDC,0x62,0x42,0x42,0x42,0x42,0xE7,0x00,0x00,/*"n",78*/
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x42,0x42,0x3C,0x00,0x00,/*"o",79*/
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xD8,0x64,0x42,0x42,0x42,0x44,0x78,0x40,0xE0,/*"p",80*/
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1E,0x22,0x42,0x42,0x42,0x22,0x1E,0x02,0x07,/*"q",81*/
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xEE,0x32,0x20,0x20,0x20,0x20,0xF8,0x00,0x00,/*"r",82*/
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3E,0x42,0x40,0x3C,0x02,0x42,0x7C,0x00,0x00,/*"s",83*/
|
||||
0x00,0x00,0x00,0x00,0x00,0x10,0x10,0x7C,0x10,0x10,0x10,0x10,0x10,0x0C,0x00,0x00,/*"t",84*/
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC6,0x42,0x42,0x42,0x42,0x46,0x3B,0x00,0x00,/*"u",85*/
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE7,0x42,0x24,0x24,0x28,0x10,0x10,0x00,0x00,/*"v",86*/
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xD7,0x92,0x92,0xAA,0xAA,0x44,0x44,0x00,0x00,/*"w",87*/
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x6E,0x24,0x18,0x18,0x18,0x24,0x76,0x00,0x00,/*"x",88*/
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE7,0x42,0x24,0x24,0x28,0x18,0x10,0x10,0xE0,/*"y",89*/
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x44,0x08,0x10,0x10,0x22,0x7E,0x00,0x00,/*"z",90*/
|
||||
0x00,0x03,0x04,0x04,0x04,0x04,0x04,0x08,0x04,0x04,0x04,0x04,0x04,0x04,0x03,0x00,/*"{",91*/
|
||||
0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,/*"|",92*/
|
||||
0x00,0x60,0x10,0x10,0x10,0x10,0x10,0x08,0x10,0x10,0x10,0x10,0x10,0x10,0x60,0x00,/*"}",93*/
|
||||
0x30,0x4C,0x43,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"~",94*/
|
||||
};
|
||||
|
||||
struct rtgui_font_bitmap asc16 =
|
||||
{
|
||||
(const rt_uint8_t *)asc16_font, /* bmp */
|
||||
RT_NULL, /* each character width, NULL for fixed font */
|
||||
RT_NULL, /* offset for each character */
|
||||
8, /* width */
|
||||
16, /* height */
|
||||
32, /* first char */
|
||||
127 /* last char */
|
||||
};
|
||||
|
||||
struct rtgui_font rtgui_font_asc16 =
|
||||
{
|
||||
"asc", /* family */
|
||||
16, /* height */
|
||||
1, /* refer count */
|
||||
&bmp_font_engine, /* font engine */
|
||||
&asc16, /* font private data */
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,379 +0,0 @@
|
||||
/*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2012-01-24 onelife add one more blit table which exchanges the
|
||||
* positions of R and B color components in output
|
||||
*/
|
||||
#include <rtgui/rtgui.h>
|
||||
#include <rtgui/blit.h>
|
||||
|
||||
/* 2 bpp to 1 bpp */
|
||||
static void rtgui_blit_line_2_1(rt_uint8_t *dst_ptr, rt_uint8_t *src_ptr, int line)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/* 3 bpp to 1 bpp */
|
||||
static void rtgui_blit_line_3_1(rt_uint8_t *dst_ptr, rt_uint8_t *src_ptr, int line)
|
||||
{
|
||||
line = line / 3;
|
||||
while (line)
|
||||
{
|
||||
*dst_ptr = (rt_uint8_t)(((*src_ptr & 0x00E00000) >> 16) |
|
||||
((*(src_ptr + 1) & 0x0000E000) >> 11) |
|
||||
((*(src_ptr + 2) & 0x000000C0) >> 6));
|
||||
|
||||
src_ptr += 3;
|
||||
dst_ptr ++;
|
||||
line --;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/* 4 bpp to 1 bpp */
|
||||
static void rtgui_blit_line_4_1(rt_uint8_t *dst_ptr, rt_uint8_t *src_ptr, int line)
|
||||
{
|
||||
struct _color
|
||||
{
|
||||
rt_uint8_t r, g, b, a;
|
||||
} *c;
|
||||
|
||||
c = (struct _color *)src_ptr;
|
||||
while (line-- > 0)
|
||||
{
|
||||
*dst_ptr = (c->r & 0xe0) | (c->g & 0xc0) >> 3 | (c->b & 0xe0) >> 5 ;
|
||||
|
||||
c ++;
|
||||
dst_ptr ++;
|
||||
}
|
||||
}
|
||||
|
||||
/* 1 bpp to 2 bpp */
|
||||
static void rtgui_blit_line_1_2(rt_uint8_t *dst_ptr, rt_uint8_t *src_ptr, int line)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/* 3 bpp to 2 bpp */
|
||||
static void rtgui_blit_line_3_2(rt_uint8_t *dst_ptr, rt_uint8_t *src_ptr, int line)
|
||||
{
|
||||
rt_uint16_t *dst;
|
||||
|
||||
dst = (rt_uint16_t *)dst_ptr;
|
||||
line = line / 3;
|
||||
while (line)
|
||||
{
|
||||
*dst = (((*(src_ptr + 2) << 8) & 0x0000F800) |
|
||||
((*(src_ptr + 1) << 3) & 0x000007E0) |
|
||||
((*src_ptr >> 3) & 0x0000001F));
|
||||
|
||||
src_ptr += 3;
|
||||
dst ++;
|
||||
line --;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* 4 bpp to 2 bpp */
|
||||
static void rtgui_blit_line_4_2(rt_uint8_t *dst_ptr, rt_uint8_t *src_ptr, int line)
|
||||
{
|
||||
struct _color
|
||||
{
|
||||
rt_uint8_t r, g, b, a;
|
||||
} *c;
|
||||
rt_uint16_t *ptr;
|
||||
|
||||
c = (struct _color *)src_ptr;
|
||||
ptr = (rt_uint16_t *)dst_ptr;
|
||||
|
||||
line = line / 4;
|
||||
while (line-- > 0)
|
||||
{
|
||||
*ptr = ((c->r & 0xf8) << 8) | ((c->g & 0xfc) << 3) | (c->b >> 3);
|
||||
|
||||
c ++;
|
||||
ptr ++;
|
||||
}
|
||||
}
|
||||
|
||||
static void rtgui_blit_line_1_3(rt_uint8_t *dst_ptr, rt_uint8_t *src_ptr, int line)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
#define HI 1
|
||||
#define LO 0
|
||||
|
||||
/* Special optimized blit for RGB 5-6-5 --> RGBA 8-8-8-8 */
|
||||
static const rt_uint32_t RGB565_RGBA8888_LUT[512] =
|
||||
{
|
||||
0x000000ff, 0x00000000, 0x000008ff, 0x00200000,
|
||||
0x000010ff, 0x00400000, 0x000018ff, 0x00610000,
|
||||
0x000020ff, 0x00810000, 0x000029ff, 0x00a10000,
|
||||
0x000031ff, 0x00c20000, 0x000039ff, 0x00e20000,
|
||||
0x000041ff, 0x08000000, 0x00004aff, 0x08200000,
|
||||
0x000052ff, 0x08400000, 0x00005aff, 0x08610000,
|
||||
0x000062ff, 0x08810000, 0x00006aff, 0x08a10000,
|
||||
0x000073ff, 0x08c20000, 0x00007bff, 0x08e20000,
|
||||
0x000083ff, 0x10000000, 0x00008bff, 0x10200000,
|
||||
0x000094ff, 0x10400000, 0x00009cff, 0x10610000,
|
||||
0x0000a4ff, 0x10810000, 0x0000acff, 0x10a10000,
|
||||
0x0000b4ff, 0x10c20000, 0x0000bdff, 0x10e20000,
|
||||
0x0000c5ff, 0x18000000, 0x0000cdff, 0x18200000,
|
||||
0x0000d5ff, 0x18400000, 0x0000deff, 0x18610000,
|
||||
0x0000e6ff, 0x18810000, 0x0000eeff, 0x18a10000,
|
||||
0x0000f6ff, 0x18c20000, 0x0000ffff, 0x18e20000,
|
||||
0x000400ff, 0x20000000, 0x000408ff, 0x20200000,
|
||||
0x000410ff, 0x20400000, 0x000418ff, 0x20610000,
|
||||
0x000420ff, 0x20810000, 0x000429ff, 0x20a10000,
|
||||
0x000431ff, 0x20c20000, 0x000439ff, 0x20e20000,
|
||||
0x000441ff, 0x29000000, 0x00044aff, 0x29200000,
|
||||
0x000452ff, 0x29400000, 0x00045aff, 0x29610000,
|
||||
0x000462ff, 0x29810000, 0x00046aff, 0x29a10000,
|
||||
0x000473ff, 0x29c20000, 0x00047bff, 0x29e20000,
|
||||
0x000483ff, 0x31000000, 0x00048bff, 0x31200000,
|
||||
0x000494ff, 0x31400000, 0x00049cff, 0x31610000,
|
||||
0x0004a4ff, 0x31810000, 0x0004acff, 0x31a10000,
|
||||
0x0004b4ff, 0x31c20000, 0x0004bdff, 0x31e20000,
|
||||
0x0004c5ff, 0x39000000, 0x0004cdff, 0x39200000,
|
||||
0x0004d5ff, 0x39400000, 0x0004deff, 0x39610000,
|
||||
0x0004e6ff, 0x39810000, 0x0004eeff, 0x39a10000,
|
||||
0x0004f6ff, 0x39c20000, 0x0004ffff, 0x39e20000,
|
||||
0x000800ff, 0x41000000, 0x000808ff, 0x41200000,
|
||||
0x000810ff, 0x41400000, 0x000818ff, 0x41610000,
|
||||
0x000820ff, 0x41810000, 0x000829ff, 0x41a10000,
|
||||
0x000831ff, 0x41c20000, 0x000839ff, 0x41e20000,
|
||||
0x000841ff, 0x4a000000, 0x00084aff, 0x4a200000,
|
||||
0x000852ff, 0x4a400000, 0x00085aff, 0x4a610000,
|
||||
0x000862ff, 0x4a810000, 0x00086aff, 0x4aa10000,
|
||||
0x000873ff, 0x4ac20000, 0x00087bff, 0x4ae20000,
|
||||
0x000883ff, 0x52000000, 0x00088bff, 0x52200000,
|
||||
0x000894ff, 0x52400000, 0x00089cff, 0x52610000,
|
||||
0x0008a4ff, 0x52810000, 0x0008acff, 0x52a10000,
|
||||
0x0008b4ff, 0x52c20000, 0x0008bdff, 0x52e20000,
|
||||
0x0008c5ff, 0x5a000000, 0x0008cdff, 0x5a200000,
|
||||
0x0008d5ff, 0x5a400000, 0x0008deff, 0x5a610000,
|
||||
0x0008e6ff, 0x5a810000, 0x0008eeff, 0x5aa10000,
|
||||
0x0008f6ff, 0x5ac20000, 0x0008ffff, 0x5ae20000,
|
||||
0x000c00ff, 0x62000000, 0x000c08ff, 0x62200000,
|
||||
0x000c10ff, 0x62400000, 0x000c18ff, 0x62610000,
|
||||
0x000c20ff, 0x62810000, 0x000c29ff, 0x62a10000,
|
||||
0x000c31ff, 0x62c20000, 0x000c39ff, 0x62e20000,
|
||||
0x000c41ff, 0x6a000000, 0x000c4aff, 0x6a200000,
|
||||
0x000c52ff, 0x6a400000, 0x000c5aff, 0x6a610000,
|
||||
0x000c62ff, 0x6a810000, 0x000c6aff, 0x6aa10000,
|
||||
0x000c73ff, 0x6ac20000, 0x000c7bff, 0x6ae20000,
|
||||
0x000c83ff, 0x73000000, 0x000c8bff, 0x73200000,
|
||||
0x000c94ff, 0x73400000, 0x000c9cff, 0x73610000,
|
||||
0x000ca4ff, 0x73810000, 0x000cacff, 0x73a10000,
|
||||
0x000cb4ff, 0x73c20000, 0x000cbdff, 0x73e20000,
|
||||
0x000cc5ff, 0x7b000000, 0x000ccdff, 0x7b200000,
|
||||
0x000cd5ff, 0x7b400000, 0x000cdeff, 0x7b610000,
|
||||
0x000ce6ff, 0x7b810000, 0x000ceeff, 0x7ba10000,
|
||||
0x000cf6ff, 0x7bc20000, 0x000cffff, 0x7be20000,
|
||||
0x001000ff, 0x83000000, 0x001008ff, 0x83200000,
|
||||
0x001010ff, 0x83400000, 0x001018ff, 0x83610000,
|
||||
0x001020ff, 0x83810000, 0x001029ff, 0x83a10000,
|
||||
0x001031ff, 0x83c20000, 0x001039ff, 0x83e20000,
|
||||
0x001041ff, 0x8b000000, 0x00104aff, 0x8b200000,
|
||||
0x001052ff, 0x8b400000, 0x00105aff, 0x8b610000,
|
||||
0x001062ff, 0x8b810000, 0x00106aff, 0x8ba10000,
|
||||
0x001073ff, 0x8bc20000, 0x00107bff, 0x8be20000,
|
||||
0x001083ff, 0x94000000, 0x00108bff, 0x94200000,
|
||||
0x001094ff, 0x94400000, 0x00109cff, 0x94610000,
|
||||
0x0010a4ff, 0x94810000, 0x0010acff, 0x94a10000,
|
||||
0x0010b4ff, 0x94c20000, 0x0010bdff, 0x94e20000,
|
||||
0x0010c5ff, 0x9c000000, 0x0010cdff, 0x9c200000,
|
||||
0x0010d5ff, 0x9c400000, 0x0010deff, 0x9c610000,
|
||||
0x0010e6ff, 0x9c810000, 0x0010eeff, 0x9ca10000,
|
||||
0x0010f6ff, 0x9cc20000, 0x0010ffff, 0x9ce20000,
|
||||
0x001400ff, 0xa4000000, 0x001408ff, 0xa4200000,
|
||||
0x001410ff, 0xa4400000, 0x001418ff, 0xa4610000,
|
||||
0x001420ff, 0xa4810000, 0x001429ff, 0xa4a10000,
|
||||
0x001431ff, 0xa4c20000, 0x001439ff, 0xa4e20000,
|
||||
0x001441ff, 0xac000000, 0x00144aff, 0xac200000,
|
||||
0x001452ff, 0xac400000, 0x00145aff, 0xac610000,
|
||||
0x001462ff, 0xac810000, 0x00146aff, 0xaca10000,
|
||||
0x001473ff, 0xacc20000, 0x00147bff, 0xace20000,
|
||||
0x001483ff, 0xb4000000, 0x00148bff, 0xb4200000,
|
||||
0x001494ff, 0xb4400000, 0x00149cff, 0xb4610000,
|
||||
0x0014a4ff, 0xb4810000, 0x0014acff, 0xb4a10000,
|
||||
0x0014b4ff, 0xb4c20000, 0x0014bdff, 0xb4e20000,
|
||||
0x0014c5ff, 0xbd000000, 0x0014cdff, 0xbd200000,
|
||||
0x0014d5ff, 0xbd400000, 0x0014deff, 0xbd610000,
|
||||
0x0014e6ff, 0xbd810000, 0x0014eeff, 0xbda10000,
|
||||
0x0014f6ff, 0xbdc20000, 0x0014ffff, 0xbde20000,
|
||||
0x001800ff, 0xc5000000, 0x001808ff, 0xc5200000,
|
||||
0x001810ff, 0xc5400000, 0x001818ff, 0xc5610000,
|
||||
0x001820ff, 0xc5810000, 0x001829ff, 0xc5a10000,
|
||||
0x001831ff, 0xc5c20000, 0x001839ff, 0xc5e20000,
|
||||
0x001841ff, 0xcd000000, 0x00184aff, 0xcd200000,
|
||||
0x001852ff, 0xcd400000, 0x00185aff, 0xcd610000,
|
||||
0x001862ff, 0xcd810000, 0x00186aff, 0xcda10000,
|
||||
0x001873ff, 0xcdc20000, 0x00187bff, 0xcde20000,
|
||||
0x001883ff, 0xd5000000, 0x00188bff, 0xd5200000,
|
||||
0x001894ff, 0xd5400000, 0x00189cff, 0xd5610000,
|
||||
0x0018a4ff, 0xd5810000, 0x0018acff, 0xd5a10000,
|
||||
0x0018b4ff, 0xd5c20000, 0x0018bdff, 0xd5e20000,
|
||||
0x0018c5ff, 0xde000000, 0x0018cdff, 0xde200000,
|
||||
0x0018d5ff, 0xde400000, 0x0018deff, 0xde610000,
|
||||
0x0018e6ff, 0xde810000, 0x0018eeff, 0xdea10000,
|
||||
0x0018f6ff, 0xdec20000, 0x0018ffff, 0xdee20000,
|
||||
0x001c00ff, 0xe6000000, 0x001c08ff, 0xe6200000,
|
||||
0x001c10ff, 0xe6400000, 0x001c18ff, 0xe6610000,
|
||||
0x001c20ff, 0xe6810000, 0x001c29ff, 0xe6a10000,
|
||||
0x001c31ff, 0xe6c20000, 0x001c39ff, 0xe6e20000,
|
||||
0x001c41ff, 0xee000000, 0x001c4aff, 0xee200000,
|
||||
0x001c52ff, 0xee400000, 0x001c5aff, 0xee610000,
|
||||
0x001c62ff, 0xee810000, 0x001c6aff, 0xeea10000,
|
||||
0x001c73ff, 0xeec20000, 0x001c7bff, 0xeee20000,
|
||||
0x001c83ff, 0xf6000000, 0x001c8bff, 0xf6200000,
|
||||
0x001c94ff, 0xf6400000, 0x001c9cff, 0xf6610000,
|
||||
0x001ca4ff, 0xf6810000, 0x001cacff, 0xf6a10000,
|
||||
0x001cb4ff, 0xf6c20000, 0x001cbdff, 0xf6e20000,
|
||||
0x001cc5ff, 0xff000000, 0x001ccdff, 0xff200000,
|
||||
0x001cd5ff, 0xff400000, 0x001cdeff, 0xff610000,
|
||||
0x001ce6ff, 0xff810000, 0x001ceeff, 0xffa10000,
|
||||
0x001cf6ff, 0xffc20000, 0x001cffff, 0xffe20000,
|
||||
};
|
||||
|
||||
static void rtgui_blit_line_2_3(rt_uint8_t *dst_ptr, rt_uint8_t *src_ptr, int line)
|
||||
{
|
||||
rt_uint16_t *src;
|
||||
rt_uint32_t *dst;
|
||||
|
||||
src = (rt_uint16_t *)src_ptr;
|
||||
dst = (rt_uint32_t *)dst_ptr;
|
||||
|
||||
line = line / 2;
|
||||
while (line)
|
||||
{
|
||||
*dst++ = RGB565_RGBA8888_LUT[src[LO] * 2] + RGB565_RGBA8888_LUT[src[HI] * 2 + 1];
|
||||
line--;
|
||||
src ++;
|
||||
}
|
||||
}
|
||||
|
||||
void rtgui_blit_line_direct(rt_uint8_t *dst_ptr, rt_uint8_t *src_ptr, int line)
|
||||
{
|
||||
rt_memcpy(dst_ptr, src_ptr, line);
|
||||
}
|
||||
|
||||
/* convert 4bpp to 3bpp */
|
||||
static void rtgui_blit_line_4_3(rt_uint8_t *dst_ptr, rt_uint8_t *src_ptr, int line)
|
||||
{
|
||||
line = line / 4;
|
||||
while (line)
|
||||
{
|
||||
*dst_ptr++ = *src_ptr++;
|
||||
*dst_ptr++ = *src_ptr++;
|
||||
*dst_ptr++ = *src_ptr++;
|
||||
src_ptr ++;
|
||||
line --;
|
||||
}
|
||||
}
|
||||
|
||||
static void rtgui_blit_line_1_4(rt_uint8_t *dst_ptr, rt_uint8_t *src_ptr, int line)
|
||||
{
|
||||
}
|
||||
|
||||
static void rtgui_blit_line_2_4(rt_uint8_t *dst_ptr, rt_uint8_t *src_ptr, int line)
|
||||
{
|
||||
}
|
||||
|
||||
/* convert 3bpp to 4bpp */
|
||||
static void rtgui_blit_line_3_4(rt_uint8_t *dst_ptr, rt_uint8_t *src_ptr, int line)
|
||||
{
|
||||
line = line / 4;
|
||||
while (line)
|
||||
{
|
||||
*dst_ptr++ = *src_ptr++;
|
||||
*dst_ptr++ = *src_ptr++;
|
||||
*dst_ptr++ = *src_ptr++;
|
||||
*dst_ptr++ = 0;
|
||||
line --;
|
||||
}
|
||||
}
|
||||
|
||||
static const rtgui_blit_line_func _blit_table[5][5] =
|
||||
{
|
||||
/* 0_0, 1_0, 2_0, 3_0, 4_0 */
|
||||
{RT_NULL, RT_NULL, RT_NULL, RT_NULL, RT_NULL },
|
||||
/* 0_1, 1_1, 2_1, 3_1, 4_1 */
|
||||
{RT_NULL, rtgui_blit_line_direct, rtgui_blit_line_2_1, rtgui_blit_line_3_1, rtgui_blit_line_4_1 },
|
||||
/* 0_2, 1_2, 2_2, 3_2, 4_2 */
|
||||
{RT_NULL, rtgui_blit_line_1_2, rtgui_blit_line_direct, rtgui_blit_line_3_2, rtgui_blit_line_4_2 },
|
||||
/* 0_3, 1_3, 2_3, 3_3, 4_3 */
|
||||
{RT_NULL, rtgui_blit_line_1_3, rtgui_blit_line_2_3, rtgui_blit_line_direct, rtgui_blit_line_4_3 },
|
||||
/* 0_4, 1_4, 2_4, 3_4, 4_4 */
|
||||
{RT_NULL, rtgui_blit_line_1_4, rtgui_blit_line_2_4, rtgui_blit_line_3_4, rtgui_blit_line_direct },
|
||||
};
|
||||
|
||||
rtgui_blit_line_func rtgui_blit_line_get(int dst_bpp, int src_bpp)
|
||||
{
|
||||
RT_ASSERT(dst_bpp > 0 && dst_bpp < 5);
|
||||
RT_ASSERT(src_bpp > 0 && src_bpp < 5);
|
||||
|
||||
return _blit_table[dst_bpp][src_bpp];
|
||||
}
|
||||
|
||||
|
||||
static void rtgui_blit_line_3_2_inv(rt_uint8_t *dst_ptr, rt_uint8_t *src_ptr, int line)
|
||||
{
|
||||
rt_uint16_t *dst;
|
||||
|
||||
dst = (rt_uint16_t *)dst_ptr;
|
||||
line = line / 3;
|
||||
while (line)
|
||||
{
|
||||
*dst = (((*src_ptr << 8) & 0x0000F800) |
|
||||
((*(src_ptr + 1) << 3) & 0x000007E0) |
|
||||
((*(src_ptr + 2) >> 3) & 0x0000001F));
|
||||
|
||||
src_ptr += 3;
|
||||
dst ++;
|
||||
line --;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void rtgui_blit_line_2_2_inv(rt_uint8_t *dst_ptr, rt_uint8_t *src_ptr, int line)
|
||||
{
|
||||
rt_uint16_t *dst, *src;
|
||||
|
||||
dst = (rt_uint16_t *)dst_ptr;
|
||||
src = (rt_uint16_t *)src_ptr;
|
||||
line = line / 2;
|
||||
while (line)
|
||||
{
|
||||
*dst = ((*src << 11) & 0xF800) | (*src & 0x07E0) | ((*src >> 11) & 0x001F);
|
||||
src ++;
|
||||
dst ++;
|
||||
line --;
|
||||
}
|
||||
}
|
||||
|
||||
static const rtgui_blit_line_func _blit_table_inv[5][5] =
|
||||
{
|
||||
/* 0_0, 1_0, 2_0, 3_0, 4_0 */
|
||||
{RT_NULL, RT_NULL, RT_NULL, RT_NULL, RT_NULL },
|
||||
/* 0_1, 1_1, 2_1, 3_1, 4_1 */
|
||||
{RT_NULL, rtgui_blit_line_direct, rtgui_blit_line_2_1, rtgui_blit_line_3_1, rtgui_blit_line_4_1 },
|
||||
/* 0_2, 1_2, 2_2, 3_2, 4_2 */
|
||||
{RT_NULL, rtgui_blit_line_1_2, rtgui_blit_line_2_2_inv, rtgui_blit_line_3_2_inv, rtgui_blit_line_4_2 },
|
||||
/* 0_3, 1_3, 2_3, 3_3, 4_3 */
|
||||
{RT_NULL, rtgui_blit_line_1_3, rtgui_blit_line_2_3, rtgui_blit_line_direct, rtgui_blit_line_4_3 },
|
||||
/* 0_4, 1_4, 2_4, 3_4, 4_4 */
|
||||
{RT_NULL, rtgui_blit_line_1_4, rtgui_blit_line_2_4, rtgui_blit_line_3_4, rtgui_blit_line_direct },
|
||||
};
|
||||
|
||||
rtgui_blit_line_func rtgui_blit_line_get_inv(int dst_bpp, int src_bpp)
|
||||
{
|
||||
RT_ASSERT(dst_bpp > 0 && dst_bpp < 5);
|
||||
RT_ASSERT(src_bpp > 0 && src_bpp < 5);
|
||||
|
||||
return _blit_table_inv[dst_bpp][src_bpp];
|
||||
}
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
* File : color.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rt-thread.org/license/LICENSE
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2009-10-16 Bernard first version
|
||||
*/
|
||||
#include <rtgui/color.h>
|
||||
|
||||
const rtgui_color_t red = RTGUI_RGB(0xff, 0x00, 0x00);
|
||||
const rtgui_color_t green = RTGUI_RGB(0x00, 0xff, 0x00);
|
||||
const rtgui_color_t blue = RTGUI_RGB(0x00, 0x00, 0xff);
|
||||
const rtgui_color_t black = RTGUI_RGB(0x00, 0x00, 0x00);
|
||||
const rtgui_color_t white = RTGUI_RGB(0xff, 0xff, 0xff);
|
||||
|
||||
const rtgui_color_t high_light = RTGUI_RGB(0xff, 0xff, 0xff);
|
||||
const rtgui_color_t dark_grey = RTGUI_RGB(0x7f, 0x7f, 0x7f);
|
||||
const rtgui_color_t light_grey = RTGUI_RGB(0xc0, 0xc0, 0xc0);
|
||||
|
||||
#define RTGUI_RGB_R(c) ((c) & 0xff)
|
||||
#define RTGUI_RGB_G(c) (((c) >> 8) & 0xff)
|
||||
#define RTGUI_RGB_B(c) (((c) >> 16) & 0xff)
|
||||
#define RTGUI_RGB_A(c) (((c) >> 24) & 0xff)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,345 +0,0 @@
|
||||
/*
|
||||
* File : dc_buffer.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rt-thread.org/license/LICENSE
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2009-10-16 Bernard first version
|
||||
*/
|
||||
#include <rtgui/rtgui.h>
|
||||
#include <rtgui/dc.h>
|
||||
#include <rtgui/blit.h>
|
||||
#include <rtgui/dc_hw.h>
|
||||
#include <rtgui/color.h>
|
||||
#include <rtgui/rtgui_system.h>
|
||||
|
||||
#define hw_driver (rtgui_graphic_driver_get_default())
|
||||
|
||||
#define RTGUI_BLENDMODE_NONE 0x00
|
||||
#define RTGUI_BLENDMODE_BLEND 0x01
|
||||
#define RTGUI_BLENDMODE_ADD 0x02
|
||||
#define RTGUI_BLENDMODE_MOD 0x03
|
||||
|
||||
struct rtgui_dc_buffer
|
||||
{
|
||||
struct rtgui_dc parent;
|
||||
|
||||
/* graphic context */
|
||||
rtgui_gc_t gc;
|
||||
|
||||
/* pixel format */
|
||||
rt_uint8_t pixel_format;
|
||||
rt_uint8_t blend_mode;
|
||||
|
||||
/* width and height */
|
||||
rt_uint16_t width, height;
|
||||
rt_uint16_t pitch;
|
||||
|
||||
/* blit info */
|
||||
rtgui_region_t clip;
|
||||
|
||||
/* pixel data */
|
||||
rt_uint8_t *pixel;
|
||||
};
|
||||
|
||||
static rt_bool_t rtgui_dc_buffer_fini(struct rtgui_dc *dc);
|
||||
static void rtgui_dc_buffer_draw_point(struct rtgui_dc *dc, int x, int y);
|
||||
static void rtgui_dc_buffer_draw_color_point(struct rtgui_dc *dc, int x, int y, rtgui_color_t color);
|
||||
static void rtgui_dc_buffer_draw_vline(struct rtgui_dc *dc, int x, int y1, int y2);
|
||||
static void rtgui_dc_buffer_draw_hline(struct rtgui_dc *dc, int x1, int x2, int y);
|
||||
static void rtgui_dc_buffer_fill_rect(struct rtgui_dc *dc, struct rtgui_rect *rect);
|
||||
static void rtgui_dc_buffer_blit_line(struct rtgui_dc *self, int x1, int x2, int y, rt_uint8_t *line_data);
|
||||
static void rtgui_dc_buffer_blit(struct rtgui_dc *self, struct rtgui_point *dc_point,
|
||||
struct rtgui_dc *dest, rtgui_rect_t *rect);
|
||||
|
||||
static void rtgui_dc_buffer_set_gc(struct rtgui_dc *dc, rtgui_gc_t *gc);
|
||||
static rtgui_gc_t *rtgui_dc_buffer_get_gc(struct rtgui_dc *dc);
|
||||
|
||||
static rt_bool_t rtgui_dc_buffer_get_visible(struct rtgui_dc *dc);
|
||||
static void rtgui_dc_buffer_get_rect(struct rtgui_dc *dc, rtgui_rect_t *rect);
|
||||
|
||||
const static struct rtgui_dc_engine dc_buffer_engine =
|
||||
{
|
||||
rtgui_dc_buffer_draw_point,
|
||||
rtgui_dc_buffer_draw_color_point,
|
||||
rtgui_dc_buffer_draw_vline,
|
||||
rtgui_dc_buffer_draw_hline,
|
||||
rtgui_dc_buffer_fill_rect,
|
||||
rtgui_dc_buffer_blit_line,
|
||||
rtgui_dc_buffer_blit,
|
||||
|
||||
rtgui_dc_buffer_set_gc,
|
||||
rtgui_dc_buffer_get_gc,
|
||||
|
||||
rtgui_dc_buffer_get_visible,
|
||||
rtgui_dc_buffer_get_rect,
|
||||
|
||||
rtgui_dc_buffer_fini,
|
||||
};
|
||||
|
||||
struct rtgui_dc *rtgui_dc_buffer_create(int w, int h)
|
||||
{
|
||||
struct rtgui_dc_buffer *dc;
|
||||
|
||||
dc = (struct rtgui_dc_buffer *)rtgui_malloc(sizeof(struct rtgui_dc_buffer));
|
||||
dc->parent.type = RTGUI_DC_BUFFER;
|
||||
dc->parent.engine = &dc_buffer_engine;
|
||||
dc->gc.foreground = default_foreground;
|
||||
dc->gc.background = default_background;
|
||||
dc->gc.font = rtgui_font_default();
|
||||
dc->gc.textalign = RTGUI_ALIGN_LEFT | RTGUI_ALIGN_TOP;
|
||||
|
||||
dc->width = w;
|
||||
dc->height = h;
|
||||
dc->pitch = w *sizeof(rtgui_color_t);
|
||||
|
||||
rtgui_region_init(&(dc->clip));
|
||||
|
||||
dc->pixel = rtgui_malloc(h * dc->pitch);
|
||||
rt_memset(dc->pixel, 0, h * dc->pitch);
|
||||
|
||||
return &(dc->parent);
|
||||
}
|
||||
|
||||
rt_uint8_t *rtgui_dc_buffer_get_pixel(struct rtgui_dc *dc)
|
||||
{
|
||||
struct rtgui_dc_buffer *dc_buffer;
|
||||
|
||||
dc_buffer = (struct rtgui_dc_buffer *)dc;
|
||||
|
||||
return dc_buffer->pixel;
|
||||
}
|
||||
|
||||
static rt_bool_t rtgui_dc_buffer_fini(struct rtgui_dc *dc)
|
||||
{
|
||||
struct rtgui_dc_buffer *buffer = (struct rtgui_dc_buffer *)dc;
|
||||
|
||||
if (dc->type != RTGUI_DC_BUFFER) return RT_FALSE;
|
||||
|
||||
rtgui_free(buffer->pixel);
|
||||
buffer->pixel = RT_NULL;
|
||||
|
||||
return RT_TRUE;
|
||||
}
|
||||
|
||||
static void rtgui_dc_buffer_draw_point(struct rtgui_dc *self, int x, int y)
|
||||
{
|
||||
rtgui_color_t *ptr;
|
||||
struct rtgui_dc_buffer *dc;
|
||||
|
||||
dc = (struct rtgui_dc_buffer *)self;
|
||||
|
||||
/* does not draw point out of dc */
|
||||
if ((x > dc->width) || (y > dc->height)) return ;
|
||||
|
||||
/* note: there is no parameter check in this function */
|
||||
ptr = (rtgui_color_t *)(dc->pixel + y * dc->pitch + x * sizeof(rtgui_color_t));
|
||||
|
||||
*ptr = dc->gc.foreground;
|
||||
}
|
||||
|
||||
static void rtgui_dc_buffer_draw_color_point(struct rtgui_dc *self, int x, int y, rtgui_color_t color)
|
||||
{
|
||||
rtgui_color_t *ptr;
|
||||
struct rtgui_dc_buffer *dc;
|
||||
|
||||
dc = (struct rtgui_dc_buffer *)self;
|
||||
|
||||
/* note: there is no parameter check in this function */
|
||||
ptr = (rtgui_color_t *)(dc->pixel + y * dc->pitch + x * sizeof(rtgui_color_t));
|
||||
|
||||
*ptr = color;
|
||||
}
|
||||
|
||||
static void rtgui_dc_buffer_draw_vline(struct rtgui_dc *self, int x, int y1, int y2)
|
||||
{
|
||||
rtgui_color_t *ptr;
|
||||
register rt_base_t index;
|
||||
struct rtgui_dc_buffer *dc;
|
||||
|
||||
dc = (struct rtgui_dc_buffer *)self;
|
||||
|
||||
if (x >= dc->width) return;
|
||||
if (y1 > dc->height) y1 = dc->height;
|
||||
if (y2 > dc->height) y2 = dc->height;
|
||||
|
||||
ptr = (rtgui_color_t *)(dc->pixel + y1 * dc->pitch + x * sizeof(rtgui_color_t));
|
||||
for (index = y1; index < y2; index ++)
|
||||
{
|
||||
/* draw this point */
|
||||
*ptr = dc->gc.foreground;
|
||||
ptr += dc->width;
|
||||
}
|
||||
}
|
||||
|
||||
static void rtgui_dc_buffer_draw_hline(struct rtgui_dc *self, int x1, int x2, int y)
|
||||
{
|
||||
rtgui_color_t *ptr;
|
||||
register rt_base_t index;
|
||||
struct rtgui_dc_buffer *dc;
|
||||
|
||||
dc = (struct rtgui_dc_buffer *)self;
|
||||
if (y >= dc->height) return;
|
||||
if (x1 > dc->width) x1 = dc->width;
|
||||
if (x2 > dc->width) x2 = dc->width;
|
||||
|
||||
ptr = (rtgui_color_t *)(dc->pixel + y * dc->pitch + x1 * sizeof(rtgui_color_t));
|
||||
for (index = x1; index < x2; index ++)
|
||||
{
|
||||
/* draw this point */
|
||||
*ptr++ = dc->gc.foreground;
|
||||
}
|
||||
}
|
||||
|
||||
static void rtgui_dc_buffer_fill_rect(struct rtgui_dc *self, struct rtgui_rect *rect)
|
||||
{
|
||||
rtgui_color_t foreground;
|
||||
rtgui_rect_t r;
|
||||
struct rtgui_dc_buffer *dc;
|
||||
|
||||
r = *rect;
|
||||
dc = (struct rtgui_dc_buffer *)self;
|
||||
if (r.x1 > dc->width) r.x1 = dc->width;
|
||||
if (r.x2 > dc->width) r.x2 = dc->width;
|
||||
if (r.y1 > dc->height) r.y1 = dc->height;
|
||||
if (r.y2 > dc->height) r.y2 = dc->height;
|
||||
|
||||
/* save foreground color */
|
||||
foreground = RTGUI_DC_FC(self);
|
||||
|
||||
/* set background color as foreground color */
|
||||
RTGUI_DC_FC(self) = RTGUI_DC_BC(self);
|
||||
|
||||
/* fill first line */
|
||||
rtgui_dc_buffer_draw_hline(&(dc->parent), r.x1, r.x2, r.y1);
|
||||
|
||||
/* memory copy other lines */
|
||||
if (r.y2 > r.y1)
|
||||
{
|
||||
register rt_base_t index;
|
||||
for (index = r.y1 + 1; index < r.y2; index ++)
|
||||
{
|
||||
rt_memcpy(dc->pixel + index * dc->pitch,
|
||||
dc->pixel + r.y1 * dc->pitch,
|
||||
(r.x2 - r.x1) * sizeof(rtgui_color_t));
|
||||
}
|
||||
}
|
||||
|
||||
/* restore foreground color */
|
||||
RTGUI_DC_FC(self) = foreground;
|
||||
}
|
||||
|
||||
/* blit a dc to a hardware dc */
|
||||
static void rtgui_dc_buffer_blit(struct rtgui_dc *self, struct rtgui_point *dc_point, struct rtgui_dc *dest, rtgui_rect_t *rect)
|
||||
{
|
||||
struct rtgui_dc_buffer *dc = (struct rtgui_dc_buffer *)self;
|
||||
|
||||
if (dc_point == RT_NULL) dc_point = &rtgui_empty_point;
|
||||
if (rtgui_dc_get_visible(dest) == RT_FALSE) return;
|
||||
|
||||
if ((dest->type == RTGUI_DC_HW) || (dest->type == RTGUI_DC_CLIENT))
|
||||
{
|
||||
rt_uint8_t *line_ptr, *pixels;
|
||||
rt_uint16_t rect_width, rect_height, index, pitch;
|
||||
rtgui_blit_line_func blit_line;
|
||||
|
||||
/* calculate correct width and height */
|
||||
if (rtgui_rect_width(*rect) > (dc->width - dc_point->x))
|
||||
rect_width = dc->width - dc_point->x;
|
||||
else
|
||||
rect_width = rtgui_rect_width(*rect);
|
||||
|
||||
if (rtgui_rect_height(*rect) > (dc->height - dc_point->y))
|
||||
rect_height = dc->height - dc_point->y;
|
||||
else
|
||||
rect_height = rtgui_rect_height(*rect);
|
||||
|
||||
/* prepare pixel line */
|
||||
pixels = dc->pixel + dc_point->y * dc->pitch + dc_point->x * sizeof(rtgui_color_t);
|
||||
|
||||
if (hw_driver->bits_per_pixel == sizeof(rtgui_color_t) * 8)
|
||||
{
|
||||
/* it's the same byte per pixel, draw it directly */
|
||||
for (index = rect->y1; index < rect->y1 + rect_height; index++)
|
||||
{
|
||||
dest->engine->blit_line(dest, rect->x1, rect->x1 + rect_width, index, pixels);
|
||||
pixels += dc->width * sizeof(rtgui_color_t);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* get blit line function */
|
||||
blit_line = rtgui_blit_line_get(hw_driver->bits_per_pixel / 8, 4);
|
||||
/* calculate pitch */
|
||||
pitch = rect_width * sizeof(rtgui_color_t);
|
||||
/* create line buffer */
|
||||
line_ptr = (rt_uint8_t *) rtgui_malloc(rect_width * hw_driver->bits_per_pixel / 8);
|
||||
|
||||
/* draw each line */
|
||||
for (index = rect->y1; index < rect->y1 + rect_height; index ++)
|
||||
{
|
||||
/* blit on line buffer */
|
||||
blit_line(line_ptr, (rt_uint8_t *)pixels, pitch);
|
||||
pixels += dc->width * sizeof(rtgui_color_t);
|
||||
|
||||
/* draw on hardware dc */
|
||||
dest->engine->blit_line(dest, rect->x1, rect->x1 + rect_width, index, line_ptr);
|
||||
}
|
||||
|
||||
/* release line buffer */
|
||||
rtgui_free(line_ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void rtgui_dc_buffer_blit_line(struct rtgui_dc *self, int x1, int x2, int y, rt_uint8_t *line_data)
|
||||
{
|
||||
rtgui_color_t *color_ptr;
|
||||
struct rtgui_dc_buffer *dc = (struct rtgui_dc_buffer *)self;
|
||||
|
||||
RT_ASSERT(dc != RT_NULL);
|
||||
RT_ASSERT(line_data != RT_NULL);
|
||||
|
||||
/* out of range */
|
||||
if ((x1 > dc->width) || (y > dc->height)) return;
|
||||
/* check range */
|
||||
if (x2 > dc->width) x2 = dc->width;
|
||||
|
||||
color_ptr = (rtgui_color_t *)(dc->pixel + y * dc->pitch + x1 * sizeof(rtgui_color_t));
|
||||
rt_memcpy(color_ptr, line_data, (x2 - x1) * sizeof(rtgui_color_t));
|
||||
}
|
||||
|
||||
static void rtgui_dc_buffer_set_gc(struct rtgui_dc *self, rtgui_gc_t *gc)
|
||||
{
|
||||
struct rtgui_dc_buffer *dc = (struct rtgui_dc_buffer *)self;
|
||||
|
||||
dc->gc = *gc;
|
||||
}
|
||||
|
||||
static rtgui_gc_t *rtgui_dc_buffer_get_gc(struct rtgui_dc *self)
|
||||
{
|
||||
struct rtgui_dc_buffer *dc = (struct rtgui_dc_buffer *)self;
|
||||
|
||||
return &dc->gc;
|
||||
}
|
||||
|
||||
static rt_bool_t rtgui_dc_buffer_get_visible(struct rtgui_dc *dc)
|
||||
{
|
||||
return RT_TRUE;
|
||||
}
|
||||
|
||||
static void rtgui_dc_buffer_get_rect(struct rtgui_dc *self, rtgui_rect_t *rect)
|
||||
{
|
||||
struct rtgui_dc_buffer *dc = (struct rtgui_dc_buffer *)self;
|
||||
|
||||
rect->x1 = rect->y1 = 0;
|
||||
|
||||
rect->x2 = dc->width;
|
||||
rect->y2 = dc->height;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,372 +0,0 @@
|
||||
/*
|
||||
* File : dc_hw.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rt-thread.org/license/LICENSE
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2009-10-16 Bernard first version
|
||||
*/
|
||||
#include <rtgui/dc.h>
|
||||
#include <rtgui/dc_hw.h>
|
||||
#include <rtgui/driver.h>
|
||||
#include <rtgui/rtgui_system.h>
|
||||
#include <rtgui/rtgui_app.h>
|
||||
#include <rtgui/rtgui_server.h>
|
||||
|
||||
#include <rtgui/widgets/container.h>
|
||||
#include <rtgui/widgets/window.h>
|
||||
#include <rtgui/widgets/title.h>
|
||||
|
||||
#define _int_swap(x, y) do {x ^= y; y ^= x; x ^= y;} while (0)
|
||||
|
||||
static void rtgui_dc_hw_draw_point(struct rtgui_dc *dc, int x, int y);
|
||||
static void rtgui_dc_hw_draw_color_point(struct rtgui_dc *dc, int x, int y, rtgui_color_t color);
|
||||
static void rtgui_dc_hw_draw_hline(struct rtgui_dc *dc, int x1, int x2, int y);
|
||||
static void rtgui_dc_hw_draw_vline(struct rtgui_dc *dc, int x, int y1, int y2);
|
||||
static void rtgui_dc_hw_fill_rect(struct rtgui_dc *dc, rtgui_rect_t *rect);
|
||||
static void rtgui_dc_hw_blit_line(struct rtgui_dc *self, int x1, int x2, int y, rt_uint8_t *line_data);
|
||||
static void rtgui_dc_hw_blit(struct rtgui_dc *dc, struct rtgui_point *dc_point, struct rtgui_dc *dest, rtgui_rect_t *rect);
|
||||
static void rtgui_dc_hw_set_gc(struct rtgui_dc *dc, rtgui_gc_t *gc);
|
||||
static rtgui_gc_t *rtgui_dc_hw_get_gc(struct rtgui_dc *dc);
|
||||
static rt_bool_t rtgui_dc_hw_fini(struct rtgui_dc *dc);
|
||||
static rt_bool_t rtgui_dc_hw_get_visible(struct rtgui_dc *dc);
|
||||
static void rtgui_dc_hw_get_rect(struct rtgui_dc *dc, rtgui_rect_t *rect);
|
||||
|
||||
const struct rtgui_dc_engine dc_hw_engine =
|
||||
{
|
||||
rtgui_dc_hw_draw_point,
|
||||
rtgui_dc_hw_draw_color_point,
|
||||
rtgui_dc_hw_draw_vline,
|
||||
rtgui_dc_hw_draw_hline,
|
||||
rtgui_dc_hw_fill_rect,
|
||||
rtgui_dc_hw_blit_line,
|
||||
rtgui_dc_hw_blit,
|
||||
|
||||
rtgui_dc_hw_set_gc,
|
||||
rtgui_dc_hw_get_gc,
|
||||
|
||||
rtgui_dc_hw_get_visible,
|
||||
rtgui_dc_hw_get_rect,
|
||||
|
||||
rtgui_dc_hw_fini,
|
||||
};
|
||||
|
||||
extern struct rt_mutex cursor_mutex;
|
||||
extern void rtgui_mouse_show_cursor(void);
|
||||
extern void rtgui_mouse_hide_cursor(void);
|
||||
struct rtgui_dc *rtgui_dc_hw_create(rtgui_widget_t *owner)
|
||||
{
|
||||
struct rtgui_dc_hw *dc;
|
||||
rtgui_widget_t *widget;
|
||||
|
||||
/* adjudge owner */
|
||||
if (owner == RT_NULL || owner->toplevel == RT_NULL) return RT_NULL;
|
||||
if (!RTGUI_IS_WIN(owner->toplevel)) return RT_NULL;
|
||||
|
||||
/* set init visible as true */
|
||||
RTGUI_WIDGET_DC_SET_VISIBLE(owner);
|
||||
|
||||
/* check widget visible */
|
||||
widget = owner;
|
||||
while (widget != RT_NULL)
|
||||
{
|
||||
if (RTGUI_WIDGET_IS_HIDE(widget))
|
||||
{
|
||||
RTGUI_WIDGET_DC_SET_UNVISIBLE(owner);
|
||||
return RT_NULL;
|
||||
}
|
||||
|
||||
widget = widget->parent;
|
||||
}
|
||||
|
||||
if (!RTGUI_WIDGET_IS_DC_VISIBLE(owner)) return RT_NULL;
|
||||
|
||||
/* create DC */
|
||||
dc = (struct rtgui_dc_hw *) rtgui_malloc(sizeof(struct rtgui_dc_hw));
|
||||
dc->parent.type = RTGUI_DC_HW;
|
||||
dc->parent.engine = &dc_hw_engine;
|
||||
dc->owner = owner;
|
||||
dc->hw_driver = rtgui_graphic_driver_get_default();
|
||||
|
||||
if (RTGUI_IS_WINTITLE(owner->toplevel))
|
||||
{
|
||||
struct rtgui_win *top = RTGUI_WIN(owner->toplevel);
|
||||
top->drawing ++;
|
||||
|
||||
if (top->drawing == 1)
|
||||
{
|
||||
#ifdef RTGUI_USING_MOUSE_CURSOR
|
||||
#ifdef _WIN32_NATIVE
|
||||
rt_mutex_take(&cursor_mutex, RT_WAITING_FOREVER);
|
||||
rt_kprintf("hide cursor\n");
|
||||
rtgui_mouse_hide_cursor();
|
||||
#else
|
||||
/* hide cursor */
|
||||
rtgui_mouse_hide_cursor();
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else if (RTGUI_IS_APP(owner->toplevel) ||
|
||||
RTGUI_IS_WIN(owner->toplevel))
|
||||
{
|
||||
struct rtgui_win *top = RTGUI_WIN(owner->toplevel);
|
||||
top->drawing ++;
|
||||
|
||||
if (top->drawing == 1)
|
||||
{
|
||||
#ifdef _WIN32_NATIVE
|
||||
#ifdef RTGUI_USING_MOUSE_CURSOR
|
||||
rt_mutex_take(&cursor_mutex, RT_WAITING_FOREVER);
|
||||
rt_kprintf("hide cursor\n");
|
||||
rtgui_mouse_hide_cursor();
|
||||
#endif
|
||||
#else
|
||||
/* send draw begin to server */
|
||||
struct rtgui_event_update_begin eupdate;
|
||||
RTGUI_EVENT_UPDATE_BEGIN_INIT(&(eupdate));
|
||||
eupdate.rect = RTGUI_WIDGET(top)->extent;
|
||||
|
||||
rtgui_server_post_event((struct rtgui_event *)&eupdate, sizeof(eupdate));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
return &(dc->parent);
|
||||
}
|
||||
|
||||
static rt_bool_t rtgui_dc_hw_fini(struct rtgui_dc *dc)
|
||||
{
|
||||
rtgui_widget_t *owner;
|
||||
struct rtgui_dc_hw *self;
|
||||
|
||||
if (dc == RT_NULL || dc->type != RTGUI_DC_HW) return RT_FALSE;
|
||||
|
||||
self = (struct rtgui_dc_hw *)dc;
|
||||
/* get owner */
|
||||
owner = self->owner;
|
||||
|
||||
if (RTGUI_IS_WINTITLE(owner->toplevel))
|
||||
{
|
||||
/* update title extent */
|
||||
struct rtgui_win *top = RTGUI_WIN(owner->toplevel);
|
||||
|
||||
top->drawing --;
|
||||
if ((top->drawing == 0) && RTGUI_WIDGET_IS_DC_VISIBLE(owner))
|
||||
{
|
||||
#ifdef _WIN32_NATIVE
|
||||
#ifdef RTGUI_USING_MOUSE_CURSOR
|
||||
rt_mutex_release(&cursor_mutex);
|
||||
/* show cursor */
|
||||
rtgui_mouse_show_cursor();
|
||||
rt_kprintf("show cursor\n");
|
||||
#endif
|
||||
/* update screen */
|
||||
rtgui_graphic_driver_screen_update(self->hw_driver, &(owner->extent));
|
||||
#else
|
||||
#ifdef RTGUI_USING_MOUSE_CURSOR
|
||||
/* show cursor */
|
||||
rtgui_mouse_show_cursor();
|
||||
#endif
|
||||
|
||||
/* update screen */
|
||||
rtgui_graphic_driver_screen_update(self->hw_driver, &(owner->extent));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else if (RTGUI_IS_APP(owner->toplevel) ||
|
||||
RTGUI_IS_WIN(owner->toplevel))
|
||||
{
|
||||
struct rtgui_win *top = RTGUI_WIN(owner->toplevel);
|
||||
top->drawing --;
|
||||
|
||||
if ((top->drawing == 0) && RTGUI_WIDGET_IS_DC_VISIBLE(owner))
|
||||
{
|
||||
#ifdef _WIN32_NATIVE
|
||||
#ifdef RTGUI_USING_MOUSE_CURSOR
|
||||
rt_mutex_release(&cursor_mutex);
|
||||
/* show cursor */
|
||||
rtgui_mouse_show_cursor();
|
||||
rt_kprintf("show cursor\n");
|
||||
#endif
|
||||
/* update screen */
|
||||
rtgui_graphic_driver_screen_update(self->hw_driver, &(owner->extent));
|
||||
#else
|
||||
/* send to server to end drawing */
|
||||
struct rtgui_event_update_end eupdate;
|
||||
RTGUI_EVENT_UPDATE_END_INIT(&(eupdate));
|
||||
eupdate.rect = owner->extent;
|
||||
|
||||
rtgui_server_post_event((struct rtgui_event *)&eupdate, sizeof(eupdate));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/* release hardware dc */
|
||||
rtgui_free(self);
|
||||
|
||||
return RT_TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
* draw a logic point on device
|
||||
*/
|
||||
static void rtgui_dc_hw_draw_point(struct rtgui_dc *self, int x, int y)
|
||||
{
|
||||
struct rtgui_dc_hw *dc;
|
||||
|
||||
RT_ASSERT(self != RT_NULL);
|
||||
dc = (struct rtgui_dc_hw *) self;
|
||||
|
||||
x = x + dc->owner->extent.x1;
|
||||
y = y + dc->owner->extent.y1;
|
||||
|
||||
/* draw this point */
|
||||
dc->hw_driver->ops->set_pixel(&(dc->owner->gc.foreground), x, y);
|
||||
}
|
||||
|
||||
static void rtgui_dc_hw_draw_color_point(struct rtgui_dc *self, int x, int y, rtgui_color_t color)
|
||||
{
|
||||
struct rtgui_dc_hw *dc;
|
||||
|
||||
RT_ASSERT(self != RT_NULL);
|
||||
dc = (struct rtgui_dc_hw *) self;
|
||||
|
||||
x = x + dc->owner->extent.x1;
|
||||
y = y + dc->owner->extent.y1;
|
||||
|
||||
/* draw this point */
|
||||
dc->hw_driver->ops->set_pixel(&color, x, y);
|
||||
}
|
||||
|
||||
/*
|
||||
* draw a logic vertical line on device
|
||||
*/
|
||||
static void rtgui_dc_hw_draw_vline(struct rtgui_dc *self, int x, int y1, int y2)
|
||||
{
|
||||
struct rtgui_dc_hw *dc;
|
||||
|
||||
RT_ASSERT(self != RT_NULL);
|
||||
dc = (struct rtgui_dc_hw *) self;
|
||||
|
||||
x = x + dc->owner->extent.x1;
|
||||
y1 = y1 + dc->owner->extent.y1;
|
||||
y2 = y2 + dc->owner->extent.y1;
|
||||
if (y1 > y2) _int_swap(y1, y2);
|
||||
|
||||
/* draw vline */
|
||||
dc->hw_driver->ops->draw_vline(&(dc->owner->gc.foreground), x, y1, y2);
|
||||
}
|
||||
|
||||
/*
|
||||
* draw a logic horizontal line on device
|
||||
*/
|
||||
static void rtgui_dc_hw_draw_hline(struct rtgui_dc *self, int x1, int x2, int y)
|
||||
{
|
||||
struct rtgui_dc_hw *dc;
|
||||
|
||||
RT_ASSERT(self != RT_NULL);
|
||||
dc = (struct rtgui_dc_hw *) self;
|
||||
|
||||
/* convert logic to device */
|
||||
x1 = x1 + dc->owner->extent.x1;
|
||||
x2 = x2 + dc->owner->extent.x1;
|
||||
if (x1 > x2) _int_swap(x1, x2);
|
||||
y = y + dc->owner->extent.y1;
|
||||
|
||||
/* draw hline */
|
||||
dc->hw_driver->ops->draw_hline(&(dc->owner->gc.foreground), x1, x2, y);
|
||||
}
|
||||
|
||||
static void rtgui_dc_hw_fill_rect(struct rtgui_dc *self, struct rtgui_rect *rect)
|
||||
{
|
||||
rtgui_color_t color;
|
||||
register rt_base_t index, x1, x2;
|
||||
struct rtgui_dc_hw *dc;
|
||||
|
||||
RT_ASSERT(self != RT_NULL);
|
||||
dc = (struct rtgui_dc_hw *) self;
|
||||
|
||||
/* get background color */
|
||||
color = dc->owner->gc.background;
|
||||
/* convert logic to device */
|
||||
x1 = rect->x1 + dc->owner->extent.x1;
|
||||
x2 = rect->x2 + dc->owner->extent.x1;
|
||||
|
||||
/* fill rect */
|
||||
for (index = dc->owner->extent.y1 + rect->y1; index < dc->owner->extent.y1 + rect->y2; index ++)
|
||||
{
|
||||
dc->hw_driver->ops->draw_hline(&color, x1, x2, index);
|
||||
}
|
||||
}
|
||||
|
||||
static void rtgui_dc_hw_blit_line(struct rtgui_dc *self, int x1, int x2, int y, rt_uint8_t *line_data)
|
||||
{
|
||||
struct rtgui_dc_hw *dc;
|
||||
|
||||
RT_ASSERT(self != RT_NULL);
|
||||
dc = (struct rtgui_dc_hw *) self;
|
||||
|
||||
/* convert logic to device */
|
||||
x1 = x1 + dc->owner->extent.x1;
|
||||
x2 = x2 + dc->owner->extent.x1;
|
||||
if (x1 > x2) _int_swap(x1, x2);
|
||||
y = y + dc->owner->extent.y1;
|
||||
|
||||
dc->hw_driver->ops->draw_raw_hline(line_data, x1, x2, y);
|
||||
}
|
||||
|
||||
static void rtgui_dc_hw_blit(struct rtgui_dc *dc, struct rtgui_point *dc_point, struct rtgui_dc *dest, rtgui_rect_t *rect)
|
||||
{
|
||||
/* not blit in hardware dc */
|
||||
return ;
|
||||
}
|
||||
|
||||
static void rtgui_dc_hw_set_gc(struct rtgui_dc *self, rtgui_gc_t *gc)
|
||||
{
|
||||
struct rtgui_dc_hw *dc;
|
||||
|
||||
RT_ASSERT(self != RT_NULL);
|
||||
dc = (struct rtgui_dc_hw *) self;
|
||||
|
||||
/* set gc */
|
||||
dc->owner->gc = *gc;
|
||||
}
|
||||
|
||||
static rtgui_gc_t *rtgui_dc_hw_get_gc(struct rtgui_dc *self)
|
||||
{
|
||||
struct rtgui_dc_hw *dc;
|
||||
|
||||
RT_ASSERT(self != RT_NULL);
|
||||
dc = (struct rtgui_dc_hw *) self;
|
||||
|
||||
return &(dc->owner->gc);
|
||||
}
|
||||
|
||||
static rt_bool_t rtgui_dc_hw_get_visible(struct rtgui_dc *self)
|
||||
{
|
||||
struct rtgui_dc_hw *dc;
|
||||
|
||||
RT_ASSERT(self != RT_NULL);
|
||||
dc = (struct rtgui_dc_hw *) self;
|
||||
|
||||
if (!RTGUI_WIDGET_IS_DC_VISIBLE(dc->owner)) return RT_FALSE;
|
||||
|
||||
return RT_TRUE;
|
||||
}
|
||||
|
||||
static void rtgui_dc_hw_get_rect(struct rtgui_dc *self, rtgui_rect_t *rect)
|
||||
{
|
||||
struct rtgui_dc_hw *dc;
|
||||
|
||||
RT_ASSERT(self != RT_NULL);
|
||||
dc = (struct rtgui_dc_hw *) self;
|
||||
|
||||
/* get owner */
|
||||
rtgui_widget_get_rect(dc->owner, rect);
|
||||
}
|
||||
@@ -1,364 +0,0 @@
|
||||
/*
|
||||
* File : filerw.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rt-thread.org/license/LICENSE
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2009-10-16 Bernard first version
|
||||
*/
|
||||
#include <rtgui/rtgui_system.h>
|
||||
#include <rtgui/filerw.h>
|
||||
|
||||
#ifdef RTGUI_USING_DFS_FILERW
|
||||
|
||||
/* standard file read/write */
|
||||
struct rtgui_filerw_stdio
|
||||
{
|
||||
/* inherit from rtgui_filerw */
|
||||
struct rtgui_filerw parent;
|
||||
|
||||
int fd;
|
||||
rt_bool_t eof;
|
||||
};
|
||||
|
||||
static int stdio_seek(struct rtgui_filerw *context, rt_off_t offset, int whence)
|
||||
{
|
||||
struct rtgui_filerw_stdio *stdio_filerw = (struct rtgui_filerw_stdio *)context;
|
||||
int stdio_whence[3] = {SEEK_SET, SEEK_CUR, SEEK_END};
|
||||
|
||||
if (whence < RTGUI_FILE_SEEK_SET || whence > RTGUI_FILE_SEEK_END)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return lseek(stdio_filerw->fd, offset, stdio_whence[whence]);
|
||||
}
|
||||
|
||||
static int stdio_read(struct rtgui_filerw *context, void *ptr, rt_size_t size, rt_size_t maxnum)
|
||||
{
|
||||
int result;
|
||||
|
||||
struct rtgui_filerw_stdio *stdio_filerw = (struct rtgui_filerw_stdio *)context;
|
||||
|
||||
/* end of file */
|
||||
if (stdio_filerw->eof == RT_TRUE) return -1;
|
||||
|
||||
result = read(stdio_filerw->fd, ptr, size * maxnum);
|
||||
if (result == 0) stdio_filerw->eof = RT_TRUE;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static int stdio_write(struct rtgui_filerw *context, const void *ptr, rt_size_t size, rt_size_t num)
|
||||
{
|
||||
struct rtgui_filerw_stdio *stdio_filerw = (struct rtgui_filerw_stdio *)context;
|
||||
|
||||
return write(stdio_filerw->fd, (char *)ptr, size * num);
|
||||
}
|
||||
|
||||
static int stdio_tell(struct rtgui_filerw *context)
|
||||
{
|
||||
struct rtgui_filerw_stdio *stdio_filerw = (struct rtgui_filerw_stdio *)context;
|
||||
|
||||
return lseek(stdio_filerw->fd, 0, SEEK_CUR);
|
||||
}
|
||||
|
||||
static int stdio_eof(struct rtgui_filerw *context)
|
||||
{
|
||||
int result;
|
||||
struct rtgui_filerw_stdio *stdio_filerw = (struct rtgui_filerw_stdio *)context;
|
||||
|
||||
if (stdio_filerw->eof == RT_TRUE) result = 1;
|
||||
else result = -1;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static int stdio_close(struct rtgui_filerw *context)
|
||||
{
|
||||
struct rtgui_filerw_stdio *stdio_filerw = (struct rtgui_filerw_stdio *)context;
|
||||
|
||||
if (stdio_filerw)
|
||||
{
|
||||
close(stdio_filerw->fd);
|
||||
rtgui_free(stdio_filerw);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* memory file read/write */
|
||||
struct rtgui_filerw_mem
|
||||
{
|
||||
/* inherit from rtgui_filerw */
|
||||
struct rtgui_filerw parent;
|
||||
|
||||
const rt_uint8_t *mem_base, *mem_position, *mem_end;
|
||||
};
|
||||
|
||||
static int mem_seek(struct rtgui_filerw *context, rt_off_t offset, int whence)
|
||||
{
|
||||
const rt_uint8_t *newpos;
|
||||
struct rtgui_filerw_mem *mem = (struct rtgui_filerw_mem *)context;
|
||||
|
||||
RT_ASSERT(mem != RT_NULL);
|
||||
|
||||
switch (whence)
|
||||
{
|
||||
case RTGUI_FILE_SEEK_SET:
|
||||
newpos = mem->mem_base + offset;
|
||||
break;
|
||||
|
||||
case RTGUI_FILE_SEEK_CUR:
|
||||
newpos = mem->mem_position + offset;
|
||||
break;
|
||||
|
||||
case RTGUI_FILE_SEEK_END:
|
||||
newpos = mem->mem_end + offset;
|
||||
break;
|
||||
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (newpos < mem->mem_base)
|
||||
newpos = mem->mem_base;
|
||||
|
||||
if (newpos > mem->mem_end)
|
||||
newpos = mem->mem_end;
|
||||
|
||||
mem->mem_position = newpos;
|
||||
return mem->mem_position - mem->mem_base;
|
||||
}
|
||||
|
||||
static int mem_read(struct rtgui_filerw *context, void *ptr, rt_size_t size, rt_size_t maxnum)
|
||||
{
|
||||
int total_bytes;
|
||||
int mem_available;
|
||||
struct rtgui_filerw_mem *mem = (struct rtgui_filerw_mem *)context;
|
||||
|
||||
total_bytes = (maxnum * size);
|
||||
if ((maxnum <= 0) || (size <= 0) || ((total_bytes / maxnum) != size))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
mem_available = mem->mem_end - mem->mem_position;
|
||||
if (total_bytes > mem_available)
|
||||
total_bytes = mem_available;
|
||||
|
||||
rt_memcpy(ptr, mem->mem_position, total_bytes);
|
||||
mem->mem_position += total_bytes;
|
||||
|
||||
return (total_bytes / size);
|
||||
}
|
||||
|
||||
static int mem_write(struct rtgui_filerw *context, const void *ptr, rt_size_t size, rt_size_t num)
|
||||
{
|
||||
return 0; /* not support memory write */
|
||||
}
|
||||
|
||||
static int mem_tell(struct rtgui_filerw *context)
|
||||
{
|
||||
struct rtgui_filerw_mem *mem = (struct rtgui_filerw_mem *)context;
|
||||
|
||||
return mem->mem_position - mem->mem_base;
|
||||
}
|
||||
|
||||
static int mem_eof(struct rtgui_filerw *context)
|
||||
{
|
||||
struct rtgui_filerw_mem *mem = (struct rtgui_filerw_mem *)context;
|
||||
|
||||
return mem->mem_position >= mem->mem_end;
|
||||
}
|
||||
|
||||
static int mem_close(struct rtgui_filerw *context)
|
||||
{
|
||||
struct rtgui_filerw_mem *mem = (struct rtgui_filerw_mem *)context;
|
||||
|
||||
if (mem != RT_NULL)
|
||||
{
|
||||
rtgui_free(mem);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
const rt_uint8_t *rtgui_filerw_mem_getdata(struct rtgui_filerw *context)
|
||||
{
|
||||
struct rtgui_filerw_mem *mem = (struct rtgui_filerw_mem *)context;
|
||||
|
||||
/* check whether it's a memory filerw */
|
||||
if (mem->parent.read != mem_read) return RT_NULL;
|
||||
|
||||
return mem->mem_base;
|
||||
}
|
||||
|
||||
/* file read/write public interface */
|
||||
#ifdef RTGUI_USING_DFS_FILERW
|
||||
static int parse_mode(const char *mode)
|
||||
{
|
||||
int f = 0;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
switch (*mode)
|
||||
{
|
||||
case 0:
|
||||
return f;
|
||||
case 'b':
|
||||
f |= O_BINARY;
|
||||
break;
|
||||
case 'r':
|
||||
f = O_RDONLY;
|
||||
break;
|
||||
case 'w':
|
||||
f = O_WRONLY | O_CREAT | O_TRUNC;
|
||||
break;
|
||||
case 'a':
|
||||
f = O_WRONLY | O_CREAT | O_APPEND;
|
||||
break;
|
||||
case '+':
|
||||
f = (f & (~O_WRONLY)) | O_RDWR;
|
||||
break;
|
||||
}
|
||||
|
||||
++mode;
|
||||
}
|
||||
}
|
||||
|
||||
struct rtgui_filerw *rtgui_filerw_create_file(const char *filename, const char *mode)
|
||||
{
|
||||
int fd;
|
||||
struct rtgui_filerw_stdio *rw;
|
||||
|
||||
RT_ASSERT(filename != RT_NULL);
|
||||
|
||||
rw = RT_NULL;
|
||||
#ifdef _WIN32_NATIVE
|
||||
fd = _open(filename, parse_mode(mode), 0);
|
||||
#else
|
||||
fd = open(filename, parse_mode(mode), 0);
|
||||
#endif
|
||||
|
||||
if (fd >= 0)
|
||||
{
|
||||
rw = (struct rtgui_filerw_stdio *) rtgui_malloc(sizeof(struct rtgui_filerw_stdio));
|
||||
if (rw != RT_NULL)
|
||||
{
|
||||
rw->parent.seek = stdio_seek;
|
||||
rw->parent.read = stdio_read;
|
||||
rw->parent.write = stdio_write;
|
||||
rw->parent.tell = stdio_tell;
|
||||
rw->parent.close = stdio_close;
|
||||
rw->parent.eof = stdio_eof;
|
||||
|
||||
rw->fd = fd;
|
||||
rw->eof = RT_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return &(rw->parent);
|
||||
}
|
||||
|
||||
int rtgui_filerw_unlink(const char *filename)
|
||||
{
|
||||
#ifdef _WIN32_NATIVE
|
||||
return _unlink(filename);
|
||||
#else
|
||||
#ifndef RT_USING_DFS
|
||||
/* no unlink function */
|
||||
return -1;
|
||||
#else
|
||||
return unlink(filename);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
struct rtgui_filerw *rtgui_filerw_create_mem(const rt_uint8_t *mem, rt_size_t size)
|
||||
{
|
||||
struct rtgui_filerw_mem *rw;
|
||||
RT_ASSERT(mem != RT_NULL);
|
||||
|
||||
rw = (struct rtgui_filerw_mem *) rtgui_malloc(sizeof(struct rtgui_filerw_mem));
|
||||
if (rw != RT_NULL)
|
||||
{
|
||||
rw->parent.seek = mem_seek;
|
||||
rw->parent.read = mem_read;
|
||||
rw->parent.write = mem_write;
|
||||
rw->parent.tell = mem_tell;
|
||||
rw->parent.eof = mem_eof;
|
||||
rw->parent.close = mem_close;
|
||||
|
||||
rw->mem_base = mem;
|
||||
rw->mem_position = mem;
|
||||
rw->mem_end = mem + size;
|
||||
}
|
||||
|
||||
return &(rw->parent);
|
||||
}
|
||||
|
||||
int rtgui_filerw_seek(struct rtgui_filerw *context, rt_off_t offset, int whence)
|
||||
{
|
||||
RT_ASSERT(context != RT_NULL);
|
||||
|
||||
return context->seek(context, offset, whence);
|
||||
}
|
||||
|
||||
int rtgui_filerw_read(struct rtgui_filerw *context, void *buffer, rt_size_t size, rt_size_t count)
|
||||
{
|
||||
RT_ASSERT(context != RT_NULL);
|
||||
|
||||
return context->read(context, buffer, size, count);
|
||||
}
|
||||
|
||||
int rtgui_filerw_write(struct rtgui_filerw *context, const void *buffer, rt_size_t size, rt_size_t count)
|
||||
{
|
||||
RT_ASSERT(context != RT_NULL);
|
||||
|
||||
return context->write(context, buffer, size, count);
|
||||
}
|
||||
|
||||
int rtgui_filerw_eof(struct rtgui_filerw *context)
|
||||
{
|
||||
RT_ASSERT(context != RT_NULL);
|
||||
|
||||
return context->eof(context);
|
||||
}
|
||||
|
||||
int rtgui_filerw_tell(struct rtgui_filerw *context)
|
||||
{
|
||||
RT_ASSERT(context != RT_NULL);
|
||||
|
||||
return context->tell(context);
|
||||
}
|
||||
|
||||
int rtgui_filerw_close(struct rtgui_filerw *context)
|
||||
{
|
||||
int result;
|
||||
|
||||
RT_ASSERT(context != RT_NULL);
|
||||
|
||||
/* close context */
|
||||
result = context->close(context);
|
||||
if (result != 0)
|
||||
{
|
||||
/* close file failed */
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,161 +0,0 @@
|
||||
/*
|
||||
* File : font.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rt-thread.org/license/LICENSE
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2009-10-16 Bernard first version
|
||||
*/
|
||||
#include <rtgui/font.h>
|
||||
#include <rtgui/dc.h>
|
||||
|
||||
static rtgui_list_t _rtgui_font_list;
|
||||
static struct rtgui_font *rtgui_default_font;
|
||||
|
||||
extern struct rtgui_font rtgui_font_asc16;
|
||||
extern struct rtgui_font rtgui_font_arial16;
|
||||
extern struct rtgui_font rtgui_font_asc12;
|
||||
extern struct rtgui_font rtgui_font_arial12;
|
||||
#ifdef RTGUI_USING_FONTHZ
|
||||
extern struct rtgui_font rtgui_font_hz16;
|
||||
extern struct rtgui_font rtgui_font_hz12;
|
||||
#endif
|
||||
|
||||
void rtgui_font_system_init()
|
||||
{
|
||||
rtgui_list_init(&(_rtgui_font_list));
|
||||
|
||||
/* set default font to NULL */
|
||||
rtgui_default_font = RT_NULL;
|
||||
|
||||
#ifdef RTGUI_USING_FONT16
|
||||
rtgui_font_system_add_font(&rtgui_font_asc16);
|
||||
#ifdef RTGUI_USING_FONTHZ
|
||||
rtgui_font_system_add_font(&rtgui_font_hz16);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef RTGUI_USING_FONT12
|
||||
rtgui_font_system_add_font(&rtgui_font_asc12);
|
||||
#ifdef RTGUI_USING_FONTHZ
|
||||
rtgui_font_system_add_font(&rtgui_font_hz12);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef RTGUI_USING_FONT12
|
||||
if (rtgui_default_font == RT_NULL)
|
||||
rtgui_font_set_defaut(&rtgui_font_asc12);
|
||||
#endif
|
||||
#ifdef RTGUI_USING_FONT16
|
||||
if (rtgui_default_font == RT_NULL)
|
||||
rtgui_font_set_defaut(&rtgui_font_asc16);
|
||||
#endif
|
||||
}
|
||||
|
||||
void rtgui_font_system_add_font(struct rtgui_font *font)
|
||||
{
|
||||
rtgui_list_init(&(font->list));
|
||||
rtgui_list_append(&_rtgui_font_list, &(font->list));
|
||||
|
||||
/* init font */
|
||||
if (font->engine->font_init != RT_NULL)
|
||||
font->engine->font_init(font);
|
||||
|
||||
/* first refer, load it */
|
||||
if (font->engine->font_load != RT_NULL)
|
||||
font->engine->font_load(font);
|
||||
}
|
||||
RTM_EXPORT(rtgui_font_system_add_font);
|
||||
|
||||
void rtgui_font_system_remove_font(struct rtgui_font *font)
|
||||
{
|
||||
rtgui_list_remove(&_rtgui_font_list, &(font->list));
|
||||
}
|
||||
RTM_EXPORT(rtgui_font_system_remove_font);
|
||||
|
||||
struct rtgui_font *rtgui_font_default()
|
||||
{
|
||||
return rtgui_default_font;
|
||||
}
|
||||
|
||||
void rtgui_font_set_defaut(struct rtgui_font *font)
|
||||
{
|
||||
rtgui_default_font = font;
|
||||
}
|
||||
|
||||
struct rtgui_font *rtgui_font_refer(const char *family, rt_uint16_t height)
|
||||
{
|
||||
/* search font */
|
||||
struct rtgui_list_node *node;
|
||||
struct rtgui_font *font;
|
||||
|
||||
rtgui_list_foreach(node, &_rtgui_font_list)
|
||||
{
|
||||
font = rtgui_list_entry(node, struct rtgui_font, list);
|
||||
if ((rt_strncmp(font->family, family, RTGUI_NAME_MAX) == 0) &&
|
||||
font->height == height)
|
||||
{
|
||||
font->refer_count ++;
|
||||
return font;
|
||||
}
|
||||
}
|
||||
|
||||
return RT_NULL;
|
||||
}
|
||||
RTM_EXPORT(rtgui_font_refer);
|
||||
|
||||
void rtgui_font_derefer(struct rtgui_font *font)
|
||||
{
|
||||
RT_ASSERT(font != RT_NULL);
|
||||
|
||||
font->refer_count --;
|
||||
|
||||
/* no refer, remove font */
|
||||
if (font->refer_count == 0)
|
||||
{
|
||||
rtgui_font_system_remove_font(font);
|
||||
}
|
||||
}
|
||||
|
||||
/* draw a text */
|
||||
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);
|
||||
|
||||
if (font->engine != RT_NULL &&
|
||||
font->engine->font_draw_text != RT_NULL)
|
||||
{
|
||||
font->engine->font_draw_text(font, dc, text, len, rect);
|
||||
}
|
||||
}
|
||||
|
||||
int rtgui_font_get_string_width(struct rtgui_font *font, const char *text)
|
||||
{
|
||||
rtgui_rect_t rect;
|
||||
|
||||
/* get metrics */
|
||||
rtgui_font_get_metrics(font, text, &rect);
|
||||
|
||||
return rect.x2 - rect.x1;
|
||||
}
|
||||
|
||||
void rtgui_font_get_metrics(struct rtgui_font *font, const char *text, rtgui_rect_t *rect)
|
||||
{
|
||||
RT_ASSERT(font != RT_NULL);
|
||||
|
||||
if (font->engine != RT_NULL &&
|
||||
font->engine->font_get_metrics != RT_NULL)
|
||||
{
|
||||
font->engine->font_get_metrics(font, text, rect);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* no font engine found, set rect to zero */
|
||||
rt_memset(rect, 0, sizeof(rtgui_rect_t));
|
||||
}
|
||||
}
|
||||
@@ -1,185 +0,0 @@
|
||||
/*
|
||||
* File : font.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2010, RT-Thread Development Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rt-thread.org/license/LICENSE
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2010-09-15 Bernard first version
|
||||
*/
|
||||
#include <rtgui/font.h>
|
||||
#include <rtgui/dc.h>
|
||||
|
||||
/* bitmap font private data */
|
||||
|
||||
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 char *text, rtgui_rect_t *rect);
|
||||
const struct rtgui_font_engine bmp_font_engine =
|
||||
{
|
||||
RT_NULL,
|
||||
RT_NULL,
|
||||
rtgui_bitmap_font_draw_text,
|
||||
rtgui_bitmap_font_get_metrics
|
||||
};
|
||||
|
||||
void rtgui_bitmap_font_draw_char(struct rtgui_font_bitmap *font, struct rtgui_dc *dc, const char ch,
|
||||
rtgui_rect_t *rect)
|
||||
{
|
||||
rtgui_color_t bc;
|
||||
const rt_uint8_t *font_ptr;
|
||||
rt_uint16_t x, y, w, h, style;
|
||||
register rt_base_t i, j, /*k,*/ word_bytes;
|
||||
|
||||
/* check first and last char */
|
||||
if (ch < font->first_char || ch > font->last_char) return;
|
||||
|
||||
/* get text style */
|
||||
style = rtgui_dc_get_gc(dc)->textstyle;
|
||||
bc = rtgui_dc_get_gc(dc)->background;
|
||||
|
||||
x = rect->x1;
|
||||
y = rect->y1;
|
||||
/* get width */
|
||||
if (font->char_width == RT_NULL)
|
||||
{
|
||||
word_bytes = (((font->width - 1) / 8) + 1);
|
||||
font_ptr = font->bmp + (ch - font->first_char) * word_bytes * font->height;
|
||||
}
|
||||
else
|
||||
{
|
||||
word_bytes = ((font->char_width[ch - font->first_char] - 1) / 8) + 1;
|
||||
font_ptr = font->bmp + font->offset[ch - font->first_char];
|
||||
}
|
||||
w = (font->width + x > rect->x2) ? rect->x2 - rect->x1 : font->width;
|
||||
h = (font->height + y > rect->y2) ? rect->y2 - rect->y1 : font->height;
|
||||
|
||||
for (i = 0; i < h; i++)
|
||||
{
|
||||
rt_uint8_t chr = 0;
|
||||
const rt_uint8_t *ptr = font_ptr + i * word_bytes;
|
||||
for (j = 0; j < w; j++)
|
||||
{
|
||||
if (j % 8 == 0)
|
||||
chr = *ptr++;
|
||||
if (chr & 0x80)
|
||||
rtgui_dc_draw_point(dc, j + x, i + y);
|
||||
else if (style & RTGUI_TEXTSTYLE_DRAW_BACKGROUND)
|
||||
rtgui_dc_draw_color_point(dc, j + x, i + y, bc);
|
||||
chr <<= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
rt_uint32_t length;
|
||||
struct rtgui_font_bitmap *bmp_font = (struct rtgui_font_bitmap *)(font->data);
|
||||
#ifdef RTGUI_USING_FONTHZ
|
||||
struct rtgui_font *hz_font;
|
||||
|
||||
RT_ASSERT(bmp_font != RT_NULL);
|
||||
|
||||
if (rect->y1 > rect->y2) return;
|
||||
|
||||
hz_font = rtgui_font_refer("hz", font->height);
|
||||
while ((rect->x1 < rect->x2) && len)
|
||||
{
|
||||
length = 0;
|
||||
while ((rt_uint8_t) * (text + length) >= 0x80) length ++; /* it's not a ascii character */
|
||||
if (length > 0)
|
||||
{
|
||||
if (hz_font != RT_NULL) rtgui_font_draw(hz_font, dc, text, length, rect);
|
||||
text += length;
|
||||
len -= length;
|
||||
}
|
||||
|
||||
length = 0;
|
||||
while (((rt_uint8_t) * (text + length) < 0x80) && *(text + length)) length ++;
|
||||
if (length > 0)
|
||||
{
|
||||
len -= length;
|
||||
while (length-- && rect->x1 < rect->x2)
|
||||
{
|
||||
rtgui_bitmap_font_draw_char(bmp_font, dc, *text, rect);
|
||||
|
||||
/* move x to next character */
|
||||
if (bmp_font->char_width == RT_NULL)
|
||||
rect->x1 += bmp_font->width;
|
||||
else
|
||||
rect->x1 += bmp_font->char_width[*text - bmp_font->first_char];
|
||||
text ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (hz_font != RT_NULL) rtgui_font_derefer(hz_font);
|
||||
|
||||
#else
|
||||
if (rect->y1 > rect->y2) return;
|
||||
|
||||
while ((rect->x1 < rect->x2) && len)
|
||||
{
|
||||
length = 0;
|
||||
while (((rt_uint8_t) * (text + length) < 0x80) && *(text + length)) length ++;
|
||||
if (length > 0)
|
||||
{
|
||||
len -= length;
|
||||
while (length-- && rect->x1 < rect->x2)
|
||||
{
|
||||
rtgui_bitmap_font_draw_char(bmp_font, dc, *text, rect);
|
||||
|
||||
/* move x to next character */
|
||||
if (bmp_font->char_width == RT_NULL)
|
||||
rect->x1 += bmp_font->width;
|
||||
else
|
||||
rect->x1 += bmp_font->char_width[*text - bmp_font->first_char];
|
||||
text ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void rtgui_bitmap_font_get_metrics(struct rtgui_font *font, const char *text, rtgui_rect_t *rect)
|
||||
{
|
||||
rt_uint32_t length;
|
||||
struct rtgui_font_bitmap *bmp_font = (struct rtgui_font_bitmap *)(font->data);
|
||||
|
||||
RT_ASSERT(bmp_font != RT_NULL);
|
||||
|
||||
/* set init metrics rect */
|
||||
rect->x1 = rect->y1 = 0;
|
||||
rect->x2 = 0;
|
||||
rect->y2 = bmp_font->height;
|
||||
|
||||
while (*text)
|
||||
{
|
||||
length = 0;
|
||||
while ((rt_uint8_t) * (text + length) >= 0x80) length ++; /* it's not a ascii character */
|
||||
rect->x2 += (font->height / 2) * length;
|
||||
text += length;
|
||||
|
||||
length = 0;
|
||||
while (((rt_uint8_t) * (text + length) < 0x80) && *(text + length)) length ++;
|
||||
if (bmp_font->char_width != NULL)
|
||||
{
|
||||
/* get width for each character */
|
||||
while (*text && ((rt_uint8_t)*text < 0x80))
|
||||
{
|
||||
rect->x2 += bmp_font->char_width[*text - bmp_font->first_char];
|
||||
text ++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* set metrics rect */
|
||||
rect->x2 += bmp_font->width * length;
|
||||
text += length;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,239 +0,0 @@
|
||||
#include <rtgui/font_freetype.h>
|
||||
|
||||
#ifdef RTGUI_USING_TTF
|
||||
#include <ft2build.h>
|
||||
#include <freetype/freetype.h>
|
||||
#include <freetype/ftglyph.h>
|
||||
|
||||
static void rtgui_freetype_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_freetype_font_get_metrics(struct rtgui_font *font, const char *text, rtgui_rect_t *rect);
|
||||
|
||||
struct rtgui_font_engine freetype_font_engine =
|
||||
{
|
||||
RT_NULL,
|
||||
RT_NULL,
|
||||
rtgui_freetype_font_draw_text,
|
||||
rtgui_freetype_font_get_metrics
|
||||
};
|
||||
|
||||
struct rtgui_freetype_font
|
||||
{
|
||||
int bold;
|
||||
int italic;
|
||||
|
||||
FT_Face face;
|
||||
FT_Library library;
|
||||
};
|
||||
|
||||
static void gbk_to_unicode(rt_uint16_t *unicode, const unsigned char *text, int len)
|
||||
{
|
||||
int i;
|
||||
unsigned short wch;
|
||||
extern unsigned short ff_convert(unsigned short wch, int direction);
|
||||
|
||||
for (i = 0; i < len;)
|
||||
{
|
||||
if (*text < 0x80)
|
||||
{
|
||||
wch = *text;
|
||||
*unicode = ff_convert(wch, 1);
|
||||
text ++;
|
||||
i ++;
|
||||
}
|
||||
else
|
||||
{
|
||||
wch = wch = *(text + 1) | (*text << 8);
|
||||
*unicode = ff_convert(wch, 1);
|
||||
text += 2;
|
||||
i += 2;
|
||||
}
|
||||
|
||||
unicode ++;
|
||||
}
|
||||
|
||||
*unicode = '\0';
|
||||
}
|
||||
|
||||
static void rtgui_freetype_font_draw_text(struct rtgui_font *font, struct rtgui_dc *dc, const char *text, rt_ubase_t len, struct rtgui_rect *rect)
|
||||
{
|
||||
int index = 0;
|
||||
FT_Error err = 0;
|
||||
rt_uint16_t *text_short, *text_ptr;
|
||||
struct rtgui_freetype_font *freetype;
|
||||
|
||||
RT_ASSERT(font != RT_NULL);
|
||||
freetype = (struct rtgui_freetype_font *) font->data;
|
||||
RT_ASSERT(freetype != RT_NULL);
|
||||
|
||||
/* allocate unicode buffer */
|
||||
text_short = (rt_uint16_t *)rtgui_malloc((len + 1) * 2);
|
||||
if (text_short == RT_NULL) return ; /* out of memory */
|
||||
|
||||
/* convert gbk to unicode */
|
||||
gbk_to_unicode(text_short, text, len);
|
||||
text_ptr = text_short;
|
||||
|
||||
while (*text_ptr)
|
||||
{
|
||||
index = FT_Get_Char_Index(freetype->face, *text_ptr);
|
||||
err = FT_Load_Glyph(freetype->face, index, FT_LOAD_DEFAULT | FT_LOAD_RENDER);
|
||||
if (err == 0)
|
||||
{
|
||||
int rows, x;
|
||||
rt_uint8_t *ptr;
|
||||
|
||||
/* render font */
|
||||
ptr = (rt_uint8_t *)freetype->face->glyph->bitmap.buffer;
|
||||
|
||||
for (rows = 0; rows < freetype->face->glyph->bitmap.rows; rows ++)
|
||||
for (x = 0; x < freetype->face->glyph->bitmap.width; x++)
|
||||
{
|
||||
if (*ptr > 0)
|
||||
rtgui_dc_draw_color_point(dc, rect->x1 + x, rect->y1 + rows, RTGUI_RGB(0xff - *ptr, 0xff - *ptr, 0xff - *ptr));
|
||||
ptr ++;
|
||||
}
|
||||
}
|
||||
|
||||
text_ptr ++;
|
||||
rect->x1 += freetype->face->glyph->bitmap.width;
|
||||
}
|
||||
|
||||
/* release unicode buffer */
|
||||
rtgui_free(text_short);
|
||||
}
|
||||
|
||||
static void rtgui_freetype_font_get_metrics(struct rtgui_font *font, const char *text, rtgui_rect_t *rect)
|
||||
{
|
||||
int index = 0, len;
|
||||
FT_Error err = 0;
|
||||
rt_uint16_t w = 0, h = 0;
|
||||
rt_uint16_t *text_short, *text_ptr;
|
||||
struct rtgui_freetype_font *freetype;
|
||||
|
||||
RT_ASSERT(font != RT_NULL);
|
||||
RT_ASSERT(rect != RT_NULL);
|
||||
freetype = (struct rtgui_freetype_font *) font->data;
|
||||
RT_ASSERT(freetype != RT_NULL);
|
||||
|
||||
len = strlen(text);
|
||||
memset(rect, 0, sizeof(struct rtgui_rect));
|
||||
|
||||
/* allocate unicode buffer */
|
||||
text_short = (rt_uint16_t *)rtgui_malloc((len + 1) * 2);
|
||||
if (text_short == RT_NULL) return ; /* out of memory */
|
||||
|
||||
/* convert gbk to unicode */
|
||||
gbk_to_unicode(text_short, text, len);
|
||||
text_ptr = text_short;
|
||||
|
||||
while (*text_ptr)
|
||||
{
|
||||
index = FT_Get_Char_Index(freetype->face, *text_ptr);
|
||||
err = FT_Load_Glyph(freetype->face, index, FT_LOAD_DEFAULT);
|
||||
|
||||
if (err == 0)
|
||||
{
|
||||
w += freetype->face->glyph->bitmap.width;
|
||||
if (freetype->face->glyph->bitmap.rows > h)
|
||||
{
|
||||
h = freetype->face->glyph->bitmap.rows;
|
||||
}
|
||||
}
|
||||
|
||||
text_ptr ++;
|
||||
}
|
||||
|
||||
rect->x1 = 0;
|
||||
rect->y1 = 0;
|
||||
rect->x2 = w;
|
||||
rect->y2 = h;
|
||||
|
||||
/* release unicode buffer */
|
||||
rtgui_free(text_short);
|
||||
}
|
||||
|
||||
rtgui_font_t *rtgui_freetype_font_create(const char *filename, int bold, int italic, rt_size_t size)
|
||||
{
|
||||
FT_Error err = 0;
|
||||
struct rtgui_font *font;
|
||||
|
||||
font = (struct rtgui_font *) rtgui_malloc(sizeof(struct rtgui_font));
|
||||
if (font != RT_NULL)
|
||||
{
|
||||
struct rtgui_freetype_font *freetype;
|
||||
|
||||
freetype = (struct rtgui_freetype_font *) rtgui_malloc(sizeof(struct rtgui_freetype_font));
|
||||
if (freetype == RT_NULL)
|
||||
{
|
||||
rtgui_free(font);
|
||||
font = RT_NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
err = FT_Init_FreeType(&freetype->library);
|
||||
if ((err = FT_New_Face(freetype->library, filename, 0, &freetype->face)))
|
||||
{
|
||||
FT_Done_FreeType(freetype->library);
|
||||
|
||||
rtgui_free(font);
|
||||
font = RT_NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
err = FT_Select_Charmap(freetype->face, ft_encoding_unicode);
|
||||
if (err)
|
||||
{
|
||||
err = FT_Select_Charmap(freetype->face, ft_encoding_latin_1);
|
||||
}
|
||||
|
||||
err = FT_Set_Pixel_Sizes(freetype->face, 0, size);
|
||||
if (err != 0)
|
||||
{
|
||||
rtgui_free(font);
|
||||
font = RT_NULL;
|
||||
|
||||
FT_Done_FreeType(freetype->library);
|
||||
rtgui_free(freetype);
|
||||
|
||||
return RT_NULL;
|
||||
}
|
||||
|
||||
freetype->bold = bold;
|
||||
freetype->italic = italic;
|
||||
|
||||
rt_kprintf("fonfile:%s\n", filename);
|
||||
rt_kprintf("font family_name:%s\n", freetype->face->family_name);
|
||||
rt_kprintf("font style_name:%s\n", freetype->face->style_name);
|
||||
|
||||
/* set user data */
|
||||
font->data = freetype;
|
||||
font->family = rt_strdup(freetype->face->family_name);
|
||||
font->height = (rt_uint16_t)size;
|
||||
font->refer_count = 0;
|
||||
font->engine = &freetype_font_engine;
|
||||
|
||||
/* add to system */
|
||||
rtgui_font_system_add_font(font);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return font;
|
||||
}
|
||||
|
||||
void rtgui_freetype_font_destroy(rtgui_font_t *font)
|
||||
{
|
||||
struct rtgui_freetype_font *freetype;
|
||||
|
||||
RT_ASSERT(font != RT_NULL);
|
||||
freetype = (struct rtgui_freetype_font *) font->data;
|
||||
RT_ASSERT(freetype != RT_NULL);
|
||||
|
||||
rtgui_font_system_remove_font(font);
|
||||
|
||||
FT_Done_Face(freetype->face);
|
||||
FT_Done_FreeType(freetype->library);
|
||||
rtgui_free(freetype);
|
||||
rtgui_free(font);
|
||||
}
|
||||
#endif
|
||||
@@ -1,159 +0,0 @@
|
||||
|
||||
#include <rtgui/dc.h>
|
||||
#include <rtgui/font.h>
|
||||
|
||||
#ifdef RTGUI_USING_HZ_BMP
|
||||
|
||||
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 char *text, rtgui_rect_t *rect);
|
||||
const struct rtgui_font_engine hz_bmp_font_engine =
|
||||
{
|
||||
RT_NULL,
|
||||
RT_NULL,
|
||||
rtgui_hz_bitmap_font_draw_text,
|
||||
rtgui_hz_bitmap_font_get_metrics
|
||||
};
|
||||
|
||||
#ifdef RTGUI_USING_FONT_COMPACT
|
||||
extern rt_uint32_t rtgui_font_mph12(const rt_uint16_t key);
|
||||
extern rt_uint32_t rtgui_font_mph16(const rt_uint16_t key);
|
||||
rt_inline const rt_uint8_t *_rtgui_hz_bitmap_get_font_ptr(struct rtgui_font_bitmap *bmp_font,
|
||||
rt_uint8_t *str,
|
||||
rt_base_t font_bytes)
|
||||
{
|
||||
rt_uint16_t cha = *(rt_uint16_t *)str;
|
||||
int idx;
|
||||
|
||||
if (bmp_font->height == 16)
|
||||
idx = rtgui_font_mph16(cha);
|
||||
else // asume the height is 12
|
||||
idx = rtgui_font_mph12(cha);
|
||||
|
||||
/* don't access beyond the data */
|
||||
if (idx < 0)
|
||||
idx = 0;
|
||||
|
||||
/* get font pixel data */
|
||||
return bmp_font->bmp + idx * font_bytes;
|
||||
}
|
||||
#else
|
||||
rt_inline const rt_uint8_t *_rtgui_hz_bitmap_get_font_ptr(struct rtgui_font_bitmap *bmp_font,
|
||||
rt_uint8_t *str,
|
||||
rt_base_t font_bytes)
|
||||
{
|
||||
rt_ubase_t sect, index;
|
||||
|
||||
/* calculate section and index */
|
||||
sect = *str - 0xA0;
|
||||
index = *(str + 1) - 0xA0;
|
||||
|
||||
/* get font pixel data */
|
||||
return bmp_font->bmp + (94 * (sect - 1) + (index - 1)) * font_bytes;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void _rtgui_hz_bitmap_font_draw_text(struct rtgui_font_bitmap *bmp_font, struct rtgui_dc *dc, const char *text, rt_ubase_t len, struct rtgui_rect *rect)
|
||||
{
|
||||
rtgui_color_t bc;
|
||||
rt_uint16_t style;
|
||||
rt_uint8_t *str;
|
||||
register rt_base_t h, word_bytes, font_bytes;
|
||||
|
||||
RT_ASSERT(bmp_font != RT_NULL);
|
||||
|
||||
/* get text style */
|
||||
style = rtgui_dc_get_gc(dc)->textstyle;
|
||||
bc = rtgui_dc_get_gc(dc)->background;
|
||||
|
||||
/* drawing height */
|
||||
h = (bmp_font->height + rect->y1 > rect->y2) ? rect->y2 - rect->y1 : bmp_font->height;
|
||||
word_bytes = (bmp_font->width + 7) / 8;
|
||||
font_bytes = word_bytes * bmp_font->height;
|
||||
|
||||
str = (rt_uint8_t *)text;
|
||||
|
||||
while (len > 0 && rect->x1 < rect->x2)
|
||||
{
|
||||
const rt_uint8_t *font_ptr;
|
||||
register rt_base_t i, j, k;
|
||||
|
||||
/* get font pixel data */
|
||||
font_ptr = _rtgui_hz_bitmap_get_font_ptr(bmp_font, str, font_bytes);
|
||||
/* draw word */
|
||||
for (i = 0; i < h; i ++)
|
||||
{
|
||||
for (j = 0; j < word_bytes; j++)
|
||||
for (k = 0; k < 8; k++)
|
||||
{
|
||||
if (((font_ptr[i * word_bytes + j] >> (7 - k)) & 0x01) != 0 &&
|
||||
(rect->x1 + 8 * j + k < rect->x2))
|
||||
{
|
||||
rtgui_dc_draw_point(dc, rect->x1 + 8 * j + k, rect->y1 + i);
|
||||
}
|
||||
else if (style & RTGUI_TEXTSTYLE_DRAW_BACKGROUND)
|
||||
{
|
||||
rtgui_dc_draw_color_point(dc, rect->x1 + 8 * j + k, rect->y1 + i, bc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* move x to next character */
|
||||
rect->x1 += bmp_font->width;
|
||||
str += 2;
|
||||
len -= 2;
|
||||
}
|
||||
}
|
||||
|
||||
static void rtgui_hz_bitmap_font_draw_text(struct rtgui_font *font, struct rtgui_dc *dc, const char *text, rt_ubase_t length, struct rtgui_rect *rect)
|
||||
{
|
||||
rt_uint32_t len;
|
||||
struct rtgui_font *efont;
|
||||
struct rtgui_font_bitmap *bmp_font = (struct rtgui_font_bitmap *)(font->data);
|
||||
|
||||
RT_ASSERT(dc != RT_NULL);
|
||||
|
||||
/* get English font */
|
||||
efont = rtgui_font_refer("asc", bmp_font->height);
|
||||
if (efont == RT_NULL) efont = rtgui_font_default(); /* use system default font */
|
||||
|
||||
while (length > 0)
|
||||
{
|
||||
len = 0;
|
||||
while (((rt_uint8_t) * (text + len)) < 0x80 && *(text + len) && len < length) len ++;
|
||||
/* draw text with English font */
|
||||
if (len > 0)
|
||||
{
|
||||
rtgui_font_draw(efont, dc, text, len, rect);
|
||||
|
||||
text += len;
|
||||
length -= len;
|
||||
}
|
||||
|
||||
len = 0;
|
||||
while (((rt_uint8_t) * (text + len)) >= 0x80 && len < length) len ++;
|
||||
if (len > 0)
|
||||
{
|
||||
_rtgui_hz_bitmap_font_draw_text(bmp_font, dc, text, len, rect);
|
||||
|
||||
text += len;
|
||||
length -= len;
|
||||
}
|
||||
}
|
||||
|
||||
rtgui_font_derefer(efont);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
RT_ASSERT(bmp_font != RT_NULL);
|
||||
|
||||
/* set metrics rect */
|
||||
rect->x1 = rect->y1 = 0;
|
||||
/* Chinese font is always fixed font */
|
||||
rect->x2 = (rt_int16_t)(bmp_font->width * rt_strlen((const char *)text));
|
||||
rect->y2 = bmp_font->height;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,226 +0,0 @@
|
||||
/*
|
||||
* Cached HZ font engine
|
||||
*/
|
||||
#include <rtgui/dc.h>
|
||||
#include <rtgui/font.h>
|
||||
#include <rtgui/tree.h>
|
||||
#include <rtgui/rtgui_system.h>
|
||||
|
||||
#ifdef RTGUI_USING_HZ_FILE
|
||||
#ifdef _WIN32_NATIVE
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <io.h>
|
||||
#define open _open
|
||||
#define close _close
|
||||
#define read _read
|
||||
#define write _write
|
||||
#define unlink _unlink
|
||||
#else
|
||||
#include <dfs_posix.h>
|
||||
#endif
|
||||
|
||||
#define HZ_CACHE_MAX 64
|
||||
|
||||
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_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 char *text, rtgui_rect_t *rect);
|
||||
const struct rtgui_font_engine rtgui_hz_file_font_engine =
|
||||
{
|
||||
RT_NULL,
|
||||
rtgui_hz_file_font_load,
|
||||
rtgui_hz_file_font_draw_text,
|
||||
rtgui_hz_file_font_get_metrics
|
||||
};
|
||||
|
||||
SPLAY_PROTOTYPE(cache_tree, hz_cache, hz_node, _font_cache_compare);
|
||||
SPLAY_GENERATE(cache_tree, hz_cache, hz_node, _font_cache_compare);
|
||||
|
||||
static int _font_cache_compare(struct hz_cache *cache_1, struct hz_cache *cache_2)
|
||||
{
|
||||
if (cache_1->hz_id > cache_2->hz_id) return 1;
|
||||
if (cache_1->hz_id < cache_2->hz_id) return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static rt_uint8_t *_font_cache_get(struct rtgui_hz_file_font *font, rt_uint16_t hz_id)
|
||||
{
|
||||
rt_uint32_t seek;
|
||||
struct hz_cache *cache, search;
|
||||
|
||||
search.hz_id = hz_id;
|
||||
|
||||
/* enter critical */
|
||||
rtgui_enter_critical();
|
||||
|
||||
cache = SPLAY_FIND(cache_tree, &(font->cache_root), &search);
|
||||
if (cache != RT_NULL)
|
||||
{
|
||||
/* exit critical */
|
||||
rtgui_exit_critical();
|
||||
|
||||
/* found it */
|
||||
return (rt_uint8_t *)(cache + 1);
|
||||
}
|
||||
|
||||
/* exit critical */
|
||||
rtgui_exit_critical();
|
||||
|
||||
/* can not find it, load to cache */
|
||||
cache = (struct hz_cache *) rtgui_malloc(sizeof(struct hz_cache) + font->font_data_size);
|
||||
if (cache == RT_NULL)
|
||||
return RT_NULL; /* no memory yet */
|
||||
|
||||
cache->hz_id = hz_id;
|
||||
seek = 94 * (((hz_id & 0xff) - 0xA0) - 1) + ((hz_id >> 8) - 0xA0) - 1;
|
||||
seek *= font->font_data_size;
|
||||
|
||||
/* read hz font data */
|
||||
if ((lseek(font->fd, seek, SEEK_SET) < 0) ||
|
||||
read(font->fd, (char *)(cache + 1), font->font_data_size) !=
|
||||
font->font_data_size)
|
||||
{
|
||||
rtgui_free(cache);
|
||||
return RT_NULL;
|
||||
}
|
||||
|
||||
/* enter critical */
|
||||
rtgui_enter_critical();
|
||||
|
||||
if (font->cache_size >= HZ_CACHE_MAX)
|
||||
{
|
||||
/* remove a cache */
|
||||
struct hz_cache *left;
|
||||
left = font->cache_root.sph_root;
|
||||
while (SPLAY_LEFT(left, hz_node) != RT_NULL) left = SPLAY_LEFT(left, hz_node);
|
||||
|
||||
/* remove the left node */
|
||||
SPLAY_REMOVE(cache_tree, &(font->cache_root), left);
|
||||
rtgui_free(left);
|
||||
font->cache_size --;
|
||||
}
|
||||
|
||||
/* insert to cache */
|
||||
SPLAY_INSERT(cache_tree, &(font->cache_root), cache);
|
||||
font->cache_size ++;
|
||||
|
||||
/* exit critical */
|
||||
rtgui_exit_critical();
|
||||
|
||||
return (rt_uint8_t *)(cache + 1);
|
||||
}
|
||||
|
||||
static void rtgui_hz_file_font_load(struct rtgui_font *font)
|
||||
{
|
||||
struct rtgui_hz_file_font *hz_file_font = (struct rtgui_hz_file_font *)font->data;
|
||||
RT_ASSERT(hz_file_font != RT_NULL);
|
||||
|
||||
hz_file_font->fd = open(hz_file_font->font_fn, O_RDONLY, 0);
|
||||
}
|
||||
|
||||
static void _rtgui_hz_file_font_draw_text(struct rtgui_hz_file_font *hz_file_font, struct rtgui_dc *dc, const char *text, rt_ubase_t len, struct rtgui_rect *rect)
|
||||
{
|
||||
rt_uint8_t *str;
|
||||
rtgui_color_t bc;
|
||||
rt_uint16_t style;
|
||||
register rt_base_t h, word_bytes;
|
||||
|
||||
/* get text style */
|
||||
style = rtgui_dc_get_gc(dc)->textstyle;
|
||||
bc = rtgui_dc_get_gc(dc)->background;
|
||||
|
||||
/* drawing height */
|
||||
h = (hz_file_font->font_size + rect->y1 > rect->y2) ?
|
||||
rect->y2 - rect->y1 : hz_file_font->font_size;
|
||||
word_bytes = (hz_file_font->font_size + 7) / 8;
|
||||
|
||||
str = (rt_uint8_t *)text;
|
||||
|
||||
while (len > 0 && rect->x1 < rect->x2)
|
||||
{
|
||||
const rt_uint8_t *font_ptr;
|
||||
register rt_base_t i, j, k;
|
||||
|
||||
/* get font pixel data */
|
||||
font_ptr = _font_cache_get(hz_file_font, *str | (*(str + 1) << 8));
|
||||
|
||||
/* draw word */
|
||||
for (i = 0; i < h; i ++)
|
||||
{
|
||||
for (j = 0; j < word_bytes; j++)
|
||||
for (k = 0; k < 8; k++)
|
||||
{
|
||||
if (((font_ptr[i * word_bytes + j] >> (7 - k)) & 0x01) != 0 &&
|
||||
(rect->x1 + 8 * j + k < rect->x2))
|
||||
{
|
||||
rtgui_dc_draw_point(dc, rect->x1 + 8 * j + k, rect->y1 + i);
|
||||
}
|
||||
else if (style & RTGUI_TEXTSTYLE_DRAW_BACKGROUND)
|
||||
{
|
||||
rtgui_dc_draw_color_point(dc, rect->x1 + 8 * j + k, rect->y1 + i, bc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* move x to next character */
|
||||
rect->x1 += hz_file_font->font_size;
|
||||
str += 2;
|
||||
len -= 2;
|
||||
}
|
||||
}
|
||||
|
||||
static void rtgui_hz_file_font_draw_text(struct rtgui_font *font, struct rtgui_dc *dc, const char *text, rt_ubase_t length, struct rtgui_rect *rect)
|
||||
{
|
||||
rt_uint32_t len;
|
||||
struct rtgui_font *efont;
|
||||
struct rtgui_hz_file_font *hz_file_font = (struct rtgui_hz_file_font *)font->data;
|
||||
|
||||
RT_ASSERT(dc != RT_NULL);
|
||||
RT_ASSERT(hz_file_font != RT_NULL);
|
||||
|
||||
/* get English font */
|
||||
efont = rtgui_font_refer("asc", hz_file_font->font_size);
|
||||
if (efont == RT_NULL) efont = rtgui_font_default(); /* use system default font */
|
||||
|
||||
while (length > 0)
|
||||
{
|
||||
len = 0;
|
||||
while (((rt_uint8_t) * (text + len)) < 0x80 && *(text + len) && len < length) len ++;
|
||||
/* draw text with English font */
|
||||
if (len > 0)
|
||||
{
|
||||
rtgui_font_draw(efont, dc, text, len, rect);
|
||||
|
||||
text += len;
|
||||
length -= len;
|
||||
}
|
||||
|
||||
len = 0;
|
||||
while (((rt_uint8_t) * (text + len)) >= 0x80 && len < length) len ++;
|
||||
if (len > 0)
|
||||
{
|
||||
_rtgui_hz_file_font_draw_text(hz_file_font, dc, text, len, rect);
|
||||
|
||||
text += len;
|
||||
length -= len;
|
||||
}
|
||||
}
|
||||
|
||||
rtgui_font_derefer(efont);
|
||||
}
|
||||
|
||||
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;
|
||||
RT_ASSERT(hz_file_font != RT_NULL);
|
||||
|
||||
/* set metrics rect */
|
||||
rect->x1 = rect->y1 = 0;
|
||||
rect->x2 = (rt_int16_t)(hz_file_font->font_size / 2 * rt_strlen((const char *)text));
|
||||
rect->y2 = hz_file_font->font_size;
|
||||
}
|
||||
#endif
|
||||
@@ -1,35 +0,0 @@
|
||||
/* adapted from utils/perfect_hash/example1-C/states-tmpl.c */
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <string.h>
|
||||
|
||||
static const rt_uint32_t T1[] = { $S1 };
|
||||
static const rt_uint32_t T2[] = { $S2 };
|
||||
static const rt_uint16_t G[] = { $G };
|
||||
|
||||
static rt_uint32_t hash_g(const rt_uint16_t key, const rt_uint32_t *T)
|
||||
{
|
||||
rt_uint32_t sum = (T[0] * (key & 0xFF) + T[1] * (key >> 8)) % $NG;
|
||||
return G[sum % $NG];
|
||||
}
|
||||
|
||||
static rt_uint32_t perfect_hash(const rt_uint16_t key)
|
||||
{
|
||||
return (hash_g(key, T1) + hash_g(key, T2)) % $NG;
|
||||
}
|
||||
|
||||
rt_uint32_t rtgui_font_mph${height}(const rt_uint16_t key)
|
||||
{
|
||||
rt_uint32_t hash_value = perfect_hash(key);
|
||||
|
||||
/*rt_kprintf("hash 0x7684 is %d", perfect_hash(0x7684));*/
|
||||
/*RT_ASSERT(K[hash_value] == key);*/
|
||||
/* NOTE: we trust you will not feed invalid data into me. So there is no
|
||||
* more sanity check which will consume more flash and memory. */
|
||||
if (hash_value < $NK)
|
||||
return hash_value;
|
||||
return -1;
|
||||
}
|
||||
|
||||
const unsigned char hz${height}_font[] = { $font_data };
|
||||
|
||||
@@ -1,225 +0,0 @@
|
||||
#include <rtgui/rtgui_system.h>
|
||||
#include <rtgui/driver.h>
|
||||
|
||||
#define GET_PIXEL(dst, x, y, type) \
|
||||
(type *)((rt_uint8_t*)((dst)->framebuffer) + (y) * (dst)->pitch + (x) * ((dst)->bits_per_pixel/8))
|
||||
|
||||
static void _rgb565_set_pixel(rtgui_color_t *c, int x, int y)
|
||||
{
|
||||
*GET_PIXEL(rtgui_graphic_get_device(), x, y, rt_uint16_t) = rtgui_color_to_565(*c);
|
||||
}
|
||||
|
||||
static void _rgb565_get_pixel(rtgui_color_t *c, int x, int y)
|
||||
{
|
||||
rt_uint16_t pixel;
|
||||
|
||||
pixel = *GET_PIXEL(rtgui_graphic_get_device(), x, y, rt_uint16_t);
|
||||
|
||||
/* get pixel from color */
|
||||
*c = rtgui_color_from_565(pixel);
|
||||
}
|
||||
|
||||
static void _rgb565_draw_hline(rtgui_color_t *c, int x1, int x2, int y)
|
||||
{
|
||||
rt_ubase_t index;
|
||||
rt_uint16_t pixel;
|
||||
rt_uint16_t *pixel_ptr;
|
||||
|
||||
/* get pixel from color */
|
||||
pixel = rtgui_color_to_565(*c);
|
||||
|
||||
/* get pixel pointer in framebuffer */
|
||||
pixel_ptr = GET_PIXEL(rtgui_graphic_get_device(), x1, y, rt_uint16_t);
|
||||
|
||||
for (index = x1; index < x2; index ++)
|
||||
{
|
||||
*pixel_ptr = pixel;
|
||||
pixel_ptr ++;
|
||||
}
|
||||
}
|
||||
|
||||
static void _rgb565_draw_vline(rtgui_color_t *c, int x , int y1, int y2)
|
||||
{
|
||||
rt_uint8_t *dst;
|
||||
rt_uint16_t pixel;
|
||||
rt_ubase_t index;
|
||||
|
||||
pixel = rtgui_color_to_565(*c);
|
||||
dst = GET_PIXEL(rtgui_graphic_get_device(), x, y1, rt_uint8_t);
|
||||
for (index = y1; index < y2; index ++)
|
||||
{
|
||||
*(rt_uint16_t *)dst = pixel;
|
||||
dst += rtgui_graphic_get_device()->pitch;
|
||||
}
|
||||
}
|
||||
|
||||
static void _rgb565p_set_pixel(rtgui_color_t *c, int x, int y)
|
||||
{
|
||||
*GET_PIXEL(rtgui_graphic_get_device(), x, y, rt_uint16_t) = rtgui_color_to_565p(*c);
|
||||
}
|
||||
|
||||
static void _rgb565p_get_pixel(rtgui_color_t *c, int x, int y)
|
||||
{
|
||||
rt_uint16_t pixel;
|
||||
|
||||
pixel = *GET_PIXEL(rtgui_graphic_get_device(), x, y, rt_uint16_t);
|
||||
|
||||
/* get pixel from color */
|
||||
*c = rtgui_color_from_565p(pixel);
|
||||
}
|
||||
|
||||
static void _rgb565p_draw_hline(rtgui_color_t *c, int x1, int x2, int y)
|
||||
{
|
||||
rt_ubase_t index;
|
||||
rt_uint16_t pixel;
|
||||
rt_uint16_t *pixel_ptr;
|
||||
|
||||
/* get pixel from color */
|
||||
pixel = rtgui_color_to_565p(*c);
|
||||
|
||||
/* get pixel pointer in framebuffer */
|
||||
pixel_ptr = GET_PIXEL(rtgui_graphic_get_device(), x1, y, rt_uint16_t);
|
||||
|
||||
for (index = x1; index < x2; index ++)
|
||||
{
|
||||
*pixel_ptr = pixel;
|
||||
pixel_ptr ++;
|
||||
}
|
||||
}
|
||||
|
||||
static void _rgb565p_draw_vline(rtgui_color_t *c, int x , int y1, int y2)
|
||||
{
|
||||
rt_uint8_t *dst;
|
||||
rt_uint16_t pixel;
|
||||
rt_ubase_t index;
|
||||
|
||||
pixel = rtgui_color_to_565p(*c);
|
||||
dst = GET_PIXEL(rtgui_graphic_get_device(), x, y1, rt_uint8_t);
|
||||
for (index = y1; index < y2; index ++)
|
||||
{
|
||||
*(rt_uint16_t *)dst = pixel;
|
||||
dst += rtgui_graphic_get_device()->pitch;
|
||||
}
|
||||
}
|
||||
|
||||
/* draw raw hline */
|
||||
static void framebuffer_draw_raw_hline(rt_uint8_t *pixels, int x1, int x2, int y)
|
||||
{
|
||||
rt_uint8_t *dst;
|
||||
|
||||
dst = GET_PIXEL(rtgui_graphic_get_device(), x1, y, rt_uint8_t);
|
||||
rt_memcpy(dst, pixels, (x2 - x1) * (rtgui_graphic_get_device()->bits_per_pixel / 8));
|
||||
}
|
||||
|
||||
const struct rtgui_graphic_driver_ops _framebuffer_rgb565_ops =
|
||||
{
|
||||
_rgb565_set_pixel,
|
||||
_rgb565_get_pixel,
|
||||
_rgb565_draw_hline,
|
||||
_rgb565_draw_vline,
|
||||
framebuffer_draw_raw_hline,
|
||||
};
|
||||
|
||||
const struct rtgui_graphic_driver_ops _framebuffer_rgb565p_ops =
|
||||
{
|
||||
_rgb565p_set_pixel,
|
||||
_rgb565p_get_pixel,
|
||||
_rgb565p_draw_hline,
|
||||
_rgb565p_draw_vline,
|
||||
framebuffer_draw_raw_hline,
|
||||
};
|
||||
|
||||
#define FRAMEBUFFER (rtgui_graphic_get_device()->framebuffer)
|
||||
#define MONO_PIXEL(framebuffer, x, y) \
|
||||
((rt_uint8_t**)(framebuffer))[y/8][x]
|
||||
|
||||
static void _mono_set_pixel(rtgui_color_t *c, int x, int y)
|
||||
{
|
||||
if (*c == white)
|
||||
MONO_PIXEL(FRAMEBUFFER, x, y) &= ~(1 << (y % 8));
|
||||
else
|
||||
MONO_PIXEL(FRAMEBUFFER, x, y) |= (1 << (y % 8));
|
||||
}
|
||||
|
||||
static void _mono_get_pixel(rtgui_color_t *c, int x, int y)
|
||||
{
|
||||
if (MONO_PIXEL(FRAMEBUFFER, x, y) & (1 << (y % 8)))
|
||||
*c = black;
|
||||
else
|
||||
*c = white;
|
||||
}
|
||||
|
||||
static void _mono_draw_hline(rtgui_color_t *c, int x1, int x2, int y)
|
||||
{
|
||||
rt_ubase_t index;
|
||||
|
||||
if (*c == white)
|
||||
for (index = x1; index < x2; index ++)
|
||||
{
|
||||
MONO_PIXEL(FRAMEBUFFER, index, y) &= ~(1 << (y % 8));
|
||||
}
|
||||
else
|
||||
for (index = x1; index < x2; index ++)
|
||||
{
|
||||
MONO_PIXEL(FRAMEBUFFER, index, y) |= (1 << (y % 8));
|
||||
}
|
||||
}
|
||||
|
||||
static void _mono_draw_vline(rtgui_color_t *c, int x , int y1, int y2)
|
||||
{
|
||||
rt_ubase_t index;
|
||||
|
||||
if (*c == white)
|
||||
for (index = y1; index < y2; index ++)
|
||||
{
|
||||
MONO_PIXEL(FRAMEBUFFER, x, index) &= ~(1 << (index % 8));
|
||||
}
|
||||
else
|
||||
for (index = y1; index < y2; index ++)
|
||||
{
|
||||
MONO_PIXEL(FRAMEBUFFER, x, index) |= (1 << (index % 8));
|
||||
}
|
||||
}
|
||||
|
||||
/* draw raw hline */
|
||||
static void _mono_draw_raw_hline(rt_uint8_t *pixels, int x1, int x2, int y)
|
||||
{
|
||||
rt_ubase_t index;
|
||||
|
||||
for (index = x1; index < x2; index ++)
|
||||
{
|
||||
if (pixels[index / 8] && (1 << (index % 8)))
|
||||
MONO_PIXEL(FRAMEBUFFER, index, y) |= (1 << (y % 8));
|
||||
else
|
||||
MONO_PIXEL(FRAMEBUFFER, index, y) &= ~(1 << (y % 8));
|
||||
}
|
||||
}
|
||||
|
||||
const struct rtgui_graphic_driver_ops _framebuffer_mono_ops =
|
||||
{
|
||||
_mono_set_pixel,
|
||||
_mono_get_pixel,
|
||||
_mono_draw_hline,
|
||||
_mono_draw_vline,
|
||||
_mono_draw_raw_hline,
|
||||
};
|
||||
|
||||
const struct rtgui_graphic_driver_ops *rtgui_framebuffer_get_ops(int pixel_format)
|
||||
{
|
||||
switch (pixel_format)
|
||||
{
|
||||
case RTGRAPHIC_PIXEL_FORMAT_MONO:
|
||||
return &_framebuffer_mono_ops;
|
||||
case RTGRAPHIC_PIXEL_FORMAT_GRAY4:
|
||||
break;
|
||||
case RTGRAPHIC_PIXEL_FORMAT_GRAY16:
|
||||
break;
|
||||
case RTGRAPHIC_PIXEL_FORMAT_RGB565:
|
||||
return &_framebuffer_rgb565_ops;
|
||||
case RTGRAPHIC_PIXEL_FORMAT_RGB565P:
|
||||
return &_framebuffer_rgb565p_ops;
|
||||
}
|
||||
|
||||
return RT_NULL;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,346 +0,0 @@
|
||||
/*
|
||||
* File : image.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rt-thread.org/license/LICENSE
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2009-10-16 Bernard first version
|
||||
* 2012-01-24 onelife add TJpgDec (Tiny JPEG Decompressor) support
|
||||
* 2012-08-29 amsl add Image zoom interface.
|
||||
*/
|
||||
#include <rtthread.h>
|
||||
#include <rtgui/image.h>
|
||||
|
||||
#include <rtgui/image_hdc.h>
|
||||
#include <rtgui/rtgui_system.h>
|
||||
#include <rtgui/image_container.h>
|
||||
|
||||
#include <string.h>
|
||||
#ifdef _WIN32
|
||||
#define strncasecmp strnicmp
|
||||
#endif
|
||||
|
||||
#ifdef RTGUI_IMAGE_XPM
|
||||
#include <rtgui/image_xpm.h>
|
||||
#endif
|
||||
|
||||
#ifdef RTGUI_IMAGE_BMP
|
||||
#include <rtgui/image_bmp.h>
|
||||
#endif
|
||||
#if (defined(RTGUI_IMAGE_JPEG) || defined(RTGUI_IMAGE_TJPGD))
|
||||
#include <rtgui/image_jpeg.h>
|
||||
#endif
|
||||
#ifdef RTGUI_IMAGE_PNG
|
||||
#include <rtgui/image_png.h>
|
||||
#endif
|
||||
|
||||
static rtgui_list_t _rtgui_system_image_list = {RT_NULL};
|
||||
|
||||
/* initialize rtgui image system */
|
||||
void rtgui_system_image_init(void)
|
||||
{
|
||||
/* always support HDC image */
|
||||
rtgui_image_hdc_init();
|
||||
|
||||
#ifdef RTGUI_IMAGE_XPM
|
||||
rtgui_image_xpm_init();
|
||||
#endif
|
||||
|
||||
#ifdef RTGUI_IMAGE_BMP
|
||||
rtgui_image_bmp_init();
|
||||
#endif
|
||||
|
||||
#if (defined(RTGUI_IMAGE_JPEG) || defined(RTGUI_IMAGE_TJPGD))
|
||||
rtgui_image_jpeg_init();
|
||||
#endif
|
||||
|
||||
#ifdef RTGUI_IMAGE_PNG
|
||||
rtgui_image_png_init();
|
||||
#endif
|
||||
|
||||
#ifdef RTGUI_IMAGE_CONTAINER
|
||||
/* initialize image container */
|
||||
rtgui_system_image_container_init(RT_FALSE);
|
||||
#endif
|
||||
}
|
||||
|
||||
static struct rtgui_image_engine *rtgui_image_get_engine(const char *type)
|
||||
{
|
||||
struct rtgui_list_node *node;
|
||||
struct rtgui_image_engine *engine;
|
||||
|
||||
rtgui_list_foreach(node, &_rtgui_system_image_list)
|
||||
{
|
||||
engine = rtgui_list_entry(node, struct rtgui_image_engine, list);
|
||||
|
||||
if (strncasecmp(engine->name, type, strlen(engine->name)) == 0)
|
||||
return engine;
|
||||
}
|
||||
|
||||
return RT_NULL;
|
||||
}
|
||||
|
||||
#if defined(RTGUI_USING_DFS_FILERW)
|
||||
struct rtgui_image_engine *rtgui_image_get_engine_by_filename(const char *fn)
|
||||
{
|
||||
struct rtgui_list_node *node;
|
||||
struct rtgui_image_engine *engine;
|
||||
const char *ext;
|
||||
|
||||
ext = fn + rt_strlen(fn);
|
||||
while (ext != fn)
|
||||
{
|
||||
if (*ext == '.')
|
||||
{
|
||||
ext ++;
|
||||
break;
|
||||
}
|
||||
ext --;
|
||||
}
|
||||
if (ext == fn) return RT_NULL; /* no ext */
|
||||
|
||||
rtgui_list_foreach(node, &_rtgui_system_image_list)
|
||||
{
|
||||
engine = rtgui_list_entry(node, struct rtgui_image_engine, list);
|
||||
if (strncasecmp(engine->name, ext, strlen(engine->name)) == 0)
|
||||
return engine;
|
||||
}
|
||||
|
||||
return RT_NULL;
|
||||
}
|
||||
RTM_EXPORT(rtgui_image_get_engine_by_filename);
|
||||
|
||||
struct rtgui_image *rtgui_image_create_from_file(const char *type, const char *filename, rt_bool_t load)
|
||||
{
|
||||
struct rtgui_filerw *filerw;
|
||||
struct rtgui_image_engine *engine;
|
||||
struct rtgui_image *image = RT_NULL;
|
||||
|
||||
/* create filerw context */
|
||||
filerw = rtgui_filerw_create_file(filename, "rb");
|
||||
if (filerw == RT_NULL) return RT_NULL;
|
||||
|
||||
/* get image engine */
|
||||
engine = rtgui_image_get_engine(type);
|
||||
if (engine == RT_NULL)
|
||||
{
|
||||
/* close filerw context */
|
||||
rtgui_filerw_close(filerw);
|
||||
return RT_NULL;
|
||||
}
|
||||
|
||||
if (engine->image_check(filerw) == RT_TRUE)
|
||||
{
|
||||
image = (struct rtgui_image *) rtgui_malloc(sizeof(struct rtgui_image));
|
||||
if (image == RT_NULL)
|
||||
{
|
||||
/* close filerw context */
|
||||
rtgui_filerw_close(filerw);
|
||||
return RT_NULL;
|
||||
}
|
||||
|
||||
image->palette = RT_NULL;
|
||||
if (engine->image_load(image, filerw, load) != RT_TRUE)
|
||||
{
|
||||
/* close filerw context */
|
||||
rtgui_filerw_close(filerw);
|
||||
return RT_NULL;
|
||||
}
|
||||
|
||||
/* set image engine */
|
||||
image->engine = engine;
|
||||
}
|
||||
else
|
||||
{
|
||||
rtgui_filerw_close(filerw);
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
||||
RTM_EXPORT(rtgui_image_create_from_file);
|
||||
|
||||
struct rtgui_image *rtgui_image_create(const char *filename, rt_bool_t load)
|
||||
{
|
||||
struct rtgui_filerw *filerw;
|
||||
struct rtgui_image_engine *engine;
|
||||
struct rtgui_image *image = RT_NULL;
|
||||
|
||||
/* create filerw context */
|
||||
filerw = rtgui_filerw_create_file(filename, "rb");
|
||||
if (filerw == RT_NULL) return RT_NULL;
|
||||
|
||||
/* get image engine */
|
||||
engine = rtgui_image_get_engine_by_filename(filename);
|
||||
if (engine == RT_NULL)
|
||||
{
|
||||
/* close filerw context */
|
||||
rtgui_filerw_close(filerw);
|
||||
return RT_NULL;
|
||||
}
|
||||
|
||||
if (engine->image_check(filerw) == RT_TRUE)
|
||||
{
|
||||
image = (struct rtgui_image *) rtgui_malloc(sizeof(struct rtgui_image));
|
||||
if (image == RT_NULL)
|
||||
{
|
||||
/* close filerw context */
|
||||
rtgui_filerw_close(filerw);
|
||||
return RT_NULL;
|
||||
}
|
||||
|
||||
image->palette = RT_NULL;
|
||||
if (engine->image_load(image, filerw, load) != RT_TRUE)
|
||||
{
|
||||
/* close filerw context */
|
||||
rtgui_filerw_close(filerw);
|
||||
return RT_NULL;
|
||||
}
|
||||
|
||||
/* set image engine */
|
||||
image->engine = engine;
|
||||
}
|
||||
else
|
||||
{
|
||||
rtgui_filerw_close(filerw);
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
||||
RTM_EXPORT(rtgui_image_create);
|
||||
#endif
|
||||
|
||||
struct rtgui_image *rtgui_image_create_from_mem(const char *type, const rt_uint8_t *data, rt_size_t length, rt_bool_t load)
|
||||
{
|
||||
struct rtgui_filerw *filerw;
|
||||
struct rtgui_image_engine *engine;
|
||||
struct rtgui_image *image = RT_NULL;
|
||||
|
||||
/* create filerw context */
|
||||
filerw = rtgui_filerw_create_mem(data, length);
|
||||
if (filerw == RT_NULL) return RT_NULL;
|
||||
|
||||
/* get image engine */
|
||||
engine = rtgui_image_get_engine(type);
|
||||
if (engine == RT_NULL)
|
||||
{
|
||||
/* close filerw context */
|
||||
rtgui_filerw_close(filerw);
|
||||
return RT_NULL;
|
||||
}
|
||||
|
||||
if (engine->image_check(filerw) == RT_TRUE)
|
||||
{
|
||||
image = (struct rtgui_image *) rtgui_malloc(sizeof(struct rtgui_image));
|
||||
if (image == RT_NULL)
|
||||
{
|
||||
/* close filerw context */
|
||||
rtgui_filerw_close(filerw);
|
||||
return RT_NULL;
|
||||
}
|
||||
|
||||
image->palette = RT_NULL;
|
||||
if (engine->image_load(image, filerw, load) != RT_TRUE)
|
||||
{
|
||||
/* close filerw context */
|
||||
rtgui_filerw_close(filerw);
|
||||
return RT_NULL;
|
||||
}
|
||||
|
||||
/* set image engine */
|
||||
image->engine = engine;
|
||||
}
|
||||
else
|
||||
{
|
||||
rtgui_filerw_close(filerw);
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
||||
RTM_EXPORT(rtgui_image_create_from_mem);
|
||||
|
||||
void rtgui_image_destroy(struct rtgui_image *image)
|
||||
{
|
||||
RT_ASSERT(image != RT_NULL);
|
||||
|
||||
image->engine->image_unload(image);
|
||||
if (image->palette != RT_NULL)
|
||||
rtgui_free(image->palette);
|
||||
rtgui_free(image);
|
||||
}
|
||||
RTM_EXPORT(rtgui_image_destroy);
|
||||
|
||||
/* register an image engine */
|
||||
void rtgui_image_register_engine(struct rtgui_image_engine *engine)
|
||||
{
|
||||
RT_ASSERT(engine != RT_NULL);
|
||||
|
||||
rtgui_list_append(&_rtgui_system_image_list, &(engine->list));
|
||||
}
|
||||
RTM_EXPORT(rtgui_image_register_engine);
|
||||
|
||||
void rtgui_image_blit(struct rtgui_image *image, struct rtgui_dc *dc, struct rtgui_rect *rect)
|
||||
{
|
||||
RT_ASSERT(dc != RT_NULL);
|
||||
RT_ASSERT(rect != RT_NULL);
|
||||
|
||||
if (rtgui_dc_get_visible(dc) != RT_TRUE) return;
|
||||
|
||||
if (image != RT_NULL && image->engine != RT_NULL)
|
||||
{
|
||||
/* use image engine to blit */
|
||||
image->engine->image_blit(image, dc, rect);
|
||||
}
|
||||
}
|
||||
RTM_EXPORT(rtgui_image_blit);
|
||||
|
||||
struct rtgui_image_palette *rtgui_image_palette_create(rt_uint32_t ncolors)
|
||||
{
|
||||
struct rtgui_image_palette *palette = RT_NULL;
|
||||
|
||||
if (ncolors > 0)
|
||||
{
|
||||
palette = (struct rtgui_image_palette *) rtgui_malloc(sizeof(struct rtgui_image_palette) +
|
||||
sizeof(rtgui_color_t) * ncolors);
|
||||
if (palette != RT_NULL) palette->colors = (rtgui_color_t *)(palette + 1);
|
||||
}
|
||||
|
||||
return palette;
|
||||
}
|
||||
RTM_EXPORT(rtgui_image_palette_create);
|
||||
|
||||
void rtgui_image_get_rect(struct rtgui_image *image, struct rtgui_rect *rect)
|
||||
{
|
||||
RT_ASSERT(image != RT_NULL);
|
||||
RT_ASSERT(rect != RT_NULL);
|
||||
|
||||
rect->x1 = 0;
|
||||
rect->y1 = 0;
|
||||
rect->x2 = image->w;
|
||||
rect->y2 = image->h;
|
||||
}
|
||||
RTM_EXPORT(rtgui_image_get_rect);
|
||||
|
||||
rtgui_image_t *rtgui_image_zoom(rtgui_image_t *image, float scalew, float scaleh, rt_uint32_t mode)
|
||||
{
|
||||
if (image != RT_NULL && image->engine != RT_NULL)
|
||||
{
|
||||
return image->engine->image_zoom(image, scalew, scaleh, mode);
|
||||
}
|
||||
return RT_NULL;
|
||||
}
|
||||
RTM_EXPORT(rtgui_image_zoom);
|
||||
|
||||
rtgui_image_t *rtgui_image_rotate(rtgui_image_t *image, float angle)
|
||||
{
|
||||
if (image != RT_NULL && image->engine != RT_NULL)
|
||||
{
|
||||
return image->engine->image_rotate(image, angle);
|
||||
}
|
||||
return RT_NULL;
|
||||
}
|
||||
RTM_EXPORT(rtgui_image_rotate);
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,447 +0,0 @@
|
||||
#include <rtgui/image_container.h>
|
||||
|
||||
#ifdef RTGUI_IMAGE_CONTAINER
|
||||
typedef unsigned int (*rtgui_hash_func_t)(const void *key);
|
||||
typedef struct _rtgui_hash_table rtgui_hash_table_t;
|
||||
typedef rt_bool_t (*rtgui_equal_func_t)(const void *a, const void *b);
|
||||
typedef void (*rtgui_user_func_t)(const void *value, const void *data);
|
||||
|
||||
/*
|
||||
*Hash tables
|
||||
*/
|
||||
rtgui_hash_table_t *hash_table_create(rtgui_hash_func_t hash_func, rtgui_equal_func_t key_equal_func);
|
||||
void hash_table_destroy(rtgui_hash_table_t *hash_table);
|
||||
|
||||
void *hash_table_find(rtgui_hash_table_t *hash_table, const void *key);
|
||||
void hash_table_insert(rtgui_hash_table_t *hash_table, const void *key, void *value);
|
||||
rt_bool_t hash_table_remove(rtgui_hash_table_t *hash_table, const void *key);
|
||||
|
||||
void hash_table_foreach(rtgui_hash_table_t *hash_table, rtgui_user_func_t user_func, void *data);
|
||||
unsigned int hash_table_get_size(rtgui_hash_table_t *hash_table);
|
||||
|
||||
/* Hash Functions
|
||||
*/
|
||||
unsigned int direct_hash(const void *v);
|
||||
|
||||
#define HASH_TABLE_MIN_SIZE 11
|
||||
#define HASH_TABLE_MAX_SIZE 6247
|
||||
|
||||
typedef struct _gui_hash_node rtgui_hash_node_t;
|
||||
struct _gui_hash_node
|
||||
{
|
||||
void *key;
|
||||
void *value;
|
||||
rtgui_hash_node_t *next;
|
||||
};
|
||||
|
||||
struct _rtgui_hash_table
|
||||
{
|
||||
rt_uint16_t size;
|
||||
rt_uint16_t nnodes;
|
||||
|
||||
rtgui_hash_node_t **nodes;
|
||||
rtgui_hash_func_t hash_func;
|
||||
rtgui_equal_func_t key_equal_func;
|
||||
};
|
||||
|
||||
static const unsigned int primes[] =
|
||||
{
|
||||
11,
|
||||
19,
|
||||
37,
|
||||
73,
|
||||
109,
|
||||
163,
|
||||
251,
|
||||
367,
|
||||
557,
|
||||
823,
|
||||
1237,
|
||||
1861,
|
||||
2777,
|
||||
4177,
|
||||
6247,
|
||||
/*
|
||||
9371,
|
||||
14057,
|
||||
21089,
|
||||
31627,
|
||||
47431,
|
||||
71143,
|
||||
106721,
|
||||
160073,
|
||||
240101,
|
||||
360163,
|
||||
540217,
|
||||
810343,
|
||||
1215497,
|
||||
1823231,
|
||||
2734867,
|
||||
4102283,
|
||||
6153409,
|
||||
9230113,
|
||||
13845163,
|
||||
*/
|
||||
};
|
||||
|
||||
static const unsigned int nprimes = sizeof(primes) / sizeof(primes[0]);
|
||||
|
||||
static void hash_table_resize(rtgui_hash_table_t *hash_table);
|
||||
static rtgui_hash_node_t **hash_table_find_node(rtgui_hash_table_t *hash_table, const void *key);
|
||||
static rtgui_hash_node_t *hash_node_create(const void *key, void *value);
|
||||
static void hash_node_destroy(rtgui_hash_node_t *hash_node);
|
||||
static void hash_nodes_destroy(rtgui_hash_node_t *hash_node);
|
||||
static unsigned int primes_closest(unsigned int num);
|
||||
static void hash_table_needresize(rtgui_hash_table_t *hash_table);
|
||||
|
||||
rt_inline unsigned int primes_closest(unsigned int num)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < nprimes; i++)
|
||||
if (primes[i] > num)
|
||||
return primes[i];
|
||||
|
||||
return primes[nprimes - 1];
|
||||
}
|
||||
|
||||
/* directly hash */
|
||||
unsigned int direct_hash(const void *v)
|
||||
{
|
||||
return (unsigned int)v;
|
||||
}
|
||||
|
||||
rtgui_hash_table_t *hash_table_create(rtgui_hash_func_t hash_func, rtgui_equal_func_t key_equal_func)
|
||||
{
|
||||
rtgui_hash_table_t *hash_table;
|
||||
|
||||
hash_table = (rtgui_hash_table_t *) rtgui_malloc(sizeof(rtgui_hash_table_t));
|
||||
if (hash_table != RT_NULL)
|
||||
{
|
||||
hash_table->size = HASH_TABLE_MIN_SIZE;
|
||||
hash_table->nnodes = 0;
|
||||
hash_table->hash_func = hash_func ? hash_func : direct_hash;
|
||||
hash_table->key_equal_func = key_equal_func;
|
||||
hash_table->nodes = (rtgui_hash_node_t **)rtgui_malloc(sizeof(rtgui_hash_node_t *) * hash_table->size);
|
||||
if (hash_table->nodes == RT_NULL)
|
||||
{
|
||||
/* no memory yet */
|
||||
rtgui_free(hash_table);
|
||||
return RT_NULL;
|
||||
}
|
||||
|
||||
rt_memset(hash_table->nodes, 0, sizeof(rtgui_hash_node_t *) * hash_table->size);
|
||||
}
|
||||
|
||||
return hash_table;
|
||||
}
|
||||
|
||||
void hash_table_destroy(rtgui_hash_table_t *hash_table)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
RT_ASSERT(hash_table != RT_NULL);
|
||||
|
||||
for (i = 0; i < hash_table->size; i++)
|
||||
hash_nodes_destroy(hash_table->nodes[i]);
|
||||
|
||||
rtgui_free(hash_table->nodes);
|
||||
rtgui_free(hash_table);
|
||||
}
|
||||
|
||||
static rtgui_hash_node_t **hash_table_find_node(rtgui_hash_table_t *hash_table, const void *key)
|
||||
{
|
||||
rtgui_hash_node_t **node;
|
||||
|
||||
node = &hash_table->nodes [(* hash_table->hash_func)(key) % hash_table->size];
|
||||
|
||||
if (hash_table->key_equal_func)
|
||||
while (*node && !(*hash_table->key_equal_func)((*node)->key, key))
|
||||
node = &(*node)->next;
|
||||
else
|
||||
while (*node && (*node)->key != key)
|
||||
node = &(*node)->next;
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
void *hash_table_find(rtgui_hash_table_t *hash_table, const void *key)
|
||||
{
|
||||
rtgui_hash_node_t *node;
|
||||
|
||||
RT_ASSERT(hash_table != RT_NULL);
|
||||
RT_ASSERT(key != RT_NULL);
|
||||
|
||||
node = *hash_table_find_node(hash_table, key);
|
||||
|
||||
if (node) return node->value;
|
||||
else return RT_NULL;
|
||||
}
|
||||
|
||||
void hash_table_insert(rtgui_hash_table_t *hash_table, const void *key, void *value)
|
||||
{
|
||||
rtgui_hash_node_t **node;
|
||||
|
||||
if (hash_table == RT_NULL)return;
|
||||
|
||||
node = hash_table_find_node(hash_table, key);
|
||||
if (*node)
|
||||
{
|
||||
(*node)->value = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
*node = hash_node_create(key, value);
|
||||
hash_table->nnodes++;
|
||||
hash_table_needresize(hash_table);
|
||||
}
|
||||
}
|
||||
|
||||
rt_bool_t hash_table_remove(rtgui_hash_table_t *hash_table, const void *key)
|
||||
{
|
||||
rtgui_hash_node_t **node, *dest;
|
||||
|
||||
if (hash_table == RT_NULL) return RT_FALSE;
|
||||
|
||||
node = hash_table_find_node(hash_table, key);
|
||||
if (*node)
|
||||
{
|
||||
dest = *node;
|
||||
(*node) = dest->next;
|
||||
hash_node_destroy(dest);
|
||||
hash_table->nnodes--;
|
||||
|
||||
hash_table_needresize(hash_table);
|
||||
|
||||
return RT_TRUE;
|
||||
}
|
||||
|
||||
return RT_FALSE;
|
||||
}
|
||||
|
||||
void hash_table_foreach(rtgui_hash_table_t *hash_table, rtgui_user_func_t user_func, void *data)
|
||||
{
|
||||
rtgui_hash_node_t *node;
|
||||
int i;
|
||||
|
||||
RT_ASSERT(hash_table != RT_NULL);
|
||||
RT_ASSERT(user_func != RT_NULL);
|
||||
|
||||
for (i = 0; i < hash_table->size; i++)
|
||||
for (node = hash_table->nodes[i]; node; node = node->next)
|
||||
(* user_func)(node->value, data);
|
||||
}
|
||||
|
||||
unsigned int hash_table_get_size(rtgui_hash_table_t *hash_table)
|
||||
{
|
||||
if (hash_table == NULL) return 0;
|
||||
|
||||
return hash_table->nnodes;
|
||||
}
|
||||
|
||||
static void hash_table_needresize(rtgui_hash_table_t *hash_table)
|
||||
{
|
||||
if ((hash_table->size >= 3 * hash_table->nnodes && hash_table->size > HASH_TABLE_MIN_SIZE) ||
|
||||
(3 * hash_table->size <= hash_table->nnodes && hash_table->size < HASH_TABLE_MAX_SIZE))
|
||||
hash_table_resize(hash_table);
|
||||
}
|
||||
|
||||
static void hash_table_resize(rtgui_hash_table_t *hash_table)
|
||||
{
|
||||
rtgui_hash_node_t **new_nodes;
|
||||
rtgui_hash_node_t *node;
|
||||
rtgui_hash_node_t *next;
|
||||
unsigned int hash_val;
|
||||
int new_size;
|
||||
int i;
|
||||
|
||||
i = primes_closest(hash_table->nnodes);
|
||||
new_size = i > HASH_TABLE_MAX_SIZE ? HASH_TABLE_MAX_SIZE : i < HASH_TABLE_MIN_SIZE ? HASH_TABLE_MIN_SIZE : i ;
|
||||
|
||||
new_nodes = (rtgui_hash_node_t **)rtgui_malloc(sizeof(rtgui_hash_node_t *) * new_size);
|
||||
if (new_nodes == RT_NULL) return; /* no memory yet */
|
||||
rt_memset(new_nodes, 0, sizeof(rtgui_hash_node_t *) * new_size);
|
||||
|
||||
for (i = 0; i < hash_table->size; i++)
|
||||
{
|
||||
for (node = hash_table->nodes[i]; node; node = next)
|
||||
{
|
||||
next = node->next;
|
||||
|
||||
hash_val = (* hash_table->hash_func)(node->key) % new_size;
|
||||
|
||||
node->next = new_nodes[hash_val];
|
||||
new_nodes[hash_val] = node;
|
||||
}
|
||||
}
|
||||
|
||||
rtgui_free(hash_table->nodes);
|
||||
hash_table->nodes = new_nodes;
|
||||
hash_table->size = new_size;
|
||||
}
|
||||
|
||||
static rtgui_hash_node_t *hash_node_create(void *key, void *value)
|
||||
{
|
||||
rtgui_hash_node_t *hash_node;
|
||||
|
||||
hash_node = (rtgui_hash_node_t *) rtgui_malloc(sizeof(rtgui_hash_node_t));
|
||||
if (hash_node != RT_NULL)
|
||||
{
|
||||
/* set value and key */
|
||||
hash_node->key = key;
|
||||
hash_node->value = value;;
|
||||
|
||||
hash_node->next = RT_NULL;
|
||||
}
|
||||
|
||||
return hash_node;
|
||||
}
|
||||
|
||||
static void hash_node_destroy(rtgui_hash_node_t *hash_node)
|
||||
{
|
||||
rtgui_free(hash_node);
|
||||
}
|
||||
|
||||
static void hash_nodes_destroy(rtgui_hash_node_t *hash_node)
|
||||
{
|
||||
if (hash_node)
|
||||
{
|
||||
rtgui_hash_node_t *node = hash_node;
|
||||
rtgui_hash_node_t *temp;
|
||||
|
||||
while (node->next)
|
||||
{
|
||||
node->key = NULL;
|
||||
node->value = NULL;
|
||||
|
||||
temp = node;
|
||||
node = node->next;
|
||||
rtgui_free(temp);
|
||||
}
|
||||
|
||||
node->key = NULL;
|
||||
node->value = NULL;
|
||||
rtgui_free(node);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int string_hash_func(const void *self)
|
||||
{
|
||||
const char *p;
|
||||
int h = 0, g;
|
||||
|
||||
for (p = self; *p != '\0'; p += 1)
|
||||
{
|
||||
h = (h << 4) + *p;
|
||||
if ((g = h & 0xf0000000))
|
||||
{
|
||||
h = h ^ (g >> 24);
|
||||
h = h ^ g;
|
||||
}
|
||||
}
|
||||
|
||||
return h ;
|
||||
}
|
||||
rt_bool_t string_equal_func(const void *a, const void *b)
|
||||
{
|
||||
const char *str1, *str2;
|
||||
|
||||
str1 = (const char *)a;
|
||||
str2 = (const char *)b;
|
||||
|
||||
if (strcmp(str1, str2) == 0) return RT_TRUE;
|
||||
return RT_FALSE;
|
||||
}
|
||||
|
||||
static rtgui_hash_table_t *image_hash_table;
|
||||
static rt_bool_t load_image = RT_FALSE;
|
||||
void rtgui_system_image_container_init(rt_bool_t load)
|
||||
{
|
||||
/* create image hash table */
|
||||
image_hash_table = hash_table_create(string_hash_func, string_equal_func);
|
||||
RT_ASSERT(image_hash_table != RT_NULL);
|
||||
|
||||
/* set load type */
|
||||
load_image = load;
|
||||
}
|
||||
|
||||
#ifdef RTGUI_USING_DFS_FILERW
|
||||
rtgui_image_item_t *rtgui_image_container_get(const char *filename)
|
||||
{
|
||||
struct rtgui_image_item *item;
|
||||
|
||||
item = hash_table_find(image_hash_table, filename);
|
||||
if (item == RT_NULL)
|
||||
{
|
||||
item = (struct rtgui_image_item *) rtgui_malloc(sizeof(struct rtgui_image_item));
|
||||
if (item == RT_NULL) return RT_NULL;
|
||||
|
||||
/* create a image object */
|
||||
item->image = rtgui_image_create(filename, load_image);
|
||||
if (item->image == RT_NULL)
|
||||
{
|
||||
rtgui_free(item);
|
||||
return RT_NULL; /* create image failed */
|
||||
}
|
||||
|
||||
item->refcount = 1;
|
||||
item->filename = rt_strdup(filename);
|
||||
hash_table_insert(image_hash_table, item->filename, item);
|
||||
}
|
||||
else
|
||||
{
|
||||
item->refcount ++; /* increase refcount */
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
#endif
|
||||
|
||||
rtgui_image_item_t *rtgui_image_container_get_memref(const char *type, const rt_uint8_t *memory, rt_uint32_t length)
|
||||
{
|
||||
char filename[32];
|
||||
struct rtgui_image_item *item;
|
||||
|
||||
/* create filename for image identification */
|
||||
rt_snprintf(filename, sizeof(filename), "0x%08x_%s", memory, type);
|
||||
|
||||
/* search in container */
|
||||
item = hash_table_find(image_hash_table, filename);
|
||||
if (item == RT_NULL)
|
||||
{
|
||||
item = (struct rtgui_image_item *) rtgui_malloc(sizeof(struct rtgui_image_item));
|
||||
if (item == RT_NULL) return RT_NULL;
|
||||
|
||||
/* create image object */
|
||||
item->image = rtgui_image_create_from_mem(type, memory, length, load_image);
|
||||
if (item->image == RT_NULL)
|
||||
{
|
||||
rtgui_free(item);
|
||||
return RT_NULL; /* create image failed */
|
||||
}
|
||||
|
||||
item->refcount = 1;
|
||||
item->filename = rt_strdup(filename);
|
||||
hash_table_insert(image_hash_table, item->filename, item);
|
||||
}
|
||||
else item->refcount ++;
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
void rtgui_image_container_put(rtgui_image_item_t *item)
|
||||
{
|
||||
item->refcount --;
|
||||
if (item->refcount == 0)
|
||||
{
|
||||
/* remove item from container */
|
||||
hash_table_remove(image_hash_table, item->filename);
|
||||
|
||||
/* destroy image and image item */
|
||||
rt_free(item->filename);
|
||||
rtgui_image_destroy(item->image);
|
||||
rtgui_free(item);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,243 +0,0 @@
|
||||
#include <rtthread.h>
|
||||
#include <rtgui/dc_hw.h>
|
||||
#include <rtgui/image.h>
|
||||
#include <rtgui/rtgui_system.h>
|
||||
#include <rtgui/image_hdc.h>
|
||||
|
||||
#define HDC_MAGIC_LEN 4
|
||||
|
||||
struct rtgui_image_hdc
|
||||
{
|
||||
rt_bool_t is_loaded;
|
||||
|
||||
/* hdc image information */
|
||||
rt_uint16_t byte_per_pixel;
|
||||
rt_uint16_t pitch;
|
||||
|
||||
rt_size_t pixel_offset;
|
||||
rt_uint8_t *pixels;
|
||||
|
||||
struct rtgui_filerw *filerw;
|
||||
const struct rtgui_graphic_driver *hw_driver;
|
||||
};
|
||||
|
||||
static rt_bool_t rtgui_image_hdc_check(struct rtgui_filerw *file);
|
||||
static rt_bool_t rtgui_image_hdc_load(struct rtgui_image *image, struct rtgui_filerw *file, rt_bool_t load);
|
||||
static void rtgui_image_hdc_unload(struct rtgui_image *image);
|
||||
static void rtgui_image_hdc_blit(struct rtgui_image *image, struct rtgui_dc *dc, struct rtgui_rect *rect);
|
||||
static void rtgui_image_hdcmm_blit(struct rtgui_image *image, struct rtgui_dc *dc, struct rtgui_rect *dst_rect);
|
||||
|
||||
struct rtgui_image_engine rtgui_image_hdc_engine =
|
||||
{
|
||||
"hdc",
|
||||
{ RT_NULL },
|
||||
rtgui_image_hdc_check,
|
||||
rtgui_image_hdc_load,
|
||||
rtgui_image_hdc_unload,
|
||||
rtgui_image_hdc_blit,
|
||||
RT_NULL,
|
||||
RT_NULL
|
||||
};
|
||||
|
||||
const struct rtgui_image_engine rtgui_image_hdcmm_engine =
|
||||
{
|
||||
"hdcmm",
|
||||
{RT_NULL},
|
||||
RT_NULL,
|
||||
RT_NULL,
|
||||
RT_NULL,
|
||||
rtgui_image_hdcmm_blit,
|
||||
RT_NULL,
|
||||
RT_NULL
|
||||
};
|
||||
|
||||
static rt_bool_t rtgui_image_hdc_check(struct rtgui_filerw *file)
|
||||
{
|
||||
int start;
|
||||
rt_bool_t is_HDC;
|
||||
rt_uint8_t magic[4];
|
||||
|
||||
if (!file) return 0;
|
||||
|
||||
start = rtgui_filerw_tell(file);
|
||||
|
||||
/* move to the beginning of file */
|
||||
rtgui_filerw_seek(file, 0, RTGUI_FILE_SEEK_SET);
|
||||
|
||||
is_HDC = RT_FALSE;
|
||||
if (rtgui_filerw_read(file, magic, 1, sizeof(magic)) == sizeof(magic))
|
||||
{
|
||||
if (magic[0] == 'H' &&
|
||||
magic[1] == 'D' &&
|
||||
magic[2] == 'C' &&
|
||||
magic[3] == '\0')
|
||||
{
|
||||
is_HDC = RT_TRUE;
|
||||
}
|
||||
}
|
||||
rtgui_filerw_seek(file, start, RTGUI_FILE_SEEK_SET);
|
||||
|
||||
return(is_HDC);
|
||||
}
|
||||
|
||||
static rt_bool_t rtgui_image_hdc_load(struct rtgui_image *image, struct rtgui_filerw *file, rt_bool_t load)
|
||||
{
|
||||
rt_uint32_t header[5];
|
||||
struct rtgui_image_hdc *hdc;
|
||||
|
||||
hdc = (struct rtgui_image_hdc *) rtgui_malloc(sizeof(struct rtgui_image_hdc));
|
||||
if (hdc == RT_NULL) return RT_FALSE;
|
||||
|
||||
hdc->hw_driver = rtgui_graphic_driver_get_default();
|
||||
if (hdc->hw_driver == RT_NULL)
|
||||
{
|
||||
rtgui_free(hdc);
|
||||
return RT_FALSE;
|
||||
}
|
||||
|
||||
rtgui_filerw_read(file, (char *)&header, 1, sizeof(header));
|
||||
|
||||
/* set image information */
|
||||
image->w = (rt_uint16_t)header[1];
|
||||
image->h = (rt_uint16_t)header[2];
|
||||
image->engine = &rtgui_image_hdc_engine;
|
||||
image->data = hdc;
|
||||
hdc->filerw = file;
|
||||
hdc->byte_per_pixel = hdc->hw_driver->bits_per_pixel / 8;
|
||||
hdc->pitch = image->w * hdc->byte_per_pixel;
|
||||
hdc->pixel_offset = rtgui_filerw_tell(file);
|
||||
|
||||
if (load == RT_TRUE)
|
||||
{
|
||||
/* load all pixels */
|
||||
hdc->pixels = rtgui_malloc(image->h * hdc->pitch);
|
||||
if (hdc->pixels == RT_NULL)
|
||||
{
|
||||
/* release data */
|
||||
rtgui_free(hdc);
|
||||
return RT_FALSE;
|
||||
}
|
||||
|
||||
rtgui_filerw_read(hdc->filerw, hdc->pixels, 1, image->h * hdc->pitch);
|
||||
rtgui_filerw_close(hdc->filerw);
|
||||
hdc->filerw = RT_NULL;
|
||||
hdc->pixel_offset = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
hdc->pixels = RT_NULL;
|
||||
}
|
||||
|
||||
return RT_TRUE;
|
||||
}
|
||||
|
||||
static void rtgui_image_hdc_unload(struct rtgui_image *image)
|
||||
{
|
||||
struct rtgui_image_hdc *hdc;
|
||||
|
||||
if (image != RT_NULL)
|
||||
{
|
||||
hdc = (struct rtgui_image_hdc *) image->data;
|
||||
|
||||
if (hdc->pixels != RT_NULL) rtgui_free(hdc->pixels);
|
||||
if (hdc->filerw != RT_NULL)
|
||||
{
|
||||
rtgui_filerw_close(hdc->filerw);
|
||||
hdc->filerw = RT_NULL;
|
||||
}
|
||||
|
||||
/* release data */
|
||||
rtgui_free(hdc);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
struct rtgui_image_hdc *hdc;
|
||||
|
||||
RT_ASSERT(image != RT_NULL || dc != RT_NULL || dst_rect != RT_NULL);
|
||||
|
||||
/* this dc is not visible */
|
||||
if (rtgui_dc_get_visible(dc) != RT_TRUE) return;
|
||||
|
||||
hdc = (struct rtgui_image_hdc *) image->data;
|
||||
RT_ASSERT(hdc != RT_NULL);
|
||||
|
||||
/* the minimum rect */
|
||||
if (image->w < rtgui_rect_width(*dst_rect)) w = image->w;
|
||||
else w = rtgui_rect_width(*dst_rect);
|
||||
if (image->h < rtgui_rect_height(*dst_rect)) h = image->h;
|
||||
else h = rtgui_rect_height(*dst_rect);
|
||||
|
||||
if (hdc->pixels != RT_NULL)
|
||||
{
|
||||
rt_uint8_t *ptr;
|
||||
|
||||
/* get pixel pointer */
|
||||
ptr = hdc->pixels;
|
||||
|
||||
for (y = 0; y < h; y ++)
|
||||
{
|
||||
dc->engine->blit_line(dc, dst_rect->x1, dst_rect->x1 + w, dst_rect->y1 + y, ptr);
|
||||
ptr += hdc->pitch;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_uint8_t *ptr;
|
||||
ptr = rtgui_malloc(hdc->pitch);
|
||||
if (ptr == RT_NULL) return; /* no memory */
|
||||
|
||||
/* seek to the begin of pixel data */
|
||||
rtgui_filerw_seek(hdc->filerw, hdc->pixel_offset, RTGUI_FILE_SEEK_SET);
|
||||
|
||||
for (y = 0; y < h; y ++)
|
||||
{
|
||||
/* read pixel data */
|
||||
if (rtgui_filerw_read(hdc->filerw, ptr, 1, hdc->pitch) != hdc->pitch)
|
||||
break; /* read data failed */
|
||||
|
||||
dc->engine->blit_line(dc, dst_rect->x1, dst_rect->x1 + w, dst_rect->y1 + y, ptr);
|
||||
}
|
||||
|
||||
rtgui_free(ptr);
|
||||
}
|
||||
}
|
||||
|
||||
static void rtgui_image_hdcmm_blit(struct rtgui_image *image, struct rtgui_dc *dc, struct rtgui_rect *dst_rect)
|
||||
{
|
||||
rt_uint8_t *ptr;
|
||||
rt_uint16_t y, w, h;
|
||||
struct rtgui_image_hdcmm *hdc;
|
||||
|
||||
RT_ASSERT(image != RT_NULL || dc != RT_NULL || dst_rect != RT_NULL);
|
||||
|
||||
/* this dc is not visible */
|
||||
if (rtgui_dc_get_visible(dc) != RT_TRUE) return;
|
||||
|
||||
hdc = (struct rtgui_image_hdcmm *) image;
|
||||
RT_ASSERT(hdc != RT_NULL);
|
||||
|
||||
/* the minimum rect */
|
||||
if (image->w < rtgui_rect_width(*dst_rect)) w = image->w;
|
||||
else w = rtgui_rect_width(*dst_rect);
|
||||
if (image->h < rtgui_rect_height(*dst_rect)) h = image->h;
|
||||
else h = rtgui_rect_height(*dst_rect);
|
||||
|
||||
|
||||
/* get pixel pointer */
|
||||
ptr = hdc->pixels;
|
||||
|
||||
for (y = 0; y < h; y ++)
|
||||
{
|
||||
dc->engine->blit_line(dc, dst_rect->x1, dst_rect->x1 + w, dst_rect->y1 + y, ptr);
|
||||
ptr += hdc->pitch;
|
||||
}
|
||||
}
|
||||
|
||||
void rtgui_image_hdc_init()
|
||||
{
|
||||
/* register hdc on image system */
|
||||
rtgui_image_register_engine(&rtgui_image_hdc_engine);
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,379 +0,0 @@
|
||||
#include <rtthread.h>
|
||||
#include <rtgui/rtgui_system.h>
|
||||
|
||||
#ifdef RTGUI_IMAGE_PNG
|
||||
#include "png.h"
|
||||
#include <rtgui/image_png.h>
|
||||
|
||||
#define PNG_MAGIC_LEN 8
|
||||
|
||||
struct rtgui_image_png
|
||||
{
|
||||
rt_bool_t is_loaded;
|
||||
|
||||
struct rtgui_filerw *filerw;
|
||||
|
||||
/* png image information */
|
||||
png_structp png_ptr;
|
||||
png_infop info_ptr;
|
||||
|
||||
rt_uint8_t *pixels;
|
||||
};
|
||||
|
||||
static rt_bool_t rtgui_image_png_check(struct rtgui_filerw *file);
|
||||
static rt_bool_t rtgui_image_png_load(struct rtgui_image *image, struct rtgui_filerw *file, rt_bool_t load);
|
||||
static void rtgui_image_png_unload(struct rtgui_image *image);
|
||||
static void rtgui_image_png_blit(struct rtgui_image *image, struct rtgui_dc *dc, struct rtgui_rect *rect);
|
||||
|
||||
struct rtgui_image_engine rtgui_image_png_engine =
|
||||
{
|
||||
"png",
|
||||
{ RT_NULL },
|
||||
rtgui_image_png_check,
|
||||
rtgui_image_png_load,
|
||||
rtgui_image_png_unload,
|
||||
rtgui_image_png_blit,
|
||||
RT_NULL,
|
||||
RT_NULL
|
||||
};
|
||||
|
||||
static void rtgui_image_png_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
{
|
||||
struct rtgui_filerw *filerw = (struct rtgui_filerw *)png_ptr->io_ptr;
|
||||
|
||||
rtgui_filerw_read(filerw, data, length, 1);
|
||||
}
|
||||
|
||||
static rt_bool_t rtgui_image_png_process(png_structp png_ptr, png_infop info_ptr, struct rtgui_image_png *png)
|
||||
{
|
||||
rt_uint32_t x, y;
|
||||
png_bytep row;
|
||||
png_bytep data;
|
||||
rtgui_color_t *ptr;
|
||||
|
||||
row = (png_bytep) rtgui_malloc(png_get_rowbytes(png_ptr, info_ptr));
|
||||
if (row == RT_NULL) return RT_FALSE;
|
||||
|
||||
ptr = (rtgui_color_t *)png->pixels;
|
||||
|
||||
switch (info_ptr->color_type)
|
||||
{
|
||||
case PNG_COLOR_TYPE_RGB:
|
||||
for (y = 0; y < info_ptr->height; y++)
|
||||
{
|
||||
png_read_row(png_ptr, row, png_bytep_NULL);
|
||||
for (x = 0; x < info_ptr->width; x++)
|
||||
{
|
||||
data = &(row[x * 3]);
|
||||
|
||||
ptr[x + y * info_ptr->width] = RTGUI_RGB(data[0], data[1], data[2]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case PNG_COLOR_TYPE_RGBA:
|
||||
for (y = 0; y < info_ptr->height; y++)
|
||||
{
|
||||
png_read_row(png_ptr, row, png_bytep_NULL);
|
||||
for (x = 0; x < info_ptr->width; x++)
|
||||
{
|
||||
data = &(row[x * 4]);
|
||||
|
||||
ptr[x + y * info_ptr->width] = RTGUI_ARGB((255 - data[3]), data[0], data[1], data[2]);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case PNG_COLOR_TYPE_PALETTE:
|
||||
for (y = 0; y < info_ptr->height; y++)
|
||||
{
|
||||
png_read_row(png_ptr, row, png_bytep_NULL);
|
||||
for (x = 0; x < info_ptr->width; x++)
|
||||
{
|
||||
data = &(row[x]);
|
||||
|
||||
ptr[x] = RTGUI_ARGB(0, info_ptr->palette[data[0]].red,
|
||||
info_ptr->palette[data[0]].green,
|
||||
info_ptr->palette[data[0]].blue);
|
||||
}
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
};
|
||||
|
||||
rtgui_free(row);
|
||||
|
||||
return RT_TRUE;
|
||||
}
|
||||
|
||||
static rt_bool_t rtgui_image_png_check(struct rtgui_filerw *file)
|
||||
{
|
||||
int start;
|
||||
rt_bool_t is_PNG;
|
||||
rt_uint8_t magic[4];
|
||||
|
||||
if (!file) return 0;
|
||||
|
||||
start = rtgui_filerw_tell(file);
|
||||
|
||||
/* move to the begining of file */
|
||||
rtgui_filerw_seek(file, 0, SEEK_SET);
|
||||
|
||||
is_PNG = RT_FALSE;
|
||||
if (rtgui_filerw_read(file, magic, 1, sizeof(magic)) == sizeof(magic))
|
||||
{
|
||||
if (magic[0] == 0x89 &&
|
||||
magic[1] == 'P' &&
|
||||
magic[2] == 'N' &&
|
||||
magic[3] == 'G')
|
||||
{
|
||||
is_PNG = RT_TRUE;
|
||||
}
|
||||
}
|
||||
rtgui_filerw_seek(file, start, SEEK_SET);
|
||||
|
||||
return(is_PNG);
|
||||
}
|
||||
|
||||
static rt_bool_t rtgui_image_png_load(struct rtgui_image *image, struct rtgui_filerw *file, rt_bool_t load)
|
||||
{
|
||||
png_uint_32 width;
|
||||
png_uint_32 height;
|
||||
int bit_depth;
|
||||
int color_type;
|
||||
double gamma;
|
||||
struct rtgui_image_png *png;
|
||||
|
||||
png = (struct rtgui_image_png *) rtgui_malloc(sizeof(struct rtgui_image_png));
|
||||
png->png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
if (png->png_ptr == RT_NULL)
|
||||
{
|
||||
rtgui_free(png);
|
||||
return RT_FALSE;
|
||||
}
|
||||
|
||||
png->info_ptr = png_create_info_struct(png->png_ptr);
|
||||
if (png->info_ptr == RT_NULL)
|
||||
{
|
||||
png_destroy_read_struct(&png->png_ptr, NULL, NULL);
|
||||
rtgui_free(png);
|
||||
return RT_FALSE;
|
||||
}
|
||||
|
||||
png->filerw = file;
|
||||
png_set_read_fn(png->png_ptr, png->filerw, rtgui_image_png_read_data);
|
||||
|
||||
png_read_info(png->png_ptr, png->info_ptr);
|
||||
png_get_IHDR(png->png_ptr, png->info_ptr, &width, &height, &bit_depth,
|
||||
&color_type, NULL, NULL, NULL);
|
||||
|
||||
/* set image information */
|
||||
image->w = width;
|
||||
image->h = height;
|
||||
image->engine = &rtgui_image_png_engine;
|
||||
image->data = png;
|
||||
|
||||
if (bit_depth == 16)
|
||||
png_set_strip_16(png->png_ptr);
|
||||
if (color_type == PNG_COLOR_TYPE_PALETTE)
|
||||
png_set_expand(png->png_ptr);
|
||||
if (bit_depth < 8)
|
||||
png_set_expand(png->png_ptr);
|
||||
if (png_get_valid(png->png_ptr, png->info_ptr, PNG_INFO_tRNS))
|
||||
png_set_expand(png->png_ptr);
|
||||
if (color_type == PNG_COLOR_TYPE_GRAY ||
|
||||
color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
|
||||
png_set_gray_to_rgb(png->png_ptr);
|
||||
|
||||
/* Ignore background color */
|
||||
|
||||
/* set gamma conversion */
|
||||
if (png_get_gAMA(png->png_ptr, png->info_ptr, &gamma))
|
||||
png_set_gamma(png->png_ptr, (double)2.2, gamma);
|
||||
|
||||
png_read_update_info(png->png_ptr, png->info_ptr);
|
||||
|
||||
if (load == RT_TRUE)
|
||||
{
|
||||
/* load all pixels */
|
||||
png->pixels = rtgui_malloc(image->w * image->h * sizeof(rtgui_color_t));
|
||||
if (png->pixels == RT_NULL)
|
||||
{
|
||||
png_read_end(png->png_ptr, RT_NULL);
|
||||
|
||||
/* destroy png struct */
|
||||
png_destroy_info_struct(png->png_ptr, &png->info_ptr);
|
||||
png_destroy_read_struct(&png->png_ptr, RT_NULL, RT_NULL);
|
||||
|
||||
/* release data */
|
||||
rtgui_free(png);
|
||||
return RT_FALSE;
|
||||
}
|
||||
|
||||
rtgui_image_png_process(png->png_ptr, png->info_ptr, png);
|
||||
}
|
||||
else
|
||||
{
|
||||
png->pixels = RT_NULL;
|
||||
}
|
||||
|
||||
return RT_TRUE;
|
||||
}
|
||||
|
||||
static void rtgui_image_png_unload(struct rtgui_image *image)
|
||||
{
|
||||
struct rtgui_image_png *png;
|
||||
|
||||
if (image != RT_NULL)
|
||||
{
|
||||
png = (struct rtgui_image_png *) image->data;
|
||||
|
||||
png_read_end(png->png_ptr, RT_NULL);
|
||||
|
||||
/* destroy png struct */
|
||||
png_destroy_info_struct(png->png_ptr, &png->info_ptr);
|
||||
png_destroy_read_struct(&png->png_ptr, RT_NULL, RT_NULL);
|
||||
|
||||
if (png->pixels != RT_NULL) rtgui_free(png->pixels);
|
||||
|
||||
/* release data */
|
||||
rtgui_free(png);
|
||||
}
|
||||
}
|
||||
|
||||
static void rtgui_image_png_blit(struct rtgui_image *image, struct rtgui_dc *dc, struct rtgui_rect *rect)
|
||||
{
|
||||
struct rtgui_graphic_driver *hwdev = rtgui_graphic_get_device();
|
||||
rt_uint16_t x, y, w, h;
|
||||
rtgui_color_t *ptr;
|
||||
struct rtgui_image_png *png;
|
||||
int fg_maxsample;
|
||||
int ialpha;
|
||||
float alpha;
|
||||
rtgui_color_t color;
|
||||
rtgui_color_t c, bgcolor;
|
||||
int fc[3], bc[3];
|
||||
|
||||
RT_ASSERT(image != RT_NULL && dc != RT_NULL && rect != RT_NULL);
|
||||
RT_ASSERT(image->data != RT_NULL);
|
||||
|
||||
png = (struct rtgui_image_png *) image->data;
|
||||
|
||||
if (image->w < rtgui_rect_width(*rect)) w = image->w;
|
||||
else w = rtgui_rect_width(*rect);
|
||||
if (image->h < rtgui_rect_height(*rect)) h = image->h;
|
||||
else h = rtgui_rect_height(*rect);
|
||||
|
||||
fg_maxsample = (1 << png->info_ptr->bit_depth) - 1;
|
||||
|
||||
if (png->pixels != RT_NULL)
|
||||
{
|
||||
ptr = (rtgui_color_t *)png->pixels;
|
||||
bgcolor = rtgui_color_from_565(RTGUI_DC_BC(dc));
|
||||
bc[0] = RTGUI_RGB_R(bgcolor);
|
||||
bc[1] = RTGUI_RGB_G(bgcolor);
|
||||
bc[2] = RTGUI_RGB_B(bgcolor);
|
||||
/* draw each point within dc */
|
||||
for (y = 0; y < h; y ++)
|
||||
{
|
||||
for (x = 0; x < w; x++)
|
||||
{
|
||||
c = *ptr;
|
||||
ialpha = RTGUI_RGB_A(c);
|
||||
if (ialpha == 0)
|
||||
{
|
||||
/*
|
||||
* Foreground image is transparent hear.
|
||||
* If the background image is already in the frame
|
||||
* buffer, there is nothing to do.
|
||||
*/
|
||||
}
|
||||
else if (ialpha == fg_maxsample)
|
||||
{
|
||||
/*
|
||||
* Copy foreground pixel to frame buffer.
|
||||
*/
|
||||
rtgui_dc_draw_color_point(dc, x + rect->x1, y + rect->y1, c);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* output = alpha * foreground + (1-alpha) * background */
|
||||
/*
|
||||
* Compositing is necessary.
|
||||
* Get floating-point alpha and its complement.
|
||||
* Note: alpha is always linear: gamma does not
|
||||
* affect it.
|
||||
*/
|
||||
fc[0] = RTGUI_RGB_R(c);
|
||||
fc[1] = RTGUI_RGB_G(c);
|
||||
fc[2] = RTGUI_RGB_B(c);
|
||||
|
||||
alpha = (float) ialpha / fg_maxsample;
|
||||
color = RTGUI_RGB((rt_uint8_t)(fc[0] * alpha + bc[0] * (1 - alpha)),
|
||||
(rt_uint8_t)(fc[1] * alpha + bc[1] * (1 - alpha)),
|
||||
(rt_uint8_t)(fc[2] * alpha + bc[2] * (1 - alpha)));
|
||||
rtgui_dc_draw_color_point(dc, x + rect->x1, y + rect->y1, color);
|
||||
}
|
||||
/* move to next color buffer */
|
||||
ptr ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
png_bytep row;
|
||||
png_bytep data;
|
||||
|
||||
row = (png_bytep) rtgui_malloc(png_get_rowbytes(png->png_ptr, png->info_ptr));
|
||||
if (row == RT_NULL) return ;
|
||||
|
||||
switch (png->info_ptr->color_type)
|
||||
{
|
||||
case PNG_COLOR_TYPE_RGBA:
|
||||
for (y = 0; y < h; y++)
|
||||
{
|
||||
png_read_row(png->png_ptr, row, png_bytep_NULL);
|
||||
for (x = 0; x < w; x++)
|
||||
{
|
||||
data = &(row[x * 4]);
|
||||
if (data[3] != 0)
|
||||
{
|
||||
rtgui_dc_draw_color_point(dc, x + rect->x1, y + rect->y1,
|
||||
RTGUI_ARGB((255 - data[3]), data[0], data[1], data[2]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case PNG_COLOR_TYPE_PALETTE:
|
||||
for (y = 0; y < h; y++)
|
||||
{
|
||||
png_read_row(png->png_ptr, row, png_bytep_NULL);
|
||||
for (x = 0; x < w; x++)
|
||||
{
|
||||
data = &(row[x]);
|
||||
|
||||
rtgui_dc_draw_color_point(dc, x + rect->x1, y + rect->y1,
|
||||
RTGUI_ARGB(0, png->info_ptr->palette[data[0]].red,
|
||||
png->info_ptr->palette[data[0]].green,
|
||||
png->info_ptr->palette[data[0]].blue));
|
||||
}
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
};
|
||||
|
||||
rtgui_free(row);
|
||||
}
|
||||
}
|
||||
|
||||
void rtgui_image_png_init()
|
||||
{
|
||||
/* register png on image system */
|
||||
rtgui_image_register_engine(&rtgui_image_png_engine);
|
||||
}
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,203 +0,0 @@
|
||||
/*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2012-01-24 onelife add mono color support
|
||||
*/
|
||||
#include <rtgui/rtgui_system.h>
|
||||
#include <rtgui/driver.h>
|
||||
|
||||
#define gfx_device (rtgui_graphic_get_device()->device)
|
||||
#define gfx_device_ops rt_graphix_ops(gfx_device)
|
||||
|
||||
static void _pixel_mono_set_pixel(rtgui_color_t *c, int x, int y)
|
||||
{
|
||||
rt_uint8_t pixel;
|
||||
|
||||
pixel = rtgui_color_to_mono(*c);
|
||||
gfx_device_ops->set_pixel((char *)&pixel, x, y);
|
||||
}
|
||||
|
||||
static void _pixel_rgb565p_set_pixel(rtgui_color_t *c, int x, int y)
|
||||
{
|
||||
rt_uint16_t pixel;
|
||||
|
||||
pixel = rtgui_color_to_565p(*c);
|
||||
gfx_device_ops->set_pixel((char *)&pixel, x, y);
|
||||
}
|
||||
|
||||
static void _pixel_rgb565_set_pixel(rtgui_color_t *c, int x, int y)
|
||||
{
|
||||
rt_uint16_t pixel;
|
||||
|
||||
pixel = rtgui_color_to_565(*c);
|
||||
gfx_device_ops->set_pixel((char *)&pixel, x, y);
|
||||
}
|
||||
|
||||
static void _pixel_rgb888_set_pixel(rtgui_color_t *c, int x, int y)
|
||||
{
|
||||
rt_uint32_t pixel;
|
||||
|
||||
pixel = rtgui_color_to_888(*c);
|
||||
gfx_device_ops->set_pixel((char *)&pixel, x, y);
|
||||
}
|
||||
|
||||
static void _pixel_mono_get_pixel(rtgui_color_t *c, int x, int y)
|
||||
{
|
||||
rt_uint8_t pixel;
|
||||
|
||||
gfx_device_ops->get_pixel((char *)&pixel, x, y);
|
||||
*c = rtgui_color_from_mono(pixel);
|
||||
}
|
||||
|
||||
static void _pixel_rgb565p_get_pixel(rtgui_color_t *c, int x, int y)
|
||||
{
|
||||
rt_uint16_t pixel;
|
||||
|
||||
gfx_device_ops->get_pixel((char *)&pixel, x, y);
|
||||
*c = rtgui_color_from_565p(pixel);
|
||||
}
|
||||
|
||||
static void _pixel_rgb565_get_pixel(rtgui_color_t *c, int x, int y)
|
||||
{
|
||||
rt_uint16_t pixel;
|
||||
|
||||
gfx_device_ops->get_pixel((char *)&pixel, x, y);
|
||||
*c = rtgui_color_from_565(pixel);
|
||||
}
|
||||
|
||||
static void _pixel_rgb888_get_pixel(rtgui_color_t *c, int x, int y)
|
||||
{
|
||||
rt_uint32_t pixel;
|
||||
|
||||
gfx_device_ops->get_pixel((char *)&pixel, x, y);
|
||||
*c = rtgui_color_from_888(pixel);
|
||||
}
|
||||
|
||||
static void _pixel_mono_draw_hline(rtgui_color_t *c, int x1, int x2, int y)
|
||||
{
|
||||
rt_uint8_t pixel;
|
||||
|
||||
pixel = rtgui_color_to_mono(*c);
|
||||
gfx_device_ops->draw_hline((char *)&pixel, x1, x2, y);
|
||||
}
|
||||
|
||||
static void _pixel_rgb565p_draw_hline(rtgui_color_t *c, int x1, int x2, int y)
|
||||
{
|
||||
rt_uint16_t pixel;
|
||||
|
||||
pixel = rtgui_color_to_565p(*c);
|
||||
gfx_device_ops->draw_hline((char *)&pixel, x1, x2, y);
|
||||
}
|
||||
|
||||
static void _pixel_rgb565_draw_hline(rtgui_color_t *c, int x1, int x2, int y)
|
||||
{
|
||||
rt_uint16_t pixel;
|
||||
|
||||
pixel = rtgui_color_to_565(*c);
|
||||
gfx_device_ops->draw_hline((char *)&pixel, x1, x2, y);
|
||||
}
|
||||
|
||||
static void _pixel_rgb888_draw_hline(rtgui_color_t *c, int x1, int x2, int y)
|
||||
{
|
||||
rt_uint32_t pixel;
|
||||
|
||||
pixel = rtgui_color_to_888(*c);
|
||||
gfx_device_ops->draw_hline((char *)&pixel, x1, x2, y);
|
||||
}
|
||||
|
||||
static void _pixel_mono_draw_vline(rtgui_color_t *c, int x, int y1, int y2)
|
||||
{
|
||||
rt_uint8_t pixel;
|
||||
|
||||
pixel = rtgui_color_to_mono(*c);
|
||||
gfx_device_ops->draw_vline((char *)&pixel, x, y1, y2);
|
||||
}
|
||||
|
||||
static void _pixel_rgb565p_draw_vline(rtgui_color_t *c, int x, int y1, int y2)
|
||||
{
|
||||
rt_uint16_t pixel;
|
||||
|
||||
pixel = rtgui_color_to_565p(*c);
|
||||
gfx_device_ops->draw_vline((char *)&pixel, x, y1, y2);
|
||||
}
|
||||
|
||||
static void _pixel_rgb565_draw_vline(rtgui_color_t *c, int x, int y1, int y2)
|
||||
{
|
||||
rt_uint16_t pixel;
|
||||
|
||||
pixel = rtgui_color_to_565(*c);
|
||||
gfx_device_ops->draw_vline((char *)&pixel, x, y1, y2);
|
||||
}
|
||||
|
||||
static void _pixel_rgb888_draw_vline(rtgui_color_t *c, int x, int y1, int y2)
|
||||
{
|
||||
rt_uint32_t pixel;
|
||||
|
||||
pixel = rtgui_color_to_888(*c);
|
||||
gfx_device_ops->draw_vline((char *)&pixel, x, y1, y2);
|
||||
}
|
||||
|
||||
static void _pixel_draw_raw_hline(rt_uint8_t *pixels, int x1, int x2, int y)
|
||||
{
|
||||
if (x2 > x1)
|
||||
gfx_device_ops->blit_line((char *)pixels, x1, y, (x2 - x1));
|
||||
else
|
||||
gfx_device_ops->blit_line((char *)pixels, x2, y, (x1 - x2));
|
||||
}
|
||||
|
||||
/* pixel device */
|
||||
const struct rtgui_graphic_driver_ops _pixel_mono_ops =
|
||||
{
|
||||
_pixel_mono_set_pixel,
|
||||
_pixel_mono_get_pixel,
|
||||
_pixel_mono_draw_hline,
|
||||
_pixel_mono_draw_vline,
|
||||
_pixel_draw_raw_hline,
|
||||
};
|
||||
|
||||
const struct rtgui_graphic_driver_ops _pixel_rgb565p_ops =
|
||||
{
|
||||
_pixel_rgb565p_set_pixel,
|
||||
_pixel_rgb565p_get_pixel,
|
||||
_pixel_rgb565p_draw_hline,
|
||||
_pixel_rgb565p_draw_vline,
|
||||
_pixel_draw_raw_hline,
|
||||
};
|
||||
|
||||
const struct rtgui_graphic_driver_ops _pixel_rgb565_ops =
|
||||
{
|
||||
_pixel_rgb565_set_pixel,
|
||||
_pixel_rgb565_get_pixel,
|
||||
_pixel_rgb565_draw_hline,
|
||||
_pixel_rgb565_draw_vline,
|
||||
_pixel_draw_raw_hline,
|
||||
};
|
||||
|
||||
const struct rtgui_graphic_driver_ops _pixel_rgb888_ops =
|
||||
{
|
||||
_pixel_rgb888_set_pixel,
|
||||
_pixel_rgb888_get_pixel,
|
||||
_pixel_rgb888_draw_hline,
|
||||
_pixel_rgb888_draw_vline,
|
||||
_pixel_draw_raw_hline,
|
||||
};
|
||||
|
||||
const struct rtgui_graphic_driver_ops *rtgui_pixel_device_get_ops(int pixel_format)
|
||||
{
|
||||
switch (pixel_format)
|
||||
{
|
||||
case RTGRAPHIC_PIXEL_FORMAT_MONO:
|
||||
return &_pixel_mono_ops;
|
||||
|
||||
case RTGRAPHIC_PIXEL_FORMAT_RGB565:
|
||||
return &_pixel_rgb565_ops;
|
||||
|
||||
case RTGRAPHIC_PIXEL_FORMAT_RGB565P:
|
||||
return &_pixel_rgb565p_ops;
|
||||
|
||||
case RTGRAPHIC_PIXEL_FORMAT_RGB888:
|
||||
return &_pixel_rgb888_ops;
|
||||
}
|
||||
|
||||
return RT_NULL;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,409 +0,0 @@
|
||||
/*
|
||||
* File : rtgui_app.c
|
||||
* This file is part of RTGUI in RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2012, RT-Thread Development Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rt-thread.org/license/LICENSE
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2012-01-13 Grissiom first version(just a prototype of application API)
|
||||
* 2012-07-07 Bernard move the send/recv message to the rtgui_system.c
|
||||
*/
|
||||
|
||||
#include <rtgui/rtgui_system.h>
|
||||
#include <rtgui/rtgui_app.h>
|
||||
#include <rtgui/widgets/window.h>
|
||||
|
||||
static void _rtgui_app_constructor(struct rtgui_app *app)
|
||||
{
|
||||
/* set event handler */
|
||||
rtgui_object_set_event_handler(RTGUI_OBJECT(app),
|
||||
rtgui_app_event_handler);
|
||||
|
||||
app->name = RT_NULL;
|
||||
app->icon = RT_NULL;
|
||||
/* set EXITED so we can destroy an application that just created */
|
||||
app->state_flag = RTGUI_APP_FLAG_EXITED;
|
||||
app->ref_count = 0;
|
||||
app->exit_code = 0;
|
||||
app->tid = RT_NULL;
|
||||
app->mq = RT_NULL;
|
||||
app->modal_object = RT_NULL;
|
||||
app->main_object = RT_NULL;
|
||||
app->on_idle = RT_NULL;
|
||||
}
|
||||
|
||||
static void _rtgui_app_destructor(struct rtgui_app *app)
|
||||
{
|
||||
RT_ASSERT(app != RT_NULL);
|
||||
|
||||
rt_free(app->name);
|
||||
app->name = RT_NULL;
|
||||
}
|
||||
|
||||
DEFINE_CLASS_TYPE(application, "application",
|
||||
RTGUI_OBJECT_TYPE,
|
||||
_rtgui_app_constructor,
|
||||
_rtgui_app_destructor,
|
||||
sizeof(struct rtgui_app));
|
||||
|
||||
struct rtgui_app *rtgui_app_create(const char *title)
|
||||
{
|
||||
rt_thread_t tid = rt_thread_self();
|
||||
struct rtgui_app *app;
|
||||
struct rtgui_app *srv_app;
|
||||
struct rtgui_event_application event;
|
||||
char mq_name[RT_NAME_MAX];
|
||||
|
||||
RT_ASSERT(tid != RT_NULL);
|
||||
RT_ASSERT(title != RT_NULL);
|
||||
|
||||
/* create application */
|
||||
app = RTGUI_APP(rtgui_object_create(RTGUI_APP_TYPE));
|
||||
if (app == RT_NULL)
|
||||
return RT_NULL;
|
||||
|
||||
/* one thread only can create one rtgui application */
|
||||
RT_ASSERT(tid->user_data == 0);
|
||||
app->tid = tid;
|
||||
|
||||
rt_snprintf(mq_name, RT_NAME_MAX, "g%s", title);
|
||||
app->mq = rt_mq_create(mq_name, sizeof(union rtgui_event_generic), 32, RT_IPC_FLAG_FIFO);
|
||||
if (app->mq == RT_NULL)
|
||||
{
|
||||
rt_kprintf("create msgq failed.\n");
|
||||
goto __mq_err;
|
||||
}
|
||||
|
||||
/* set application title */
|
||||
app->name = (unsigned char *)rt_strdup((char *)title);
|
||||
if (app->name == RT_NULL)
|
||||
goto __err;
|
||||
|
||||
/* the first app should be the server */
|
||||
srv_app = rtgui_get_server();
|
||||
if (srv_app == RT_NULL)
|
||||
{
|
||||
/* set user thread */
|
||||
tid->user_data = (rt_uint32_t)app;
|
||||
rt_kprintf("RTGUI: creating the server app %p.\n", app);
|
||||
return app;
|
||||
}
|
||||
|
||||
RTGUI_EVENT_APP_CREATE_INIT(&event);
|
||||
event.app = app;
|
||||
|
||||
/* notify rtgui server to one application has been created */
|
||||
if (rtgui_send_sync(srv_app, RTGUI_EVENT(&event), sizeof(event)) == RT_EOK)
|
||||
{
|
||||
/* set user thread */
|
||||
tid->user_data = (rt_uint32_t)app;
|
||||
return app;
|
||||
}
|
||||
|
||||
__err:
|
||||
__mq_err:
|
||||
rtgui_object_destroy(RTGUI_OBJECT(app));
|
||||
return RT_NULL;
|
||||
}
|
||||
RTM_EXPORT(rtgui_app_create);
|
||||
|
||||
#define _rtgui_application_check(app) \
|
||||
do { \
|
||||
RT_ASSERT(app != RT_NULL); \
|
||||
RT_ASSERT(app->tid != RT_NULL); \
|
||||
RT_ASSERT(app->tid->user_data != 0); \
|
||||
RT_ASSERT(app->mq != RT_NULL); \
|
||||
} while (0)
|
||||
|
||||
void rtgui_app_destroy(struct rtgui_app *app)
|
||||
{
|
||||
struct rtgui_app *srv_app;
|
||||
_rtgui_application_check(app);
|
||||
|
||||
if (!(app->state_flag & RTGUI_APP_FLAG_EXITED))
|
||||
{
|
||||
rt_kprintf("cannot destroy a running application: %s.\n",
|
||||
app->name);
|
||||
return;
|
||||
}
|
||||
|
||||
/* send a message to notify rtgui server */
|
||||
srv_app = rtgui_get_server();
|
||||
if (srv_app != rtgui_app_self())
|
||||
{
|
||||
struct rtgui_event_application event;
|
||||
RTGUI_EVENT_APP_DESTROY_INIT(&event);
|
||||
event.app = app;
|
||||
|
||||
if (rtgui_send_sync(srv_app, RTGUI_EVENT(&event), sizeof(event)) != RT_EOK)
|
||||
{
|
||||
rt_kprintf("destroy an application in server failed\n");
|
||||
return ;
|
||||
}
|
||||
}
|
||||
|
||||
app->tid->user_data = 0;
|
||||
rt_mq_delete(app->mq);
|
||||
rtgui_object_destroy(RTGUI_OBJECT(app));
|
||||
}
|
||||
RTM_EXPORT(rtgui_app_destroy);
|
||||
|
||||
struct rtgui_app *rtgui_app_self(void)
|
||||
{
|
||||
struct rtgui_app *app;
|
||||
rt_thread_t self;
|
||||
|
||||
/* get current thread */
|
||||
self = rt_thread_self();
|
||||
app = (struct rtgui_app *)(self->user_data);
|
||||
|
||||
return app;
|
||||
}
|
||||
RTM_EXPORT(rtgui_app_self);
|
||||
|
||||
void rtgui_app_set_onidle(struct rtgui_app *app, rtgui_idle_func_t onidle)
|
||||
{
|
||||
_rtgui_application_check(app);
|
||||
app->on_idle = onidle;
|
||||
}
|
||||
RTM_EXPORT(rtgui_app_set_onidle);
|
||||
|
||||
rtgui_idle_func_t rtgui_app_get_onidle(struct rtgui_app *app)
|
||||
{
|
||||
|
||||
_rtgui_application_check(app);
|
||||
return app->on_idle;
|
||||
}
|
||||
RTM_EXPORT(rtgui_app_get_onidle);
|
||||
|
||||
rt_inline rt_bool_t _rtgui_application_dest_handle(
|
||||
struct rtgui_app *app,
|
||||
struct rtgui_event *event)
|
||||
{
|
||||
struct rtgui_event_win *wevent = (struct rtgui_event_win *)event;
|
||||
|
||||
struct rtgui_object *dest_object = RTGUI_OBJECT(wevent->wid);
|
||||
|
||||
if (dest_object != RT_NULL)
|
||||
{
|
||||
if (dest_object->event_handler != RT_NULL)
|
||||
return dest_object->event_handler(RTGUI_OBJECT(dest_object), event);
|
||||
else
|
||||
return RT_FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_kprintf("RTGUI ERROR:server sent a event(%d) without wid\n", event->type);
|
||||
return RT_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
rt_bool_t rtgui_app_event_handler(struct rtgui_object *object, rtgui_event_t *event)
|
||||
{
|
||||
struct rtgui_app *app;
|
||||
|
||||
RT_ASSERT(object != RT_NULL);
|
||||
RT_ASSERT(event != RT_NULL);
|
||||
|
||||
app = RTGUI_APP(object);
|
||||
|
||||
switch (event->type)
|
||||
{
|
||||
case RTGUI_EVENT_PAINT:
|
||||
case RTGUI_EVENT_CLIP_INFO:
|
||||
case RTGUI_EVENT_WIN_ACTIVATE:
|
||||
case RTGUI_EVENT_WIN_DEACTIVATE:
|
||||
case RTGUI_EVENT_WIN_CLOSE:
|
||||
case RTGUI_EVENT_WIN_MOVE:
|
||||
case RTGUI_EVENT_KBD:
|
||||
_rtgui_application_dest_handle(app, event);
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_APP_ACTIVATE:
|
||||
if (app->main_object != RT_NULL)
|
||||
{
|
||||
rtgui_win_activate(RTGUI_WIN(app->main_object));
|
||||
if (app->modal_object != RT_NULL)
|
||||
rtgui_win_activate(RTGUI_WIN(app->modal_object));
|
||||
}
|
||||
else if (app->modal_object != RT_NULL)
|
||||
{
|
||||
rtgui_win_activate(RTGUI_WIN(app->modal_object));
|
||||
}
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_APP_DESTROY:
|
||||
rtgui_app_exit(app, 0);
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_MOUSE_BUTTON:
|
||||
case RTGUI_EVENT_MOUSE_MOTION:
|
||||
{
|
||||
struct rtgui_event_win *wevent = (struct rtgui_event_win *)event;
|
||||
struct rtgui_object *dest_object = RTGUI_OBJECT(wevent->wid);
|
||||
|
||||
// FIXME: let application determine the dest_wiget but not in sever
|
||||
// so we can combine this handler with above one
|
||||
if (app->modal_object != RT_NULL &&
|
||||
dest_object != app->modal_object)
|
||||
{
|
||||
// rt_kprintf("discard event %s that is not sent to modal object\n",
|
||||
// event_string[event->type]);
|
||||
}
|
||||
else
|
||||
{
|
||||
_rtgui_application_dest_handle(app, event);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_TIMER:
|
||||
{
|
||||
struct rtgui_timer *timer;
|
||||
struct rtgui_event_timer *etimer = (struct rtgui_event_timer *) event;
|
||||
|
||||
timer = etimer->timer;
|
||||
if (timer->timeout != RT_NULL)
|
||||
{
|
||||
/* call timeout function */
|
||||
timer->timeout(timer, timer->user_data);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_MV_MODEL:
|
||||
{
|
||||
struct rtgui_event_mv_model *emodel = (struct rtgui_event_mv_model *)event;
|
||||
RT_ASSERT(emodel->view);
|
||||
return rtgui_object_handle(RTGUI_OBJECT(emodel->view), event);
|
||||
}
|
||||
|
||||
case RTGUI_EVENT_COMMAND:
|
||||
{
|
||||
struct rtgui_event_command *ecmd = (struct rtgui_event_command *)event;
|
||||
|
||||
if (ecmd->wid != RT_NULL)
|
||||
return _rtgui_application_dest_handle(app, event);
|
||||
}
|
||||
default:
|
||||
return rtgui_object_event_handler(object, event);
|
||||
}
|
||||
|
||||
return RT_TRUE;
|
||||
}
|
||||
|
||||
rt_inline void _rtgui_application_event_loop(struct rtgui_app *app)
|
||||
{
|
||||
rt_err_t result;
|
||||
rt_uint16_t current_ref;
|
||||
struct rtgui_event *event;
|
||||
|
||||
_rtgui_application_check(app);
|
||||
|
||||
/* point to event buffer */
|
||||
event = (struct rtgui_event *)app->event_buffer;
|
||||
|
||||
current_ref = ++app->ref_count;
|
||||
|
||||
while (current_ref <= app->ref_count)
|
||||
{
|
||||
RT_ASSERT(current_ref == app->ref_count);
|
||||
|
||||
if (app->on_idle != RT_NULL)
|
||||
{
|
||||
result = rtgui_recv_nosuspend(event, sizeof(union rtgui_event_generic));
|
||||
if (result == RT_EOK)
|
||||
RTGUI_OBJECT(app)->event_handler(RTGUI_OBJECT(app), event);
|
||||
else if (result == -RT_ETIMEOUT)
|
||||
app->on_idle(RTGUI_OBJECT(app), RT_NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = rtgui_recv(event, sizeof(union rtgui_event_generic));
|
||||
if (result == RT_EOK)
|
||||
RTGUI_OBJECT(app)->event_handler(RTGUI_OBJECT(app), event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rt_base_t rtgui_app_run(struct rtgui_app *app)
|
||||
{
|
||||
_rtgui_application_check(app);
|
||||
|
||||
app->state_flag &= ~RTGUI_APP_FLAG_EXITED;
|
||||
|
||||
_rtgui_application_event_loop(app);
|
||||
|
||||
if (app->ref_count == 0)
|
||||
app->state_flag |= RTGUI_APP_FLAG_EXITED;
|
||||
|
||||
return app->exit_code;
|
||||
}
|
||||
RTM_EXPORT(rtgui_app_run);
|
||||
|
||||
void rtgui_app_exit(struct rtgui_app *app, rt_uint16_t code)
|
||||
{
|
||||
--app->ref_count;
|
||||
app->exit_code = code;
|
||||
}
|
||||
RTM_EXPORT(rtgui_app_exit);
|
||||
|
||||
void rtgui_app_activate(struct rtgui_app *app)
|
||||
{
|
||||
struct rtgui_event_application event;
|
||||
|
||||
RTGUI_EVENT_APP_ACTIVATE_INIT(&event);
|
||||
event.app = app;
|
||||
|
||||
rtgui_send(app, RTGUI_EVENT(&event), sizeof(struct rtgui_event_application));
|
||||
}
|
||||
RTM_EXPORT(rtgui_app_activate);
|
||||
|
||||
void rtgui_app_close(struct rtgui_app *app)
|
||||
{
|
||||
struct rtgui_event_application event;
|
||||
|
||||
RTGUI_EVENT_APP_DESTROY_INIT(&event);
|
||||
event.app = app;
|
||||
|
||||
rtgui_send(app, RTGUI_EVENT(&event), sizeof(struct rtgui_event_application));
|
||||
}
|
||||
RTM_EXPORT(rtgui_app_close);
|
||||
|
||||
/**
|
||||
* set this application as window manager
|
||||
*/
|
||||
rt_err_t rtgui_app_set_as_wm(struct rtgui_app *app)
|
||||
{
|
||||
struct rtgui_app *srv_app;
|
||||
struct rtgui_event_set_wm event;
|
||||
|
||||
_rtgui_application_check(app);
|
||||
|
||||
srv_app = rtgui_get_server();
|
||||
if (srv_app != RT_NULL)
|
||||
{
|
||||
/* notify rtgui server, this is a window manager */
|
||||
RTGUI_EVENT_SET_WM_INIT(&event);
|
||||
event.app = app;
|
||||
|
||||
rtgui_send_sync(srv_app, RTGUI_EVENT(&event), sizeof(event));
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
return RT_ERROR;
|
||||
}
|
||||
RTM_EXPORT(rtgui_app_set_as_wm);
|
||||
|
||||
void rtgui_app_set_main_win(struct rtgui_app *app, struct rtgui_win *win)
|
||||
{
|
||||
|
||||
_rtgui_application_check(app);
|
||||
app->main_object = RTGUI_OBJECT(win);
|
||||
}
|
||||
RTM_EXPORT(rtgui_app_set_main_win);
|
||||
|
||||
@@ -1,454 +0,0 @@
|
||||
/*
|
||||
* File : rtgui_mv_model.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2012, RT-Thread Development Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rt-thread.org/license/LICENSE
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2012-09-15 Grissiom first version
|
||||
*/
|
||||
|
||||
#include <rtgui/rtgui.h>
|
||||
#include <rtgui/rtgui_app.h>
|
||||
#include <rtgui/rtgui_object.h>
|
||||
#include <rtgui/rtgui_system.h>
|
||||
#include <rtgui/rtgui_mv_model.h>
|
||||
#include <rtgui/widgets/mv_view.h>
|
||||
#include <rtgui/widgets/window.h>
|
||||
|
||||
static void _rtgui_mv_model_bare_remove(struct rtgui_mv_model *model, struct rtgui_mv_view *view);
|
||||
static void _rtgui_mv_view_bare_remove(struct rtgui_mv_view *view, struct rtgui_mv_model *model);
|
||||
static rt_bool_t _rtgui_mv_model_notify_view(struct rtgui_mv_model *model,
|
||||
struct rtgui_mv_view *view,
|
||||
struct rtgui_event_mv_model *emodel);
|
||||
|
||||
static void _rtgui_mv_model_constructor(struct rtgui_mv_model *model)
|
||||
{
|
||||
model->dimension = 0;
|
||||
model->length = 0;
|
||||
model->data = RT_NULL;
|
||||
model->view_number = 0;
|
||||
model->view = RT_NULL;
|
||||
|
||||
/* currently not interested in any event */
|
||||
rtgui_object_set_event_handler(RTGUI_OBJECT(model), RT_NULL);
|
||||
}
|
||||
|
||||
static void _rtgui_mv_model_destructor(struct rtgui_mv_model *model)
|
||||
{
|
||||
if (model->view_number == 1)
|
||||
{
|
||||
rtgui_mv_model_remove_view(model, model->view);
|
||||
}
|
||||
else if (model->view_number > 1)
|
||||
{
|
||||
int i;
|
||||
struct rtgui_mv_view **view_arr = (struct rtgui_mv_view **)(model)->view;
|
||||
|
||||
for (i = 0; i < model->view_number; i++)
|
||||
{
|
||||
rtgui_mv_model_remove_view(model, view_arr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (model->dimension > 1)
|
||||
rtgui_free(model->data);
|
||||
}
|
||||
|
||||
DEFINE_CLASS_TYPE(mv_model, "mv_model",
|
||||
RTGUI_OBJECT_TYPE,
|
||||
_rtgui_mv_model_constructor,
|
||||
_rtgui_mv_model_destructor,
|
||||
sizeof(struct rtgui_mv_model));
|
||||
|
||||
struct rtgui_mv_model *rtgui_mv_model_create(rt_uint16_t dimension)
|
||||
{
|
||||
struct rtgui_mv_model *model;
|
||||
|
||||
RT_ASSERT(dimension);
|
||||
|
||||
model = RTGUI_MV_MODEL(rtgui_object_create(RTGUI_MV_MODEL_TYPE));
|
||||
if (model == RT_NULL)
|
||||
return RT_NULL;
|
||||
|
||||
if (rtgui_mv_model_set_dimension(model, dimension) != RT_EOK)
|
||||
{
|
||||
rtgui_object_destroy(RTGUI_OBJECT(model));
|
||||
return RT_NULL;
|
||||
}
|
||||
|
||||
return model;
|
||||
}
|
||||
RTM_EXPORT(rtgui_mv_model_create);
|
||||
|
||||
rt_err_t rtgui_mv_model_set_dimension(struct rtgui_mv_model *model, rt_uint16_t dimension)
|
||||
{
|
||||
if (dimension == 1)
|
||||
{
|
||||
if (model->dimension > 1)
|
||||
rtgui_free(model->data);
|
||||
model->data = RT_NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
void *data;
|
||||
|
||||
if (model->dimension > 1)
|
||||
rtgui_free(model->data);
|
||||
|
||||
data = rtgui_malloc(sizeof(void *)*dimension);
|
||||
|
||||
if (data == RT_NULL)
|
||||
{
|
||||
return -RT_ENOMEM;
|
||||
}
|
||||
|
||||
rt_memset(data, 0, sizeof(void *)*dimension);
|
||||
model->data = data;
|
||||
}
|
||||
model->dimension = dimension;
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
RTM_EXPORT(rtgui_mv_model_set_dimension);
|
||||
|
||||
void rtgui_mv_model_destroy(struct rtgui_mv_model *model)
|
||||
{
|
||||
rtgui_object_destroy(RTGUI_OBJECT(model));
|
||||
}
|
||||
RTM_EXPORT(rtgui_mv_model_destroy);
|
||||
|
||||
rt_err_t rtgui_mv_model_add_view(struct rtgui_mv_model *model, struct rtgui_mv_view *view)
|
||||
{
|
||||
RT_ASSERT(model);
|
||||
|
||||
if (view == RT_NULL)
|
||||
return RT_EOK;
|
||||
|
||||
/* add view to model */
|
||||
if (model->view_number == 0)
|
||||
{
|
||||
model->view = view;
|
||||
}
|
||||
else if (model->view_number == 1)
|
||||
{
|
||||
/* create the array of view pointers */
|
||||
struct rtgui_mv_view **new_view;
|
||||
|
||||
if (view == model->view)
|
||||
return RT_EOK;
|
||||
|
||||
new_view = rtgui_malloc(2 * sizeof(struct rtgui_mv_view *));
|
||||
if (new_view == RT_NULL)
|
||||
return -RT_ENOMEM;
|
||||
|
||||
new_view[0] = model->view;
|
||||
new_view[1] = view;
|
||||
model->view = new_view;
|
||||
}
|
||||
else
|
||||
{
|
||||
int i;
|
||||
struct rtgui_mv_view **new_view;
|
||||
struct rtgui_mv_view **view_arr = (struct rtgui_mv_view **)(model)->view;
|
||||
|
||||
for (i = 0; i < model->view_number; i++)
|
||||
{
|
||||
if (view == view_arr[i])
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
new_view = rtgui_realloc(model->view,
|
||||
(model->view_number + 1) * sizeof(struct rtgui_mv_view *));
|
||||
|
||||
if (new_view == RT_NULL)
|
||||
return -RT_ENOMEM;
|
||||
|
||||
new_view[model->view_number] = view;
|
||||
model->view = new_view;
|
||||
}
|
||||
model->view_number++;
|
||||
|
||||
/* add model to view. Roll back previous action on fail. */
|
||||
if (view->model_number == 0)
|
||||
{
|
||||
view->model = model;
|
||||
}
|
||||
else if (view->model_number == 1)
|
||||
{
|
||||
struct rtgui_mv_model **new_arr = rtgui_malloc(2 * sizeof(struct rtgui_mv_model *));
|
||||
|
||||
if (new_arr == RT_NULL)
|
||||
{
|
||||
_rtgui_mv_model_bare_remove(model, view);
|
||||
return -RT_ENOMEM;
|
||||
}
|
||||
|
||||
new_arr[0] = view->model;
|
||||
new_arr[1] = model;
|
||||
view->model = new_arr;
|
||||
}
|
||||
else
|
||||
{
|
||||
struct rtgui_mv_model **new_arr = rtgui_realloc(view->model,
|
||||
(view->model_number + 1) * sizeof(struct rtgui_mv_model *));
|
||||
|
||||
if (new_arr == RT_NULL)
|
||||
{
|
||||
_rtgui_mv_model_bare_remove(model, view);
|
||||
return -RT_ENOMEM;
|
||||
}
|
||||
|
||||
new_arr[view->model_number] = model;
|
||||
view->model = new_arr;
|
||||
}
|
||||
view->model_number++;
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
RTM_EXPORT(rtgui_mv_model_add_view);
|
||||
|
||||
static void _rtgui_mv_model_bare_remove(struct rtgui_mv_model *model, struct rtgui_mv_view *view)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (model->view_number == 1)
|
||||
{
|
||||
if (model->view == view)
|
||||
{
|
||||
model->view_number--;
|
||||
model->view = RT_NULL;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < model->view_number; i++)
|
||||
{
|
||||
struct rtgui_mv_view **view_arr = (struct rtgui_mv_view **)(model)->view;
|
||||
if (view == view_arr[i])
|
||||
break;
|
||||
}
|
||||
|
||||
/* no match */
|
||||
if (i == model->view_number)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if (model->view_number == 2)
|
||||
{
|
||||
struct rtgui_mv_view **view_arr = (struct rtgui_mv_view **)(model)->view;
|
||||
struct rtgui_mv_view *the_view = view_arr[(i + 1) % 2];
|
||||
rtgui_free(model->view);
|
||||
model->view = the_view;
|
||||
model->view_number--;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
struct rtgui_mv_view **view_arr = (struct rtgui_mv_view **)(model)->view;
|
||||
void *new_view;
|
||||
|
||||
for (; i < model->view_number - 1; i++)
|
||||
{
|
||||
view_arr[i] = view_arr[i + 1];
|
||||
}
|
||||
|
||||
new_view = rtgui_realloc(model->view,
|
||||
(model->view_number - 1) * sizeof(struct rtgui_mv_view *));
|
||||
|
||||
/* no need to be panic on OOM error. The original array is still there
|
||||
* and we can operate it safely. So just ignore the NULL value returned
|
||||
* by realloc. */
|
||||
if (new_view != RT_NULL)
|
||||
model->view = new_view;
|
||||
|
||||
model->view_number--;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static void _rtgui_mv_view_bare_remove(struct rtgui_mv_view *view, struct rtgui_mv_model *model)
|
||||
{
|
||||
int i;
|
||||
struct rtgui_mv_model **model_arr = (struct rtgui_mv_model **)(view)->model;
|
||||
|
||||
if (view->model_number == 1)
|
||||
{
|
||||
if (view->model == model)
|
||||
{
|
||||
view->model_number--;
|
||||
view->model = RT_NULL;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < view->model_number; i++)
|
||||
{
|
||||
if (model == model_arr[i])
|
||||
break;
|
||||
}
|
||||
|
||||
/* no match */
|
||||
if (i == view->model_number)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if (view->model_number == 2)
|
||||
{
|
||||
struct rtgui_mv_model **model_arr = (struct rtgui_mv_model **)(view)->model;
|
||||
struct rtgui_mv_model *the_model = model_arr[(i + 1) % 2];
|
||||
rtgui_free(view->model);
|
||||
view->model = the_model;
|
||||
view->model_number--;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
struct rtgui_mv_model **model_arr = (struct rtgui_mv_model **)(view)->model;
|
||||
void *new_model;
|
||||
|
||||
for (; i < view->model_number - 1; i++)
|
||||
{
|
||||
model_arr[i] = model_arr[i + 1];
|
||||
}
|
||||
|
||||
new_model = rtgui_realloc(view->model,
|
||||
(view->model_number - 1) * sizeof(struct rtgui_mv_model *));
|
||||
|
||||
/* no need to be panic on OOM error. The original array is still there
|
||||
* and we can operate it safely. So just ignore the NULL value returned
|
||||
* by realloc. */
|
||||
if (new_model != RT_NULL)
|
||||
view->model = new_model;
|
||||
|
||||
view->model_number--;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void rtgui_mv_model_remove_view(struct rtgui_mv_model *model, struct rtgui_mv_view *view)
|
||||
{
|
||||
RT_ASSERT(model);
|
||||
|
||||
if (view == RT_NULL)
|
||||
return;
|
||||
|
||||
if (model->length > 0)
|
||||
{
|
||||
struct rtgui_event_mv_model emodel;
|
||||
|
||||
RTGUI_EVENT_MV_MODEL_DELETED_INIT(&emodel);
|
||||
emodel.first_data_changed_idx = 0;
|
||||
emodel.last_data_changed_idx = model->length;
|
||||
|
||||
/* rtgui_mv_model_remove_view is to be called in thread context.
|
||||
* Besides, it is called by _rtgui_mv_view_destructor which means the
|
||||
* view will be invalid in the future. So we should call the event
|
||||
* handler immediately. */
|
||||
RTGUI_OBJECT(view)->event_handler(RTGUI_OBJECT(view), (struct rtgui_event *)&emodel);
|
||||
}
|
||||
|
||||
_rtgui_mv_model_bare_remove(model, view);
|
||||
_rtgui_mv_view_bare_remove(view, model);
|
||||
}
|
||||
RTM_EXPORT(rtgui_mv_model_remove_view);
|
||||
|
||||
rt_bool_t rtgui_mv_model_has_view(struct rtgui_mv_model *model, struct rtgui_mv_view *view)
|
||||
{
|
||||
RT_ASSERT(model);
|
||||
|
||||
if (view == RT_NULL || model->view_number == 0)
|
||||
return RT_FALSE;
|
||||
|
||||
if (model->view_number == 1)
|
||||
{
|
||||
return model->view == view;
|
||||
}
|
||||
else
|
||||
{
|
||||
int i;
|
||||
struct rtgui_mv_view **view_arr = (struct rtgui_mv_view **)(model)->view;
|
||||
|
||||
for (i = 0; i < model->view_number; i++)
|
||||
{
|
||||
if (view == view_arr[i])
|
||||
return RT_TRUE;
|
||||
}
|
||||
return RT_FALSE;
|
||||
}
|
||||
}
|
||||
RTM_EXPORT(rtgui_mv_model_has_view);
|
||||
|
||||
void rtgui_mv_model_set_data(struct rtgui_mv_model *model, rt_uint16_t dim, void *p)
|
||||
{
|
||||
RT_ASSERT(model);
|
||||
RT_ASSERT(dim < model->dimension);
|
||||
|
||||
if (model->dimension == 1)
|
||||
{
|
||||
model->data = p;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
void **d_arr = (void **)model->data;
|
||||
d_arr[dim] = p;
|
||||
}
|
||||
}
|
||||
RTM_EXPORT(rtgui_mv_model_set_data);
|
||||
|
||||
void *rtgui_mv_model_get_data(struct rtgui_mv_model *model, rt_uint16_t dim)
|
||||
{
|
||||
RT_ASSERT(model);
|
||||
RT_ASSERT(dim < model->dimension);
|
||||
|
||||
if (model->dimension == 1)
|
||||
{
|
||||
return model->data;
|
||||
}
|
||||
else
|
||||
{
|
||||
void **d_arr = (void **)model->data;
|
||||
return d_arr[dim];
|
||||
}
|
||||
}
|
||||
RTM_EXPORT(rtgui_mv_model_get_data);
|
||||
|
||||
static rt_bool_t _rtgui_mv_model_notify_view(struct rtgui_mv_model *model,
|
||||
struct rtgui_mv_view *view,
|
||||
struct rtgui_event_mv_model *emodel)
|
||||
{
|
||||
struct rtgui_app *target = RTGUI_WIDGET(view)->toplevel->app;
|
||||
emodel->model = model;
|
||||
emodel->view = view;
|
||||
return rtgui_send(target, (struct rtgui_event *)emodel, sizeof(*emodel));
|
||||
}
|
||||
|
||||
void rtgui_mv_model_notify(struct rtgui_mv_model *model,
|
||||
struct rtgui_event_mv_model *em)
|
||||
{
|
||||
/* model and view may not be in the same thread. Actually, model may not
|
||||
* belong to any RTGUI thread. So we have to notify the views by sending
|
||||
* events to the thread directly. */
|
||||
|
||||
if (model->view_number == 1)
|
||||
{
|
||||
struct rtgui_mv_view *view = (struct rtgui_mv_view *)model->view;
|
||||
_rtgui_mv_model_notify_view(model, view, em);
|
||||
}
|
||||
else
|
||||
{
|
||||
int i;
|
||||
struct rtgui_mv_view **view_arr = (struct rtgui_mv_view **)(model)->view;
|
||||
for (i = 0; i < model->view_number; i++)
|
||||
{
|
||||
_rtgui_mv_model_notify_view(model, view_arr[i], em);
|
||||
}
|
||||
}
|
||||
}
|
||||
RTM_EXPORT(rtgui_mv_model_notify);
|
||||
|
||||
@@ -1,207 +0,0 @@
|
||||
/*
|
||||
* File : rtgui_object.c
|
||||
* This file is part of RTGUI in RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rt-thread.org/license/LICENSE
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2009-10-04 Bernard first version
|
||||
*/
|
||||
|
||||
#include <rtgui/rtgui_object.h>
|
||||
#include <rtgui/rtgui_system.h>
|
||||
|
||||
static void _rtgui_object_constructor(rtgui_object_t *object)
|
||||
{
|
||||
if (!object)
|
||||
return;
|
||||
|
||||
object->flag = RTGUI_OBJECT_FLAG_NONE;
|
||||
}
|
||||
|
||||
/* Destroys the object */
|
||||
static void _rtgui_object_destructor(rtgui_object_t *object)
|
||||
{
|
||||
/* nothing */
|
||||
}
|
||||
|
||||
DEFINE_CLASS_TYPE(object, "object",
|
||||
RT_NULL,
|
||||
_rtgui_object_constructor,
|
||||
_rtgui_object_destructor,
|
||||
sizeof(struct rtgui_object));
|
||||
RTM_EXPORT(_rtgui_object);
|
||||
|
||||
void rtgui_type_object_construct(const rtgui_type_t *type, rtgui_object_t *object)
|
||||
{
|
||||
/* first call parent's type */
|
||||
if (type->parent != RT_NULL)
|
||||
rtgui_type_object_construct(type->parent, object);
|
||||
|
||||
if (type->constructor) type->constructor(object);
|
||||
}
|
||||
|
||||
void rtgui_type_destructors_call(const rtgui_type_t *type, rtgui_object_t *object)
|
||||
{
|
||||
const rtgui_type_t *t;
|
||||
|
||||
t = type;
|
||||
while (t)
|
||||
{
|
||||
if (t->destructor) t->destructor(object);
|
||||
t = t->parent;
|
||||
}
|
||||
}
|
||||
|
||||
rt_bool_t rtgui_type_inherits_from(const rtgui_type_t *type, const rtgui_type_t *parent)
|
||||
{
|
||||
const rtgui_type_t *t;
|
||||
|
||||
t = type;
|
||||
while (t)
|
||||
{
|
||||
if (t == parent) return RT_TRUE;
|
||||
t = t->parent;
|
||||
}
|
||||
|
||||
return RT_FALSE;
|
||||
}
|
||||
|
||||
const rtgui_type_t *rtgui_type_parent_type_get(const rtgui_type_t *type)
|
||||
{
|
||||
return type->parent;
|
||||
}
|
||||
|
||||
const char *rtgui_type_name_get(const rtgui_type_t *type)
|
||||
{
|
||||
if (!type) return RT_NULL;
|
||||
|
||||
return type->name;
|
||||
}
|
||||
|
||||
#ifdef RTGUI_OBJECT_TRACE
|
||||
struct rtgui_object_information
|
||||
{
|
||||
rt_uint32_t objs_number;
|
||||
rt_uint32_t allocated_size;
|
||||
rt_uint32_t max_allocated;
|
||||
};
|
||||
struct rtgui_object_information obj_info = {0, 0, 0};
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Creates a new object: it calls the corresponding constructors
|
||||
* (from the constructor of the base class to the constructor of the more
|
||||
* derived class) and then sets the values of the given properties
|
||||
*
|
||||
* @param object_type the type of object to create
|
||||
* @return the created object
|
||||
*/
|
||||
rtgui_object_t *rtgui_object_create(rtgui_type_t *object_type)
|
||||
{
|
||||
rtgui_object_t *new_object;
|
||||
|
||||
if (!object_type)
|
||||
return RT_NULL;
|
||||
|
||||
new_object = rtgui_malloc(object_type->size);
|
||||
if (new_object == RT_NULL) return RT_NULL;
|
||||
|
||||
#ifdef RTGUI_OBJECT_TRACE
|
||||
obj_info.objs_number ++;
|
||||
obj_info.allocated_size += object_type->size;
|
||||
if (obj_info.allocated_size > obj_info.max_allocated)
|
||||
obj_info.max_allocated = obj_info.allocated_size;
|
||||
#endif
|
||||
|
||||
new_object->type = object_type;
|
||||
|
||||
rtgui_type_object_construct(object_type, new_object);
|
||||
|
||||
return new_object;
|
||||
}
|
||||
RTM_EXPORT(rtgui_object_create);
|
||||
|
||||
/**
|
||||
* @brief Destroys the object.
|
||||
*
|
||||
* The object destructors will be called in inherited type order.
|
||||
*
|
||||
* @param object the object to destroy
|
||||
*/
|
||||
void rtgui_object_destroy(rtgui_object_t *object)
|
||||
{
|
||||
if (!object || object->flag & RTGUI_OBJECT_FLAG_STATIC)
|
||||
return;
|
||||
|
||||
#ifdef RTGUI_OBJECT_TRACE
|
||||
obj_info.objs_number --;
|
||||
obj_info.allocated_size -= object->type->size;
|
||||
#endif
|
||||
|
||||
/* call destructor */
|
||||
RT_ASSERT(object->type != RT_NULL);
|
||||
rtgui_type_destructors_call(object->type, object);
|
||||
|
||||
/* release object */
|
||||
rtgui_free(object);
|
||||
}
|
||||
RTM_EXPORT(rtgui_object_destroy);
|
||||
|
||||
/**
|
||||
* @brief Checks if the object can be cast to the specified type.
|
||||
*
|
||||
* If the object doesn't inherit from the specified type, a warning
|
||||
* is displayed in the console but the object is returned anyway.
|
||||
*
|
||||
* @param object the object to cast
|
||||
* @param type the type to which we cast the object
|
||||
* @return Returns the object
|
||||
*/
|
||||
rtgui_object_t *rtgui_object_check_cast(rtgui_object_t *obj, rtgui_type_t *obj_type, const char *func, int line)
|
||||
{
|
||||
if (!obj) return RT_NULL;
|
||||
|
||||
if (!rtgui_type_inherits_from(obj->type, obj_type))
|
||||
{
|
||||
rt_kprintf("%s[%d]: Invalid cast from \"%s\" to \"%s\"\n", func, line,
|
||||
rtgui_type_name_get(obj->type), rtgui_type_name_get(obj_type));
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
RTM_EXPORT(rtgui_object_check_cast);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Gets the type of the object
|
||||
*
|
||||
* @param object an object
|
||||
* @return the type of the object (RT_NULL on failure)
|
||||
*/
|
||||
const rtgui_type_t *rtgui_object_object_type_get(rtgui_object_t *object)
|
||||
{
|
||||
if (!object) return RT_NULL;
|
||||
|
||||
return object->type;
|
||||
}
|
||||
RTM_EXPORT(rtgui_object_object_type_get);
|
||||
|
||||
void rtgui_object_set_event_handler(struct rtgui_object *object, rtgui_event_handler_ptr handler)
|
||||
{
|
||||
RT_ASSERT(object != RT_NULL);
|
||||
|
||||
object->event_handler = handler;
|
||||
}
|
||||
RTM_EXPORT(rtgui_object_set_event_handler);
|
||||
|
||||
rt_bool_t rtgui_object_event_handler(struct rtgui_object *object, struct rtgui_event *event)
|
||||
{
|
||||
return RT_FALSE;
|
||||
}
|
||||
RTM_EXPORT(rtgui_object_event_handler);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,294 +0,0 @@
|
||||
#include <rtgui/rtgui_xml.h>
|
||||
#include <rtgui/rtgui_system.h>
|
||||
|
||||
/* Internal states that the parser can be in at any given time. */
|
||||
enum
|
||||
{
|
||||
STAT_START = 0, /* starting base state, default state */
|
||||
STAT_TEXT, /* text state */
|
||||
STAT_START_TAG, /* start tag state */
|
||||
STAT_START_TAGNAME, /* start tagname state */
|
||||
STAT_START_TAGNAME_END, /* start tagname ending state */
|
||||
STAT_END_TAG, /* end tag state */
|
||||
STAT_END_TAGNAME, /* end tag tagname state */
|
||||
STAT_END_TAGNAME_END, /* end tag tagname ending */
|
||||
STAT_EMPTY_TAG, /* empty tag state */
|
||||
STAT_SPACE, /* linear whitespace state */
|
||||
STAT_ATTR_NAME, /* attribute name state */
|
||||
STAT_ATTR_NAME_END, /* attribute name ending state */
|
||||
STAT_ATTR_VAL, /* attribute value starting state */
|
||||
STAT_ATTR_VAL2, /* attribute value state */
|
||||
STAT_ERROR /* error state */
|
||||
};
|
||||
|
||||
/* character classes that we will match against; This could be expanded if
|
||||
need be, however, we are aiming for simple. */
|
||||
enum
|
||||
{
|
||||
CLASS_TYPE_NONE = 0, /* matches nothing, a base state */
|
||||
CLASS_TYPE_LEFT_ANGLE, /* matches start tag '<' */
|
||||
CLASS_TYPE_SLASH, /* matches forward slash */
|
||||
CLASS_TYPE_RIGHT_ANGLE, /* matches end tag '>' */
|
||||
CLASS_TYPE_EQUALS, /* matches equals sign */
|
||||
CLASS_TYPE_QUOTE, /* matches double-quotes */
|
||||
CLASS_TYPE_LETTERS, /* matches a-zA-Z letters and digits 0-9 */
|
||||
CLASS_TYPE_SPACE, /* matches whitespace */
|
||||
CLASS_TYPE_ANY /* matches any ASCII character; will match all
|
||||
above classes */
|
||||
};
|
||||
|
||||
/* xml state transition table */
|
||||
struct rtgui_xml_state
|
||||
{
|
||||
rt_uint8_t state;
|
||||
rt_uint8_t class_type;
|
||||
rt_uint8_t next_state;
|
||||
rt_uint8_t event;
|
||||
};
|
||||
|
||||
/* Note: States must be grouped in match order AND grouped together! */
|
||||
static const struct rtgui_xml_state RTGUI_XML_STATES [] =
|
||||
{
|
||||
/* [0-2] starting state, which also serves as the default state in case
|
||||
of error */
|
||||
{ STAT_START, CLASS_TYPE_SPACE, STAT_SPACE, EVENT_NONE },
|
||||
{ STAT_START, CLASS_TYPE_LEFT_ANGLE, STAT_START_TAG, EVENT_NONE },
|
||||
{ STAT_START, CLASS_TYPE_ANY, STAT_TEXT, EVENT_COPY },
|
||||
|
||||
/* [3-5] space state handles linear white space */
|
||||
{ STAT_SPACE, CLASS_TYPE_SPACE, STAT_SPACE, EVENT_NONE },
|
||||
{ STAT_SPACE, CLASS_TYPE_LEFT_ANGLE, STAT_START_TAG, EVENT_TEXT },
|
||||
{ STAT_SPACE, CLASS_TYPE_ANY, STAT_TEXT, EVENT_COPY },
|
||||
|
||||
/* [6-8] handle start tag */
|
||||
{ STAT_START_TAG, CLASS_TYPE_LETTERS, STAT_START_TAGNAME, EVENT_COPY },
|
||||
{ STAT_START_TAG, CLASS_TYPE_SLASH, STAT_END_TAG, EVENT_COPY },
|
||||
/* below added since some individuals get a little carried away with
|
||||
spacing around tag names, e.g. < tag > */
|
||||
{ STAT_START_TAG, CLASS_TYPE_SPACE, STAT_START_TAG, EVENT_NONE },
|
||||
|
||||
/* [9-12] handle start tag name */
|
||||
{ STAT_START_TAGNAME, CLASS_TYPE_LETTERS, STAT_START_TAGNAME, EVENT_NONE },
|
||||
{ STAT_START_TAGNAME, CLASS_TYPE_SPACE, STAT_START_TAGNAME_END, EVENT_START },
|
||||
/* below added for tags without any space between tag and ending
|
||||
slash, e.g., <br/> */
|
||||
{ STAT_START_TAGNAME, CLASS_TYPE_SLASH, STAT_EMPTY_TAG, EVENT_END },
|
||||
{ STAT_START_TAGNAME, CLASS_TYPE_RIGHT_ANGLE, STAT_START, EVENT_START },
|
||||
|
||||
/* [13-16] handle start tag name end */
|
||||
{ STAT_START_TAGNAME_END, CLASS_TYPE_LETTERS, STAT_ATTR_NAME, EVENT_COPY },
|
||||
/* below added to handle additional space in between attribute value
|
||||
pairs in start tags, e.g., <tag attr="2" attr2="test" > */
|
||||
{ STAT_START_TAGNAME_END, CLASS_TYPE_SPACE, STAT_START_TAGNAME_END, EVENT_NONE },
|
||||
{ STAT_START_TAGNAME_END, CLASS_TYPE_RIGHT_ANGLE, STAT_START, EVENT_START },
|
||||
/* below supports tags that are self-closing, e.g., <br /> */
|
||||
{ STAT_START_TAGNAME_END, CLASS_TYPE_SLASH, STAT_EMPTY_TAG, EVENT_COPY },
|
||||
|
||||
/* [17] handle empty tags, e.g., <br /> */
|
||||
{ STAT_EMPTY_TAG, CLASS_TYPE_RIGHT_ANGLE, STAT_START, EVENT_END },
|
||||
|
||||
/* [18] handle end tag, e.g., <tag /> */
|
||||
{ STAT_END_TAG, CLASS_TYPE_LETTERS, STAT_END_TAGNAME, EVENT_NONE },
|
||||
|
||||
/* [19-21] handle end tag name */
|
||||
{ STAT_END_TAGNAME, CLASS_TYPE_LETTERS, STAT_END_TAGNAME, EVENT_NONE },
|
||||
{ STAT_END_TAGNAME, CLASS_TYPE_RIGHT_ANGLE, STAT_START, EVENT_END },
|
||||
/* below adds support for spaces at the end of an end tag (before
|
||||
closing bracket) */
|
||||
{ STAT_END_TAGNAME, CLASS_TYPE_SPACE, STAT_END_TAGNAME_END, EVENT_END },
|
||||
|
||||
/* [22] handle ending of end tag name */
|
||||
{ STAT_END_TAGNAME_END, CLASS_TYPE_SPACE, STAT_END_TAGNAME_END, EVENT_NONE },
|
||||
{ STAT_END_TAGNAME_END, CLASS_TYPE_RIGHT_ANGLE, STAT_START, EVENT_NONE },
|
||||
|
||||
/* [23-25] handle text */
|
||||
{ STAT_TEXT, CLASS_TYPE_SPACE, STAT_SPACE, EVENT_NONE },
|
||||
{ STAT_TEXT, CLASS_TYPE_LEFT_ANGLE, STAT_START_TAG, EVENT_TEXT },
|
||||
{ STAT_TEXT, CLASS_TYPE_ANY, STAT_TEXT, EVENT_NONE },
|
||||
|
||||
/* [26-30] handle attribute names */
|
||||
{ STAT_ATTR_NAME, CLASS_TYPE_LETTERS, STAT_ATTR_NAME, EVENT_COPY },
|
||||
/* below add support for space before the equals sign, e.g, <tag
|
||||
attr ="2"> */
|
||||
{ STAT_ATTR_NAME, CLASS_TYPE_SPACE, STAT_ATTR_NAME_END, EVENT_NAME },
|
||||
{ STAT_ATTR_NAME, CLASS_TYPE_EQUALS, STAT_ATTR_VAL, EVENT_NAME },
|
||||
|
||||
/* [31-33] attribute name end */
|
||||
{ STAT_ATTR_NAME_END, CLASS_TYPE_SPACE, STAT_ATTR_NAME_END, EVENT_NONE },
|
||||
{ STAT_ATTR_NAME_END, CLASS_TYPE_LETTERS, STAT_ATTR_NAME, EVENT_COPY },
|
||||
{ STAT_ATTR_NAME_END, CLASS_TYPE_EQUALS, STAT_ATTR_VAL, EVENT_NONE },
|
||||
|
||||
/* [34-35] handle attribute values, initial quote and spaces */
|
||||
{ STAT_ATTR_VAL, CLASS_TYPE_QUOTE, STAT_ATTR_VAL2, EVENT_NONE },
|
||||
/* below handles initial spaces before quoted attribute value */
|
||||
{ STAT_ATTR_VAL, CLASS_TYPE_SPACE, STAT_ATTR_VAL, EVENT_NONE },
|
||||
|
||||
/* [36-37] handle actual attribute values */
|
||||
{ STAT_ATTR_VAL2, CLASS_TYPE_QUOTE, STAT_START_TAGNAME_END, EVENT_VAL },
|
||||
{ STAT_ATTR_VAL2, CLASS_TYPE_LETTERS, STAT_ATTR_VAL2, EVENT_COPY },
|
||||
{ STAT_ATTR_VAL2, CLASS_TYPE_SLASH, STAT_ATTR_VAL2, EVENT_NONE },
|
||||
|
||||
/* End of table marker */
|
||||
{ STAT_ERROR, CLASS_TYPE_NONE, STAT_ERROR, EVENT_NONE }
|
||||
};
|
||||
|
||||
struct rtgui_xml
|
||||
{
|
||||
/* event handler */
|
||||
rtgui_xml_event_handler_t event_handler;
|
||||
void *user;
|
||||
|
||||
char *buffer; /* xml buffer */
|
||||
rt_size_t buffer_size; /* buffer size */
|
||||
rt_size_t position; /* current position in buffer */
|
||||
rt_uint16_t state, event; /* current state and event */
|
||||
|
||||
rt_bool_t copy; /* copy text into tmp buffer */
|
||||
rt_bool_t halt; /* halt parsing of document */
|
||||
};
|
||||
|
||||
rtgui_xml_t *rtgui_xml_create(rt_size_t buffer_size, rtgui_xml_event_handler_t handler,
|
||||
void *user)
|
||||
{
|
||||
rtgui_xml_t *xml = (rtgui_xml_t *) rtgui_malloc(sizeof(struct rtgui_xml));
|
||||
rt_memset(xml, 0, sizeof(rtgui_xml_t));
|
||||
|
||||
xml->event_handler = handler;
|
||||
xml->user = user;
|
||||
|
||||
/* create buffer */
|
||||
xml->buffer_size = buffer_size;
|
||||
xml->buffer = (char *)rtgui_malloc(xml->buffer_size);
|
||||
return xml;
|
||||
}
|
||||
|
||||
void rtgui_xml_destroy(rtgui_xml_t *xml)
|
||||
{
|
||||
if (xml)
|
||||
{
|
||||
rtgui_free(xml->buffer);
|
||||
rtgui_free(xml);
|
||||
}
|
||||
}
|
||||
|
||||
const char *rtgui_xml_event_str(rt_uint8_t event)
|
||||
{
|
||||
switch (event)
|
||||
{
|
||||
case EVENT_START:
|
||||
return "start tag";
|
||||
case EVENT_END:
|
||||
return "end tag";
|
||||
case EVENT_TEXT:
|
||||
return "text";
|
||||
case EVENT_NAME:
|
||||
return "attr name";
|
||||
case EVENT_VAL:
|
||||
return "attr val";
|
||||
case EVENT_END_DOC:
|
||||
return "end document";
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return "err";
|
||||
}
|
||||
|
||||
int rtgui_xml_parse(rtgui_xml_t *xml, const char *buf, rt_size_t len)
|
||||
{
|
||||
int i, j, c, match;
|
||||
|
||||
#define is_space(ch) \
|
||||
((rt_uint32_t)(ch - 9) < 5u || ch == ' ')
|
||||
#define is_alpha(ch) \
|
||||
((rt_uint32_t)((ch | 0x20) - 'a') < 26u)
|
||||
#define is_digit(ch) \
|
||||
((rt_uint32_t)(ch - '0') < 10u)
|
||||
#define is_letters(ch) \
|
||||
(is_alpha(ch) || is_digit(ch) || (ch == '.'))
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
if (xml->halt) break;
|
||||
|
||||
c = buf[i] & 0xff;
|
||||
|
||||
/* search in state table */
|
||||
for (j = 0, match = 0; RTGUI_XML_STATES[j].state != STAT_ERROR; j++)
|
||||
{
|
||||
if (RTGUI_XML_STATES[j].state != xml->state)
|
||||
continue;
|
||||
|
||||
switch (RTGUI_XML_STATES[j].class_type)
|
||||
{
|
||||
case CLASS_TYPE_LETTERS:
|
||||
match = is_letters(c);
|
||||
break;
|
||||
case CLASS_TYPE_LEFT_ANGLE:
|
||||
match = (c == '<');
|
||||
break;
|
||||
case CLASS_TYPE_SLASH:
|
||||
match = (c == '/');
|
||||
break;
|
||||
case CLASS_TYPE_RIGHT_ANGLE:
|
||||
match = (c == '>');
|
||||
break;
|
||||
case CLASS_TYPE_EQUALS:
|
||||
match = (c == '=');
|
||||
break;
|
||||
case CLASS_TYPE_QUOTE:
|
||||
match = (c == '"');
|
||||
break;
|
||||
case CLASS_TYPE_SPACE:
|
||||
match = is_space(c);
|
||||
break;
|
||||
case CLASS_TYPE_ANY:
|
||||
match = 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
/* we matched a character class */
|
||||
if (match)
|
||||
{
|
||||
if (RTGUI_XML_STATES[j].event == EVENT_COPY)
|
||||
{
|
||||
xml->copy = RT_TRUE;
|
||||
}
|
||||
else if (RTGUI_XML_STATES[j].event != EVENT_NONE)
|
||||
{
|
||||
if (xml->copy == RT_TRUE)
|
||||
{
|
||||
/* basically we are guaranteed never to have an event of
|
||||
type EVENT_COPY or EVENT_NONE here. */
|
||||
xml->event = RTGUI_XML_STATES[j].event;
|
||||
xml->buffer[xml->position] = 0; /* make a string */
|
||||
|
||||
if (!xml->event_handler(RTGUI_XML_STATES[j].event,
|
||||
xml->buffer, xml->position ,
|
||||
xml->user))
|
||||
{
|
||||
xml->halt = 1; /* stop parsing from here out */
|
||||
}
|
||||
xml->position = 0;
|
||||
xml->copy = RT_FALSE;
|
||||
}
|
||||
}
|
||||
if (xml->copy == RT_TRUE)
|
||||
{
|
||||
/* check to see if we have room; one less for trailing
|
||||
nul */
|
||||
if (xml->position < xml->buffer_size - 1)
|
||||
{
|
||||
xml->buffer[xml->position] = buf[i];
|
||||
xml->position++;
|
||||
}
|
||||
}
|
||||
xml->state = RTGUI_XML_STATES[j].next_state; /* change state */
|
||||
break; /* break out of loop though state search */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return !xml->halt;
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
RTGUI 0.6版发布纪要
|
||||
|
||||
# 为什么是 0.6?
|
||||
|
||||
RTGUI 是作为 RT-Thread 的一个组件存在的。这次新发布的版本是在原 RTGUI 基础上重
|
||||
构而来的。原 RTGUI 没有独立的版本号。暂设其为 0.5。所以本版本号取 0.6,为在原有
|
||||
基础上改进之意。以后我们会每个月发布一个新版本。下一个版本号会是 0.6.1。
|
||||
|
||||
# 运行环境
|
||||
|
||||
理论上原来可以运行 RTGUI 的设备上都可以运行新的 RTGUI。本版本自带一个 Windows
|
||||
模拟器,用来方便地评估运行效果。默认的运行环境是 realtouch。RT-Thread 中的模拟
|
||||
器也是可以运作的。
|
||||
|
||||
# 新版本有什么特点?
|
||||
|
||||
0. 新版本的 GUI 摒弃了原有的 workbench/view/window 的工作方式。转换成全面向
|
||||
window的工作方式。原有的 workbench/view 可以用 notebook 来实现。
|
||||
0. 用 `rtgui_app` 对线程进行了抽象。
|
||||
0. 事件驱动更彻底:
|
||||
0. 将事件处理机制集成进 `rtgui_object`。
|
||||
0. 添加了`RTGUI_EVENT_SHOW` 和 `RTGUI_EVENT_HIDE` 来通知控件将要被显示/隐藏。
|
||||
0. 底层代码中对事件的应用更加彻底。
|
||||
0. 重构了自动布局方式。使得控件的摆放更加方便。
|
||||
|
||||
# 增强
|
||||
|
||||
- 添加了 TJPGD 引擎。使得小内存系统解码 jpeg 图片成为可能。(onelife)
|
||||
- 添加了对单色屏的支持(onelife)
|
||||
- bmp 图像引擎的重构(onelife)
|
||||
- bmp 图像的旋转/缩放,以及功能性增强(amsl)
|
||||
- 增加屏幕快照功能(amsl)
|
||||
- PNG 引擎增加 Alpha 通道支持(amsl)
|
||||
- 新增 edit 多行文本编辑控件。(amsl)
|
||||
- 增加了 Model/View 的编程框架。(Grissiom)
|
||||
- 添加了缩减字库的特性,开启后可以自动添加用到的汉字,不用的汉字字形不会加入到
|
||||
字库当中。使得 GUI 能够在小 ROM 系统上得以应用。(Grissiom)
|
||||
- 新增 digtube 七段码显示控件(prife)
|
||||
- demo/benchmark 新增了 FPS 输出(amsl)
|
||||
- 新增 box/panel/groupbox,支持自动布局(Bernard)
|
||||
|
||||
# API 变化
|
||||
|
||||
除了 workbench/view 的消失以外,还有如下的 API 变化:
|
||||
|
||||
- c05a301, 68e3e30: `rtgui_{menu,win}_hiden` 被重命名为 `rtgui_{menu,win}_hide`。
|
||||
- 05e4894: 将 `struct rtgui_widget` 中的 `mini_{height,width}` 重命名为 `min_{height,width}`。
|
||||
- 等等……
|
||||
|
||||
今后很长时间内,新版本的 RTGUI 会与此版本的 API 尽量只增不减,保持兼容。
|
||||
|
||||
# Bug fixes
|
||||
|
||||
- 00a6690: 解决了 `rtgui_notebook_set_current_by_index` 中重绘标签页的 bug。感
|
||||
谢 prife 提交 bug 信息和补丁。
|
||||
- 6850ff2: 解决了 `last_mevent_widget` 引起的事件传送失败。感谢 heryon 提交bug
|
||||
报告。
|
||||
- 9143e11: 解决了 jpeg 引擎中的内存泄漏。感谢 Young 提供 bug 信息。
|
||||
- fbd567c: 解决了 `rtgui_textbox_set_line_length` 的 bug。
|
||||
- 9b67b66: 修复了窗口标题栏渐变效果的绘制。
|
||||
- fc3abbf: 修复了 `rtgui_label_set_text`。感谢 tanghong668 提供 bug 信息。
|
||||
- d41586c: 修复了窗口激活时重复刷新的问题。感谢 onelife 提供 bug 信息。
|
||||
- ab08de6: 修复了字库缓存的 bug。感谢 rtt\_fans 提供 bug 信息。
|
||||
- 等等……
|
||||
|
||||
除了上面提到的,luoyuncong2012, lgnq, shaolin 也有贡献。上面的列表也必然是不完
|
||||
整的。感谢编写了第一版 RTGUI 的 Bernard 和其他大侠们,没有他们的辛勤劳动,也不
|
||||
会有今天的版本。感谢各位使用和支持RTGUI的开发人员,是你们 RTGUI 体现了 RTGUI 的
|
||||
价值。
|
||||
@@ -1,18 +0,0 @@
|
||||
1, 对同一 window 销毁两次会引起 segfault。同时,如果在创建时设置了
|
||||
RTGUI_WIN_STYLE_DESTROY_ON_CLOSE,close 窗口之后不要再去销毁窗口。
|
||||
|
||||
2, 所有的 window 由 topwin 进行管理,用户不要在指定创建具有父窗口的子窗口之后在
|
||||
把这个窗口加为父窗口的 child。这可能会导致子窗口无法显示。
|
||||
|
||||
3, command 事件添加了 wid 参数,用于指定此事件需要传递的目标窗口。
|
||||
|
||||
4, 在 widget 中添加了 on_show 和 on_hide 事件回调函数。他们会在控件显示/隐藏的
|
||||
时候被调用。
|
||||
|
||||
5, slider 控件改为左键减小数值,右键增加数值。横向的 slider 处理左右键,纵向的
|
||||
slider 处理上下键,上面的值小,下面的值大。
|
||||
|
||||
6, view 不再提供 show 方法。如果想单独显示控件,请用 window 包含之。
|
||||
|
||||
7, 若窗口在销毁(destroy)时没有关闭,则 RTGUI 会先关闭之。也会调用 on_close 函数
|
||||
但是此函数的返回值会被忽略。
|
||||
@@ -1,70 +0,0 @@
|
||||
RTGUI for 1.1 路线图(排名不分先后)
|
||||
1, 把 rtgui_thread 给去掉,变成 rtgui_application ,消除原来的 rtgui_thread +
|
||||
mq 的模式。rtgui_application 记录当前依附的 panel,和 panel 的 extent。(Done)
|
||||
1.1, rtgui_application_run 运行主事件循环(Done)
|
||||
1.2, rtgui_application 作为事件的接收者_和_事件派发者。(Done)
|
||||
|
||||
2, workbench,window并成一个,其事件主循环并合并到rtgui_application中。
|
||||
2.1, window 作为有标题栏的 workbench(Done)
|
||||
2.2, 将其事件主循环移至 application 中。(Done)
|
||||
2.3, 将 window 的父类 toplevel 合并进 window 中。所有直接与服务器打交道的从
|
||||
window 继承。(或者将 toplevel 合并进 application 中,因为只有 application 才
|
||||
会和服务器打交道。)
|
||||
2.4 在创建 window 的时候需要指定 parent,如果为 RT_NULL,则此 window 为 root
|
||||
窗口,parent 为当前 rtgui_application。每一个 application 必须有且只有一个根
|
||||
窗口。(Done)
|
||||
2.5 添加一个 FULL_PANEL 的 STYLE。指定此 STYLE 之后会自动填满整个 panel。其
|
||||
与 NO_TITLE 之类的合用可以达到之前 workbench 的效果。(Deprecated)
|
||||
2.6 event_loop 可以设定顶层控件,只会把事件传递给顶层控件。这样可以方便的实
|
||||
现模态窗口。event_loop 靠 object 的一个标志位来判断是否要退出当前循环。(Done)
|
||||
|
||||
3, 将 view 合并进 container,所有容器类继承 container。[note1](Done)
|
||||
|
||||
4, 事件循环完成后不主动销毁控件,销毁任务交由用户完成。但是有些自动销毁是必要的
|
||||
,比如 container 自动销毁其包含的控件(Done)
|
||||
4.1 对于 window 的 onclose事件,保证在其回调函数中可以(但不是必须)安全销毁窗
|
||||
口。这个功能不保证能够实现。(onclose 是在将要关闭窗口的时候触发的,调用它之
|
||||
后 RTGUI 还要进行其他的设置和清理工作,所以不能在 onclose 里销毁窗口)(Cannot
|
||||
Implement)
|
||||
4.2 对 window 添加 RTGUI_WIN_STYLE_DESTROY_ON_CLOSE 。使得其在被关闭时自动销
|
||||
毁。注意:对同一 window 销毁两次会引起 segfault。同时,如果在创建时设置了
|
||||
RTGUI_WIN_STYLE_DESTROY_ON_CLOSE,close 窗口之后不要再去销毁窗口。
|
||||
|
||||
5, API 清理。更详细的文档。
|
||||
|
||||
6, 使 panel 退化为无窗口标题的 window,这样 server 就只记录 window 一种东西的位
|
||||
置。(Done, 删除了 panel,使得整体以 window 为主)
|
||||
|
||||
7, 指定名称的时候不再自己拷贝一份。(我觉得 90% 的情况下名称都是静态的字符串,这
|
||||
时用 strdup其实并没有必要。)(Deprecated)
|
||||
|
||||
8, 添加一些工业控制当中用到的波形、仪表之类的控件。
|
||||
|
||||
9, 在 window 中记录焦点控件,键盘事件由 window 直接投送。各个控件不记录焦点控件
|
||||
。(Done)
|
||||
|
||||
10, 在 widget 中添加 on_show 和 on_hide 事件回调函数。(Done)
|
||||
|
||||
11, 添加 EVENT_WIN_MODAL_ENTER 和 EVENT_WIN_MODAL_EXIT 事件,用来通知窗口管理器
|
||||
(topwin)一个窗口进入模态。窗口管理器根据这个进行相应的设置。(Done)
|
||||
|
||||
12, rtgui_filelist_view 不必继承自 container。(Deprecated)
|
||||
|
||||
13, 添加 desktop window 支持。(Done)
|
||||
概念与名词:
|
||||
13.1 desktop window:最底层的桌面窗口。它会在所有窗口下面显示,并且不会被它
|
||||
上面的窗口模态掉。它的子窗口是 root window。(继承关系由 RTGUI 管理,不
|
||||
用用户管理)它只有在启用 RTGUI_USING_DESKTOP_WINDOW 时才有此特性。
|
||||
13.2 root window:创建时父窗口为 RT_NULL 的窗口。是用户空间窗口继承树的根。
|
||||
13.3 normal window:创建时父窗口不为 RT_NULL 的窗口。它始终会在父窗口之上显
|
||||
示(它会 clip 父窗口)。normal windows 和 root window 组成一个窗口树。
|
||||
13.4 模态:当一个 normal window 模态显示时会会模态自己所在树的同级窗口
|
||||
和所有父级窗口,但不会影响别的窗口树。被模态的窗口不会接受到用户事
|
||||
件(按键,触摸等)
|
||||
|
||||
----
|
||||
[note1] 我们至少需要一种容器控件来盛放其他的控件,并且能把上层事件传递给被包含
|
||||
的控件。实现这样的功能有一个就好,container 可以担当这个责任。其他需要放多个控
|
||||
件的控件则可以继承/包含这个控件。然后多个容器控件轮换的,notebook 可以来做。
|
||||
notebook可以是有标签和无标签的,有标签的对应一般的 tab 控件,无标签的对应 rtgui
|
||||
for RTT 1.0 的 workbench+view。
|
||||
@@ -1,81 +0,0 @@
|
||||
/** @~english
|
||||
@page pg-mv-model Model-View framework
|
||||
|
||||
@brief A overview of the Model-View framework
|
||||
|
||||
@section Glossary
|
||||
|
||||
@li view: widget dedicated to show the data. It could be a graph, list etc.
|
||||
@li model: abstraction and combination of data.
|
||||
@li data: things that needed to be delivered or shown. It could be a array of
|
||||
votage values which is sampled from a AD in an interval. Or it could be the
|
||||
attributes of all the files in a folder.
|
||||
|
||||
@section Design considerations and implementations
|
||||
|
||||
@li one model can respond to more than one views. one view can connect to
|
||||
more than one models.
|
||||
@li It is guaranteed that the change events of a model will be sent to all
|
||||
the registered views.
|
||||
@li Because there are so many formats of data, Model-View neither specify the
|
||||
format data is stored nor try to abstract them. The only thing stored in
|
||||
model is a pointer to the underlaying data. It is the responsibility of
|
||||
inherited classed to implement the boxing/un-boxing operations.
|
||||
@li Data can be multi-dimensional. The "dimension" does not only means
|
||||
dimension geometry. It can also means attributes. For example, a folder could
|
||||
have two attributes which are name and icon. So it's two-dimensional. If take
|
||||
the size into consideration, it will be three-dimensional. The size of
|
||||
dimension is saved in model. Each dimension is correspond to a pointer to some
|
||||
sort of data. Model can save many of them. As above, model does not make
|
||||
assumptions on the underlaying data structure. It only provide mechanism, not
|
||||
policy and leave that to the inherited classes.
|
||||
|
||||
@section Events
|
||||
|
||||
@li model has a record of registered views. When data changes, model notify
|
||||
views the change by sending events. The event contains the id of the model,
|
||||
the id of target view, the scope of changed data.
|
||||
@li views can handle the event by retrieve data from model, and update
|
||||
themselves according to the scope that data has changed. The connected model
|
||||
views should have the same presentation of data structure. Views should also
|
||||
restore all the models it interested. In the case of repainting, it should
|
||||
re-retrieve data from those models.
|
||||
@li model send events by rtgui_send. So it's suitable for the synchronization
|
||||
between threads and even could be used in ISR.
|
||||
*/
|
||||
|
||||
/** @~chinese
|
||||
@page pg-mv-model Model-View 框架
|
||||
|
||||
@brief 对于 Model-View 框架的简介
|
||||
|
||||
@section 名词解释
|
||||
|
||||
@li view:用于显示数据的控件。可以是诸如图表控件、列表控件的控件。
|
||||
@li model:对于数据的组合和抽象。
|
||||
@li 数据:需要显示或传递的数据。它可以是每隔一段时间就从AD读取的电压值,也可
|
||||
以是一个目录下所有文件的属性列表。
|
||||
|
||||
@section 设计原则和实现
|
||||
|
||||
@li 一个 model 可以对应多个view。一个view可以对应多个 model。
|
||||
@li 保证 model 的更新事件会同时发送到所有注册的 view 上。
|
||||
@li 因为数据的形式与内容千差万别,所以 Model-View 不规定数据的存储形式,也不对其进
|
||||
行抽象。只在 model 中保留指向第一个数据的指针。打包/解包由从m odel/view 派生出
|
||||
的子类实现。
|
||||
@li 数据源可以是多维的。这里的维度指的不只是几何的维度,而且可以是属性。比如
|
||||
一个目录,它可以有名称、图标两个属性,那么它就是两维的。如果加入大小这个属性
|
||||
,就是三维的。 model 内部存储数据的维度大小。一个维度对应一个数据首地址的指针
|
||||
。model 中可以存储多个数据首地址。model 对底层数据结构不作假设。只提供机制,不
|
||||
提供策略。只保证能够多维,但把具体的实现方式留给子类实现。
|
||||
|
||||
@subsection 事件
|
||||
|
||||
@li model 内部记录对自己感兴趣的 view。在数据变化时,用事件通知所有相关 view。事
|
||||
件内容包含:自己的 id;目标 view 的 id;所变化数据的 index 范围。
|
||||
@li view 收到事件之后通过 model id 拿到数据并根据事件中的变化范围更新自己。对于
|
||||
指针的数据类型转换需要自己实现并保证和 model 一致。view 内部保存与自己相关的
|
||||
model id,在需要重绘的时候要从所有相关 model 提取数据。
|
||||
@li model 通过 rtgui_send 给 view 发送事件。使得这个模型适用于线程间同步,也
|
||||
可以在中断上下文里通知事件的发生。
|
||||
*/
|
||||
@@ -1,10 +0,0 @@
|
||||
#ifndef __RTGUI_BLIT_H__
|
||||
#define __RTGUI_BLIT_H__
|
||||
|
||||
#include <rtgui/rtgui.h>
|
||||
|
||||
typedef void (*rtgui_blit_line_func)(rt_uint8_t *dst, rt_uint8_t *src, int line);
|
||||
rtgui_blit_line_func rtgui_blit_line_get(int dst_bpp, int src_bpp);
|
||||
rtgui_blit_line_func rtgui_blit_line_get_inv(int dst_bpp, int src_bpp);
|
||||
|
||||
#endif
|
||||
@@ -1,139 +0,0 @@
|
||||
/*
|
||||
* File : color.h
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rt-thread.org/license/LICENSE
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2009-10-16 Bernard first version
|
||||
* 2012-01-24 onelife add mono color support
|
||||
*/
|
||||
#ifndef __RTGUI_COLOR_H__
|
||||
#define __RTGUI_COLOR_H__
|
||||
|
||||
#include <rtgui/rtgui.h>
|
||||
|
||||
#define RTGUI_ARGB(a, r, g, b) \
|
||||
((rtgui_color_t)(((rt_uint8_t)(r)|\
|
||||
(((unsigned)(rt_uint8_t)(g))<<8))|\
|
||||
(((unsigned long)(rt_uint8_t)(b))<<16)|\
|
||||
(((unsigned long)(rt_uint8_t)(a))<<24)))
|
||||
#define RTGUI_RGB(r, g, b) RTGUI_ARGB(255, (r), (g), (b))
|
||||
|
||||
#define RTGUI_RGB_R(c) ((c) & 0xff)
|
||||
#define RTGUI_RGB_G(c) (((c) >> 8) & 0xff)
|
||||
#define RTGUI_RGB_B(c) (((c) >> 16) & 0xff)
|
||||
#define RTGUI_RGB_A(c) (((c) >> 24) & 0xff)
|
||||
|
||||
extern const rtgui_color_t default_foreground;
|
||||
extern const rtgui_color_t default_background;
|
||||
|
||||
extern const rtgui_color_t red;
|
||||
extern const rtgui_color_t green;
|
||||
extern const rtgui_color_t blue;
|
||||
extern const rtgui_color_t black;
|
||||
extern const rtgui_color_t white;
|
||||
extern const rtgui_color_t high_light;
|
||||
extern const rtgui_color_t dark_grey;
|
||||
extern const rtgui_color_t light_grey;
|
||||
|
||||
/*
|
||||
* RTGUI default color format
|
||||
* BBBB BBBB GGGG GGGG RRRR RRRR
|
||||
*/
|
||||
|
||||
/* convert rtgui color to mono */
|
||||
rt_inline rt_uint8_t rtgui_color_to_mono(rtgui_color_t c)
|
||||
{
|
||||
rt_uint8_t pixel;
|
||||
|
||||
pixel = (RTGUI_RGB_R(c) | RTGUI_RGB_G(c) | RTGUI_RGB_B(c)) ? 0x01 : 0x00;
|
||||
return pixel;
|
||||
}
|
||||
|
||||
rt_inline rtgui_color_t rtgui_color_from_mono(rt_uint8_t pixel)
|
||||
{
|
||||
rtgui_color_t color;
|
||||
|
||||
if (pixel)
|
||||
{
|
||||
color = white;
|
||||
}
|
||||
else
|
||||
{
|
||||
color = black;
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
/* convert rtgui color to BBBBBGGGGGGRRRRR */
|
||||
rt_inline rt_uint16_t rtgui_color_to_565(rtgui_color_t c)
|
||||
{
|
||||
rt_uint16_t pixel;
|
||||
|
||||
pixel = (rt_uint16_t)(((RTGUI_RGB_B(c) >> 3) << 11) | ((RTGUI_RGB_G(c) >> 2) << 5) | (RTGUI_RGB_R(c) >> 3));
|
||||
|
||||
return pixel;
|
||||
}
|
||||
|
||||
rt_inline rtgui_color_t rtgui_color_from_565(rt_uint16_t pixel)
|
||||
{
|
||||
rt_uint16_t r, g, b;
|
||||
rtgui_color_t color;
|
||||
|
||||
r = pixel & 0x1f;
|
||||
g = (pixel >> 5) & 0x3f;
|
||||
b = (pixel >> 11) & 0x1f;
|
||||
|
||||
color = r * 255 / 31 + ((g * 255 / 63) << 8) + ((b * 255 / 31) << 16);
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
/* convert rtgui color to RRRRRGGGGGGBBBBB */
|
||||
rt_inline rt_uint16_t rtgui_color_to_565p(rtgui_color_t c)
|
||||
{
|
||||
rt_uint16_t pixel;
|
||||
|
||||
pixel = (rt_uint16_t)(((RTGUI_RGB_R(c) >> 3) << 11) | ((RTGUI_RGB_G(c) >> 2) << 5) | (RTGUI_RGB_B(c) >> 3));
|
||||
return pixel;
|
||||
}
|
||||
|
||||
rt_inline rtgui_color_t rtgui_color_from_565p(rt_uint16_t pixel)
|
||||
{
|
||||
rt_uint8_t r, g, b;
|
||||
rtgui_color_t color;
|
||||
|
||||
r = (pixel >> 11) & 0x1f;
|
||||
g = (pixel >> 5) & 0x3f;
|
||||
b = pixel & 0x1f;
|
||||
|
||||
color = r * 255 / 31 + ((g * 255 / 63) << 8) + ((b * 255 / 31) << 16);
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
/* convert rtgui color to RGB */
|
||||
rt_inline rt_uint32_t rtgui_color_to_888(rtgui_color_t c)
|
||||
{
|
||||
rt_uint32_t pixel;
|
||||
|
||||
pixel = RTGUI_RGB_R(c) << 16 | RTGUI_RGB_G(c) << 8 | RTGUI_RGB_B(c);
|
||||
return pixel;
|
||||
}
|
||||
|
||||
rt_inline rtgui_color_t rtgui_color_from_888(rt_uint32_t pixel)
|
||||
{
|
||||
rtgui_color_t color;
|
||||
|
||||
color = RTGUI_RGB(((pixel >> 16) & 0xff), ((pixel >> 8) & 0xff), pixel & 0xff);
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,206 +0,0 @@
|
||||
/*
|
||||
* File : dc.h
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rt-thread.org/license/LICENSE
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2009-10-16 Bernard first version
|
||||
*/
|
||||
#ifndef __RTGUI_DC_H__
|
||||
#define __RTGUI_DC_H__
|
||||
|
||||
#include <rtgui/rtgui.h>
|
||||
#include <rtgui/font.h>
|
||||
#include <rtgui/driver.h>
|
||||
#include <rtgui/widgets/widget.h>
|
||||
|
||||
enum rtgui_dc_type
|
||||
{
|
||||
RTGUI_DC_HW,
|
||||
RTGUI_DC_CLIENT,
|
||||
RTGUI_DC_BUFFER,
|
||||
};
|
||||
|
||||
struct rtgui_dc_engine
|
||||
{
|
||||
/* interface */
|
||||
void (*draw_point)(struct rtgui_dc *dc, int x, int y);
|
||||
void (*draw_color_point)(struct rtgui_dc *dc, int x, int y, rtgui_color_t color);
|
||||
void (*draw_vline)(struct rtgui_dc *dc, int x, int y1, int y2);
|
||||
void (*draw_hline)(struct rtgui_dc *dc, int x1, int x2, int y);
|
||||
void (*fill_rect)(struct rtgui_dc *dc, rtgui_rect_t *rect);
|
||||
void (*blit_line)(struct rtgui_dc *dc, int x1, int x2, int y, rt_uint8_t *line_data);
|
||||
void (*blit)(struct rtgui_dc *dc, struct rtgui_point *dc_point, struct rtgui_dc *dest, rtgui_rect_t *rect);
|
||||
|
||||
/* set and get graphic context */
|
||||
void (*set_gc)(struct rtgui_dc *dc, struct rtgui_gc *gc);
|
||||
struct rtgui_gc *(*get_gc)(struct rtgui_dc *dc);
|
||||
|
||||
/* get dc visible */
|
||||
rt_bool_t (*get_visible)(struct rtgui_dc *dc);
|
||||
|
||||
/* get dc rect */
|
||||
void (*get_rect)(struct rtgui_dc *dc, rtgui_rect_t *rect);
|
||||
|
||||
rt_bool_t (*fini)(struct rtgui_dc *dc);
|
||||
};
|
||||
|
||||
/* the abstract device context */
|
||||
struct rtgui_dc
|
||||
{
|
||||
/* type of device context */
|
||||
rt_uint32_t type;
|
||||
|
||||
/* dc engine */
|
||||
const struct rtgui_dc_engine *engine;
|
||||
};
|
||||
|
||||
/* hardware device context */
|
||||
struct rtgui_dc_hw
|
||||
{
|
||||
struct rtgui_dc parent;
|
||||
rtgui_widget_t *owner;
|
||||
const struct rtgui_graphic_driver *hw_driver;
|
||||
};
|
||||
|
||||
#define RTGUI_DC_FC(dc) (rtgui_dc_get_gc(dc)->foreground)
|
||||
#define RTGUI_DC_BC(dc) (rtgui_dc_get_gc(dc)->background)
|
||||
#define RTGUI_DC_FONT(dc) (rtgui_dc_get_gc(dc)->font)
|
||||
#define RTGUI_DC_TEXTALIGN(dc) (rtgui_dc_get_gc(dc)->textalign)
|
||||
|
||||
/* create a buffer dc */
|
||||
struct rtgui_dc *rtgui_dc_buffer_create(int width, int height);
|
||||
rt_uint8_t *rtgui_dc_buffer_get_pixel(struct rtgui_dc *dc);
|
||||
|
||||
/* begin and end a drawing */
|
||||
struct rtgui_dc *rtgui_dc_begin_drawing(rtgui_widget_t *owner);
|
||||
void rtgui_dc_end_drawing(struct rtgui_dc *dc);
|
||||
|
||||
/* destroy a dc */
|
||||
void rtgui_dc_destory(struct rtgui_dc *dc);
|
||||
|
||||
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_fill_rect_forecolor(struct rtgui_dc *dc, struct rtgui_rect *rect);
|
||||
void rtgui_dc_draw_round_rect(struct rtgui_dc *dc, struct rtgui_rect *rect, int r);
|
||||
void rtgui_dc_fill_round_rect(struct rtgui_dc *dc, struct rtgui_rect *rect, int r);
|
||||
void rtgui_dc_draw_annulus(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_int16_t r1, rt_int16_t r2, rt_int16_t start, rt_int16_t end);
|
||||
void rtgui_dc_draw_sector(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_int16_t r, rt_int16_t start, rt_int16_t end);
|
||||
void rtgui_dc_fill_sector(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_int16_t r, rt_int16_t start, rt_int16_t end);
|
||||
|
||||
void rtgui_dc_draw_text(struct rtgui_dc *dc, const char *text, struct rtgui_rect *rect);
|
||||
void rtgui_dc_draw_text_stroke(struct rtgui_dc *dc, const char *text, struct rtgui_rect *rect,
|
||||
rtgui_color_t color_stroke, rtgui_color_t color_core);
|
||||
|
||||
void rtgui_dc_draw_mono_bmp(struct rtgui_dc *dc, int x, int y, int w, 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_border(struct rtgui_dc *dc, rtgui_rect_t *rect, int flag);
|
||||
void rtgui_dc_draw_horizontal_line(struct rtgui_dc *dc, int x1, int x2, int y);
|
||||
void rtgui_dc_draw_vertical_line(struct rtgui_dc *dc, int x, int y1, int y2);
|
||||
void rtgui_dc_draw_focus_rect(struct rtgui_dc *dc, rtgui_rect_t *rect);
|
||||
|
||||
void rtgui_dc_draw_polygon(struct rtgui_dc *dc, const int *vx, const int *vy, int count);
|
||||
void rtgui_dc_fill_polygon(struct rtgui_dc *dc, const int *vx, const int *vy, int count);
|
||||
|
||||
void rtgui_dc_draw_circle(struct rtgui_dc *dc, int x, int y, int r);
|
||||
void rtgui_dc_fill_circle(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_int16_t r);
|
||||
void rtgui_dc_draw_arc(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_int16_t r, rt_int16_t start, rt_int16_t end);
|
||||
|
||||
void rtgui_dc_draw_ellipse(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_int16_t rx, rt_int16_t ry);
|
||||
void rtgui_dc_fill_ellipse(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_int16_t rx, rt_int16_t ry);
|
||||
|
||||
/*
|
||||
* dc inline function
|
||||
*
|
||||
* Note:
|
||||
* In order to improve drawing speed, put most of common function of dc to inline
|
||||
*/
|
||||
|
||||
/*
|
||||
* draw a point on dc
|
||||
*/
|
||||
rt_inline void rtgui_dc_draw_point(struct rtgui_dc *dc, int x, int y)
|
||||
{
|
||||
dc->engine->draw_point(dc, x, y);
|
||||
}
|
||||
|
||||
/*
|
||||
* draw a color point on dc
|
||||
*/
|
||||
rt_inline void rtgui_dc_draw_color_point(struct rtgui_dc *dc, int x, int y, rtgui_color_t color)
|
||||
{
|
||||
dc->engine->draw_color_point(dc, x, y, color);
|
||||
}
|
||||
|
||||
/*
|
||||
* draw a vertical line on dc
|
||||
*/
|
||||
rt_inline void rtgui_dc_draw_vline(struct rtgui_dc *dc, int x, int y1, int y2)
|
||||
{
|
||||
dc->engine->draw_vline(dc, x, y1, y2);
|
||||
}
|
||||
|
||||
/*
|
||||
* draw a horizontal line on dc
|
||||
*/
|
||||
rt_inline void rtgui_dc_draw_hline(struct rtgui_dc *dc, int x1, int x2, int y)
|
||||
{
|
||||
dc->engine->draw_hline(dc, x1, x2, y);
|
||||
}
|
||||
|
||||
/*
|
||||
* fill a rect with background color
|
||||
*/
|
||||
rt_inline void rtgui_dc_fill_rect(struct rtgui_dc *dc, struct rtgui_rect *rect)
|
||||
{
|
||||
dc->engine->fill_rect(dc, rect);
|
||||
}
|
||||
|
||||
/*
|
||||
* blit a dc on hardware dc
|
||||
*/
|
||||
rt_inline void rtgui_dc_blit(struct rtgui_dc *dc, struct rtgui_point *dc_point, struct rtgui_dc *dest, rtgui_rect_t *rect)
|
||||
{
|
||||
dc->engine->blit(dc, dc_point, dest, rect);
|
||||
}
|
||||
|
||||
/*
|
||||
* set gc of dc
|
||||
*/
|
||||
rt_inline void rtgui_dc_set_gc(struct rtgui_dc *dc, rtgui_gc_t *gc)
|
||||
{
|
||||
dc->engine->set_gc(dc, gc);
|
||||
}
|
||||
|
||||
/*
|
||||
* get gc of dc
|
||||
*/
|
||||
rt_inline rtgui_gc_t *rtgui_dc_get_gc(struct rtgui_dc *dc)
|
||||
{
|
||||
return dc->engine->get_gc(dc);
|
||||
}
|
||||
|
||||
/*
|
||||
* get visible status of dc
|
||||
*/
|
||||
rt_inline rt_bool_t rtgui_dc_get_visible(struct rtgui_dc *dc)
|
||||
{
|
||||
return dc->engine->get_visible(dc);
|
||||
}
|
||||
|
||||
/*
|
||||
* get rect of dc
|
||||
*/
|
||||
rt_inline void rtgui_dc_get_rect(struct rtgui_dc *dc, rtgui_rect_t *rect)
|
||||
{
|
||||
dc->engine->get_rect(dc, rect);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
* File : dc_buffer.h
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2010, RT-Thread Development Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rt-thread.org/license/LICENSE
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2010-04-10 Bernard first version
|
||||
* 2010-06-14 Bernard embedded hardware dc to each widget
|
||||
* 2010-08-09 Bernard rename hardware dc to client dc
|
||||
*/
|
||||
|
||||
#ifndef __RTGUI_DC_CLIENT_H__
|
||||
#define __RTGUI_DC_CLIENT_H__
|
||||
|
||||
#include <rtgui/dc.h>
|
||||
|
||||
/* create a hardware dc */
|
||||
struct rtgui_dc *rtgui_dc_client_create(rtgui_widget_t *owner);
|
||||
void rtgui_dc_client_init(rtgui_widget_t *owner);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
/*
|
||||
* File : dc_buffer.h
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2010, RT-Thread Development Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rt-thread.org/license/LICENSE
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2010-04-10 Bernard first version
|
||||
* 2010-06-14 Bernard embedded hardware dc to each widget
|
||||
*/
|
||||
#ifndef __RTGUI_DC_HW_H__
|
||||
#define __RTGUI_DC_HW_H__
|
||||
|
||||
#include <rtgui/dc.h>
|
||||
|
||||
/* create a hardware dc */
|
||||
struct rtgui_dc *rtgui_dc_hw_create(rtgui_widget_t *owner);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,119 +0,0 @@
|
||||
/*
|
||||
* File : dlist.h
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2011, RT-Thread Development Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rt-thread.org/license/LICENSE
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2006-03-16 Bernard the first version
|
||||
* 2006-09-07 Bernard move the kservice APIs to rtthread.h
|
||||
* 2007-06-27 Bernard fix the rt_list_remove bug
|
||||
* 2012-02-25 Grissiom move to rtgui/include/rtgui and some misc changes
|
||||
*/
|
||||
|
||||
#ifndef __RTGUI_DLIST_H__
|
||||
#define __RTGUI_DLIST_H__
|
||||
|
||||
/* This file is copied from kservice.h in RTT kernel. There are some differences:
|
||||
* 1, naming. Use rtgui_dlist_ prefix instead of rt_list.
|
||||
* 2, add rtgui_dlist_foreach for convenience.
|
||||
* 3, move the definition of list node into this file.
|
||||
*
|
||||
* Please keep both of the files synchronized when fixing bugs.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct rtgui_dlist_node
|
||||
{
|
||||
struct rtgui_dlist_node *next; /* point to next node. */
|
||||
struct rtgui_dlist_node *prev; /* point to prev node. */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief initialize a list
|
||||
*
|
||||
* @param l list to be initialized
|
||||
*/
|
||||
rt_inline void rtgui_dlist_init(struct rtgui_dlist_node *l)
|
||||
{
|
||||
l->next = l->prev = l;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief insert a node after a list
|
||||
*
|
||||
* @param l list to insert it
|
||||
* @param n new node to be inserted
|
||||
*/
|
||||
rt_inline void rtgui_dlist_insert_after(struct rtgui_dlist_node *l, struct rtgui_dlist_node *n)
|
||||
{
|
||||
l->next->prev = n;
|
||||
n->next = l->next;
|
||||
|
||||
l->next = n;
|
||||
n->prev = l;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief insert a node before a list
|
||||
*
|
||||
* @param n new node to be inserted
|
||||
* @param l list to insert it
|
||||
*/
|
||||
rt_inline void rtgui_dlist_insert_before(struct rtgui_dlist_node *l, struct rtgui_dlist_node *n)
|
||||
{
|
||||
l->prev->next = n;
|
||||
n->prev = l->prev;
|
||||
|
||||
l->prev = n;
|
||||
n->next = l;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief remove node from list.
|
||||
* @param n the node to remove from the list.
|
||||
*/
|
||||
rt_inline void rtgui_dlist_remove(struct rtgui_dlist_node *n)
|
||||
{
|
||||
n->next->prev = n->prev;
|
||||
n->prev->next = n->next;
|
||||
|
||||
rtgui_dlist_init(n);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief tests whether a list is empty
|
||||
* @param l the list to test.
|
||||
*/
|
||||
rt_inline int rtgui_dlist_isempty(const struct rtgui_dlist_node *l)
|
||||
{
|
||||
return l->next == l;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get the struct for this entry
|
||||
* @param node the entry point
|
||||
* @param type the type of structure
|
||||
* @param member the name of list in structure
|
||||
*/
|
||||
#define rtgui_dlist_entry(node, type, member) \
|
||||
((type *)((char *)(node) - (unsigned long)(&((type *)0)->member)))
|
||||
|
||||
/* the direction can only be next or prev. If you want to iterate the list in
|
||||
* normal order, use next. If you want to iterate the list with reverse order,
|
||||
* use prev.*/
|
||||
#define rtgui_dlist_foreach(node, list, direction) \
|
||||
for ((node) = (list)->direction; (node) != list; (node) = (node)->direction)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,99 +0,0 @@
|
||||
/*
|
||||
* File : driver.h
|
||||
* This file is part of RTGUI in RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rt-thread.org/license/LICENSE
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2009-10-04 Bernard first version
|
||||
*/
|
||||
#ifndef __RTGUI_DRIVER_H__
|
||||
#define __RTGUI_DRIVER_H__
|
||||
|
||||
#include <rtgui/list.h>
|
||||
#include <rtgui/color.h>
|
||||
|
||||
/* graphic driver operations */
|
||||
struct rtgui_graphic_driver_ops
|
||||
{
|
||||
/* set and get pixel in (x, y) */
|
||||
void (*set_pixel)(rtgui_color_t *c, int x, int y);
|
||||
void (*get_pixel)(rtgui_color_t *c, int x, int y);
|
||||
|
||||
void (*draw_hline)(rtgui_color_t *c, int x1, int x2, int y);
|
||||
void (*draw_vline)(rtgui_color_t *c, int x , int y1, int y2);
|
||||
|
||||
/* draw raw hline */
|
||||
void (*draw_raw_hline)(rt_uint8_t *pixels, int x1, int x2, int y);
|
||||
};
|
||||
|
||||
/* graphic extension operations */
|
||||
struct rtgui_graphic_ext_ops
|
||||
{
|
||||
/* some 2D operations */
|
||||
void (*draw_line)(rtgui_color_t *c, int x1, int y1, int x2, int y2);
|
||||
|
||||
void (*draw_rect)(rtgui_color_t *c, int x1, int y1, int x2, int y2);
|
||||
void (*fill_rect)(rtgui_color_t *c, int x1, int y1, int x2, int y2);
|
||||
|
||||
void (*draw_circle)(rtgui_color_t *c, int x, int y, int r);
|
||||
void (*fill_circle)(rtgui_color_t *c, int x, int y, int r);
|
||||
|
||||
void (*draw_ellipse)(rtgui_color_t *c, int x, int y, int rx, int ry);
|
||||
void (*fill_ellipse)(rtgui_color_t *c, int x, int y, int rx, int ry);
|
||||
};
|
||||
|
||||
struct rtgui_graphic_driver
|
||||
{
|
||||
/* pixel format and byte per pixel */
|
||||
rt_uint8_t pixel_format;
|
||||
rt_uint8_t bits_per_pixel;
|
||||
rt_uint16_t pitch;
|
||||
|
||||
/* screen width and height */
|
||||
rt_uint16_t width;
|
||||
rt_uint16_t height;
|
||||
|
||||
/* framebuffer address and ops */
|
||||
volatile rt_uint8_t *framebuffer;
|
||||
struct rt_device* device;
|
||||
|
||||
const struct rtgui_graphic_driver_ops *ops;
|
||||
const struct rtgui_graphic_ext_ops *ext_ops;
|
||||
};
|
||||
|
||||
struct rtgui_graphic_driver *rtgui_graphic_driver_get_default(void);
|
||||
|
||||
void rtgui_graphic_driver_get_rect(const struct rtgui_graphic_driver *driver, rtgui_rect_t *rect);
|
||||
void rtgui_graphic_driver_screen_update(const struct rtgui_graphic_driver *driver, rtgui_rect_t *rect);
|
||||
rt_uint8_t *rtgui_graphic_driver_get_framebuffer(const struct rtgui_graphic_driver *driver);
|
||||
rt_uint8_t *rtgui_graphic_driver_get_default_framebuffer(void);
|
||||
|
||||
rt_err_t rtgui_graphic_set_device(rt_device_t device);
|
||||
|
||||
rt_inline struct rtgui_graphic_driver *rtgui_graphic_get_device()
|
||||
{
|
||||
extern struct rtgui_graphic_driver _driver;
|
||||
return &_driver;
|
||||
}
|
||||
|
||||
#ifdef RTGUI_USING_HW_CURSOR
|
||||
/*
|
||||
* hardware cursor
|
||||
*/
|
||||
enum rtgui_cursor_type
|
||||
{
|
||||
RTGUI_CURSOR_ARROW,
|
||||
RTGUI_CURSOR_HAND,
|
||||
};
|
||||
|
||||
void rtgui_cursor_set_device(const char* device_name);
|
||||
void rtgui_cursor_set_position(rt_uint16_t x, rt_uint16_t y);
|
||||
void rtgui_cursor_set_image(enum rtgui_cursor_type type);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,466 +0,0 @@
|
||||
/*
|
||||
* File : event.h
|
||||
* This file is part of RTGUI in RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rt-thread.org/license/LICENSE
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2009-10-04 Bernard first version
|
||||
*/
|
||||
#ifndef __RTGUI_EVENT_H__
|
||||
#define __RTGUI_EVENT_H__
|
||||
|
||||
#include <rtgui/rtgui.h>
|
||||
#include <rtgui/kbddef.h>
|
||||
|
||||
/* NOTE: if you create a new event type, remember to add it into the union
|
||||
* rtgui_event_generic */
|
||||
enum _rtgui_event_type
|
||||
{
|
||||
/* applications event */
|
||||
RTGUI_EVENT_APP_CREATE, /* create an application */
|
||||
RTGUI_EVENT_APP_DESTROY, /* destroy an application */
|
||||
RTGUI_EVENT_APP_ACTIVATE, /* activate an application */
|
||||
|
||||
/* window event */
|
||||
RTGUI_EVENT_WIN_CREATE, /* create a window */
|
||||
RTGUI_EVENT_WIN_DESTROY, /* destroy a window */
|
||||
RTGUI_EVENT_WIN_SHOW, /* show a window */
|
||||
RTGUI_EVENT_WIN_HIDE, /* hide a window */
|
||||
RTGUI_EVENT_WIN_ACTIVATE, /* activate a window */
|
||||
RTGUI_EVENT_WIN_DEACTIVATE, /* deactivate a window */
|
||||
RTGUI_EVENT_WIN_CLOSE, /* close a window */
|
||||
RTGUI_EVENT_WIN_MOVE, /* move a window */
|
||||
RTGUI_EVENT_WIN_RESIZE, /* resize a window */
|
||||
RTGUI_EVENT_WIN_MODAL_ENTER, /* the window is entering modal mode.
|
||||
This event should be sent after the
|
||||
window got setup and before the
|
||||
application got setup. */
|
||||
|
||||
/* WM event */
|
||||
RTGUI_EVENT_SET_WM, /* set window manager */
|
||||
|
||||
RTGUI_EVENT_UPDATE_BEGIN, /* update a rect */
|
||||
RTGUI_EVENT_UPDATE_END, /* update a rect */
|
||||
RTGUI_EVENT_MONITOR_ADD, /* add a monitor rect */
|
||||
RTGUI_EVENT_MONITOR_REMOVE, /* remove a monitor rect */
|
||||
RTGUI_EVENT_SHOW, /* the widget is going to be shown */
|
||||
RTGUI_EVENT_HIDE, /* the widget is going to be hidden */
|
||||
RTGUI_EVENT_PAINT, /* paint on screen */
|
||||
RTGUI_EVENT_TIMER, /* timer */
|
||||
RTGUI_EVENT_UPDATE_TOPLVL, /* update the toplevel */
|
||||
|
||||
/* clip rect information */
|
||||
RTGUI_EVENT_CLIP_INFO, /* clip rect info */
|
||||
|
||||
/* mouse and keyboard event */
|
||||
RTGUI_EVENT_MOUSE_MOTION, /* mouse motion */
|
||||
RTGUI_EVENT_MOUSE_BUTTON, /* mouse button info */
|
||||
RTGUI_EVENT_KBD, /* keyboard info */
|
||||
|
||||
/* widget event */
|
||||
RTGUI_EVENT_FOCUSED, /* widget focused */
|
||||
RTGUI_EVENT_SCROLLED, /* scroll bar scrolled */
|
||||
RTGUI_EVENT_RESIZE, /* widget resize */
|
||||
RTGUI_EVENT_SELECTED, /* widget selected */
|
||||
RTGUI_EVENT_UNSELECTED, /* widget un-selected */
|
||||
RTGUI_EVENT_MV_MODEL, /* data of a model has been changed */
|
||||
|
||||
/* user command event. It should always be the last command type. */
|
||||
RTGUI_EVENT_COMMAND = 0x0100, /* user command */
|
||||
};
|
||||
typedef enum _rtgui_event_type rtgui_event_type;
|
||||
|
||||
enum
|
||||
{
|
||||
RTGUI_STATUS_OK = 0, /* status ok */
|
||||
RTGUI_STATUS_ERROR, /* generic error */
|
||||
RTGUI_STATUS_NRC, /* no resource */
|
||||
};
|
||||
|
||||
struct rtgui_event
|
||||
{
|
||||
/* the event type */
|
||||
enum _rtgui_event_type type;
|
||||
/* user field of event */
|
||||
rt_uint16_t user;
|
||||
|
||||
/* the event sender */
|
||||
struct rtgui_app *sender;
|
||||
|
||||
/* mailbox to acknowledge request */
|
||||
rt_mailbox_t ack;
|
||||
};
|
||||
typedef struct rtgui_event rtgui_event_t;
|
||||
#define RTGUI_EVENT(e) ((struct rtgui_event*)(e))
|
||||
|
||||
extern struct rtgui_app* rtgui_app_self(void);
|
||||
|
||||
#define RTGUI_EVENT_INIT(e, t) do \
|
||||
{ \
|
||||
(e)->type = (t); \
|
||||
(e)->user = 0; \
|
||||
(e)->sender = rtgui_app_self(); \
|
||||
(e)->ack = RT_NULL; \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* RTGUI Application Event
|
||||
*/
|
||||
struct rtgui_event_application
|
||||
{
|
||||
struct rtgui_event parent;
|
||||
|
||||
struct rtgui_app *app;
|
||||
};
|
||||
|
||||
/* gui application init */
|
||||
#define RTGUI_EVENT_APP_CREATE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_APP_CREATE)
|
||||
#define RTGUI_EVENT_APP_DESTROY_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_APP_DESTROY)
|
||||
#define RTGUI_EVENT_APP_ACTIVATE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_APP_ACTIVATE)
|
||||
|
||||
/*
|
||||
* RTGUI Window Event
|
||||
*/
|
||||
#define _RTGUI_EVENT_WIN_ELEMENTS \
|
||||
struct rtgui_event parent; \
|
||||
struct rtgui_win *wid;
|
||||
|
||||
/*
|
||||
* RTGUI Window Event
|
||||
*/
|
||||
struct rtgui_event_win
|
||||
{
|
||||
_RTGUI_EVENT_WIN_ELEMENTS
|
||||
};
|
||||
|
||||
struct rtgui_event_win_create
|
||||
{
|
||||
_RTGUI_EVENT_WIN_ELEMENTS
|
||||
struct rtgui_win *parent_window;
|
||||
#ifndef RTGUI_USING_SMALL_SIZE
|
||||
/* the window title */
|
||||
rt_uint8_t title[RTGUI_NAME_MAX];
|
||||
/* the window extent */
|
||||
struct rtgui_rect extent;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct rtgui_event_win_move
|
||||
{
|
||||
_RTGUI_EVENT_WIN_ELEMENTS
|
||||
rt_int16_t x, y;
|
||||
};
|
||||
|
||||
struct rtgui_event_win_resize
|
||||
{
|
||||
_RTGUI_EVENT_WIN_ELEMENTS
|
||||
|
||||
rtgui_rect_t rect;
|
||||
};
|
||||
|
||||
#define rtgui_event_win_destroy rtgui_event_win
|
||||
#define rtgui_event_win_show rtgui_event_win
|
||||
#define rtgui_event_win_hide rtgui_event_win
|
||||
#define rtgui_event_win_activate rtgui_event_win
|
||||
#define rtgui_event_win_deactivate rtgui_event_win
|
||||
#define rtgui_event_win_close rtgui_event_win
|
||||
#define rtgui_event_win_modal_enter rtgui_event_win
|
||||
|
||||
/* window event init */
|
||||
#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_SHOW_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_SHOW)
|
||||
#define RTGUI_EVENT_WIN_HIDE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_HIDE)
|
||||
#define RTGUI_EVENT_WIN_ACTIVATE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_ACTIVATE)
|
||||
#define RTGUI_EVENT_WIN_DEACTIVATE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_DEACTIVATE)
|
||||
#define RTGUI_EVENT_WIN_CLOSE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_CLOSE)
|
||||
#define RTGUI_EVENT_WIN_MOVE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_MOVE)
|
||||
#define RTGUI_EVENT_WIN_RESIZE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_RESIZE)
|
||||
#define RTGUI_EVENT_WIN_MODAL_ENTER_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_MODAL_ENTER)
|
||||
|
||||
/*
|
||||
* RTGUI set window manager
|
||||
*/
|
||||
struct rtgui_event_set_wm
|
||||
{
|
||||
struct rtgui_event parent;
|
||||
struct rtgui_app *app;
|
||||
};
|
||||
#define RTGUI_EVENT_SET_WM_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_SET_WM);
|
||||
|
||||
/*
|
||||
* RTGUI Other Event
|
||||
*/
|
||||
struct rtgui_event_update_begin
|
||||
{
|
||||
struct rtgui_event parent;
|
||||
|
||||
/* the update rect */
|
||||
rtgui_rect_t rect;
|
||||
};
|
||||
|
||||
struct rtgui_event_update_end
|
||||
{
|
||||
struct rtgui_event parent;
|
||||
|
||||
/* the update rect */
|
||||
rtgui_rect_t rect;
|
||||
};
|
||||
|
||||
struct rtgui_event_monitor
|
||||
{
|
||||
_RTGUI_EVENT_WIN_ELEMENTS
|
||||
|
||||
/* the monitor rect */
|
||||
rtgui_rect_t rect;
|
||||
};
|
||||
|
||||
struct rtgui_event_paint
|
||||
{
|
||||
_RTGUI_EVENT_WIN_ELEMENTS
|
||||
|
||||
rtgui_rect_t rect; /* rect to be updated */
|
||||
};
|
||||
|
||||
struct rtgui_timer;
|
||||
struct rtgui_event_timer
|
||||
{
|
||||
struct rtgui_event parent;
|
||||
|
||||
struct rtgui_timer *timer;
|
||||
};
|
||||
typedef struct rtgui_event_timer rtgui_event_timer_t;
|
||||
|
||||
|
||||
struct rtgui_event_clip_info
|
||||
{
|
||||
_RTGUI_EVENT_WIN_ELEMENTS
|
||||
|
||||
/* the number of rects */
|
||||
//rt_uint32_t num_rect;
|
||||
|
||||
/* rtgui_rect_t *rects */
|
||||
};
|
||||
#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_END_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_UPDATE_END)
|
||||
#define RTGUI_EVENT_MONITOR_ADD_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_MONITOR_ADD)
|
||||
#define RTGUI_EVENT_MONITOR_REMOVE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_MONITOR_REMOVE)
|
||||
#define RTGUI_EVENT_CLIP_INFO_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_CLIP_INFO)
|
||||
#define RTGUI_EVENT_PAINT_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_PAINT)
|
||||
#define RTGUI_EVENT_TIMER_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_TIMER)
|
||||
|
||||
#define rtgui_event_show rtgui_event
|
||||
#define rtgui_event_hide rtgui_event
|
||||
|
||||
#define RTGUI_EVENT_SHOW_INIT(e) RTGUI_EVENT_INIT((e), RTGUI_EVENT_SHOW)
|
||||
#define RTGUI_EVENT_HIDE_INIT(e) RTGUI_EVENT_INIT((e), RTGUI_EVENT_HIDE)
|
||||
|
||||
struct rtgui_event_update_toplvl
|
||||
{
|
||||
struct rtgui_event parent;
|
||||
struct rtgui_win *toplvl;
|
||||
};
|
||||
|
||||
#define RTGUI_EVENT_UPDATE_TOPLVL_INIT(e) \
|
||||
do { \
|
||||
RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_UPDATE_TOPLVL); \
|
||||
(e)->toplvl = RT_NULL; \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* RTGUI Mouse and Keyboard Event
|
||||
*/
|
||||
struct rtgui_event_mouse
|
||||
{
|
||||
_RTGUI_EVENT_WIN_ELEMENTS
|
||||
|
||||
rt_uint16_t x, y;
|
||||
rt_uint16_t button;
|
||||
};
|
||||
#define RTGUI_MOUSE_BUTTON_LEFT 0x01
|
||||
#define RTGUI_MOUSE_BUTTON_RIGHT 0x02
|
||||
#define RTGUI_MOUSE_BUTTON_MIDDLE 0x03
|
||||
#define RTGUI_MOUSE_BUTTON_WHEELUP 0x04
|
||||
#define RTGUI_MOUSE_BUTTON_WHEELDOWN 0x08
|
||||
|
||||
#define RTGUI_MOUSE_BUTTON_DOWN 0x10
|
||||
#define RTGUI_MOUSE_BUTTON_UP 0x20
|
||||
|
||||
struct rtgui_event_kbd
|
||||
{
|
||||
_RTGUI_EVENT_WIN_ELEMENTS
|
||||
|
||||
rt_uint16_t type; /* key down or up */
|
||||
rt_uint16_t key; /* current key */
|
||||
rt_uint16_t mod; /* current key modifiers */
|
||||
rt_uint16_t unicode; /* translated character */
|
||||
};
|
||||
#define RTGUI_KBD_IS_SET_CTRL(e) ((e)->mod & (RTGUI_KMOD_LCTRL | RTGUI_KMOD_RCTRL)))
|
||||
#define RTGUI_KBD_IS_SET_ALT(e) ((e)->mod & (RTGUI_KMOD_LALT | RTGUI_KMOD_RALT))
|
||||
#define RTGUI_KBD_IS_SET_SHIFT(e) ((e)->mod & (RTGUI_KMOD_LSHIFT| RTGUI_KMOD_RSHIFT))
|
||||
#define RTGUI_KBD_IS_UP(e) ((e)->type == RTGUI_KEYUP)
|
||||
#define RTGUI_KBD_IS_DOWN(e) ((e)->type == RTGUI_KEYDOWN)
|
||||
|
||||
#define RTGUI_EVENT_MOUSE_MOTION_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_MOUSE_MOTION)
|
||||
#define RTGUI_EVENT_MOUSE_BUTTON_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_MOUSE_BUTTON)
|
||||
#define RTGUI_EVENT_KBD_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_KBD)
|
||||
|
||||
struct rtgui_event_command
|
||||
{
|
||||
_RTGUI_EVENT_WIN_ELEMENTS
|
||||
|
||||
/* command type */
|
||||
rt_int32_t type;
|
||||
|
||||
/* command id */
|
||||
rt_int32_t command_id;
|
||||
|
||||
/* command string */
|
||||
char command_string[RTGUI_NAME_MAX];
|
||||
};
|
||||
#define RTGUI_EVENT_COMMAND_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_COMMAND)
|
||||
|
||||
#define RTGUI_CMD_UNKNOWN 0x00
|
||||
#define RTGUI_CMD_WM_CLOSE 0x10
|
||||
|
||||
#define RTGUI_CMD_USER_INT 0x20
|
||||
#define RTGUI_CMD_USER_STRING 0x21
|
||||
|
||||
/************************************************************************/
|
||||
/* Widget Event */
|
||||
/************************************************************************/
|
||||
#define RTGUI_WIDGET_EVENT_INIT(e, t) do \
|
||||
{ \
|
||||
(e)->type = (t); \
|
||||
(e)->sender = RT_NULL; \
|
||||
(e)->ack = RT_NULL; \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* RTGUI Scrollbar Event
|
||||
*/
|
||||
struct rtgui_event_scrollbar
|
||||
{
|
||||
struct rtgui_event parent;
|
||||
|
||||
rt_uint8_t event;
|
||||
};
|
||||
#define RTGUI_SCROLL_LINEUP 0x01
|
||||
#define RTGUI_SCROLL_LINEDOWN 0x02
|
||||
#define RTGUI_SCROLL_PAGEUP 0x03
|
||||
#define RTGUI_SCROLL_PAGEDOWN 0x04
|
||||
#define RTGUI_EVENT_SCROLLED_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_SCROLLED)
|
||||
|
||||
/*
|
||||
* RTGUI Widget Focused Event
|
||||
*/
|
||||
struct rtgui_event_focused
|
||||
{
|
||||
struct rtgui_event parent;
|
||||
|
||||
struct rtgui_widget *widget;
|
||||
};
|
||||
#define RTGUI_EVENT_FOCUSED_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_FOCUSED)
|
||||
|
||||
/*
|
||||
* RTGUI Widget Resize Event
|
||||
*/
|
||||
struct rtgui_event_resize
|
||||
{
|
||||
struct rtgui_event parent;
|
||||
rt_int16_t x, y;
|
||||
rt_int16_t w, h;
|
||||
};
|
||||
#define RTGUI_EVENT_RESIZE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_RESIZE)
|
||||
|
||||
/*
|
||||
* RTGUI Model/View Event
|
||||
*/
|
||||
enum rtgui_event_model_mode
|
||||
{
|
||||
RTGUI_MV_DATA_ADDED,
|
||||
RTGUI_MV_DATA_CHANGED,
|
||||
RTGUI_MV_DATA_DELETED,
|
||||
};
|
||||
|
||||
struct rtgui_event_mv_model
|
||||
{
|
||||
struct rtgui_event parent;
|
||||
struct rtgui_mv_model *model;
|
||||
struct rtgui_mv_view *view;
|
||||
rt_size_t first_data_changed_idx;
|
||||
rt_size_t last_data_changed_idx;
|
||||
};
|
||||
|
||||
#define _RTGUI_EVENT_MV_INIT_TYPE(T) \
|
||||
rt_inline void RTGUI_EVENT_MV_MODEL_##T##_INIT(struct rtgui_event_mv_model *e) \
|
||||
{ \
|
||||
RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_MV_MODEL); \
|
||||
(e)->parent.user = RTGUI_MV_DATA_##T; \
|
||||
} \
|
||||
/* useless struct to allow trailing semicolon */ \
|
||||
struct dummy
|
||||
|
||||
_RTGUI_EVENT_MV_INIT_TYPE(ADDED);
|
||||
_RTGUI_EVENT_MV_INIT_TYPE(CHANGED);
|
||||
_RTGUI_EVENT_MV_INIT_TYPE(DELETED);
|
||||
#undef _RTGUI_EVENT_MV_INIT_TYPE
|
||||
|
||||
#define _RTGUI_EVENT_MV_IS_TYPE(T) \
|
||||
rt_inline rt_bool_t RTGUI_EVENT_MV_MODEL_IS_##T(struct rtgui_event_mv_model *e) \
|
||||
{ \
|
||||
return e->parent.user == RTGUI_MV_DATA_##T; \
|
||||
} \
|
||||
/* useless struct to allow trailing semicolon */ \
|
||||
struct dummy
|
||||
|
||||
_RTGUI_EVENT_MV_IS_TYPE(ADDED);
|
||||
_RTGUI_EVENT_MV_IS_TYPE(CHANGED);
|
||||
_RTGUI_EVENT_MV_IS_TYPE(DELETED);
|
||||
#undef _RTGUI_EVENT_MV_IS_TYPE
|
||||
|
||||
#undef _RTGUI_EVENT_WIN_ELEMENTS
|
||||
|
||||
union rtgui_event_generic
|
||||
{
|
||||
struct rtgui_event base;
|
||||
|
||||
struct rtgui_event_application app_create;
|
||||
struct rtgui_event_application app_destroy;
|
||||
struct rtgui_event_application app_activate;
|
||||
|
||||
struct rtgui_event_set_wm set_wm;
|
||||
struct rtgui_event_win win_base;
|
||||
struct rtgui_event_win_create win_create;
|
||||
struct rtgui_event_win_move win_move;
|
||||
struct rtgui_event_win_resize win_resize;
|
||||
struct rtgui_event_win_destroy win_destroy;
|
||||
struct rtgui_event_win_show win_show;
|
||||
struct rtgui_event_win_hide win_hide;
|
||||
struct rtgui_event_win_activate win_activate;
|
||||
struct rtgui_event_win_deactivate win_deactivate;
|
||||
struct rtgui_event_win_close win_close;
|
||||
struct rtgui_event_win_modal_enter win_modal_enter;
|
||||
struct rtgui_event_update_begin update_begin;
|
||||
struct rtgui_event_update_end update_end;
|
||||
struct rtgui_event_monitor monitor;
|
||||
struct rtgui_event_paint paint;
|
||||
struct rtgui_event_timer timer;
|
||||
struct rtgui_event_update_toplvl update_toplvl;
|
||||
struct rtgui_event_clip_info clip_info;
|
||||
struct rtgui_event_mouse mouse;
|
||||
struct rtgui_event_kbd kbd;
|
||||
struct rtgui_event_scrollbar scrollbar;
|
||||
struct rtgui_event_focused focused;
|
||||
struct rtgui_event_resize resize;
|
||||
struct rtgui_event_mv_model model;
|
||||
struct rtgui_event_command command;
|
||||
};
|
||||
#endif
|
||||
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* File : filerw.h
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rt-thread.org/license/LICENSE
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2009-10-16 Bernard first version
|
||||
*/
|
||||
#ifndef __RTGUI_FILERW_H__
|
||||
#define __RTGUI_FILERW_H__
|
||||
|
||||
#ifdef RTGUI_USING_DFS_FILERW
|
||||
#ifdef _WIN32_NATIVE
|
||||
#pragma warning(disable: 4996)
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <io.h>
|
||||
#else
|
||||
#include <dfs_posix.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <rtgui/rtgui.h>
|
||||
|
||||
#define RTGUI_FILE_SEEK_SET 0
|
||||
#define RTGUI_FILE_SEEK_CUR 1
|
||||
#define RTGUI_FILE_SEEK_END 2
|
||||
|
||||
struct rtgui_filerw
|
||||
{
|
||||
int (*seek)(struct rtgui_filerw *context, rt_off_t offset, int whence);
|
||||
int (*read)(struct rtgui_filerw *context, void *buffer, rt_size_t size, rt_size_t count);
|
||||
int (*write)(struct rtgui_filerw *context, const void *buffer, rt_size_t size, rt_size_t count);
|
||||
int (*tell)(struct rtgui_filerw *context);
|
||||
int (*eof)(struct rtgui_filerw *context);
|
||||
int (*close)(struct rtgui_filerw *context);
|
||||
};
|
||||
typedef struct rtgui_filerw rtgui_filerw_t;
|
||||
|
||||
struct rtgui_filerw *rtgui_filerw_create_file(const char *filename, const char *mode);
|
||||
struct rtgui_filerw *rtgui_filerw_create_mem(const rt_uint8_t *mem, rt_size_t size);
|
||||
|
||||
int rtgui_filerw_seek(struct rtgui_filerw *context, rt_off_t offset, int whence);
|
||||
int rtgui_filerw_read(struct rtgui_filerw *context, void *buffer, rt_size_t size, rt_size_t count);
|
||||
int rtgui_filerw_write(struct rtgui_filerw *context, const void *buffer, rt_size_t size, rt_size_t count);
|
||||
int rtgui_filerw_tell(struct rtgui_filerw *context);
|
||||
int rtgui_filerw_eof(struct rtgui_filerw *context);
|
||||
int rtgui_filerw_close(struct rtgui_filerw *context);
|
||||
int rtgui_filerw_unlink(const char *filename);
|
||||
|
||||
/* get memory data from filerw memory object */
|
||||
const rt_uint8_t *rtgui_filerw_mem_getdata(struct rtgui_filerw *context);
|
||||
|
||||
#endif
|
||||
@@ -1,118 +0,0 @@
|
||||
/*
|
||||
* File : font.h
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rt-thread.org/license/LICENSE
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2009-10-16 Bernard first version
|
||||
*/
|
||||
#ifndef __RTGUI_FONT_H__
|
||||
#define __RTGUI_FONT_H__
|
||||
|
||||
#include <rtgui/rtgui.h>
|
||||
#include <rtgui/list.h>
|
||||
|
||||
struct rtgui_font;
|
||||
struct rtgui_dc;
|
||||
struct rtgui_rect;
|
||||
|
||||
struct rtgui_font_engine
|
||||
{
|
||||
/* font engine function */
|
||||
void (*font_init)(struct rtgui_font *font);
|
||||
void (*font_load)(struct rtgui_font *font);
|
||||
|
||||
void (*font_draw_text)(struct rtgui_font *font, struct rtgui_dc *dc, const char *text,
|
||||
rt_ubase_t len, struct rtgui_rect *rect);
|
||||
void (*font_get_metrics)(struct rtgui_font *font, const char *text, struct rtgui_rect *rect);
|
||||
};
|
||||
|
||||
/*
|
||||
* bitmap font engine
|
||||
*/
|
||||
struct rtgui_font_bitmap
|
||||
{
|
||||
const rt_uint8_t *bmp; /* bitmap font data */
|
||||
const rt_uint8_t *char_width; /* each character width, NULL for fixed font */
|
||||
const rt_uint32_t *offset; /* offset for each character */
|
||||
|
||||
rt_uint16_t width; /* font width */
|
||||
rt_uint16_t height; /* font height */
|
||||
|
||||
rt_uint8_t first_char;
|
||||
rt_uint8_t last_char;
|
||||
};
|
||||
extern const struct rtgui_font_engine bmp_font_engine;
|
||||
|
||||
#include <rtgui/tree.h>
|
||||
SPLAY_HEAD(cache_tree, hz_cache);
|
||||
struct hz_cache
|
||||
{
|
||||
SPLAY_ENTRY(hz_cache) hz_node;
|
||||
|
||||
rt_uint16_t hz_id;
|
||||
};
|
||||
|
||||
struct rtgui_hz_file_font
|
||||
{
|
||||
struct cache_tree cache_root;
|
||||
rt_uint16_t cache_size;
|
||||
|
||||
/* font size */
|
||||
rt_uint16_t font_size;
|
||||
rt_uint16_t font_data_size;
|
||||
|
||||
/* file descriptor */
|
||||
int fd;
|
||||
|
||||
/* font file name */
|
||||
const char *font_fn;
|
||||
};
|
||||
extern const struct rtgui_font_engine rtgui_hz_file_font_engine;
|
||||
|
||||
struct rtgui_font
|
||||
{
|
||||
/* font name */
|
||||
char *family;
|
||||
|
||||
/* font height */
|
||||
rt_uint16_t height;
|
||||
|
||||
/* refer count */
|
||||
rt_uint32_t refer_count;
|
||||
|
||||
/* font engine */
|
||||
const struct rtgui_font_engine *engine;
|
||||
|
||||
/* font private data */
|
||||
void *data;
|
||||
|
||||
/* the font list */
|
||||
rtgui_list_t list;
|
||||
};
|
||||
typedef struct rtgui_font rtgui_font_t;
|
||||
|
||||
void rtgui_font_system_init(void);
|
||||
void rtgui_font_system_add_font(struct rtgui_font *font);
|
||||
void rtgui_font_system_remove_font(struct rtgui_font *font);
|
||||
struct rtgui_font *rtgui_font_default(void);
|
||||
void rtgui_font_set_defaut(struct rtgui_font *font);
|
||||
|
||||
struct rtgui_font *rtgui_font_refer(const char *family, rt_uint16_t height);
|
||||
void rtgui_font_derefer(struct rtgui_font *font);
|
||||
|
||||
/* draw a text */
|
||||
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 char *text);
|
||||
void rtgui_font_get_metrics(struct rtgui_font *font, const char *text, struct rtgui_rect *rect);
|
||||
|
||||
/* used by stract font */
|
||||
#define FONT_BMP_DATA_BEGIN
|
||||
#define FONT_BMP_DATA_END
|
||||
|
||||
#endif
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user