mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2025-01-15 17:30:37 -06:00
improve viewboxfunction
- add logo + checkmark + warning - add params - render on param "render" - custom dialog logo function call fix - main logo function call fix - update winutiltaskbaritem to use new images
This commit is contained in:
parent
274daae30f
commit
2e757c5491
@ -1,14 +1,31 @@
|
|||||||
function Invoke-WinUtilLogoviewbox {
|
function Invoke-WinUtilLogoviewbox {
|
||||||
param ($Size)
|
param (
|
||||||
|
$type,
|
||||||
|
$Size,
|
||||||
|
[switch]$render
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# Create the Viewbox and set its size
|
# Create the Viewbox and set its size
|
||||||
$LogoViewbox = New-Object Windows.Controls.Viewbox
|
$LogoViewbox = New-Object Windows.Controls.Viewbox
|
||||||
$LogoViewbox.Width = $Size
|
$LogoViewbox.Width = $Size
|
||||||
$LogoViewbox.Height = $Size
|
$LogoViewbox.Height = $Size
|
||||||
|
|
||||||
|
# Create a Canvas to hold the paths
|
||||||
|
$canvas = New-Object Windows.Controls.Canvas
|
||||||
|
$canvas.Width = 100
|
||||||
|
$canvas.Height = 100
|
||||||
|
|
||||||
# Define a scale factor for the content inside the Canvas
|
# Define a scale factor for the content inside the Canvas
|
||||||
$scaleFactor = $Size / 100
|
$scaleFactor = $Size / 100
|
||||||
|
|
||||||
|
# Apply a scale transform to the Canvas content
|
||||||
|
$scaleTransform = New-Object Windows.Media.ScaleTransform($scaleFactor, $scaleFactor)
|
||||||
|
$canvas.LayoutTransform = $scaleTransform
|
||||||
|
|
||||||
|
switch ($type) {
|
||||||
|
'logo' {
|
||||||
|
|
||||||
# Part 1
|
# Part 1
|
||||||
$LogoPathData1 = @"
|
$LogoPathData1 = @"
|
||||||
M 18.00,14.00
|
M 18.00,14.00
|
||||||
@ -67,22 +84,135 @@ function Invoke-WinUtilLogoviewbox {
|
|||||||
$LogoPath3.Data = [Windows.Media.Geometry]::Parse($LogoPathData3)
|
$LogoPath3.Data = [Windows.Media.Geometry]::Parse($LogoPathData3)
|
||||||
$LogoPath3.Fill = [Windows.Media.Brushes]::Gray # Set fill color for bottom part
|
$LogoPath3.Fill = [Windows.Media.Brushes]::Gray # Set fill color for bottom part
|
||||||
|
|
||||||
# Create a Canvas to hold the paths
|
# Add the paths to the Canvas
|
||||||
$LogoCanvas = New-Object Windows.Controls.Canvas
|
$canvas.Children.Add($LogoPath1) | Out-Null
|
||||||
$LogoCanvas.Width = 100
|
$canvas.Children.Add($LogoPath2) | Out-Null
|
||||||
$LogoCanvas.Height = 100
|
$canvas.Children.Add($LogoPath3) | Out-Null
|
||||||
|
|
||||||
# Apply a scale transform to the Canvas content
|
}
|
||||||
|
'checkmark' {
|
||||||
|
# Create a Canvas to hold the paths
|
||||||
|
$canvas = New-Object Windows.Controls.Canvas
|
||||||
|
$canvas.Width = 2.54 # Adjust to the needed size for the content
|
||||||
|
$canvas.Height = 2.54
|
||||||
|
|
||||||
|
# Define a scale factor for the content inside the Canvas
|
||||||
|
$scaleFactor = $Size / 2.54 # Adjust scaling based on the canvas size
|
||||||
$scaleTransform = New-Object Windows.Media.ScaleTransform($scaleFactor, $scaleFactor)
|
$scaleTransform = New-Object Windows.Media.ScaleTransform($scaleFactor, $scaleFactor)
|
||||||
$LogoCanvas.LayoutTransform = $scaleTransform
|
$canvas.LayoutTransform = $scaleTransform
|
||||||
|
|
||||||
|
# Define the circle path
|
||||||
|
$circlePathData = "M 1.27,0 A 1.27,1.27 0 1,0 1.27,2.54 A 1.27,1.27 0 1,0 1.27,0"
|
||||||
|
$circlePath = New-Object Windows.Shapes.Path
|
||||||
|
$circlePath.Data = [Windows.Media.Geometry]::Parse($circlePathData)
|
||||||
|
$circlePath.Fill = [Windows.Media.Brushes]::Green # Set fill color to green
|
||||||
|
|
||||||
|
# Define the checkmark path
|
||||||
|
$checkmarkPathData = "M 0.873 1.89 L 0.41 1.391 A 0.17 0.17 0 0 1 0.418 1.151 A 0.17 0.17 0 0 1 0.658 1.16 L 1.016 1.543 L 1.583 1.013 A 0.17 0.17 0 0 1 1.599 1 L 1.865 0.751 A 0.17 0.17 0 0 1 2.105 0.759 A 0.17 0.17 0 0 1 2.097 0.999 L 1.282 1.759 L 0.999 2.022 L 0.874 1.888 Z"
|
||||||
|
$checkmarkPath = New-Object Windows.Shapes.Path
|
||||||
|
$checkmarkPath.Data = [Windows.Media.Geometry]::Parse($checkmarkPathData)
|
||||||
|
$checkmarkPath.Fill = [Windows.Media.Brushes]::White # Set fill color to white
|
||||||
|
|
||||||
# Add the paths to the Canvas
|
# Add the paths to the Canvas
|
||||||
$LogoCanvas.Children.Add($LogoPath1) | Out-Null
|
$canvas.Children.Add($circlePath) | Out-Null
|
||||||
$LogoCanvas.Children.Add($LogoPath2) | Out-Null
|
$canvas.Children.Add($checkmarkPath) | Out-Null
|
||||||
$LogoCanvas.Children.Add($LogoPath3) | Out-Null
|
}
|
||||||
|
'warning' {
|
||||||
|
# Create a Canvas to hold the paths
|
||||||
|
$canvas = New-Object Windows.Controls.Canvas
|
||||||
|
$canvas.Width = 512 # Adjust to the needed size for the warning icon
|
||||||
|
$canvas.Height = 512
|
||||||
|
|
||||||
|
# Define a scale factor for the content inside the Canvas
|
||||||
|
$scaleFactor = $Size / 512 # Adjust scaling based on the canvas size
|
||||||
|
$scaleTransform = New-Object Windows.Media.ScaleTransform($scaleFactor, $scaleFactor)
|
||||||
|
$canvas.LayoutTransform = $scaleTransform
|
||||||
|
|
||||||
|
# Define the circle path
|
||||||
|
$circlePathData = "M 256,0 A 256,256 0 1,0 256,512 A 256,256 0 1,0 256,0"
|
||||||
|
$circlePath = New-Object Windows.Shapes.Path
|
||||||
|
$circlePath.Data = [Windows.Media.Geometry]::Parse($circlePathData)
|
||||||
|
$circlePath.Fill = [Windows.Media.Brushes]::Red # Set fill color to red
|
||||||
|
|
||||||
|
# Define the exclamation mark path
|
||||||
|
$exclamationPathData = "M 256 307.2 A 35.89 35.89 0 0 1 220.14 272.74 L 215.41 153.3 A 35.89 35.89 0 0 1 251.27 116 H 260.73 A 35.89 35.89 0 0 1 296.59 153.3 L 291.86 272.74 A 35.89 35.89 0 0 1 256 307.2 Z"
|
||||||
|
$exclamationPath = New-Object Windows.Shapes.Path
|
||||||
|
$exclamationPath.Data = [Windows.Media.Geometry]::Parse($exclamationPathData)
|
||||||
|
$exclamationPath.Fill = [Windows.Media.Brushes]::White # Set fill color to white
|
||||||
|
|
||||||
|
# Calculate the center position for the exclamation mark path
|
||||||
|
# Get the bounds of the exclamation mark path
|
||||||
|
$exclamationBounds = $exclamationPath.Data.Bounds
|
||||||
|
|
||||||
|
# Calculate the center position for the exclamation mark path
|
||||||
|
$exclamationCenterX = ($canvas.Width - $exclamationBounds.Width) / 2 - $exclamationBounds.X
|
||||||
|
$exclamationPath.SetValue([Windows.Controls.Canvas]::LeftProperty, $exclamationCenterX)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Define the rounded rectangle at the bottom (dot of exclamation mark)
|
||||||
|
$roundedRectangle = New-Object Windows.Shapes.Rectangle
|
||||||
|
$roundedRectangle.Width = 80
|
||||||
|
$roundedRectangle.Height = 80
|
||||||
|
$roundedRectangle.RadiusX = 30
|
||||||
|
$roundedRectangle.RadiusY = 30
|
||||||
|
$roundedRectangle.Fill = [Windows.Media.Brushes]::White
|
||||||
|
|
||||||
|
# Calculate the center position for the rounded rectangle
|
||||||
|
$centerX = ($canvas.Width - $roundedRectangle.Width) / 2
|
||||||
|
$roundedRectangle.SetValue([Windows.Controls.Canvas]::LeftProperty, $centerX)
|
||||||
|
$roundedRectangle.SetValue([Windows.Controls.Canvas]::TopProperty, 324.34)
|
||||||
|
|
||||||
|
|
||||||
|
# Add the paths to the Canvas
|
||||||
|
$canvas.Children.Add($circlePath) | Out-Null
|
||||||
|
$canvas.Children.Add($exclamationPath) | Out-Null
|
||||||
|
$canvas.Children.Add($roundedRectangle) | Out-Null
|
||||||
|
|
||||||
# Add the Canvas to the Viewbox
|
# Add the Canvas to the Viewbox
|
||||||
$LogoViewbox.Child = $LogoCanvas
|
$LogoViewbox.Child = $canvas
|
||||||
|
}
|
||||||
|
default {
|
||||||
|
Write-Host "Invalid type: $type"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Add the Canvas to the Viewbox
|
||||||
|
$LogoViewbox.Child = $canvas
|
||||||
|
|
||||||
|
if ($render) {
|
||||||
|
# Measure and arrange the canvas to ensure proper rendering
|
||||||
|
$canvas.Measure([Windows.Size]::new($canvas.Width, $canvas.Height))
|
||||||
|
$canvas.Arrange([Windows.Rect]::new(0, 0, $canvas.Width, $canvas.Height))
|
||||||
|
$canvas.UpdateLayout()
|
||||||
|
|
||||||
|
# Initialize RenderTargetBitmap correctly with dimensions
|
||||||
|
$renderTargetBitmap = New-Object Windows.Media.Imaging.RenderTargetBitmap($canvas.Width, $canvas.Height, 96, 96, [Windows.Media.PixelFormats]::Pbgra32)
|
||||||
|
|
||||||
|
# Render the canvas to the bitmap
|
||||||
|
$renderTargetBitmap.Render($canvas)
|
||||||
|
|
||||||
|
# Create a BitmapFrame from the RenderTargetBitmap
|
||||||
|
$bitmapFrame = [Windows.Media.Imaging.BitmapFrame]::Create($renderTargetBitmap)
|
||||||
|
|
||||||
|
# Create a PngBitmapEncoder and add the frame
|
||||||
|
$bitmapEncoder = [Windows.Media.Imaging.PngBitmapEncoder]::new()
|
||||||
|
$bitmapEncoder.Frames.Add($bitmapFrame)
|
||||||
|
|
||||||
|
# Save to a memory stream
|
||||||
|
$imageStream = New-Object System.IO.MemoryStream
|
||||||
|
$bitmapEncoder.Save($imageStream)
|
||||||
|
$imageStream.Position = 0
|
||||||
|
|
||||||
|
# Load the stream into a BitmapImage
|
||||||
|
$bitmapImage = [Windows.Media.Imaging.BitmapImage]::new()
|
||||||
|
$bitmapImage.BeginInit()
|
||||||
|
$bitmapImage.StreamSource = $imageStream
|
||||||
|
$bitmapImage.CacheOption = [Windows.Media.Imaging.BitmapCacheOption]::OnLoad
|
||||||
|
$bitmapImage.EndInit()
|
||||||
|
|
||||||
|
return $bitmapImage
|
||||||
|
} else {
|
||||||
return $LogoViewbox
|
return $LogoViewbox
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,13 +61,13 @@ function Set-WinUtilTaskbaritem {
|
|||||||
if ($overlay) {
|
if ($overlay) {
|
||||||
switch ($overlay) {
|
switch ($overlay) {
|
||||||
'logo' {
|
'logo' {
|
||||||
$sync["Form"].taskbarItemInfo.Overlay = "$env:LOCALAPPDATA\winutil\cttlogo.png"
|
$sync["Form"].taskbarItemInfo.Overlay = (Invoke-WinUtilLogoviewbox -Type "Logo" -Size 80 -Render)
|
||||||
}
|
}
|
||||||
'checkmark' {
|
'checkmark' {
|
||||||
$sync["Form"].taskbarItemInfo.Overlay = "$env:LOCALAPPDATA\winutil\checkmark.png"
|
$sync["Form"].taskbarItemInfo.Overlay = (Invoke-WinUtilLogoviewbox -Type "checkmark" -Size 80 -Render)
|
||||||
}
|
}
|
||||||
'warning' {
|
'warning' {
|
||||||
$sync["Form"].taskbarItemInfo.Overlay = "$env:LOCALAPPDATA\winutil\warning.png"
|
$sync["Form"].taskbarItemInfo.Overlay = (Invoke-WinUtilLogoviewbox -Type "warning" -Size 80 -Render)
|
||||||
}
|
}
|
||||||
'None' {
|
'None' {
|
||||||
$sync["Form"].taskbarItemInfo.Overlay = $null
|
$sync["Form"].taskbarItemInfo.Overlay = $null
|
||||||
|
@ -129,7 +129,7 @@ function Show-CustomDialog {
|
|||||||
[Windows.Controls.Grid]::SetRow($stackPanel, 0) # Set the row to the second row (0-based index)
|
[Windows.Controls.Grid]::SetRow($stackPanel, 0) # Set the row to the second row (0-based index)
|
||||||
|
|
||||||
# Add SVG path to the stack panel
|
# Add SVG path to the stack panel
|
||||||
$stackPanel.Children.Add((Invoke-WinUtilLogoviewbox -Size 25))
|
$stackPanel.Children.Add((Invoke-WinUtilLogoviewbox -Type "logo" -Size 25))
|
||||||
|
|
||||||
# Add "Winutil" text
|
# Add "Winutil" text
|
||||||
$winutilTextBlock = New-Object Windows.Controls.TextBlock
|
$winutilTextBlock = New-Object Windows.Controls.TextBlock
|
||||||
|
@ -446,7 +446,7 @@ $sync["Form"].Add_Loaded({
|
|||||||
})
|
})
|
||||||
|
|
||||||
$NavLogoPanel = $sync["Form"].FindName("NavLogoPanel")
|
$NavLogoPanel = $sync["Form"].FindName("NavLogoPanel")
|
||||||
$NavLogoPanel.Children.Add((Invoke-WinUtilLogoviewbox -Size 25)) | Out-Null
|
$NavLogoPanel.Children.Add((Invoke-WinUtilLogoviewbox -Type "logo" -Size 25)) | Out-Null
|
||||||
|
|
||||||
# Initialize the hashtable
|
# Initialize the hashtable
|
||||||
$winutildir = @{}
|
$winutildir = @{}
|
||||||
|
Loading…
Reference in New Issue
Block a user