Skip to content

Commit

Permalink
Support tiff files for icon.
Browse files Browse the repository at this point in the history
  • Loading branch information
ricaun committed Nov 11, 2024
1 parent 7306483 commit e3c49bc
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 4 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ 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
### Features
- Support `tiff` files for icon.
### Updated
- Update `GetBitmapFrame` to round `width` that is changed by `dpi`.
### Example
- Add `Cube-Grey-Light.tiff` and `Cube-Grey-Dark.tiff` in `AppTheme`.

## [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 +368,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-alpha</Version>
</PropertyGroup>
</Project>
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
4 changes: 4 additions & 0 deletions ricaun.Revit.UI.Example/ricaun.Revit.UI.Example.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -96,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 @@ -126,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
7 changes: 4 additions & 3 deletions ricaun.Revit.UI/BitmapExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ TImageSource ScaleDownIfWidthIsGreater(TImageSource imageSource, int width)
if (width <= 0)
return imageSource;

if (imageSource.Width > width)
imageSource = imageSource.Scale(width / imageSource.Width) as TImageSource;
var imageRoundWidth = Math.Round(imageSource.Width);
if (imageRoundWidth > width)
imageSource = imageSource.Scale(width / imageRoundWidth) as TImageSource;

return imageSource;
}
Expand All @@ -110,7 +111,7 @@ BitmapFrame GetBitmapFrameByWidth(BitmapFrame bitmapFrame, int width)
var frames = bitmapFrame.Decoder.Frames;
var frame = frames
.OrderBy(e => e.Width)
.FirstOrDefault(e => e.Width >= width);
.FirstOrDefault(e => Math.Round(e.Width) >= width);

return frame;
}
Expand Down

0 comments on commit e3c49bc

Please sign in to comment.