diff --git a/Source/Plugins/BuilderModes/General/BuilderModesTools.cs b/Source/Plugins/BuilderModes/General/BuilderModesTools.cs index d3de4da7..566be4a5 100644 --- a/Source/Plugins/BuilderModes/General/BuilderModesTools.cs +++ b/Source/Plugins/BuilderModes/General/BuilderModesTools.cs @@ -23,6 +23,7 @@ namespace CodeImp.DoomBuilder.BuilderModes internal readonly Dictionary NextSides; internal readonly Dictionary PreviousSides; internal readonly int Index; + internal int GroupIndex = -1; private static int index; //Initial texture coordinates @@ -198,49 +199,54 @@ namespace CodeImp.DoomBuilder.BuilderModes foreach (KeyValuePair> pair in sidesbytexture) { // Create strips - IEnumerable group = ConnectSides(pair.Value); + Dictionary> strips = ConnectSides(pair.Value); // Calculate global bounds... - int minx = int.MaxValue; - int maxx = int.MinValue; - int miny = int.MaxValue; - int maxy = int.MinValue; - - foreach(SortedVisualSide side in group) + foreach(List group in strips.Values) { - if(side.Bounds.X < minx) minx = side.Bounds.X; - if(side.Bounds.X + side.Bounds.Width > maxx) maxx = side.Bounds.X + side.Bounds.Width; - if(side.Bounds.Y < miny) miny = side.Bounds.Y; - if(side.Bounds.Y + side.Bounds.Height > maxy) maxy = side.Bounds.Y + side.Bounds.Height; + int minx = int.MaxValue; + int maxx = int.MinValue; + int miny = int.MaxValue; + int maxy = int.MinValue; + + foreach(SortedVisualSide side in group) + { + if(side.Bounds.X < minx) minx = side.Bounds.X; + if(side.Bounds.X + side.Bounds.Width > maxx) maxx = side.Bounds.X + side.Bounds.Width; + if(side.Bounds.Y < miny) miny = side.Bounds.Y; + if(side.Bounds.Y + side.Bounds.Height > maxy) maxy = side.Bounds.Y + side.Bounds.Height; + } + + Rectangle bounds = new Rectangle(minx, miny, maxx - minx, maxy - miny); + + // Normalize Y-offset + int offsety = bounds.Y; + bounds.Y = 0; + + // Apply changes + foreach(SortedVisualSide side in group) + { + side.Bounds.Y -= offsety; + side.GlobalBounds = bounds; + } + + // Add to result + result.AddRange(group); } - - Rectangle bounds = new Rectangle(minx, miny, maxx - minx, maxy - miny); - - // Normalize Y-offset - int offsety = bounds.Y; - bounds.Y = 0; - - // Apply changes - foreach(SortedVisualSide side in group) - { - side.Bounds.Y -= offsety; - side.GlobalBounds = bounds; - } - - // Add to result - result.AddRange(group); } return result; } - // Connect sides, left to right + // Connect sides, left to right and sort them into connected groups // NextSides - sides connected to the right (Start) vertex, // PreviousSides - sides connected to the left (End) vertex - private static IEnumerable ConnectSides(List allsides) + private static Dictionary> ConnectSides(List allsides) { - List result = new List(); + Dictionary> result = new Dictionary>(); List sides = new List(allsides.Count); + int groupindex = 0; + foreach (BaseVisualGeometrySidedef side in allsides) { sides.Add(new SortedVisualSide(side)); @@ -248,6 +254,8 @@ namespace CodeImp.DoomBuilder.BuilderModes foreach(SortedVisualSide curside in sides) { + if(curside.GroupIndex == -1) curside.GroupIndex = groupindex++; + // Find sides connected to the end of curside foreach(SortedVisualSide nextside in sides) { @@ -255,8 +263,16 @@ namespace CodeImp.DoomBuilder.BuilderModes if(nextside.Start == curside.End && nextside.End != curside.Start) { // Add both ways - if(!nextside.PreviousSides.ContainsKey(curside)) nextside.PreviousSides.Add(curside, false); - if(!curside.NextSides.ContainsKey(nextside)) curside.NextSides.Add(nextside, false); + if(!nextside.PreviousSides.ContainsKey(curside)) + { + nextside.PreviousSides.Add(curside, false); + nextside.GroupIndex = curside.GroupIndex; + } + if(!curside.NextSides.ContainsKey(nextside)) + { + curside.NextSides.Add(nextside, false); + nextside.GroupIndex = curside.GroupIndex; + } } } @@ -267,27 +283,39 @@ namespace CodeImp.DoomBuilder.BuilderModes if(prevside.End == curside.Start && prevside.Start != curside.End) { // Add both ways - if(!prevside.NextSides.ContainsKey(curside)) prevside.NextSides.Add(curside, false); - if(!curside.PreviousSides.ContainsKey(prevside)) curside.PreviousSides.Add(prevside, false); + if(!prevside.NextSides.ContainsKey(curside)) + { + prevside.NextSides.Add(curside, false); + prevside.GroupIndex = curside.GroupIndex; + } + if(!curside.PreviousSides.ContainsKey(prevside)) + { + curside.PreviousSides.Add(prevside, false); + prevside.GroupIndex = curside.GroupIndex; + } } } - result.Add(curside); + // Add to collection + if(!result.ContainsKey(curside.GroupIndex)) result.Add(curside.GroupIndex, new List()); + result[curside.GroupIndex].Add(curside); } // Try to find the left-most side - SortedVisualSide start = result[0]; - foreach (SortedVisualSide side in result) + foreach(KeyValuePair> pair in result) { - if (side.PreviousSides.Count == 0) + SortedVisualSide start = pair.Value[0]; + foreach(SortedVisualSide side in pair.Value) { - start = side; - break; + if(side.PreviousSides.Count == 0) { + start = side; + break; + } } - } - // Set horizontal offsets... - ApplyHorizontalOffset(start, null, true, new Dictionary()); + // Set horizontal offsets... + ApplyHorizontalOffset(start, null, true, new Dictionary()); + } return result; } diff --git a/Source/Plugins/BuilderModes/Interface/FitTexturesForm.Designer.cs b/Source/Plugins/BuilderModes/Interface/FitTexturesForm.Designer.cs index b8ce4e3e..3e585868 100644 --- a/Source/Plugins/BuilderModes/Interface/FitTexturesForm.Designer.cs +++ b/Source/Plugins/BuilderModes/Interface/FitTexturesForm.Designer.cs @@ -152,7 +152,7 @@ this.cbfitwidth.TabIndex = 2; this.cbfitwidth.Text = "Fit width"; this.cbfitwidth.UseVisualStyleBackColor = true; - this.cbfitwidth.CheckedChanged += new System.EventHandler(this.cbfitwidth_CheckedChanged); + this.cbfitwidth.CheckedChanged += new System.EventHandler(this.cb_CheckedChanged); // // accept // @@ -185,7 +185,7 @@ this.cbfitheight.TabIndex = 8; this.cbfitheight.Text = "Fit height"; this.cbfitheight.UseVisualStyleBackColor = true; - this.cbfitheight.CheckedChanged += new System.EventHandler(this.cbfitheight_CheckedChanged); + this.cbfitheight.CheckedChanged += new System.EventHandler(this.cb_CheckedChanged); // // cbfitconnected // @@ -196,6 +196,7 @@ this.cbfitconnected.TabIndex = 9; this.cbfitconnected.Text = "Fit across connected surfaces"; this.cbfitconnected.UseVisualStyleBackColor = true; + this.cbfitconnected.CheckedChanged += new System.EventHandler(this.cb_CheckedChanged); // // groupBox2 // diff --git a/Source/Plugins/BuilderModes/Interface/FitTexturesForm.cs b/Source/Plugins/BuilderModes/Interface/FitTexturesForm.cs index f3f4e3fe..7be88e6d 100644 --- a/Source/Plugins/BuilderModes/Interface/FitTexturesForm.cs +++ b/Source/Plugins/BuilderModes/Interface/FitTexturesForm.cs @@ -209,14 +209,7 @@ namespace CodeImp.DoomBuilder.BuilderModes this.Close(); } - private void cbfitwidth_CheckedChanged(object sender, EventArgs e) - { - if(blockupdate) return; - UpdateRepeatGroup(); - UpdateChanges(); - } - - private void cbfitheight_CheckedChanged(object sender, EventArgs e) + private void cb_CheckedChanged(object sender, EventArgs e) { if(blockupdate) return; UpdateRepeatGroup();