blob: 2c08cbf371ea1eaa467cb8e0885368cac97ec4a1 (
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
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
{
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))
{
BrushStops.ToList().ForEach(x => x.RaiseOffsetChanged());
}
}
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(); }
}
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()
{
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;
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;
}
}
}
}
|