diff --git a/OpenRA.Editor/Form1.Designer.cs b/OpenRA.Editor/Form1.Designer.cs index 8bbbd0ce04..80fa8d79db 100644 --- a/OpenRA.Editor/Form1.Designer.cs +++ b/OpenRA.Editor/Form1.Designer.cs @@ -39,9 +39,6 @@ this.actorPalette = new System.Windows.Forms.FlowLayoutPanel(); this.tabPage3 = new System.Windows.Forms.TabPage(); this.resourcePalette = new System.Windows.Forms.FlowLayoutPanel(); - this.surface1 = new OpenRA.Editor.Surface(); - this.vScrollBar1 = new System.Windows.Forms.VScrollBar(); - this.hScrollBar1 = new System.Windows.Forms.HScrollBar(); this.toolStrip1 = new System.Windows.Forms.ToolStrip(); this.toolStripButton3 = new System.Windows.Forms.ToolStripButton(); this.toolStripButton5 = new System.Windows.Forms.ToolStripButton(); @@ -52,6 +49,7 @@ this.toolStripButton2 = new System.Windows.Forms.ToolStripButton(); this.tt = new System.Windows.Forms.ToolTip(this.components); this.folderBrowser = new System.Windows.Forms.FolderBrowserDialog(); + this.surface1 = new OpenRA.Editor.Surface(); this.toolStripContainer1.ContentPanel.SuspendLayout(); this.toolStripContainer1.TopToolStripPanel.SuspendLayout(); this.toolStripContainer1.SuspendLayout(); @@ -96,8 +94,6 @@ // splitContainer1.Panel2 // this.splitContainer1.Panel2.Controls.Add(this.surface1); - this.splitContainer1.Panel2.Controls.Add(this.vScrollBar1); - this.splitContainer1.Panel2.Controls.Add(this.hScrollBar1); this.splitContainer1.Size = new System.Drawing.Size(985, 680); this.splitContainer1.SplitterDistance = 198; this.splitContainer1.TabIndex = 0; @@ -115,7 +111,6 @@ this.tabControl1.SelectedIndex = 0; this.tabControl1.Size = new System.Drawing.Size(198, 680); this.tabControl1.TabIndex = 0; - this.tabControl1.Resize += new System.EventHandler(this.surface1_Resize); // // tabPage1 // @@ -179,43 +174,6 @@ this.resourcePalette.Size = new System.Drawing.Size(171, 672); this.resourcePalette.TabIndex = 3; // - // surface1 - // - this.surface1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.surface1.BackColor = System.Drawing.Color.Black; - this.surface1.Location = new System.Drawing.Point(2, 0); - this.surface1.Name = "surface1"; - this.surface1.Size = new System.Drawing.Size(763, 662); - this.surface1.TabIndex = 5; - this.surface1.Text = "surface1"; - this.surface1.Resize += new System.EventHandler(this.surface1_Resize); - // - // vScrollBar1 - // - this.vScrollBar1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Right))); - this.vScrollBar1.LargeChange = 24; - this.vScrollBar1.Location = new System.Drawing.Point(766, 0); - this.vScrollBar1.Name = "vScrollBar1"; - this.vScrollBar1.Size = new System.Drawing.Size(16, 662); - this.vScrollBar1.SmallChange = 24; - this.vScrollBar1.TabIndex = 4; - this.vScrollBar1.Scroll += new System.Windows.Forms.ScrollEventHandler(this.vScrollBar1_Scroll); - // - // hScrollBar1 - // - this.hScrollBar1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.hScrollBar1.LargeChange = 24; - this.hScrollBar1.Location = new System.Drawing.Point(0, 663); - this.hScrollBar1.Name = "hScrollBar1"; - this.hScrollBar1.Size = new System.Drawing.Size(765, 16); - this.hScrollBar1.SmallChange = 24; - this.hScrollBar1.TabIndex = 3; - this.hScrollBar1.Scroll += new System.Windows.Forms.ScrollEventHandler(this.hScrollBar1_Scroll); - // // toolStrip1 // this.toolStrip1.Dock = System.Windows.Forms.DockStyle.None; @@ -299,14 +257,27 @@ // this.tt.ShowAlways = true; // + // surface1 + // + this.surface1.BackColor = System.Drawing.Color.Black; + this.surface1.Dock = System.Windows.Forms.DockStyle.Fill; + this.surface1.Location = new System.Drawing.Point(0, 0); + this.surface1.Name = "surface1"; + this.surface1.Size = new System.Drawing.Size(783, 680); + this.surface1.TabIndex = 5; + this.surface1.Text = "surface1"; + // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(985, 705); this.Controls.Add(this.toolStripContainer1); + this.KeyPreview = true; this.Name = "Form1"; this.Text = "OpenRA Editor"; + this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.Form1_KeyUp); + this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Form1_KeyDown); this.toolStripContainer1.ContentPanel.ResumeLayout(false); this.toolStripContainer1.TopToolStripPanel.ResumeLayout(false); this.toolStripContainer1.TopToolStripPanel.PerformLayout(); @@ -346,8 +317,6 @@ private System.Windows.Forms.FolderBrowserDialog folderBrowser; private System.Windows.Forms.ToolStripButton toolStripButton6; private System.Windows.Forms.ToolStripButton toolStripButton7; - private System.Windows.Forms.VScrollBar vScrollBar1; - private System.Windows.Forms.HScrollBar hScrollBar1; private Surface surface1; } diff --git a/OpenRA.Editor/Form1.cs b/OpenRA.Editor/Form1.cs index c277ced642..16aa564407 100644 --- a/OpenRA.Editor/Form1.cs +++ b/OpenRA.Editor/Form1.cs @@ -88,9 +88,7 @@ namespace OpenRA.Editor var palette = new Palette(FileSystem.Open(map.Theater.ToLowerInvariant() + ".pal"), true); surface1.Bind(map, tileset, palette); - vScrollBar1.Maximum = map.MapSize.Y*24 - surface1.Height; - hScrollBar1.Maximum = map.MapSize.X*24 - surface1.Width; - + // construct the palette of tiles foreach (var n in tileset.tiles.Keys) @@ -148,7 +146,7 @@ namespace OpenRA.Editor info.Name, info.Category)); - actorTemplates.Add( template); + actorTemplates.Add(template); } catch { } } @@ -318,8 +316,6 @@ namespace OpenRA.Editor { surface1.Map.Resize((int)rd.width.Value, (int)rd.height.Value); surface1.Bind(surface1.Map, surface1.TileSet, surface1.Palette); // rebind it to invalidate all caches - vScrollBar1.Maximum = surface1.Map.MapSize.Y * 24 - surface1.Height; - hScrollBar1.Maximum = surface1.Map.MapSize.X * 24 - surface1.Width; } surface1.Invalidate(); @@ -329,7 +325,7 @@ namespace OpenRA.Editor void SavePreviewImage(string filepath) { var Map = surface1.Map; - + var xs = Map.TopLeft.X; var ys = Map.TopLeft.Y; @@ -367,7 +363,7 @@ namespace OpenRA.Editor folderBrowser.ShowNewFolderButton = true; if (DialogResult.OK == folderBrowser.ShowDialog()) { - + loadedMapName = folderBrowser.SelectedPath; SaveClicked(sender, e); } @@ -438,30 +434,8 @@ namespace OpenRA.Editor } } - void SpawnPointsClicked(object sender, EventArgs e) - { - surface1.SetWaypoint(new WaypointTemplate()); // hack - } - - private void vScrollBar1_Scroll(object sender, ScrollEventArgs e) - { - surface1.Scroll(new int2(0,e.NewValue-e.OldValue)); - } - - private void hScrollBar1_Scroll(object sender, ScrollEventArgs e) - { - surface1.Scroll(new int2(e.NewValue - e.OldValue,0)); - } - - private void surface1_Resize(object sender, EventArgs e) - { - if (surface1.Map == null) - return; - - vScrollBar1.Maximum = surface1.Map.MapSize.Y * 24 - surface1.Height; - hScrollBar1.Maximum = surface1.Map.MapSize.X * 24 - surface1.Width; - - surface1.ValidateOffset(surface1.Width,surface1.Height); - } + void SpawnPointsClicked(object sender, EventArgs e) { surface1.SetWaypoint(new WaypointTemplate()); } + void Form1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Space) surface1.IsPanning = true; } + void Form1_KeyUp(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Space) surface1.IsPanning = false; } } } \ No newline at end of file diff --git a/OpenRA.Editor/Surface.cs b/OpenRA.Editor/Surface.cs index 4b2d91d419..466a25bd5f 100644 --- a/OpenRA.Editor/Surface.cs +++ b/OpenRA.Editor/Surface.cs @@ -1,8 +1,8 @@ using System.Collections.Generic; using System.Drawing; using System.Drawing.Imaging; -using System.Windows.Forms; using System.Linq; +using System.Windows.Forms; using OpenRA.FileFormats; using OpenRA.Thirdparty; @@ -15,10 +15,12 @@ namespace OpenRA.Editor public Palette Palette { get; private set; } int2 Offset; - public BrushTemplate Brush; - public ActorTemplate Actor; - public ResourceTemplate Resource; - public WaypointTemplate Waypoint; + BrushTemplate Brush; + ActorTemplate Actor; + ResourceTemplate Resource; + WaypointTemplate Waypoint; + + public bool IsPanning; Dictionary ActorTemplates = new Dictionary(); Dictionary ResourceTemplates = new Dictionary(); @@ -68,12 +70,6 @@ namespace OpenRA.Editor Invalidate(); } - public void ValidateOffset(int width, int height) - { - Offset.X = System.Math.Max(Offset.X, width - Map.MapSize.X * 24); - Offset.Y = System.Math.Max(Offset.Y, height - Map.MapSize.Y * 24); - } - protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); @@ -81,7 +77,7 @@ namespace OpenRA.Editor var oldMousePos = MousePos; MousePos = new int2(e.Location); - if (e.Button == MouseButtons.Middle) + if (e.Button == MouseButtons.Middle || (e.Button != MouseButtons.None && IsPanning)) Scroll(oldMousePos - MousePos); else { @@ -216,8 +212,11 @@ namespace OpenRA.Editor { base.OnMouseDown(e); - if (e.Button == MouseButtons.Right) Erase(); - if (e.Button == MouseButtons.Left) Draw(); + if (!IsPanning) + { + if (e.Button == MouseButtons.Right) Erase(); + if (e.Button == MouseButtons.Left) Draw(); + } Invalidate(); }