using System;
using System.Collections.Generic;
using System.Threading;
using Collary.Native.SDL2;
using WTelegram;
using TL;
using System.Threading.Tasks;
namespace Teeply;
public class TelegramThread
{
public Client Client { get; private set; }
public static object Locker { get; private set; }
public static List<ChatListItem> ChatListItems { get; set; }
public TelegramThread()
{
TelegramThread.Locker = new object();
TelegramThread.ChatListItems = new List<ChatListItem>();
}
public async Task Run()
{
Client = new WTelegram.Client(id, "hash");
await Client.ConnectAsync();
Thread _GetAllChats = new Thread(this.GetAllChats);
_GetAllChats.Start();
}
private void ThreadContainer(Action action, int range_rate = 10000)
{
SDL.SDL_Init(SDL.SDL_INIT_TIMER);
double rate = 0;
while(true)
{
ulong first_tick = SDL.SDL_GetTicks64();
if (rate > range_rate)
{
range_rate = 0;
action.Invoke();
}
ulong second_tick = SDL.SDL_GetTicks64();
rate += second_tick - first_tick;
}
}
private void GetAllChats()
{
Messages_Dialogs msgs_dialogs = this.Client.Messages_GetAllDialogs().Result;
Messages_Chats msgs_chats = this.Client.Messages_GetAllChats().Result;
lock(TelegramThread.Locker)
{
TelegramThread.ChatListItems = new List<ChatListItem>();
foreach (KeyValuePair<long, ChatBase> chat in msgs_dialogs.chats)
TelegramThread.ChatListItems.Add(new ChatListItem(){Title = chat.Value.Title});
foreach (KeyValuePair<long, ChatBase> chat in msgs_chats.chats)
TelegramThread.ChatListItems.Add(new ChatListItem(){Title = chat.Value.Title});
}
}
}
public class ChatListItem
{
public string Title { get; set; }
}
using System;
using System.IO;
using System.Numerics;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Collary.Native.SDL2;
using Collary.UI.System;
using Collary.UI.Graphics;
using Collary.UI.Windowing;
using Collary.UI.Components;
using System.Threading;
namespace Teeply;
public class Application
{
private bool Quit { get; set; }
private EventHost Events { get; set; }
private Window Window { get; set; }
private Renderer Renderer { get; set; }
private List<Component> Components { get; set; }
private byte Framerate { get; set; }
public static double DeltaTime { get; private set; }
private ulong NowTick = 0;
private ulong PrevTick = 0;
public Application(Window window)
{
this.Quit = false;
this.Window = window;
this.Renderer = new Renderer(this.Window);
this.Renderer.Font = new Font("C:\\Windows\\Fonts\\segoeui.ttf", 14);
this.Components = new List<Component>();
this.Components.Add(new ChatList(new Vector2(150, 405), new Vector2(0, 0), this.Renderer, this.Window));
this.Events = new EventHost();
this.Events.AddTarget(this.Window);
this.Framerate = 30;
}
public async Task Run()
{
TelegramThread tt = new TelegramThread();
new Thread(async () => await tt.Run()).Start();
while (!this.Quit)
{
this.PrevTick = SDL.SDL_GetTicks64();
// Logic
this.Events.Dispatch();
this.Renderer.Clear();
foreach (Component component in this.Components)
{
component.Update();
component.Draw();
this.Renderer.Target = null;
this.Renderer.Draw(component.Texture, component.Position);
}
this.Renderer.Present();
// End Logic
this.NowTick = SDL.SDL_GetTicks64();
Console.WriteLine(this.NowTick);
Application.DeltaTime = this.NowTick - this.PrevTick;
int sleep_time = (1000 / this.Framerate) - (int)Application.DeltaTime;
if (sleep_time > 0)
System.Threading.Thread.Sleep(sleep_time);
}
}
}