mirror of
https://gitee.com/idea4good/GuiLite.git
synced 2025-01-15 17:02:52 +08:00
Add mask color for c_bitmap
This commit is contained in:
parent
3d58ef1c3f
commit
7ebae0b87e
12
README.md
12
README.md
@ -15,14 +15,15 @@
|
||||
- ⚙️希望GuiLite小到足够帮助大家掌握UI工作原理,从而摆脱UI框架的束缚,构建自己独一无二的UI
|
||||
- 👑任何UI框架都不为你我而生,你才是自己真正的主人
|
||||
|
||||
## 新功能:在单片机上运行“波形/粒子”效果 -- HelloWave + HelloParticle
|
||||
![HelloWave](doc/HelloWave.gif) ![HelloParticle](doc/HelloParticle.gif)
|
||||
## 新功能:单片机系列 - “超级玛丽” -- HelloMario + HelloParticle + HelloWave
|
||||
![HelloMario](doc/HelloMario.gif) ![HelloParticle](doc/HelloParticle.gif) ![HelloWave](doc/HelloWave.gif)
|
||||
- 单片机硬件配置:STM32F103ZET6(512K ROM,64K RAM) + 240*320 16位TFT屏
|
||||
- 单片机软件配置:无操作系统 + GuiLite
|
||||
- Hello Wave 仅有[100+行代码](https://gitee.com/idea4good/GuiLiteSamples/blob/master/HelloWave/UIcode/UIcode.cpp),用于向开发者展示:如何使用GuiLite进行“波形”效果的开发。
|
||||
- Hello Mario 仅有[100+行代码](https://gitee.com/idea4good/GuiLiteSamples/blob/master/HelloMario/UIcode/UIcode.cpp),以“超级玛丽”为例,用于向开发者展示:如何使用GuiLite进行多图层的开发。
|
||||
- Hello Particle 仅有[100-行代码](https://gitee.com/idea4good/GuiLiteSamples/blob/master/HelloParticle/UIcode/UIcode.cpp),用于向开发者展示:如何使用GuiLite进行“粒子”效果的开发。
|
||||
- Hello Wave 仅有[100+行代码](https://gitee.com/idea4good/GuiLiteSamples/blob/master/HelloWave/UIcode/UIcode.cpp),用于向开发者展示:如何使用GuiLite进行“波形”效果的开发。
|
||||
- [1分钟“无痛”移植到任意单片机平台?](https://gitee.com/idea4good/GuiLiteSamples/blob/master/HelloWave/README.md#How-to-port-on-any-MCU-)
|
||||
- 该实例亦可支持Windows和Linux平台
|
||||
- 这些实例亦可支持Windows和Linux平台
|
||||
|
||||
## 功能介绍
|
||||
### 卓越的跨平台能力
|
||||
@ -68,10 +69,11 @@ GuiLite只是一个框架,本身并不能生成UI。为了能够展示如何
|
||||
|
||||
| 实例名称 | 支持的平台 | 功能简介 | 编译方法 | 难度 |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| HelloParticle | Windows, Linux, STM32F103, STM32F429 | 粒子效果的应用 | [编译/运行](https://gitee.com/idea4good/GuiLiteSamples/blob/master/HelloParticle/README.md) | ★|
|
||||
| HelloGuiLite | Windows, Linux | 初始化GuiLite,加载资源,布局界面元素,按钮响应 | [编译/运行](https://gitee.com/idea4good/GuiLiteSamples/blob/master/HelloGuiLite/README.md) | ★★|
|
||||
| HelloMario | Windows, Linux, STM32F103, STM32F429 | 多图层的UI系统 | [编译/运行](https://gitee.com/idea4good/GuiLiteSamples/blob/master/HelloMario/README.md) | ★★|
|
||||
| HelloFont | Windows, Linux | 显示多种语言(不限:中、英文) | [编译/运行](https://gitee.com/idea4good/GuiLiteSamples/blob/master/HelloFont/README.md) | ★★|
|
||||
| HelloAnimation | Windows, Linux | 动画的应用 | [编译/运行](https://gitee.com/idea4good/GuiLiteSamples/blob/master/HelloAnimation/README.md) | ★★|
|
||||
| HelloParticle | Windows, Linux, STM32F103, STM32F429 | 粒子效果的应用 | [编译/运行](https://gitee.com/idea4good/GuiLiteSamples/blob/master/HelloParticle/README.md) | ★|
|
||||
| HelloSlide | Windows, Linux | 滑屏界面的应用 | [编译/运行](https://gitee.com/idea4good/GuiLiteSamples/blob/master/HelloSlide/README.md) | ★★★|
|
||||
| HelloWave | Windows, Linux, STM32F103, STM32F429 | 波形控件的应用,及单片机移植办法 | [编译/运行](https://gitee.com/idea4good/GuiLiteSamples/blob/master/HelloWave/README.md) | ★★★|
|
||||
| HostMonitor | iOS, Mac, Android, Windows, Linux | 创建复杂界面,扩展自定义控件,适配全平台 | [编译/运行](https://gitee.com/idea4good/GuiLiteSamples/blob/master/HostMonitor/README.md) | ★★★★|
|
||||
|
@ -1,16 +1,17 @@
|
||||
#ifndef BITMAP_UNIT_H
|
||||
#define BITMAP_UNIT_H
|
||||
|
||||
#define DEFAULT_MASK_COLOR 0xFF080408
|
||||
class c_surface;
|
||||
class c_bitmap
|
||||
{
|
||||
public:
|
||||
static void draw_bitmap(c_surface* surface, int z_order, const BITMAP_INFO *pBitmap, int x, int y);
|
||||
static void draw_bitmap_in_rect(c_surface* surface, int z_order, const BITMAP_INFO *pBitmap, c_rect rect, unsigned int align_type);
|
||||
static void draw_bitmap(c_surface* surface, int z_order, const BITMAP_INFO *pBitmap, int x, int y, unsigned int mask_rgb = DEFAULT_MASK_COLOR);
|
||||
static void draw_bitmap_in_rect(c_surface* surface, int z_order, const BITMAP_INFO *pBitmap, c_rect rect, unsigned int align_type, unsigned int mask_rgb = DEFAULT_MASK_COLOR);
|
||||
private:
|
||||
static void draw_bitmap_565(c_surface* surface, int z_order, int x, int y, int xsize, int ysize, const unsigned char* pPixel);
|
||||
static void draw_bitmap_565(c_surface* surface, int z_order, int x, int y, int xsize, int ysize, const unsigned char* pPixel, unsigned int mask_color);
|
||||
static void get_bitmap_pos(const BITMAP_INFO *pBitmap, c_rect rect, unsigned int align_type, int &x, int &y);
|
||||
static void draw_bitmap_565_in_rect(c_surface* surface, int z_order, int x, int y, int width, int height, int xsize, int ysize, const unsigned char* pPixel);
|
||||
static void draw_bitmap_565_in_rect(c_surface* surface, int z_order, int x, int y, int width, int height, int xsize, int ysize, const unsigned char* pPixel, unsigned int mask_color);
|
||||
|
||||
c_bitmap(){}
|
||||
c_bitmap(const c_bitmap&);
|
||||
|
@ -25,7 +25,7 @@ struct EXTERNAL_GFX_OP
|
||||
|
||||
class c_display;
|
||||
class c_surface {
|
||||
friend class c_display;
|
||||
friend class c_display; friend class c_bitmap;
|
||||
public:
|
||||
virtual void draw_pixel(int x, int y, unsigned int rgb, unsigned int z_order);
|
||||
virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb, unsigned int z_order);
|
||||
|
@ -4,28 +4,21 @@
|
||||
#include "../core_include/bitmap.h"
|
||||
#include "../core_include/surface.h"
|
||||
|
||||
void c_bitmap::draw_bitmap(c_surface* surface, int z_order, const BITMAP_INFO *pBitmap, int x, int y)
|
||||
void c_bitmap::draw_bitmap(c_surface* surface, int z_order, const BITMAP_INFO *pBitmap, int x, int y, unsigned int mask_rgb)
|
||||
{
|
||||
if (0 == pBitmap)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (0 == pBitmap) { return; }
|
||||
draw_bitmap_565(surface, z_order, x, y, pBitmap->XSize, pBitmap->YSize,
|
||||
(unsigned char const *)pBitmap->pData);
|
||||
(unsigned char const *)pBitmap->pData, mask_rgb);
|
||||
}
|
||||
|
||||
void c_bitmap::draw_bitmap_in_rect(c_surface* surface, int z_order, const BITMAP_INFO *pBitmap, c_rect rect, unsigned int align_type)
|
||||
void c_bitmap::draw_bitmap_in_rect(c_surface* surface, int z_order, const BITMAP_INFO *pBitmap, c_rect rect, unsigned int align_type, unsigned int mask_rgb)
|
||||
{
|
||||
if (0 == pBitmap)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (0 == pBitmap) { return; }
|
||||
int x, y;
|
||||
get_bitmap_pos(pBitmap, rect, align_type, x, y);
|
||||
draw_bitmap_565_in_rect(surface, z_order, rect.m_left + x, rect.m_top + y,
|
||||
(rect.m_right - rect.m_left + 1), (rect.m_bottom - rect.m_top + 1),
|
||||
pBitmap->XSize, pBitmap->YSize, (unsigned char const *)pBitmap->pData);
|
||||
pBitmap->XSize, pBitmap->YSize, (unsigned char const *)pBitmap->pData, mask_rgb);
|
||||
}
|
||||
|
||||
void c_bitmap::get_bitmap_pos(const BITMAP_INFO *pBitmap, c_rect rect, unsigned int align_type, int &x, int &y)
|
||||
@ -83,8 +76,15 @@ void c_bitmap::get_bitmap_pos(const BITMAP_INFO *pBitmap, c_rect rect, unsigned
|
||||
}
|
||||
}
|
||||
|
||||
void c_bitmap::draw_bitmap_565(c_surface* surface, int z_order, int x, int y, int xsize, int ysize, const unsigned char* pPixel)
|
||||
void c_bitmap::draw_bitmap_565(c_surface* surface, int z_order, int x, int y, int xsize, int ysize, const unsigned char* pPixel, unsigned int mask_rgb)
|
||||
{
|
||||
unsigned short* lower_fb = NULL;
|
||||
int lower_fb_width = surface->m_width;
|
||||
if (z_order >= Z_ORDER_LEVEL_1)
|
||||
{
|
||||
lower_fb = surface->m_frame_layers[z_order - 1].fb;
|
||||
}
|
||||
unsigned int mask_rgb_16 = GL_RGB_32_to_16(mask_rgb);
|
||||
const unsigned short* pData = (const unsigned short*)pPixel;
|
||||
for (int j = 0; j < ysize; j++)
|
||||
{
|
||||
@ -92,28 +92,51 @@ void c_bitmap::draw_bitmap_565(c_surface* surface, int z_order, int x, int y, in
|
||||
for (int i = 0; i < xsize; i++)
|
||||
{
|
||||
unsigned int rgb = *p++;
|
||||
surface->draw_pixel(x + i, y + j, GL_RGB_16_to_32(rgb), z_order);
|
||||
}
|
||||
pData += xsize;
|
||||
}
|
||||
}
|
||||
|
||||
void c_bitmap::draw_bitmap_565_in_rect(c_surface* surface, int z_order, int x, int y, int width, int height, int xsize, int ysize, const unsigned char* pPixel)
|
||||
{
|
||||
const unsigned short* pData = (const unsigned short*)pPixel;
|
||||
for (int j = 0; j < ysize; j++)
|
||||
{
|
||||
if(j >= height)break;
|
||||
const unsigned short * p = pData;
|
||||
for (int i = 0; i < xsize; i++)
|
||||
{
|
||||
if (i >= width)
|
||||
if (mask_rgb_16 == rgb)
|
||||
{
|
||||
break;
|
||||
if (lower_fb)
|
||||
{//restore lower layer
|
||||
surface->draw_pixel(x + i, y + j, GL_RGB_16_to_32(lower_fb[(y + j) * lower_fb_width + x + i]), z_order);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
surface->draw_pixel(x + i, y + j, GL_RGB_16_to_32(rgb), z_order);
|
||||
}
|
||||
}
|
||||
pData += xsize;
|
||||
}
|
||||
}
|
||||
|
||||
void c_bitmap::draw_bitmap_565_in_rect(c_surface* surface, int z_order, int x, int y, int width, int height, int xsize, int ysize, const unsigned char* pPixel, unsigned int mask_rgb)
|
||||
{
|
||||
unsigned short* lower_fb = NULL;
|
||||
int lower_fb_width = surface->m_width;
|
||||
if (z_order >= Z_ORDER_LEVEL_1)
|
||||
{
|
||||
lower_fb = surface->m_frame_layers[z_order - 1].fb;
|
||||
}
|
||||
unsigned int mask_rgb_16 = GL_RGB_32_to_16(mask_rgb);
|
||||
const unsigned short* pData = (const unsigned short*)pPixel;
|
||||
for (int j = 0; j < ysize; j++)
|
||||
{
|
||||
if (j >= height) { break; }
|
||||
const unsigned short * p = pData;
|
||||
for (int i = 0; i < xsize; i++)
|
||||
{
|
||||
if (i >= width) { break; }
|
||||
unsigned int rgb = *p++;
|
||||
if (mask_rgb_16 == rgb)
|
||||
{
|
||||
if (lower_fb)
|
||||
{//restore lower layer
|
||||
surface->draw_pixel(x + i, y + j, GL_RGB_16_to_32(lower_fb[(y + j) * lower_fb_width + x + i]), z_order);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
surface->draw_pixel(x + i, y + j, GL_RGB_16_to_32(rgb), z_order);
|
||||
}
|
||||
|
||||
unsigned int rgb = *p++;
|
||||
surface->draw_pixel(x + i, y + j, GL_RGB_16_to_32(rgb), z_order);
|
||||
}
|
||||
pData += xsize;
|
||||
}
|
||||
|
@ -380,39 +380,20 @@ int c_surface::set_frame_layer(c_rect& rect, unsigned int z_order)
|
||||
}
|
||||
m_top_zorder = (Z_ORDER_LEVEL)z_order;
|
||||
|
||||
c_rect current_rect = m_frame_layers[z_order].rect;
|
||||
if (!current_rect.IsEmpty())
|
||||
{
|
||||
//Recover the lower layer
|
||||
int src_zorder = (Z_ORDER_LEVEL)(z_order - 1);
|
||||
int display_width = m_display->get_width();
|
||||
int display_height = m_display->get_height();
|
||||
c_rect old_rect = m_frame_layers[z_order].rect;
|
||||
//Recover the lower layer
|
||||
int src_zorder = (Z_ORDER_LEVEL)(z_order - 1);
|
||||
int display_width = m_display->get_width();
|
||||
int display_height = m_display->get_height();
|
||||
|
||||
for (int y = current_rect.m_top; y <= current_rect.m_bottom; y++)
|
||||
for (int y = old_rect.m_top; y <= old_rect.m_bottom; y++)
|
||||
{
|
||||
for (int x = old_rect.m_left; x <= old_rect.m_right; x++)
|
||||
{
|
||||
for (int x = current_rect.m_left; x <= current_rect.m_right; x++)
|
||||
if (!rect.PtInRect(x, y))
|
||||
{
|
||||
if (m_frame_layers[src_zorder].rect.PtInRect(x, y))
|
||||
{
|
||||
unsigned int rgb = ((unsigned short*)(m_frame_layers[src_zorder].fb))[x + y * m_width];
|
||||
if (m_color_bytes == 4)
|
||||
{
|
||||
rgb = GL_RGB_16_to_32(rgb);
|
||||
if (m_fb) { ((unsigned int*)m_fb)[y * m_width + x] = rgb; }
|
||||
if (m_is_active && (x < display_width) && (y < display_height))
|
||||
{
|
||||
((unsigned int*)m_phy_fb)[y * display_width + x] = rgb;
|
||||
}
|
||||
}
|
||||
else if(m_color_bytes == 2)
|
||||
{
|
||||
if (m_fb) { ((unsigned short*)m_fb)[y * m_width + x] = rgb; }
|
||||
if (m_is_active && (x < display_width) && (y < display_height))
|
||||
{
|
||||
((unsigned short*)m_phy_fb)[y * display_width + x] = rgb;
|
||||
}
|
||||
}
|
||||
}
|
||||
unsigned int rgb = ((unsigned short*)(m_frame_layers[src_zorder].fb))[x + y * m_width];
|
||||
draw_pixel_on_fb(x, y, GL_RGB_16_to_32(rgb));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -422,7 +403,6 @@ int c_surface::set_frame_layer(c_rect& rect, unsigned int z_order)
|
||||
{
|
||||
m_top_zorder = (Z_ORDER_LEVEL)(z_order - 1);
|
||||
}
|
||||
*m_phy_write_index = *m_phy_write_index + 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -524,10 +504,6 @@ void c_surface_no_fb::fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned i
|
||||
|
||||
void c_surface_no_fb::draw_pixel_on_fb(int x, int y, unsigned int rgb)
|
||||
{
|
||||
if (x >= m_width || y >= m_height || x < 0 || y < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (m_gfx_op && m_gfx_op->draw_pixel && m_is_active)
|
||||
{
|
||||
m_gfx_op->draw_pixel(x, y, rgb);
|
||||
|
BIN
doc/HelloMario.gif
Normal file
BIN
doc/HelloMario.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 153 KiB |
Loading…
x
Reference in New Issue
Block a user