Starshatter_Open
Open source Starshatter engine
Main Page
Classes
Files
File List
File Members
All
Classes
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
KeyDlg.cpp
Go to the documentation of this file.
1
/* Project Starshatter 4.5
2
Destroyer Studios LLC
3
Copyright © 1997-2004. All Rights Reserved.
4
5
SUBSYSTEM: Stars.exe
6
FILE: KeyDlg.cpp
7
AUTHOR: John DiCamillo
8
9
10
OVERVIEW
11
========
12
*/
13
14
#include "
MemDebug.h
"
15
#include "
KeyDlg.h
"
16
#include "
KeyMap.h
"
17
#include "
MenuScreen.h
"
18
#include "
Starshatter.h
"
19
#include "
FormatUtil.h
"
20
21
#include "
Game.h
"
22
#include "
ListBox.h
"
23
#include "
ComboBox.h
"
24
#include "
Button.h
"
25
#include "
Joystick.h
"
26
27
// +--------------------------------------------------------------------+
28
// DECLARE MAPPING FUNCTIONS:
29
30
DEF_MAP_CLIENT
(
KeyDlg
, OnApply);
31
DEF_MAP_CLIENT
(
KeyDlg
, OnCancel);
32
DEF_MAP_CLIENT
(
KeyDlg
, OnClear);
33
34
// +--------------------------------------------------------------------+
35
36
KeyDlg::KeyDlg
(
Screen
* s,
FormDef
& def,
BaseScreen
* mgr)
37
:
FormWindow
(s, 0, 0, s->Width(), s->Height()), manager(mgr),
38
key_key(0), key_shift(0), key_joy(0), key_clear(0),
39
command(0), current_key(0), new_key(0), clear(0),
40
apply(0), cancel(0)
41
{
42
Init
(def);
43
}
44
45
KeyDlg::~KeyDlg
()
46
{
47
}
48
49
void
50
KeyDlg::RegisterControls
()
51
{
52
if
(
apply
)
53
return
;
54
55
command
=
FindControl
(201);
56
current_key
=
FindControl
(202);
57
new_key
=
FindControl
(203);
58
59
clear
= (
Button
*)
FindControl
(300);
60
REGISTER_CLIENT
(
EID_CLICK
,
clear
,
KeyDlg
,
OnClear
);
61
62
apply
= (
Button
*)
FindControl
(1);
63
REGISTER_CLIENT
(
EID_CLICK
,
apply
,
KeyDlg
,
OnApply
);
64
65
cancel
= (
Button
*)
FindControl
(2);
66
REGISTER_CLIENT
(
EID_CLICK
,
cancel
,
KeyDlg
,
OnCancel
);
67
}
68
69
// +--------------------------------------------------------------------+
70
71
void
72
KeyDlg::ExecFrame
()
73
{
74
int
key = 0;
75
int
shift = 0;
76
int
joy = 0;
77
Joystick
* joystick =
Joystick::GetInstance
();
78
79
if
(joystick) joystick->
Acquire
();
80
81
for
(
int
i = 0; i < 256; i++) {
82
int
vk =
KeyMap::GetMappableVKey
(i);
83
84
if
(vk >=
KEY_JOY_1
&& vk <=
KEY_JOY_16
) {
85
if
(joystick && joystick->
KeyDown
(vk))
86
joy = vk;
87
}
88
89
else
if
(vk >=
KEY_POV_0_UP
&& vk <=
KEY_POV_3_RIGHT
) {
90
if
(joystick && joystick->
KeyDown
(vk))
91
joy = vk;
92
}
93
94
else
if
(GetAsyncKeyState(vk)) {
95
if
(vk == VK_SHIFT || vk == VK_MENU)
96
shift = vk;
97
else
98
key = vk;
99
}
100
}
101
102
if
(key) {
103
key_key
= key;
104
key_shift
= shift;
105
106
new_key
->
SetText
(
KeyMap::DescribeKey
(key, shift, joy));
107
}
108
109
else
if
(joy) {
110
key_joy
= joy;
111
new_key
->
SetText
(
KeyMap::DescribeKey
(key, shift, joy));
112
}
113
}
114
115
// +--------------------------------------------------------------------+
116
117
void
118
KeyDlg::Show
()
119
{
120
FormWindow::Show
();
121
122
Starshatter
* stars =
Starshatter::GetInstance
();
123
124
if
(stars) {
125
KeyMap
& keymap = stars->
GetKeyMap
();
126
127
if
(
command
)
128
command
->
SetText
(keymap.
DescribeAction
(
key_index
));
129
130
if
(
current_key
)
131
current_key
->
SetText
(keymap.
DescribeKey
(
key_index
));
132
}
133
134
key_clear
=
false
;
135
new_key
->
SetText
(
""
);
136
SetFocus
();
137
}
138
139
// +--------------------------------------------------------------------+
140
141
void
142
KeyDlg::SetKeyMapIndex
(
int
i)
143
{
144
key_index
= i;
145
key_key
= 0;
146
key_shift
= 0;
147
}
148
149
// +--------------------------------------------------------------------+
150
151
void
152
KeyDlg::OnClear
(
AWEvent
* event)
153
{
154
key_clear
=
true
;
155
156
key_key
= 0;
157
key_shift
= 0;
158
key_joy
= 0;
159
}
160
161
// +--------------------------------------------------------------------+
162
163
void
164
KeyDlg::OnApply
(
AWEvent
* event)
165
{
166
Starshatter
* stars =
Starshatter::GetInstance
();
167
168
if
(stars) {
169
KeyMap
& keymap = stars->
GetKeyMap
();
170
KeyMapEntry
* map = keymap.
GetKeyMap
(
key_index
);
171
172
if
(
key_clear
) {
173
map->
key
= 0;
174
map->
alt
= 0;
175
map->
joy
= 0;
176
}
177
178
if
(
key_key
) {
179
map->
key
=
key_key
;
180
map->
alt
=
key_shift
;
181
}
182
183
if
(
key_joy
) {
184
map->
joy
=
key_joy
;
185
}
186
}
187
188
if
(
manager
)
189
manager
->
ShowCtlDlg
();
190
}
191
192
void
193
KeyDlg::OnCancel
(
AWEvent
* event)
194
{
195
if
(
manager
)
196
manager
->
ShowCtlDlg
();
197
}
198
199
// +--------------------------------------------------------------------+
Stars45
KeyDlg.cpp
Generated on Tue Jun 5 2012 20:46:55 for Starshatter_Open by
1.8.1