-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlable.cpp
executable file
·118 lines (106 loc) · 2.03 KB
/
lable.cpp
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
#include "lable.h"
// 带文字
Lable *CreateLable(int x, int y, char *s)
{
Lable *p = (Lable*)malloc(sizeof(Lable));
setDefalutProperty(p);
setText(p, s);
setLocation(p, x, y);
setSize(p);
return p;
}
// 带图标文字
Lable *CreateLable(int x, int y, char *s, IMAGE *img)
{
Lable *p = (Lable*)malloc(sizeof(Lable));
setDefalutProperty(p);
setText(p, s);
setIcon(p, img);
setLocation(p, x, y);
setSize(p);
return p;
}
// 文本
void setText(Lable *p, char *s)
{
memset(p->text, 0, sizeof(p->text));
sprintf(p->text, "%s", s);
}
// 字体
void setTextStyle(int w, int h, char *lpface)
{
settextstyle(w, h, lpface);
}
// 图标
void setIcon(Lable *p, IMAGE *img)
{
p->image = img;
}
// 自适应尺寸
void setSize(Lable *p)
{
if (p->image != NULL){
p->width += p->image->getwidth();
p->height += p->image->getheight();
}
if (strlen(p->text)>0){
p->width += 80;// textwidth(p->text);
}
}
// 尺寸
void setSize(Lable *p, int w, int h)
{
p->width = w;
p->height = h;
}
// 位置
void setLocation(Lable *p, int x, int y)
{
p->x = x;
p->y = y;
}
// 前景色
void setForeground(Lable *p, COLORREF color)
{
p->foreground = color;
}
// 背景色
void setBackground(Lable *p, COLORREF color)
{
p->background = color;
}
// 默认属性
void setDefalutProperty(Lable *p)
{
p->x = 0;
p->y = 0;
p->width = 0;
p->height = 0;
p->image = NULL;
p->foreground = 0xffccff;
p->background = 0x000000;
p->focuscolor = 0xccffff;
}
// 显示
void display(Lable *p)
{
setlinestyle(0, 0);
setlinecolor(p->background);
setfillcolor(p->background);
fillrectangle(p->x, p->y, p->x+p->width, p->y+p->height);
setcolor(p->foreground);
if (p->image != NULL)
{
putimage(p->x, p->y, p->image, SRCCOPY);
if (strlen(p->text)>0)
{
settextcolor(p->foreground);
outtextxy(p->x + p->image->getwidth(), p->y, p->text);
}//有文字
}// 有图片
else if (strlen(p->text)>0)
{
settextcolor(p->foreground);
outtextxy(p->x, p->y, p->text);
}// 无图片 有文字
}