1 |
b4d47cc5
|
Oto Šťáva
|
using System;
|
2 |
|
|
using System.Drawing;
|
3 |
|
|
using System.Windows.Forms;
|
4 |
|
|
|
5 |
|
|
namespace DeltarobotVr.Launcher
|
6 |
|
|
{
|
7 |
|
|
public class LauncherForm : Form
|
8 |
|
|
{
|
9 |
|
|
|
10 |
|
|
private readonly Label _serverHostLabel = new Label();
|
11 |
|
|
private readonly TextBox _serverHost = new TextBox();
|
12 |
|
|
|
13 |
|
|
private readonly Label _serverPortLabel = new Label();
|
14 |
|
|
private readonly TextBox _serverPort = new TextBox();
|
15 |
|
|
|
16 |
|
|
private readonly Button _launchButton = new Button();
|
17 |
|
|
|
18 |
|
|
|
19 |
|
|
private const int Spacing = 5;
|
20 |
|
|
private const int ControlHeight = 24;
|
21 |
|
|
private const int LabelWidth = 120;
|
22 |
|
|
|
23 |
|
|
public LauncherForm()
|
24 |
|
|
{
|
25 |
|
|
Text = "Deltarobot VR Launcher";
|
26 |
|
|
|
27 |
|
|
_serverHostLabel.Text = "Server host:";
|
28 |
|
|
_serverHostLabel.TextAlign = ContentAlignment.MiddleRight;
|
29 |
|
|
Controls.Add(_serverHostLabel);
|
30 |
|
|
|
31 |
|
|
Controls.Add(_serverHost);
|
32 |
|
|
|
33 |
|
|
_serverPortLabel.Text = "Server port:";
|
34 |
|
|
_serverPortLabel.TextAlign = ContentAlignment.MiddleRight;
|
35 |
|
|
Controls.Add(_serverPortLabel);
|
36 |
|
|
|
37 |
|
|
Controls.Add(_serverPort);
|
38 |
|
|
|
39 |
|
|
_launchButton.Text = "Launch";
|
40 |
|
|
Controls.Add(_launchButton);
|
41 |
|
|
}
|
42 |
|
|
|
43 |
|
|
protected override void OnLoad(EventArgs e)
|
44 |
|
|
{
|
45 |
|
|
base.OnLoad(e);
|
46 |
|
|
|
47 |
|
|
Width = 640;
|
48 |
|
|
Height = 480;
|
49 |
|
|
|
50 |
|
|
UpdateLayout();
|
51 |
|
|
CenterToScreen();
|
52 |
|
|
}
|
53 |
|
|
|
54 |
|
|
protected override void OnResize(EventArgs e)
|
55 |
|
|
{
|
56 |
|
|
base.OnResize(e);
|
57 |
|
|
|
58 |
|
|
UpdateLayout();
|
59 |
|
|
}
|
60 |
|
|
|
61 |
|
|
private void UpdateLayout()
|
62 |
|
|
{
|
63 |
|
|
var lr = new LayoutRectangle(ClientRectangle);
|
64 |
|
|
lr.Shrink(10);
|
65 |
|
|
|
66 |
|
|
var hostRect = lr.RemoveFromTop(ControlHeight);
|
67 |
|
|
_serverHostLabel.Bounds = hostRect.RemoveFromLeft(LabelWidth).ToRectangle();
|
68 |
|
|
hostRect.RemoveFromLeft(Spacing);
|
69 |
|
|
_serverHost.Bounds = hostRect.RemoveFromLeft(250).ToRectangle();
|
70 |
|
|
|
71 |
|
|
lr.RemoveFromTop(Spacing);
|
72 |
|
|
|
73 |
|
|
var portRect = lr.RemoveFromTop(ControlHeight);
|
74 |
|
|
_serverPortLabel.Bounds = portRect.RemoveFromLeft(LabelWidth).ToRectangle();
|
75 |
|
|
portRect.RemoveFromLeft(Spacing);
|
76 |
|
|
_serverPort.Bounds = portRect.RemoveFromLeft(64).ToRectangle();
|
77 |
|
|
|
78 |
|
|
lr.RemoveFromTop(2 * Spacing);
|
79 |
|
|
|
80 |
|
|
_launchButton.Bounds = lr.RemoveFromBottom(ControlHeight * 2).Shrink(10).ToRectangle();
|
81 |
|
|
}
|
82 |
|
|
}
|
83 |
|
|
}
|