Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: Sledge.Editor/UI/Camera2DViewportListener.cs
- ===================================================================
- --- Sledge.Editor/UI/Camera2DViewportListener.cs (revision 477)
- +++ Sledge.Editor/UI/Camera2DViewportListener.cs (working copy)
- @@ -5,6 +5,7 @@
- using Sledge.DataStructures.Geometric;
- using Sledge.Extensions;
- using Sledge.UI;
- +using System.Drawing;
- namespace Sledge.Editor.UI
- {
- @@ -29,6 +30,8 @@
- if (e.KeyCode == Keys.Space)
- {
- Viewport.Cursor = Cursors.Default;
- + _mouseDown = null; //mxd
- + Viewport.Capture = false; //mxd
- e.Handled = true;
- }
- }
- @@ -38,6 +41,9 @@
- if (e.KeyCode == Keys.Space)
- {
- Viewport.Cursor = Cursors.SizeAll;
- + Viewport.Capture = true; //mxd
- + Point p = e.Sender.PointToClient(Cursor.Position); //TODO: (mxd) Shouldn't ViewportEvent always have proper mouse location?
- + _mouseDown = new Coordinate(p.X, Viewport2D.Height - p.Y, 0); //mxd
- e.Handled = true;
- }
- var str = e.KeyCode.ToString();
- @@ -67,15 +73,11 @@
- public void MouseMove(ViewportEvent e)
- {
- - var lmouse = Control.MouseButtons.HasFlag(MouseButtons.Left);
- var mmouse = Control.MouseButtons.HasFlag(MouseButtons.Middle);
- var space = KeyboardState.IsKeyDown(Keys.Space);
- if (space || mmouse)
- {
- Viewport.Cursor = Cursors.SizeAll;
- -
- - if (lmouse || mmouse)
- - {
- var point = new Coordinate(e.X, Viewport2D.Height - e.Y, 0);
- var difference = _mouseDown - point;
- Viewport2D.Position += difference / Viewport2D.Zoom;
- @@ -82,7 +84,6 @@
- _mouseDown = point;
- e.Handled = true;
- }
- - }
- var pt = Viewport2D.Expand(Viewport2D.ScreenToWorld(new Coordinate(e.X, Viewport2D.Height - e.Y, 0)));
- Mediator.Publish(EditorMediator.MouseCoordinatesChanged, pt);
- @@ -104,7 +105,7 @@
- public void MouseUp(ViewportEvent e)
- {
- - if ((KeyboardState.IsKeyDown(Keys.Space) && e.Button == MouseButtons.Left) || e.Button == MouseButtons.Middle) e.Handled = true;
- + if (KeyboardState.IsKeyDown(Keys.Space) || e.Button == MouseButtons.Middle) e.Handled = true;
- if (e.Button == MouseButtons.Middle) Viewport.Cursor = Cursors.Default;
- _mouseDown = null;
- }
- @@ -113,7 +114,7 @@
- public void MouseDown(ViewportEvent e)
- {
- - if ((KeyboardState.IsKeyDown(Keys.Space) && e.Button == MouseButtons.Left) || e.Button == MouseButtons.Middle) e.Handled = true;
- + if (KeyboardState.IsKeyDown(Keys.Space) || e.Button == MouseButtons.Middle) e.Handled = true;
- if (e.Button == MouseButtons.Middle) Viewport.Cursor = Cursors.SizeAll;
- _mouseDown = new Coordinate(e.X, Viewport2D.Height - e.Y, 0);
- }
- Index: Sledge.Editor/UI/Camera3DViewportListener.cs
- ===================================================================
- --- Sledge.Editor/UI/Camera3DViewportListener.cs (revision 477)
- +++ Sledge.Editor/UI/Camera3DViewportListener.cs (working copy)
- @@ -19,7 +19,6 @@
- private int LastKnownX { get; set; }
- private int LastKnownY { get; set; }
- private bool PositionKnown { get; set; }
- - private bool FreeLook { get; set; }
- private bool FreeLookToggle { get; set; }
- private bool CursorVisible { get; set; }
- private Rectangle CursorClip { get; set; }
- @@ -34,7 +33,6 @@
- LastKnownX = 0;
- LastKnownY = 0;
- PositionKnown = false;
- - FreeLook = false;
- FreeLookToggle = false;
- CursorVisible = true;
- Focus = false;
- @@ -76,6 +74,8 @@
- IfKey(Keys.S, () => Camera.Advance(-move), ignore);
- IfKey(Keys.A, () => Camera.Strafe(-move), ignore);
- IfKey(Keys.D, () => Camera.Strafe(move), ignore);
- + IfKey(Keys.Q, () => Camera.AscendAbs(move), ignore); //mxd
- + IfKey(Keys.E, () => Camera.AscendAbs(-move), ignore); //mxd
- IfKey(Keys.Right, () => Camera.Pan(-tilt), ignore);
- IfKey(Keys.Left, () => Camera.Pan(tilt), ignore);
- IfKey(Keys.Up, () => Camera.Tilt(-tilt), ignore);
- @@ -111,7 +111,7 @@
- public void Render2D()
- {
- - if (!Focus || !FreeLook) return;
- + if (!Focus || !Camera.FreeLook) return;
- TextureHelper.Unbind();
- GL.Begin(PrimitiveType.Lines);
- @@ -145,7 +145,7 @@
- {
- SetFreeLook();
- }
- - if (FreeLook)
- + if (Camera.FreeLook)
- {
- e.Handled = true;
- }
- @@ -154,20 +154,19 @@
- private void SetFreeLook()
- {
- if (!Viewport.IsUnlocked(this)) return;
- - FreeLook = false;
- if (FreeLookToggle)
- {
- - FreeLook = true;
- + Camera.FreeLook = true;
- }
- else
- {
- - var space = KeyboardState.IsKeyDown(Keys.Space) || ToolManager.ActiveTool is CameraTool;
- + var space = KeyboardState.IsKeyDown(Keys.Space);
- var left = Control.MouseButtons.HasFlag(MouseButtons.Left);
- var right = Control.MouseButtons.HasFlag(MouseButtons.Right);
- - FreeLook = space && (left || right);
- + Camera.FreeLook = space || (ToolManager.ActiveTool is CameraTool && (left || right));
- }
- - if (FreeLook && CursorVisible)
- + if (Camera.FreeLook && CursorVisible)
- {
- CursorClip = Cursor.Clip;
- Cursor.Clip = Viewport.RectangleToScreen(new Rectangle(0, 0, Viewport.Width, Viewport.Height));
- @@ -176,7 +175,7 @@
- Cursor.Hide();
- Viewport.AquireInputLock(this);
- }
- - else if (!FreeLook && !CursorVisible)
- + else if (!Camera.FreeLook && !CursorVisible)
- {
- Cursor.Clip = CursorClip;
- CursorClip = Rectangle.Empty;
- @@ -189,7 +188,7 @@
- public void KeyPress(ViewportEvent e)
- {
- - if (FreeLook)
- + if (Camera.FreeLook)
- {
- e.Handled = true;
- }
- @@ -198,7 +197,7 @@
- public void MouseMove(ViewportEvent e)
- {
- if (!Focus) return;
- - if (PositionKnown && FreeLook)
- + if (PositionKnown && Camera.FreeLook)
- {
- var dx = LastKnownX - e.X;
- var dy = e.Y - LastKnownY;
- @@ -215,7 +214,7 @@
- private void MouseMoved(ViewportEvent e, int dx, int dy)
- {
- - if (!FreeLook) return;
- + if (!Camera.FreeLook) return;
- var left = Control.MouseButtons.HasFlag(MouseButtons.Left);
- var right = Control.MouseButtons.HasFlag(MouseButtons.Right);
- @@ -279,7 +278,7 @@
- public void MouseLeave(ViewportEvent e)
- {
- - if (FreeLook)
- + if (Camera.FreeLook)
- {
- LastKnownX = Viewport.Width/2;
- LastKnownY = Viewport.Height/2;
- Index: Sledge.Editor/UI/TextureBrowser.cs
- ===================================================================
- --- Sledge.Editor/UI/TextureBrowser.cs (revision 477)
- +++ Sledge.Editor/UI/TextureBrowser.cs (working copy)
- @@ -20,6 +20,20 @@
- var so = GetMemory("SortBy", 0);
- InitializeComponent();
- +
- + //mxd. Apply window position, state and size
- + Point location = GetMemory("Location", Point.Empty);
- + Size size = GetMemory("Size", Size.Empty);
- + if (location.IsEmpty || size.IsEmpty)
- + {
- + this.WindowState = FormWindowState.Maximized;
- + }
- + else
- + {
- + this.Location = location;
- + this.Size = size;
- + }
- +
- TextureList.TextureSelected += TextureSelected;
- TextureList.SelectionChanged += SelectionChanged;
- SizeCombo.SelectedIndex = 2;
- @@ -209,5 +223,20 @@
- SetMemory("SortDescending", SortDescendingCheckbox.Checked);
- TextureList.SortDescending = SortDescendingCheckbox.Checked;
- }
- +
- + //mxd. Save window size and location
- + private void TextureBrowser_FormClosing(object sender, FormClosingEventArgs e)
- + {
- + if (this.WindowState == FormWindowState.Maximized)
- + {
- + SetMemory("Location", Point.Empty);
- + SetMemory("Size", Size.Empty);
- }
- + else
- + {
- + SetMemory("Location", this.Location);
- + SetMemory("Size", this.Size);
- }
- + }
- + }
- +}
- Index: Sledge.Editor/UI/TextureBrowser.Designer.cs
- ===================================================================
- --- Sledge.Editor/UI/TextureBrowser.Designer.cs (revision 477)
- +++ Sledge.Editor/UI/TextureBrowser.Designer.cs (working copy)
- @@ -224,8 +224,9 @@
- this.KeyPreview = true;
- this.MinimizeBox = false;
- this.Name = "TextureBrowser";
- + this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
- this.Text = "Texture Browser";
- - this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
- + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.TextureBrowser_FormClosing);
- this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.TextureBrowserKeyPress);
- this.panel1.ResumeLayout(false);
- this.panel1.PerformLayout();
- Index: Sledge.Graphics/Camera.cs
- ===================================================================
- --- Sledge.Graphics/Camera.cs (revision 477)
- +++ Sledge.Graphics/Camera.cs (working copy)
- @@ -15,6 +15,9 @@
- public int FOV { get; set; }
- public int ClipDistance { get; set; }
- + //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
- + public bool FreeLook { get; set; }
- +
- public Camera()
- {
- LookAt = new Vector3(1, 0, 0);
- @@ -107,6 +110,14 @@
- Location += add;
- }
- + //mxd. Ascend/descent in world-space
- + public void AscendAbs(decimal units)
- + {
- + var up = new Vector3(0, 0, (float)units);
- + LookAt += up;
- + Location += up;
- + }
- +
- public Vector3 GetUp()
- {
- var temp = LookAt - Location;
- Index: Sledge.UI/Viewport3D.cs
- ===================================================================
- --- Sledge.UI/Viewport3D.cs (revision 477)
- +++ Sledge.UI/Viewport3D.cs (working copy)
- @@ -49,7 +49,11 @@
- public override void FocusOn(Box box)
- {
- - FocusOn(box.Center, Coordinate.UnitY * -box.Length);
- + decimal dist = System.Math.Max(System.Math.Max(box.Width, box.Length), box.Height); //mxd
- + Vector3 normal = Camera.Location - Camera.LookAt; //mxd
- + Vector v = new Vector(new Coordinate((decimal)normal.X, (decimal)normal.Y, (decimal)normal.Z), dist); //mxd
- +
- + FocusOn(box.Center, new Coordinate((decimal)v.X, (decimal)v.Y, (decimal)v.Z)); //mxd
- }
- public override void FocusOn(Coordinate coordinate)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement