<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
- <TargetFramework>netcoreapp3.0</TargetFramework>
+ <TargetFramework>netcoreapp3.0</TargetFramework>
+ <EnableDefaultCompileItems>false</EnableDefaultCompileItems>
</PropertyGroup>
- <ItemGroup>
- <Compile Include="src\**\*.cs" />
- </ItemGroup>
+ <ItemGroup>
+ <Compile Include="src\**\*.cs" Exclude="src\NativeMethods-internal.cs"/>
+ </ItemGroup>
+
+ <ItemGroup>
+ <PackageReference Include="glfw-sharp" Version="$(GlfwSharpVersion)" />
+ <ProjectReference Include="..\..\Drawing2D\Drawing2D.csproj" />
+ </ItemGroup>
- <ItemGroup>
- <ProjectReference Include="..\..\Drawing2D\Drawing2D.csproj" />
- </ItemGroup>
</Project>
using System;
using System.Runtime.InteropServices;
-namespace Crow.Drawing
+namespace Crow.CairoBackend
{
public static class CairoAPI {
static public int Version {
using System;
-namespace Crow.Drawing {
-
+namespace Crow.CairoBackend
+{
static class CairoDebug
{
static System.Collections.Generic.Dictionary<IntPtr,string> traces;
using System;
-namespace Crow.Drawing
+namespace Crow.CairoBackend
{
//[Flags]
public enum Content
using System.Text;
using Drawing2D;
-namespace Crow.Drawing {
-
- [Obsolete ("Renamed Cairo.Context per suggestion from cairo binding guidelines.")]
- public class Graphics : Context {
- public Graphics (IntPtr state) : base (state) {}
- public Graphics (Surface surface) : base (surface) {}
- }
-
- public class Context : IDisposable
+namespace Crow.CairoBackend
+{
+ public class Context : IContext
{
IntPtr handle = IntPtr.Zero;
}
}
- public Context (Surface surface) : this (NativeMethods.cairo_create (surface.Handle), true)
+ public Context (ISurface surface) : this (NativeMethods.cairo_create (surface.Handle), true)
{
}
NativeMethods.cairo_identity_matrix (handle);
}
- [Obsolete ("Use SetFontSize() instead.")]
- public void FontSetSize (double scale)
- {
- SetFontSize (scale);
- }
-
- [Obsolete ("Use SetFontSize() instead.")]
- public double FontSize {
- set { SetFontSize (value); }
- }
-
public Matrix FontMatrix {
get {
Matrix m;
NativeMethods.cairo_copy_page (handle);
}
- [Obsolete ("Use SelectFontFace() instead.")]
- public void FontFace (string family, FontSlant slant, FontWeight weight)
- {
- SelectFontFace (family, slant, weight);
- }
-
public void SetContextFontFace (FontFace value)
{
NativeMethods.cairo_set_font_face (handle, value == null ? IntPtr.Zero : value.Handle);
//
using System;
-namespace Crow.Drawing
+namespace Crow.CairoBackend
{
public class DRMDevice : Device
{
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
-//
+//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
-//
+//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
//
using System;
+using Drawing2D;
-namespace Crow.Drawing {
+namespace Crow.CairoBackend {
public class DRMSurface : Surface
{
-
+
public DRMSurface (IntPtr ptr, bool own) : base (ptr, own)
{}
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
+using Drawing2D;
+using Glfw;
-namespace Crow.Drawing
+namespace Crow.CairoBackend
{
- public class Device : IDisposable
+ public class Device : IDevice
{
IntPtr handle = IntPtr.Zero;
+ /// <summary> Global font rendering settings for Cairo </summary>
+ FontOptions FontRenderingOptions;
+ /// <summary> Global font rendering settings for Cairo </summary>
+ Antialias Antialias = Antialias.Subpixel;
protected Device()
{
+ FontRenderingOptions = new FontOptions ();
+ FontRenderingOptions.Antialias = Antialias.Subpixel;
+ FontRenderingOptions.HintMetrics = HintMetrics.On;
+ FontRenderingOptions.HintStyle = HintStyle.Full;
+ FontRenderingOptions.SubpixelOrder = SubpixelOrder.Default;
}
protected Device (IntPtr ptr) : this (ptr, true)
return;
NativeMethods.cairo_device_destroy (handle);
+
+ FontRenderingOptions.Dispose ();
handle = IntPtr.Zero;
}
+
+ public void GetDpy(out int hdpy, out int vdpy)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void SetDpy(int hdpy, int vdpy)
+ {
+ throw new NotImplementedException();
+ }
+
+ public virtual ISurface CreateSurface(int width, int height)
+ {
+ throw new NotImplementedException();
+ }
+ public ISurface CreateSurface (IntPtr nativeWindoPointer, int width, int height) {
+ switch (Environment.OSVersion.Platform) {
+ case PlatformID.Unix:
+ IntPtr disp = Glfw3.GetX11Display ();
+ IntPtr nativeWin = Glfw3.GetX11Window (nativeWindoPointer);
+ Int32 scr = Glfw3.GetX11DefaultScreen (disp);
+ IntPtr visual = Glfw3.GetX11DefaultVisual (disp, scr);
+ return new XlibSurface (disp, nativeWin, visual, width, height);
+ case PlatformID.Win32NT:
+ case PlatformID.Win32S:
+ case PlatformID.Win32Windows:
+ IntPtr hWin32 = Glfw3.GetWin32Window (nativeWindoPointer);
+ IntPtr hdc = Glfw3.GetWin32DC (hWin32);
+ return new Win32Surface (hdc);
+ }
+ throw new PlatformNotSupportedException ("Unable to create cairo surface.");
+ }
+
+ public virtual IContext CreateContext(ISurface surf)
+ {
+ Context gr = new Context (surf);
+ gr.FontOptions = FontRenderingOptions;
+ gr.Antialias = Antialias;
+ throw new NotImplementedException();
+ }
}
}
using System;
-namespace Crow.Drawing {
+namespace Crow.CairoBackend {
public class DirectFBSurface : Surface
{
internal DirectFBSurface (IntPtr handle, bool owns) : base (handle, owns)
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-namespace Crow.Drawing {
+namespace Crow.CairoBackend {
public struct Distance
{
//
using System;
-namespace Crow.Drawing
+namespace Crow.CairoBackend
{
public class EGLDevice : Device
{
+++ /dev/null
-//
-// Mono.Cairo.Extend.cs
-//
-// Authors:
-// Duncan Mak (duncan@ximian.com)
-// Hisham Mardam Bey (hisham.mardambey@gmail.com)
-// John Luke (john.luke@gmail.com)
-//
-// (C) Ximian, Inc. 2003
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
-// Copyright (C) 2005 John Luke
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System;
-
-namespace Crow.Drawing
-{
-
- public enum Extend
- {
- None,
- Repeat,
- Reflect,
- Pad,
- }
-}
+++ /dev/null
-//
-// Mono.Cairo.FillRule.cs
-//
-// Authors:
-// Duncan Mak (duncan@ximian.com)
-// Hisham Mardam Bey (hisham.mardambey@gmail.com)
-//
-// (C) Ximian, Inc. 2003
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System;
-
-namespace Crow.Drawing
-{
-
- public enum FillRule
- {
- Winding,
- EvenOdd
- }
-}
+++ /dev/null
-//
-// Mono.Cairo.Filter.cs
-//
-// Authors:
-// Duncan Mak (duncan@ximian.com)
-// Hisham Mardam Bey (hisham.mardambey@gmail.com)
-//
-// (C) Ximian, Inc. 2003
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System;
-
-namespace Crow.Drawing
-{
-
- public enum Filter
- {
- Fast,
- Good,
- Best,
- Nearest,
- Bilinear,
- Gaussian,
- }
-}
+++ /dev/null
-//
-// Mono.Cairo.FontExtents.cs
-//
-// Authors: Duncan Mak (duncan@ximian.com)
-// Hisham Mardam Bey (hisham.mardambey@gmail.com)
-//
-// (C) Ximian, Inc. 2003
-//
-// This is a simplistic binding of the Cairo API to C#. All functions
-// in cairo.h are transcribed into their C# equivelants
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System;
-using System.Runtime.InteropServices;
-
-namespace Crow.Drawing
-{
- [StructLayout (LayoutKind.Sequential)]
- public struct FontExtents
- {
- double ascent;
- double descent;
- double height;
- double maxXAdvance;
- double maxYAdvance;
-
- public double Ascent {
- get { return ascent; }
- set { ascent = value; }
- }
-
- public double Descent {
- get { return descent; }
- set { descent = value; }
- }
-
- public double Height {
- get { return height; }
- set { height = value; }
- }
-
- public double MaxXAdvance {
- get { return maxXAdvance; }
- set { maxXAdvance = value; }
- }
-
- public double MaxYAdvance {
- get { return maxYAdvance; }
- set { maxYAdvance = value; }
- }
-
- public FontExtents (double ascent, double descent, double height, double maxXAdvance, double maxYAdvance)
- {
- this.ascent = ascent;
- this.descent = descent;
- this.height = height;
- this.maxXAdvance = maxXAdvance;
- this.maxYAdvance = maxYAdvance;
- }
-
- public override bool Equals (object obj)
- {
- if (obj is FontExtents)
- return this == (FontExtents) obj;
- return false;
- }
-
- public override int GetHashCode ()
- {
- return (int) Ascent ^ (int) Descent ^ (int) Height ^ (int) MaxXAdvance ^ (int) MaxYAdvance;
- }
-
- public static bool operator == (FontExtents extents, FontExtents other)
- {
- return extents.Ascent == other.Ascent && extents.Descent == other.Descent && extents.Height == other.Height && extents.MaxXAdvance == other.MaxXAdvance && extents.MaxYAdvance == other.MaxYAdvance;
- }
-
- public static bool operator != (FontExtents extents, FontExtents other)
- {
- return !(extents == other);
- }
- }
-}
//
using System;
-namespace Crow.Drawing
+namespace Crow.CairoBackend
{
public class FontFace : IDisposable
{
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
-//
+//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
-//
+//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
//
using System;
+using Drawing2D;
-namespace Crow.Drawing
+namespace Crow.CairoBackend
{
public class FontOptions : IDisposable
{
{
return (int) NativeMethods.cairo_font_options_hash (handle);
}
-
+
public void Merge (FontOptions other)
{
if (other == null)
+++ /dev/null
-//
-// Mono.Cairo.FontSlant.cs
-//
-// Authors:
-// Duncan Mak (duncan@ximian.com)
-// Hisham Mardam Bey (hisham.mardambey@gmail.com)
-//
-// (C) Ximian, Inc. 2003
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System;
-
-namespace Crow.Drawing
-{
-
- public enum FontSlant
- {
- Normal,
- Italic,
- Oblique
- }
-}
using System;
-namespace Crow.Drawing {
+namespace Crow.CairoBackend {
-
public enum FontType
{
Toy,
+++ /dev/null
-//
-// Mono.Cairo.FontWeight.cs
-//
-// Authors:
-// Duncan Mak (duncan@ximian.com)
-// Hisham Mardam Bey (hisham.mardambey@gmail.com)
-//
-// (C) Ximian, Inc. 2003
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System;
-
-namespace Crow.Drawing
-{
-
- public enum FontWeight
- {
- Normal,
- Bold,
- }
-}
using System;
-namespace Crow.Drawing {
+namespace Crow.CairoBackend {
public class GLSurface : Surface
{
//
using System;
-namespace Crow.Drawing
+namespace Crow.CairoBackend
{
public class GLXDevice : Device
{
using System;
-namespace Crow.Drawing {
+namespace Crow.CairoBackend {
public class GlitzSurface : Surface
{
internal GlitzSurface (IntPtr handle, bool owns) : base (handle, owns)
using System;
using System.Runtime.InteropServices;
-namespace Crow.Drawing
+namespace Crow.CairoBackend
{
[StructLayout(LayoutKind.Sequential)]
public struct Glyph
//
using System;
-using Color = Crow.Color;
-namespace Crow.Drawing {
+using Color = Drawing2D.Color;
+
+namespace Crow.CairoBackend {
public class Gradient : Pattern
{
using System;
-namespace Crow.Drawing
+namespace Crow.CairoBackend
{
public enum HintMetrics
using System;
-namespace Crow.Drawing
+namespace Crow.CairoBackend
{
public enum HintStyle
using System;
using System.Runtime.InteropServices;
+using Drawing2D;
-namespace Crow.Drawing {
+namespace Crow.CairoBackend {
public class ImageSurface : Surface
{
}
public override int Width => NativeMethods.cairo_image_surface_get_width (Handle);
- public override int Height => NativeMethods.cairo_image_surface_get_height (Handle);
+ public override int Height => NativeMethods.cairo_image_surface_get_height (Handle);
public byte[] Data {
get {
+++ /dev/null
-//
-// Mono.Cairo.LineCap.cs
-//
-// Authors: Duncan Mak (duncan@ximian.com)
-// Hisham Mardam Bey (hisham.mardambey@gmail.com)
-//
-// (C) Ximian, Inc. 2003
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System;
-
-namespace Crow.Drawing
-{
-
- public enum LineCap
- {
- Butt,
- Round,
- Square,
- }
-}
+++ /dev/null
-//
-// Mono.Cairo.LineJoin.cs
-//
-// Authors: Duncan Mak (duncan@ximian.com)
-// Hisham Mardam Bey (hisham.mardambey@gmail.com)
-//
-// (C) Ximian, Inc. 2003
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System;
-
-namespace Crow.Drawing
-{
-
- public enum LineJoin
- {
- Miter,
- Round,
- Bevel
- }
-}
-
using System;
using Drawing2D;
-namespace Crow.Drawing {
+namespace Crow.CairoBackend {
public class LinearGradient : Gradient
{
using System;
using System.Runtime.InteropServices;
-namespace Crow.Drawing {
+namespace Crow.CairoBackend {
[StructLayout(LayoutKind.Sequential)]
public class Matrix //: ICloneable
using System;
using Drawing2D;
-namespace Crow.Drawing {
+namespace Crow.CairoBackend {
public class MeshPattern : Pattern
{
using System;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
+using Drawing2D;
-namespace Cairo
+namespace Crow.CairoBackend
{
// sort the functions like in the following page so it is easier to find what is missing
// http://cairographics.org/manual/index-all.html
using System.Runtime.InteropServices;
using Drawing2D;
-namespace Crow.Drawing
+namespace Crow.CairoBackend
{
// sort the functions like in the following page so it is easier to find what is missing
// http://cairographics.org/manual/index-all.html
using System;
-namespace Crow.Drawing {
+namespace Crow.CairoBackend {
public class PSSurface : Surface
{
using System.Runtime.InteropServices;
-namespace Crow.Drawing {
+namespace Crow.CairoBackend {
public class Path : IDisposable
{
using System;
using System.Collections;
+using Drawing2D;
-namespace Crow.Drawing {
+namespace Crow.CairoBackend {
public class Pattern : IDisposable
{
+++ /dev/null
-//
-// Mono.Cairo.PatternType.cs
-//
-// Authors:
-// John Luke
-//
-// (C) John Luke, 2006.
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System;
-
-namespace Crow.Drawing {
-
-
- public enum PatternType
- {
- Solid,
- Surface,
- Linear,
- Radial,
- Mesh,
- RasterSource
- }
-}
-
using System;
-namespace Crow.Drawing {
+namespace Crow.CairoBackend {
public class PdfSurface : Surface
{
using System;
-namespace Crow.Drawing {
+namespace Crow.CairoBackend {
public class RadialGradient : Gradient
{
using System.Runtime.InteropServices;
using Drawing2D;
-namespace Crow.Drawing
+namespace Crow.CairoBackend
{
[StructLayout(LayoutKind.Sequential)]
public struct RectangleList {
using System;
using System.Runtime.InteropServices;
+using Drawing2D;
-namespace Crow.Drawing {
-
+namespace Crow.CairoBackend {
public class ScaledFont : IDisposable
{
protected IntPtr handle = IntPtr.Zero;
//
using System;
-using Color = Crow.Color;
-namespace Crow.Drawing {
+using Color = Drawing2D.Color;
+namespace Crow.CairoBackend {
public class SolidPattern : Pattern
{
using System;
-namespace Crow.Drawing
+namespace Crow.CairoBackend
{
public enum Status
using System;
-namespace Crow.Drawing
+namespace Crow.CairoBackend
{
-
public enum SubpixelOrder
{
Default,
using System.Collections;
using Drawing2D;
-namespace Crow.Drawing {
+namespace Crow.CairoBackend {
- public class Surface : IDisposable
+ public class Surface : ISurface
{
IntPtr handle = IntPtr.Zero;
public uint ReferenceCount {
get { return NativeMethods.cairo_surface_get_reference_count (handle); }
}
+
+ public void WriteTo(IntPtr bitmap)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void Clear()
+ {
+ throw new NotImplementedException();
+ }
+
+ public ISurface CreateSimilar(int width, int height)
+ {
+ throw new NotImplementedException();
+ }
}
}
//
using System;
+using Drawing2D;
-namespace Crow.Drawing {
+namespace Crow.CairoBackend {
public class SurfacePattern : Pattern
{
using System;
-namespace Crow.Drawing {
-
-
+namespace Crow.CairoBackend {
public enum SurfaceType
{
Image,
using System;
-namespace Crow.Drawing {
+namespace Crow.CairoBackend {
public class SvgSurface : Surface
{
using System;
-namespace Crow.Drawing {
-
-
+namespace Crow.CairoBackend {
public enum SvgVersion
{
// FIXME: yuck
+++ /dev/null
-//
-// Mono.Cairo.TextExtents.cs
-//
-// Authors:
-// Duncan Mak (duncan@ximian.com)
-// Hisham Mardam Bey (hisham.mardambey@gmail.com)
-//
-// (C) Ximian, Inc. 2003
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System;
-using System.Runtime.InteropServices;
-
-namespace Crow.Drawing
-{
- [StructLayout (LayoutKind.Sequential)]
- public struct TextExtents
- {
- double xbearing;
- double ybearing;
- double width;
- double height;
- double xadvance;
- double yadvance;
-
- public double XBearing {
- get { return xbearing; }
- set { xbearing = value; }
- }
-
- public double YBearing {
- get { return ybearing; }
- set { ybearing = value; }
- }
-
- public double Width {
- get { return width; }
- set { width = value; }
- }
-
- public double Height {
- get { return height; }
- set { height = value; }
- }
-
- public double XAdvance {
- get { return xadvance; }
- set { xadvance = value; }
- }
-
- public double YAdvance {
- get { return yadvance; }
- set { yadvance = value; }
- }
-
- public override bool Equals (object obj)
- {
- if (obj is TextExtents)
- return this == (TextExtents)obj;
- return false;
- }
-
- public override int GetHashCode ()
- {
- return (int)XBearing ^ (int)YBearing ^ (int)Width ^ (int)Height ^ (int)XAdvance ^ (int)YAdvance;
- }
-
- public static bool operator == (TextExtents extents, TextExtents other)
- {
- return extents.XBearing == other.XBearing && extents.YBearing == other.YBearing && extents.Width == other.Width && extents.Height == other.Height && extents.XAdvance == other.XAdvance && extents.YAdvance == other.YAdvance;
- }
-
- public static bool operator != (TextExtents extents, TextExtents other)
- {
- return !(extents == other);
- }
- }
-}
//
using System;
-namespace Crow.Drawing
+namespace Crow.CairoBackend
{
public class WGLDevice : Device
{
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
-//
+//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
-//
+//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
using System;
-namespace Crow.Drawing {
-
+namespace Crow.CairoBackend {
+
public class Win32Surface : Surface
{
internal Win32Surface (IntPtr handle, bool owns) : base (handle, owns)
{
}
-
+
public Win32Surface (IntPtr hdc)
: base (NativeMethods.cairo_win32_surface_create (hdc), true)
{
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
-//
+//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
-//
+//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
using System;
-namespace Crow.Drawing {
+namespace Crow.CairoBackend {
public class XcbSurface : Surface
{
internal XcbSurface (IntPtr handle, bool owns) : base (handle, owns)
return new XcbSurface (ptr, true);
}
public override void SetSize (int width, int height)
- {
+ {
NativeMethods.cairo_xcb_surface_set_size (Handle, width, height);
}
}
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
-//
+//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
-//
+//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
using System;
-namespace Crow.Drawing {
+namespace Crow.CairoBackend {
public class XlibSurface : Surface
{
public int Depth => NativeMethods.cairo_xlib_surface_get_depth (Handle);
public IntPtr Display => NativeMethods.cairo_xlib_surface_get_display (Handle);
public IntPtr Drawable => NativeMethods.cairo_xlib_surface_get_drawable (Handle);
- public override int Width => NativeMethods.cairo_xlib_surface_get_width (Handle);
- public override int Height => NativeMethods.cairo_xlib_surface_get_height (Handle);
+ public override int Width => NativeMethods.cairo_xlib_surface_get_width (Handle);
+ public override int Height => NativeMethods.cairo_xlib_surface_get_height (Handle);
public IntPtr Screen => NativeMethods.cairo_xlib_surface_get_screen (Handle);
public IntPtr Visual=> NativeMethods.cairo_xlib_surface_get_visual (Handle);
using System.Runtime.InteropServices;
using Drawing2D;
-namespace Crow.Drawing {
+namespace Crow.CairoBackend {
public sealed class SvgHandle : IDisposable {
Raw = rsvg_handle_new();
}
public SvgHandle (byte[] data)
- {
+ {
Raw = rsvg_handle_new_from_data(data, new UIntPtr ((ulong) (data == null ? 0 : data.Length)), out IntPtr error);
if (error != IntPtr.Zero) throw new Exception (error.ToString());
}
public SvgHandle (string file_name)
- {
+ {
Raw = rsvg_handle_new_from_file(file_name, out IntPtr error);
if (error != IntPtr.Zero) throw new Exception (error.ToString());
}
public void Render(Context cr) =>
rsvg_handle_render_cairo (Raw, cr == null ? IntPtr.Zero : cr.Handle);
-
+
public void Render (Context cr, string id) =>
rsvg_handle_render_cairo_sub (Raw, cr == null ? IntPtr.Zero : cr.Handle, id);
-
+
[StructLayout(LayoutKind.Sequential)]
struct DimensionData {
return DimensionData.Zero;
return (DimensionData) Marshal.PtrToStructure (raw, typeof (DimensionData));
}
- }
+ }
public Size Dimensions {
get {
DimensionData dimension_data;
}
}
- public void Dispose() {
+ public void Dispose() {
bool raw_ret = rsvg_handle_close(Raw, out IntPtr error);
- if (error != IntPtr.Zero) throw new Exception (error.ToString());
+ if (error != IntPtr.Zero) throw new Exception (error.ToString());
}
}
}
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
+ <EnableDefaultCompileItems>false</EnableDefaultCompileItems>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="glfw-sharp" Version="$(GlfwSharpVersion)" />
</ItemGroup>
- <PropertyGroup Condition=" '$(CrowStbSharp)' == 'true'">
- <DefineConstants>$(DefineConstants);STB_SHARP</DefineConstants>
- </PropertyGroup>
- <ItemGroup Condition=" '$(CrowStbSharp)' == 'true'">
- <PackageReference Include="StbImageSharp" Version="2.22.4" />
- </ItemGroup>
-
<PropertyGroup Condition=" '$(CrowDebugLogEnabled)' == 'true'">
<DefineConstants>$(DefineConstants);DEBUG_LOG</DefineConstants>
</PropertyGroup>
#endif
Dimensions = new Size (stbi.Width, stbi.Height);
#else
- using (StbImage stbi = new StbImage (stream)) {
- image = new byte [stbi.Size];
+ using (StbImage stbi = new StbImage (stream)) {
+ image = new byte [stbi.Size];
#if VKVG
- Marshal.Copy (stbi.Handle, image, 0, stbi.Size);
+ Marshal.Copy (stbi.Handle, image, 0, stbi.Size);
#else
- for (int i = 0; i < stbi.Size; i+=4) {
- //rgba to argb for cairo. ???? looks like bgra to me.
- image [i] = Marshal.ReadByte (stbi.Handle, i + 2);
- image [i + 1] = Marshal.ReadByte (stbi.Handle, i + 1);
- image [i + 2] = Marshal.ReadByte (stbi.Handle, i);
- image [i + 3] = Marshal.ReadByte (stbi.Handle, i + 3);
- }
- #endif
- Dimensions = new Size (stbi.Width, stbi.Height);
+ for (int i = 0; i < stbi.Size; i+=4) {
+ //rgba to argb for cairo. ???? looks like bgra to me.
+ image [i] = Marshal.ReadByte (stbi.Handle, i + 2);
+ image [i + 1] = Marshal.ReadByte (stbi.Handle, i + 1);
+ image [i + 2] = Marshal.ReadByte (stbi.Handle, i);
+ image [i + 3] = Marshal.ReadByte (stbi.Handle, i + 3);
}
+ #endif
+ Dimensions = new Size (stbi.Width, stbi.Height);
+ }
#endif
}
internal static sharedPicture CreateSharedPicture (Stream stream) {
widthRatio = heightRatio;
}
-#if VKVG
- using (Surface tmp = new Surface (iFace.vkvgDevice, bounds.Width, bounds.Height)) {
-#else
- using (Surface tmp = new ImageSurface (Format.Argb32, bounds.Width, bounds.Height)) {
-#endif
- using (IContext gr = new Context (tmp)) {
+ using (ISurface tmp = iFace.Device.CreateSurface (bounds.Width, bounds.Height)) {
+ using (IContext gr = iFace.Device.CreateContext (tmp)) {
gr.Translate (bounds.Left, bounds.Top);
gr.Scale (widthRatio, heightRatio);
gr.Translate ((bounds.Width/widthRatio - Dimensions.Width)/2, (bounds.Height/heightRatio - Dimensions.Height)/2);
-#if VKVG
- using (Surface imgSurf = new Surface (iFace.vkvgDevice, image, Dimensions.Width, Dimensions.Height))
-#else
- using (Surface imgSurf = new ImageSurface (image, Format.Argb32, Dimensions.Width, Dimensions.Height, 4 * Dimensions.Width))
-#endif
- {
+
+ using (ISurface imgSurf = iFace.Device.CreateSurface (bounds.Width, bounds.Height)) {
gr.SetSource (imgSurf, 0,0);
gr.Paint ();
}
ctx.SetSource (tmp);
}
}
-#endregion
+ #endregion
/// <summary>
/// paint the image in the rectangle given in arguments according
if (!Directory.Exists (CROW_CONFIG_ROOT))
Directory.CreateDirectory (CROW_CONFIG_ROOT);
- FontRenderingOptions = new FontOptions ();
- FontRenderingOptions.Antialias = Antialias.Subpixel;
- FontRenderingOptions.HintMetrics = HintMetrics.On;
- FontRenderingOptions.HintStyle = HintStyle.Full;
- FontRenderingOptions.SubpixelOrder = SubpixelOrder.Default;
}
/// <summary>
/// Each time this array is set, the resolved Assemblies will be
initBackend ();
vkCtx.CreateSurface (clientRectangle.Width, clientRectangle.Height, ref surf);
#else
- switch (Environment.OSVersion.Platform) {
- case PlatformID.MacOSX:
- break;
- case PlatformID.Unix:
- IntPtr disp = Glfw3.GetX11Display ();
- IntPtr nativeWin = Glfw3.GetX11Window (hWin);
- Int32 scr = Glfw3.GetX11DefaultScreen (disp);
- IntPtr visual = Glfw3.GetX11DefaultVisual (disp, scr);
- surf = new XlibSurface (disp, nativeWin, visual, clientRectangle.Width, clientRectangle.Height);
- break;
- case PlatformID.Win32NT:
- case PlatformID.Win32S:
- case PlatformID.Win32Windows:
- IntPtr hWin32 = Glfw3.GetWin32Window (hWin);
- IntPtr hdc = Glfw3.GetWin32DC (hWin32);
- surf = new Win32Surface (hdc);
- break;
- case PlatformID.Xbox:
- case PlatformID.WinCE:
- throw new PlatformNotSupportedException ("Unable to create cairo surface.");
- }
+
#endif
}
/// <summary>
vkCtx.CreateSurface (clientRectangle.Width, clientRectangle.Height, ref surf);
#else
surf = new ImageSurface (Format.ARGB32, r.Width, r.Height);
-#endif
- }
- public Surface CreateSurface (ref Rectangle r) {
-#if (VKVG)
- return new Surface (vkvgDevice, r.Width, r.Height);
-#else
- return surf.CreateSimilar (Content.ColorAlpha, r.Width, r.Height);
-#endif
- }
- public Surface CreateSurface (int width, int height) {
-#if (VKVG)
- return new Surface (vkvgDevice, width, height);
-#else
- return surf.CreateSimilar (Content.ColorAlpha, width, height);
-#endif
- }
- public Surface CreateSurface (IntPtr existingSurfaceHandle) {
-#if (VKVG)
- return new Surface (vkvgDevice, existingSurfaceHandle);
-#else
- return Surface.Lookup (existingSurfaceHandle, false);
-#endif
- }
- public Surface CreateSurfaceForData (IntPtr data, int width, int height) {
-#if (VKVG)
- throw new NotImplementedException ();
-#else
- return new ImageSurface (data, Format.Argb32, width, height, width * 4);
#endif
}
public IntPtr SurfacePointer {
get {
lock(UpdateMutex)
-#if (VKVG)
- return (vkCtx as OffscreenVulkanContext).bitmap;
-#else
return surf.Handle;
-#endif
}
}
/// <summary>
/// <summary> Above this count, the layouting is discard for the widget and it
/// will not be rendered on screen </summary>
public static int MaxDiscardCount = 5;
- /// <summary> Global font rendering settings for Cairo </summary>
- public static FontOptions FontRenderingOptions;
- /// <summary> Global font rendering settings for Cairo </summary>
- public static Antialias Antialias = Antialias.Subpixel;
/// <summary>
/// Each control need a ref to the root interface containing it, if not set in Widget.currentInterface,
public event EventHandler<KeyEventArgs> KeyboardKeyUp;*/
#endregion
- /// <summary>Main Cairo surface</summary>
- public Surface surf;
+ /// <summary>Main backend surface</summary>
+ public ISurface surf;
#region Public Fields
/// <summary>Graphic Tree of this interface</summary>
public DragDropEventArgs DragAndDropOperation = null;
internal Widget dragndropHover;
- public Surface DragImage = null;
+ public ISurface DragImage = null;
public Rectangle DragImageBounds, lastDragImageBounds;
public bool DragImageFolowMouse;//prevent dragImg to be moved by mouse
public void ClearDragImage () {
DragImageBounds = lastDragImageBounds = default;
}
}
- public void CreateDragImage (Surface img, Rectangle bounds, bool followMouse = true) {
+ public void CreateDragImage (ISurface img, Rectangle bounds, bool followMouse = true) {
lock (UpdateMutex) {
if (DragImage != null)
ClearDragImage ();
+++ /dev/null
-// Copyright (c) 2019 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
-//
-// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
-using System;
-using System.IO;
-using System.Runtime.InteropServices;
-
-namespace Crow {
- public class StbImage : IDisposable {
- const string stblib = "stb";
-
- [DllImport (stblib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_load")]
- static extern IntPtr Load ([MarshalAs (UnmanagedType.LPStr)] string filename, out int x, out int y, out int channels_in_file, int desired_channels);
-
- [DllImport (stblib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_load_from_memory")]
- static extern IntPtr Load (IntPtr bitmap, int byteCount, out int x, out int y, out int channels_in_file, int desired_channels);
-
- [DllImport (stblib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_image_free")]
- static extern void FreeImage (IntPtr img);
-
- public readonly IntPtr Handle;
- public readonly int Width;
- public readonly int Height;
- public readonly int Channels;
- public int Size => Width * Height * Channels;
-
- /// <summary>
- /// Open image file with STBI library
- /// </summary>
- /// <param name="path">file path</param>
- /// <param name="requestedChannels">Force returned channels count, set 0 for original count</param>
- public StbImage (string path, int requestedChannels = 4) {
- Handle = StbImage.Load (path, out Width, out Height, out Channels, requestedChannels);
- if (Handle == IntPtr.Zero)
- throw new Exception ($"STBI image loading error.");
- if (requestedChannels > 0)
- Channels = requestedChannels;
- }
- /// <summary>
- /// Open image in memory with STBI library
- /// </summary>
- /// <param name="bitmap">raw bitmap datas</param>
- /// <param name="bitmapByteCount">Bitmap byte count.</param>
- /// <param name="requestedChannels">Force returned channels count, set 0 for original count</param>
- public StbImage (IntPtr bitmap, ulong bitmapByteCount, int requestedChannels = 4) {
- Handle = StbImage.Load (bitmap, (int)bitmapByteCount, out Width, out Height, out Channels, requestedChannels);
- if (Handle == IntPtr.Zero)
- throw new Exception ($"STBI image loading error.");
- if (requestedChannels > 0)
- Channels = requestedChannels;
- }
- public StbImage (Stream stream, int requestedChannels = 4)
- {
- byte [] buff = new byte [stream.Length];
- stream.Read (buff, 0, (int)stream.Length);
- GCHandle hnd = GCHandle.Alloc (buff, GCHandleType.Pinned);
- Handle = StbImage.Load (hnd.AddrOfPinnedObject(), (int)stream.Length, out Width, out Height, out Channels, requestedChannels);
- hnd.Free ();
- if (Handle == IntPtr.Zero)
- throw new Exception ($"STBI image loading error.");
- if (requestedChannels > 0)
- Channels = requestedChannels;
- }
- public void Dispose () {
- StbImage.FreeImage (Handle);
- }
- }
-}
using System.ComponentModel;
using System.Collections.Generic;
using System.Linq;
+using Drawing2D;
namespace Crow
{
r.Inflate (r.Width / -3, r.Height / -3);
break;
}
- Surface dragImg = IFace.CreateSurface (r.Width, r.Height);
- using (IContext gr = new Context(dragImg)) {
+ ISurface dragImg = IFace.Device.CreateSurface (r.Width, r.Height);
+ using (IContext gr = IFace.Device.CreateContext (dragImg)) {
gr.LineWidth = 1;
gr.Rectangle (0,0,r.Width,r.Height);
gr.SetSource (0.2,0.3,0.9,0.5);
using System.ComponentModel;
using System.Threading;
-
+using Drawing2D;
using static Crow.Logger;
{
DbgLogger.StartEvent(DbgEvtType.GOUpdateCache, this);
if (!Clipping.IsEmpty) {
- using (IContext gr = new Context (bmp)) {
+ using (IContext gr = IFace.Device.CreateContext (bmp)) {
for (int i = 0; i < Clipping.NumRectangles; i++)
gr.Rectangle(Clipping.GetRectangle(i));
gr.ClipPreserve();
int hoverLine = _multiline ?
(int)Math.Min (Math.Max (0, Math.Floor (mouseLocalPos.Y / (fe.Ascent + fe.Descent))), lines.Count - 1) : 0;
hoverLoc = new CharLocation (hoverLine, -1, mouseLocalPos.X);
- using (IContext gr = new Context (IFace.surf)) {
- setFontForContext (gr);
+ using (IContext gr = IFace.Device.CreateContext (IFace.surf)) {
+ gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight);
+ gr.SetFontSize (Font.Size);
updateLocation (gr, ClientRectangle.Width, ref hoverLoc);
}
}
return false;
}
if (!CurrentLoc.Value.HasVisualX) {
- setFontForContext (ctx);
+ ctx.SelectFontFace (Font.Name, Font.Slant, Font.Wheight);
+ ctx.SetFontSize (Font.Size);
lock (linesMutex) {
if (currentLoc?.Column < 0) {
updateLocation (ctx, ClientRectangle.Width, ref currentLoc);
getLines ();
if (!textMeasureIsUpToDate) {
- using (IContext gr = new Context (IFace.surf)) {
- setFontForContext (gr);
+ using (IContext gr = IFace.Device.CreateContext (IFace.surf)) {
+ gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight);
+ gr.SetFontSize (Font.Size);
measureTextBounds (gr);
}
}
try {
base.onDraw (gr);
- setFontForContext (gr);
+ gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight);
+ gr.SetFontSize (Font.Size);
if (!textMeasureIsUpToDate) {
lock (linesMutex)
Rectangle rb = Slot + Parent.ClientRectangle.Position;
if (!Clipping.IsEmpty) {
- using (IContext gr = new Context (bmp)) {
+ using (IContext gr = IFace.Device.CreateContext (bmp)) {
for (int i = 0; i < Clipping.NumRectangles; i++)
gr.Rectangle(Clipping.GetRectangle(i));
gr.ClipPreserve();
using System;
using System.ComponentModel;
-
+using Drawing2D;
namespace Crow {
public class ScrollingStack : GenericStack {
{
DbgLogger.StartEvent(DbgEvtType.GOUpdateCache, this);
if (!Clipping.IsEmpty) {
- using (IContext gr = new Context (bmp)) {
+ using (IContext gr = IFace.Device.CreateContext (bmp)) {
for (int i = 0; i < Clipping.NumRectangles; i++)
gr.Rectangle(Clipping.GetRectangle(i));
gr.ClipPreserve();
if (size != default (Size))
contentSize = size;
else {
- using (IContext ctx = new Context (IFace.surf)) {
+ using (IContext ctx = IFace.Device.CreateContext (IFace.surf)) {
using (PathParser parser = new PathParser (path))
parser.Draw (ctx, true);
Rectangle r = ctx.StrokeExtents ();
using System.ComponentModel;
using System.IO;
using System.Xml;
-
+using Drawing2D;
namespace Crow
{
#endif
/// <summary>
- /// The interface this widget is bound to when instantiated,
+ /// The interface this widget is bound to when instantiated,
/// </summary>
public readonly Interface IFace = null;
/// <summary>Prevent requeuing multiple times the same widget</summary>
public bool IsQueueForClipping = false;
/// <summary>drawing Cache, if null, a redraw is done on repaint, cached or not</summary>
- public Surface bmp;
+ public ISurface bmp;
/// <summary>
/// If the widget dirty state is set to true, a full redraw will be triggered on paint.
/// </summary>
#endregion
protected void setFontForContext (IContext gr) {
-#if VKVG
- gr.FontFace = Font.Name;
- gr.FontSize = (uint)Font.Size;
-#else
- gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight);
- gr.SetFontSize (Font.Size);
- gr.FontOptions = Interface.FontRenderingOptions;
- gr.Antialias = Interface.Antialias;
-#endif
}
#region Rendering
//bmp = new ImageSurface(Format.Argb32, Slot.Width, Slot.Height);
DbgLogger.StartEvent (DbgEvtType.GOCreateContext, this);
- using (IContext gr = new Context (bmp)) {
+ using (IContext gr = IFace.Device.CreateContext (bmp)) {
DbgLogger.EndEvent (DbgEvtType.GOCreateContext);
- gr.Antialias = Interface.Antialias;
onDraw (gr);
}
<PackageReference Include="Enums.NET" Version="4.0.0" />
</ItemGroup>
+ <PropertyGroup Condition=" '$(CrowStbSharp)' == 'true'">
+ <DefineConstants>$(DefineConstants);STB_SHARP</DefineConstants>
+ </PropertyGroup>
+ <ItemGroup Condition=" '$(CrowStbSharp)' == 'true'">
+ <Compile Remove="src\StbImage.cs" />
+ <PackageReference Include="StbImageSharp" Version="2.22.4" />
+ </ItemGroup>
+
</Project>
+++ /dev/null
-// Copyright (c) 2018-2020 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
-//
-// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
-
-using System;
-
-namespace Drawing2D
-{
- public interface IDevice: IDisposable
- {
- //IntPtr Handle => handle;
-
- void GetDpy (out int hdpy, out int vdpy);
- void SetDpy (int hdpy, int vdpy);
- ISurface CreateSurface (int width, int height);
- }
-}
-
double LineWidth { get; set; }
LineJoin LineJoin { get; set; }
LineCap LineCap { get; set; }
- uint FontSize { get; set; }
- string FontFace { get; set; }
+ void SetFontSize (double scale);
+ void SelectFontFace (string family, FontSlant slant, FontWeight weight);
Operator Operator { get; set; }
FillRule FillRule { get; set; }
- FontExtents FontExtents { get; set; }
+ FontExtents FontExtents { get; }
Antialias Antialias { get; set; }
TextExtents TextExtents (ReadOnlySpan<char> s, int tabSize = 4);
void TextExtents (ReadOnlySpan<char> s, int tabSize, out TextExtents extents);
--- /dev/null
+// Copyright (c) 2018-2020 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
+//
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
+
+using System;
+
+namespace Drawing2D
+{
+ public interface IDevice: IDisposable
+ {
+ //IntPtr Handle => handle;
+
+ void GetDpy (out int hdpy, out int vdpy);
+ void SetDpy (int hdpy, int vdpy);
+ ISurface CreateSurface (int width, int height);
+
+ IContext CreateContext (ISurface surf);
+ }
+}
+
--- /dev/null
+// Copyright (c) 2022 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
+//
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
+
+using System;
+
+namespace Drawing2D
+{
+ public interface ISurface: IDisposable
+ {
+ IntPtr Handle { get; }
+ int Width { get; }
+ int Height { get; }
+
+ void Flush ();
+
+ void WriteToPng (string path);
+ void WriteTo (IntPtr bitmap);
+ void Clear ();
+ ISurface CreateSimilar (int width, int height);
+ }
+}
+
--- /dev/null
+// Copyright (c) 2019-2021 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
+//
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
+using System;
+using System.IO;
+using System.Runtime.InteropServices;
+
+namespace Drawing2D {
+ public class StbImage : IDisposable {
+ const string stblib = "stb";
+
+ [DllImport (stblib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_load")]
+ static extern IntPtr Load ([MarshalAs (UnmanagedType.LPStr)] string filename, out int x, out int y, out int channels_in_file, int desired_channels);
+
+ [DllImport (stblib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_load_from_memory")]
+ static extern IntPtr Load (IntPtr bitmap, int byteCount, out int x, out int y, out int channels_in_file, int desired_channels);
+
+ [DllImport (stblib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_image_free")]
+ static extern void FreeImage (IntPtr img);
+
+ public readonly IntPtr Handle;
+ public readonly int Width;
+ public readonly int Height;
+ public readonly int Channels;
+ public int Size => Width * Height * Channels;
+
+ /// <summary>
+ /// Open image file with STBI library
+ /// </summary>
+ /// <param name="path">file path</param>
+ /// <param name="requestedChannels">Force returned channels count, set 0 for original count</param>
+ public StbImage (string path, int requestedChannels = 4) {
+ Handle = StbImage.Load (path, out Width, out Height, out Channels, requestedChannels);
+ if (Handle == IntPtr.Zero)
+ throw new Exception ($"STBI image loading error.");
+ if (requestedChannels > 0)
+ Channels = requestedChannels;
+ }
+ /// <summary>
+ /// Open image in memory with STBI library
+ /// </summary>
+ /// <param name="bitmap">raw bitmap datas</param>
+ /// <param name="bitmapByteCount">Bitmap byte count.</param>
+ /// <param name="requestedChannels">Force returned channels count, set 0 for original count</param>
+ public StbImage (IntPtr bitmap, ulong bitmapByteCount, int requestedChannels = 4) {
+ Handle = StbImage.Load (bitmap, (int)bitmapByteCount, out Width, out Height, out Channels, requestedChannels);
+ if (Handle == IntPtr.Zero)
+ throw new Exception ($"STBI image loading error.");
+ if (requestedChannels > 0)
+ Channels = requestedChannels;
+ }
+ public StbImage (Stream stream, int requestedChannels = 4)
+ {
+ byte [] buff = new byte [stream.Length];
+ stream.Read (buff, 0, (int)stream.Length);
+ GCHandle hnd = GCHandle.Alloc (buff, GCHandleType.Pinned);
+ Handle = StbImage.Load (hnd.AddrOfPinnedObject(), (int)stream.Length, out Width, out Height, out Channels, requestedChannels);
+ hnd.Free ();
+ if (Handle == IntPtr.Zero)
+ throw new Exception ($"STBI image loading error.");
+ if (requestedChannels > 0)
+ Channels = requestedChannels;
+ }
+ public void Dispose () {
+ StbImage.FreeImage (Handle);
+ }
+ }
+}
+++ /dev/null
-// Copyright (c) 2022 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
-//
-// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
-
-using System;
-
-namespace Drawing2D
-{
- public interface ISurface: IDisposable
- {
- //IntPtr Handle { get; }
- int Width { get; }
- int Height { get; }
-
- void Flush ();
-
- void WriteToPng (string path);
- void WriteTo (IntPtr bitmap);
- void Clear ();
- ISurface CreateSimilar (int width, int height);
- }
-}
-