Bladeren bron

Main camera aspect ratio switching works

BearishSun 10 jaren geleden
bovenliggende
commit
4356e8e773
4 gewijzigde bestanden met toevoegingen van 37 en 10 verwijderingen
  1. 1 1
      MBansheeEditor/ConsoleWindow.cs
  2. 31 6
      MBansheeEditor/GameWindow.cs
  3. 2 1
      MBansheeEngine/Color.cs
  4. 3 2
      TODO.txt

+ 1 - 1
MBansheeEditor/ConsoleWindow.cs

@@ -338,7 +338,7 @@ namespace BansheeEditor
             private const int CALLER_LABEL_HEIGHT = 11;
             private const int PADDING = 3;
             private const int MESSAGE_HEIGHT = ENTRY_HEIGHT - CALLER_LABEL_HEIGHT - PADDING * 2;
-            private static readonly Color BG_COLOR = Color.DarkGray;
+            private static readonly Color BG_COLOR = Color.LightGray;
             private static readonly Color SELECTION_COLOR = Color.DarkCyan;
 
             private GUIPanel overlay;

+ 31 - 6
MBansheeEditor/GameWindow.cs

@@ -8,6 +8,7 @@ namespace BansheeEditor
     public class GameWindow : EditorWindow
     {
         private const int HeaderHeight = 20;
+        private static readonly Color BG_COLOR = Color.DarkGray;
         private readonly AspectRatio[] aspectRatios =
         {
             new AspectRatio(16, 9), 
@@ -19,6 +20,7 @@ namespace BansheeEditor
 
         private int selectedAspectRatio = 0;
         private GUIRenderTexture renderTextureGUI;
+        private GUITexture renderTextureBg;
         private GUILabel noCameraLabel;
 
         /// <summary>
@@ -79,7 +81,7 @@ namespace BansheeEditor
             for (int i = 0; i < aspectRatios.Length; i++)
                 aspectRatioTitles[i + 1] = aspectRatios[i].width + ":" + aspectRatios[i].height;
 
-            GUIListBoxField aspectField = new GUIListBoxField(aspectRatioTitles, new LocEdString("Aspect ratio"), 100, GUIOption.FixedWidth(300));
+            GUIListBoxField aspectField = new GUIListBoxField(aspectRatioTitles, new LocEdString("Aspect ratio"));
             aspectField.OnSelectionChanged += OnAspectRatioChanged;
             
             GUILayoutY buttonLayoutVert = mainLayout.AddLayoutY();
@@ -89,11 +91,17 @@ namespace BansheeEditor
             buttonLayoutVert.AddFlexibleSpace();
 
             renderTextureGUI = new GUIRenderTexture(null);
+            renderTextureBg = new GUITexture(Builtin.WhiteTexture);
+            renderTextureBg.SetTint(BG_COLOR);
+
             noCameraLabel = new GUILabel(new LocEdString("(No main camera in scene)"));
 
             GUIPanel rtPanel = mainLayout.AddPanel();
             rtPanel.AddElement(renderTextureGUI);
 
+            GUIPanel bgPanel = rtPanel.AddPanel(1);
+            bgPanel.AddElement(renderTextureBg);
+
             GUILayoutY alignLayoutY = rtPanel.AddLayoutY();
             alignLayoutY.AddFlexibleSpace();
             GUILayoutX alignLayoutX = alignLayoutY.AddLayoutX();
@@ -131,24 +139,41 @@ namespace BansheeEditor
         /// <param name="height">Height of the scene render target, in pixels.</param>
         private void UpdateRenderTexture(int width, int height)
         {
-            width = MathEx.Max(20, width);
-            height = MathEx.Max(20, height - HeaderHeight);
+            height = height - HeaderHeight;
+
+            int rtWidth = MathEx.Max(20, width);
+            int rtHeight = MathEx.Max(20, height);
 
             if (selectedAspectRatio != 0) // 0 is free aspect
             {
                 AspectRatio aspectRatio = aspectRatios[selectedAspectRatio - 1];
 
+                int visibleAreaHeight = rtHeight;
+
                 float aspectInv = aspectRatio.height/(float)aspectRatio.width;
-                height = MathEx.RoundToInt(width*aspectInv);
+                rtHeight = MathEx.RoundToInt(rtWidth*aspectInv);
+
+                if (rtHeight > visibleAreaHeight)
+                {
+                    rtHeight = visibleAreaHeight;
+                    float aspect = aspectRatio.width / (float)aspectRatio.height;
+                    rtWidth = MathEx.RoundToInt(rtHeight * aspect);
+                }
             }
 
-            RenderTexture2D renderTexture = new RenderTexture2D(PixelFormat.R8G8B8A8, width, height) {Priority = 1};
+            RenderTexture2D renderTexture = new RenderTexture2D(PixelFormat.R8G8B8A8, rtWidth, rtHeight) {Priority = 1};
 
             EditorApplication.MainRenderTarget = renderTexture;
             renderTextureGUI.RenderTexture = renderTexture;
 
-            Rect2I rtBounds = new Rect2I(0, 0, width, height);
+            int offsetX = (width - rtWidth)/2;
+            int offsetY = (height - rtHeight)/2;
+
+            Rect2I rtBounds = new Rect2I(offsetX, offsetY, rtWidth, rtHeight);
             renderTextureGUI.Bounds = rtBounds;
+
+            Rect2I bgBounds = new Rect2I(0, 0, width, height);
+            renderTextureBg.Bounds = bgBounds;
         }
 
         /// <summary>

+ 2 - 1
MBansheeEngine/Color.cs

@@ -23,7 +23,8 @@ namespace BansheeEngine
         public static Color White { get { return new Color(1.0f, 1.0f, 1.0f, 1.0f); } }
         public static Color Black { get { return new Color(0.0f, 0.0f, 0.0f, 1.0f); } }
         public static Color DarkCyan { get { return new Color(0.0f, (114.0f / 255.0f), (188.0f / 255.0f), 1.0f); } }
-        public static Color DarkGray { get { return new Color(63.0f / 255.0f, 63.0f / 255.0f, 63.0f / 255.0f, 1.0f); } }
+        public static Color DarkGray { get { return new Color(23.0f / 255.0f, 23.0f / 255.0f, 23.0f / 255.0f, 1.0f); } }
+        public static Color LightGray { get { return new Color(63.0f / 255.0f, 63.0f / 255.0f, 63.0f / 255.0f, 1.0f); } }
         public static Color BansheeOrange { get { return new Color(1.0f, (168.0f/255.0f), 0.0f, 1.0f); } }
 
         /// <summary>

+ 3 - 2
TODO.txt

@@ -21,7 +21,7 @@ Optional:
  - Undocking of editor window doesn't work (they just get lost)
  - Crash when adding a new directional light and then shutting down (also crash when just deleting a directional light)
  - Start editor in fullscreen
- - If user clears the default shader he has no way of re-assigning it - add default shader to project folder?
+ - If user clears the default shader he has no way of re-assigning it - add default shader to project folder? (needs to be packaged with project)
  - Toggle to enable/disable SceneObject in Inspector
  - Resource import options don't get saved
  - Undo/Redo
@@ -42,6 +42,8 @@ Optional:
  More optional:
  - When starting drag from hierarchy tree view it tends to select another object (can't repro)
  - Handle seems to lag behind the selected mesh
+ - When starting play-in-editor, automatically make the Game Window active
+ - Console filter icons look ugly when toggled (also message warning/info icons seem misaligned compared to each other)
  - When resizing library window while docked, selection area appears
  - Move all the code files into subfolders so their hierarchy is similar to VS filters
  - MenuBar - will likely need a way to mark elements as disabled when not appropriate (e.g. no "frame selected unless scene is focused")
@@ -55,7 +57,6 @@ Optional:
 
 Seriously optional:
  - Drag to select in scene view
- - When starting play-in-editor, automatically make the Game Window active
  - Automatically generate readable inspector names and add [Name] attribute that allows custom naming
  - Add Range[] attribute to C# that forces a float/int to be displayed as a slider
  - GUI tabbing to switch between elements