Skip to content

Commit e320dae

Browse files
committed
Added flag to prevent a panel from receiving keyboard input when it does not want to.
1 parent ce2a662 commit e320dae

File tree

133 files changed

+7368
-23
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+7368
-23
lines changed

WinMan/Panel.cs

+41-9
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,29 @@ public abstract class Panel
6161
/// </summary>
6262
public bool RealTimeUpdate { get; protected set; }
6363

64+
private bool _acceptsKeyboardInput;
65+
/// <summary>
66+
/// Whether or not the panel needs to accept keyboard input. If not, the OnKeyPress function will never be called.
67+
/// </summary>
68+
public bool AcceptsKeyboardInput
69+
{
70+
get => _acceptsKeyboardInput;
71+
set
72+
{
73+
if (_acceptsKeyboardInput != value)
74+
{
75+
_acceptsKeyboardInput = value;
76+
if (Shown)
77+
{
78+
if (_acceptsKeyboardInput)
79+
Engine.AddToKeyPressFront(OnKeyPress);
80+
else
81+
Engine.KeyPress -= OnKeyPress;
82+
}
83+
}
84+
}
85+
}
86+
6487
/// <summary>
6588
/// The width of the section of the root console that this panel is rendering to.
6689
/// </summary>
@@ -98,8 +121,10 @@ public int Height
98121
/// root console that the panel will render to should be.</param>
99122
/// <param name="height">A function that takes no parameters and returns an int, saying what the height of the section of the
100123
/// root console that the panel will render to should be.</param>
124+
/// <param name="acceptsKeyboardInput">Whether or not the panel will accept keyboard input (have its OnKeyPress function called) when it is
125+
/// being shown.</param>
101126
/// <param name="realTimeUpdate">Whether or not the panel should run the code to update its offscreen console every frame.</param>
102-
public Panel(ResizeCalc rootX, ResizeCalc rootY, ResizeCalc width, ResizeCalc height, bool realTimeUpdate = false)
127+
protected Panel(ResizeCalc rootX, ResizeCalc rootY, ResizeCalc width, ResizeCalc height, bool acceptsKeyboardInput = false, bool realTimeUpdate = false)
103128
{
104129
rootXCalc = rootX;
105130
rootYCalc = rootY;
@@ -112,6 +137,7 @@ public Panel(ResizeCalc rootX, ResizeCalc rootY, ResizeCalc width, ResizeCalc he
112137
console = new RLConsole(widthCalc(), heightCalc());
113138
Shown = false;
114139
RealTimeUpdate = realTimeUpdate;
140+
_acceptsKeyboardInput = acceptsKeyboardInput;
115141
OnResize = null;
116142
}
117143

@@ -147,8 +173,9 @@ virtual public void Render(object sender, UpdateEventArgs e)
147173
protected virtual void OnKeyPress(object sender, KeyPressEventArgs e) { }
148174

149175
/// <summary>
150-
/// Causes the panel to be rendered (shown to the program user) each render frame, if it is not already shown. If RealTimeUpdate is true, the panel's UpdateLayout
151-
/// handler is added to the Program.UpdateRealTimeLayout event handler list. If RealTimeUpdate is false, it simply calls UpdateLayout once.
176+
/// Causes the panel to be rendered (shown to the program user) each render frame, and to accept keyboard input if AcceptsKeyboardInput is true,
177+
/// if it is not already shown. If RealTimeUpdate is true, the panel's UpdateLayout handler is added to the Program.UpdateRealTimeLayout event
178+
/// handler list. If RealTimeUpdate is false, it simply calls UpdateLayout once.
152179
/// </summary>
153180
public void Show()
154181
{
@@ -160,23 +187,29 @@ public void Show()
160187
UpdateLayout(this, new UpdateEventArgs(0f));
161188

162189
Engine.Render += Render;
163-
Engine.AddToKeyPressFront(OnKeyPress);
190+
191+
if (_acceptsKeyboardInput)
192+
Engine.AddToKeyPressFront(OnKeyPress);
193+
164194
Shown = true;
165195
}
166196
else
167197
Console.WriteLine("WARNING: Tried to show panel that is already shown... BAD!!!");
168198
}
169199

