Advertisement
Guest User

sledge_mxd_2014.04.09

a guest
Apr 9th, 2014
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Index: Sledge.Editor/Documents/DocumentSubscriptions.cs
  2. ===================================================================
  3. --- Sledge.Editor/Documents/DocumentSubscriptions.cs    (revision 489)
  4. +++ Sledge.Editor/Documents/DocumentSubscriptions.cs    (working copy)
  5. @@ -440,7 +440,7 @@
  6.                  }
  7.              }
  8.  
  9. -            var qf = new QuickForm("Select wall width").NumericUpDown("Wall width (negative to hollow outwards)", -1024, 1024, 0, 32).OkCancel();
  10. +            var qf = new QuickForm("Select wall width") { UseShortcutKeys = true } .NumericUpDown("Wall width (negative to hollow outwards)", -1024, 1024, 0, 32).OkCancel();
  11.  
  12.              decimal width;
  13.              do
  14. Index: Sledge.Editor/Rendering/Arrays/MapObjectArray.cs
  15. ===================================================================
  16. --- Sledge.Editor/Rendering/Arrays/MapObjectArray.cs    (revision 489)
  17. +++ Sledge.Editor/Rendering/Arrays/MapObjectArray.cs    (working copy)
  18. @@ -18,7 +18,8 @@
  19.      {
  20.          private const int Textured = 0;
  21.          private const int Transparent = 1;
  22. -        private const int Wireframe = 2;
  23. +        private const int BrushWireframe = 2; //mxd. Renamed
  24. +        private const int EntityWireframe = 3; //mxd
  25.  
  26.          public MapObjectArray(IEnumerable<MapObject> data)
  27.              : base(data)
  28. @@ -71,12 +72,28 @@
  29.  
  30.          public void RenderWireframe(IGraphicsContext context)
  31.          {
  32. -            foreach (var subset in GetSubsets(Wireframe))
  33. +            foreach (var subset in GetSubsets(BrushWireframe))
  34.              {
  35.                  Render(context, BeginMode.Lines, subset);
  36.              }
  37. +
  38. +            foreach (var subset in GetSubsets(EntityWireframe)) //mxd
  39. +            {
  40. +                Render(context, BeginMode.Lines, subset);
  41.          }
  42. +        }
  43.  
  44. +        //mxd
  45. +        public void RenderVertices(IGraphicsContext context)
  46. +        {
  47. +            OpenTK.Graphics.OpenGL.GL.PointSize(4.0f); //TODO: make this into setting? Restore initial value? Set during propgram startup?
  48. +            foreach (var subset in GetSubsets(BrushWireframe))
  49. +            {
  50. +                Render(context, BeginMode.Points, subset);
  51. +            }
  52. +
  53. +        }
  54. +
  55.          public void UpdatePartial(IEnumerable<MapObject> objects)
  56.          {
  57.              UpdatePartial(objects.OfType<Solid>().SelectMany(x => x.Faces));
  58. @@ -111,7 +128,7 @@
  59.              var faces = obj.OfType<Solid>().SelectMany(x => x.Faces).ToList();
  60.              var entities = obj.OfType<Entity>().Where(x => x.Children.Count == 0).ToList();
  61.  
  62. -            StartSubset(Wireframe);
  63. +            StartSubset(BrushWireframe);
  64.  
  65.              // Render solids
  66.              foreach (var group in faces.GroupBy(x => new { x.Texture.Texture, Transparent = HasTransparency(x) }))
  67. @@ -126,7 +143,7 @@
  68.                      PushOffset(face);
  69.                      var index = PushData(Convert(face));
  70.                      if (!face.Parent.IsRenderHidden3D) PushIndex(subset, index, Triangulate(face.Vertices.Count));
  71. -                    if (!face.Parent.IsRenderHidden2D) PushIndex(Wireframe, index, Linearise(face.Vertices.Count));
  72. +                    if (!face.Parent.IsRenderHidden2D) PushIndex(BrushWireframe, index, Linearise(face.Vertices.Count));
  73.  
  74.                      if (group.Key.Transparent) PushSubset(subset, face);
  75.                  }
  76. @@ -134,6 +151,9 @@
  77.                  if (!group.Key.Transparent) PushSubset(subset, group.Key.Texture);
  78.              }
  79.  
  80. +            PushSubset(BrushWireframe, (object)null); //mxd
  81. +            StartSubset(EntityWireframe); //mxd
  82. +
  83.              // Render entities
  84.              foreach (var g in entities.GroupBy(x => x.HasModel()))
  85.              {
  86. @@ -148,7 +168,7 @@
  87.                      {
  88.                          var index = PushData(Convert(face));
  89.                          if (!face.Parent.IsRenderHidden3D) PushIndex(Textured, index, Triangulate(face.Vertices.Count));
  90. -                        if (!face.Parent.IsRenderHidden2D) PushIndex(Wireframe, index, Linearise(face.Vertices.Count));
  91. +                        if (!face.Parent.IsRenderHidden2D) PushIndex(EntityWireframe, index, Linearise(face.Vertices.Count));
  92.                      }
  93.                      if (g.Key) PushSubset(Textured, entity);
  94.                  }
  95. @@ -155,7 +175,7 @@
  96.                  if (!g.Key) PushSubset(Textured, (ITexture) null);
  97.              }
  98.  
  99. -            PushSubset(Wireframe, (object)null);
  100. +            PushSubset(EntityWireframe, (object)null);
  101.          }
  102.  
  103.          private bool HasTransparency(Face face)
  104. Index: Sledge.Editor/Rendering/Helpers/EntityTextHelper.cs
  105. ===================================================================
  106. --- Sledge.Editor/Rendering/Helpers/EntityTextHelper.cs (revision 489)
  107. +++ Sledge.Editor/Rendering/Helpers/EntityTextHelper.cs (working copy)
  108. @@ -49,7 +49,10 @@
  109.              var nameProp = entityData.GetPropertyValue("targetname");
  110.              if (!String.IsNullOrWhiteSpace(nameProp)) text += ": " + nameProp;
  111.  
  112. -            _printer.Print(text, _printerFont, o.Colour, new RectangleF((float)start.X + 2, viewport.Height - (float)end.Y - _printerFont.Height - 6, viewport.Width, viewport.Height));
  113. +            var wid = _printer.Measure(text, _printerFont, new RectangleF(0, 0, viewport.Width, viewport.Height)); //mxd
  114. +            var cx = (float)(start.X + (end.X - start.X) / 2); //mxd
  115. +
  116. +            _printer.Print(text, _printerFont, o.Colour, new RectangleF(cx - wid.BoundingBox.Width / 2, viewport.Height - (float)end.Y - _printerFont.Height - 6, viewport.Width, viewport.Height));
  117.          }
  118.  
  119.          public void AfterRender2D(Viewport2D viewport)
  120. Index: Sledge.Editor/Rendering/Renderers/ModernRenderer.cs
  121. ===================================================================
  122. --- Sledge.Editor/Rendering/Renderers/ModernRenderer.cs (revision 489)
  123. +++ Sledge.Editor/Rendering/Renderers/ModernRenderer.cs (working copy)
  124. @@ -116,6 +116,7 @@
  125.              // Render wireframe (untransformed)
  126.              _mapObject2DShader.ModelView = modelView;
  127.              _array.RenderWireframe(context.Context);
  128. +            _array.RenderVertices(context.Context); //mxd
  129.              _decalArray.RenderWireframe(context.Context);
  130.  
  131.              // Render wireframe (transformed)
  132. @@ -123,6 +124,7 @@
  133.              _mapObject2DShader.SelectedOnly = true;
  134.              _mapObject2DShader.SelectedColour = new Vector4(1, 0, 0, 1);
  135.              _array.RenderWireframe(context.Context);
  136. +            _array.RenderVertices(context.Context); //mxd
  137.              _decalArray.RenderWireframe(context.Context);
  138.  
  139.              _mapObject2DShader.Unbind();
  140. Index: Sledge.Editor/Settings/SettingsForm.Designer.cs
  141. ===================================================================
  142. --- Sledge.Editor/Settings/SettingsForm.Designer.cs (revision 489)
  143. +++ Sledge.Editor/Settings/SettingsForm.Designer.cs (working copy)
  144. @@ -1969,6 +1969,7 @@
  145.              this.SelectedGameMapDirBrowse.TabIndex = 8;
  146.              this.SelectedGameMapDirBrowse.Text = "Browse...";
  147.              this.SelectedGameMapDirBrowse.UseVisualStyleBackColor = true;
  148. +            this.SelectedGameMapDirBrowse.Click += new System.EventHandler(this.SelectedGameMapDirBrowseClicked);
  149.              //
  150.              // SelectedGameAutosaveTime
  151.              //
  152. @@ -2040,6 +2041,7 @@
  153.              this.SelectedGameDiffAutosaveDirBrowse.TabIndex = 13;
  154.              this.SelectedGameDiffAutosaveDirBrowse.Text = "Browse...";
  155.              this.SelectedGameDiffAutosaveDirBrowse.UseVisualStyleBackColor = true;
  156. +            this.SelectedGameDiffAutosaveDirBrowse.Click += new System.EventHandler(this.SelectedGameDiffAutosaveDirBrowseClicked);
  157.              //
  158.              // label12
  159.              //
  160. Index: Sledge.Editor/Tools/BaseBoxTool.cs
  161. ===================================================================
  162. --- Sledge.Editor/Tools/BaseBoxTool.cs  (revision 489)
  163. +++ Sledge.Editor/Tools/BaseBoxTool.cs  (working copy)
  164. @@ -8,6 +8,7 @@
  165.  using OpenTK.Graphics.OpenGL;
  166.  using TextPrinter = OpenTK.Graphics.TextPrinter;
  167.  using TextQuality = OpenTK.Graphics.TextQuality;
  168. +using Sledge.Editor.Documents;
  169.  
  170.  namespace Sledge.Editor.Tools
  171.  {
  172. @@ -173,7 +174,7 @@
  173.              State = new BoxState();
  174.  
  175.              _printer = new TextPrinter(TextQuality.Low);
  176. -            _printerFont = new Font(FontFamily.GenericSansSerif, 18, GraphicsUnit.Pixel);
  177. +            _printerFont = new Font(FontFamily.GenericSansSerif, 12, GraphicsUnit.Pixel);
  178.          }
  179.  
  180.          protected virtual void OnBoxChanged()
  181. @@ -615,6 +616,10 @@
  182.              Coord(end.DX, end.DY, start.DZ);
  183.              Coord(start.DX, end.DY, start.DZ);
  184.              GL.End();
  185. +
  186. +            GL.LineStipple(4, 0xAAAA); //mxd
  187. +            GL.Enable(EnableCap.LineStipple); //mxd
  188. +
  189.              GL.Begin(PrimitiveType.LineLoop);
  190.              GL.Color3(GetRenderBoxColour());
  191.              Coord(start.DX, start.DY, start.DZ);
  192. @@ -622,6 +627,8 @@
  193.              Coord(end.DX, end.DY, start.DZ);
  194.              Coord(start.DX, end.DY, start.DZ);
  195.              GL.End();
  196. +
  197. +            GL.Disable(EnableCap.LineStipple); //mxd
  198.          }
  199.  
  200.          protected virtual bool ShouldRenderResizeBox(Viewport2D viewport)
  201. @@ -636,63 +643,63 @@
  202.              var width = Math.Abs(start.DX - end.DX);
  203.              var height = Math.Abs(start.DY - end.DY);
  204.              double x1, y1, x2, y2;
  205. -            var handleWidth = width / 10d;
  206. -            var handleHeight = height / 10d;
  207. +            var handleSize = (width + height) / 20d; //mxd
  208. +
  209.              switch (State.Handle)
  210.              {
  211.                  case ResizeHandle.TopLeft:
  212.                      x1 = start.DX;
  213. -                    x2 = x1 + handleWidth;
  214. -                    y1 = end.DY;
  215. -                    y2 = y1 - handleHeight;
  216. +                    x2 = x1 + handleSize;
  217. +                    y1 = end.DY - handleSize;
  218. +                    y2 = end.DY;
  219.                      break;
  220.                  case ResizeHandle.Top:
  221.                      x1 = start.DX;
  222.                      x2 = end.DX;
  223. -                    y1 = end.DY;
  224. -                    y2 = y1 - handleHeight;
  225. +                    y1 = end.DY - handleSize;
  226. +                    y2 = end.DY;
  227.                      break;
  228.                  case ResizeHandle.TopRight:
  229. -                    x1 = end.DX - handleWidth;
  230. +                    x1 = end.DX - handleSize;
  231.                      x2 = end.DX;
  232. -                    y1 = end.DY;
  233. -                    y2 = y1 - handleHeight;
  234. +                    y1 = end.DY - handleSize;
  235. +                    y2 = end.DY;
  236.                      break;
  237.                  case ResizeHandle.Left:
  238.                      x1 = start.DX;
  239. -                    x2 = x1 + handleWidth;
  240. -                    y1 = end.DY;
  241. -                    y2 = start.DY;
  242. +                    x2 = x1 + handleSize;
  243. +                    y1 = start.DY;
  244. +                    y2 = end.DY;
  245.                      break;
  246.                  case ResizeHandle.Center:
  247.                      x1 = start.DX;
  248.                      x2 = end.DX;
  249. -                    y1 = end.DY;
  250. -                    y2 = start.DY;
  251. +                    y1 = start.DY;
  252. +                    y2 = end.DY;
  253.                      break;
  254.                  case ResizeHandle.Right:
  255. -                    x1 = end.DX - handleWidth;
  256. +                    x1 = end.DX - handleSize;
  257.                      x2 = end.DX;
  258. -                    y1 = end.DY;
  259. -                    y2 = start.DY;
  260. +                    y1 = start.DY;
  261. +                    y2 = end.DY;
  262.                      break;
  263.                  case ResizeHandle.BottomLeft:
  264.                      x1 = start.DX;
  265. -                    x2 = x1 + handleWidth;
  266. +                    x2 = x1 + handleSize;
  267.                      y1 = start.DY;
  268. -                    y2 = y1 + handleHeight;
  269. +                    y2 = y1 + handleSize;
  270.                      break;
  271.                  case ResizeHandle.Bottom:
  272.                      x1 = start.DX;
  273.                      x2 = end.DX;
  274.                      y1 = start.DY;
  275. -                    y2 = y1 + handleHeight;
  276. +                    y2 = y1 + handleSize;
  277.                      break;
  278.                  case ResizeHandle.BottomRight:
  279. -                    x1 = end.DX - handleWidth;
  280. +                    x1 = end.DX - handleSize;
  281.                      x2 = end.DX;
  282.                      y1 = start.DY;
  283. -                    y2 = y1 + handleHeight;
  284. +                    y2 = y1 + handleSize;
  285.                      break;
  286.                  default:
  287.                      throw new ArgumentOutOfRangeException();
  288. @@ -713,12 +720,18 @@
  289.              GL.End();
  290.          }
  291.  
  292. +        //mxd
  293.          protected void RenderBoxText(Viewport2D viewport, Coordinate boxStart, Coordinate boxEnd)
  294.          {
  295. +            RenderBoxText(viewport, boxStart, boxEnd, (float)HandleWidth);
  296. +        }
  297. +
  298. +        protected void RenderBoxText(Viewport2D viewport, Coordinate boxStart, Coordinate boxEnd, float padding)
  299. +        {
  300.              if (!Sledge.Settings.View.DrawBoxText) return;
  301.  
  302. -            var widthText = (boxEnd.X - boxStart.X).ToString("0.0");
  303. -            var heightText = (boxEnd.Y - boxStart.Y).ToString("0.0");
  304. +            var widthText = (Math.Round(boxEnd.X - boxStart.X, 1)).ToString("G29");
  305. +            var heightText = (Math.Round(boxEnd.Y - boxStart.Y, 1)).ToString("G29");
  306.  
  307.              var wid = _printer.Measure(widthText, _printerFont, new RectangleF(0, 0, viewport.Width, viewport.Height));
  308.              var hei = _printer.Measure(heightText, _printerFont, new RectangleF(0, 0, viewport.Width, viewport.Height));
  309. @@ -726,11 +739,12 @@
  310.              boxStart = viewport.WorldToScreen(boxStart);
  311.              boxEnd = viewport.WorldToScreen(boxEnd);
  312.  
  313. -            var cx = (float)(boxStart.X + (boxEnd.X - boxStart.X) / 2);
  314. -            var cy = (float)(boxStart.Y + (boxEnd.Y - boxStart.Y) / 2);
  315. +            var cx = (float)(boxStart.X + ((boxEnd.X - boxStart.X) / 2));
  316. +            var cy = (float)(boxStart.Y + ((boxEnd.Y - boxStart.Y) / 2));
  317. +            var offset = (float)HandleWidth / 2;
  318.  
  319. -            var wrect = new RectangleF(cx - wid.BoundingBox.Width / 2, viewport.Height - (float)boxEnd.Y - _printerFont.Height - 15, wid.BoundingBox.Width * 1.2f, wid.BoundingBox.Height);
  320. -            var hrect = new RectangleF((float)boxEnd.X + 15, viewport.Height - cy - hei.BoundingBox.Height / 2, hei.BoundingBox.Width * 1.2f, hei.BoundingBox.Height);
  321. +            var wrect = new RectangleF(cx - wid.BoundingBox.Width / 2, viewport.Height - (float)boxEnd.Y - _printerFont.Height - padding - offset, wid.BoundingBox.Width * 1.2f, wid.BoundingBox.Height);
  322. +            var hrect = new RectangleF((float)boxEnd.X + padding + offset, viewport.Height - cy - hei.BoundingBox.Height * 0.75f, hei.BoundingBox.Width * 1.2f, hei.BoundingBox.Height);
  323.  
  324.              GL.Disable(EnableCap.CullFace);
  325.  
  326. @@ -739,7 +753,7 @@
  327.              _printer.Print(heightText, _printerFont, BoxColour, hrect);
  328.              _printer.End();
  329.  
  330. -            GL.Enable(OpenTK.Graphics.OpenGL.EnableCap.CullFace);
  331. +            GL.Enable(EnableCap.CullFace);
  332.          }
  333.  
  334.          protected virtual void Render2D(Viewport2D viewport)
  335. @@ -757,7 +771,7 @@
  336.              }
  337.              if (ShouldDrawBoxText(viewport))
  338.              {
  339. -                RenderBoxText(viewport, start, end);
  340. +                RenderBoxText(viewport, start, end, 0f);
  341.              }
  342.          }
  343.  
  344. Index: Sledge.Editor/Tools/SelectTool.cs
  345. ===================================================================
  346. --- Sledge.Editor/Tools/SelectTool.cs   (revision 489)
  347. +++ Sledge.Editor/Tools/SelectTool.cs   (working copy)
  348. @@ -296,6 +296,9 @@
  349.          #region Double Click
  350.          public override void MouseDoubleClick(ViewportBase viewport, ViewportEvent e)
  351.          {
  352. +            //mxd. Do not perform this when space is down
  353. +            if (KeyboardState.IsKeyDown(Keys.Space)) return;
  354. +            
  355.              if (WidgetAction((w, vp, ev) => w.MouseDoubleClick(vp, ev), viewport, e)) return;
  356.  
  357.              if (viewport is Viewport3D && !Document.Selection.IsEmpty() && !ObjectPropertiesDialog.IsShowing)
  358. @@ -319,9 +322,6 @@
  359.          /// <param name="e">The click event</param>
  360.          protected override void MouseDown3D(Viewport3D viewport, ViewportEvent e)
  361.          {
  362. -            // Do not perform selection if space is down
  363. -            if (KeyboardState.IsKeyDown(Keys.Space)) return;
  364. -
  365.              // First, get the ray that is cast from the clicked point along the viewport frustrum
  366.              var ray = viewport.CastRayFromScreen(e.X, e.Y);
  367.  
  368. Index: Sledge.Editor/Tools/TextureApplicationForm.cs
  369. ===================================================================
  370. --- Sledge.Editor/Tools/TextureApplicationForm.cs   (revision 489)
  371. +++ Sledge.Editor/Tools/TextureApplicationForm.cs   (working copy)
  372. @@ -503,6 +503,12 @@
  373.              }
  374.          }
  375.  
  376. +        //mxd
  377. +        private void TexturesListTextureSelected(object sender, TextureItem item)
  378. +        {
  379. +            OnTextureApply(item);
  380. +        }
  381. +
  382.          private void TreatAsOneCheckboxToggled(object sender, EventArgs e)
  383.          {
  384.              if (_freeze) return;
  385. @@ -527,5 +533,6 @@
  386.                  Mediator.Publish(HotkeysMediator.SwitchTool, HotkeyTool.Texture);
  387.              }
  388.          }
  389. +
  390.      }
  391.  }
  392. Index: Sledge.Editor/Tools/TextureApplicationForm.Designer.cs
  393. ===================================================================
  394. --- Sledge.Editor/Tools/TextureApplicationForm.Designer.cs  (revision 489)
  395. +++ Sledge.Editor/Tools/TextureApplicationForm.Designer.cs  (working copy)
  396. @@ -600,6 +600,7 @@
  397.              this.RecentTexturesList.SortDescending = false;
  398.              this.RecentTexturesList.SortOrder = Sledge.Editor.UI.TextureListPanel.TextureSortOrder.None;
  399.              this.RecentTexturesList.TabIndex = 38;
  400. +            this.RecentTexturesList.TextureSelected += new Sledge.Editor.UI.TextureListPanel.TextureSelectedEventHandler(this.TexturesListTextureSelected);
  401.              //
  402.              // SelectedTexturesList
  403.              //
  404. @@ -614,6 +615,7 @@
  405.              this.SelectedTexturesList.SortDescending = false;
  406.              this.SelectedTexturesList.SortOrder = Sledge.Editor.UI.TextureListPanel.TextureSortOrder.Name;
  407.              this.SelectedTexturesList.TabIndex = 37;
  408. +            this.SelectedTexturesList.TextureSelected += new Sledge.Editor.UI.TextureListPanel.TextureSelectedEventHandler(this.TexturesListTextureSelected);
  409.              //
  410.              // TextureApplicationForm
  411.              //
  412. Index: Sledge.Editor/UI/Camera2DViewportListener.cs
  413. ===================================================================
  414. --- Sledge.Editor/UI/Camera2DViewportListener.cs    (revision 489)
  415. +++ Sledge.Editor/UI/Camera2DViewportListener.cs    (working copy)
  416. @@ -5,6 +5,7 @@
  417.  using Sledge.DataStructures.Geometric;
  418.  using Sledge.Extensions;
  419.  using Sledge.UI;
  420. +using System.Drawing;
  421.  
  422.  namespace Sledge.Editor.UI
  423.  {
  424. @@ -29,6 +30,8 @@
  425.              if (e.KeyCode == Keys.Space)
  426.              {
  427.                  Viewport.Cursor = Cursors.Default;
  428. +                _mouseDown = null; //mxd
  429. +                Viewport.Capture = false; //mxd
  430.                  e.Handled = true;
  431.              }
  432.          }
  433. @@ -38,6 +41,9 @@
  434.              if (e.KeyCode == Keys.Space)
  435.              {
  436.                  Viewport.Cursor = Cursors.SizeAll;
  437. +                Viewport.Capture = true; //mxd
  438. +                Point p = e.Sender.PointToClient(Cursor.Position); //TODO: (mxd) Shouldn't ViewportEvent always have proper mouse location?
  439. +                _mouseDown = new Coordinate(p.X, Viewport2D.Height - p.Y, 0); //mxd
  440.                  e.Handled = true;
  441.              }
  442.              var str = e.KeyCode.ToString();
  443. @@ -67,15 +73,11 @@
  444.  
  445.          public void MouseMove(ViewportEvent e)
  446.          {
  447. -            var lmouse = Control.MouseButtons.HasFlag(MouseButtons.Left);
  448.              var mmouse = Control.MouseButtons.HasFlag(MouseButtons.Middle);
  449.              var space = KeyboardState.IsKeyDown(Keys.Space);
  450.              if (space || mmouse)
  451.              {
  452.                  Viewport.Cursor = Cursors.SizeAll;
  453. -
  454. -                if (lmouse || mmouse)
  455. -                {
  456.                      var point = new Coordinate(e.X, Viewport2D.Height - e.Y, 0);
  457.                      var difference = _mouseDown - point;
  458.                      Viewport2D.Position += difference / Viewport2D.Zoom;
  459. @@ -82,7 +84,6 @@
  460.                      _mouseDown = point;
  461.                      e.Handled = true;
  462.                  }
  463. -            }
  464.  
  465.              var pt = Viewport2D.Expand(Viewport2D.ScreenToWorld(new Coordinate(e.X, Viewport2D.Height - e.Y, 0)));
  466.              Mediator.Publish(EditorMediator.MouseCoordinatesChanged, pt);
  467. @@ -104,7 +105,7 @@
  468.  
  469.          public void MouseUp(ViewportEvent e)
  470.          {
  471. -            if ((KeyboardState.IsKeyDown(Keys.Space) && e.Button == MouseButtons.Left) || e.Button == MouseButtons.Middle) e.Handled = true;
  472. +            if (KeyboardState.IsKeyDown(Keys.Space) || e.Button == MouseButtons.Middle) e.Handled = true;
  473.              if (e.Button == MouseButtons.Middle) Viewport.Cursor = Cursors.Default;
  474.              _mouseDown = null;
  475.          }
  476. @@ -113,7 +114,7 @@
  477.  
  478.          public void MouseDown(ViewportEvent e)
  479.          {
  480. -            if ((KeyboardState.IsKeyDown(Keys.Space) && e.Button == MouseButtons.Left) || e.Button == MouseButtons.Middle) e.Handled = true;
  481. +            if (KeyboardState.IsKeyDown(Keys.Space) || e.Button == MouseButtons.Middle) e.Handled = true;
  482.              if (e.Button == MouseButtons.Middle) Viewport.Cursor = Cursors.SizeAll;
  483.              _mouseDown = new Coordinate(e.X, Viewport2D.Height - e.Y, 0);
  484.          }
  485. Index: Sledge.Editor/UI/Camera3DViewportListener.cs
  486. ===================================================================
  487. --- Sledge.Editor/UI/Camera3DViewportListener.cs    (revision 489)
  488. +++ Sledge.Editor/UI/Camera3DViewportListener.cs    (working copy)
  489. @@ -19,7 +19,6 @@
  490.          private int LastKnownX { get; set; }
  491.          private int LastKnownY { get; set; }
  492.          private bool PositionKnown { get; set; }
  493. -        private bool FreeLook { get; set; }
  494.          private bool FreeLookToggle { get; set; }
  495.          private bool CursorVisible { get; set; }
  496.          private Rectangle CursorClip { get; set; }
  497. @@ -34,7 +33,6 @@
  498.              LastKnownX = 0;
  499.              LastKnownY = 0;
  500.              PositionKnown = false;
  501. -            FreeLook = false;
  502.              FreeLookToggle = false;
  503.              CursorVisible = true;
  504.              Focus = false;
  505. @@ -76,6 +74,8 @@
  506.              IfKey(Keys.S, () => Camera.Advance(-move), ignore);
  507.              IfKey(Keys.A, () => Camera.Strafe(-move), ignore);
  508.              IfKey(Keys.D, () => Camera.Strafe(move), ignore);
  509. +            IfKey(Keys.Q, () => Camera.AscendAbs(move), ignore); //mxd
  510. +            IfKey(Keys.E, () => Camera.AscendAbs(-move), ignore); //mxd
  511.              IfKey(Keys.Right, () => Camera.Pan(-tilt), ignore);
  512.              IfKey(Keys.Left, () => Camera.Pan(tilt), ignore);
  513.              IfKey(Keys.Up, () => Camera.Tilt(-tilt), ignore);
  514. @@ -111,7 +111,7 @@
  515.  
  516.          public void Render2D()
  517.          {
  518. -            if (!Focus || !FreeLook) return;
  519. +            if (!Focus || !Camera.FreeLook) return;
  520.  
  521.              TextureHelper.Unbind();
  522.              GL.Begin(PrimitiveType.Lines);
  523. @@ -145,7 +145,7 @@
  524.              {
  525.                  SetFreeLook();
  526.              }
  527. -            if (FreeLook)
  528. +            if (Camera.FreeLook)
  529.              {
  530.                  e.Handled = true;
  531.              }
  532. @@ -154,20 +154,19 @@
  533.          private void SetFreeLook()
  534.          {
  535.              if (!Viewport.IsUnlocked(this)) return;
  536. -            FreeLook = false;
  537.              if (FreeLookToggle)
  538.              {
  539. -                FreeLook = true;
  540. +                Camera.FreeLook = true;
  541.              }
  542.              else
  543.              {
  544. -                var space = KeyboardState.IsKeyDown(Keys.Space) || ToolManager.ActiveTool is CameraTool;
  545. +                var space = KeyboardState.IsKeyDown(Keys.Space);
  546.                  var left = Control.MouseButtons.HasFlag(MouseButtons.Left);
  547.                  var right = Control.MouseButtons.HasFlag(MouseButtons.Right);
  548. -                FreeLook = space && (left || right);
  549. +                Camera.FreeLook = space || (ToolManager.ActiveTool is CameraTool && (left || right));
  550.              }
  551.  
  552. -            if (FreeLook && CursorVisible)
  553. +            if (Camera.FreeLook && CursorVisible)
  554.              {
  555.                  CursorClip = Cursor.Clip;
  556.                  Cursor.Clip = Viewport.RectangleToScreen(new Rectangle(0, 0, Viewport.Width, Viewport.Height));
  557. @@ -176,7 +175,7 @@
  558.                  Cursor.Hide();
  559.                  Viewport.AquireInputLock(this);
  560.              }
  561. -            else if (!FreeLook && !CursorVisible)
  562. +            else if (!Camera.FreeLook && !CursorVisible)
  563.              {
  564.                  Cursor.Clip = CursorClip;
  565.                  CursorClip = Rectangle.Empty;
  566. @@ -189,7 +188,7 @@
  567.  
  568.          public void KeyPress(ViewportEvent e)
  569.          {
  570. -            if (FreeLook)
  571. +            if (Camera.FreeLook)
  572.              {
  573.                  e.Handled = true;
  574.              }
  575. @@ -198,7 +197,7 @@
  576.          public void MouseMove(ViewportEvent e)
  577.          {
  578.              if (!Focus) return;
  579. -            if (PositionKnown && FreeLook)
  580. +            if (PositionKnown && Camera.FreeLook)
  581.              {
  582.                  var dx = LastKnownX - e.X;
  583.                  var dy = e.Y - LastKnownY;
  584. @@ -215,7 +214,7 @@
  585.  
  586.          private void MouseMoved(ViewportEvent e, int dx, int dy)
  587.          {
  588. -            if (!FreeLook) return;
  589. +            if (!Camera.FreeLook) return;
  590.  
  591.              var left = Control.MouseButtons.HasFlag(MouseButtons.Left);
  592.              var right = Control.MouseButtons.HasFlag(MouseButtons.Right);
  593. @@ -279,7 +278,7 @@
  594.  
  595.          public void MouseLeave(ViewportEvent e)
  596.          {
  597. -            if (FreeLook)
  598. +            if (Camera.FreeLook)
  599.              {
  600.                  LastKnownX = Viewport.Width/2;
  601.                  LastKnownY = Viewport.Height/2;
  602. Index: Sledge.Editor/UI/TextureBrowser.cs
  603. ===================================================================
  604. --- Sledge.Editor/UI/TextureBrowser.cs  (revision 489)
  605. +++ Sledge.Editor/UI/TextureBrowser.cs  (working copy)
  606. @@ -20,6 +20,20 @@
  607.              var so = GetMemory("SortBy", 0);
  608.  
  609.              InitializeComponent();
  610. +
  611. +            //mxd. Apply window position, state and size
  612. +            Point location = GetMemory("Location", Point.Empty);
  613. +            Size size = GetMemory("Size", Size.Empty);
  614. +            if (location.IsEmpty || size.IsEmpty)
  615. +            {
  616. +                this.WindowState = FormWindowState.Maximized;
  617. +            }
  618. +            else
  619. +            {
  620. +                this.Location = location;
  621. +                this.Size = size;
  622. +            }
  623. +
  624.              TextureList.TextureSelected += TextureSelected;
  625.              TextureList.SelectionChanged += SelectionChanged;
  626.              SizeCombo.SelectedIndex = 2;
  627. @@ -209,5 +223,20 @@
  628.              SetMemory("SortDescending", SortDescendingCheckbox.Checked);
  629.              TextureList.SortDescending = SortDescendingCheckbox.Checked;
  630.          }
  631. +
  632. +        //mxd. Save window size and location
  633. +        private void TextureBrowser_FormClosing(object sender, FormClosingEventArgs e)
  634. +        {
  635. +            if (this.WindowState == FormWindowState.Maximized)
  636. +            {
  637. +                SetMemory("Location", Point.Empty);
  638. +                SetMemory("Size", Size.Empty);
  639.      }
  640. +            else
  641. +            {
  642. +                SetMemory("Location", this.Location);
  643. +                SetMemory("Size", this.Size);
  644.  }
  645. +        }
  646. +    }
  647. +}
  648. Index: Sledge.Editor/UI/TextureBrowser.Designer.cs
  649. ===================================================================
  650. --- Sledge.Editor/UI/TextureBrowser.Designer.cs (revision 489)
  651. +++ Sledge.Editor/UI/TextureBrowser.Designer.cs (working copy)
  652. @@ -224,8 +224,9 @@
  653.              this.KeyPreview = true;
  654.              this.MinimizeBox = false;
  655.              this.Name = "TextureBrowser";
  656. +            this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
  657.              this.Text = "Texture Browser";
  658. -            this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
  659. +            this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.TextureBrowser_FormClosing);
  660.              this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.TextureBrowserKeyPress);
  661.              this.panel1.ResumeLayout(false);
  662.              this.panel1.PerformLayout();
  663. Index: Sledge.Graphics/Camera.cs
  664. ===================================================================
  665. --- Sledge.Graphics/Camera.cs   (revision 489)
  666. +++ Sledge.Graphics/Camera.cs   (working copy)
  667. @@ -15,6 +15,9 @@
  668.          public int FOV { get; set; }
  669.          public int ClipDistance { get; set; }
  670.  
  671. +        //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
  672. +        public bool FreeLook { get; set; }
  673. +
  674.          public Camera()
  675.          {
  676.              LookAt = new Vector3(1, 0, 0);
  677. @@ -107,6 +110,14 @@
  678.              Location += add;
  679.          }
  680.  
  681. +        //mxd. Ascend/descent in world-space
  682. +        public void AscendAbs(decimal units)
  683. +        {
  684. +            var up = new Vector3(0, 0, (float)units);
  685. +            LookAt += up;
  686. +            Location += up;
  687. +        }
  688. +
  689.          public Vector3 GetUp()
  690.          {
  691.              var temp = LookAt - Location;
  692. Index: Sledge.UI/Viewport3D.cs
  693. ===================================================================
  694. --- Sledge.UI/Viewport3D.cs (revision 489)
  695. +++ Sledge.UI/Viewport3D.cs (working copy)
  696. @@ -49,7 +49,11 @@
  697.  
  698.          public override void FocusOn(Box box)
  699.          {
  700. -            FocusOn(box.Center, Coordinate.UnitY * -box.Length);
  701. +            decimal dist = System.Math.Max(System.Math.Max(box.Width, box.Length), box.Height); //mxd
  702. +            Vector3 normal = Camera.Location - Camera.LookAt; //mxd
  703. +            Vector v = new Vector(new Coordinate((decimal)normal.X, (decimal)normal.Y, (decimal)normal.Z), dist); //mxd
  704. +
  705. +            FocusOn(box.Center, new Coordinate((decimal)v.X, (decimal)v.Y, (decimal)v.Z)); //mxd
  706.          }
  707.  
  708.          public override void FocusOn(Coordinate coordinate)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement