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;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Drawing;
|
|
|
|
using System.Windows.Forms;
|
|
|
|
using CodeImp.DoomBuilder.Data;
|
2015-04-03 12:05:37 +00:00
|
|
|
using CodeImp.DoomBuilder.Windows;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.Controls
|
|
|
|
{
|
|
|
|
internal partial class ImageBrowserControl : UserControl
|
|
|
|
{
|
|
|
|
#region ================== Constants
|
|
|
|
|
2016-12-22 15:04:40 +00:00
|
|
|
private static readonly HashSet<char> AllowedSpecialChars = new HashSet<char>("!@#$%^&*()-_=+<>,.?/'\"\\;:[]{}`~".ToCharArray()); //mxd
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Delegates / Events
|
|
|
|
|
2016-12-22 15:04:40 +00:00
|
|
|
public delegate void SelectedItemChangedDelegate(ImageBrowserItem item);
|
|
|
|
public delegate void SelectedItemDoubleClickDelegate(ImageBrowserItem item);
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
public event SelectedItemChangedDelegate SelectedItemChanged;
|
|
|
|
public event SelectedItemDoubleClickDelegate SelectedItemDoubleClicked;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Variables
|
|
|
|
|
|
|
|
// Properties
|
|
|
|
private bool preventselection;
|
|
|
|
|
|
|
|
// States
|
|
|
|
private int keepselected;
|
2016-12-22 15:04:40 +00:00
|
|
|
private bool browseflats; //mxd
|
|
|
|
private bool uselongtexturenames; //mxd
|
|
|
|
private bool blockupdate; //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
|
2016-12-22 15:04:40 +00:00
|
|
|
//mxd. All items
|
2016-12-23 12:39:09 +00:00
|
|
|
private List<ImageBrowserItem> items;
|
|
|
|
private string usedfirstgroup;
|
|
|
|
private string availgroup;
|
2009-05-05 12:24:00 +00:00
|
|
|
|
2016-12-22 15:04:40 +00:00
|
|
|
// Filtered items
|
2009-05-05 12:24:00 +00:00
|
|
|
private List<ImageBrowserItem> visibleitems;
|
2013-03-26 12:31:07 +00:00
|
|
|
|
|
|
|
//mxd
|
2016-12-22 15:04:40 +00:00
|
|
|
private int texturetype;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Properties
|
|
|
|
|
|
|
|
public bool PreventSelection { get { return preventselection; } set { preventselection = value; } }
|
|
|
|
public bool HideInputBox { get { return splitter.Panel2Collapsed; } set { splitter.Panel2Collapsed = value; } }
|
2016-12-22 15:04:40 +00:00
|
|
|
public List<ImageBrowserItem> SelectedItems { get { return list.SelectedItems; } } //mxd
|
|
|
|
public ImageBrowserItem SelectedItem { get { return (list.SelectedItems.Count > 0 ? list.SelectedItems[0] : null); } }
|
2016-12-23 12:39:09 +00:00
|
|
|
public string ElementName //mxd
|
|
|
|
{
|
|
|
|
set
|
|
|
|
{
|
|
|
|
usedfirstgroup = "Available " + value + " (used first):";
|
|
|
|
availgroup = "Available " + value + ":";
|
2017-01-09 04:47:58 +00:00
|
|
|
list.ContentType = value;
|
|
|
|
}
|
2016-12-23 12:39:09 +00:00
|
|
|
}
|
2016-12-22 15:04:40 +00:00
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Constructor / Disposer
|
|
|
|
|
|
|
|
// Constructor
|
|
|
|
public ImageBrowserControl()
|
|
|
|
{
|
|
|
|
// Initialize
|
|
|
|
InitializeComponent();
|
2016-12-23 12:39:09 +00:00
|
|
|
items = new List<ImageBrowserItem>();
|
2013-09-26 12:43:39 +00:00
|
|
|
|
2014-12-03 09:06:05 +00:00
|
|
|
//mxd
|
2013-09-26 12:43:39 +00:00
|
|
|
StepsList sizes = new StepsList { 4, 8, 16, 32, 48, 64, 96, 128, 196, 256, 512, 1024 };
|
|
|
|
filterWidth.StepValues = sizes;
|
|
|
|
filterHeight.StepValues = sizes;
|
2015-04-03 12:05:37 +00:00
|
|
|
|
|
|
|
//mxd. Looks like SplitterDistance is unaffected by DPI scaling. Let's fix that...
|
|
|
|
if(MainForm.DPIScaler.Height != 1.0f)
|
|
|
|
{
|
|
|
|
splitter.SplitterDistance = splitter.Height - splitter.Panel2.Height - (int)Math.Round(splitter.SplitterWidth * MainForm.DPIScaler.Height);
|
|
|
|
}
|
2016-12-22 15:04:40 +00:00
|
|
|
|
|
|
|
//mxd
|
|
|
|
list.SelectionChanged += list_SelectionChanged;
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
2016-12-22 15:04:40 +00:00
|
|
|
|
|
|
|
// This applies the application settings
|
|
|
|
public void ApplySettings(string settingpath, bool browseflats)
|
|
|
|
{
|
|
|
|
blockupdate = true;
|
|
|
|
|
|
|
|
this.browseflats = browseflats;
|
2017-01-09 05:21:26 +00:00
|
|
|
uselongtexturenames = General.Map.Options.UseLongTextureNames;
|
2016-12-22 15:04:40 +00:00
|
|
|
texturetype = General.Settings.ReadSetting(settingpath + ".texturetype", 0);
|
2017-01-09 05:21:26 +00:00
|
|
|
ElementName = (texturetype == 2 || (texturetype == 3 && browseflats)) ? "flats" : "textures";
|
2017-01-09 05:00:27 +00:00
|
|
|
list.UsedTexturesFirst = usedtexturesfirst.Checked = General.Settings.ReadSetting(settingpath + ".showusedtexturesfirst", false);
|
2017-01-09 04:47:58 +00:00
|
|
|
list.ClassicView = classicview.Checked = General.Settings.ReadSetting(settingpath + ".classicview", false);
|
2016-12-22 15:04:40 +00:00
|
|
|
|
|
|
|
int imagesize = General.Settings.ReadSetting(settingpath + ".imagesize", 128);
|
|
|
|
sizecombo.Text = (imagesize == 0 ? sizecombo.Items[0].ToString() : imagesize.ToString());
|
|
|
|
list.ImageSize = imagesize;
|
|
|
|
|
|
|
|
ApplySettings();
|
|
|
|
|
|
|
|
blockupdate = false;
|
|
|
|
}
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// This applies the application settings
|
|
|
|
public void ApplySettings()
|
|
|
|
{
|
|
|
|
// Force black background?
|
|
|
|
if(General.Settings.BlackBrowsers)
|
|
|
|
{
|
|
|
|
list.BackColor = Color.Black;
|
|
|
|
list.ForeColor = Color.White;
|
|
|
|
}
|
|
|
|
|
2011-12-02 22:18:55 +00:00
|
|
|
// Set the size of preview images
|
2009-05-12 08:01:50 +00:00
|
|
|
if(General.Map != null)
|
2011-12-02 22:18:55 +00:00
|
|
|
{
|
2013-06-19 11:18:13 +00:00
|
|
|
//mxd
|
2014-11-25 11:52:01 +00:00
|
|
|
if(General.Map.Config.MixTexturesFlats)
|
|
|
|
{
|
2016-12-22 15:04:40 +00:00
|
|
|
texturetypecombo.SelectedIndex = texturetype;
|
2014-11-25 11:52:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-12-22 15:04:40 +00:00
|
|
|
labelMixMode.Enabled = false;
|
|
|
|
texturetypecombo.Enabled = false;
|
|
|
|
texturetype = 0;
|
2013-06-19 11:18:13 +00:00
|
|
|
}
|
2014-12-03 09:06:05 +00:00
|
|
|
|
|
|
|
//mxd. Use long texture names?
|
|
|
|
longtexturenames.Checked = (uselongtexturenames && General.Map.Config.UseLongTextureNames);
|
2016-12-22 15:04:40 +00:00
|
|
|
longtexturenames.Enabled = General.Map.Config.UseLongTextureNames;
|
2014-12-03 09:06:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-12-22 15:04:40 +00:00
|
|
|
longtexturenames.Enabled = false; //mxd
|
2014-12-03 09:06:05 +00:00
|
|
|
uselongtexturenames = false; //mxd
|
2011-12-02 22:18:55 +00:00
|
|
|
}
|
2014-07-15 08:50:52 +00:00
|
|
|
|
|
|
|
//mxd
|
2016-12-22 15:04:40 +00:00
|
|
|
objectname.CharacterCasing = (longtexturenames.Checked ? CharacterCasing.Normal : CharacterCasing.Upper);
|
|
|
|
}
|
|
|
|
|
|
|
|
//mxd. Save settings
|
|
|
|
public virtual void OnClose(string settingpath)
|
|
|
|
{
|
2016-12-23 12:39:09 +00:00
|
|
|
General.Settings.WriteSetting(settingpath + ".showusedtexturesfirst", usedtexturesfirst.Checked);
|
2017-01-09 04:47:58 +00:00
|
|
|
General.Settings.WriteSetting(settingpath + ".classicview", classicview.Checked);
|
2016-12-22 15:04:40 +00:00
|
|
|
General.Settings.WriteSetting(settingpath + ".imagesize", list.ImageSize);
|
|
|
|
if(General.Map.Config.UseLongTextureNames) General.Map.Options.UseLongTextureNames = uselongtexturenames;
|
2014-12-03 09:06:05 +00:00
|
|
|
|
2016-12-22 15:04:40 +00:00
|
|
|
CleanUp();
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This cleans everything up
|
|
|
|
public virtual void CleanUp()
|
|
|
|
{
|
|
|
|
// Stop refresh timer
|
|
|
|
refreshtimer.Enabled = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Rendering
|
|
|
|
|
|
|
|
// Refresher
|
|
|
|
private void refreshtimer_Tick(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
bool allpreviewsloaded = true;
|
2016-12-22 15:04:40 +00:00
|
|
|
bool redrawneeded = false; //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Go for all items
|
|
|
|
foreach(ImageBrowserItem i in list.Items)
|
|
|
|
{
|
|
|
|
// Check if there are still previews that are not loaded
|
|
|
|
allpreviewsloaded &= i.IsPreviewLoaded;
|
2016-12-22 15:04:40 +00:00
|
|
|
|
|
|
|
//mxd. Item needs to be redrawn?
|
|
|
|
redrawneeded |= i.CheckRedrawNeeded();
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If all previews were loaded, stop this timer
|
|
|
|
if(allpreviewsloaded) refreshtimer.Stop();
|
2016-12-22 15:04:40 +00:00
|
|
|
|
|
|
|
// Redraw the list if needed
|
|
|
|
if(redrawneeded) list.Invalidate();
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Events
|
|
|
|
|
|
|
|
// Name typed
|
|
|
|
private void objectname_TextChanged(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
// Update list
|
|
|
|
RefillList(false);
|
|
|
|
|
|
|
|
// No item selected?
|
|
|
|
if(list.SelectedItems.Count == 0)
|
|
|
|
{
|
|
|
|
// Select first
|
|
|
|
SelectFirstItem();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-05 12:24:00 +00:00
|
|
|
// Key pressed in textbox
|
2009-04-19 18:07:22 +00:00
|
|
|
private void objectname_KeyDown(object sender, KeyEventArgs e)
|
|
|
|
{
|
2016-12-24 21:52:42 +00:00
|
|
|
// Toggle used items sorting
|
|
|
|
if(e.KeyData == Keys.Tab)
|
2016-12-22 15:04:40 +00:00
|
|
|
{
|
2016-12-24 21:52:42 +00:00
|
|
|
usedtexturesfirst.Checked = !usedtexturesfirst.Checked;
|
2016-12-22 15:04:40 +00:00
|
|
|
e.SuppressKeyPress = true;
|
|
|
|
}
|
2016-12-24 21:52:42 +00:00
|
|
|
//mxd. Clear text field instead of typing strange chars...
|
|
|
|
else if(e.KeyData == (Keys.Back | Keys.Control))
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2016-12-24 21:52:42 +00:00
|
|
|
if(objectname.Text.Length > 0) objectname.Clear();
|
2016-12-22 15:04:40 +00:00
|
|
|
e.SuppressKeyPress = true;
|
2009-05-05 12:24:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-22 15:04:40 +00:00
|
|
|
//mxd
|
|
|
|
private void objectclear_Click(object sender, EventArgs e)
|
2016-02-10 23:40:02 +00:00
|
|
|
{
|
2016-12-22 15:04:40 +00:00
|
|
|
objectname.Clear();
|
|
|
|
list.Focus();
|
2016-02-10 23:40:02 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 12:43:39 +00:00
|
|
|
//mxd
|
2014-05-19 13:33:38 +00:00
|
|
|
private void filterSize_WhenTextChanged(object sender, EventArgs e)
|
|
|
|
{
|
2013-09-26 12:43:39 +00:00
|
|
|
objectname_TextChanged(sender, e);
|
|
|
|
}
|
|
|
|
|
2015-03-25 22:13:40 +00:00
|
|
|
//mxd
|
|
|
|
protected override bool ProcessTabKey(bool forward)
|
|
|
|
{
|
2016-12-23 12:39:09 +00:00
|
|
|
usedtexturesfirst.Checked = !usedtexturesfirst.Checked;
|
2015-03-25 22:13:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Selection changed
|
2016-12-22 15:04:40 +00:00
|
|
|
private void list_SelectionChanged(object sender, List<ImageBrowserItem> selection)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
// Prevent selecting?
|
|
|
|
if(preventselection)
|
|
|
|
{
|
2016-12-22 15:04:40 +00:00
|
|
|
if(selection.Count > 0) list.ClearSelection(); //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Raise event
|
2016-12-22 15:04:40 +00:00
|
|
|
if(SelectedItemChanged != null)
|
|
|
|
SelectedItemChanged(list.SelectedItems.Count > 0 ? list.SelectedItems[0] : null);
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Doublelicking an item
|
2016-12-22 15:04:40 +00:00
|
|
|
private void list_ItemDoubleClicked(object sender, ImageBrowserItem item)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
if(!preventselection && (list.SelectedItems.Count > 0))
|
2016-12-22 15:04:40 +00:00
|
|
|
if(SelectedItemDoubleClicked != null) SelectedItemDoubleClicked(item);
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
2014-12-03 09:06:05 +00:00
|
|
|
|
2016-12-22 15:04:40 +00:00
|
|
|
//mxd. Transfer input to Filter textbox
|
2015-11-20 14:31:54 +00:00
|
|
|
private void list_KeyPress(object sender, KeyPressEventArgs e)
|
|
|
|
{
|
2016-12-24 21:52:42 +00:00
|
|
|
if(e.KeyChar == 8) // Backspace
|
2015-11-20 14:31:54 +00:00
|
|
|
{
|
2016-12-24 21:52:42 +00:00
|
|
|
if(objectname.Text.Length > 0)
|
2015-11-20 14:31:54 +00:00
|
|
|
{
|
2016-12-24 21:52:42 +00:00
|
|
|
if(objectname.SelectionLength > 0)
|
|
|
|
{
|
|
|
|
objectname.Text = objectname.Text.Substring(0, objectname.SelectionStart) +
|
|
|
|
objectname.Text.Substring(objectname.SelectionStart + objectname.SelectionLength);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
objectname.Text = objectname.Text.Substring(0, objectname.Text.Length - 1);
|
|
|
|
}
|
2015-11-20 14:31:54 +00:00
|
|
|
}
|
|
|
|
}
|
2016-12-24 21:52:42 +00:00
|
|
|
else if(e.KeyChar == 127) // Ctrl-Backspace
|
2015-11-20 14:31:54 +00:00
|
|
|
{
|
2016-12-24 21:52:42 +00:00
|
|
|
if(objectname.Text.Length > 0) objectname.Clear();
|
2016-12-22 15:04:40 +00:00
|
|
|
}
|
|
|
|
else if((e.KeyChar >= 'a' && e.KeyChar <= 'z') || (e.KeyChar >= '0' && e.KeyChar <= '9') || AllowedSpecialChars.Contains(e.KeyChar))
|
|
|
|
{
|
|
|
|
if(objectname.SelectionLength > 0)
|
|
|
|
{
|
|
|
|
objectname.Text = objectname.Text.Substring(0, objectname.SelectionStart) +
|
|
|
|
e.KeyChar +
|
|
|
|
objectname.Text.Substring(objectname.SelectionStart + objectname.SelectionLength);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
objectname.Text += e.KeyChar;
|
|
|
|
}
|
2015-11-20 14:31:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-03 09:06:05 +00:00
|
|
|
//mxd
|
2016-12-22 15:04:40 +00:00
|
|
|
private void texturetypecombo_SelectedIndexChanged(object sender, EventArgs e)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2016-12-22 15:04:40 +00:00
|
|
|
texturetype = texturetypecombo.SelectedIndex;
|
2017-01-09 05:21:26 +00:00
|
|
|
ElementName = (texturetype == 2 || (texturetype == 3 && browseflats)) ? "flats" : "textures";
|
|
|
|
|
|
|
|
RefillList(false);
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
2016-12-22 15:04:40 +00:00
|
|
|
//mxd
|
|
|
|
private void sizecombo_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if(blockupdate) return;
|
|
|
|
list.ImageSize = (sizecombo.SelectedIndex == 0 ? 0 : Convert.ToInt32(sizecombo.SelectedItem));
|
|
|
|
list.Focus();
|
2017-01-09 05:21:26 +00:00
|
|
|
}
|
2016-12-22 15:04:40 +00:00
|
|
|
|
2014-12-03 09:06:05 +00:00
|
|
|
//mxd
|
|
|
|
private void longtexturenames_CheckedChanged(object sender, EventArgs e)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2016-12-23 12:39:09 +00:00
|
|
|
if(!blockupdate)
|
|
|
|
{
|
|
|
|
uselongtexturenames = longtexturenames.Checked;
|
|
|
|
objectname.CharacterCasing = (uselongtexturenames ? CharacterCasing.Normal : CharacterCasing.Upper);
|
|
|
|
|
|
|
|
foreach(var item in items) item.ShowFullName = uselongtexturenames;
|
2017-01-08 22:04:55 +00:00
|
|
|
list.UpdateRectangles();
|
2016-12-23 12:39:09 +00:00
|
|
|
list.Focus();
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
2013-03-26 12:31:07 +00:00
|
|
|
|
|
|
|
//mxd
|
2016-12-23 12:39:09 +00:00
|
|
|
private void usedtexturesfirst_CheckedChanged(object sender, EventArgs e)
|
2014-11-25 11:52:01 +00:00
|
|
|
{
|
2016-12-23 12:39:09 +00:00
|
|
|
if(!blockupdate)
|
|
|
|
{
|
2017-01-09 05:00:27 +00:00
|
|
|
list.UsedTexturesFirst = usedtexturesfirst.Checked;
|
|
|
|
RefillList(false);
|
2016-12-23 12:39:09 +00:00
|
|
|
list.Focus();
|
|
|
|
}
|
2013-03-26 12:31:07 +00:00
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
|
2017-01-09 04:47:58 +00:00
|
|
|
//
|
|
|
|
private void classicview_CheckedChanged(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if(!blockupdate)
|
|
|
|
{
|
|
|
|
list.ClassicView = classicview.Checked;
|
|
|
|
list.Focus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
2009-04-19 18:07:22 +00:00
|
|
|
|
2017-01-09 04:47:58 +00:00
|
|
|
#region ================== Methods
|
|
|
|
|
|
|
|
// This selects an item by longname (mxd - changed from name to longname)
|
|
|
|
public void SelectItem(long longname)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
// Not when selecting is prevented
|
|
|
|
if(preventselection) return;
|
|
|
|
|
2016-12-22 15:04:40 +00:00
|
|
|
// Search for item
|
|
|
|
ImageBrowserItem target = null; //mxd
|
2016-12-23 12:39:09 +00:00
|
|
|
foreach(ImageBrowserItem item in items)
|
2016-12-22 15:04:40 +00:00
|
|
|
{
|
2016-12-23 12:39:09 +00:00
|
|
|
if(item.Icon.LongName == longname) //mxd
|
2016-02-10 23:40:02 +00:00
|
|
|
{
|
2016-12-23 12:39:09 +00:00
|
|
|
target = item;
|
|
|
|
break;
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
2016-12-22 15:04:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(target != null)
|
|
|
|
{
|
|
|
|
// Select the item
|
|
|
|
list.SetSelectedItem(target);
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This selectes the first item
|
|
|
|
private void SelectFirstItem()
|
|
|
|
{
|
|
|
|
// Not when selecting is prevented
|
|
|
|
if(preventselection) return;
|
|
|
|
|
|
|
|
// Select first
|
2016-12-22 15:04:40 +00:00
|
|
|
if(list.Items.Count > 0) list.SetSelectedItem(list.Items[0]);
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This begins adding items
|
2016-12-22 15:04:40 +00:00
|
|
|
public void BeginAdding(bool keepselectedindex)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
if(keepselectedindex && (list.SelectedItems.Count > 0))
|
2016-12-22 15:04:40 +00:00
|
|
|
keepselected = list.Items.IndexOf(list.SelectedItems[0]);
|
2009-04-19 18:07:22 +00:00
|
|
|
else
|
|
|
|
keepselected = -1;
|
|
|
|
|
|
|
|
// Clean list
|
|
|
|
items.Clear();
|
|
|
|
|
|
|
|
// Stop updating
|
|
|
|
refreshtimer.Enabled = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This ends adding items
|
|
|
|
public void EndAdding()
|
|
|
|
{
|
|
|
|
// Fill list with items
|
|
|
|
RefillList(true);
|
|
|
|
|
|
|
|
// Start updating
|
|
|
|
refreshtimer.Enabled = true;
|
|
|
|
}
|
2016-12-22 15:04:40 +00:00
|
|
|
|
|
|
|
//mxd. This adds a category item
|
2016-12-23 12:39:09 +00:00
|
|
|
public void AddFolder(ImageBrowserItemType itemtype, string categoryname)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2016-12-22 15:04:40 +00:00
|
|
|
switch(itemtype)
|
|
|
|
{
|
|
|
|
case ImageBrowserItemType.FOLDER: case ImageBrowserItemType.FOLDER_UP:
|
2016-12-23 12:39:09 +00:00
|
|
|
items.Add(new ImageBrowserCategoryItem(itemtype, categoryname));
|
2016-12-22 15:04:40 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default: throw new Exception("Unsupported ImageBrowserItemType");
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This adds an item
|
2016-12-23 12:39:09 +00:00
|
|
|
public void AddItem(ImageData image, string tooltip)
|
2016-12-22 15:04:40 +00:00
|
|
|
{
|
2016-12-23 12:39:09 +00:00
|
|
|
items.Add(new ImageBrowserItem(image, tooltip, uselongtexturenames));
|
2016-12-22 15:04:40 +00:00
|
|
|
}
|
|
|
|
|
2016-12-23 12:39:09 +00:00
|
|
|
public void AddItem(ImageData image)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2016-12-23 12:39:09 +00:00
|
|
|
items.Add(new ImageBrowserItem(image, string.Empty, uselongtexturenames));
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This fills the list based on the objectname filter
|
|
|
|
private void RefillList(bool selectfirst)
|
|
|
|
{
|
2009-05-05 12:24:00 +00:00
|
|
|
visibleitems = new List<ImageBrowserItem>();
|
2016-02-10 23:40:02 +00:00
|
|
|
|
|
|
|
//mxd. Store info about currently selected item
|
|
|
|
string selectedname = string.Empty;
|
2016-12-22 15:04:40 +00:00
|
|
|
if(!selectfirst && keepselected == -1 && list.SelectedItems.Count > 0)
|
2016-02-10 23:40:02 +00:00
|
|
|
{
|
2016-12-22 15:04:40 +00:00
|
|
|
selectedname = list.SelectedItems[0].Icon.Name;
|
2016-02-10 23:40:02 +00:00
|
|
|
}
|
2016-12-22 15:04:40 +00:00
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// Clear list first
|
2016-12-22 15:04:40 +00:00
|
|
|
list.Clear();
|
2016-12-23 12:39:09 +00:00
|
|
|
list.Title = (usedtexturesfirst.Checked ? usedfirstgroup : availgroup);
|
|
|
|
|
|
|
|
//mxd. Anything to do?
|
|
|
|
if(items.Count == 0) return;
|
2013-09-26 12:43:39 +00:00
|
|
|
|
|
|
|
//mxd. Filtering by texture size?
|
|
|
|
int w = filterWidth.GetResult(-1);
|
|
|
|
int h = filterHeight.GetResult(-1);
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Go for all items
|
2015-03-22 20:43:05 +00:00
|
|
|
ImageBrowserItem previtem = null; //mxd
|
2016-12-23 12:39:09 +00:00
|
|
|
for(int i = items.Count - 1; i > -1; i--)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
// Add item if valid
|
2016-12-23 12:39:09 +00:00
|
|
|
items[i].ShowFullName = uselongtexturenames; //mxd
|
2016-12-24 21:52:42 +00:00
|
|
|
switch(items[i].ItemType)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2016-12-24 21:52:42 +00:00
|
|
|
case ImageBrowserItemType.IMAGE:
|
|
|
|
if(ValidateItem(items[i], previtem) && ValidateItemSize(items[i], w, h))
|
|
|
|
{
|
|
|
|
visibleitems.Add(items[i]);
|
|
|
|
previtem = items[i];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ImageBrowserItemType.FOLDER_UP: //mxd. "Browse Up" items are always valid
|
|
|
|
visibleitems.Add(items[i]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ImageBrowserItemType.FOLDER: //mxd. Only apply name filtering to "Folder" items
|
|
|
|
if(items[i].TextureName.ToUpperInvariant().Contains(objectname.Text.ToUpperInvariant()))
|
|
|
|
visibleitems.Add(items[i]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: throw new NotImplementedException("Unknown ImageBrowserItemType");
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fill list
|
2016-12-23 12:39:09 +00:00
|
|
|
visibleitems.Sort(SortItems);
|
2016-12-22 15:04:40 +00:00
|
|
|
list.SetItems(visibleitems);
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Make selection?
|
2016-12-22 15:04:40 +00:00
|
|
|
if(!preventselection && list.Items.Count > 0)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
// Select specific item?
|
|
|
|
if(keepselected > -1)
|
|
|
|
{
|
2016-12-22 15:04:40 +00:00
|
|
|
list.SetSelectedItem(list.Items[keepselected]);
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
// Select first item?
|
|
|
|
else if(selectfirst)
|
|
|
|
{
|
|
|
|
SelectFirstItem();
|
|
|
|
}
|
2016-02-10 23:40:02 +00:00
|
|
|
//mxd. Try reselecting the same/next closest item
|
2016-12-22 15:04:40 +00:00
|
|
|
else if(!string.IsNullOrEmpty(selectedname))
|
2016-02-10 23:40:02 +00:00
|
|
|
{
|
2016-12-22 15:04:40 +00:00
|
|
|
ImageBrowserItem bestmatch = null;
|
2016-02-10 23:40:02 +00:00
|
|
|
int charsmatched = 1;
|
2016-12-22 15:04:40 +00:00
|
|
|
foreach(ImageBrowserItem item in list.Items)
|
2016-02-10 23:40:02 +00:00
|
|
|
{
|
2016-12-22 15:04:40 +00:00
|
|
|
if(item.ItemType == ImageBrowserItemType.IMAGE && item.Icon.Name[0] == selectedname[0])
|
2016-02-10 23:40:02 +00:00
|
|
|
{
|
2016-12-22 15:04:40 +00:00
|
|
|
if(item.Icon.Name == selectedname)
|
2016-02-10 23:40:02 +00:00
|
|
|
{
|
|
|
|
bestmatch = item;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-12-22 15:04:40 +00:00
|
|
|
for(int i = 1; i < Math.Min(item.Icon.Name.Length, selectedname.Length); i++)
|
2016-02-10 23:40:02 +00:00
|
|
|
{
|
2016-12-22 15:04:40 +00:00
|
|
|
if(item.Icon.Name[i] != selectedname[i])
|
2016-02-10 23:40:02 +00:00
|
|
|
{
|
|
|
|
if(i > charsmatched)
|
|
|
|
{
|
|
|
|
bestmatch = item;
|
|
|
|
charsmatched = i;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Select found item
|
|
|
|
if(bestmatch != null)
|
|
|
|
{
|
2016-12-22 15:04:40 +00:00
|
|
|
list.SetSelectedItem(bestmatch);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SelectFirstItem();
|
2016-02-10 23:40:02 +00:00
|
|
|
}
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Raise event
|
2016-12-22 15:04:40 +00:00
|
|
|
if((SelectedItemChanged != null) && !preventselection)
|
|
|
|
SelectedItemChanged(list.SelectedItems.Count > 0 ? list.SelectedItems[0] : null);
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This validates an item
|
2015-03-22 20:43:05 +00:00
|
|
|
private bool ValidateItem(ImageBrowserItem item, ImageBrowserItem previtem)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2014-12-03 09:06:05 +00:00
|
|
|
//mxd. Don't show duplicate items
|
2016-12-22 15:04:40 +00:00
|
|
|
if(previtem != null && item.TextureName == previtem.TextureName) return false; //mxd
|
2014-12-03 09:06:05 +00:00
|
|
|
|
2014-01-24 08:09:57 +00:00
|
|
|
//mxd. mixMode: 0 = All, 1 = Textures, 2 = Flats, 3 = Based on BrowseFlats
|
2014-12-03 09:06:05 +00:00
|
|
|
if(!splitter.Panel2Collapsed)
|
|
|
|
{
|
2016-12-22 15:04:40 +00:00
|
|
|
if(texturetype == 1 && item.Icon.IsFlat) return false;
|
|
|
|
if(texturetype == 2 && !item.Icon.IsFlat) return false;
|
|
|
|
if(texturetype == 3 && (browseflats != item.Icon.IsFlat)) return false;
|
2013-03-26 12:31:07 +00:00
|
|
|
}
|
|
|
|
|
2016-12-22 15:04:40 +00:00
|
|
|
return item.TextureName.ToUpperInvariant().Contains(objectname.Text.ToUpperInvariant());
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
2013-09-26 12:43:39 +00:00
|
|
|
|
|
|
|
//mxd. This validates an item's texture size
|
2014-05-19 13:33:38 +00:00
|
|
|
private static bool ValidateItemSize(ImageBrowserItem i, int w, int h)
|
|
|
|
{
|
2015-12-28 15:01:53 +00:00
|
|
|
if(!i.Icon.IsPreviewLoaded) return true;
|
|
|
|
if(w > 0 && i.Icon.Width != w) return false;
|
|
|
|
if(h > 0 && i.Icon.Height != h) return false;
|
2013-09-26 12:43:39 +00:00
|
|
|
return true;
|
|
|
|
}
|
2016-12-23 12:39:09 +00:00
|
|
|
|
|
|
|
//mxd
|
|
|
|
private int SortItems(ImageBrowserItem item1, ImageBrowserItem item2)
|
|
|
|
{
|
|
|
|
if(usedtexturesfirst.Checked
|
|
|
|
&& item1.ItemType == ImageBrowserItemType.IMAGE
|
|
|
|
&& item2.ItemType == ImageBrowserItemType.IMAGE
|
|
|
|
&& item1.Icon.UsedInMap != item2.Icon.UsedInMap)
|
|
|
|
{
|
|
|
|
// Push used items to the top
|
|
|
|
return (item1.Icon.UsedInMap ? -1 : 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return item1.CompareTo(item2);
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
|
2016-12-22 15:04:40 +00:00
|
|
|
//mxd. This sends the focus to the textures list
|
|
|
|
public void FocusList()
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2016-12-22 15:04:40 +00:00
|
|
|
list.Focus();
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
2017-01-09 04:47:58 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|