2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#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.Drawing;
|
|
|
|
using CodeImp.DoomBuilder.Windows;
|
2013-06-17 13:17:53 +00:00
|
|
|
using CodeImp.DoomBuilder.Data;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.Controls
|
|
|
|
{
|
|
|
|
public class TextureSelectorControl : ImageSelectorControl
|
|
|
|
{
|
|
|
|
// Variables
|
|
|
|
private bool required;
|
|
|
|
|
|
|
|
// Properties
|
|
|
|
public bool Required { get { return required; } set { required = value; } }
|
|
|
|
|
|
|
|
// Setup
|
2009-07-09 22:43:39 +00:00
|
|
|
public override void Initialize()
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2009-07-09 22:43:39 +00:00
|
|
|
base.Initialize();
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// Fill autocomplete list
|
|
|
|
name.AutoCompleteCustomSource.AddRange(General.Map.Data.TextureNames.ToArray());
|
2014-03-06 11:45:20 +00:00
|
|
|
|
|
|
|
//mxd
|
|
|
|
if(required) Refresh();
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This finds the image we need for the given texture name
|
|
|
|
protected override Image FindImage(string imagename)
|
|
|
|
{
|
2013-11-21 10:53:11 +00:00
|
|
|
timer.Stop(); //mxd
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// Check if name is a "none" texture
|
2014-11-25 11:52:01 +00:00
|
|
|
if(string.IsNullOrEmpty(imagename))
|
|
|
|
{
|
2013-07-08 13:13:28 +00:00
|
|
|
DisplayImageSize(0, 0); //mxd
|
2014-12-03 09:06:05 +00:00
|
|
|
UpdateToggleImageNameButton(null); //mxd
|
2013-06-17 13:17:53 +00:00
|
|
|
|
2014-03-05 09:21:28 +00:00
|
|
|
//mxd. Determine image to show
|
2015-12-28 15:01:53 +00:00
|
|
|
if(multipletextures) return Properties.Resources.ImageStack;
|
2014-03-05 09:21:28 +00:00
|
|
|
return (required ? Properties.Resources.MissingTexture : null);
|
|
|
|
}
|
|
|
|
else if(imagename == "-") //mxd
|
|
|
|
{
|
|
|
|
DisplayImageSize(0, 0);
|
2014-12-03 09:06:05 +00:00
|
|
|
UpdateToggleImageNameButton(null); //mxd
|
2014-03-05 09:21:28 +00:00
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// Determine image to show
|
2014-02-21 14:42:12 +00:00
|
|
|
return (required ? Properties.Resources.MissingTexture : null);
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
else
|
|
|
|
{
|
2013-07-08 13:13:28 +00:00
|
|
|
ImageData texture = General.Map.Data.GetTextureImage(imagename); //mxd
|
2014-12-03 09:06:05 +00:00
|
|
|
UpdateToggleImageNameButton(texture); //mxd
|
2013-07-08 13:13:28 +00:00
|
|
|
|
2015-11-17 17:50:56 +00:00
|
|
|
if(string.IsNullOrEmpty(texture.FilePathName) || texture is UnknownImage) DisplayImageSize(0, 0); //mxd
|
2013-07-08 13:13:28 +00:00
|
|
|
else DisplayImageSize(texture.ScaledWidth, texture.ScaledHeight); //mxd
|
2016-03-01 23:24:41 +00:00
|
|
|
|
|
|
|
if(usepreviews && !texture.IsPreviewLoaded) timer.Start(); //mxd
|
|
|
|
else if(!texture.IsImageLoaded) texture.LoadImage(); //mxd. In some cases the image may never me loaded by the DataManager
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// Set the image
|
2016-03-04 08:10:56 +00:00
|
|
|
// mxd. GetPreview() returns a copy of preview, GetBitmap() returns actual bitmap
|
|
|
|
return (usepreviews ? texture.GetPreview() : new Bitmap(texture.GetBitmap()));
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This browses for a texture
|
2014-11-25 11:52:01 +00:00
|
|
|
protected override string BrowseImage(string imagename)
|
|
|
|
{
|
2009-04-19 18:07:22 +00:00
|
|
|
// Browse for texture
|
2014-02-21 14:42:12 +00:00
|
|
|
string result = TextureBrowserForm.Browse(this.ParentForm, imagename, false);
|
|
|
|
return result ?? imagename;
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|