a8dac7ed473f381b7042cf9d14028488192624c5
As always, full log is in GitHub.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2276 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
dzzxzz@gmail.com 2012-09-07 01:50:13 +00:00
parent fd425e792d
commit 9707b6ce0b
55 changed files with 8795 additions and 351 deletions

124
components/external/lzo/README.LZO vendored Normal file
View File

@ -0,0 +1,124 @@
============================================================================
miniLZO -- mini subset of the LZO real-time data compression library
============================================================================
Author : Markus Franz Xaver Johannes Oberhumer
<markus@oberhumer.com>
http://www.oberhumer.com/opensource/lzo/
Version : 2.06
Date : 12 Aug 2011
I've created miniLZO for projects where it is inconvenient to
include (or require) the full LZO source code just because you
want to add a little bit of data compression to your application.
miniLZO implements the LZO1X-1 compressor and both the standard and
safe LZO1X decompressor. Apart from fast compression it also useful
for situations where you want to use pre-compressed data files (which
must have been compressed with LZO1X-999).
miniLZO consists of one C source file and three header files:
minilzo.c
minilzo.h, lzoconf.h, lzodefs.h
To use miniLZO just copy these files into your source directory, add
minilzo.c to your Makefile and #include minilzo.h from your program.
Note: you also must distribute this file ('README.LZO') with your project.
minilzo.o compiles to about 6 KiB (using gcc or Visual C on an i386), and
the sources are about 30 KiB when packed with zip - so there's no more
excuse that your application doesn't support data compression :-)
For more information, documentation, example programs and other support
files (like Makefiles and build scripts) please download the full LZO
package from
http://www.oberhumer.com/opensource/lzo/
Have fun,
Markus
P.S. minilzo.c is generated automatically from the LZO sources and
therefore functionality is completely identical
Appendix A: building miniLZO
----------------------------
miniLZO is written such a way that it should compile and run
out-of-the-box on most machines.
If you are running on a very unusual architecture and lzo_init() fails then
you should first recompile with '-DLZO_DEBUG' to see what causes the failure.
The most probable case is something like 'sizeof(void *) != sizeof(size_t)'.
After identifying the problem you can compile by adding some defines
like '-DSIZEOF_VOID_P=8' to your Makefile.
The best solution is (of course) using Autoconf - if your project uses
Autoconf anyway just add '-DMINILZO_HAVE_CONFIG_H' to your compiler
flags when compiling minilzo.c. See the LZO distribution for an example
how to set up configure.ac.
Appendix B: list of public functions available in miniLZO
---------------------------------------------------------
Library initialization
lzo_init()
Compression
lzo1x_1_compress()
Decompression
lzo1x_decompress()
lzo1x_decompress_safe()
Checksum functions
lzo_adler32()
Version functions
lzo_version()
lzo_version_string()
lzo_version_date()
Portable (but slow) string functions
lzo_memcmp()
lzo_memcpy()
lzo_memmove()
lzo_memset()
Appendix C: suggested macros for 'configure.ac' when using Autoconf
-------------------------------------------------------------------
Checks for typedefs and structures
AC_CHECK_TYPE(ptrdiff_t,long)
AC_TYPE_SIZE_T
AC_CHECK_SIZEOF(short)
AC_CHECK_SIZEOF(int)
AC_CHECK_SIZEOF(long)
AC_CHECK_SIZEOF(long long)
AC_CHECK_SIZEOF(__int64)
AC_CHECK_SIZEOF(void *)
AC_CHECK_SIZEOF(size_t)
AC_CHECK_SIZEOF(ptrdiff_t)
Checks for compiler characteristics
AC_C_CONST
Checks for library functions
AC_CHECK_FUNCS(memcmp memcpy memmove memset)
Appendix D: Copyright
---------------------
LZO and miniLZO are Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001,
2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
Markus Franz Xaver Oberhumer <markus@oberhumer.com>.
LZO and miniLZO are distributed under the terms of the GNU General
Public License (GPL). See the file COPYING.
Special licenses for commercial and other applications which
are not willing to accept the GNU General Public License
are available by contacting the author.

13
components/external/lzo/SConscript vendored Normal file
View File

@ -0,0 +1,13 @@
Import('RTT_ROOT')
Import('rtconfig')
from building import *
src = Split('''
minilzo.c
lzo.c
''')
CPPPATH = [RTT_ROOT + '/components/external/lzo']
group = DefineGroup('lzo', src, depend = ['RT_USING_LZO'], CPPPATH = CPPPATH)
Return('group')

159
components/external/lzo/lzo.c vendored Normal file
View File

@ -0,0 +1,159 @@
/* lzo.c - location for general purpose minilzo functions
* 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
*/
#include <rtthread.h>
#include "minilzo.h"
#include <rtgui/rtgui_config.h>
#include <rtgui/filerw.h>
#ifdef RT_USING_FINSH
#include <finsh.h>
#endif
#define RT_USING_LZO
#if defined(RT_USING_LZO) && defined(RTGUI_USING_DFS_FILERW)
/* the worst of allocation */
#define LZO1X_WORST(x) ( (x) + ((x)/16) + 64 + 3 )
#define HEAP_ALLOC(var,size) \
lzo_align_t __LZO_MMODEL var [ ((size) + (sizeof(lzo_align_t) - 1)) / sizeof(lzo_align_t) ]
static HEAP_ALLOC(wrkmem, LZO1X_1_MEM_COMPRESS);
char* parse_lzo_error_code(int error_code)
{
switch(error_code)
{
case LZO_E_ERROR: return "error";
case LZO_E_OUT_OF_MEMORY: return "out of memory";
case LZO_E_NOT_COMPRESSIBLE: return "not compressible";
case LZO_E_INPUT_OVERRUN: return "input overrun";
case LZO_E_OUTPUT_OVERRUN: return "output overrun";
case LZO_E_LOOKBEHIND_OVERRUN: return "lookbehind overrun";
case LZO_E_EOF_NOT_FOUND: return "eof not found";
case LZO_E_INPUT_NOT_CONSUMED: return "input not consumed";
case LZO_E_NOT_YET_IMPLEMENTED: return "not yet implemented"; /* [not used right now] */
case LZO_E_INVALID_ARGUMENT: return "invalid argument";
default: return "none";
}
}
int lzo(char *srcfile, char *destfile)
{
int result;
struct rtgui_filerw *file;
struct stat s;
lzo_bytep in;
lzo_bytep out;
lzo_uint in_len, out_len;
rt_memset(&s, 0, sizeof(struct stat));
stat(srcfile, &s);
in_len = s.st_size;
in = rt_malloc(in_len);
if (in == RT_NULL) return -1;
out = rt_malloc(LZO1X_WORST(in_len));
if (out == RT_NULL) return -1;
file = rtgui_filerw_create_file(srcfile, "rb");
if(file == RT_NULL)
{
result = -1;
goto _exit;
}
rtgui_filerw_read(file, in, in_len, 1);
rtgui_filerw_close(file);
result = lzo1x_1_compress(in, in_len, out, &out_len, wrkmem);
if(result != LZO_E_OK)
{
rt_kprintf("internal error - compression failed: \nerr_code:(%d) %s, %s.\n",
result, parse_lzo_error_code(result), "Please use the binary access");
goto _exit;
}
file = rtgui_filerw_create_file(destfile, "wb");
if(file == RT_NULL)
{
result = -1;
goto _exit;
}
rtgui_filerw_write(file, &in_len, sizeof(lzo_uint), 1); /* source file len */
rtgui_filerw_write(file, out, out_len, 1);
rtgui_filerw_close(file);
rt_kprintf("compress lzo ok!\n");
result = 0;
_exit:
rt_free(in);
rt_free(out);
return result;
}
#ifdef RT_USING_FINSH
FINSH_FUNCTION_EXPORT(lzo, compress a file. usage:lzo(src, dest));
#endif
int lzode(char *srcfile, char *destfile)
{
int result;
struct rtgui_filerw *file;
struct stat s;
lzo_bytep in=RT_NULL;
lzo_bytep out=RT_NULL;
lzo_uint in_len, out_len;
rt_memset(&s, 0, sizeof(struct stat));
stat(srcfile, &s);
in_len = s.st_size;
file = rtgui_filerw_create_file(srcfile, "rb");
if(file == RT_NULL) return 0;
rtgui_filerw_read(file, &out_len, sizeof(lzo_uint), 1); /* source file len */
in_len -= sizeof(lzo_uint);
in = rt_malloc(in_len);
if (in == RT_NULL) return -1;
out = rt_malloc(out_len);
if (out == RT_NULL) return -1;
rtgui_filerw_read(file, in, in_len, 1);
rtgui_filerw_close(file);
result = lzo1x_decompress(in, in_len, out, &out_len, RT_NULL);
if(result != LZO_E_OK)
{
rt_kprintf("internal error - decompression failed: \nerr_code:(%d) %s, %s.\n",
result, parse_lzo_error_code(result), "Please use the binary access");
goto _exit;
}
file = rtgui_filerw_create_file(destfile, "wb");
if(file == RT_NULL)
{
result = -1;
goto _exit;
}
rtgui_filerw_write(file, out, out_len, 1);
rtgui_filerw_close(file);
rt_kprintf("decompress lzo ok!\n");
result = 0;
_exit:
rt_free(in);
rt_free(out);
return result;
}
#ifdef RT_USING_FINSH
FINSH_FUNCTION_EXPORT(lzode, decompress a file. usage:lzode(src, dest));
#endif
#endif

446
components/external/lzo/lzoconf.h vendored Normal file
View File

