mirror of
https://github.com/lc-soft/LCUI.git
synced 2026-12-01 16:56:34 +01:00
148 lines
4.6 KiB
C
148 lines
4.6 KiB
C
#include <LCUI.h>
|
|
#include <LCUI/graph.h>
|
|
#include <LCUI/image.h>
|
|
#include <LCUI/painter.h>
|
|
|
|
int test_paint_background_color(void)
|
|
{
|
|
LCUI_Graph canvas;
|
|
LCUI_Color gray = RGB(240, 240, 240);
|
|
LCUI_Color green = RGB(102, 204, 0);
|
|
LCUI_Rect rect = { 200, 100, 400, 300 };
|
|
LCUI_Background bg = { 0 };
|
|
LCUI_PaintContext paint;
|
|
|
|
Graph_Init(&canvas);
|
|
Graph_Create(&canvas, 800, 600);
|
|
Graph_FillRect(&canvas, gray, NULL, FALSE);
|
|
// 设置背景色
|
|
bg.color = green;
|
|
// 创建绘制上下文
|
|
paint = LCUIPainter_Begin(&canvas, &rect);
|
|
// 绘制背景
|
|
Background_Paint(&bg, &rect, paint);
|
|
LCUI_WritePNGFile("test_paint_background_color.png", &canvas);
|
|
LCUIPainter_End(paint);
|
|
Graph_Free(&canvas);
|
|
return 0;
|
|
}
|
|
|
|
int test_paint_background_image(void)
|
|
{
|
|
LCUI_Graph canvas;
|
|
LCUI_Graph image;
|
|
LCUI_Color gray = RGB(240, 240, 240);
|
|
LCUI_Color green = RGB(102, 204, 0);
|
|
LCUI_Rect rect = { 200, 100, 400, 300 };
|
|
LCUI_Background bg = { 0 };
|
|
LCUI_PaintContext paint;
|
|
|
|
Graph_Init(&canvas);
|
|
Graph_Init(&image);
|
|
Graph_Create(&canvas, 800, 600);
|
|
Graph_FillRect(&canvas, gray, NULL, FALSE);
|
|
// 读取背景图片
|
|
if (LCUI_ReadImageFile("test_image_reader.png", &image) != 0) {
|
|
return -1;
|
|
}
|
|
// 设置背景色
|
|
bg.color = green;
|
|
// 设置背景图
|
|
bg.image = ℑ
|
|
bg.size.width = image.width;
|
|
bg.size.height = image.height;
|
|
// 创建绘制上下文
|
|
paint = LCUIPainter_Begin(&canvas, &rect);
|
|
// 绘制背景
|
|
Background_Paint(&bg, &rect, paint);
|
|
LCUI_WritePNGFile("test_paint_background_image.png", &canvas);
|
|
LCUIPainter_End(paint);
|
|
Graph_Free(&image);
|
|
Graph_Free(&canvas);
|
|
return 0;
|
|
}
|
|
|
|
int test_paint_background_image_with_size(void)
|
|
{
|
|
LCUI_Graph canvas;
|
|
LCUI_Graph image;
|
|
LCUI_Color gray = RGB(240, 240, 240);
|
|
LCUI_Color green = RGB(102, 204, 0);
|
|
LCUI_Rect rect = { 200, 100, 400, 300 };
|
|
LCUI_Background bg = { 0 };
|
|
LCUI_PaintContext paint;
|
|
|
|
Graph_Init(&canvas);
|
|
Graph_Init(&image);
|
|
Graph_Create(&canvas, 800, 600);
|
|
Graph_FillRect(&canvas, gray, NULL, FALSE);
|
|
// 读取背景图片
|
|
if (LCUI_ReadImageFile("test_image_reader.png", &image) != 0) {
|
|
return -1;
|
|
}
|
|
// 设置背景色
|
|
bg.color = green;
|
|
// 设置背景图
|
|
bg.image = ℑ
|
|
// 将背景图设置成与背景区域相同的尺寸
|
|
bg.size.width = rect.width;
|
|
bg.size.height = rect.height;
|
|
// 创建绘制上下文
|
|
paint = LCUIPainter_Begin(&canvas, &rect);
|
|
// 绘制背景
|
|
Background_Paint(&bg, &rect, paint);
|
|
LCUI_WritePNGFile("test_paint_background_image_with_size.png", &canvas);
|
|
LCUIPainter_End(paint);
|
|
Graph_Free(&image);
|
|
Graph_Free(&canvas);
|
|
return 0;
|
|
}
|
|
|
|
int test_paint_background_image_with_position(void)
|
|
{
|
|
LCUI_Graph canvas;
|
|
LCUI_Graph image;
|
|
LCUI_Color gray = RGB(240, 240, 240);
|
|
LCUI_Color green = RGB(102, 204, 0);
|
|
LCUI_Rect rect = { 200, 100, 400, 300 };
|
|
LCUI_Background bg = { 0 };
|
|
LCUI_PaintContext paint;
|
|
|
|
Graph_Init(&canvas);
|
|
Graph_Init(&image);
|
|
Graph_Create(&canvas, 800, 600);
|
|
Graph_FillRect(&canvas, gray, NULL, FALSE);
|
|
// 读取背景图片
|
|
if (LCUI_ReadImageFile("test_image_reader.png", &image) != 0) {
|
|
return -1;
|
|
}
|
|
// 设置背景色
|
|
bg.color = green;
|
|
// 设置背景图
|
|
bg.image = ℑ
|
|
bg.size.width = image.width;
|
|
bg.size.height = image.height;
|
|
// 让背景图居中
|
|
bg.position.x = (rect.width - image.width) / 2;
|
|
bg.position.y = (rect.height - image.height) / 2;
|
|
// 创建绘制上下文
|
|
paint = LCUIPainter_Begin(&canvas, &rect);
|
|
// 绘制背景
|
|
Background_Paint(&bg, &rect, paint);
|
|
LCUI_WritePNGFile("test_paint_background_image_with_position.png",
|
|
&canvas);
|
|
LCUIPainter_End(paint);
|
|
Graph_Free(&image);
|
|
Graph_Free(&canvas);
|
|
return 0;
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
test_paint_background_color();
|
|
test_paint_background_image();
|
|
test_paint_background_image_with_size();
|
|
test_paint_background_image_with_position();
|
|
return 0;
|
|
}
|