Files
UnrealEngineUWP/Engine/Source/Editor/MainFrame/Private/Frame/RootWindowLocation.h
Andrew Rodham 8ff0d8b98b Added config migration path for newer versions of the engine.
Newly installed versions of the engine will now attempt to copy the project-agnostic config settings from a previous engine installation. This happens by way of a versioned manifest that copies old versions when the manifest does not exist, or is a different version. This code path is benign for non-installed versions of the engine (or FPaths::ShouldSaveToUserDir() is false).

EditorGameAgnosticSettings and EditorUserSettings ini paths have been renamed to EditorSettings and EditorPerProjectUserSettings respectively to better convey their purpose. In general, most settings should be saved in EditorSettings (project-agnostic) so that they apply regardless of which project is open. We have some way to go migrating existing settings for this to be the case, however.

Some previously per-project configuration files are now project-agnostic (such as Editor.ini, EditorKeyBindings.ini, and EditorLayout.ini)

GEditor->Access...Settings and GEditor->Get...Settings have been removed in favor of direct access of the CDO through GetMutableDefault<> and GetDefault<> respectively. Global config ini filenames that are not set up are now neither loaded nor saved on build machines, to handle the problem of indeterminate state more generically.

This addresses UETOOL-270 (Most editor preferences should be project-agnostic)

[CL 2517558 by Andrew Rodham in Main branch]
2015-04-20 10:12:55 -04:00

115 lines
3.1 KiB
C++

// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
#pragma once
/**
* Describes the position and size of the main window.
*/
struct FRootWindowLocation
{
/**
* Holds the window's position on the screen.
*/
FVector2D ScreenPosition;
/**
* Holds the size of the window.
*/
FVector2D WindowSize;
/**
* Whether the window is initially maximized.
*/
bool InitiallyMaximized;
public:
/**
* Default constructor.
*/
FRootWindowLocation( )
: WindowSize( VectorFromSettings(TEXT("WindowSize"), FVector2D(1280,720)) )
, InitiallyMaximized( BoolFromSettings(TEXT("InitiallyMaximized"), true) )
{
ScreenPosition = VectorFromSettings(TEXT("ScreenPosition"), GetCenteredScreenPosition() );
}
/**
* Creates and initializes a new instance with the specified size.
*/
FRootWindowLocation(FVector2D InWindowSize, bool InInitiallyMaximized)
: WindowSize(InWindowSize)
, InitiallyMaximized(InInitiallyMaximized)
{
ScreenPosition = GetCenteredScreenPosition();
}
/**
* Creates and initializes a new instance with the specified position and size.
*/
FRootWindowLocation( FVector2D InScreenPosition, FVector2D InWindowSize, bool InInitiallyMaximized )
: ScreenPosition( InScreenPosition )
, WindowSize( InWindowSize )
, InitiallyMaximized( InInitiallyMaximized )
{ }
public:
/**
* Set centered screen position based on the size
*/
FVector2D GetCenteredScreenPosition() const
{
// Find the default centered screen position
FDisplayMetrics DisplayMetrics;
FSlateApplication::Get().GetDisplayMetrics(DisplayMetrics);
const FVector2D DisplayTopLeft(DisplayMetrics.PrimaryDisplayWorkAreaRect.Left, DisplayMetrics.PrimaryDisplayWorkAreaRect.Top);
const FVector2D DisplaySize(DisplayMetrics.PrimaryDisplayWorkAreaRect.Right - DisplayMetrics.PrimaryDisplayWorkAreaRect.Left,
DisplayMetrics.PrimaryDisplayWorkAreaRect.Bottom - DisplayMetrics.PrimaryDisplayWorkAreaRect.Top);
return DisplayTopLeft + (DisplaySize - WindowSize) * 0.5f;
}
/**
* Saves this structure to the INI file.
*/
void SaveToIni( )
{
GConfig->SetString( TEXT("RootWindow"), TEXT("ScreenPosition"), *ScreenPosition.ToString(), GEditorPerProjectIni );
GConfig->SetString( TEXT("RootWindow"), TEXT("WindowSize"), *WindowSize.ToString(), GEditorPerProjectIni );
GConfig->SetBool( TEXT("RootWindow"), TEXT("InitiallyMaximized"), InitiallyMaximized, GEditorPerProjectIni );
}
private:
static FVector2D VectorFromSettings( const TCHAR* SettingName, FVector2D DefaultValue )
{
FVector2D ReturnValue = DefaultValue;
FString ValueAsString;
if ( GConfig->GetString(TEXT("RootWindow"), SettingName, ValueAsString, GEditorPerProjectIni) && ReturnValue.InitFromString(ValueAsString) )
{
// Successfully loaded setting
return ReturnValue;
}
else
{
return DefaultValue;
}
}
static bool BoolFromSettings( const TCHAR* SettingName, bool DefaultValue )
{
bool ReturnValue;
if ( GConfig->GetBool(TEXT("RootWindow"), SettingName, ReturnValue, GEditorPerProjectIni) )
{
return ReturnValue;
}
else
{
return DefaultValue;
}
}
};