// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
using System.Runtime.InteropServices;
using FlaxEngine;
namespace FlaxEditor.Surface
{
public partial class VisjectSurface
{
[StructLayout(LayoutKind.Sequential)]
internal struct Meta10 // TypeID: 10, for surface
{
public Float2 ViewCenterPosition;
public float Scale;
}
[StructLayout(LayoutKind.Sequential)]
internal struct Meta11 // TypeID: 11, for nodes
{
public Float2 Position;
public bool Selected;
}
///
/// Loads surface from the bytes.
///
///
/// The method calls the getter to load the surface data bytes.
///
/// True if failed, otherwise false.
public virtual bool Load()
{
Enabled = false;
// Clean data
_connectionInstigator = null;
_lastInstigatorUnderMouse = null;
var failed = RootContext.Load();
Enabled = true;
if (failed)
{
// Error
return true;
}
// Update the view from context meta
ViewCenterPosition = _context.CachedSurfaceMeta.ViewCenterPosition;
ViewScale = _context.CachedSurfaceMeta.Scale;
// End
Owner.OnSurfaceEditedChanged();
return false;
}
///
/// Saves the surface graph to bytes.
///
///
/// The method calls the setter to assign the result bytes. Sets null value if failed.
///
public virtual void Save()
{
var wasEdited = IsEdited;
// Update the current context meta
_context.CachedSurfaceMeta.ViewCenterPosition = ViewCenterPosition;
_context.CachedSurfaceMeta.Scale = ViewScale;
// Save context (and every modified child context)
bool failed = RootContext.Save();
if (failed)
{
// Error
return;
}
// Clear flag
if (wasEdited)
{
Owner.OnSurfaceEditedChanged();
}
}
}
}