Skip to content

Commit

Permalink
Merge pull request #37 from ricaun-io/develop
Browse files Browse the repository at this point in the history
Release 0.7.1
  • Loading branch information
ricaun authored Nov 19, 2024
2 parents 7371de1 + 2a1b12c commit 3e9dc27
Show file tree
Hide file tree
Showing 12 changed files with 247 additions and 33 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [0.7.1] / 2024-11-11 - 2024-11-19
### Features
- Support `tiff` files for icon.
### Updated
- Update `GetBitmapFrame` to round `width` that is changed by `dpi`.
- Add `GetBitmapFrameByWidthAndDpi` to get optimal frame by `dpi` and `width`.
- Add `GetSystemDpi` to get the system `dpi` on the fly.
- Add `SystemDpi` to store the system `dpi` value.
- Update `GetBitmapFrameByWidthAndDpi` to round `dpi` frame value.
- Update `Width` to `Math.Round` to improve order by `Width`.
- Update `GetBitmapFrameByWidthAndDpi` to public.
- Update `GetBitmapFrameByWidthAndDpi` to return last `Width`.
- Update `UriToBitmapFrame` to use `GetBitmapFrameByWidthAndDpi` with `int.MaxValue`.
### Example
- Add `Cube-Grey-Light.tiff` and `Cube-Grey-Dark.tiff` in `AppTheme`.
### Tests
- Add `ResourceTiffTests` with `Cube.tiff` with multiple dpi and scales.

## [0.7.0] / 2024-07-06 - 2024-07-25
### Features
- Auto set image based on the theme of the Ribbon using `light` and `dark` image pattern.
Expand Down Expand Up @@ -360,6 +378,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- First Release

