Skip to content

Commit ed6c634

Browse files
authored
Merge pull request #756 from da-markson/VIX-3737
VIX-3737 Added new movement type of Resize to the Text Effect
2 parents 723653e + 0d75209 commit ed6c634

File tree

4 files changed

+93
-9
lines changed

4 files changed

+93
-9
lines changed

src/Vixen.Modules/Effect/Picture/EffectType.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ public enum EffectType
3333
[Description("Peekaboo 270")]
3434
RenderPicturePeekaboo270,
3535
[Description("Wiggle")]
36-
RenderPictureWiggle
37-
36+
RenderPictureWiggle,
37+
[Description("Resize")]
38+
RenderPictureResize
3839
}
3940
}

src/Vixen.Modules/Effect/Picture/Picture.cs

Lines changed: 75 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public EffectType Type
5858
UpdateDirectionAttribute();
5959
UpdateMovementRateAttribute();
6060
UpdateCenterStopAttribute();
61+
UpdateSizingAttribute();
6162
OnPropertyChanged();
6263
}
6364
}
@@ -150,6 +151,23 @@ public Curve YOffsetCurve
150151
}
151152
}
152153

154+
[Value]
155+
[ProviderCategory(@"Movement", 1)]
156+
[ProviderDisplayName(@"Sizing")]
157+
[ProviderDescription(@"Sizing")]
158+
[PropertyOrder(7)]
159+
public Curve SizingCurve
160+
{
161+
get { return _data.ScalingCurve; }
162+
set
163+
{
164+
_data.ScalingCurve = value;
165+
IsDirty = true;
166+
UpdateSizingAttribute();
167+
OnPropertyChanged();
168+
}
169+
}
170+
153171
[Value]
154172
[ProviderCategory(@"Movement", 1)]
155173
[ProviderDisplayName(@"PictureCenterStop")]
@@ -415,6 +433,7 @@ private void UpdateAttributes()
415433
UpdateStringOrientationAttributes();
416434
UpdatePictureSourceAttribute(false);
417435
UpdateCenterStopAttribute(false);
436+
UpdateSizingAttribute(false);
418437
TypeDescriptor.Refresh(this);
419438
}
420439

@@ -470,6 +489,24 @@ private void UpdateCenterStopAttribute(bool refresh = true)
470489
}
471490
}
472491

492+
/// <summary>
493+
/// Determines when the 'Sizing' setting is applicable.
494+
/// </summary>
495+
private void UpdateSizingAttribute(bool refresh = true)
496+
{
497+
// Sizing is only applicable for movement type of Resize
498+
bool resizeApplicable = Type == EffectType.RenderPictureResize;
499+
500+
Dictionary<string, bool> propertyStates = new Dictionary<string, bool>(1)
501+
{
502+
{nameof(SizingCurve), resizeApplicable }
503+
};
504+
SetBrowsable(propertyStates);
505+
if (refresh)
506+
{
507+
TypeDescriptor.Refresh(this);
508+
}
509+
}
473510

474511
private void UpdateMovementRateAttribute(bool refresh = true)
475512
{
@@ -753,13 +790,28 @@ private void InitialRender(int frame, double intervalPosFactor)
753790

754791
if (_pictures.Count > 0)
755792
{
756-
for (int i = 0; i < _pictures.Count; i++)
793+
if (Type == EffectType.RenderPictureResize && _pictures.Count == 1)
794+
{
795+
_fp = new FastPixel.FastPixel(ScaleImage(_pictures[0].bitmap, CalculateSizing(GetEffectTimeIntervalPosition(frame) * 100)));
796+
}
797+
798+
else
757799
{
758-
if (frame >= _pictures[i].frame)
800+
for (int i = 0; i < _pictures.Count; i++)
759801
{
760-
_fp = new FastPixel.FastPixel(_pictures[i].bitmap);
761-
_pictures.RemoveAt(i);
762-
break;
802+
if (frame >= _pictures[i].frame)
803+
{
804+
if (Type == EffectType.RenderPictureResize)
805+
{
806+
_fp = new FastPixel.FastPixel(ScaleImage(_pictures[i].bitmap, CalculateSizing(GetEffectTimeIntervalPosition(frame) * 100)));
807+
}
808+
else
809+
{
810+
_fp = new FastPixel.FastPixel(_pictures[i].bitmap);
811+
}
812+
_pictures.RemoveAt(i);
813+
break;
814+
}
763815
}
764816
}
765817
}
@@ -971,6 +1023,15 @@ private void CalculatePixel(int x, int y, IPixelFrameBuffer frameBuffer, int fra
9711023
}
9721024
switch (Type)
9731025
{
1026+
case EffectType.RenderPictureResize:
1027+
if (TargetPositioning == TargetPositioningType.Locations)
1028+
{
1029+
locationY = _yoffset - y + _yOffsetAdj;
1030+
locationX = x + _xoffset - _xOffsetAdj;
1031+
break;
1032+
}
1033+
frameBuffer.SetPixel(xCoord - _xoffset + _xOffsetAdj, _yoffset - yCoord + _yOffsetAdj, fpColor);
1034+
return;
9741035
case EffectType.RenderPicturePeekaboo0:
9751036
if (TargetPositioning == TargetPositioningType.Locations)
9761037
{
@@ -1188,6 +1249,11 @@ private double CalculateIncreaseBrightness(double intervalPos)
11881249
return ScaleCurveToValue(IncreaseBrightnessCurve.GetValue(intervalPos), 100, 10);
11891250
}
11901251

1252+
private double CalculateSizing(double intervalPos)
1253+
{
1254+
return ScaleCurveToValue(SizingCurve.GetValue(intervalPos), 100, 0) / 100;
1255+
}
1256+
11911257
private Color CustomColor(int frame, double level, Color fpColor, double adjustedBrightness)
11921258
{
11931259
if (ColorEffect == ColorEffect.CustomColor)
@@ -1248,6 +1314,10 @@ public static Bitmap ScaleImage(Image image, double scale)
12481314
var newWidth = (int) (image.Width * ratio);
12491315
var newHeight = (int) (image.Height * ratio);
12501316

1317+
// Make sure dimensions are at least 1 pixel
1318+
newWidth = Math.Max(1, newWidth);
1319+
newHeight = Math.Max(1, newHeight);
1320+
12511321
var newImage = new Bitmap(newWidth, newHeight);
12521322
using (var g = Graphics.FromImage(newImage))
12531323
{

src/Vixen.Modules/Effect/Picture/PictureData.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public PictureData()
2020
LevelCurve = new Curve(new PointPairList(new[] { 0.0, 100.0 }, new[] { 100.0, 100.0 }));
2121
Colors = new ColorGradient(Color.DodgerBlue);
2222
ColorEffect = ColorEffect.None;
23+
ScalingCurve = new Curve(new PointPairList(new[] { 0.0, 100.0 }, new[] { 100.0, 100.0 }));
2324
ScalePercent = 50;
2425
Source = PictureSource.Embedded;
2526
MovementRate = 4;
@@ -65,6 +66,9 @@ public PictureData()
6566
[DataMember]
6667
public int ScalePercent { get; set; }
6768

69+
[DataMember]
70+
public Curve ScalingCurve { get; set; }
71+
6872
[DataMember(EmitDefaultValue = false)]
6973
public int XOffset { get; set; }
7074

@@ -112,6 +116,12 @@ public void OnDeserialized(StreamingContext c)
112116
if (TilePictures == TilePictures.None)
113117
TilePictures = TilePictures.BlueGlowDots;
114118

119+
// Ensure curves are not null. This use-case can be if loading a sequence prior to introducing the Movement of Resize
120+
if (ScalingCurve == null)
121+
{
122+
ScalingCurve = new Curve(new PointPairList(new[] { 0.0, 100.0 }, new[] { 100.0, 100.0 }));
123+
}
124+
115125
//if one of them is null the others probably are, and if this one is not then they all should be good.
116126
//Try to save some cycles on every load
117127

src/Vixen.Modules/EffectEditor/EffectDescriptorAttributes/EffectDisplayNameDescriptors.resx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@
141141
<data name="CenterStop" xml:space="preserve">
142142
<value>Center Stop</value>
143143
</data>
144-
<data name="EndStop" xml:space="preserve">
144+
<data name="EndStop" xml:space="preserve">
145145
<value>End Stop</value>
146146
</data>
147-
<data name="CenterText" xml:space="preserve">
147+
<data name="CenterText" xml:space="preserve">
148148
<value>Center Text</value>
149149
</data>
150150
<data name="Interval" xml:space="preserve">
@@ -1383,4 +1383,7 @@
13831383
<data name="PatternPatternType" xml:space="preserve">
13841384
<value>Pattern Type</value>
13851385
</data>
1386+
<data name="Sizing" xml:space="preserve">
1387+
<value>Sizing</value>
1388+
</data>
13861389
</root>

0 commit comments

Comments
 (0)