]> O.S.I.I.S - jp/crow.git/commitdiff
wip, set v0.9.8
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Mon, 27 Sep 2021 05:25:11 +0000 (05:25 +0000)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Mon, 27 Sep 2021 05:25:11 +0000 (05:25 +0000)
Crow/src/Input/MouseEventArgs.cs
Crow/src/Interface.cs
Crow/src/Mono.Cairo [deleted file]
Crow/src/Text/CharLocation.cs
Crow/src/Text/TextLine.cs
Crow/src/Text/TextLineCollection.cs
Crow/src/Text/TextSpan.cs
Directory.Build.props

index f84822ebd542fbef60f21273b806e3f2616d4a81..9b242dd6fdcbbfef188f7123e6a978402522f06e 100644 (file)
@@ -32,6 +32,10 @@ namespace Crow
                        X = x;
                        Y = y;
                }
+               public MouseEventArgs (Point mousePosition) {
+                       X = mousePosition.X;
+                       Y = mousePosition.Y;
+               }
        }
        public class MouseMoveEventArgs : MouseEventArgs
        {
@@ -57,7 +61,7 @@ namespace Crow
        public class MouseWheelEventArgs : MouseEventArgs
        {
                public readonly int Delta;
-               public MouseWheelEventArgs (int delta)
+               public MouseWheelEventArgs (int delta, Point mousePosition) : base (mousePosition)
                {
                        Delta = delta;
                }
index c177cd1bd50d697d122074013ca73de07eee9f3e..0901b9bc6bef938fa138d3149321ff3fa76ea362 100644 (file)
@@ -1906,7 +1906,7 @@ namespace Crow
                /// <param name="delta">wheel delta</param>
                public virtual bool OnMouseWheelChanged (float delta)
                {
-                       MouseWheelEventArgs e = new MouseWheelEventArgs ((int)delta);
+                       MouseWheelEventArgs e = new MouseWheelEventArgs ((int)delta, MousePosition);
 
                        if (_hoverWidget == null)
                                return false;
diff --git a/Crow/src/Mono.Cairo b/Crow/src/Mono.Cairo
deleted file mode 100644 (file)
index e69de29..0000000
index cfc537c603740d3a25b841e344479c278e4e4e9b..0d07b3029a1db240b975b8cba93cdc8610a595fd 100644 (file)
@@ -6,13 +6,13 @@ using System.Diagnostics;
 
 namespace Crow.Text
 {
-    [DebuggerDisplay ("{Line}, {Column}, {VisualCharXPosition}")]
+       [DebuggerDisplay ("{Line}, {Column}, {VisualCharXPosition}")]
        public struct CharLocation : IEquatable<CharLocation>
        {
                public readonly int Line;
                /// <summary>
                /// Character position in current line. If equals '-1', the visualX must contains the on screen position.
-               /// 
+               ///
                /// </summary>
                public int Column;
                public double VisualCharXPosition;
@@ -21,7 +21,7 @@ namespace Crow.Text
                        Column = column;
                        VisualCharXPosition = visualX;
                }
-               public bool HasVisualX => Column >= 0 && VisualCharXPosition >= 0;              
+               public bool HasVisualX => Column >= 0 && VisualCharXPosition >= 0;
                public void ResetVisualX () => VisualCharXPosition = -1;
                public static bool operator == (CharLocation a, CharLocation b)
                        => a.Equals (b);
@@ -40,5 +40,5 @@ namespace Crow.Text
                }
 
                public override string ToString () => $"{Line}, {Column}";
-    }
+       }
 }
index e3565083cc50a84543ca1899911e805b1fe4dc8b..d757ed77e9708ed96e150fe1a7282f39449527bd 100644 (file)
@@ -41,6 +41,8 @@ namespace Crow.Text
                /// Absolute end character position just before linebreak if any.
                /// </summary>
                public int End => Start + Length;
+               public TextSpan Span => new TextSpan (Start, End);
+               public TextSpan SpanIncludingLineBreak => new TextSpan (Start, EndIncludingLineBreak);
                /// <summary>
                /// Absolute line's end position after linebreak if any.
                /// </summary>
@@ -85,7 +87,7 @@ namespace Crow.Text
                /// </summary>
                /// <param name="start"></param>
                /// <returns></returns>