[vNext]: ../../compare/1.0.0...HEAD
[0.7.1]: ../../compare/0.7.0...0.7.1
[0.7.0]: ../../compare/0.6.2...0.7.0
[0.6.2]: ../../compare/0.6.1...0.6.2
[0.6.1]: ../../compare/0.6.0...0.6.1
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project>
<PropertyGroup>
<Version>0.7.0</Version>
<Version>0.7.1</Version>
</PropertyGroup>
</Project>
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,6 @@ Autodesk.Windows.RibbonPanel awRibbonPanel;
awRibbonPanel.SetDialogLauncher(ribbonCommandItem);
```

### Ribbon Description Extension
... Todo

## Release

* [Latest release](https://github.com/ricaun-io/ricaun.Revit.UI/releases/latest)
Expand Down
Binary file not shown.
Binary file not shown.
31 changes: 31 additions & 0 deletions ricaun.Revit.UI.Example/Revit/AppTheme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,37 @@ public Result OnStartup(UIControlledApplication application)

ribbonPanel.AddSeparator();


{
var buttonTiff = ribbonPanel.CreatePushButton<CommandTheme>("Grey")
.SetLargeImage("Resources/Cube-Grey-Light.tiff");
//if (buttonTiff.LargeImage is System.Windows.Media.Imaging.BitmapSource largeImage)
//{
// System.Console.WriteLine($"{largeImage.GetType().Name} | {largeImage.Width:0}x{largeImage.Height:0} ({largeImage.PixelWidth}x{largeImage.PixelHeight}) {largeImage.DpiX:0}:{largeImage.DpiY:0}");
//}
//if (buttonTiff.Image is System.Windows.Media.Imaging.BitmapSource smallImage)
//{
// System.Console.WriteLine($"{smallImage.GetType().Name} | {smallImage.Width:0}x{smallImage.Height:0} ({smallImage.PixelWidth}x{smallImage.PixelHeight}) {smallImage.DpiX:0}:{smallImage.DpiY:0}");
//}
}

ribbonPanel.RowStackedItems(
ribbonPanel.CreatePushButton<CommandTheme>("Grey")
.SetLargeImage("Resources/Cube-Grey-Light.tiff"),
ribbonPanel.CreatePushButton<CommandTheme>("Grey")
.SetLargeImage("Resources/Cube-Grey-Light.tiff"),
ribbonPanel.CreatePushButton<CommandTheme>("Grey")
.SetLargeImage("Resources/Cube-Grey-Light.tiff")
);
ribbonPanel.RowLargeStackedItems(
ribbonPanel.CreatePushButton<CommandTheme>("Grey")
.SetLargeImage("Resources/Cube-Grey-Light.tiff"),
ribbonPanel.CreatePushButton<CommandTheme>("Grey")
.SetLargeImage("Resources/Cube-Grey-Light.tiff")
);

ribbonPanel.AddSeparator();

ribbonPanel.FlowStackedItems(
ribbonPanel.CreatePushButton<CommandTheme>("1").SetLargeImage(LIGHT_RED),
ribbonPanel.CreatePushButton<CommandTheme>("2").SetLargeImage(DARK_RED),
Expand Down
18 changes: 16 additions & 2 deletions ricaun.Revit.UI.Example/ricaun.Revit.UI.Example.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,20 @@

<!-- RevitVersion -->
<PropertyGroup>
<TargetFrameworks>net48;net8.0-windows</TargetFrameworks>
<TargetFrameworks>net46;net47;net48;net8.0-windows</TargetFrameworks>
</PropertyGroup>
<Choose>
<When Condition="$(TargetFramework.StartsWith('net4'))">
<When Condition="$(TargetFramework.StartsWith('net46'))">
<PropertyGroup>
<RevitVersion>2017</RevitVersion>
</PropertyGroup>
</When>
<When Condition="$(TargetFramework.StartsWith('net47'))">
<PropertyGroup>
<RevitVersion>2019</RevitVersion>
</PropertyGroup>
</When>
<When Condition="$(TargetFramework.StartsWith('net48'))">
<PropertyGroup>
<RevitVersion>2021</RevitVersion>
</PropertyGroup>
Expand Down Expand Up @@ -86,6 +96,8 @@
<ItemGroup>
<None Remove="Resources\Box-Grey-Dark.ico" />
<None Remove="Resources\Box-Grey-Light.ico" />
<None Remove="Resources\Cube-Grey-Dark.tiff" />
<None Remove="Resources\Cube-Grey-Light.tiff" />
<None Remove="Resources\icon.png" />
<None Remove="Resources\Revit.ico" />
</ItemGroup>
Expand Down Expand Up @@ -116,6 +128,8 @@
<ItemGroup>
<Resource Include="Resources\Box-Grey-Dark.ico" />
<Resource Include="Resources\Box-Grey-Light.ico" />
<Resource Include="Resources\Cube-Grey-Dark.tiff" />
<Resource Include="Resources\Cube-Grey-Light.tiff" />
<Resource Include="Resources\icon.png" />
<Resource Include="Resources\Revit.ico" />
</ItemGroup>
Expand Down
Binary file added ricaun.Revit.UI.Tests/Resources/Images/Cube.tiff
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace ricaun.Revit.UI.Tests.Resources
{
public class ResourcesFramesTests
public class ResourceIcoFramesTests
{
const string ResourceNameIcoFrames = "Resources/Images/Revit21Frames.ico";

Expand Down
102 changes: 102 additions & 0 deletions ricaun.Revit.UI.Tests/Resources/ResourceTiffTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
using NUnit.Framework;
using System;

namespace ricaun.Revit.UI.Tests.Resources
{
public class ResourceTiffTests
{
/// <summary>
/// Tiff file with multiple scales, 1.0x, 1.5x, 2.0x, 3.0x, 4.0x for 16x16 and 32x32, 10 frames.
/// </summary>
/// <remarks>
/// Tiff file based in the https://github.com/ricaun-io/Autodesk.Icon.Example?tab=readme-ov-file#autodesk-high-resolution-icons
/// </remarks>
const string ResourceNameTiff = "Resources/Images/Cube.tiff";

System.Windows.Media.Imaging.BitmapFrame BitmapFrame;
[OneTimeSetUp]
public void Setup()
{
BitmapFrame = ResourceNameTiff.GetBitmapSource() as System.Windows.Media.Imaging.BitmapFrame;
}

[Test]
public void GetBitmapSource_NotNull()
{
Console.WriteLine(ResourceNameTiff.GetBitmapSource());
Assert.IsNotNull(ResourceNameTiff.GetBitmapSource());
Assert.IsNotNull(("/" + ResourceNameTiff).GetBitmapSource());
}

[TestCase(32)]
public void GetBitmapSource_Default_Width(int width)
{
var source = ResourceNameTiff.GetBitmapSource();
Assert.AreEqual(width, Math.Round(source.Width));
var systemDpi = BitmapExtension.SystemDpi;
if (systemDpi != Math.Round(source.DpiX))
Assert.Ignore($"SystemDpi:{systemDpi} != {Math.Round(source.DpiX)}");
}

[TestCase(10)]
public void BitmapFrame_CountFrames(int count)
{
Assert.IsNotNull(BitmapFrame);
var decoder = BitmapFrame.Decoder;
Assert.AreEqual(count, decoder.Frames.Count);
}

[TestCase(16, 96)] // 1.0
[TestCase(16, 144)] // 1.5
[TestCase(16, 192)] // 2.0
[TestCase(16, 288)] // 3.0
[TestCase(16, 384)] // 4.0
[TestCase(32, 96)] // 1.0
[TestCase(32, 144)] // 1.5
[TestCase(32, 192)] // 2.0
[TestCase(32, 288)] // 3.0
[TestCase(32, 384)] // 4.0
public void BitmapFrame_ByWidthAndDpi(int width, int dpi)
{
Assert.IsNotNull(BitmapFrame);
var decoder = BitmapFrame.Decoder;
var frame = decoder.GetBitmapFrameByWidthAndDpi(width, dpi) as System.Windows.Media.Imaging.BitmapFrame;
Assert.IsNotNull(frame);
Assert.AreEqual(width, Math.Round(frame.Width));
Assert.AreEqual(dpi, Math.Round(frame.DpiX));
}

[TestCase(16, 168, 192)] // 1.75
[TestCase(32, 168, 192)] // 1.75
[TestCase(16, 240, 288)] // 2.5
[TestCase(32, 240, 288)] // 2.5
[TestCase(16, 336, 384)] // 3.5
[TestCase(32, 336, 384)] // 3.5
[TestCase(16, 480, 384)] // 5.0
[TestCase(32, 480, 384)] // 5.0
public void BitmapFrame_ByWidthAndDpi_DpiExpected(int width, int dpi, int dpiExpected)
{
Assert.IsNotNull(BitmapFrame);
var decoder = BitmapFrame.Decoder;
var frame = decoder.GetBitmapFrameByWidthAndDpi(width, dpi) as System.Windows.Media.Imaging.BitmapFrame;
Assert.IsNotNull(frame);
Assert.AreEqual(width, Math.Round(frame.Width));
Assert.AreEqual(dpiExpected, Math.Round(frame.DpiX));
}

[TestCase(64, 96, 32)] // 1.0
[TestCase(64, 144, 32)] // 1.5
[TestCase(64, 192, 32)] // 2.0
[TestCase(64, 288, 32)] // 3.0
[TestCase(64, 384, 32)] // 4.0
public void BitmapFrame_ByWidthAndDpi_WidthExpected(int width, int dpi, int widthExpected)
{
Assert.IsNotNull(BitmapFrame);
var decoder = BitmapFrame.Decoder;
var frame = decoder.GetBitmapFrameByWidthAndDpi(width, dpi) as System.Windows.Media.Imaging.BitmapFrame;
Assert.IsNotNull(frame);
Assert.AreEqual(widthExpected, Math.Round(frame.Width));
Assert.AreEqual(dpi, Math.Round(frame.DpiX));
}
}
}
9 changes: 3 additions & 6 deletions ricaun.Revit.UI.Tests/ricaun.Revit.UI.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,10 @@
</PropertyGroup>
</Otherwise>
</Choose>
<ItemGroup>
<None Remove="Resources\Images\Revit21Frames.ico" />
<None Remove="Resources\Images\Revit32.png" />
</ItemGroup>


<ItemGroup>
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="ricaun.RevitTest.TestAdapter" Version="*" />
<PackageReference Include="ricaun.RevitTest.TestAdapter" Version="*-*" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" Condition="!$(TargetFramework.StartsWith('net4'))" />
</ItemGroup>

Expand Down Expand Up @@ -69,6 +65,7 @@
</ItemGroup>

<ItemGroup>
<Resource Include="Resources\Images\Cube.tiff" />
<Resource Include="Resources\Images\Revit.ico" />
<Resource Include="Resources\Images\Revit21Frames.ico" />
<Resource Include="Resources\Images\Revit32.png" />
Expand Down
Loading

0 comments on commit 3e9dc27

Please sign in to comment.