Starshatter_Open
Open source Starshatter engine
Main Page
Classes
Files
File List
File Members
All
Classes
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Menu.cpp
Go to the documentation of this file.
1
/* Project nGenEx
2
Destroyer Studios LLC
3
Copyright © 1997-2004. All Rights Reserved.
4
5
SUBSYSTEM: nGenEx.lib
6
FILE: Menu.cpp
7
AUTHOR: John DiCamillo
8
9
10
OVERVIEW
11
========
12
Simple menu hierarchy class
13
*/
14
15
#include "
MemDebug.h
"
16
#include "
Menu.h
"
17
18
// +--------------------------------------------------------------------+
19
20
void
21
Menu::AddItem
(
Text
label, DWORD value,
bool
enabled)
22
{
23
MenuItem
* item =
new
(__FILE__,__LINE__)
MenuItem
(label, value, enabled);
24
25
if
(item) {
26
item->
menu
=
this
;
27
items
.
append
(item);
28
}
29
}
30
31
void
32
Menu::AddItem
(
MenuItem
* item)
33
{
34
if
(item->
submenu
)
35
item->
submenu
->
SetParent
(
this
);
36
item->
menu
=
this
;
37
items
.
append
(item);
38
}
39
40
void
41
Menu::AddMenu
(
Text
label,
Menu
* menu, DWORD value)
42
{
43
MenuItem
* item =
new
(__FILE__,__LINE__)
MenuItem
(label, value);
44
45
if
(item) {
46
item->
menu
=
this
;
47
item->
submenu
= menu;
48
menu->
parent
=
this
;
49
50
items
.
append
(item);
51
}
52
}
53
54
MenuItem
*
55
Menu::GetItem
(
int
index)
56
{
57
if
(index >= 0 && index <
items
.
size
())
58
return
items
[index];
59
60
return
0;
61
}
62
63
void
64
Menu::SetItem
(
int
index,
MenuItem
* item)
65
{
66
if
(item && index >= 0 && index <
items
.
size
())
67
items
[index] = item;
68
}
69
70
int
71
Menu::NumItems
()
const
72
{
73
return
items
.
size
();
74
}
75
76
void
77
Menu::ClearItems
()
78
{
79
items
.
destroy
();
80
}
81
82
83
// +--------------------------------------------------------------------+
84
85
MenuItem::MenuItem
(
Text
label, DWORD value,
bool
e)
86
: text(label), data(value), enabled(e), submenu(0), selected(0)
87
{ }
88
89
MenuItem::~MenuItem
()
90
{ }
91
92
// +--------------------------------------------------------------------+
93
94
Menu
*
95
MenuHistory::GetCurrent
()
96
{
97
int
n = history.
size
();
98
99
if
(n)
100
return
history[n-1];
101
102
return
0;
103
}
104
105
Menu
*
106
MenuHistory::GetLevel
(
int
n)
107
{
108
if
(n >= 0 && n < history.
size
())
109
return
history[n];
110
111
return
0;
112
}
113
114
Menu
*
115
MenuHistory::Find
(
const
char
* title)
116
{
117
for
(
int
i = 0; i < history.
size
(); i++)
118
if
(history[i]->GetTitle() == title)
119
return
history[i];
120
121
return
0;
122
}
123
124
void
125
MenuHistory::Pop
()
126
{
127
int
n = history.
size
();
128
129
if
(n)
130
history.
removeIndex
(n-1);
131
}
132
133
void
134
MenuHistory::Push
(
Menu
* menu)
135
{
136
history.
append
(menu);
137
}
138
139
void
140
MenuHistory::Clear
()
141
{
142
history.
clear
();
143
}
nGenEx
Menu.cpp
Generated on Thu May 31 2012 16:30:55 for Starshatter_Open by
1.8.1