Skip to content

Commit df48671

Browse files
committed
added the function of resizing pictures automatically
1 parent 734758c commit df48671

File tree

8 files changed

+80
-43
lines changed

8 files changed

+80
-43
lines changed

ColorfulIDE/ColorfulIDE.cs

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,15 @@ protected virtual void Dispose(bool disposing)
5858
private readonly Timer _opacityTimer;
5959
private int _opacityIndex;
6060
private int _flag;
61+
private double _ratio;
6162

6263
private readonly IServiceProvider _serviceProvider;
6364

6465
private int _current;
6566
private string[] _imagePaths;
6667
private int[] _sequence;
6768

68-
private void RandomSequence()
69+
private void RandomSequence()
6970
{
7071
var list = new List<int>();
7172
var random = new Random();
@@ -155,15 +156,15 @@ public ColorfulIde(IWpfTextView view, IServiceProvider sp)
155156
{
156157
_opacityTimer.Stop();
157158
_flag = 1;
158-
Application.Current.Dispatcher.BeginInvoke(new Action(() => { ChangeImage(); this.OnSizeChange(); }));
159+
Application.Current.Dispatcher.BeginInvoke(new Action(() => { ChangeImage(); OnSizeChange(); }));
159160
_opacityIndex = 0;
160161
_opacityTimer.Start();
161162
}
162163
else if (_opacityIndex == 10)
163164
{
164165
_opacityTimer.Stop();
165166
_flag = 0;
166-
Application.Current.Dispatcher.BeginInvoke(new Action(this.OnSizeChange));
167+
Application.Current.Dispatcher.BeginInvoke(new Action(OnSizeChange));
167168
_opacityIndex = 10;
168169
}
169170
}
@@ -173,8 +174,8 @@ public ColorfulIde(IWpfTextView view, IServiceProvider sp)
173174
}
174175
};
175176

176-
_view.ViewportHeightChanged += delegate { this.OnSizeChange(); };
177-
_view.ViewportWidthChanged += delegate { this.OnSizeChange(); };
177+
_view.ViewportHeightChanged += delegate { OnSizeChange(); };
178+
_view.ViewportWidthChanged += delegate { OnSizeChange(); };
178179
}
179180
catch (Exception)
180181
{
@@ -229,6 +230,7 @@ private void ChangeImage()
229230

230231
_image.Width = _bitmap.PixelWidth;
231232
_image.Height = _bitmap.PixelHeight;
233+
232234
_image.IsHitTestVisible = false;
233235

234236
_current = (_current + 1) % _imagePaths.Length;
@@ -241,7 +243,7 @@ private Setting GetConfigFromVisualStudioSettings()
241243
var config = new Setting();
242244

243245
var dte2 = (DTE2)_serviceProvider.GetService(typeof(DTE));
244-
246+
245247
var props = dte2.Properties["Colorful-IDE", "General"];
246248

247249
config.IsDirectory = props.Item("IsDirectory").Value;
@@ -267,16 +269,18 @@ public void OnSizeChange()
267269
{
268270
_adornmentLayer.RemoveAllAdornments();
269271

272+
ResizeImage();
273+
270274
switch (_config.PositionHorizon)
271275
{
272276
case PositionH.Left:
273277
Canvas.SetLeft(_image, _view.ViewportLeft);
274278
break;
275279
case PositionH.Right:
276-
Canvas.SetLeft(_image, _view.ViewportRight - _bitmap.PixelWidth);
280+
Canvas.SetLeft(_image, _view.ViewportRight - _bitmap.PixelWidth * _ratio);
277281
break;
278282
case PositionH.Center:
279-
Canvas.SetLeft(_image, _view.ViewportRight - _view.ViewportWidth + ((_view.ViewportWidth / 2) - ((double)_bitmap.PixelWidth / 2)));
283+
Canvas.SetLeft(_image, _view.ViewportRight - _view.ViewportWidth + (_view.ViewportWidth / 2 - _bitmap.PixelWidth * _ratio / 2));
280284
break;
281285
default:
282286
throw new ArgumentOutOfRangeException();
@@ -287,10 +291,10 @@ public void OnSizeChange()
287291
Canvas.SetTop(_image, _view.ViewportTop);
288292
break;
289293
case PositionV.Bottom:
290-
Canvas.SetTop(_image, _view.ViewportBottom - _bitmap.PixelHeight);
294+
Canvas.SetTop(_image, _view.ViewportBottom - _bitmap.PixelHeight * _ratio);
291295
break;
292296
case PositionV.Center:
293-
Canvas.SetTop(_image, _view.ViewportBottom - _view.ViewportHeight + ((_view.ViewportHeight / 2) - ((double)_bitmap.PixelHeight / 2)));
297+
Canvas.SetTop(_image, _view.ViewportBottom - _view.ViewportHeight + (_view.ViewportHeight / 2 - _bitmap.PixelHeight * _ratio / 2.0));
294298
break;
295299
default:
296300
throw new ArgumentOutOfRangeException();
@@ -302,5 +306,23 @@ public void OnSizeChange()
302306
// ignored
303307
}
304308
}
309+
310+
private void ResizeImage()
311+
{
312+
_ratio = 1.0;
313+
314+
if (_bitmap.PixelWidth > _view.ViewportWidth)
315+
{
316+
_ratio = _view.ViewportWidth / _bitmap.PixelWidth;
317+
}
318+
319+
if (_bitmap.PixelHeight > _view.ViewportHeight)
320+
{
321+
_ratio = _view.ViewportHeight / _bitmap.PixelHeight < _ratio ? _view.ViewportHeight / _bitmap.PixelHeight : _ratio;
322+
}
323+
324+
_image.Height = _bitmap.PixelHeight * _ratio;
325+
_image.Width = _bitmap.PixelWidth * _ratio;
326+
}
305327
}
306328
}

ColorfulIDE/ColorfulIDE.csproj

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,21 @@
99
<UpgradeBackupLocation>
1010
</UpgradeBackupLocation>
1111
<OldToolsVersion>12.0</OldToolsVersion>
12+
<PublishUrl>publish\</PublishUrl>
13+
<Install>true</Install>
14+
<InstallFrom>Disk</InstallFrom>
15+
<UpdateEnabled>false</UpdateEnabled>
16+
<UpdateMode>Foreground</UpdateMode>
17+
<UpdateInterval>7</UpdateInterval>
18+
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
19+
<UpdatePeriodically>false</UpdatePeriodically>
20+
<UpdateRequired>false</UpdateRequired>
21+
<MapFileExtensions>true</MapFileExtensions>
22+
<ApplicationRevision>0</ApplicationRevision>
23+
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
24+
<IsWebBootstrapper>false</IsWebBootstrapper>
25+
<UseApplicationTrust>false</UseApplicationTrust>
26+
<BootstrapperEnabled>true</BootstrapperEnabled>
1227
</PropertyGroup>
1328
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
1429
<PropertyGroup>
@@ -46,11 +61,7 @@
4661
</PropertyGroup>
4762
<ItemGroup>
4863
<Reference Include="Microsoft.CSharp" />
49-
<Reference Include="Microsoft.VisualStudio.CoreUtility, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
50-
<Reference Include="Microsoft.VisualStudio.Data, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
51-
<Reference Include="Microsoft.VisualStudio.Data.Core, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
52-
<Reference Include="Microsoft.VisualStudio.Data.Framework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
53-
<Reference Include="Microsoft.VisualStudio.Editor, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
64+
<Reference Include="Microsoft.VisualStudio.CoreUtility, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
5465
<Reference Include="Microsoft.VisualStudio.OLE.Interop, Version=7.1.40304.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
5566
<Reference Include="Microsoft.VisualStudio.Shell.Interop" />
5667
<Reference Include="Microsoft.VisualStudio.Shell.Interop.8.0" />
@@ -62,10 +73,10 @@
6273
<Reference Include="Microsoft.VisualStudio.Shell.Interop.12.0">
6374
<EmbedInteropTypes>true</EmbedInteropTypes>
6475
</Reference>
65-
<Reference Include="Microsoft.VisualStudio.Text.Data, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
66-
<Reference Include="Microsoft.VisualStudio.Text.Logic, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
67-
<Reference Include="Microsoft.VisualStudio.Text.UI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
68-
<Reference Include="Microsoft.VisualStudio.Text.UI.Wpf, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
76+
<Reference Include="Microsoft.VisualStudio.Text.Data, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
77+
<Reference Include="Microsoft.VisualStudio.Text.Logic, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
78+
<Reference Include="Microsoft.VisualStudio.Text.UI, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
79+
<Reference Include="Microsoft.VisualStudio.Text.UI.Wpf, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
6980
<Reference Include="Microsoft.VisualStudio.TextManager.Interop" />
7081
<Reference Include="Microsoft.VisualStudio.Shell.12.0" />
7182
<Reference Include="Microsoft.VisualStudio.Shell.Immutable.10.0" />
@@ -265,7 +276,18 @@
265276
<IncludeInVSIX>true</IncludeInVSIX>
266277
</Content>
267278
</ItemGroup>
268-
<ItemGroup />
279+
<ItemGroup>
280+
<BootstrapperPackage Include=".NETFramework,Version=v4.5">
281+
<Visible>False</Visible>
282+
<ProductName>Microsoft .NET Framework 4.5 %28x86 和 x64%29</ProductName>
283+
<Install>true</Install>
284+
</BootstrapperPackage>
285+
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
286+
<Visible>False</Visible>
287+
<ProductName>.NET Framework 3.5 SP1</ProductName>
288+
<Install>false</Install>
289+
</BootstrapperPackage>
290+
</ItemGroup>
269291
<PropertyGroup>
270292
<UseCodebase>true</UseCodebase>
271293
</PropertyGroup>

ColorfulIDE/ColorfulIDEFactory.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ internal sealed class ColorfulIdeAdornmentFactory : IWpfTextViewCreationListener
3535
/// Instantiates a MyIDE manager when a textView is created.
3636
/// </summary>
3737
/// <param name="textView">The <see cref="IWpfTextView"/> upon which the adornment should be placed</param>
38-
public void TextViewCreated(IWpfTextView textView) => new ColorfulIde(textView, ServiceProvider);
38+
public void TextViewCreated(IWpfTextView textView)
39+
{
40+
new ColorfulIde(textView, ServiceProvider);
41+
}
3942
}
4043

