From 4a21274521665aeed6c22d6ea564f3c65de4817d Mon Sep 17 00:00:00 2001 From: codeimp Date: Wed, 7 Dec 2011 21:05:09 +0000 Subject: [PATCH] @ work in progress --- Resources/Icons/CeilingAlign.png | Bin 0 -> 579 bytes Resources/Icons/FloorAlign.png | Bin 0 -> 583 bytes .../ClassicModes/CeilingAlignMode.cs | 103 ++++++++++++++++++ .../ClassicModes/FlatAlignMode.cs | 91 ++++++++++++++-- .../ClassicModes/FloorAlignMode.cs | 103 ++++++++++++++++++ .../GZDoomEditing/GZDoomEditing.csproj | 6 + .../GZDoomEditing/Resources/Actions.cfg | 17 ++- .../GZDoomEditing/Resources/CeilingAlign.png | Bin 0 -> 579 bytes .../GZDoomEditing/Resources/FloorAlign.png | Bin 0 -> 583 bytes 9 files changed, 307 insertions(+), 13 deletions(-) create mode 100644 Resources/Icons/CeilingAlign.png create mode 100644 Resources/Icons/FloorAlign.png create mode 100644 Source/Plugins/GZDoomEditing/ClassicModes/CeilingAlignMode.cs create mode 100644 Source/Plugins/GZDoomEditing/ClassicModes/FloorAlignMode.cs create mode 100644 Source/Plugins/GZDoomEditing/Resources/CeilingAlign.png create mode 100644 Source/Plugins/GZDoomEditing/Resources/FloorAlign.png diff --git a/Resources/Icons/CeilingAlign.png b/Resources/Icons/CeilingAlign.png new file mode 100644 index 0000000000000000000000000000000000000000..014137fcf66ac37dc3486f030e443f49f753b7a2 GIT binary patch literal 579 zcmV-J0=)f+P)mq5XE+f6}eSH&0#h1ycBf(GqEY_XII5)%{S7+Vvk8A~!GHU4R0ZITf;O0}Xk zE$!FvoX(5RFw+dd2WRu%eZM*PzB4Yr-|w=j+cIhxcF|DB#!cn(`RoAw12>kV195Qc z{v>-}%<%E#ET@JS`6jx`Xe`UfOp#dv2V!EiX-uGJj`^t*v}ZwBDr>jgecY;!nX z!@_DEO8yunrG7VCdx>mCPYaatq0wQ;e$`B8fVl&(|;~ z??I7|yF2L9Um%rgQqBHgrTQ1r);XhVP4us5x|3ZvJgFVfJMfmH=`AcO`%srpE=&1e zh*wW8#|oNx*;ppPnuFUIXUopy;lI^#}M%p3A>)~|LT~52{5E@1k89kFPj5V`wybY$>R{( RdN%+7002ovPDHLkV1o2p2z3Ae literal 0 HcmV?d00001 diff --git a/Resources/Icons/FloorAlign.png b/Resources/Icons/FloorAlign.png new file mode 100644 index 0000000000000000000000000000000000000000..cadfacd2e8c47fc0a9f4361a99c095bdef38292f GIT binary patch literal 583 zcmV-N0=WH&P)p(~<^G0}J-ic+kK(wY`fqYLFC;LM1~wK3M(GEQtF zZDN0j-`hFpkQuRrle~*L=R41LIq&GqX0uMMc1wwYO9w?Q8=cBzGHC&Ff{yiM1?*sA zv>U$p=U88KVkhdw_?8!*up5gD!w63HVrjJpE|;qjD_3BV?^+tYDS%bq3kV1AaB&l( zOnr;ET8z?#CCUh|sB~nf>i!^c90!}t27|%SrPu3qT0p>w%Wpws>e~o^4-$7ekK_0d z6;B6H%6q6*nQZ{9Rx69|YED-HY(&SfEryZ#8KG=`fztd-D)M$Jr`#k;%ar;PZ4dBA z$FY7EfLu0&_#l-82Z|>iy1x2=%iB18l0xkPGaFuH`DtW@VJhSuR8G1{s=cRVJwm(U zM=DfT+5@KiufZKSQO@?Glp7)G*BXBOP0`-f=Kr2l3z+lufzQc3AHF5=+<%w;9iz`; z=q^`TrpEiLRuiE1L16kB3j7Fa*CAZoCMY3&LHz3)@xmJ@fR+l>0A>=_<5N;s@L;5S zA82eTe=?IWu|cWzxB><+8jbe=<;P(5WDa|n@MCGRYXFMm4NKFWt*e=xU1Vah{{We1 V!}SSsG1veA002ovPDHLkV1fy&0Z;${ literal 0 HcmV?d00001 diff --git a/Source/Plugins/GZDoomEditing/ClassicModes/CeilingAlignMode.cs b/Source/Plugins/GZDoomEditing/ClassicModes/CeilingAlignMode.cs new file mode 100644 index 00000000..ca1465d0 --- /dev/null +++ b/Source/Plugins/GZDoomEditing/ClassicModes/CeilingAlignMode.cs @@ -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 + } +} diff --git a/Source/Plugins/GZDoomEditing/ClassicModes/FlatAlignMode.cs b/Source/Plugins/GZDoomEditing/ClassicModes/FlatAlignMode.cs index 94543306..8d43315c 100644 --- a/Source/Plugins/GZDoomEditing/ClassicModes/FlatAlignMode.cs +++ b/Source/Plugins/GZDoomEditing/ClassicModes/FlatAlignMode.cs @@ -24,6 +24,7 @@ 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; @@ -37,14 +38,7 @@ using CodeImp.DoomBuilder.Actions; namespace CodeImp.DoomBuilder.GZDoomEditing { - [EditMode(DisplayName = "Flat Align Mode", - SwitchAction = "flatalignmode", - ButtonImage = "VisualModeZ.png", - ButtonOrder = int.MinValue + 210, - ButtonGroup = "000_editing", - Volatile = true)] - - public class FlatAlignMode : BaseClassicMode + public abstract class FlatAlignMode : BaseClassicMode { #region ================== Constants @@ -53,13 +47,29 @@ namespace CodeImp.DoomBuilder.GZDoomEditing #region ================== Variables private ICollection 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 #region ================== Constructor / Disposer // Constructor - public FlatAlignMode() + protected FlatAlignMode() { } @@ -67,6 +77,26 @@ namespace CodeImp.DoomBuilder.GZDoomEditing #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 #region ================== Events @@ -114,10 +144,44 @@ namespace CodeImp.DoomBuilder.GZDoomEditing General.Interface.MessageBeep(MessageBeepType.Default); General.Interface.DisplayStatus(StatusType.Info, "A selected sector is required for this action."); General.Editing.CancelMode(); + return; } + editsector = General.GetByIndex(selection, 0); - // Find the nearest texture corner + // 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; + } + + // 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 @@ -153,6 +217,13 @@ namespace CodeImp.DoomBuilder.GZDoomEditing // Render overlay 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(); } diff --git a/Source/Plugins/GZDoomEditing/ClassicModes/FloorAlignMode.cs b/Source/Plugins/GZDoomEditing/ClassicModes/FloorAlignMode.cs new file mode 100644 index 00000000..59f5a5d1 --- /dev/null +++ b/Source/Plugins/GZDoomEditing/ClassicModes/FloorAlignMode.cs @@ -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 + } +} diff --git a/Source/Plugins/GZDoomEditing/GZDoomEditing.csproj b/Source/Plugins/GZDoomEditing/GZDoomEditing.csproj index 3bf1d33b..546a50af 100644 --- a/Source/Plugins/GZDoomEditing/GZDoomEditing.csproj +++ b/Source/Plugins/GZDoomEditing/GZDoomEditing.csproj @@ -42,7 +42,9 @@ + + @@ -106,6 +108,10 @@ Always + + + +