Skip to content

Commit 0afa587

Browse files
Notify out of focus
1 parent ebafd5d commit 0afa587

File tree

8 files changed

+161
-17
lines changed

8 files changed

+161
-17
lines changed
-696 Bytes
Loading

Source/Documentation/Manual/options.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ The default setting is checked.
408408

409409

410410
At game start, Electric - power connected
411-
-----------------------------------
411+
-----------------------------------------
412412

413413
When this option is checked, stationary electric locos start the simulation with power available.
414414
Uncheck this option for a more detailed behaviour in which the player has to switch on electrical equipment.
@@ -602,6 +602,15 @@ specific width and height to be used.
602602

603603
The format is <width>x<height>, for example 1024x768.
604604

605+
.. -options-out-of-focus:
606+
607+
Notify out of focus
608+
-------------------
609+
610+
When this option is checked, on the corners of the Open Rails main window a red rectangle is shown when the window is not in focus.
611+
Just a reminder that the main window currently does not react on keystrokes.
612+
613+
The default setting is unchecked.
605614

606615
.. _options-window-glass:
607616

Source/Menu/Options.Designer.cs

Lines changed: 47 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Source/Menu/Options.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ orderby folder.Key
303303

304304
checkWindowed.Checked = !Settings.FullScreen;
305305
comboWindowSize.Text = Settings.WindowSize;
306+
checkOutOfFocus.Checked = Settings.OutOfFocus;
306307
checkWindowGlass.Checked = Settings.WindowGlass;
307308

308309
// keep values in line with enum Orts.Simulation.ConfirmLevel
@@ -507,6 +508,7 @@ void buttonOK_Click(object sender, EventArgs e)
507508
UpdateManager.SetChannel((string)control.Tag);
508509
Settings.FullScreen = !checkWindowed.Checked;
509510
Settings.WindowSize = GetValidWindowSize(comboWindowSize.Text);
511+
Settings.OutOfFocus = checkOutOfFocus.Checked;
510512
Settings.WindowGlass = checkWindowGlass.Checked;
511513
Settings.SuppressConfirmations = comboControlConfirmations.SelectedIndex;
512514
Settings.WebServerPort = (int)numericWebServerPort.Value;
@@ -890,6 +892,7 @@ private void InitializeHelpIcons()
890892
(pbLanguage, new Control[] { labelLanguage, comboLanguage }),
891893
(pbUpdateMode, new Control[] { labelUpdateMode }),
892894
(pbWindowed, new Control[] { checkWindowed, labelWindowSize, comboWindowSize }),
895+
(pbOutOfFocus, new[] { checkOutOfFocus }),
893896
(pbWindowGlass, new[] { checkWindowGlass }),
894897
(pbControlConfirmations, new Control[] { labelControlConfirmations, comboControlConfirmations }),
895898
(pbWebServerPort, new Control[] { labelWebServerPort }),
@@ -1036,6 +1039,10 @@ private void HelpIcon_Click(object sender, EventArgs _)
10361039
pbWindowed,
10371040
baseUrl + "/options.html#windowed"
10381041
},
1042+
{
1043+
pbOutOfFocus,
1044+
baseUrl + "/options.html#out-of-focus"
1045+
},
10391046
{
10401047
pbWindowGlass,
10411048
baseUrl + "/options.html#window-glass"

Source/ORTS.Settings/UserSettings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,8 @@ public enum DirectXFeature
278278
[Default("1024x768")]
279279
public string WindowSize { get; set; }
280280
[Default(false)]
281+
public bool OutOfFocus { get; set; }
282+
[Default(false)]
281283
public bool WindowGlass { get; set; }
282284
[Default(0)]
283285
public int SuppressConfirmations { get; set; }
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// COPYRIGHT 2023 by the Open Rails project.
2+
//
3+
// This file is part of Open Rails.
4+
//
5+
// Open Rails is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// Open Rails is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU General Public License
16+
// along with Open Rails. If not, see <http://www.gnu.org/licenses/>.
17+
//
18+
19+
using Microsoft.Xna.Framework;
20+
using Microsoft.Xna.Framework.Graphics;
21+
22+
namespace Orts.Viewer3D.Popups
23+
{
24+
public class OutOfFocusWindow : Window
25+
{
26+
private readonly Texture2D Line;
27+
private readonly int Thickness = 3;
28+
private readonly Color Color = Color.Red;
29+
30+
private readonly int Width;
31+
private readonly int Height;
32+
33+
public OutOfFocusWindow(WindowManager owner) : base(owner)
34+
{
35+
Line = new Texture2D(owner.Viewer.GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
36+
Line.SetData(new[] { Color });
37+
38+
Width = owner.Viewer.GraphicsDevice.Viewport.Width;
39+
Height = owner.Viewer.GraphicsDevice.Viewport.Height;
40+
}
41+
42+
public override void Draw(SpriteBatch SpriteBatch)
43+
{
44+
// top
45+
DrawLine(SpriteBatch, 0, 0, Width, Thickness, 0);
46+
47+
// bottom
48+
DrawLine(SpriteBatch, 0, Height - Thickness, Width, Thickness, 0);
49+
50+
// left
51+
DrawLine(SpriteBatch, Thickness, Thickness, Height, Thickness, 90);
52+
53+
// right
54+
DrawLine(SpriteBatch, Width, Thickness, Height, Thickness, 90);
55+
}
56+
57+
private void DrawLine(SpriteBatch SpriteBatch, int X, int Y, int width, int height, int degrees)
58+
{
59+
SpriteBatch.Draw(
60+
Line,
61+
new Rectangle(X, Y, width, height),
62+
null,
63+
Color,
64+
(float)ConvertToRadiansFromDegrees(degrees),
65+
new Vector2(0, 0),
66+
SpriteEffects.None, 0);
67+
}
68+
69+
private float ConvertToRadiansFromDegrees(int angle)
70+
{
71+
return (float)((System.Math.PI / 180) * angle);
72+
}
73+
74+
}
75+
}

Source/RunActivity/Viewer3D/Popups/Window.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public abstract class Window : RenderPrimitive
4545
VertexBuffer WindowVertexBuffer;
4646
IndexBuffer WindowIndexBuffer;
4747

48+
readonly bool DoNotDisplayWindow = false;
49+
4850
public Window(WindowManager owner, int width, int height, string caption)
4951
{
5052
Owner = owner;
@@ -66,6 +68,13 @@ public Window(WindowManager owner, int width, int height, string caption)
6668
Owner.Add(this);
6769
}
6870

71+
public Window(WindowManager owner)
72+
{
73+
Owner = owner;
74+
DoNotDisplayWindow = true;
75+
Owner.Add(this);
76+
}
77+
6978
protected internal virtual void Initialize()
7079
{
7180
VisibilityChanged();
@@ -224,6 +233,11 @@ public virtual void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime, boo
224233

225234
public override void Draw(GraphicsDevice graphicsDevice)
226235
{
236+
if (DoNotDisplayWindow)
237+
{
238+
return;
239+
}
240+
227241
if (WindowVertexBuffer == null)
228242
{
229243
// Edges/corners are 32px (1/4th image size).

0 commit comments

Comments
 (0)