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;
|
2014-03-06 09:08:21 +00:00
|
|
|
using System.ComponentModel;
|
2009-04-19 18:07:22 +00:00
|
|
|
using System.Drawing;
|
|
|
|
using System.Windows.Forms;
|
2014-12-03 09:06:05 +00:00
|
|
|
using CodeImp.DoomBuilder.Data;
|
2009-04-19 18:07:22 +00:00
|
|
|
using SlimDX;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.Controls
|
|
|
|
{
|
2009-05-21 08:18:34 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Abstract control that provides a list of images.
|
|
|
|
/// </summary>
|
2009-04-19 18:07:22 +00:00
|
|
|
public abstract partial class ImageSelectorControl : UserControl
|
|
|
|
{
|
|
|
|
#region ================== Variables
|
|
|
|
|
2013-03-18 13:52:27 +00:00
|
|
|
public event EventHandler OnValueChanged; //mxd
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
private MouseButtons button;
|
2014-12-03 09:06:05 +00:00
|
|
|
private ImageData image; //mxd
|
2014-12-19 09:24:22 +00:00
|
|
|
private string previousimagename; //mxd
|
2014-03-05 09:21:28 +00:00
|
|
|
protected bool multipletextures; //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Properties
|
|
|
|
|
|
|
|
public string TextureName { get { return name.Text; } set { name.Text = value; } }
|
2014-11-25 11:52:01 +00:00
|
|
|
|
2014-03-06 09:08:21 +00:00
|
|
|
[Browsable(false)]
|
2014-03-05 09:21:28 +00:00
|
|
|
public bool MultipleTextures { get { return multipletextures; } set { multipletextures = value; } }
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Constructor / Destructor
|
|
|
|
|
|
|
|
// Constructor
|
2015-05-27 12:38:03 +00:00
|
|
|
protected ImageSelectorControl()
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
// Initialize
|
|
|
|
InitializeComponent();
|
2009-07-09 22:43:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Setup
|
|
|
|
public virtual void Initialize()
|
|
|
|
{
|
2009-06-08 18:52:56 +00:00
|
|
|
// set the max length of texture names
|
2014-05-19 13:33:38 +00:00
|
|
|
name.MaxLength = General.Map.Config.MaxTextureNameLength;
|
2016-12-22 15:04:40 +00:00
|
|
|
if(!General.Map.Options.UseLongTextureNames) this.name.CharacterCasing = CharacterCasing.Upper; //mxd
|
2014-11-25 11:52:01 +00:00
|
|
|
labelSize.BackColor = Color.FromArgb(196, labelSize.BackColor);
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Events
|
|
|
|
|
|
|
|
// When resized
|
|
|
|
private void ImageSelectorControl_Resize(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
// Fixed size
|
|
|
|
preview.Width = this.ClientSize.Width;
|
|
|
|
preview.Height = this.ClientSize.Height - name.Height - 4;
|
|
|
|
name.Width = this.ClientSize.Width;
|
|
|
|
name.Top = this.ClientSize.Height - name.Height;
|
2014-12-03 09:06:05 +00:00
|
|
|
togglefullname.Left = preview.Right - togglefullname.Width - 1; //mxd
|
|
|
|
togglefullname.Top = preview.Bottom - togglefullname.Height - 1; //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Layout change
|
|
|
|
private void ImageSelectorControl_Layout(object sender, LayoutEventArgs e)
|
|
|
|
{
|
|
|
|
ImageSelectorControl_Resize(sender, EventArgs.Empty);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Image clicked
|
|
|
|
private void preview_Click(object sender, EventArgs e)
|
|
|
|
{
|
2014-11-25 11:52:01 +00:00
|
|
|
imagebox.BackColor = SystemColors.Highlight;
|
2015-12-28 15:01:53 +00:00
|
|
|
switch(button)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2015-07-15 09:09:47 +00:00
|
|
|
case MouseButtons.Right: name.Text = "-"; break;
|
2016-12-22 15:04:40 +00:00
|
|
|
case MouseButtons.Left:
|
|
|
|
// We need to change CharacterCasing before applying the text, so let's hack around a bit...
|
|
|
|
string newname = BrowseImage(name.Text);
|
|
|
|
name.CharacterCasing = (IsLongTextureName(newname) ? CharacterCasing.Normal : CharacterCasing.Upper);
|
|
|
|
name.Text = newname;
|
|
|
|
break;
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Name text changed
|
|
|
|
private void name_TextChanged(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
// Show it centered
|
|
|
|
ShowPreview(FindImage(name.Text));
|
2014-11-25 11:52:01 +00:00
|
|
|
|
|
|
|
// Update tooltip (mxd)
|
|
|
|
tooltip.SetToolTip(imagebox, name.Text);
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Mouse pressed
|
|
|
|
private void preview_MouseDown(object sender, MouseEventArgs e)
|
|
|
|
{
|
|
|
|
button = e.Button;
|
2013-08-26 10:51:33 +00:00
|
|
|
if((button == MouseButtons.Left) || ((button == MouseButtons.Right)))
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2014-11-25 11:52:01 +00:00
|
|
|
imagebox.BackColor = AdjustedColor(SystemColors.Highlight, 0.2f);
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mouse leaves
|
|
|
|
private void preview_MouseLeave(object sender, EventArgs e)
|
|
|
|
{
|
2014-11-25 11:52:01 +00:00
|
|
|
imagebox.BackColor = SystemColors.AppWorkspace;
|
2015-03-27 09:51:19 +00:00
|
|
|
imagebox.Highlighted = false;
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Mouse enters
|
|
|
|
private void preview_MouseEnter(object sender, EventArgs e)
|
|
|
|
{
|
2014-11-25 11:52:01 +00:00
|
|
|
imagebox.BackColor = SystemColors.Highlight;
|
2015-03-27 09:51:19 +00:00
|
|
|
imagebox.Highlighted = true;
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
2013-11-21 10:53:11 +00:00
|
|
|
|
|
|
|
//mxd
|
2014-05-19 13:33:38 +00:00
|
|
|
private void timer_Tick(object sender, EventArgs e)
|
|
|
|
{
|
2013-11-21 10:53:11 +00:00
|
|
|
Refresh();
|
|
|
|
}
|
2014-01-09 11:31:34 +00:00
|
|
|
|
|
|
|
//mxd
|
2014-05-19 13:33:38 +00:00
|
|
|
private void ImageSelectorControl_EnabledChanged(object sender, EventArgs e)
|
|
|
|
{
|
2014-01-09 11:31:34 +00:00
|
|
|
labelSize.Visible = !(!General.Settings.ShowTextureSizes || !this.Enabled || string.IsNullOrEmpty(labelSize.Text));
|
|
|
|
}
|
2014-12-03 09:06:05 +00:00
|
|
|
|
|
|
|
//mxd
|
|
|
|
private void togglefullname_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
// Toggle between short and full name
|
2016-12-22 15:04:40 +00:00
|
|
|
if(string.Compare(name.Text, image.ShortName, StringComparison.OrdinalIgnoreCase) == 0)
|
|
|
|
{
|
|
|
|
name.CharacterCasing = CharacterCasing.Normal;
|
|
|
|
name.Text = image.Name;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
name.CharacterCasing = CharacterCasing.Upper;
|
|
|
|
name.Text = image.ShortName;
|
|
|
|
}
|
2014-12-03 09:06:05 +00:00
|
|
|
|
|
|
|
// Update icon and tooltip
|
|
|
|
UpdateToggleImageNameButton(image);
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Methods
|
|
|
|
|
|
|
|
// This refreshes the control
|
|
|
|
new public void Refresh()
|
|
|
|
{
|
2013-11-27 15:38:03 +00:00
|
|
|
if(General.Map == null) return;
|
2009-04-19 18:07:22 +00:00
|
|
|
ShowPreview(FindImage(name.Text));
|
|
|
|
base.Refresh();
|
|
|
|
}
|
2015-09-16 12:10:43 +00:00
|
|
|
|
|
|
|
//mxd
|
|
|
|
public void StopUpdate()
|
|
|
|
{
|
|
|
|
timer.Stop();
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// This redraws the image preview
|
|
|
|
private void ShowPreview(Image image)
|
|
|
|
{
|
|
|
|
// Dispose old image
|
2014-12-19 09:24:22 +00:00
|
|
|
imagebox.Image = null;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
if(image != null)
|
|
|
|
{
|
|
|
|
// Show it centered
|
2014-11-25 11:52:01 +00:00
|
|
|
imagebox.Image = image;
|
|
|
|
imagebox.Refresh();
|
2013-07-09 11:29:10 +00:00
|
|
|
}
|
2013-03-18 13:52:27 +00:00
|
|
|
|
2013-07-09 11:29:10 +00:00
|
|
|
//mxd. Dispatch event
|
2014-12-19 09:24:22 +00:00
|
|
|
if(OnValueChanged != null && previousimagename != name.Text)
|
2014-11-25 11:52:01 +00:00
|
|
|
{
|
2014-12-19 09:24:22 +00:00
|
|
|
previousimagename = name.Text;
|
2013-07-09 11:29:10 +00:00
|
|
|
OnValueChanged(this, EventArgs.Empty);
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
}
|
2013-06-17 13:17:53 +00:00
|
|
|
|
|
|
|
//mxd
|
Fixed, Texture previews: texture size labels were displaying incorrect size or no size at all when showing TEXTURES textures with negative scale.
Fixed, Visual mode, UDMF: when several wall parts were selected, only one could be dragged with the mouse.
Fixed, Visual mode, Auto-align textures, UDMF: TEXTURES scale is now taken into account when aligning textures.
Fixed, Visual mode, Auto-align textures (Y), UDMF: nearest height matching is now applied to non-wrapped middle backsides.
Cosmetic changes in ZDoom_ACS.cfg.
2015-01-27 11:40:25 +00:00
|
|
|
protected void DisplayImageSize(float width, float height)
|
2014-05-19 13:33:38 +00:00
|
|
|
{
|
Fixed, Texture previews: texture size labels were displaying incorrect size or no size at all when showing TEXTURES textures with negative scale.
Fixed, Visual mode, UDMF: when several wall parts were selected, only one could be dragged with the mouse.
Fixed, Visual mode, Auto-align textures, UDMF: TEXTURES scale is now taken into account when aligning textures.
Fixed, Visual mode, Auto-align textures (Y), UDMF: nearest height matching is now applied to non-wrapped middle backsides.
Cosmetic changes in ZDoom_ACS.cfg.
2015-01-27 11:40:25 +00:00
|
|
|
width = Math.Abs(width);
|
|
|
|
height = Math.Abs(height);
|
2014-01-09 11:31:34 +00:00
|
|
|
labelSize.Text = (width > 0 && height > 0) ? width + "x" + height : string.Empty;
|
|
|
|
ImageSelectorControl_EnabledChanged(this, EventArgs.Empty);
|
2013-06-17 13:17:53 +00:00
|
|
|
}
|
2016-12-22 15:04:40 +00:00
|
|
|
|
|
|
|
//mxd
|
|
|
|
private bool IsLongTextureName(string imagename)
|
|
|
|
{
|
|
|
|
if(!General.Map.Config.UseLongTextureNames || string.IsNullOrEmpty(imagename) || imagename == "-")
|
|
|
|
return false;
|
|
|
|
|
|
|
|
ImageData texture = GetImageData(imagename);
|
|
|
|
if(texture == null || !texture.HasLongName) return false;
|
|
|
|
|
|
|
|
return string.Compare(imagename, texture.ShortName, StringComparison.OrdinalIgnoreCase) != 0;
|
|
|
|
}
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// This must determine and return the image to show
|
|
|
|
protected abstract Image FindImage(string imagename);
|
|
|
|
|
2016-12-22 15:04:40 +00:00
|
|
|
//mxd. This gets ImageData by name...
|
|
|
|
protected abstract ImageData GetImageData(string imagename);
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// This must show the image browser and return the selected texture name
|
|
|
|
protected abstract string BrowseImage(string imagename);
|
|
|
|
|
2014-12-03 09:06:05 +00:00
|
|
|
protected void UpdateToggleImageNameButton(ImageData image)
|
|
|
|
{
|
|
|
|
this.image = image;
|
|
|
|
|
|
|
|
// Update visibility
|
|
|
|
if(!General.Map.Config.UseLongTextureNames || image == null || !image.HasLongName)
|
|
|
|
{
|
|
|
|
togglefullname.Visible = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update icon and tooltip
|
|
|
|
togglefullname.Visible = true;
|
2016-12-22 15:04:40 +00:00
|
|
|
if(string.Compare(image.ShortName, name.Text, StringComparison.OrdinalIgnoreCase) == 0)
|
2014-12-03 09:06:05 +00:00
|
|
|
{
|
|
|
|
togglefullname.Image = Properties.Resources.Expand;
|
|
|
|
tooltip.SetToolTip(togglefullname, "Switch to full name");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
togglefullname.Image = Properties.Resources.Collapse;
|
|
|
|
tooltip.SetToolTip(togglefullname, "Switch to short name");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// This determines the result value
|
|
|
|
public string GetResult(string original)
|
|
|
|
{
|
|
|
|
// Anyting entered?
|
|
|
|
if(name.Text.Trim().Length > 0)
|
|
|
|
{
|
|
|
|
// Return the new value
|
|
|
|
return name.Text;
|
|
|
|
}
|
2014-05-20 09:09:28 +00:00
|
|
|
|
|
|
|
// Nothing given, keep original value
|
|
|
|
return original;
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This brightens or darkens a color
|
2014-05-20 09:09:28 +00:00
|
|
|
private static Color AdjustedColor(Color c, float amount)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
Color4 cc = new Color4(c);
|
|
|
|
|
|
|
|
// Adjust color
|
|
|
|
cc.Red = Saturate((cc.Red * (1f + amount)) + (amount * 0.5f));
|
|
|
|
cc.Green = Saturate((cc.Green * (1f + amount)) + (amount * 0.5f));
|
|
|
|
cc.Blue = Saturate((cc.Blue * (1f + amount)) + (amount * 0.5f));
|
|
|
|
|
|
|
|
// Return result
|
|
|
|
return Color.FromArgb(cc.ToArgb());
|
|
|
|
}
|
|
|
|
|
|
|
|
// This clamps a value between 0 and 1
|
2014-03-05 09:21:28 +00:00
|
|
|
private static float Saturate(float v)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2014-01-09 11:31:34 +00:00
|
|
|
if(v < 0f) return 0f;
|
|
|
|
if(v > 1f) return 1f;
|
|
|
|
return v;
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|