Files
GhostEngine/Ghost.Editor/View/Pages/EngineEditor/ScenePage.xaml.cs
Misaki d2d9f5feb7 Refactor and enhance codebase for maintainability
Refactored and reorganized the codebase to improve readability, performance, and maintainability. Introduced new interfaces and structs for better resource management, updated project configuration files, and refactored shader and graphics pipeline management. Improved error handling, code formatting, and removed unused code and namespaces. Updated DLL references and method signatures for consistency and maintainability.
2025-10-22 18:46:39 +09:00

45 lines
1.5 KiB
C#

using Ghost.Editor.Controls.Internal;
using Ghost.Graphics.Contracts;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using WinRT;
namespace Ghost.Editor.View.Pages.EngineEditor;
internal sealed partial class ScenePage : NavigationTabPage
{
private Renderer? _renderView;
private ISwapChainPanelNative _swapChainPanelNative;
public ScenePage()
{
InitializeComponent();
SwapChainPanel.Loaded += SwapChainPanel_Loaded;
SwapChainPanel.Unloaded += SwapChainPanel_Unloaded;
SwapChainPanel.SizeChanged += SwapChainPanel_SizeChanged;
}
private void SwapChainPanel_Loaded(object sender, RoutedEventArgs e)
{
var guid = typeof(ISwapChainPanelNative.Interface).GUID;
((IWinRTObject)SwapChainPanel).NativeObject.TryAs(guid, out var swapChainPanelNativeHandle);
_swapChainPanelNative = new ISwapChainPanelNative(swapChainPanelNativeHandle);
_renderView = GraphicsPipeline.GraphicsDevice.CreateRenderer(new(_swapChainPanelNative, (uint)SwapChainPanel.ActualWidth, (uint)SwapChainPanel.ActualHeight));
}
private void SwapChainPanel_Unloaded(object sender, RoutedEventArgs e)
{
_swapChainPanelNative.Dispose();
_renderView?.Dispose();
}
private void SwapChainPanel_SizeChanged(object sender, SizeChangedEventArgs e)
{
if (e.NewSize.Width > 8.0 && e.NewSize.Height > 8.0)
{
_renderView?.RequestResize((uint)e.NewSize.Width, (uint)e.NewSize.Height);
}
}
}