[GUI] Update GUI engine code and add Kconfig file.

This commit is contained in:
bernard 2017-10-10 00:17:58 +08:00
parent f8a1bf6fd8
commit 01108b5252
81 changed files with 6537 additions and 4334 deletions

View File

@ -16,10 +16,12 @@ source "$RTT_DIR/components/finsh/KConfig"
source "$RTT_DIR/components/dfs/KConfig"
source "$RTT_DIR/components/net/KConfig"
source "$RTT_DIR/components/drivers/KConfig"
source "$RTT_DIR/components/gui/KConfig"
source "$RTT_DIR/components/libc/KConfig"
source "$RTT_DIR/components/net/KConfig"
endmenu

61
components/gui/Kconfig Normal file
View File

@ -0,0 +1,61 @@
menu "RT-Thread UI Engine"
config RT_USING_GUIENGINE
bool "Enable UI Engine"
default n
if RT_USING_GUIENGINE
config RTGUI_NAME_MAX
int "The maximal size of name in GUI engine"
default 16
config RTGUI_USING_TTF
bool "Support TrueType font"
default n
config RTGUI_USING_FONT16
bool "Support 16 height font"
default y
config RTGUI_USING_FONT12
bool "Support 12 height font"
default y
config RTGUI_USING_FONTHZ
bool "Support Chinese font"
default n
if RTGUI_USING_FONTHZ
config RTGUI_USING_HZ_BMP
bool "Use bitmap Chinese font"
default n
endif
config RTGUI_IMAGE_XPM
bool "Support XPM image format"
default n
config RTGUI_IMAGE_JPEG
bool "Support JPEG image format"
default n
config RTGUI_IMAGE_TJPGD
bool "Use TJPGD for JPEG image"
default n
config RTGUI_IMAGE_PNG
bool "Support PNG image format"
default n
config RTGUI_IMAGE_LODEPNG
bool "Use lodepng for PNG image"
default n
config RTGUI_IMAGE_BMP
bool "Support BMP image format"
default n
endif
endmenu

View File

@ -28,6 +28,7 @@ src/hz12font.c
src/hz16font.c
src/image.c
src/image_bmp.c
src/image_container.c
src/image_hdc.c
src/image_jpg.c
src/image_png.c

View File

@ -1,7 +1,7 @@
/*
* File : blit.h
* This file is part of RT-Thread GUI
* COPYRIGHT (C) 2006 - 2013, RT-Thread Development Team
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -47,6 +47,7 @@
#define __RTGUI_BLIT_H__
#include <rtgui/rtgui.h>
#include <rtgui/dc.h>
/* Assemble R-G-B values into a specified pixel format and store them */
#define RGB565_FROM_RGB(Pixel, r, g, b) \
@ -201,13 +202,13 @@ struct rtgui_blit_info
rt_uint8_t r, g, b, a;
};
struct rtgui_blit_info_src
struct rtgui_image_info
{
rt_uint8_t *src;
int src_w, src_h;
int src_skip;
rt_uint8_t *pixels;
int src_pitch;
rt_uint8_t src_fmt;
rt_uint8_t a;
};
extern const rt_uint8_t* rtgui_blit_expand_byte[9];
@ -217,6 +218,7 @@ rtgui_blit_line_func rtgui_blit_line_get(int dst_bpp, int src_bpp);
rtgui_blit_line_func rtgui_blit_line_get_inv(int dst_bpp, int src_bpp);
void rtgui_blit(struct rtgui_blit_info * info);
void rtgui_image_info_blit(struct rtgui_image_info* image, struct rtgui_dc* dc, struct rtgui_rect *dc_rect);
#endif

View File

@ -1,11 +1,21 @@
/*
* File : color.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, 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
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes

View File

@ -1,11 +1,21 @@
/*
* File : dc.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, 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
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
@ -106,6 +116,11 @@ struct rtgui_dc_buffer
/* pitch */
rt_uint16_t pitch;
#ifdef RTGUI_IMAGE_CONTAINER
/* image dc */
struct rtgui_image_item *image_item;
#endif
/* pixel data */
rt_uint8_t *pixel;
};
@ -118,6 +133,10 @@ struct rtgui_dc_buffer
/* create a buffer dc */
struct rtgui_dc *rtgui_dc_buffer_create(int width, int height);
struct rtgui_dc *rtgui_dc_buffer_create_pixformat(rt_uint8_t pixel_format, int w, int h);
#ifdef RTGUI_IMAGE_CONTAINER
struct rtgui_dc *rtgui_img_dc_create_pixformat(rt_uint8_t pixel_format, rt_uint8_t *pixel,
struct rtgui_image_item *image_item);
#endif
struct rtgui_dc *rtgui_dc_buffer_create_from_dc(struct rtgui_dc* dc);
/* create a widget dc */
@ -125,11 +144,18 @@ struct rtgui_dc *rtgui_dc_widget_create(struct rtgui_widget * owner);
/* begin and end a drawing */
struct rtgui_dc *rtgui_dc_begin_drawing(rtgui_widget_t *owner);
void rtgui_dc_end_drawing(struct rtgui_dc *dc);
void rtgui_dc_end_drawing(struct rtgui_dc *dc, rt_bool_t update);
/* destroy a dc */
void rtgui_dc_destory(struct rtgui_dc *dc);
/* create a hardware dc */
struct rtgui_dc *rtgui_dc_hw_create(rtgui_widget_t *owner);
/* create a client dc */
struct rtgui_dc *rtgui_dc_client_create(rtgui_widget_t *owner);
void rtgui_dc_client_init(rtgui_widget_t *owner);
rt_uint8_t *rtgui_dc_buffer_get_pixel(struct rtgui_dc *dc);
void rtgui_dc_draw_line(struct rtgui_dc *dc, int x1, int y1, int x2, int y2);
@ -259,6 +285,9 @@ struct rtgui_dc *rtgui_dc_shrink(struct rtgui_dc *dc, int factorx, int factory);
struct rtgui_dc *rtgui_dc_zoom(struct rtgui_dc *dc, double zoomx, double zoomy, int smooth);
struct rtgui_dc *rtgui_dc_rotozoom(struct rtgui_dc *dc, double angle, double zoomx, double zoomy, int smooth);
/* dc buffer dump to file */
void rtgui_dc_buffer_dump(struct rtgui_dc *self, char *fn);
#ifdef __cplusplus
}
#endif

View File

@ -1,27 +0,0 @@
/*
* File : dc_buffer.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2010, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
*
* Change Logs:
* Date Author Notes
* 2010-04-10 Bernard first version
* 2010-06-14 Bernard embedded hardware dc to each widget
* 2010-08-09 Bernard rename hardware dc to client dc
*/
#ifndef __RTGUI_DC_CLIENT_H__
#define __RTGUI_DC_CLIENT_H__
#include <rtgui/dc.h>
/* create a hardware dc */
struct rtgui_dc *rtgui_dc_client_create(rtgui_widget_t *owner);
void rtgui_dc_client_init(rtgui_widget_t *owner);
#endif

View File

@ -1,7 +1,7 @@
/*
* File : dc_blend.c
* This file is part of RT-Thread GUI
* COPYRIGHT (C) 2006 - 2013, RT-Thread Development Team
* File : dc_draw.h
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@ -1,24 +0,0 @@
/*
* File : dc_buffer.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2010, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
*
* Change Logs:
* Date Author Notes
* 2010-04-10 Bernard first version
* 2010-06-14 Bernard embedded hardware dc to each widget
*/
#ifndef __RTGUI_DC_HW_H__
#define __RTGUI_DC_HW_H__
#include <rtgui/dc.h>
/* create a hardware dc */
struct rtgui_dc *rtgui_dc_hw_create(rtgui_widget_t *owner);
#endif

View File

@ -1,3 +1,27 @@
/*
* File : dc_trans.h
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2010-04-10 Bernard first version
*/
#ifndef __RTGUI_DC_TRANS_H__
#define __RTGUI_DC_TRANS_H__

View File

@ -1,11 +1,21 @@
/*
* File : driver.h
* This file is part of RTGUI in RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, 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
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes

View File

@ -1,11 +1,21 @@
/*
* File : event.h
* This file is part of RTGUI in RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, 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
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
@ -41,6 +51,7 @@ enum _rtgui_event_type
RTGUI_EVENT_WIN_CLOSE, /* close a window */
RTGUI_EVENT_WIN_MOVE, /* move a window */
RTGUI_EVENT_WIN_RESIZE, /* resize a window */
RTGUI_EVENT_WIN_UPDATE_END, /* update done for window */
RTGUI_EVENT_WIN_MODAL_ENTER, /* the window is entering modal mode.
This event should be sent after the
window got setup and before the
@ -169,6 +180,13 @@ struct rtgui_event_win_resize
rtgui_rect_t rect;
};
struct rtgui_event_win_update_end
{
_RTGUI_EVENT_WIN_ELEMENTS
rtgui_rect_t rect;
};
#define rtgui_event_win_destroy rtgui_event_win
#define rtgui_event_win_show rtgui_event_win
#define rtgui_event_win_hide rtgui_event_win
@ -187,6 +205,7 @@ struct rtgui_event_win_resize
#define RTGUI_EVENT_WIN_CLOSE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_CLOSE)
#define RTGUI_EVENT_WIN_MOVE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_MOVE)
#define RTGUI_EVENT_WIN_RESIZE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_RESIZE)
#define RTGUI_EVENT_WIN_UPDATE_END_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_UPDATE_END)
#define RTGUI_EVENT_WIN_MODAL_ENTER_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_MODAL_ENTER)
/*

View File

@ -1,11 +1,21 @@
/*
* File : filerw.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, 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
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes

View File

@ -1,11 +1,21 @@
/*
* File : font.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, 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
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
@ -17,6 +27,7 @@
#include <rtgui/rtgui.h>
#include <rtgui/list.h>
#ifdef __cplusplus
extern "C" {
#endif

View File

@ -1,3 +1,27 @@
/*
* File : font_fnt.h
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2010-04-10 Bernard first version
*/
#ifndef __FONT_FNT_H__
#define __FONT_FNT_H__

View File

@ -1,3 +1,27 @@
/*
* File : font_freetype.h
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2010-04-10 Bernard first version
*/
#ifndef __RTGUI_FONT_TTF_H__
#define __RTGUI_FONT_TTF_H__
@ -8,7 +32,8 @@
extern "C" {
#endif
rtgui_font_t *rtgui_freetype_font_create(const char *filename, int bold, int italic, rt_size_t size);
void rtgui_ttf_system_init(void);
rtgui_font_t *rtgui_freetype_font_create(const char *filename, rt_size_t size);
void rtgui_freetype_font_destroy(rtgui_font_t *font);
#ifdef __cplusplus

View File

@ -1,11 +1,21 @@
/*
* File : image.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, 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
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes

View File

@ -1,11 +1,21 @@
/*
* File : image_bmp.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, 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
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes

View File

@ -0,0 +1,58 @@
/*
* File : image_container.h
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2010-04-10 Bernard first version
*/
#ifndef __RTGUI_IMAGE_CONTAINER_H__
#define __RTGUI_IMAGE_CONTAINER_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <rtgui/rtgui.h>
#include <rtgui/image.h>
#if defined(RTGUI_IMAGE_CONTAINER)
/* image item in image container */
struct rtgui_image_item
{
rtgui_image_t *image;
char *filename;
rt_uint32_t refcount;
};
typedef struct rtgui_image_item rtgui_image_item_t;
void rtgui_system_image_container_init(void);
struct rtgui_image_item *rtgui_image_container_get(const char *filename);
void rtgui_image_container_put(struct rtgui_image_item *item);
#endif
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,11 +1,21 @@
/*
* File : image_xpm.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* File : image_hdc.h
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, 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
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
@ -27,6 +37,21 @@ struct rtgui_image_hdcmm
rt_uint8_t *pixels;
};
struct rtgui_image_hdc
{
rt_bool_t is_loaded;
/* hdc image information */
rt_uint16_t byte_per_pixel;
rt_uint16_t pitch;
rt_uint8_t pixel_format;
rt_size_t pixel_offset;
rt_uint8_t *pixels;
struct rtgui_filerw *filerw;
};
void rtgui_image_hdc_init(void);
extern const struct rtgui_image_engine rtgui_image_hdcmm_engine;

View File

@ -1,8 +0,0 @@
#ifndef __RTGUI_IMAGE_JPEG_H__
#define __RTGUI_IMAGE_JPEG_H__
#include <rtgui/image.h>
void rtgui_image_jpeg_init(void);
#endif

View File

@ -1,21 +0,0 @@
/*
* File : image_png.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_IMAGE_PNG_H__
#define __RTGUI_IMAGE_PNG_H__
#include <rtgui/image.h>
void rtgui_image_png_init(void);
#endif

View File

@ -1,21 +0,0 @@
/*
* File : image_xpm.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_IMAGE_XPM_H__
#define __RTGUI_IMAGE_XPM_H__
#include <rtgui/image.h>
void rtgui_image_xpm_init(void);
#endif

View File

@ -1,11 +1,21 @@
/*
* File : kbddef.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, 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
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes

View File

@ -1,11 +1,21 @@
/*
* File : list.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, 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
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes

View File

@ -1,3 +1,27 @@
/*
* File : matrix.h
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2010-04-10 Grissiom The first version
*/
#ifndef __MATRIX_H__
#define __MATRIX_H__

View File

@ -1,11 +1,21 @@
/*
* File : region.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, 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
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
@ -90,6 +100,7 @@ int rtgui_region_is_flat(rtgui_region_t *region);
extern rtgui_rect_t rtgui_empty_rect;
void rtgui_rect_moveto(rtgui_rect_t *rect, int x, int y);
void rtgui_rect_moveto_point(rtgui_rect_t *rect, int x, int y);
void rtgui_rect_moveto_align(const rtgui_rect_t *rect, rtgui_rect_t *to, int align);
void rtgui_rect_inflate(rtgui_rect_t *rect, int d);
void rtgui_rect_intersect(rtgui_rect_t *src, rtgui_rect_t *dest);
@ -98,11 +109,14 @@ int rtgui_rect_is_intersect(const rtgui_rect_t *rect1, const rtgui_rect_t *rect
int rtgui_rect_is_equal(const rtgui_rect_t *rect1, const rtgui_rect_t *rect2);
rtgui_rect_t *rtgui_rect_set(rtgui_rect_t *rect, int x, int y, int w, int h);
rt_bool_t rtgui_rect_is_empty(const rtgui_rect_t *rect);
void rtgui_rect_union(rtgui_rect_t *src, rtgui_rect_t *dest);
rt_inline void rtgui_rect_init(rtgui_rect_t* rect, int x, int y, int width, int height)
{
rect->x1 = x; rect->y1 = y;
rect->x2 = x + width; rect->y2 = y + height;
rect->x1 = x;
rect->y1 = y;
rect->x2 = x + width;
rect->y2 = y + height;
}
#define RTGUI_RECT(rect, x, y, w, h) \

View File

@ -1,7 +1,7 @@
/*
* File : rtgui.h
* This file is part of RT-Thread GUI
* COPYRIGHT (C) 2009 - 2013, RT-Thread Development Team
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -31,15 +31,6 @@
extern "C" {
#endif
#define RTGUI_VERSION 0L /**< major version number */
#define RTGUI_SUBVERSION 8L /**< minor version number */
#define RTGUI_REVISION 1L /**< revise version number */
#define RTGUI_CODENAME "Newton" /**< code name */
#define RT_INT16_MAX 32767
#define RT_INT16_MIN (-RT_INT16_MAX-1)
#define RTGUI_NOT_FOUND (-1)
#define _UI_MIN(x, y) (((x)<(y))?(x):(y))
#define _UI_MAX(x, y) (((x)>(y))?(x):(y))
#define _UI_BITBYTES(bits) ((bits + 7)/8)
@ -180,7 +171,8 @@ enum RTGUI_TEXTSTYLE
enum RTGUI_MODAL_CODE
{
RTGUI_MODAL_OK,
RTGUI_MODAL_CANCEL
RTGUI_MODAL_CANCEL,
RTGUI_MODAL_MAX = 0xFFFF,
};
typedef enum RTGUI_MODAL_CODE rtgui_modal_code_t;

View File

@ -1,11 +1,21 @@
/*
* File : rtgui_app.h
* This file is part of RTGUI in RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, 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
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes

View File

@ -1,11 +1,21 @@
/*
* File : rtgui_config.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, 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
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes

View File

@ -1,11 +1,21 @@
/*
* File : rtgui_object.h
* This file is part of RTGUI in RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, 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
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes

View File

@ -1,11 +1,21 @@
/*
* File : rtgui_server.h
* This file is part of RTGUI in RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, 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
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
@ -14,6 +24,10 @@
#ifndef __RTGUI_SERVER_H__
#define __RTGUI_SERVER_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <rtservice.h>
#include <rtgui/list.h>
@ -72,8 +86,11 @@ void rtgui_server_install_show_win_hook(void (*hk)(void));
void rtgui_server_install_act_win_hook(void (*hk)(void));
/* post an event to server */
void rtgui_server_post_event(struct rtgui_event *event, rt_size_t size);
rt_err_t rtgui_server_post_event(struct rtgui_event *event, rt_size_t size);
rt_err_t rtgui_server_post_event_sync(struct rtgui_event *event, rt_size_t size);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,11 +1,21 @@
/*
* File : rtgui_system.h
* This file is part of RTGUI in RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, 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
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes

View File

@ -1,11 +1,21 @@
/*
* File : box.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, 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
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes

View File

@ -1,11 +1,21 @@
/*
* File : container.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, 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
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes

View File

@ -1,11 +1,21 @@
/*
* File : title.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, 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
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes

View File

@ -1,7 +1,7 @@
/*
* File : widget.h
* This file is part of RT-Thread GUI
* COPYRIGHT (C) 2006 - 2013, RT-Thread Development Team
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -110,6 +110,10 @@ struct rtgui_widget
/* the widget extent */
rtgui_rect_t extent;
/* the visiable extent (includes the rectangles of children) */
rtgui_rect_t extent_visiable;
/* the rect clip information */
rtgui_region_t clip;
/* minimal width and height of widget */
rt_int16_t min_width, min_height;
@ -117,13 +121,10 @@ struct rtgui_widget
rt_int32_t align;
rt_uint16_t border;
rt_uint16_t border_style;
/* the rect clip */
rtgui_region_t clip;
/* 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);
rt_bool_t (*on_paint)(struct rtgui_object *widget, struct rtgui_event *event);
/* user private data */
rt_uint32_t user_data;
@ -142,7 +143,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_onpaint(rtgui_widget_t *widget, rtgui_event_handler_ptr handler);
/* get and set rect of widget */
void rtgui_widget_get_rect(rtgui_widget_t *widget, rtgui_rect_t *rect);

View File

