- added feature to display an image from file on the background along with ability to scale it

- fixed some scaled sizes in some image data classes
This commit is contained in:
codeimp 2008-10-15 19:14:32 +00:00
parent 1bf3ab747c
commit 6d1f43c7c6
9 changed files with 243 additions and 36 deletions

View file

@ -12,6 +12,9 @@
- Make DECORATE support
- Make plugin dependencies
(load BEFORE and load AFTER so that also their functions are called in that order)
- Make dialog and editing mode help documentation
- Make Plugin Development Kit

View file

@ -46,6 +46,18 @@ namespace CodeImp.DoomBuilder.Data
this.filepathname = filepathname;
SetName(name);
// Temporarily load file
Bitmap bmp = (Bitmap)Bitmap.FromFile(filepathname);
// Get width and height from image
width = bmp.Size.Width;
height = bmp.Size.Height;
scaledwidth = (float)bmp.Size.Width * General.Map.Config.DefaultTextureScale;
scaledheight = (float)bmp.Size.Height * General.Map.Config.DefaultTextureScale;
// Unload file
bmp.Dispose();
// We have no destructor
GC.SuppressFinalize(this);
}
@ -69,6 +81,8 @@ namespace CodeImp.DoomBuilder.Data
// Get width and height from image
width = bitmap.Size.Width;
height = bitmap.Size.Height;
scaledwidth = (float)bitmap.Size.Width * General.Map.Config.DefaultTextureScale;
scaledheight = (float)bitmap.Size.Height * General.Map.Config.DefaultTextureScale;
// Pass on to base
base.LocalLoadImage();

View file

@ -102,13 +102,16 @@ namespace CodeImp.DoomBuilder.Data
// Constructor
public ImageData()
{
// We have no destructor
GC.SuppressFinalize(this);
// Defaults
usecolorcorrection = true;
}
// Destructor
~ImageData()
{
this.Dispose();
}
// Disposer
public virtual void Dispose()
{
@ -243,6 +246,8 @@ namespace CodeImp.DoomBuilder.Data
bitmap = new Bitmap(Properties.Resources.Failed);
width = bitmap.Size.Width;
height = bitmap.Size.Height;
scaledwidth = (float)bitmap.Size.Width * General.Map.Config.DefaultTextureScale;
scaledheight = (float)bitmap.Size.Height * General.Map.Config.DefaultTextureScale;
}
// Image is ready

View file

@ -41,6 +41,20 @@ namespace CodeImp.DoomBuilder.Data
// Initialize
SetName(resourcename);
// Temporarily load resource from memory
Stream bitmapdata = General.ThisAssembly.GetManifestResourceStream("CodeImp.DoomBuilder.Resources." + Name);
Bitmap bmp = (Bitmap)Image.FromStream(bitmapdata);
// Get width and height from image
width = bmp.Size.Width;
height = bmp.Size.Height;
scaledwidth = (float)bmp.Size.Width;
scaledheight = (float)bmp.Size.Height;
// Done
bmp.Dispose();
bitmapdata.Dispose();
// We have no destructor
GC.SuppressFinalize(this);
}

View file

