@ work in progress

This commit is contained in:
codeimp 2011-12-07 21:05:09 +00:00
parent f95e8bd09f
commit 4a21274521
9 changed files with 307 additions and 13 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 579 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 583 B

View file

@ -0,0 +1,103 @@

#region ================== Copyright (c) 2007 Pascal vd Heiden
/*
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
* This program is released under GNU General Public License
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#endregion
#region ================== Namespaces
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Reflection;
using CodeImp.DoomBuilder.Data;
using CodeImp.DoomBuilder.Windows;
using CodeImp.DoomBuilder.IO;
using CodeImp.DoomBuilder.Map;
using CodeImp.DoomBuilder.Rendering;
using CodeImp.DoomBuilder.Geometry;
using CodeImp.DoomBuilder.Editing;
using System.Drawing;
using CodeImp.DoomBuilder.Actions;
#endregion
namespace CodeImp.DoomBuilder.GZDoomEditing
{
[EditMode(DisplayName = "Ceiling Align Mode",
SwitchAction = "ceilingalignmode",
ButtonImage = "CeilingAlign.png",
ButtonOrder = int.MinValue + 211,
ButtonGroup = "000_editing",
Volatile = true)]
public class CeilingAlignMode : FlatAlignMode
{
#region ================== Constants
#endregion
#region ================== Variables
#endregion
#region ================== Properties
public override string XScaleName { get { return "xscaleceiling"; } }
public override string YScaleName { get { return "yscaleceiling"; } }
public override string XOffsetName { get { return "xpanningceiling"; } }
public override string YOffsetName { get { return "ypanningceiling"; } }
public override string RotationName { get { return "rotationceiling"; } }
#endregion
#region ================== Constructor / Disposer
// Constructor
public CeilingAlignMode()
{
}
#endregion
#region ================== Methods
// Get the texture data to align
protected override ImageData GetTexture(Sector editsector)
{
return General.Map.Data.GetFlatImage(editsector.LongCeilTexture);
}
#endregion
#region ================== Events
// Mode engages
public override void OnEngage()
{
base.OnEngage();
}
// Mode disengages
public override void OnDisengage()
{
base.OnDisengage();
}
#endregion
}
}

View file

@ -24,6 +24,7 @@ using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
using System.IO; using System.IO;
using System.Reflection; using System.Reflection;
using CodeImp.DoomBuilder.Data;
using CodeImp.DoomBuilder.Windows; using CodeImp.DoomBuilder.Windows;
using CodeImp.DoomBuilder.IO; using CodeImp.DoomBuilder.IO;
using CodeImp.DoomBuilder.Map; using CodeImp.DoomBuilder.Map;
@ -37,14 +38,7 @@ using CodeImp.DoomBuilder.Actions;
namespace CodeImp.DoomBuilder.GZDoomEditing namespace CodeImp.DoomBuilder.GZDoomEditing
{ {
[EditMode(DisplayName = "Flat Align Mode", public abstract class FlatAlignMode : BaseClassicMode
SwitchAction = "flatalignmode",
ButtonImage = "VisualModeZ.png",
ButtonOrder = int.MinValue + 210,
ButtonGroup = "000_editing",
Volatile = true)]
public class FlatAlignMode : BaseClassicMode
{ {
#region ================== Constants #region ================== Constants
@ -53,13 +47,29 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
#region ================== Variables #region ================== Variables
private ICollection<Sector> selection; private ICollection<Sector> selection;
protected Sector editsector;
private ImageData texture;
private Vector2D texturegraboffset;
private float rotation;
private Vector2D scale;
private Vector2D offset;
#endregion
#region ================== Properties
public abstract string XScaleName { get; }
public abstract string YScaleName { get; }
public abstract string XOffsetName { get; }
public abstract string YOffsetName { get; }
public abstract string RotationName { get; }
#endregion #endregion
#region ================== Constructor / Disposer #region ================== Constructor / Disposer
// Constructor // Constructor
public FlatAlignMode() protected FlatAlignMode()
{ {
} }
@ -67,6 +77,26 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
#region ================== Methods #region ================== Methods
protected abstract ImageData GetTexture(Sector editsector);
// Transforms p from Texture space into World space
protected Vector2D TexToWorld(Vector2D p)
{
p /= scale;
p -= offset;
p = p.GetRotated(-rotation);
return p;
}
// Transforms p from World space into Texture space
protected Vector2D WorldToTex(Vector2D p)
{
p = p.GetRotated(rotation);
p += offset;
p *= scale;
return p;
}
#endregion #endregion
#region ================== Events #region ================== Events
@ -114,10 +144,44 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
General.Interface.MessageBeep(MessageBeepType.Default); General.Interface.MessageBeep(MessageBeepType.Default);
General.Interface.DisplayStatus(StatusType.Info, "A selected sector is required for this action."); General.Interface.DisplayStatus(StatusType.Info, "A selected sector is required for this action.");
General.Editing.CancelMode(); General.Editing.CancelMode();
return;
}
editsector = General.GetByIndex(selection, 0);
// Get the texture
texture = GetTexture(editsector);
if((texture == null) || (texture == General.Map.Data.WhiteTexture) ||
(texture.Width <= 0) || (texture.Height <= 0) || !texture.IsImageLoaded)
{
General.Interface.MessageBeep(MessageBeepType.Default);
General.Interface.DisplayStatus(StatusType.Info, "The selected sector must have a loaded texture to align.");
General.Editing.CancelMode();
return;
} }
// Find the nearest texture corner // Cache the transformation values
rotation = Angle2D.DegToRad(editsector.Fields.GetValue(RotationName, 0.0f));
scale.x = editsector.Fields.GetValue(XScaleName, 1.0f);
scale.y = editsector.Fields.GetValue(YScaleName, 1.0f);
offset.x = editsector.Fields.GetValue(XOffsetName, 0.0f);
offset.y = -editsector.Fields.GetValue(YOffsetName, 0.0f);
// We want the texture corner nearest to the center of the sector
Vector2D fp;
fp.x = (editsector.BBox.Left + editsector.BBox.Right) / 2;
fp.y = (editsector.BBox.Top + editsector.BBox.Bottom) / 2;
// Transform the point into texture space
fp = WorldToTex(fp);
// Snap to the nearest left-top corner
fp.x = (float)Math.Round(fp.x / texture.ScaledWidth) * texture.ScaledWidth;
fp.y = (float)Math.Round(fp.y / texture.ScaledHeight) * texture.ScaledHeight;
texturegraboffset = fp;
// Transorm the point into world space
// fp = fp.GetRotated(rotation);
// fp = (fp / scale) + offset;
} }
// Mode disengages // Mode disengages
@ -153,6 +217,13 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
// Render overlay // Render overlay
if(renderer.StartOverlay(true)) if(renderer.StartOverlay(true))
{ {
Vector2D rightpoint = texturegraboffset + new Vector2D(texture.ScaledWidth, 0f);
Vector2D p1world = TexToWorld(texturegraboffset);
Vector2D p2world = TexToWorld(rightpoint);
renderer.RenderLine(p1world, p2world, 1f, General.Colors.Highlight, true);
renderer.Finish(); renderer.Finish();
} }

View file

@ -0,0 +1,103 @@

#region ================== Copyright (c) 2007 Pascal vd Heiden
/*
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
* This program is released under GNU General Public License
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#endregion
#region ================== Namespaces
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Reflection;
using CodeImp.DoomBuilder.Data;
using CodeImp.DoomBuilder.Windows;
using CodeImp.DoomBuilder.IO;
using CodeImp.DoomBuilder.Map;
using CodeImp.DoomBuilder.Rendering;
using CodeImp.DoomBuilder.Geometry;
using CodeImp.DoomBuilder.Editing;
using System.Drawing;
using CodeImp.DoomBuilder.Actions;
#endregion
namespace CodeImp.DoomBuilder.GZDoomEditing
{
[EditMode(DisplayName = "Floor Align Mode",
SwitchAction = "flooralignmode",
ButtonImage = "FloorAlign.png",
ButtonOrder = int.MinValue + 210,
ButtonGroup = "000_editing",
Volatile = true)]
public class FloorAlignMode : FlatAlignMode
{
#region ================== Constants
#endregion
#region ================== Variables
#endregion
#region ================== Properties
public override string XScaleName { get { return "xscalefloor"; } }
public override string YScaleName { get { return "yscalefloor"; } }
public override string XOffsetName { get { return "xpanningfloor"; } }
public override string YOffsetName { get { return "ypanningfloor"; } }
public override string RotationName { get { return "rotationfloor"; } }
#endregion
#region ================== Constructor / Disposer
// Constructor
public FloorAlignMode()
{
}
#endregion
#region ================== Methods
// Get the texture data to align
protected override ImageData GetTexture(Sector editsector)
{
return General.Map.Data.GetFlatImage(editsector.LongFloorTexture);
}
#endregion
#region ================== Events
// Mode engages
public override void OnEngage()
{
base.OnEngage();
}
// Mode disengages
public override void OnDisengage()
{
base.OnDisengage();
}
#endregion
}
}

View file

@ -42,7 +42,9 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="ClassicModes\BaseClassicMode.cs" /> <Compile Include="ClassicModes\BaseClassicMode.cs" />
<Compile Include="ClassicModes\CeilingAlignMode.cs" />
<Compile Include="ClassicModes\FlatAlignMode.cs" /> <Compile Include="ClassicModes\FlatAlignMode.cs" />
<Compile Include="ClassicModes\FloorAlignMode.cs" />
<Compile Include="General\BuilderPlug.cs" /> <Compile Include="General\BuilderPlug.cs" />
<Compile Include="General\CopyStructures.cs" /> <Compile Include="General\CopyStructures.cs" />
<Compile Include="General\UndoGroup.cs" /> <Compile Include="General\UndoGroup.cs" />
@ -106,6 +108,10 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None> </None>
</ItemGroup> </ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\CeilingAlign.png" />
<EmbeddedResource Include="Resources\FloorAlign.png" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.

View file

@ -12,13 +12,24 @@ gzdoomvisualmode
allowscroll = true; allowscroll = true;
} }
flatalignmode flooralignmode
{ {
title = "Flat Align Mode"; title = "Floor Align Mode";
category = "modes"; category = "modes";
description = "Switches to the (G)ZDoom Flat Align mode."; description = "Switches to the (G)ZDoom Floor Align mode.";
allowkeys = true; allowkeys = true;
allowmouse = true; allowmouse = true;
allowscroll = true; allowscroll = true;
} }
ceilingalignmode
{
title = "Ceiling Align Mode";
category = "modes";
description = "Switches to the (G)ZDoom Ceiling Align mode.";
allowkeys = true;
allowmouse = true;
allowscroll = true;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 579 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 583 B