Skip to content

Commit

Permalink
feat: Added GeneratedIconSource istead GeneratedIcon class. #48.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Mar 12, 2023
1 parent d1ea0b6 commit ee9d89b
Show file tree
Hide file tree
Showing 16 changed files with 281 additions and 349 deletions.
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,67 +72,67 @@ TaskbarIcon.ForceCreate(bool enablesEfficiencyMode = true) // default value
Example 1: <img width="15" alt="image" src="https://user-images.githubusercontent.com/3002068/163721411-1388f2b4-a039-4b4a-8114-f74bfc8835ba.png">
```xml
<tb:TaskbarIcon>
<tb:TaskbarIcon.GeneratedIcon>
<tb:GeneratedIcon
<tb:TaskbarIcon.IconSource>
<tb:GeneratedIconSource
Text="❤️"
Foreground="Red"
/>
</tb:TaskbarIcon.GeneratedIcon>
</tb:TaskbarIcon.IconSource>
</tb:TaskbarIcon>
```
Example 2: <img width="14" alt="image" src="https://user-images.githubusercontent.com/3002068/163721399-cbfd0286-d2d4-4b40-b3f3-388c9613f535.png">
```xml
<tb:TaskbarIcon
IconSource="/Icons/Error.ico"
>
<tb:TaskbarIcon.GeneratedIcon>
<tb:GeneratedIcon
<tb:TaskbarIcon.IconSource>
<tb:GeneratedIconSource
Text="5"
Foreground="Black"
FontSize="36"
FontWeight="Bold"
/>
</tb:TaskbarIcon.GeneratedIcon>
</tb:TaskbarIcon.IconSource>
</tb:TaskbarIcon>
```
Example 3: <img width="19" alt="image" src="https://user-images.githubusercontent.com/3002068/163721367-dc6878df-3ec2-4288-b699-cf664894e1b1.png">
```xml
<tb:TaskbarIcon>
<tb:TaskbarIcon.GeneratedIcon>
<tb:GeneratedIcon
<tb:TaskbarIcon.IconSource>
<tb:GeneratedIconSource
Text="❤️"
Foreground="Red"
FontFamily="Segoe UI Emoji"
Background="AliceBlue"
FontWeight="Bold"
FontSize="38"
/>
</tb:TaskbarIcon.GeneratedIcon>
</tb:TaskbarIcon.IconSource>
</tb:TaskbarIcon>
```
Example 4: <img width="18" alt="image" src="https://user-images.githubusercontent.com/3002068/163723782-8b135584-8b35-401e-926e-0fe0e7aa801e.png">
```xml
<tb:TaskbarIcon>
<tb:TaskbarIcon.GeneratedIcon>
<tb:GeneratedIcon
<tb:TaskbarIcon.IconSource>
<tb:GeneratedIconSource
Text="❤️"
BorderThickness="5"
FontSize="46"
>
<tb:GeneratedIcon.Foreground>
<tb:GeneratedIconSource.Foreground>
<LinearGradientBrush StartPoint="0,0" EndPoint="128,128">
<GradientStop Color="White" />
<GradientStop Color="Red" />
</LinearGradientBrush>
</tb:GeneratedIcon.Foreground>
<tb:GeneratedIcon.BorderBrush>
</tb:GeneratedIconSource.Foreground>
<tb:GeneratedIconSource.BorderBrush>
<LinearGradientBrush StartPoint="0,0" EndPoint="128,128">
<GradientStop Color="White" />
<GradientStop Color="Red" />
</LinearGradientBrush>
</tb:GeneratedIcon.BorderBrush>
</tb:GeneratedIcon>
</tb:TaskbarIcon.GeneratedIcon>
</tb:GeneratedIconSource.BorderBrush>
</tb:GeneratedIconSource>
</tb:TaskbarIcon.IconSource>
</tb:TaskbarIcon>
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ private void ShowNotificationButton_Click(object sender, RoutedEventArgs e)
"Error" => NotificationIcon.Error,
_ => NotificationIcon.None,
},
customIcon: selectedIcon switch
customIconHandle: selectedIcon switch
{
"Custom" => TrayIcon.Icon,
"Custom" => TrayIcon.Icon?.Handle,
_ => null,
},
//largeIcon: LargeIconCheckBox.IsChecked ?? false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<tb:GeneratedIconSource
Text="❤️"
BorderThickness="5"
FontSize="46"
FontSize="36"
>
<tb:GeneratedIconSource.Foreground>
<LinearGradientBrush StartPoint="0,0" EndPoint="128,128">
Expand Down
190 changes: 0 additions & 190 deletions src/libs/H.NotifyIcon.Shared/GeneratedIcon.cs

This file was deleted.

16 changes: 12 additions & 4 deletions src/libs/H.NotifyIcon.Shared/GeneratedIconSource.System.Drawing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public sealed partial class GeneratedIconSource : BitmapSource
{
internal System.Drawing.Bitmap Generate()
internal Bitmap Generate(Bitmap? backgroundBitmap = null)
{
var size = Size;
using var fontFamily =
Expand All @@ -12,8 +12,7 @@ internal System.Drawing.Bitmap Generate()
fontFamily,
(float)FontSize,
FontStyle.ToSystemDrawingFontStyle(FontWeight));
//using var baseImageStream = Background?.ToStream();
//using var baseImage = baseImageStream?.ToBitmap();
using var baseImage = backgroundBitmap ?? BackgroundSource?.ToBitmap();
using var pen = BorderBrush.ToSystemDrawingPen(BorderThickness);
using var backgroundBrush = Background.ToSystemDrawingBrush();
using var foregroundBrush = Foreground.ToSystemDrawingBrush();
Expand All @@ -32,7 +31,16 @@ internal System.Drawing.Bitmap Generate()
text: Text,
font: font,
textRectangle: TextMargin.ToSystemDrawingRectangleF(width: size, height: size),
baseImage: null,
baseImage: baseImage,
size: size);
}

internal async Task<Bitmap> GenerateAsync(CancellationToken cancellationToken = default)
{
using var baseImage = BackgroundSource == null
? null
: await BackgroundSource.ToBitmapAsync(cancellationToken).ConfigureAwait(true);

return Generate(baseImage);
}
}
4 changes: 1 addition & 3 deletions src/libs/H.NotifyIcon.Shared/GeneratedIconSource.Wpf.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#if HAS_WPF
namespace H.NotifyIcon;
namespace H.NotifyIcon;

/// <summary>
///
Expand Down Expand Up @@ -34,4 +33,3 @@ protected override Freezable CreateInstanceCore()
stride: bits.Stride);
}
}
#endif
Loading

0 comments on commit ee9d89b

Please sign in to comment.