mirror of
https://github.com/denglihong2007/CRSim
synced 2026-08-06 17:53:17 +08:00
feat: 引导屏模拟可调整大小
This commit is contained in:
@@ -3,14 +3,15 @@
|
||||
public interface ITimeService
|
||||
{
|
||||
event EventHandler OneSecondElapsed;
|
||||
|
||||
event EventHandler RefreshSecondsElapsed;
|
||||
|
||||
void Start();
|
||||
void Stop();
|
||||
|
||||
DateTime GetDateTimeNow();
|
||||
|
||||
DateTime SimulateTime { get; set; } // 初始模拟时间
|
||||
|
||||
double Speed { get; set; } // 模拟倍速
|
||||
}
|
||||
}
|
||||
@@ -51,12 +51,6 @@ namespace CRSim.Core.Services
|
||||
_lastSpeedChangeTime = DateTime.Now; // 启动时刷新时间
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
_oneSecondTimer.Stop();
|
||||
_twentySecondsTimer.Stop();
|
||||
}
|
||||
|
||||
private void OnOneSecondElapsed(object sender, ElapsedEventArgs e)
|
||||
{
|
||||
OneSecondElapsed?.Invoke(this, EventArgs.Empty);
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
Background="Transparent"
|
||||
Foreground="White"
|
||||
SizeToContent="WidthAndHeight"
|
||||
ResizeMode="NoResize"
|
||||
WindowStyle="None"
|
||||
AllowsTransparency="True"
|
||||
MouseDown="Window_MouseDown"
|
||||
@@ -24,15 +23,23 @@
|
||||
<Border Grid.Column="1" Background="#E0202020" CornerRadius="8" BorderBrush="#424242"
|
||||
BorderThickness="1" Padding="4">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Image Source="/CRSim.ScreenSimulator;component/Assets/CRSimIcon.png" Width="30" Margin="0,0,12,0"/>
|
||||
<Image Source="/CRSim.ScreenSimulator;component/Assets/CRSimIcon.png" Width="30" Margin="0,0,16,0"/>
|
||||
<TextBlock x:Name="TimeText" FontSize="22" VerticalAlignment="Center" Margin="0,0,16,0"/>
|
||||
<TextBlock Text="" FontFamily="Segoe MDL2 Assets" FontSize="20" VerticalAlignment="Center" MouseLeftButtonDown="DecreaseSpeed"/>
|
||||
<TextBlock x:Name="SpeedText" Text="1x" FontSize="22" VerticalAlignment="Center" Margin="6,0"/>
|
||||
<TextBlock x:Name="SpeedText" Text="1x" FontSize="22" VerticalAlignment="Center" Margin="4,0"/>
|
||||
<TextBlock Text="" FontFamily="Segoe MDL2 Assets" FontSize="20" VerticalAlignment="Center" MouseLeftButtonDown="IncreaseSpeed"/>
|
||||
<TextBlock x:Name="FullScreenIcon" Text="" FontFamily="Segoe MDL2 Assets"
|
||||
FontSize="20" VerticalAlignment="Center" Margin="16,0,0,0" MouseLeftButtonDown="FullScreen"/>
|
||||
<TextBlock x:Name="RestoreWindowIcon" Text="" FontFamily="Segoe MDL2 Assets"
|
||||
FontSize="20" VerticalAlignment="Center" Margin="16,0,0,0" MouseLeftButtonDown="RestoreWindow"
|
||||
Visibility="Collapsed"/>
|
||||
<TextBlock Text="" FontFamily="Segoe MDL2 Assets" FontSize="20"
|
||||
VerticalAlignment="Center" Margin="12,0,2,0" MouseLeftButtonDown="CloseWindow"/>
|
||||
VerticalAlignment="Center" Margin="4,0,2,0" MouseLeftButtonDown="CloseWindow"/>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</Grid>
|
||||
<Frame x:Name="contentFrame" Margin="0,4,0,0"/>
|
||||
<Viewbox x:Name="viewbox" Stretch="None">
|
||||
<Frame x:Name="contentFrame" Margin="0,4,0,0"/>
|
||||
</Viewbox>
|
||||
</StackPanel>
|
||||
</Window>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using CRSim.Core.Abstractions;
|
||||
using CRSim.Core.Abstractions;
|
||||
using CRSim.ScreenSimulator.Models;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
@@ -15,12 +14,13 @@ namespace CRSim.ScreenSimulator.Views
|
||||
public Session Session { get; }
|
||||
public SimulatorWindow(Page page,ITimeService timeService,StyleManager styleManager,Session session)
|
||||
{
|
||||
Session = session;
|
||||
InitializeComponent();
|
||||
RenderOptions.SetEdgeMode(this, EdgeMode.Aliased);
|
||||
Session = session;
|
||||
contentFrame.Content = page;
|
||||
_timeService = timeService;
|
||||
_styleManager = styleManager;
|
||||
|
||||
foreach (var resource in page.Resources.Values)
|
||||
{
|
||||
if (resource is IHasTimeService needsTime)
|
||||
@@ -28,6 +28,15 @@ namespace CRSim.ScreenSimulator.Views
|
||||
needsTime.TimeService = timeService;
|
||||
}
|
||||
}
|
||||
_timeService.OneSecondElapsed += UpdateTime;
|
||||
}
|
||||
|
||||
private void UpdateTime(object? sender, EventArgs e)
|
||||
{
|
||||
Dispatcher.Invoke(() =>
|
||||
{
|
||||
TimeText.Text = _timeService.GetDateTimeNow().ToString("HH:mm:ss");
|
||||
});
|
||||
}
|
||||
|
||||
private void Window_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
|
||||
@@ -78,5 +87,20 @@ namespace CRSim.ScreenSimulator.Views
|
||||
Close();
|
||||
});
|
||||
}
|
||||
|
||||
private void FullScreen(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
Left = 0;
|
||||
viewbox.Stretch = Stretch.Uniform;
|
||||
FullScreenIcon.Visibility = Visibility.Collapsed;
|
||||
RestoreWindowIcon.Visibility = Visibility.Visible;
|
||||
}
|
||||
|
||||
private void RestoreWindow(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
viewbox.Stretch = Stretch.None;
|
||||
FullScreenIcon.Visibility = Visibility.Visible;
|
||||
RestoreWindowIcon.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user