aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Intellisense/FieldCompletionItemPopup.cs
blob: e1ea3ce55e143fabfd5fad18269c7b8c0b1db56e (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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Tango.Scripting.Editors.Intellisense
{
    public class FieldCompletionItemPopup : CompletionItemPopupControl
    {
        static FieldCompletionItemPopup()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(FieldCompletionItemPopup), new FrameworkPropertyMetadata(typeof(FieldCompletionItemPopup)));
        }
    }
}
.gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;

namespace Tango.BL.Entities
{
    public partial class Segment
    {
        private double _lastLength;
        private LinearGradientBrush _brush;

        public override void Save(ObservablesContext context)
        {
            for (int i = 0; i < BrushStops.Count; i++)
            {
                BrushStops[i].StopIndex = i;
            }

            base.Save(context);
        }

        protected override void RaisePropertyChanged(string propName)
        {
            base.RaisePropertyChanged(propName);

            if (propName == nameof(Length) && _lastLength != Length)
            {
                BrushStops.ToList().ForEach(x => x.RaiseOffsetChanged());
                _lastLength = Length;
            }

            if (propName == nameof(BrushStops))
            {
                if (BrushStops != null)
                {
                    BrushStops.CollectionChanged -= BrushStops_CollectionChanged;
                    BrushStops.CollectionChanged += BrushStops_CollectionChanged;

                    foreach (var stop in BrushStops)
                    {
                        stop.RaiseOffsetChanged();
                    }

                    RaiseSegmentBrushChanged();
                }
            }
        }

        private void BrushStops_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            foreach (var stop in BrushStops)
            {
                stop.RaiseOffsetChanged();
            }

            if (BrushStops.Count > 0)
            {
                BrushStops.First().OffsetPercent = 0;
            }
            if (BrushStops.Count > 1)
            {
                BrushStops.Last().OffsetPercent = 100;
            }

            RaiseSegmentBrushChanged();
        }

        private TimeSpan _remainingTime;
        [NotMapped]
        [JsonIgnore]
        public TimeSpan RemainingTime
        {
            get { return _remainingTime; }
            set { _remainingTime = value; RaisePropertyChangedAuto(); }
        }

        private bool _started;
        [NotMapped]
        [JsonIgnore]
        public bool Started
        {
            get { return _started; }
            set { _started = value; RaisePropertyChangedAuto(); }
        }

        private bool _completed;
        [NotMapped]
        [JsonIgnore]
        public bool Completed
        {
            get { return _completed; }
            set { _completed = value; RaisePropertyChangedAuto(); }
        }

        [NotMapped]
        [JsonIgnore]
        public Brush SegmentBrush
        {
            get
            {
                return GetSegmentBrush();
            }
        }

        private bool _isInterSegment;
        [NotMapped]
        [JsonIgnore]
        public bool IsInterSegment
        {
            get { return _isInterSegment; }
            set { _isInterSegment = value; RaisePropertyChangedAuto(); }
        }


        [NotMapped]
        public bool HasOutOfGamutBrushStop
        {
            get { return BrushStops.Any(x => x.IsOutOfGamut); }
        }

        internal void RaiseHasOutOfGamutBrushStop()
        {
            RaisePropertyChanged(nameof(HasOutOfGamutBrushStop));
        }

        public override Segment Clone()
        {
            Segment cloned = base.Clone();

            cloned.BrushStops = BrushStops.Select(x => x.Clone()).ToObservableCollection();

            return cloned;
        }

        public Segment Clone(Job job)
        {
            Segment cloned = base.Clone();

            cloned.BrushStops = BrushStops.Select(x => x.Clone(cloned)).ToObservableCollection();

            cloned.Job = job;
            cloned.JobGuid = job.Guid;

            return cloned;
        }

        public override void DefferedDelete(ObservablesContext context)
        {
            BrushStops.ToList().ForEach(x => x.DefferedDelete(context));
            BrushStops.Clear();
            base.DefferedDelete(context);
        }

        public LinearGradientBrush GetSegmentBrush()
        {
            if (_brush == null || _brush.GradientStops.Count != BrushStops.Count)
            {
                GradientStopCollection stops = new GradientStopCollection();

                foreach (var stop in BrushStops.OrderBy(x => x.StopIndex))
                {
                    stops.Add(new GradientStop(stop.Color, stop.OffsetPercent / 100d));
                }

                LinearGradientBrush brush = new LinearGradientBrush();
                brush.StartPoint = new Point(0, 0);
                brush.EndPoint = new Point(1, 0);

                brush.GradientStops = stops;

                _brush = brush;
                return brush;
            }
            else
            {
                for (int i = 0; i < BrushStops.Count; i++)
                {
                    _brush.GradientStops[i].Color = BrushStops[i].Color;
                    _brush.GradientStops[i].Offset = BrushStops[i].OffsetPercent / 100d;
                }

                return _brush;
            }
        }

        public System.Drawing.Brush CreateGdiBrush(int width, int height)
        {
            if (BrushStops.Count > 1)
            {
                System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new System.Drawing.PointF(0, 0), new System.Drawing.Point(width, height), System.Drawing.Color.Black, System.Drawing.Color.Black);

                System.Drawing.Drawing2D.ColorBlend blend = new System.Drawing.Drawing2D.ColorBlend();

                List<System.Drawing.Color> colors = new List<System.Drawing.Color>();
                List<float> offsets = new List<float>();

                foreach (var stop in BrushStops.OrderBy(x => x.OffsetPercent))
                {
                    colors.Add(stop.Color.ToGdiColor());
                    offsets.Add((float)stop.OffsetPercent / 100f);
                }

                blend.Colors = colors.ToArray();
                blend.Positions = offsets.ToArray();

                brush.InterpolationColors = blend;

                return brush;
            }
            else if (BrushStops.Count == 1)
            {
                return new System.Drawing.SolidBrush(BrushStops.First().Color.ToGdiColor());
            }
            else
            {
                return System.Drawing.Brushes.Black;
            }
        }

        public void RaiseSegmentBrushChanged()
        {
            RaisePropertyChanged(nameof(SegmentBrush));
        }

        public BrushStop AddBrushStop()
        {
            BrushStop stop = new BrushStop();

            if (Job.ColorSpace != null)
            {
                stop.ColorSpace = Job.ColorSpace;
            }
            else
            {
                stop.ColorSpaceGuid = Job.ColorSpaceGuid;
            }

            if (BrushStops.Count > 0)
            {
                stop.StopIndex = BrushStops.Max(x => x.StopIndex) + 1;
                stop.OffsetPercent = 100;
            }
            else
            {
                stop.StopIndex = 1;
            }

            stop.Segment = this;
            stop.Color = Colors.Black;

            BrushStops.Add(stop);

            return stop;
        }
    }
}