Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Add-Type -AssemblyName PresentationFramework
- Add-Type -AssemblyName PresentationCore
- Add-Type -AssemblyName WindowsBase
- Add-Type -AssemblyName System.Windows.Forms
- # --- Constants & Limits ---
- $script:MAX_TOKENS = 61440
- $script:RECOMMENDED_LIMIT = 50.0
- $script:HARD_LIMIT = 60.0
- $script:TOKENS_PER_AUDIO_SEC = 128
- $script:ImageTokenCost = 1024.0
- function Get-ImageDimensions {
- param ([string]$FilePath)
- try {
- $img = [System.Drawing.Image]::FromFile($FilePath)
- $w = $img.Width
- $h = $img.Height
- $img.Dispose()
- return @{ Width = $w; Height = $h }
- } catch {
- return $null
- }
- }
- function Update-LimitLinePosition {
- if ($C.MeterBar -and $C.LimitLine) {
- $barWidth = $C.MeterBar.ActualWidth
- if ($barWidth -gt 0) {
- $lineX = $barWidth * ($script:RECOMMENDED_LIMIT / $script:HARD_LIMIT)
- $C.LimitLine.X1 = $lineX
- $C.LimitLine.X2 = $lineX
- }
- }
- }
- function Get-RefModVideoTokenRate {
- if (-not $C.CmbVidMode -or -not $C.CmbVidMode.SelectedValue) { return 6144 }
- $mode = $C.CmbVidMode.SelectedValue.Tag
- if ($mode -eq "training") {
- $gridSize = [double]$C.CmbGridSize.SelectedValue.Tag
- $tokensPerTemporalFrame = [math]::Pow(($gridSize / 2.0), 2)
- } else {
- $res = [double]$C.CmbVidRes.SelectedValue.Tag
- $latentGrid = $res / 16.0
- $tokensPerTemporalFrame = [math]::Pow(($latentGrid / 2.0), 2)
- }
- return ($tokensPerTemporalFrame * 6.0)
- }
- function Recalculate-Budget {
- if (-not $C.SliderImages) { return }
- $w = [double]$C.TxtWidth.Text
- $h = [double]$C.TxtHeight.Text
- if ($w -le 0) { $w = 1024 }
- if ($h -le 0) { $h = 1024 }
- $script:ImageTokenCost = [math]::Max(1.0, ([math]::Ceiling($w / 32.0) * [math]::Ceiling($h / 32.0)))
- $vidRatePerSec = Get-RefModVideoTokenRate
- if ($C.ChkVidHasAudio.IsChecked) {
- $vidRatePerSec += $script:TOKENS_PER_AUDIO_SEC
- }
- $maxImageCount = [math]::Floor($script:MAX_TOKENS / $script:ImageTokenCost)
- $maxVideoSec = [math]::Floor($script:MAX_TOKENS / [math]::Max(1.0, $vidRatePerSec))
- $maxAudioSec = [math]::Floor($script:MAX_TOKENS / $script:TOKENS_PER_AUDIO_SEC)
- $C.SliderImages.Maximum = $maxImageCount
- $C.SliderVideo.Maximum = $maxVideoSec
- $C.SliderAudio.Maximum = $maxAudioSec
- $imgCount = $C.SliderImages.Value
- $vidSec = $C.SliderVideo.Value
- $audSec = $C.SliderAudio.Value
- $usedTokens = ($imgCount * $script:ImageTokenCost) + ($vidSec * $vidRatePerSec) + ($audSec * $script:TOKENS_PER_AUDIO_SEC)
- $equivalentUnits = $usedTokens / 1024.0
- $C.LblImageCount.Text = [string][int]$imgCount
- $C.LblVideoSec.Text = "$([int]$vidSec)s"
- $C.LblAudioSec.Text = "$([int]$audSec)s"
- $C.LblImgCostInfo.Text = "($([int]$script:ImageTokenCost) t/img | Max: $maxImageCount)"
- $C.LblVidCostInfo.Text = "($([math]::Round($vidRatePerSec)) t/s | Max: ${maxVideoSec}s)"
- $C.LblAudCostInfo.Text = "($script:TOKENS_PER_AUDIO_SEC t/s | Max: ${maxAudioSec}s)"
- $C.LblTokenUsage.Text = "$([math]::Round($usedTokens)) / $script:MAX_TOKENS Tokens"
- $C.LblMeterUnits.Text = "{0:F1} / 60.0 Equivalent Units" -f $equivalentUnits
- $meterPct = [math]::Min(100.0, ($equivalentUnits / $script:HARD_LIMIT) * 100.0)
- $C.MeterBar.Value = $meterPct
- if ($equivalentUnits -gt $script:HARD_LIMIT) {
- $C.MeterBar.Foreground = [System.Windows.Media.BrushConverter]::new().ConvertFrom("#FFFF4444")
- $C.LblMeterStatus.Text = "OVER BUDGET"
- $C.LblMeterStatus.Foreground = [System.Windows.Media.BrushConverter]::new().ConvertFrom("#FFFF4444")
- } elseif ($equivalentUnits -ge $script:RECOMMENDED_LIMIT) {
- $C.MeterBar.Foreground = [System.Windows.Media.BrushConverter]::new().ConvertFrom("#FFCCAA00")
- $C.LblMeterStatus.Text = "WARNING (Near Limit)"
- $C.LblMeterStatus.Foreground = [System.Windows.Media.BrushConverter]::new().ConvertFrom("#FFCCAA00")
- } else {
- $C.MeterBar.Foreground = [System.Windows.Media.BrushConverter]::new().ConvertFrom("#FF00CC66")
- $C.LblMeterStatus.Text = "WITHIN BUDGET"
- $C.LblMeterStatus.Foreground = [System.Windows.Media.BrushConverter]::new().ConvertFrom("#FF00CC66")
- }
- }
- function Toggle-GridVisibility {
- if (-not $C.CmbVidMode -or -not $C.CmbVidMode.SelectedValue) { return }
- $mode = $C.CmbVidMode.SelectedValue.Tag
- if ($mode -eq "training") {
- $C.PnlGridSize.Visibility = [System.Windows.Visibility]::Visible
- } else {
- $C.PnlGridSize.Visibility = [System.Windows.Visibility]::Collapsed
- }
- Recalculate-Budget
- }
- # ===================== XAML UI =====================
- [xml]$xaml = @"
- <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:shell="clr-namespace:System.Windows.Shell;assembly=PresentationFramework"
- Title="Context Budget Calculator" Height="730" Width="800" MinWidth="740"
- WindowStartupLocation="CenterScreen" AllowsTransparency="True" WindowStyle="None"
- Background="Transparent" Name="MainWindow" ResizeMode="CanResize">
- <Window.Resources>
- <SolidColorBrush x:Key="DarkBg" Color="#FF2D2D30"/>
- <SolidColorBrush x:Key="DarkHeaderBg" Color="#FF3E3E42"/>
- <SolidColorBrush x:Key="BorderBrush" Color="#FF555555"/>
- <SolidColorBrush x:Key="TextBrush" Color="White"/>
- <SolidColorBrush x:Key="HoverBrush" Color="#FF007ACC"/>
- <!-- Custom Dropdown Item Styling -->
- <Style TargetType="ComboBoxItem">
- <Setter Property="Background" Value="{StaticResource DarkBg}"/>
- <Setter Property="Foreground" Value="{StaticResource TextBrush}"/>
- <Setter Property="Padding" Value="6,4"/>
- <Setter Property="Template">
- <Setter.Value>
- <ControlTemplate TargetType="ComboBoxItem">
- <Border Name="Bd" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true">
- <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
- </Border>
- <ControlTemplate.Triggers>
- <Trigger Property="IsMouseOver" Value="True">
- <Setter TargetName="Bd" Property="Background" Value="{StaticResource HoverBrush}"/>
- <Setter Property="TextElement.Foreground" Value="White"/>
- </Trigger>
- <Trigger Property="IsSelected" Value="True">
- <Setter TargetName="Bd" Property="Background" Value="{StaticResource DarkHeaderBg}"/>
- <Setter Property="TextElement.Foreground" Value="White"/>
- </Trigger>
- <MultiTrigger>
- <MultiTrigger.Conditions>
- <Condition Property="IsSelected" Value="True"/>
- <Condition Property="IsMouseOver" Value="True"/>
- </MultiTrigger.Conditions>
- <Setter TargetName="Bd" Property="Background" Value="{StaticResource HoverBrush}"/>
- <Setter Property="TextElement.Foreground" Value="White"/>
- </MultiTrigger>
- </ControlTemplate.Triggers>
- </ControlTemplate>
- </Setter.Value>
- </Setter>
- </Style>
- <!-- Custom ComboBox Control Template -->
- <Style TargetType="ComboBox">
- <Setter Property="Background" Value="{StaticResource DarkHeaderBg}"/>
- <Setter Property="Foreground" Value="{StaticResource TextBrush}"/>
- <Setter Property="BorderBrush" Value="{StaticResource BorderBrush}"/>
- <Setter Property="BorderThickness" Value="1"/>
- <Setter Property="Padding" Value="6,3"/>
- <Setter Property="Template">
- <Setter.Value>
- <ControlTemplate TargetType="ComboBox">
- <Grid Name="MainGrid" SnapsToDevicePixels="true">
- <Grid.ColumnDefinitions>
- <ColumnDefinition Width="*"/>
- <ColumnDefinition Width="20"/>
- </Grid.ColumnDefinitions>
- <!-- Toggle Button with Custom Hover States -->
- <ToggleButton Grid.ColumnSpan="2" Focusable="false" IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}">
- <ToggleButton.Style>
- <Style TargetType="ToggleButton">
- <Setter Property="Background" Value="#FF3E3E42"/>
- <Setter Property="BorderBrush" Value="#FF555555"/>
- <Setter Property="BorderThickness" Value="1"/>
- <Setter Property="Template">
- <Setter.Value>
- <ControlTemplate TargetType="ToggleButton">
- <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"/>
- </ControlTemplate>
- </Setter.Value>
- </Setter>
- <Style.Triggers>
- <Trigger Property="IsMouseOver" Value="True">
- <Setter Property="Background" Value="#FF555555"/>
- <Setter Property="BorderBrush" Value="#FF007ACC"/>
- </Trigger>
- </Style.Triggers>
- </Style>
- </ToggleButton.Style>
- </ToggleButton>
- <!-- Content Presenter for Selected Item -->
- <ContentPresenter Grid.Column="0" Content="{TemplateBinding SelectionBoxItem}" ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" IsHitTestVisible="false" Margin="{TemplateBinding Padding}">
- <ContentPresenter.Resources>
- <Style TargetType="TextBlock">
- <Setter Property="Foreground" Value="White"/>
- </Style>
- </ContentPresenter.Resources>
- </ContentPresenter>
- <Path Grid.Column="1" Data="M 0 0 L 4 4 L 8 0 Z" Fill="White" HorizontalAlignment="Center" VerticalAlignment="Center" IsHitTestVisible="False"/>
- <!-- Dropdown Popup -->
- <Popup Name="PART_Popup" Grid.ColumnSpan="2" AllowsTransparency="true" IsOpen="{TemplateBinding IsDropDownOpen}" Placement="Bottom" PopupAnimation="Slide">
- <Border Name="DropDownBorder" Background="{StaticResource DarkBg}" BorderBrush="{StaticResource BorderBrush}" BorderThickness="1" MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{TemplateBinding ActualWidth}">
- <ScrollViewer Name="DropDownScrollViewer">
- <Grid RenderOptions.ClearTypeHint="Enabled">
- <Canvas Height="0" Width="0" HorizontalAlignment="Left" VerticalAlignment="Top">
- <Rectangle Name="OpaqueRect" Fill="{StaticResource DarkBg}" Height="{Binding ElementName=DropDownBorder, Path=ActualHeight}" Width="{Binding ElementName=DropDownBorder, Path=ActualWidth}"/>
- </Canvas>
- <ItemsPresenter Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Contained" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
- </Grid>
- </ScrollViewer>
- </Border>
- </Popup>
- </Grid>
- <ControlTemplate.Triggers>
- <Trigger Property="IsMouseOver" Value="True">
- <Setter Property="Foreground" Value="White"/>
- </Trigger>
- </ControlTemplate.Triggers>
- </ControlTemplate>
- </Setter.Value>
- </Setter>
- </Style>
- </Window.Resources>
- <shell:WindowChrome.WindowChrome>
- <shell:WindowChrome CaptionHeight="30" CornerRadius="0" GlassFrameThickness="0" ResizeBorderThickness="8" UseAeroCaptionButtons="False"/>
- </shell:WindowChrome.WindowChrome>
- <Border Background="#FF2D2D30" BorderBrush="#FF007ACC" BorderThickness="1">
- <Grid>
- <Grid.RowDefinitions>
- <RowDefinition Height="Auto"/>
- <RowDefinition Height="*"/>
- </Grid.RowDefinitions>
- <!-- Title Bar -->
- <Border Grid.Row="0" Background="#FF252526" Height="30">
- <Grid>
- <TextBlock Text="RefMod & Context Budget Calculator" Foreground="White" FontWeight="SemiBold" VerticalAlignment="Center" Margin="10,0,0,0"/>
- <StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
- <Button Name="MinimizeButton" Content="―" Width="40" Height="30" shell:WindowChrome.IsHitTestVisibleInChrome="True">
- <Button.Style>
- <Style TargetType="Button">
- <Setter Property="Background" Value="Transparent"/><Setter Property="Foreground" Value="White"/><Setter Property="BorderThickness" Value="0"/>
- <Style.Triggers><Trigger Property="IsMouseOver" Value="True"><Setter Property="Background" Value="#FF555555"/></Trigger></Style.Triggers>
- </Style>
- </Button.Style>
- </Button>
- <Button Name="CloseButton" Content="✕" Width="40" Height="30" shell:WindowChrome.IsHitTestVisibleInChrome="True">
- <Button.Style>
- <Style TargetType="Button">
- <Setter Property="Background" Value="Transparent"/><Setter Property="Foreground" Value="White"/><Setter Property="BorderThickness" Value="0"/>
- <Style.Triggers><Trigger Property="IsMouseOver" Value="True"><Setter Property="Background" Value="#FFE81123"/></Trigger></Style.Triggers>
- </Style>
- </Button.Style>
- </Button>
- </StackPanel>
- </Grid>
- </Border>
- <!-- Main Content -->
- <Grid Grid.Row="1" Margin="20">
- <Grid.RowDefinitions>
- <RowDefinition Height="Auto"/>
- <RowDefinition Height="Auto"/>
- <RowDefinition Height="Auto"/>
- <RowDefinition Height="Auto"/>
- <RowDefinition Height="*"/>
- </Grid.RowDefinitions>
- <!-- Meter Panel -->
- <Border Grid.Row="0" Background="#FF1E1E1E" BorderBrush="#FF555555" BorderThickness="1" CornerRadius="6" Padding="15" Margin="0,0,0,12">
- <StackPanel>
- <Grid Margin="0,0,0,8">
- <TextBlock Name="LblMeterStatus" Text="WITHIN BUDGET" Foreground="#FF00CC66" FontWeight="Bold" FontSize="14" HorizontalAlignment="Left"/>
- <TextBlock Name="LblMeterUnits" Text="0.0 / 60.0 Equivalent Units" Foreground="White" FontWeight="Bold" FontSize="14" HorizontalAlignment="Right"/>
- </Grid>
- <Grid Height="26">
- <ProgressBar Name="MeterBar" Minimum="0" Maximum="100" Value="0" Background="#FF3E3E42" Foreground="#FF00CC66" BorderBrush="#FF555555" BorderThickness="1"/>
- <Canvas>
- <Line Name="LimitLine" X1="0" Y1="0" X2="0" Y2="26" Stroke="#FFCCAA00" StrokeThickness="2" StrokeDashArray="2 2"/>
- </Canvas>
- <TextBlock Name="LblTokenUsage" Text="0 / 61440 Tokens" Foreground="White" FontWeight="Bold" FontSize="11" HorizontalAlignment="Center" VerticalAlignment="Center"/>
- </Grid>
- <Grid Margin="0,6,0,0">
- <Grid.ColumnDefinitions>
- <ColumnDefinition Width="*"/>
- <ColumnDefinition Width="Auto"/>
- </Grid.ColumnDefinitions>
- <TextBlock Text="0" Foreground="#FF888888" FontSize="10" HorizontalAlignment="Left"/>
- <TextBlock Grid.Column="0" Text="50 (Recommended)" Foreground="#FFCCAA00" FontSize="10" HorizontalAlignment="Right" Margin="0,0,50,0"/>
- <TextBlock Grid.Column="1" Text="60 (Limit)" Foreground="#FFFF4444" FontSize="10" HorizontalAlignment="Right"/>
- </Grid>
- </StackPanel>
- </Border>
- <!-- Image Configuration -->
- <Border Grid.Row="1" Name="DropZone" Background="#FF1E1E1E" BorderBrush="#FF555555" BorderThickness="1" CornerRadius="6" Padding="10" Margin="0,0,0,12" AllowDrop="True">
- <Grid>
- <Grid.ColumnDefinitions>
- <ColumnDefinition Width="*"/>
- <ColumnDefinition Width="Auto"/>
- </Grid.ColumnDefinitions>
- <StackPanel Grid.Column="0" VerticalAlignment="Center" Margin="0,0,10,0">
- <TextBlock Text="Image Configuration & Resolution Detection" Foreground="#FFBBBBBB" FontWeight="SemiBold" FontSize="12" Margin="0,0,0,6"/>
- <WrapPanel Orientation="Horizontal">
- <Label Content="Width:" Foreground="#FFBBBBBB" VerticalAlignment="Center" Margin="0,0,2,0"/>
- <TextBox Name="TxtWidth" Text="1024" Width="55" Height="24" Background="#FF3E3E42" Foreground="White" BorderBrush="#FF555555" Padding="3,1" VerticalContentAlignment="Center"/>
- <Label Content="px" Foreground="#FF888888" VerticalAlignment="Center" Margin="2,0,8,0"/>
- <Label Content="Height:" Foreground="#FFBBBBBB" VerticalAlignment="Center" Margin="0,0,2,0"/>
- <TextBox Name="TxtHeight" Text="1024" Width="55" Height="24" Background="#FF3E3E42" Foreground="White" BorderBrush="#FF555555" Padding="3,1" VerticalContentAlignment="Center"/>
- <Label Content="px" Foreground="#FF888888" VerticalAlignment="Center" Margin="2,0,8,0"/>
- <Button Name="BtnPresetDVD" Content="DVD" Width="Auto" Padding="6,0" Height="24" Background="#FF3E3E42" Foreground="White" BorderBrush="#FF555555" Margin="0,0,4,0"/>
- <Button Name="BtnPreset1080" Content="1080p" Width="Auto" Padding="6,0" Height="24" Background="#FF3E3E42" Foreground="White" BorderBrush="#FF555555"/>
- </WrapPanel>
- </StackPanel>
- <Border Grid.Column="1" Width="160" Height="46" Background="#FF252540" BorderBrush="#FF007ACC" BorderThickness="1" CornerRadius="4" Padding="8,4">
- <TextBlock Text="Drag & Drop Image Here
to Detect Resolution" Foreground="#FF007ACC" FontSize="10" TextAlignment="Center" VerticalAlignment="Center" IsHitTestVisible="False"/>
- </Border>
- </Grid>
- </Border>
- <!-- RefMod Video Extraction Configuration -->
- <Border Grid.Row="2" Background="#FF1E1E1E" BorderBrush="#FF555555" BorderThickness="1" CornerRadius="6" Padding="10" Margin="0,0,0,12">
- <StackPanel>
- <TextBlock Text="RefMod Video Extraction Parameters (ComfyUI-MiniMaxH3Mod)" Foreground="#FFBBBBBB" FontWeight="SemiBold" FontSize="12" Margin="0,0,0,6"/>
- <WrapPanel Orientation="Horizontal">
- <!-- Mode Selector -->
- <StackPanel Orientation="Horizontal" Margin="0,0,15,0">
- <Label Content="Mode:" Foreground="#FFBBBBBB" VerticalAlignment="Center" Margin="0,0,2,0"/>
- <ComboBox Name="CmbVidMode" Width="100" Height="24" VerticalContentAlignment="Center">
- <ComboBoxItem Content="encode" Tag="encode" IsSelected="True"/>
- <ComboBoxItem Content="training" Tag="training"/>
- </ComboBox>
- </StackPanel>
- <!-- Short-edge Resolution -->
- <StackPanel Orientation="Horizontal" Margin="0,0,15,0">
- <Label Content="ref_resolution:" Foreground="#FFBBBBBB" VerticalAlignment="Center" Margin="0,0,2,0"/>
- <ComboBox Name="CmbVidRes" Width="130" Height="24" VerticalContentAlignment="Center">
- <ComboBoxItem Content="512px" Tag="512"/>
- <ComboBoxItem Content="1024px (Default)" Tag="1024" IsSelected="True"/>
- <ComboBoxItem Content="2048px (Max)" Tag="2048"/>
- </ComboBox>
- </StackPanel>
- <!-- Pooled Grid Size -->
- <StackPanel Name="PnlGridSize" Orientation="Horizontal" Margin="0,0,15,0" Visibility="Collapsed">
- <Label Content="Grid Size:" Foreground="#FFBBBBBB" VerticalAlignment="Center" Margin="0,0,2,0"/>
- <ComboBox Name="CmbGridSize" Width="120" Height="24" VerticalContentAlignment="Center">
- <ComboBoxItem Content="8x8 (16 t/f)" Tag="8"/>
- <ComboBoxItem Content="16x16 (64 t/f)" Tag="16" IsSelected="True"/>
- <ComboBoxItem Content="32x32 (256 t/f)" Tag="32"/>
- <ComboBoxItem Content="64x64 (1024 t/f)" Tag="64"/>
- </ComboBox>
- </StackPanel>
- </WrapPanel>
- </StackPanel>
- </Border>
- <!-- Sliders Section -->
- <StackPanel Grid.Row="3">
- <Grid Margin="0,0,0,12">
- <Grid.RowDefinitions><RowDefinition Height="Auto"/><RowDefinition Height="Auto"/></Grid.RowDefinitions>
- <Grid Grid.Row="0" Margin="0,0,0,4">
- <StackPanel Orientation="Horizontal">
- <TextBlock Text="Images" Foreground="White" FontWeight="Bold" FontSize="13"/>
- <TextBlock Name="LblImgCostInfo" Text="(1024 t/img)" Foreground="#FF888888" FontSize="11" Margin="8,2,0,0"/>
- </StackPanel>
- <TextBlock Name="LblImageCount" Text="0" Foreground="#FF007ACC" FontWeight="Bold" FontSize="14" HorizontalAlignment="Right"/>
- </Grid>
- <Slider Grid.Row="1" Name="SliderImages" Minimum="0" Maximum="60" Value="0" IsSnapToTickEnabled="True" TickFrequency="1"/>
- </Grid>
- <Grid Margin="0,0,0,12">
- <Grid.RowDefinitions><RowDefinition Height="Auto"/><RowDefinition Height="Auto"/></Grid.RowDefinitions>
- <Grid Grid.Row="0" Margin="0,0,0,4">
- <StackPanel Orientation="Horizontal">
- <TextBlock Text="RefMod Video Duration" Foreground="White" FontWeight="Bold" FontSize="13"/>
- <TextBlock Name="LblVidCostInfo" Text="(6144 t/s)" Foreground="#FF888888" FontSize="11" Margin="8,2,15,0"/>
- <CheckBox Name="ChkVidHasAudio" Content="Include Audio Track (+128 t/s)" Foreground="#FFBBBBBB" FontSize="11" IsChecked="False" VerticalAlignment="Center"/>
- </StackPanel>
- <TextBlock Name="LblVideoSec" Text="0s" Foreground="#FF007ACC" FontWeight="Bold" FontSize="14" HorizontalAlignment="Right"/>
- </Grid>
- <Slider Grid.Row="1" Name="SliderVideo" Minimum="0" Maximum="240" Value="0" IsSnapToTickEnabled="True" TickFrequency="1"/>
- </Grid>
- <Grid Margin="0,0,0,10">
- <Grid.RowDefinitions><RowDefinition Height="Auto"/><RowDefinition Height="Auto"/></Grid.RowDefinitions>
- <Grid Grid.Row="0" Margin="0,0,0,4">
- <StackPanel Orientation="Horizontal">
- <TextBlock Text="Standalone Audio Duration" Foreground="White" FontWeight="Bold" FontSize="13"/>
- <TextBlock Name="LblAudCostInfo" Text="(128 t/s)" Foreground="#FF888888" FontSize="11" Margin="8,2,0,0"/>
- </StackPanel>
- <TextBlock Name="LblAudioSec" Text="0s" Foreground="#FF007ACC" FontWeight="Bold" FontSize="14" HorizontalAlignment="Right"/>
- </Grid>
- <Slider Grid.Row="1" Name="SliderAudio" Minimum="0" Maximum="480" Value="0" IsSnapToTickEnabled="True" TickFrequency="1"/>
- </Grid>
- </StackPanel>
- <!-- Reset Button -->
- <Button Grid.Row="4" Name="BtnReset" Content="RESET ALL SLIDERS" Height="34" VerticalAlignment="Bottom" Background="#FF3E3E42" Foreground="White" BorderBrush="#FF555555" FontWeight="Bold"/>
- </Grid>
- </Grid>
- </Border>
- </Window>
- "@
- # ===================== Load Window & Bind Events =====================
- $reader = New-Object System.Xml.XmlNodeReader($xaml)
- $script:Window = [Windows.Markup.XamlReader]::Load($reader)
- $C = @{}
- @("MinimizeButton","CloseButton","DropZone","LimitLine",
- "LblMeterStatus","LblMeterUnits","MeterBar","LblTokenUsage",
- "TxtWidth","TxtHeight","BtnPresetDVD","BtnPreset1080",
- "CmbVidMode","CmbVidRes","CmbGridSize","PnlGridSize",
- "SliderImages","SliderVideo","SliderAudio","ChkVidHasAudio",
- "LblImageCount","LblVideoSec","LblAudioSec",
- "LblImgCostInfo","LblVidCostInfo","LblAudCostInfo",
- "BtnReset"
- ) | ForEach-Object { $C[$_] = $script:Window.FindName($_) }
- $C.MeterBar.Add_SizeChanged({ Update-LimitLinePosition })
- $C.CloseButton.Add_Click({ $script:Window.Close() })
- $C.MinimizeButton.Add_Click({ $script:Window.WindowState = 'Minimized' })
- $C.SliderImages.Add_ValueChanged({ Recalculate-Budget })
- $C.SliderVideo.Add_ValueChanged({ Recalculate-Budget })
- $C.SliderAudio.Add_ValueChanged({ Recalculate-Budget })
- $C.ChkVidHasAudio.Add_Checked({ Recalculate-Budget })
- $C.ChkVidHasAudio.Add_Unchecked({ Recalculate-Budget })
- $C.TxtWidth.Add_TextChanged({ Recalculate-Budget })
- $C.TxtHeight.Add_TextChanged({ Recalculate-Budget })
- $C.CmbVidMode.Add_SelectionChanged({ Toggle-GridVisibility })
- $C.CmbVidRes.Add_SelectionChanged({ Recalculate-Budget })
- $C.CmbGridSize.Add_SelectionChanged({ Recalculate-Budget })
- $C.BtnPresetDVD.Add_Click({
- $C.TxtWidth.Text = "720"
- $C.TxtHeight.Text = "480"
- })
- $C.BtnPreset1080.Add_Click({
- $C.TxtWidth.Text = "1920"
- $C.TxtHeight.Text = "1080"
- })
- $C.DropZone.Add_PreviewDragOver({ param($s,$e)
- $e.Effects = [Windows.DragDropEffects]::Copy
- $e.Handled = $true
- })
- $C.DropZone.Add_Drop({ param($s,$e)
- if ($e.Data.GetDataPresent([Windows.DataFormats]::FileDrop)) {
- $files = $e.Data.GetData([Windows.DataFormats]::FileDrop)
- if ($files.Count -gt 0) {
- $dims = Get-ImageDimensions -FilePath $files[0]
- if ($dims) {
- $C.TxtWidth.Text = $dims.Width
- $C.TxtHeight.Text = $dims.Height
- }
- }
- }
- })
- $C.BtnReset.Add_Click({
- $C.SliderImages.Value = 0
- $C.SliderVideo.Value = 0
- $C.SliderAudio.Value = 0
- })
- Recalculate-Budget
- $script:Window.ShowDialog() | Out-Null
Advertisement