public static class CairoAPI {
static public int Version {
get {
- return Cairo.NativeMethods.cairo_version ();
+ return NativeMethods.cairo_version ();
}
}
static public string VersionString {
get {
- IntPtr x = Cairo.NativeMethods.cairo_version_string ();
+ IntPtr x = NativeMethods.cairo_version_string ();
return Marshal.PtrToStringAnsi (x);
}
}
set { NativeMethods.cairo_set_antialias (handle, value); }
}
- public Cairo.Status Status {
+ public Status Status {
get {
return NativeMethods.cairo_status (handle);
}
}
}
- public Cairo.FillRule FillRule {
+ public FillRule FillRule {
set {
NativeMethods.cairo_set_fill_rule (handle, value);
}
}
}
- public Cairo.LineCap LineCap {
+ public LineCap LineCap {
set {
NativeMethods.cairo_set_line_cap (handle, value);
}
}
}
- public Cairo.LineJoin LineJoin {
+ public LineJoin LineJoin {
set {
NativeMethods.cairo_set_line_join (handle, value);
}
public Pattern GetSource ()
{
var ptr = NativeMethods.cairo_get_source (handle);
- return Cairo.Pattern.Lookup (ptr, false);
+ return Pattern.Lookup (ptr, false);
}
public double MiterLimit {
}
[Obsolete ("Use GetTarget/SetTarget")]
- public Cairo.Surface Target {
+ public Surface Target {
set {
if (handle != IntPtr.Zero)
NativeMethods.cairo_destroy (handle);
SelectFontFace (family, slant, weight);
}
- [Obsolete("Use GetFontFace/SetFontFace")]
- public FontFace ContextFontFace {
- get {
- return GetContextFontFace ();
- }
- set {
- SetContextFontFace (value);
- }
- }
-
- public FontFace GetContextFontFace ()
- {
- return Cairo.FontFace.Lookup (NativeMethods.cairo_get_font_face (handle), false);
- }
-
public void SetContextFontFace (FontFace value)
{
NativeMethods.cairo_set_font_face (handle, value == null ? IntPtr.Zero : value.Handle);
public GLSurface (IntPtr ptr, bool own) : base (ptr, own)
{}
- public GLSurface (Device device, Cairo.Content content, uint tex, int width, int height)
+ public GLSurface (Device device, Content content, uint tex, int width, int height)
: base (NativeMethods.cairo_gl_surface_create_for_texture (device.Handle, (uint)content, tex, width, height), true)
{}
}
[Obsolete ("Use ImageSurface (byte[] data, Cairo.Format format, int width, int height, int stride)")]
- public ImageSurface (ref byte[] data, Cairo.Format format, int width, int height, int stride)
+ public ImageSurface (ref byte[] data, Format format, int width, int height, int stride)
: this (data, format, width, height, stride)
{
}
NativeMethods.cairo_matrix_rotate (this, radians);
}
- public Cairo.Status Invert ()
+ public Status Invert ()
{
return NativeMethods.cairo_matrix_invert (this);
}
#region Image Surface
[DllImport (cairo, CallingConvention=CallingConvention.Cdecl)]
- internal static extern IntPtr cairo_image_surface_create (Cairo.Format format, int width, int height);
+ internal static extern IntPtr cairo_image_surface_create (Format format, int width, int height);
[DllImport (cairo, CallingConvention=CallingConvention.Cdecl)]
- internal static extern IntPtr cairo_image_surface_create_for_data (byte[] data, Cairo.Format format, int width, int height, int stride);
+ internal static extern IntPtr cairo_image_surface_create_for_data (byte[] data, Format format, int width, int height, int stride);
[DllImport (cairo, CallingConvention=CallingConvention.Cdecl)]
- internal static extern IntPtr cairo_image_surface_create_for_data (IntPtr data, Cairo.Format format, int width, int height, int stride);
+ internal static extern IntPtr cairo_image_surface_create_for_data (IntPtr data, Format format, int width, int height, int stride);
[DllImport (cairo, CallingConvention=CallingConvention.Cdecl)]
internal static extern IntPtr cairo_image_surface_create_from_png (string filename);
internal static extern int cairo_get_dash_count (IntPtr cr);
[DllImport (cairo, CallingConvention=CallingConvention.Cdecl)]
- internal static extern void cairo_set_fill_rule (IntPtr cr, Cairo.FillRule fill_rule);
+ internal static extern void cairo_set_fill_rule (IntPtr cr, FillRule fill_rule);
[DllImport (cairo, CallingConvention=CallingConvention.Cdecl)]
internal static extern void cairo_set_font_face (IntPtr cr, IntPtr fontFace);
internal static extern void cairo_set_miter_limit (IntPtr cr, double limit);
[DllImport (cairo, CallingConvention=CallingConvention.Cdecl)]
- internal static extern void cairo_set_operator (IntPtr cr, Cairo.Operator op);
+ internal static extern void cairo_set_operator (IntPtr cr, Operator op);
[DllImport (cairo, CallingConvention=CallingConvention.Cdecl)]
internal static extern void cairo_set_source (IntPtr cr, IntPtr pattern);
#region Surface
[DllImport (cairo, CallingConvention=CallingConvention.Cdecl)]
- internal static extern IntPtr cairo_surface_create_similar (IntPtr surface, Cairo.Content content, int width, int height);
+ internal static extern IntPtr cairo_surface_create_similar (IntPtr surface, Content content, int width, int height);
[DllImport (cairo, CallingConvention=CallingConvention.Cdecl)]
internal static extern void cairo_surface_destroy (IntPtr surface);
NativeMethods.cairo_region_destroy (Handle);
handle = NativeMethods.cairo_region_create ();
}
- public bool OverlapOut (Crow.Rectangle rectangle) => Contains (p.Slot) == RegionOverlap.Out;
+ public bool OverlapOut (Crow.Rectangle rectangle) => Contains (rectangle) == RegionOverlap.Out;
}
}
}
[Obsolete ("Use an ImageSurface constructor instead.")]
- public static Cairo.Surface CreateForImage (
- ref byte[] data, Cairo.Format format, int width, int height, int stride)
+ public static Surface CreateForImage (
+ ref byte[] data, Format format, int width, int height, int stride)
{
IntPtr p = NativeMethods.cairo_image_surface_create_for_data (
data, format, width, height, stride);
- return new Cairo.Surface (p, true);
+ return new Surface (p, true);
}
[Obsolete ("Use an ImageSurface constructor instead.")]
- public static Cairo.Surface CreateForImage (
- Cairo.Format format, int width, int height)
+ public static Surface CreateForImage (
+ Format format, int width, int height)
{
IntPtr p = NativeMethods.cairo_image_surface_create (
format, width, height);
- return new Cairo.Surface (p, true);
+ return new Surface (p, true);
}
- public Cairo.Surface CreateSimilar (
- Cairo.Content content, int width, int height)
+ public Surface CreateSimilar (
+ Content content, int width, int height)
{
IntPtr p = NativeMethods.cairo_surface_create_similar (
this.Handle, content, width, height);
using System;
using System.Text;
+using System.Linq;
using Crow;
namespace Crow.Drawing
NativeMethods.vkvg_set_matrix(handle, ref value);
}
}
- public void ShowText (ReadOnlySpan<char> s, int tabSize) {
+ public void ShowText (string text) => ShowText (text.AsSpan());
+ public void ShowText (ReadOnlySpan<char> s, int tabSize = 4) {
int size = s.Length * 4 + 1;
Span<byte> bytes = size > 512 ? new byte[size] : stackalloc byte[size];
int encodedBytes = Crow.Text.Encoding.ToUtf8 (s, bytes, tabSize);
Encoding.UTF8.GetBytes(s, 0, s.Length, bytes, 0);
return bytes;
}
-
+ public void SetDash (double [] dashes, double offset = 0) {
+ if (dashes == null)
+ NativeMethods.vkvg_set_dash(handle, null, 0, 0);
+ else {
+ float[] floats = dashes.Cast<float> ().ToArray ();
+ NativeMethods.vkvg_set_dash(handle, floats, (uint)dashes.Length, (float)offset);
+ }
+ }
public float[] Dashes
{
set
vkvgDev = device;
handle = NativeMethods.vkvg_surface_create_from_image (device.Handle, imgPath);
}
-
+ public Surface (Device device, IntPtr surfHandle) {
+ vkvgDev = device;
+ handle = surfHandle;
+ AddReference ();
+ }
Surface (IntPtr devHandle, int width, int heigth)
{
};
#endregion
-
+ 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 string WindowTitle {
set => Glfw3.SetWindowTitle (hWin, value);
}
using (ZipArchive archive = ZipFile.Open (Theme, ZipArchiveMode.Read)) {
foreach (ZipArchiveEntry entry in archive.Entries.Where (e => e.FullName.StartsWith ("Images"))) {
Console.WriteLine (entry.FullName);
- }
+ }
foreach (ZipArchiveEntry entry in archive.Entries.Where (e => e.FullName.StartsWith ("IML"))) {
Console.WriteLine (entry.FullName);
}
void loadThemeStyle () {
if (string.IsNullOrEmpty (Theme))
return;
- try {
+ try {
if (Directory.Exists (theme)) {
string stylePath = Directory.GetFiles (theme, "*.style").FirstOrDefault ();
using (Stream s = new FileStream (stylePath, FileMode.Open, FileAccess.Read)) {
}
} catch (Exception e) {
throw new Exception ($"[Theme] Error reading theme style ({Theme})", e);
- }
+ }
}
#endregion
PerformanceMeasure.Notify ();
}
+#if VKVG
void resizeVulkanContext () {
vkCtx.WaitIdle();
vkCtx.blitSource?.Dispose ();
g.RegisterForLayouting (LayoutingType.All);
registerRefreshClientRectangle ();
-
}
+#endif
/// <summary>Layouting loop, this is the first step of the udpate and process registered
/// Layouting queue items. Failing LQI's are requeued in this cycle until MaxTry is reached which
/// trigger an enqueue for the next Update Cycle</summary>
if (LayoutingQueue.Count == 0) {
Monitor.Exit (LayoutMutex);
return;
- }
+ }
DbgLogger.StartEvent (DbgEvtType.ProcessLayouting);
PerformanceMeasure.Begin (PerformanceMeasure.Kind.Layouting);
ctx.Fill ();
ctx.Operator = Operator.Over;
}
- bool solidBackground = false;
+ bool solidBackground = false;
public bool SolidBackground {
get => solidBackground;
set {
if (SolidBackground)
clear (ctx);
- ctx.Flush();
#endif
for (int i = GraphicTree.Count -1; i >= 0 ; i--){
}
/*if (DragAndDropInProgress) {
- }*/
+ }*/
surf.Flush ();
}
clientRectangle = bounds;
#if VKVG
-
#else
switch (Environment.OSVersion.Platform) {
case PlatformID.MacOSX:
currentCursor?.Dispose ();
switch (cursor) {
- case MouseCursor.arrow:
+ case MouseCursor.arrow:
case MouseCursor.top_left_arrow:
currentCursor = new Cursor (CursorShape.Arrow);
break;
- case MouseCursor.crosshair:
+ case MouseCursor.crosshair:
currentCursor = new Cursor (CursorShape.Crosshair);
break;
- case MouseCursor.hand:
+ case MouseCursor.hand:
currentCursor = new Cursor (CursorShape.Hand);
break;
- case MouseCursor.ibeam:
+ case MouseCursor.ibeam:
currentCursor = new Cursor (CursorShape.IBeam);
break;
- default:
+ default:
currentCursor = XCursor.Create (this, cursor);
break;
- }
+ }
currentCursor.Set (hWin);
//MouseCursorChanged.Raise (this,new MouseCursorChangedEventArgs(cursor));
dragndropHover = value;
} else
HoverWidget = value;
- }
- }
+ }
+ }
/// <summary>
/// Ask OS to force the mouse position to the actual coordinate of Interface.MousePosition
/// </summary>
int indexOfTopContainer = GraphicTree.IndexOf (topContainer);
if (indexOfTopContainer != 0) {
- for (int i = 0; i < indexOfTopContainer; i++) {//check all top containers that are at a higher level
+ for (int i = 0; i < indexOfTopContainer; i++) {//check all top containers that are at a higher level
//if logical parent of top container is the Interface, that's not a popup.
if (GraphicTree [i].LogicalParent is Interface) {
if (GraphicTree [i].MouseIsIn (e.Position)) {
ActiveWidget = null;
}
return true;
- }
+ }
if (_activeWidget == null)
return false;
public Rectangle ClientRectangle => clientRectangle;
public Interface HostContainer => this;
- public Rectangle getSlot () => ClientRectangle;
+ public Rectangle getSlot () => ClientRectangle;
public void ChildrenLayoutingConstraints(ILayoutable layoutable, ref LayoutingType layoutType){ }
#endregion
}
ctx.SetSource (bmp, rb.X, rb.Y);
ctx.Paint ();
+#if VKVG
ctx.Flush ();
+#endif
DbgLogger.EndEvent(DbgEvtType.GOPaintCache);
}
protected virtual void UpdateCache(Context ctx){
<CrowVersion>0.9.7</CrowVersion>
<CrowPackageVersion>$(CrowVersion)-beta</CrowPackageVersion>
+
+ <!-- If you dont have a native libstb on your system, enable the managed version of stb here
+ TODO: this could be detected on startup or install automatically-->
<CrowStbSharp>true</CrowStbSharp>
+
+ <!-- Compile with logging enabled, this will slow down apps, use this only
+ for debugging purpose-->
<CrowDebugLogEnabled>false</CrowDebugLogEnabled>
+
+ <!-- Collect several statistics on widgets-->
<CrowDebugStatsEnabled>true</CrowDebugStatsEnabled>
+
+ <!-- Used only by CrowIDE and CrowEdit-->
<CrowDesignModeEnabled>false</CrowDesignModeEnabled>
- <CrowVkvgBackend>true</CrowVkvgBackend>
+
+ <!-- Experimental vkvg backend, testing only-->
+ <CrowVkvgBackend>false</CrowVkvgBackend>
+
<GlfwSharpVersion>0.2.12-beta</GlfwSharpVersion>
</PropertyGroup>
</Project>
-using System.Diagnostics;
-using System.Runtime.InteropServices.ComTypes;
-// Copyright (c) 2013-2020 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
+// Copyright (c) 2013-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.Collections.Generic;
using System.ComponentModel;
-using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Crow.Drawing;
using Crow.DebugLogger;
-using DebugLogAnalyzer;
+using System.Diagnostics;
namespace Crow
{
set {
base.Font = value;
using (Context gr = new Context (IFace.surf)) {
- gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight);
- gr.SetFontSize (Font.Size);
-
+ setFontForContext (gr);
fe = gr.FontExtents;
}
updateMargins ();
}
DbgEvtType currentFilter;
- protected override void onDraw (Cairo.Context gr)
+ protected override void onDraw (Context gr)
{
base.onDraw (gr);
}
string ticksToMS(long ticks) => Math.Round ((double)ticks / Stopwatch.Frequency * 1000.0, 2).ToString();
- public override void Paint (Cairo.Context ctx)
+ public override void Paint (Context ctx)
{
base.Paint (ctx);
ctx.MoveTo (ctxR.X - ctx.TextExtents (str).Width / 2, ctxR.Y + fe.Height);
ctx.ShowText (str);
- ctx.Operator = Cairo.Operator.Add;
+ ctx.Operator = Operator.Add;
if (hoverLine >= 0) {
double y = fe.Height * (hoverLine - ScrollY) + topMargin + cb.Top;
}
if (selStart < 0 || selEnd < 0) {
- ctx.Operator = Cairo.Operator.Over;
+ ctx.Operator = Operator.Over;
return;
}
double selStartX = (double)(selStart - ScrollX - minTicks) * xScale + leftMargin + cb.Left;
ctx.SetSource (0.0,0.2,0.8,0.15);
//ctx.SetSource (Colors.Jet);
ctx.Fill();
- ctx.Operator = Cairo.Operator.Over;
+ ctx.Operator = Operator.Over;
str = $"{ticksToMS(Math.Abs (selEnd - selStart))} (ms)";
-// Copyright (c) 2013-2019 Bruyère Jean-Philippe <jp_bruyere@hotmail.com>
+// Copyright (c) 2013-2021 Bruyère Jean-Philippe <jp_bruyere@hotmail.com>
//
// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
public DebugInterface (IntPtr hWin) : base (hWin)
{
SolidBackground = false;
- surf = new ImageSurface (Format.Argb32, 100, 100);
+ surf = CreateSurface (100, 100);
}
public override void Run()
lock (UpdateMutex) {
clientRectangle = new Rectangle (0, 0, width, height);
surf?.Dispose();
- surf = new ImageSurface (Format.Argb32, width, height);
+ surf = CreateSurface (width, height);
foreach (Widget g in GraphicTree)
g.RegisterForLayouting (LayoutingType.All);
RegisterClip (clientRectangle);
if (initialized) {
delResize (Slot.Width, Slot.Height);
- bmp = Crow.Cairo.Surface.Lookup (delGetSurfacePointer(), false);
+ bmp = IFace.CreateSurface (delGetSurfacePointer());
} else
- bmp = IFace.surf.CreateSimilar (Content.ColorAlpha, Slot.Width, Slot.Height);
+ bmp = IFace.CreateSurface (Slot.Width, Slot.Height);
IsDirty = false;
}
-using Crow.Cairo;
-using System;
-using System.Collections;
-using System.Collections.Generic;
+// Copyright (c) 2021 Bruyère Jean-Philippe <jp_bruyere@hotmail.com>
+//
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
+
+using Crow.Drawing;
using System.ComponentModel;
-using System.Text;
namespace Crow
-{
- public class Painter : ScrollingObject
+{
+ public class Painter : ScrollingObject
{
#region CTOR
protected Painter () { }
if (screenOutput)
initSurface ();
else
- surf = new Crow.Cairo.ImageSurface (Crow.Cairo.Format.Argb32, ClientRectangle.Width, ClientRectangle.Height);
+ surf = CreateSurface (ClientRectangle.Width, ClientRectangle.Height);
initDictionaries ();
loadStyling ();
public int intValue = 500;
VerticalAlignment currentVAlign;
- DirectoryInfo curDir = new DirectoryInfo(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location));
+ DirectoryInfo curDir = new DirectoryInfo(System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location));
public FileSystemInfo[] CurDirectory => curDir.GetFileSystemInfos();
public string MultilineText =
$"Lorem ipsum dolor sit amet,\nconsectetur adipiscing elit. Sed non risus.\n\nSuspendisse lectus tortor,\nLorem ipsum dolor sit amet,\nconsectetur adipiscing elit. Sed non risus.\n\nSuspendisse lectus tortor,";
using Crow;
using Samples;
+using Crow.Drawing;
namespace tests
{
Rectangle r = e.DragSource.LastPaintedSlot;
startGroup = e.DragSource.Parent as Group;
- Crow.Cairo.Surface dragImg = surf.CreateSimilar (Crow.Cairo.Content.ColorAlpha,
- r.Width, r.Height);
- using (Crow.Cairo.Context gr = new Crow.Cairo.Context(dragImg)) {
+ Surface dragImg = CreateSurface (ref r);
+ using (Context gr = new Context(dragImg)) {
gr.SetSource (e.DragSource.bmp, 0, 0);
gr.Paint ();
}
{
public TestInterface (int width = 800, int height = 600)
: base (width, height, false, false) {
- surf = new Crow.Cairo.ImageSurface (Crow.Cairo.Format.Argb32, ClientRectangle.Width, ClientRectangle.Height);
+ surf = CreateSurface (ClientRectangle.Width, ClientRectangle.Height);
}
bool isRunning;
public bool IsRunning {