@ -45,6 +45,7 @@ namespace CodeImp.DoomBuilder.Editing
public const int SOURCE_TEXTURES = 0;
public const int SOURCE_FLATS = 1;
public const int SOURCE_FILE = 2;
#endregion
@ -60,6 +61,7 @@ namespace CodeImp.DoomBuilder.Editing
private int backsource;
private ImageData backimage = new NullImage();
private int backoffsetx, backoffsety;
private float backscalex, backscaley;
// Disposing
private bool isdisposed;
@ -75,6 +77,8 @@ namespace CodeImp.DoomBuilder.Editing
internal ImageData Background { get { return backimage; } }
internal int BackgroundX { get { return backoffsetx; } }
internal int BackgroundY { get { return backoffsety; } }
internal float BackgroundScaleX { get { return backscalex; } }
internal float BackgroundScaleY { get { return backscaley; } }
internal bool Disposed { get { return isdisposed; } }
#endregion
@ -86,6 +90,8 @@ namespace CodeImp.DoomBuilder.Editing
{
// Initialize
SetGridSize(DEFAULT_GRID_SIZE);
backscalex = 1.0f;
backscaley = 1.0f;
// Register actions
General.Actions.BindMethods(this);
@ -99,6 +105,9 @@ namespace CodeImp.DoomBuilder.Editing
{
if(!isdisposed)
{
// Dispose image if needed
if(backimage is FileImage) (backimage as FileImage).Dispose();
// Clean up
backimage = null;
@ -138,28 +147,36 @@ namespace CodeImp.DoomBuilder.Editing
LinkBackground();
}
// This sets the background offset
internal void SetBackgroundOffset(int offsetx, int offsety)
// This sets the background view
internal void SetBackgroundView(int offsetx, int offsety, float scalex, float scaley)
{
// Set background offset
this.backoffsetx = offsetx;
this.backoffsety = offsety;
this.backscalex = scalex;
this.backscaley = scaley;
}
// This finds and links the background image
internal void LinkBackground()
{
// From textures?
if(backsource == SOURCE_TEXTURES)
// Dispose image if needed
if(backimage is FileImage) (backimage as FileImage).Dispose();
// Where to load background from?
switch(backsource)
{
// Get this texture
case SOURCE_TEXTURES:
backimage = General.Map.Data.GetTextureImage(background);
}
// From flats?
else if(backsource == SOURCE_FLATS)
{
// Get this flat
break;
case SOURCE_FLATS:
backimage = General.Map.Data.GetFlatImage(background);
break;
case SOURCE_FILE:
backimage = new FileImage(background, background);
break;
}
// Make sure it is loaded

View file

@ -731,7 +731,11 @@ namespace CodeImp.DoomBuilder.Rendering
{
Vector2D ltpos, rbpos;
Vector2D backoffset = new Vector2D((float)General.Map.Grid.BackgroundX, (float)General.Map.Grid.BackgroundY);
Vector2D backimagesize = new Vector2D((float)General.Map.Grid.Background.Width, (float)General.Map.Grid.Background.Height);
Vector2D backimagesize = new Vector2D((float)General.Map.Grid.Background.ScaledWidth, (float)General.Map.Grid.Background.ScaledHeight);
Vector2D backimagescale = new Vector2D(General.Map.Grid.BackgroundScaleX, General.Map.Grid.BackgroundScaleY);
// Scale the background image size
backimagesize *= backimagescale;
// Only if a background image is set
if((General.Map.Grid.Background != null) &&

View file

@ -32,6 +32,10 @@ namespace CodeImp.DoomBuilder.Windows
System.Windows.Forms.Label label1;
System.Windows.Forms.GroupBox groupBox2;
this.gridsize = new System.Windows.Forms.NumericUpDown();
this.backscaley = new System.Windows.Forms.NumericUpDown();
this.backscalex = new System.Windows.Forms.NumericUpDown();
this.backscale = new System.Windows.Forms.Label();
this.selectfile = new System.Windows.Forms.Button();
this.showbackground = new System.Windows.Forms.CheckBox();
this.backoffsety = new System.Windows.Forms.NumericUpDown();
this.backoffsetx = new System.Windows.Forms.NumericUpDown();
@ -41,18 +45,23 @@ namespace CodeImp.DoomBuilder.Windows
this.backgroundimage = new System.Windows.Forms.Panel();
this.cancel = new System.Windows.Forms.Button();
this.apply = new System.Windows.Forms.Button();
this.browsefile = new System.Windows.Forms.OpenFileDialog();
groupBox1 = new System.Windows.Forms.GroupBox();
label1 = new System.Windows.Forms.Label();
groupBox2 = new System.Windows.Forms.GroupBox();
groupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.gridsize)).BeginInit();
groupBox2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.backscaley)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.backscalex)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.backoffsety)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.backoffsetx)).BeginInit();
this.SuspendLayout();
//
// groupBox1
//
groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
groupBox1.Controls.Add(this.gridsize);
groupBox1.Controls.Add(label1);
groupBox1.Location = new System.Drawing.Point(12, 12);
@ -96,6 +105,12 @@ namespace CodeImp.DoomBuilder.Windows
//
// groupBox2
//
groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)));
groupBox2.Controls.Add(this.backscaley);
groupBox2.Controls.Add(this.backscalex);
groupBox2.Controls.Add(this.backscale);
groupBox2.Controls.Add(this.selectfile);
groupBox2.Controls.Add(this.showbackground);
groupBox2.Controls.Add(this.backoffsety);
groupBox2.Controls.Add(this.backoffsetx);
@ -105,11 +120,80 @@ namespace CodeImp.DoomBuilder.Windows
groupBox2.Controls.Add(this.backgroundimage);
groupBox2.Location = new System.Drawing.Point(12, 89);
groupBox2.Name = "groupBox2";
groupBox2.Size = new System.Drawing.Size(285, 181);
groupBox2.Size = new System.Drawing.Size(285, 255);
groupBox2.TabIndex = 1;
groupBox2.TabStop = false;
groupBox2.Text = " Background ";
//
// backscaley
//
this.backscaley.Enabled = false;
this.backscaley.ImeMode = System.Windows.Forms.ImeMode.Off;
this.backscaley.Location = new System.Drawing.Point(197, 209);
this.backscaley.Maximum = new decimal(new int[] {
1000,
0,
0,
0});
this.backscaley.Minimum = new decimal(new int[] {
1,
0,
0,
0});
this.backscaley.Name = "backscaley";
this.backscaley.Size = new System.Drawing.Size(57, 20);
this.backscaley.TabIndex = 11;
this.backscaley.Value = new decimal(new int[] {
1,
0,
0,
0});
//
// backscalex
//
this.backscalex.Enabled = false;
this.backscalex.ImeMode = System.Windows.Forms.ImeMode.Off;
this.backscalex.Location = new System.Drawing.Point(134, 209);
this.backscalex.Maximum = new decimal(new int[] {
1000,
0,
0,
0});
this.backscalex.Minimum = new decimal(new int[] {
1,
0,
0,
0});
this.backscalex.Name = "backscalex";
this.backscalex.Size = new System.Drawing.Size(57, 20);
this.backscalex.TabIndex = 10;
this.backscalex.Value = new decimal(new int[] {
1,
0,
0,
0});
//
// backscale
//
this.backscale.AutoSize = true;
this.backscale.Enabled = false;
this.backscale.Location = new System.Drawing.Point(40, 211);
this.backscale.Name = "backscale";
this.backscale.Size = new System.Drawing.Size(88, 14);
this.backscale.TabIndex = 9;
this.backscale.Text = "Scale in percent:";
//
// selectfile
//
this.selectfile.Enabled = false;
this.selectfile.Location = new System.Drawing.Point(137, 122);
this.selectfile.Name = "selectfile";
this.selectfile.Size = new System.Drawing.Size(117, 25);
this.selectfile.TabIndex = 8;
this.selectfile.Text = "Select File...";
this.selectfile.UseVisualStyleBackColor = true;
this.selectfile.Click += new System.EventHandler(this.selectfile_Click);
//
// showbackground
//
this.showbackground.AutoSize = true;
@ -125,7 +209,7 @@ namespace CodeImp.DoomBuilder.Windows
//
this.backoffsety.Enabled = false;
this.backoffsety.ImeMode = System.Windows.Forms.ImeMode.Off;
this.backoffsety.Location = new System.Drawing.Point(197, 137);
this.backoffsety.Location = new System.Drawing.Point(197, 172);
this.backoffsety.Maximum = new decimal(new int[] {
4096,
0,
@ -139,7 +223,7 @@ namespace CodeImp.DoomBuilder.Windows
//
this.backoffsetx.Enabled = false;
this.backoffsetx.ImeMode = System.Windows.Forms.ImeMode.Off;
this.backoffsetx.Location = new System.Drawing.Point(134, 137);
this.backoffsetx.Location = new System.Drawing.Point(134, 172);
this.backoffsetx.Maximum = new decimal(new int[] {
4096,
0,
@ -153,7 +237,7 @@ namespace CodeImp.DoomBuilder.Windows
//
this.backoffset.AutoSize = true;
this.backoffset.Enabled = false;
this.backoffset.Location = new System.Drawing.Point(25, 140);
this.backoffset.Location = new System.Drawing.Point(25, 175);
this.backoffset.Name = "backoffset";
this.backoffset.Size = new System.Drawing.Size(103, 14);
this.backoffset.TabIndex = 4;
@ -162,7 +246,7 @@ namespace CodeImp.DoomBuilder.Windows
// selectflat
//
this.selectflat.Enabled = false;
this.selectflat.Location = new System.Drawing.Point(92, 91);
this.selectflat.Location = new System.Drawing.Point(137, 91);
this.selectflat.Name = "selectflat";
this.selectflat.Size = new System.Drawing.Size(117, 25);
this.selectflat.TabIndex = 3;
@ -173,7 +257,7 @@ namespace CodeImp.DoomBuilder.Windows
// selecttexture
//
this.selecttexture.Enabled = false;
this.selecttexture.Location = new System.Drawing.Point(92, 60);
this.selecttexture.Location = new System.Drawing.Point(137, 60);
this.selecttexture.Name = "selecttexture";
this.selecttexture.Size = new System.Drawing.Size(117, 25);
this.selecttexture.TabIndex = 2;
@ -188,13 +272,14 @@ namespace CodeImp.DoomBuilder.Windows
this.backgroundimage.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.backgroundimage.Location = new System.Drawing.Point(28, 60);
this.backgroundimage.Name = "backgroundimage";
this.backgroundimage.Size = new System.Drawing.Size(58, 56);
this.backgroundimage.Size = new System.Drawing.Size(91, 87);
this.backgroundimage.TabIndex = 1;
//
// cancel
//
this.cancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.cancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.cancel.Location = new System.Drawing.Point(185, 283);
this.cancel.Location = new System.Drawing.Point(185, 357);
this.cancel.Name = "cancel";
this.cancel.Size = new System.Drawing.Size(112, 25);
this.cancel.TabIndex = 22;
@ -204,7 +289,8 @@ namespace CodeImp.DoomBuilder.Windows
//
// apply
//
this.apply.Location = new System.Drawing.Point(67, 283);
this.apply.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.apply.Location = new System.Drawing.Point(67, 357);
this.apply.Name = "apply";
this.apply.Size = new System.Drawing.Size(112, 25);
this.apply.TabIndex = 21;
@ -212,12 +298,18 @@ namespace CodeImp.DoomBuilder.Windows
this.apply.UseVisualStyleBackColor = true;
this.apply.Click += new System.EventHandler(this.apply_Click);
//
// browsefile
//
this.browsefile.Filter = "All supported images|*.bmp;*.jpg;*.png|All Files|*.*";
this.browsefile.RestoreDirectory = true;
this.browsefile.Title = "Select Background Image File";
//
// GridSetupForm
//
this.AcceptButton = this.apply;
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.CancelButton = this.cancel;
this.ClientSize = new System.Drawing.Size(309, 318);
this.ClientSize = new System.Drawing.Size(309, 392);
this.Controls.Add(this.cancel);
this.Controls.Add(this.apply);
this.Controls.Add(groupBox2);
@ -237,6 +329,8 @@ namespace CodeImp.DoomBuilder.Windows
((System.ComponentModel.ISupportInitialize)(this.gridsize)).EndInit();
groupBox2.ResumeLayout(false);
groupBox2.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.backscaley)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.backscalex)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.backoffsety)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.backoffsetx)).EndInit();
this.ResumeLayout(false);
@ -255,5 +349,10 @@ namespace CodeImp.DoomBuilder.Windows
private System.Windows.Forms.Button cancel;
private System.Windows.Forms.Button apply;
private System.Windows.Forms.Label backoffset;
private System.Windows.Forms.Button selectfile;
private System.Windows.Forms.NumericUpDown backscaley;
private System.Windows.Forms.NumericUpDown backscalex;
private System.Windows.Forms.Label backscale;
private System.Windows.Forms.OpenFileDialog browsefile;
}
}

