What am I doing

This commit is contained in:
JacobTech 2023-01-29 21:06:01 -05:00
parent df9b68c440
commit 910b7f43e7
13 changed files with 208 additions and 56 deletions

View File

@ -1,5 +1,7 @@
using System.Diagnostics; using System.Diagnostics;
using System.Net;
using System.Reflection; using System.Reflection;
using System.Runtime.InteropServices;
using GraphicsManager; using GraphicsManager;
using GraphicsManager.Enums; using GraphicsManager.Enums;
using GraphicsManager.Interfaces; using GraphicsManager.Interfaces;
@ -12,6 +14,7 @@ using Luski.net;
using Luski.net.Enums; using Luski.net.Enums;
using Luski.net.Interfaces; using Luski.net.Interfaces;
using Luski.net.JsonTypes; using Luski.net.JsonTypes;
using OpenTK.Graphics.OpenGL4;
using OpenTK.Mathematics; using OpenTK.Mathematics;
using OpenTK.Windowing.Desktop; using OpenTK.Windowing.Desktop;
using OpenTK.Windowing.Common; using OpenTK.Windowing.Common;
@ -28,7 +31,8 @@ public class MainScreen : Window
APIVersion = new Version(3, 2), APIVersion = new Version(3, 2),
StartFocused = true, StartFocused = true,
Size = new Vector2i((int)(240.5 * Globals.Settings.Scale), (int)(419 * Globals.Settings.Scale)), Size = new Vector2i((int)(240.5 * Globals.Settings.Scale), (int)(419 * Globals.Settings.Scale)),
Icon = Globals.Icon Icon = Globals.Icon,
SharedContext = null
}; };
private TabControl tc; private TabControl tc;
@ -37,10 +41,50 @@ public class MainScreen : Window
public Chat? chat; public Chat? chat;
Login login; Login login;
CreateAccount ca; CreateAccount ca;
private static DebugProc DebugMessageDelegate = OnDebugMessage;
private static void OnDebugMessage(
DebugSource source, // Source of the debugging message.
DebugType type, // Type of the debugging message.
int id, // ID associated with the message.
DebugSeverity severity, // Severity of the message.
int length, // Length of the string in pMessage.
IntPtr pMessage, // Pointer to message string.
IntPtr pUserParam) // The pointer you gave to OpenGL, explained later.
{
// In order to access the string pointed to by pMessage, you can use Marshal
// class to copy its contents to a C# string without unsafe code. You can
// also use the new function Marshal.PtrToStringUTF8 since .NET Core 1.1.
string message = Marshal.PtrToStringAnsi(pMessage, length);
// The rest of the function is up to you to implement, however a debug output
// is always useful.
return;
switch (severity)
{
case DebugSeverity.DebugSeverityHigh:
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.WriteLine("[{0} source={1} type={2} id={3}] {4}", severity, source, type, id, message);
Console.ResetColor();
break;
case DebugSeverity.DebugSeverityMedium:
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("[{0} source={1} type={2} id={3}] {4}", severity, source, type, id, message);
Console.ResetColor();
break;
default:
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(message);
Console.ResetColor();
break;
}
}
public MainScreen() : base(Settings) public MainScreen() : base(Settings)
{ {
VSync = VSyncMode.On; VSync = VSyncMode.On;
GL.DebugMessageCallback(DebugMessageDelegate, IntPtr.Zero);
GL.Enable(EnableCap.DebugOutput);
Globals.DefaultFont = Globals.DefaultFont =
Font.MakeEmbeddedFont("Luski.Resources.Fonts.OpenSans-Regular.ttf", Assembly.GetExecutingAssembly()); Font.MakeEmbeddedFont("Luski.Resources.Fonts.OpenSans-Regular.ttf", Assembly.GetExecutingAssembly());
Globals.DefaultFont.PixelHeight = (uint)(12 * Globals.Settings.Scale); Globals.DefaultFont.PixelHeight = (uint)(12 * Globals.Settings.Scale);
@ -53,6 +97,7 @@ public class MainScreen : Window
ca.Visible = false; ca.Visible = false;
ca.ChangeToApp += LoginOnChangeToApp; ca.ChangeToApp += LoginOnChangeToApp;
Controls.Add(login = new Login()); Controls.Add(login = new Login());
login.ChangeToApp += LoginOnChangeToApp; login.ChangeToApp += LoginOnChangeToApp;
login.ChangeToCa += LoginOnChangeToCa; login.ChangeToCa += LoginOnChangeToCa;
@ -62,9 +107,17 @@ public class MainScreen : Window
}); });
t.Start(); t.Start();
WindowLoaded += OnWindowLoaded; WindowLoaded += OnWindowLoadedd;
} }
private Task OnWindowLoadedd(Window arg)
{
Console.WriteLine(login.r.Location.Y);
Console.WriteLine(login.r.ScissorLocation.Y);
Console.WriteLine(login.r.Location.X);
Console.WriteLine(login.r.ScissorLocation.X);
return Task.CompletedTask;
}
private Task OnWindowLoaded(Window arg) private Task OnWindowLoaded(Window arg)
{ {
if (Globals.UpdaterSettings.AutoUpdateCheck && new HttpClient().GetAsync($"https://www.jacobtech.com/Updater/GetProgramVersion?directory=Luski&branch={Globals.UpdaterSettings.Branch}&selfcontained={Globals.UpdaterSettings.SelfContained.ToString().ToLower()}&platform={Globals.UpdaterSettings.Platform}").Result.Content.ReadAsStringAsync().Result != FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion) if (Globals.UpdaterSettings.AutoUpdateCheck && new HttpClient().GetAsync($"https://www.jacobtech.com/Updater/GetProgramVersion?directory=Luski&branch={Globals.UpdaterSettings.Branch}&selfcontained={Globals.UpdaterSettings.SelfContained.ToString().ToLower()}&platform={Globals.UpdaterSettings.Platform}").Result.Content.ReadAsStringAsync().Result != FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion)
@ -168,13 +221,13 @@ public class MainScreen : Window
foreach (SocketMessage message in messages.Reverse()) foreach (SocketMessage message in messages.Reverse())
{ {
if (channelCancellationToken.Token.IsCancellationRequested) return; if (channelCancellationToken is null || channelCancellationToken.Token.IsCancellationRequested) return;
Invoke(new Action(() => Invoke(new Action(() =>
{ {
chat!.AddMessage(message); chat!.AddMessage(TextureManager, message);
})); }));
} }
if (channelCancellationToken.Token.IsCancellationRequested) return; if (channelCancellationToken is null || channelCancellationToken.Token.IsCancellationRequested) return;
channelCancellationToken = null; channelCancellationToken = null;
Invoke(new Action(() => Invoke(new Action(() =>
{ {
@ -211,10 +264,10 @@ public class MainScreen : Window
DateTime start1 = DateTime.Now; DateTime start1 = DateTime.Now;
WindowBorder = WindowBorder.Resizable; WindowBorder = WindowBorder.Resizable;
BackgroundColor = new Color4(34, 34, 34, 255); BackgroundColor = new Color4(34, 34, 34, 255);
Controls.Add(new Rectangle(TextureManager.AddTexture(Globals.Luski.CurrentUser.GetAvatar(CancellationToken.None).Result)) { Anchor = ObjectAnchor.Bottom | ObjectAnchor.Left, Size = new((int)(35 * Globals.Settings.Scale)), Location = new((int)(47 * Globals.Settings.Scale), (int)(624 * Globals.Settings.Scale))}); Controls.Add(new Rectangle(TextureManager.AddTexture(Globals.Luski.CurrentUser.GetAvatar(CancellationToken.None).Result, true)) { Anchor = ObjectAnchor.Bottom | ObjectAnchor.Left, Size = new((int)(35 * Globals.Settings.Scale)), Location = new((int)(47 * Globals.Settings.Scale), (int)(624 * Globals.Settings.Scale))});
Controls.Add(new Label(){ Font = Globals.DefaultFont, Anchor = ObjectAnchor.Bottom | ObjectAnchor.Left, Location = new((int)(86 * Globals.Settings.Scale), (int)(635.5 * Globals.Settings.Scale)), Text = Globals.Luski.CurrentUser.Username}); Controls.Add(new Label(){ Font = Globals.DefaultFont, Anchor = ObjectAnchor.Bottom | ObjectAnchor.Left, Location = new((int)(86 * Globals.Settings.Scale), (int)(635.5 * Globals.Settings.Scale)), Text = Globals.Luski.CurrentUser.Username});
FlowLayout ser; FlowLayout ser;
Controls.Add(chat = new(this) {Location = new((int)(270 * Globals.Settings.Scale),0)}); Controls.Add(chat = new() {Location = new((int)(270 * Globals.Settings.Scale),0)});
Controls.Add(ser = new FlowLayout() Controls.Add(ser = new FlowLayout()
{ {
BackgroundColor = new(26, 26, 26, 255), BackgroundColor = new(26, 26, 26, 255),
@ -246,7 +299,6 @@ public class MainScreen : Window
{ {
Size = new((int)(40 * Globals.Settings.Scale)), Size = new((int)(40 * Globals.Settings.Scale)),
}); });
Controls.Add(channelpicker = new FlowLayout() Controls.Add(channelpicker = new FlowLayout()
{ {
BackgroundColor = new(34,34,34,255), BackgroundColor = new(34,34,34,255),
@ -269,13 +321,14 @@ public class MainScreen : Window
SocketTextChannel chan = Globals.Luski.GetChannel<SocketTextChannel>(Globals.Luski.CurrentUser.SelectedChannel, CancellationToken.None).Result; SocketTextChannel chan = Globals.Luski.GetChannel<SocketTextChannel>(Globals.Luski.CurrentUser.SelectedChannel, CancellationToken.None).Result;
chat.UpdateTitle(chans.First(s => s.Channel.Id == chan.Id)); chat.UpdateTitle(chans.First(s => s.Channel.Id == chan.Id));
chat.MessageFlow.BlockDraw = true;
try try
{ {
IReadOnlyList<SocketMessage> messages = chan.GetMessages(CancellationToken.None, Globals.Settings.LoadPerChannel).Result; IReadOnlyList<SocketMessage> messages = chan.GetMessages(CancellationToken.None, Globals.Settings.LoadPerChannel).Result;
Console.WriteLine("Messages done in " + (DateTime.Now - start).TotalSeconds + " seconds"); Console.WriteLine("Messages done in " + (DateTime.Now - start).TotalSeconds + " seconds");
foreach (SocketMessage message in messages.Reverse()) foreach (SocketMessage message in messages.Reverse())
{ {
chat.AddMessage(message); chat.AddMessage(TextureManager, message);
} }
chat.MessageFlow.ScrollToBottom(); chat.MessageFlow.ScrollToBottom();
} }
@ -285,6 +338,7 @@ public class MainScreen : Window
ChannelOnClickCon(chans.Where(s => s.Channel.Id == 0).First()); ChannelOnClickCon(chans.Where(s => s.Channel.Id == 0).First());
} }
chat.MessageFlow.BlockDraw = false;
Console.WriteLine("Messages Fonts done in " + (DateTime.Now - start).TotalSeconds + " seconds"); Console.WriteLine("Messages Fonts done in " + (DateTime.Now - start).TotalSeconds + " seconds");
foreach (SocketRemoteUser cufr in Globals.Luski.CurrentUser.FriendRequests) foreach (SocketRemoteUser cufr in Globals.Luski.CurrentUser.FriendRequests)

View File

@ -1,6 +1,7 @@
using GraphicsManager.Enums; using GraphicsManager.Enums;
using GraphicsManager.Interfaces; using GraphicsManager.Interfaces;
using GraphicsManager.Objects; using GraphicsManager.Objects;
using GraphicsManager.Objects.Core;
using Luski.GUI.MainScreen.Interfaces; using Luski.GUI.MainScreen.Interfaces;
using Luski.net; using Luski.net;
using Luski.net.Enums; using Luski.net.Enums;
@ -14,13 +15,12 @@ namespace Luski.GUI.MainScreen.UI;
public class Chat : UserControl public class Chat : UserControl
{ {
public FlowLayout MessageFlow; public FlowLayout MessageFlow;
private UserControl titlecon, typecon; private UserControl titlecon;//, typecon;
private Label title, desc; private Label title, desc;
private Textbox tb; private Textbox tb;
private SocketTextChannel? Channel = null; private SocketTextChannel? Channel = null;
public Chat(MainScreen screen) public Chat()
{ {
screen.MainShow += ScreenOnMainShow;
Size = new((int)(754 * Globals.Settings.Scale), (int)(667 * Globals.Settings.Scale)); Size = new((int)(754 * Globals.Settings.Scale), (int)(667 * Globals.Settings.Scale));
BackgroundColor = new(50, 50, 50, 255); BackgroundColor = new(50, 50, 50, 255);
Anchor = ObjectAnchor.All; Anchor = ObjectAnchor.All;
@ -33,7 +33,7 @@ public class Chat : UserControl
HScrollPixels = Globals.Settings.PerScrollPixels HScrollPixels = Globals.Settings.PerScrollPixels
}); });
Controls.Add(titlecon = new UserControl(){Anchor = ObjectAnchor.Left | ObjectAnchor.Top | ObjectAnchor.Right, Size = new((int)(754 * Globals.Settings.Scale), (int)(40 * Globals.Settings.Scale)), BackgroundColor = BackgroundColor}); Controls.Add(titlecon = new UserControl(){Anchor = ObjectAnchor.Left | ObjectAnchor.Top | ObjectAnchor.Right, Size = new((int)(754 * Globals.Settings.Scale), (int)(40 * Globals.Settings.Scale)), BackgroundColor = BackgroundColor});
Controls.Add(typecon = new UserControl(){Anchor = ObjectAnchor.Left | ObjectAnchor.Bottom | ObjectAnchor.Right, Location = new(0, (int)(626 * Globals.Settings.Scale)), Size = new((int)(754 * Globals.Settings.Scale), (int)(41 * Globals.Settings.Scale)), BackgroundColor = BackgroundColor}); //Controls.Add(typecon = new UserControl(){Anchor = ObjectAnchor.Left | ObjectAnchor.Bottom | ObjectAnchor.Right, Location = new(0, (int)(626 * Globals.Settings.Scale)), Size = new((int)(754 * Globals.Settings.Scale), (int)(41 * Globals.Settings.Scale)), BackgroundColor = BackgroundColor});
titlecon.Controls.Add(title = new Label() titlecon.Controls.Add(title = new Label()
{ {
Font = Globals.DefaultFont, Location = new( Font = Globals.DefaultFont, Location = new(
@ -41,22 +41,18 @@ public class Chat : UserControl
(int)((20 * Globals.Settings.Scale) - (Globals.DefaultFont.PixelHeight / 2))) (int)((20 * Globals.Settings.Scale) - (Globals.DefaultFont.PixelHeight / 2)))
}); });
titlecon.Controls.Add(desc = new Label(){ Font = Globals.DefaultFont, Color = new(161,161,161,255), Location = new(title.Location.X + title.Size.X + 5, title.Location.Y)}); titlecon.Controls.Add(desc = new Label(){ Font = Globals.DefaultFont, Color = new(161,161,161,255), Location = new(title.Location.X + title.Size.X + 5, title.Location.Y)});
typecon.Controls.Add(tb = new Textbox() //typecon.Controls.Add();
Controls.Add(tb = new Textbox()
{ {
Font = Globals.DefaultFont, Font = Globals.DefaultFont,
InsideColor = new(28, 28, 28, 255), InsideColor = new(28, 28, 28, 255),
BorderColor = Color4.DarkCyan, BorderColor = Color4.DarkCyan,
Location = new((int)(7.5 * Globals.Settings.Scale)), Location = new((int)(7.5 * Globals.Settings.Scale), (int)(633.5 * Globals.Settings.Scale)),
Size = new((int)(739 * Globals.Settings.Scale), (int)(26 * Globals.Settings.Scale)), Size = new((int)(739 * Globals.Settings.Scale), (int)(26 * Globals.Settings.Scale)),
Anchor = ObjectAnchor.All Anchor = ObjectAnchor.All
}); });
tb.KeyPress += TbOnKeyPress; tb.KeyPress += TbOnKeyPress;
}
private Task ScreenOnMainShow()
{
Globals.Luski.MessageReceived += LuskiOnMessageReceived; Globals.Luski.MessageReceived += LuskiOnMessageReceived;
return Task.CompletedTask;
} }
private Task TbOnKeyPress(KeyboardKeyEventArgs arg) private Task TbOnKeyPress(KeyboardKeyEventArgs arg)
@ -78,7 +74,7 @@ public class Chat : UserControl
if (Channel!.Id != arg.ChannelID) return Task.CompletedTask; if (Channel!.Id != arg.ChannelID) return Task.CompletedTask;
IRenderObject? reff = null; IRenderObject? reff = null;
if (MessageFlow.Controls.Length > 0) reff = MessageFlow.Controls[MessageFlow.Controls.Length - 1]; if (MessageFlow.Controls.Length > 0) reff = MessageFlow.Controls[MessageFlow.Controls.Length - 1];
AddMessage(arg); AddMessage(Window!.TextureManager, arg);
if (reff is null || (reff.Location.Y + reff.Size.Y <= MessageFlow.Size.Y && reff.Location.X >= 0)) Window.Invoke(new Action(() => { MessageFlow.ScrollToBottom();})); if (reff is null || (reff.Location.Y + reff.Size.Y <= MessageFlow.Size.Y && reff.Location.X >= 0)) Window.Invoke(new Action(() => { MessageFlow.ScrollToBottom();}));
return Task.CompletedTask; return Task.CompletedTask;
@ -116,7 +112,7 @@ public class Chat : UserControl
private long? lastUser = null; private long? lastUser = null;
private ChatMessage? LastChatMessage = null; private ChatMessage? LastChatMessage = null;
public void AddMessage(SocketMessage Message) public void AddMessage(TextureManager m, SocketMessage Message)
{ {
bool hasbeentenmin = false; bool hasbeentenmin = false;
if (lastm is not null) if (lastm is not null)
@ -126,17 +122,21 @@ public class Chat : UserControl
lastm = Message; lastm = Message;
if (lastUser is null || lastUser != Message.AuthorID || hasbeentenmin) if (lastUser is null || lastUser != Message.AuthorID || hasbeentenmin)
{ {
if (Window is null || !Window.InvokeRequired) if (Window is null || !Globals.ms.InvokeRequired)
MessageFlow.Controls.Add(LastChatMessage = new ChatMessage(Message)); {
MessageFlow.Controls.Add(LastChatMessage = new ChatMessage(m, Message));
}
else else
Window!.Invoke(new Action(() => { MessageFlow.Controls.Add(LastChatMessage = new ChatMessage(Message)); Window.DrawFrame(); })); Globals.ms!.Invoke(new Action(() => { MessageFlow.Controls.Add(LastChatMessage = new ChatMessage(m ,Message)); Window.DrawFrame(); }));
} }
else else
{ {
if (Window is null || !Window.InvokeRequired) if (Window is null || !Globals.ms.InvokeRequired)
{
LastChatMessage!.AddMessage(Message); LastChatMessage!.AddMessage(Message);
}
else else
Window!.Invoke(new Action(() => { LastChatMessage!.AddMessage(Message); Window!.DrawFrame(); })); Globals.ms!.Invoke(new Action(() => { LastChatMessage!.AddMessage(Message); Window!.DrawFrame(); }));
} }
lastUser = Message.AuthorID; lastUser = Message.AuthorID;

View File

@ -20,7 +20,7 @@ public class ChatMessage : UserControl
private static Dictionary<SocketRemoteUser, ContextMenu> Menues = new(); private static Dictionary<SocketRemoteUser, ContextMenu> Menues = new();
private static Dictionary<SocketRemoteUser, List<ChatMessage>> Messages = new(); private static Dictionary<SocketRemoteUser, List<ChatMessage>> Messages = new();
public ChatMessage(SocketMessage message) public ChatMessage(TextureManager tm, SocketMessage message)
{ {
Size = new((int)(723.5 * Globals.Settings.Scale), (int)(37 * Globals.Settings.Scale)); Size = new((int)(723.5 * Globals.Settings.Scale), (int)(37 * Globals.Settings.Scale));
@ -48,7 +48,7 @@ public class ChatMessage : UserControl
timestr = $"{time:M/dd/yyyy h:mm tt}"; timestr = $"{time:M/dd/yyyy h:mm tt}";
} }
Controls.Add(new Label() { Font = Globals.DefaultFont, Location = new(label1.Location.X + label1.Size.X + 4, (int)(4.5 * Globals.Settings.Scale)), Text = timestr}); Controls.Add(new Label() { Font = Globals.DefaultFont, Location = new(label1.Location.X + label1.Size.X + 4, (int)(4.5 * Globals.Settings.Scale)), Text = timestr});
Controls.Add(new Rectangle(Globals.ms.TextureManager.AddTexture(user.GetAvatar(CancellationToken.None).Result)) { Location = new((int)(7.5 * Globals.Settings.Scale), (int)(1.5 * Globals.Settings.Scale)), Size = new((int)(29 * Globals.Settings.Scale)) }); Controls.Add(new Rectangle(tm.AddTexture(user.GetAvatar(CancellationToken.None).Result, true)) { Location = new((int)(7.5 * Globals.Settings.Scale), (int)(1.5 * Globals.Settings.Scale)), Size = new((int)(29 * Globals.Settings.Scale)) });
Controls.Add(label2 = new Label() { Font = Globals.DefaultFont, Location = new((int)(41.5 * Globals.Settings.Scale), (int)(20 * Globals.Settings.Scale)), Text = message.Context}); Controls.Add(label2 = new Label() { Font = Globals.DefaultFont, Location = new((int)(41.5 * Globals.Settings.Scale), (int)(20 * Globals.Settings.Scale)), Text = message.Context});
lastm = label2; lastm = label2;
if (Msg.Files != null && Msg.Files.Length > 0) if (Msg.Files != null && Msg.Files.Length > 0)

View File

@ -1,9 +1,16 @@
using GraphicsManager.Enums;
using GraphicsManager.Interfaces; using GraphicsManager.Interfaces;
using GraphicsManager.Objects; using GraphicsManager.Objects;
using GraphicsManager.Objects.Core; using GraphicsManager.Objects.Core;
using Luski.GUI.MainScreen.Interfaces; using Luski.GUI.MainScreen.Interfaces;
using Luski.GUI.Windows;
using Luski.net.JsonTypes; using Luski.net.JsonTypes;
using OpenTK.Graphics.OpenGL4;
using OpenTK.Mathematics; using OpenTK.Mathematics;
using OpenTK.Windowing.Common;
using OpenTK.Windowing.Desktop;
using OpenTK.Windowing.GraphicsLibraryFramework;
using Window = GraphicsManager.Window;
namespace Luski.GUI.MainScreen.UI; namespace Luski.GUI.MainScreen.UI;
@ -25,20 +32,45 @@ public class Friend : UserControl, IChannelPick
User = person; User = person;
Size = new((int)(185 * Globals.Settings.Scale), (int)(48* Globals.Settings.Scale)); Size = new((int)(185 * Globals.Settings.Scale), (int)(48* Globals.Settings.Scale));
BackgroundColor = new(34, 34, 34, 255); BackgroundColor = new(34, 34, 34, 255);
Controls.Add( r = new Rectangle(Globals.ms.TextureManager.AddTexture(person.GetAvatar(CancellationToken.None).Result)) { Location = new((int)(7.5 * Globals.Settings.Scale),(int)(8.5 * Globals.Settings.Scale)), Size = new((int)(29* Globals.Settings.Scale))}); Controls.Add( r = new Rectangle(Globals.ms.TextureManager.AddTexture(person.GetAvatar(CancellationToken.None).Result, true)) { Location = new((int)(7.5 * Globals.Settings.Scale),(int)(8.5 * Globals.Settings.Scale)), Size = new((int)(29* Globals.Settings.Scale))});
Controls.Add(Username = new Label() { Font = Globals.DefaultFont, Text = person.Username, Location = new((int)(38.5 * Globals.Settings.Scale),(int)(10 * Globals.Settings.Scale))}); Controls.Add(Username = new Label() { Font = Globals.DefaultFont, Text = person.Username, Location = new((int)(38.5 * Globals.Settings.Scale),(int)(10 * Globals.Settings.Scale))});
Controls.Add(Status = new Label() { Font = Globals.DefaultFont, Text = person.Status.ToString(), Location = new((int)(38.5 * Globals.Settings.Scale),(int)(24 * Globals.Settings.Scale))}); Controls.Add(Status = new Label() { Font = Globals.DefaultFont, Text = person.Status.ToString(), Location = new((int)(38.5 * Globals.Settings.Scale),(int)(24 * Globals.Settings.Scale))});
this.Clicked += AllOnClicked; this.Clicked += AllOnClicked;
ContextMenu = new((int)(150 * Globals.Settings.Scale)); ContextMenu = new((int)(150 * Globals.Settings.Scale));
RoundedButton rr; RoundedButton rr, rr2;
ContextMenu.Items.Add(rr=new() ContextMenu.Items.Add(rr=new()
{ {
InsideColor = new(28, 28, 28, 255), BorderColor = Color4.DarkCyan, InsideColor = new(28, 28, 28, 255), BorderColor = Color4.DarkCyan,
Size = new((int)(25 * Globals.Settings.Scale)), Font = Globals.DefaultFont, Text = "Export Keys" Size = new((int)(25 * Globals.Settings.Scale)), Font = Globals.DefaultFont, Text = "Export Keys"
}); });
ContextMenu.Items.Add(rr2=new()
{
InsideColor = new(28, 28, 28, 255), BorderColor = Color4.DarkCyan,
Size = new((int)(25 * Globals.Settings.Scale)), Font = Globals.DefaultFont, Text = "Open In New Window"
});
rr2.Clicked += Rr2OnClicked;
rr.Clicked += RrOnClicked; rr.Clicked += RrOnClicked;
} }
private Task Rr2OnClicked(IRenderObject arg)
{
GLFW.WindowHint(WindowHintBool.Decorated, false);
ChatWindow w = new(this);
//w.WindowBorder = WindowBorder.Resizable;
// ContextMenu!.HideContext(Window!);
//Window!.DrawFrame();
w.StartRender();
//w.IsEventDriven = true;
//Window.Windows.Add(w);
//w.StartRenderAsync();
//w.StartRender();
//ContextMenu!.HideContext(Window!);
return Task.CompletedTask;
}
private Task RrOnClicked(IRenderObject arg) private Task RrOnClicked(IRenderObject arg)
{ {
_ = User.Channel!.SendKeysToUsers(CancellationToken.None); _ = User.Channel!.SendKeysToUsers(CancellationToken.None);

View File

@ -20,7 +20,7 @@ public class FriendRequest : UserControl
this.Screen = Parent; this.Screen = Parent;
Size = new((int)(200 * Globals.Settings.Scale), (int)(48* Globals.Settings.Scale)); Size = new((int)(200 * Globals.Settings.Scale), (int)(48* Globals.Settings.Scale));
BackgroundColor = new(34, 34, 34, 255); BackgroundColor = new(34, 34, 34, 255);
Controls.Add(new Rectangle(Globals.ms.TextureManager.AddTexture(User.GetAvatar(CancellationToken.None).Result)) { Location = new((int)(7.5 * Globals.Settings.Scale),(int)(8.5 * Globals.Settings.Scale)), Size = new((int)(29 * Globals.Settings.Scale))}); Controls.Add(new Rectangle(Globals.ms.TextureManager.AddTexture(User.GetAvatar(CancellationToken.None).Result, true)) { Location = new((int)(7.5 * Globals.Settings.Scale),(int)(8.5 * Globals.Settings.Scale)), Size = new((int)(29 * Globals.Settings.Scale))});
Controls.Add(new Label() { Font = Globals.DefaultFont, Text = User.Username, Location = new((int)(38.5 * Globals.Settings.Scale),(int)(10 * Globals.Settings.Scale))}); Controls.Add(new Label() { Font = Globals.DefaultFont, Text = User.Username, Location = new((int)(38.5 * Globals.Settings.Scale),(int)(10 * Globals.Settings.Scale))});
Controls.Add(new Label() { Font = Globals.DefaultFont, Text = User.FriendStatus.ToString(), Location = new((int)(38.5 * Globals.Settings.Scale),(int)(24 * Globals.Settings.Scale))}); Controls.Add(new Label() { Font = Globals.DefaultFont, Text = User.FriendStatus.ToString(), Location = new((int)(38.5 * Globals.Settings.Scale),(int)(24 * Globals.Settings.Scale))});
if (User.FriendStatus == FriendStatus.PendingIn) if (User.FriendStatus == FriendStatus.PendingIn)

View File

@ -18,7 +18,7 @@ public class Group : UserControl, IChannelPick
Channel = chan; Channel = chan;
Size = new((int)(185 * Globals.Settings.Scale), (int)(48* Globals.Settings.Scale)); Size = new((int)(185 * Globals.Settings.Scale), (int)(48* Globals.Settings.Scale));
BackgroundColor = new(34, 34, 34, 255); BackgroundColor = new(34, 34, 34, 255);
Controls.Add( r = new Rectangle(Globals.ms.TextureManager.AddTexture(chan.GetPicture(CancellationToken.None).Result)) { Location = new((int)(7.5 * Globals.Settings.Scale),(int)(8.5 * Globals.Settings.Scale)), Size = new((int)(29* Globals.Settings.Scale))}); Controls.Add( r = new Rectangle(Globals.ms.TextureManager.AddTexture(chan.GetPicture(CancellationToken.None).Result, true)) { Location = new((int)(7.5 * Globals.Settings.Scale),(int)(8.5 * Globals.Settings.Scale)), Size = new((int)(29* Globals.Settings.Scale))});
Controls.Add(Username = new Label() { Font = Globals.DefaultFont, Text = chan.Title, Location = new((int)(38.5 * Globals.Settings.Scale),(int)(10 * Globals.Settings.Scale))}); Controls.Add(Username = new Label() { Font = Globals.DefaultFont, Text = chan.Title, Location = new((int)(38.5 * Globals.Settings.Scale),(int)(10 * Globals.Settings.Scale))});
string sl = "Online"; string sl = "Online";
if (chan.Id != 0) if (chan.Id != 0)

View File

@ -46,10 +46,12 @@ public class CreateAccount : UserControl
private Task RecOnFilesDroped(string[] arg) private Task RecOnFilesDroped(string[] arg)
{ {
if (!arg[0].ToLower().EndsWith("png")) return Task.CompletedTask; if (!arg[0].ToLower().EndsWith("png")) return Task.CompletedTask;
Controls.Remove(rec);
pfp = arg[0]; pfp = arg[0];
rec = new(Globals.ms.TextureManager.AddTexture(File.ReadAllBytes(arg[0]))){ Location = new(350, 585), Size = new(100) }; if (rec.Texture is null)
Controls.Add(rec); {Controls.Remove(rec);rec = new(Globals.ms.TextureManager.AddTexture(File.ReadAllBytes(arg[0]), true)){ Location = new(350, 585), Size = new(100) };Controls.Add(rec);}
else rec.Texture = Globals.ms.TextureManager.AddTexture(File.ReadAllBytes(arg[0]), true);
Window!.DrawFrame(); Window!.DrawFrame();
return Task.CompletedTask; return Task.CompletedTask;
} }

View File

@ -5,6 +5,7 @@ using OpenTK.Mathematics;
using OpenTK.Windowing.Common; using OpenTK.Windowing.Common;
using OpenTK.Windowing.Desktop; using OpenTK.Windowing.Desktop;
using OpenTK.Windowing.GraphicsLibraryFramework; using OpenTK.Windowing.GraphicsLibraryFramework;
using SixLabors.ImageSharp.Drawing.Processing;
namespace Luski.GUI.StartPage.UI; namespace Luski.GUI.StartPage.UI;
@ -15,10 +16,11 @@ public class Login : UserControl
private Label ca; private Label ca;
public event Func<Task>? ChangeToApp; public event Func<Task>? ChangeToApp;
public event Func<Task>? ChangeToCa; public event Func<Task>? ChangeToCa;
public Rectangle r;
public Login() public Login()
{ {
Size = new((int)(240.5*Globals.Settings.Scale), (int)(419*Globals.Settings.Scale)); Size = new((int)(240.5*Globals.Settings.Scale), (int)(419*Globals.Settings.Scale));
Controls.Add(new Rectangle(Globals.LuskiTexture) { Location = new((int)(51.5 * Globals.Settings.Scale), (int)(4 * Globals.Settings.Scale)), Size = new((int)(138*Globals.Settings.Scale), (int)(144.5*Globals.Settings.Scale))}); Controls.Add(r=new Rectangle(Globals.LuskiTexture) { Location = new((int)(51.5 * Globals.Settings.Scale), (int)(4 * Globals.Settings.Scale)), Size = new((int)(138*Globals.Settings.Scale), (int)(144.5*Globals.Settings.Scale))});
Label t; Label t;
Controls.Add(t=new Label() { Scale = 1.6f, Font = Globals.DefaultFont, Location = new((int)(85*Globals.Settings.Scale),(int)(153*Globals.Settings.Scale)), Text = "Luski", Color = new(243, 119, 53, 255) }); Controls.Add(t=new Label() { Scale = 1.6f, Font = Globals.DefaultFont, Location = new((int)(85*Globals.Settings.Scale),(int)(153*Globals.Settings.Scale)), Text = "Luski", Color = new(243, 119, 53, 255) });
t.Location = new((Size.X / 2) - (t.Size.X / 2), t.Location.Y); t.Location = new((Size.X / 2) - (t.Size.X / 2), t.Location.Y);

View File

@ -16,8 +16,9 @@ public class UpdateWindow : Window
WindowBorder = WindowBorder.Fixed, WindowBorder = WindowBorder.Fixed,
APIVersion = new Version(3, 2), APIVersion = new Version(3, 2),
StartFocused = true, StartFocused = true,
Size = new OpenTK.Mathematics.Vector2i(481, 838), Size = new Vector2i(481, 838),
Icon = Globals.Icon Icon = Globals.Icon,
SharedContext = null
}; };
public enum DialogueResult public enum DialogueResult

View File

@ -0,0 +1,44 @@
using GraphicsManager;
using GraphicsManager.Enums;
using Luski.GUI.MainScreen.Interfaces;
using Luski.GUI.MainScreen.UI;
using Luski.net.JsonTypes;
using OpenTK.Windowing.Common;
using OpenTK.Windowing.Desktop;
namespace Luski.GUI.Windows;
public class ChatWindow : Window
{
private static readonly NativeWindowSettings Settings = new()
{
Title = "Channel",
WindowBorder = WindowBorder.Resizable,
APIVersion = new Version(3, 2),
StartFocused = true,
Size = new OpenTK.Mathematics.Vector2i((int)(754 * Globals.Settings.Scale), (int)(667 * Globals.Settings.Scale)),
Icon = Globals.Icon,
SharedContext = null
};
public ChatWindow(IChannelPick pick) : base(Settings)
{
Chat c;
WindowBorder = WindowBorder.Resizable;
Controls.Add(c= new Chat()
{
Location = new(0),
Size = new(Size.X, Size.Y),
Anchor = ObjectAnchor.All
});
c.UpdateTitle(pick);
IReadOnlyList<SocketMessage> messages = pick.Channel.GetMessages(CancellationToken.None, Globals.Settings.LoadPerChannel).Result;
foreach (SocketMessage message in messages.Reverse())
{
c!.AddMessage(TextureManager, message);
}
c!.MessageFlow.ScrollToBottom();
}
}

View File

@ -13,6 +13,25 @@ namespace Luski;
public class Globals public class Globals
{ {
public record Snowflake
{
public Snowflake(long ID)
{
this.ID = ID;
Increment = (ushort)((ID << 52) >> 52);
Worker_ID = (ushort)((ID << 47) >> 59);
Server_ID = (ushort)((ID << 42) >> 59);
Timestamp = ID >> 22;
}
public long ID { get; }
public long Timestamp { get; }
public ushort Worker_ID { get; }
public ushort Server_ID { get; }
public ushort Increment { get; }
private static ushort i = 0;
}
public static bool Download { get; set; } = false; public static bool Download { get; set; } = false;
public static Server Luski { get; set; } = null!; public static Server Luski { get; set; } = null!;
public static MainScreen ms; public static MainScreen ms;

View File

@ -15,7 +15,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="GraphicsManager" Version="1.0.4-alpha03" /> <PackageReference Include="GraphicsManager" Version="1.0.5-alpha08" />
<PackageReference Include="Luski.net" Version="1.1.2-beta05" /> <PackageReference Include="Luski.net" Version="1.1.2-beta05" />
</ItemGroup> </ItemGroup>

View File

@ -8,9 +8,17 @@ using Luski.net;
using OpenTK.Windowing.Common.Input; using OpenTK.Windowing.Common.Input;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
try try
{ {
Console.WriteLine(new Globals.Snowflake(6080823133885445424));
bool f = false;
bool t = true;
byte bf = Convert.ToByte(f);
byte bt = Convert.ToByte(t);
Console.WriteLine("{0} converted to {1}.", f, bf);
Console.WriteLine("{0} converted to {1}.", t, bt);
Globals.Settings = Globals.GetSettings(Path.Combine(Globals.LuskiPath, "Settings.json"), SettingsContext.Default.Settings); Globals.Settings = Globals.GetSettings(Path.Combine(Globals.LuskiPath, "Settings.json"), SettingsContext.Default.Settings);
Globals.UpdaterSettings = Globals.GetSettings(Path.Combine(Globals.LuskiPath, "UpdaterSettings.json"), UpdaterSettingsContext.Default.UpdaterSettings); Globals.UpdaterSettings = Globals.GetSettings(Path.Combine(Globals.LuskiPath, "UpdaterSettings.json"), UpdaterSettingsContext.Default.UpdaterSettings);
@ -20,20 +28,10 @@ try
resource_stream?.CopyTo(ms); resource_stream?.CopyTo(ms);
var Logo = SixLabors.ImageSharp.Image.Load<Rgba32>(ms.ToArray()); var Logo = SixLabors.ImageSharp.Image.Load<Rgba32>(ms.ToArray());
var pixels = new List<byte>(4 * Logo.Width * Logo.Height); //List<byte> pixels = new List<byte>(4 * Logo.Width * Logo.Height);
Span<byte> pixels = new byte[4 * Logo.Width * Logo.Height].AsSpan();
Logo.CopyPixelDataTo(pixels);
for (int y = 0; y < Logo.Height; y++)
{
var row = Logo.GetPixelRowSpan(y);
for (int x = 0; x < Logo.Width; x++)
{
pixels.Add(row[x].R);
pixels.Add(row[x].G);
pixels.Add(row[x].B);
pixels.Add(row[x].A);
}
}
Globals.Icon = new WindowIcon(new Image(Logo.Width, Logo.Height, pixels.ToArray())); Globals.Icon = new WindowIcon(new Image(Logo.Width, Logo.Height, pixels.ToArray()));
Globals.ms = new MainScreen(); Globals.ms = new MainScreen();
Globals.ms.StartRender(); Globals.ms.StartRender();