@ -0,0 +1,446 @@
/* lzoconf.h -- configuration of the LZO data compression library
This file is part of the LZO real-time data compression library.
Copyright (C) 2011 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 2010 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer
All Rights Reserved.
The LZO library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
The LZO library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the LZO library; see the file COPYING.
If not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Markus F.X.J. Oberhumer
<markus@oberhumer.com>
http://www.oberhumer.com/opensource/lzo/
*/
#ifndef __LZOCONF_H_INCLUDED
#define __LZOCONF_H_INCLUDED 1
#define LZO_VERSION 0x2060
#define LZO_VERSION_STRING "2.06"
#define LZO_VERSION_DATE "Aug 12 2011"
/* internal Autoconf configuration file - only used when building LZO */
#if defined(LZO_HAVE_CONFIG_H)
# include <config.h>
#endif
#include <limits.h>
#include <stddef.h>
/***********************************************************************
// LZO requires a conforming <limits.h>
************************************************************************/
#if !defined(CHAR_BIT) || (CHAR_BIT != 8)
# error "invalid CHAR_BIT"
#endif
#if !defined(UCHAR_MAX) || !defined(UINT_MAX) || !defined(ULONG_MAX)
# error "check your compiler installation"
#endif
#if (USHRT_MAX < 1) || (UINT_MAX < 1) || (ULONG_MAX < 1)
# error "your limits.h macros are broken"
#endif
/* get OS and architecture defines */
#ifndef __LZODEFS_H_INCLUDED
#include "lzodefs.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
/***********************************************************************
// some core defines
************************************************************************/
#if !defined(LZO_UINT32_C)
# if (UINT_MAX < LZO_0xffffffffL)
# define LZO_UINT32_C(c) c ## UL
# else
# define LZO_UINT32_C(c) ((c) + 0U)
# endif
#endif
/* memory checkers */
#if !defined(__LZO_CHECKER)
# if defined(__BOUNDS_CHECKING_ON)
# define __LZO_CHECKER 1
# elif defined(__CHECKER__)
# define __LZO_CHECKER 1
# elif defined(__INSURE__)
# define __LZO_CHECKER 1
# elif defined(__PURIFY__)
# define __LZO_CHECKER 1
# endif
#endif
/***********************************************************************
// integral and pointer types
************************************************************************/
/* lzo_uint should match size_t */
#if !defined(LZO_UINT_MAX)
# if defined(LZO_ABI_LLP64) /* WIN64 */
# if defined(LZO_OS_WIN64)
typedef unsigned __int64 lzo_uint;
typedef __int64 lzo_int;
# else
typedef unsigned long long lzo_uint;
typedef long long lzo_int;
# endif
# define LZO_UINT_MAX 0xffffffffffffffffull
# define LZO_INT_MAX 9223372036854775807LL
# define LZO_INT_MIN (-1LL - LZO_INT_MAX)
# elif defined(LZO_ABI_IP32L64) /* MIPS R5900 */
typedef unsigned int lzo_uint;
typedef int lzo_int;
# define LZO_UINT_MAX UINT_MAX
# define LZO_INT_MAX INT_MAX
# define LZO_INT_MIN INT_MIN
# elif (ULONG_MAX >= LZO_0xffffffffL)
typedef unsigned long lzo_uint;
typedef long lzo_int;
# define LZO_UINT_MAX ULONG_MAX
# define LZO_INT_MAX LONG_MAX
# define LZO_INT_MIN LONG_MIN
# else
# error "lzo_uint"
# endif
#endif
/* Integral types with 32 bits or more. */
#if !defined(LZO_UINT32_MAX)
# if (UINT_MAX >= LZO_0xffffffffL)
typedef unsigned int lzo_uint32;
typedef int lzo_int32;
# define LZO_UINT32_MAX UINT_MAX
# define LZO_INT32_MAX INT_MAX
# define LZO_INT32_MIN INT_MIN
# elif (ULONG_MAX >= LZO_0xffffffffL)
typedef unsigned long lzo_uint32;
typedef long lzo_int32;
# define LZO_UINT32_MAX ULONG_MAX
# define LZO_INT32_MAX LONG_MAX
# define LZO_INT32_MIN LONG_MIN
# else
# error "lzo_uint32"
# endif
#endif
/* Integral types with exactly 64 bits. */
#if !defined(LZO_UINT64_MAX)
# if (LZO_UINT_MAX >= LZO_0xffffffffL)
# if ((((LZO_UINT_MAX) >> 31) >> 31) == 3)
# define lzo_uint64 lzo_uint
# define lzo_int64 lzo_int
# define LZO_UINT64_MAX LZO_UINT_MAX
# define LZO_INT64_MAX LZO_INT_MAX
# define LZO_INT64_MIN LZO_INT_MIN
# endif
# elif (ULONG_MAX >= LZO_0xffffffffL)
# if ((((ULONG_MAX) >> 31) >> 31) == 3)
typedef unsigned long lzo_uint64;
typedef long lzo_int64;
# define LZO_UINT64_MAX ULONG_MAX
# define LZO_INT64_MAX LONG_MAX
# define LZO_INT64_MIN LONG_MIN
# endif
# endif
#endif
/* The larger type of lzo_uint and lzo_uint32. */
#if (LZO_UINT_MAX >= LZO_UINT32_MAX)
# define lzo_xint lzo_uint
#else
# define lzo_xint lzo_uint32
#endif
/* Memory model that allows to access memory at offsets of lzo_uint. */
#if !defined(__LZO_MMODEL)
# if (LZO_UINT_MAX <= UINT_MAX)
# define __LZO_MMODEL /*empty*/
# elif defined(LZO_HAVE_MM_HUGE_PTR)
# define __LZO_MMODEL_HUGE 1
# define __LZO_MMODEL __huge
# else
# define __LZO_MMODEL /*empty*/
# endif
#endif
/* no typedef here because of const-pointer issues */
#define lzo_bytep unsigned char __LZO_MMODEL *
#define lzo_charp char __LZO_MMODEL *
#define lzo_voidp void __LZO_MMODEL *
#define lzo_shortp short __LZO_MMODEL *
#define lzo_ushortp unsigned short __LZO_MMODEL *
#define lzo_uint32p lzo_uint32 __LZO_MMODEL *
#define lzo_int32p lzo_int32 __LZO_MMODEL *
#if defined(LZO_UINT64_MAX)
#define lzo_uint64p lzo_uint64 __LZO_MMODEL *
#define lzo_int64p lzo_int64 __LZO_MMODEL *
#endif
#define lzo_uintp lzo_uint __LZO_MMODEL *
#define lzo_intp lzo_int __LZO_MMODEL *
#define lzo_xintp lzo_xint __LZO_MMODEL *
#define lzo_voidpp lzo_voidp __LZO_MMODEL *
#define lzo_bytepp lzo_bytep __LZO_MMODEL *
/* deprecated - use 'lzo_bytep' instead of 'lzo_byte *' */
#define lzo_byte unsigned char __LZO_MMODEL
typedef int lzo_bool;
/***********************************************************************
// function types
************************************************************************/
/* name mangling */
#if !defined(__LZO_EXTERN_C)
# ifdef __cplusplus
# define __LZO_EXTERN_C extern "C"
# else
# define __LZO_EXTERN_C extern
# endif
#endif
/* calling convention */
#if !defined(__LZO_CDECL)
# define __LZO_CDECL __lzo_cdecl
#endif
/* DLL export information */
#if !defined(__LZO_EXPORT1)
# define __LZO_EXPORT1 /*empty*/
#endif
#if !defined(__LZO_EXPORT2)
# define __LZO_EXPORT2 /*empty*/
#endif
/* __cdecl calling convention for public C and assembly functions */
#if !defined(LZO_PUBLIC)
# define LZO_PUBLIC(_rettype) __LZO_EXPORT1 _rettype __LZO_EXPORT2 __LZO_CDECL
#endif
#if !defined(LZO_EXTERN)
# define LZO_EXTERN(_rettype) __LZO_EXTERN_C LZO_PUBLIC(_rettype)
#endif
#if !defined(LZO_PRIVATE)
# define LZO_PRIVATE(_rettype) static _rettype __LZO_CDECL
#endif
/* function types */
typedef int
(__LZO_CDECL *lzo_compress_t) ( const lzo_bytep src, lzo_uint src_len,
lzo_bytep dst, lzo_uintp dst_len,
lzo_voidp wrkmem );
typedef int
(__LZO_CDECL *lzo_decompress_t) ( const lzo_bytep src, lzo_uint src_len,
lzo_bytep dst, lzo_uintp dst_len,
lzo_voidp wrkmem );
typedef int
(__LZO_CDECL *lzo_optimize_t) ( lzo_bytep src, lzo_uint src_len,
lzo_bytep dst, lzo_uintp dst_len,
lzo_voidp wrkmem );
typedef int
(__LZO_CDECL *lzo_compress_dict_t)(const lzo_bytep src, lzo_uint src_len,
lzo_bytep dst, lzo_uintp dst_len,
lzo_voidp wrkmem,
const lzo_bytep dict, lzo_uint dict_len );
typedef int
(__LZO_CDECL *lzo_decompress_dict_t)(const lzo_bytep src, lzo_uint src_len,
lzo_bytep dst, lzo_uintp dst_len,
lzo_voidp wrkmem,
const lzo_bytep dict, lzo_uint dict_len );
/* Callback interface. Currently only the progress indicator ("nprogress")
* is used, but this may change in a future release. */
struct lzo_callback_t;
typedef struct lzo_callback_t lzo_callback_t;
#define lzo_callback_p lzo_callback_t __LZO_MMODEL *
/* malloc & free function types */
typedef lzo_voidp (__LZO_CDECL *lzo_alloc_func_t)
(lzo_callback_p self, lzo_uint items, lzo_uint size);
typedef void (__LZO_CDECL *lzo_free_func_t)
(lzo_callback_p self, lzo_voidp ptr);
/* a progress indicator callback function */
typedef void (__LZO_CDECL *lzo_progress_func_t)
(lzo_callback_p, lzo_uint, lzo_uint, int);
struct lzo_callback_t
{
/* custom allocators (set to 0 to disable) */
lzo_alloc_func_t nalloc; /* [not used right now] */
lzo_free_func_t nfree; /* [not used right now] */
/* a progress indicator callback function (set to 0 to disable) */
lzo_progress_func_t nprogress;
/* NOTE: the first parameter "self" of the nalloc/nfree/nprogress
* callbacks points back to this struct, so you are free to store
* some extra info in the following variables. */
lzo_voidp user1;
lzo_xint user2;
lzo_xint user3;
};
/***********************************************************************
// error codes and prototypes
************************************************************************/
/* Error codes for the compression/decompression functions. Negative
* values are errors, positive values will be used for special but
* normal events.
*/
#define LZO_E_OK 0
#define LZO_E_ERROR (-1)
#define LZO_E_OUT_OF_MEMORY (-2) /* [lzo_alloc_func_t failure] */
#define LZO_E_NOT_COMPRESSIBLE (-3) /* [not used right now] */
#define LZO_E_INPUT_OVERRUN (-4)
#define LZO_E_OUTPUT_OVERRUN (-5)
#define LZO_E_LOOKBEHIND_OVERRUN (-6)
#define LZO_E_EOF_NOT_FOUND (-7)
#define LZO_E_INPUT_NOT_CONSUMED (-8)
#define LZO_E_NOT_YET_IMPLEMENTED (-9) /* [not used right now] */
#define LZO_E_INVALID_ARGUMENT (-10)
#ifndef lzo_sizeof_dict_t
# define lzo_sizeof_dict_t ((unsigned)sizeof(lzo_bytep))
#endif
/* lzo_init() should be the first function you call.
* Check the return code !
*
* lzo_init() is a macro to allow checking that the library and the
* compiler's view of various types are consistent.
*/
#define lzo_init() __lzo_init_v2(LZO_VERSION,(int)sizeof(short),(int)sizeof(int),\
(int)sizeof(long),(int)sizeof(lzo_uint32),(int)sizeof(lzo_uint),\
(int)lzo_sizeof_dict_t,(int)sizeof(char *),(int)sizeof(lzo_voidp),\
(int)sizeof(lzo_callback_t))
LZO_EXTERN(int) __lzo_init_v2(unsigned,int,int,int,int,int,int,int,int,int);
/* version functions (useful for shared libraries) */
LZO_EXTERN(unsigned) lzo_version(void);
LZO_EXTERN(const char *) lzo_version_string(void);
LZO_EXTERN(const char *) lzo_version_date(void);
LZO_EXTERN(const lzo_charp) _lzo_version_string(void);
LZO_EXTERN(const lzo_charp) _lzo_version_date(void);
/* string functions */
LZO_EXTERN(int)
lzo_memcmp(const lzo_voidp a, const lzo_voidp b, lzo_uint len);
LZO_EXTERN(lzo_voidp)
lzo_memcpy(lzo_voidp dst, const lzo_voidp src, lzo_uint len);
LZO_EXTERN(lzo_voidp)
lzo_memmove(lzo_voidp dst, const lzo_voidp src, lzo_uint len);
LZO_EXTERN(lzo_voidp)
lzo_memset(lzo_voidp buf, int c, lzo_uint len);
/* checksum functions */
LZO_EXTERN(lzo_uint32)
lzo_adler32(lzo_uint32 c, const lzo_bytep buf, lzo_uint len);
LZO_EXTERN(lzo_uint32)
lzo_crc32(lzo_uint32 c, const lzo_bytep buf, lzo_uint len);
LZO_EXTERN(const lzo_uint32p)
lzo_get_crc32_table(void);
/* misc. */
LZO_EXTERN(int) _lzo_config_check(void);
typedef union { lzo_bytep p; lzo_uint u; } __lzo_pu_u;
typedef union { lzo_bytep p; lzo_uint32 u32; } __lzo_pu32_u;
typedef union { void *vp; lzo_bytep bp; lzo_uint u; lzo_uint32 u32; unsigned long l; } lzo_align_t;
/* align a char pointer on a boundary that is a multiple of 'size' */
LZO_EXTERN(unsigned) __lzo_align_gap(const lzo_voidp p, lzo_uint size);
#define LZO_PTR_ALIGN_UP(p,size) \
((p) + (lzo_uint) __lzo_align_gap((const lzo_voidp)(p),(lzo_uint)(size)))
/***********************************************************************
// deprecated macros - only for backward compatibility with LZO v1.xx
************************************************************************/
#if defined(LZO_CFG_COMPAT)
#define __LZOCONF_H 1
#if defined(LZO_ARCH_I086)
# define __LZO_i386 1
#elif defined(LZO_ARCH_I386)
# define __LZO_i386 1
#endif
#if defined(LZO_OS_DOS16)
# define __LZO_DOS 1
# define __LZO_DOS16 1
#elif defined(LZO_OS_DOS32)
# define __LZO_DOS 1
#elif defined(LZO_OS_WIN16)
# define __LZO_WIN 1
# define __LZO_WIN16 1
#elif defined(LZO_OS_WIN32)
# define __LZO_WIN 1
#endif
#define __LZO_CMODEL /*empty*/
#define __LZO_DMODEL /*empty*/
#define __LZO_ENTRY __LZO_CDECL
#define LZO_EXTERN_CDECL LZO_EXTERN
#define LZO_ALIGN LZO_PTR_ALIGN_UP
#define lzo_compress_asm_t lzo_compress_t
#define lzo_decompress_asm_t lzo_decompress_t
#endif /* LZO_CFG_COMPAT */
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* already included */
/* vim:set ts=4 et: */

1852
components/external/lzo/lzodefs.h vendored Normal file

File diff suppressed because it is too large Load Diff

4579
components/external/lzo/minilzo.c vendored Normal file

File diff suppressed because it is too large Load Diff

109
components/external/lzo/minilzo.h vendored Normal file
View File