View file

@ -68,6 +68,8 @@ namespace CodeImp.DoomBuilder.Windows
// Show background offset
backoffsetx.Value = General.Map.Grid.BackgroundX;
backoffsety.Value = General.Map.Grid.BackgroundY;
backscalex.Value = (int)(General.Map.Grid.BackgroundScaleX * 100.0f);
backscaley.Value = (int)(General.Map.Grid.BackgroundScaleY * 100.0f);
}
// Show Background changed
@ -76,9 +78,13 @@ namespace CodeImp.DoomBuilder.Windows
// Enable/disable controls
selecttexture.Enabled = showbackground.Checked;
selectflat.Enabled = showbackground.Checked;
selectfile.Enabled = showbackground.Checked;
backoffset.Enabled = showbackground.Checked;
backscale.Enabled = showbackground.Checked;
backoffsetx.Enabled = showbackground.Checked;
backoffsety.Enabled = showbackground.Checked;
backscalex.Enabled = showbackground.Checked;
backscaley.Enabled = showbackground.Checked;
}
// Browse texture
@ -93,7 +99,9 @@ namespace CodeImp.DoomBuilder.Windows
// Set this texture as background
backgroundname = result;
backgroundsource = GridSetup.SOURCE_TEXTURES;
General.DisplayZoomedImage(backgroundimage, General.Map.Data.GetTextureImage(result).GetPreview());
ImageData img = General.Map.Data.GetTextureImage(result);
img.LoadImage();
General.DisplayZoomedImage(backgroundimage, img.Bitmap);
}
}
@ -109,7 +117,25 @@ namespace CodeImp.DoomBuilder.Windows
// Set this flat as background
backgroundname = result;
backgroundsource = GridSetup.SOURCE_FLATS;
General.DisplayZoomedImage(backgroundimage, General.Map.Data.GetFlatImage(result).GetPreview());
ImageData img = General.Map.Data.GetFlatImage(result);
img.LoadImage();
General.DisplayZoomedImage(backgroundimage, img.Bitmap);
}
}
// Browse file
private void selectfile_Click(object sender, EventArgs e)
{
// Browse for file
if(browsefile.ShowDialog(this) == DialogResult.OK)
{
// Set this file as background
backgroundname = browsefile.FileName;
backgroundsource = GridSetup.SOURCE_FILE;
ImageData img = new FileImage(backgroundname, backgroundname);
img.LoadImage();
General.DisplayZoomedImage(backgroundimage, new Bitmap(img.Bitmap));
img.Dispose();
}
}
@ -125,7 +151,8 @@ namespace CodeImp.DoomBuilder.Windows
{
// Apply
General.Map.Grid.SetGridSize((int)gridsize.Value);
General.Map.Grid.SetBackgroundOffset((int)backoffsetx.Value, (int)backoffsety.Value);
General.Map.Grid.SetBackgroundView((int)backoffsetx.Value, (int)backoffsety.Value,
(float)backscalex.Value / 100.0f, (float)backscaley.Value / 100.0f);
// Background image?
if(showbackground.Checked)

View file

@ -117,12 +117,12 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="groupBox1.GenerateMember" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="groupBox1.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="groupBox1.GenerateMember" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="gridsize.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
@ -132,12 +132,33 @@
<metadata name="label1.GenerateMember" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="groupBox2.GenerateMember" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<metadata name="gridsize.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="label1.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="label1.GenerateMember" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="groupBox2.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="groupBox2.GenerateMember" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="backscaley.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="backscalex.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="backscale.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="selectfile.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="showbackground.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
@ -165,6 +186,9 @@
<metadata name="apply.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="browsefile.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="$this.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>