aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Intellisense/CompletionItem.cs
blob: c8beebd283812f8cc711896ab803f4b19215870f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media.Imaging;
using Tango.Scripting.Editors.Document;
using Tango.Scripting.Editors.Editing;

namespace Tango.Scripting.Editors.Intellisense
{
    public abstract class CompletionItem : DependencyObject, ICompletionItem
    {
        public abstract string Text { get; }
        public object Description { get; set; }
        public double Priority { get; set; }
        public abstract CompletionItemPopupControl PopupControl { get; }

        public bool IsSelected
        {
            get { return (bool)GetValue(IsSelectedProperty); }
            set { SetValue(IsSelectedProperty, value); }
        }
        public static readonly DependencyProperty IsSelectedProperty =
            DependencyProperty.Register("IsSelected", typeof(bool), typeof(CompletionItem), new PropertyMetadata(false));

        public virtual void Complete(ScriptEditor editor)
        {
            var word = editor.GetCurrentWord();
            int index = editor.GetCurrentWordStartIndex();
            int max = editor.GetCurrentLine().EndOffset;

            editor.Document.Replace(index, word.Length,Text);
        }

        public abstract BitmapSource Image { get; }

        protected static BitmapSource GetImage(String name)
        {
            return new BitmapImage(new Uri($"pack://application:,,,/Tango.Scripting.Editors;component/Images/{name}", UriKind.Absolute));
        }

        public override string ToString()
        {
            return Text;
        }
    }
}
class="w"> series, IEnumerable<GraphPoint> points, bool sizeChanged) { if (sizeChanged) { if (g != null) { g.Dispose(); } _writeable_bitmap = new WriteableBitmap((int)Math.Max(Output.SurfaceWidth, 1), (int)Math.Max(Output.SurfaceHeight, 1), 96.0, 96.0, PixelFormats.Pbgra32, null); if (_gdi_bitmap != null) { _gdi_bitmap.Dispose(); } _gdi_bitmap = new Bitmap(_writeable_bitmap.PixelWidth, _writeable_bitmap.PixelHeight, _writeable_bitmap.BackBufferStride, System.Drawing.Imaging.PixelFormat.Format32bppPArgb, _writeable_bitmap.BackBuffer); _writeable_bitmap.Lock(); } bool isFirst = series == seriesCollection.First(); bool isLast = series == seriesCollection.Last(); if (isFirst) { if (!sizeChanged) { _writeable_bitmap.Lock(); } g = Graphics.FromImage(_gdi_bitmap); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; g.Clear(System.Drawing.Color.Transparent); //Apply zooming. if (ZoomRect.Width > 0 && ZoomRect.Height > 0) { var scale_x = (float)(Output.SurfaceWidth / ZoomRect.Width); var scale_y = (float)(Output.SurfaceHeight / ZoomRect.Height); var translate_x = (float)-ZoomRect.Left * scale_x; var translate_y = (float)-ZoomRect.Top * scale_y; g.TranslateTransform(translate_x, translate_y); g.ScaleTransform(scale_x, scale_y); if (scale_x != Transform.ScaleX || scale_y != Transform.ScaleY || translate_x != Transform.TranslateX || translate_y != Transform.TranslateY) { OnTransformChanged(new TransformChangedEventArgs() { Transform = new GraphTransform() { ScaleX = scale_x, ScaleY = scale_y, TranslateX = translate_x, TranslateY = translate_y, } }); OnVirtualRangeXChanged(); OnVirtualRangeYChanged(); } } } OnDraw(seriesCollection, series, points, g); if (isLast) { _writeable_bitmap.AddDirtyRect(new Int32Rect(0, 0, _writeable_bitmap.PixelWidth, _writeable_bitmap.PixelHeight)); _writeable_bitmap.Unlock(); var cloned = _writeable_bitmap.Clone(); cloned.Freeze(); OnPaintingCompleted(cloned); g.Dispose(); } } /// <summary> /// Called when the connected input <see cref="T:RealTimeGraphX.IGraphRenderer" /> invoked the <see cref="M:RealTimeGraphX.GraphPainterBase.Draw(RealTimeGraphX.GraphDataSeries,System.Collections.Generic.IEnumerable{RealTimeGraphX.Drawing.GraphPoint})" /> method. /// </summary> /// <param name="seriesCollection">The series collection.</param> /// <param name="series">The series.</param> /// <param name="points">The points.</param> /// <param name="g">The graphics object.</param> protected virtual void OnDraw(IEnumerable<WpfDataSeries> seriesCollection, WpfDataSeries series, IEnumerable<GraphPoint> points, Graphics g) { if (SurfaceWidth > 10 && SurfaceHeight > 10) { System.Drawing.Pen pen = new System.Drawing.Pen(series.GdiStroke, (float)series.StrokeThickness); List<PointF> gdiPoints = points.Select(x => new PointF((float)x.X, (float)x.Y)).ToList(); if (series.GdiFill != null) { if (series.GdiFill is System.Drawing.Drawing2D.LinearGradientBrush) { var gradient = (series.GdiFill as System.Drawing.Drawing2D.LinearGradientBrush); gradient.ResetTransform(); gradient.ScaleTransform((float)(Output.SurfaceWidth / gradient.Rectangle.Width), (float)(Output.SurfaceHeight / gradient.Rectangle.Height)); } g.FillPolygon(series.GdiFill, GetFillPoints(gdiPoints)); } try { g.DrawCurve(pen, gdiPoints.ToArray()); } catch { } pen.Dispose(); } } /// <summary> /// Gets a closed polygon version of the specified points to use with FillPolygon(). /// </summary> /// <param name="points">The points.</param> /// <returns></returns> protected virtual PointF[] GetFillPoints(List<PointF> points) { List<PointF> closed = points.ToList(); closed.Add(new PointF(points.Last().X, (float)SurfaceWidth)); closed.Add(new PointF(0, (float)SurfaceHeight)); return closed.ToArray(); } } }