170200
/// <summary>
171-
/// Causes the panel to stop being rendered (shown to the user), if it is currently shown. If RealTimeUpdate is true, the panel's UpdateLayout handler is
172-
/// removed from the Program.UpdateRealTimeLayout event handler list.
201+
/// Causes the panel to stop being rendered (shown to the user) and to stop receiving keyboard input, if it is currently shown.
202+
/// If RealTimeUpdate is true, the panel's UpdateLayout handler is removed from the Program.UpdateRealTimeLayout event handler list.
173203
/// </summary>
174204
public void Hide()
175205
{
176206
if (Shown)
177207
{
178208
Engine.Render -= Render;
179-
Engine.KeyPress -= OnKeyPress;
209+
210+
if (_acceptsKeyboardInput)
211+
Engine.KeyPress -= OnKeyPress;
212+
180213
if (RealTimeUpdate)
181214
Engine.UpdateRealTimeLayouts -= UpdateLayout;
182215

@@ -198,8 +231,7 @@ internal void onScreenResize(object sender, ResizeEventArgs e)
198231
RootY = rootYCalc();
199232
console.Resize(widthCalc(), heightCalc());
200233

201-
if (OnResize != null)
202-
OnResize(this, EventArgs.Empty);
234+
OnResize?.Invoke(this, EventArgs.Empty);
203235

204236
if (!RealTimeUpdate)
205237
UpdateLayout(this, null);

WinMan/Properties/AssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@
3131
// You can specify all the values or you can default the Build and Revision Numbers
3232
// by using the '*' as shown below:
3333
// [assembly: AssemblyVersion("1.0.*")]
34-
[assembly: AssemblyVersion("0.5.0")]
35-
[assembly: AssemblyFileVersion("0.5.0")]
34+
[assembly: AssemblyVersion("0.6.0")]
35+
[assembly: AssemblyFileVersion("0.6.0")]

WinMan/WinMan.csproj

+4-3
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,21 @@
1717
<DebugSymbols>true</DebugSymbols>
1818
<DebugType>full</DebugType>
1919
<Optimize>false</Optimize>
20-
<OutputPath>bin\Debug\</OutputPath>
20+
<OutputPath>.\</OutputPath>
2121
<DefineConstants>DEBUG;TRACE</DefineConstants>
2222
<ErrorReport>prompt</ErrorReport>
2323
<WarningLevel>4</WarningLevel>
24+
<NoWarn>RECS0145;RECS0129</NoWarn>
2425
</PropertyGroup>
2526
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
2627
<DebugType>pdbonly</DebugType>
2728
<Optimize>true</Optimize>
28-
<OutputPath>bin\Release\</OutputPath>
29+
<OutputPath>.\</OutputPath>
2930
<DefineConstants>TRACE</DefineConstants>
3031
<ErrorReport>prompt</ErrorReport>
3132
<WarningLevel>4</WarningLevel>
3233
<DocumentationFile>bin\Release\WinMan.xml</DocumentationFile>
33-
<NoWarn>RECS0145; RECS0129</NoWarn>
34+
<NoWarn>RECS0145;RECS0129</NoWarn>
3435
</PropertyGroup>
3536
<ItemGroup>
3637
<Reference Include="OpenTK, Version=1.1.0.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4, processorArchitecture=MSIL">

WinMap.Test/AlertPanel.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ internal class AlertPanel : Panel
77
private string message;
88

99
public AlertPanel(ResizeCalc centerX, ResizeCalc centerY, string message)
10-
: base(() => centerX() - (message.Length / 2), () => centerY() - 2, () => message.Length, Screen.SizeC(5))
10+
: base(() => centerX() - (message.Length / 2), () => centerY() - 2, () => message.Length, Screen.SizeC(5), true, false)
1111
{
1212
this.message = message;
1313
}

WinMap.Test/MapPanel.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ internal class MapPanel : Panel
88
private int[,] map;
99

1010
public MapPanel(ResizeCalc rootX, ResizeCalc rootY, ResizeCalc width, ResizeCalc height)
11-
: base(rootX, rootY, width, height, true)
11+
: base(rootX, rootY, width, height, false, true)
1212
{
1313
Random rng = new Random();
1414
map = new int[Width, Height];

WinMap.Test/MenuPanel.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace WinMan.Test
44
{
55
internal class MenuPanel : Panel
66
{
7-
public MenuPanel(ResizeCalc rootX, ResizeCalc rootY, ResizeCalc width, ResizeCalc height) : base(rootX, rootY, width, height)
7+
public MenuPanel(ResizeCalc rootX, ResizeCalc rootY, ResizeCalc width, ResizeCalc height) : base(rootX, rootY, width, height, true, false)
88
{
99
}
1010

WinMap.Test/WinMap.Test.csproj

+7-6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<DefineConstants>DEBUG;TRACE</DefineConstants>
2222
<ErrorReport>prompt</ErrorReport>
2323
<WarningLevel>4</WarningLevel>
24+
<NoWarn>RECS0145;RECS0129</NoWarn>
2425
</PropertyGroup>
2526
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
2627
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -30,7 +31,7 @@
3031
<DefineConstants>TRACE</DefineConstants>
3132
<ErrorReport>prompt</ErrorReport>
3233
<WarningLevel>4</WarningLevel>
33-
<NoWarn>RECS0145; RECS0129</NoWarn>
34+
<NoWarn>RECS0145;RECS0129</NoWarn>
3435
</PropertyGroup>
3536
<ItemGroup>
3637
<Reference Include="OpenTK, Version=1.1.0.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4, processorArchitecture=MSIL">
@@ -60,16 +61,16 @@
6061
<None Include="App.config" />
6162
<None Include="packages.config" />
6263
</ItemGroup>
64+
<ItemGroup>
65+
<Content Include="terminal8x8.png">
66+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
67+
</Content>
68+
</ItemGroup>
6369
<ItemGroup>
6470
<ProjectReference Include="..\WinMan\WinMan.csproj">
6571
<Project>{3a43a4b7-3e24-4e07-a623-d93c75a70246}</Project>
6672
<Name>WinMan</Name>
6773
</ProjectReference>
6874
</ItemGroup>
69-
<ItemGroup>
70-
<Content Include="terminal8x8.png">
71-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
72-
</Content>
73-
</ItemGroup>
7475
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
7576
</Project>

docs/html/annotated.html

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2+
<html xmlns="http://www.w3.org/1999/xhtml">
3+
<head>
4+
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
5+
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
6+
<meta name="generator" content="Doxygen 1.8.12"/>
7+
<meta name="viewport" content="width=device-width, initial-scale=1"/>
8+
<title>WinMan: Class List</title>
9+
<link href="tabs.css" rel="stylesheet" type="text/css"/>
10+
<script type="text/javascript" src="jquery.js"></script>
11+
<script type="text/javascript" src="dynsections.js"></script>
12+
<link href="search/search.css" rel="stylesheet" type="text/css"/>
13+
<script type="text/javascript" src="search/searchdata.js"></script>
14+
<script type="text/javascript" src="search/search.js"></script>
15+
<link href="doxygen.css" rel="stylesheet" type="text/css" />
16+
</head>
17+
<body>
18+
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
19+
<div id="titlearea">
20+
<table cellspacing="0" cellpadding="0">
21+
<tbody>
22+
<tr style="height: 56px;">
23+
<td id="projectalign" style="padding-left: 0.5em;">
24+
<div id="projectname">WinMan
25+
</div>
26+
<div id="projectbrief">Window/panel display utility library written with roguelike/2D game development in mind, on top of the C# full color console library RLNET.</div>
27+
</td>
28+
</tr>
29+
</tbody>
30+
</table>
31+
</div>
32+
<!-- end header part -->
33+
<!-- Generated by Doxygen 1.8.12 -->
34+
<script type="text/javascript">
35+
var searchBox = new SearchBox("searchBox", "search",false,'Search');
36+
</script>
37+
<script type="text/javascript" src="menudata.js"></script>
38+
<script type="text/javascript" src="menu.js"></script>
39+
<script type="text/javascript">
40+
$(function() {
41+
initMenu('',true,false,'search.php','Search');
42+
$(document).ready(function() { init_search(); });
43+
});
44+
</script>
45+
<div id="main-nav"></div>
46+
</div><!-- top -->
47+
<!-- window showing the filter options -->
48+
<div id="MSearchSelectWindow"
49+
onmouseover="return searchBox.OnSearchSelectShow()"
50+
onmouseout="return searchBox.OnSearchSelectHide()"
51+
onkeydown="return searchBox.OnSearchSelectKey(event)">
52+
</div>
53+
54+
<!-- iframe showing the search results (closed by default) -->
55+
<div id="MSearchResultsWindow">
56+
<iframe src="javascript:void(0)" frameborder="0"
57+
name="MSearchResults" id="MSearchResults">
58+
</iframe>
59+
</div>
60+
61+
<div class="header">
62+
<div class="headertitle">
63+
<div class="title">Class List</div> </div>
64+
</div><!--header-->
65+
<div class="contents">
66+
<div class="textblock">Here are the classes, structs, unions and interfaces with brief descriptions:</div><div class="directory">
67+
<div class="levels">[detail level <span onclick="javascript:toggleLevel(1);">1</span><span onclick="javascript:toggleLevel(2);">2</span>]</div><table class="directory">
68+
<tr id="row_0_" class="even"><td class="entry"><span style="width:0px;display:inline-block;">&#160;</span><span id="arr_0_" class="arrow" onclick="toggleFolder('0_')">&#9660;</span><span class="icona"><span class="icon">N</span></span><a class="el" href="namespace_win_man.html" target="_self">WinMan</a></td><td class="desc"></td></tr>
69+
<tr id="row_0_0_"><td class="entry"><span style="width:32px;display:inline-block;">&#160;</span><span class="icona"><span class="icon">C</span></span><a class="el" href="class_win_man_1_1_key_handler.html" target="_self">KeyHandler</a></td><td class="desc"><a class="el" href="class_win_man_1_1_key_handler.html" title="KeyHandler can be subclassed to represent anything that handles keys. Panels have an OnKeyPress funct...">KeyHandler</a> can be subclassed to represent anything that handles keys. Panels have an OnKeyPress function by default, so this class can be subclassed to represents something that ONLY handles keys. This allows objects that are not panels to handle keypresses. </td></tr>
70+
<tr id="row_0_1_" class="even"><td class="entry"><span style="width:32px;display:inline-block;">&#160;</span><span class="icona"><span class="icon">C</span></span><a class="el" href="class_win_man_1_1_key_press_event_args.html" target="_self">KeyPressEventArgs</a></td><td class="desc">Passed to KeyPressEventHandler functions. Contains an RLKeyPress detailing information about the key that was pressed. Cancelable. </td></tr>
71+
<tr id="row_0_2_"><td class="entry"><span style="width:32px;display:inline-block;">&#160;</span><span class="icona"><span class="icon">C</span></span><a class="el" href="class_win_man_1_1_panel.html" target="_self">Panel</a></td><td class="desc">This class is designed to be subclassed by any entity that wishes to have a section of the root console on which to render. </td></tr>
72+
<tr id="row_0_3_" class="even"><td class="entry"><span style="width:32px;display:inline-block;">&#160;</span><span class="icona"><span class="icon">C</span></span><a class="el" href="class_win_man_1_1_screen.html" target="_self">Screen</a></td><td class="desc">This class is designed to be subclassed to represent any collection of related panels. This could be panels that resize relative to each other, or even just panels that will be shown and hidden as one unit. </td></tr>
73+
</table>
74+
</div><!-- directory -->
75+
</div><!-- contents -->
76+
<!-- start footer part -->
77+
<hr class="footer"/><address class="footer"><small>
78+
Generated by &#160;<a href="http://www.doxygen.org/index.html">
79+
<img class="footer" src="doxygen.png" alt="doxygen"/>
80+
</a> 1.8.12
81+
</small></address>
82+
</body>
83+
</html>

docs/html/bc_s.png

676 Bytes
Loading

docs/html/bdwn.png

147 Bytes
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2+
<html xmlns="http://www.w3.org/1999/xhtml">
3+
<head>
4+
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
5+
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
6+
<meta name="generator" content="Doxygen 1.8.12"/>
7+
<meta name="viewport" content="width=device-width, initial-scale=1"/>
8+
<title>WinMan: Member List</title>
9+
<link href="tabs.css" rel="stylesheet" type="text/css"/>
10+
<script type="text/javascript" src="jquery.js"></script>
11+
<script type="text/javascript" src="dynsections.js"></script>
12+
<link href="search/search.css" rel="stylesheet" type="text/css"/>
13+
<script type="text/javascript" src="search/searchdata.js"></script>
14+
<script type="text/javascript" src="search/search.js"></script>
15+
<link href="doxygen.css" rel="stylesheet" type="text/css" />
16+
</head>
17+
<body>
18+
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
19+
<div id="titlearea">
20+
<table cellspacing="0" cellpadding="0">
21+
<tbody>
22+
<tr style="height: 56px;">
23+
<td id="projectalign" style="padding-left: 0.5em;">
24+
<div id="projectname">WinMan
25+
</div>
26+
<div id="projectbrief">Window/panel display utility library written with roguelike/2D game development in mind, on top of the C# full color console library RLNET.</div>
27+
</td>
28+
</tr>
29+
</tbody>
30+
</table>
31+
</div>
32+
<!-- end header part -->
33+
<!-- Generated by Doxygen 1.8.12 -->
34+
<script type="text/javascript">
35+
var searchBox = new SearchBox("searchBox", "search",false,'Search');
36+
</script>
37+
<script type="text/javascript" src="menudata.js"></script>
38+
<script type="text/javascript" src="menu.js"></script>
39+
<script type="text/javascript">
40+
$(function() {
41+
initMenu('',true,false,'search.php','Search');
42+
$(document).ready(function() { init_search(); });
43+
});
44+
</script>
45+
<div id="main-nav"></div>
46+
<!-- window showing the filter options -->
47+
<div id="MSearchSelectWindow"
48+
onmouseover="return searchBox.OnSearchSelectShow()"
49+
onmouseout="return searchBox.OnSearchSelectHide()"
50+
onkeydown="return searchBox.OnSearchSelectKey(event)">
51+
</div>
52+
53+
<!-- iframe showing the search results (closed by default) -->
54+
<div id="MSearchResultsWindow">
55+
<iframe src="javascript:void(0)" frameborder="0"
56+
name="MSearchResults" id="MSearchResults">
57+
</iframe>
58+
</div>
59+
60+
<div id="nav-path" class="navpath">
61+
<ul>
62+
<li class="navelem"><a class="el" href="namespace_win_man.html">WinMan</a></li><li class="navelem"><a class="el" href="class_win_man_1_1_key_handler.html">KeyHandler</a></li> </ul>
63+
</div>
64+
</div><!-- top -->
65+
<div class="header">
66+
<div class="headertitle">
67+
<div class="title">WinMan.KeyHandler Member List</div> </div>
68+
</div><!--header-->
69+
<div class="contents">
70+
71+
<p>This is the complete list of members for <a class="el" href="class_win_man_1_1_key_handler.html">WinMan.KeyHandler</a>, including all inherited members.</p>
72+
<table class="directory">
73+
<tr class="even"><td class="entry"><a class="el" href="class_win_man_1_1_key_handler.html#acab2027ccfc8fc90afebdfc1b02b9f9c">Handling</a></td><td class="entry"><a class="el" href="class_win_man_1_1_key_handler.html">WinMan.KeyHandler</a></td><td class="entry"></td></tr>
74+
<tr><td class="entry"><a class="el" href="class_win_man_1_1_key_handler.html#a470071a94e429358d3610e83cee5307e">KeyHandler</a>()</td><td class="entry"><a class="el" href="class_win_man_1_1_key_handler.html">WinMan.KeyHandler</a></td><td class="entry"></td></tr>
75+
<tr class="even"><td class="entry"><a class="el" href="class_win_man_1_1_key_handler.html#a8c454fd1408a5119b4df97317272a957">OnKeyPress</a>(object sender, KeyPressEventArgs e)</td><td class="entry"><a class="el" href="class_win_man_1_1_key_handler.html">WinMan.KeyHandler</a></td><td class="entry"><span class="mlabel">protected</span><span class="mlabel">pure virtual</span></td></tr>
76+
<tr><td class="entry"><a class="el" href="class_win_man_1_1_key_handler.html#a8451dd47f3d1eeb468e7d506ff8cecc0">StartHandling</a>()</td><td class="entry"><a class="el" href="class_win_man_1_1_key_handler.html">WinMan.KeyHandler</a></td><td class="entry"></td></tr>
77+
<tr class="even"><td class="entry"><a class="el" href="class_win_man_1_1_key_handler.html#afffadd79f85fdf293bd29d47951fd69e">StopHandling</a>()</td><td class="entry"><a class="el" href="class_win_man_1_1_key_handler.html">WinMan.KeyHandler</a></td><td class="entry"></td></tr>
78+
</table></div><!-- contents -->
79+
<!-- start footer part -->
80+
<hr class="footer"/><address class="footer"><small>
81+
Generated by &#160;<a href="http://www.doxygen.org/index.html">
82+
<img class="footer" src="doxygen.png" alt="doxygen"/>
83+
</a> 1.8.12
84+
</small></address>
85+
</body>
86+
</html>

0 commit comments

Comments
 (0)