-               public TextLine WithStartOffset (int start) => new TextLine (Start + start, End, EndIncludingLineBreak);                
+               public TextLine WithStartOffset (int start) => new TextLine (Start + start, End, EndIncludingLineBreak);
                public int CompareTo (TextLine other) => Start - other.Start;
     }
 }
index 19696867d08aa13a63ea94b673da0105b7576b72..19be9c9e32ca7fded8c2fc6a24222d780bcf1547 100644 (file)
@@ -8,203 +8,203 @@ using System.Text;
 
 namespace Crow.Text
 {
-    public class LineCollection : IList<TextLine>
-    {
-        TextLine[] lines;
-        int length;
-
-        #region CTOR
-        public LineCollection (int capacity) {
-            lines = new TextLine[capacity];
-            length = 0;
-        }
-        public LineCollection (TextLine[] _lines, int capacity = -1) {
-            if (capacity >= _lines.Length) {
-                lines = new TextLine[capacity];
-                _lines.AsSpan ().CopyTo (lines);
-            } else
-                lines =_lines;
-            
-            length = _lines.Length;
-        }
-        
-        public LineCollection (string _text, int capacity = 4) : this (capacity) {
-            Update (_text.AsSpan ());
-        }
-        #endregion
-
-        public void Update (ReadOnlySpan<char> _text) {
-            length = 0;
-            int start = 0, i = 0;
-            while (i < _text.Length) {
-                char c = _text[i];
-                if (c == '\r') {
-                    if (++i < _text.Length) {
-                        if (_text[i] == '\n')
-                            Add (new TextLine (start, i - 1, ++i));
-                        else
-                            Add (new TextLine (start, i - 1, i));
-                    } else
-                        Add (new TextLine (start, i - 1, i));
-                    start = i;
-                } else if (c == '\n') {
-                    if (++i < _text.Length) {
-                        if (_text[i] == '\r')
-                            Add (new TextLine (start, i - 1, ++i));
-                        else
-                            Add (new TextLine (start, i - 1, i));
-                    } else
-                        Add (new TextLine (start, i - 1, i));
-                    start = i;
-
-                } else if (c == '\u0085' || c == '\u2028' || c == '\u2029')
-                    Add (new TextLine (start, i - 1, i));
-                else
-                    i++;
-            }
-
-            if (start < i)
-                Add (new TextLine (start, _text.Length, _text.Length));
-            else
-                Add (new TextLine (_text.Length, _text.Length, _text.Length));
-        }
-
-        public void Update (TextChange change) {
-            CharLocation locStart = GetLocation (change.Start);
-            int charsDiff = change.ChangedText.Length - change.Length;
-            int lineEnd = locStart.Line;
-            while (lineEnd < length - 1 && change.End >= lines[lineEnd + 1].Start)
-                lineEnd++;
-            int columnEnd = change.End - lines[lineEnd].Start;
-            int lineEndLineBreakLength = lines[lineEnd].LineBreakLength;
-
-            LineCollection newLines = new LineCollection (change.ChangedText);
-            int linesDiff = newLines.length - 1 - (lineEnd - locStart.Line);
-            TextLine endTl = lines[lineEnd];
-
-            if (linesDiff < 0)
-                RemoveAt (locStart.Line + 1, -linesDiff);
-            else if (linesDiff > 0) {
-                for (int i = 0; i < linesDiff; i++)
-                    Insert (locStart.Line + 1, default);
-            }
-
-            int remainingColumns = endTl.Length - columnEnd;
-            lineEnd += linesDiff;
-            lines[lineEnd].SetLength (0);
-            lines[locStart.Line].SetLength (locStart.Column + newLines[0].Length);
-            lines[lineEnd].Length += remainingColumns;
-            if (newLines.Count > 1) {
-                lines[lineEnd].Length += newLines[newLines.Count - 1].Length;                
-                lines[locStart.Line].LengthIncludingLineBreak = lines[locStart.Line].Length + newLines[0].LineBreakLength;
-            }
-            lines[lineEnd].LengthIncludingLineBreak = lines[lineEnd].Length + endTl.LineBreakLength;
-
-            for (int i = 1; i < newLines.Count - 1; i++) {
-                int l = locStart.Line + i;
-                lines[l] = newLines[i];
-                lines[l].Start = lines[l - 1].EndIncludingLineBreak;
-            }
-            if (lineEnd > 0)
-                lines[lineEnd].Start = lines[lineEnd - 1].EndIncludingLineBreak;
-
-            //shift start for remaining lines
-            for (int i = lineEnd + 1; i < length; i++)
-                lines[i].Start += charsDiff;            
-        }
-        public int GetAbsolutePosition (CharLocation loc) => lines[loc.Line].Start + loc.Column;        
-        public CharLocation GetLocation (int absolutePosition) {
-            TextLine tl = new TextLine (absolutePosition);
-            int result = lines.AsSpan (0, length).BinarySearch (tl);            
-            if (result < 0) {
-                result = ~result;
-                return result == 0 ?
-                    new CharLocation (0, absolutePosition) :
-                    new CharLocation (result - 1, absolutePosition - lines[result - 1].Start);
-            }
-            return new CharLocation (result, absolutePosition - lines[result].Start);
-        }
-        public void UpdateLineLengthInPixel (int index, int lengthInPixel) {
-            lines[index].LengthInPixel = lengthInPixel;
-        }
-        public int Count => length;
-        public bool IsReadOnly => false;
-        public bool IsEmpty => length == 0;
-
-        public TextLine this[int index] { get => lines[index]; set => lines[index] = value; }
-
-        public void Add (TextLine item) {
-            if (lines.Length < length + 1) {
-                TextLine[] tmp = new TextLine[length * 2];
-                lines.AsSpan ().CopyTo (tmp);
-                lines = tmp;
-            }
-            lines[length] = item;
-            length++;
-        }
-
-        public void Clear () {
-            length = 0;
-        }
-
-        public bool Contains (TextLine item) => Array.IndexOf<TextLine> (lines, item) >= 0;
-
-        public void CopyTo (TextLine[] array, int arrayIndex) {
-            lines.AsSpan (0, length).CopyTo (array.AsSpan (arrayIndex));
-        }
-
-        public bool Remove (TextLine item) {
-            int idx = Array.IndexOf<TextLine> (lines, item);
-            if (idx < 0)
-                return false;
-            if (idx + 1 < length)
-                lines.AsSpan (idx + 1, length - idx - 1).CopyTo (lines.AsSpan (idx));
-            length--;
-            return true;
-        }
-        public IEnumerator<TextLine> GetEnumerator () => new Enumerator (this);
-        IEnumerator IEnumerable.GetEnumerator () => GetEnumerator ();
-
-        public int IndexOf (TextLine item) => Array.IndexOf (lines, item);
-
-        public void Insert (int index, TextLine item) {
-            if (lines.Length < length + 1) {
-                TextLine[] tmp = new TextLine[length * 2];
-                lines.AsSpan (0, index).CopyTo (tmp);
-                lines.AsSpan (index).CopyTo (tmp.AsSpan (index + 1));
-                lines = tmp;
-            }else
-                lines.AsSpan (index, length - index).CopyTo (lines.AsSpan (index + 1));            
-            lines[index] = item;
-            length++;
-        }
-
-        public void RemoveAt (int index) {
-            if (index + 1 < length)
-                lines.AsSpan (index + 1, length - index - 1).CopyTo (lines.AsSpan (index));
-            length--;
-        }
-        public void RemoveAt (int index, int count) {
-            if (index + count < length)
-                lines.AsSpan (index + count, length - index - count).CopyTo (lines.AsSpan (index));
-            length -= count;
-        }
-
-        public class Enumerator : IEnumerator<TextLine>
-        {
-            TextLine[] lines;
-            int length, position = -1;
-            public Enumerator (LineCollection coll) {
-                lines = coll.lines;
-                length = coll.length;
-            }
-            public TextLine Current => lines[position];
-            object IEnumerator.Current => Current;
-            public void Dispose () { }
-            public bool MoveNext () => ++position < length;            
-            public void Reset () {
-                position = -1;
-            }
-        }
-    }
+       public class LineCollection : IList<TextLine>
+       {
+               TextLine[] lines;
+               int length;
+
+               #region CTOR
+               public LineCollection (int capacity) {
+                       lines = new TextLine[capacity];
+                       length = 0;
+               }
+               public LineCollection (TextLine[] _lines, int capacity = -1) {
+                       if (capacity >= _lines.Length) {
+                               lines = new TextLine[capacity];
+                               _lines.AsSpan ().CopyTo (lines);
+                       } else
+                               lines =_lines;
+
+                       length = _lines.Length;
+               }
+
+               public LineCollection (string _text, int capacity = 4) : this (capacity) {
+                       Update (_text.AsSpan ());
+               }
+               #endregion
+
+               public void Update (ReadOnlySpan<char> _text) {
+                       length = 0;
+                       int start = 0, i = 0;
+                       while (i < _text.Length) {
+                               char c = _text[i];
+                               if (c == '\r') {
+                                       if (++i < _text.Length) {
+                                               if (_text[i] == '\n')
+                                                       Add (new TextLine (start, i - 1, ++i));
+                                               else
+                                                       Add (new TextLine (start, i - 1, i));
+                                       } else
+                                               Add (new TextLine (start, i - 1, i));
+                                       start = i;
+                               } else if (c == '\n') {
+                                       if (++i < _text.Length) {
+                                               if (_text[i] == '\r')
+                                                       Add (new TextLine (start, i - 1, ++i));
+                                               else
+                                                       Add (new TextLine (start, i - 1, i));
+                                       } else
+                                               Add (new TextLine (start, i - 1, i));
+                                       start = i;
+
+                               } else if (c == '\u0085' || c == '\u2028' || c == '\u2029')
+                                       Add (new TextLine (start, i - 1, i));
+                               else
+                                       i++;
+                       }
+
+                       if (start < i)
+                               Add (new TextLine (start, _text.Length, _text.Length));
+                       else
+                               Add (new TextLine (_text.Length, _text.Length, _text.Length));
+               }
+
+               public void Update (TextChange change) {
+                       CharLocation locStart = GetLocation (change.Start);
+                       int charsDiff = change.ChangedText.Length - change.Length;
+                       int lineEnd = locStart.Line;
+                       while (lineEnd < length - 1 && change.End >= lines[lineEnd + 1].Start)
+                               lineEnd++;
+                       int columnEnd = change.End - lines[lineEnd].Start;
+                       int lineEndLineBreakLength = lines[lineEnd].LineBreakLength;
+
+                       LineCollection newLines = new LineCollection (change.ChangedText);
+                       int linesDiff = newLines.length - 1 - (lineEnd - locStart.Line);
+                       TextLine endTl = lines[lineEnd];
+
+                       if (linesDiff < 0)
+                               RemoveAt (locStart.Line + 1, -linesDiff);
+                       else if (linesDiff > 0) {
+                               for (int i = 0; i < linesDiff; i++)
+                                       Insert (locStart.Line + 1, default);
+                       }
+
+                       int remainingColumns = endTl.Length - columnEnd;
+                       lineEnd += linesDiff;
+                       lines[lineEnd].SetLength (0);
+                       lines[locStart.Line].SetLength (locStart.Column + newLines[0].Length);
+                       lines[lineEnd].Length += remainingColumns;
+                       if (newLines.Count > 1) {
+                               lines[lineEnd].Length += newLines[newLines.Count - 1].Length;
+                               lines[locStart.Line].LengthIncludingLineBreak = lines[locStart.Line].Length + newLines[0].LineBreakLength;
+                       }
+                       lines[lineEnd].LengthIncludingLineBreak = lines[lineEnd].Length + endTl.LineBreakLength;
+
+                       for (int i = 1; i < newLines.Count - 1; i++) {
+                               int l = locStart.Line + i;
+                               lines[l] = newLines[i];
+                               lines[l].Start = lines[l - 1].EndIncludingLineBreak;
+                       }
+                       if (lineEnd > 0)
+                               lines[lineEnd].Start = lines[lineEnd - 1].EndIncludingLineBreak;
+
+                       //shift start for remaining lines
+                       for (int i = lineEnd + 1; i < length; i++)
+                               lines[i].Start += charsDiff;
+               }
+               public int GetAbsolutePosition (CharLocation loc) => lines[loc.Line].Start + loc.Column;
+               public CharLocation GetLocation (int absolutePosition) {
+                       TextLine tl = new TextLine (absolutePosition);
+                       int result = lines.AsSpan (0, length).BinarySearch (tl);
+                       if (result < 0) {
+                               result = ~result;
+                               return result == 0 ?
+                                       new CharLocation (0, absolutePosition) :
+                                       new CharLocation (result - 1, absolutePosition - lines[result - 1].Start);
+                       }
+                       return new CharLocation (result, absolutePosition - lines[result].Start);
+               }
+               public void UpdateLineLengthInPixel (int index, int lengthInPixel) {
+                       lines[index].LengthInPixel = lengthInPixel;
+               }
+               public int Count => length;
+               public bool IsReadOnly => false;
+               public bool IsEmpty => length == 0;
+
+               public TextLine this[int index] { get => lines[index]; set => lines[index] = value; }
+
+               public void Add (TextLine item) {
+                       if (lines.Length < length + 1) {
+                               TextLine[] tmp = new TextLine[length * 2];
+                               lines.AsSpan ().CopyTo (tmp);
+                               lines = tmp;
+                       }
+                       lines[length] = item;
+                       length++;
+               }
+
+               public void Clear () {
+                       length = 0;
+               }
+
+               public bool Contains (TextLine item) => Array.IndexOf<TextLine> (lines, item) >= 0;
+
+               public void CopyTo (TextLine[] array, int arrayIndex) {
+                       lines.AsSpan (0, length).CopyTo (array.AsSpan (arrayIndex));
+               }
+
+               public bool Remove (TextLine item) {
+                       int idx = Array.IndexOf<TextLine> (lines, item);
+                       if (idx < 0)
+                               return false;
+                       if (idx + 1 < length)
+                               lines.AsSpan (idx + 1, length - idx - 1).CopyTo (lines.AsSpan (idx));
+                       length--;
+                       return true;
+               }
+               public IEnumerator<TextLine> GetEnumerator () => new Enumerator (this);
+               IEnumerator IEnumerable.GetEnumerator () => GetEnumerator ();
+
+               public int IndexOf (TextLine item) => Array.IndexOf (lines, item);
+
+               public void Insert (int index, TextLine item) {
+                       if (lines.Length < length + 1) {
+                               TextLine[] tmp = new TextLine[length * 2];
+                               lines.AsSpan (0, index).CopyTo (tmp);
+                               lines.AsSpan (index).CopyTo (tmp.AsSpan (index + 1));
+                               lines = tmp;
+                       }else
+                               lines.AsSpan (index, length - index).CopyTo (lines.AsSpan (index + 1));
+                       lines[index] = item;
+                       length++;
+               }
+
+               public void RemoveAt (int index) {
+                       if (index + 1 < length)
+                               lines.AsSpan (index + 1, length - index - 1).CopyTo (lines.AsSpan (index));
+                       length--;
+               }
+               public void RemoveAt (int index, int count) {
+                       if (index + count < length)
+                               lines.AsSpan (index + count, length - index - count).CopyTo (lines.AsSpan (index));
+                       length -= count;
+               }
+
+               public class Enumerator : IEnumerator<TextLine>
+               {
+                       TextLine[] lines;
+                       int length, position = -1;
+                       public Enumerator (LineCollection coll) {
+                               lines = coll.lines;
+                               length = coll.length;
+                       }
+                       public TextLine Current => lines[position];
+                       object IEnumerator.Current => Current;
+                       public void Dispose () { }
+                       public bool MoveNext () => ++position < length;
+                       public void Reset () {
+                               position = -1;
+                       }
+               }
+       }
 }
