Beginnings of textfield widget
This commit is contained in:
@@ -61,7 +61,8 @@ namespace OpenRA
|
|||||||
|
|
||||||
public static Widget rootWidget = null;
|
public static Widget rootWidget = null;
|
||||||
public static Widget selectedWidget;
|
public static Widget selectedWidget;
|
||||||
|
public static Widget keyboardFocusWidget;
|
||||||
|
|
||||||
public void Tick(World world)
|
public void Tick(World world)
|
||||||
{
|
{
|
||||||
if (!world.GameHasStarted) return;
|
if (!world.GameHasStarted) return;
|
||||||
@@ -225,7 +226,7 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
if (selectedWidget != null)
|
if (selectedWidget != null)
|
||||||
return selectedWidget.HandleInput(mi);
|
return selectedWidget.HandleInput(mi);
|
||||||
|
|
||||||
if (rootWidget.HandleInput(mi))
|
if (rootWidget.HandleInput(mi))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@@ -247,6 +248,17 @@ namespace OpenRA
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public bool HandleKeyPress(System.Windows.Forms.KeyPressEventArgs e, Modifiers modifiers)
|
||||||
|
{
|
||||||
|
if (keyboardFocusWidget != null)
|
||||||
|
return keyboardFocusWidget.HandleKeyPress(e, modifiers);
|
||||||
|
|
||||||
|
if (rootWidget.HandleKeyPress(e, modifiers))
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public bool HitTest(int2 mousePos)
|
public bool HitTest(int2 mousePos)
|
||||||
{
|
{
|
||||||
if (selectedWidget != null)
|
if (selectedWidget != null)
|
||||||
|
|||||||
@@ -492,7 +492,10 @@ namespace OpenRA
|
|||||||
|
|
||||||
public static void HandleKeyPress(KeyPressEventArgs e, Modifiers modifiers)
|
public static void HandleKeyPress(KeyPressEventArgs e, Modifiers modifiers)
|
||||||
{
|
{
|
||||||
int sync = world.SyncHash();
|
int sync = world.SyncHash();
|
||||||
|
|
||||||
|
if (chrome.HandleKeyPress(e, modifiers))
|
||||||
|
return;
|
||||||
|
|
||||||
if (e.KeyChar == '\r')
|
if (e.KeyChar == '\r')
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -225,6 +225,7 @@
|
|||||||
<Compile Include="Traits\SharesCell.cs" />
|
<Compile Include="Traits\SharesCell.cs" />
|
||||||
<Compile Include="Traits\World\AircraftInfluence.cs" />
|
<Compile Include="Traits\World\AircraftInfluence.cs" />
|
||||||
<Compile Include="Traits\World\HazardLayer.cs" />
|
<Compile Include="Traits\World\HazardLayer.cs" />
|
||||||
|
<Compile Include="Widgets\TextFieldWidget.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||||
|
|||||||
98
OpenRA.Game/Widgets/TextFieldWidget.cs
Normal file
98
OpenRA.Game/Widgets/TextFieldWidget.cs
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
|
||||||
|
* This file is part of OpenRA.
|
||||||
|
*
|
||||||
|
* OpenRA is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* OpenRA is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System.Drawing;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace OpenRA.Widgets
|
||||||
|
{
|
||||||
|
class TextFieldWidget : Widget
|
||||||
|
{
|
||||||
|
string TextBuffer = "zomg text";
|
||||||
|
|
||||||
|
public TextFieldWidget()
|
||||||
|
: base()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextFieldWidget(Widget widget)
|
||||||
|
:base(widget)
|
||||||
|
{
|
||||||
|
TextBuffer = (widget as TextFieldWidget).TextBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool HandleInput(MouseInput mi)
|
||||||
|
{
|
||||||
|
// Are we able to handle this event?
|
||||||
|
if (!Visible || !GetEventBounds().Contains(mi.Location.X,mi.Location.Y))
|
||||||
|
return base.HandleInput(mi);
|
||||||
|
|
||||||
|
if (base.HandleInput(mi))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (mi.Event == MouseInputEvent.Down)
|
||||||
|
{
|
||||||
|
Chrome.keyboardFocusWidget = this;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool HandleKeyPress(System.Windows.Forms.KeyPressEventArgs e, Modifiers modifiers)
|
||||||
|
{
|
||||||
|
if (base.HandleKeyPress(e,modifiers))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
TypeChar(e.KeyChar);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void TypeChar(char c)
|
||||||
|
{
|
||||||
|
if (c == '\b' || c == 0x7f)
|
||||||
|
{
|
||||||
|
if (TextBuffer.Length > 0)
|
||||||
|
TextBuffer = TextBuffer.Remove(TextBuffer.Length - 1);
|
||||||
|
}
|
||||||
|
else if (!char.IsControl(c))
|
||||||
|
TextBuffer += c;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void DrawInner(World world)
|
||||||
|
{
|
||||||
|
var pos = DrawPosition();
|
||||||
|
int margin = 10;
|
||||||
|
WidgetUtils.DrawPanel("dialog3",
|
||||||
|
new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height ) );
|
||||||
|
|
||||||
|
var text = TextBuffer;
|
||||||
|
Game.chrome.renderer.BoldFont.DrawText(text,
|
||||||
|
new int2( pos.X + margin, pos.Y + Bounds.Height / 2)
|
||||||
|
- new int2(0, Game.chrome.renderer.BoldFont.Measure(text).Y / 2),
|
||||||
|
Color.White);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Widget Clone()
|
||||||
|
{
|
||||||
|
return new TextFieldWidget(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -51,6 +51,8 @@ namespace OpenRA.Widgets
|
|||||||
public Func<MouseInput,bool> OnMouseDown = mi => {return false;};
|
public Func<MouseInput,bool> OnMouseDown = mi => {return false;};
|
||||||
public Func<MouseInput,bool> OnMouseUp = mi => {return false;};
|
public Func<MouseInput,bool> OnMouseUp = mi => {return false;};
|
||||||
public Func<MouseInput,bool> OnMouseMove = mi => {return false;};
|
public Func<MouseInput,bool> OnMouseMove = mi => {return false;};
|
||||||
|
public Func<System.Windows.Forms.KeyPressEventArgs, Modifiers,bool> OnKeyPress = (e,modifiers) => {return false;};
|
||||||
|
|
||||||
public Func<bool> IsVisible;
|
public Func<bool> IsVisible;
|
||||||
|
|
||||||
public Widget() { IsVisible = () => Visible; }
|
public Widget() { IsVisible = () => Visible; }
|
||||||
@@ -72,6 +74,8 @@ namespace OpenRA.Widgets
|
|||||||
OnMouseDown = widget.OnMouseDown;
|
OnMouseDown = widget.OnMouseDown;
|
||||||
OnMouseUp = widget.OnMouseUp;
|
OnMouseUp = widget.OnMouseUp;
|
||||||
OnMouseMove = widget.OnMouseMove;
|
OnMouseMove = widget.OnMouseMove;
|
||||||
|
OnKeyPress = widget.OnKeyPress;
|
||||||
|
|
||||||
IsVisible = widget.IsVisible;
|
IsVisible = widget.IsVisible;
|
||||||
|
|
||||||
foreach(var child in widget.Children)
|
foreach(var child in widget.Children)
|
||||||
@@ -169,6 +173,17 @@ namespace OpenRA.Widgets
|
|||||||
throw new InvalidOperationException("Impossible");
|
throw new InvalidOperationException("Impossible");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual bool HandleKeyPress(System.Windows.Forms.KeyPressEventArgs e, Modifiers modifiers)
|
||||||
|
{
|
||||||
|
// Can any of our children handle this?
|
||||||
|
foreach (var child in Children)
|
||||||
|
if (child.HandleKeyPress(e, modifiers))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// Have we been assigned an action?
|
||||||
|
return OnKeyPress(e,modifiers);
|
||||||
|
}
|
||||||
|
|
||||||
public abstract void DrawInner( World world );
|
public abstract void DrawInner( World world );
|
||||||
|
|
||||||
public void Draw(World world)
|
public void Draw(World world)
|
||||||
|
|||||||
@@ -491,6 +491,20 @@ Container:
|
|||||||
Width:120
|
Width:120
|
||||||
Height:25
|
Height:25
|
||||||
Text:Change Map
|
Text:Change Map
|
||||||
|
TextField@CHAT_TEXTFIELD:
|
||||||
|
Id:CHAT_TEXTFIELD
|
||||||
|
Visible:true
|
||||||
|
X:PARENT_RIGHT-550
|
||||||
|
Y:300
|
||||||
|
Width:300
|
||||||
|
Height:25
|
||||||
|
TextField@CHAT_TEXTFIELD2:
|
||||||
|
Id:CHAT_TEXTFIELD2
|
||||||
|
Visible:true
|
||||||
|
X:PARENT_RIGHT-550
|
||||||
|
Y:250
|
||||||
|
Width:300
|
||||||
|
Height:25
|
||||||
Button@DISCONNECT_BUTTON:
|
Button@DISCONNECT_BUTTON:
|
||||||
Id:DISCONNECT_BUTTON
|
Id:DISCONNECT_BUTTON
|
||||||
Visible:true
|
Visible:true
|
||||||
|
|||||||
Reference in New Issue
Block a user