diff --git a/GraphicsManager/Enums/TextLocation.cs b/GraphicsManager/Enums/TextLocation.cs
index 1d51044..7a5605c 100644
--- a/GraphicsManager/Enums/TextLocation.cs
+++ b/GraphicsManager/Enums/TextLocation.cs
@@ -3,7 +3,5 @@ namespace GraphicsManager.Enums;
public enum TextLocation
{
TopLeft,
- PxLeft,
- TrueCenterLeft,
- PostiveTureCenterLeft
+ LineCenter
}
\ No newline at end of file
diff --git a/GraphicsManager/GraphicsManager.csproj b/GraphicsManager/GraphicsManager.csproj
index c2d1943..803fe6b 100644
--- a/GraphicsManager/GraphicsManager.csproj
+++ b/GraphicsManager/GraphicsManager.csproj
@@ -10,7 +10,7 @@
False
https://git.jacobtech.com/JacobTech.com/GraphicsManager
git
- 1.0.9-alpha07
+ 1.0.9-alpha29
@@ -33,7 +33,7 @@
-
+
diff --git a/GraphicsManager/Interfaces/IRenderObject.cs b/GraphicsManager/Interfaces/IRenderObject.cs
index db26e0c..2efc1cc 100755
--- a/GraphicsManager/Interfaces/IRenderObject.cs
+++ b/GraphicsManager/Interfaces/IRenderObject.cs
@@ -34,5 +34,6 @@ public interface IRenderObject
public event Func? Clicked;
public event Func? MouseLeave;
public event Func? MouseEnter;
+ public event Func? SizeChanged;
public event Func? WindowLoaded;
}
diff --git a/GraphicsManager/Objects/Core/Texture.cs b/GraphicsManager/Objects/Core/Texture.cs
index 5be6b8d..a241774 100755
--- a/GraphicsManager/Objects/Core/Texture.cs
+++ b/GraphicsManager/Objects/Core/Texture.cs
@@ -171,6 +171,37 @@ public class Texture
AdvanceY = ((Math.Abs(face.Descender) / (double)face.UnitsPerEM) * 16)
};
}
+
+ internal static Character GetChar(FontInteraction l, char charter, IGLFWGraphicsContext con)
+ {
+ try
+ {
+ if (!Label._characters[con].ContainsKey(l)) Label._characters[con].Add(l, new Dictionary());
+ if (Label._characters[con][l].ContainsKey(charter)) return Label._characters[con][l][(ushort)charter];
+ for (int i = 0; i < l.CurrentFonts.Length; i++)
+ {
+ try
+ {
+ l.CurrentFonts[i].Face.SetPixelSizes(0, l.PixelHeight);
+ l.CurrentFonts[i].Face.SelectCharmap(Encoding.Unicode);
+ }
+ catch
+ {
+ continue;
+ }
+ ushort temp = (charter);
+ if (l.CurrentFonts[i].Face.GetCharIndex(temp) == 0) continue;
+
+ return GetChar(l.CurrentFonts[i].Face, charter);
+ }
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine(e);
+ throw;
+ }
+ return GetChar(l.CurrentFonts[0].Face, (char)1);
+ }
internal static Character GetChar(FontInteraction l, char charter)
{
diff --git a/GraphicsManager/Objects/FlowLayout.cs b/GraphicsManager/Objects/FlowLayout.cs
index 85e6043..ad8ee4f 100644
--- a/GraphicsManager/Objects/FlowLayout.cs
+++ b/GraphicsManager/Objects/FlowLayout.cs
@@ -158,7 +158,7 @@ public class FlowLayout : ParentBase, IFlow
if (index < Controls.Length)
{
arg.Location = Controls[index].Location;
- Controls[index].Location = new(arg.Location.X, arg.Location.Y + arg.Size.Y, arg.Location.Z);
+ Controls[index].Location = new(arg.Location.X, Controls[index].Location.Y + arg.Size.Y, arg.Location.Z);
for (int i = index + 1; i < Controls.Length; i++)
{
Controls[i].Location = new(0, Controls[i - 1].Location.Y + Controls[i - 1].Size.Y, arg.Location.Z);
diff --git a/GraphicsManager/Objects/Label.cs b/GraphicsManager/Objects/Label.cs
index 0b0a03e..02b0e3d 100755
--- a/GraphicsManager/Objects/Label.cs
+++ b/GraphicsManager/Objects/Label.cs
@@ -32,6 +32,67 @@ public class Label : ILabel
public Vector2 LocationAsFloat { get { return laf; } }
public Vector2 SizeAsFloat { get { return saf; } }
+ private Vector2i? msize = null;
+ public Vector2i? MaxSize
+ {
+ get => msize;
+ set
+ {
+ msize = value;
+ text_Calculated = string.Empty;
+ float max_x = 0, lines = 1, char_x = 0F;
+ for (int i = 0; i < Text.Length; i++)
+ {
+ char c;
+ if (PasswordChar is null)
+ c = Text[i];
+ else
+ c = PasswordChar.Value;
+ bool n = (c == '\n');
+
+ if (n)
+ {
+ lines++;
+ text_Calculated += c;
+ char_x = 0f;
+ }
+ else
+ {
+ Character ch;
+ if (Window is not null) ch = Texture.GetChar(Font, c, Window.Context);
+ else ch = Texture.GetChar(Font, c);
+ if (i > 0 && text[i-1] == ' ')
+ {
+ int addc = 0;
+ float word_char_x = char_x;
+ while (MaxSize is not null)
+ {
+ if (addc + i == Text.Length) break;
+ if (text[addc + i] == ' ') break;
+ Character ch2;
+ if (Window is not null) ch2 = Texture.GetChar(Font, text[addc + i], Window.Context);
+ else ch2 = Texture.GetChar(Font, c);
+ word_char_x += (ch2.Advance >> 6) * Scale;
+ if (word_char_x > MaxSize.Value.X)
+ {
+ char_x = 0f;
+ lines++;
+ text_Calculated += '\n';
+ break;
+ }
+ addc++;
+ }
+ }
+ text_Calculated += c;
+ float w = ch.Size.X * Scale;
+ float xrel = char_x + ch.Bearing.X * Scale;
+ char_x += (ch.Advance >> 6) * Scale;
+ if ((xrel + w) >= max_x) max_x = (xrel + w);
+ }
+ }
+ Size = new((int)max_x, (int)(lines * LineHeight) + (int)(lines * Font.ExtraLinePixels));
+ }
+ }
private char? pc;
public char? PasswordChar
{
@@ -56,6 +117,7 @@ public class Label : ILabel
public static readonly Dictionary>> _characters = new();
private string text = string.Empty;
+ private string text_Calculated = string.Empty;
public int VAO { get; private set; }
public void Focus()
@@ -68,37 +130,31 @@ public class Label : ILabel
}
public int VBO { get; private set; }
public Vector2 DIR { get; set; } = new Vector2(1f, 0f);
-
- public int TrueHeight;
- public int PostiveTrueHeight;
-
+
public Vector2i GetSizeOfChar(int Index)
{
- float addy = Font.PixelHeight * Scale, addx = 0F, char_x = 0F;
- for (int i = 0; i < Index + 1; i++)
+ float mx = 0, my = 0;
+ char character;
+ if (PasswordChar is null)
+ character = Text[Index];
+ else
+ character = PasswordChar.Value;
+
+
+ if (character == '\n')
{
- char character;
- if (PasswordChar is null)
- character = Text[i];
- else
- character = PasswordChar.Value;
-
-
- if (character == '\n')
- {
- char_x = 0f;
- addy += Font.PixelHeight * Scale;
- addy += Font.ExtraLinePixels;
- continue;
- }
- Character cha = Texture.GetChar(Font, character);
- float w = cha.Size.X * Scale;
- float xrel = char_x + cha.Bearing.X * Scale;
- char_x += (cha.Advance >> 6) * Scale;
- if ((xrel + w) >= addx) addx = (xrel + w);
+ mx = 0f;
+ my += Font.PixelHeight * Scale;
}
-
- return new((int)addx, (int)addy);
+ else
+ {
+ Character cha;
+ if (Window is not null) cha = Texture.GetChar(Font, character, Window.Context);
+ else cha = Texture.GetChar(Font, character);
+ mx = cha.Size.X * Scale;
+ my = cha.Size.Y * Scale;
+ }
+ return new((int)mx, (int)my);
}
public string Text
@@ -108,40 +164,61 @@ public class Label : ILabel
{
if (value is null) value = string.Empty;
text = value;
- int line = 0;
- double nl = 0;
- double addy = 0f, addy2 =0f, addx = 0F, char_x = 0F;
- for (int i = 0; i < value.Length; i++)
+ text_Calculated = string.Empty;
+ float max_x = 0, lines = 1, char_x = 0F;
+ for (int i = 0; i < Text.Length; i++)
{
- char character;
+ char c;
if (PasswordChar is null)
- character = value[i];
+ c = Text[i];
else
- character = PasswordChar.Value;
+ c = PasswordChar.Value;
+ bool n = (c == '\n');
- if (character == '\n')
+ if (n)
{
+ lines++;
char_x = 0f;
- nl = addy;
- line++;
- continue;
+ text_Calculated += c;
}
- Character cha = Texture.GetChar(Font, character);
- double w = cha.Size.X * Scale;
- double xrel = char_x + cha.Bearing.X * Scale;
- double yrel = ((cha.Size.Y - cha.Bearing.Y) * Scale) + (Font.PixelHeight * Scale);
- yrel += nl;
- char_x += (cha.Advance >> 6) * Scale;
- if ((xrel + w) >= addx) addx = (xrel + w);
- if (yrel > addy) addy = yrel;
- if (line == 0)
+ else
{
- if (addy2 < cha.Bearing.Y) addy2 = cha.Bearing.Y;
+ Character ch;
+ if (Window is not null) ch = Texture.GetChar(Font, c, Window.Context);
+ else ch = Texture.GetChar(Font, c);
+ if (MaxSize is not null && i > 0 && text[i-1] == ' ')
+ {
+ int addc = 0;
+ float word_char_x = char_x;
+ while (true)
+ {
+ if (addc + i == Text.Length) break;
+ if (text[addc + i] == ' ') break;
+ Character ch2;
+ if (Window is not null) ch2 = Texture.GetChar(Font, text[addc + i], Window.Context);
+ else ch2 = Texture.GetChar(Font, c);
+ word_char_x += (ch2.Advance >> 6) * Scale;
+ if (word_char_x > MaxSize.Value.X)
+ {
+ char_x = 0f;
+ lines++;
+ text_Calculated += '\n';
+ break;
+ }
+ addc++;
+ }
+ }
+
+ text_Calculated += c;
+ float w = ch.Size.X * Scale;
+ float xrel = char_x + ch.Bearing.X * Scale;
+ char_x += (ch.Advance >> 6) * Scale;
+ if ((xrel + w) >= max_x) max_x = (xrel + w);
}
}
- Size = new((int)addx, (int)addy + (int)(line * Font.ExtraLinePixels));
- PostiveTrueHeight = (int)addy2;
- TrueHeight = (int)(addy - (Font.PixelHeight - addy2));
+
+
+ Size = new((int)max_x, (int)(lines * LineHeight) + (int)(lines * Font.ExtraLinePixels));
if (Loaded)
{
@@ -169,6 +246,13 @@ public class Label : ILabel
}
}
}
+ public uint LineHeight
+ {
+ get
+ {
+ return (uint)((Font.PixelHeight * (Font.CurrentFonts[0].Face.Height / (float)Font.CurrentFonts[0].Face.UnitsPerEM)) * Scale);
+ }
+ }
public Shader Shader { get; set; } = null!;
public FontInteraction Font { get; }
public float Scale { get; set; } = 1.0f;
@@ -204,38 +288,33 @@ public class Label : ILabel
public Vector2i GetCharLocation(int index)
{
- int line = 0;
- double nl = 0;
- double addy = 0f, addy2 =0f, addx = 0F, char_x = 0F;
+ float max_x = 0, lines = 0, char_x = 0F;
for (int i = 0; i < index; i++)
{
- char character;
+ char c;
if (PasswordChar is null)
- character = Text[i];
+ c = text_Calculated[i];
else
- character = PasswordChar.Value;
+ c = PasswordChar.Value;
+ bool n = (c == '\n');
- if (character == '\n')
+ if (n)
{
+ lines++;
char_x = 0f;
- nl = addy;
- line++;
- continue;
}
- Character cha = Texture.GetChar(Font, character);
- double w = cha.Size.X * Scale;
- double xrel = char_x + cha.Bearing.X * Scale;
- double yrel = ((cha.Size.Y - cha.Bearing.Y) * Scale) + (Font.PixelHeight * Scale);
- yrel += nl;
- char_x += (cha.Advance >> 6) * Scale;
- if ((xrel + w) >= addx) addx = (xrel + w);
- if (yrel > addy) addy = yrel;
- if (line == 0)
+ else
{
- if (addy2 < cha.Bearing.Y) addy2 = cha.Bearing.Y;
+ Character ch;
+ if (Window is not null) ch = Texture.GetChar(Font, c, Window.Context);
+ else ch = Texture.GetChar(Font, c);
+ float w = ch.Size.X * Scale;
+ float xrel = char_x + ch.Bearing.X * Scale;
+ char_x += (ch.Advance >> 6) * Scale;
+ max_x = (xrel + w);
}
}
- return new((int)addx, (int)(line * Font.ExtraLinePixels) + (int)(Font.PixelHeight * line));
+ return new((int)max_x, (int)(lines * LineHeight) + (int)(lines * Font.ExtraLinePixels));
}
public void Clean()
@@ -260,6 +339,8 @@ public class Label : ILabel
Visible = false;
}
+ public event Func? SizeChanged;
+
public void Draw(int x, int y, int ww, int hh)
{
if (Visible && Loaded && this.Font is not null)
@@ -296,23 +377,22 @@ public class Label : ILabel
}));
float hhh = 0f;
- for (int i = 0; i < Text.Length; i++)
+ for (int i = 0; i < text_Calculated.Length; i++)
{
char c;
if (PasswordChar is null)
- c = Text[i];
+ c = text_Calculated[i];
else
c = PasswordChar.Value;
bool n = (c == '\n');
if (!_characters[Window!.Context][Font].ContainsKey(c) && !n)
{
- Texture f = Texture.TextureForChar(Window!.Context, Font, c, Shader);
+ _ = Texture.TextureForChar(Window!.Context, Font, c, Shader);
}
- int maxx = 0;
if (n)
{
- hhh += Font.PixelHeight * Scale;
+ hhh += LineHeight;
hhh += Font.ExtraLinePixels;
char_x = 0f;
}
@@ -320,6 +400,7 @@ public class Label : ILabel
{
if (!_characters[Window!.Context][Font].ContainsKey(c)) continue;
Character ch = _characters[Window!.Context][Font][c];
+
float w = ch.Size.X * Scale;
float h = ch.Size.Y * Scale;
float xrel = char_x + ch.Bearing.X * Scale;
diff --git a/GraphicsManager/Objects/RainbowLabel.cs b/GraphicsManager/Objects/RainbowLabel.cs
index f6b2167..90c705a 100755
--- a/GraphicsManager/Objects/RainbowLabel.cs
+++ b/GraphicsManager/Objects/RainbowLabel.cs
@@ -219,6 +219,8 @@ public class RainbowLabel : ILabel
Visible = false;
}
public Vector2i ScissorLocation { get; private set; }
+
+ public event Func? SizeChanged;
public void Draw(int x, int y, int ww, int hh)
{
diff --git a/GraphicsManager/Objects/Rectangle.cs b/GraphicsManager/Objects/Rectangle.cs
index 2c3d57c..69ca350 100755
--- a/GraphicsManager/Objects/Rectangle.cs
+++ b/GraphicsManager/Objects/Rectangle.cs
@@ -292,6 +292,8 @@ public class Rectangle : ITextureObject
}
}
}
+
+ public event Func? SizeChanged;
public ushort[] Indexs { get; set; } = new ushort[6] { 0, 1, 3, 1, 2, 3 };
public BufferUsageHint Hint { get; set; } = BufferUsageHint.StaticDraw;
@@ -658,6 +660,7 @@ public class Rectangle : ITextureObject
}
Points = temp;
+ if (SizeChanged is not null) SizeChanged.Invoke(this);
}
}
diff --git a/GraphicsManager/Objects/TexturedTextBox.cs b/GraphicsManager/Objects/TexturedTextBox.cs
deleted file mode 100755
index e3d93f8..0000000
--- a/GraphicsManager/Objects/TexturedTextBox.cs
+++ /dev/null
@@ -1,307 +0,0 @@
-using GraphicsManager.Enums;
-using GraphicsManager.Interfaces;
-using GraphicsManager.Objects.Core;
-using OpenTK.Graphics.OpenGL4;
-using OpenTK.Mathematics;
-using OpenTK.Windowing.Common;
-using OpenTK.Windowing.Common.Input;
-using OpenTK.Windowing.GraphicsLibraryFramework;
-
-namespace GraphicsManager.Objects;
-
-public class TexturedTextBox : Rectangle
-{
- private Label _label;
- private Label _watermark;
-
- public TextLocation TextLocation { get; set; } = TextLocation.TopLeft;
-
- public TexturedTextBox(Texture texture, FontFamily LabelFam, FontFamily WaterFam)
- :base(texture)
- {
- base.HoverMouse = MouseCursor.IBeam;
- _label = new Label(LabelFam)
- {
- HoverMouse = MouseCursor.IBeam,
- IgnoreHover = true
- };
- TextureDisplay = TextureDisplay.HorizontalCenter;
- _watermark = new(WaterFam)
- {
- Color = new(128, 128, 128, 255),
- HoverMouse = MouseCursor.IBeam,
- IgnoreHover = true
- };
- }
-
- public override MouseCursor HoverMouse
- {
- get => base.HoverMouse;
- set
- {
- _watermark.HoverMouse = value;
- _label.HoverMouse = value;
- base.HoverMouse = value;
- }
- }
-
- public int Border { get; set; } = 2;
-
- public TexturedTextBox(Texture texture, FontInteraction LabelFam, FontInteraction WaterFam)
- :base(texture)
- {
- base.HoverMouse = MouseCursor.IBeam;
- _label = new Label(LabelFam)
- {
- HoverMouse = MouseCursor.IBeam,
- IgnoreHover = true
- };
- TextureDisplay = TextureDisplay.HorizontalCenter;
- _watermark = new(WaterFam)
- {
- Color = new(128, 128, 128, 255),
- HoverMouse = MouseCursor.IBeam,
- IgnoreHover = true
- };
- }
-
- public FontInteraction Font { get => _label.Font; }
- public string Text
- {
- get => _label.Text;
- set
- {
- int old = _label.TrueHeight;
- _label.Text = value;
- if (!string.IsNullOrEmpty(value))
- {
- bool f = false;
- if (!_label.Visible)
- {
- f = true;
- _label.Visible = true;
- _label.Location = TextLocation switch
- {
- TextLocation.TrueCenterLeft => new(Location.X + Border + 5, Location.Y + ((Size.Y - _label.TrueHeight) / 2) - (_label.Size.Y - _label.TrueHeight), Location.Z),
- TextLocation.PostiveTureCenterLeft => new(Location.X + Border + 5, Location.Y + ((Size.Y - _label.PostiveTrueHeight) / 2) - _label.Size.Y + _label.TrueHeight, Location.Z),
- TextLocation.PxLeft => new(Location.X + Border + 5, Location.Y + ((Size.Y - _label.Size.Y) / 2), Location.Z),
- _ => new(Location.X + Border + 5, Location.Y + Border + 5, Location.Z)
- };
- _watermark.Location = _label.Location;
- }
- if (_watermark.Visible) _watermark.Visible = false;
- if (!f && TextLocation == TextLocation.TrueCenterLeft && old != _label.TrueHeight)
- {
- _label.Location = new(Location.X + Border + 5, Location.Y + ((Size.Y - _label.TrueHeight) / 2) - (_label.Size.Y - _label.TrueHeight), Location.Z);
- _watermark.Location = _label.Location;
- }
- }
- else
- {
- if (_label.Visible) _label.Visible = false;
- if (!_watermark.Visible)
- {
- _watermark.Visible = true;
- _watermark.Location = TextLocation switch
- {
- TextLocation.TrueCenterLeft => new(Location.X + Border + 5, Location.Y + ((Size.Y - _watermark.TrueHeight) / 2) - (_watermark.Size.Y - _watermark.TrueHeight), Location.Z),
- TextLocation.PostiveTureCenterLeft => new(Location.X + Border + 5, Location.Y + ((Size.Y - _label.PostiveTrueHeight) / 2) - _label.Size.Y + _label.TrueHeight, Location.Z),
- TextLocation.PxLeft => new(Location.X + Border + 5, Location.Y + ((Size.Y - _watermark.Size.Y) / 2), Location.Z),
- _ => new(Location.X + Border + 5, Location.Y + Border + 5, Location.Z)
- };
- _label.Location = _label.Location;
- }
- }
- }
- }
-
- public FontInteraction WatermarkFont { get => _watermark.Font; }
- public string WatermarkText
- {
- get
- {
- return _watermark.Text;
- }
- set
- {
- _watermark.Text = value;
- }
- }
- public char? PasswordChar { get => _label.PasswordChar; set => _label.PasswordChar = value; }
- public override Vector2i Size
- {
- get
- {
- return base.Size;
- }
- set
- {
- if (base.Size == value) return;
- base.Size = value;
- }
- }
- public override Vector3i Location {
- get => base.Location;
- set
- {
- Vector3i diff = base.Location - value;
- base.Location = value;
- if (_watermark.Visible && !string.IsNullOrEmpty(_watermark.Text))
- {
- _watermark.Location = TextLocation switch
- {
- TextLocation.TrueCenterLeft => new(value.X + Border + 5, value.Y + ((Size.Y - _watermark.TrueHeight) / 2) - (_watermark.Size.Y - _watermark.TrueHeight), Location.Z),
- TextLocation.PostiveTureCenterLeft => new(value.X + Border + 5, value.Y + ((Size.Y - _label.PostiveTrueHeight) / 2) - _label.Size.Y + _label.TrueHeight, Location.Z),
- TextLocation.PxLeft => new(value.X + Border + 5, value.Y + ((Size.Y - _watermark.Size.Y) / 2), Location.Z),
- _ => new(value.X + Border + 5, value.Y + Border + 5, Location.Z)
- };
- _label.Location = _watermark.Location;
- }
- else
- {
- _label.Location = TextLocation switch
- {
- TextLocation.TrueCenterLeft => new(value.X + Border + 5, value.Y + ((Size.Y - _label.TrueHeight) / 2) - (_label.Size.Y - _label.TrueHeight), Location.Z),
- TextLocation.PostiveTureCenterLeft => new(value.X + Border + 5, value.Y + ((Size.Y - _label.PostiveTrueHeight) / 2) - _label.Size.Y + _label.TrueHeight, Location.Z),
- TextLocation.PxLeft => new(value.X + Border + 5, value.Y + ((Size.Y - _label.Size.Y) / 2), Location.Z),
- _ => new(value.X + Border + 5, value.Y + Border + 5, Location.Z)
- };
- _watermark.Location = _label.Location;
- }
- }
- }
-
- public Color4 TextColor { get => _label.Color; set => _label.Color = value; }
- public Color4 WatermarkColor { get => _watermark.Color; set => _watermark.Color = value; }
-
- public override bool Visible
- {
- get => base.Visible;
- set
- {
- if (value == base.Visible) return;
- if (value)
- {
- if (!string.IsNullOrEmpty(_label.Text))
- {
- _label.Visible = true;
- _watermark.Visible = false;
- }
- else
- {
- _label.Visible = false;
- _watermark.Visible = true;
- }
- }
- else
- {
- _label.Visible = value;
- _watermark.Visible = value;
- }
-
- base.Visible = value;
- }
- }
-
- public override void Clean()
- {
- _label.Clean();
- _watermark.Clean();
- base.Clean();
- }
-
-
- public override void Draw(int x, int y, int w, int h)
- {
- if (!Visible || !Loaded) return;
- int nx = x, ny = y, nw = w, nh = h;
- if (Location.X > nw)
- return;
- else
- {
- nx += Location.X;
- nw -= Location.X;
- if (Size.X < nw)
- nw = Size.X;
- }
-
- if (Location.Y > nh)
- return;
- else
- {
- ny += Location.Y;
- nh -= Location.Y;
- if (Size.Y < nh)
- nh = Size.Y;
- }
- if (nw == 0 || nh == 0) return;
- GL.Scissor(nx, Window!.Size.Y - ny - nh, nw, nh);
- base.Draw(nx,ny,nw,nh);
- GL.Scissor(nx, Window!.Size.Y - ny - nh, nw, nh);
- if (!string.IsNullOrEmpty(_label.Text)) _label.Draw(nx,ny,nw,nh);
- else _watermark.Draw(nx,ny,nw,nh);
- }
-
- public override void LoadToParent(IParent parent, IWindow window)
- {
- if (Loaded) return;
- window.MouseDown += Window_MouseDown;
- window.KeyDown += Window_KeyDown;
- window.TextInput += WindowOnTextInput;
- if (!window.Context.IsCurrent) window.Context.MakeCurrent();
- _label.LoadToParent(parent, window);
- _watermark.LoadToParent(parent, window);
- base.LoadToParent(parent, window);
- }
-
- private void WindowOnTextInput(TextInputEventArgs obj)
- {
- if (!use) return;
- Text += obj.AsString;
- }
-
- private bool use;
- public event Func? KeyPress;
-
- public override void UnFocus()
- {
- use = false;
- if (Window is not null && Window.focused == this)
- Window.focused = null;
- }
- public override void Focus()
- {
- if (Window is not null)
- {
- if (Window.focused is not null)
- {
- Window.focused.UnFocus();
- }
-
- Window.focused = this;
- use = true;
- }
- }
- private void Window_KeyDown(KeyboardKeyEventArgs obj)
- {
- 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.Backspace || obj.Key == Keys.Delete)
- {
- if (!(Text.Length > 0)) return;
- Text = Text.Remove(Text.Length - 1, 1);
- }
- if (obj.Key == Keys.V && obj.Control && Window is not null) Text += Window.ClipboardString;
- if (KeyPress is not null) _ = KeyPress.Invoke(obj);
- }
-
- private void Window_MouseDown(MouseButtonEventArgs e)
- {
- if (MouseInside && e.Button == MouseButton.Button1)
- {
- use = true;
- Focus();
- }
- else use = false;
- }
-}
diff --git a/GraphicsManager/Window.cs b/GraphicsManager/Window.cs
index 82d3669..58796d1 100755
--- a/GraphicsManager/Window.cs
+++ b/GraphicsManager/Window.cs
@@ -245,6 +245,9 @@ public class Window : NativeWindow , IWindow
public void ParentResize(ResizeEventArgs e)
{
base.OnResize(e);
+
+
+
if (e.Width == 0 && e.Height == 0 && WindowState != WindowState.Fullscreen) return;
GL.Viewport(0, 0, e.Width, e.Height);
Matrix4.CreateOrthographicOffCenter(0.0f, 800.0f, 0.0f, 600.0f, 0.1f, 100.0f);
@@ -285,13 +288,12 @@ public class Window : NativeWindow , IWindow
public void ProcessEvent()
{
- ProcessEvents();
+ ProcessEvents(10);
}
public void StartRender()
{
Context.MakeCurrent();
initthread = Thread.CurrentThread.ManagedThreadId;
- //GL.Enable(EnableCap.DepthTest);
MouseMove += WhenMouseMove;
GLFW.PollEvents();
DrawFrame();