index ddc21c4724752f7f3675df283153df13f23fa99b..929d505451d3be4984c5736344c56cd8aec27b6c 100644 (file)
@@ -27,9 +27,11 @@ namespace Crow.Text
                public override int GetHashCode()
                        => HashCode.Combine(Start, End);
                public static bool operator ==(TextSpan left, TextSpan right)
-                       => left.Equals (right);         
+                       => left.Equals (right);
                public static bool operator !=(TextSpan left, TextSpan right)
                        => !left.Equals (right);
                public override string ToString() => $"{Start},{End}";
+               public bool Contains (int absolutePosition)
+                       => absolutePosition >= Start && absolutePosition < End;
        }
 }
index a0ea5fb5d3b83658d81f7fe41b16c1e93a79cc92..c0160dcbbc064d780ad5d1721fb6a333dc154d11 100644 (file)
@@ -6,7 +6,7 @@
                <Authors>Jean-Philippe Bruyère</Authors>
                <LangVersion>7.3</LangVersion>
 
-               <CrowVersion>0.9.7</CrowVersion>
+               <CrowVersion>0.9.8</CrowVersion>
                <CrowPackageVersion>$(CrowVersion)-beta</CrowPackageVersion>
 
                <!-- If you dont have a native libstb on your system, enable the managed version of stb here