Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions MoeIDE/EditorBackground.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ private void SetSolidBrush(ThemeChangedEventArgs e)
var color = uiShell.GetThemedWPFColor(EnvironmentColors.SystemWindowColorKey);
var brush = new SolidColorBrush(color);
brush.Freeze();
if (hostRootVisual == null)
{
var source = PresentationSource.FromVisual(control) as HwndSource;
hostRootVisual = source.RootVisual as Panel;
}
hostRootVisual.Background = brush;
}

Expand Down
13 changes: 13 additions & 0 deletions MoeIDE/ImageSwitcher.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<UserControl x:Class="Meowtrix.MoeIDE.ImageSwitcher"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Meowtrix.MoeIDE"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800" x:Name="window">
<Grid>
<Image x:Name="behind" Panel.ZIndex="0" Stretch="{Binding Stretch, ElementName=window}" SourceUpdated="behind_SourceUpdated"/>
<Image x:Name="front" Panel.ZIndex="1" Stretch="{Binding Stretch, ElementName=window}" SourceUpdated="front_SourceUpdated"/>
</Grid>
</UserControl>
213 changes: 213 additions & 0 deletions MoeIDE/ImageSwitcher.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Threading;

namespace Meowtrix.MoeIDE
{
/// <summary>
/// Interaction logic for ImageSwitcher.xaml
/// </summary>
public partial class ImageSwitcher : UserControl
{
public static readonly DependencyProperty StretchProperty =
DependencyProperty.Register("Stretch", typeof(Stretch), typeof(ImageSwitcher), new PropertyMetadata(Stretch.UniformToFill));

public Stretch Stretch
{
get { return (Stretch)GetValue(StretchProperty); }
set { SetValue(StretchProperty, value); }
}

public static readonly DependencyProperty IntervalProperty =
DependencyProperty.Register("Interval", typeof(double), typeof(ImageSwitcher), new PropertyMetadata(120000.0));

public double Interval
{
get { return (double)GetValue(IntervalProperty); }
set
{
if ((double)GetValue(IntervalProperty) != value)
{
if (backgroundChanger != null)
{
backgroundChanger.Stop();
backgroundChanger.Interval = TimeSpan.FromMilliseconds(value);
if (!Hibernating)
{
backgroundChanger.Start();
}
}
SetValue(IntervalProperty, value);
}
}
}

public enum Transitions
{
[Description("Smooth fade between 2 images")]FADE, // Implemented :D
[Description("Fade-out old image, fade-in new image")] FADE_IN_OUT, // todo: later
[Description("Slide new image to the left")] SLIDE_TO_LEFT, // todo: later
[Description("Slide new image to the right")] SLIDE_TO_RIGHT, //todo: later
}

private DispatcherTimer backgroundChanger;
private Queue<string> imageFiles;
private Storyboard story = new Storyboard();
private bool Hibernating = true;

public double TransitionDuration;
public Transitions TransitionType;
public Image ActiveImage;

public ImageSwitcher(string mustExistsFolderPath)
{
TransitionType = Transitions.FADE;
Interval = 30000.0;
Stretch = Stretch.UniformToFill;
TransitionDuration = 2000.0;
var files = Directory.EnumerateFiles(mustExistsFolderPath).Where(f => f.EndsWith(".jpg") || f.EndsWith(".png"));
imageFiles = new Queue<string>(files);
backgroundChanger = new DispatcherTimer
{
Interval = TimeSpan.FromMilliseconds(Interval) // 2 minutes | todo: implement on setting Page
};
backgroundChanger.Tick += BackgroundChanger_Tick;

InitializeComponent();
}

public void Hibernate()
{
backgroundChanger.Stop();
Hibernating = true;
}

public void Wake()
{
if (!Hibernating)
{
if (!backgroundChanger.IsEnabled)
{
backgroundChanger.Start();
}
return;
}

if (imageFiles.Count > 0)
{
var t = imageFiles.Dequeue();
SwitchTo(LoadImage(t));
imageFiles.Enqueue(t);
}
if (imageFiles.Count > 1)
{
backgroundChanger.Start();
}
Hibernating = false;
}

private void BackgroundChanger_Tick(object sender, EventArgs e)
{
backgroundChanger.Stop();

var t = imageFiles.Dequeue();
ImageSource newImg = LoadImage(t);
imageFiles.Enqueue(t);
SwitchTo(newImg, TransitionType);

backgroundChanger.Start();
}

public void SwitchTo(ImageSource newImage)
{
SwitchTo(newImage, TransitionType);
}

public void SwitchTo(ImageSource newImage, Transitions transition)
{
if (newImage == null)
{
return;
}
switch (transition)
{
default:
case Transitions.FADE:
if (ActiveImage == behind)
{
front.Source = newImage;
ActiveImage = front;
front.BeginAnimation(OpacityProperty,
new DoubleAnimation(1,
new Duration(TimeSpan.FromMilliseconds(TransitionDuration))));
}
else
{
behind.Source = newImage;
ActiveImage = behind;
front.BeginAnimation(OpacityProperty,
new DoubleAnimation(0,
new Duration(TimeSpan.FromMilliseconds(TransitionDuration))));
}
break;
case Transitions.FADE_IN_OUT:
break;
case Transitions.SLIDE_TO_LEFT:
break;
case Transitions.SLIDE_TO_RIGHT:
break;
}
}

private BitmapFrame LoadImage(string filename)
{
var imagesource = BitmapFrame.Create(new Uri(filename), BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
imagesource.Freeze();
return imagesource;
}

public void ChangeFolder(string folderPath)
{
if (imageFiles.Count > 0 && imageFiles.Peek().Contains(folderPath))
{
return;
}
backgroundChanger.Stop();

var files = Directory.EnumerateFiles(folderPath).Where(f => f.EndsWith(".jpg") || f.EndsWith(".png"));
imageFiles = new Queue<string>(files);
if (!Hibernating)
{
if (imageFiles.Count > 0)
{
var t = imageFiles.Dequeue();
SwitchTo(LoadImage(t), TransitionType);
imageFiles.Enqueue(t);
}
if (imageFiles.Count > 1)
{
backgroundChanger.Start();
}
}
}

private void behind_SourceUpdated(object sender, DataTransferEventArgs e)
{
ActiveImage = behind;
}

private void front_SourceUpdated(object sender, DataTransferEventArgs e)
{
ActiveImage = front;
}
}
}
55 changes: 31 additions & 24 deletions MoeIDE/MoeIDE.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
<ItemGroup>
<Compile Include="EditorBackground.cs" />
<Compile Include="EditorBackgroundTextViewCreationListener.cs" />
<Compile Include="ImageSwitcher.xaml.cs">
<DependentUpon>ImageSwitcher.xaml</DependentUpon>
</Compile>
<Compile Include="LocalizedExtension.cs" />
<Compile Include="Native.cs" />
<Compile Include="Settings.cs">
Expand Down Expand Up @@ -113,30 +116,30 @@
<Reference Include="Microsoft.VisualStudio.CommandBars, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<EmbedInteropTypes>False</EmbedInteropTypes>
</Reference>
<PackageReference Include="Microsoft.VisualStudio.CoreUtility" Version="14.3.25407" />
<PackageReference Include="Microsoft.VisualStudio.Imaging" Version="14.3.25407" />
<PackageReference Include="Microsoft.VisualStudio.OLE.Interop" Version="7.10.6070" />
<PackageReference Include="Microsoft.VisualStudio.CoreUtility" Version="15.6.27740" />
<PackageReference Include="Microsoft.VisualStudio.Imaging" Version="15.7.27703" />
<PackageReference Include="Microsoft.VisualStudio.OLE.Interop" Version="7.10.6071" />
<PackageReference Include="Microsoft.VisualStudio.Shell.14.0" Version="14.3.25407" />
<PackageReference Include="Microsoft.VisualStudio.Shell.Immutable.10.0" Version="10.0.30319" />
<PackageReference Include="Microsoft.VisualStudio.Shell.Immutable.11.0" Version="11.0.50727" />
<PackageReference Include="Microsoft.VisualStudio.Shell.Immutable.12.0" Version="12.0.21003" />
<PackageReference Include="Microsoft.VisualStudio.Shell.Immutable.14.0" Version="14.3.25407" />
<PackageReference Include="Microsoft.VisualStudio.Shell.Interop" Version="7.10.6071" />
<PackageReference Include="Microsoft.VisualStudio.Shell.Interop.8.0" Version="8.0.50727" />
<PackageReference Include="Microsoft.VisualStudio.Shell.Interop.9.0" Version="9.0.30729" />
<PackageReference Include="Microsoft.VisualStudio.Shell.Interop.10.0" Version="10.0.30319" />
<PackageReference Include="Microsoft.VisualStudio.Shell.Interop.11.0" Version="11.0.61030" />
<PackageReference Include="Microsoft.VisualStudio.Shell.Interop.12.0" Version="12.0.30110" />
<PackageReference Include="Microsoft.VisualStudio.Text.Data" Version="14.3.25407" />
<PackageReference Include="Microsoft.VisualStudio.Text.Logic" Version="14.3.25407" />
<PackageReference Include="Microsoft.VisualStudio.Text.UI" Version="14.3.25407" />
<PackageReference Include="Microsoft.VisualStudio.Text.UI.Wpf" Version="14.3.25407" />
<PackageReference Include="Microsoft.VisualStudio.TextManager.Interop" Version="7.10.6070" />
<PackageReference Include="Microsoft.VisualStudio.TextManager.Interop.8.0" Version="8.0.50727" />
<PackageReference Include="Microsoft.VisualStudio.Threading" Version="14.1.131" />
<PackageReference Include="Microsoft.VisualStudio.Utilities" Version="14.3.25407" />
<PackageReference Include="Microsoft.VisualStudio.Validation" Version="14.1.111" />
<PackageReference Include="Microsoft.VSSDK.BuildTools" Version="15.0.26201" />
<PackageReference Include="Microsoft.VisualStudio.Shell.Immutable.10.0" Version="15.0.25415" />
<PackageReference Include="Microsoft.VisualStudio.Shell.Immutable.11.0" Version="15.0.25415" />
<PackageReference Include="Microsoft.VisualStudio.Shell.Immutable.12.0" Version="15.0.25415" />
<PackageReference Include="Microsoft.VisualStudio.Shell.Immutable.14.0" Version="15.0.25405" />
<PackageReference Include="Microsoft.VisualStudio.Shell.Interop" Version="7.10.6072" />
<PackageReference Include="Microsoft.VisualStudio.Shell.Interop.8.0" Version="8.0.50728" />
<PackageReference Include="Microsoft.VisualStudio.Shell.Interop.9.0" Version="9.0.30730" />
<PackageReference Include="Microsoft.VisualStudio.Shell.Interop.10.0" Version="10.0.30320" />
<PackageReference Include="Microsoft.VisualStudio.Shell.Interop.11.0" Version="11.0.61031" />
<PackageReference Include="Microsoft.VisualStudio.Shell.Interop.12.0" Version="12.0.30111" />
<PackageReference Include="Microsoft.VisualStudio.Text.Data" Version="15.6.27740" />
<PackageReference Include="Microsoft.VisualStudio.Text.Logic" Version="15.6.27740" />
<PackageReference Include="Microsoft.VisualStudio.Text.UI" Version="15.6.27740" />
<PackageReference Include="Microsoft.VisualStudio.Text.UI.Wpf" Version="15.6.27740" />
<PackageReference Include="Microsoft.VisualStudio.TextManager.Interop" Version="7.10.6071" />
<PackageReference Include="Microsoft.VisualStudio.TextManager.Interop.8.0" Version="8.0.50728" />
<PackageReference Include="Microsoft.VisualStudio.Threading" Version="15.7.18" />
<PackageReference Include="Microsoft.VisualStudio.Utilities" Version="15.7.27703" />
<PackageReference Include="Microsoft.VisualStudio.Validation" Version="15.3.53" />
<PackageReference Include="Microsoft.VSSDK.BuildTools" Version="15.7.109" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="stdole, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
Expand Down Expand Up @@ -164,13 +167,17 @@
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Page Include="ImageSwitcher.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="SettingsPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Xaml.Extend\Meowtrix.WPF.Extend\Meowtrix.WPF.Extend.csproj">
<ProjectReference Include="..\Xaml.Extend\Meowtrix.WPF.Extend\Meowtrix.WPF.Extend.csproj">
<Project>{15cacac9-9e3c-4056-a26d-b4b9cd7fe596}</Project>
<Name>Meowtrix.WPF.Extend</Name>
<IncludeOutputGroupsInVSIX>BuiltProjectOutputGroup%3bBuiltProjectOutputGroupDependencies%3bGetCopyToOutputDirectoryItems%3bSatelliteDllsProjectOutputGroup</IncludeOutputGroupsInVSIX>
Expand Down
12 changes: 8 additions & 4 deletions MoeIDE/SettingsModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,25 @@ namespace Meowtrix.MoeIDE
public class SettingsModel
{
[Serializable]
public class ImageInfo
public class SettingPack
{
public string Filename { get; set; }
public bool IsLive { get; set; } = false;
public string Folderpath { get; set; }
public double Interval { get; set; } = 30000.0;
public double TransitionDuration { get; set; } = 2000.0;
public Stretch Stretch { get; set; } = Stretch.UniformToFill;
public HorizontalAlignment HorizontalAlignment { get; set; } = HorizontalAlignment.Center;
public VerticalAlignment VerticalAlignment { get; set; } = VerticalAlignment.Center;
public Color BackColor { get; set; } = Colors.Transparent;
public double Opacity { get; set; } = 1.0;
public double Blur { get; set; } = 0.0;
public ImageInfo Clone() => (ImageInfo)MemberwiseClone();
public SettingPack Clone() => (SettingPack)MemberwiseClone();
}
public ImageInfo MainBackground { get; set; } = new ImageInfo();
public SettingPack MainSetting { get; set; } = new SettingPack();
public SettingsModel Clone() => new SettingsModel
{
MainBackground = this.MainBackground.Clone()
MainSetting = this.MainSetting.Clone()
};
}
}
Loading