@ -0,0 +1,109 @@
/* minilzo.h -- mini subset of the LZO real-time data compression library
This file is part of the LZO real-time data compression library.
Copyright (C) 2011 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 2010 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer
All Rights Reserved.
The LZO library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
The LZO library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the LZO library; see the file COPYING.
If not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Markus F.X.J. Oberhumer
<markus@oberhumer.com>
http://www.oberhumer.com/opensource/lzo/
*/
/*
* NOTE:
* the full LZO package can be found at
* http://www.oberhumer.com/opensource/lzo/
*/
#ifndef __MINILZO_H
#define __MINILZO_H 1
#define MINILZO_VERSION 0x2060
#ifdef __LZOCONF_H
# error "you cannot use both LZO and miniLZO"
#endif
#undef LZO_HAVE_CONFIG_H
#include "lzoconf.h"
#if !defined(LZO_VERSION) || (LZO_VERSION != MINILZO_VERSION)
# error "version mismatch in header files"
#endif
#ifdef __cplusplus
extern "C" {
#endif
/***********************************************************************
//
************************************************************************/
/* Memory required for the wrkmem parameter.
* When the required size is 0, you can also pass a NULL pointer.
*/
#define LZO1X_MEM_COMPRESS LZO1X_1_MEM_COMPRESS
#define LZO1X_1_MEM_COMPRESS ((lzo_uint32) (16384L * lzo_sizeof_dict_t))
#define LZO1X_MEM_DECOMPRESS (0)
/* compression */
LZO_EXTERN(int)
lzo1x_1_compress ( const lzo_bytep src, lzo_uint src_len,
lzo_bytep dst, lzo_uintp dst_len,
lzo_voidp wrkmem );
/* decompression */
LZO_EXTERN(int)
lzo1x_decompress ( const lzo_bytep src, lzo_uint src_len,
lzo_bytep dst, lzo_uintp dst_len,
lzo_voidp wrkmem /* NOT USED */ );
/* safe decompression with overrun testing */
LZO_EXTERN(int)
lzo1x_decompress_safe ( const lzo_bytep src, lzo_uint src_len,
lzo_bytep dst, lzo_uintp dst_len,
lzo_voidp wrkmem /* NOT USED */ );
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* already included */

View File

@ -59,7 +59,6 @@ widgets/staticline.c
widgets/textbox.c
widgets/listbox.c
widgets/title.c
widgets/toplevel.c
widgets/notebook.c
widgets/container.c
widgets/list_view.c
@ -69,6 +68,8 @@ widgets/window.c
widgets/panel.c
widgets/groupbox.c
widgets/edit.c
widgets/plot.c
widgets/plot_curve.c
""")
# The set of source files associated with this SConscript file.

View File

@ -111,7 +111,7 @@ struct rtgui_dc* rtgui_dc_client_create(rtgui_widget_t* owner)
/* adjudge owner */
if (owner == RT_NULL || owner->toplevel == RT_NULL) return RT_NULL;
if (!RTGUI_IS_TOPLEVEL(owner->toplevel)) return RT_NULL;
if (!RTGUI_IS_WIN(owner->toplevel)) return RT_NULL;
dc = RTGUI_WIDGET_DC(owner);
/* set init visible as true */
@ -132,7 +132,7 @@ struct rtgui_dc* rtgui_dc_client_create(rtgui_widget_t* owner)
if (RTGUI_IS_WINTITLE(owner->toplevel))
{
rtgui_toplevel_t* top = RTGUI_TOPLEVEL(owner->toplevel);
struct rtgui_win* top = RTGUI_WIN(owner->toplevel);
top->drawing ++;
if (top->drawing == 1)
@ -155,7 +155,7 @@ struct rtgui_dc* rtgui_dc_client_create(rtgui_widget_t* owner)
}
else if (RTGUI_IS_WIN(owner->toplevel))
{
rtgui_toplevel_t* top = RTGUI_TOPLEVEL(owner->toplevel);
struct rtgui_win* top = RTGUI_WIN(owner->toplevel);
top->drawing ++;
if (top->drawing == 1)
@ -192,7 +192,7 @@ static rt_bool_t rtgui_dc_client_fini(struct rtgui_dc* dc)
if (RTGUI_IS_WINTITLE(owner->toplevel))
{
/* update title extent */
rtgui_toplevel_t* top = RTGUI_TOPLEVEL(owner->toplevel);
struct rtgui_win* top = RTGUI_WIN(owner->toplevel);
top->drawing --;
if ((top->drawing == 0) && RTGUI_WIDGET_IS_DC_VISIBLE(owner))
@ -220,7 +220,7 @@ static rt_bool_t rtgui_dc_client_fini(struct rtgui_dc* dc)
else if (RTGUI_IS_APP(owner->toplevel) ||
RTGUI_IS_WIN(owner->toplevel))
{
rtgui_toplevel_t* top = RTGUI_TOPLEVEL(owner->toplevel);
struct rtgui_win* top = RTGUI_WIN(owner->toplevel);
top->drawing --;
if ((top->drawing == 0) && RTGUI_WIDGET_IS_DC_VISIBLE(owner))

View File

@ -73,7 +73,7 @@ struct rtgui_dc* rtgui_dc_hw_create(rtgui_widget_t* owner)
/* adjudge owner */
if (owner == RT_NULL || owner->toplevel == RT_NULL) return RT_NULL;
if (!RTGUI_IS_TOPLEVEL(owner->toplevel)) return RT_NULL;
if (!RTGUI_IS_WIN(owner->toplevel)) return RT_NULL;
/* set init visible as true */
RTGUI_WIDGET_DC_SET_VISIBLE(owner);
@ -102,7 +102,7 @@ struct rtgui_dc* rtgui_dc_hw_create(rtgui_widget_t* owner)
if (RTGUI_IS_WINTITLE(owner->toplevel))
{
rtgui_toplevel_t* top = RTGUI_TOPLEVEL(owner->toplevel);
struct rtgui_win* top = RTGUI_WIN(owner->toplevel);
top->drawing ++;
if (top->drawing == 1)
@ -122,7 +122,7 @@ struct rtgui_dc* rtgui_dc_hw_create(rtgui_widget_t* owner)
else if (RTGUI_IS_APP(owner->toplevel) ||
RTGUI_IS_WIN(owner->toplevel))
{
rtgui_toplevel_t* top = RTGUI_TOPLEVEL(owner->toplevel);
struct rtgui_win* top = RTGUI_WIN(owner->toplevel);
top->drawing ++;
if (top->drawing == 1)
@ -161,7 +161,7 @@ static rt_bool_t rtgui_dc_hw_fini(struct rtgui_dc* dc)
if (RTGUI_IS_WINTITLE(owner->toplevel))
{
/* update title extent */
rtgui_toplevel_t* top = RTGUI_TOPLEVEL(owner->toplevel);
struct rtgui_win* top = RTGUI_WIN(owner->toplevel);
top->drawing --;
if ((top->drawing == 0) && RTGUI_WIDGET_IS_DC_VISIBLE(owner))
@ -189,7 +189,7 @@ static rt_bool_t rtgui_dc_hw_fini(struct rtgui_dc* dc)
else if (RTGUI_IS_APP(owner->toplevel) ||
RTGUI_IS_WIN(owner->toplevel))
{
rtgui_toplevel_t* top = RTGUI_TOPLEVEL(owner->toplevel);
struct rtgui_win* top = RTGUI_WIN(owner->toplevel);
top->drawing --;
if ((top->drawing == 0) && RTGUI_WIDGET_IS_DC_VISIBLE(owner))

View File

@ -11,9 +11,8 @@
* Date Author Notes
* 2009-10-16 Bernard first version
*/
#include <rtgui/filerw.h>
#include <rtgui/rtgui_system.h>
#include <rtgui/filerw.h>
#ifdef RTGUI_USING_DFS_FILERW
@ -264,6 +263,15 @@ struct rtgui_filerw* rtgui_filerw_create_file(const char* filename, const char*
return &(rw->parent);
}
int rtgui_filerw_unlink(const char *filename)
{
#ifdef _WIN32
return _unlink(filename);
#else
return unlink(filename);
#endif
}
#endif
struct rtgui_filerw* rtgui_filerw_create_mem(const rt_uint8_t* mem, rt_size_t size)
@ -341,11 +349,3 @@ int rtgui_filerw_close(struct rtgui_filerw* context)
return 0;
}
int rtgui_filerw_unlink(const char *filename)
{
#ifdef _WIN32
return _unlink(filename);
#else
return unlink(filename);
#endif
}

View File

@ -158,16 +158,16 @@ static void rtgui_bitmap_font_get_metrics(struct rtgui_font* font, const char* t
while (*text)
{
length = 0;
while (*(text + length) >= 0x80) length ++; /* it's not a ascii character */
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 ((*(text + length) < 0x80) && *(text + length)) length ++;
while (((rt_uint8_t)*(text + length) < 0x80) && *(text + length)) length ++;
if (bmp_font->char_width != NULL)
{
/* get width for each character */
while (*text && (*text < 0x80))
while (*text && ((rt_uint8_t)*text < 0x80))
{
rect->x2 += bmp_font->char_width[*text - bmp_font->first_char];
text ++;

View File

@ -11,6 +11,7 @@
* 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>
@ -315,3 +316,22 @@ void rtgui_image_get_rect(struct rtgui_image* image, struct rtgui_rect* rect)
}
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);

View File

@ -46,7 +46,9 @@ static rt_bool_t rtgui_image_bmp_check(struct rtgui_filerw *file);
static rt_bool_t rtgui_image_bmp_load(struct rtgui_image *image, struct rtgui_filerw *file, rt_bool_t load);
static void rtgui_image_bmp_unload(struct rtgui_image *image);
static void rtgui_image_bmp_blit(struct rtgui_image *image, struct rtgui_dc *dc, struct rtgui_rect *rect);
static struct rtgui_image* rtgui_image_bmp_zoom(struct rtgui_image* image,
float scalew, float scaleh, rt_uint32_t mode);
static struct rtgui_image* rtgui_image_bmp_rotate(struct rtgui_image* image, float angle);
struct rtgui_image_engine rtgui_image_bmp_engine =
{
@ -55,7 +57,9 @@ struct rtgui_image_engine rtgui_image_bmp_engine =
rtgui_image_bmp_check,
rtgui_image_bmp_load,
rtgui_image_bmp_unload,
rtgui_image_bmp_blit
rtgui_image_bmp_blit,
rtgui_image_bmp_zoom,
rtgui_image_bmp_rotate
};
static rt_bool_t rtgui_image_bmp_check(struct rtgui_filerw *file)
@ -289,8 +293,8 @@ static rt_bool_t rtgui_image_bmp_load(struct rtgui_image *image, struct rtgui_fi
bmp->pixels = RT_NULL;
bmp->filerw = file;
image->w = bmp->w >> bmp->scale;
image->h = bmp->h >> bmp->scale;
image->w = (rt_uint16_t)bmp->w >> bmp->scale;
image->h = (rt_uint16_t)bmp->h >> bmp->scale;
image->engine = &rtgui_image_bmp_engine;
image->data = bmp;
@ -367,8 +371,8 @@ static rt_bool_t rtgui_image_bmp_load(struct rtgui_image *image, struct rtgui_fi
rt_kprintf("\r%lu%%", y * 100UL / image->h);
/* Read data to buffer */
readLength = (BMP_WORKING_BUFFER_SIZE > (bmp->pitch - readIndex)) ? \
(bmp->pitch - readIndex) : BMP_WORKING_BUFFER_SIZE;
readLength = (BMP_WORKING_BUFFER_SIZE > ((rt_uint16_t)bmp->pitch - readIndex)) ? \
((rt_uint16_t)bmp->pitch - readIndex) : BMP_WORKING_BUFFER_SIZE;
if (rtgui_filerw_read(file, (void *)wrkBuffer, 1, readLength) != readLength)
{
rt_kprintf("BMP err: read failed\n");
@ -626,8 +630,8 @@ static void rtgui_image_bmp_blit(struct rtgui_image *image, struct rtgui_dc *dc,
rt_kprintf("\r%lu%%", y * 100UL / h);
/* Read data to buffer */
readLength = (BMP_WORKING_BUFFER_SIZE > (bmp->pitch - readIndex)) ? \
(bmp->pitch - readIndex) : BMP_WORKING_BUFFER_SIZE;
readLength = (BMP_WORKING_BUFFER_SIZE > ((rt_uint16_t)bmp->pitch - readIndex)) ? \
((rt_uint16_t)bmp->pitch - readIndex) : BMP_WORKING_BUFFER_SIZE;
if (rtgui_filerw_read(bmp->filerw, (void *)wrkBuffer, 1, readLength) != readLength)
{
rt_kprintf("BMP err: read failed\n");
@ -863,7 +867,7 @@ void rtgui_image_bmp_header_cfg(struct rtgui_image_bmp_header *bhr, rt_int32_t w
bhr->bfOffBits += 12;
}
}
#ifdef RTGUI_USING_DFS_FILERW
#define WRITE_CLUSTER_SIZE 2048
void bmp_align_write(struct rtgui_filerw *file, char *dest, char *src, rt_int32_t len, rt_int32_t *count)
{
@ -1003,6 +1007,292 @@ void screenshot(const char *filename)
#include <finsh.h>
FINSH_FUNCTION_EXPORT(screenshot, usage: screenshot(filename));
#endif
#endif
/*
* image zoom in, zoom out interface
* Support 16/24 bits format image
*/
static struct rtgui_image* rtgui_image_bmp_zoom(struct rtgui_image* image,
float scalew, float scaleh, rt_uint32_t mode)
{
struct rtgui_image *d_img;
struct rtgui_image_bmp *bmp, *d_bmp;
int bitcount, nbytes, i, j;
int sw, sh, dw, dh;
int dest_buff_size;
int src_line_size, dest_line_size;
char *src_buf;
char *des_buf;
bmp = (struct rtgui_image_bmp*)image->data;
src_buf = bmp->pixels;
sw = bmp->w;
sh = bmp->h;
bitcount = bmp->bit_per_pixel;
if(bitcount != 16 && bitcount != 24)
{
rt_kprintf("Does not support %d bits format\n", bitcount);
return RT_NULL;
}
nbytes = bitcount / 8;
src_line_size = sw * nbytes;
dw = (int)(sw / scalew);
dh = (int)(sh / scaleh);
d_img = rt_malloc(sizeof(struct rtgui_image));
if(d_img == RT_NULL)
{
rt_kprintf("Not enough memory allocation IMG!\n");
return RT_NULL;
}
d_img->w = dw;
d_img->h = dh;
d_img->engine = &rtgui_image_bmp_engine;
d_img->palette = RT_NULL;
/* config dest bmp data */
dest_line_size = ((dw * bitcount + (bitcount-1)) / bitcount) * nbytes;
dest_buff_size = dest_line_size * dh;
d_bmp = rt_malloc(sizeof(struct rtgui_image_bmp));
if(d_bmp == RT_NULL)
{
rt_free(d_img);
rt_kprintf("Not enough memory allocation BMP!\n");
return RT_NULL;
}
d_bmp->w = dw;
d_bmp->h = dh;
d_bmp->bit_per_pixel = bitcount;
d_bmp->pixel_offset = 54; /* insignificant parameter */
d_bmp->filerw = RT_NULL;
d_bmp->is_loaded = RT_TRUE; /* Don't want to loading */
d_bmp->pitch = d_bmp->w * nbytes;
d_bmp->pad = ((d_bmp->pitch % 4) ? (4 - (d_bmp->pitch%4)) : 0);
d_bmp->scale = 0;
d_bmp->pixels = rt_malloc(dest_buff_size);
if(d_bmp->pixels == RT_NULL)
{
rt_free(d_img);
rt_free(d_bmp);
rt_kprintf("Not enough memory allocation BMP data!\n");
return RT_NULL;
}
des_buf = d_bmp->pixels;
if (mode == RTGUI_IMG_ZOOM_NEAREST)
{
for (i = 0; i < dh; i++)
{
int src_th = (int)(scaleh * i + 0.5);
for (j = 0; j < dw; j++)
{
int src_tw = (int)(scalew * j + 0.5);
rt_memcpy (&des_buf[i * dest_line_size] + j * nbytes,
&src_buf[src_th * src_line_size] + src_tw * nbytes,
nbytes);
}
}
}
else if (mode == RTGUI_IMG_ZOOM_BILINEAR)
{
/*
** known: (i,j), (i+1,j), (i,j+1), (i+1,j+1), u, v
** float coord: (i+u, j+v)
** f(i+u,j+v) = (1-u)(1-v)f(i,j) + (1-u)vf(i,j+1) + u(1-v)f(i+1,j) + uvf(i+1,j+1)
*/
for (i = 0; i < dh; i++)
{
int y = (int)(scaleh * i);
float u = (float)(scaleh * i - y);
unsigned char c1, c2, c3, c4;
for (j = 0; j < dw; j++)
{
int x = (int)(scalew * j);
float v = (float)(scalew * j - x);
if(bitcount == 16)
{ /* Each color component is calculated separately */
rt_uint32_t cc1,cc2,cc3,cc4;
unsigned char r, g, b;
cc1 = rtgui_color_from_565p(*(rt_uint16_t*)(src_buf +
src_line_size * y + nbytes * x ));
cc2 = rtgui_color_from_565p(*(rt_uint16_t*)(src_buf +
src_line_size * y + nbytes * (x+1)));
cc3 = rtgui_color_from_565p(*(rt_uint16_t*)(src_buf +
src_line_size * (y+1) + nbytes * x ));
cc4 = rtgui_color_from_565p(*(rt_uint16_t*)(src_buf +
src_line_size * (y+1) + nbytes * (x+1)));
r = (unsigned char)((1-u)*(1-v)*(float)RTGUI_RGB_R(cc1) +
(1-u)*v*(float)RTGUI_RGB_R(cc2) + u*(1-v)*(float)RTGUI_RGB_R(cc3) +
u*v*(float)RTGUI_RGB_R(cc4));
g = (unsigned char)((1-u)*(1-v)*(float)RTGUI_RGB_G(cc1) +
(1-u)*v*(float)RTGUI_RGB_G(cc2) + u*(1-v)*(float)RTGUI_RGB_G(cc3) +
u*v*(float)RTGUI_RGB_G(cc4));
b = (unsigned char)((1-u)*(1-v)*(float)RTGUI_RGB_B(cc1) +
(1-u)*v*(float)RTGUI_RGB_B(cc2) + u*(1-v)*(float)RTGUI_RGB_B(cc3) +
u*v*(float)RTGUI_RGB_B(cc4));
*(rt_uint16_t*)(des_buf + i * dest_line_size + j * nbytes) =
rtgui_color_to_565p(RTGUI_RGB(r, g, b));
}
else if(bitcount == 24)
{
int k;
for (k = 0; k < 3; k++)
{ /* 24 bits color is 3 bytes R:G:B */
c1 = (src_buf[src_line_size * y + nbytes * x + k]);
c2 = (src_buf[src_line_size * y + nbytes * (x+1) + k]);
c3 = (src_buf[src_line_size * (y+1) + nbytes * x + k]);
c4 = (src_buf[src_line_size * (y+1) + nbytes * (x+1) + k]);
des_buf[i * dest_line_size + j * nbytes + k] = (unsigned char)
((1-u)*(1-v)*(float)c1 + (1-u)*v*(float)c2 + u*(1-v)*(float)c3 + u*v*(float)c4);
}
}
}
}
}
d_img->data = d_bmp;
return d_img;
}
#include <math.h>
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
/*
* around a pos o, rotating pos p
*/
rt_inline rtgui_point_t _rotate_pos(rtgui_point_t o, rtgui_point_t p, float sina, float cosa)
{
rtgui_point_t rp;
float dx, dy;
dx = p.x - o.x;
dy = p.y - o.y;
rp.x = (float)o.x + dx * cosa + dy * sina;
rp.y = (float)o.y + dy * cosa - dx * sina;
return rp;
}
/*
* image rotate interface, rotate direction: clockwise
* Support 16/24 bits format image
*/
static struct rtgui_image* rtgui_image_bmp_rotate(struct rtgui_image* image, float angle)
{
float age, sina, cosa;
rtgui_point_t o, p, cp;
rtgui_rect_t rect;
struct rtgui_image *d_img;
struct rtgui_image_bmp *bmp, *d_bmp;
int bitcount, nbytes, i, j;
int sw, sh, dw, dh;
int dest_buff_size;
int src_line_size, dest_line_size;
char *src_buf;
char *des_buf;
/* rt_tick_t tick = rt_tick_get(); */
bmp = (struct rtgui_image_bmp*)image->data;
src_buf = bmp->pixels;
sw = bmp->w;
sh = bmp->h;
bitcount = bmp->bit_per_pixel;
if(bitcount != 16 && bitcount != 24)
{
rt_kprintf("Does not support %d bits format\n", bitcount);
return RT_NULL;
}
nbytes = bitcount / 8;
src_line_size = sw * nbytes;
/* convert angle to radians */
age = angle * M_PI / 180.0;
sina = sin(age);
cosa = cos(age);
/*
** known: a, b, angle;
** solve: aa = a*abs(cos(angle)) + b*abs(sin(angle));
** solve: bb = b*abs(cos(angle)) + a*abs(sin(angle));
*/
dw = (int)(sw * fabs(cosa) + sh * fabs(sina));
dh = (int)(sh * fabs(cosa) + sw * fabs(sina));
rect.x1 = rect.y1 = 0;
rect.x2 = sw; rect.y2 = sh;
d_img = rt_malloc(sizeof(struct rtgui_image));
if(d_img == RT_NULL)
{
rt_kprintf("Not enough memory allocation IMG!\n");
return RT_NULL;
}
d_img->w = dw;
d_img->h = dh;
d_img->engine = &rtgui_image_bmp_engine;
d_img->palette = RT_NULL;
/* config dest bmp data */
dest_line_size = ((dw * bitcount + (bitcount-1)) / bitcount) * nbytes;
dest_buff_size = dest_line_size * dh;
d_bmp = rt_malloc(sizeof(struct rtgui_image_bmp));
if(d_bmp == RT_NULL)
{
rt_free(d_img);
rt_kprintf("Not enough memory allocation BMP!\n");
return RT_NULL;
}
d_bmp->w = dw;
d_bmp->h = dh;
d_bmp->bit_per_pixel = bitcount;
d_bmp->pixel_offset = 54; /* insignificant parameter */
d_bmp->filerw = RT_NULL;
d_bmp->is_loaded = RT_TRUE; /* Don't want to loading */
d_bmp->pitch = d_bmp->w * nbytes;
d_bmp->pad = ((d_bmp->pitch % 4) ? (4 - (d_bmp->pitch%4)) : 0);
d_bmp->scale = 0;
d_bmp->pixels = rt_malloc(dest_buff_size);
if(d_bmp->pixels == RT_NULL)
{
rt_free(d_img);
rt_free(d_bmp);
rt_kprintf("Not enough memory allocation BMP data!\n");
return RT_NULL;
}
des_buf = d_bmp->pixels;
/* use white fill empty pixel */
rt_memset(des_buf, 0xFF, dest_buff_size);
o.x = dw>>1;
o.y = dh>>1;
if(bitcount == 16 || bitcount == 24)
{
for (i = 0; i < dh; i++)
{
for (j = 0; j < dw; j++)
{
p.x = j; p.y = i;
cp = _rotate_pos(o, p, sina, cosa);
cp.x -= (dw-sw)>>1;
cp.y -= (dh-sh)>>1;
if(rtgui_rect_contains_point(&rect, cp.x, cp.y) != RT_EOK)
continue;
rt_memcpy (&des_buf[dest_line_size * i] + nbytes * j,
&src_buf[src_line_size * cp.y] + nbytes * cp.x, nbytes);
}
}
}
d_img->data = d_bmp;
/* rt_kprintf("rotate use %d ticks\n", rt_tick_get()-tick); */
return d_img;
}
void rtgui_image_bmp_init()
{

View File

@ -365,6 +365,7 @@ void rtgui_system_image_container_init(rt_bool_t load)
load_image = load;
}
#ifdef RTGUI_USING_DFS_FILERW
rtgui_image_item_t* rtgui_image_container_get(const char* filename)
{
struct rtgui_image_item* item;
@ -394,6 +395,7 @@ rtgui_image_item_t* rtgui_image_container_get(const char* filename)
return item;
}
#endif
rtgui_image_item_t* rtgui_image_container_get_memref(const char* type, const rt_uint8_t* memory, rt_uint32_t length)
{

View File

@ -34,7 +34,9 @@ struct rtgui_image_engine rtgui_image_hdc_engine =
rtgui_image_hdc_check,
rtgui_image_hdc_load,
rtgui_image_hdc_unload,
rtgui_image_hdc_blit
rtgui_image_hdc_blit,
RT_NULL,
RT_NULL
};
const struct rtgui_image_engine rtgui_image_hdcmm_engine =
@ -44,7 +46,9 @@ const struct rtgui_image_engine rtgui_image_hdcmm_engine =
RT_NULL,
RT_NULL,
RT_NULL,
rtgui_image_hdcmm_blit
rtgui_image_hdcmm_blit,
RT_NULL,
RT_NULL
};
static rt_bool_t rtgui_image_hdc_check(struct rtgui_filerw* file)

View File

@ -32,7 +32,9 @@ struct rtgui_image_engine rtgui_image_png_engine =
rtgui_image_png_check,
rtgui_image_png_load,
rtgui_image_png_unload,
rtgui_image_png_blit
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)

View File

@ -33,7 +33,9 @@ struct rtgui_image_engine rtgui_image_xpm_engine =
rtgui_image_xpm_check,
rtgui_image_xpm_load,
rtgui_image_xpm_unload,
rtgui_image_xpm_blit
rtgui_image_xpm_blit,
RT_NULL,
RT_NULL
};
struct rgb_item

View File

@ -14,6 +14,7 @@
#ifndef __RTGUI_FILERW_H__
#define __RTGUI_FILERW_H__
#ifdef RTGUI_USING_DFS_FILERW
#ifdef _WIN32
#pragma warning(disable: 4996)
#include <fcntl.h>
@ -23,6 +24,7 @@
#else
#include <dfs_posix.h>
#endif
#endif
#include <rtgui/rtgui.h>

View File

@ -18,6 +18,12 @@
#include <rtgui/filerw.h>
#include <rtgui/region.h>
enum rtgui_img_zoom
{
RTGUI_IMG_ZOOM_NEAREST,
RTGUI_IMG_ZOOM_BILINEAR
};
struct rtgui_image;
struct rtgui_image_engine
{
@ -31,6 +37,8 @@ struct rtgui_image_engine
void (*image_unload)(struct rtgui_image* image);
void (*image_blit)(struct rtgui_image* image, struct rtgui_dc* dc, struct rtgui_rect* rect);
struct rtgui_image* (*image_zoom)(struct rtgui_image* image, float scalew, float scaleh, rt_uint32_t mode);
struct rtgui_image* (*image_rotate)(struct rtgui_image* image, float angle);
};
struct rtgui_image_palette
@ -76,6 +84,8 @@ void rtgui_image_register_engine(struct rtgui_image_engine* engine);
/* blit an image on DC */
void rtgui_image_blit(struct rtgui_image* image, struct rtgui_dc* dc, struct rtgui_rect* rect);
struct rtgui_image_palette* rtgui_image_palette_create(rt_uint32_t ncolors);
rtgui_image_t* rtgui_image_zoom(rtgui_image_t* image, float scalew, float scaleh, rt_uint32_t mode);
rtgui_image_t* rtgui_image_rotate(rtgui_image_t* image, float angle);
#endif

View File

@ -16,8 +16,9 @@ struct rtgui_image_item
typedef struct rtgui_image_item rtgui_image_item_t;
void rtgui_system_image_container_init(rt_bool_t load);
#ifdef RTGUI_USING_DFS_FILERW
rtgui_image_item_t* rtgui_image_container_get(const char* filename);
#endif
rtgui_image_item_t* rtgui_image_container_get_from_mem(const rt_uint8_t* mem, const char* type, rt_uint32_t len);
void rtgui_image_container_put(rtgui_image_item_t* item);

View File

@ -0,0 +1,65 @@
/*
* File : plot.h
* 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-03 Grissiom first version
*/
#ifndef __RTGUI_PLOT_H__
#define __RTGUI_PLOT_H__
#include <rtgui/rtgui.h>
#include <rtgui/widgets/widget.h>
#include <rtgui/widgets/plot_curve.h>
DECLARE_CLASS_TYPE(plot);
/** Gets the type of a plot */
#define RTGUI_PLOT_TYPE (RTGUI_TYPE(plot))
/** Casts the object to an rtgui_plot */
#define RTGUI_PLOT(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_PLOT_TYPE, struct rtgui_plot))
/** Checks if the object is an rtgui_plot */
#define RTGUI_IS_PLOT(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_PLOT_TYPE))
struct rtgui_plot_curve_container
{
struct rtgui_plot_curve *curve;
struct rtgui_plot_curve_container *next;
};
enum rtgui_plot_flag
{
RTGUI_PLOT_INCREMENTAL,
RTGUI_PLOT_MOVING_WINDOW,
RTGUI_PLOT_SCAN,
};
/*
* the plot widget
*/
struct rtgui_plot
{
struct rtgui_widget parent;
enum rtgui_plot_flag pflag;
struct rtgui_point base_point;
struct rtgui_plot_curve_container curve_container;
};
struct rtgui_plot *rtgui_plot_create(struct rtgui_plot_curve*);
void rtgui_plot_destroy(struct rtgui_plot *plot);
void rtgui_plot_set_base_point(struct rtgui_plot *plot, rt_uint16_t x, rt_uint16_t y);
void rtgui_plot_append_curve(struct rtgui_plot *plot, struct rtgui_plot_curve *curve);
void rtgui_plot_remove_curve(struct rtgui_plot *plot, struct rtgui_plot_curve *curve);
rt_bool_t rtgui_plot_event_handler(struct rtgui_object *object, struct rtgui_event *event);
#endif

View File

@ -0,0 +1,45 @@
/*
* File : plot_curve.h
* 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-03 Grissiom first version
*/
#ifndef __RTGUI_PLOT_CURVE_H__
#define __RTGUI_PLOT_CURVE_H__
#include <rtgui/rtgui.h>
DECLARE_CLASS_TYPE(plot_curve);
/** Gets the type of a plot_curve */
#define RTGUI_PLOT_CURVE_TYPE (RTGUI_TYPE(plot_curve))
/** Casts the object to an rtgui_plot */
#define RTGUI_PLOT_CURVE(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_PLOT_CURVE_TYPE, struct rtgui_plot_curve))
/** Checks if the object is an rtgui_plot */
#define RTGUI_IS_PLOT_CURVE(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_PLOT_CURVE_TYPE))
/* change this if you want to use other type of data.
* For example, rt_uint8_t or rt_uint32_t. */
#define rtgui_plot_curve_dtype rt_int16_t
struct rtgui_plot_curve
{
struct rtgui_object parent;
rtgui_color_t color;
rt_size_t length;
rtgui_plot_curve_dtype *x_data;
rtgui_plot_curve_dtype *y_data;
};
struct rtgui_plot_curve *rtgui_plot_curve_create(void);
void rtgui_plot_curve_destroy(struct rtgui_plot_curve *curve);
#endif

View File

@ -14,7 +14,7 @@
#ifndef __RTGUI_TITLE__
#define __RTGUI_TITLE__
#include <rtgui/widgets/toplevel.h>
#include <rtgui/widgets/widget.h>
DECLARE_CLASS_TYPE(wintitle);
/** Gets the type of a title */
@ -26,14 +26,14 @@ DECLARE_CLASS_TYPE(wintitle);
struct rtgui_wintitle
{
struct rtgui_toplevel parent;
struct rtgui_widget parent;
/* title */
char* title;
};
typedef struct rtgui_wintitle rtgui_wintitle_t;
rtgui_wintitle_t* rtgui_wintitle_create(const char* title);
rtgui_wintitle_t* rtgui_wintitle_create(struct rtgui_win *window, const char* title);
void rtgui_wintitle_destroy(rtgui_wintitle_t* wintitle);
rt_bool_t rtgui_wintile_event_handler(rtgui_widget_t* widget, rtgui_event_t* event);

View File

@ -1,44 +0,0 @@
/*
* File : toplevel.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_TOPLEVEL_H__
#define __RTGUI_TOPLEVEL_H__
#include <rtgui/widgets/container.h>
DECLARE_CLASS_TYPE(toplevel);
/** Gets the type of a toplevel */
#define RTGUI_TOPLEVEL_TYPE (RTGUI_TYPE(toplevel))
/** Casts the object to an rtgui_toplevel */
#define RTGUI_TOPLEVEL(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_TOPLEVEL_TYPE, rtgui_toplevel_t))
/** Checks if the object is an rtgui_toplevel */
#define RTGUI_IS_TOPLEVEL(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_TOPLEVEL_TYPE))
struct rtgui_toplevel
{
/* inherit from view */
rtgui_container_t parent;
/* drawing count */
rt_base_t drawing;
/* external clip info */
rtgui_rect_t* external_clip_rect;
rt_uint32_t external_clip_size;
};
typedef struct rtgui_toplevel rtgui_toplevel_t;
rt_bool_t rtgui_toplevel_event_handler(struct rtgui_object* widget, struct rtgui_event* event);
void rtgui_toplevel_update_clip(rtgui_toplevel_t* top);
#endif

View File

@ -111,16 +111,6 @@ struct rtgui_widget
/* call back */
rt_bool_t (*on_focus_in) (struct rtgui_object* widget, struct rtgui_event* event);
rt_bool_t (*on_focus_out) (struct rtgui_object* widget, struct rtgui_event* event);
/* will be called just before the widget is shown. You can setup your
* widget in this call back. It's return value is ignored. The @param event
* will always be RT_NULL
*/
rt_bool_t (*on_show) (struct rtgui_object* widget, struct rtgui_event* event);
/* will be called just before the widget is hiden. You can setup your
* widget in this call back. It's return value is ignored. The @param event
* will always be RT_NULL
*/
rt_bool_t (*on_hide) (struct rtgui_object* widget, struct rtgui_event* event);
#ifndef RTGUI_USING_SMALL_SIZE
rt_bool_t (*on_draw) (struct rtgui_object* widget, struct rtgui_event* event);
rt_bool_t (*on_mouseclick) (struct rtgui_object* widget, struct rtgui_event* event);
@ -146,8 +136,6 @@ void rtgui_widget_unfocus(rtgui_widget_t *widget);
/* event handler for each command */
void rtgui_widget_set_onfocus(rtgui_widget_t* widget, rtgui_event_handler_ptr handler);
void rtgui_widget_set_onunfocus(rtgui_widget_t* widget, rtgui_event_handler_ptr handler);
void rtgui_widget_set_onshow(rtgui_widget_t* widget, rtgui_event_handler_ptr handler);
void rtgui_widget_set_onhide(rtgui_widget_t* widget, rtgui_event_handler_ptr handler);
#ifndef RTGUI_USING_SMALL_SIZE
void rtgui_widget_set_ondraw(rtgui_widget_t* widget, rtgui_event_handler_ptr handler);
void rtgui_widget_set_onmouseclick(rtgui_widget_t* widget, rtgui_event_handler_ptr handler);

View File

@ -18,7 +18,6 @@
#include <rtgui/rtgui.h>
#include <rtgui/list.h>
#include <rtgui/widgets/widget.h>
#include <rtgui/widgets/toplevel.h>
#include <rtgui/widgets/box.h>
DECLARE_CLASS_TYPE(win);
@ -67,8 +66,11 @@ struct rtgui_win_area;
struct rtgui_win
{
/* inherit from toplevel */
struct rtgui_toplevel parent;
/* inherit from container */
rtgui_container_t parent;
/* drawing count */
rt_base_t drawing;
/* parent window. RT_NULL if the window is a top level window */
struct rtgui_win *parent_window;
@ -134,6 +136,7 @@ void rtgui_win_move(struct rtgui_win* win, int x, int y);
/* reset extent of window */
void rtgui_win_set_rect(rtgui_win_t* win, rtgui_rect_t* rect);
void rtgui_win_update_clip(struct rtgui_win* win);
void rtgui_win_set_onactivate(rtgui_win_t* win, rtgui_event_handler_ptr handler);
void rtgui_win_set_ondeactivate(rtgui_win_t* win, rtgui_event_handler_ptr handler);

View File

@ -146,9 +146,9 @@ rt_err_t rtgui_topwin_add(struct rtgui_event_win_create* event)
if (!(topwin->flag & WINTITLE_NO)) rect.y1 -= WINTITLE_HEIGHT;
#ifdef RTGUI_USING_SMALL_SIZE
topwin->title = rtgui_wintitle_create(event->wid->title);
topwin->title = rtgui_wintitle_create(topwin->wid, event->wid->title);
#else
topwin->title = rtgui_wintitle_create((const char*)event->title);
topwin->title = rtgui_wintitle_create(topwin->wid, (const char*)event->title);
#endif
rtgui_widget_set_rect(RTGUI_WIDGET(topwin->title), &rect);

View File

@ -16,12 +16,14 @@
#include <rtgui/widgets/button.h>
#include <rtgui/widgets/window.h>
static rt_bool_t rtgui_button_onunfocus(struct rtgui_object* object, rtgui_event_t* event);
static void _rtgui_button_constructor(rtgui_button_t *button)
{
/* init widget and set event handler */
RTGUI_WIDGET(button)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
rtgui_object_set_event_handler(RTGUI_OBJECT(button), rtgui_button_event_handler);
rtgui_widget_set_onunfocus(RTGUI_WIDGET(button), rtgui_button_onunfocus);
/* un-press button */
button->flag = 0;
@ -259,3 +261,31 @@ void rtgui_button_set_onbutton(rtgui_button_t* btn, rtgui_onbutton_func_t func)
}
RTM_EXPORT(rtgui_button_set_onbutton);
static rt_bool_t rtgui_button_onunfocus(struct rtgui_object* object, rtgui_event_t* event)
{
rtgui_rect_t rect;
rtgui_widget_t *widget;
struct rtgui_dc *dc;
RT_ASSERT(object);
widget = RTGUI_WIDGET(object);
dc = rtgui_dc_begin_drawing(widget);
if(dc == RT_NULL) return RT_FALSE;
rtgui_widget_get_rect(widget, &rect);
if(!RTGUI_WIDGET_IS_FOCUSED(widget))
{
/* only clear focus rect */
rtgui_color_t color;
rtgui_rect_inflate(&rect, -2);
color = RTGUI_DC_FC(dc);
RTGUI_DC_FC(dc) = RTGUI_DC_BC(dc);
rtgui_dc_draw_focus_rect(dc, &rect);
RTGUI_DC_FC(dc) = color;
}
rtgui_dc_end_drawing(dc);
return RT_TRUE;
}

View File

@ -215,7 +215,7 @@ void rtgui_container_add_child(rtgui_container_t *container, rtgui_widget_t* chi
/* update children toplevel */
if (RTGUI_WIDGET(container)->toplevel != RT_NULL &&
RTGUI_IS_TOPLEVEL(RTGUI_WIDGET(container)->toplevel))
RTGUI_IS_WIN(RTGUI_WIDGET(container)->toplevel))
{
struct rtgui_event_update_toplvl eup;
RTGUI_EVENT_UPDATE_TOPLVL_INIT(&eup);
@ -279,7 +279,7 @@ void rtgui_container_destroy_children(rtgui_container_t *container)
container->children.next = RT_NULL;
/* update widget clip */
rtgui_toplevel_update_clip(RTGUI_TOPLEVEL(RTGUI_WIDGET(container)->toplevel));
rtgui_win_update_clip(RTGUI_WIN(RTGUI_WIDGET(container)->toplevel));
}
RTM_EXPORT(rtgui_container_destroy_children);

View File

@ -608,7 +608,7 @@ static rt_bool_t identify_double_byte(struct rtgui_edit *edit, struct edit_line
effe_nums = 0;
while(index--)
{
if(*(line->text + index) >= 0x80)
if((rt_uint8_t)(*(line->text + index)) >= 0x80)
effe_nums ++;
else
break;
@ -627,7 +627,7 @@ static rt_bool_t identify_double_byte(struct rtgui_edit *edit, struct edit_line
effe_nums = 0;
while(index < line->len)
{
if(*(line->text + index) >= 0x80)
if((rt_uint8_t)(*(line->text + index)) >= 0x80)
effe_nums ++;
else
break;
@ -1274,20 +1274,8 @@ static rt_bool_t rtgui_edit_onkey(struct rtgui_object* object, rtgui_event_t* ev
rtgui_edit_insert_line(edit, line, line->text + edit->upleft.x + edit->visual.x);
line->text[edit->upleft.x + edit->visual.x] = '\0';
line->len = rtgui_edit_line_strlen(line->text);
/* adjust update line end position */
if((edit->max_rows-edit->upleft.y) > edit->row_per_page)
{
update_type = EDIT_UPDATE;
edit->update.start = edit->visual;
update_end_line = rtgui_edit_get_line_by_index(edit, edit->upleft.y+edit->row_per_page-1);
if(update_end_line != RT_NULL)
{
edit->update.end.x = update_end_line->len;
edit->update.end.y = edit->upleft.y + edit->row_per_page;
}
}
else if((edit->max_rows-edit->upleft.y) < edit->row_per_page)
if((edit->max_rows-edit->upleft.y) < edit->row_per_page)
{
int update_end_index = rtgui_edit_get_index_by_line(edit, edit->tail);
update_type = EDIT_UPDATE;
@ -1306,6 +1294,20 @@ static rt_bool_t rtgui_edit_onkey(struct rtgui_object* object, rtgui_event_t* ev
rtgui_edit_onkey(object, (rtgui_event_t*)&event_kbd);
kbd_event_set_key(&event_kbd, RTGUIK_HOME);
rtgui_edit_onkey(object, (rtgui_event_t*)&event_kbd);
/* adjust update line end position */
if((edit->max_rows-edit->upleft.y) >= edit->row_per_page)
{
update_type = EDIT_UPDATE;
edit->update.start = edit->visual;
edit->update.start.y -= 1;
update_end_line = rtgui_edit_get_line_by_index(edit, edit->upleft.y+edit->row_per_page-1);
if(update_end_line != RT_NULL)
{
edit->update.end.x = update_end_line->len;
edit->update.end.y = edit->upleft.y + edit->row_per_page;
}
}
}
else
{
@ -1630,6 +1632,7 @@ void rtgui_edit_ondraw(struct rtgui_edit *edit)
}
line = line->next;
rect.y1 += edit->item_height;
if((rect.y1 + edit->item_height) < r.y2)
rect.y2 = rect.y1 + edit->item_height;
@ -1825,10 +1828,10 @@ rt_uint32_t rtgui_edit_get_mem_consume(struct rtgui_edit *edit)
return mem_size;
}
#ifdef RTGUI_USING_DFS_FILERW
/**
* File access component, General File Access Interface
*/
rt_bool_t rtgui_edit_readin_file(struct rtgui_edit *edit, const char *filename)
{
struct rtgui_filerw *filerw;
@ -1906,3 +1909,4 @@ rt_bool_t rtgui_edit_saveas_file(struct rtgui_edit *edit, const char *filename)
return RT_TRUE;
}
#endif

View File

@ -309,9 +309,8 @@ static void rtgui_filelist_view_menu_pop(rtgui_widget_t *parent)
listbox = rtgui_listbox_create(items, sizeof(items)/sizeof(items[0]), &rect);
rtgui_listbox_set_onitem(listbox, rtgui_filelist_view_on_folder_item);
rtgui_container_add_child(RTGUI_CONTAINER(menu), RTGUI_WIDGET(listbox));
rtgui_win_show(menu, RT_FALSE);
rtgui_widget_focus(RTGUI_WIDGET(listbox));
rtgui_listbox_set_current_item(listbox, 0);
rtgui_win_show(menu, RT_TRUE);
}
}
@ -675,6 +674,7 @@ rtgui_filelist_view_t* rtgui_filelist_view_create(const char* directory,
view = (struct rtgui_filelist_view*) rtgui_widget_create(RTGUI_FILELIST_VIEW_TYPE);
if (view != RT_NULL)
{
rtgui_widget_set_rect(RTGUI_WIDGET(view), rect);
view->items = RT_NULL;
view->pattern = rt_strdup(pattern);
view->page_items = rtgui_rect_height(*rect) / (1 + rtgui_theme_get_selected_height());
@ -683,12 +683,15 @@ rtgui_filelist_view_t* rtgui_filelist_view_create(const char* directory,
return view;
}
RTM_EXPORT(rtgui_filelist_view_create);
void rtgui_filelist_view_destroy(rtgui_filelist_view_t* view)
{
/* destroy view */
rtgui_widget_destroy(RTGUI_WIDGET(view));
}
RTM_EXPORT(rtgui_filelist_view_destroy);
/* clear all file items */
static void rtgui_filelist_view_clear(rtgui_filelist_view_t* view)
@ -712,6 +715,7 @@ static void rtgui_filelist_view_clear(rtgui_filelist_view_t* view)
view->items_count = 0;
view->current_item = 0;
}
RTM_EXPORT(rtgui_filelist_view_clear);
void rtgui_filelist_view_set_directory(rtgui_filelist_view_t* view, const char* directory)
{
@ -771,7 +775,11 @@ void rtgui_filelist_view_set_directory(rtgui_filelist_view_t* view, const char*
item = &(view->items[0]);
/* add .. directory */
item->name = rt_strdup("ØXµÌ<EFBFBD>`Á§ãš”M");
#ifdef RTGUI_USING_FONTHZ
item->name = rt_strdup("退出文件浏览");
#else
item->name = rt_strdup("..");
#endif
item->type = RTGUI_FITEM_DIR;
item->size = 0;
@ -824,6 +832,7 @@ __return:
/* update view */
rtgui_widget_update(RTGUI_WIDGET(view));
}
RTM_EXPORT(rtgui_filelist_view_set_directory);
void rtgui_filelist_view_get_fullpath(rtgui_filelist_view_t* view, char* path, rt_size_t len)
{
@ -836,4 +845,6 @@ void rtgui_filelist_view_get_fullpath(rtgui_filelist_view_t* view, char* path, r
rt_snprintf(path, len, "%s%s",view->current_directory,
view->items[view->current_item].name);
}
RTM_EXPORT(rtgui_filelist_view_get_fullpath);
#endif

View File

@ -18,6 +18,7 @@
static void _rtgui_label_constructor(rtgui_label_t *label)
{
RTGUI_WIDGET_TEXTALIGN(label) = RTGUI_ALIGN_LEFT | RTGUI_ALIGN_CENTER_VERTICAL;
/* init widget and set event handler */
rtgui_object_set_event_handler(RTGUI_OBJECT(label), rtgui_label_event_handler);

View File

@ -16,12 +16,13 @@
#include <rtgui/widgets/listbox.h>
#define LIST_MARGIN 5
static rt_bool_t rtgui_listbox_onunfocus(struct rtgui_object* object, rtgui_event_t* event);
static void _rtgui_listbox_constructor(struct rtgui_listbox *box)
{
/* set default widget rect and set event handler */
rtgui_object_set_event_handler(RTGUI_OBJECT(box), rtgui_listbox_event_handler);
rtgui_widget_set_onunfocus(RTGUI_WIDGET(box), rtgui_listbox_onunfocus);
RTGUI_WIDGET(box)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
box->current_item = -1;
@ -392,3 +393,31 @@ void rtgui_listbox_set_current_item(rtgui_listbox_t* box, int index)
}
RTM_EXPORT(rtgui_listbox_set_current_item);
static rt_bool_t rtgui_listbox_onunfocus(struct rtgui_object* object, rtgui_event_t* event)
{
rtgui_rect_t rect;
rtgui_widget_t *widget;
struct rtgui_dc *dc;
RT_ASSERT(object);
widget = RTGUI_WIDGET(object);
dc = rtgui_dc_begin_drawing(widget);
if(dc == RT_NULL) return RT_FALSE;
rtgui_widget_get_rect(widget, &rect);
if(!RTGUI_WIDGET_IS_FOCUSED(widget))
{
/* only clear focus rect */
rtgui_color_t color;
rect.x2 -= 1; rect.y2 -= 1;
color = RTGUI_DC_FC(dc);
RTGUI_DC_FC(dc) = RTGUI_DC_BC(dc);
rtgui_dc_draw_focus_rect(dc, &rect);
RTGUI_DC_FC(dc) = color;
}
rtgui_dc_end_drawing(dc);
return RT_TRUE;
}

View File

@ -383,7 +383,7 @@ void rtgui_notebook_add(struct rtgui_notebook* notebook, const char* label, stru
rtgui_widget_hide(child);
if (RTGUI_WIDGET(notebook)->toplevel != RT_NULL &&
RTGUI_IS_TOPLEVEL(RTGUI_WIDGET(notebook)->toplevel))
RTGUI_IS_WIN(RTGUI_WIDGET(notebook)->toplevel))
{
struct rtgui_event_update_toplvl eup;
RTGUI_EVENT_UPDATE_TOPLVL_INIT(&eup);
@ -421,7 +421,7 @@ void rtgui_notebook_add_image(struct rtgui_notebook* notebook, const char* label
rtgui_widget_hide(child);
if (RTGUI_WIDGET(notebook)->toplevel != RT_NULL &&
RTGUI_IS_TOPLEVEL(RTGUI_WIDGET(notebook)->toplevel))
RTGUI_IS_WIN(RTGUI_WIDGET(notebook)->toplevel))
{
struct rtgui_event_update_toplvl eup;
RTGUI_EVENT_UPDATE_TOPLVL_INIT(&eup);
@ -538,6 +538,7 @@ void rtgui_notebook_set_current_by_index(struct rtgui_notebook* notebook, rt_uin
notebook->current = index;
widget = notebook->childs[notebook->current].widget;
rtgui_widget_show(widget);
rtgui_widget_update_clip(widget);
rtgui_widget_update(widget);
rtgui_widget_focus(widget);
}

View File

@ -0,0 +1,184 @@
/*
* File : plot.h
* 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-03 Grissiom first version
*/
#include <rtgui/rtgui_system.h>
#include <rtgui/dc.h>
#include <rtgui/widgets/plot.h>
static void _rtgui_plot_constructor(struct rtgui_plot *plot)
{
plot->base_point.x = plot->base_point.y = 0;
plot->curve_container.curve = RT_NULL;
plot->curve_container.next = RT_NULL;
/* init widget and set event handler */
rtgui_object_set_event_handler(RTGUI_OBJECT(plot), rtgui_plot_event_handler);
}
static void _free_curve_container_recursive(struct rtgui_plot_curve_container *cnt)
{
if (!cnt)
return;
_free_curve_container_recursive(cnt->next);
rtgui_free(cnt);
}
static void _rtgui_plot_destructor(struct rtgui_plot *plot)
{
_free_curve_container_recursive(plot->curve_container.next);
}
DEFINE_CLASS_TYPE(plot, "plot",
RTGUI_WIDGET_TYPE,
_rtgui_plot_constructor,
_rtgui_plot_destructor,
sizeof(struct rtgui_plot));
struct rtgui_plot *rtgui_plot_create(struct rtgui_plot_curve *curve)
{
struct rtgui_plot *plot;
plot = (struct rtgui_plot *)rtgui_widget_create(RTGUI_PLOT_TYPE);
plot->curve_container.curve = curve;
return plot;
}
RTM_EXPORT(rtgui_plot_create);
void rtgui_plot_destroy(struct rtgui_plot *plot)
{
rtgui_widget_destroy(RTGUI_WIDGET(plot));
}
RTM_EXPORT(rtgui_plot_destroy);
void rtgui_plot_set_base_point(struct rtgui_plot *plot, rt_uint16_t x, rt_uint16_t y)
{
plot->base_point.x = x;
plot->base_point.y = y;
}
RTM_EXPORT(rtgui_plot_set_base_point);
void rtgui_plot_append_curve(struct rtgui_plot *plot, struct rtgui_plot_curve *curve)
{
struct rtgui_plot_curve_container *cur_cnt, *next_cnt;
RT_ASSERT(plot);
next_cnt = rtgui_malloc(sizeof(*next_cnt));
next_cnt->curve = curve;
next_cnt->next = RT_NULL;
cur_cnt = &plot->curve_container;
while (cur_cnt->next)
{
cur_cnt = cur_cnt->next;
}
cur_cnt->next = next_cnt;
}
RTM_EXPORT(rtgui_plot_append_curve);
static void _rtgui_plot_curve_onpaint(
struct rtgui_dc *dc,
struct rtgui_plot_curve *curve,
struct rtgui_point base)
{
struct rtgui_rect rect;
rt_uint16_t height;
int last_x, last_y;
rtgui_color_t old_color;
rtgui_dc_get_rect(dc, &rect);
height = rtgui_rect_height(rect);
old_color = RTGUI_DC_FC(dc);
RTGUI_DC_FC(dc) = curve->color;
if (curve->x_data)
{
rt_size_t i;
last_x = curve->x_data[0] + base.x;
last_y = height - curve->y_data[0] - base.y;
for (i = 1; i < curve->length; i++)
{
int cur_x = curve->x_data[i] + base.x;
int cur_y = height - curve->y_data[i] - base.y;
rtgui_dc_draw_line(dc,
last_x, last_y,
cur_x, cur_y);
last_x = cur_x;
last_y = cur_y;
}
}
else
{
rt_size_t i;
last_x = 0 + base.x;
last_y = height - curve->y_data[0] - base.y;
for (i = 1; i < curve->length; i++)
{
int cur_x = i + base.x;
int cur_y = height - curve->y_data[i] - base.y;
rtgui_dc_draw_line(dc,
last_x, last_y,
cur_x, cur_y);
last_x = cur_x;
last_y = cur_y;
}
}
RTGUI_DC_FC(dc) = old_color;
}
static void _rtgui_plot_onpaint(struct rtgui_object *object, struct rtgui_event *event)
{
struct rtgui_dc *dc;
struct rtgui_rect rect;
struct rtgui_plot *plot = RTGUI_PLOT(object);
struct rtgui_plot_curve_container *cnt;
dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(plot));
if (dc == RT_NULL)
return;
rtgui_widget_get_rect(RTGUI_WIDGET(object), &rect);
rtgui_dc_fill_rect(dc, &rect);
for (cnt = &plot->curve_container; cnt; cnt = cnt->next)
{
_rtgui_plot_curve_onpaint(dc, cnt->curve, plot->base_point);
}
rtgui_dc_end_drawing(dc);
}
rt_bool_t rtgui_plot_event_handler(struct rtgui_object *object, struct rtgui_event *event)
{
struct rtgui_plot *plot;
RTGUI_WIDGET_EVENT_HANDLER_PREPARE;
plot = RTGUI_PLOT(object);
switch (event->type)
{
case RTGUI_EVENT_PAINT:
_rtgui_plot_onpaint(object, event);
break;
default:
return rtgui_widget_event_handler(object, event);
}
return RT_FALSE;
}
RTM_EXPORT(rtgui_plot_event_handler);

View File

@ -0,0 +1,51 @@
/*
* File : plot.h
* 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-03 Grissiom first version
*/
#include <rtgui/color.h>
#include <rtgui/widgets/widget.h>
#include <rtgui/widgets/plot_curve.h>
static void _rtgui_plot_curve_constructor(struct rtgui_plot_curve *curve)
{
curve->length = 0;
curve->x_data = curve->y_data = RT_NULL;
curve->color = red;
/* init widget and set event handler */
rtgui_object_set_event_handler(RTGUI_OBJECT(curve), RT_NULL);
}
static void _rtgui_plot_curve_destructor(struct rtgui_plot_curve *curve)
{
/* nothing to do so far. */
}
DEFINE_CLASS_TYPE(plot_curve, "plot_curve",
RTGUI_OBJECT_TYPE,
_rtgui_plot_curve_constructor,
_rtgui_plot_curve_destructor,
sizeof(struct rtgui_plot_curve));
struct rtgui_plot_curve *rtgui_plot_curve_create(void)
{
return (struct rtgui_plot_curve*)rtgui_object_create(RTGUI_PLOT_CURVE_TYPE);
}
RTM_EXPORT(rtgui_plot_curve_create);
void rtgui_plot_curve_destroy(struct rtgui_plot_curve *curve)
{
rtgui_object_destroy(RTGUI_OBJECT(curve));
}
RTM_EXPORT(rtgui_plot_curve_destroy);

View File

@ -21,6 +21,8 @@
#define RTGUI_SLIDER_DEFAULT_MIN 0
#define RTGUI_SLIDER_DEFAULT_MAX 100
static rt_bool_t rtgui_slider_onunfocus(struct rtgui_object* object, rtgui_event_t* event);
static void _rtgui_slider_constructor(rtgui_slider_t *slider)
{
rtgui_rect_t rect = {0, 0, RTGUI_SLIDER_DEFAULT_WIDTH, RTGUI_SLIDER_DEFAULT_HEIGHT};
@ -29,7 +31,7 @@ static void _rtgui_slider_constructor(rtgui_slider_t *slider)
RTGUI_WIDGET(slider)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
rtgui_widget_set_rect(RTGUI_WIDGET(slider), &rect);
rtgui_object_set_event_handler(RTGUI_OBJECT(slider), rtgui_slider_event_handler);
rtgui_widget_set_onunfocus(RTGUI_WIDGET(slider), rtgui_slider_onunfocus);
/* set proper of control */
slider->min = RTGUI_SLIDER_DEFAULT_MIN;
slider->max = RTGUI_SLIDER_DEFAULT_MAX;
@ -274,3 +276,29 @@ rt_size_t rtgui_slider_get_value(struct rtgui_slider* slider)
}
RTM_EXPORT(rtgui_slider_get_value);
static rt_bool_t rtgui_slider_onunfocus(struct rtgui_object* object, rtgui_event_t* event)
{
rtgui_rect_t rect;
rtgui_widget_t *widget;
struct rtgui_dc *dc;
RT_ASSERT(object);
widget = RTGUI_WIDGET(object);
dc = rtgui_dc_begin_drawing(widget);
if(dc == RT_NULL) return RT_FALSE;
rtgui_widget_get_rect(widget, &rect);
if(!RTGUI_WIDGET_IS_FOCUSED(widget))
{
/* only clear focus rect */
rtgui_color_t color = RTGUI_DC_FC(dc);
RTGUI_DC_FC(dc) = RTGUI_DC_BC(dc);
rtgui_dc_draw_focus_rect(dc, &rect);
RTGUI_DC_FC(dc) = color;
}
rtgui_dc_end_drawing(dc);
return RT_TRUE;
}

View File

@ -29,13 +29,13 @@ static void _rtgui_wintitle_deconstructor(rtgui_wintitle_t* wintitle)
wintitle->title = RT_NULL;
}
DEFINE_CLASS_TYPE(wintitle, "wintitle",
RTGUI_TOPLEVEL_TYPE,
DEFINE_CLASS_TYPE(wintitle, "wintitle",
RTGUI_WIDGET_TYPE,
_rtgui_wintitle_constructor,
_rtgui_wintitle_deconstructor,
sizeof(struct rtgui_wintitle));
rtgui_wintitle_t* rtgui_wintitle_create(const char* title)
rtgui_wintitle_t* rtgui_wintitle_create(struct rtgui_win *window, const char* title)
{
rtgui_wintitle_t* wintitle;
@ -43,6 +43,7 @@ rtgui_wintitle_t* rtgui_wintitle_create(const char* title)
if (wintitle != RT_NULL)
{
rtgui_wintitle_set_title(wintitle, title);
RTGUI_WIDGET(wintitle)->toplevel = window;
}
return wintitle;

View File

@ -1,101 +0,0 @@
/*
* File : toplevel.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/widgets/toplevel.h>
#include <rtgui/widgets/window.h>
#include <rtgui/widgets/title.h>
static void _rtgui_toplevel_constructor(rtgui_toplevel_t *toplevel)
{
/* set event handler */
rtgui_object_set_event_handler(RTGUI_OBJECT(toplevel), rtgui_toplevel_event_handler);
/* set toplevel to self */
if (RTGUI_IS_WINTITLE(toplevel))
RTGUI_WIDGET(toplevel)->toplevel = (struct rtgui_win*)toplevel;
else
RTGUI_WIDGET(toplevel)->toplevel = RTGUI_WIN(toplevel);
/* init toplevel property */
toplevel->drawing = 0;
/* hide toplevel default */
RTGUI_WIDGET_HIDE(toplevel);
}
static void _rtgui_toplevel_destructor(rtgui_toplevel_t* toplevel)
{
/* release external clip info */
toplevel->drawing = 0;
}
DEFINE_CLASS_TYPE(toplevel, "toplevel",
RTGUI_CONTAINER_TYPE,
_rtgui_toplevel_constructor,
_rtgui_toplevel_destructor,
sizeof(struct rtgui_toplevel));
rt_bool_t rtgui_toplevel_event_handler(struct rtgui_object* object, rtgui_event_t* event)
{
struct rtgui_toplevel* toplevel;
RT_ASSERT(object != RT_NULL);
RT_ASSERT(event != RT_NULL);
toplevel = RTGUI_TOPLEVEL(object);
switch (event->type)
{
case RTGUI_EVENT_CLIP_INFO:
/* update toplevel clip */
rtgui_toplevel_update_clip(toplevel);
break;
case RTGUI_EVENT_COMMAND:
if (rtgui_container_dispatch_event(RTGUI_CONTAINER(object), event) != RT_TRUE)
{
#ifndef RTGUI_USING_SMALL_SIZE
if (RTGUI_WIDGET(object)->on_command != RT_NULL)
{
RTGUI_WIDGET(object)->on_command(object, event);
}
#endif
}
else return RT_TRUE;
break;
default :
return rtgui_container_event_handler(object, event);
}
return RT_FALSE;
}
void rtgui_toplevel_update_clip(rtgui_toplevel_t* top)
{
rtgui_container_t* view;
struct rtgui_list_node* node;
if (top == RT_NULL)
return;
/* update the clip info of each child */
view = RTGUI_CONTAINER(top);
rtgui_list_foreach(node, &(view->children))
{
rtgui_widget_t* child = rtgui_list_entry(node, rtgui_widget_t, sibling);
rtgui_widget_update_clip(child);
}
}

View File

@ -38,6 +38,11 @@ static void _rtgui_widget_constructor(rtgui_widget_t *widget)
widget->gc.textalign = RTGUI_ALIGN_LEFT | RTGUI_ALIGN_TOP;
widget->align = RTGUI_ALIGN_LEFT | RTGUI_ALIGN_TOP;
/* clear the garbage value of extent and clip */
widget->extent.x1 = widget->extent.y1 = 0;
widget->extent.x2 = widget->extent.y2 = 0;
rtgui_region_init_with_extents(&widget->clip, &widget->extent);
/* set parent and toplevel root */
widget->parent = RT_NULL;
widget->toplevel = RT_NULL;
@ -45,8 +50,6 @@ static void _rtgui_widget_constructor(rtgui_widget_t *widget)
/* some common event handler */
widget->on_focus_in = RT_NULL;
widget->on_focus_out = RT_NULL;
widget->on_show = RT_NULL;
widget->on_hide = RT_NULL;
#ifndef RTGUI_USING_SMALL_SIZE
widget->on_draw = RT_NULL;
@ -276,22 +279,6 @@ void rtgui_widget_set_onunfocus(rtgui_widget_t* widget, rtgui_event_handler_ptr
}
RTM_EXPORT(rtgui_widget_set_onunfocus);
void rtgui_widget_set_onshow(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
{
RT_ASSERT(widget != RT_NULL);
widget->on_show = handler;
}
RTM_EXPORT(rtgui_widget_set_onshow);
void rtgui_widget_set_onhide(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
{
RT_ASSERT(widget != RT_NULL);
widget->on_hide = handler;
}
RTM_EXPORT(rtgui_widget_set_onhide);
#ifndef RTGUI_USING_SMALL_SIZE
void rtgui_widget_set_ondraw(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
{
@ -385,8 +372,17 @@ void rtgui_widget_unfocus(rtgui_widget_t *widget)
RTGUI_WIN(widget->toplevel)->focused_widget = RT_NULL;
/* refresh widget */
rtgui_widget_update(widget);
/* Ergodic constituent widget, make child loss of focus */
if(RTGUI_IS_CONTAINER(widget))
{
rtgui_list_t *node;
rtgui_list_foreach(node, &(RTGUI_CONTAINER(widget)->children))
{
rtgui_widget_t *child = rtgui_list_entry(node, rtgui_widget_t, sibling);
if(RTGUI_WIDGET_IS_HIDE(child)) continue;
rtgui_widget_unfocus(child);
}
}
}
RTM_EXPORT(rtgui_widget_unfocus);
@ -617,9 +613,6 @@ rt_bool_t rtgui_widget_onshow(struct rtgui_object *object, struct rtgui_event *e
RTGUI_WIDGET_UNHIDE(widget);
if (widget->on_show != RT_NULL)
widget->on_show(RTGUI_OBJECT(widget), RT_NULL);
return RT_FALSE;
}
RTM_EXPORT(rtgui_widget_onshow);
@ -649,9 +642,6 @@ rt_bool_t rtgui_widget_onhide(struct rtgui_object *object, struct rtgui_event *e
rtgui_region_union_rect(&(parent->clip), &(parent->clip), &(widget->extent));
}
if (widget->on_hide != RT_NULL)
widget->on_hide(RTGUI_OBJECT(widget), RT_NULL);
return RT_FALSE;
}
RTM_EXPORT(rtgui_widget_onhide);

View File

@ -23,6 +23,15 @@
static void _rtgui_win_constructor(rtgui_win_t *win)
{
/* set toplevel to self */
RTGUI_WIDGET(win)->toplevel = win;
/* init win property */
win->drawing = 0;
/* hide win default */
RTGUI_WIDGET_HIDE(win);
RTGUI_WIDGET(win)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
win->parent_window = RT_NULL;
/* init window attribute */
@ -71,6 +80,8 @@ static void _rtgui_win_destructor(rtgui_win_t* win)
/* release field */
if (win->title != RT_NULL)
rt_free(win->title);
/* release external clip info */
win->drawing = 0;
}
static rt_bool_t _rtgui_win_create_in_server(struct rtgui_win *win)
@ -104,7 +115,7 @@ static rt_bool_t _rtgui_win_create_in_server(struct rtgui_win *win)
}
DEFINE_CLASS_TYPE(win, "win",
RTGUI_TOPLEVEL_TYPE,
RTGUI_CONTAINER_TYPE,
_rtgui_win_constructor,
_rtgui_win_destructor,
sizeof(struct rtgui_win));
@ -121,7 +132,7 @@ rtgui_win_t* rtgui_win_create(struct rtgui_win* parent_window,
if (win == RT_NULL)
return RT_NULL;
/* set parent toplevel */
/* set parent window */
win->parent_window = parent_window;
/* set title, rect and style */
@ -423,6 +434,24 @@ static rt_bool_t rtgui_win_ondraw(struct rtgui_win* win)
return RT_FALSE;
}
void rtgui_win_update_clip(struct rtgui_win* win)
{
struct rtgui_container* cnt;
struct rtgui_list_node* node;
if (win == RT_NULL)
return;
/* update the clip info of each child */
cnt = RTGUI_CONTAINER(win);
rtgui_list_foreach(node, &(cnt->children))
{
rtgui_widget_t* child = rtgui_list_entry(node, rtgui_widget_t, sibling);
rtgui_widget_update_clip(child);
}
}
rt_bool_t rtgui_win_event_handler(struct rtgui_object* object, struct rtgui_event* event)
{
struct rtgui_win* win;
@ -507,6 +536,11 @@ rt_bool_t rtgui_win_event_handler(struct rtgui_object* object, struct rtgui_even
}
break;
case RTGUI_EVENT_CLIP_INFO:
/* update win clip */
rtgui_win_update_clip(win);
break;
case RTGUI_EVENT_PAINT:
#ifndef RTGUI_USING_SMALL_SIZE
if (RTGUI_WIDGET(object)->on_draw != RT_NULL)
@ -588,9 +622,22 @@ rt_bool_t rtgui_win_event_handler(struct rtgui_object* object, struct rtgui_even
}
break;
default:
/* call parent event handler */
return rtgui_toplevel_event_handler(object, event);
case RTGUI_EVENT_COMMAND:
if (rtgui_container_dispatch_event(RTGUI_CONTAINER(object), event) != RT_TRUE)
{
#ifndef RTGUI_USING_SMALL_SIZE
if (RTGUI_WIDGET(object)->on_command != RT_NULL)
{
RTGUI_WIDGET(object)->on_command(object, event);
}
#endif
}
else
return RT_TRUE;
break;
default :
return rtgui_container_event_handler(object, event);
}
return RT_FALSE;

View File

@ -14,6 +14,7 @@ demo_view_module.c
src = Split("""
demo_application.c
demo_view.c
demo_xml.c
demo_view_benchmark.c
demo_view_dc.c
demo_view_ttf.c
@ -38,6 +39,8 @@ demo_view_notebook.c
demo_view_mywidget.c
demo_view_box.c
demo_view_edit.c
demo_view_bmp.c
demo_plot.c
mywidget.c
""")

View File

@ -94,19 +94,25 @@ static void application_entry(void *parameter)
demo_view_slider();
demo_view_notebook();
demo_view_mywidget();
demo_view_edit();
demo_plot();
#if defined(RTGUI_USING_DFS_FILERW)
demo_view_edit();
demo_view_bmp();
#endif
#if 0
#if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW)
#if defined(RTGUI_USING_DFS_FILERW)
demo_view_image();
#endif
#ifdef RT_USING_MODULE
#if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW)
#if defined(RTGUI_USING_DFS_FILERW)
demo_view_module();
#endif
#endif
demo_listview_view();
demo_listview_icon_view();
#if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW)
#if defined(RTGUI_USING_DFS_FILERW)
demo_fn_view();
#endif
#endif

65
examples/gui/demo_plot.c Normal file
View File

@ -0,0 +1,65 @@
#include <rtgui/widgets/plot.h>
#include "demo_view.h"
/* sin data */
rt_int16_t sin_ydata[] = {
0, 9, 19, 29, 38, 47, 56, 64, 71, 78, 84, 89, 93, 96, 98, 99, 99, 99, 97,
94, 90, 86, 80, 74, 67, 59, 51, 42, 33, 23, 14, 4, -5, -15, -25, -35, -44,
-52, -61, -68, -75, -81, -87, -91, -95, -97, -99, -99, -99, -98, -95, -92,
-88, -83, -77, -70, -63, -55, -46, -37, -27, -18, -8, 1, 11, 21, 31
};
rt_int16_t cos_ydata[] = {
50, 49, 46, 41, 34, 27, 18, 8, -1, -11, -20, -29, -36, -42, -47, -49, -49,
-48, -44, -39, -32, -24, -15, -5, 4, 14, 23, 31, 38, 44, 48, 49, 49, 47,
43, 37, 30, 21, 12, 2, -7, -16, -25, -33, -40, -45, -48, -49, -49, -46,
-41, -35, -28, -19, -9, 0, 10, 19, 28, 36, 42, 46, 49, 49, 48, 45, 40, 33,
25, 16, 6, -3, -12, -22, -30, -37, -43, -47, -49, -49, -47, -44, -38, -31,
-23, -13, -3, 6, 15, 24, 33, 39, 45, 48, 49, 49, 46, 42, 36, 29, 20, 10, 1,
-8, -18, -27, -35, -41, -46, -49, -49, -48, -45, -41, -34, -26, -17, -8, 1,
11, 21, 29, 37, 43, 47, 49, 49, 48, 44, 39, 32, 24, 14, 5, -4, -14, -23,
-32, -39, -44, -48, -49, -49, -47, -43, -37, -30, -21, -12, -2, 7, 17, 26,
34, 40, 45, 48, 49, 49, 46, 41, 35, 27, 18, 9, 0, -10, -20, -28, -36, -42,
-46, -49, -49, -48, -45, -40, -33, -25, -16, -6, 3, 13, 22, 31, 38, 43, 47,
49, 49, 47, 43, 38
};
struct rtgui_container* demo_plot(void)
{
struct rtgui_container *cnt;
struct rtgui_plot_curve *curve1, *curve2, *curve3;
struct rtgui_plot *plot;
struct rtgui_rect rect;
cnt = demo_view("ÇúĎßťćÍź");
curve1 = rtgui_plot_curve_create();
curve1->y_data = sin_ydata;
curve1->length = sizeof(sin_ydata)/sizeof(sin_ydata[0]);
curve1->color = red;
plot = rtgui_plot_create(curve1);
curve2 = rtgui_plot_curve_create();
curve2->y_data = cos_ydata;
curve2->length = sizeof(cos_ydata)/sizeof(cos_ydata[0]);
curve2->color = blue;
rtgui_plot_append_curve(plot, curve2);
curve3 = rtgui_plot_curve_create();
curve3->x_data = cos_ydata;
curve3->y_data = sin_ydata;
curve3->length = sizeof(sin_ydata)/sizeof(sin_ydata[0]);
curve3->color = black;
rtgui_plot_append_curve(plot, curve3);
rtgui_widget_get_rect(RTGUI_WIDGET(cnt), &rect);
rtgui_widget_set_rect(RTGUI_WIDGET(plot), &rect);
rtgui_plot_set_base_point(plot,
rtgui_rect_width(rect)/3, rtgui_rect_height(rect)/2);
rtgui_container_add_child(cnt, RTGUI_WIDGET(plot));
return cnt;
}

View File

@ -48,7 +48,7 @@ rtgui_container_t *demo_view(const char *title)
rtgui_widget_rect_to_device(RTGUI_WIDGET(container), &rect);
rect.x1 += 5;
rect.y1 += 5;
rect.x2 -= 5;
rect.x2 = rect.x1 + rt_strlen(title)*8;
rect.y2 = rect.y1 + 20;
/* 创建标题用的标签 */
@ -57,9 +57,11 @@ rtgui_container_t *demo_view(const char *title)
rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
/* 添加标签到视图中 */
rtgui_container_add_child(container, RTGUI_WIDGET(label));
rect.y1 += 20;
rect.y2 += 20;
rtgui_widget_get_rect(RTGUI_WIDGET(container), &rect);
rtgui_widget_rect_to_device(RTGUI_WIDGET(container), &rect);
rect.y1 += 20 + 5;
rect.y2 = rect.y1 + 2;
/* 创建一个水平的 staticline 线 */
line = rtgui_staticline_create(RTGUI_HORIZONTAL);
/* 设置静态线的位置信息 */

View File

@ -61,6 +61,22 @@ void timeout(struct rtgui_timer *timer, void *parameter)
rtgui_dc_end_drawing(dc);
}
static rt_bool_t animation_on_show(struct rtgui_object *object, struct rtgui_event *event)
{
rt_kprintf("animation on show\n");
if (timer != RT_NULL)
rtgui_timer_start(timer);
return RT_TRUE;
}
static rt_bool_t animation_on_hide(struct rtgui_object *object, struct rtgui_event *event)
{
rt_kprintf("animation on hide\n");
if (timer != RT_NULL)
rtgui_timer_stop(timer);
return RT_TRUE;
}
rt_bool_t animation_event_handler(struct rtgui_object *object, rtgui_event_t *event)
{
struct rtgui_widget *widget = RTGUI_WIDGET(object);
@ -90,6 +106,16 @@ rt_bool_t animation_event_handler(struct rtgui_object *object, rtgui_event_t *ev
/* 绘图完成 */
rtgui_dc_end_drawing(dc);
}
else if (event->type == RTGUI_EVENT_SHOW)
{
rtgui_container_event_handler(object, event);
animation_on_show(object, event);
}
else if (event->type == RTGUI_EVENT_HIDE)
{
rtgui_container_event_handler(object, event);
animation_on_hide(object, event);
}
else
{
/* 调用默认的事件处理函数 */
@ -99,22 +125,6 @@ rt_bool_t animation_event_handler(struct rtgui_object *object, rtgui_event_t *ev
return RT_FALSE;
}
static rt_bool_t animation_on_show(struct rtgui_object *object, struct rtgui_event *event)
{
rt_kprintf("animation on show\n");
if (timer != RT_NULL)
rtgui_timer_start(timer);
return RT_TRUE;
}
static rt_bool_t animation_on_hide(struct rtgui_object *object, struct rtgui_event *event)
{
rt_kprintf("animation on hide\n");
if (timer != RT_NULL)
rtgui_timer_stop(timer);
return RT_TRUE;
}
rtgui_container_t *demo_view_animation()
{
rtgui_container_t *container;
@ -127,8 +137,5 @@ rtgui_container_t *demo_view_animation()
rtgui_rect_moveto(&text_rect, 0, 45);
timer = rtgui_timer_create(2, RT_TIMER_FLAG_PERIODIC, timeout, (void *)container);
rtgui_widget_set_onshow(RTGUI_WIDGET(container), animation_on_show);
rtgui_widget_set_onhide(RTGUI_WIDGET(container), animation_on_hide);
return container;
}

View File

@ -1,3 +1,4 @@
#include <stdlib.h>
#include <rtgui/dc.h>
#include <rtgui/dc_hw.h>
#include <rtgui/rtgui_system.h>
@ -8,6 +9,8 @@
static struct rtgui_container *container = RT_NULL;
static int running = 0;
static rt_tick_t ticks;
static long long area;
void _onidle(struct rtgui_object *object, rtgui_event_t *event)
{
@ -26,7 +29,7 @@ void _onidle(struct rtgui_object *object, rtgui_event_t *event)
draw_rect.y1 = RAND(rect.y1, rect.y2);
draw_rect.x2 = RAND(draw_rect.x1, rect.x2);
draw_rect.y2 = RAND(draw_rect.y1, rect.y2);
area += rtgui_rect_width(draw_rect) * rtgui_rect_height(draw_rect);
color = RTGUI_RGB(rand() % 255, rand() % 255, rand() % 255);
RTGUI_WIDGET_BACKGROUND(container) = color;
@ -34,6 +37,14 @@ void _onidle(struct rtgui_object *object, rtgui_event_t *event)
/* »æͼÍê³É */
rtgui_dc_end_drawing(dc);
if(rt_tick_get()-ticks >= RT_TICK_PER_SECOND)
{
char buf[16];
sprintf(buf, "%.2f", (double)area/(800*480));
rt_kprintf("frames per second: %s fps\n", buf);
area = 0;
ticks = rt_tick_get();
}
}
void _draw_default(struct rtgui_object *object, rtgui_event_t *event)
@ -70,6 +81,11 @@ rt_bool_t benchmark_event_handler(struct rtgui_object *object, rtgui_event_t *ev
{
_draw_default(object, event);
}
else if (event->type == RTGUI_EVENT_SHOW)
{
rtgui_container_event_handler(object, event);
_benchmark_onshow(object, event);
}
else if (event->type == RTGUI_EVENT_KBD)
{
struct rtgui_event_kbd *kbd = (struct rtgui_event_kbd *)event;
@ -88,6 +104,8 @@ rt_bool_t benchmark_event_handler(struct rtgui_object *object, rtgui_event_t *ev
else
{
/* run */
ticks = rt_tick_get();
area = 0;
rtgui_app_set_onidle(_onidle);
}
@ -116,7 +134,6 @@ rtgui_container_t *demo_view_benchmark(void)
container = demo_view("»æͼ²âÊÔ");
RTGUI_WIDGET(container)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
rtgui_object_set_event_handler(RTGUI_OBJECT(container), benchmark_event_handler);
rtgui_widget_set_onshow(RTGUI_WIDGET(container), _benchmark_onshow);
return container;
}

View File

@ -0,0 +1,304 @@
/*
* bmp_zoom演示
*/
#include "demo_view.h"
#include <rtgui/dc.h>
#include <rtgui/image.h>
#include <rtgui/image_bmp.h>
#include <rtgui/widgets/label.h>
#include <rtgui/widgets/button.h>
#include <rtgui/widgets/textbox.h>
#include <rtgui/widgets/container.h>
#if defined(RTGUI_USING_DFS_FILERW)
struct demo_bmp_dt
{
float scale, angle;
char *filename;
struct rtgui_image *image;
struct rtgui_image *showimg;
rtgui_container_t *showbox;
rtgui_textbox_t *box;
rtgui_rect_t lastrect;
}bmpdt;
rt_bool_t demo_bitmap_showbox(struct rtgui_object* object, struct rtgui_event* event)
{
rtgui_container_t *container;
rtgui_widget_t *widget;
RT_ASSERT(object != RT_NULL);
container = RTGUI_CONTAINER(object);
widget = RTGUI_WIDGET(object);
if(event->type == RTGUI_EVENT_PAINT)
{
int w, h;
rtgui_rect_t rect;
struct rtgui_dc *dc;
struct rtgui_image *image = bmpdt.showimg;
/* 如果从其他标签切换到当前标签, image应该是RT_NULL, 重置它 */
if(image == RT_NULL && bmpdt.image != RT_NULL)
{
image = bmpdt.image;
bmpdt.scale = 1.0f;
bmpdt.angle = 0.0f;
rtgui_widget_get_rect(RTGUI_WIDGET(bmpdt.showbox), &bmpdt.lastrect);
rtgui_rect_inflate(&bmpdt.lastrect, -RTGUI_WIDGET_BORDER(bmpdt.showbox));
}
dc = rtgui_dc_begin_drawing(widget);
if (dc == RT_NULL)
return RT_FALSE;
rtgui_widget_get_rect(widget, &rect);
/* 在绘制边框后, 再将rect缩小填充背景, 可以降低闪烁现象 */
rtgui_dc_draw_border(dc, &rect, RTGUI_WIDGET_BORDER_STYLE(widget));
rtgui_rect_inflate(&rect, -RTGUI_WIDGET_BORDER(widget));
w = rtgui_rect_width(bmpdt.lastrect);
h = rtgui_rect_height(bmpdt.lastrect);
if(w > rtgui_rect_width(rect)) w = rtgui_rect_width(rect);
if(h > rtgui_rect_height(rect)) h = rtgui_rect_height(rect);
/* fill container with background */
/*
* lastrect会记录上一次绘图所用区域
* ,lastrect比较,
* ,lastrect比当前绘图区小,,
* , lastrect大的区域.
*/
if(image != RT_NULL)
{ /* 减少不必要的绘图 */
rtgui_rect_t rc;
if(w > image->w)
{
rc.x1 = image->w;
rc.y1 = bmpdt.lastrect.y1;
rc.x2 = bmpdt.lastrect.x2;
rc.y2 = (h > image->h) ? image->h : bmpdt.lastrect.y2;
rtgui_dc_fill_rect(dc, &rc);
}
if(h > image->h)
{
rc.x1 = bmpdt.lastrect.x1;
rc.y1 = image->h;
rc.x2 = bmpdt.lastrect.x2;
rc.y2 = bmpdt.lastrect.y2;
rtgui_dc_fill_rect(dc, &rc);
}
}
else
rtgui_dc_fill_rect(dc, &bmpdt.lastrect);
/* 将图像数据blit到画布上 */
if (image != RT_NULL)
{
int value;
rtgui_image_blit(image, dc, &rect);
bmpdt.lastrect.x1 = bmpdt.lastrect.y1 = RTGUI_WIDGET_BORDER(bmpdt.showbox);
if(image->w > rtgui_rect_width(rect))
value = rtgui_rect_width(rect);
else
value = image->w;
bmpdt.lastrect.x2 = bmpdt.lastrect.x1 + value;
if(image->h > rtgui_rect_height(rect))
value = rtgui_rect_height(rect);
else
value = image->h;
bmpdt.lastrect.y2 = bmpdt.lastrect.y1 + value;
}
rtgui_dc_end_drawing(dc);
return RT_FALSE;
}
return rtgui_container_event_handler(object, event);
}
void demo_bitmap_open(struct rtgui_object* object, struct rtgui_event* event)
{
char *str;
rtgui_button_t *button = RTGUI_BUTTON(object);
/* 从textbox控件中取得文件名 */
str = (char*)rtgui_textbox_get_value(bmpdt.box);
if(str == RT_NULL) return;
if(*str == '/' && (rt_strstr(str, ".bmp")!=RT_NULL || rt_strstr(str, ".BMP")!=RT_NULL))
{ /* 如果是bmp文件, 且文件名有效, 则读入图像数据 */
if(bmpdt.filename != RT_NULL)
rt_free(bmpdt.filename);
bmpdt.filename = rt_strdup(str);
if(bmpdt.image != RT_NULL)
rtgui_image_destroy(bmpdt.image);
bmpdt.image = rtgui_image_create_from_file("bmp", bmpdt.filename, RT_TRUE);
if(bmpdt.image != RT_NULL)
{
bmpdt.showimg = bmpdt.image;
bmpdt.scale = 1.0;
bmpdt.angle = 0.0;
rtgui_widget_update(RTGUI_WIDGET(bmpdt.showbox));
}
}
else
rt_kprintf("Bad filename!");
}
void demo_image_zoom_in(struct rtgui_object* object, struct rtgui_event* event)
{
rtgui_button_t *button = RTGUI_BUTTON(object);
if (bmpdt.image == RT_NULL) return;
if (bmpdt.scale > 0.45)
{ /* 更新缩放倍率 */
if (bmpdt.scale > 1.0) bmpdt.scale -= (float)0.5;
else bmpdt.scale -= (float)0.1;
}
/* 根据缩放倍率, 缩放原始图形, 并得到新图形的指针 */
bmpdt.showimg = rtgui_image_zoom(bmpdt.image, bmpdt.scale, bmpdt.scale, RTGUI_IMG_ZOOM_BILINEAR);
if (bmpdt.showimg != RT_NULL)
rtgui_widget_update(RTGUI_WIDGET(bmpdt.showbox));
else
return;
if(bmpdt.showimg != bmpdt.image)
{ /* 释放掉新图形所用的资源 */
rtgui_image_destroy(bmpdt.showimg);
bmpdt.showimg = RT_NULL;
}
}
void demo_image_zoom_out(struct rtgui_object* object, struct rtgui_event* event)
{
rtgui_button_t *button = RTGUI_BUTTON(object);
if (bmpdt.image == RT_NULL) return;
if (bmpdt.scale < 4.95)
{ /* 更新缩放倍率 */
if (bmpdt.scale > 0.95) bmpdt.scale += (float)0.5;
else bmpdt.scale += (float)0.1;
}
bmpdt.showimg = rtgui_image_zoom(bmpdt.image, bmpdt.scale, bmpdt.scale, RTGUI_IMG_ZOOM_BILINEAR);
if (bmpdt.showimg != RT_NULL)
rtgui_widget_update(RTGUI_WIDGET(bmpdt.showbox));
else
return;
if(bmpdt.showimg != bmpdt.image)
{
rtgui_image_destroy(bmpdt.showimg);
bmpdt.showimg = RT_NULL;
}
}
void demo_image_rotate(struct rtgui_object* object, struct rtgui_event* event)
{
rtgui_button_t *button = RTGUI_BUTTON(object);
if (bmpdt.image == RT_NULL) return;
/* 更新图像旋转角度 */
if (bmpdt.angle < 360.0)
bmpdt.angle += (float)1.0;
else
bmpdt.angle = 0.0;
/* 调用旋转函数执行旋转, 并取得一个新的图像指针 */
bmpdt.showimg = rtgui_image_rotate(bmpdt.image, bmpdt.angle);
if (bmpdt.showimg != RT_NULL)
rtgui_widget_update(RTGUI_WIDGET(bmpdt.showbox));
else
return;
if(bmpdt.showimg != bmpdt.image)
{
rtgui_image_destroy(bmpdt.showimg);
bmpdt.showimg = RT_NULL;
}
}
rtgui_container_t *demo_view_bmp(void)
{
rtgui_rect_t rect;
rtgui_container_t *container, *showbox;
rtgui_button_t *button;
rtgui_textbox_t *box;
/* 用bmpdt结构体记录一些参数 */
rt_memset(&bmpdt, 0, sizeof(struct demo_bmp_dt));
bmpdt.scale = 1.0;
bmpdt.angle = 0.0;
/* 创建用于演示本代码的容器控件 */
container = demo_view("Bmp File:");
demo_view_get_rect(container, &rect);
rect.x1 += 85;
rect.x2 -= 5;
rect.y1 -= 42;
rect.y2 = rect.y1 + 20;
box = rtgui_textbox_create("", RTGUI_TEXTBOX_SINGLE);
rtgui_widget_set_rect(RTGUI_WIDGET(box), &rect);
rtgui_container_add_child(container, RTGUI_WIDGET(box));
bmpdt.box = box;
/* create a button "open" */
demo_view_get_rect(container, &rect);
rect.x1 += 5;
rect.x2 = rect.x1 + 60;
rect.y1 -= 10;
rect.y2 = rect.y1 + 24;
button = rtgui_button_create("open");
rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
rtgui_container_add_child(container, RTGUI_WIDGET(button));
rtgui_button_set_onbutton(button, demo_bitmap_open);
/* create a button "zoom in" */
demo_view_get_rect(container, &rect);
rect.x1 += 85;
rect.x2 = rect.x1 + 70;
rect.y1 -= 10;
rect.y2 = rect.y1 + 24;
button = rtgui_button_create("zoom in");
rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
rtgui_container_add_child(container, RTGUI_WIDGET(button));
rtgui_button_set_onbutton(button, demo_image_zoom_in);
/* create a button "zoom out" */
demo_view_get_rect(container, &rect);
rect.x1 += 165;
rect.x2 = rect.x1 + 70;
rect.y1 -= 10;
rect.y2 = rect.y1 + 24;
button = rtgui_button_create("zoom out");
rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
rtgui_container_add_child(container, RTGUI_WIDGET(button));
rtgui_button_set_onbutton(button, demo_image_zoom_out);
/* create a button "rotate" */
demo_view_get_rect(container, &rect);
rect.x1 += 245;
rect.x2 = rect.x1 + 70;
rect.y1 -= 10;
rect.y2 = rect.y1 + 24;
button = rtgui_button_create("rotate");
rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
rtgui_container_add_child(container, RTGUI_WIDGET(button));
rtgui_button_set_onbutton(button, demo_image_rotate);
/* create a container "showbox" */
demo_view_get_rect(container, &rect);
rect.x1 += 5;
rect.x2 -= 5;
rect.y1 += 20;
rect.y2 -= 0;
showbox = rtgui_container_create();
rtgui_widget_set_rect(RTGUI_WIDGET(showbox), &rect);
rtgui_container_add_child(container, RTGUI_WIDGET(showbox));
rtgui_widget_set_border(RTGUI_WIDGET(showbox), RTGUI_BORDER_SIMPLE);
bmpdt.showbox = showbox;
rtgui_object_set_event_handler(RTGUI_OBJECT(showbox), demo_bitmap_showbox);
rtgui_widget_get_rect(RTGUI_WIDGET(showbox), &bmpdt.lastrect);
rtgui_rect_inflate(&bmpdt.lastrect, -RTGUI_WIDGET_BORDER(showbox));
return container;
}
#endif

View File

@ -59,6 +59,22 @@ static void timeout(struct rtgui_timer *timer, void *parameter)
rtgui_dc_end_drawing(dc);
}
static rt_bool_t animation_on_show(struct rtgui_object *object, struct rtgui_event *event)
{
rt_kprintf("buffer animation on show\n");
rtgui_timer_start(timer);
return RT_TRUE;
}
static rt_bool_t animation_on_hide(struct rtgui_object *object, struct rtgui_event *event)
{
rt_kprintf("buffer animation on hide\n");
rtgui_timer_stop(timer);
return RT_TRUE;
}
static rt_bool_t animation_event_handler(struct rtgui_object *object, rtgui_event_t *event)
{
struct rtgui_widget *widget = RTGUI_WIDGET(object);
@ -87,6 +103,16 @@ static rt_bool_t animation_event_handler(struct rtgui_object *object, rtgui_even
/* 绘图完成 */
rtgui_dc_end_drawing(dc);
}
else if (event->type == RTGUI_EVENT_SHOW)
{
rtgui_container_event_handler(object, event);
animation_on_show(object, event);
}
else if (event->type == RTGUI_EVENT_HIDE)
{
rtgui_container_event_handler(object, event);
animation_on_hide(object, event);
}
else
{
/* 调用默认的事件处理函数 */
@ -96,22 +122,6 @@ static rt_bool_t animation_event_handler(struct rtgui_object *object, rtgui_even
return RT_FALSE;
}
static rt_bool_t animation_on_show(struct rtgui_object *object, struct rtgui_event *event)
{
rt_kprintf("buffer animation on show\n");
rtgui_timer_start(timer);
return RT_TRUE;
}
static rt_bool_t animation_on_hide(struct rtgui_object *object, struct rtgui_event *event)
{
rt_kprintf("buffer animation on hide\n");
rtgui_timer_stop(timer);
return RT_TRUE;
}
struct rtgui_container *demo_view_buffer_animation(void)
{
struct rtgui_container *container;
@ -143,8 +153,5 @@ struct rtgui_container *demo_view_buffer_animation(void)
/* 启动定时器以触发动画 */
timer = rtgui_timer_create(1, RT_TIMER_FLAG_PERIODIC, timeout, (void *)container);
rtgui_widget_set_onshow(RTGUI_WIDGET(container), animation_on_show);
rtgui_widget_set_onhide(RTGUI_WIDGET(container), animation_on_hide);
return container;
}

View File

@ -10,8 +10,6 @@
#include <rtgui/widgets/slider.h>
#include <rtgui/image.h>
static rtgui_image_t *background;
static struct rtgui_dc *dc_buffer;
/*
* view的事件处理函数
@ -19,6 +17,7 @@ static struct rtgui_dc *dc_buffer;
static rt_bool_t dc_buffer_event_handler(struct rtgui_object *object, rtgui_event_t *event)
{
struct rtgui_widget *widget = RTGUI_WIDGET(object);
struct rtgui_dc *dc_buffer;
/* 仅对PAINT事件进行处理 */
if (event->type == RTGUI_EVENT_PAINT)
@ -31,7 +30,7 @@ static rt_bool_t dc_buffer_event_handler(struct rtgui_object *object, rtgui_even
*
*/
rtgui_container_event_handler(object, event);
dc_buffer = (struct rtgui_dc*)widget->user_data;
/* 获得控件所属的DC */
dc = rtgui_dc_begin_drawing(widget);
/* 如果不能正常获得DC返回如果控件或父控件是隐藏状态DC是获取不成功的 */
@ -61,6 +60,7 @@ static rt_bool_t dc_buffer_event_handler(struct rtgui_object *object, rtgui_even
rtgui_container_t *demo_view_dc_buffer()
{
rtgui_container_t *view;
struct rtgui_dc *dc_buffer=RT_NULL;
if (dc_buffer == RT_NULL)
{
@ -68,7 +68,7 @@ rtgui_container_t *demo_view_dc_buffer()
/* 创建 DC Buffer长 50宽 50 */
dc_buffer = rtgui_dc_buffer_create(50, 50);
RTGUI_DC_FC(dc_buffer) = blue;
RTGUI_DC_BC(dc_buffer) = blue;
rtgui_dc_fill_rect(dc_buffer, &rect);
RTGUI_DC_FC(dc_buffer) = red;
@ -79,6 +79,7 @@ rtgui_container_t *demo_view_dc_buffer()
if (view != RT_NULL)
/* 设置成自己的事件处理函数 */
rtgui_object_set_event_handler(RTGUI_OBJECT(view), dc_buffer_event_handler);
RTGUI_WIDGET(view)->user_data = (rt_uint32_t)dc_buffer;
return view;
}

View File

@ -6,16 +6,19 @@
#include "demo_view.h"
#include <rtgui/dc.h>
#include <rtgui/filerw.h>
#include <rtgui/rtgui_system.h>
#include <rtgui/widgets/edit.h>
#include <rtgui/widgets/label.h>
#include <rtgui/widgets/button.h>
#ifdef RTGUI_USING_DFS_FILERW
void demo_edit_readin_file(struct rtgui_object *object, struct rtgui_event *event)
{
rtgui_button_t *button;
struct rtgui_edit *edit;
const char *filename = "/test_readin.txt";
int fd;
struct rtgui_filerw *file;
RT_ASSERT(object != RT_NULL);
button = RTGUI_BUTTON(object);
@ -23,15 +26,15 @@ void demo_edit_readin_file(struct rtgui_object *object, struct rtgui_event *even
edit = RTGUI_EDIT(RTGUI_WIDGET(button)->user_data);
/* 判断文件是否存在 */
fd = open(filename, O_RDONLY, 0);
if (fd < 0)
file = rtgui_filerw_create_file(filename, "rb");
if (file == RT_NULL)
{
/* 不存在存在,则创建它 */
rt_kprintf("file:\"%s\" does not exist!\n", filename);
return;
}
close(fd);
rtgui_filerw_close(file);
rt_kprintf("read-in file:\"%s\"\n", filename);
rtgui_edit_readin_file(edit, filename);
@ -42,7 +45,7 @@ void demo_edit_saveas_file(struct rtgui_object *object, struct rtgui_event *even
rtgui_button_t *button;
struct rtgui_edit *edit;
const char* filename = "/test_saveas.txt";
int fd;
struct rtgui_filerw *file;
RT_ASSERT(object != RT_NULL);
button = RTGUI_BUTTON(object);
@ -50,12 +53,12 @@ void demo_edit_saveas_file(struct rtgui_object *object, struct rtgui_event *even
edit = RTGUI_EDIT(RTGUI_WIDGET(button)->user_data);
/* 判断文件是否存在, 如果存在则删除之 */
fd = open(filename, O_RDONLY, 0);
if (fd > 0)
file = rtgui_filerw_create_file(filename, "rb");
if (file != RT_NULL)
{
close(fd);
rtgui_filerw_close(file);
/* 如果是在win32中调试, 请手工删除该文件吧, NT中文件是只读的,unlink删除不掉 */
if (unlink(filename) == -1)
if (rtgui_filerw_unlink(filename) == -1)
rt_kprintf("Could not delete %s\n", filename);
}
@ -63,12 +66,42 @@ void demo_edit_saveas_file(struct rtgui_object *object, struct rtgui_event *even
rtgui_edit_saveas_file(edit, filename);
}
void demo_edit_get_mem(struct rtgui_object* object, struct rtgui_event* event)
{
rtgui_button_t *button;
struct rtgui_edit *edit;
RT_ASSERT(object != RT_NULL);
button = RTGUI_BUTTON(object);
edit = RTGUI_EDIT( RTGUI_WIDGET(button)->user_data );
rt_kprintf("edit mem consume: %d\n", rtgui_edit_get_mem_consume(edit));
}
rt_bool_t demo_edit_event_handler(struct rtgui_object* object, struct rtgui_event *event)
{
rt_bool_t result;
char buf[32];
rtgui_point_t p;
struct rtgui_edit *edit = RTGUI_EDIT(object);
struct rtgui_label *label = (struct rtgui_label*)RTGUI_WIDGET(edit)->user_data;
result = rtgui_edit_event_handler(object, event);
p = rtgui_edit_get_current_point(edit);
rt_sprintf(buf, "TRACK: line:%d, col:%d", p.y, p.x);
rtgui_label_set_text(label, buf);
return result;
}
/* 创建用于演示edit控件的视图 */
rtgui_container_t *demo_view_edit(void)
{
rtgui_rect_t rect;
rtgui_container_t *container;
struct rtgui_edit *edit;
struct rtgui_label *label;
struct rtgui_button *button;
/* 先创建一个演示用的视图 */
@ -84,6 +117,7 @@ rtgui_container_t *demo_view_edit(void)
"rtgui_edit_insert_line\n"
"rtgui_edit_delete_line\n"
"rtgui_edit_connect_line\n"
"双字节测试\n"
"a\n"
"b\n"
"c\n"
@ -116,5 +150,33 @@ rtgui_container_t *demo_view_edit(void)
/* 使用user_data传递edit指针 */
RTGUI_WIDGET(button)->user_data = (rt_uint32_t)edit;
/* 创建一个标签, 显示EDIT的主要参数 */
demo_view_get_rect(container, &rect);
rect.x1 += 10;
rect.x2 = rect.x1 + 220;
rect.y1 += 225;
rect.y2 = rect.y1 + 18;
label = rtgui_label_create("TRACK:");
RTGUI_WIDGET_TEXTALIGN(label) = RTGUI_ALIGN_LEFT | RTGUI_ALIGN_CENTER_VERTICAL;
RTGUI_WIDGET_FOREGROUND(label) = blue;
rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
rtgui_container_add_child(container, RTGUI_WIDGET(label));
RTGUI_WIDGET(edit)->user_data = (rt_uint32_t)label;
rtgui_object_set_event_handler(RTGUI_OBJECT(edit), demo_edit_event_handler);
/* 创建一个按钮, 读取EDIT的内存消耗 */
demo_view_get_rect(container, &rect);
rect.x1 += 150;
rect.x2 = rect.x1 + 80;
rect.y1 -= 42;
rect.y2 = rect.y1 + 20;
button = rtgui_button_create("Get Mem");
rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
rtgui_container_add_child(container, RTGUI_WIDGET(button));
rtgui_button_set_onbutton(button, demo_edit_get_mem);
RTGUI_WIDGET(button)->user_data = (rt_uint32_t)edit;
return container;
}
#endif

View File

@ -1,7 +1,7 @@
/*
* 3ì??μoDCé???ê?í?????
* DC上显示图像演示
*
* ?a??ày×ó?á?ú?¨3?μ?viewé???ê?í???
* view上显示图像
*/
#include "demo_view.h"
@ -10,63 +10,63 @@
#include <string.h>
#ifdef RT_USING_MODULE
#if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW)
#if defined(RTGUI_USING_DFS_FILERW)
static rtgui_container_t *_view = RT_NULL;
/* ′ò?a°?¥μ???μ÷oˉêy */
/* 打开按钮的回调函数 */
static void open_btn_onbutton(rtgui_widget_t *widget, struct rtgui_event *event)
{
rtgui_filelist_view_t *view;
rtgui_workbench_t *workbench;
rtgui_rect_t rect;
/* ??μ??¥2?μ?workbench */
/* 获得顶层的workbench */
workbench = RTGUI_WORKBENCH(rtgui_widget_get_toplevel(widget));
rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect);
/* WIN32??ì¨é?oí??êμéè±?é?μ?3?ê??·??|àí */
/* WIN32平台上和真实设备上的初始路径处理 */
#ifdef _WIN32
view = rtgui_filelist_view_create(workbench, "d:\\", "*.*", &rect);
#else
view = rtgui_filelist_view_create(workbench, "/", "*.*", &rect);
#endif
/* ?£ì???ê?ò??????táD±íêóí?£?ò?ìá1???ó??§????í??????t */
/* 模态显示一个文件列表视图,以提供给用户选择图像文件 */
if (rtgui_container_show(RTGUI_CONTAINER(view), RT_TRUE) == RTGUI_MODAL_OK)
{
char path[32], name[8];
/* éè?????t?·??μ?±ê?? */
/* 设置文件路径的标签 */
rtgui_filelist_view_get_fullpath(view, path, sizeof(path));
rt_memset(name, 0, sizeof(name));
/* ??μ?ó|ó??£?éμ?ààDí */
/* 获得应用模块的类型 */
if (rt_strstr(path, ".mo") != RT_NULL || rt_strstr(path, ".so") != RT_NULL)
{
rt_module_open(path);
}
}
/* é?3y ???táD±í êóí? */
/* 删除 文件列表 视图 */
rtgui_container_destroy(RTGUI_CONTAINER(view));
rtgui_container_show(_view, RT_FALSE);
}
/* ?¨ó?óú??ê?ó|ó??£?éμ??Yê?êóí? */
/* 创建用于显示应用模块的演示视图 */
rtgui_container_t *demo_view_module(rtgui_workbench_t *workbench)
{
rtgui_rect_t rect;
rtgui_button_t *open_btn;
/* ?è′′?¨ò????Yê?êóí? */
_view = demo_view(workbench, "ó|ó??£?é?Yê?");
/* 先创建一个演示视图 */
_view = demo_view(workbench, "应用模块演示");
/* ìí?óò???°′?¥ */
/* 添加一个按钮 */
demo_view_get_rect(_view, &rect);
rect.x1 += 5;
rect.x2 = rect.x1 + 120;
rect.y2 = rect.y1 + 20;
open_btn = rtgui_button_create("′ò?aó|ó??£?é");
open_btn = rtgui_button_create("打开应用模块");
rtgui_container_add_child(RTGUI_CONTAINER(_view), RTGUI_WIDGET(open_btn));
rtgui_widget_set_rect(RTGUI_WIDGET(open_btn), &rect);
rtgui_button_set_onbutton(open_btn, open_btn_onbutton);

View File

@ -33,6 +33,29 @@ static rt_bool_t stop_timer(struct rtgui_object *object, struct rtgui_event *eve
return RT_TRUE;
}
static rt_bool_t progressbar_event_handler(struct rtgui_object *object, rtgui_event_t *event)
{
struct rtgui_widget *widget = RTGUI_WIDGET(object);
if (event->type == RTGUI_EVENT_SHOW)
{
rtgui_container_event_handler(object, event);
start_timer(object, event);
}
else if (event->type == RTGUI_EVENT_HIDE)
{
rtgui_container_event_handler(object, event);
stop_timer(object, event);
}
else
{
/* 调用默认的事件处理函数 */
return rtgui_progressbar_event_handler(object, event);
}
return RT_FALSE;
}
rtgui_container_t *demo_view_progressbar(void)
{
rtgui_container_t *container;
@ -75,9 +98,6 @@ rtgui_container_t *demo_view_progressbar(void)
bar_timer = rtgui_timer_create(50, RT_TIMER_FLAG_PERIODIC,
progressbar_timeout, RT_NULL);
rtgui_widget_set_onshow(RTGUI_WIDGET(container), start_timer);
rtgui_widget_set_onhide(RTGUI_WIDGET(container), stop_timer);
return container;
}

View File

@ -14,7 +14,7 @@
static struct rtgui_timer *timer;
static struct rtgui_label *label;
static struct rtgui_win *msgbox = RT_NULL;
static struct rtgui_win *autowin = RT_NULL;
static char label_text[80];
static rt_uint8_t cnt = 5;
@ -92,7 +92,7 @@ void diag_close(struct rtgui_timer *timer, void *parameter)
if (cnt == 0)
{
/* 超时,关闭对话框 */
rtgui_win_destroy(msgbox);
rtgui_win_destroy(autowin);
}
}
@ -107,6 +107,7 @@ rt_bool_t auto_window_close(struct rtgui_object *object, struct rtgui_event *eve
timer = RT_NULL;
}
autowin = RT_NULL;
return RT_TRUE;
}
@ -120,12 +121,12 @@ static void demo_autowin_onbutton(struct rtgui_object *object, rtgui_event_t *ev
struct rtgui_rect rect = {50, 50, 200, 200};
/* don't create the window twice */
if (msgbox)
if (autowin)
return;
msgbox = rtgui_win_create(main_win, "Information",
autowin = rtgui_win_create(main_win, "Information",
&rect, RTGUI_WIN_STYLE_DEFAULT | RTGUI_WIN_STYLE_DESTROY_ON_CLOSE);
if (msgbox == RT_NULL)
if (autowin == RT_NULL)
return;
cnt = 5;
@ -136,13 +137,13 @@ static void demo_autowin_onbutton(struct rtgui_object *object, rtgui_event_t *ev
rect.y1 += 5;
rect.y2 = rect.y1 + 20;
rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
rtgui_container_add_child(RTGUI_CONTAINER(msgbox),
rtgui_container_add_child(RTGUI_CONTAINER(autowin),
RTGUI_WIDGET(label));
/* 设置关闭窗口时的动作 */
rtgui_win_set_onclose(msgbox, auto_window_close);
rtgui_win_set_onclose(autowin, auto_window_close);
rtgui_win_show(msgbox, RT_FALSE);
rtgui_win_show(autowin, RT_FALSE);
/* 创建一个定时器 */
timer = rtgui_timer_create(100, RT_TIMER_FLAG_PERIODIC, diag_close, RT_NULL);
rtgui_timer_start(timer);