Skip to content

Commit

Permalink
Add Catalina dynamic wallpaper
Browse files Browse the repository at this point in the history
  • Loading branch information
t1m0thyj committed Jun 4, 2019
1 parent 5b1219d commit 5181ff1
Show file tree
Hide file tree
Showing 16 changed files with 145 additions and 59 deletions.
2 changes: 1 addition & 1 deletion src/DownloadDialog.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions src/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 12 additions & 6 deletions src/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,6 @@
<data name="Solar_Gradients_json" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\themes\Solar_Gradients.json;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="Mojave_Desert_thumbnail" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\themes\Mojave_Desert_thumbnail.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="Solar_Gradients_thumbnail" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\themes\Solar_Gradients_thumbnail.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="locale_cs_CZ" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\locale\cs_CZ.mo;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
Expand All @@ -157,4 +151,16 @@
<data name="locale_pl_PL" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\locale\pl_PL.mo;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="Catalina_json" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\themes\Catalina.json;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="Catalina_thumbnail" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\themes\Catalina_thumbnail.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="Mojave_Desert_thumbnail" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\themes\Mojave_Desert_thumbnail.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="Solar_Gradients_thumbnail" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\themes\Solar_Gradients_thumbnail.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>
23 changes: 12 additions & 11 deletions src/ThemeDialog.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 51 additions & 27 deletions src/ThemeDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public void ImportThemes(List<string> themePaths)
ImportDialog importDialog = new ImportDialog() { Owner = this };
importDialog.FormClosing += OnImportDialogClosing;
importDialog.Show();
this.Enabled = false;
importDialog.InitImport(themePaths);
}

Expand Down Expand Up @@ -85,7 +86,7 @@ private int GetMaxImageNumber()
return max;
}

private void LoadPreviewImage(int imageNumber)
private void LoadPreviewImage(Image image)
{
int width = pictureBox1.Size.Width;
int height = pictureBox1.Size.Height;
Expand All @@ -100,18 +101,22 @@ private void LoadPreviewImage(int imageNumber)
width = height * 16 / 9;
}

pictureBox1.Image = ThemeThumbLoader.ScaleImage(image, new Size(width, height));
}

private void LoadPreviewImage(int imageNumber)
{
if (selectedIndex == 0)
{
pictureBox1.Image = ThemeThumbLoader.ScaleImage(windowsWallpaper,
new Size(width, height));
LoadPreviewImage(Image.FromFile(windowsWallpaper));
}
else
{
ThemeConfig theme = ThemeManager.themeSettings[selectedIndex - 1];
int imageId = ThemeManager.GetThemeImageList(theme)[imageNumber - 1];
string imageFilename = theme.imageFilename.Replace("*", imageId.ToString());
pictureBox1.Image = ThemeThumbLoader.ScaleImage(Path.Combine("themes",
theme.themeId, imageFilename), new Size(width, height));
LoadPreviewImage(Image.FromFile(Path.Combine("themes", theme.themeId,
imageFilename)));
}

imageNumberLabel.Text = string.Format(_("Image {0} of {1}"), imageNumber,
Expand Down Expand Up @@ -184,13 +189,12 @@ private void LoadImportedThemes(List<ThemeConfig> themes, ImportDialog importDia

private void SetThemeDownloaded(bool themeDownloaded)
{
pictureBox1.Visible = themeDownloaded;
firstButton.Visible = themeDownloaded;
previousButton.Visible = themeDownloaded;
imageNumberLabel.Visible = themeDownloaded;
nextButton.Visible = themeDownloaded;
lastButton.Visible = themeDownloaded;
downloadButton.Visible = !themeDownloaded;
downloadLabel.Visible = !themeDownloaded;
}

private void UpdateSelectedItem()
Expand All @@ -215,6 +219,11 @@ private void UpdateSelectedItem()
imageNumber = ThemeManager.GetThemeImageList(theme).IndexOf(
AppContext.wpEngine.GetImageData(solarData, theme).Item1) + 1;
}
else
{
LoadPreviewImage((Image)Properties.Resources.ResourceManager.GetObject(
themeId + "_thumbnail"));
}
}

SetThemeDownloaded(themeDownloaded);
Expand All @@ -226,7 +235,7 @@ private void UpdateSelectedItem()
LoadPreviewImage(imageNumber);
}

applyButton.Enabled = themeDownloaded;
applyButton.Enabled = true;
}
else
{
Expand Down Expand Up @@ -293,6 +302,29 @@ private void ThemeDialog_Load(object sender, EventArgs e)
}));
}

private void ApplySelectedTheme()
{
if (selectedIndex > 0)
{
ThemeManager.currentTheme = ThemeManager.themeSettings[selectedIndex - 1];
}
else
{
ThemeManager.currentTheme = null;
}

JsonConfig.settings.themeName = ThemeManager.currentTheme?.themeId;

if (selectedIndex == 0)
{
WallpaperApi.SetWallpaper(windowsWallpaper);
}
else
{
AppContext.wpEngine.RunScheduler();
}
}

private void imageListView1_SelectionChanged(object sender, EventArgs e)
{
UpdateSelectedItem();
Expand All @@ -318,15 +350,6 @@ private void lastButton_Click(object sender, EventArgs e)
LoadPreviewImage(maxImageNumber);
}

