Fixed Bug

Textbox could type the wrong char sometimes
This commit is contained in:
JacobTech 2023-01-01 22:05:15 -05:00
parent 4d22c3a8d5
commit caeda301bc
2 changed files with 10 additions and 18 deletions

View File

@ -10,7 +10,7 @@
<IncludeSymbols>False</IncludeSymbols> <IncludeSymbols>False</IncludeSymbols>
<RepositoryUrl>https://git.jacobtech.com/JacobTech.com/GraphicsManager</RepositoryUrl> <RepositoryUrl>https://git.jacobtech.com/JacobTech.com/GraphicsManager</RepositoryUrl>
<RepositoryType>git</RepositoryType> <RepositoryType>git</RepositoryType>
<Version>1.0.0-alpha4</Version> <Version>1.0.0-alpha6</Version>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@ -2,6 +2,7 @@
using GraphicsManager.Interfaces; using GraphicsManager.Interfaces;
using GraphicsManager.Objects.Core; using GraphicsManager.Objects.Core;
using OpenTK.Mathematics; using OpenTK.Mathematics;
using OpenTK.Windowing.Common;
using OpenTK.Windowing.GraphicsLibraryFramework; using OpenTK.Windowing.GraphicsLibraryFramework;
namespace GraphicsManager.Objects; namespace GraphicsManager.Objects;
@ -110,38 +111,29 @@ public class Textbox : IRenderObject
this.Window = Window; this.Window = Window;
this.Window.MouseDown += Window_MouseDown; this.Window.MouseDown += Window_MouseDown;
this.Window.KeyDown += Window_KeyDown; this.Window.KeyDown += Window_KeyDown;
this.Window.TextInput += WindowOnTextInput;
Loaded = true; Loaded = true;
_bounds.LoadToParent(Parent, Window); _bounds.LoadToParent(Parent, Window);
_inside.LoadToParent(Parent, Window); _inside.LoadToParent(Parent, Window);
_label.LoadToParent(Parent, Window); _label.LoadToParent(Parent, Window);
Location = Location; Location = Location;
} }
private void WindowOnTextInput(TextInputEventArgs obj)
{
Text += obj.AsString;
}
private bool use = false; private bool use = false;
private void Window_KeyDown(OpenTK.Windowing.Common.KeyboardKeyEventArgs obj) private void Window_KeyDown(OpenTK.Windowing.Common.KeyboardKeyEventArgs obj)
{ {
if (!use) return; if (!use) return;
if (obj.Key == Keys.CapsLock || obj.Key == Keys.Menu || obj.Key == Keys.LeftSuper || obj.Key == Keys.RightSuper || obj.Key == Keys.End || obj.Key == Keys.Home || obj.Key == Keys.PageDown || obj.Key == Keys.PageUp || obj.Key == Keys.Insert || obj.Key == Keys.Up || obj.Key == Keys.Down || obj.Key == Keys.Left || obj.Key == Keys.Right) return; if (obj.Key == Keys.CapsLock || obj.Key == Keys.Menu || obj.Key == Keys.LeftSuper || obj.Key == Keys.RightSuper || obj.Key == Keys.End || obj.Key == Keys.Home || obj.Key == Keys.PageDown || obj.Key == Keys.PageUp || obj.Key == Keys.Insert || obj.Key == Keys.Up || obj.Key == Keys.Down || obj.Key == Keys.Left || obj.Key == Keys.Right) return;
if (obj.Key == Keys.Backspace) if (obj.Key == Keys.Backspace || obj.Key == Keys.Delete)
{ {
if (!(Text.Length > 0)) return; if (!(Text.Length > 0)) return;
Text = Text.Remove(Text.Length - 1, 1); Text = Text.Remove(Text.Length - 1, 1);
} }
else if (obj.Key == Keys.Delete)
{
if (!(Text.Length > 0)) return;
Text = Text.Remove(Text.Length - 1, 1);
}
else if (obj.Shift)
{
if (obj.Key == Keys.Enter || obj.Key == Keys.KeyPadEnter) Text += '\n';
else if (obj.Key == Keys.LeftShift || obj.Key == Keys.KeyPadEnter || obj.Key == Keys.Enter || obj.Key == Keys.End || obj.Key == Keys.Down) return;
else Text += ((char)obj.Key).ToString().ToUpper();
}
else if (obj.Command || obj.Alt || obj.Control) { }
else
{
Text += ((char)obj.Key).ToString().ToLower();
}
} }
private void Window_MouseDown(OpenTK.Windowing.Common.MouseButtonEventArgs e) private void Window_MouseDown(OpenTK.Windowing.Common.MouseButtonEventArgs e)