forked from lc-soft/LCUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_paint_background.c
147 lines (138 loc) · 4.57 KB
/
test_paint_background.c
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#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;
}