private void downloadButton_Click(object sender, EventArgs e)
{
DownloadDialog downloadDialog = new DownloadDialog() { Owner = this };
downloadDialog.FormClosed += OnDownloadDialogClosed;
downloadDialog.Show();
this.Enabled = false;
downloadDialog.InitDownload(ThemeManager.themeSettings[selectedIndex - 1]);
}

private void importButton_Click(object sender, EventArgs e)
{
DialogResult result = openFileDialog1.ShowDialog();
Expand All @@ -350,25 +373,25 @@ private void themeLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEvent
private void applyButton_Click(object sender, EventArgs e)
{
applyButton.Enabled = false;
bool themeDownloaded = true;

if (selectedIndex > 0)
{
ThemeManager.currentTheme = ThemeManager.themeSettings[selectedIndex - 1];
}
else
{
ThemeManager.currentTheme = null;
themeDownloaded = ThemeManager.IsThemeDownloaded(
ThemeManager.themeSettings[selectedIndex - 1]);
}

JsonConfig.settings.themeName = ThemeManager.currentTheme?.themeId;

if (selectedIndex == 0)
if (!themeDownloaded)
{
WallpaperApi.SetWallpaper(windowsWallpaper);
DownloadDialog downloadDialog = new DownloadDialog() { Owner = this };
downloadDialog.FormClosed += OnDownloadDialogClosed;
downloadDialog.Show();
this.Enabled = false;
downloadDialog.InitDownload(ThemeManager.themeSettings[selectedIndex - 1]);
}
else
{
AppContext.wpEngine.RunScheduler();
ApplySelectedTheme();
}

applyButton.Enabled = true;
Expand Down Expand Up @@ -416,6 +439,7 @@ private void OnDownloadDialogClosed(object sender, FormClosedEventArgs e)
{
if (ThemeManager.IsThemeDownloaded(ThemeManager.themeSettings[selectedIndex - 1]))
{
ApplySelectedTheme();
UpdateSelectedItem();
}

Expand Down
17 changes: 14 additions & 3 deletions src/ThemeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ namespace WinDynamicDesktop
class ThemeManager
{
private static readonly Func<string, string> _ = Localization.GetTranslation;
public static string[] defaultThemes = new string[] { "Mojave_Desert", "Solar_Gradients" };
public static string[] defaultThemes = new string[] { "Catalina", "Mojave_Desert",
"Solar_Gradients" };
public static List<ThemeConfig> themeSettings = new List<ThemeConfig>();

public static bool downloadMode = false;
Expand Down Expand Up @@ -80,9 +81,19 @@ public static bool IsThemeDownloaded(ThemeConfig theme)
public static List<int> GetThemeImageList(ThemeConfig theme)
{
List<int> imageList = new List<int>();
imageList.AddRange(theme.sunriseImageList);

if (!theme.sunriseImageList.SequenceEqual(theme.dayImageList))
{
imageList.AddRange(theme.sunriseImageList);
}

imageList.AddRange(theme.dayImageList);
imageList.AddRange(theme.sunsetImageList);

if (!theme.sunsetImageList.SequenceEqual(theme.dayImageList))
{
imageList.AddRange(theme.sunsetImageList);
}

imageList.AddRange(theme.nightImageList);
return imageList;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ThemeThumbLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static Size GetThumbnailSize(System.Windows.Forms.Control control)
return new Size(scaledWidth, scaledWidth * 9 / 16);
}

private static Image ScaleImage(Image tempImage, Size size)
public static Image ScaleImage(Image tempImage, Size size)
{
if (tempImage.Size == size)
{
Expand Down
20 changes: 12 additions & 8 deletions src/WinDynamicDesktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@
<Compile Include="AppContext.cs" />
<Compile Include="DebugLogger.cs" />
<Compile Include="DesktopHelper.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="ThemeResult.cs" />
<Compile Include="LocationDialog.cs">
<SubType>Form</SubType>
Expand Down Expand Up @@ -175,14 +180,9 @@
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<EmbeddedResource Include="ThemeDialog.resx">
<DependentUpon>ThemeDialog.cs</DependentUpon>
</EmbeddedResource>
Expand Down Expand Up @@ -210,15 +210,19 @@
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<None Include="themes\Catalina.json" />
<None Include="themes\Mojave_Desert.json" />
<None Include="themes\Solar_Gradients.json" />
<None Include="WinDynamicDesktop.ico" />
</ItemGroup>
<ItemGroup>
<None Include="themes\Mojave_Desert_thumbnail.png" />
<None Include="themes\Catalina_thumbnail.jpg" />
</ItemGroup>
<ItemGroup>
<None Include="themes\Mojave_Desert_thumbnail.jpg" />
</ItemGroup>
<ItemGroup>
<None Include="themes\Solar_Gradients_thumbnail.png" />
<None Include="themes\Solar_Gradients_thumbnail.jpg" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="packages\Fody.5.0.0\build\Fody.targets" Condition="Exists('packages\Fody.5.0.0\build\Fody.targets')" />
Expand Down
Loading

0 comments on commit 5181ff1

Please sign in to comment.