2014-12-22 21:36:49 +00:00
|
|
|
|
#region ================== Namespaces
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Drawing.Imaging;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using CodeImp.DoomBuilder.Windows;
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.BuilderModes
|
|
|
|
|
{
|
|
|
|
|
internal struct FitTextureOptions
|
|
|
|
|
{
|
2020-07-16 21:25:07 +00:00
|
|
|
|
public double HorizontalRepeat;
|
|
|
|
|
public double VerticalRepeat;
|
2017-07-18 11:56:27 +00:00
|
|
|
|
public int PatternWidth;
|
|
|
|
|
public int PatternHeight;
|
2014-12-22 21:36:49 +00:00
|
|
|
|
public bool FitWidth;
|
|
|
|
|
public bool FitHeight;
|
|
|
|
|
public bool FitAcrossSurfaces;
|
2017-07-18 11:56:27 +00:00
|
|
|
|
public bool AutoWidth;
|
|
|
|
|
public bool AutoHeight;
|
2014-12-22 21:36:49 +00:00
|
|
|
|
public Rectangle GlobalBounds;
|
|
|
|
|
public Rectangle Bounds;
|
|
|
|
|
|
|
|
|
|
//Initial texture coordinats
|
2020-05-21 12:20:02 +00:00
|
|
|
|
public double InitialOffsetX;
|
|
|
|
|
public double InitialOffsetY;
|
|
|
|
|
public double ControlSideOffsetX;
|
|
|
|
|
public double ControlSideOffsetY;
|
|
|
|
|
public double InitialScaleX;
|
|
|
|
|
public double InitialScaleY;
|
2014-12-22 21:36:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal partial class FitTexturesForm : DelayedForm
|
|
|
|
|
{
|
|
|
|
|
#region ================== Event handlers
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ================== Variables
|
|
|
|
|
|
|
|
|
|
private static Point location = Point.Empty;
|
|
|
|
|
private bool blockupdate;
|
2020-07-16 21:25:07 +00:00
|
|
|
|
private double prevhorizrepeat;
|
|
|
|
|
private double prevvertrepeat;
|
2014-12-22 21:36:49 +00:00
|
|
|
|
|
|
|
|
|
// Settings
|
2020-07-16 21:25:07 +00:00
|
|
|
|
private static double horizontalrepeat = 1.0;
|
|
|
|
|
private static double verticalrepeat = 1.0;
|
2014-12-22 21:36:49 +00:00
|
|
|
|
private static bool fitacrosssurfaces = true;
|
|
|
|
|
private static bool fitwidth = true;
|
|
|
|
|
private static bool fitheight = true;
|
|
|
|
|
|
|
|
|
|
//Surface stuff
|
|
|
|
|
private List<SortedVisualSide> strips;
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ================== Constructor
|
|
|
|
|
|
|
|
|
|
public FitTexturesForm()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
2015-12-28 15:01:53 +00:00
|
|
|
|
if(!location.IsEmpty)
|
2014-12-22 21:36:49 +00:00
|
|
|
|
{
|
|
|
|
|
this.StartPosition = FormStartPosition.Manual;
|
|
|
|
|
this.Location = location;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ================== Methods
|
|
|
|
|
|
2015-03-10 18:49:29 +00:00
|
|
|
|
public bool Setup(IEnumerable<BaseVisualGeometrySidedef> sides)
|
2014-12-22 21:36:49 +00:00
|
|
|
|
{
|
|
|
|
|
// Get shapes
|
|
|
|
|
strips = BuilderModesTools.SortVisualSides(sides);
|
|
|
|
|
|
|
|
|
|
// No dice...
|
|
|
|
|
if(strips.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
General.Interface.DisplayStatus(StatusType.Warning, "Failed to setup sidedef chains...");
|
|
|
|
|
this.DialogResult = DialogResult.Cancel;
|
|
|
|
|
this.Close();
|
2015-03-10 18:49:29 +00:00
|
|
|
|
return false;
|
2014-12-22 21:36:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Restore settings
|
|
|
|
|
blockupdate = true;
|
|
|
|
|
|
2020-07-16 21:25:07 +00:00
|
|
|
|
// Make sure we start with sensible values for horizontal and vertical repeat
|
|
|
|
|
if (horizontalrepeat == 0.0)
|
|
|
|
|
horizontalrepeat = 1.0;
|
|
|
|
|
|
|
|
|
|
if (verticalrepeat == 0.0)
|
|
|
|
|
verticalrepeat = 1.0;
|
|
|
|
|
|
2017-07-18 11:56:27 +00:00
|
|
|
|
horizrepeat.Text = horizontalrepeat.ToString();
|
|
|
|
|
vertrepeat.Text = verticalrepeat.ToString();
|
2014-12-23 12:32:08 +00:00
|
|
|
|
prevhorizrepeat = horizontalrepeat;
|
|
|
|
|
prevvertrepeat = verticalrepeat;
|
2014-12-22 21:36:49 +00:00
|
|
|
|
cbfitconnected.Checked = fitacrosssurfaces;
|
2015-01-29 21:41:16 +00:00
|
|
|
|
cbfitconnected.Enabled = (strips.Count > 1);
|
2014-12-22 21:36:49 +00:00
|
|
|
|
cbfitwidth.Checked = fitwidth;
|
|
|
|
|
cbfitheight.Checked = fitheight;
|
|
|
|
|
UpdateRepeatGroup();
|
|
|
|
|
|
|
|
|
|
blockupdate = false;
|
|
|
|
|
|
|
|
|
|
//trigger update
|
|
|
|
|
UpdateChanges();
|
2015-03-10 18:49:29 +00:00
|
|
|
|
|
|
|
|
|
return true;
|
2014-12-22 21:36:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateChanges()
|
|
|
|
|
{
|
|
|
|
|
// Apply changes
|
|
|
|
|
FitTextureOptions options = new FitTextureOptions
|
|
|
|
|
{
|
2015-01-29 21:41:16 +00:00
|
|
|
|
FitAcrossSurfaces = (cbfitconnected.Enabled && cbfitconnected.Checked),
|
2014-12-22 21:36:49 +00:00
|
|
|
|
FitWidth = cbfitwidth.Checked,
|
|
|
|
|
FitHeight = cbfitheight.Checked,
|
2017-07-18 11:56:27 +00:00
|
|
|
|
PatternWidth = (int)patternwidth.GetResultFloat(0),
|
|
|
|
|
PatternHeight = (int)patternheight.GetResultFloat(0),
|
|
|
|
|
AutoWidth = cbautowidth.Checked,
|
2020-07-16 21:25:07 +00:00
|
|
|
|
AutoHeight = cbautoheight.Checked
|
2014-12-22 21:36:49 +00:00
|
|
|
|
};
|
|
|
|
|
|
2020-07-16 21:25:07 +00:00
|
|
|
|
// Default horizonal repeat to 1 if the value can't be parsed or if it's 0
|
|
|
|
|
double hrepeat = horizrepeat.GetResultFloat(double.NaN);
|
|
|
|
|
if (double.IsNaN(hrepeat) || hrepeat == 0.0)
|
|
|
|
|
hrepeat = 1.0;
|
|
|
|
|
|
|
|
|
|
// Default vertical repeat to 1 if the value can't be parsed or if it's 0
|
|
|
|
|
double vrepeat = vertrepeat.GetResultFloat(double.NaN);
|
|
|
|
|
if (double.IsNaN(vrepeat) || vrepeat == 0.0)
|
|
|
|
|
vrepeat = 1.0;
|
|
|
|
|
|
|
|
|
|
options.HorizontalRepeat = hrepeat;
|
|
|
|
|
options.VerticalRepeat = vrepeat;
|
|
|
|
|
|
|
|
|
|
foreach (SortedVisualSide side in strips) side.OnTextureFit(options);
|
2014-12-22 21:36:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateRepeatGroup()
|
|
|
|
|
{
|
|
|
|
|
// Disable whole group?
|
|
|
|
|
repeatgroup.Enabled = cbfitwidth.Checked || cbfitheight.Checked;
|
|
|
|
|
if(!repeatgroup.Enabled) return;
|
|
|
|
|
|
|
|
|
|
// Update control status
|
2017-07-18 11:56:27 +00:00
|
|
|
|
cbautowidth.Enabled = cbfitwidth.Checked;
|
|
|
|
|
patternwidth.Enabled = cbfitwidth.Checked && (cbautowidth.Enabled && cbautowidth.Checked);
|
|
|
|
|
labelpatternwidth.Enabled = patternwidth.Enabled;
|
2014-12-22 21:36:49 +00:00
|
|
|
|
labelhorizrepeat.Enabled = cbfitwidth.Checked;
|
2017-07-18 11:56:27 +00:00
|
|
|
|
horizrepeat.Enabled = cbfitwidth.Checked && !cbautowidth.Checked;
|
|
|
|
|
resethoriz.Enabled = cbfitwidth.Checked && !cbautowidth.Checked;
|
2014-12-22 21:36:49 +00:00
|
|
|
|
|
2017-07-18 11:56:27 +00:00
|
|
|
|
cbautoheight.Enabled = cbfitheight.Checked;
|
|
|
|
|
patternheight.Enabled = cbfitheight.Checked && (cbautoheight.Enabled && cbautoheight.Checked);
|
|
|
|
|
labelpatternheight.Enabled = patternheight.Enabled;
|
2014-12-22 21:36:49 +00:00
|
|
|
|
labelvertrepeat.Enabled = cbfitheight.Checked;
|
2017-07-18 11:56:27 +00:00
|
|
|
|
vertrepeat.Enabled = cbfitheight.Checked && !cbautoheight.Checked;
|
|
|
|
|
resetvert.Enabled = cbfitheight.Checked && !cbautoheight.Checked;
|
2014-12-22 21:36:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ================== Events
|
|
|
|
|
|
|
|
|
|
private void FitTexturesForm_FormClosing(object sender, FormClosingEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
location = this.Location;
|
|
|
|
|
|
|
|
|
|
// Store settings
|
2015-12-28 15:01:53 +00:00
|
|
|
|
if(this.DialogResult == DialogResult.OK)
|
2014-12-22 21:36:49 +00:00
|
|
|
|
{
|
2020-07-16 21:25:07 +00:00
|
|
|
|
horizontalrepeat = horizrepeat.GetResultFloat(0);
|
|
|
|
|
verticalrepeat = vertrepeat.GetResultFloat(0);
|
2014-12-22 21:36:49 +00:00
|
|
|
|
fitacrosssurfaces = cbfitwidth.Checked;
|
|
|
|
|
fitwidth = cbfitwidth.Checked;
|
|
|
|
|
fitheight = cbfitheight.Checked;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void resethoriz_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2014-12-23 12:32:08 +00:00
|
|
|
|
prevhorizrepeat = 1;
|
2017-07-18 11:56:27 +00:00
|
|
|
|
horizrepeat.Text = "1";
|
2014-12-22 21:36:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void resetvert_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2014-12-23 12:32:08 +00:00
|
|
|
|
prevvertrepeat = 1;
|
2017-07-18 11:56:27 +00:00
|
|
|
|
vertrepeat.Text = "1";
|
2014-12-22 21:36:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-23 12:32:08 +00:00
|
|
|
|
private void horizrepeat_ValueChanged(object sender, EventArgs e)
|
2014-12-22 21:36:49 +00:00
|
|
|
|
{
|
|
|
|
|
if(blockupdate) return;
|
2014-12-23 12:32:08 +00:00
|
|
|
|
|
2020-07-16 21:25:07 +00:00
|
|
|
|
prevhorizrepeat = horizrepeat.GetResultFloat(1);
|
2014-12-23 12:32:08 +00:00
|
|
|
|
UpdateChanges();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void vertrepeat_ValueChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if(blockupdate) return;
|
|
|
|
|
|
2020-07-16 21:25:07 +00:00
|
|
|
|
prevvertrepeat = vertrepeat.GetResultFloat(1);
|
2014-12-22 21:36:49 +00:00
|
|
|
|
UpdateChanges();
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-18 11:56:27 +00:00
|
|
|
|
private void accept_Click(object sender, EventArgs e)
|
2014-12-22 21:36:49 +00:00
|
|
|
|
{
|
|
|
|
|
this.DialogResult = DialogResult.OK;
|
|
|
|
|
this.Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void cancel_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
this.DialogResult = DialogResult.Cancel;
|
|
|
|
|
this.Close();
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-12 18:18:48 +00:00
|
|
|
|
private void cb_CheckedChanged(object sender, EventArgs e)
|
2014-12-22 21:36:49 +00:00
|
|
|
|
{
|
|
|
|
|
if(blockupdate) return;
|
|
|
|
|
UpdateRepeatGroup();
|
|
|
|
|
UpdateChanges();
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-18 11:56:27 +00:00
|
|
|
|
private void patternsize_ValueChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (blockupdate) return;
|
|
|
|
|
UpdateChanges();
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-22 21:36:49 +00:00
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|