Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
92 changed files
with
12,241 additions
and
492 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
100 changes: 100 additions & 0 deletions
100
src/EgamiFlowScreensaver/AlphaChangeScreensaverImageItemBehavior.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// <copyright file="AlphaChangeScreensaverImageItemBehavior.cs" company="natsnudasoft"> | ||
// Copyright (c) Adrian John Dunstan. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// </copyright> | ||
|
||
namespace Natsnudasoft.EgamiFlowScreensaver | ||
{ | ||
using System; | ||
using Microsoft.Xna.Framework; | ||
|
||
/// <summary> | ||
/// Provides a behaviour to apply to an image item that causes the image item to transition from | ||
/// one alpha value to another over a specified time frame. | ||
/// </summary> | ||
/// <seealso cref="TransitionScreensaverImageItemBehavior"/> | ||
public sealed class AlphaChangeScreensaverImageItemBehavior : | ||
TransitionScreensaverImageItemBehavior | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="AlphaChangeScreensaverImageItemBehavior"/> | ||
/// class. | ||
/// </summary> | ||
/// <param name="screensaverArea">The description of the area of the screensaver.</param> | ||
/// <param name="startAlpha">The alpha value that the image item this behaviour is applied | ||
/// to will start at. This value can be out of range to delay the start of the transition. | ||
/// </param> | ||
/// <param name="endAlpha">The alpha value that the image item this behaviour is applied to | ||
/// will finish at. This value can be out of range to advance to the end of the transition | ||
/// faster.</param> | ||
/// <param name="transitionTime">The time the image item this behaviour is applied to will | ||
/// take to transition between the specified alpha values.</param> | ||
/// <exception cref="ArgumentNullException"><paramref name="screensaverArea"/> is | ||
/// <see langword="null"/>.</exception> | ||
/// <exception cref="ArgumentOutOfRangeException"><paramref name="transitionTime"/> is less | ||
/// than a zero time.</exception> | ||
public AlphaChangeScreensaverImageItemBehavior( | ||
ScreensaverArea screensaverArea, | ||
float startAlpha, | ||
float endAlpha, | ||
TimeSpan transitionTime) | ||
: base( | ||
screensaverArea, | ||
transitionTime, | ||
(s, p) => s.Alpha = | ||
MathHelper.Clamp(MathHelper.Lerp(startAlpha, endAlpha, p), 0f, 1f)) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="AlphaChangeScreensaverImageItemBehavior"/> | ||
/// class. | ||
/// </summary> | ||
/// <param name="screensaverArea">The description of the area of the screensaver.</param> | ||
/// <param name="startAlpha">The alpha value that the image item this behaviour is applied | ||
/// to will start at. This value can be out of range to delay the start of the transition. | ||
/// </param> | ||
/// <param name="endAlpha">The alpha value that the image item this behaviour is applied to | ||
/// will finish at. This value can be out of range to advance to the end of the transition | ||
/// faster.</param> | ||
/// <param name="transitionTime">The time the image item this behaviour is applied to will | ||
/// take to transition between the specified alpha values.</param> | ||
/// <param name="endTransitionAlpha">The alpha value that the image item this behaviour is | ||
/// applied to will finish at when it is being destroyed (starting from | ||
/// <paramref name="endAlpha"/>).</param> | ||
/// <param name="endTransitionTime">The time the image item this behaviour is applied to | ||
/// will take to transition when it is being destroyed.</param> | ||
/// <exception cref="ArgumentNullException"><paramref name="screensaverArea"/> is | ||
/// <see langword="null"/>.</exception> | ||
/// <exception cref="ArgumentOutOfRangeException"><paramref name="transitionTime"/>, or | ||
/// <paramref name="endTransitionTime"/> is less than a zero time.</exception> | ||
public AlphaChangeScreensaverImageItemBehavior( | ||
ScreensaverArea screensaverArea, | ||
float startAlpha, | ||
float endAlpha, | ||
TimeSpan transitionTime, | ||
float endTransitionAlpha, | ||
TimeSpan endTransitionTime) | ||
: base( | ||
screensaverArea, | ||
transitionTime, | ||
(s, p) => s.Alpha = | ||
MathHelper.Clamp(MathHelper.Lerp(startAlpha, endAlpha, p), 0f, 1f), | ||
endTransitionTime, | ||
(s, p) => s.Alpha = | ||
MathHelper.Clamp(MathHelper.Lerp(endAlpha, endTransitionAlpha, p), 0f, 1f)) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
// <copyright file="BottomLeftImageEmitDetails.cs" company="natsnudasoft"> | ||
// Copyright (c) Adrian John Dunstan. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// </copyright> | ||
|
||
namespace Natsnudasoft.EgamiFlowScreensaver | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Microsoft.Xna.Framework; | ||
using Microsoft.Xna.Framework.Graphics; | ||
using Natsnudasoft.EgamiFlowScreensaver.Config; | ||
using Natsnudasoft.NatsnudaLibrary; | ||
|
||
/// <summary> | ||
/// Provides a class capable of creating locations at the bottom left of a screen for a | ||
/// <see cref="ScreensaverImageEmitter" />. | ||
/// </summary> | ||
public sealed class BottomLeftImageEmitDetails : ImageEmitDetails | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="BottomLeftImageEmitDetails"/> class. | ||
/// </summary> | ||
/// <param name="screensaverArea">The description of the area of the screensaver.</param> | ||
/// <param name="screensaverConfiguration">The <see cref="ScreensaverConfiguration"/> | ||
/// representing the configured state of the screensaver.</param> | ||
/// <param name="behaviorFactories">A collection of factories that define how to create | ||
/// behaviours that will be attached to any images emitted by a | ||
/// <see cref="ScreensaverImageEmitter"/>.</param> | ||
/// <exception cref="ArgumentNullException"><paramref name="screensaverArea"/>, | ||
/// <paramref name="screensaverConfiguration"/>, or <paramref name="behaviorFactories"/> | ||
/// is <see langword="null"/>.</exception> | ||
public BottomLeftImageEmitDetails( | ||
ScreensaverArea screensaverArea, | ||
ScreensaverConfiguration screensaverConfiguration, | ||
IEnumerable<Func<IScreensaverImageItemBehavior>> behaviorFactories) | ||
: base(screensaverArea, screensaverConfiguration, behaviorFactories) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="BottomLeftImageEmitDetails"/> class. | ||
/// </summary> | ||
/// <param name="screensaverArea">The description of the area of the screensaver.</param> | ||
/// <param name="screensaverConfiguration">The <see cref="ScreensaverConfiguration"/> | ||
/// representing the configured state of the screensaver.</param> | ||
/// <param name="behaviorFactories">A collection of factories that define how to create | ||
/// behaviours that will be attached to any images emitted by a | ||
/// <see cref="ScreensaverImageEmitter"/>.</param> | ||
/// <param name="random">A pseudo-random number generator that can be used to generate | ||
/// randomness in the <see cref="BottomLeftImageEmitDetails"/>.</param> | ||
/// <exception cref="ArgumentNullException"><paramref name="screensaverArea"/>, | ||
/// <paramref name="screensaverConfiguration"/>, <paramref name="behaviorFactories"/>, or | ||
/// <paramref name="random"/> is <see langword="null"/>.</exception> | ||
public BottomLeftImageEmitDetails( | ||
ScreensaverArea screensaverArea, | ||
ScreensaverConfiguration screensaverConfiguration, | ||
IEnumerable<Func<IScreensaverImageItemBehavior>> behaviorFactories, | ||
Random random) | ||
: base(screensaverArea, screensaverConfiguration, behaviorFactories, random) | ||
{ | ||
} | ||
|
||
/// <inheritdoc/> | ||
/// <exception cref="ArgumentNullException"><paramref name="texture"/> is | ||
/// <see langword="null"/>.</exception> | ||
public override ScreensaverImageItem CreateScreensaverImageItem(Texture2D texture) | ||
{ | ||
ParameterValidation.IsNotNull(texture, nameof(texture)); | ||
|
||
var origin = new Vector2(texture.Width, texture.Height) / 2f; | ||
var bottomLeftPrimary = new Point( | ||
this.ScreensaverArea.PrimaryGameBounds.Left, | ||
this.ScreensaverArea.PrimaryGameBounds.Bottom); | ||
var maxX = bottomLeftPrimary.X - texture.Width + origin.X; | ||
var minX = maxX - TwoPositionDistribution; | ||
var minY = bottomLeftPrimary.Y + origin.Y; | ||
var maxY = minY + TwoPositionDistribution; | ||
var position = new Vector2( | ||
this.Random.NextFloat(minX, maxX), | ||
this.Random.NextFloat(minY, maxY)); | ||
return new ScreensaverImageItem( | ||
texture, | ||
this.BehaviorFactories.Select(f => f?.Invoke())) | ||
{ | ||
Position = position, | ||
Origin = origin | ||
}; | ||
} | ||
|
||
/// <inheritdoc/> | ||
protected override Func<IScreensaverImageItemBehavior> CreateDefaultMovingBehaviorFactory() | ||
{ | ||
IScreensaverImageItemBehavior CreateDefaultMovingBehavior() | ||
{ | ||
const float minSpeed = MovingScreensaverImageItemBehavior.DefaultMinSpeed; | ||
const float maxSpeed = MovingScreensaverImageItemBehavior.DefaultMaxSpeed; | ||
var speed = new Vector2( | ||
this.Random.NextFloat(minSpeed, maxSpeed), | ||
-this.Random.NextFloat(minSpeed, maxSpeed)); | ||
return new MovingScreensaverImageItemBehavior(this.ScreensaverArea, speed); | ||
} | ||
|
||
return CreateDefaultMovingBehavior; | ||
} | ||
} | ||
} |
Oops, something went wrong.