Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ SetDisplayMode()

static void Terraria.Main.SetDisplayMode ( int width,
int height,
bool fullscreen )
inlinestatic

Definition at line 63002 of file Main.cs.

63003 {
63004 bool flag = false;
63005 Form form = null;
63006 if (Platform.IsWindows)
63007 {
63008 form = (Form)Control.FromHandle(instance.Window.Handle);
63009 screenMaximized = form.WindowState == FormWindowState.Maximized;
63010 if (screenBorderless && screenMaximized && !graphics.IsFullScreen)
63011 {
63012 screenMaximized = false;
63013 form.WindowState = FormWindowState.Normal;
63014 }
63015 flag = form.FormBorderStyle == FormBorderStyle.None;
63016 }
63017 else
63018 {
63019 screenMaximized = false;
63020 }
63021 bool flag2 = false;
63022 int num3;
63023 int num4;
63024 if (screenBorderless || screenMaximized || graphics.IsFullScreen || fullscreen)
63025 {
63026 bool flag3 = false;
63028 {
63029 flag3 = true;
63030 if (!fullscreen && !graphics.IsFullScreen)
63031 {
63032 width = 1280;
63033 height = 800;
63035 }
63036 }
63037 if (Platform.IsWindows)
63038 {
63039 form.MinimumSize = new Size(0, 0);
63040 if (!fullscreen && !flag3)
63041 {
63042 SetDisplayModeAsBorderless(ref width, ref height, form);
63043 }
63044 }
63045 if (width > maxScreenW)
63046 {
63047 float num = (float)height / (float)width;
63048 width = maxScreenW;
63049 height = (int)(num * (float)width);
63050 }
63051 if (height > maxScreenH)
63052 {
63053 float num2 = (float)width / (float)height;
63054 height = maxScreenH;
63055 width = (int)(num2 * (float)height);
63056 }
63057 PlayerInput.RawMouseScale = new Vector2((float)width / (float)instance.Window.ClientBounds.Width, (float)height / (float)instance.Window.ClientBounds.Height);
63058 if (!graphics.IsFullScreen)
63059 {
63060 num3 = Math.Max(graphics.PreferredBackBufferWidth, graphics.GraphicsDevice.Viewport.Width);
63061 num4 = Math.Max(graphics.PreferredBackBufferHeight, graphics.GraphicsDevice.Viewport.Height);
63062 if (num3 != graphics.PreferredBackBufferWidth || num4 != graphics.PreferredBackBufferHeight)
63063 {
63064 flag2 = true;
63065 }
63066 }
63067 else
63068 {
63069 num3 = graphics.PreferredBackBufferWidth;
63070 num4 = graphics.PreferredBackBufferHeight;
63071 }
63072 }
63073 else
63074 {
63075 PlayerInput.RawMouseScale = Vector2.One;
63076 if (Platform.IsWindows)
63077 {
63078 form.MinimumSize = new Size(minScreenW, minScreenH);
63079 if (flag)
63080 {
63081 width = displayWidth[0];
63082 height = displayHeight[0];
63083 }
63084 }
63085 width = Math.Min(width, maxScreenW);
63086 height = Math.Min(height, maxScreenH);
63087 num3 = graphics.GraphicsDevice.Viewport.Width;
63088 num4 = graphics.GraphicsDevice.Viewport.Height;
63089 flag2 = graphics.PreferredBackBufferWidth != graphics.GraphicsDevice.Viewport.Width || graphics.PreferredBackBufferHeight != graphics.GraphicsDevice.Viewport.Height;
63090 }
63091 if (Platform.IsWindows && !fullscreen && !flag2)
63092 {
63093 if (form.ClientSize.Width < graphics.PreferredBackBufferWidth)
63094 {
63095 width = form.ClientSize.Width;
63096 flag2 = true;
63097 }
63098 if (form.ClientSize.Height < graphics.PreferredBackBufferHeight)
63099 {
63100 height = form.ClientSize.Height;
63101 flag2 = true;
63102 }
63103 }
63104 width &= 0x7FFFFFFE;
63105 height &= 0x7FFFFFFE;
63106 width = Math.Max(width, minScreenW);
63107 height = Math.Max(height, minScreenH);
63108 if (graphics.IsFullScreen != fullscreen)
63109 {
63110 graphics.PreferredBackBufferWidth = width;
63111 graphics.PreferredBackBufferHeight = height;
63112 graphics.ApplyChanges();
63113 graphics.ToggleFullScreen();
63114 }
63115 if (width != num3 || height != num4 || flag2)
63116 {
63117 mapTime = 0;
63118 if (gamePaused)
63119 {
63120 renderNow = true;
63121 }
63122 screenWidth = width;
63123 screenHeight = height;
63124 graphics.PreferredBackBufferWidth = screenWidth;
63125 graphics.PreferredBackBufferHeight = screenHeight;
63126 graphics.ApplyChanges();
63128 FixUIScale();
63129 if (Main.OnResolutionChanged != null)
63130 {
63131 Main.OnResolutionChanged(new Vector2(screenWidth, screenHeight));
63132 }
63137 {
63138 if (screenBorderless)
63139 {
63141 form.FormBorderStyle = FormBorderStyle.None;
63142 }
63143 else
63144 {
63145 form.FormBorderStyle = FormBorderStyle.Sizable;
63146 }
63147 form.SendToBack();
63148 form.BringToFront();
63149 }
63150 Lighting.Initialize();
63152 {
63154 instance.InitTargets();
63156 }
63157 UserInterface.ActiveInstance.Recalculate();
63158 instance._needsMenuUIRecalculation = true;
63159 Console.WriteLine(Language.GetTextValue("Misc.ResolutionChanged", width, height));
63160 chatMonitor.OnResolutionChange();
63161 }
63162 if (!graphics.SynchronizeWithVerticalRetrace)
63163 {
63164 graphics.SynchronizeWithVerticalRetrace = true;
63165 graphics.ApplyChanges();
63166 }
63167 }
static bool IsWindows
Definition Platform.cs:19
static void WriteLine()
Definition Console.cs:733
static byte Min(byte val1, byte val2)
Definition Math.cs:912
static byte Max(byte val1, byte val2)
Definition Math.cs:738
static void CacheOriginalScreenDimensions()
static string GetTextValue(string key)
Definition Language.cs:15
static int minScreenW
Definition Main.cs:754
static bool screenMaximized
Definition Main.cs:1723
static int minScreenH
Definition Main.cs:756
static int[] displayHeight
Definition Main.cs:1924
static bool drawToScreen
Definition Main.cs:600
static int PendingResolutionHeight
Definition Main.cs:1966
static Main instance
Definition Main.cs:283
static void FixUIScale()
Definition Main.cs:63169
static int screenHeight
Definition Main.cs:1721
static void SetDisplayModeAsBorderless(ref int width, ref int height, Form form)
Definition Main.cs:49205
static void TryPickingDefaultUIScale(float displayHeight)
Definition Main.cs:3927
static int maxScreenW
Definition Main.cs:750
static IChatMonitor chatMonitor
Definition Main.cs:2339
static bool _isResizingAndRemakingTargets
Definition Main.cs:2609
static int[] displayWidth
Definition Main.cs:1922
static bool screenBorderless
Definition Main.cs:1725
static bool renderNow
Definition Main.cs:598
static int screenWidth
Definition Main.cs:1719
static void ApplyBorderlessResolution(Form form)
Definition Main.cs:49217
static int PendingResolutionWidth
Definition Main.cs:1964
static int mapTime
Definition Main.cs:884
static bool gamePaused
Definition Main.cs:1072
static int maxScreenH
Definition Main.cs:752
static GraphicsDeviceManager graphics
Definition Main.cs:972
static UserInterface ActiveInstance

