Rev 1390 |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace SpriteEditor
{
public partial class NewSpriteDialog
: Form
{
public class ListBoxItem
{
public string FullPath
{ get
; set
; }
public string DisplayName
{ get
; set
; }
}
public NewSpriteDialog
()
{
InitializeComponent
();
}
private void NewSpriteDialog_Load
(object sender, EventArgs e
)
{
String s
= Path
.Combine(Application
.StartupPath,
@"..\\..\\..\\..\\..\\BauzoidApps\\BurutaruZ_v2\\burutaru-android\\assets\\data\\textures");
dlgAddTextures
.InitialDirectory = Path
.GetFullPath(s
);
lbTextures
.DisplayMember = "DisplayName";
lbTextures
.ValueMember = "FullPath";
}
private void AddTextures_Click
(object sender, EventArgs e
)
{
if (dlgAddTextures
.ShowDialog() == DialogResult
.OK)
{
for (int i
= 0; i
< dlgAddTextures
.FileNames.Length; i
++)
{
lbTextures
.Items.Add(new ListBoxItem
{ FullPath
= dlgAddTextures
.FileNames[i
], DisplayName
= dlgAddTextures
.SafeFileNames[i
] } );
}
btnOK
.Enabled = true;
}
}
private void RemoveTextures_Click
(object sender, EventArgs e
)
{
if (lbTextures
.SelectedIndex == -1)
return;
lbTextures
.Items.RemoveAt(lbTextures
.SelectedIndex);
if (lbTextures
.Items.Count == 0)
btnOK
.Enabled = false;
}
private void MoveUp_Click
(object sender, EventArgs e
)
{
if (lbTextures
.SelectedIndex == -1)
return;
int currentIndex
= lbTextures
.SelectedIndex;
ListBoxItem item
= (ListBoxItem
)lbTextures
.SelectedItem;
if (currentIndex
> 0)
{
lbTextures
.Items.RemoveAt(currentIndex
);
lbTextures
.Items.Insert(currentIndex
- 1, item
);
lbTextures
.SelectedIndex = currentIndex
- 1;
}
}
private void MoveDown_Click
(object sender, EventArgs e
)
{
if (lbTextures
.SelectedIndex == -1)
return;
int currentIndex
= lbTextures
.SelectedIndex;
ListBoxItem item
= (ListBoxItem
)lbTextures
.SelectedItem;
if (currentIndex
< (lbTextures
.Items.Count-1))
{
lbTextures
.Items.RemoveAt(currentIndex
);
lbTextures
.Items.Insert(currentIndex
+ 1, item
);
lbTextures
.SelectedIndex = currentIndex
+ 1;
}
}
private void TextureSelection_Changed
(object sender, EventArgs e
)
{
if (lbTextures
.SelectedItems.Count > 0)
{
picPreview
.Image = Image
.FromFile(((ListBoxItem
)lbTextures
.SelectedItems[0]).FullPath);
picPreview
.Invalidate();
}
else
{
picPreview
.Image = null;
}
}
public string[] GetFilenames
()
{
string[] filenames
= new string[lbTextures
.Items.Count];
for (int i
= 0; i
< filenames
.Length; i
++)
{
filenames
[i
] = ((ListBoxItem
)lbTextures
.Items[i
]).FullPath;
}
return filenames
;
}
}
}