Adaug proiectul Unity

This commit is contained in:
2026-11-01 23:39:55 +02:00
parent cb14d9d37d
commit 863eac8f2c
23463 changed files with 5412601 additions and 0 deletions
@@ -0,0 +1,52 @@
using System;
using UnityEngine;
namespace Unity.CodeEditor.Platform
{
internal sealed class KeyGesture : IEquatable<KeyGesture>
{
internal KeyGesture(KeyCode key, KeyModifiers modifiers = KeyModifiers.None)
{
Key = key;
KeyModifiers = modifiers;
}
public bool Equals(KeyGesture other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return Key == other.Key && KeyModifiers == other.KeyModifiers;
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
return obj is KeyGesture gesture && Equals(gesture);
}
public override int GetHashCode()
{
unchecked
{
return ((int)Key * 397) ^ (int)KeyModifiers;
}
}
public static bool operator ==(KeyGesture left, KeyGesture right)
{
return Equals(left, right);
}
public static bool operator !=(KeyGesture left, KeyGesture right)
{
return !Equals(left, right);
}
internal KeyCode Key { get; }
internal KeyModifiers KeyModifiers { get; }
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 06d2ae5c2afa4cd5b639f474ecacbd5c
timeCreated: 1711363159
@@ -0,0 +1,46 @@
using System;
using UnityEngine;
using UnityEngine.UIElements;
namespace Unity.CodeEditor.Platform
{
[Flags]
internal enum KeyModifiers
{
None = 0,
Alt = 1,
Control = 2,
Shift = 4,
Meta = 8,
}
internal static class EventExtensions
{
internal static KeyModifiers GetKeyModifiers(this KeyDownEvent e)
{
var modifiers = KeyModifiers.None;
if (e.altKey)
{
modifiers |= KeyModifiers.Alt;
}
if (e.ctrlKey)
{
modifiers |= KeyModifiers.Control;
}
if (e.shiftKey)
{
modifiers |= KeyModifiers.Shift;
}
if (e.commandKey)
{
modifiers |= KeyModifiers.Meta;
}
return modifiers;
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 757ba4d39d48487da6bb88c8f846b385
timeCreated: 1711363091
@@ -0,0 +1,400 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
using Unity.CodeEditor.Rendering;
using UnityEngine;
namespace Unity.CodeEditor.Platform
{
internal sealed class PathFigures : List<PathFigure>
{
/// <summary>
/// Parses the specified path data to a <see cref="PathFigures"/>.
/// </summary>
/// <param name="pathData">The s.</param>
/// <returns></returns>
internal static PathFigures Parse(string pathData)
{
/*
var pathGeometry = new PathGeometry();
using (var context = new PathGeometryContext(pathGeometry))
using (var parser = new PathMarkupParser(context))
{
parser.Parse(pathData);
}
return pathGeometry.Figures!;
*/
return new PathFigures();
}
}
internal sealed class PathFigure
{
internal event EventHandler? SegmentsInvalidated;
private PathSegments? _segments;
private IDisposable? _segmentsDisposable;
private IDisposable? _segmentsPropertiesDisposable;
/// <summary>
/// Initializes a new instance of the <see cref="PathFigure"/> class.
/// </summary>
internal PathFigure()
{
Segments = new PathSegments();
}
static PathFigure()
{
}
private void OnSegmentsChanged()
{
_segmentsDisposable?.Dispose();
_segmentsPropertiesDisposable?.Dispose();
_segments?.ForEach(_ => InvalidateSegments());
//_segmentsPropertiesDisposable = _segments?.TrackItemPropertyChanged(_ => InvalidateSegments());
}
private void InvalidateSegments()
{
SegmentsInvalidated?.Invoke(this, EventArgs.Empty);
}
/// <summary>
/// Gets or sets a value indicating whether this instance is closed.
/// </summary>
/// <value>
/// <c>true</c> if this instance is closed; otherwise, <c>false</c>.
/// </value>
internal bool IsClosed { get; set; }
/// <summary>
/// Gets or sets a value indicating whether this instance is filled.
/// </summary>
/// <value>
/// <c>true</c> if this instance is filled; otherwise, <c>false</c>.
/// </value>
internal bool IsFilled { get; set; }
/// <summary>
/// Gets or sets the segments.
/// </summary>
/// <value>
/// The segments.
/// </value>
internal PathSegments? Segments
{
get { return _segments; }
set
{
_segments = value;
OnSegmentsChanged();
}
}
/// <summary>
/// Gets or sets the start point.
/// </summary>
/// <value>
/// The start point.
/// </value>
internal Vector2 StartPoint { get; set; }
public override string ToString()
=> FormattableString.Invariant($"M {StartPoint} {string.Join(" ", _segments ?? Enumerable.Empty<PathSegment>())}{(IsClosed ? "Z" : "")}");
internal void ApplyTo(StreamGeometryContext ctx)
{
ctx.BeginFigure(StartPoint, IsFilled);
if (Segments != null)
{
foreach (var segment in Segments)
{
segment.ApplyTo(ctx);
}
}
ctx.EndFigure(IsClosed);
}
}
internal sealed class PathSegments : List<PathSegment>
{
}
internal abstract class PathSegment
{
internal abstract void ApplyTo(StreamGeometryContext ctx);
}
internal sealed class LineSegment : PathSegment
{
/// <summary>
/// Gets or sets the point.
/// </summary>
/// <value>
/// The point.
/// </value>
internal Vector2 Point { get; set; }
internal override void ApplyTo(StreamGeometryContext ctx)
{
ctx.LineTo(Point);
}
public override string ToString()
=> FormattableString.Invariant($"L {Point}");
}
internal sealed class ArcSegment : PathSegment
{
/// <summary>
/// Gets or sets a value indicating whether this instance is large arc.
/// </summary>
/// <value>
/// <c>true</c> if this instance is large arc; otherwise, <c>false</c>.
/// </value>
internal bool IsLargeArc { get; set; }
/// <summary>
/// Gets or sets the point.
/// </summary>
/// <value>
/// The point.
/// </value>
internal Vector2 Point { get; set; }
/// <summary>
/// Gets or sets the rotation angle.
/// </summary>
/// <value>
/// The rotation angle.
/// </value>
internal double RotationAngle { get; set; }
/// <summary>
/// Gets or sets the size.
/// </summary>
/// <value>
/// The size.
/// </value>
internal Vector2 Size { get; set; }
/// <summary>
/// Gets or sets the sweep direction.
/// </summary>
/// <value>
/// The sweep direction.
/// </value>
internal BackgroundGeometryBuilder.SweepDirection SweepDirection { get; set; }
internal override void ApplyTo(StreamGeometryContext ctx)
{
ctx.ArcTo(Point, Size, RotationAngle, IsLargeArc, SweepDirection);
}
public override string ToString()
=> FormattableString.Invariant($"A {Size} {RotationAngle} {(IsLargeArc ? 1 : 0)} {(int)SweepDirection} {Point}");
}
/// <summary>
/// Describes a geometry using drawing commands.
/// </summary>
/// <remarks>
/// This class is used to define the geometry of a <see cref="StreamGeometry"/>. An instance
/// of <see cref="StreamGeometryContext"/> is obtained by calling
/// <see cref="StreamGeometry.Open"/>.
/// </remarks>
internal class StreamGeometryContext //: IGeometryContext
{
private readonly IStreamGeometryContextImpl _impl;
private Vector2 _currentPoint;
/// <summary>
/// Initializes a new instance of the <see cref="StreamGeometryContext"/> class.
/// </summary>
/// <param name="impl">The platform-specific implementation.</param>
internal StreamGeometryContext(IStreamGeometryContextImpl impl)
{
_impl = impl;
}
/// <summary>
/// Sets path's winding rule (default is EvenOdd). You should call this method before any calls to BeginFigure. If you wonder why, ask Direct2D guys about their design decisions.
/// </summary>
/// <param name="fillRule"></param>
internal void SetFillRule(FillRule fillRule)
{
_impl.SetFillRule(fillRule);
}
/// <summary>
/// Draws an arc to the specified point.
/// </summary>
/// <param name="point">The destination point.</param>
/// <param name="size">The radii of an oval whose perimeter is used to draw the angle.</param>
/// <param name="rotationAngle">The rotation angle (in radians) of the oval that specifies the curve.</param>
/// <param name="isLargeArc">true to draw the arc greater than 180 degrees; otherwise, false.</param>
/// <param name="sweepDirection">
/// A value that indicates whether the arc is drawn in the Clockwise or Counterclockwise direction.
/// </param>
internal void ArcTo(Vector2 point, Vector2 size, double rotationAngle, bool isLargeArc, BackgroundGeometryBuilder.SweepDirection sweepDirection)
{
_impl.ArcTo(point, size, rotationAngle, isLargeArc, sweepDirection);
_currentPoint = point;
}
/// <summary>
/// Draws an arc to the specified point using polylines, quadratic or cubic Bezier curves
/// Significantly more precise when drawing elliptic arcs with extreme width:height ratios.
/// </summary>
/// <param name="point">The destination point.</param>
/// <param name="size">The radii of an oval whose perimeter is used to draw the angle.</param>
/// <param name="rotationAngle">The rotation angle (in radians) of the oval that specifies the curve.</param>
/// <param name="isLargeArc">true to draw the arc greater than 180 degrees; otherwise, false.</param>
/// <param name="sweepDirection">
/// A value that indicates whether the arc is drawn in the Clockwise or Counterclockwise direction.
/// </param>
internal void PreciseArcTo(Vector2 point, Vector2 size, double rotationAngle, bool isLargeArc, BackgroundGeometryBuilder.SweepDirection sweepDirection)
{
//PreciseEllipticArcHelper.ArcTo(this, _currentPoint, point, size, rotationAngle, isLargeArc, sweepDirection);
}
/// <summary>
/// Begins a new figure.
/// </summary>
/// <param name="startPoint">The starting point for the figure.</param>
/// <param name="isFilled">Whether the figure is filled.</param>
internal void BeginFigure(Vector2 startPoint, bool isFilled)
{
_impl.BeginFigure(startPoint, isFilled);
_currentPoint = startPoint;
}
/// <summary>
/// Draws a Bezier curve to the specified point.
/// </summary>
/// <param name="point1">The first control point used to specify the shape of the curve.</param>
/// <param name="point2">The second control point used to specify the shape of the curve.</param>
/// <param name="point3">The destination point for the end of the curve.</param>
internal void CubicBezierTo(Vector2 point1, Vector2 point2, Vector2 point3)
{
_impl.CubicBezierTo(point1, point2, point3);
_currentPoint = point3;
}
/// <summary>
/// Draws a quadratic Bezier curve to the specified point
/// </summary>
/// <param name="control">The control point used to specify the shape of the curve.</param>
/// <param name="endPoint">The destination point for the end of the curve.</param>
internal void QuadraticBezierTo(Vector2 control, Vector2 endPoint)
{
_impl.QuadraticBezierTo(control, endPoint);
_currentPoint = endPoint;
}
/// <summary>
/// Draws a line to the specified point.
/// </summary>
/// <param name="point">The destination point.</param>
internal void LineTo(Vector2 point)
{
_impl.LineTo(point);
_currentPoint = point;
}
/// <summary>
/// Ends the figure started by <see cref="BeginFigure(Point, bool)"/>.
/// </summary>
/// <param name="isClosed">Whether the figure is closed.</param>
internal void EndFigure(bool isClosed)
{
_impl.EndFigure(isClosed);
}
/// <summary>
/// Finishes the drawing session.
/// </summary>
internal void Dispose()
{
_impl.Dispose();
}
}
internal interface IStreamGeometryContextImpl : IGeometryContext
{
}
internal interface IGeometryContext : IDisposable
{
/// <summary>
/// Draws an arc to the specified point.
/// </summary>
/// <param name="point">The destination point.</param>
/// <param name="size">The radii of an oval whose perimeter is used to draw the angle.</param>
/// <param name="rotationAngle">The rotation angle (in radians) of the oval that specifies the curve.</param>
/// <param name="isLargeArc">true to draw the arc greater than 180 degrees; otherwise, false.</param>
/// <param name="sweepDirection">
/// A value that indicates whether the arc is drawn in the Clockwise or Counterclockwise direction.
/// </param>
void ArcTo(Vector2 point, Vector2 size, double rotationAngle, bool isLargeArc, BackgroundGeometryBuilder.SweepDirection sweepDirection);
/// <summary>
/// Begins a new figure.
/// </summary>
/// <param name="startVector2">The starting point for the figure.</param>
/// <param name="isFilled">Whether the figure is filled.</param>
void BeginFigure(Vector2 startPoint, bool isFilled = true);
/// <summary>
/// Draws a Bezier curve to the specified point.
/// </summary>
/// <param name="point1">The first control point used to specify the shape of the curve.</param>
/// <param name="point2">The second control point used to specify the shape of the curve.</param>
/// <param name="point3">The destination point for the end of the curve.</param>
void CubicBezierTo(Vector2 point1, Vector2 point2, Vector2 point3);
/// <summary>
/// Draws a quadratic Bezier curve to the specified point
/// </summary>
/// <param name="control">Control point</param>
/// <param name="endPoint">DestinationPoint</param>
void QuadraticBezierTo(Vector2 control, Vector2 endPoint);
/// <summary>
/// Draws a line to the specified point.
/// </summary>
/// <param name="point">The destination point.</param>
void LineTo(Vector2 point);
/// <summary>
/// Ends the figure started by <see cref="BeginFigure(Point, bool)"/>.
/// </summary>
/// <param name="isClosed">Whether the figure is closed.</param>
void EndFigure(bool isClosed);
/// <summary>
/// Sets the fill rule.
/// </summary>
/// <param name="fillRule">The fill rule.</param>
void SetFillRule(FillRule fillRule);
}
internal enum FillRule
{
EvenOdd,
NonZero
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 717010216a3b45b19f04d091bf1b4ee1
timeCreated: 1710948723
@@ -0,0 +1,168 @@
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine;
namespace Unity.CodeEditor.Platform
{
internal sealed class PlatformHotkeyConfiguration
{
private static PlatformHotkeyConfiguration s_Current;
internal static PlatformHotkeyConfiguration Current
{
get
{
if (s_Current != null)
return s_Current;
s_Current = Init();
return s_Current;
}
}
static PlatformHotkeyConfiguration Init()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
return new PlatformHotkeyConfiguration(
KeyModifiers.Meta,
KeyModifiers.Shift,
KeyModifiers.Alt,
KeyModifiers.Control,
KeyModifiers.Alt);
}
return new PlatformHotkeyConfiguration(KeyModifiers.Control);
}
PlatformHotkeyConfiguration(KeyModifiers commandModifiers,
KeyModifiers selectionModifiers = KeyModifiers.Shift,
KeyModifiers wholeWordTextActionModifiers = KeyModifiers.Control,
KeyModifiers boxSelectionModifiers = KeyModifiers.Alt,
KeyModifiers deleteWholeLineModifiers = KeyModifiers.Shift)
{
CommandModifiers = commandModifiers;
SelectionModifiers = selectionModifiers;
WholeWordTextActionModifiers = wholeWordTextActionModifiers;
BoxSelectionModifiers = boxSelectionModifiers;
Copy = new List<KeyGesture>
{
new KeyGesture(KeyCode.C, commandModifiers),
new KeyGesture(KeyCode.Insert, KeyModifiers.Control)
};
Cut = new List<KeyGesture>
{
new KeyGesture(KeyCode.X, commandModifiers)
};
Paste = new List<KeyGesture>
{
new KeyGesture(KeyCode.V, commandModifiers),
new KeyGesture(KeyCode.Insert, KeyModifiers.Shift)
};
Undo = new List<KeyGesture>
{
new KeyGesture(KeyCode.Z, commandModifiers)
};
Redo = new List<KeyGesture>
{
new KeyGesture(KeyCode.Y, commandModifiers),
new KeyGesture(KeyCode.Z, commandModifiers | selectionModifiers)
};
SelectAll = new List<KeyGesture>
{
new KeyGesture(KeyCode.A, commandModifiers)
};
MoveCursorToTheStartOfLine = new List<KeyGesture>
{
new KeyGesture(KeyCode.Home)
};
MoveCursorToTheEndOfLine = new List<KeyGesture>
{
new KeyGesture(KeyCode.End)
};
MoveCursorToTheStartOfDocument = new List<KeyGesture>
{
new KeyGesture(KeyCode.Home, commandModifiers)
};
MoveCursorToTheEndOfDocument = new List<KeyGesture>
{
new KeyGesture(KeyCode.End, commandModifiers)
};
MoveCursorToTheStartOfLineWithSelection = new List<KeyGesture>
{
new KeyGesture(KeyCode.Home, selectionModifiers)
};
MoveCursorToTheEndOfLineWithSelection = new List<KeyGesture>
{
new KeyGesture(KeyCode.End, selectionModifiers)
};
MoveCursorToTheStartOfDocumentWithSelection = new List<KeyGesture>
{
new KeyGesture(KeyCode.Home, commandModifiers | selectionModifiers)
};
MoveCursorToTheEndOfDocumentWithSelection = new List<KeyGesture>
{
new KeyGesture(KeyCode.End, commandModifiers | selectionModifiers)
};
Back = new List<KeyGesture>
{
new KeyGesture(KeyCode.LeftArrow, KeyModifiers.Alt)
};
PageLeft = new List<KeyGesture>
{
new KeyGesture(KeyCode.PageUp, KeyModifiers.Shift)
};
PageRight = new List<KeyGesture>
{
new KeyGesture(KeyCode.PageDown, KeyModifiers.Shift)
};
PageUp = new List<KeyGesture>
{
new KeyGesture(KeyCode.PageUp)
};
PageDown = new List<KeyGesture>
{
new KeyGesture(KeyCode.PageDown)
};
DeleteWholeLine = new List<KeyGesture>
{
new KeyGesture(KeyCode.Delete, deleteWholeLineModifiers)
};
Find = new List<KeyGesture>
{
new KeyGesture(KeyCode.F, commandModifiers)
};
Replace = new List<KeyGesture>
{
new KeyGesture(KeyCode.H, commandModifiers)
};
}
internal KeyModifiers CommandModifiers { get; set; }
internal KeyModifiers WholeWordTextActionModifiers { get; set; }
internal KeyModifiers SelectionModifiers { get; set; }
internal KeyModifiers BoxSelectionModifiers { get; set; }
internal List<KeyGesture> Copy { get; set; }
internal List<KeyGesture> Cut { get; set; }
internal List<KeyGesture> Paste { get; set; }
internal List<KeyGesture> Undo { get; set; }
internal List<KeyGesture> Redo { get; set; }
internal List<KeyGesture> SelectAll { get; set; }
internal List<KeyGesture> MoveCursorToTheStartOfLine { get; set; }
internal List<KeyGesture> MoveCursorToTheEndOfLine { get; set; }
internal List<KeyGesture> MoveCursorToTheStartOfDocument { get; set; }
internal List<KeyGesture> MoveCursorToTheEndOfDocument { get; set; }
internal List<KeyGesture> MoveCursorToTheStartOfLineWithSelection { get; set; }
internal List<KeyGesture> MoveCursorToTheEndOfLineWithSelection { get; set; }
internal List<KeyGesture> MoveCursorToTheStartOfDocumentWithSelection { get; set; }
internal List<KeyGesture> MoveCursorToTheEndOfDocumentWithSelection { get; set; }
internal List<KeyGesture> Back { get; set; }
internal List<KeyGesture> PageUp { get; set; }
internal List<KeyGesture> PageDown { get; set; }
internal List<KeyGesture> PageRight { get; set; }
internal List<KeyGesture> PageLeft { get; set; }
internal List<KeyGesture> DeleteWholeLine { get; set; }
internal List<KeyGesture> Find { get; set; }
internal List<KeyGesture> Replace { get; set; }
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0038f75bdeed4f27a4ff0d1a241932b6
timeCreated: 1711363459
@@ -0,0 +1,10 @@
using System;
namespace Unity.CodeEditor.Platform
{
internal class TextInputEventArgs : EventArgs
{
internal string Text { get; set; }
internal bool Handled { get; set; }
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 7fad7a28c6ed44abad1ce715e7c502bf
timeCreated: 1711110534