-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMenu.cpp
77 lines (68 loc) · 1.42 KB
/
Menu.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
#include "Menu.h"
#include <graphics.h>
/**
* 菜单显示
*/
void printMenu(MenuNode *list, int offset/* = 0*/)
{
cleardevice();
// 打印开头
RECT rc;
rc.left = 100;
rc.top = 60;
rc.right = getwidth() - rc.left;
rc.bottom = getheight() - rc.top;
BeginBatchDraw();
setlinecolor(BLUE);
setlinestyle(0, 4);
rectangle(rc.left, rc.top, rc.right, rc.bottom);
TCHAR buf[16];
settextstyle(36, 0, NULL);
rc.left += 160;
rc.right -= 160;
// 打印标题
rc.top -= 20;
rc.bottom = rc.top + 40;
drawtext(list->name, &rc, DT_CENTER);
rc.top += 20;
rc.bottom += 20;
// 打印主体
int i = 1 + offset;
MenuNode *pNode = list->next;
while (pNode) {
rc.top += 40;
rc.bottom += 40;
// 返回选项以0为标号
if (pNode->next == NULL)
i = 0;
_stprintf(buf, _T("%d. %s"), i, pNode->name);
drawtext(buf, &rc, 0);
pNode = pNode->next;
++i;
}
settextstyle(20, 0, NULL);
EndBatchDraw();
}
void printMenu(const TCHAR * items, int rows, int cols, LPCTSTR title/* = NULL*/, int offset/* = 0*/)
{
MenuNode *list, *pNode;
list = new MenuNode;
pNode = list;
pNode->name = title;
pNode->next = NULL;
for (int i = offset; i < rows; ++i)
{
pNode->next = new MenuNode;
pNode = pNode->next;
pNode->name = items + i * cols;
pNode->next = NULL;
}
printMenu(list, offset);
// 销毁链表
while (list)
{
pNode = list;
list = list->next;
delete pNode;
}
}