From d5498ac01ed4652108b5edc640bfab3d39e8f29d Mon Sep 17 00:00:00 2001 From: Mike Date: Sat, 16 Sep 2017 18:58:38 -0500 Subject: [PATCH] made MapForm resizable --- MapForm.Designer.cs | 96 +++++++++++++++--------------- MapForm.cs | 139 ++++++++++++++++++++++++++++++-------------- MapForm.resx | 8 +-- 3 files changed, 149 insertions(+), 94 deletions(-) diff --git a/MapForm.Designer.cs b/MapForm.Designer.cs index d61a7ee..ccf2008 100644 --- a/MapForm.Designer.cs +++ b/MapForm.Designer.cs @@ -30,7 +30,7 @@ private void InitializeComponent() this.optXY = new System.Windows.Forms.RadioButton(); this.optXZ = new System.Windows.Forms.RadioButton(); this.imgCraft = new System.Windows.Forms.ImageList(this.components); - this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.grpPoints = new System.Windows.Forms.GroupBox(); this.chkSP1 = new System.Windows.Forms.CheckBox(); this.chkSP2 = new System.Windows.Forms.CheckBox(); this.chkSP3 = new System.Windows.Forms.CheckBox(); @@ -62,7 +62,7 @@ private void InitializeComponent() this.label1 = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.pctMap)).BeginInit(); this.grpDir.SuspendLayout(); - this.groupBox1.SuspendLayout(); + this.grpPoints.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.numRegion)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numOrder)).BeginInit(); this.SuspendLayout(); @@ -75,20 +75,20 @@ private void InitializeComponent() this.pctMap.Size = new System.Drawing.Size(720, 408); this.pctMap.TabIndex = 28; this.pctMap.TabStop = false; + this.pctMap.Paint += new System.Windows.Forms.PaintEventHandler(this.pctMap_Paint); this.pctMap.DoubleClick += new System.EventHandler(this.pctMap_DoubleClick); - this.pctMap.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pctMap_MouseMove); this.pctMap.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pctMap_MouseDown); - this.pctMap.Paint += new System.Windows.Forms.PaintEventHandler(this.pctMap_Paint); - this.pctMap.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pctMap_MouseUp); this.pctMap.MouseEnter += new System.EventHandler(this.pctMap_MouseEnter); + this.pctMap.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pctMap_MouseMove); + this.pctMap.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pctMap_MouseUp); // // hscZoom // - this.hscZoom.Location = new System.Drawing.Point(488, 504); + this.hscZoom.Location = new System.Drawing.Point(402, 504); this.hscZoom.Maximum = 500; this.hscZoom.Minimum = 5; this.hscZoom.Name = "hscZoom"; - this.hscZoom.Size = new System.Drawing.Size(200, 16); + this.hscZoom.Size = new System.Drawing.Size(342, 16); this.hscZoom.TabIndex = 30; this.hscZoom.Value = 40; this.hscZoom.ValueChanged += new System.EventHandler(this.hscZoom_ValueChanged); @@ -111,7 +111,7 @@ private void InitializeComponent() // // lblZoom // - this.lblZoom.Location = new System.Drawing.Point(408, 504); + this.lblZoom.Location = new System.Drawing.Point(322, 504); this.lblZoom.Name = "lblZoom"; this.lblZoom.Size = new System.Drawing.Size(64, 16); this.lblZoom.TabIndex = 25; @@ -168,35 +168,35 @@ private void InitializeComponent() this.imgCraft.ImageSize = new System.Drawing.Size(16, 16); this.imgCraft.TransparentColor = System.Drawing.Color.Black; // - // groupBox1 - // - this.groupBox1.Controls.Add(this.chkSP1); - this.groupBox1.Controls.Add(this.chkSP2); - this.groupBox1.Controls.Add(this.chkSP3); - this.groupBox1.Controls.Add(this.chkSP4); - this.groupBox1.Controls.Add(this.chkWP1); - this.groupBox1.Controls.Add(this.chkWP2); - this.groupBox1.Controls.Add(this.chkWP3); - this.groupBox1.Controls.Add(this.chkWP4); - this.groupBox1.Controls.Add(this.chkWP5); - this.groupBox1.Controls.Add(this.chkWP6); - this.groupBox1.Controls.Add(this.chkWP7); - this.groupBox1.Controls.Add(this.chkWP8); - this.groupBox1.Controls.Add(this.chkRDV); - this.groupBox1.Controls.Add(this.chkHYP); - this.groupBox1.Controls.Add(this.chkBRF8); - this.groupBox1.Controls.Add(this.chkBRF7); - this.groupBox1.Controls.Add(this.chkBRF6); - this.groupBox1.Controls.Add(this.chkBRF5); - this.groupBox1.Controls.Add(this.chkBRF4); - this.groupBox1.Controls.Add(this.chkBRF3); - this.groupBox1.Controls.Add(this.chkBRF2); - this.groupBox1.Controls.Add(this.chkBRF); - this.groupBox1.Location = new System.Drawing.Point(750, 100); - this.groupBox1.Name = "groupBox1"; - this.groupBox1.Size = new System.Drawing.Size(64, 362); - this.groupBox1.TabIndex = 5; - this.groupBox1.TabStop = false; + // grpPoints + // + this.grpPoints.Controls.Add(this.chkSP1); + this.grpPoints.Controls.Add(this.chkSP2); + this.grpPoints.Controls.Add(this.chkSP3); + this.grpPoints.Controls.Add(this.chkSP4); + this.grpPoints.Controls.Add(this.chkWP1); + this.grpPoints.Controls.Add(this.chkWP2); + this.grpPoints.Controls.Add(this.chkWP3); + this.grpPoints.Controls.Add(this.chkWP4); + this.grpPoints.Controls.Add(this.chkWP5); + this.grpPoints.Controls.Add(this.chkWP6); + this.grpPoints.Controls.Add(this.chkWP7); + this.grpPoints.Controls.Add(this.chkWP8); + this.grpPoints.Controls.Add(this.chkRDV); + this.grpPoints.Controls.Add(this.chkHYP); + this.grpPoints.Controls.Add(this.chkBRF8); + this.grpPoints.Controls.Add(this.chkBRF7); + this.grpPoints.Controls.Add(this.chkBRF6); + this.grpPoints.Controls.Add(this.chkBRF5); + this.grpPoints.Controls.Add(this.chkBRF4); + this.grpPoints.Controls.Add(this.chkBRF3); + this.grpPoints.Controls.Add(this.chkBRF2); + this.grpPoints.Controls.Add(this.chkBRF); + this.grpPoints.Location = new System.Drawing.Point(750, 100); + this.grpPoints.Name = "grpPoints"; + this.grpPoints.Size = new System.Drawing.Size(64, 362); + this.grpPoints.TabIndex = 5; + this.grpPoints.TabStop = false; // // chkSP1 // @@ -473,9 +473,9 @@ private void InitializeComponent() this.label1.Size = new System.Drawing.Size(399, 32); this.label1.TabIndex = 33; this.label1.Text = "Double-click: 2x zoom. Left click: drag WP. Right click: center on mouse." + - " Middle click: Reset map. Mouse Wheel: zoom"; + " Middle click: Reset map. Mouse Wheel: zoom"; // - // frmMap + // MapForm // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(824, 524); @@ -485,7 +485,7 @@ private void InitializeComponent() this.Controls.Add(this.lblOrder); this.Controls.Add(this.lblRegion); this.Controls.Add(this.chkTags); - this.Controls.Add(this.groupBox1); + this.Controls.Add(this.grpPoints); this.Controls.Add(this.grpDir); this.Controls.Add(this.lblZoom); this.Controls.Add(this.lblCoor2); @@ -493,17 +493,19 @@ private void InitializeComponent() this.Controls.Add(this.hscZoom); this.Controls.Add(this.pctMap); this.Controls.Add(this.chkTrace); - this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); - this.MaximizeBox = false; - this.Name = "frmMap"; + this.MinimumSize = new System.Drawing.Size(700, 563); + this.Name = "MapForm"; this.Text = "YOGEME Map Interface"; - this.Load += new System.EventHandler(this.frmMap_Load); - this.Closed += new System.EventHandler(this.frmMap_Closed); this.Activated += new System.EventHandler(this.frmMap_Activated); + this.Closed += new System.EventHandler(this.frmMap_Closed); + this.Load += new System.EventHandler(this.frmMap_Load); + this.ResizeBegin += new System.EventHandler(this.MapForm_ResizeBegin); + this.ResizeEnd += new System.EventHandler(this.MapForm_ResizeEnd); + this.Resize += new System.EventHandler(this.MapForm_Resize); ((System.ComponentModel.ISupportInitialize)(this.pctMap)).EndInit(); this.grpDir.ResumeLayout(false); - this.groupBox1.ResumeLayout(false); + this.grpPoints.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.numRegion)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numOrder)).EndInit(); this.ResumeLayout(false); @@ -522,7 +524,7 @@ private void InitializeComponent() RadioButton optXZ; RadioButton optXY; ImageList imgCraft; - GroupBox groupBox1; + GroupBox grpPoints; CheckBox chkSP1; CheckBox chkSP2; CheckBox chkSP3; diff --git a/MapForm.cs b/MapForm.cs index 9dd62e5..9d7b129 100644 --- a/MapForm.cs +++ b/MapForm.cs @@ -1,12 +1,13 @@ /* * YOGEME.exe, All-in-one Mission Editor for the X-wing series, TIE through XWA - * Copyright (C) 2007-2014 Michael Gaisser (mjgaisser@gmail.com) + * Copyright (C) 2007-2017 Michael Gaisser (mjgaisser@gmail.com) * Licensed under the MPL v2.0 or later * - * VERSION: 1.2.3 + * VERSION: 1.2.3+ */ /* CHANGELOG + * [ADD] form is now resizable, can be maximized * v1.2.3, 141214 * [UPD] change to MPL * v1.2, 121006 @@ -41,6 +42,7 @@ enum Orientation { XY, XZ, YZ }; CheckBox[] chkWP = new CheckBox[22]; Settings.Platform _platform; int _wpSetCount = 1; + bool _isDragged; /// TFlights array public MapForm(Settings settings, Platform.Tie.FlightGroupCollection fg) @@ -87,6 +89,56 @@ public MapForm(Settings settings, Platform.Xwa.FlightGroupCollection fg) startup(settings); } + /// Get the center pixel of pctMap and the coordinates it pertains to + /// A point with the map coordinates in klicks + PointF getCenterCoord() + { + PointF coord = new PointF(); + switch (_displayMode) + { + case Orientation.XY: + coord.X = (w / 2 - mapX) / Convert.ToSingle(_zoom); + coord.Y = (mapY - h / 2) / Convert.ToSingle(_zoom); + break; + case Orientation.XZ: + coord.X = (w / 2 - mapX) / Convert.ToSingle(_zoom); + coord.Y = (mapZ - h / 2) / Convert.ToSingle(_zoom); + break; + case Orientation.YZ: + coord.X = (w / 2 - mapY) / Convert.ToSingle(_zoom); + coord.Y = (mapZ - h / 2) / Convert.ToSingle(_zoom); + break; + } + return coord; + } + + /// Updaete mapX and mapY + /// The coordinate in klicks to use as the new center + void updateMapCoord(PointF coord) + { + switch (_displayMode) + { + case Orientation.XY: + mapX = Convert.ToInt32(w / 2 - coord.X * Convert.ToSingle(_zoom)); + mapY = Convert.ToInt32(h / 2 + coord.Y * Convert.ToSingle(_zoom)); + break; + case Orientation.XZ: + mapX = Convert.ToInt32(w / 2 - coord.X * Convert.ToSingle(_zoom)); + mapZ = Convert.ToInt32(h / 2 + coord.Y * Convert.ToSingle(_zoom)); + break; + case Orientation.YZ: + mapY = Convert.ToInt32(w / 2 - coord.X * Convert.ToSingle(_zoom)); + mapZ = Convert.ToInt32(h / 2 + coord.Y * Convert.ToSingle(_zoom)); + break; + } + if (mapX / _zoom > 150) mapX = 150 * _zoom; + if ((mapX - w) / _zoom < -150) mapX = -150 * _zoom + w; + if (mapY / _zoom > 150) mapY = 150 * _zoom; + if ((mapY - h) / _zoom < -150) mapY = -150 * _zoom + h; + if (mapZ / _zoom > 150) mapZ = 150 * _zoom; + if ((mapZ - h) / _zoom < -150) mapZ = -150 * _zoom + h; + } + /// Intialization routine, loads settings and config per platform void startup(Settings config) { @@ -119,8 +171,7 @@ void startup(Settings config) chkWP[i].Tag = i; } #endregion - w = pctMap.Width; - h = pctMap.Height; + updateLayout(); mapX = w/2; mapY = h/2; mapZ = h/2; @@ -149,6 +200,32 @@ void startup(Settings config) _loading = false; } + /// Adjust control size/locations + void updateLayout() + { + PointF center = getCenterCoord(); + pctMap.Width = Width - 120; + pctMap.Height = Height - 155; + w = pctMap.Width; + h = pctMap.Height; + _map = new Bitmap(w, h, PixelFormat.Format24bppRgb); + lblCoor1.Top = Height - 59; + lblCoor2.Top = lblCoor1.Top; + lblZoom.Top = lblCoor1.Top; + hscZoom.Top = lblCoor1.Top; + hscZoom.Width = Width - 498; + lblRegion.Left = Width - 268; + numRegion.Left = Width - 218; + lblOrder.Left = Width - 171; + numOrder.Left = Width - 129; + grpDir.Left = Width - 90; + grpPoints.Left = grpDir.Left; + chkTags.Left = grpDir.Left; + chkTrace.Left = grpDir.Left; + updateMapCoord(center); + MapPaint(true); + } + /// The down-and-dirty function that handles map display /// When true draws to memory, false draws directly to the image public void MapPaint(bool persistant) @@ -379,46 +456,9 @@ public void Import(Platform.Xwa.FlightGroupCollection fg) /// Change the zoom of the map and reset local x/y/z coords as neccessary void hscZoom_ValueChanged(object sender, EventArgs e) { - // emulate a right-click to the center of the map and store the cords in klicks - double msX = 0, msY = 0; - switch(_displayMode) - { - case Orientation.XY: - msX = (w/2 - mapX) / Convert.ToDouble(_zoom); - msY = (mapY - h/2) / Convert.ToDouble(_zoom); - break; - case Orientation.XZ: - msX = (w/2 - mapX) / Convert.ToDouble(_zoom); - msY = (mapZ - h/2) / Convert.ToDouble(_zoom); - break; - case Orientation.YZ: - msX = (w/2 - mapY) / Convert.ToDouble(_zoom); - msY = (mapZ - h/2) / Convert.ToDouble(_zoom); - break; - } + PointF center = getCenterCoord(); _zoom = hscZoom.Value; - // using the coords determine the correct map location with the new zoom - switch(_displayMode) - { - case Orientation.XY: - mapX = Convert.ToInt32(w/2 - msX * Convert.ToDouble(_zoom)); - mapY = Convert.ToInt32(h/2 + msY * Convert.ToDouble(_zoom)); - break; - case Orientation.XZ: - mapX = Convert.ToInt32(w/2 - msX * Convert.ToDouble(_zoom)); - mapZ = Convert.ToInt32(h/2 + msY * Convert.ToDouble(_zoom)); - break; - case Orientation.YZ: - mapY = Convert.ToInt32(w/2 - msX * Convert.ToDouble(_zoom)); - mapZ = Convert.ToInt32(h/2 + msY * Convert.ToDouble(_zoom)); - break; - } - if (mapX/_zoom > 150) mapX = 150*_zoom; - if ((mapX-w)/_zoom < -150) mapX = -150*_zoom + w; - if (mapY/_zoom > 150) mapY = 150*_zoom; - if ((mapY-h)/_zoom < -150) mapY = -150*_zoom + h; - if (mapZ/_zoom > 150) mapZ = 150*_zoom; - if ((mapZ-h)/_zoom < -150) mapZ = -150*_zoom + h; + updateMapCoord(center); MapPaint(true); lblZoom.Text = "Zoom: " + _zoom.ToString(); } @@ -633,6 +673,19 @@ void frmMap_MouseWheel(object sender, MouseEventArgs e) else if (hscZoom.Value > 480 && e.Delta > 0) hscZoom.Value = 500; else hscZoom.Value += 20 * Math.Sign(e.Delta); } + void MapForm_Resize(object sender, EventArgs e) + { + if (!_isDragged) updateLayout(); + } + void MapForm_ResizeBegin(object sender, EventArgs e) + { + _isDragged = true; + } + void MapForm_ResizeEnd(object sender, EventArgs e) + { + _isDragged = false; + updateLayout(); + } #endregion /// Take the original image from the craft image strip and adds the RGB values from the craft IFF diff --git a/MapForm.resx b/MapForm.resx index 6ebe9d4..da2dc15 100644 --- a/MapForm.resx +++ b/MapForm.resx @@ -112,15 +112,15 @@ 2.0 - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + 17, 17 - + AAABAAEAICAQAAAAAADoAgAAFgAAACgAAAAgAAAAQAAAAAEABAAAAAAAAAIAAAAAAAAAAAAAEAAAABAA