Use .Loaded / FileProto / Monospace / add flags
This commit is contained in:
parent
3fa00d5fc2
commit
e049b1a090
|
@ -20,7 +20,6 @@ static class MainUI
|
|||
|
||||
public static unsafe void AddFontFromResource(string resource, Action<IntPtr, int> f)
|
||||
{
|
||||
var io = ImGui.GetIO();
|
||||
using(var m = new MemoryStream())
|
||||
{
|
||||
Assembly.GetExecutingAssembly().GetManifestResourceStream(resource).CopyTo(m);
|
||||
|
@ -32,7 +31,7 @@ static class MainUI
|
|||
}
|
||||
}
|
||||
|
||||
public static unsafe bool Load()
|
||||
public static bool Load(string[] args)
|
||||
{
|
||||
var io = ImGui.GetIO();
|
||||
ImGui.StyleColorsDark();
|
||||
|
@ -48,6 +47,10 @@ static class MainUI
|
|||
MonospaceFont = io.Fonts.AddFontFromMemoryTTF(buf, len, 16f);
|
||||
});
|
||||
|
||||
if(args.Length > 0)
|
||||
foreach (var arg in args)
|
||||
NewTab(arg);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,9 @@ class PlainMediaHandler : MediaHandler
|
|||
|
||||
public override void Render()
|
||||
{
|
||||
ImGui.PushFont(MainUI.MonospaceFont);
|
||||
foreach(var line in lines)
|
||||
ImGui.TextUnformatted(line);
|
||||
ImGui.PopFont();
|
||||
}
|
||||
}
|
16
Program.cs
16
Program.cs
|
@ -1,4 +1,3 @@
|
|||
using ImGuiNET;
|
||||
using Raylib_cs;
|
||||
using rlImGui_cs;
|
||||
|
||||
|
@ -8,17 +7,18 @@ class Program
|
|||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Raylib.SetConfigFlags(ConfigFlags.FLAG_WINDOW_RESIZABLE | ConfigFlags.FLAG_WINDOW_MAXIMIZED);
|
||||
Raylib.InitWindow(1024, 768, "Shoko");
|
||||
Raylib.SetConfigFlags(
|
||||
ConfigFlags.FLAG_MSAA_4X_HINT |
|
||||
ConfigFlags.FLAG_WINDOW_HIGHDPI |
|
||||
ConfigFlags.FLAG_WINDOW_MAXIMIZED |
|
||||
ConfigFlags.FLAG_WINDOW_RESIZABLE |
|
||||
ConfigFlags.FLAG_VSYNC_HINT);
|
||||
Raylib.InitWindow(0, 0, "Shoko");
|
||||
|
||||
rlImGui.BeginInitImGui();
|
||||
bool quit = MainUI.Load();
|
||||
bool quit = MainUI.Load(args);
|
||||
rlImGui.EndInitImGui();
|
||||
|
||||
if(args.Length > 0)
|
||||
foreach (var arg in args)
|
||||
MainUI.NewTab(arg);
|
||||
|
||||
while(!Raylib.WindowShouldClose() && quit)
|
||||
{
|
||||
Raylib.BeginDrawing();
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
using System.Text;
|
||||
using System.Web;
|
||||
|
||||
namespace Shoko;
|
||||
|
||||
[Protocol("file")]
|
||||
|
@ -10,13 +13,39 @@ class FileProtoHandler : ProtoHandler
|
|||
|
||||
public override void Load()
|
||||
{
|
||||
var file = new UriBuilder(URL).Path;
|
||||
var file = HttpUtility.UrlDecode(new UriBuilder(URL).Path);
|
||||
|
||||
var stream = new FileStream(file, FileMode.Open);
|
||||
if(URL.Host.Length > 0)
|
||||
file = "//" + URL.Host + file;
|
||||
|
||||
Content = stream;
|
||||
MediaType = "text/plain"; // TODO: magic numbers
|
||||
Status = "OK";
|
||||
|
||||
if(File.Exists(file))
|
||||
{
|
||||
var stream = new FileStream(file, FileMode.Open);
|
||||
Content = stream;
|
||||
}
|
||||
else if(Directory.Exists(file))
|
||||
{
|
||||
MediaType = "text/gemini";
|
||||
var str = "# "+file+"\r\n";
|
||||
var entries = Directory.EnumerateFileSystemEntries(file);
|
||||
|
||||
foreach(var entry in entries)
|
||||
{
|
||||
var path = Path.GetFileName(entry);
|
||||
str += string.Format("=>{0}/{1} {2}\r\n", URL.ToString(), HttpUtility.UrlEncode(path), path);
|
||||
}
|
||||
|
||||
Content = new MemoryStream(Encoding.UTF8.GetBytes(str));
|
||||
}
|
||||
else
|
||||
{
|
||||
Content = new MemoryStream(Encoding.UTF8.GetBytes("file not found"));
|
||||
Status = "not found";
|
||||
}
|
||||
|
||||
Loaded = true;
|
||||
}
|
||||
public override void Render()
|
||||
|
|
|
@ -22,6 +22,8 @@ class ProtoHandler
|
|||
public Stream Content;
|
||||
public string Status;
|
||||
public bool Loaded = false;
|
||||
public int LoadedBytes = 0;
|
||||
public int TotalBytes = 0;
|
||||
public IEnumerable<KeyValuePair<string,IEnumerable<string>>> Headers;
|
||||
public IEnumerable<KeyValuePair<string,string>> MediaTypeParams;
|
||||
public ProtoHandler()
|
||||
|
@ -36,6 +38,7 @@ class ProtoHandler
|
|||
{
|
||||
Content = new MemoryStream(Encoding.UTF8.GetBytes("error: no handler for this scheme"));
|
||||
MediaType = "text/plain";
|
||||
Loaded = true;
|
||||
}
|
||||
|
||||
public virtual void Render()
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
using System.Reflection;
|
||||
using System.Web;
|
||||
|
||||
namespace Shoko;
|
||||
|
||||
[Protocol("res")]
|
||||
class ResProtoHandler : ProtoHandler
|
||||
{
|
||||
public ResProtoHandler(Uri url)
|
||||
{
|
||||
URL = url;
|
||||
}
|
||||
|
||||
public override void Load()
|
||||
{
|
||||
var path = HttpUtility.HtmlDecode(new UriBuilder(URL).Path);
|
||||
Status = "OK";
|
||||
Loaded = true;
|
||||
MediaType = "text/plain";
|
||||
try
|
||||
{
|
||||
Content = Assembly.GetExecutingAssembly().GetManifestResourceStream(path);
|
||||
}
|
||||
catch
|
||||
{
|
||||
Status = "not found";
|
||||
Loaded = false;
|
||||
}
|
||||
}
|
||||
public override void Render()
|
||||
{
|
||||
}
|
||||
}
|
8
Tab.cs
8
Tab.cs
|
@ -66,7 +66,8 @@ class Tab
|
|||
if(Error is null)
|
||||
{
|
||||
Handler.MenuBar();
|
||||
Document.MenuBar();
|
||||
if(Handler.Loaded)
|
||||
Document.MenuBar();
|
||||
}
|
||||
|
||||
Gui.Button("<<", ()=>{
|
||||
|
@ -78,6 +79,8 @@ class Tab
|
|||
Gui.Button("Go", ()=>{
|
||||
Load(txtURL);
|
||||
});
|
||||
if(!Handler.Loaded && Handler.TotalBytes != 0)
|
||||
ImGui.ProgressBar(Handler.LoadedBytes / Handler.TotalBytes);
|
||||
});
|
||||
if(Error is not null)
|
||||
{
|
||||
|
@ -86,7 +89,8 @@ class Tab
|
|||
}
|
||||
else
|
||||
{
|
||||
Document.Render();
|
||||
if(Handler.Loaded)
|
||||
Document.Render();
|
||||
Handler.Render();
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue