diff --git a/Quik.Media.Defaults/FreeTypeFontFactory.cs b/Quik.Media.Defaults/FreeTypeFontFactory.cs new file mode 100644 index 0000000..f75653e --- /dev/null +++ b/Quik.Media.Defaults/FreeTypeFontFactory.cs @@ -0,0 +1,24 @@ + +using System.Diagnostics.CodeAnalysis; +using System.IO; +using Quik.PAL; + +namespace Quik.Media.Defaults +{ + public class FreeTypeFontFactory : IFontFactory + { + public bool TryOpen(Stream stream, [NotNullWhen(true)] out QFont font) + { + try + { + font = new QFontFreeType(stream); + return true; + } + catch + { + font = null; + return false; + } + } + } +} \ No newline at end of file diff --git a/Quik/OpenGL/GL21Driver.cs b/Quik/OpenGL/GL21Driver.cs index bc132be..4302ba5 100644 --- a/Quik/OpenGL/GL21Driver.cs +++ b/Quik/OpenGL/GL21Driver.cs @@ -112,6 +112,8 @@ namespace Quik.OpenGL GL.Enable(GL_BLEND); GL.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); GL.Enable(GL_SCISSOR_TEST); + GL.Enable(GL_DEPTH_TEST); + GL.DepthFunc(GL_LESS); foreach (DrawCall call in queue) { @@ -151,6 +153,10 @@ namespace Quik.OpenGL GL.DrawElements(GL_TRIANGLES, call.Count, GL_UNSIGNED_INT, sizeof(int)*call.Start); } + + GL.Disable(GL_SCISSOR_TEST); + GL.Disable(GL_DEPTH_TEST); + GL.Disable(GL_BLEND); } public void ClearDrawQueue(DrawQueue queue) diff --git a/Quik/OpenGL/GLEnum.cs b/Quik/OpenGL/GLEnum.cs index d2ebb93..89b5213 100644 --- a/Quik/OpenGL/GLEnum.cs +++ b/Quik/OpenGL/GLEnum.cs @@ -81,9 +81,13 @@ namespace Quik.OpenGL GL_TRIANGLES = 0x0004, GL_SCISSOR_TEST = 0x0C11, + GL_DEPTH_TEST = 0x0B71, + GL_TEXTURE_SWIZZLE_R = 0x8E42, GL_TEXTURE_SWIZZLE_G = 0x8E43, GL_TEXTURE_SWIZZLE_B = 0x8E44, - GL_TEXTURE_SWIZZLE_A = 0x8E45 + GL_TEXTURE_SWIZZLE_A = 0x8E45, + + GL_LESS = 0x0201, } } \ No newline at end of file diff --git a/Quik/PAL/IFontFactory.cs b/Quik/PAL/IFontFactory.cs new file mode 100644 index 0000000..7d11710 --- /dev/null +++ b/Quik/PAL/IFontFactory.cs @@ -0,0 +1,12 @@ + +using System.Diagnostics.CodeAnalysis; +using System.IO; +using Quik.Media; + +namespace Quik.PAL +{ + public interface IFontFactory + { + bool TryOpen(Stream stream, [NotNullWhen(true)] out QFont font); + } +} \ No newline at end of file diff --git a/Quik/QuikApplication.cs b/Quik/QuikApplication.cs index 24aa773..98e48c3 100644 --- a/Quik/QuikApplication.cs +++ b/Quik/QuikApplication.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Threading; using Quik.CommandMachine; using Quik.Controls; using Quik.Media; @@ -85,24 +86,43 @@ namespace Quik return disposable; } - public void Run(View mainView) + private CommandList cmd = new CommandList(); + + public void Run(View mainView, bool yield = true) { - MainPort = new QuikPort(Platform) { UIElement = mainView }; - CommandList cmd = new CommandList(); + Init(mainView); - MainPort.EventRaised += (sender, ea) => mainView.NotifyEvent(sender, ea); - - while (MainPort.IsValid) + while (RunSync()) { - Platform.ProcessEvents(false); - if (MainPort.IsValid) + if (yield) { - cmd.Clear(); - MainPort.Paint(cmd); + Thread.Yield(); } } } + public void Init(View mainView) + { + MainPort = new QuikPort(Platform) { UIElement = mainView }; + MainPort.EventRaised += (sender, ea) => mainView.NotifyEvent(sender, ea); + } + + public bool RunSync() + { + if (!MainPort.IsValid) + return false; + + Platform.ProcessEvents(false); + + if (MainPort.IsValid) + { + cmd.Clear(); + MainPort.Paint(cmd); + } + + return true; + } + public static QuikApplication Current { get; private set; } public static void SetCurrentApplication(QuikApplication application) diff --git a/Quik/Typography/FontProvider.cs b/Quik/Typography/FontProvider.cs index cdfa878..6926e28 100644 --- a/Quik/Typography/FontProvider.cs +++ b/Quik/Typography/FontProvider.cs @@ -1,8 +1,10 @@ using Quik.Media; using Quik.Media.Font; +using Quik.PAL; using System; using System.Collections.Generic; -using System.Linq; +using System.IO; +using System.Reflection; namespace Quik.Typography { @@ -14,6 +16,8 @@ namespace Quik.Typography private Dictionary Fonts { get; } = new Dictionary(); private HashSet UsedFonts { get; } = new HashSet(); public readonly FontRasterizerOptions RasterizerOptions; + public IFontDataBase Database { get; set; } + public IFontFactory FontFactory { get; set; } private readonly QuikApplication App; public QFont this[FontFace info] @@ -22,8 +26,15 @@ namespace Quik.Typography { if (!Fonts.TryGetValue(info, out QFont font)) { - font = (QFont)App.GetMedia(info, MediaHint.Font); - Fonts[info] = font; + using Stream str = Database?.Open(info); + if (FontFactory.TryOpen(str, out font)) + { + Fonts.Add(info, font); + } + else + { + throw new Exception("Font not found."); + } } UsedFonts.Add(font); @@ -31,10 +42,35 @@ namespace Quik.Typography } } + public QFont this[SystemFontFamily family] + { + get + { + return this[Database.GetSystemFontFace(family)]; + } + } + public FontProvider(QuikApplication app, in FontRasterizerOptions options) { RasterizerOptions = options; App = app; + + Type fdb = Type.GetType("Quik.Media.Defaults.FontDataBaseProvider, Quik.Media.Defaults"); + if (fdb != null) + { + PropertyInfo instanceProperty = fdb.GetProperty("Instance", BindingFlags.Static | BindingFlags.Public | BindingFlags.GetProperty); + if (instanceProperty != null) + { + Database = (IFontDataBase)instanceProperty.GetValue(null); + } + } + + Type ffact = Type.GetType("Quik.Media.Defaults.FreeTypeFontFactory, Quik.Media.Defaults"); + if (ffact != null) + { + ConstructorInfo ctor = ffact.GetConstructor(Array.Empty()); + FontFactory = (IFontFactory)ctor.Invoke(null); + } } public FontProvider(QuikApplication app) : this(app, FontRasterizerOptions.Default)