References Terraria.Main._isResizingAndRemakingTargets, Terraria.UI.UserInterface.ActiveInstance, Terraria.Main.ApplyBorderlessResolution(), Terraria.GameInput.PlayerInput.CacheOriginalScreenDimensions(), Terraria.Main.chatMonitor, System.Control, Terraria.Main.displayHeight, Terraria.Main.displayWidth, Terraria.Main.drawToScreen, Terraria.Main.FixUIScale(), Terraria.Main.gamePaused, Terraria.Localization.Language.GetTextValue(), Terraria.Main.graphics, Terraria.Lighting.Initialize(), Terraria.Main.instance, ReLogic.OS.Platform.IsWindows, Terraria.Main.mapTime, System.Math.Max(), Terraria.Main.maxScreenH, Terraria.Main.maxScreenW, System.Math.Min(), Terraria.Main.minScreenH, Terraria.Main.minScreenW, Microsoft.Xna.Framework.Vector2.One, Terraria.Main.OnResolutionChanged, Terraria.Main.PendingResolutionHeight, Terraria.Main.PendingResolutionWidth, Terraria.Main.renderNow, Terraria.Main.screenBorderless, Terraria.Main.screenHeight, Terraria.Main.screenMaximized, Terraria.Main.screenWidth, Terraria.Main.SetDisplayModeAsBorderless(), System.IO.Size, Terraria.GameInput.PlayerInput.SteamDeckIsUsed, Terraria.Main.TryPickingDefaultUIScale(), Microsoft.Xna.Framework.Graphics.Vector2, and System.Console.WriteLine().

Referenced by Terraria.Main.FullscreenStartup(), Terraria.Main.LoadSettings(), Terraria.Main.OpenLegacySettings(), Terraria.Main.SetFullScreen(), and Terraria.Main.SetResolution().