@ -1,11 +1,21 @@
/*
* File : window.h
* This file is part of RTGUI in RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, 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
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
@ -80,6 +90,7 @@ struct rtgui_win
/* drawing count */
rt_base_t drawing;
struct rtgui_rect drawing_rect;
/* parent window. RT_NULL if the window is a top level window */
struct rtgui_win *parent_window;
@ -183,6 +194,8 @@ struct rtgui_dc *rtgui_win_get_drawing(rtgui_win_t * win);
struct rtgui_win* rtgui_win_get_topmost_shown(void);
struct rtgui_win* rtgui_win_get_next_shown(void);
void rtgui_theme_draw_win(struct rtgui_wintitle *wint);
#ifdef __cplusplus
}
#endif

View File

@ -1,11 +1,21 @@
/*
* File : asc12font.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, 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
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes

View File

@ -1,11 +1,21 @@
/*
* File : asc16font.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, 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
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes

View File

@ -1,7 +1,7 @@
/*
* File : blit.h
* This file is part of RT-Thread GUI
* COPYRIGHT (C) 2006 - 2013, RT-Thread Development Team
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -48,10 +48,13 @@
#include <rtgui/rtgui.h>
#include <rtgui/blit.h>
#include <rtgui/color.h>
#include <rtgui/region.h>
#include <rtgui/dc.h>
/* Lookup tables to expand partial bytes to the full 0..255 range */
static const rt_uint8_t lookup_0[] = {
static const rt_uint8_t lookup_0[] =
{
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
@ -64,7 +67,8 @@ static const rt_uint8_t lookup_0[] = {
247, 248, 249, 250, 251, 252, 253, 254, 255
};
static const rt_uint8_t lookup_1[] = {
static const rt_uint8_t lookup_1[] =
{
0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62,
64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100, 102, 104, 106, 108, 110, 112, 114, 116, 118,
120, 122, 124, 126, 128, 130, 132, 134, 136, 138, 140, 142, 144, 146, 148, 150, 152, 154, 156, 158, 160, 162, 164, 166,
@ -72,38 +76,46 @@ static const rt_uint8_t lookup_1[] = {
216, 218, 220, 222, 224, 226, 228, 230, 232, 234, 236, 238, 240, 242, 244, 246, 248, 250, 252, 255
};
static const rt_uint8_t lookup_2[] = {
static const rt_uint8_t lookup_2[] =
{
0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 68, 72, 76, 80, 85, 89, 93, 97, 101, 105, 109, 113, 117,
121, 125, 129, 133, 137, 141, 145, 149, 153, 157, 161, 165, 170, 174, 178, 182, 186, 190, 194, 198, 202, 206, 210, 214, 218,
222, 226, 230, 234, 238, 242, 246, 250, 255
};
static const rt_uint8_t lookup_3[] = {
static const rt_uint8_t lookup_3[] =
{
0, 8, 16, 24, 32, 41, 49, 57, 65, 74, 82, 90, 98, 106, 115, 123, 131, 139, 148, 156, 164, 172, 180, 189, 197, 205, 213, 222,
230, 238, 246, 255
};
static const rt_uint8_t lookup_4[] = {
static const rt_uint8_t lookup_4[] =
{
0, 17, 34, 51, 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255
};
static const rt_uint8_t lookup_5[] = {
static const rt_uint8_t lookup_5[] =
{
0, 36, 72, 109, 145, 182, 218, 255
};
static const rt_uint8_t lookup_6[] = {
static const rt_uint8_t lookup_6[] =
{
0, 85, 170, 255
};
static const rt_uint8_t lookup_7[] = {
static const rt_uint8_t lookup_7[] =
{
0, 255
};
static const rt_uint8_t lookup_8[] = {
static const rt_uint8_t lookup_8[] =
{
255
};
const rt_uint8_t* rtgui_blit_expand_byte[9] = {
const rt_uint8_t* rtgui_blit_expand_byte[9] =
{
lookup_0,
lookup_1,
lookup_2,
@ -191,17 +203,22 @@ static void rtgui_blit_line_4_2(rt_uint8_t *dst_ptr, rt_uint8_t *src_ptr, int li
rt_uint16_t *dstp = (rt_uint16_t *) dst_ptr;
/* *INDENT-OFF* */
DUFFS_LOOP4({
DUFFS_LOOP4(
{
rt_uint32_t s = *srcp;
unsigned alpha = s >> 27; /* downscale alpha to 5 bits */
/* FIXME: Here we special-case opaque alpha since the
compositioning used (>>8 instead of /255) doesn't handle
it correctly. Also special-case alpha=0 for speed?
Benchmark this! */
if(alpha) {
if(alpha == (255 >> 3)) {
if(alpha)
{
if(alpha == (255 >> 3))
{
*dstp = (rt_uint16_t)((s >> 8 & 0xf800) + (s >> 5 & 0x7e0) + (s >> 3 & 0x1f));
} else {
}
else
{
rt_uint32_t d = *dstp;
/*
* convert source and destination to G0RAB65565
@ -362,7 +379,8 @@ static const rt_uint32_t RGB565_RGBA8888_LUT[512] =
};
/* Special optimized blit for RGB 5-6-5 --> ARGB 8-8-8-8 */
static const rt_uint32_t RGB565_ARGB8888_LUT[512] = {
static const rt_uint32_t RGB565_ARGB8888_LUT[512] =
{
0x00000000, 0xff000000, 0x00000008, 0xff002000,
0x00000010, 0xff004000, 0x00000018, 0xff006100,
0x00000020, 0xff008100, 0x00000029, 0xff00a100,
@ -653,8 +671,10 @@ Blit16to16SurfaceAlpha128(struct rtgui_blit_info * info, rt_uint16_t mask)
rt_uint16_t *dstp = (rt_uint16_t *) info->dst;
int dstskip = info->dst_skip >> 1;
while (height--) {
if (((unsigned int) srcp ^ (unsigned int) dstp) & 2) {
while (height--)
{
if (((unsigned int) srcp ^ (unsigned int) dstp) & 2)
{
/*
* Source and destination not aligned, pipeline it.
* This is mostly a win for big blits but no loss for
@ -664,7 +684,8 @@ Blit16to16SurfaceAlpha128(struct rtgui_blit_info * info, rt_uint16_t mask)
int w = width;
/* handle odd destination */
if ((unsigned int) dstp & 2) {
if ((unsigned int) dstp & 2)
{
rt_uint16_t d = *dstp, s = *srcp;
*dstp = BLEND16_50(d, s, mask);
dstp++;
@ -676,7 +697,8 @@ Blit16to16SurfaceAlpha128(struct rtgui_blit_info * info, rt_uint16_t mask)
/* bootstrap pipeline with first halfword */
prev_sw = ((rt_uint32_t *) srcp)[-1];
while (w > 1) {
while (w > 1)
{
rt_uint32_t sw, dw, s;
sw = *(rt_uint32_t *) srcp;
dw = *(rt_uint32_t *) dstp;
@ -689,7 +711,8 @@ Blit16to16SurfaceAlpha128(struct rtgui_blit_info * info, rt_uint16_t mask)
}
/* final pixel if any */
if (w) {
if (w)
{
rt_uint16_t d = *dstp, s;
s = (rt_uint16_t) (prev_sw >> 16);
*dstp = BLEND16_50(d, s, mask);
@ -698,12 +721,15 @@ Blit16to16SurfaceAlpha128(struct rtgui_blit_info * info, rt_uint16_t mask)
}
srcp += srcskip - 1;
dstp += dstskip;
} else {
}
else
{
/* source and destination are aligned */
int w = width;
/* first odd pixel? */
if ((unsigned int) srcp & 2) {
if ((unsigned int) srcp & 2)
{
rt_uint16_t d = *dstp, s = *srcp;
*dstp = BLEND16_50(d, s, mask);
srcp++;
@ -712,7 +738,8 @@ Blit16to16SurfaceAlpha128(struct rtgui_blit_info * info, rt_uint16_t mask)
}
/* srcp and dstp are now 32-bit aligned */
while (w > 1) {
while (w > 1)
{
rt_uint32_t sw = *(rt_uint32_t *) srcp;
rt_uint32_t dw = *(rt_uint32_t *) dstp;
*(rt_uint32_t *) dstp = BLEND2x16_50(dw, sw, mask);
@ -722,7 +749,8 @@ Blit16to16SurfaceAlpha128(struct rtgui_blit_info * info, rt_uint16_t mask)
}
/* last odd pixel? */
if (w) {
if (w)
{
rt_uint16_t d = *dstp, s = *srcp;
*dstp = BLEND16_50(d, s, mask);
srcp++;
@ -774,7 +802,8 @@ Blit565to565PixelAlpha(struct rtgui_blit_info * info)
rt_uint32_t *srcp = (rt_uint32_t *) info->src;
rt_uint32_t *dstp = (rt_uint32_t *) info->dst;
while (height--) {
while (height--)
{
DUFFS_LOOP4(
{
rt_uint32_t s = *srcp++;
@ -821,8 +850,10 @@ static void BlitRGBtoRGBSurfaceAlpha128(struct rtgui_blit_info *info)
rt_uint32_t *dstp = (rt_uint32_t *)info->dst;
int dstskip = info->dst_skip >> 2;
while(height--) {
DUFFS_LOOP4({
while(height--)
{
DUFFS_LOOP4(
{
rt_uint32_t s = *srcp++;
rt_uint32_t d = *dstp;
*dstp++ = ((((s & 0x00fefefe) + (d & 0x00fefefe)) >> 1)
@ -837,9 +868,12 @@ static void BlitRGBtoRGBSurfaceAlpha128(struct rtgui_blit_info *info)
static void BlitRGBtoRGBSurfaceAlpha(struct rtgui_blit_info *info)
{
unsigned int alpha = info->a;
if(alpha == 128) {
if(alpha == 128)
{
BlitRGBtoRGBSurfaceAlpha128(info);
} else {
}
else
{
int width = info->dst_w;
int height = info->dst_h;
rt_uint32_t *srcp = (rt_uint32_t *)info->src;
@ -847,8 +881,10 @@ static void BlitRGBtoRGBSurfaceAlpha(struct rtgui_blit_info *info)
rt_uint32_t *dstp = (rt_uint32_t *)info->dst;
int dstskip = info->dst_skip >> 2;
while(height--) {
DUFFS_LOOP4({
while(height--)
{
DUFFS_LOOP4(
{
rt_uint32_t s;
rt_uint32_t d;
rt_uint32_t s1;
@ -872,6 +908,77 @@ static void BlitRGBtoRGBSurfaceAlpha(struct rtgui_blit_info *info)
}
}
/* fast alpha -> RGB565 blending with pixel alpha */
static void BlitAlphato565PixelAlpha(struct rtgui_blit_info * info)
{
rt_uint32_t srcpixel, dstpixel;
rt_uint32_t srcR, srcG, srcB, srcA;
srcR = info->r;
srcG = info->g;
srcB = info->b;
while (info->dst_h--)
{
rt_uint8_t *src = (rt_uint8_t *)info->src;
rt_uint16_t *dst = (rt_uint16_t *)info->dst;
int n = info->dst_w;
while (n--)
{
srcA = (rt_uint8_t)(*src);
ARGB8888_FROM_RGBA(srcpixel, srcR, srcG, srcB, srcA);
/* not do alpha blend */
if (srcA == 255)
{
dstpixel = srcpixel;
}
else if (srcA >> 3 == 0)
{
/* keep original pixel data */
}
else
{
dstpixel = ((rt_uint32_t)srcA << 24) | ((rt_uint32_t)srcR << 16) | ((rt_uint32_t)srcG << 8) | srcB;
}
if (srcA >> 3 != 0)
{
rt_uint32_t s = dstpixel;
unsigned alpha = s >> 27;
if (alpha)
{
if (alpha == (255 >> 3))
{
*dst = (rt_uint16_t)((s >> 8 & 0xf800) + (s >> 5 & 0x7e0) + (s >> 3 & 0x1f));
}
else
{
rt_uint32_t d = *dst;
/*
* convert source and destination to G0RAB65565
* and blend all components at the same time
*/
s = ((s & 0xfc00) << 11) + (s >> 8 & 0xf800)
+ (s >> 3 & 0x1f);
d = (d | d << 16) & 0x07e0f81f;
d += (s - d) * alpha >> 5;
d &= 0x07e0f81f;
*dst = (rt_uint16_t)(d | d >> 16);
}
}
}
++src;
++dst;
}
info->src += info->src_pitch;
info->dst += info->dst_pitch;
}
}
/* fast ARGB8888->RGB565 blending with pixel alpha */
static void BlitARGBto565PixelAlpha(struct rtgui_blit_info * info)
{
@ -882,19 +989,25 @@ static void BlitARGBto565PixelAlpha(struct rtgui_blit_info * info)
rt_uint16_t *dstp = (rt_uint16_t *) info->dst;
int dstskip = info->dst_skip >> 1;
while (height--) {
while (height--)
{
/* *INDENT-OFF* */
DUFFS_LOOP4({
DUFFS_LOOP4(
{
rt_uint32_t s = *srcp;
unsigned alpha = s >> 27; /* downscale alpha to 5 bits */
/* FIXME: Here we special-case opaque alpha since the
compositioning used (>>8 instead of /255) doesn't handle
it correctly. Also special-case alpha=0 for speed?
Benchmark this! */
if(alpha) {
if(alpha == (255 >> 3)) {
if(alpha)
{
if(alpha == (255 >> 3))
{
*dstp = (rt_uint16_t)((s >> 8 & 0xf800) + (s >> 5 & 0x7e0) + (s >> 3 & 0x1f));
} else {
}
else
{
rt_uint32_t d = *dstp;
/*
* convert source and destination to G0RAB65565
@ -927,8 +1040,10 @@ static void BlitRGBtoRGBPixelAlpha(struct rtgui_blit_info *info)
rt_uint32_t *dstp = (rt_uint32_t *)info->dst;
int dstskip = info->dst_skip >> 2;
while(height--) {
DUFFS_LOOP4({
while(height--)
{
DUFFS_LOOP4(
{
rt_uint32_t dalpha;
rt_uint32_t d;
rt_uint32_t s1;
@ -940,9 +1055,11 @@ static void BlitRGBtoRGBPixelAlpha(struct rtgui_blit_info *info)
compositioning used (>>8 instead of /255) doesn't handle
it correctly. Also special-case alpha=0 for speed?
Benchmark this! */
if(alpha == 255) {
if(alpha == 255)
{
*dstp = (s & 0x00ffffff) | (*dstp & 0xff000000);
} else {
}
else {
/*
* take out the middle component (green), and process
* the other two in parallel. One multiply less.
@ -965,6 +1082,73 @@ static void BlitRGBtoRGBPixelAlpha(struct rtgui_blit_info *info)
}
}
static void BlitAlphatoARGB8888PixelAlpha(struct rtgui_blit_info *info)
{
rt_uint32_t srcpixel;
rt_uint32_t srcR, srcG, srcB, srcA;
rt_uint32_t dstpixel;
rt_uint32_t dstR, dstG, dstB, dstA;
srcR = info->r;
srcG = info->g;
srcB = info->b;
while (info->dst_h--)
{
rt_uint8_t *src = (rt_uint8_t *)info->src;
rt_uint32_t *dst = (rt_uint32_t *)info->dst;
int n = info->dst_w;
while (n--)
{
srcA = (rt_uint8_t)(*src);
ARGB8888_FROM_RGBA(srcpixel, srcR, srcG, srcB, srcA);
/* not do alpha blend */
if (srcA == 255)
{
*dst = srcpixel;
}
else if (srcA >> 3 == 0)
{
/* keep original pixel data */
}
else
{
dstpixel = *dst;
dstA = (rt_uint8_t)(dstpixel >> 24);
dstR = (rt_uint8_t)(dstpixel >> 16);
dstG = (rt_uint8_t)(dstpixel >> 8);
dstB = (rt_uint8_t)dstpixel;
if (dstA)
{
int alpha = srcA + 1;
int inverse_alpha = 257 - alpha;
dstR = ((srcR * alpha) + (inverse_alpha * dstR)) >> 8;
dstG = ((srcG * alpha) + (inverse_alpha * dstG)) >> 8;
dstB = ((srcB * alpha) + (inverse_alpha * dstB)) >> 8;
dstA = srcA + ((255 - srcA) * dstA) / 255;
dstpixel = ((rt_uint32_t)dstA << 24) | ((rt_uint32_t)dstR << 16) | ((rt_uint32_t)dstG << 8) | dstB;
}
else
{
dstpixel = ((rt_uint32_t)srcA << 24) | ((rt_uint32_t)srcR << 16) | ((rt_uint32_t)srcG << 8) | srcB;
}
*dst = dstpixel;
}
++src;
++dst;
}
info->src += info->src_pitch;
info->dst += info->dst_pitch;
}
}
static void BlitARGB8888toARGB8888PixelAlpha(struct rtgui_blit_info *info)
{
rt_uint32_t srcpixel;
@ -972,23 +1156,50 @@ static void BlitARGB8888toARGB8888PixelAlpha(struct rtgui_blit_info *info)
rt_uint32_t dstpixel;
rt_uint32_t dstR, dstG, dstB, dstA;
while (info->dst_h--) {
while (info->dst_h--)
{
rt_uint32_t *src = (rt_uint32_t *)info->src;
rt_uint32_t *dst = (rt_uint32_t *)info->dst;
int n = info->dst_w;
while (n--) {
while (n--)
{
srcpixel = *src;
srcA = (rt_uint8_t)(srcpixel >> 24); srcR = (rt_uint8_t)(srcpixel >> 16); srcG = (rt_uint8_t)(srcpixel >> 8); srcB = (rt_uint8_t)srcpixel;
dstpixel = *dst;
dstA = (rt_uint8_t)(dstpixel >> 24); dstR = (rt_uint8_t)(dstpixel >> 16); dstG = (rt_uint8_t)(dstpixel >> 8); dstB = (rt_uint8_t)dstpixel;
srcA = (rt_uint8_t)(srcpixel >> 24);
dstR = srcR + ((255 - srcA) * dstR) / 255;
dstG = srcG + ((255 - srcA) * dstG) / 255;
dstB = srcB + ((255 - srcA) * dstB) / 255;
/* not do alpha blend */
if (srcA == 255)
{
*dst = srcpixel;
}
else if (srcA == 0)
{
/* keep original pixel data */
}
else
{
srcR = (rt_uint8_t)(srcpixel >> 16);
srcG = (rt_uint8_t)(srcpixel >> 8);
srcB = (rt_uint8_t)srcpixel;
dstpixel = *dst;
dstA = (rt_uint8_t)(dstpixel >> 24);
dstR = (rt_uint8_t)(dstpixel >> 16);
dstG = (rt_uint8_t)(dstpixel >> 8);
dstB = (rt_uint8_t)dstpixel;
{
int alpha = srcA + 1;
int inverse_alpha = 257 - alpha;
dstR = ((srcR * alpha) + (inverse_alpha * dstR)) >> 8;
dstG = ((srcG * alpha) + (inverse_alpha * dstG)) >> 8;
dstB = ((srcB * alpha) + (inverse_alpha * dstB)) >> 8;
dstA = srcA + ((255 - srcA) * dstA) / 255;
}
dstpixel = ((rt_uint32_t)dstA << 24) | ((rt_uint32_t)dstR << 16) | ((rt_uint32_t)dstG << 8) | dstB;
*dst = dstpixel;
}
++src;
++dst;
}
@ -1015,7 +1226,8 @@ BlitRGB565to32(struct rtgui_blit_info * info, const rt_uint32_t* map)
dst = (rt_uint32_t *) info->dst;
dstskip = info->dst_skip / 4;
while (height--) {
while (height--)
{
/* *INDENT-OFF* */
DUFFS_LOOP(
{
@ -1069,55 +1281,166 @@ void rtgui_blit(struct rtgui_blit_info * info)
}
else if (info->src_fmt == RTGRAPHIC_PIXEL_FORMAT_ARGB888)
{
if (info->dst_fmt == RTGRAPHIC_PIXEL_FORMAT_RGB565)
switch (info->dst_fmt)
{
case RTGRAPHIC_PIXEL_FORMAT_RGB565:
BlitARGBto565PixelAlpha(info);
else if (info->dst_fmt == RTGRAPHIC_PIXEL_FORMAT_RGB888)
break;
case RTGRAPHIC_PIXEL_FORMAT_RGB888:
BlitRGBtoRGBPixelAlpha(info);
else if (info->dst_fmt == RTGRAPHIC_PIXEL_FORMAT_ARGB888)
break;
case RTGRAPHIC_PIXEL_FORMAT_ARGB888:
BlitARGB8888toARGB8888PixelAlpha(info);
break;
}
}
else if (info->src_fmt == RTGRAPHIC_PIXEL_FORMAT_RGB888)
{
if (info->dst_fmt == RTGRAPHIC_PIXEL_FORMAT_ARGB888)
BlitRGBtoRGBSurfaceAlpha(info);
}
else if (info->src_fmt == RTGRAPHIC_PIXEL_FORMAT_ALPHA)
{
switch (info->dst_fmt)
{
case RTGRAPHIC_PIXEL_FORMAT_RGB565:
BlitAlphato565PixelAlpha(info);
break;
case RTGRAPHIC_PIXEL_FORMAT_RGB888:
break;
case RTGRAPHIC_PIXEL_FORMAT_ARGB888:
BlitAlphatoARGB8888PixelAlpha(info);
break;
}
}
}
RTM_EXPORT(rtgui_blit);
#if 0
void rtgui_blit_client(rtgui_blit_info_src* src, struct rtgui_dc* client, struct rtgui_rect *dc_rect)
{
int index;
struct rtgui_widget* widget;
rtgui_region_t clip_region;
rtgui_rect_t rect;
/* get owner widget */
widget = RTGUI_CONTAINER_OF(client, struct rtgui_widget, dc_type);
/* get rect information */
if (dc_rect == NULL) rtgui_dc_get_rect(client, &rect);
else rect = *dc_rect;
/* to device */
rtgui_rect_moveto(&rect, widget->extent.x1, widget->extent.y1);
/* get the clipped region */
rtgui_region_intersect_rect(&clip_region, &widget->clip, &rect);
/* only 1 rect in extant */
if (clip_region.data == RT_NULL)
void rtgui_image_info_blit(struct rtgui_image_info* image, struct rtgui_dc* dc, struct rtgui_rect *dc_rect)
{
rt_uint8_t bpp, hw_bpp;
struct rtgui_widget *owner;
struct rtgui_blit_info info;
}
else
struct rtgui_rect dest_extent;
struct rtgui_graphic_driver *hw_driver;
hw_driver = rtgui_graphic_driver_get_default();
dest_extent = *dc_rect;
if (dc->type == RTGUI_DC_CLIENT && hw_driver->framebuffer)
{
/* blit on each rect */
for (index = 0; index < clip_region.data.numRects; index ++)
int index, num_rects;
struct rtgui_rect *rects;
struct rtgui_region dest_region;
bpp = rtgui_color_get_bpp(image->src_fmt);
hw_bpp = rtgui_color_get_bpp(hw_driver->pixel_format);
owner = RTGUI_CONTAINER_OF(dc, struct rtgui_widget, dc_type);
rtgui_widget_rect_to_device(owner, &dest_extent);
/* get intersect region clip */
rtgui_region_init_with_extents(&dest_region, &dest_extent);
rtgui_region_intersect_rect(&dest_region, &(owner->clip), &dest_extent);
num_rects = rtgui_region_num_rects(&dest_region);
rects = rtgui_region_rects(&dest_region);
/* fill common info */
info.a = image->a;
info.src_fmt = image->src_fmt;
info.src_pitch = image->src_pitch;
info.dst_fmt = hw_driver->pixel_format;
info.dst_pitch = hw_driver->pitch;
for (index = 0; index < num_rects; index ++)
{
}
struct rtgui_rect *r = &rects[index];
/* blit source */
info.src = image->pixels + (r->x1 - dest_extent.x1) * bpp + (r->y1 - dest_extent.y1) * image->src_pitch;
info.src_h = rtgui_rect_height(*r);
info.src_w = rtgui_rect_width(*r);
info.src_skip = info.src_pitch - info.src_w * bpp;
/* blit destination */
info.dst = (rt_uint8_t*)hw_driver->framebuffer + r->y1 * hw_driver->pitch +
r->x1 * hw_bpp;
info.dst_h = rtgui_rect_height(*r);
info.dst_w = rtgui_rect_width(*r);
info.dst_skip = info.dst_pitch - info.dst_w * hw_bpp;
rtgui_blit(&info);
}
rtgui_region_fini(&clip_region);
rtgui_region_fini(&dest_region);
}
RTM_EXPORT(rtgui_blit_client);
#endif
else if (dc->type == RTGUI_DC_HW && hw_driver->framebuffer)
{
struct rtgui_dc_hw *hw = (struct rtgui_dc_hw *)dc;
struct rtgui_rect *r;
bpp = rtgui_color_get_bpp(image->src_fmt);
hw_bpp = rtgui_color_get_bpp(hw_driver->pixel_format);
owner = hw->owner;
rtgui_widget_rect_to_device(owner, &dest_extent);
r = &dest_extent;
/* fill common info */
info.a = image->a;
info.src_fmt = image->src_fmt;
info.src_pitch = image->src_pitch;
info.dst_fmt = hw_driver->pixel_format;
info.dst_pitch = hw_driver->pitch;
/* blit source */
info.src = image->pixels;
info.src_h = rtgui_rect_height(*r);
info.src_w = rtgui_rect_width(*r);
info.src_skip = info.src_pitch - info.src_w * bpp;
/* blit destination */
info.dst = (rt_uint8_t*)hw_driver->framebuffer + r->y1 * hw_driver->pitch + r->x1 * hw_bpp;
info.dst_h = rtgui_rect_height(*r);
info.dst_w = rtgui_rect_width(*r);
info.dst_skip = info.dst_pitch - info.dst_w * hw_bpp;
rtgui_blit(&info);
}
else if (dc->type == RTGUI_DC_BUFFER)
{
struct rtgui_rect *r;
struct rtgui_dc_buffer *dc_buffer = (struct rtgui_dc_buffer*)dc;
bpp = rtgui_color_get_bpp(image->src_fmt);
hw_bpp = rtgui_color_get_bpp(dc_buffer->pixel_format);
r = &dest_extent;
/* fill common info */
info.a = image->a;
info.src_fmt = image->src_fmt;
info.src_pitch = image->src_pitch;
info.dst_fmt = dc_buffer->pixel_format;
info.dst_pitch = dc_buffer->pitch;
/* blit source */
info.src = image->pixels;
info.src_w = rtgui_rect_width(*r);
info.src_h = rtgui_rect_height(*r);
info.src_skip = info.src_pitch - info.src_w * bpp;
/* blit destination */
info.dst = (rt_uint8_t*)dc_buffer->pixel + r->y1 * dc_buffer->pitch + r->x1 * hw_bpp;
info.dst_w = rtgui_rect_width(*r);
info.dst_h = rtgui_rect_height(*r);
info.dst_skip = info.dst_pitch - info.dst_w * hw_bpp;
rtgui_blit(&info);
}
}
RTM_EXPORT(rtgui_image_info_blit);

View File

@ -1,11 +1,21 @@
/*
* File : box.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, 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
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes

View File

@ -1,11 +1,21 @@
/*
* File : color.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, 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
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes

View File

@ -1,11 +1,21 @@
/*
* File : container.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, 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
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
@ -49,16 +59,42 @@ rt_bool_t rtgui_container_dispatch_event(rtgui_container_t *container, rtgui_eve
{
/* handle in child widget */
struct rtgui_list_node *node;
rtgui_event_t _event, save_event = *event;
rtgui_widget_t *widget = (rtgui_widget_t *)container;
rtgui_list_foreach(node, &(container->children))
{
struct rtgui_widget *w;
w = rtgui_list_entry(node, struct rtgui_widget, sibling);
_event = save_event;
if (RTGUI_EVENT_PAINT & _event.type)
{
if (widget->extent.x1 > w->extent.x2)
{
_event.type &= !RTGUI_EVENT_PAINT;
}
else if (widget->extent.x2 < w->extent.x1)
{
_event.type &= !RTGUI_EVENT_PAINT;
}
else if (widget->extent.y1 > w->extent.y2)
{
_event.type &= !RTGUI_EVENT_PAINT;
}
else if (widget->extent.y2 < w->extent.y1)
{
_event.type &= !RTGUI_EVENT_PAINT;
}
}
if (RTGUI_OBJECT(w)->event_handler &&
RTGUI_OBJECT(w)->event_handler(RTGUI_OBJECT(w), event) == RT_TRUE)
RTGUI_OBJECT(w)->event_handler(RTGUI_OBJECT(w), &_event) == RT_TRUE)
{
return RT_TRUE;
}
}
return RT_FALSE;
}
@ -140,7 +176,7 @@ rt_bool_t rtgui_container_event_handler(struct rtgui_object *object, struct rtgu
/* paint on each child */
rtgui_container_dispatch_event(container, event);
rtgui_dc_end_drawing(dc);
rtgui_dc_end_drawing(dc, 1);
}
break;
@ -158,8 +194,8 @@ rt_bool_t rtgui_container_event_handler(struct rtgui_object *object, struct rtgu
rtgui_container_dispatch_event(container, event);
break;
case RTGUI_EVENT_HIDE:
rtgui_widget_onhide(RTGUI_OBJECT(container), event);
rtgui_container_dispatch_event(container, event);
rtgui_widget_onhide(RTGUI_OBJECT(container), event);
break;
case RTGUI_EVENT_COMMAND:
rtgui_container_dispatch_event(container, event);

View File

@ -1,11 +1,21 @@
/*
* File : dc.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, 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
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
@ -19,8 +29,6 @@
#include <math.h>
#include <rtgui/dc.h>
#include <rtgui/dc_hw.h>
#include <rtgui/dc_client.h>
#include <rtgui/rtgui_system.h>
#include <rtgui/rtgui_server.h>
@ -690,21 +698,20 @@ void rtgui_dc_draw_arc(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_int16
/*
* Draw arc
* Octant labelling
*
* \ 5 | 6 /
* \ | /
* 4 \ | / 7
* \|/
*------+------ +x
* /|\
* 3 / | \ 0
* / | \
* / 2 | 1 \
* +y
*/
// Octant labelling
//
// \ 5 | 6 /
// \ | /
// 4 \ | / 7
// \|/
//------+------ +x
// /|\
// 3 / | \ 0
// / | \
// / 2 | 1 \
// +y
drawoct = 0; // 0x00000000
// whether or not to keep drawing a given octant.
// For example: 0x00111100 means we're drawing in octants 2-5
@ -1319,18 +1326,20 @@ void rtgui_dc_draw_pie(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_int16
}
RTM_EXPORT(rtgui_dc_draw_pie);
// Octant labelling
//
// \ 5 | 6 /
// \ | /
// 4 \ | / 7
// \|/
//------+------ +x
// /|\
// 3 / | \ 0
// / | \
// / 2 | 1 \
// +y
/*
* Octant labelling
*
* \ 5 | 6 /
* \ | /
* 4 \ | / 7
* \|/
*------+------ +x
* /|\
* 3 / | \ 0
* / | \
* / 2 | 1 \
* +y
*/
static void _draw_octant(struct rtgui_dc *dc,
rt_int16_t ox, rt_int16_t oy,
rt_int16_t y1, rt_int16_t y2, rt_int16_t x, int oct)
@ -1814,6 +1823,10 @@ struct rtgui_dc *rtgui_dc_begin_drawing(rtgui_widget_t *owner)
return RT_NULL;
/* increase drawing count */
if (win->drawing == 0)
{
memset(&(win->drawing_rect), 0x0, sizeof(struct rtgui_rect));
}
win->drawing ++;
/* always drawing on the virtual mode */
@ -1873,7 +1886,7 @@ struct rtgui_dc *rtgui_dc_begin_drawing(rtgui_widget_t *owner)
}
RTM_EXPORT(rtgui_dc_begin_drawing);
void rtgui_dc_end_drawing(struct rtgui_dc *dc)
void rtgui_dc_end_drawing(struct rtgui_dc *dc, rt_bool_t update)
{
struct rtgui_widget *owner;
struct rtgui_win *win;
@ -1889,9 +1902,25 @@ void rtgui_dc_end_drawing(struct rtgui_dc *dc)
/* get window */
win = owner->toplevel;
/* union drawing rect */
rtgui_rect_union(&(owner->extent_visiable), &(win->drawing_rect));
/* decrease drawing counter */
win->drawing--;
if (win->drawing == 0 && rtgui_graphic_driver_is_vmode() == RT_FALSE)
if (win->drawing == 0)
{
/* notify window to handle window update done */
if (RTGUI_OBJECT(win)->event_handler)
{
struct rtgui_event_win_update_end ewin_update;
RTGUI_EVENT_WIN_UPDATE_END_INIT(&(ewin_update));
ewin_update.rect = win->drawing_rect;
RTGUI_OBJECT(win)->event_handler(RTGUI_OBJECT(win), (struct rtgui_event *)&ewin_update);
}
if (rtgui_graphic_driver_is_vmode() == RT_FALSE && update)
{
#ifdef RTGUI_USING_MOUSE_CURSOR
rt_mutex_release(&cursor_mutex);
@ -1915,9 +1944,9 @@ void rtgui_dc_end_drawing(struct rtgui_dc *dc)
rtgui_server_post_event((struct rtgui_event *)&eupdate, sizeof(eupdate));
}
}
}
dc->engine->fini(dc);
rtgui_screen_unlock();
}
RTM_EXPORT(rtgui_dc_end_drawing);

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +1,21 @@
/*
* File : dc_buffer.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, 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
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
@ -14,11 +24,10 @@
#include <rtgui/rtgui.h>
#include <rtgui/dc.h>
#include <rtgui/blit.h>
#include <rtgui/dc_hw.h>
#include <rtgui/color.h>
#include <rtgui/rtgui_system.h>
#include <rtgui/dc_draw.h>
#include <rtgui/image_container.h>
#include <string.h>
static rt_bool_t rtgui_dc_buffer_fini(struct rtgui_dc *dc);
@ -84,6 +93,9 @@ struct rtgui_dc *rtgui_dc_buffer_create_pixformat(rt_uint8_t pixel_format, int w
dc->height = h;
dc->pitch = w * rtgui_color_get_bpp(pixel_format);
#ifdef RTGUI_IMAGE_CONTAINER
dc->image_item = RT_NULL;
#endif
dc->pixel = rtgui_malloc(h * dc->pitch);
if (!dc->pixel)
{
@ -99,6 +111,38 @@ struct rtgui_dc *rtgui_dc_buffer_create_pixformat(rt_uint8_t pixel_format, int w
}
RTM_EXPORT(rtgui_dc_buffer_create_pixformat);
#ifdef RTGUI_IMAGE_CONTAINER
struct rtgui_dc *rtgui_img_dc_create_pixformat(rt_uint8_t pixel_format,
rt_uint8_t *pixel, struct rtgui_image_item *image_item)
{
struct rtgui_dc_buffer *dc;
dc = (struct rtgui_dc_buffer *)rtgui_malloc(sizeof(struct rtgui_dc_buffer));
if (dc)
{
dc->parent.type = RTGUI_DC_BUFFER;
dc->parent.engine = &dc_buffer_engine;
dc->gc.foreground = default_foreground;
dc->gc.background = default_background;
dc->gc.font = rtgui_font_default();
dc->gc.textalign = RTGUI_ALIGN_LEFT | RTGUI_ALIGN_TOP;
dc->pixel_format = pixel_format;
dc->width = image_item->image->w;
dc->height = image_item->image->h;
dc->pitch = image_item->image->w * rtgui_color_get_bpp(pixel_format);
dc->image_item = image_item;
dc->pixel = pixel;
return &(dc->parent);
}
return RT_NULL;
}
RTM_EXPORT(rtgui_img_dc_create_pixformat);
#endif
struct rtgui_dc *rtgui_dc_buffer_create_from_dc(struct rtgui_dc* dc)
{
struct rtgui_dc_buffer *buffer;
@ -142,8 +186,16 @@ static rt_bool_t rtgui_dc_buffer_fini(struct rtgui_dc *dc)
if (dc->type != RTGUI_DC_BUFFER) return RT_FALSE;
rtgui_free(buffer->pixel);
#ifdef RTGUI_IMAGE_CONTAINER
if (buffer->image_item)
{
rtgui_image_container_put(buffer->image_item);
buffer->pixel = RT_NULL;
}
#endif
if (buffer->pixel)
rtgui_free(buffer->pixel);
return RT_TRUE;
}
@ -409,63 +461,15 @@ static void rtgui_dc_buffer_blit(struct rtgui_dc *self,
/* prepare pixel line */
pixels = _dc_get_pixel(dc, dc_point.x, dc_point.y);
if (hw_driver->bits_per_pixel == _dc_get_bits_per_pixel(dc))
{
if (dest->type == RTGUI_DC_HW && hw_driver->framebuffer != RT_NULL)
{
rt_uint8_t *hw_pixels;
struct rtgui_dc_hw *hw;
/* use rtgui_blit */
hw = (struct rtgui_dc_hw*)dest;
/* NOTES: the rect of DC is the logic coordination.
* It should be converted to client
*/
if (dest_rect != &_rect)
{
/* use local rect */
_rect = *dest_rect;
dest_rect = &_rect;
}
rtgui_rect_moveto(dest_rect, hw->owner->extent.x1, hw->owner->extent.y1);
pitch = rtgui_color_get_bpp(hw_driver->pixel_format) * rect_width;
hw_pixels = (rt_uint8_t*)(hw_driver->framebuffer + dest_rect->y1 * hw_driver->pitch +
dest_rect->x1 * rtgui_color_get_bpp(hw_driver->pixel_format));
/* do the blit with memory copy */
for (index = 0; index < rect_height; index ++)
{
rt_memcpy(hw_pixels, pixels, pitch);
pixels += dc->pitch;
hw_pixels += hw_driver->pitch;
}
}
else
{
/* it's the same bits per pixel, draw it directly */
for (index = dest_rect->y1; index < dest_rect->y1 + rect_height; index++)
{
dest->engine->blit_line(dest, dest_rect->x1, dest_rect->x1 + rect_width, index, pixels);
pixels += dc->pitch;
}
}
}
else
{
struct rtgui_graphic_driver *hw_driver;
hw_driver = rtgui_graphic_driver_get_default();
if ((dc->pixel_format == RTGRAPHIC_PIXEL_FORMAT_ARGB888) &&
(dest->type == RTGUI_DC_HW) &&
(hw_driver->framebuffer != RT_NULL) &&
(hw_driver->pixel_format == RTGRAPHIC_PIXEL_FORMAT_RGB565))
{
/* do the fast ARGB to RGB565 blit */
struct rtgui_blit_info info;
struct rtgui_widget *owner;
info.a = 255;
/* blit source */
info.src = _dc_get_pixel(dc, dc_point.x, dc_point.y);
info.src_fmt = dc->pixel_format;
@ -488,6 +492,62 @@ static void rtgui_dc_buffer_blit(struct rtgui_dc *self,
rtgui_blit(&info);
}
else if (dest->type == RTGUI_DC_CLIENT&& hw_driver->framebuffer != RT_NULL)
{
/* use rtgui_blit */
rt_uint8_t bpp, hw_bpp;
struct rtgui_blit_info info;
struct rtgui_widget *owner;
struct rtgui_region dest_region;
struct rtgui_rect dest_extent;
int num_rects;
struct rtgui_rect *rects;
/* get owner */
owner = RTGUI_CONTAINER_OF(dest, struct rtgui_widget, dc_type);
dest_extent = *dest_rect;
rtgui_widget_rect_to_device(owner, &dest_extent);
rtgui_region_init_with_extents(&dest_region, &dest_extent);
rtgui_region_intersect_rect(&dest_region, &(owner->clip), &dest_extent);
bpp = rtgui_color_get_bpp(dc->pixel_format);
hw_bpp = rtgui_color_get_bpp(hw_driver->pixel_format);
num_rects = rtgui_region_num_rects(&dest_region);
rects = rtgui_region_rects(&dest_region);
/* common info */
info.a = 255;
info.src_fmt = dc->pixel_format;
info.src_pitch = dc->pitch;
info.dst_fmt = hw_driver->pixel_format;
info.dst_pitch = hw_driver->pitch;
for (index = 0; index < num_rects; index ++)
{
struct rtgui_rect *r = &rects[index];
/* blit source */
info.src = _dc_get_pixel(dc, dc_point.x + (r->x1 - dest_extent.x1),
dc_point.y + (r->y1 - dest_extent.y1));
info.src_h = rtgui_rect_height(*r);
info.src_w = rtgui_rect_width(*r);
info.src_skip = info.src_pitch - info.src_w * bpp;
/* blit destination */
info.dst = (rt_uint8_t*)hw_driver->framebuffer + r->y1 * hw_driver->pitch +
r->x1 * hw_bpp;
info.dst_h = rtgui_rect_height(*r);
info.dst_w = rtgui_rect_width(*r);
info.dst_skip = info.dst_pitch - info.dst_w * hw_bpp;
rtgui_blit(&info);
}
rtgui_region_fini(&dest_region);
}
else
{
/* calculate pitch */
@ -537,34 +597,15 @@ static void rtgui_dc_buffer_blit(struct rtgui_dc *self,
}
}
}
}
else if (dest->type == RTGUI_DC_BUFFER)
{
struct rtgui_dc_buffer *dest_dc = (struct rtgui_dc_buffer*)dest;
if (dest_dc->pixel_format == dc->pixel_format && dest_dc->pixel_format == RTGRAPHIC_PIXEL_FORMAT_RGB565)
{
int index;
rt_uint8_t *pixels, *dest_pixels;
/* get pitch */
pitch = rect_width * rtgui_color_get_bpp(dc->pixel_format);
pixels = _dc_get_pixel(dc, dc_point.x, dc_point.y);
dest_pixels = _dc_get_pixel(dest_dc, dest_rect->x1, dest_rect->y1);
for (index = 0; index < rect_height; index ++)
{
rt_memcpy(dest_pixels, pixels, pitch);
pixels += dc->pitch;
dest_pixels += dest_dc->pitch;
}
}
else /* use rtgui_blit to handle buffer blit */
{
/* do the fast ARGB to RGB565 blit */
/* use rtgui_blit to handle buffer blit */
struct rtgui_blit_info info;
info.a = 255;
/* blit source */
info.src = _dc_get_pixel(dc, dc_point.x, dc_point.y);
info.src_fmt = dc->pixel_format;
@ -584,7 +625,6 @@ static void rtgui_dc_buffer_blit(struct rtgui_dc *self,
rtgui_blit(&info);
}
}
}
static void rtgui_dc_buffer_blit_line(struct rtgui_dc *self, int x1, int x2, int y, rt_uint8_t *line_data)
{
@ -608,3 +648,32 @@ static void rtgui_dc_buffer_blit_line(struct rtgui_dc *self, int x1, int x2, int
rt_memcpy(pixel, line_data, (x2 - x1) * rtgui_color_get_bpp(dc->pixel_format));
}
#ifdef RT_USING_DFS
#include <dfs_posix.h>
void rtgui_dc_buffer_dump(struct rtgui_dc *self, char *fn)
{
struct dc_file_header
{
int w, h;
int format;
} header;
struct rtgui_dc_buffer *buffer;
int fd;
if (self->type != RTGUI_DC_BUFFER) return; /* only support DC buffer */
buffer = (struct rtgui_dc_buffer*)self;
header.w = buffer->width;
header.h = buffer->height;
header.format = buffer->pixel_format;
fd = open(fn, O_RDWR | O_CREAT | O_TRUNC, 0);
if (fd >= 0)
{
write(fd, &header, sizeof(header));
write(fd, buffer->pixel, header.w * header.h * rtgui_color_get_bpp(header.format));
close(fd);
}
}
#endif

View File

@ -1,11 +1,21 @@
/*
* File : dc_client.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, 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
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
@ -16,8 +26,6 @@
* 2010-09-14 Bernard fix vline and hline coordinate issue
*/
#include <rtgui/dc.h>
#include <rtgui/dc_hw.h>
#include <rtgui/dc_client.h>
#include <rtgui/driver.h>
#include <rtgui/rtgui_system.h>

View File

@ -1,18 +1,27 @@
/*
* File : dc_hw.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, 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
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2009-10-16 Bernard first version
*/
#include <rtgui/dc.h>
#include <rtgui/dc_hw.h>
#include <rtgui/driver.h>
#include <rtgui/rtgui_system.h>
#include <rtgui/rtgui_app.h>

View File

@ -65,7 +65,8 @@ Andreas Schiffler -- aschiffler at ferzkopp dot net
/*!
\brief A 32 bit RGBA pixel.
*/
typedef struct tColorRGBA {
typedef struct tColorRGBA
{
rt_uint8_t r;
rt_uint8_t g;
rt_uint8_t b;
@ -75,7 +76,8 @@ typedef struct tColorRGBA {
/*!
\brief A 8bit Y/palette pixel.
*/
typedef struct tColorY {
typedef struct tColorY
{
rt_uint8_t y;
} tColorY;
@ -220,10 +222,12 @@ int _rtgui_dc_zoom_RGBA(struct rtgui_dc_buffer * src, struct rtgui_dc_buffer * d
/*
* Allocate memory for row/column increments
*/
if ((sax = (int *) rtgui_malloc((dst->width + 1) * sizeof(rt_uint32_t))) == RT_NULL) {
if ((sax = (int *) rtgui_malloc((dst->width + 1) * sizeof(rt_uint32_t))) == RT_NULL)
{
return (-1);
}
if ((say = (int *) rtgui_malloc((dst->height + 1) * sizeof(rt_uint32_t))) == RT_NULL) {
if ((say = (int *) rtgui_malloc((dst->height + 1) * sizeof(rt_uint32_t))) == RT_NULL)
{
rtgui_free(sax);
return (-1);
}
@ -233,10 +237,13 @@ int _rtgui_dc_zoom_RGBA(struct rtgui_dc_buffer * src, struct rtgui_dc_buffer * d
*/
spixelw = (src->width - 1);
spixelh = (src->height- 1);
if (smooth) {
if (smooth)
{
sx = (int) (65536.0 * (double) spixelw / (double) (dst->width - 1));
sy = (int) (65536.0 * (double) spixelh / (double) (dst->height - 1));
} else {
}
else
{
sx = (int) (65536.0 * (double) (src->width) / (double) (dst->width));
sy = (int) (65536.0 * (double) (src->height) / (double) (dst->height));
}
@ -248,13 +255,15 @@ int _rtgui_dc_zoom_RGBA(struct rtgui_dc_buffer * src, struct rtgui_dc_buffer * d
/* Precalculate horizontal row increments */
csx = 0;
csax = sax;
for (x = 0; x <= dst->width; x++) {
for (x = 0; x <= dst->width; x++)
{
*csax = csx;
csax++;
csx += sx;
/* Guard from overflows */
if (csx > ssx) {
if (csx > ssx)
{
csx = ssx;
}
}
@ -262,13 +271,15 @@ int _rtgui_dc_zoom_RGBA(struct rtgui_dc_buffer * src, struct rtgui_dc_buffer * d
/* Precalculate vertical row increments */
csy = 0;
csay = say;
for (y = 0; y <= dst->height; y++) {
for (y = 0; y <= dst->height; y++)
{
*csay = csy;
csay++;
csy += sy;
/* Guard from overflows */
if (csy > ssy) {
if (csy > ssy)
{
csy = ssy;
}
}
@ -284,16 +295,19 @@ int _rtgui_dc_zoom_RGBA(struct rtgui_dc_buffer * src, struct rtgui_dc_buffer * d
/*
* Switch between interpolating and non-interpolating code
*/
if (smooth) {
if (smooth)
{
/*
* Interpolating Zoom
*/
csay = say;
for (y = 0; y < dst->height; y++) {
for (y = 0; y < dst->height; y++)
{
csp = sp;
csax = sax;
for (x = 0; x < dst->width; x++) {
for (x = 0; x < dst->width; x++)
{
/*
* Setup color source pointers
*/
@ -306,19 +320,27 @@ int _rtgui_dc_zoom_RGBA(struct rtgui_dc_buffer * src, struct rtgui_dc_buffer * d
c00 = sp;
c01 = sp;
c10 = sp;
if (sstepy) {
if (flipy) {
if (sstepy)
{
if (flipy)
{
c10 -= spixelgap;
} else {
}
else
{
c10 += spixelgap;
}
}
c11 = c10;
if (sstepx) {
if (flipx) {
if (sstepx)
{
if (flipx)
{
c01--;
c11--;
} else {
}
else
{
c01++;
c11++;
}
@ -345,9 +367,12 @@ int _rtgui_dc_zoom_RGBA(struct rtgui_dc_buffer * src, struct rtgui_dc_buffer * d
salast = csax;
csax++;
sstep = (*csax >> 16) - (*salast >> 16);
if (flipx) {
if (flipx)
{
sp -= sstep;
} else {
}
else
{
sp += sstep;
}
@ -363,9 +388,12 @@ int _rtgui_dc_zoom_RGBA(struct rtgui_dc_buffer * src, struct rtgui_dc_buffer * d
csay++;
sstep = (*csay >> 16) - (*salast >> 16);
sstep *= spixelgap;
if (flipy) {
if (flipy)
{
sp = csp - sstep;
} else {
}
else
{
sp = csp + sstep;
}
@ -374,15 +402,19 @@ int _rtgui_dc_zoom_RGBA(struct rtgui_dc_buffer * src, struct rtgui_dc_buffer * d
*/
dp = (tColorRGBA *) ((rt_uint8_t *) dp + dgap);
}
} else {
}
else
{
/*
* Non-Interpolating Zoom
*/
csay = say;
for (y = 0; y < dst->height; y++) {
for (y = 0; y < dst->height; y++)
{
csp = sp;
csax = sax;
for (x = 0; x < dst->width; x++) {
for (x = 0; x < dst->width; x++)
{
/*
* Draw
*/
@ -470,7 +502,8 @@ int _rtgui_dc_transform_RGBA(struct rtgui_dc_buffer * src, struct rtgui_dc_buffe
/*
* Switch between interpolating and non-interpolating code
*/
if (smooth) {
if (smooth)
{
for (y = 0; y < dst->height; y++)
{
dy = cy - y;
@ -494,13 +527,23 @@ int _rtgui_dc_transform_RGBA(struct rtgui_dc_buffer * src, struct rtgui_dc_buffe
c11 = *sp;
sp -= 1;
c10 = *sp;
if (flipx) {
cswap = c00; c00=c01; c01=cswap;
cswap = c10; c10=c11; c11=cswap;
if (flipx)
{
cswap = c00;
c00=c01;
c01=cswap;
cswap = c10;
c10=c11;
c11=cswap;
}
if (flipy) {
cswap = c00; c00=c10; c10=cswap;
cswap = c01; c01=c11; c11=cswap;
if (flipy)
{
cswap = c00;
c00=c10;
c10=cswap;
cswap = c01;
c01=c11;
c11=cswap;
}
/*
* Interpolate colors
@ -526,17 +569,22 @@ int _rtgui_dc_transform_RGBA(struct rtgui_dc_buffer * src, struct rtgui_dc_buffe
}
pc = (tColorRGBA *) ((rt_uint8_t *) pc + gap);
}
} else {
for (y = 0; y < dst->height; y++) {
}
else
{
for (y = 0; y < dst->height; y++)
{
dy = cy - y;
sdx = (ax + (isin * dy)) + xd;
sdy = (ay - (icos * dy)) + yd;
for (x = 0; x < dst->width; x++) {
for (x = 0; x < dst->width; x++)
{
dx = (short) (sdx >> 16);
dy = (short) (sdy >> 16);
if (flipx) dx = (src->width-1)-dx;
if (flipy) dy = (src->height-1)-dy;
if ((dx >= 0) && (dy >= 0) && (dx < src->width) && (dy < src->height)) {
if ((dx >= 0) && (dy >= 0) && (dx < src->width) && (dy < src->height))
{
sp = (tColorRGBA *) ((rt_uint8_t *) src->pixel + src->pitch * dy);
sp += dx;
*pc = *sp;
@ -579,7 +627,10 @@ struct rtgui_dc* rtgui_dc_rotate_90degrees(struct rtgui_dc_buffer* src, int numC
if (rtgui_color_get_bits(src->pixel_format) != 32) return RT_NULL;
/* normalize numClockwiseTurns */
while(numClockwiseTurns < 0) { numClockwiseTurns += 4; }
while(numClockwiseTurns < 0)
{
numClockwiseTurns += 4;
}
numClockwiseTurns = (numClockwiseTurns % 4);
/* if it's even, our new width will be the same as the source surface */
@ -623,10 +674,12 @@ struct rtgui_dc* rtgui_dc_rotate_90degrees(struct rtgui_dc_buffer* src, int numC
/* rotate clockwise */
case 1: /* rotated 90 degrees clockwise */
{
for (row = 0; row < src->height; ++row) {
for (row = 0; row < src->height; ++row)
{
srcBuf = (rt_uint32_t*)(src->pixel) + (row * src_ipr);
dstBuf = (rt_uint32_t*)(dst->pixel) + (dst->width - row - 1);
for (col = 0; col < src->width; ++col) {
for (col = 0; col < src->width; ++col)
{
*dstBuf = *srcBuf;
++srcBuf;
dstBuf += dst_ipr;
@ -891,10 +944,12 @@ void rtgui_dc_zoom_size(int width, int height, double zoomx, double zoomy, int *
/*
* Sanity check zoom factors
*/
if (zoomx < VALUE_LIMIT) {
if (zoomx < VALUE_LIMIT)
{
zoomx = VALUE_LIMIT;
}
if (zoomy < VALUE_LIMIT) {
if (zoomy < VALUE_LIMIT)
{
zoomy = VALUE_LIMIT;
}
@ -903,10 +958,12 @@ void rtgui_dc_zoom_size(int width, int height, double zoomx, double zoomy, int *
*/
*dstwidth = (int) floor(((double) width * zoomx) + 0.5);
*dstheight = (int) floor(((double) height * zoomy) + 0.5);
if (*dstwidth < 1) {
if (*dstwidth < 1)
{
*dstwidth = 1;
}
if (*dstheight < 1) {
if (*dstheight < 1)
{
*dstheight = 1;
}
}
@ -1004,9 +1061,15 @@ struct rtgui_dc *rtgui_dc_shrink(struct rtgui_dc *dc, int factorx, int factory)
/* Get size for target */
dstwidth=rz_src->width/factorx;
while (dstwidth*factorx>rz_src->width) { dstwidth--; }
while (dstwidth*factorx>rz_src->width)
{
dstwidth--;
}
dstheight=rz_src->height/factory;
while (dstheight*factory>rz_src->height) { dstheight--; }
while (dstheight*factory>rz_src->height)
{
dstheight--;
}
/*
* Target surface is 32bit with source RGBA/ABGR ordering

View File

@ -1,3 +1,27 @@
/*
* File : dc_trans.c
* This file is part of RT-Thread GUI
* COPYRIGHT (C) 2006 - 2014, RT-Thread Development Team
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2014-03-15 Grissom The first version
*/
#include <rtgui/rtgui.h>
#include <rtgui/rtgui_system.h>
#include <rtgui/dc.h>
@ -646,7 +670,8 @@ static void _blit_rotate_B2B(struct rtgui_dc_trans *dct,
if (dc->pixel_format == dest->pixel_format)
{
switch (rtgui_color_get_bpp(dest->pixel_format)) {
switch (rtgui_color_get_bpp(dest->pixel_format))
{
case 2:
if (dct->use_aa)
_blit_rotate_FR2FR_SF2B_AA(&srcfb, dc_point,
@ -724,7 +749,8 @@ static void _blit_rotate_B2H(struct rtgui_dc_trans *dct,
if (dc->pixel_format == dest->hw_driver->pixel_format)
{
switch (rtgui_color_get_bpp(dest->hw_driver->pixel_format)) {
switch (rtgui_color_get_bpp(dest->hw_driver->pixel_format))
{
case 2:
if (dct->use_aa)
_blit_rotate_FR2FR_SF2B_AA(&srcfb, dc_point,

View File

@ -1,11 +1,21 @@
/*
* File : filerw.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, 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
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes

View File

@ -1,11 +1,21 @@
/*
* File : font.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, 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
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
@ -99,6 +109,16 @@ struct rtgui_font *rtgui_font_refer(const char *family, rt_uint16_t height)
}
}
rtgui_list_foreach(node, &_rtgui_font_list)
{
font = rtgui_list_entry(node, struct rtgui_font, list);
if (rt_strncmp(font->family, family, RTGUI_NAME_MAX) == 0)
{
font->refer_count ++;
return font;
}
}
return RT_NULL;
}
RTM_EXPORT(rtgui_font_refer);

View File

@ -1,11 +1,21 @@
/*
* File : font.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2010, RT-Thread Development Team
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, 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
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes

View File

@ -1,3 +1,27 @@
/*
* File : font_fnt.c
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2010-09-15 Bernard first version
*/
/*
* rockbox fnt font engine
*/
@ -31,7 +55,8 @@ void rtgui_fnt_font_draw_text(struct rtgui_font *font, struct rtgui_dc *dc, cons
/* NOTE: we only support asc character right now */
if (ch > 0x80)
{
text += 1; len -= 1;
text += 1;
len -= 1;
continue;
}

View File

@ -1,11 +1,38 @@
/*
* File : font_freetype.c
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2010-09-15 Grissom first version
*/
#include <rtthread.h>
#ifdef RTGUI_USING_TTF
#include <rtgui/rtgui.h>
#include <rtgui/rtgui_system.h>
#include <rtgui/dc.h>
#include <rtgui/blit.h>
#include <rtgui/font.h>
#include <rtgui/font_freetype.h>
#include <ftcache.h>
#include <ft2build.h>
#include FT_FREETYPE_H
@ -25,31 +52,8 @@
#define PINFO(...)
#endif
static void ftf_draw_text(struct rtgui_font *font,
struct rtgui_dc *dc,
const char *text,
rt_ubase_t len,
struct rtgui_rect *rect);
static void ftf_get_metrics_kern(struct rtgui_font *font,
const char *text,
rtgui_rect_t *rect);
static const struct rtgui_font_engine ftf_engine =
{
RT_NULL,
RT_NULL,
ftf_draw_text,
ftf_get_metrics_kern
};
struct rtgui_freetype2_font
{
int bold;
int italic;
FT_Face face;
FT_Library library;
};
#define _dc_get_pixel(dc, x, y) \
((dc)->pixel + (y) * (dc)->pitch + (x) * rtgui_color_get_bpp((dc)->pixel_format))
#if !defined(RT_USING_DFS) || !defined(RT_USING_DFS_ELMFAT) || (RT_DFS_ELM_CODE_PAGE != 936)
extern rt_uint32_t gb2312tounicode(const rt_uint16_t key);
@ -87,129 +91,321 @@ static void gbk_to_unicode(rt_uint16_t *unicode, const char *text, int len)
*unicode = '\0';
}
static void _rtgui_rect_moveto_align(const rtgui_rect_t *rect, rtgui_rect_t *to, int align)
{
int dw, dh;
dw = 0;
dh = 0;
/* get delta width and height */
dw = rtgui_rect_width(*rect) - rtgui_rect_width(*to);
dh = rtgui_rect_height(*rect) - rtgui_rect_height(*to);
if (dw < 0) dw = 0;
if (dh < 0) dh = 0;
/* move to insider of rect */
rtgui_rect_moveto_point(to, rect->x1, rect->y1);
/* limited the destination rect to source rect */
// if (dw == 0) to->x2 = rect->x2;
// if (dh == 0) to->y2 = rect->y2;
/* align to right */
if (align & RTGUI_ALIGN_RIGHT)
{
to->x1 += dw;
to->x2 += dw;
}
/* align to bottom */
if (align & RTGUI_ALIGN_BOTTOM)
{
to->y1 += dh;
to->y2 += dh;
}
/* align to center horizontal */
if (align & RTGUI_ALIGN_CENTER_HORIZONTAL)
{
to->x1 += dw >> 1;
to->x2 += dw >> 1;
}
/* align to center vertical */
if (align & RTGUI_ALIGN_CENTER_VERTICAL)
{
to->y1 += dh >> 1;
to->y2 += dh >> 1;
}
}
static void ftc_draw_text(struct rtgui_font *font,
struct rtgui_dc *dc,
const char *text,
rt_ubase_t len,
struct rtgui_rect *rect);
static void ftc_get_metrics(struct rtgui_font *font, const char *text, rtgui_rect_t *rect);
static const struct rtgui_font_engine ftc_engine =
{
RT_NULL,
RT_NULL,
ftc_draw_text,
ftc_get_metrics
};
struct ttf_face_id
{
const char* pathname;
FT_Long face_index;
};
struct rtgui_ttf
{
/* the ttf list */
rtgui_list_t list;
rt_uint32_t refer_count;
struct ttf_face_id face_id;
FT_Library library;
FTC_Manager manager;
FTC_SBitCache sbit_cache;
FTC_CMapCache cmap_cache;
};
struct rtgui_ttf_font
{
struct rtgui_ttf *ttf;
FTC_ImageTypeRec image_type_rec;
};
static rtgui_list_t _rtgui_ttf_list;
void rtgui_ttf_system_init(void)
{
rtgui_list_init(&(_rtgui_ttf_list));
}
static void rtgui_ttf_system_add_ttf(struct rtgui_ttf *ttf)
{
rtgui_list_append(&_rtgui_ttf_list, &(ttf->list));
}
static void rtgui_ttf_system_remove_ttf(struct rtgui_ttf *ttf)
{
rtgui_list_remove(&_rtgui_ttf_list, &(ttf->list));
}
static struct rtgui_ttf *rtgui_ttf_refer(const char *family)
{
/* search ttf */
struct rtgui_list_node *node;
struct rtgui_ttf *ttf;
rtgui_list_foreach(node, &_rtgui_ttf_list)
{
ttf = (struct rtgui_ttf *)node;
if (rt_strncmp(ttf->face_id.pathname, family, RT_DFS_ELM_MAX_LFN) == 0)
{
ttf->refer_count ++;
return ttf;
}
}
return RT_NULL;
}
static void rtgui_ttf_derefer(struct rtgui_ttf *ttf)
{
RT_ASSERT(ttf != RT_NULL);
ttf->refer_count --;
/* no refer, remove ttf */
if (ttf->refer_count == 0)
{
rtgui_ttf_system_remove_ttf(ttf);
}
}
static void _get_metrics(struct rtgui_ttf_font *ttf_font, const rt_uint16_t *text_short, struct rtgui_rect *rect);
static void _draw_bitmap(struct rtgui_dc *dc,
FT_GlyphSlot slot,
FTC_SBit bitmap,
rt_int16_t ox, rt_int16_t btm_y,
rt_uint8_t r, rt_uint8_t g, rt_uint8_t b)
{
int rows;
rt_uint8_t *ptr;
FT_Bitmap *bitmap;
rt_int16_t xstart;
rt_int16_t x_start, y_start;
struct rtgui_blit_info info;
struct rtgui_dc_buffer *dest_buf;
bitmap = &slot->bitmap;
ptr = (rt_uint8_t *)bitmap->buffer;
xstart = ox + slot->bitmap_left;
for (rows = 0; rows < bitmap->rows; rows++)
{
int x;
int y = btm_y + rows - slot->bitmap_top;
x_start = ox + bitmap->left;
y_start = btm_y - bitmap->top;
for (x = 0; x < bitmap->width; x++)
info.a = 255;
info.r = r;
info.g = g;
info.b = b;
if (dc->type == RTGUI_DC_HW)
{
/* Use 5bit alpha. */
rt_uint8_t c = *ptr;
if (c >= 0xF8)
struct rtgui_graphic_driver *hw_driver = rtgui_graphic_driver_get_default();
dest_buf = (struct rtgui_dc_buffer*)dc;
if (hw_driver->framebuffer != RT_NULL)
{
rtgui_dc_draw_point(dc, xstart + x, y);
struct rtgui_widget *owner = ((struct rtgui_dc_hw*)dest_buf)->owner;
if (x_start + bitmap->width < 0 || y_start + bitmap->height < 0
|| x_start > owner->extent.x2 - owner->extent.x1 || y_start > owner->extent.y2 - owner->extent.y1)
return;
/* blit source */
info.src = (rt_uint8_t *)bitmap->buffer;
info.src = info.src + (y_start > 0 ? 0 : bitmap->top - btm_y) * bitmap->width + (x_start > 0 ? 0 : -x_start);
info.src_fmt = RTGRAPHIC_PIXEL_FORMAT_ALPHA;
info.src_w = bitmap->width - (x_start > 0 ? 0 : -x_start) - (x_start + bitmap->width < owner->extent.x2 - owner->extent.x1 ? 0 : x_start + bitmap->width - owner->extent.x2 + owner->extent.x1);
info.src_h = bitmap->height - (y_start > 0 ? 0 : bitmap->top - btm_y) - (y_start + bitmap->height < owner->extent.y2 - owner->extent.y1 ? 0 : y_start + bitmap->height - owner->extent.y2 + owner->extent.y1);
info.src_pitch = bitmap->width;
info.src_skip = info.src_pitch - info.src_w;
/* blit destination */
info.dst = (rt_uint8_t*)hw_driver->framebuffer;
info.dst = info.dst + (owner->extent.y1 + (y_start < 0 ? 0 : y_start)) * hw_driver->pitch + (owner->extent.x1 + (x_start < 0 ? 0 : x_start)) * rtgui_color_get_bpp(hw_driver->pixel_format);
info.dst_fmt = hw_driver->pixel_format;
info.dst_w = info.src_w;
info.dst_h = info.src_h;
info.dst_pitch = hw_driver->pitch;
info.dst_skip = info.dst_pitch - info.dst_w * rtgui_color_get_bpp(hw_driver->pixel_format);
rtgui_blit(&info);
}
else if (c >> 3)
{
rtgui_dc_blend_point(dc, xstart + x, y,
RTGUI_BLENDMODE_BLEND,
r, g, b, c);
}
ptr++;
else if (dc->type == RTGUI_DC_BUFFER)
{
dest_buf = (struct rtgui_dc_buffer*)dc;
if (x_start + bitmap->width < 0 || y_start + bitmap->height < 0
|| x_start > dest_buf->width || y_start > dest_buf->height)
return;
/* blit source */
info.src = (rt_uint8_t *)bitmap->buffer;
info.src = info.src + (y_start > 0 ? 0 : -y_start) * bitmap->width + (x_start > 0 ? 0 : -x_start);
info.src_fmt = RTGRAPHIC_PIXEL_FORMAT_ALPHA;
info.src_w = bitmap->width - (x_start > 0 ? 0 : -x_start) - (x_start + bitmap->width < dest_buf->width ? 0 : x_start + bitmap->width - dest_buf->width);
info.src_h = bitmap->height - (y_start > 0 ? 0 : -y_start) - (y_start + bitmap->height < dest_buf->height ? 0 : y_start + bitmap->height - dest_buf->height);
info.src_pitch = bitmap->width;
info.src_skip = info.src_pitch - info.src_w;
/* blit destination */
info.dst = _dc_get_pixel(dest_buf, (x_start < 0 ? 0 : x_start), (y_start < 0 ? 0 : y_start));
info.dst_fmt = dest_buf->pixel_format;
info.dst_w = info.src_w;
info.dst_h = info.src_h;
info.dst_pitch = dest_buf->pitch;
info.dst_skip = info.dst_pitch - info.dst_w * rtgui_color_get_bpp(dest_buf->pixel_format);
rtgui_blit(&info);
}
else
{
struct rtgui_rect text_rect;
struct rtgui_point dc_point = { 0, 0 };
struct rtgui_dc *text_dc = rtgui_dc_buffer_create_pixformat(RTGRAPHIC_PIXEL_FORMAT_ARGB888, bitmap->width, bitmap->height);
if (text_dc)
{
dest_buf = (struct rtgui_dc_buffer*)text_dc;
/* blit source */
info.src = (rt_uint8_t *)bitmap->buffer;
info.src_fmt = RTGRAPHIC_PIXEL_FORMAT_ALPHA;
info.src_w = bitmap->width;
info.src_h = bitmap->height;
info.src_pitch = bitmap->width;
info.src_skip = 0;
/* blit destination */
info.dst = _dc_get_pixel(dest_buf, 0, 0);
info.dst_fmt = dest_buf->pixel_format;
info.dst_w = info.src_w;
info.dst_h = info.src_h;
info.dst_pitch = dest_buf->pitch;
info.dst_skip = info.dst_pitch - info.dst_w * rtgui_color_get_bpp(dest_buf->pixel_format);
rtgui_blit(&info);
text_rect.x1 = x_start;
text_rect.x2 = text_rect.x1 + bitmap->width;
text_rect.y1 = y_start;
text_rect.y2 = text_rect.y1 + bitmap->height;
rtgui_dc_blit(text_dc, &dc_point, dc, &text_rect);
rtgui_dc_destory(text_dc);
}
}
}
static void _draw_text_nkern(struct rtgui_dc *dc,
struct rtgui_freetype2_font *fft,
static void _draw_text(struct rtgui_dc *dc,
struct rtgui_ttf_font *ttf_font,
rt_uint16_t *text_short,
rt_int16_t begin_x, rt_int16_t btm_y,
rt_uint8_t r, rt_uint8_t g, rt_uint8_t b)
{
rt_uint16_t *text_ptr;
FT_GlyphSlot slot;
slot = fft->face->glyph;
for (text_ptr = text_short; *text_ptr; text_ptr++)
{
int glyphIndex;
FTC_SBit ftcSBit = RT_NULL;
FT_Error err = 0;
err = FT_Load_Char(fft->face, *text_ptr, FT_LOAD_RENDER | FT_LOAD_NO_HINTING);
if (err)
continue; /* ignore errors */
while (*text_short)
{
glyphIndex = FTC_CMapCache_Lookup(ttf_font->ttf->cmap_cache, &ttf_font->ttf->face_id, 0, *text_short);
err = FTC_SBitCache_Lookup(ttf_font->ttf->sbit_cache, &ttf_font->image_type_rec, glyphIndex, &ftcSBit, 0);
if (err == 0 && ftcSBit->width != 0)
{
/* render font */
_draw_bitmap(dc, slot, begin_x, btm_y, r, g, b);
_draw_bitmap(dc, ftcSBit, begin_x, btm_y, r, g, b);
begin_x += slot->advance.x >> 6;
}
}
begin_x += ftcSBit->width + ftcSBit->left;
static void _draw_text_kern(struct rtgui_dc *dc,
struct rtgui_freetype2_font *fft,
rt_uint16_t *text_short,
rt_int16_t begin_x, rt_int16_t btm_y,
rt_uint8_t r, rt_uint8_t g, rt_uint8_t b)
text_short++;
}
else if (*text_short == ' ')
{
rt_uint16_t *tp;
FT_GlyphSlot slot;
FT_Face face;
rt_uint32_t prev_gidx;
glyphIndex = FTC_CMapCache_Lookup(ttf_font->ttf->cmap_cache, &ttf_font->ttf->face_id, 0, '-');
face = fft->face;
slot = face->glyph;
prev_gidx = 0;
for (tp = text_short; *tp; tp++)
err = FTC_SBitCache_Lookup(ttf_font->ttf->sbit_cache, &ttf_font->image_type_rec, glyphIndex, &ftcSBit, 0);
if (err == 0)
{
FT_Error err;
rt_uint32_t cur_gidx;
begin_x += ftcSBit->width;
cur_gidx = FT_Get_Char_Index(face, *tp);
if (prev_gidx && cur_gidx)
{
FT_Vector delta;
FT_Get_Kerning(face, prev_gidx, cur_gidx,
FT_KERNING_DEFAULT, &delta );
begin_x += delta.x >> 6;
text_short++;
}
}
prev_gidx = cur_gidx;
err = FT_Load_Glyph(face, cur_gidx, FT_LOAD_RENDER | FT_LOAD_NO_HINTING);
if (err)
continue;
/* render font */
_draw_bitmap(dc, slot, begin_x, btm_y, r, g, b);
begin_x += slot->advance.x >> 6;
}
}
static void ftf_draw_text(struct rtgui_font *font,
static void ftc_draw_text(struct rtgui_font *font,
struct rtgui_dc *dc,
const char *text,
rt_ubase_t len,
struct rtgui_rect *rect)
{
rt_uint16_t *text_short;
struct rtgui_freetype2_font *fft;
struct rtgui_ttf_font *ttf_font;
rt_int16_t begin_x, btm_y;
rt_int16_t topy;
rt_uint8_t r, g, b;
rtgui_color_t fgc;
struct rtgui_rect text_rect;
RT_ASSERT(font != RT_NULL);
fft = (struct rtgui_freetype2_font *) font->data;
RT_ASSERT(fft != RT_NULL);
ttf_font = (struct rtgui_ttf_font *) font->data;
RT_ASSERT(ttf_font != RT_NULL);
/* allocate unicode buffer */
text_short = (rt_uint16_t *)rtgui_malloc((len + 1) * 2);
@ -226,16 +422,17 @@ static void ftf_draw_text(struct rtgui_font *font,
g = RTGUI_RGB_G(fgc);
b = RTGUI_RGB_B(fgc);
/* FIXME: RTGUI has no concept of "base line" right now. FreeType
* coordinate(0, 0) start from base line. So we have to adjust the rect to
* fit the glyphs within the rect. */
/* FIXME: face->size->metrics.descender is format specific actually. But it
* just works on TrueType. Varify this if you want to use with other fonts. */
topy = rect->y1 + (fft->face->size->metrics.descender >> 6);
btm_y = topy + rtgui_rect_height(*rect);
/* text align */
_get_metrics(ttf_font, text_short, &text_rect);
topy = text_rect.y1;
_rtgui_rect_moveto_align(rect, &text_rect, RTGUI_DC_TEXTALIGN(dc));
btm_y = topy + text_rect.y2;
if (btm_y <= 0)
return;
begin_x = rect->x1;
begin_x = text_rect.x1;
if (dc->type == RTGUI_DC_BUFFER)
{
@ -259,102 +456,70 @@ static void ftf_draw_text(struct rtgui_font *font,
goto _out;
}
if (FT_HAS_KERNING(fft->face))
{
_draw_text_kern(dc, fft, text_short, begin_x, btm_y, r, g, b);
}
else
{
_draw_text_nkern(dc, fft, text_short, begin_x, btm_y, r, g, b);
}
_draw_text(dc, ttf_font, text_short, begin_x, btm_y, r, g, b);
_out:
/* release unicode buffer */
rtgui_free(text_short);
}
static void _get_metrics_nkern(FT_Face face, const rt_uint16_t *text_short, struct rtgui_rect *rect)
static void _get_metrics(struct rtgui_ttf_font *ttf_font, const rt_uint16_t *text_short, struct rtgui_rect *rect)
{
rt_int16_t w;
FTC_SBit ftcSBit = RT_NULL;
rt_int16_t w = 0, top = 0, btm = 0;
w = 0;
while (*text_short)
{
FT_Error err = 0;
rt_uint16_t index;
int glyphIndex;
index = FT_Get_Char_Index(face, *text_short);
err = FT_Load_Glyph(face, index,
FT_LOAD_DEFAULT |
FT_LOAD_NO_HINTING |
FT_LOAD_IGNORE_TRANSFORM |
FT_LOAD_NO_AUTOHINT);
glyphIndex = FTC_CMapCache_Lookup(ttf_font->ttf->cmap_cache, &ttf_font->ttf->face_id, 0, *text_short);
err = FTC_SBitCache_Lookup(ttf_font->ttf->sbit_cache, &ttf_font->image_type_rec, glyphIndex, &ftcSBit, 0);
if (err == 0 && ftcSBit->width != 0)
{
if (w == 0)
w = ftcSBit->width;
else
w += ftcSBit->width + ftcSBit->left;
top = top > ftcSBit->top ? top : ftcSBit->top;
btm = (ftcSBit->top - ftcSBit->height) > btm ? btm : (ftcSBit->top - ftcSBit->height);
}
else if (*text_short == ' ')
{
glyphIndex = FTC_CMapCache_Lookup(ttf_font->ttf->cmap_cache, &ttf_font->ttf->face_id, 0, '-');
err = FTC_SBitCache_Lookup(ttf_font->ttf->sbit_cache, &ttf_font->image_type_rec, glyphIndex, &ftcSBit, 0);
if (err == 0)
w += face->glyph->advance.x >> 6;
{
w += ftcSBit->width;
}
}
PINFO(" bitmap:(%d, %d, %d, %d)\n", ftcSBit->left, ftcSBit->top,
ftcSBit->width, ftcSBit->height);
text_short ++;
}
rect->x1 = 0;
rect->y1 = 0;
rect->y1 = btm;
rect->x2 = w;
rect->y2 = FT_MulFix(face->bbox.yMax - face->bbox.yMin,
face->size->metrics.y_scale) >> 6;
rect->y2 = top;
PINFO(" _get_metrics: %d %d %d %d\n", rect->x1, rect->y1, rect->x2, rect->y2);
}
static void _get_metrics_kern(FT_Face face, const rt_uint16_t *text_short, struct rtgui_rect *rect)
{
rt_uint16_t prev_gidx;
rt_int16_t w;
prev_gidx = 0;
w = 0;
while (*text_short)
{
FT_Error err = 0;
rt_uint16_t index;
index = FT_Get_Char_Index(face, *text_short);
if (prev_gidx && index)
{
FT_Vector delta;
FT_Get_Kerning(face, prev_gidx, index,
FT_KERNING_DEFAULT, &delta);
w += delta.x >> 6;
}
prev_gidx = index;
err = FT_Load_Glyph(face, index,
FT_LOAD_DEFAULT |
FT_LOAD_NO_HINTING |
FT_LOAD_IGNORE_TRANSFORM |
FT_LOAD_NO_AUTOHINT);
if (err == 0)
w += face->glyph->advance.x >> 6;
text_short ++;
}
rect->x1 = 0;
rect->y1 = 0;
rect->x2 = w;
rect->y2 = FT_MulFix(face->bbox.yMax - face->bbox.yMin,
face->size->metrics.y_scale) >> 6;
}
static void ftf_get_metrics_kern(struct rtgui_font *font, const char *text, rtgui_rect_t *rect)
static void ftc_get_metrics(struct rtgui_font *font, const char *text, struct rtgui_rect *rect)
{
int len;
rt_uint16_t *text_short;
struct rtgui_freetype2_font *fft;
struct rtgui_ttf_font *ttf_font;
RT_ASSERT(font != RT_NULL);
RT_ASSERT(rect != RT_NULL);
fft = (struct rtgui_freetype2_font *) font->data;
RT_ASSERT(fft != RT_NULL);
ttf_font = (struct rtgui_ttf_font *) font->data;
RT_ASSERT(ttf_font != RT_NULL);
len = strlen(text);
memset(rect, 0, sizeof(struct rtgui_rect));
@ -367,111 +532,168 @@ static void ftf_get_metrics_kern(struct rtgui_font *font, const char *text, rtgu
/* convert gbk to unicode */
gbk_to_unicode(text_short, text, len);
if (FT_HAS_KERNING(fft->face))
_get_metrics_kern(fft->face, text_short, rect);
else
_get_metrics_nkern(fft->face, text_short, rect);
_get_metrics(ttf_font, text_short, rect);
rtgui_rect_moveto_point(rect, 0, 0);
PINFO(" ftc_get_metrics_kern: %d %d %d %d\n", rect->x1, rect->y1, rect->x2, rect->y2);
/* release unicode buffer */
rtgui_free(text_short);
}
rtgui_font_t *rtgui_freetype_font_create(const char *filename, int bold, int italic, rt_size_t size)
static FT_Error ftc_face_requester(FTC_FaceID faceID, FT_Library lib, FT_Pointer reqData, FT_Face *face)
{
int ret;
struct ttf_face_id *face_id = (struct ttf_face_id *)faceID;
PINFO("ftc_face_requester %s %d\n", face_id->pathname, face_id->face_index);
ret = FT_New_Face(lib, (char *)face_id->pathname, face_id->face_index, face);
if (ret != 0)
{
PERROR("FT_New_Face failed!\n");
return -1;
}
return 0;
}
static struct rtgui_ttf *rtgui_ttf_load(const char *filename)
{
FT_Error err = 0;
struct rtgui_font *font;
struct rtgui_freetype2_font *fft;
struct rtgui_ttf *ttf;
font = (struct rtgui_font *)rtgui_malloc(sizeof(struct rtgui_font)
+ sizeof(struct rtgui_freetype2_font));
rt_memset(font, 0, sizeof(struct rtgui_font) + sizeof(struct rtgui_freetype2_font));
if (!font)
ttf = (struct rtgui_ttf *)rtgui_malloc(sizeof(struct rtgui_ttf));
if (!ttf)
{
PERROR("failed to allocate structs\n");
PERROR("rtgui_ttf_load rtgui_malloc failed!\n");
return RT_NULL;
}
fft = (struct rtgui_freetype2_font *)(font + 1);
font->data = fft;
/* face_id init */
ttf->face_id.pathname = rt_strdup(filename);
ttf->face_id.face_index = 0;
err = FT_Init_FreeType(&fft->library);
err = FT_Init_FreeType(&ttf->library);
if (err)
{
PERROR("failed to Init FreeType: %d\n", err);
PERROR("FT_Init_FreeType failed err: %d\n", err);
goto _err_done_malloc;
}
err = FT_New_Face(fft->library, filename, 0, &fft->face);
if (err)
err = FTC_Manager_New(ttf->library, 0, 0, 0, ftc_face_requester, 0, &ttf->manager);
if (err != 0)
{
PERROR("failed to New Face: %d\n", err);
PERROR("FTC_Manager_New failed!\n");
goto _err_done_init;
}
err = FT_Select_Charmap(fft->face, FT_ENCODING_UNICODE);
if (err)
{
err = FT_Select_Charmap(fft->face, FT_ENCODING_ADOBE_LATIN_1);
}
err = FT_Set_Pixel_Sizes(fft->face, 0, size);
err = FTC_CMapCache_New(ttf->manager, &ttf->cmap_cache);
if (err != 0)
{
PERROR("failed to set Pixel Size: %d\n", err);
goto _err_done_face;
PERROR("FTC_CMapCache_New failed!\n");
goto _err_done_manager;
}
fft->bold = bold;
fft->italic = italic;
err = FTC_SBitCache_New(ttf->manager, &ttf->sbit_cache);
if (err != 0)
{
PERROR("FTC_SBitCache_New failed!\n");
goto _err_done_manager;
}
PINFO("fonfile:%s\n", filename);
PINFO("font family_name:%s\n", fft->face->family_name);
PINFO("font style_name:%s\n", fft->face->style_name);
PINFO("%s kerneling\n", FT_HAS_KERNING(fft->face) ? "has" : "not has");
ttf->refer_count = 1;
rtgui_ttf_system_add_ttf(ttf);
return ttf;
_err_done_manager:
FTC_Manager_Done(ttf->manager);
_err_done_init:
FT_Done_FreeType(ttf->library);
_err_done_malloc:
rt_free((void *)ttf->face_id.pathname);
rtgui_free(ttf);
return RT_NULL;
}
RTM_EXPORT(rtgui_ttf_load);
rtgui_font_t *rtgui_freetype_font_create(const char *filename, rt_size_t size)
{
struct rtgui_font *font;
struct rtgui_ttf_font *ttf_font;
struct rtgui_ttf *ttf;
ttf = rtgui_ttf_refer(filename);
if (!ttf)
{
PERROR("rtgui_ttf_refer failed!\n");
ttf = rtgui_ttf_load(filename);
if (!ttf)
{
PERROR("rtgui_ttf_load failed!\n");
return RT_NULL;
}
}
font = (struct rtgui_font *)rtgui_malloc(sizeof(struct rtgui_font) + sizeof(struct rtgui_ttf_font));
if (!font)
{
PERROR("rtgui_ttf_load rtgui_malloc failed!\n");
return RT_NULL;
}
ttf_font = (struct rtgui_ttf_font *)(font + 1);
font->data = ttf_font;
ttf_font->ttf = ttf;
/* image_type_rec init */
ttf_font->image_type_rec.face_id = &ttf_font->ttf->face_id;
ttf_font->image_type_rec.width = size;
ttf_font->image_type_rec.height = size;
ttf_font->image_type_rec.flags = FT_LOAD_RENDER | FT_LOAD_NO_HINTING;
/* set user data */
font->family = rt_strdup(fft->face->family_name);
font->height = (rt_uint16_t)size;
font->family = (char *)(ttf_font->ttf->face_id.pathname);
font->height = (rt_uint16_t)ttf_font->image_type_rec.height;
font->refer_count = 1;
font->engine = &ftf_engine;
font->engine = &ftc_engine;
/* add to system */
rtgui_font_system_add_font(font);
return font;
_err_done_face:
FT_Done_Face(fft->face);
_err_done_init:
FT_Done_FreeType(fft->library);
_err_done_malloc:
rtgui_free(font);
return RT_NULL;
}
RTM_EXPORT(rtgui_freetype_font_create);
void rtgui_freetype_font_destroy(rtgui_font_t *font)
{
struct rtgui_freetype2_font *fft;
struct rtgui_ttf_font *ttf_font;
RT_ASSERT(font != RT_NULL);
fft = (struct rtgui_freetype2_font *) font->data;
RT_ASSERT(fft != RT_NULL);
ttf_font = (struct rtgui_ttf_font *) font->data;
RT_ASSERT(ttf_font != RT_NULL);
rtgui_font_system_remove_font(font);
FT_Done_Face(fft->face);
FT_Done_FreeType(fft->library);
rtgui_ttf_derefer(ttf_font->ttf);
if (ttf_font->ttf->refer_count == 0)
{
FTC_Manager_Done(ttf_font->ttf->manager);
FT_Done_FreeType(ttf_font->ttf->library);
rt_free(font->family);
}
rtgui_free(font);
}
RTM_EXPORT(rtgui_freetype_font_destroy);
#ifdef RT_USING_FINSH
#include <finsh.h>
FINSH_FUNCTION_EXPORT_ALIAS(rtgui_freetype_font_create, ftc, "create freetype font: name, bold, italic, size")
FINSH_FUNCTION_EXPORT_ALIAS(rtgui_freetype_font_destroy, ftd, "destroy freetype font")
FINSH_FUNCTION_EXPORT_ALIAS(rtgui_freetype_font_create, ffc, "create freetype font: name, size")
#endif
#endif

View File

@ -1,4 +1,26 @@
/*
* File : font_hz_bmp.c
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2010-09-15 Bernard first version
*/
#include <rtgui/dc.h>
#include <rtgui/font.h>

View File

@ -1,3 +1,26 @@
/*
* File : font_hz_file.c
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2010-09-15 Bernard first version
*/
/*
* Cached HZ font engine
*/

View File

@ -1,3 +1,26 @@
/*
* File : hz12font.c
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2010-09-15 Bernard first version
*/
#include <rtgui/font.h>
#if defined(RTGUI_USING_FONT12) && defined(RTGUI_USING_FONTHZ)

View File

@ -1,3 +1,26 @@
/*
* File : hz16font.c
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2010-09-15 Bernard first version
*/
#include <rtgui/font.h>
#if defined(RTGUI_USING_FONT16) && defined(RTGUI_USING_FONTHZ)

View File

@ -1,11 +1,21 @@
/*
* File : image.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, 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
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
@ -18,6 +28,7 @@
#include <rtgui/image_hdc.h>
#include <rtgui/rtgui_system.h>
#include <rtgui/image_container.h>
#include <string.h>
#ifdef _WIN32
@ -25,17 +36,18 @@
#endif
#ifdef RTGUI_IMAGE_XPM
#include <rtgui/image_xpm.h>
extern void rtgui_image_xpm_init(void);
#endif
#ifdef RTGUI_IMAGE_BMP
#include <rtgui/image_bmp.h>
#endif
#if (defined(RTGUI_IMAGE_JPEG) || defined(RTGUI_IMAGE_TJPGD))
#include <rtgui/image_jpeg.h>
extern void rtgui_image_jpeg_init(void);
#endif
#if defined(RTGUI_IMAGE_PNG) || defined(RTGUI_IMAGE_LODEPNG)
#include <rtgui/image_png.h>
extern void rtgui_image_png_init(void);
#endif
static rtgui_list_t _rtgui_system_image_list = {RT_NULL};
@ -61,6 +73,11 @@ void rtgui_system_image_init(void)
#if defined(RTGUI_IMAGE_PNG) || defined(RTGUI_IMAGE_LODEPNG)
rtgui_image_png_init();
#endif
#ifdef RTGUI_IMAGE_CONTAINER
/* initialize image container */
rtgui_system_image_container_init();
#endif
}
static struct rtgui_image_engine *rtgui_image_get_engine(const char *type)

View File

@ -1,4 +1,22 @@
/*
* File : image_bmp.c
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2012-01-24 onelife Reimplement to improve efficiency and add
@ -6,7 +24,7 @@
* provides scaledown function.
*/
#include <rtthread.h>
#include <rtgui/dc_hw.h>
#include <rtgui/dc.h>
#include <rtgui/image.h>
#include <rtgui/rtgui_system.h>
#include <rtgui/image_bmp.h>

View File

@ -0,0 +1,440 @@
/*
* File : image_container.c
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2010-09-15 Bernard first version
*/
#include <rtgui/rtgui_system.h>
#include <rtgui/image_container.h>
/*
* ImageContainer is a Image pool to manage image resource in the system.
*
* All of image in the ImageContainer should be loaded in the memory.
* All of image are identified by image file name.
*
* Applications can use rtgui_image_container_get/put to refer or derefer
* a image resource.
*/
#if defined(RTGUI_IMAGE_CONTAINER) && defined(RTGUI_USING_DFS_FILERW)
typedef unsigned int (*rtgui_hash_func_t)(const void *key);
typedef struct _rtgui_hash_table rtgui_hash_table_t;
typedef rt_bool_t (*rtgui_equal_func_t)(const void *a, const void *b);
typedef void (*rtgui_user_func_t)(const void *value, const void *data);
/*
*Hash tables
*/
rtgui_hash_table_t *hash_table_create(rtgui_hash_func_t hash_func, rtgui_equal_func_t key_equal_func);
void hash_table_destroy(rtgui_hash_table_t *hash_table);
void *hash_table_find(rtgui_hash_table_t *hash_table, const void *key);
void hash_table_insert(rtgui_hash_table_t *hash_table, const void *key, void *value);
rt_bool_t hash_table_remove(rtgui_hash_table_t *hash_table, const void *key);
void hash_table_foreach(rtgui_hash_table_t *hash_table, rtgui_user_func_t user_func, void *data);
unsigned int hash_table_get_size(rtgui_hash_table_t *hash_table);
/* Hash Functions
*/
unsigned int direct_hash(const void *v);
#define HASH_TABLE_MIN_SIZE 11
#define HASH_TABLE_MAX_SIZE 6247
typedef struct _gui_hash_node rtgui_hash_node_t;
struct _gui_hash_node
{
const void *key;
void *value;
rtgui_hash_node_t *next;
};
struct _rtgui_hash_table
{
rt_uint16_t size;
rt_uint16_t nnodes;
rtgui_hash_node_t **nodes;
rtgui_hash_func_t hash_func;
rtgui_equal_func_t key_equal_func;
};
static const unsigned int primes[] =
{
11,
19,
37,
73,
109,
163,
251,
367,
557,
823,
1237,
1861,
2777,
4177,
6247,
};
static const unsigned int nprimes = sizeof(primes) / sizeof(primes[0]);
static void hash_table_resize(rtgui_hash_table_t *hash_table);
static rtgui_hash_node_t **hash_table_find_node(rtgui_hash_table_t *hash_table, const void *key);
static rtgui_hash_node_t *hash_node_create(const void *key, void *value);
static void hash_node_destroy(rtgui_hash_node_t *hash_node);
static void hash_nodes_destroy(rtgui_hash_node_t *hash_node);
static unsigned int primes_closest(unsigned int num);
static void hash_table_needresize(rtgui_hash_table_t *hash_table);
rt_inline unsigned int primes_closest(unsigned int num)
{
unsigned int i;
for (i = 0; i < nprimes; i++)
if (primes[i] > num)
return primes[i];
return primes[nprimes - 1];
}
/* directly hash */
unsigned int direct_hash(const void *v)
{
return (unsigned int)v;
}
rtgui_hash_table_t *hash_table_create(rtgui_hash_func_t hash_func, rtgui_equal_func_t key_equal_func)
{
rtgui_hash_table_t *hash_table;
hash_table = (rtgui_hash_table_t *) rtgui_malloc(sizeof(rtgui_hash_table_t));
if (hash_table != RT_NULL)
{
hash_table->size = HASH_TABLE_MIN_SIZE;
hash_table->nnodes = 0;
hash_table->hash_func = hash_func ? hash_func : direct_hash;
hash_table->key_equal_func = key_equal_func;
hash_table->nodes = (rtgui_hash_node_t **)rtgui_malloc(sizeof(rtgui_hash_node_t *) * hash_table->size);
if (hash_table->nodes == RT_NULL)
{
/* no memory yet */
rtgui_free(hash_table);
return RT_NULL;
}
rt_memset(hash_table->nodes, 0, sizeof(rtgui_hash_node_t *) * hash_table->size);
}
return hash_table;
}
void hash_table_destroy(rtgui_hash_table_t *hash_table)
{
unsigned int i;
RT_ASSERT(hash_table != RT_NULL);
for (i = 0; i < hash_table->size; i++)
hash_nodes_destroy(hash_table->nodes[i]);
rtgui_free(hash_table->nodes);
rtgui_free(hash_table);
}
static rtgui_hash_node_t **hash_table_find_node(rtgui_hash_table_t *hash_table, const void *key)
{
rtgui_hash_node_t **node;
node = &hash_table->nodes [(* hash_table->hash_func)(key) % hash_table->size];
if (hash_table->key_equal_func)
while (*node && !(*hash_table->key_equal_func)((*node)->key, key))
node = &(*node)->next;
else
while (*node && (*node)->key != key)
node = &(*node)->next;
return node;
}
void *hash_table_find(rtgui_hash_table_t *hash_table, const void *key)
{
rtgui_hash_node_t *node;
RT_ASSERT(hash_table != RT_NULL);
RT_ASSERT(key != RT_NULL);
node = *hash_table_find_node(hash_table, key);
if (node) return node->value;
else return RT_NULL;
}
void hash_table_insert(rtgui_hash_table_t *hash_table, const void *key, void *value)
{
rtgui_hash_node_t **node;
if (hash_table == RT_NULL)return;
node = hash_table_find_node(hash_table, key);
if (*node)
{
(*node)->value = value;
}
else
{
*node = hash_node_create(key, value);
hash_table->nnodes++;
hash_table_needresize(hash_table);
}
}
rt_bool_t hash_table_remove(rtgui_hash_table_t *hash_table, const void *key)
{
rtgui_hash_node_t **node, *dest;
if (hash_table == RT_NULL) return RT_FALSE;
node = hash_table_find_node(hash_table, key);
if (*node)
{
rt_enter_critical();
dest = *node;
(*node) = dest->next;
hash_node_destroy(dest);
hash_table->nnodes--;
hash_table_needresize(hash_table);
rt_exit_critical();
return RT_TRUE;
}
return RT_FALSE;
}
void hash_table_foreach(rtgui_hash_table_t *hash_table, rtgui_user_func_t user_func, void *data)
{
rtgui_hash_node_t *node;
int i;
RT_ASSERT(hash_table != RT_NULL);
RT_ASSERT(user_func != RT_NULL);
for (i = 0; i < hash_table->size; i++)
for (node = hash_table->nodes[i]; node; node = node->next)
(* user_func)(node->value, data);
}
unsigned int hash_table_get_size(rtgui_hash_table_t *hash_table)
{
if (hash_table == NULL) return 0;
return hash_table->nnodes;
}
static void hash_table_needresize(rtgui_hash_table_t *hash_table)
{
if ((hash_table->size >= 3 * hash_table->nnodes && hash_table->size > HASH_TABLE_MIN_SIZE) ||
(3 * hash_table->size <= hash_table->nnodes && hash_table->size < HASH_TABLE_MAX_SIZE))
hash_table_resize(hash_table);
}
static void hash_table_resize(rtgui_hash_table_t *hash_table)
{
rtgui_hash_node_t **new_nodes;
rtgui_hash_node_t *node;
rtgui_hash_node_t *next;
unsigned int hash_val;
int new_size;
int i;
i = primes_closest(hash_table->nnodes);
new_size = i > HASH_TABLE_MAX_SIZE ? HASH_TABLE_MAX_SIZE : i < HASH_TABLE_MIN_SIZE ? HASH_TABLE_MIN_SIZE : i ;
new_nodes = (rtgui_hash_node_t **)rtgui_malloc(sizeof(rtgui_hash_node_t *) * new_size);
if (new_nodes == RT_NULL) return; /* no memory yet */
rt_memset(new_nodes, 0, sizeof(rtgui_hash_node_t *) * new_size);
for (i = 0; i < hash_table->size; i++)
{
for (node = hash_table->nodes[i]; node; node = next)
{
next = node->next;
hash_val = (* hash_table->hash_func)(node->key) % new_size;
node->next = new_nodes[hash_val];
new_nodes[hash_val] = node;
}
}
rtgui_free(hash_table->nodes);
hash_table->nodes = new_nodes;
hash_table->size = new_size;
}
static rtgui_hash_node_t *hash_node_create(const void *key, void *value)
{
rtgui_hash_node_t *hash_node;
hash_node = (rtgui_hash_node_t *) rtgui_malloc(sizeof(rtgui_hash_node_t));
if (hash_node != RT_NULL)
{
/* set value and key */
hash_node->key = key;
hash_node->value = value;;
hash_node->next = RT_NULL;
}
return hash_node;
}
static void hash_node_destroy(rtgui_hash_node_t *hash_node)
{
rtgui_free(hash_node);
}
static void hash_nodes_destroy(rtgui_hash_node_t *hash_node)
{
if (hash_node)
{
rtgui_hash_node_t *node = hash_node;
rtgui_hash_node_t *temp;
while (node->next)
{
node->key = NULL;
node->value = NULL;
temp = node;
node = node->next;
rtgui_free(temp);
}
node->key = NULL;
node->value = NULL;
rtgui_free(node);
}
}
unsigned int string_hash_func(const void *self)
{
const char *p;
int h = 0, g;
for (p = self; *p != '\0'; p += 1)
{
h = (h << 4) + *p;
g = h;
if (g & 0xf0000000)
{
h = h ^ (g >> 24);
h = h ^ g;
}
}
return h ;
}
rt_bool_t string_equal_func(const void *a, const void *b)
{
const char *str1, *str2;
str1 = (const char *)a;
str2 = (const char *)b;
if (strcmp(str1, str2) == 0) return RT_TRUE;
return RT_FALSE;
}
static rtgui_hash_table_t *image_hash_table;
static struct rt_mutex _image_hash_lock;
void rtgui_system_image_container_init(void)
{
rt_mutex_init(&_image_hash_lock, "image", RT_IPC_FLAG_FIFO);
/* create image hash table */
image_hash_table = hash_table_create(string_hash_func, string_equal_func);
RT_ASSERT(image_hash_table != RT_NULL);
}
rtgui_image_item_t *rtgui_image_container_get(const char *filename)
{
struct rtgui_image_item *item = RT_NULL;
if (rt_mutex_take(&_image_hash_lock, RT_WAITING_FOREVER) == RT_EOK)
{
item = hash_table_find(image_hash_table, filename);
if (item == RT_NULL)
{
item = (struct rtgui_image_item *) rtgui_malloc(sizeof(struct rtgui_image_item));
if (item == RT_NULL) return RT_NULL;
/* create a image object */
item->image = rtgui_image_create(filename, RT_TRUE);
if (item->image == RT_NULL)
{
rtgui_free(item);
return RT_NULL; /* create image failed */
}
item->refcount = 1;
item->filename = rt_strdup(filename);
hash_table_insert(image_hash_table, item->filename, item);
}
else
{
item->refcount ++; /* increase refcount */
}
rt_mutex_release(&_image_hash_lock);
}
return item;
}
RTM_EXPORT(rtgui_image_container_get);
void rtgui_image_container_put(rtgui_image_item_t *item)
{
rt_mutex_take(&_image_hash_lock, RT_WAITING_FOREVER);
item->refcount --;
if (item->refcount == 0)
{
/* remove item from container */
hash_table_remove(image_hash_table, item->filename);
/* destroy image and image item */
rt_free(item->filename);
rtgui_image_destroy(item->image);
rtgui_free(item);
}
rt_mutex_release(&_image_hash_lock);
}
RTM_EXPORT(rtgui_image_container_put);
#endif

View File

@ -1,5 +1,28 @@
/*
* File : image_hdc.c
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2010-09-15 Bernard first version
*/
#include <rtthread.h>
#include <rtgui/dc_hw.h>
#include <rtgui/dc.h>
#include <rtgui/image.h>
#include <rtgui/rtgui_system.h>
#include <rtgui/image_hdc.h>
@ -9,21 +32,6 @@
extern int fastlz_decompress(const void *input, int length, void *output, int maxout);
struct rtgui_image_hdc
{
rt_bool_t is_loaded;
/* hdc image information */
rt_uint16_t byte_per_pixel;
rt_uint16_t pitch;
rt_uint8_t pixel_format;
rt_size_t pixel_offset;
rt_uint8_t *pixels;
struct rtgui_filerw *filerw;
};
static rt_bool_t rtgui_image_hdc_check(struct rtgui_filerw *file);
static rt_bool_t rtgui_image_hdc_load(struct rtgui_image *image, struct rtgui_filerw *file, rt_bool_t load);
static void rtgui_image_hdc_unload(struct rtgui_image *image);
@ -257,112 +265,17 @@ static void rtgui_image_hdc_blit(struct rtgui_image *image,
if (hdc->pixels != RT_NULL)
{
rt_uint8_t *ptr;
/* get pixel pointer */
ptr = hdc->pixels + hdc->pitch * yoff + hdc->byte_per_pixel * xoff;
if (hdc->pixel_format == rtgui_dc_get_pixel_format(dc) &&
hdc->pixel_format != RTGRAPHIC_PIXEL_FORMAT_ARGB888)
{
for (y = 0; y < h; y ++)
{
dc->engine->blit_line(dc,
dst_rect->x1,
dst_rect->x1 + w,
dst_rect->y1 + y,
ptr);
ptr += hdc->pitch;
}
}
else if (dc->type == RTGUI_DC_CLIENT)
{
const struct rtgui_graphic_driver *hw_driver;
struct rtgui_widget *owner = RTGUI_CONTAINER_OF(dc, struct rtgui_widget, dc_type);
hw_driver = rtgui_graphic_driver_get_default();
if (hdc->pixel_format == RTGRAPHIC_PIXEL_FORMAT_ARGB888)
{
rt_uint8_t alpha;
for (y = 0; y < h; y ++)
{
int x;
rtgui_color_t *pixel = (rtgui_color_t *)(hdc->pixels + hdc->pitch * (yoff + y) + hdc->byte_per_pixel * xoff);
for (x = 0; x < w; x ++)
{
alpha = RTGUI_RGB_A(*pixel);
if (alpha == 0) { }
if (alpha == 0xff)
{
rtgui_dc_draw_color_point(dc, dst_rect->x1 + x, dst_rect->y1 + y, *pixel);
}
else
{
/* draw an alpha blending point */
if (hw_driver->framebuffer != RT_NULL)
rtgui_dc_blend_point(dc, dst_rect->x1 + x, dst_rect->y1 + y, RTGUI_BLENDMODE_BLEND,
RTGUI_RGB_R(*pixel), RTGUI_RGB_G(*pixel), RTGUI_RGB_B(*pixel), RTGUI_RGB_A(*pixel));
}
pixel ++;
}
}
}
}
else
{
struct rtgui_blit_info info;
info.a = 0;
/* initialize source blit information */
info.src = ptr;
info.src_h = h;
info.src_w = w;
struct rtgui_image_info info;
struct rtgui_rect dest = *dst_rect;
info.a = 255;
info.pixels = hdc->pixels + hdc->pitch * yoff + hdc->byte_per_pixel * xoff;
info.src_fmt = hdc->pixel_format;
info.src_pitch = hdc->pitch;
info.src_skip = hdc->pitch - w * rtgui_color_get_bpp(hdc->pixel_format);
/* initialize destination blit information */
if (dc->type == RTGUI_DC_BUFFER)
{
struct rtgui_dc_buffer *buffer;
buffer = (struct rtgui_dc_buffer *)dc;
dest.x2 = dst_rect->x1 + w;
dest.y2 = dst_rect->y1 + h;
info.dst = rtgui_dc_buffer_get_pixel(RTGUI_DC(buffer)) + dst_rect->y1 * buffer->pitch +
dst_rect->x1 * rtgui_color_get_bpp(buffer->pixel_format);
info.dst_h = h;
info.dst_w = w;
info.dst_fmt = buffer->pixel_format;
info.dst_pitch = buffer->pitch;
info.dst_skip = info.dst_pitch - info.dst_w * rtgui_color_get_bpp(buffer->pixel_format);
}
else if (dc->type == RTGUI_DC_HW)
{
struct rtgui_widget *owner;
struct rtgui_rect r;
struct rtgui_dc_hw *ddc = (struct rtgui_dc_hw *)dc;
owner = ((struct rtgui_dc_hw *)dc)->owner;
rtgui_graphic_driver_get_rect(RT_NULL, &r);
/* blit destination */
info.dst = (rt_uint8_t *)ddc->hw_driver->framebuffer;
info.dst = info.dst + (owner->extent.y1 + dst_rect->y1) * ddc->hw_driver->pitch +
(owner->extent.x1 + dst_rect->x1) * rtgui_color_get_bpp(ddc->hw_driver->pixel_format);
info.dst_fmt = ddc->hw_driver->pixel_format;
info.dst_h = h;
info.dst_w = w;
info.dst_pitch = ddc->hw_driver->pitch;
info.dst_skip = info.dst_pitch - info.dst_w * rtgui_color_get_bpp(ddc->hw_driver->pixel_format);
}
rtgui_blit(&info);
}
rtgui_image_info_blit(&info, dc, &dest);
}
else
{

View File

@ -1,6 +1,25 @@
/*
* File : image_jpg.c
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2010-09-15 Bernard first version
* 2012-01-24 onelife add TJpgDec (Tiny JPEG Decompressor) support
*/
#include <rtthread.h>
@ -13,7 +32,6 @@
#include <rtgui/rtgui_system.h>
#include <rtgui/filerw.h>
#include <rtgui/image_jpeg.h>
#include <rtgui/blit.h>
#ifdef RTGUI_USING_DFS_FILERW

View File

@ -1,3 +1,27 @@
/*
* File : image_png.c
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2010-09-15 Bernard first version
*/
#include <rtthread.h>
#include <rtgui/rtgui_system.h>
#include <rtgui/blit.h>
@ -5,7 +29,6 @@
#ifdef RTGUI_IMAGE_PNG
#include "png.h"
#include <rtgui/image_png.h>
#define PNG_MAGIC_LEN 8
@ -518,7 +541,8 @@ static void rtgui_image_png_unload(struct rtgui_image *image)
pixels = (rt_uint8_t*) image->data;
/* release data */
rtgui_free(pixels);
//rtgui_free(pixels);
free(pixels);
}
}
@ -541,10 +565,18 @@ static void rtgui_image_png_blit(struct rtgui_image *image, struct rtgui_dc *dc,
h = _UI_MIN(image->h, rtgui_rect_height(*rect));
/* border checking */
if (rect->x1 < 0) { x = -rect->x1; w += rect->x1; }
if (rect->x1 < 0)
{
x = -rect->x1;
w += rect->x1;
}
else x = 0;
if (rect->y1 < 0) { y = -rect->y1; h += rect->y1; }
if (rect->y1 < 0)
{
y = -rect->y1;
h += rect->y1;
}
else y = 0;
if (w < 0 || h < 0) return; /* no drawing */
@ -561,7 +593,8 @@ static void rtgui_image_png_blit(struct rtgui_image *image, struct rtgui_dc *dc,
{
/* get owner and calculate dx,dy */
owner = RTGUI_CONTAINER_OF(dc, struct rtgui_widget, dc_type);
dx = owner->extent.x1; dy = owner->extent.y1;
dx = owner->extent.x1;
dy = owner->extent.y1;
}
else
{

View File

@ -1,11 +1,21 @@
/*
* File : image_xpm.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, 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
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
@ -15,7 +25,6 @@
#include <string.h>
#include <rtgui/filerw.h>
#include <rtgui/image_xpm.h>
#include <rtgui/rtgui_system.h>
#ifdef RTGUI_IMAGE_XPM

View File

@ -1,3 +1,26 @@
/*
* File : matrix.c
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2009-10-16 Grissiom first version
*/
#include <rtgui/rtgui.h>
#include <rtgui/matrix.h>
@ -91,7 +114,8 @@ int rtgui_matrix_inverse(const struct rtgui_matrix *mm, struct rtgui_matrix *mo)
/* @dd is the degree range in 0~512 */
rt_inline int icost(int dd)
{
static const short t[COS_TABLE_SZ] = {
static const short t[COS_TABLE_SZ] =
{
2048, 2048, 2047, 2047, 2046, 2044, 2042, 2040, 2038, 2036, 2033, 2029, 2026,
2022, 2018, 2013, 2009, 2004, 1998, 1993, 1987, 1980, 1974, 1967, 1960, 1952,
1945, 1937, 1928, 1920, 1911, 1902, 1892, 1882, 1872, 1862, 1851, 1840, 1829,

View File

@ -1,11 +1,21 @@
/*
* File : mouse.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, 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
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes

View File

@ -1,11 +1,21 @@
/*
* File : mouse.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, 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
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes

View File

@ -1,11 +1,21 @@
/*
* File : region.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, 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
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
@ -2017,113 +2027,6 @@ rtgui_rect_t *rtgui_region_extents(rtgui_region_t *region)
return(&region->extents);
}
#define ExchangeSpans(a, b) \
{ \
rtgui_point_t tpt; \
int tw; \
\
tpt = spans[a]; spans[a] = spans[b]; spans[b] = tpt; \
tw = widths[a]; widths[a] = widths[b]; widths[b] = tw; \
}
/* ||| I should apply the merge sort code to rectangle sorting above, and see
if mapping time can be improved. But right now I've been at work 12 hours,
so forget it.
*/
static void QuickSortSpans(
rtgui_point_t spans[],
int widths[],
int numSpans)
{
int y;
int i, j, m;
rtgui_point_t *r;
/* Always called with numSpans > 1 */
/* Sorts only by y, doesn't bother to sort by x */
do
{
if (numSpans < 9)
{
/* Do insertion sort */
int yprev;
yprev = spans[0].y;
i = 1;
do
{
/* while i != numSpans */
y = spans[i].y;
if (yprev > y)
{
/* spans[i] is out of order. Move into proper location. */
rtgui_point_t tpt;
int tw, k;
for (j = 0; y >= spans[j].y; j++)
{}
tpt = spans[i];
tw = widths[i];
for (k = i; k != j; k--)
{
spans[k] = spans[k - 1];
widths[k] = widths[k - 1];
}
spans[j] = tpt;
widths[j] = tw;
y = spans[i].y;
} /* if out of order */
yprev = y;
i++;
}
while (i != numSpans);
return;
}
/* Choose partition element, stick in location 0 */
m = numSpans / 2;
if (spans[m].y > spans[0].y) ExchangeSpans(m, 0);
if (spans[m].y > spans[numSpans - 1].y) ExchangeSpans(m, numSpans - 1);
if (spans[m].y > spans[0].y) ExchangeSpans(m, 0);
y = spans[0].y;
/* Partition array */
i = 0;
j = numSpans;
do
{
r = &(spans[i]);
do
{
r++;
i++;
}
while (i != numSpans && r->y < y);
r = &(spans[j]);
do
{
r--;
j--;
}
while (y < r->y);
if (i < j)
ExchangeSpans(i, j);
}
while (i < j);
/* Move partition element back to middle */
ExchangeSpans(0, j);
/* Recurse */
if (numSpans - j - 1 > 1)
QuickSortSpans(&spans[j + 1], &widths[j + 1], numSpans - j - 1);
numSpans = j;
}
while (numSpans > 1);
}
#define RTGUI_REGION_TRACE
#ifdef RTGUI_REGION_TRACE
@ -2207,6 +2110,21 @@ void rtgui_rect_moveto(rtgui_rect_t *rect, int x, int y)
}
RTM_EXPORT(rtgui_rect_moveto);
void rtgui_rect_moveto_point(rtgui_rect_t *rect, int x, int y)
{
int mx, my;
mx = x - rect->x1;
my = y - rect->y1;
rect->x1 += mx;
rect->x2 += mx;
rect->y1 += my;
rect->y2 += my;
}
RTM_EXPORT(rtgui_rect_moveto_point);
void rtgui_rect_moveto_align(const rtgui_rect_t *rect, rtgui_rect_t *to, int align)
{
int dw, dh;
@ -2275,6 +2193,22 @@ void rtgui_rect_intersect(rtgui_rect_t *src, rtgui_rect_t *dest)
}
RTM_EXPORT(rtgui_rect_intersect);
/* union src rect into dest rect */
void rtgui_rect_union(rtgui_rect_t *src, rtgui_rect_t *dest)
{
if (rtgui_rect_is_empty(dest))
{
*dest = *src;
return ;
}
if (dest->x1 > src->x1) dest->x1 = src->x1;
if (dest->y1 > src->y1) dest->y1 = src->y1;
if (dest->x2 < src->x2) dest->x2 = src->x2;
if (dest->y2 < src->y2) dest->y2 = src->y2;
}
RTM_EXPORT(rtgui_rect_union);
int rtgui_rect_contains_point(const rtgui_rect_t *rect, int x, int y)
{
if (INBOX(rect, x, y)) return RT_EOK;
@ -2335,8 +2269,10 @@ rtgui_rect_t *rtgui_rect_set(rtgui_rect_t *rect, int x, int y, int w, int h)
{
RT_ASSERT(rect != RT_NULL);
rect->x1 = x; rect->y1 = y;
rect->x2 = x + w; rect->y2 = y + h;
rect->x1 = x;
rect->y1 = y;
rect->x2 = x + w;
rect->y2 = y + h;
return rect;
}

View File

@ -1,11 +1,21 @@
/*
* File : rtgui_app.c
* This file is part of RTGUI in RT-Thread RTOS
* COPYRIGHT (C) 2012, RT-Thread Development Team
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, 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
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes

View File

@ -1,11 +1,21 @@
/*
* File : driver.c
* This file is part of RTGUI in RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, 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
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
@ -276,7 +286,7 @@ static void _rgb565_get_pixel(rtgui_color_t *c, int x, int y)
static void _rgb565_draw_hline(rtgui_color_t *c, int x1, int x2, int y)
{
rt_ubase_t index;
int index;
rt_uint16_t pixel;
rt_uint16_t *pixel_ptr;
@ -298,7 +308,7 @@ static void _rgb565_draw_vline(rtgui_color_t *c, int x , int y1, int y2)
struct rtgui_graphic_driver *drv;
rt_uint8_t *dst;
rt_uint16_t pixel;
rt_ubase_t index;
int index;
drv = rtgui_graphic_get_device();
pixel = rtgui_color_to_565(*c);
@ -327,7 +337,7 @@ static void _rgb565p_get_pixel(rtgui_color_t *c, int x, int y)
static void _rgb565p_draw_hline(rtgui_color_t *c, int x1, int x2, int y)
{
rt_ubase_t index;
int index;
rt_uint16_t pixel;
rt_uint16_t *pixel_ptr;
@ -349,7 +359,7 @@ static void _rgb565p_draw_vline(rtgui_color_t *c, int x , int y1, int y2)
struct rtgui_graphic_driver *drv;
rt_uint8_t *dst;
rt_uint16_t pixel;
rt_ubase_t index;
int index;
drv = rtgui_graphic_get_device();
pixel = rtgui_color_to_565p(*c);
@ -361,6 +371,46 @@ static void _rgb565p_draw_vline(rtgui_color_t *c, int x , int y1, int y2)
}
}
static void _argb888_set_pixel(rtgui_color_t *c, int x, int y)
{
*GET_PIXEL(rtgui_graphic_get_device(), x, y, rtgui_color_t) = *c;
}
static void _argb888_get_pixel(rtgui_color_t *c, int x, int y)
{
*c = (rtgui_color_t)*GET_PIXEL(rtgui_graphic_get_device(), x, y, rtgui_color_t);
}
static void _argb888_draw_hline(rtgui_color_t *c, int x1, int x2, int y)
{
int index;
rtgui_color_t *pixel_ptr;
/* get pixel pointer in framebuffer */
pixel_ptr = GET_PIXEL(rtgui_graphic_get_device(), x1, y, rtgui_color_t);
for (index = x1; index < x2; index++)
{
*pixel_ptr = *c;
pixel_ptr++;
}
}
static void _argb888_draw_vline(rtgui_color_t *c, int x, int y1, int y2)
{
struct rtgui_graphic_driver *drv;
rtgui_color_t *dst;
int index;
drv = rtgui_graphic_get_device();
dst = GET_PIXEL(drv, x, y1, rtgui_color_t);
for (index = y1; index < y2; index++)
{
*dst = *c;
dst += drv->width;
}
}
/* draw raw hline */
static void framebuffer_draw_raw_hline(rt_uint8_t *pixels, int x1, int x2, int y)
{
@ -391,6 +441,15 @@ const struct rtgui_graphic_driver_ops _framebuffer_rgb565p_ops =
framebuffer_draw_raw_hline,
};
const struct rtgui_graphic_driver_ops _framebuffer_argb888_ops =
{
_argb888_set_pixel,
_argb888_get_pixel,
_argb888_draw_hline,
_argb888_draw_vline,
framebuffer_draw_raw_hline,
};
#define FRAMEBUFFER (drv->framebuffer)
#define MONO_PIXEL(framebuffer, x, y) \
((rt_uint8_t**)(framebuffer))[y/8][x]
@ -417,8 +476,8 @@ static void _mono_get_pixel(rtgui_color_t *c, int x, int y)
static void _mono_draw_hline(rtgui_color_t *c, int x1, int x2, int y)
{
int index;
struct rtgui_graphic_driver *drv = rtgui_graphic_get_device();
rt_ubase_t index;
if (*c == white)
for (index = x1; index < x2; index ++)
@ -435,7 +494,7 @@ static void _mono_draw_hline(rtgui_color_t *c, int x1, int x2, int y)
static void _mono_draw_vline(rtgui_color_t *c, int x , int y1, int y2)
{
struct rtgui_graphic_driver *drv = rtgui_graphic_get_device();
rt_ubase_t index;
int index;
if (*c == white)
for (index = y1; index < y2; index ++)
@ -453,7 +512,7 @@ static void _mono_draw_vline(rtgui_color_t *c, int x , int y1, int y2)
static void _mono_draw_raw_hline(rt_uint8_t *pixels, int x1, int x2, int y)
{
struct rtgui_graphic_driver *drv = rtgui_graphic_get_device();
rt_ubase_t index;
int index;
for (index = x1; index < x2; index ++)
{
@ -487,6 +546,8 @@ const struct rtgui_graphic_driver_ops *rtgui_framebuffer_get_ops(int pixel_forma
return &_framebuffer_rgb565_ops;
case RTGRAPHIC_PIXEL_FORMAT_RGB565P:
return &_framebuffer_rgb565p_ops;
case RTGRAPHIC_PIXEL_FORMAT_ARGB888:
return &_framebuffer_argb888_ops;
default:
RT_ASSERT(0);
break;

View File

@ -1,11 +1,21 @@
/*
* File : rtgui_object.c
* This file is part of RTGUI in RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, 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
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes

View File

@ -1,11 +1,21 @@
/*
* File : rtgui_system.c
* This file is part of RTGUI in RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, 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
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
@ -22,6 +32,10 @@
#include <rtgui/rtgui_system.h>
#include <rtgui/widgets/window.h>
#ifdef RTGUI_USING_TTF
#include <rtgui/font_freetype.h>
#endif
#ifdef _WIN32_NATIVE
#define RTGUI_MEM_TRACE
#endif
@ -60,6 +74,10 @@ int rtgui_system_server_init(void)
rtgui_font_set_defaut(&rtgui_font_asc12);
#endif
#ifdef RTGUI_USING_TTF
rtgui_ttf_system_init();
#endif
return 0;
}
INIT_APP_EXPORT(rtgui_system_server_init);

View File

@ -1,11 +1,21 @@
/*
* File : server.c
* This file is part of RTGUI in RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, 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
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
@ -391,12 +401,21 @@ static void rtgui_server_entry(void *parameter)
rtgui_server_app = RT_NULL;
}
void rtgui_server_post_event(struct rtgui_event *event, rt_size_t size)
rt_err_t rtgui_server_post_event(struct rtgui_event *event, rt_size_t size)
{
rt_err_t result;
if (rtgui_server_app != RT_NULL)
rtgui_send(rtgui_server_app, event, size);
{
result = rtgui_send(rtgui_server_app, event, size);
}
else
{
rt_kprintf("post when server is not running\n");
result = -RT_ENOSYS;
}
return result;
}
rt_err_t rtgui_server_post_event_sync(struct rtgui_event *event, rt_size_t size)

View File

@ -1,11 +1,21 @@
/*
* File : title.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, 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
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
@ -75,7 +85,8 @@ rt_bool_t rtgui_wintile_event_handler(struct rtgui_object *obj, rtgui_event_t *e
rtgui_theme_draw_win(wint);
return RT_FALSE;
case RTGUI_EVENT_MOUSE_BUTTON: {
case RTGUI_EVENT_MOUSE_BUTTON:
{
struct rtgui_event_mouse *emou = (struct rtgui_event_mouse *)eve;
if (win->style & RTGUI_WIN_STYLE_CLOSEBOX)

View File

@ -1,11 +1,21 @@
/*
* File : topwin.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, 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
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
@ -1004,7 +1014,8 @@ rt_err_t rtgui_topwin_modal_enter(struct rtgui_event_win_modal_enter *event)
/* modal window should be on top already */
RT_ASSERT(get_topwin_from_list(parent_top->child_list.next) == topwin);
do {
do
{
rt_list_foreach(node, &parent_top->child_list, next)
{
get_topwin_from_list(node)->flag |= WINTITLE_MODALED;

View File

@ -1,11 +1,21 @@
/*
* File : topwin.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, 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
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes

View File

@ -1,7 +1,7 @@
/*
* File : widget.c
* This file is part of RT-Thread GUI
* COPYRIGHT (C) 2006 - 2013, RT-Thread Development Team
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -24,14 +24,12 @@
* 2013-10-07 Bernard remove the win_check in update_clip.
*/
#include <rtgui/dc_client.h>
#include <string.h>
#include <rtgui/dc.h>
#include <rtgui/rtgui_app.h>
#include <rtgui/widgets/widget.h>
#include <rtgui/widgets/window.h>
#include <rtgui/widgets/container.h>
#ifdef RTGUI_USING_NOTEBOOK
#include <rtgui/widgets/notebook.h>
#endif
static void _rtgui_widget_constructor(rtgui_widget_t *widget)
{
@ -52,8 +50,8 @@ static void _rtgui_widget_constructor(rtgui_widget_t *widget)
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;
memset(&(widget->extent), 0x0, sizeof(widget->extent));
memset(&(widget->extent_visiable), 0x0, sizeof(widget->extent_visiable));
widget->min_width = widget->min_height = 0;
rtgui_region_init_with_extents(&widget->clip, &widget->extent);
@ -64,7 +62,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_paint = RT_NULL;
/* set default event handler */
rtgui_object_set_event_handler(RTGUI_OBJECT(widget), rtgui_widget_event_handler);
@ -72,9 +69,6 @@ static void _rtgui_widget_constructor(rtgui_widget_t *widget)
/* init user data private to 0 */
widget->user_data = 0;
/* init clip information */
rtgui_region_init(&(widget->clip));
/* init hardware dc */
rtgui_dc_client_init(widget);
}
@ -127,6 +121,8 @@ void rtgui_widget_set_rect(rtgui_widget_t *widget, const rtgui_rect_t *rect)
/* update extent rectangle */
widget->extent = *rect;
/* set the visiable extern as extern */
widget->extent_visiable = *rect;
if (RTGUI_IS_CONTAINER(widget))
{
/* re-do layout */
@ -166,7 +162,6 @@ void rtgui_widget_set_rect(rtgui_widget_t *widget, const rtgui_rect_t *rect)
rtgui_widget_move_to_logic(widget, delta_x, delta_y);
}
}
RTM_EXPORT(rtgui_widget_set_rect);
@ -226,9 +221,18 @@ RTM_EXPORT(rtgui_widget_set_minheight);
static void _widget_moveto(struct rtgui_widget* widget, int dx, int dy)
{
struct rtgui_list_node *node;
rtgui_widget_t *child;
rtgui_widget_t *child, *parent;
rtgui_rect_moveto(&(widget->extent), dx, dy);
/* handle visiable extent */
widget->extent_visiable = widget->extent;
parent = widget->parent;
/* we should find out the none-transparent parent */
while (parent != RT_NULL && parent->flag & RTGUI_WIDGET_FLAG_TRANSPARENT) parent = parent->parent;
if (widget->parent)
rtgui_rect_intersect(&(widget->parent->extent_visiable), &(widget->extent_visiable));
/* reset clip info */
rtgui_region_init_with_extents(&(widget->clip), &(widget->extent));
@ -260,7 +264,7 @@ void rtgui_widget_move_to_logic(rtgui_widget_t *widget, int dx, int dy)
if (parent != RT_NULL)
{
/* get the parent rect, even if it's a transparent parent. */
rect = parent->clip.extents;
rect = parent->extent_visiable;
}
/* we should find out the none-transparent parent */
@ -270,7 +274,6 @@ void rtgui_widget_move_to_logic(rtgui_widget_t *widget, int dx, int dy)
/* reset clip info */
rtgui_region_init_with_extents(&(widget->clip), &(widget->extent));
rtgui_region_intersect_rect(&(widget->clip), &(widget->clip), &rect);
rtgui_region_intersect_rect(&(widget->clip), &(widget->clip), &(parent->extent));
/* give back the extent */
rtgui_region_union(&(parent->clip), &(parent->clip), &(widget->clip));
@ -344,14 +347,6 @@ void rtgui_widget_set_onunfocus(rtgui_widget_t *widget, rtgui_event_handler_ptr
}
RTM_EXPORT(rtgui_widget_set_onunfocus);
void rtgui_widget_set_onpaint(rtgui_widget_t *widget, rtgui_event_handler_ptr handler)
{
RT_ASSERT(widget != RT_NULL);
widget->on_paint = handler;
}
RTM_EXPORT(rtgui_widget_set_onpaint);
/**
* @brief Focuses the widget. The focused widget is the widget which can receive the keyboard events
* @param widget a widget
@ -511,15 +506,6 @@ rt_bool_t rtgui_widget_onupdate_toplvl(struct rtgui_object *object, struct rtgui
}
RTM_EXPORT(rtgui_widget_onupdate_toplvl);
rt_bool_t rtgui_widget_onpaint(struct rtgui_object *object, struct rtgui_event *event)
{
if (RTGUI_WIDGET(object)->on_paint)
return RTGUI_WIDGET(object)->on_paint(object, event);
else
return RT_FALSE;
}
RTM_EXPORT(rtgui_widget_onpaint);
rt_bool_t rtgui_widget_event_handler(struct rtgui_object *object, rtgui_event_t *event)
{
RTGUI_WIDGET_EVENT_HANDLER_PREPARE;
@ -527,7 +513,7 @@ rt_bool_t rtgui_widget_event_handler(struct rtgui_object *object, rtgui_event_t
switch (event->type)
{
case RTGUI_EVENT_PAINT:
return rtgui_widget_onpaint(object, event);
break;
case RTGUI_EVENT_SHOW:
return rtgui_widget_onshow(object, event);
case RTGUI_EVENT_HIDE:
@ -556,7 +542,11 @@ void rtgui_widget_update_clip(rtgui_widget_t *widget)
return;
parent = widget->parent;
rect = parent->clip.extents;
/* reset visiable extent */
widget->extent_visiable = widget->extent;
rtgui_rect_intersect(&(parent->extent_visiable), &(widget->extent_visiable));
rect = parent->extent_visiable;
/* reset clip to extent */
rtgui_region_reset(&(widget->clip), &(widget->extent));
/* limit widget extent in parent extent */
@ -575,7 +565,7 @@ void rtgui_widget_update_clip(rtgui_widget_t *widget)
/* subtract widget clip in parent clip */
if (!(widget->flag & RTGUI_WIDGET_FLAG_TRANSPARENT) && RTGUI_IS_CONTAINER(parent))
{
rtgui_region_subtract_rect(&(parent->clip), &(parent->clip), &(widget->extent));
rtgui_region_subtract_rect(&(parent->clip), &(parent->clip), &(widget->extent_visiable));
}
}
@ -628,7 +618,6 @@ void rtgui_widget_hide(struct rtgui_widget *widget)
if (RTGUI_WIDGET_IS_HIDE(widget))
return;
RTGUI_WIDGET_HIDE(widget);
if (widget->toplevel != RT_NULL)
{
RTGUI_EVENT_HIDE_INIT(&ehide);
@ -639,6 +628,8 @@ void rtgui_widget_hide(struct rtgui_widget *widget)
&ehide);
}
}
RTGUI_WIDGET_HIDE(widget);
}
RTM_EXPORT(rtgui_widget_hide);
@ -648,7 +639,7 @@ rt_bool_t rtgui_widget_onshow(struct rtgui_object *object, struct rtgui_event *e
if (RTGUI_WIDGET_IS_HIDE(object)) return RT_FALSE;
if (widget->parent != RT_NULL)
if (widget->parent != RT_NULL && !(RTGUI_WIDGET_FLAG(widget) & RTGUI_WIDGET_FLAG_TRANSPARENT))
{
rtgui_widget_clip_parent(widget);
}

View File

@ -1,11 +1,21 @@
/*
* File : window.c
* This file is part of RTGUI in RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* This file is part of RT-Thread GUI Engine
* COPYRIGHT (C) 2006 - 2017, 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
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
@ -557,7 +567,7 @@ static rt_bool_t rtgui_win_ondraw(struct rtgui_win *win)
/* fill area */
rtgui_dc_fill_rect(dc, &rect);
rtgui_widget_onpaint(RTGUI_OBJECT(win), RT_NULL);
/* widget drawing */
/* paint each widget */
RTGUI_EVENT_PAINT_INIT(&event);
@ -565,7 +575,7 @@ static rt_bool_t rtgui_win_ondraw(struct rtgui_win *win)
rtgui_container_dispatch_event(RTGUI_CONTAINER(win),
(rtgui_event_t *)&event);
rtgui_dc_end_drawing(dc);
rtgui_dc_end_drawing(dc, 1);
return RT_FALSE;
}
@ -713,6 +723,9 @@ rt_bool_t rtgui_win_event_handler(struct rtgui_object *object, struct rtgui_even
break;
case RTGUI_EVENT_WIN_UPDATE_END:
break;
case RTGUI_EVENT_CLIP_INFO:
/* update win clip */
rtgui_win_update_clip(win);
@ -740,7 +753,8 @@ rt_bool_t rtgui_win_event_handler(struct rtgui_object *object, struct rtgui_even
}
#endif
case RTGUI_EVENT_MOUSE_BUTTON: {
case RTGUI_EVENT_MOUSE_BUTTON:
{
struct rtgui_event_mouse *emouse = (struct rtgui_event_mouse*)event;
if (rtgui_rect_contains_point(&RTGUI_WIDGET(win)->extent,
@ -974,7 +988,8 @@ struct rtgui_dc *rtgui_win_get_drawing(rtgui_win_t * win)
RTM_EXPORT(rtgui_win_get_drawing);
#endif
static const rt_uint8_t close_byte[14] = {
static const rt_uint8_t close_byte[14] =
{
0x06, 0x18, 0x03, 0x30, 0x01, 0xE0, 0x00,
0xC0, 0x01, 0xE0, 0x03, 0x30, 0x06, 0x18
};
@ -1101,5 +1116,5 @@ void rtgui_theme_draw_win(struct rtgui_wintitle *wint)
}
}
rtgui_dc_end_drawing(dc);
rtgui_dc_end_drawing(dc, 1);
}