4144
#endregion //Adornment Factory

ColorfulIDE/ColorfulIDEPackage.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Diagnostics;
22
using System.Globalization;
33
using System.Runtime.InteropServices;
4+
using HiTeam.ColorfulIDE.Options;
45
using Microsoft.VisualStudio.Shell;
56

67
namespace HiTeam.ColorfulIDE
@@ -22,8 +23,8 @@ namespace HiTeam.ColorfulIDE
2223
// This attribute is used to register the information needed to show this package
2324
// in the Help/About dialog of Visual Studio.
2425
[InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)]
25-
[ProvideOptionPage(typeof(Options.ColorfulIdeOptionPageGrid), "Colorful-IDE", "General", 110, 214, true)]
26-
[Guid(GuidList.guidColorfulIDEPkgString)]
26+
[ProvideOptionPage(typeof(ColorfulIdeOptionPageGrid), "Colorful-IDE", "General", 110, 214, true)]
27+
[Guid(GuidList.GuidColorfulIdePkgString)]
2728
public sealed class ColorfulIdePackage : Package
2829
{
2930
/// <summary>
@@ -35,7 +36,7 @@ public sealed class ColorfulIdePackage : Package
3536
/// </summary>
3637
public ColorfulIdePackage()
3738
{
38-
Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering constructor for: {0}", this.ToString()));
39+
Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering constructor for: {0}", ToString()));
3940
}
4041

4142

@@ -50,7 +51,7 @@ public ColorfulIdePackage()
5051
/// </summary>
5152
protected override void Initialize()
5253
{
53-
Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString()));
54+
Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", ToString()));
5455
base.Initialize();
5556

5657
}

ColorfulIDE/Guids.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ namespace HiTeam.ColorfulIDE
66
{
77
static class GuidList
88
{
9-
public const string guidColorfulIDEPkgString = "6f012ab1-a7eb-48ec-a09a-344442bf17e2";
10-
public const string guidColorfulIDECmdSetString = "a436d208-80da-4c94-b22e-90f6d344035b";
9+
public const string GuidColorfulIdePkgString = "6f012ab1-a7eb-48ec-a09a-344442bf17e2";
10+
public const string GuidColorfulIdeCmdSetString = "a436d208-80da-4c94-b22e-90f6d344035b";
1111

12-
public static readonly Guid guidColorfulIDECmdSet = new Guid(guidColorfulIDECmdSetString);
12+
public static readonly Guid GuidColorfulIdeCmdSet = new Guid(GuidColorfulIdeCmdSetString);
1313
};
1414
}

ColorfulIDE/Options/LocalizedDescription.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.ComponentModel;
4-
using System.Linq;
5-
using System.Text;
6-
using System.Threading.Tasks;
1+
using System.ComponentModel;
72

83
namespace HiTeam.ColorfulIDE.Options
94
{

ColorfulIDE/Options/LocalizedDisplayName.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.ComponentModel;
4-
using System.Linq;
5-
using System.Text;
6-
using System.Threading.Tasks;
1+
using System.ComponentModel;
72

83
namespace HiTeam.ColorfulIDE.Options
94
{

ColorfulIDE/source.extension.vsixmanifest

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
33
<Metadata>
4-
<Identity Id="af26cdc1-8385-4daa-a8de-68a7f339ed14" Version="2.9" Language="en-US" Publisher="Hi Team" />
4+
<Identity Id="af26cdc1-8385-4daa-a8de-68a7f339ed14" Version="3.0" Language="en-US" Publisher="Hi Team" />
55
<DisplayName>Colorful-IDE</DisplayName>
66
<Description xml:space="preserve">Colorful-IDE is a visual studio add-in that allows user to change the background image. The images may change at a constant interval.</Description>
77
<Icon>vsixicon.png</Icon>
@@ -15,8 +15,7 @@
1515
</Installation>
1616
<Dependencies>
1717
<Dependency Id="Microsoft.Framework.NDP" DisplayName="Microsoft .NET Framework" d:Source="Manual" Version="[4.5,)" />
18-
<Dependency d:Source="Installed" Id="Microsoft.VisualStudio.MPF.12.0" DisplayName="Visual Studio MPF 12.0" Version="[12.0,13.0)" />
19-
<Dependency d:Source="Installed" Id="Microsoft.VisualStudio.MPF.11.0" DisplayName="Visual Studio MPF 11.0" Version="[11.0,12.0)" />
18+
<Dependency d:Source="Installed" Id="Microsoft.VisualStudio.MPF" DisplayName="Visual Studio MPF" Version="[11.0,16.0)" />
2019
</Dependencies>
2120
<Assets>
2221
<Asset Type="Microsoft.VisualStudio.VsPackage" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%;PkgdefProjectOutputGroup|" />

0 commit comments

Comments
 (0)