-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
71 additions
and
6 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
54 changes: 54 additions & 0 deletions
54
GammaJul.ReSharper.EnhancedTooltip/Presentation/IconScaling.cs
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,54 @@ | ||
using System; | ||
using System.Windows; | ||
using System.Windows.Documents; | ||
using System.Windows.Media; | ||
using JetBrains.Annotations; | ||
using JetBrains.Util; | ||
|
||
namespace GammaJul.ReSharper.EnhancedTooltip.Presentation { | ||
|
||
public static class IconScaling { | ||
|
||
public static readonly DependencyProperty IsScalingWithFontSizeProperty = DependencyProperty.RegisterAttached( | ||
"IsScalingWithFontSize", | ||
typeof(bool), | ||
typeof(IconScaling), | ||
new FrameworkPropertyMetadata(BooleanBoxes.False, OnFontSizeForScaleChanged)); | ||
|
||
public static double GetIsScalingWithFontSize([NotNull] DependencyObject owner) { | ||
if (owner == null) | ||
throw new ArgumentNullException("owner"); | ||
return (double) owner.GetValue(IsScalingWithFontSizeProperty); | ||
} | ||
|
||
public static void SetIsScalingWithFontSize([NotNull] DependencyObject owner, bool value) { | ||
if (owner == null) | ||
throw new ArgumentNullException("owner"); | ||
owner.SetValue(IsScalingWithFontSizeProperty, value); | ||
} | ||
|
||
private static void OnFontSizeForScaleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { | ||
var element = d as FrameworkElement; | ||
if (element == null) | ||
return; | ||
|
||
FontFamily fontFamily = TextElement.GetFontFamily(element); | ||
if (fontFamily == null) | ||
return; | ||
|
||
double fontSize = TextElement.GetFontSize(element); | ||
if (Double.IsNaN(fontSize)) | ||
return; | ||
|
||
|
||
double size = fontFamily.LineSpacing * fontSize; | ||
if (size < 18.0) { | ||
// Scaling isn't a real need at these small sizes, use the best looking 16x16 instead. | ||
size = 16.0; | ||
} | ||
element.Width = element.Height = size; | ||
} | ||
|
||
} | ||
|
||
} |
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