diff --git a/Quik.FreeType/FT.cs b/Quik.FreeType/FT.cs deleted file mode 100644 index 4af977e..0000000 --- a/Quik.FreeType/FT.cs +++ /dev/null @@ -1,83 +0,0 @@ -using System; -using System.Runtime.InteropServices; - -namespace Quik.FreeType -{ - public static class FT - { - private const string freetype2 = "freetype"; - - [DllImport(freetype2, EntryPoint = "FT_Init_FreeType")] - public static extern FTError InitFreeType(out FTLibrary library); - - [DllImport(freetype2, EntryPoint = "FT_Done_FreeType")] - public static extern FTError DoneFreeType(FTLibrary library); - - [DllImport(freetype2, EntryPoint = "FT_New_Face")] - public static extern FTError NewFace( - FTLibrary library, - [MarshalAs(UnmanagedType.LPStr)] string path, - long faceIndex, - out FTFace face); - - [DllImport(freetype2, EntryPoint = "FT_New_Memory_Face")] - public static extern FTError NewMemoryFace( - FTLibrary library, - IntPtr buffer, - long size, - long faceIndex, - out FTFace face); - - [DllImport(freetype2, EntryPoint = "FT_New_Memory_Face")] - public static extern FTError NewMemoryFace( - FTLibrary library, - [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] byte[] buffer, - long size, - long faceIndex, - out FTFace face); - - [DllImport(freetype2, EntryPoint = "FT_New_Memory_Face")] - public static extern FTError NewMemoryFace( - FTLibrary library, - [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] Span buffer, - long size, - long faceIndex, - out FTFace face); - - // public static extern FTError OpenFace(FTLibrary library, in FTOpenArgs args, long faceIndex, out FTFace face); - - // [DllImport(freetype2, EntryPoint = "FT_Attach_File")] - // public static extern FTError AttachFile(FTFace face, [MarshalAs(UnmanagedType.LPStr)] string filePathName); - - [DllImport(freetype2, EntryPoint = "FT_Set_Char_Size")] - public static extern FTError SetCharSize( - FTFace library, - long charWidth, - long charHeight, - uint horizontalResolution, - uint verticalResolution); - - - [DllImport(freetype2, EntryPoint = "FT_Get_Char_Index")] - public static extern uint GetCharIndex(FTFace face, ulong charCode); - - [DllImport(freetype2, EntryPoint = "FT_Load_Glyph")] - public static extern FTError LoadGlyph(FTFace face, uint charIndex, FTLoadFlags flags); - - [DllImport(freetype2, EntryPoint = "FT_Render_Glyph")] - public static extern FTError RenderGlyph(FTGlyphSlot slot, FTRenderMode mode); - - [DllImport(freetype2, EntryPoint = "FT_Done_Face")] - public static extern FTError DoneFace(FTFace face); - - [DllImport(freetype2, EntryPoint = "FT_Bitmap_Init")] - public static extern void BitmapInit(ref FTBitmap bitmap); - - [DllImport(freetype2, EntryPoint = "FT_Bitmap_Convert")] - public static extern void BitmapConvert(FTLibrary library, in FTBitmap source, ref FTBitmap target, - int alignment); - - [DllImport(freetype2, EntryPoint = "FT_Bitmap_Done")] - public static extern void BitmapDone(FTLibrary library, ref FTBitmap bitmap); - } -} \ No newline at end of file diff --git a/Quik.FreeType/FTError.cs b/Quik.FreeType/FTError.cs deleted file mode 100644 index d80c4b7..0000000 --- a/Quik.FreeType/FTError.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Quik.FreeType -{ - public enum FTError : int - { - None = 0, - } -} \ No newline at end of file diff --git a/Quik.FreeType/FTLoadFlags.cs b/Quik.FreeType/FTLoadFlags.cs deleted file mode 100644 index ad8ff4a..0000000 --- a/Quik.FreeType/FTLoadFlags.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; - -namespace Quik.FreeType -{ - [Flags] - public enum FTLoadFlags - { - Default = 0, - NoScale = 1 << 0, - NoHinting = 1 << 1, - Render = 1 << 2, - NoBitmap = 1 << 3, - VerticalLayout = 1 << 4, - ForceAutoHint = 1 << 5, - CropBitmap = 1 << 6, - Pedantic = 1 << 7, - IgnoreGlobalAdvanceWidth = 1 << 9, - NoRecurse = 1 << 10, - IgnoreTransform = 1 << 11, - Monochrome= 1 << 12, - LinearDesign = 1 << 13, - SbitsOnly = 1 << 14, - NoAutoHint = 1 << 15, - Color = 1 << 20, - ComputeMetrics = 1 << 21, - BitmapMetricsOnly = 1 << 22 - } -} \ No newline at end of file diff --git a/Quik.FreeType/FTRenderMode.cs b/Quik.FreeType/FTRenderMode.cs deleted file mode 100644 index c3cd212..0000000 --- a/Quik.FreeType/FTRenderMode.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace Quik.FreeType -{ - public enum FTRenderMode - { - Normal = 0, - Light, - Mono, - Lcd, - LcdVertical, - Sdf - } -} \ No newline at end of file diff --git a/Quik.FreeType/FaceFlag.cs b/Quik.FreeType/FaceFlag.cs deleted file mode 100644 index dde662f..0000000 --- a/Quik.FreeType/FaceFlag.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; - -namespace Quik.FreeType -{ - [Flags] - public enum FaceFlag : int - { - Scalable = 1 << 0, - FixedSizes = 1 << 1, - FixedWidth = 1 << 2, - Sfnt = 1 << 3, - Horizontal = 1 << 4, - Vertical = 1 << 5, - Kerning = 1 << 6, - FastGlyphs = 1 << 7, - MultipleMasters = 1 << 8, - GlyphNames = 1 << 9, - ExternalStream = 1 << 10, - Hinter = 1 << 11, - CidKeyed = 1 << 12, - Tricky = 1 << 13, - Color = 1 << 14, - Variation = 1 << 15, - Svg = 1 << 16, - Sbix = 1 << 17, - SbixOverlay = 1 << 18 - } -} \ No newline at end of file diff --git a/Quik.FreeType/FreeTypeFont.cs b/Quik.FreeType/FreeTypeFont.cs deleted file mode 100644 index 6d2112d..0000000 --- a/Quik.FreeType/FreeTypeFont.cs +++ /dev/null @@ -1,181 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using Quik.Typography; - -namespace Quik.FreeType -{ - public class FreeTypeFont : QuikFont, IDisposable - { - - private FreeTypeFontManager _owner; - private FTLibrary _library; - private FTFace _face; - private List _textures = new List(); - private Dictionary _entries = new Dictionary(); - - public override float Ascender => _face.ScaledSize.Ascender / 64f; - public override float Descender => _face.ScaledSize.Descender / 64f; - - internal FreeTypeFont(FreeTypeFontManager owner, FileInfo file, QuikFontStyle style) - { - Style = style; - _owner = owner; - _library = owner._library; - - if (FT.NewFace(_library, file.FullName, 0, out _face) != FTError.None) - { - throw new Exception("Could not load font file."); - } - - FT.SetCharSize(_face, 0, (long)(style.Size * 64), 96, 96); - - _textures.Add(new Atlas(owner.Context.TextureManager, _library)); - } - - public override QuikFontStyle Style { get; } - - public override bool HasCharacter(int character) - { - return FT.GetCharIndex(_face, (ulong)character) != 0; - } - - public override void GetCharacter(int character, out QuikTexture texture, out QuikGlyph glyph) - { - GlyphEntry entry; - - if (_entries.TryGetValue(character, out entry)) - { - texture = entry.Atlas.Texture; - glyph = entry.Metrics; - return; - } - - entry = new GlyphEntry(); - entry.Character = character; - - uint index = FT.GetCharIndex(_face, (ulong) character); - FT.LoadGlyph(_face, index, FTLoadFlags.Default); - FT.RenderGlyph(_face.Glyph, FTRenderMode.Normal); - - entry.Atlas = _textures[_textures.Count - 1]; - if (!entry.Atlas.CanFit(_face.Glyph)) - { - entry.Atlas = new Atlas(_owner.Context.TextureManager, _library); - _textures.Add(entry.Atlas); - } - entry.Atlas.AttachGlyph(_face.Glyph, out QRectangle uvs); - - entry.Metrics = new QuikGlyph( - character, - uvs, - new QVec2(_face.Glyph.Metrics.Width / 64f, _face.Glyph.Metrics.Height / 64f), - new QVec2(_face.Glyph.Metrics.HorizontalBearingX / 64f, _face.Glyph.Metrics.HorizontalBearingY / 64f), - new QVec2(_face.Glyph.Metrics.VerticalBearingX / 64f , _face.Glyph.Metrics.VerticalBearingY / 64f), - new QVec2(_face.Glyph.Metrics.HorizontalAdvance / 64f, _face.Glyph.Metrics.VerticalAdvance / 64f)); - - _entries[character] = entry; - - texture = entry.Atlas.Texture; - glyph = entry.Metrics; - } - - public bool IsDisposed { get; private set; } = false; - - private void Dispose(bool disposing) - { - if (IsDisposed) return; - - if (disposing) - { - foreach (Atlas atlas in _textures) - { - atlas.Dispose(); - } - } - - FT.DoneFace(_face); - IsDisposed = true; - } - - public void Dispose() => Dispose(true); - - private class Atlas : IDisposable - { - public QuikTexture Texture; - - private QVec2 _pointer = new QVec2(); - private float _verticalAdvance = 0; - private FTLibrary _ft; - private FTBitmap _bitmap; - - public Atlas(IQuikTextureManager textureManager, FTLibrary ft) - { - Texture = textureManager.CreateTexture( - new QVec2(4096, 4096), - false, - QuikImageFormat.RgbaU8); - - FT.BitmapInit(ref _bitmap); - _ft = ft; - } - - public bool CanFit(in FTGlyphSlot slot) - { - // FIXME: the atlas will overflow. - return true; - } - - public void AttachGlyph(in FTGlyphSlot slot, out QRectangle UVs) - { - FT.BitmapConvert(_ft, slot.Bitmap, ref _bitmap, 1); - - QRectangle position = - new QRectangle( - _pointer + new QVec2(_bitmap.Width + 1, _bitmap.Rows + 1), - _pointer + new QVec2(1, 1)); - - Texture.SubImage( - _bitmap.Buffer, - QuikImageFormat.AlphaU8, - position, - 0, - 1); - - _pointer.X += _bitmap.Width + 2; - _verticalAdvance = Math.Max(_verticalAdvance, slot.Bitmap.Rows + 2); - - UVs = new QRectangle( - position.Right / 4096, - position.Bottom / 4096, - position.Left / 4096, - position.Top / 4096 - ); - } - - private bool _isDisposed = false; - - public void Dispose(bool disposing) - { - if (_isDisposed) return; - if (disposing) - { - Texture.Dispose(); - } - FT.BitmapDone(_ft, ref _bitmap); - _isDisposed = true; - } - - public void Dispose() - { - } - } - - private class GlyphEntry - { - public int Character; - public Atlas Atlas; - public QuikGlyph Metrics; - } - } -} \ No newline at end of file diff --git a/Quik.FreeType/FreeTypeFontManager.cs b/Quik.FreeType/FreeTypeFontManager.cs deleted file mode 100644 index b585e59..0000000 --- a/Quik.FreeType/FreeTypeFontManager.cs +++ /dev/null @@ -1,177 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using Quik.Typography; - -namespace Quik.FreeType -{ - public class FreeTypeFontManager : IQuikFontManager, IDisposable - { - public QuikContext Context { get; set; } - - internal FTLibrary _library; - private Dictionary _cache = new Dictionary(); - private Dictionary _fonts= new Dictionary(); - - public event FreeTypeFontManagerFontFinder FontNotFound; - - public FreeTypeFontManager() - { - FT.InitFreeType(out _library); - - // FIXME: There are operating system specific ways to achieve this. This is - // definitely not the best way to do this. - - // Scan the fonts folder and build up a font cache. - string path = Environment.GetFolderPath(Environment.SpecialFolder.Fonts); - if (string.IsNullOrEmpty(path)) - { - if (OperatingSystem.IsLinux()) - { - path = "/usr/share/fonts"; - } - else if (OperatingSystem.IsWindows()) - { - path = Path.Combine( - Environment.GetFolderPath(Environment.SpecialFolder.Windows), - "Fonts"); - } - // For macOS I don't know. Too bad. - } - - DirectoryInfo directory = new DirectoryInfo(path); - ScanDirectoryForFonts(directory); - } - - private void ScanDirectoryForFonts(DirectoryInfo directory) - { - foreach (FileSystemInfo node in directory.GetFileSystemInfos()) - { - if (node.Attributes.HasFlag(FileAttributes.Directory)) - { - ScanDirectoryForFonts(node as DirectoryInfo); - } - else - { - ScanFileForFonts(node as FileInfo); - } - } - } - - private void ScanFileForFonts(FileInfo file) - { - if (file is null) return; - - if (FT.NewFace(_library, file.FullName, 0, out FTFace face) == FTError.None) - { - FontCacheEntry entry; - string name = face.FamilyName; - string style = face.StyleName; - - if (name is null) - goto done_face; - - if (_cache.ContainsKey(name)) - { - entry = _cache[name]; - } - else - { - entry = new FontCacheEntry(); - entry.Family = name; - _cache[name] = entry; - } - - switch (style.ToLowerInvariant()) - { - case "regular": - entry.Regular = file; - break; - case "bold": - entry.Bold = file; - break; - case "italic": - entry.Italic = file; - break; - } - - done_face: - FT.DoneFace(face); - } - } - - public void Clear() - { - // Nothing to do. - } - - public QuikFont GetFont(QuikFontStyle fontStyle) - { - FreeTypeFont font; - - if (_fonts.TryGetValue(fontStyle, out font)) - return font; - - FileInfo file = FindFont(fontStyle); - if (file == null) - { - FontNotFound?.Invoke(fontStyle, ref file); - if (file == null) - { - throw new Exception("Could not find the font you are looking for."); - } - } - - font = new FreeTypeFont(this, file, fontStyle); - _fonts.Add(fontStyle, font); - return font; - } - - private FileInfo FindFont(QuikFontStyle fontStyle) - { - FontCacheEntry entry; - if (_cache.TryGetValue(fontStyle.Family, out entry)) - { - switch (fontStyle.Type) - { - case QuikFontType.Normal: - return entry.Regular; - case QuikFontType.Bold: - return entry.Bold; - case QuikFontType.Italic: - return entry.Italic; - } - } - - return null; - } - - - // IDisposable - private void ReleaseUnmanagedResources() - { - FT.DoneFreeType(_library); - } - - public void Dispose() - { - ReleaseUnmanagedResources(); - GC.SuppressFinalize(this); - } - - ~FreeTypeFontManager() - { - ReleaseUnmanagedResources(); - } - - private class FontCacheEntry - { - public string Family; - public FileInfo Regular; - public FileInfo Bold; - public FileInfo Italic; - } - } - - public delegate void FreeTypeFontManagerFontFinder(QuikFontStyle style, ref FileInfo info); -} \ No newline at end of file diff --git a/Quik.FreeType/Quik.FreeType.csproj b/Quik.FreeType/Quik.FreeType.csproj deleted file mode 100644 index a11ae84..0000000 --- a/Quik.FreeType/Quik.FreeType.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - - net6.0 - 7.3 - true - - - - - - - diff --git a/Quik.FreeType/Structures.cs b/Quik.FreeType/Structures.cs deleted file mode 100644 index 046b38f..0000000 --- a/Quik.FreeType/Structures.cs +++ /dev/null @@ -1,180 +0,0 @@ -using System; -using System.Runtime.InteropServices; - -namespace Quik.FreeType -{ - public struct FTLibrary - { - private IntPtr _handle; - public IntPtr Handle => _handle; - } - - public unsafe struct FTFace - { - private IntPtr _handle; - public IntPtr Handle => _handle; - private unsafe FTFaceInternal* Ptr => (FTFaceInternal*)_handle; - - public long NumberOfGlyphs => Ptr->NumberOfGlyphs; - public long FaceIndex => Ptr->FaceIndex; - public FaceFlag FaceFlags => (FaceFlag)Ptr->FaceFlags; - public long StyleFlags => Ptr->StyleFlags; - public string FamilyName => Marshal.PtrToStringUTF8(Ptr->FamilyName); - public string StyleName => Marshal.PtrToStringUTF8(Ptr->StyleName); - public int NumberOfFixedSizes => Ptr->NumberOfFixedSizes; - public int NumberOfCharMaps => Ptr->NumberOfCharMaps; - public FTGlyphSlot Glyph => Ptr->Glyph; - public short Ascender => Ptr->Ascender; - public short Descender => Ptr->Descender; - public ref readonly FTSizeMetrics ScaledSize => ref ((FTSize*)Ptr->Size)->Metrics; - } - - public struct FTBox - { - public long XMin; - public long YMin; - public long XMax; - public long YMax; - } - - internal struct FTFaceInternal - { - public long NumberOfFaces; - public long FaceIndex; - public long FaceFlags; - public long StyleFlags; - public long NumberOfGlyphs; - public IntPtr FamilyName; - public IntPtr StyleName; - public int NumberOfFixedSizes; - public IntPtr AvailableSizes; - public int NumberOfCharMaps; - public IntPtr Charmaps; - public FTGeneric Generic; - public FTBox BoundingBox; - public ushort UnitsPerEm; - public short Ascender; - public short Descender; - public short Height; - public short MaxAdvanceWidth; - public short MaxAdvanceHeight; - public short UnderlinePosition; - public short UnderlineThickness; - public FTGlyphSlot Glyph; - public IntPtr Size; - public IntPtr Charmap; - - // Rest of the struct is private to implementation. - } - - public struct FTGeneric - { - public IntPtr Data; - public IntPtr Finalizer; - } - - public struct FTVector - { - public long X; - public long Y; - } - - public struct FTBitmap - { - public uint Rows; - public uint Width; - public int Pitch; - public IntPtr Buffer; - public ushort NumberOfGrays; - public byte PixelMode; - public byte PaletteMode; - public IntPtr Palette; - } - - public struct FTOutline - { - public short NumberOfContours; - public short NumberOfPoints; - public IntPtr Points; - public IntPtr Tags; - public IntPtr Contours; - public int Flags; - } - - internal struct FTGlyphSlotInternal - { - public FTLibrary Library; - public FTFace Face; - public FTGlyphSlot Next; - public uint GlyphIndex; - public FTGeneric Generic; - public FTGlyphMetrics Metrics; - public long LinearHorizontalAdvance; - public long LinearVerticalAdvance; - public FTVector Advance; - public int Format; - public FTBitmap Bitmap; - public int BitmapLeft; - public int BitmapTop; - public FTOutline Outline; - public uint NumberOfSubGlyphs; - public IntPtr SubGlyphs; - public IntPtr ControlData; - public long ControlLength; - public long LsbDelta; - public long RsbDelta; - public IntPtr Other; - public IntPtr Internal; - } - - public unsafe struct FTGlyphSlot - { - private IntPtr _handle; - public IntPtr Handle => _handle; - private FTGlyphSlotInternal* Ptr => (FTGlyphSlotInternal*) _handle; - - public FTLibrary Library => Ptr->Library; - public FTFace Face => Ptr->Face; - public FTGlyphSlot Next => Ptr->Next; - public uint GlyphIndex => Ptr->GlyphIndex; - public ref readonly FTGlyphMetrics Metrics => ref Ptr->Metrics; - public long LinearHorizontalAdvance => Ptr->LinearHorizontalAdvance; - public long LinearVerticalAdvance => Ptr->LinearVerticalAdvance; - public FTVector Advance => Ptr->Advance; - public ref readonly FTBitmap Bitmap => ref Ptr->Bitmap; - public long BitmapLeft => Ptr->BitmapLeft; - public long BitmapTop => Ptr->BitmapTop; - } - - public struct FTGlyphMetrics - { - public long Width; - public long Height; - public long HorizontalBearingX; - public long HorizontalBearingY; - public long HorizontalAdvance; - public long VerticalBearingX; - public long VerticalBearingY; - public long VerticalAdvance; - } - - public struct FTSizeMetrics - { - public short Xppem; - public short Yppem; - public long XScale; - public long YScale; - public long Ascender; - public long Descender; - public long Height; - public long MaxAdvance; - } - - public struct FTSize - { - public IntPtr Face; - public FTGeneric Generic; - public FTSizeMetrics Metrics; - private IntPtr Privates; - } -} \ No newline at end of file diff --git a/Quik.sln b/Quik.sln index c10197d..e071d92 100644 --- a/Quik.sln +++ b/Quik.sln @@ -1,14 +1,10 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# +# Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Quik", "Quik\Quik.csproj", "{B86B2B99-DAE4-43CE-A040-1D8E143B94A7}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Quik.OpenTK", "Quik.OpenTK\Quik.OpenTK.csproj", "{586E5E28-1D07-4CC2-B04F-0BC420564F57}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuikTestApplication", "QuikTestApplication\QuikTestApplication.csproj", "{49AEF502-692A-48A4-8076-EF2228925280}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Quik.FreeType", "Quik.FreeType\Quik.FreeType.csproj", "{53B95098-F304-47E6-A08C-DAFA589F5BCF}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -43,29 +39,5 @@ Global {586E5E28-1D07-4CC2-B04F-0BC420564F57}.Release|x64.Build.0 = Release|Any CPU {586E5E28-1D07-4CC2-B04F-0BC420564F57}.Release|x86.ActiveCfg = Release|Any CPU {586E5E28-1D07-4CC2-B04F-0BC420564F57}.Release|x86.Build.0 = Release|Any CPU - {49AEF502-692A-48A4-8076-EF2228925280}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {49AEF502-692A-48A4-8076-EF2228925280}.Debug|Any CPU.Build.0 = Debug|Any CPU - {49AEF502-692A-48A4-8076-EF2228925280}.Debug|x64.ActiveCfg = Debug|Any CPU - {49AEF502-692A-48A4-8076-EF2228925280}.Debug|x64.Build.0 = Debug|Any CPU - {49AEF502-692A-48A4-8076-EF2228925280}.Debug|x86.ActiveCfg = Debug|Any CPU - {49AEF502-692A-48A4-8076-EF2228925280}.Debug|x86.Build.0 = Debug|Any CPU - {49AEF502-692A-48A4-8076-EF2228925280}.Release|Any CPU.ActiveCfg = Release|Any CPU - {49AEF502-692A-48A4-8076-EF2228925280}.Release|Any CPU.Build.0 = Release|Any CPU - {49AEF502-692A-48A4-8076-EF2228925280}.Release|x64.ActiveCfg = Release|Any CPU - {49AEF502-692A-48A4-8076-EF2228925280}.Release|x64.Build.0 = Release|Any CPU - {49AEF502-692A-48A4-8076-EF2228925280}.Release|x86.ActiveCfg = Release|Any CPU - {49AEF502-692A-48A4-8076-EF2228925280}.Release|x86.Build.0 = Release|Any CPU - {53B95098-F304-47E6-A08C-DAFA589F5BCF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {53B95098-F304-47E6-A08C-DAFA589F5BCF}.Debug|Any CPU.Build.0 = Debug|Any CPU - {53B95098-F304-47E6-A08C-DAFA589F5BCF}.Debug|x64.ActiveCfg = Debug|Any CPU - {53B95098-F304-47E6-A08C-DAFA589F5BCF}.Debug|x64.Build.0 = Debug|Any CPU - {53B95098-F304-47E6-A08C-DAFA589F5BCF}.Debug|x86.ActiveCfg = Debug|Any CPU - {53B95098-F304-47E6-A08C-DAFA589F5BCF}.Debug|x86.Build.0 = Debug|Any CPU - {53B95098-F304-47E6-A08C-DAFA589F5BCF}.Release|Any CPU.ActiveCfg = Release|Any CPU - {53B95098-F304-47E6-A08C-DAFA589F5BCF}.Release|Any CPU.Build.0 = Release|Any CPU - {53B95098-F304-47E6-A08C-DAFA589F5BCF}.Release|x64.ActiveCfg = Release|Any CPU - {53B95098-F304-47E6-A08C-DAFA589F5BCF}.Release|x64.Build.0 = Release|Any CPU - {53B95098-F304-47E6-A08C-DAFA589F5BCF}.Release|x86.ActiveCfg = Release|Any CPU - {53B95098-F304-47E6-A08C-DAFA589F5BCF}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/QuikTestApplication/Program.cs b/QuikTestApplication/Program.cs deleted file mode 100644 index c8b23c4..0000000 --- a/QuikTestApplication/Program.cs +++ /dev/null @@ -1,183 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using Quik; -using Quik.VertexGenerator; -using OpenTK.Mathematics; -using OpenTK.Graphics.OpenGL4; -using OpenTK.Windowing.Common; -using OpenTK.Windowing.Desktop; -using OpenTK.Windowing.GraphicsLibraryFramework; -using Quik.FreeType; -using Quik.OpenTK; -using Quik.Typography; -using Quik.Controls; -using Quik.OpenGL; -using GL = Quik.OpenGL.GL; -using static Quik.OpenGL.GLEnum; -using Quik.CommandMachine; - -namespace QuikTestApplication -{ - public class Program - { - public const string vertex = - @"#version 140 -uniform mat4 matrix; -in vec2 position; -in vec2 texcoord; -in vec4 color; -out vec2 ftexcoord; -out vec4 fcolor; - -void main() -{ - fcolor = color; - ftexcoord = texcoord; - gl_Position = matrix * vec4(position.xy, 0, 1); -} -"; - - public const string fragment = - @"#version 140 -in vec2 ftexcoord; -in vec4 fcolor; -out vec4 outcolor; - -uniform sampler2D texture0; -uniform vec2 texture0offset; - -void main() -{ - outcolor = fcolor * texture(texture0, ftexcoord + texture0offset); -} -"; - - public static void Main(string[] args) - { - NativeWindowSettings windowSettings = NativeWindowSettings.Default; - windowSettings.NumberOfSamples = 4; - NativeWindow window = new NativeWindow(windowSettings); - - window.Context.MakeCurrent(); - GL.LoadBindings(new GLFWBindingsContext().GetProcAddress); - - FreeTypeFontManager fontManager = new FreeTypeFontManager(); - QuikContext context = new QuikContext(new OpenGLTextureManager(), fontManager); - - VertexGeneratorEngine engine = new VertexGeneratorEngine(); - CommandQueue cmdQueue = new CommandQueue(); - GL30Driver gldriver; - - RootControl root = new RootControl(context); - Button button = new Button() - { - Bounds = new QRectangle(120, 60, 20, 20), - Text = "button", - Padding = 8, - NormalStroke = new QuikStrokeStyle(new QColor(0xccccccff), 4f), - HoverStroke = new QuikStrokeStyle(new QColor(0x1010ccff), 4f), - ActiveStroke = new QuikStrokeStyle(new QColor(0x999999ff), 4f), - }; - button.Clicked += (sender, args) => { - if (!args.Buttons.HasFlag(Quik.MouseButton.Primary)) - return; - - Button xbutton = (Button)sender; - - if (xbutton.Text == "button") - { - xbutton.Text = "le button"; - } - else - { - xbutton.Text = "button"; - } - }; - root.MouseEnter += (_,_) => Console.WriteLine("enter"); - root.MouseLeave += (_,_) => Console.WriteLine("leave"); - root.MouseMove += (_,_) => Console.WriteLine("move"); - root.MouseDown += (_,_) => Console.WriteLine("down"); - root.MouseUp += (_,_) => Console.WriteLine("up"); - root.Add(button); - - GL.Enable(GL_MULTISAMPLE); - - gldriver = new GL30Driver(); - - window.Context.SwapInterval = 0; - Stopwatch stopwatch = Stopwatch.StartNew(); - float lastMs = stopwatch.ElapsedMilliseconds; - int frames = 0; - for (;!window.IsExiting;) - { - NativeWindow.ProcessWindowEvents(false); - window.ProcessEvents(0.0f); - window.TryGetCurrentMonitorDpi(out float dpi, out _); - - if (window.IsFocused) - { - var mouseState = window.MouseState; - QVec2 postion = new QVec2(mouseState.Position.X, window.ClientSize.Y - mouseState.Position.Y) * (dpi/72f); - Quik.MouseButton buttons = - (mouseState.IsButtonDown(OpenTK.Windowing.GraphicsLibraryFramework.MouseButton.Button1) ? Quik.MouseButton.Primary : 0) | - (mouseState.IsButtonDown(OpenTK.Windowing.GraphicsLibraryFramework.MouseButton.Button2) ? Quik.MouseButton.Secondary : 0) | - (mouseState.IsButtonDown(OpenTK.Windowing.GraphicsLibraryFramework.MouseButton.Button3) ? Quik.MouseButton.Tertiary : 0); - - root.NotifyMouse(new Quik.MouseState(postion, buttons)); - } - - root.Bounds = new QRectangle( - window.ClientSize.X, - window.ClientSize.Y, - 0, - 0); - root.NotifyUpdate(); - - cmdQueue.Clear(); - root.NotifyPaint(cmdQueue); - - engine.Reset(); - engine.ProcessCommands(root.Bounds, cmdQueue); - - DrawQueue drawQueue = engine.DrawQueue; - - GL.Clear(GL_COLOR_BUFFER_BIT); - gldriver.Draw(drawQueue); - - window.Context.SwapBuffers(); - - frames++; - float ms = stopwatch.ElapsedMilliseconds; - if (ms - lastMs > 1000) - { - Console.WriteLine("Frames: {0}", frames*(ms - lastMs)/1000); - frames = 0; - lastMs = ms; - Console.WriteLine("Vertex Usage: {0} ; Element Usage: {1} Calls: {2}", drawQueue.VertexCount, drawQueue.ElementCount, drawQueue.DrawCallCount); - } - } - } - - public class TextFontManager : IQuikFontManager - { - public QuikContext Context { get; set; } - - private TestFont _font; - - public void Clear() - { - } - - public QuikFont GetFont(QuikFontStyle fontStyle) - { - if (_font is null) - { - _font = new TestFont(Context); - } - - return _font; - } - } - } -} \ No newline at end of file diff --git a/QuikTestApplication/QuikTestApplication.csproj b/QuikTestApplication/QuikTestApplication.csproj deleted file mode 100644 index 5ff706b..0000000 --- a/QuikTestApplication/QuikTestApplication.csproj +++ /dev/null @@ -1,21 +0,0 @@ - - - - Exe - net6.0 - true - - - - - - - - - - - - - - - diff --git a/QuikTestApplication/TestFont.cs b/QuikTestApplication/TestFont.cs deleted file mode 100644 index f9ff127..0000000 --- a/QuikTestApplication/TestFont.cs +++ /dev/null @@ -1,126 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Xml; -using Quik; -using Quik.Typography; - -namespace QuikTestApplication -{ - public class TestFont : QuikFont - { - public override QuikFontStyle Style => _style; - - private static QuikFontStyle _style; - private static HashSet _characters = new HashSet(); - private static Dictionary _glyphs = new Dictionary(); - - public static byte[] TextureData { get; private set; } = Array.Empty(); - public static QVec2 TextureSize { get; private set; } - - public QuikTexture Texture { get; } - - public override float Ascender => throw new NotImplementedException(); - - public override float Descender => throw new NotImplementedException(); - - public TestFont(QuikContext context) - { - Texture = context.TextureManager.CreateTexture(TextureSize, false, QuikImageFormat.RgbaU8); - unsafe - { - fixed (byte* ptr = &TextureData[0]) - { - Texture.Image((IntPtr)ptr, QuikImageFormat.RgbaU8, TextureSize, 0); - } - } - } - - static TestFont() - { - using (Stream str = typeof(TestFont).Assembly.GetManifestResourceStream("QuikTestApplication.font.xml")) - { - XmlDocument document = new XmlDocument(); - document.Load(str); - - string family = document.DocumentElement.Attributes["name"].Value; - float fontSize = float.Parse(document.DocumentElement.Attributes["size"].Value); - QuikFontType style = QuikFontType.Normal; - if (document.DocumentElement.Attributes["bold"].Value == "true") - style = QuikFontType.Bold; - if (document.DocumentElement.Attributes["italic"].Value == "true") - style = QuikFontType.Italic; - - _style = new QuikFontStyle(family, fontSize, style); - - QVec2 atlasSize = default; - atlasSize.X = float.Parse(document.DocumentElement.Attributes["width"].Value); - atlasSize.Y = float.Parse(document.DocumentElement.Attributes["height"].Value); - - TextureSize = atlasSize; - - foreach (XmlElement element in document.SelectNodes("/font/character")) - { - QRectangle UVs; - QVec2 origin; - float advance; - int chr = element.Attributes["text"].Value[0]; - - QVec2 pos; - QVec2 size; - pos.X = float.Parse(element.Attributes["x"].Value); - pos.Y = float.Parse(element.Attributes["y"].Value); - size.X = float.Parse(element.Attributes["width"].Value); - size.Y = float.Parse(element.Attributes["height"].Value); - UVs = new QRectangle( - (pos.X + size.X)/atlasSize.X, - pos.Y/atlasSize.Y, - pos.X/atlasSize.X, - (size.Y + pos.Y)/atlasSize.Y); - - origin.X = float.Parse(element.Attributes["origin-x"].Value); - origin.Y = float.Parse(element.Attributes["origin-y"].Value); - - advance = float.Parse(element.Attributes["advance"].Value); - - QuikGlyph glyph = new QuikGlyph(chr, UVs, size, origin, default, new QVec2(advance, 0)); - _glyphs.Add(chr, glyph); - _characters.Add(chr); - } - } - - using (Stream str = typeof(TestFont).Assembly.GetManifestResourceStream("QuikTestApplication.font.dat")) - { - TextureData = new byte[(int)str.Length]; - str.Read(TextureData, 0, (int)str.Length); - } - - // Evil pointer stuff. Beware! - Span head = MemoryMarshal.Cast(TextureData); - for (int i = 0; i < head.Length; i++) - { - if (head[i] == 0xff000000) - { - head[i] = 0x00000000; - } - } - } - - public override bool HasCharacter(int character) - { - return _characters.Contains((char) character); - } - - public override void GetCharacter(int character, out QuikTexture texture, out QuikGlyph glyph) - { - if (!_glyphs.TryGetValue(character, out glyph)) - { - glyph = _glyphs['?']; - } - - texture = Texture; - } - } -} \ No newline at end of file diff --git a/QuikTestApplication/font.dat b/QuikTestApplication/font.dat deleted file mode 100644 index 1c997c7..0000000 Binary files a/QuikTestApplication/font.dat and /dev/null differ diff --git a/QuikTestApplication/font.png b/QuikTestApplication/font.png deleted file mode 100644 index eaa57da..0000000 Binary files a/QuikTestApplication/font.png and /dev/null differ diff --git a/QuikTestApplication/font.xml b/QuikTestApplication/font.xml deleted file mode 100644 index 7ace8aa..0000000 --- a/QuikTestApplication/font.xml +++ /dev/null @@ -1,98 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file