Advertisement
Guest User

sledge_mxd_2013.04.03.patch

a guest
Apr 4th, 2014
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 11.77 KB | None | 0 0
  1. Index: Sledge.Editor/UI/Camera2DViewportListener.cs
  2. ===================================================================
  3. --- Sledge.Editor/UI/Camera2DViewportListener.cs    (revision 477)
  4. +++ Sledge.Editor/UI/Camera2DViewportListener.cs    (working copy)
  5. @@ -5,6 +5,7 @@
  6.  using Sledge.DataStructures.Geometric;
  7.  using Sledge.Extensions;
  8.  using Sledge.UI;
  9. +using System.Drawing;
  10.  
  11.  namespace Sledge.Editor.UI
  12.  {
  13. @@ -29,6 +30,8 @@
  14.              if (e.KeyCode == Keys.Space)
  15.              {
  16.                  Viewport.Cursor = Cursors.Default;
  17. +                _mouseDown = null; //mxd
  18. +                Viewport.Capture = false; //mxd
  19.                  e.Handled = true;
  20.              }
  21.          }
  22. @@ -38,6 +41,9 @@
  23.              if (e.KeyCode == Keys.Space)
  24.              {
  25.                  Viewport.Cursor = Cursors.SizeAll;
  26. +                Viewport.Capture = true; //mxd
  27. +                Point p = e.Sender.PointToClient(Cursor.Position); //TODO: (mxd) Shouldn't ViewportEvent always have proper mouse location?
  28. +                _mouseDown = new Coordinate(p.X, Viewport2D.Height - p.Y, 0); //mxd
  29.                  e.Handled = true;
  30.              }
  31.              var str = e.KeyCode.ToString();
  32. @@ -67,15 +73,11 @@
  33.  
  34.          public void MouseMove(ViewportEvent e)
  35.          {
  36. -            var lmouse = Control.MouseButtons.HasFlag(MouseButtons.Left);
  37.              var mmouse = Control.MouseButtons.HasFlag(MouseButtons.Middle);
  38.              var space = KeyboardState.IsKeyDown(Keys.Space);
  39.              if (space || mmouse)
  40.              {
  41.                  Viewport.Cursor = Cursors.SizeAll;
  42. -
  43. -                if (lmouse || mmouse)
  44. -                {
  45.                      var point = new Coordinate(e.X, Viewport2D.Height - e.Y, 0);
  46.                      var difference = _mouseDown - point;
  47.                      Viewport2D.Position += difference / Viewport2D.Zoom;
  48. @@ -82,7 +84,6 @@
  49.                      _mouseDown = point;
  50.                      e.Handled = true;
  51.                  }
  52. -            }
  53.  
  54.              var pt = Viewport2D.Expand(Viewport2D.ScreenToWorld(new Coordinate(e.X, Viewport2D.Height - e.Y, 0)));
  55.              Mediator.Publish(EditorMediator.MouseCoordinatesChanged, pt);
  56. @@ -104,7 +105,7 @@
  57.  
  58.          public void MouseUp(ViewportEvent e)
  59.          {
  60. -            if ((KeyboardState.IsKeyDown(Keys.Space) && e.Button == MouseButtons.Left) || e.Button == MouseButtons.Middle) e.Handled = true;
  61. +            if (KeyboardState.IsKeyDown(Keys.Space) || e.Button == MouseButtons.Middle) e.Handled = true;
  62.              if (e.Button == MouseButtons.Middle) Viewport.Cursor = Cursors.Default;
  63.              _mouseDown = null;
  64.          }
  65. @@ -113,7 +114,7 @@
  66.  
  67.          public void MouseDown(ViewportEvent e)
  68.          {
  69. -            if ((KeyboardState.IsKeyDown(Keys.Space) && e.Button == MouseButtons.Left) || e.Button == MouseButtons.Middle) e.Handled = true;
  70. +            if (KeyboardState.IsKeyDown(Keys.Space) || e.Button == MouseButtons.Middle) e.Handled = true;
  71.              if (e.Button == MouseButtons.Middle) Viewport.Cursor = Cursors.SizeAll;
  72.              _mouseDown = new Coordinate(e.X, Viewport2D.Height - e.Y, 0);
  73.          }
  74. Index: Sledge.Editor/UI/Camera3DViewportListener.cs
  75. ===================================================================
  76. --- Sledge.Editor/UI/Camera3DViewportListener.cs    (revision 477)
  77. +++ Sledge.Editor/UI/Camera3DViewportListener.cs    (working copy)
  78. @@ -19,7 +19,6 @@
  79.          private int LastKnownX { get; set; }
  80.          private int LastKnownY { get; set; }
  81.          private bool PositionKnown { get; set; }
  82. -        private bool FreeLook { get; set; }
  83.          private bool FreeLookToggle { get; set; }
  84.          private bool CursorVisible { get; set; }
  85.          private Rectangle CursorClip { get; set; }
  86. @@ -34,7 +33,6 @@
  87.              LastKnownX = 0;
  88.              LastKnownY = 0;
  89.              PositionKnown = false;
  90. -            FreeLook = false;
  91.              FreeLookToggle = false;
  92.              CursorVisible = true;
  93.              Focus = false;
  94. @@ -76,6 +74,8 @@
  95.              IfKey(Keys.S, () => Camera.Advance(-move), ignore);
  96.              IfKey(Keys.A, () => Camera.Strafe(-move), ignore);
  97.              IfKey(Keys.D, () => Camera.Strafe(move), ignore);
  98. +            IfKey(Keys.Q, () => Camera.AscendAbs(move), ignore); //mxd
  99. +            IfKey(Keys.E, () => Camera.AscendAbs(-move), ignore); //mxd
  100.              IfKey(Keys.Right, () => Camera.Pan(-tilt), ignore);
  101.              IfKey(Keys.Left, () => Camera.Pan(tilt), ignore);
  102.              IfKey(Keys.Up, () => Camera.Tilt(-tilt), ignore);
  103. @@ -111,7 +111,7 @@
  104.  
  105.          public void Render2D()
  106.          {
  107. -            if (!Focus || !FreeLook) return;
  108. +            if (!Focus || !Camera.FreeLook) return;
  109.  
  110.              TextureHelper.Unbind();
  111.              GL.Begin(PrimitiveType.Lines);
  112. @@ -145,7 +145,7 @@
  113.              {
  114.                  SetFreeLook();
  115.              }
  116. -            if (FreeLook)
  117. +            if (Camera.FreeLook)
  118.              {
  119.                  e.Handled = true;
  120.              }
  121. @@ -154,20 +154,19 @@
  122.          private void SetFreeLook()
  123.          {
  124.              if (!Viewport.IsUnlocked(this)) return;
  125. -            FreeLook = false;
  126.              if (FreeLookToggle)
  127.              {
  128. -                FreeLook = true;
  129. +                Camera.FreeLook = true;
  130.              }
  131.              else
  132.              {
  133. -                var space = KeyboardState.IsKeyDown(Keys.Space) || ToolManager.ActiveTool is CameraTool;
  134. +                var space = KeyboardState.IsKeyDown(Keys.Space);
  135.                  var left = Control.MouseButtons.HasFlag(MouseButtons.Left);
  136.                  var right = Control.MouseButtons.HasFlag(MouseButtons.Right);
  137. -                FreeLook = space && (left || right);
  138. +                Camera.FreeLook = space || (ToolManager.ActiveTool is CameraTool && (left || right));
  139.              }
  140.  
  141. -            if (FreeLook && CursorVisible)
  142. +            if (Camera.FreeLook && CursorVisible)
  143.              {
  144.                  CursorClip = Cursor.Clip;
  145.                  Cursor.Clip = Viewport.RectangleToScreen(new Rectangle(0, 0, Viewport.Width, Viewport.Height));
  146. @@ -176,7 +175,7 @@
  147.                  Cursor.Hide();
  148.                  Viewport.AquireInputLock(this);
  149.              }
  150. -            else if (!FreeLook && !CursorVisible)
  151. +            else if (!Camera.FreeLook && !CursorVisible)
  152.              {
  153.                  Cursor.Clip = CursorClip;
  154.                  CursorClip = Rectangle.Empty;
  155. @@ -189,7 +188,7 @@
  156.  
  157.          public void KeyPress(ViewportEvent e)
  158.          {
  159. -            if (FreeLook)
  160. +            if (Camera.FreeLook)
  161.              {
  162.                  e.Handled = true;
  163.              }
  164. @@ -198,7 +197,7 @@
  165.          public void MouseMove(ViewportEvent e)
  166.          {
  167.              if (!Focus) return;
  168. -            if (PositionKnown && FreeLook)
  169. +            if (PositionKnown && Camera.FreeLook)
  170.              {
  171.                  var dx = LastKnownX - e.X;
  172.                  var dy = e.Y - LastKnownY;
  173. @@ -215,7 +214,7 @@
  174.  
  175.          private void MouseMoved(ViewportEvent e, int dx, int dy)
  176.          {
  177. -            if (!FreeLook) return;
  178. +            if (!Camera.FreeLook) return;
  179.  
  180.              var left = Control.MouseButtons.HasFlag(MouseButtons.Left);
  181.              var right = Control.MouseButtons.HasFlag(MouseButtons.Right);
  182. @@ -279,7 +278,7 @@
  183.  
  184.          public void MouseLeave(ViewportEvent e)
  185.          {
  186. -            if (FreeLook)
  187. +            if (Camera.FreeLook)
  188.              {
  189.                  LastKnownX = Viewport.Width/2;
  190.                  LastKnownY = Viewport.Height/2;
  191. Index: Sledge.Editor/UI/TextureBrowser.cs
  192. ===================================================================
  193. --- Sledge.Editor/UI/TextureBrowser.cs  (revision 477)
  194. +++ Sledge.Editor/UI/TextureBrowser.cs  (working copy)
  195. @@ -20,6 +20,20 @@
  196.              var so = GetMemory("SortBy", 0);
  197.  
  198.              InitializeComponent();
  199. +
  200. +            //mxd. Apply window position, state and size
  201. +            Point location = GetMemory("Location", Point.Empty);
  202. +            Size size = GetMemory("Size", Size.Empty);
  203. +            if (location.IsEmpty || size.IsEmpty)
  204. +            {
  205. +                this.WindowState = FormWindowState.Maximized;
  206. +            }
  207. +            else
  208. +            {
  209. +                this.Location = location;
  210. +                this.Size = size;
  211. +            }
  212. +
  213.              TextureList.TextureSelected += TextureSelected;
  214.              TextureList.SelectionChanged += SelectionChanged;
  215.              SizeCombo.SelectedIndex = 2;
  216. @@ -209,5 +223,20 @@
  217.              SetMemory("SortDescending", SortDescendingCheckbox.Checked);
  218.              TextureList.SortDescending = SortDescendingCheckbox.Checked;
  219.          }
  220. +
  221. +        //mxd. Save window size and location
  222. +        private void TextureBrowser_FormClosing(object sender, FormClosingEventArgs e)
  223. +        {
  224. +            if (this.WindowState == FormWindowState.Maximized)
  225. +            {
  226. +                SetMemory("Location", Point.Empty);
  227. +                SetMemory("Size", Size.Empty);
  228.      }
  229. +            else
  230. +            {
  231. +                SetMemory("Location", this.Location);
  232. +                SetMemory("Size", this.Size);
  233.  }
  234. +        }
  235. +    }
  236. +}
  237. Index: Sledge.Editor/UI/TextureBrowser.Designer.cs
  238. ===================================================================
  239. --- Sledge.Editor/UI/TextureBrowser.Designer.cs (revision 477)
  240. +++ Sledge.Editor/UI/TextureBrowser.Designer.cs (working copy)
  241. @@ -224,8 +224,9 @@
  242.              this.KeyPreview = true;
  243.              this.MinimizeBox = false;
  244.              this.Name = "TextureBrowser";
  245. +            this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
  246.              this.Text = "Texture Browser";
  247. -            this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
  248. +            this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.TextureBrowser_FormClosing);
  249.              this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.TextureBrowserKeyPress);
  250.              this.panel1.ResumeLayout(false);
  251.              this.panel1.PerformLayout();
  252. Index: Sledge.Graphics/Camera.cs
  253. ===================================================================
  254. --- Sledge.Graphics/Camera.cs   (revision 477)
  255. +++ Sledge.Graphics/Camera.cs   (working copy)
  256. @@ -15,6 +15,9 @@
  257.          public int FOV { get; set; }
  258.          public int ClipDistance { get; set; }
  259.  
  260. +        //mxd. I don't think that's the proper way to handle this, but I don't see an easy way to get to Camera3DViewportListener from a Tool
  261. +        public bool FreeLook { get; set; }
  262. +
  263.          public Camera()
  264.          {
  265.              LookAt = new Vector3(1, 0, 0);
  266. @@ -107,6 +110,14 @@
  267.              Location += add;
  268.          }
  269.  
  270. +        //mxd. Ascend/descent in world-space
  271. +        public void AscendAbs(decimal units)
  272. +        {
  273. +            var up = new Vector3(0, 0, (float)units);
  274. +            LookAt += up;
  275. +            Location += up;
  276. +        }
  277. +
  278.          public Vector3 GetUp()
  279.          {
  280.              var temp = LookAt - Location;
  281. Index: Sledge.UI/Viewport3D.cs
  282. ===================================================================
  283. --- Sledge.UI/Viewport3D.cs (revision 477)
  284. +++ Sledge.UI/Viewport3D.cs (working copy)
  285. @@ -49,7 +49,11 @@
  286.  
  287.          public override void FocusOn(Box box)
  288.          {
  289. -            FocusOn(box.Center, Coordinate.UnitY * -box.Length);
  290. +            decimal dist = System.Math.Max(System.Math.Max(box.Width, box.Length), box.Height); //mxd
  291. +            Vector3 normal = Camera.Location - Camera.LookAt; //mxd
  292. +            Vector v = new Vector(new Coordinate((decimal)normal.X, (decimal)normal.Y, (decimal)normal.Z), dist); //mxd
  293. +
  294. +            FocusOn(box.Center, new Coordinate((decimal)v.X, (decimal)v.Y, (decimal)v.Z)); //mxd
  295.          }
  296.  
  297.          public override void FocusOn(Coordinate coordinate)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement