-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
RibbonThemeBitmapUtils
to change theme for BitmapSource
- Loading branch information
Showing
11 changed files
with
148 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<Project> | ||
<PropertyGroup> | ||
<Version>0.6.3-beta.1</Version> | ||
<Version>0.6.3-beta.2</Version> | ||
</PropertyGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using Autodesk.Revit.Attributes; | ||
using Autodesk.Revit.DB; | ||
using Autodesk.Revit.UI; | ||
using ricaun.Revit.UI.Utils; | ||
|
||
namespace ricaun.Revit.UI.Example.Revit | ||
{ | ||
[AppLoader] | ||
public class AppTheme : IExternalApplication | ||
{ | ||
const string LIGHT = "https://github.com/ricaun-io/Autodesk.Icon.Example/releases/download/1.0.1-alpha/Box-Blue-Light.ico"; | ||
const string DARK = "https://github.com/ricaun-io/Autodesk.Icon.Example/releases/download/1.0.1-alpha/Box-Blue-Dark.ico"; | ||
|
||
private RibbonPanel ribbonPanel; | ||
public Result OnStartup(UIControlledApplication application) | ||
{ | ||
ribbonPanel = application.CreatePanel("Theme"); | ||
|
||
ribbonPanel.CreatePushButton<CommandTheme>("Light") | ||
.SetLargeImage(LIGHT); | ||
ribbonPanel.CreatePushButton<CommandTheme>("Dark") | ||
.SetLargeImage(DARK); | ||
string stringNull = null; | ||
ribbonPanel.CreatePushButton<CommandTheme>("Null") | ||
.SetLargeImage(LIGHT) | ||
.SetLargeImage(stringNull); | ||
|
||
ribbonPanel.FlowStackedItems( | ||
ribbonPanel.CreatePushButton<CommandTheme>("1").SetLargeImage(LIGHT), | ||
ribbonPanel.CreatePushButton<CommandTheme>("2").SetLargeImage(DARK), | ||
ribbonPanel.CreatePushButton<CommandTheme>("3").SetLargeImage(LIGHT) | ||
); | ||
|
||
ribbonPanel.AddSeparator(); | ||
|
||
var pushButton = ribbonPanel.CreatePushButton<CommandTheme>("Theme") | ||
.SetLargeImage(LIGHT); | ||
|
||
var textBox = ribbonPanel.CreateTextBox() | ||
.SetPromptText("TextBox") | ||
.SetLargeImage(LIGHT); | ||
|
||
var comboBox = ribbonPanel.CreateComboBox() | ||
.SetLargeImage(LIGHT); | ||
comboBox.CreateComboBoxMember("ComboBox") | ||
.SetLargeImage(LIGHT); | ||
|
||
ribbonPanel.RowStackedItems(pushButton, textBox, comboBox); | ||
|
||
return Result.Succeeded; | ||
} | ||
|
||
public Result OnShutdown(UIControlledApplication application) | ||
{ | ||
ribbonPanel?.Remove(); | ||
return Result.Succeeded; | ||
} | ||
|
||
[Transaction(TransactionMode.Manual)] | ||
public class CommandTheme : IExternalCommand, IExternalCommandAvailability | ||
{ | ||
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elementSet) | ||
{ | ||
UIApplication uiapp = commandData.Application; | ||
|
||
UIThemeManager.CurrentTheme = UIThemeManager.CurrentTheme == UITheme.Light ? UITheme.Dark : UITheme.Light; | ||
return Result.Succeeded; | ||
} | ||
|
||
public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories) | ||
{ | ||
return true; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System.Windows.Media; | ||
using System.Windows.Media.Imaging; | ||
|
||
namespace ricaun.Revit.UI.Utils | ||
{ | ||
internal static class RibbonThemeBitmapUtils | ||
{ | ||
private const string NAME_DARK = "dark"; | ||
private const string NAME_LIGHT = "light"; | ||
|
||
internal static TImageSource GetThemeImageSource<TImageSource>(this TImageSource imageSource, bool isLight = true) where TImageSource : ImageSource | ||
{ | ||
if (imageSource.GetSourceName().TryThemeImage(isLight, out string imageTheme)) | ||
{ | ||
if (imageTheme.GetBitmapSource() is TImageSource themeImageSource) | ||
return themeImageSource; | ||
} | ||
|
||
return imageSource; | ||
} | ||
|
||
internal static bool TryThemeImage(this string image, bool isLight, out string imageTheme) | ||
{ | ||
imageTheme = string.Empty; | ||
|
||
if (string.IsNullOrEmpty(image)) | ||
return false; | ||
|
||
var findThemeName = !isLight ? NAME_LIGHT : NAME_DARK; | ||
var replaceThemeName = isLight ? NAME_LIGHT : NAME_DARK; | ||
|
||
if (image.IndexOf(findThemeName, System.StringComparison.InvariantCultureIgnoreCase) != -1) | ||
{ | ||
imageTheme = image.Replace(findThemeName, replaceThemeName); | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
internal static string GetSourceName(this ImageSource imageSource) | ||
{ | ||
if (imageSource is TransformedBitmap transformedBitmap) | ||
{ | ||
return transformedBitmap.Source.ToString().ToLowerInvariant(); | ||
} | ||
if (imageSource is BitmapFrame bitmapFrame) | ||
{ | ||
return bitmapFrame.Decoder.ToString().ToLowerInvariant(); | ||
} | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters