<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Drawing" />
<Reference Include="VK">
- <HintPath>..\..\packages\Vulkan.0.1.2.5-alpha\lib\netstandard2.0\VK.dll</HintPath>
+ <HintPath>..\..\packages\Vulkan.0.1.2.6\lib\netstandard2.0\VK.dll</HintPath>
</Reference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<?xml version="1.0" encoding="utf-8"?>
<packages>
- <package id="Vulkan" version="0.1.2.5-alpha" targetFramework="net461" />
+ <package id="Vulkan" version="0.1.2.6" targetFramework="net461" />
</packages>
\ No newline at end of file
/// </summary>
public class BmpPicture : Picture
{
- byte[] image = null;
+ Surface imgSurface;
#region CTOR
/// <summary>
/// </summary>
/// <param name="path">image path, may be embedded</param>
public BmpPicture (string path) : base(path)
- {}
+ {
+ Load ();
+ }
#endregion
/// <summary>
/// load the image for rendering from the path given as argument
/// </summary>
/// <param name="path">image path, may be embedded</param>
void Load ()
- {
- if (sharedResources.ContainsKey (Path)) {
- sharedPicture sp = sharedResources [Path];
- image = (byte[])sp.Data;
- Dimensions = sp.Dims;
- return;
- }
- using (Stream stream = Interface.StaticGetStreamFromPath (Path)) {
- //loadBitmap (new System.Drawing.Bitmap (stream));
- }
- sharedResources [Path] = new sharedPicture (image, Dimensions);
- }
-
- //load image via System.Drawing.Bitmap, cairo load png only
- /*void loadBitmap (System.Drawing.Bitmap bitmap)
{
- if (bitmap == null)
- return;
-
- System.Drawing.Imaging.BitmapData data = bitmap.LockBits
- (new System.Drawing.Rectangle (0, 0, bitmap.Width, bitmap.Height),
- System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
-
- Dimensions = new Size (bitmap.Width, bitmap.Height);
-
- int stride = data.Stride;
- int bitmapSize = Math.Abs (data.Stride) * bitmap.Height;
-
- image = new byte[bitmapSize];
- System.Runtime.InteropServices.Marshal.Copy (data.Scan0, image, 0, bitmapSize);
+ //if (sharedResources.ContainsKey (Path)) {
+ // sharedPicture sp = sharedResources [Path];
+ // image = (byte[])sp.Data;
+ // Dimensions = sp.Dims;
+ // return;
+ //}
- bitmap.UnlockBits (data);
- }*/
+ imgSurface = new Surface (Interface.CurrentInterface.dev, Path);
+ Dimensions.Width = imgSurface.Width;
+ Dimensions.Height = imgSurface.Height;
+ //using (Stream stream = Interface.StaticGetStreamFromPath (Path)) {
+ // loadBitmap (new System.Drawing.Bitmap (stream));
+ //}
+ //sharedResources [Path] = new sharedPicture (image, Dimensions);
+ }
#region implemented abstract members of Fill
widthRatio = heightRatio;
}
- //using (ImageSurface tmp = new ImageSurface (Format.Argb32, bounds.Width, bounds.Height)) {
- // using (Context gr = new Context (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);
-
- // using (ImageSurface imgSurf = new ImageSurface (image, Format.Argb32,
- // Dimensions.Width, Dimensions.Height, 4 * Dimensions.Width)) {
- // gr.SetSourceSurface (imgSurf, 0,0);
- // gr.Paint ();
- // }
- // }
- // ctx.SetSource (tmp);
- //}
+ using (Surface tmp = new Surface (Interface.CurrentInterface.dev, bounds.Width, bounds.Height)) {
+ using (Context gr = new Context (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);
+ gr.SetSourceSurface (imgSurface, 0,0);
+ gr.Paint ();
+ }
+ ctx.SetSource (tmp);
+ }
}
#endregion
gr.Translate (rect.Left,rect.Top);
gr.Scale (widthRatio, heightRatio);
gr.Translate ((rect.Width/widthRatio - Dimensions.Width)/2, (rect.Height/heightRatio - Dimensions.Height)/2);
-
- //using (Surface imgSurf = new Surface (. image, Format.Argb32,
- // Dimensions.Width, Dimensions.Height, 4 * Dimensions.Width)) {
- // gr.SetSourceSurface (imgSurf, 0,0);
- // gr.Paint ();
- //}
+ gr.SetSourceSurface (imgSurface, 0,0);
+ gr.Paint ();
gr.Restore ();
}
}
gr.LineTo(x + radius, y + height);
gr.Arc(x + radius, y + height - radius, radius, Math.PI / 2, Math.PI);
gr.ClosePath();
+
gr.Restore();
}
public static void StrokeRaisedRectangle(Context gr, Rectangle r, double width = 1)
Oblic,
Radial
}
+
public class ColorStop
{
public double Offset;
return new ColorStop (-1, (Color)parts [0]);
}
}
+
public Gradient.Type GradientType = Type.Vertical;
// public double x0;
// public double y0;
public override void SetAsSource (Context ctx, Rectangle bounds = default(Rectangle))
{
- //Gradient grad = null;
- //switch (GradientType) {
- //case Type.Vertical:
- // grad = new LinearGradient (bounds.Left, bounds.Top, bounds.Left, bounds.Bottom);
- // break;
- //case Type.Horizontal:
- // grad = new LinearGradient (bounds.Left, bounds.Top, bounds.Right, bounds.Top);
- // break;
- //case Type.Oblic:
- // grad = new LinearGradient (bounds.Left, bounds.Top, bounds.Right, bounds.Bottom);
- // break;
- //case Type.Radial:
- // throw new NotImplementedException ();
- //}
-
- //foreach (ColorStop cs in Stops) {
- // if (cs == null)
- // continue;
- // grad.AddColorStop (cs.Offset, cs.Color);
- //}
+ Pattern grad = null;
+ switch (GradientType) {
+ case Type.Vertical:
+ grad = Pattern.CreateLinearGradient (bounds.Left, bounds.Top, bounds.Left, bounds.Bottom);
+ break;
+ case Type.Horizontal:
+ grad = Pattern.CreateLinearGradient (bounds.Left, bounds.Top, bounds.Right, bounds.Top);
+ break;
+ case Type.Oblic:
+ grad = Pattern.CreateLinearGradient (bounds.Left, bounds.Top, bounds.Right, bounds.Bottom);
+ break;
+ case Type.Radial:
+ throw new NotImplementedException ();
+ }
+
+ foreach (ColorStop cs in Stops) {
+ if (cs == null)
+ continue;
+ grad.AddColorStop ((float)cs.Offset, cs.Color);
+ }
- //ctx.SetSource (grad);
- //grad.Dispose ();
+ ctx.SetSource (grad);
+ grad.Dispose ();
}
#endregion
/// Each control need a ref to the root interface containing it, if not set in GraphicObject.currentInterface,
/// the ref of this one will be stored in GraphicObject.currentInterface
/// </summary>
- protected static Interface CurrentInterface;
+ public static Interface CurrentInterface;
Stopwatch lastClickTime = new Stopwatch();
internal Widget armedClick;//store widget with double click on first click
internal MouseButtonEventArgs armedClickEventArgs;
clippingMeasure.StopCycle();
#endif
}
+ Color clippingStrokeColor = Color.Magenta.AdjustAlpha(0.8);
/// <summary>Clipping Rectangles drive the drawing process. For compositing, each object under a clip rectangle should be
/// repainted. If it contains also clip rectangles, its cache will be update, or if not cached a full redraw will take place</summary>
void processDrawing(){
//}
#if DEBUG_CLIP_RECTANGLE
+ clippingStrokeColor.R += 0.1f;
+ if (clippingStrokeColor.R > 1f)
+ clippingStrokeColor.R = 0;
ctx.LineWidth = 1;
- clipping.stroke (ctx, Color.Magenta.AdjustAlpha (0.5));
+ clipping.stroke (ctx, clippingStrokeColor);
ctx.Stroke ();
#endif
//clipping.stroke (ctx, new Color (1, 0, 0));
gr.Scale (widthRatio, heightRatio);
gr.Translate (((float)rect.Width/widthRatio - Dimensions.Width)/2f, ((float)rect.Height/heightRatio - Dimensions.Height)/2f);
- if (string.IsNullOrEmpty (subPart))
+ /*if (string.IsNullOrEmpty (subPart))
hSVG.RenderCairo (gr);
else
- hSVG.RenderCairoSub (gr, "#" + subPart);
+ hSVG.RenderCairoSub (gr, "#" + subPart);*/
gr.Restore ();
}
set { NativeMethods.vkvg_set_operator (handle, value); }
get { return NativeMethods.vkvg_get_operator (handle); }
}
+ public FillRule FillRule {
+ set { NativeMethods.vkvg_set_fill_rule (handle, value); }
+ get { return NativeMethods.vkvg_get_fill_rule (handle); }
+ }
public FontExtents FontExtents {
get {
FontExtents f_extents;
public void ShowText (string txt) {
NativeMethods.vkvg_show_text (handle, txt);
}
+ public void ShowText (TextRun textRun) {
+ NativeMethods.vkvg_show_text_run (handle, textRun.Handle);
+ }
public void Save () {
NativeMethods.vkvg_save (handle);
}
NativeMethods.vkvg_set_source_surface (handle, surf.Handle, x, y);
}
- private static byte[] TerminateUtf8(string s)
+ internal static byte[] TerminateUtf8(string s)
{
// compute the byte count including the trailing \0
var byteCount = Encoding.UTF8.GetMaxByteCount(s.Length + 1);
Round,
Bevel
}
+ public enum FillRule {
+ EvenOdd,
+ NonZero,
+ }
}
\ No newline at end of file
internal static extern void vkvg_set_line_join (IntPtr ctx, LineJoin join);
[DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)]
internal static extern void vkvg_set_operator (IntPtr ctx, Operator op);
+ [DllImport (libvkvg, CallingConvention = CallingConvention.Cdecl)]
+ internal static extern FillRule vkvg_get_fill_rule (IntPtr ctx);
+ [DllImport (libvkvg, CallingConvention = CallingConvention.Cdecl)]
+ internal static extern void vkvg_set_fill_rule (IntPtr ctx, FillRule fr);
[DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)]
internal static extern Operator vkvg_get_operator (IntPtr ctx);
[DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)]
[DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)]
internal static extern void vkvg_show_text_run (IntPtr ctx, IntPtr textRun);
[DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)]
- internal static extern void vkvg_text_run_get_extents (IntPtr textRun);
+ internal static extern void vkvg_text_run_get_extents (IntPtr textRun, out TextExtents extents);
#endregion
#region Pattern
public void AddColorStop (float offset, float r, float g, float b, float a = 1f) {
NativeMethods.vkvg_patter_add_color_stop (handle, offset, r, g, b, a);
}
+ public void AddColorStop (float offset, Crow.Color c) {
+ NativeMethods.vkvg_patter_add_color_stop (Handle, offset, (float)c.R, (float)c.G, (float)c.B, (float)c.A);
+ }
#region IDisposable implementation
public void Dispose () {
--- /dev/null
+//
+// TextRun.cs
+//
+// Author:
+// Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
+//
+// Copyright (c) 2019 jp
+//
+// 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 vkvg {
+ public class TextRun : IDisposable {
+
+ IntPtr handle = IntPtr.Zero;
+
+ #region CTORS & DTOR
+ protected TextRun(IntPtr handle) {
+ this.handle = handle;
+ }
+ public TextRun(string text) {
+ handle = NativeMethods.vkvg_text_run_create (handle, Context.TerminateUtf8(text));
+ }
+
+ ~TextRun() {
+ Dispose (false);
+ }
+ #endregion
+
+ //public void AddReference () {
+ // NativeMethods.vkvg_pattern_reference (handle);
+ //}
+ //public uint References () => NativeMethods.vkvg_pattern_get_reference_count (handle);
+
+ public IntPtr Handle { get { return handle; } }
+
+ public TextExtents Extents {
+ get {
+ TextExtents extents;
+ NativeMethods.vkvg_text_run_get_extents (handle, out extents);
+ return extents;
+ }
+ }
+
+ #region IDisposable implementation
+ public void Dispose () {
+ Dispose (true);
+ GC.SuppressFinalize (this);
+ }
+
+ protected virtual void Dispose (bool disposing) {
+ if (!disposing || handle == IntPtr.Zero)
+ return;
+
+ NativeMethods.vkvg_text_run_destroy (handle);
+ handle = IntPtr.Zero;
+ }
+ #endregion
+ }
+}
\ No newline at end of file